Skip to content

Commit

Permalink
Issue #406
Browse files Browse the repository at this point in the history
  • Loading branch information
pavels committed Apr 12, 2016
1 parent fc38dcb commit 5766452
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 63 deletions.
27 changes: 27 additions & 0 deletions client/src/main/webapp/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,33 @@ ClientAPIDev.prototype = {
}, this));
},

/**
* Requesting children from concrete pid
* @param {string} pid - Pid of object.
* @param {requestCallback} whenready - Callback handling responses.
* @method
*/
askForRights : function(pid, actions, whenready) {
var actions = _.reduce(actions, function(memo, value, index) {
if (index > 0) {
memo = memo + ",";
}
memo = memo + value;
return memo;
}, "");
$.getJSON("api/rights?pid=" + pid + "&actions="+actions, _.bind(function(data) {
if (!this.isKeyReady("item")) {
this.ctx["item"] = {};
}
if (!this.isKeyReady("item/" + pid)) {
this.ctx["item"][pid] = {};
}
this.ctx["item"][pid]['rights'] = data;
if (whenready)
whenready.apply(null, [ data ]);
}, this));
},

/**
* Requesting children from concrete pid
* @param {string} pid - Pid of object.
Expand Down
118 changes: 59 additions & 59 deletions client/src/main/webapp/js/item/downloadItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,72 +122,72 @@ DownloadItem.prototype.open = function() {
cleanWindow();
divopen("#download");

var doptions = K5.gui.downloadoptions.ctx.actions;
K5.api.askForRights(K5.api.ctx.item.selected,["read","pdf_resource","show_client_print_menu","show_client_pdf_menu"], function (data) {
var doptions = K5.gui.downloadoptions.ctx.actions;
var select = $('<ul/>');
select.change(function(item) {
var selAction = K5.gui.selected.download.selectAction();
if (selAction && selAction.object.message) {
var tMess = selAction.object.message();
$("#download_action_message").html(tMess);
} else {
$("#download_action_message").html("");
}

var select = $('<ul/>');

select.change(function(item) {
var selAction = K5.gui.selected.download.selectAction();
if (selAction && selAction.object.message) {
var tMess = selAction.object.message();
$("#download_action_message").html(tMess);
} else {
$("#download_action_message").html("");
}
});

var options = _.map(doptions, function(a, context) {
if (a.object.enabled()) {
var liHtml = $('<li/>');

var divHtml = $('<div/>');

var optHtml =$('<input/>', {'value': a.name, 'type':'radio','name':'action'});
divHtml.append(optHtml);

var transSpan = K5.i18n.translatable(a.i18nkey);

var aHrefFunction = "javascript:(function() { $('#download_options ul li input[value=\""+a.name+"\"]').prop('checked', true); K5.gui.selected.download.doAction();}) ();";
var aHref = $('<a/>', {'href': aHrefFunction,'data-key': a.i18nkey});
aHref.append(transSpan);

divHtml.append(aHref);
liHtml.append(divHtml);
var option = {
"elem":liHtml
};
if (a.object["message"]) {
option["message"] = a.object.message();
}
return option;
} else return null;
});

_.each(options, function(opt) {
if (opt != null) {
select.append(opt.elem);
}
});

});

var options = _.map(doptions, function(a, context) {
if (a.object.enabled()) {
var liHtml = $('<li/>');

var divHtml = $('<div/>');

var optHtml =$('<input/>', {'value': a.name, 'type':'radio','name':'action'});
divHtml.append(optHtml);

var transSpan = K5.i18n.translatable(a.i18nkey);

var aHrefFunction = "javascript:(function() { $('#download_options ul li input[value=\""+a.name+"\"]').prop('checked', true); K5.gui.selected.download.doAction();}) ();";
var aHref = $('<a/>', {'href': aHrefFunction,'data-key': a.i18nkey});
aHref.append(transSpan);

divHtml.append(aHref);
liHtml.append(divHtml);
var option = {
"elem":liHtml
};
if (a.object["message"]) {
option["message"] = a.object.message();
var first = _.reduce(options, function(memo, value, index) {
if (memo == null) {
memo = value;
}
return option;
} else return null;
});
return memo;
}, null);

_.each(options, function(opt) {
if (opt != null) {
select.append(opt.elem);
}
});
var input = first.elem.find('input');
input.prop('checked', true);

var first = _.reduce(options, function(memo, value, index) {
if (memo == null) {
memo = value;
var message = first["message"];
if ((message) && (message != null)) {
$("#download_action_message").text(message);
} else {
$("#download_action_message").text("");
}
return memo;
}, null);

var input = first.elem.find('input');
input.prop('checked', true);

var message = first["message"];
if ((message) && (message != null)) {
$("#download_action_message").text(message);
} else {
$("#download_action_message").text("");
}

$("#download_options").html(select);
$("#download_options").html(select);
});
}

DownloadItem.prototype.cleanDialog = function() {
Expand Down
73 changes: 69 additions & 4 deletions client/src/main/webapp/js/menu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ PDFOnePage.prototype = {
var selected = K5.api.ctx.item.selected;
var itm = K5.api.ctx.item[selected];
if (!itm['forbidden']) {
if (itm['rights']) {
var flag = itm['rights']['read'] &&
itm['rights']['pdf_resource'] &&
itm['rights']['show_client_pdf_menu'] &&
itm['rights']['show_client_print_menu'];
if (!flag) {
return false;
}
}
if ((!_isAudio()) && (!_isPDF())) {
return K5.api.ctx.item[selected].datanode;
} else return false;
Expand Down Expand Up @@ -413,6 +422,15 @@ PrintPartItem.prototype = {
var selected = K5.api.ctx.item.selected;
var itm = K5.api.ctx.item[selected];
if (!itm['forbidden']) {
if (itm['rights']) {
var flag = itm['rights']['read'] &&
itm['rights']['pdf_resource'] &&
itm['rights']['show_client_pdf_menu'] &&
itm['rights']['show_client_print_menu'];
if (!flag) {
return false;
}
}
if ((!_isAudio()) && (!_isPDF())) {
return K5.api.ctx.item[selected].datanode;
} else return false;
Expand All @@ -435,9 +453,17 @@ PrintPage.prototype = {
},
'enabled': function() {
var selected = K5.api.ctx.item.selected;

var itm = K5.api.ctx.item[selected];
if (!itm['forbidden']) {
if (itm['rights']) {
var flag = itm['rights']['read'] &&
itm['rights']['pdf_resource'] &&
itm['rights']['show_client_pdf_menu'] &&
itm['rights']['show_client_print_menu'];
if (!flag) {
return false;
}
}
if ((!_isAudio()) && (!_isPDF())) {
return K5.api.ctx.item[selected].datanode;
} else return false;
Expand All @@ -462,6 +488,15 @@ PrintSiblings.prototype = {
var selected = K5.api.ctx.item.selected;
var itm = K5.api.ctx.item[selected];
if (!itm['forbidden']) {
if (itm['rights']) {
var flag = itm['rights']['read'] &&
itm['rights']['pdf_resource'] &&
itm['rights']['show_client_pdf_menu'] &&
itm['rights']['show_client_print_menu'];
if (!flag) {
return false;
}
}
if ((!_isAudio()) && (!_isPDF())) {
return K5.api.ctx.item[selected].datanode;
} else return false;
Expand All @@ -486,6 +521,17 @@ PrintTitle.prototype = {
var selected = K5.api.ctx.item.selected;
var itm = K5.api.ctx.item[selected];
if (!itm['forbidden']) {

if (itm['rights']) {
var flag = itm['rights']['read'] &&
itm['rights']['pdf_resource'] &&
itm['rights']['show_client_pdf_menu'] &&
itm['rights']['show_client_print_menu'];
if (!flag) {
return false;
}
}

if ((!_isAudio()) && (!_isPDF())) {
var children = K5.api.ctx.item[selected]["children"];
if (children) {
Expand Down Expand Up @@ -542,6 +588,16 @@ PDFSiblingsTitle.prototype = {

var itm = K5.api.ctx.item[selected];
if (!itm['forbidden']) {
if (itm['rights']) {
var flag = itm['rights']['read'] &&
itm['rights']['pdf_resource'] &&
itm['rights']['show_client_pdf_menu'] &&
itm['rights']['show_client_print_menu'];
if (!flag) {
return false;
}
}

if ((!_isAudio()) && (!_isPDF())) {
return K5.api.ctx.item[selected].datanode;
} else return false;
Expand All @@ -566,11 +622,11 @@ PDFTitle.prototype = {
K5.outputs.pdf.title(K5.api.ctx.item.selected);
},
'message' :function() {
this.ctx.conf
//this.ctx.conf
if (this.ctx && this.ctx.conf) {
if (this.ctx.conf.pdfMaxRange !== "unlimited") {
var f = K5.i18n.ctx.dictionary['ctx.actions.pdftitle.message.1'];
var s = K5.i18n.ctx.dictionary['ctx.actions.pdftitle.message.2'];
var f = K5.i18n.ctx.dictionary['ctx.actions.pdftitle.message.1'];
var s = K5.i18n.ctx.dictionary['ctx.actions.pdftitle.message.2'];
return f+this.ctx.conf.pdfMaxRange;
}
} else return null;
Expand All @@ -580,6 +636,15 @@ PDFTitle.prototype = {
var selected = K5.api.ctx.item.selected;
var itm = K5.api.ctx.item[selected];
if (!itm['forbidden']) {
if (itm['rights']) {
var flag = itm['rights']['read'] &&
itm['rights']['pdf_resource'] &&
itm['rights']['show_client_pdf_menu'] &&
itm['rights']['show_client_print_menu'];
if (!flag) {
return false;
}
}
if ((!_isAudio()) && (!_isPDF())) {
var children = K5.api.ctx.item[selected]["children"];
if (children) {
Expand Down

0 comments on commit 5766452

Please sign in to comment.