moodle/lib/amd/build/permissionmanager.min.js

1 line
3.0 KiB
JavaScript

define(["jquery","core/config","core/notification","core/templates"],function(a,b,c,d){var e,f,g,h,i={ADDROLE:"a.allowlink, a.prohibitlink",REMOVEROLE:"a.preventlink, a.unprohibitlink",UNPROHIBIT:"a.unprohibitlink"},j=a.Event("rolesloaded"),k=null,l=function(){var d={contextid:e,getroles:1,sesskey:b.sesskey};a.post(g+"roles/ajax.php",d,null,"json").done(function(b){try{h=b,l=function(){a("body").trigger(j)},l()}catch(d){c.exception(d)}}).fail(function(a,b,d){c.exception(d)})},m=function(b,f,i){var j={contextid:e,roleid:f,sesskey:M.cfg.sesskey,action:i,capability:b.data("name")};a.post(g+"roles/ajax.php",j,null,"json").done(function(e){var i=e;try{var j={rolename:h[f],roleid:f,adminurl:g,imageurl:M.util.image_url("t/delete","moodle")};switch(i){case"allow":j.spanclass="allowed",j.linkclass="preventlink",j.action="prevent";break;case"prohibit":j.spanclass="forbidden",j.linkclass="unprohibitlink",j.action="unprohibit";break;case"prevent":return void b.find('a[data-role-id="'+f+'"]').first().closest(".allowed").remove();case"unprohibit":return void b.find('a[data-role-id="'+f+'"]').first().closest(".forbidden").remove();default:return}d.render("core/permissionmanager_role",j).done(function(c){if("allow"==i)a(c).insertBefore(b.find(".allowmore:first"));else if("prohibit"==i){a(c).insertBefore(b.find(".prohibitmore:first"));var d=b.find(".allowedroles").first().find('a[data-role-id="'+f+'"]');d&&d.first().closest(".allowed").remove()}k.hide()}).fail(c.exception)}catch(l){c.exception(l)}}).fail(function(a,b,d){c.exception(d)})},n=function(b){b.preventDefault(),a("body").one("rolesloaded",function(){var e=a(b.currentTarget),g=e.data("action"),j=e.closest("tr.rolecap"),l={cap:j.data("humanname"),context:f},n=M.util.get_string("role"+g+"info","core_role",l);null===k&&(k=new M.core.dialogue({draggable:!0,modal:!0,closeButton:!0,width:"450px"})),k.set("headerContent",M.util.get_string("role"+g+"header","core_role"));var o,p,q=[];switch(g){case"allow":p=j.find(i.REMOVEROLE);break;case"prohibit":p=j.find(i.UNPROHIBIT)}for(o in h){var r="",s=p.filter("[data-role-id='"+o+"']").length;s&&(r="disabled");var t={roleid:o,rolename:h[o],disabled:r};q.push(t)}d.render("core/permissionmanager_panelcontent",{message:n,roles:q}).done(function(b){k.set("bodyContent",b),k.show(),a("div.role_buttons").delegate("input","click",function(b){var c=a(b.currentTarget).data("role-id");m(j,c,g)})}).fail(c.exception)}),l()},o=function(b){b.preventDefault(),a("body").one("rolesloaded",function(){var d=a(b.currentTarget),e=d.data("action"),g=d.data("role-id"),i=d.closest("tr.rolecap"),j={role:h[g],cap:i.data("humanname"),context:f};c.confirm(M.util.get_string("confirmunassigntitle","core_role"),M.util.get_string("confirmrole"+e,"core_role",j),M.util.get_string("confirmunassignyes","core_role"),M.util.get_string("confirmunassignno","core_role"),function(){m(i,g,e)})}),l()};return{initialize:function(b){e=b.contextid,f=b.contextname,g=b.adminurl;var c=a("body");c.delegate(i.ADDROLE,"click",n),c.delegate(i.REMOVEROLE,"click",o)}}});