zazzy-browser
Advanced tools
Comparing version 0.2.6 to 0.2.7
//! zzb.js | ||
//! version: 0.2.6 | ||
//! version: 0.2.7 | ||
//! author(s): Jaret Pfluger | ||
@@ -858,2 +858,32 @@ //! license: MIT | ||
/** | ||
* zzb.strings.toPlural | ||
* | ||
* Usage: | ||
* zzb.strings.toPlural('dog', 1, options) | ||
* zzb.strings.toPlural('dog', 2, options) | ||
* Produces | ||
* dog | ||
* dogs | ||
* | ||
* Appends an s or user-defined suffix (options.suffix) to a word if the number is not 1 or -1 | ||
* @param str | ||
* @param charsToAppend | ||
* @param ifMoreCharCount | ||
* @returns {String} | ||
*/ | ||
_strings.prototype.toPlural = function(word, number, options) { | ||
options = _.merge({forcePlural: false, suffix: null}, options) | ||
if ((number === 1 || number === -1) && !options.forcePlural) { | ||
return word | ||
} | ||
if (options.suffix) { | ||
return word + options.suffix | ||
} else { | ||
return word + 's' | ||
} | ||
} | ||
exports.strings = _strings | ||
@@ -860,0 +890,0 @@ |
//! zzb.js | ||
//! version: 0.2.6 | ||
//! version: 0.2.7 | ||
//! 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,o){if(t.RAWRETURN)return e(n);if(!n)return r(new Error("Data returned is empty when at minimum a status is required"));if(o.responseJSON){if(n.redirect&&n.redirect.length>0)return 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))}else n={recs:[n]};n.first=function(){return n.recs&&Array.isArray(n.recs)&&n.recs.length>0?n.recs[0]:null},n.find=function(t,e){var r=null;return i.each(n.recs,function(n){if(n&&zzb.types.isObject(n)&&!Array.isArray(n)&&n[t]===e)return r=n,!1}),r},n.length=function(){return n.recs&&Array.isArray(n.recs)?n.recs.length:0},e(n)}).fail(function(t,e,n){if(t.responseJSON&&data.redirect)return window.location.href=data.redirect;r(n),console.log(n)})})}}var s=window.$,i=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){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.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]:[]},r.rob=i},{}],5:[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},{}],6:[function(t,e,r){window._;var n=function(){},s=function(t){var e=new Error(t);return e.name="ValueError",e},i=function(t,e){return null==e?t:e},o=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};n.prototype.format=function(t){return function(e){var r=Array.prototype.slice.call(arguments,1),n=0,a="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"===a)throw s("cannot switch from implicit to explicit numbering");a="EXPLICIT"}else{if("EXPLICIT"===a)throw s("cannot switch from explicit to implicit numbering");a="IMPLICIT",u=String(n),n+=1}var p=i("",o(r,u.split(".")));if(null==c)return p;if(Object.prototype.hasOwnProperty.call(t,c))return t[c](p);throw s('no transformer named "'+c+'"')})}}({}),n.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]:""})},n.prototype.appendIfMoreThan=function(t,e,r){return t&&t.length>r?t.substring(0,r)+e:t},n.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(""):""},r.strings=n},{}],7:[function(t,e,r){function n(){}window._;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},{}],8:[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},{}],9:[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},{}],10:[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=new 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},{}],11:[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("./rob.js").rob,c=t("./ajax.js").ajax,p=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.rob=new u,e.prototype.ajax=new c,e.prototype.status=new p,new e})},{"./ajax.js":1,"./dialogs.js":2,"./forms.js":3,"./rob.js":4,"./status.js":5,"./strings.js":6,"./types.js":7,"./uib.js":8,"./uuid.js":9,"./zzNode.js":10}]},{},[11]); | ||
!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,o){if(t.RAWRETURN)return e(n);if(!n)return r(new Error("Data returned is empty when at minimum a status is required"));if(o.responseJSON){if(n.redirect&&n.redirect.length>0)return 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))}else n={recs:[n]};n.first=function(){return n.recs&&Array.isArray(n.recs)&&n.recs.length>0?n.recs[0]:null},n.find=function(t,e){var r=null;return i.each(n.recs,function(n){if(n&&zzb.types.isObject(n)&&!Array.isArray(n)&&n[t]===e)return r=n,!1}),r},n.length=function(){return n.recs&&Array.isArray(n.recs)?n.recs.length:0},e(n)}).fail(function(t,e,n){if(t.responseJSON&&data.redirect)return window.location.href=data.redirect;r(n),console.log(n)})})}}var s=window.$,i=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){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.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]:[]},r.rob=i},{}],5:[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},{}],6:[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},{}],7:[function(t,e,r){function n(){}window._;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},{}],8:[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},{}],9:[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},{}],10:[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=new 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},{}],11:[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("./rob.js").rob,c=t("./ajax.js").ajax,p=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.rob=new u,e.prototype.ajax=new c,e.prototype.status=new p,new e})},{"./ajax.js":1,"./dialogs.js":2,"./forms.js":3,"./rob.js":4,"./status.js":5,"./strings.js":6,"./types.js":7,"./uib.js":8,"./uuid.js":9,"./zzNode.js":10}]},{},[11]); |
{ | ||
"name": "zazzy-browser", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"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": { |
@@ -169,2 +169,32 @@ // client or server | ||
/** | ||
* zzb.strings.toPlural | ||
* | ||
* Usage: | ||
* zzb.strings.toPlural('dog', 1, options) | ||
* zzb.strings.toPlural('dog', 2, options) | ||
* Produces | ||
* dog | ||
* dogs | ||
* | ||
* Appends an s or user-defined suffix (options.suffix) to a word if the number is not 1 or -1 | ||
* @param str | ||
* @param charsToAppend | ||
* @param ifMoreCharCount | ||
* @returns {String} | ||
*/ | ||
_strings.prototype.toPlural = function(word, number, options) { | ||
options = _.merge({forcePlural: false, suffix: null}, options) | ||
if ((number === 1 || number === -1) && !options.forcePlural) { | ||
return word | ||
} | ||
if (options.suffix) { | ||
return word + options.suffix | ||
} else { | ||
return word + 's' | ||
} | ||
} | ||
exports.strings = _strings |
130425
24
3094