wn.pages['permission-manager'].onload = function(wrapper) { wn.ui.make_app_page({ parent: wrapper, title: wn._('Permission Manager'), single_column: true }); $(wrapper).find(".layout-main").html("
\\
"+wn._("Quick Help for Setting Permissions")+":\
|
\
"+wn._("Meaning of Submit, Cancel, Amend")+":\
|
\
"+wn._("Permission Levels")+":\
|
\
"+wn._("Restricting By User")+":\
|
\
"+wn._("Advanced Settings")+":\"+wn._("To further restrict permissions based on certain values in a document, use the 'Condition' settings.")+"
"+wn._("Once you have set this, the users will only be able access documents with that property.")+" \\ "+wn._("If these instructions where not helpful, please add in your suggestions at GitHub Issues")+" \ |
").appendTo(this.body)) .click(function() { var d = new wn.ui.Dialog({ title: wn._("Add New Permission Rule"), fields: [ {fieldtype:"Select", label:"Document Type", options:me.options.doctypes, reqd:1, fieldname:"parent"}, {fieldtype:"Select", label:"Role", options:me.options.roles, reqd:1}, {fieldtype:"Select", label:"Permission Level", options:[0,1,2,3,4,5,6,7,8,9], reqd:1, fieldname: "permlevel", description: wn._("Level 0 is for document level permissions, higher levels for field level permissions.")}, {fieldtype:"Button", label:"Add"}, ] }); if(me.get_doctype()) { d.set_value("parent", me.get_doctype()); d.get_input("parent").prop("disabled", true); } if(me.get_role()) { d.set_value("role", me.get_role()); d.get_input("role").prop("disabled", true); } d.set_value("permlevel", "0"); d.get_input("add").click(function() { var args = d.get_values(); if(!args) { return; } wn.call({ module: "core", page: "permission_manager", method: "add", args: args, callback: function(r) { if(r.exc) { msgprint(wn._("Did not add.")); } else { me.refresh(); } } }) d.hide(); }); d.show(); }); }, get_perm: function(name) { return $.map(this.perm_list, function(d) { if(d.name==name) return d; })[0]; }, show_match_manager:function(name) { var perm = this.get_perm(name); var me = this; wn.model.with_doctype(perm.parent, function() { var dialog = new wn.ui.Dialog({ title: "Applies for Users", }); $(dialog.body).html("
").appendTo(dialog.body)) .attr("data-name", perm.name) .click(function() { var match_value = $(dialog.wrapper).find(":radio:checked").val(); var perm = me.get_perm($(this).attr('data-name')) return wn.call({ module: "core", page: "permission_manager", method: "update_match", args: { name: perm.name, doctype: perm.parent, match: match_value }, callback: function() { dialog.hide(); me.refresh(); } }) }); dialog.show(); // select if(perm.match) { $(dialog.wrapper).find("[value='"+perm.match+"']").prop("checked", true).focus(); } else { $(dialog.wrapper).find('[value=""]').prop("checked", true).focus(); } }); }, get_profile_fields: function(doctype) { var profile_fields = wn.model.get("DocField", {parent:doctype, fieldtype:"Link", options:"Profile"}); profile_fields = profile_fields.concat(wn.model.get("DocField", {parent:doctype, fieldtype:"Select", link_doctype:"Profile"})) return profile_fields }, get_link_fields: function(doctype) { return link_fields = wn.model.get("DocField", {parent:doctype, fieldtype:"Link", options:["not in", ["Profile", '[Select]']]}); } })