zazzy-browser
Advanced tools
Comparing version 0.2.18 to 0.2.19
//! zzb.js | ||
//! version: 0.2.18 | ||
//! version: 0.2.19 | ||
//! author(s): Jaret Pfluger | ||
@@ -617,2 +617,62 @@ //! license: MIT | ||
_perms.prototype.hasMatch = function (permkey, target) { | ||
if (!permkey || !target) { | ||
return false | ||
} | ||
var po = permkey | ||
if (zzb.types.isNonEmptyString(permkey)) { | ||
po = this.getPermObject(permkey) | ||
} | ||
if (!zzb.types.isObject(po) || !po.key || !po.perm || po.perm.length === 0) { | ||
return false | ||
} | ||
var tp = null | ||
if (zzb.types.isNonEmptyString(target)) { | ||
tp = this.getPermObject(target) | ||
} else if (Array.isArray(target)) { | ||
var self = this | ||
_.each(target, function (item) { | ||
if (zzb.types.isNonEmptyString(item)) { | ||
item = self.getPermObject(item) | ||
} | ||
if (item.key === po.key) { | ||
tp = item | ||
return false | ||
} | ||
}) | ||
} else { | ||
if (!zzb.types.isObject(target)) { | ||
return false | ||
} | ||
if (target.key) { | ||
tp = target | ||
} else { | ||
if (!target[po.key]) { | ||
return false | ||
} else { | ||
if (zzb.types.isNonEmptyString(target[po.key])) { | ||
tp = this.getPermObject(po.key + ':' + target[po.key]) | ||
} else { | ||
tp = target[po.key] | ||
} | ||
} | ||
} | ||
} | ||
if (!tp || !tp.key || !tp.perm || !tp.perm.length === 0) { | ||
return false | ||
} | ||
for (var ii = 0; ii < tp.perm.length; ii++) { | ||
if (po.perm.indexOf(tp.perm[ii]) >= 0) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
exports.perms = _perms | ||
@@ -619,0 +679,0 @@ |
//! zzb.js | ||
//! version: 0.2.18 | ||
//! version: 0.2.19 | ||
//! author(s): Jaret Pfluger | ||
//! license: MIT | ||
//! https://github.com/jpfluger/zazzy-browser | ||
!function t(e,r,n){function s(o,a){if(!r[o]){if(!e[o]){var l="function"==typeof require&&require;if(!a&&l)return l(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var c=r[o]={exports:{}};e[o][0].call(c.exports,function(t){var r=e[o][1][t];return s(r||t)},c,c.exports,t,e,r,n)}return r[o].exports}for(var i="function"==typeof require&&require,o=0;o<n.length;o++)s(n[o]);return s}({1:[function(t,e,r){function n(){this.ajax=function(t){return new Promise(function(e,r){s.ajax(t).done(function(n,s,i){if(t.RAWRETURN)return e(n);if(!n)return r(new Error("Data returned is empty when at minimum a status is required"));var o=zzb.rob.newROB();if(i.responseJSON){if(n.redirect&&n.redirect.length>0)return void(window.location.href=n.redirect);n.ISROBERRORS||(n.err?(n.errs=zzb.rob.sanitizeErrors(n.err),n.err=null):n.error?(n.error=zzb.rob.sanitizeErrors(n.error),n.error=null):n.errs&&(n.errs=zzb.rob.sanitizeErrors(n.errs),n.err=null)),n.ISROBRECS||(n.recs?n.recs=zzb.rob.sanitizeRecords(n.rec):n.rec?(n.recs=zzb.rob.sanitizeRecords(n.rec),n.rec=null):n.recs=zzb.rob.sanitizeRecords(n)),o.errs=n.errs,o.recs=n.recs,o.fields=n.fields}else o.recs=[n];e(n)}).fail(function(t,e,n){r(n),console.log(n)})})}}var s=window.$;n.prototype.get=function(t){return t.type="GET",t.contentType="application/json; charset=UTF-8",t.data=JSON.stringify(t.data),this.ajax(t)},n.prototype.getJSON=function(t){return t.type="GET",t.dataType="json",t.contentType="application/json; charset=UTF-8",t.data=JSON.stringify(t.data),this.ajax(t)},n.prototype.postJSON=function(t){return t.type="POST",t.dataType="json",t.contentType="application/json; charset=UTF-8",t.data=JSON.stringify(t.data),this.ajax(t)},r.ajax=n},{}],2:[function(t,e,r){var n=window.BootstrapDialog,s=window._,i=function(){};i.prototype.showMessage=function(t){t=s.merge({type:n.TYPE_DEFAULT,title:"",message:"",buttonCloseName:"Ok",onShown:null},t),n.show({type:t.type,title:t.title,message:t.message,onshown:t.onShown,buttons:[{label:t.buttonCloseName,action:function(t){t.close()}}]})},i.prototype.showMessageChoice=function(t){(t=s.merge({type:n.TYPE_DEFAULT,title:"",message:"",cssClass:"",buttonLeftName:"Cancel",buttonRightName:"Accept",buttonLeftCssClass:"",buttonRightCssClass:"",buttonLeftIcon:"",buttonRightIcon:"",onShown:null,onButtonLeftClick:null,onButtonRightClick:null,noButtons:!1,buttons:[]},t)).noButtons||(t.buttons=[{label:t.buttonLeftName,cssClass:t.buttonLeftCssClass,icon:t.buttonLeftIcon,action:function(e){t.onButtonLeftClick?t.onButtonLeftClick(function(t){t||e.close()}):e.close()}},{label:t.buttonRightName,cssClass:t.buttonRightCssClass,icon:t.buttonRightIcon,action:function(e){t.onButtonRightClick?t.onButtonRightClick(function(t){t||e.close()}):e.close()}}]),n.show({type:t.type,title:t.title,message:t.message,cssClass:t.cssClass,onshown:t.onShown,buttons:t.buttons})},i.prototype.handleError=function(t){if((t=s.merge({log:null,title:"",message:null,errs:null},t)).log&&console.log(t.log),t.errs&&Array.isArray(t.errs)&&t.errs.length>0&&t.errs[0]){var e=[];s.each(t.errs,function(t,r){t.message&&zzb.types.isNonEmptyString(t.message)&&e.push(zzb.strings.format("<div>{0}</div>",t.message))}),e.length>0&&(t.message||(t.message=""),t.errIntro&&(t.message+=" "+t.errIntro),t.message+=" "+e.join(""))}t.message&&this.showMessage({type:n.TYPE_DANGER,title:t.title,message:t.message})},r.dialogs=i},{}],3:[function(t,e,r){var n=window.$,s=window._,i=function(){},o=function(t,e){var r=[],n=[];if(!t||0===t.length||!t[0]){if(e.hideWhenNoError)return{html:null,contentPopOver:null};t=[{type:"success",message:null}]}return s.each(t,function(t,s){if(t.field||(t.field="_system"),"_system"===t.field)r.push(zzb.strings.format("<div>{0}</div>",t.message));else{var i=e.typeFormats.error;t.type&&e.typeFormats[t.type]&&(i=e.typeFormats[t.type]),0===s&&r.push(zzb.strings.format('<span class="glyphicon {0} {1}"></span>',i.glyph,i.textClass)),t.message&&zzb.types.isNonEmptyString(t.message)&&n.push(t.message)}}),{html:r.join(" "),contentPopOver:n.join(" ")}},a=function(t){t.$elem&&t.$elem.length>0&&t&&t.contentPopOver&&zzb.types.isNonEmptyString(t.contentPopOver)&&t.$elem.popover({trigger:"hover",animation:!1,content:t.contentPopOver})};i.prototype.displayUIErrors=function(t,e){if((t=s.merge({selector:null,$form:null,selectorField:".zzb-form-field",attrFieldname:"zzb-fieldname",selectorError:".zzb-form-field-error",errs:null,err:null,hideWhenNoError:!1,typeFormats:{error:{glyph:"glyphicon-remove",textClass:"text-danger",bgClass:null},warning:{glyph:"glyphicon-warning",textClass:"text-warning",bgClass:null},success:{glyph:"glyphicon-ok",textClass:"text-success",bgClass:null},default:null},renderErrorHtml:o,afterHtmlAdded:a,handleSystemErrors:null},t)).renderErrorHtml){if(t.$form?t.selector=null:t.selector&&(t.$form=n("selector")),!t.$form||0===t.$form.length)return e&&e(!1);t.err&&!Array.isArray(t.err)?(t.errs=[zzb.rob.createError(t.err)],t.err=null):t.errs&&!Array.isArray(t.errs)&&(t.errs=[zzb.rob.createError(t.errs)],t.err=null);var r=zzb.rob.toObject(t.errs),i=!1;t.$form.find(t.selectorError).each(function(e,s){var o=n(s),a=o.closest(t.selectorField);if(0===a.length)return console.log("discovered an error field but could not determine the field to which it belongs (eg zzb-form-field)"),!0;var l=a.attr(t.attrFieldname);if(zzb.types.isEmptyString(l))return console.log('discovered an error field and its parent field (eg zzb-form-field) but the fieldname attribute is empty (eg zzb-fieldname="")'),!0;"_system"===l&&(i=!0);var u=t.renderErrorHtml(r[l],t);o.html(u.html),u.html&&zzb.types.isNonEmptyString(u.html)?o.removeClass("hidden"):o.addClass("hidden"),u.fieldname=l,u.$elem=o,t.afterHtmlAdded&&t.afterHtmlAdded(u)})}!i&&r._system&&r._system.length>0&&r._system[0]&&(t.handleSystemErrors?t.handleSystemErrors(r._system,t):zzb.dialogs.handleError({errs:r._system})),e&&e(!1)},r.forms=i},{}],4:[function(t,e,r){var n=window._,s=function(){};s.prototype.getPO=function(t,e){var r=t[e];return r||this.getPermObject(e+":")},s.prototype.getPermObjectFromPermkeys=function(t){var e={},r=this;return Array.isArray(t)?n.each(t,function(t){var n=r.getPermObject(t);n.key&&(e[n.key]=n)}):zzb.types.isObject(t)&&n.forOwn(t,function(t,n){t||(t="");var s=null;(s=t.indexOf(":")<0?r.getPermObject(n+":"+t):r.getPermObject(t))&&s.key&&(e[s.key]=s)}),e},s.prototype.getPermObject=function(t,e){var r={key:null,perm:null,attr:{},toPermkey:function(){return this.key+":"+this.perm}};if(!t||!zzb.types.isNonEmptyString(t))return r.attr=this.getPermAttributes(),r;if(t.indexOf(":")<=0)return r.key=t,r.perm="",r.attr=this.getPermAttributes(),r;var n=t.split(":");if(r.key=n[0],r.perm=n[1],r.perm=r.perm.trim().toUpperCase(),r.perm.length>0&&e&&zzb.types.isNonEmptyString(e)){e=e.trim().toUpperCase();for(var s=r.perm.length-1;s>=0;s--)e.indexOf(r.perm[s])<0&&(r.perm=r.perm.replace(r.perm[s],""))}return r.attr=this.getPermAttributes(r.toPermkey(),e),r};var i=new RegExp("^[CRUDX]*$");s.prototype.getPermAttributes=function(t){var e={canRead:!1,canCreate:!1,canUpdate:!1,canDelete:!1,canExecute:!1};return t&&zzb.types.isNonEmptyString(t)?(t.indexOf(":")>=0&&(t=t.split(":")[1]),0===(t=t.trim().toUpperCase()).length?e:i.test(t)?(e.canRead=t.indexOf("C")>=0,e.canCreate=t.indexOf("R")>=0,e.canUpdate=t.indexOf("U")>=0,e.canDelete=t.indexOf("D")>=0,e.canExecute=t.indexOf("X")>=0,e):e):e},r.perms=s},{}],5:[function(t,e,r){function n(t){if((t=s.merge({type:"error",message:null,field:"_system",stack:null,isErr:!0},t)).isErr)switch(t.type){case"warning":case"notice":case"info":case"debug":t.isErr=!1;break;default:t.isErr=!0}return t}var s=window._,i=function(){};i.prototype.newROB=function(t){return s.merge({errs:null,recs:[],fields:[],hasErrors:function(){return this.errs&&Array.isArray(this.errs)&&this.errs.length>0},hasFields:function(){return this.fields&&Array.isArray(this.fields)&&this.fields.length>0},hasRecords:function(){return this.recs&&Array.isArray(this.recs)&&this.recs.length>0},isEmpty:function(){return!this.hasRecords()||this.hasRecords()&&null===this.first()},first:function(){return this.recs&&Array.isArray(this.recs)&&this.recs.length>0?this.recs[0]:null},find:function(t,e){var r=null;return s.each(this.recs,function(n){if(n&&zzb.types.isObject(n)&&!Array.isArray(n)&&n[t]===e)return r=n,!1}),r},length:function(){return this.recs&&Array.isArray(this.recs)?this.recs.length:0}},t)},i.prototype.toObject=function(t){if(!t||!Array.isArray(t))return{_system:[t]};var e={};return s.each(t,function(t){t&&(t.field||(t.field="_system"),e[t.field]||(e[t.field]=[]),e[t.field].push(t))}),e};var o=function(t,e){if(!t)return n();if(zzb.types.isNonEmptyString(t))return n(s.merge({message:t},e));if(!Array.isArray(t)&&zzb.types.isObject(t))return n(t);throw new Error("bad input in createError - unrecognized err datatype")};i.prototype.createError=o,i.prototype.sanitizeErrors=function(t){var e=null;return t?(Array.isArray(t)?t.length>0&&(e=[],s.each(t,function(t){e.push(o(t))})):e=[o(t)],e):e},i.prototype.sanitizeRecords=function(t){return t?Array.isArray(t)?t:[t]:[]},i.prototype.toListErrs=function(t,e,r,n){function i(t){return n?zzb.strings.format(n,t.message):"html"===e?zzb.strings.format("<li>{0}</li>",t.message):zzb.strings.format("System: {0}",t.message)}function o(t){var n=t.title;return t.title||(n=t.field),r?zzb.strings.format(r,n,t.message):"html"===e?zzb.strings.format("<li><strong>{0}</strong>: {1}</li>",n,t.message):zzb.strings.format("{0}: {1}",n,t.message)}var a=[],l=[];return e=e||"text",t&&Array.isArray(t)&&t.length>0&&s.each(t,function(t){"_system"===t.system?l.push(i(t)):t.field?l.push(o(t)):l.push(i(t))}),{system:l,fields:a,hasSystemErrors:function(){return this.system&&this.system.length>0},hasFieldErrors:function(){return this.fields&&this.fields.length>0},combined:function(){return this.system.concat(this.fields)},hasErrors:function(){return this.hasSystemErrors()&&this.hasFieldErrors()}}},r.rob=i},{}],6:[function(t,e,r){var n=window.$,s=window._,i=function(){this.zzbStatus=null};i.prototype.get=function(t,e){var r=(t=s.merge({path:window.location.path,role:null})).path===window.location.path&&!t.role;if(r){if(this.zzbStatus)return e&&e(null,this.zzbStatus);var i=null;if("undefined"!=typeof Storage&&sessionStorage.zzbStatus){try{i=JSON.parse(sessionStorage.getItem("zzbStatus"))}catch(t){console.log("unable to parse zzbStatus from sessionStorage: "+t)}if(sessionStorage.setItem("zzbStatus",null),i)return this.zzbStatus=i,e&&e(null,this.zzbStatus)}if(n("#zzbStatus").length>0&&zzb.types.isNonEmptyString(n("#zzbStatus").attr("status"))){try{i=JSON.parse(n("#zzbStatus").attr("status"))}catch(t){console.log("unable to parse zzbStatus from embedded attribute in #zzbStatus: "+t)}if(i)return this.zzbStatus=i,e&&e(null,this.zzbStatus)}}i={user:{isLoggedIn:!1,username:null},page:{path:window.location.pathname}};var o=this;zzb.ajax.postJSON({url:"/zzb/status",data:t}).then(function(t){t.errs?e&&e(t.errs,i):(r&&(o.zzbStatus=t.one()),e&&e(null,t.one()))}).catch(function(t){console.log("failed to retrieve zzbStatus: using defaults"),e&&e(zzb.types.sanitizeErrors(t),i)})},r.status=i},{}],7:[function(t,e,r){var n=window._,s=function(){},i=function(t){var e=new Error(t);return e.name="ValueError",e},o=function(t,e){return null==e?t:e},a=function(t,e){/^\d+$/.test(e[0])||(e=["0"].concat(e));for(var r=0;r<e.length;r+=1){var n=e[r];t="function"==typeof t[n]?t[n]():t[n]}return t};s.prototype.format=function(t){return function(e){var r=Array.prototype.slice.call(arguments,1),n=0,s="UNDEFINED";if(Array.isArray(r)&&r.length>0&&Array.isArray(r[0])){var l=r[0].map(function(t){return t});r=l}return e.replace(/([{}])\1|[{](.*?)(?:!(.+?))?[}]/g,function(e,l,u,c){if(null!=l)return l;if(u.length>0){if("IMPLICIT"===s)throw i("cannot switch from implicit to explicit numbering");s="EXPLICIT"}else{if("EXPLICIT"===s)throw i("cannot switch from explicit to implicit numbering");s="IMPLICIT",u=String(n),n+=1}var p=o("",a(r,u.split(".")));if(null==c)return p;if(Object.prototype.hasOwnProperty.call(t,c))return t[c](p);throw i('no transformer named "'+c+'"')})}}({}),s.prototype.formatEmpty=function(t){var e=Array.prototype.slice.call(arguments,1);return Array.isArray(e)?t.replace(/{(\d+)}/g,function(t,r){return void 0!==e[r]?e[r]:""}):t.replace(/{((?:(?=([^{}]+|{{[^}]*}}))\2)*)}/g,function(t,r){return e.length>0&&e[0][r]?e[0][r]:""})},s.prototype.appendIfMoreThan=function(t,e,r){return t&&t.length>r?t.substring(0,r)+e:t},s.prototype.joinArrToCommas=function(t,e){return t&&Array.isArray(t)&&0!==t.length?t.map(t,function(r,n){var s="";return n<t.index-1&&(s=""),e?r[e]+s:r+s}).join(""):""},s.prototype.toPlural=function(t,e,r){return r=n.merge({forcePlural:!1,suffix:null},r),1!==e&&-1!==e||r.forcePlural?r.suffix?t+r.suffix:t+"s":t},r.strings=s},{}],8:[function(t,e,r){function n(){}n.prototype.escapeJqueryId=function(t,e){return(e=null==e?"#":e)+t.replace(/(:|\.|\[|\]|,)/g,"\\$1")},n.prototype.escapeHtml=function(t){return t?t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"):""},n.prototype.isArray=function(t){return t&&void 0!==t&&"[object Array]"===Object.prototype.toString.call(t)},n.prototype.isArrayHasRecords=function(t){return this.isArray(t)&&t.length>0},n.prototype.isObject=function(t){return t&&"object"==typeof t},n.prototype.isNumber=function(t){return!isNaN(t-0)&&null!==t&&""!==t&&!1!==t},n.prototype.isNonEmptyString=function(t){return t&&"string"==typeof t&&t.trim().length>0},n.prototype.isEmptyString=function(t){return t&&"string"==typeof t&&0===t.trim().length},n.prototype.isString=function(t){return t&&"string"==typeof t},n.prototype.isFunction=function(t){var e={};return t&&"[object Function]"===e.toString.call(t)},n.prototype.compare=function(t,e,r){return t===e?0:r?t>e?-1:1:t>e?1:-1},r.types=n},{}],9:[function(t,e,r){var n=window._,s=function(){};s.prototype.createPanelGroup=function(t){t=n.merge({id:zzb.uuid.newV4(),classPanelGroup:"",innerHtml:""},t);return zzb.strings.format('<div id="panelGroup_{id}" class="panel-group {classPanelGroup}">{innerHtml}</div>',t)},s.prototype.createPanelBody=function(t){t=n.merge({id:zzb.uuid.newV4(),classPanelBody:"",innerHtml:""},t);return zzb.strings.format('<div id="panelBody_{id}" class="panel-body {classPanelBody}">{innerHtml}</div>',t)},s.prototype.createPanel=function(t){t=n.merge({id:zzb.uuid.newV4(),className:"",attributesExtra:"",classPanelHeading:"",name:"",classPanelBody:"",innerHtml:""},t);var e='<div id="panel_{id}" class="panel panel-default {className}" {attributesExtra}><div class="panel-heading {classPanelHeading}>">{name}</div><div id="panelBody_{id}" class="panel-body {classPanelBody}">'+this.createPanelBody(t)+"</div></div>";return zzb.strings.format(e,t)},s.prototype.createPanelCollapsible=function(t){(t=n.merge({id:zzb.uuid.newV4(),className:"",attributesExtra:"",name:"",classPanelBody:"",innerHtml:"",isPanelCollapsed:!1,classNamePanelCollapsed:"",titleHtmlExtra:"",titleHtmlExtraRight:""},t)).isPanelCollapsed?(t._panelCollapsedClass1="collapsed",t._panelCollapsedClass2=""):(t._panelCollapsedClass1="",t._panelCollapsedClass2="in");var e='<div id="panel_{id}" class="panel panel-default {className}" {attributesExtra}><div class="panel-heading"><h4 class="panel-title">{titleHtmlExtra}<a data-toggle="collapse" data-target="#panelCollapse_{id}" href="#panelCollapse_{id}" class="{_panelCollapsedClass1}{classNamePanelCollapsed}">{name}</a> {titleHtmlExtraRight}</h4></div><div id="panelCollapse_{id}" class="panel-collapse collapse {_panelCollapsedClass2}">'+this.createPanelBody(t)+"</div></div>";return zzb.strings.format(e,t)},s.prototype.createPanelCollapsibleBegin=function(t){(t=n.merge({id:zzb.uuid.newV4(),className:"",attributesExtra:"",name:"",classPanelBody:"",innerHtml:"",isPanelCollapsed:!1,classNamePanelCollapsed:"",titleHtmlExtra:"",titleHtmlExtraRight:""},t)).isPanelCollapsed?(t._panelCollapsedClass1="collapsed",t._panelCollapsedClass2=""):(t._panelCollapsedClass1="",t._panelCollapsedClass2="in");return zzb.strings.format('<div class="panel panel-default {className}" id="panel_{id}" {attributesExtra}><div class="panel-heading"><h4 class="panel-title">{titleHtmlExtra}<a data-toggle="collapse" data-target="#panelCollapse_{id}" href="#panelCollapse_{id}" class="{_panelCollapsedClass1}{classNamePanelCollapsed}">{name}</a> {titleHtmlExtraRight}</h4></div><div id="panelCollapse_{id}" class="panel-collapse collapse {_panelCollapsedClass2}"><div class="panel-body" id="panelBody_{id}">',t)},s.prototype.createPanelCollapsibleEnd=function(){return"</div></div></div>"},r.uib=s},{}],10:[function(t,e,r){var n=window._,s=function(){};s.prototype.newV4=function(){var t=n.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var r=(t+n.random(16))%16|0;return t=Math.floor(t/16),("x"===e?r:3&r|8).toString(16)})},s.prototype.isV4=function(t){return/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(t)},s.prototype.isValid=function(t){return/^([a-f\d]{8}(-[a-f\d]{4}){3}-[a-f\d]{12}?)$/i.test(t)},r.uuid=s},{}],11:[function(t,e,r){function n(t,e,r,n){return new s(t,e,r,n)}function s(t,e,r,s){this.parent=t,this.data=e,this.pkField=r,this.parentField=s,this.nodeConstructor=n,this.nodeItemConstructor=n,this.isDirty=!1,this.data[r]||(this.data[r]=null),this.data[s]||(this.data[s]=null),this.parent?this.parent.getId()!==this.data[s]&&(this.data[s]=this.parent.getId(),this.isDirty=!0):this.parent=null,this.children=[],this.getData=function(){return this.data},this.getId=function(){return this.data[r]},this.getParent=function(){return this.parent},this.getRoot=function(){return null===this.parent?this:this.parent.getRoot()},this.removeChild=function(t){if(this.children.length>0){var e=i.findIndex(this.children,function(e){return e.getId()===t});e>-1&&this.children.splice(e,1)}},this.addChild=function(t,e,r){var n=this,s=i.find(this.children,function(e){return e.getId()===t[n.pkField]});return s||(s=this.nodeConstructor(this,t,e||this.pkField,r||this.parentField),this.children.push(s)),s},this.findChild=function(t,e){var r=null;return this.getId()===t?r=this:(e&&this.items.length>0&&i.each(this.items,function(e){if(e.getId()===t)return r=e,!1}),!r&&this.children.length>0&&i.each(this.children,function(n){if(r=n.findChild(t,e))return!1})),r},this.items=[],this.itemOwner=null,this.getItemOwner=function(){return this.itemOwner},this.addItem=function(t,e,r){var n=this,s=i.find(this.items,function(e){return e.getId()===t[n.pkField]});return s||((s=this.nodeItemConstructor(null,t,e,r)).itemOwner=this,this.items.push(s)),s},this.removeItem=function(t){if(this.items.length>0){var e=i.findIndex(this.items,function(e){return e.getId()===t});e>-1&&this.items.splice(e,1)}},this.findItem=function(t){var e=null;return this.items.length>0&&i.each(this.items,function(r){if(r.getId()===t)return e=r,!1}),!e&&this.children.length>0&&i.each(this.children,function(r){if(e=r.findItem(t))return!1}),e},this.sortChildren=function(t,e){t&&this.children.length>0&&(this.children.sort(t),e||i.each(this.children,function(e){e.sortChildren(t)}))},this.sortItems=function(t,e,r){t&&this.items.length>0&&(this.items.sort(t),e&&i.each(this.items,function(t){r||t.sortChildren(e,r)}))},this.getLevelDeep=function(){var t=0;return this.parent&&(t=1,t+=this.parent.getLevelDeep()),t},this.branchCallFunction=function(t,e,r){e||t&&t(this),this.parent&&this.parent.branchCallfunction(t,e,r),r&&this.itemOwner&&this.itemOwner.branchCallfunction(t,e,r),e&&t&&t(this)},this.branchCallFunctionChildren=function(t,e){t&&t(this),this.children.length>0&&i.each(this.children,function(r){r.branchCallFunctionChildren(t,e)}),e&&this.items.length>0&&i.each(this.items,function(r){r.branchCallFunctionChildren(t,e)})}}var i=window._;e.exports.zzNode=s},{}],12:[function(t,e,r){if("undefined"==typeof jQuery)throw new Error("zazzy-browser's JavaScript requires jQuery. jQuery must be included before zazzy-browser's JavaScript.");if("undefined"==typeof BootstrapDialog)throw new Error("zazzy-browser's JavaScript requires BootstrapDialog. BootstrapDialog must be included before zazzy-browser's JavaScript.");if("undefined"==typeof _)throw new Error("zazzy-browser's JavaScript requires lodash. lodash must be included before zazzy-browser's JavaScript.");!function(t,r){if("undefined"!=typeof window)window.zzb=r();else if(void 0!==t)t.zzb=r();else if("function"==typeof define&&define.amd)define(r);else{if("object"!=typeof e||!e.exports)throw new Error("could not locate global cache object in which to create zzb");e.exports=r()}}(this,function(){"use strict";function e(){}var r=t("./zzNode.js"),n=t("./types.js").types,s=t("./uuid.js").uuid,i=t("./strings.js").strings,o=t("./uib.js").uib,a=t("./forms.js").forms,l=t("./dialogs.js").dialogs,u=t("./perms.js").perms,c=t("./rob.js").rob,p=t("./ajax.js").ajax,d=t("./status.js").status;return e.prototype.zzNode=r,e.prototype.types=new n,e.prototype.uuid=new s,e.prototype.strings=new i,e.prototype.uib=new o,e.prototype.forms=new a,e.prototype.dialogs=new l,e.prototype.perms=new u,e.prototype.rob=new c,e.prototype.ajax=new p,e.prototype.status=new d,new e})},{"./ajax.js":1,"./dialogs.js":2,"./forms.js":3,"./perms.js":4,"./rob.js":5,"./status.js":6,"./strings.js":7,"./types.js":8,"./uib.js":9,"./uuid.js":10,"./zzNode.js":11}]},{},[12]); | ||
!function t(e,r,n){function s(o,a){if(!r[o]){if(!e[o]){var l="function"==typeof require&&require;if(!a&&l)return l(o,!0);if(i)return i(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var c=r[o]={exports:{}};e[o][0].call(c.exports,function(t){var r=e[o][1][t];return s(r||t)},c,c.exports,t,e,r,n)}return r[o].exports}for(var i="function"==typeof require&&require,o=0;o<n.length;o++)s(n[o]);return s}({1:[function(t,e,r){function n(){this.ajax=function(t){return new Promise(function(e,r){s.ajax(t).done(function(n,s,i){if(t.RAWRETURN)return e(n);if(!n)return r(new Error("Data returned is empty when at minimum a status is required"));var o=zzb.rob.newROB();if(i.responseJSON){if(n.redirect&&n.redirect.length>0)return void(window.location.href=n.redirect);n.ISROBERRORS||(n.err?(n.errs=zzb.rob.sanitizeErrors(n.err),n.err=null):n.error?(n.error=zzb.rob.sanitizeErrors(n.error),n.error=null):n.errs&&(n.errs=zzb.rob.sanitizeErrors(n.errs),n.err=null)),n.ISROBRECS||(n.recs?n.recs=zzb.rob.sanitizeRecords(n.rec):n.rec?(n.recs=zzb.rob.sanitizeRecords(n.rec),n.rec=null):n.recs=zzb.rob.sanitizeRecords(n)),o.errs=n.errs,o.recs=n.recs,o.fields=n.fields}else o.recs=[n];e(n)}).fail(function(t,e,n){r(n),console.log(n)})})}}var s=window.$;n.prototype.get=function(t){return t.type="GET",t.contentType="application/json; charset=UTF-8",t.data=JSON.stringify(t.data),this.ajax(t)},n.prototype.getJSON=function(t){return t.type="GET",t.dataType="json",t.contentType="application/json; charset=UTF-8",t.data=JSON.stringify(t.data),this.ajax(t)},n.prototype.postJSON=function(t){return t.type="POST",t.dataType="json",t.contentType="application/json; charset=UTF-8",t.data=JSON.stringify(t.data),this.ajax(t)},r.ajax=n},{}],2:[function(t,e,r){var n=window.BootstrapDialog,s=window._,i=function(){};i.prototype.showMessage=function(t){t=s.merge({type:n.TYPE_DEFAULT,title:"",message:"",buttonCloseName:"Ok",onShown:null},t),n.show({type:t.type,title:t.title,message:t.message,onshown:t.onShown,buttons:[{label:t.buttonCloseName,action:function(t){t.close()}}]})},i.prototype.showMessageChoice=function(t){(t=s.merge({type:n.TYPE_DEFAULT,title:"",message:"",cssClass:"",buttonLeftName:"Cancel",buttonRightName:"Accept",buttonLeftCssClass:"",buttonRightCssClass:"",buttonLeftIcon:"",buttonRightIcon:"",onShown:null,onButtonLeftClick:null,onButtonRightClick:null,noButtons:!1,buttons:[]},t)).noButtons||(t.buttons=[{label:t.buttonLeftName,cssClass:t.buttonLeftCssClass,icon:t.buttonLeftIcon,action:function(e){t.onButtonLeftClick?t.onButtonLeftClick(function(t){t||e.close()}):e.close()}},{label:t.buttonRightName,cssClass:t.buttonRightCssClass,icon:t.buttonRightIcon,action:function(e){t.onButtonRightClick?t.onButtonRightClick(function(t){t||e.close()}):e.close()}}]),n.show({type:t.type,title:t.title,message:t.message,cssClass:t.cssClass,onshown:t.onShown,buttons:t.buttons})},i.prototype.handleError=function(t){if((t=s.merge({log:null,title:"",message:null,errs:null},t)).log&&console.log(t.log),t.errs&&Array.isArray(t.errs)&&t.errs.length>0&&t.errs[0]){var e=[];s.each(t.errs,function(t,r){t.message&&zzb.types.isNonEmptyString(t.message)&&e.push(zzb.strings.format("<div>{0}</div>",t.message))}),e.length>0&&(t.message||(t.message=""),t.errIntro&&(t.message+=" "+t.errIntro),t.message+=" "+e.join(""))}t.message&&this.showMessage({type:n.TYPE_DANGER,title:t.title,message:t.message})},r.dialogs=i},{}],3:[function(t,e,r){var n=window.$,s=window._,i=function(){},o=function(t,e){var r=[],n=[];if(!t||0===t.length||!t[0]){if(e.hideWhenNoError)return{html:null,contentPopOver:null};t=[{type:"success",message:null}]}return s.each(t,function(t,s){if(t.field||(t.field="_system"),"_system"===t.field)r.push(zzb.strings.format("<div>{0}</div>",t.message));else{var i=e.typeFormats.error;t.type&&e.typeFormats[t.type]&&(i=e.typeFormats[t.type]),0===s&&r.push(zzb.strings.format('<span class="glyphicon {0} {1}"></span>',i.glyph,i.textClass)),t.message&&zzb.types.isNonEmptyString(t.message)&&n.push(t.message)}}),{html:r.join(" "),contentPopOver:n.join(" ")}},a=function(t){t.$elem&&t.$elem.length>0&&t&&t.contentPopOver&&zzb.types.isNonEmptyString(t.contentPopOver)&&t.$elem.popover({trigger:"hover",animation:!1,content:t.contentPopOver})};i.prototype.displayUIErrors=function(t,e){if((t=s.merge({selector:null,$form:null,selectorField:".zzb-form-field",attrFieldname:"zzb-fieldname",selectorError:".zzb-form-field-error",errs:null,err:null,hideWhenNoError:!1,typeFormats:{error:{glyph:"glyphicon-remove",textClass:"text-danger",bgClass:null},warning:{glyph:"glyphicon-warning",textClass:"text-warning",bgClass:null},success:{glyph:"glyphicon-ok",textClass:"text-success",bgClass:null},default:null},renderErrorHtml:o,afterHtmlAdded:a,handleSystemErrors:null},t)).renderErrorHtml){if(t.$form?t.selector=null:t.selector&&(t.$form=n("selector")),!t.$form||0===t.$form.length)return e&&e(!1);t.err&&!Array.isArray(t.err)?(t.errs=[zzb.rob.createError(t.err)],t.err=null):t.errs&&!Array.isArray(t.errs)&&(t.errs=[zzb.rob.createError(t.errs)],t.err=null);var r=zzb.rob.toObject(t.errs),i=!1;t.$form.find(t.selectorError).each(function(e,s){var o=n(s),a=o.closest(t.selectorField);if(0===a.length)return console.log("discovered an error field but could not determine the field to which it belongs (eg zzb-form-field)"),!0;var l=a.attr(t.attrFieldname);if(zzb.types.isEmptyString(l))return console.log('discovered an error field and its parent field (eg zzb-form-field) but the fieldname attribute is empty (eg zzb-fieldname="")'),!0;"_system"===l&&(i=!0);var u=t.renderErrorHtml(r[l],t);o.html(u.html),u.html&&zzb.types.isNonEmptyString(u.html)?o.removeClass("hidden"):o.addClass("hidden"),u.fieldname=l,u.$elem=o,t.afterHtmlAdded&&t.afterHtmlAdded(u)})}!i&&r._system&&r._system.length>0&&r._system[0]&&(t.handleSystemErrors?t.handleSystemErrors(r._system,t):zzb.dialogs.handleError({errs:r._system})),e&&e(!1)},r.forms=i},{}],4:[function(t,e,r){var n=window._,s=function(){};s.prototype.getPO=function(t,e){var r=t[e];return r||this.getPermObject(e+":")},s.prototype.getPermObjectFromPermkeys=function(t){var e={},r=this;return Array.isArray(t)?n.each(t,function(t){var n=r.getPermObject(t);n.key&&(e[n.key]=n)}):zzb.types.isObject(t)&&n.forOwn(t,function(t,n){t||(t="");var s=null;(s=t.indexOf(":")<0?r.getPermObject(n+":"+t):r.getPermObject(t))&&s.key&&(e[s.key]=s)}),e},s.prototype.mergePermkey=function(t,e){if(!e||!zzb.types.isNonEmptyString(e))return t;if(!t||!zzb.types.isNonEmptyString(t))return e;var r=null,n={},s={};if(t.indexOf(":")<=0?(n.key=t.trim(),n.perm=""):(r=t.split(":"),n.key=r[0].trim(),n.perm=r[1].trim().toUpperCase()),e.indexOf(":")<=0?(s.key=e.trim().toUpperCase(),s.perm=""):(r=e.split(":"),s.key=r[0].trim(),s.perm=r[1].trim().toUpperCase()),n.key!==s.key||n.perm===s.perm||0===s.perm.length)return t;if(0===n.key.length)return e;for(var i=0;i<s.perm.length;i++)n.perm.indexOf(s.perm[i])<0&&(n.perm+=s.perm[i]);return n.key+":"+n.perm},s.prototype.getPermObject=function(t,e,r){var n={key:null,perm:null,attr:{},toPermkey:function(){return this.key+":"+this.perm}};if((r||zzb.types.isNonEmptyString(r))&&(t=this.mergePermkey(t,r)),!t||!zzb.types.isNonEmptyString(t))return n.attr=this.getPermAttributes(),n;if(t.indexOf(":")<=0)return n.key=t,n.perm="",n.attr=this.getPermAttributes(),n;var s=t.split(":");if(n.key=s[0],n.perm=s[1],n.perm=n.perm.trim().toUpperCase(),n.perm.length>0&&e&&zzb.types.isNonEmptyString(e)){e=e.trim().toUpperCase();for(var i=n.perm.length-1;i>=0;i--)e.indexOf(n.perm[i])<0&&(n.perm=n.perm.replace(n.perm[i],""))}return n.attr=this.getPermAttributes(n.toPermkey(),e),n};var i=new RegExp("^[CRUDX]*$");s.prototype.getPermAttributes=function(t){var e={canRead:!1,canCreate:!1,canUpdate:!1,canDelete:!1,canExecute:!1};return t&&zzb.types.isNonEmptyString(t)?(t.indexOf(":")>=0&&(t=t.split(":")[1]),0===(t=t.trim().toUpperCase()).length?e:i.test(t)?(e.canRead=t.indexOf("C")>=0,e.canCreate=t.indexOf("R")>=0,e.canUpdate=t.indexOf("U")>=0,e.canDelete=t.indexOf("D")>=0,e.canExecute=t.indexOf("X")>=0,e):e):e},r.perms=s},{}],5:[function(t,e,r){function n(t){if((t=s.merge({type:"error",message:null,field:"_system",stack:null,isErr:!0},t)).isErr)switch(t.type){case"warning":case"notice":case"info":case"debug":t.isErr=!1;break;default:t.isErr=!0}return t}var s=window._,i=function(){};i.prototype.newROB=function(t){return s.merge({errs:null,recs:[],fields:[],hasErrors:function(){return this.errs&&Array.isArray(this.errs)&&this.errs.length>0},hasFields:function(){return this.fields&&Array.isArray(this.fields)&&this.fields.length>0},hasRecords:function(){return this.recs&&Array.isArray(this.recs)&&this.recs.length>0},isEmpty:function(){return!this.hasRecords()||this.hasRecords()&&null===this.first()},first:function(){return this.recs&&Array.isArray(this.recs)&&this.recs.length>0?this.recs[0]:null},find:function(t,e){var r=null;return s.each(this.recs,function(n){if(n&&zzb.types.isObject(n)&&!Array.isArray(n)&&n[t]===e)return r=n,!1}),r},length:function(){return this.recs&&Array.isArray(this.recs)?this.recs.length:0}},t)},i.prototype.toObject=function(t){if(!t||!Array.isArray(t))return{_system:[t]};var e={};return s.each(t,function(t){t&&(t.field||(t.field="_system"),e[t.field]||(e[t.field]=[]),e[t.field].push(t))}),e};var o=function(t,e){if(!t)return n();if(zzb.types.isNonEmptyString(t))return n(s.merge({message:t},e));if(!Array.isArray(t)&&zzb.types.isObject(t))return n(t);throw new Error("bad input in createError - unrecognized err datatype")};i.prototype.createError=o,i.prototype.sanitizeErrors=function(t){var e=null;return t?(Array.isArray(t)?t.length>0&&(e=[],s.each(t,function(t){e.push(o(t))})):e=[o(t)],e):e},i.prototype.sanitizeRecords=function(t){return t?Array.isArray(t)?t:[t]:[]},i.prototype.toListErrs=function(t,e,r,n){function i(t){return n?zzb.strings.format(n,t.message):"html"===e?zzb.strings.format("<li>{0}</li>",t.message):zzb.strings.format("System: {0}",t.message)}function o(t){var n=t.title;return t.title||(n=t.field),r?zzb.strings.format(r,n,t.message):"html"===e?zzb.strings.format("<li><strong>{0}</strong>: {1}</li>",n,t.message):zzb.strings.format("{0}: {1}",n,t.message)}var a=[],l=[];return e=e||"text",t&&Array.isArray(t)&&t.length>0&&s.each(t,function(t){"_system"===t.system?l.push(i(t)):t.field?l.push(o(t)):l.push(i(t))}),{system:l,fields:a,hasSystemErrors:function(){return this.system&&this.system.length>0},hasFieldErrors:function(){return this.fields&&this.fields.length>0},combined:function(){return this.system.concat(this.fields)},hasErrors:function(){return this.hasSystemErrors()&&this.hasFieldErrors()}}},r.rob=i},{}],6:[function(t,e,r){var n=window.$,s=window._,i=function(){this.zzbStatus=null};i.prototype.get=function(t,e){var r=(t=s.merge({path:window.location.path,role:null})).path===window.location.path&&!t.role;if(r){if(this.zzbStatus)return e&&e(null,this.zzbStatus);var i=null;if("undefined"!=typeof Storage&&sessionStorage.zzbStatus){try{i=JSON.parse(sessionStorage.getItem("zzbStatus"))}catch(t){console.log("unable to parse zzbStatus from sessionStorage: "+t)}if(sessionStorage.setItem("zzbStatus",null),i)return this.zzbStatus=i,e&&e(null,this.zzbStatus)}if(n("#zzbStatus").length>0&&zzb.types.isNonEmptyString(n("#zzbStatus").attr("status"))){try{i=JSON.parse(n("#zzbStatus").attr("status"))}catch(t){console.log("unable to parse zzbStatus from embedded attribute in #zzbStatus: "+t)}if(i)return this.zzbStatus=i,e&&e(null,this.zzbStatus)}}i={user:{isLoggedIn:!1,username:null},page:{path:window.location.pathname}};var o=this;zzb.ajax.postJSON({url:"/zzb/status",data:t}).then(function(t){t.errs?e&&e(t.errs,i):(r&&(o.zzbStatus=t.one()),e&&e(null,t.one()))}).catch(function(t){console.log("failed to retrieve zzbStatus: using defaults"),e&&e(zzb.types.sanitizeErrors(t),i)})},r.status=i},{}],7:[function(t,e,r){var n=window._,s=function(){},i=function(t){var e=new Error(t);return e.name="ValueError",e},o=function(t,e){return null==e?t:e},a=function(t,e){/^\d+$/.test(e[0])||(e=["0"].concat(e));for(var r=0;r<e.length;r+=1){var n=e[r];t="function"==typeof t[n]?t[n]():t[n]}return t};s.prototype.format=function(t){return function(e){var r=Array.prototype.slice.call(arguments,1),n=0,s="UNDEFINED";if(Array.isArray(r)&&r.length>0&&Array.isArray(r[0])){var l=r[0].map(function(t){return t});r=l}return e.replace(/([{}])\1|[{](.*?)(?:!(.+?))?[}]/g,function(e,l,u,c){if(null!=l)return l;if(u.length>0){if("IMPLICIT"===s)throw i("cannot switch from implicit to explicit numbering");s="EXPLICIT"}else{if("EXPLICIT"===s)throw i("cannot switch from explicit to implicit numbering");s="IMPLICIT",u=String(n),n+=1}var p=o("",a(r,u.split(".")));if(null==c)return p;if(Object.prototype.hasOwnProperty.call(t,c))return t[c](p);throw i('no transformer named "'+c+'"')})}}({}),s.prototype.formatEmpty=function(t){var e=Array.prototype.slice.call(arguments,1);return Array.isArray(e)?t.replace(/{(\d+)}/g,function(t,r){return void 0!==e[r]?e[r]:""}):t.replace(/{((?:(?=([^{}]+|{{[^}]*}}))\2)*)}/g,function(t,r){return e.length>0&&e[0][r]?e[0][r]:""})},s.prototype.appendIfMoreThan=function(t,e,r){return t&&t.length>r?t.substring(0,r)+e:t},s.prototype.joinArrToCommas=function(t,e){return t&&Array.isArray(t)&&0!==t.length?t.map(t,function(r,n){var s="";return n<t.index-1&&(s=""),e?r[e]+s:r+s}).join(""):""},s.prototype.toPlural=function(t,e,r){return r=n.merge({forcePlural:!1,suffix:null},r),1!==e&&-1!==e||r.forcePlural?r.suffix?t+r.suffix:t+"s":t},r.strings=s},{}],8:[function(t,e,r){function n(){}n.prototype.escapeJqueryId=function(t,e){return(e=null==e?"#":e)+t.replace(/(:|\.|\[|\]|,)/g,"\\$1")},n.prototype.escapeHtml=function(t){return t?t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"):""},n.prototype.isArray=function(t){return t&&void 0!==t&&"[object Array]"===Object.prototype.toString.call(t)},n.prototype.isArrayHasRecords=function(t){return this.isArray(t)&&t.length>0},n.prototype.isObject=function(t){return t&&"object"==typeof t},n.prototype.isNumber=function(t){return!isNaN(t-0)&&null!==t&&""!==t&&!1!==t},n.prototype.isNonEmptyString=function(t){return t&&"string"==typeof t&&t.trim().length>0},n.prototype.isEmptyString=function(t){return t&&"string"==typeof t&&0===t.trim().length},n.prototype.isString=function(t){return t&&"string"==typeof t},n.prototype.isFunction=function(t){var e={};return t&&"[object Function]"===e.toString.call(t)},n.prototype.compare=function(t,e,r){return t===e?0:r?t>e?-1:1:t>e?1:-1},r.types=n},{}],9:[function(t,e,r){var n=window._,s=function(){};s.prototype.createPanelGroup=function(t){t=n.merge({id:zzb.uuid.newV4(),classPanelGroup:"",innerHtml:""},t);return zzb.strings.format('<div id="panelGroup_{id}" class="panel-group {classPanelGroup}">{innerHtml}</div>',t)},s.prototype.createPanelBody=function(t){t=n.merge({id:zzb.uuid.newV4(),classPanelBody:"",innerHtml:""},t);return zzb.strings.format('<div id="panelBody_{id}" class="panel-body {classPanelBody}">{innerHtml}</div>',t)},s.prototype.createPanel=function(t){t=n.merge({id:zzb.uuid.newV4(),className:"",attributesExtra:"",classPanelHeading:"",name:"",classPanelBody:"",innerHtml:""},t);var e='<div id="panel_{id}" class="panel panel-default {className}" {attributesExtra}><div class="panel-heading {classPanelHeading}>">{name}</div><div id="panelBody_{id}" class="panel-body {classPanelBody}">'+this.createPanelBody(t)+"</div></div>";return zzb.strings.format(e,t)},s.prototype.createPanelCollapsible=function(t){(t=n.merge({id:zzb.uuid.newV4(),className:"",attributesExtra:"",name:"",classPanelBody:"",innerHtml:"",isPanelCollapsed:!1,classNamePanelCollapsed:"",titleHtmlExtra:"",titleHtmlExtraRight:""},t)).isPanelCollapsed?(t._panelCollapsedClass1="collapsed",t._panelCollapsedClass2=""):(t._panelCollapsedClass1="",t._panelCollapsedClass2="in");var e='<div id="panel_{id}" class="panel panel-default {className}" {attributesExtra}><div class="panel-heading"><h4 class="panel-title">{titleHtmlExtra}<a data-toggle="collapse" data-target="#panelCollapse_{id}" href="#panelCollapse_{id}" class="{_panelCollapsedClass1}{classNamePanelCollapsed}">{name}</a> {titleHtmlExtraRight}</h4></div><div id="panelCollapse_{id}" class="panel-collapse collapse {_panelCollapsedClass2}">'+this.createPanelBody(t)+"</div></div>";return zzb.strings.format(e,t)},s.prototype.createPanelCollapsibleBegin=function(t){(t=n.merge({id:zzb.uuid.newV4(),className:"",attributesExtra:"",name:"",classPanelBody:"",innerHtml:"",isPanelCollapsed:!1,classNamePanelCollapsed:"",titleHtmlExtra:"",titleHtmlExtraRight:""},t)).isPanelCollapsed?(t._panelCollapsedClass1="collapsed",t._panelCollapsedClass2=""):(t._panelCollapsedClass1="",t._panelCollapsedClass2="in");return zzb.strings.format('<div class="panel panel-default {className}" id="panel_{id}" {attributesExtra}><div class="panel-heading"><h4 class="panel-title">{titleHtmlExtra}<a data-toggle="collapse" data-target="#panelCollapse_{id}" href="#panelCollapse_{id}" class="{_panelCollapsedClass1}{classNamePanelCollapsed}">{name}</a> {titleHtmlExtraRight}</h4></div><div id="panelCollapse_{id}" class="panel-collapse collapse {_panelCollapsedClass2}"><div class="panel-body" id="panelBody_{id}">',t)},s.prototype.createPanelCollapsibleEnd=function(){return"</div></div></div>"},r.uib=s},{}],10:[function(t,e,r){var n=window._,s=function(){};s.prototype.newV4=function(){var t=n.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var r=(t+n.random(16))%16|0;return t=Math.floor(t/16),("x"===e?r:3&r|8).toString(16)})},s.prototype.isV4=function(t){return/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(t)},s.prototype.isValid=function(t){return/^([a-f\d]{8}(-[a-f\d]{4}){3}-[a-f\d]{12}?)$/i.test(t)},r.uuid=s},{}],11:[function(t,e,r){function n(t,e,r,n){return new s(t,e,r,n)}function s(t,e,r,s){this.parent=t,this.data=e,this.pkField=r,this.parentField=s,this.nodeConstructor=n,this.nodeItemConstructor=n,this.isDirty=!1,this.data[r]||(this.data[r]=null),this.data[s]||(this.data[s]=null),this.parent?this.parent.getId()!==this.data[s]&&(this.data[s]=this.parent.getId(),this.isDirty=!0):this.parent=null,this.children=[],this.getData=function(){return this.data},this.getId=function(){return this.data[r]},this.getParent=function(){return this.parent},this.getRoot=function(){return null===this.parent?this:this.parent.getRoot()},this.removeChild=function(t){if(this.children.length>0){var e=i.findIndex(this.children,function(e){return e.getId()===t});e>-1&&this.children.splice(e,1)}},this.addChild=function(t,e,r){var n=this,s=i.find(this.children,function(e){return e.getId()===t[n.pkField]});return s||(s=this.nodeConstructor(this,t,e||this.pkField,r||this.parentField),this.children.push(s)),s},this.findChild=function(t,e){var r=null;return this.getId()===t?r=this:(e&&this.items.length>0&&i.each(this.items,function(e){if(e.getId()===t)return r=e,!1}),!r&&this.children.length>0&&i.each(this.children,function(n){if(r=n.findChild(t,e))return!1})),r},this.items=[],this.itemOwner=null,this.getItemOwner=function(){return this.itemOwner},this.addItem=function(t,e,r){var n=this,s=i.find(this.items,function(e){return e.getId()===t[n.pkField]});return s||((s=this.nodeItemConstructor(null,t,e,r)).itemOwner=this,this.items.push(s)),s},this.removeItem=function(t){if(this.items.length>0){var e=i.findIndex(this.items,function(e){return e.getId()===t});e>-1&&this.items.splice(e,1)}},this.findItem=function(t){var e=null;return this.items.length>0&&i.each(this.items,function(r){if(r.getId()===t)return e=r,!1}),!e&&this.children.length>0&&i.each(this.children,function(r){if(e=r.findItem(t))return!1}),e},this.sortChildren=function(t,e){t&&this.children.length>0&&(this.children.sort(t),e||i.each(this.children,function(e){e.sortChildren(t)}))},this.sortItems=function(t,e,r){t&&this.items.length>0&&(this.items.sort(t),e&&i.each(this.items,function(t){r||t.sortChildren(e,r)}))},this.getLevelDeep=function(){var t=0;return this.parent&&(t=1,t+=this.parent.getLevelDeep()),t},this.branchCallFunction=function(t,e,r){e||t&&t(this),this.parent&&this.parent.branchCallfunction(t,e,r),r&&this.itemOwner&&this.itemOwner.branchCallfunction(t,e,r),e&&t&&t(this)},this.branchCallFunctionChildren=function(t,e){t&&t(this),this.children.length>0&&i.each(this.children,function(r){r.branchCallFunctionChildren(t,e)}),e&&this.items.length>0&&i.each(this.items,function(r){r.branchCallFunctionChildren(t,e)})}}var i=window._;e.exports.zzNode=s},{}],12:[function(t,e,r){if("undefined"==typeof jQuery)throw new Error("zazzy-browser's JavaScript requires jQuery. jQuery must be included before zazzy-browser's JavaScript.");if("undefined"==typeof BootstrapDialog)throw new Error("zazzy-browser's JavaScript requires BootstrapDialog. BootstrapDialog must be included before zazzy-browser's JavaScript.");if("undefined"==typeof _)throw new Error("zazzy-browser's JavaScript requires lodash. lodash must be included before zazzy-browser's JavaScript.");!function(t,r){if("undefined"!=typeof window)window.zzb=r();else if(void 0!==t)t.zzb=r();else if("function"==typeof define&&define.amd)define(r);else{if("object"!=typeof e||!e.exports)throw new Error("could not locate global cache object in which to create zzb");e.exports=r()}}(this,function(){"use strict";function e(){}var r=t("./zzNode.js"),n=t("./types.js").types,s=t("./uuid.js").uuid,i=t("./strings.js").strings,o=t("./uib.js").uib,a=t("./forms.js").forms,l=t("./dialogs.js").dialogs,u=t("./perms.js").perms,c=t("./rob.js").rob,p=t("./ajax.js").ajax,d=t("./status.js").status;return e.prototype.zzNode=r,e.prototype.types=new n,e.prototype.uuid=new s,e.prototype.strings=new i,e.prototype.uib=new o,e.prototype.forms=new a,e.prototype.dialogs=new l,e.prototype.perms=new u,e.prototype.rob=new c,e.prototype.ajax=new p,e.prototype.status=new d,new e})},{"./ajax.js":1,"./dialogs.js":2,"./forms.js":3,"./perms.js":4,"./rob.js":5,"./status.js":6,"./strings.js":7,"./types.js":8,"./uib.js":9,"./uuid.js":10,"./zzNode.js":11}]},{},[12]); |
{ | ||
"name": "zazzy-browser", | ||
"version": "0.2.18", | ||
"version": "0.2.19", | ||
"description": "A collection of general-purpose browser utilities used as higher-level building-blocks to create Bootstrap v3 websites and assist in client-server communications.", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -172,2 +172,62 @@ // client or server | ||
_perms.prototype.hasMatch = function (permkey, target) { | ||
if (!permkey || !target) { | ||
return false | ||
} | ||
var po = permkey | ||
if (zzb.types.isNonEmptyString(permkey)) { | ||
po = this.getPermObject(permkey) | ||
} | ||
if (!zzb.types.isObject(po) || !po.key || !po.perm || po.perm.length === 0) { | ||
return false | ||
} | ||
var tp = null | ||
if (zzb.types.isNonEmptyString(target)) { | ||
tp = this.getPermObject(target) | ||
} else if (Array.isArray(target)) { | ||
var self = this | ||
_.each(target, function (item) { | ||
if (zzb.types.isNonEmptyString(item)) { | ||
item = self.getPermObject(item) | ||
} | ||
if (item.key === po.key) { | ||
tp = item | ||
return false | ||
} | ||
}) | ||
} else { | ||
if (!zzb.types.isObject(target)) { | ||
return false | ||
} | ||
if (target.key) { | ||
tp = target | ||
} else { | ||
if (!target[po.key]) { | ||
return false | ||
} else { | ||
if (zzb.types.isNonEmptyString(target[po.key])) { | ||
tp = this.getPermObject(po.key + ':' + target[po.key]) | ||
} else { | ||
tp = target[po.key] | ||
} | ||
} | ||
} | ||
} | ||
if (!tp || !tp.key || !tp.perm || !tp.perm.length === 0) { | ||
return false | ||
} | ||
for (var ii = 0; ii < tp.perm.length; ii++) { | ||
if (po.perm.indexOf(tp.perm[ii]) >= 0) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
exports.perms = _perms |
@@ -114,2 +114,10 @@ /* global describe, it, zzs */ | ||
}) | ||
it('should create one perm object (test:CUD) merged with existing minus available and duplicate perm (UUDD)', function (done) { | ||
var pos = zzb.perms.getPermObject('test:C', 'CRUDX', 'test:UUDD') | ||
expect(pos).to.not.equal(null) | ||
expect(pos.key).to.equal('test') | ||
expect(pos.perm).to.equal('CUD') | ||
expect(pos.toPermkey()).to.equal('test:CUD') | ||
done() | ||
}) | ||
it('should create one perm object (test:C) merged with existing minus available', function (done) { | ||
@@ -123,2 +131,52 @@ var pos = zzb.perms.getPermObject('test:CRUDX', 'C', 'test:UD') | ||
}) | ||
it('should match (test:C) using pos', function (done) { | ||
var pos = zzb.perms.getPermObject('test:C', 'CRUDX', 'test:UD') | ||
expect(zzb.perms.hasMatch('test:C', pos)).to.equal(true) | ||
done() | ||
}) | ||
it('should match (test:C) using string', function (done) { | ||
expect(zzb.perms.hasMatch('test:C', 'test:CUD')).to.equal(true) | ||
done() | ||
}) | ||
it('should match (test:C) using object of pos', function (done) { | ||
expect(zzb.perms.hasMatch('module1:C', zzb.perms.getPermObjectFromPermkeys(permObj1))).to.equal(true) | ||
done() | ||
}) | ||
it('should match (test:C) using object of strings', function (done) { | ||
expect(zzb.perms.hasMatch('module1:C', permObj1)).to.equal(true) | ||
done() | ||
}) | ||
it('should match (test:C) using array of pos', function (done) { | ||
expect(zzb.perms.hasMatch('module1:C', zzb.perms.getPermObjectFromPermkeys(permArr1))).to.equal(true) | ||
done() | ||
}) | ||
it('should match (test:C) using array of string', function (done) { | ||
expect(zzb.perms.hasMatch('module1:C', permArr1)).to.equal(true) | ||
done() | ||
}) | ||
it('should not match (test:X)', function (done) { | ||
var pos = zzb.perms.getPermObject('test:C', 'CRUDX', 'test:UD') | ||
expect(zzb.perms.hasMatch('test:X', pos)).to.equal(false) | ||
done() | ||
}) | ||
it('should not match (test:C) using string', function (done) { | ||
expect(zzb.perms.hasMatch('test:C', 'test:X')).to.equal(false) | ||
done() | ||
}) | ||
it('should not match (test:X) using object of pos', function (done) { | ||
expect(zzb.perms.hasMatch('module1:X', zzb.perms.getPermObjectFromPermkeys(permObj1))).to.equal(false) | ||
done() | ||
}) | ||
it('should not match (test:X) using object of strings', function (done) { | ||
expect(zzb.perms.hasMatch('module1:X', permObj1)).to.equal(false) | ||
done() | ||
}) | ||
it('should not match (test:X) using array of pos', function (done) { | ||
expect(zzb.perms.hasMatch('module1:X', zzb.perms.getPermObjectFromPermkeys(permArr1))).to.equal(false) | ||
done() | ||
}) | ||
it('should not match (test:X) using array of string', function (done) { | ||
expect(zzb.perms.hasMatch('module1:X', permArr1)).to.equal(false) | ||
done() | ||
}) | ||
it('should create three permkeys from object', function (done) { | ||
@@ -125,0 +183,0 @@ var pos = zzb.perms.getPermObjectFromPermkeys(permObj1) |
158920
3883