text: /*
   2018-2020 (c) Sahana Software Foundation
   @license MIT
  
   requires jQuery 1.9.1+
   requires jQuery UI 1.10 widget factory
  */
  var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.arrayIteratorImpl=function(a){var g=0;return function(){return g<a.length?{done:!1,value:a[g++]}:{done:!0}}};$jscomp.arrayIterator=function(a){return{next:$jscomp.arrayIteratorImpl(a)}};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;$jscomp.ISOLATE_POLYFILLS=!1;
  $jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,g,d){if(a==Array.prototype||a==Object.prototype)return a;a[g]=d.value;return a};$jscomp.getGlobal=function(a){a=["object"==typeof globalThis&&globalThis,a,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var g=0;g<a.length;++g){var d=a[g];if(d&&d.Math==Math)return d}throw Error("Cannot find global object");};$jscomp.global=$jscomp.getGlobal(this);
  $jscomp.IS_SYMBOL_NATIVE="function"===typeof Symbol&&"symbol"===typeof Symbol("x");$jscomp.TRUST_ES6_POLYFILLS=!$jscomp.ISOLATE_POLYFILLS||$jscomp.IS_SYMBOL_NATIVE;$jscomp.polyfills={};$jscomp.propertyToPolyfillSymbol={};$jscomp.POLYFILL_PREFIX="$jscp$";var $jscomp$lookupPolyfilledValue=function(a,g){var d=$jscomp.propertyToPolyfillSymbol[g];if(null==d)return a[g];d=a[d];return void 0!==d?d:a[g]};
  $jscomp.polyfill=function(a,g,d,k){g&&($jscomp.ISOLATE_POLYFILLS?$jscomp.polyfillIsolated(a,g,d,k):$jscomp.polyfillUnisolated(a,g,d,k))};$jscomp.polyfillUnisolated=function(a,g,d,k){d=$jscomp.global;a=a.split(".");for(k=0;k<a.length-1;k++){var l=a[k];l in d||(d[l]={});d=d[l]}a=a[a.length-1];k=d[a];g=g(k);g!=k&&null!=g&&$jscomp.defineProperty(d,a,{configurable:!0,writable:!0,value:g})};
  $jscomp.polyfillIsolated=function(a,g,d,k){var l=a.split(".");a=1===l.length;k=l[0];k=!a&&k in $jscomp.polyfills?$jscomp.polyfills:$jscomp.global;for(var b=0;b<l.length-1;b++){var c=l[b];c in k||(k[c]={});k=k[c]}l=l[l.length-1];d=$jscomp.IS_SYMBOL_NATIVE&&"es6"===d?k[l]:null;g=g(d);null!=g&&(a?$jscomp.defineProperty($jscomp.polyfills,l,{configurable:!0,writable:!0,value:g}):g!==d&&($jscomp.propertyToPolyfillSymbol[l]=$jscomp.IS_SYMBOL_NATIVE?$jscomp.global.Symbol(l):$jscomp.POLYFILL_PREFIX+l,l=$jscomp.propertyToPolyfillSymbol[l],
  $jscomp.defineProperty(k,l,{configurable:!0,writable:!0,value:g})))};$jscomp.initSymbol=function(){};
  $jscomp.polyfill("Symbol",function(a){if(a)return a;var g=function(a,b){this.$jscomp$symbol$id_=a;$jscomp.defineProperty(this,"description",{configurable:!0,writable:!0,value:b})};g.prototype.toString=function(){return this.$jscomp$symbol$id_};var d=0,k=function(a){if(this instanceof k)throw new TypeError("Symbol is not a constructor");return new g("jscomp_symbol_"+(a||"")+"_"+d++,a)};return k},"es6","es3");$jscomp.initSymbolIterator=function(){};
  $jscomp.polyfill("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var g="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),d=0;d<g.length;d++){var k=$jscomp.global[g[d]];"function"===typeof k&&"function"!=typeof k.prototype[a]&&$jscomp.defineProperty(k.prototype,a,{configurable:!0,writable:!0,value:function(){return $jscomp.iteratorPrototype($jscomp.arrayIteratorImpl(this))}})}return a},"es6",
  "es3");$jscomp.initSymbolAsyncIterator=function(){};$jscomp.iteratorPrototype=function(a){a={next:a};a[Symbol.iterator]=function(){return this};return a};$jscomp.iteratorFromArray=function(a,g){a instanceof String&&(a+="");var d=0,k={next:function(){if(d<a.length){var l=d++;return{value:g(l,a[l]),done:!1}}k.next=function(){return{done:!0,value:void 0}};return k.next()}};k[Symbol.iterator]=function(){return k};return k};
  $jscomp.polyfill("Array.prototype.keys",function(a){return a?a:function(){return $jscomp.iteratorFromArray(this,function(a){return a})}},"es6","es3");
  (function(a,g){var d={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"},k=function(a){var b,e=a[3];e?!0!==e&&(b=e):!0!==a[2]&&(b=a[1]+"/"+(a[2]||"*"));return b},l=0;a.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=l;l+=
  1;this.eventNamespace=".permissionEdit"},_init:function(){var b=a(this.element).attr("id");this.input=a("#"+b+"-input");this.tableWidth=this.options.useRealms?5:4;for(var c in d)d[c]=i18n[c]||d[c];this.refresh()},_destroy:function(){a.Widget.prototype.destroy.call(this)},refresh:function(){var b=a(this.element),c=this.options;this._unbindEvents();this._deserialize();var e=this._ruleSets(),h=a(".rm-rules",b).first(),f=this,d=e.pages,n=a(".rm-page-rules",b);this._renderExpandCollapseAll().appendTo(n);
  Object.keys(c.modules).sort().forEach(function(a){c.modules[a][1]&&f._ruleTable("p",a,d[a]).appendTo(n)});d._other.length&&this._ruleTable("p","_other",d._other).appendTo(n);c.tRules&&(d=e.tables,n=a(".rm-table-rules",b),this._renderExpandCollapseAll().appendTo(n),Object.keys(c.models).sort().forEach(function(a){"_system"!=a&&f._ruleTable("t",a,d[a]).appendTo(n)}),this._ruleTable("t","_system",d._system).appendTo(n),d._other.length&&this._ruleTable("t","_other",d._other).appendTo(n));h.tabs().removeClass("hide").show();
  this._bindEvents()},_deserialize:function(){try{this.rules=JSON.parse(this.input.val())}catch(b){this.rules=[],this._serialize()}},_serialize:function(){var a=this.rules.filter(function(a){return null!==a[0]&&(0!==a[0]||!a[7])});this.input.val(JSON.stringify(a)).change()},_ruleSets:function(){var a={_other:[]},c={_other:[]},e=this.options;this.rules.forEach(function(b){var f;if(f=b[3]){var h=c;var d=e.models;f=f.split("_")[0]}else{h=a;d=e.modules;f=b[1];var m=b[2];f="default"!=f||"table"!=m&&"tables"!=
  m?f:"default/dt"}d.hasOwnProperty(f)?h[f]===g&&(h[f]=[]):f="_other";h[f].push(b)});return{pages:a,tables:c}},_renderExpandCollapseAll:function(){var b=a('<span class="action-lnk rm-expand-all">'),c=a('<span class="action-lnk rm-collapse-all">');b.text(d.rm_ExpandAll);c.text(d.rm_CollapseAll);return a('<div class="rm-toggle-all">').append(b).append(c)},_ruleTable:function(b,c,e){e||(e=[]);var h=a('<table class="rm-module-rules">').data({module:c});h.append(this._ruleTableHeader(c)).append(this._ruleTableBody(b,
  c,e)).append(this._ruleTableFooter(b,c,e));this._indicateNumRules(h,e.length);return h},_ruleTableHeader:function(b){var c=a('<thead class="rm-module-header">'),e=a("<th>").attr("colspan",this.tableWidth),h=this.options.icons;if(h){var f=a('<i class="'+h.expanded+'">').hide();h=a('<i class="'+h.collapsed+'">');a('<div class="rm-module-toggle">').append(f).append(h).appendTo(e)}switch(b){case "_system":f="SYSTEM";b=d.rm_SystemTables;break;case "_other":f="*";b=d.rm_Others;break;case "s3dt":f="S3DT";
  b=d.rm_DynamicTables;break;default:f="default/dt"==b?"DEFAULT":b.toLocaleUpperCase(),b=this.options.modules.hasOwnProperty(b)?this.options.modules[b][0]:""}a('<div class="rm-module-prefix">').text(f).appendTo(e);a('<div class="rm-module-title">').text(b).appendTo(e);a('<div class="rm-module-numrules">').appendTo(e);a("<tr>").append(e).appendTo(c);return c},_ruleTableBody:function(b,c,e){var h=this.options,f=a("<tbody>").hide(),g=!0,n=e.map(k);if("t"==b){if(c=h.models[c])for(var m in c)c[m]&&-1==n.indexOf(m)&&
  e.push([null,null,null,m,null,null,null,!1]);n=d.rm_Table;0===e.length&&(g=!1,f.append(this._defaultRule(!1)))}else{m="default/dt"==c;var l;for(l in h.defaultPermissions)if((b=m?"default/tables"==l||"default/table"==l:l.slice(0,c.length+1)==c+"/")&&-1==n.indexOf(l)){b=l.split("/");var q=b[1];if("*"==q)q=null;else if(!h.fRules)continue;e.push([null,b[0],q,null,null,null,null,!1])}n=d.rm_Page;0===e.length&&(g=!1,f.append(this._defaultRule(!0)))}c=a('<tr class="rm-rule-labels">').hide().appendTo(f);
  c.append("<th>"+n+"</th>").append("<th>"+d.rm_AllRecords+"</th>").append("<th>"+d.rm_OwnedRecords+"</th>");h.useRealms&&a("<th>").text(d.rm_Scope).appendTo(c);c.append("<th></th>");if(g){c.show();e=e.sort(function(a,b){a=a.slice(1,4).join(" ");b=b.slice(1,4).join(" ");return a===b?0:a>b&&1||-1});var p=this;e.forEach(function(a){p._ruleTableRow(a).appendTo(f)})}return f},_ruleTableFooter:function(b,c,e){var h=a("<tfoot>").hide();if("_other"!=c){c=a('<tr class="rm-module-add">');var f=a("<td>").attr("colspan",
  this.tableWidth);a('<span class="action-lnk rm-add-rule">').text(d.rm_AddRule).appendTo(f);"t"!=b&&!this.options.fRules&&e.length&&c.hide();c.append(f).appendTo(h)}return h},_ruleTableRow:function(b){var c=a('<tr class="rm-rule">').data({rule:b}),e=this.options,h=k(b);if(h)a('<td class="rm-rule-target">').text(h).appendTo(c);else{var f=this._targetSelector(b);a('<td class="rm-rule-target">').append(f).appendTo(c)}h&&null===b[0]?(c.addClass("rm-default-permissions"),b=this._defaultPermissions(h),b.oACL?
  (a("<td>").text(b.uACL).appendTo(c),a("<td>").text(b.oACL).appendTo(c)):a("<td>").attr("colspan",2).text(b.uACL).appendTo(c),e.useRealms&&a("<td>").appendTo(c),e=a('<a class="rm-add-rule action-lnk">'),a("<td>").append(e.text(d.rm_AddRule)).appendTo(c)):(f=this._permissionSelector(b),c.append(f.uACL).append(f.oACL),e.useRealms&&a("<td>").append(this._scopeSelector(b)).appendTo(c),h?(e=a('<a class="rm-delete-rule delete-btn-ajax">'),a("<td>").append(e.text(d.rm_DeleteRule)).appendTo(c)):(e=a('<a class="rm-submit-rule action-btn">'),
  b=a('<span class="rm-cancel-add action-lnk">'),a("<td>").append(e.text(d.rm_Add)).append(b.text(d.rm_Cancel)).appendTo(c)));return c},_targetSelector:function(b){var c=this.options,e=a("<div>"),h=b[1],f=function(b,c){c===g&&(c=b);return a('<option value="'+b+'">').text(c)},k=function(){return a('<option value="">').prop("selected",!0).prop("disabled",!0).hide()};if(b[3]){var n=c.models[h],m=a("<optgroup>").attr("label",d.rm_RestrictedTables),l=a("<optgroup>").attr("label",d.rm_UnrestrictedTables),
  q=0,p=0;Object.keys(n).sort().forEach(function(a){n[a]?(q+=1,m.append(f(a))):(p+=1,l.append(f(a)))});b=a("<select>").append(k());q&&b.append(m);p&&b.append(l)}else"_other"==h?(b=a('<input type="text" size="20">'),b.data("pattern",/^(\w+)(\/(\*|[\w]+))?$/)):"default/dt"==h?(b=a("<select>"),b.append(k()).append(f("default/table")).append(f("default/tables"))):(e.append("<span>"+h+" / </span>"),b=a('<input type="text" size="10">'),b.data("pattern",/^(\w+|\*)$/));b.addClass("rm-target-select").appendTo(e);
  return e},_validateTarget:function(a){var b=a.val(),e=a.data("pattern");e.lastIndex=0;if(b&&e&&!e.exec(b))return a.addClass("rm-invalid"),!1;a.removeClass("rm-invalid");return!0},_defaultPermissions:function(a){var b=this.options,e=b.defaultPermissions[a];a={};var h=" ("+d.rm_Default+")";if(e!==g){var f=e[0];e=e[1]&~f;var k=function(a){var c=[];b.permissions.forEach(function(b){a&b.b&&c.push(b.l)});return c.join(", ")};f&&(a.uACL=k(f)+h);e&&(a.oACL=k(e)+h)}a.uACL||(a.uACL=d.rm_NoAccess+h);return a},
  _defaultRule:function(b){b=b?d.rm_NoAccess:d.rm_NoRestrictions;b=a("<td>").attr("colspan",this.tableWidth).text(b);return a('<tr class="rm-default-rule">').append(b)},_permissionSelector:function(b){var c=a('<td class="rm-permission-all">'),e=a('<td class="rm-permission-own">');this.options.permissions.forEach(function(h){var f=a('<input class="rm-permission" type="checkbox">'),d=a('<input class="rm-permission" type="checkbox">');a("<label>").append(f).append(h.l).appendTo(c);a("<label>").append(d).append(h.l).css({visibility:h.o&&
  "visible"||"hidden"}).appendTo(e);var g=b[5]&h.b;d.prop("checked",g);d.data({bit:h.b,selected:g,implied:!1});g=b[4]&h.b;f.prop("checked",g);f.data({bit:h.b,selected:g,implied:!1});d.data("implied",g);g&&d.prop({checked:!0,disabled:!0});f.data("imply",d)});return{uACL:c,oACL:e}},_scopeSelector:function(b){var c=a('<select class="rm-scope-select">'),e=a('<option value="">').text(d.rm_AssignedEntities),h=a('<option value="any">').text(d.rm_AllEntities);if(b)switch(b[6]){case "any":h.prop("selected",
  !0);break;default:e.prop("selected",!0),b[6]=null}c.append(e).append(h);return a("<div>").append(c)},_addRule:function(b){var c=this.options,e=b.closest(".rm-module-rules"),h=e.data("module"),d=c.models[h],g=this;a("tfoot .rm-rule",a(this.element)).each(function(){g._cancelAdd(a(this))});var n=b.closest(".rm-rule");if(n.length){var m=n.data("rule");m=(b=m[3])?[0,null,null,b,0,0,null,!1]:[0,m[1],m[2],null,0,0,null,!1];if(c=c.defaultPermissions[k(m)])m[4]=c[0],m[5]=c[1];this.rules.push(m);c=this._ruleTableRow(m);
  n.after(c).remove();b&&(d[b]+=1);this._serialize()}else d=!0,b.closest(".rm-table-rules").length?m=[0,h,null,!0,0,0,null,!1]:c.fRules?m=[0,h,!0,null,0,0,null,!1]:a("tbody .rm-rule",e).length||(m=[0,h,null,null,0,0,null,!1],d=!1),m&&(c=this._ruleTableRow(m),d?b.closest(".rm-module-add").hide().after(c):(this.rules.push(m),a("tbody",e).append(c),b.closest(".rm-module-add").hide())),a(".rm-default-rule",e).hide(),a(".rm-rule-labels",e).show()},_submitAdd:function(b){var c=b.closest(".rm-module-rules"),
  e=b.data("rule"),d=null,f=null,k=null,n=a(".rm-target-select",b).val().replace(/\s/,"");if(e[3]){if(k=n,!k)return}else{d=e[1];f=n;var m="_other"==d;if("default/dt"==d||m){if(n=/^(\w+)(\/(\*|[\w]+))?$/.exec(n))d=n[1],f=n[3];else return;if(m)for(m=a(".rm-module-rules",b.closest(".rm-page-rules")),n=m.length;n--;){var l=a(m[n]);if(l.data("module")==d){c=l;break}}}if(!f||"*"==f)f=null;else if(!/^\w+$/.exec(f))return}e[1]=d&&d.toLowerCase();e[2]=f&&f.toLowerCase();e[3]=k&&k.toLowerCase();var q,p,r;a("tbody .rm-rule",
  c).each(function(){var b=a(this),c=b.data("rule");if(!q){a:{var d=null===e[0]||null===c[0]?[1,2,3]:[1,2,3,6];for(var h=d.length,g;h--;)if(g=d[h],e[g]!==c[g]){d=!1;break a}d=!0}d?(p=c,r=q=b):r||(k?c[3]>k&&(r=b):c[2]&&(f&&c[2]>f||!f)&&(r=b))}});if(p&&null!==p[0])p.splice(1,e.length-1),p.push.apply(p,e.slice(1)),e=p;else if(this.rules.push(e),d=e[3])m=this.options.models[c.data("module")],m[d]=m[d]!==g?m[d]+1:1;this._serialize();d=this._ruleTableRow(e);r?d.insertBefore(r):d.appendTo(a("tbody",c));q&&
  q.remove();this._indicateNumRules(c,a("tbody .rm-rule",c).length);b.siblings(".rm-module-add").show();b.remove()},_cancelAdd:function(b){var c=b.closest(".rm-module-rules");0===a("tbody .rm-rule",c).length&&(a(".rm-rule-labels",c).hide(),a(".rm-default-rule",c).show());b.siblings(".rm-module-add").show();b.remove()},_updateRule:function(a,c){if(a=a.data("rule")){for(var b in c){var d=c[b];if(d!==g)switch(b){case "c":a[1]=d;break;case "f":a[2]=d;break;case "t":a[3]=d;break;case "uACL":a[4]=d;break;
  case "oACL":a[5]=d;break;case "scope":a[6]=d;break;case "deleted":a[7]=!!d}}this._serialize()}},_deleteRule:function(b){if(confirm(d.rm_ConfirmDeleteRule)){var c=this.options,e=b.closest(".rm-module-rules"),h=!1,f=b.data("rule");f[7]=!0;this._serialize();var g=f[3];if(g){var l=this.rules.filter(function(a){return a[3]==g&&!a[7]});l.length||(l=e.data("module"),c=c.models[l],--c[g],0<c[g]&&(c=[null,null,null,g,null,null,null,!1],this._ruleTableRow(c).insertBefore(b)))}else l=this.rules.filter(function(a){return a[1]==
  f[1]&&a[2]==f[2]&&!a[7]}),!l.length&&c.defaultPermissions[k(f)]&&(c=[null,f[1],f[2],null,null,null,null,!1],this._ruleTableRow(c).insertBefore(b)),h=!0;c=a(".rm-rule",e).length-1;c||(this._defaultRule(h).insertBefore(b),a(".rm-rule-labels",e).hide(),a(".rm-module-add",e).show());this._indicateNumRules(e,c);b.remove()}},_updatePermissions:function(b){this._updateRule(b,{uACL:this._getPermissions(a(".rm-permission-all",b)),oACL:this._getPermissions(a(".rm-permission-own",b))})},_getPermissions:function(b){var c=
  0;a(".rm-permission",b).each(function(){var b=a(this);!b.data("implied")&&b.data("selected")&&(b=b.data("bit"))&&(c|=b)});return c},_indicateNumRules:function(b,c){var d=a(".rm-module-numrules",b);c?(d.text("["+c+"]"),b.addClass("hasrules")):(d.empty(),b.removeClass("hasrules"))},_toggleRuleTable:function(b){b.hasClass("rm-expanded")?(a("tbody, tfoot",b).hide(),b.removeClass("rm-expanded")):(a("tbody, tfoot",b).show(),b.addClass("rm-expanded"));a(".rm-module-toggle i",b).toggle()},_toggleAll:function(b,
  c){var d=this;c?a(".rm-module-rules:not(.rm-expanded)",b).each(function(b,c){d._toggleRuleTable(a(c))}):a(".rm-module-rules.rm-expanded",b).each(function(b,c){d._toggleRuleTable(a(c))})},_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"),d=a.data("imply");a.data({selected:b});d&&d.length&&d.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 b=a(this.element),c=this.eventNamespace,d=this;a(".rm-table-rules, .rm-page-rules",b).on("click"+c,".rm-expand-all",function(){d._toggleAll(a(this).closest(".rm-table-rules, .rm-page-rules"),!0);return!1}).on("click"+c,".rm-collapse-all",function(){d._toggleAll(a(this).closest(".rm-table-rules, .rm-page-rules"),!1);return!1});
  a(".rm-module-rules",b).on("click"+c,".rm-module-header",function(){d._toggleRuleTable(a(this).closest(".rm-module-rules"));return!1}).on("change"+c,".rm-permission",function(){d._permissionChanged(a(this));return!1}).on("change"+c,".rm-scope-select",function(){d._scopeChanged(a(this));return!1}).on("click"+c,".rm-delete-rule",function(){d._deleteRule(a(this).closest(".rm-rule"));return!1}).on("click"+c,".rm-add-rule",function(){d._addRule(a(this))}).on("click"+c,".rm-cancel-add",function(){d._cancelAdd(a(this).closest(".rm-rule"))}).on("click"+
  c,".rm-submit-rule",function(){d._submitAdd(a(this).closest(".rm-rule"))}).on("input"+c,"input.rm-target-select",function(){d._validateTarget(a(this))});return!0},_unbindEvents:function(){var b=a(this.element),c=this.eventNamespace;a(".rm-module-rules, .rm-table-rules, .rm-page-rules",b).off(c);return!0}})})(jQuery);
  