{"size": 14807, "ext": "js", "max_stars_repo_path": "static/scripts/S3/s3.ui.permissions.min.js", "max_stars_repo_name": "e2000y/eden", "max_stars_repo_stars_event_min_datetime": "2015-01-20T08:26:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T19:59:33.000Z", "max_issues_repo_path": "static/scripts/S3/s3.ui.permissions.min.js", "max_issues_repo_name": "nursix/eden-asp", "max_issues_repo_issues_event_min_datetime": "2015-02-10T09:56:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-23T19:54:36.000Z", "max_forks_repo_path": "static/scripts/S3/s3.ui.permissions.min.js", "max_forks_repo_name": "nursix/eden-asp", "max_forks_repo_forks_event_min_datetime": "2015-02-10T09:33:17.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T19:56:05.000Z"}
{"max_stars_count": 205, "max_issues_count": 249, "max_forks_count": 231, "avg_line_length": 400.1891891892, "max_line_length": 551, "alphanum_fraction": 0.6677922604}
/*
 2018-2021 (c) Sahana Software Foundation
 @license MIT

 requires jQuery 1.9.1+
 requires jQuery UI 1.10 widget factory
*/
(function(d,u){var l={rm_Add:"Add",rm_AddRule:"Add Rule",rm_AllEntities:"All Entities",rm_AllRecords:"All Records",rm_AssignedEntities:"Assigned Entities",rm_Cancel:"Cancel",rm_CollapseAll:"Collapse All",rm_ConfirmDeleteRule:"Do you want to delete this rule?",rm_Default:"default",rm_DeleteRule:"Delete",rm_ExpandAll:"Expand All",rm_NoAccess:"No access",rm_NoRestrictions:"No restrictions",rm_Others:"Others",rm_OwnedRecords:"Owned Records",rm_Page:"Page",rm_RestrictedTables:"Restricted Tables",rm_Scope:"Scope",
rm_SystemTables:"System Tables",rm_Table:"Table",rm_UnrestrictedTables:"Unrestricted Tables"},w=function(a){var b,c=a[3];c?!0!==c&&(b=c):!0!==a[2]&&(b=a[1]+"/"+(a[2]||"*"));return b},y=0;d.widget("s3.permissionEdit",{options:{fRules:!1,tRules:!1,useRealms:!1,permissions:[{l:"CREATE",b:1,o:!1},{l:"READ",b:2,o:!0},{l:"UPDATE",b:4,o:!0},{l:"DELETE",b:8,o:!0}],modules:{},models:{},defaultPermissions:{},icons:{expanded:"fa fa-caret-down",collapsed:"fa fa-caret-right"}},_create:function(){this.id=y;y+=
1;this.eventNamespace=".permissionEdit"},_init:function(){var a=d(this.element).attr("id");this.input=d("#"+a+"-input");this.tableWidth=this.options.useRealms?5:4;for(var b in l)l[b]=i18n[b]||l[b];this.refresh()},_destroy:function(){d.Widget.prototype.destroy.call(this)},refresh:function(){var a=d(this.element),b=this.options;this._unbindEvents();this._deserialize();var c=this._ruleSets(),e=d(".rm-rules",a).first(),f=this,k=c.pages,h=d(".rm-page-rules",a);this._renderExpandCollapseAll().appendTo(h);
Object.keys(b.modules).sort().forEach(function(g){b.modules[g][1]&&f._ruleTable("p",g,k[g]).appendTo(h)});k._other.length&&this._ruleTable("p","_other",k._other).appendTo(h);b.tRules&&(k=c.tables,h=d(".rm-table-rules",a),this._renderExpandCollapseAll().appendTo(h),Object.keys(b.models).sort().forEach(function(g){"_system"!=g&&f._ruleTable("t",g,k[g]).appendTo(h)}),this._ruleTable("t","_system",k._system).appendTo(h),k._other.length&&this._ruleTable("t","_other",k._other).appendTo(h));e.tabs().removeClass("hide").show();
this._bindEvents()},_deserialize:function(){try{this.rules=JSON.parse(this.input.val())}catch(a){this.rules=[],this._serialize()}},_serialize:function(){var a=this.rules.filter(function(b){return null!==b[0]&&(0!==b[0]||!b[7])});this.input.val(JSON.stringify(a)).change()},_ruleSets:function(){var a={_other:[]},b={_other:[]},c=this.options;this.rules.forEach(function(e){var f;if(f=e[3]){var k=b;var h=c.models;f=f.split("_")[0]}else{k=a;h=c.modules;f=e[1];var g=e[2];f="default"!=f||"table"!=g&&"tables"!=
g?f:"default/dt"}h.hasOwnProperty(f)?k[f]===u&&(k[f]=[]):f="_other";k[f].push(e)});return{pages:a,tables:b}},_renderExpandCollapseAll:function(){var a=d('<span class="action-lnk rm-expand-all">'),b=d('<span class="action-lnk rm-collapse-all">');a.text(l.rm_ExpandAll);b.text(l.rm_CollapseAll);return d('<div class="rm-toggle-all">').append(a).append(b)},_ruleTable:function(a,b,c){c||=[];var e=d('<table class="rm-module-rules">').data({module:b});e.append(this._ruleTableHeader(b)).append(this._ruleTableBody(a,
b,c)).append(this._ruleTableFooter(a,b,c));this._indicateNumRules(e,c.length);return e},_ruleTableHeader:function(a){var b=d('<thead class="rm-module-header">'),c=d("<th>").attr("colspan",this.tableWidth),e=this.options.icons;if(e){var f=d('<i class="'+e.expanded+'">').hide();e=d('<i class="'+e.collapsed+'">');d('<div class="rm-module-toggle">').append(f).append(e).appendTo(c)}switch(a){case "_system":f="SYSTEM";a=l.rm_SystemTables;break;case "_other":f="*";a=l.rm_Others;break;case "s3dt":f="S3DT";
a=l.rm_DynamicTables;break;default:f="default/dt"==a?"DEFAULT":a.toLocaleUpperCase(),a=this.options.modules.hasOwnProperty(a)?this.options.modules[a][0]:""}d('<div class="rm-module-prefix">').text(f).appendTo(c);d('<div class="rm-module-title">').text(a).appendTo(c);d('<div class="rm-module-numrules">').appendTo(c);d("<tr>").append(c).appendTo(b);return b},_ruleTableBody:function(a,b,c){var e=this.options,f=d("<tbody>").hide(),k=!0,h=c.map(w);if("t"==a){if(b=e.models[b])for(var g in b)b[g]&&-1==h.indexOf(g)&&
c.push([null,null,null,g,null,null,null,!1]);h=l.rm_Table;0===c.length&&(k=!1,f.append(this._defaultRule(!1)))}else{g="default/dt"==b;var n;for(n in e.defaultPermissions)if((a=g?"default/tables"==n||"default/table"==n:n.slice(0,b.length+1)==b+"/")&&-1==h.indexOf(n)){a=n.split("/");var r=a[1];if("*"==r)r=null;else if(!e.fRules)continue;c.push([null,a[0],r,null,null,null,null,!1])}h=l.rm_Page;0===c.length&&(k=!1,f.append(this._defaultRule(!0)))}b=d('<tr class="rm-rule-labels">').hide().appendTo(f);
b.append("<th>"+h+"</th>").append("<th>"+l.rm_AllRecords+"</th>").append("<th>"+l.rm_OwnedRecords+"</th>");e.useRealms&&d("<th>").text(l.rm_Scope).appendTo(b);b.append("<th></th>");if(k){b.show();c=c.sort(function(m,p){m=m.slice(1,4).join(" ");p=p.slice(1,4).join(" ");return m===p?0:m>p&&1||-1});var q=this;c.forEach(function(m){q._ruleTableRow(m).appendTo(f)})}return f},_ruleTableFooter:function(a,b,c){var e=d("<tfoot>").hide();if("_other"!=b){b=d('<tr class="rm-module-add">');var f=d("<td>").attr("colspan",
this.tableWidth);d('<span class="action-lnk rm-add-rule">').text(l.rm_AddRule).appendTo(f);"t"!=a&&!this.options.fRules&&c.length&&b.hide();b.append(f).appendTo(e)}return e},_ruleTableRow:function(a){var b=d('<tr class="rm-rule">').data({rule:a}),c=this.options,e=w(a);if(e)d('<td class="rm-rule-target">').text(e).appendTo(b);else{var f=this._targetSelector(a);d('<td class="rm-rule-target">').append(f).appendTo(b)}e&&null===a[0]?(b.addClass("rm-default-permissions"),a=this._defaultPermissions(e),a.oACL?
(d("<td>").text(a.uACL).appendTo(b),d("<td>").text(a.oACL).appendTo(b)):d("<td>").attr("colspan",2).text(a.uACL).appendTo(b),c.useRealms&&d("<td>").appendTo(b),c=d('<a class="rm-add-rule action-lnk">'),d("<td>").append(c.text(l.rm_AddRule)).appendTo(b)):(f=this._permissionSelector(a),b.append(f.uACL).append(f.oACL),c.useRealms&&d("<td>").append(this._scopeSelector(a)).appendTo(b),e?(c=d('<a class="rm-delete-rule delete-btn-ajax">'),d("<td>").append(c.text(l.rm_DeleteRule)).appendTo(b)):(c=d('<a class="rm-submit-rule action-btn">'),
a=d('<span class="rm-cancel-add action-lnk">'),d("<td>").append(c.text(l.rm_Add)).append(a.text(l.rm_Cancel)).appendTo(b)));return b},_targetSelector:function(a){var b=this.options,c=d("<div>"),e=a[1],f=function(m,p){p===u&&(p=m);return d('<option value="'+m+'">').text(p)},k=function(){return d('<option value="">').prop("selected",!0).prop("disabled",!0).hide()};if(a[3]){var h=b.models[e],g=d("<optgroup>").attr("label",l.rm_RestrictedTables),n=d("<optgroup>").attr("label",l.rm_UnrestrictedTables),
r=0,q=0;Object.keys(h).sort().forEach(function(m){h[m]?(r+=1,g.append(f(m))):(q+=1,n.append(f(m)))});a=d("<select>").append(k());r&&a.append(g);q&&a.append(n)}else"_other"==e?(a=d('<input type="text" size="20">'),a.data("pattern",/^(\w+)(\/(\*|[\w]+))?$/)):"default/dt"==e?(a=d("<select>"),a.append(k()).append(f("default/table")).append(f("default/tables"))):(c.append("<span>"+e+" / </span>"),a=d('<input type="text" size="10">'),a.data("pattern",/^(\w+|\*)$/));a.addClass("rm-target-select").appendTo(c);
return c},_validateTarget:function(a){var b=a.val(),c=a.data("pattern");c.lastIndex=0;if(b&&c&&!c.exec(b))return a.addClass("rm-invalid"),!1;a.removeClass("rm-invalid");return!0},_defaultPermissions:function(a){var b=this.options,c=b.defaultPermissions[a];a={};var e=" ("+l.rm_Default+")";if(c!==u){var f=c[0];c=c[1]&~f;var k=function(h){var g=[];b.permissions.forEach(function(n){h&n.b&&g.push(n.l)});return g.join(", ")};f&&(a.uACL=k(f)+e);c&&(a.oACL=k(c)+e)}a.uACL||(a.uACL=l.rm_NoAccess+e);return a},
_defaultRule:function(a){a=a?l.rm_NoAccess:l.rm_NoRestrictions;a=d("<td>").attr("colspan",this.tableWidth).text(a);return d('<tr class="rm-default-rule">').append(a)},_permissionSelector:function(a){var b=d('<td class="rm-permission-all">'),c=d('<td class="rm-permission-own">');this.options.permissions.forEach(function(e){var f=d('<input class="rm-permission" type="checkbox">'),k=d('<input class="rm-permission" type="checkbox">');d("<label>").append(f).append(e.l).appendTo(b);d("<label>").append(k).append(e.l).css({visibility:e.o&&
"visible"||"hidden"}).appendTo(c);var h=a[5]&e.b;k.prop("checked",h);k.data({bit:e.b,selected:h,implied:!1});h=a[4]&e.b;f.prop("checked",h);f.data({bit:e.b,selected:h,implied:!1});k.data("implied",h);h&&k.prop({checked:!0,disabled:!0});f.data("imply",k)});return{uACL:b,oACL:c}},_scopeSelector:function(a){var b=d('<select class="rm-scope-select">'),c=d('<option value="">').text(l.rm_AssignedEntities),e=d('<option value="any">').text(l.rm_AllEntities);if(a)switch(a[6]){case "any":e.prop("selected",
!0);break;default:c.prop("selected",!0),a[6]=null}b.append(c).append(e);return d("<div>").append(b)},_addRule:function(a){var b=this.options,c=a.closest(".rm-module-rules"),e=c.data("module"),f=b.models[e],k=this;d("tfoot .rm-rule",d(this.element)).each(function(){k._cancelAdd(d(this))});var h=a.closest(".rm-rule");if(h.length){var g=h.data("rule");g=(a=g[3])?[0,null,null,a,0,0,null,!1]:[0,g[1],g[2],null,0,0,null,!1];if(b=b.defaultPermissions[w(g)])g[4]=b[0],g[5]=b[1];this.rules.push(g);b=this._ruleTableRow(g);
h.after(b).remove();a&&(f[a]+=1);this._serialize()}else f=!0,a.closest(".rm-table-rules").length?g=[0,e,null,!0,0,0,null,!1]:b.fRules?g=[0,e,!0,null,0,0,null,!1]:d("tbody .rm-rule",c).length||(g=[0,e,null,null,0,0,null,!1],f=!1),g&&(b=this._ruleTableRow(g),f?a.closest(".rm-module-add").hide().after(b):(this.rules.push(g),d("tbody",c).append(b),a.closest(".rm-module-add").hide())),d(".rm-default-rule",c).hide(),d(".rm-rule-labels",c).show()},_submitAdd:function(a){var b=a.closest(".rm-module-rules"),
c=a.data("rule"),e=null,f=null,k=null,h=d(".rm-target-select",a).val().replace(/\s/,"");if(c[3]){if(k=h,!k)return}else{e=c[1];f=h;var g="_other"==e;if("default/dt"==e||g){if(h=/^(\w+)(\/(\*|[\w]+))?$/.exec(h))e=h[1],f=h[3];else return;if(g)for(g=d(".rm-module-rules",a.closest(".rm-page-rules")),h=g.length;h--;){var n=d(g[h]);if(n.data("module")==e){b=n;break}}}if(!f||"*"==f)f=null;else if(!/^\w+$/.exec(f))return}c[1]=e&&e.toLowerCase();c[2]=f&&f.toLowerCase();c[3]=k&&k.toLowerCase();var r,q,m;d("tbody .rm-rule",
b).each(function(){var p=d(this),t=p.data("rule");if(!r){a:{var v=null===c[0]||null===t[0]?[1,2,3]:[1,2,3,6];for(var z=v.length,x;z--;)if(x=v[z],c[x]!==t[x]){v=!1;break a}v=!0}v?(q=t,m=r=p):m||(k?t[3]>k&&(m=p):t[2]&&(f&&t[2]>f||!f)&&(m=p))}});if(q&&null!==q[0])q.splice(1,c.length-1),q.push.apply(q,c.slice(1)),c=q;else if(this.rules.push(c),e=c[3])g=this.options.models[b.data("module")],g[e]=g[e]!==u?g[e]+1:1;this._serialize();e=this._ruleTableRow(c);m?e.insertBefore(m):e.appendTo(d("tbody",b));r&&
r.remove();this._indicateNumRules(b,d("tbody .rm-rule",b).length);a.siblings(".rm-module-add").show();a.remove()},_cancelAdd:function(a){var b=a.closest(".rm-module-rules");0===d("tbody .rm-rule",b).length&&(d(".rm-rule-labels",b).hide(),d(".rm-default-rule",b).show());a.siblings(".rm-module-add").show();a.remove()},_updateRule:function(a,b){if(a=a.data("rule")){for(var c in b){var e=b[c];if(e!==u)switch(c){case "c":a[1]=e;break;case "f":a[2]=e;break;case "t":a[3]=e;break;case "uACL":a[4]=e;break;
case "oACL":a[5]=e;break;case "scope":a[6]=e;break;case "deleted":a[7]=!!e}}this._serialize()}},_deleteRule:function(a){if(confirm(l.rm_ConfirmDeleteRule)){var b=this.options,c=a.closest(".rm-module-rules"),e=!1,f=a.data("rule");f[7]=!0;this._serialize();var k=f[3];if(k){var h=this.rules.filter(function(g){return g[3]==k&&!g[7]});h.length||(h=c.data("module"),b=b.models[h],--b[k],0<b[k]&&(b=[null,null,null,k,null,null,null,!1],this._ruleTableRow(b).insertBefore(a)))}else h=this.rules.filter(function(g){return g[1]==
f[1]&&g[2]==f[2]&&!g[7]}),!h.length&&b.defaultPermissions[w(f)]&&(b=[null,f[1],f[2],null,null,null,null,!1],this._ruleTableRow(b).insertBefore(a)),e=!0;b=d(".rm-rule",c).length-1;b||(this._defaultRule(e).insertBefore(a),d(".rm-rule-labels",c).hide(),d(".rm-module-add",c).show());this._indicateNumRules(c,b);a.remove()}},_updatePermissions:function(a){this._updateRule(a,{uACL:this._getPermissions(d(".rm-permission-all",a)),oACL:this._getPermissions(d(".rm-permission-own",a))})},_getPermissions:function(a){var b=
0;d(".rm-permission",a).each(function(){var c=d(this);!c.data("implied")&&c.data("selected")&&(c=c.data("bit"))&&(b|=c)});return b},_indicateNumRules:function(a,b){var c=d(".rm-module-numrules",a);b?(c.text("["+b+"]"),a.addClass("hasrules")):(c.empty(),a.removeClass("hasrules"))},_toggleRuleTable:function(a){a.hasClass("rm-expanded")?(d("tbody, tfoot",a).hide(),a.removeClass("rm-expanded")):(d("tbody, tfoot",a).show(),a.addClass("rm-expanded"));d(".rm-module-toggle i",a).toggle()},_toggleAll:function(a,
b){var c=this;b?d(".rm-module-rules:not(.rm-expanded)",a).each(function(e,f){c._toggleRuleTable(d(f))}):d(".rm-module-rules.rm-expanded",a).each(function(e,f){c._toggleRuleTable(d(f))})},_permissionChanged:function(a){if(a.data("implied"))a.prop({checked:!0,disabled:!0});else if(a.prop("disabled"))a.prop({disabled:!1,checked:a.data("selected")});else{var b=a.prop("checked"),c=a.data("imply");a.data({selected:b});c&&c.length&&c.data("implied",b).change()}this._updatePermissions(a.closest(".rm-rule"))},
_scopeChanged:function(a){var b=a.closest(".rm-rule").data("rule");switch(a.val()){case "any":b[6]="any";break;default:b[6]=null}this._serialize()},_bindEvents:function(){var a=d(this.element),b=this.eventNamespace,c=this;d(".rm-table-rules, .rm-page-rules",a).on("click"+b,".rm-expand-all",function(){c._toggleAll(d(this).closest(".rm-table-rules, .rm-page-rules"),!0);return!1}).on("click"+b,".rm-collapse-all",function(){c._toggleAll(d(this).closest(".rm-table-rules, .rm-page-rules"),!1);return!1});
d(".rm-module-rules",a).on("click"+b,".rm-module-header",function(){c._toggleRuleTable(d(this).closest(".rm-module-rules"));return!1}).on("change"+b,".rm-permission",function(){c._permissionChanged(d(this));return!1}).on("change"+b,".rm-scope-select",function(){c._scopeChanged(d(this));return!1}).on("click"+b,".rm-delete-rule",function(){c._deleteRule(d(this).closest(".rm-rule"));return!1}).on("click"+b,".rm-add-rule",function(){c._addRule(d(this))}).on("click"+b,".rm-cancel-add",function(){c._cancelAdd(d(this).closest(".rm-rule"))}).on("click"+
b,".rm-submit-rule",function(){c._submitAdd(d(this).closest(".rm-rule"))}).on("input"+b,"input.rm-target-select",function(){c._validateTarget(d(this))});return!0},_unbindEvents:function(){var a=d(this.element),b=this.eventNamespace;d(".rm-module-rules, .rm-table-rules, .rm-page-rules",a).off(b);return!0}})})(jQuery);
