zazzy-browser
Advanced tools
Comparing version 0.2.7 to 0.2.8
556
dist/zzb.js
//! zzb.js | ||
//! version: 0.2.7 | ||
//! version: 0.2.8 | ||
//! author(s): Jaret Pfluger | ||
@@ -19,3 +19,3 @@ //! license: MIT | ||
this.ajax = function (options) { | ||
return new Promise(function (fulfill, reject) { | ||
return new Promise(function (resolve, reject) { | ||
$.ajax(options) | ||
@@ -25,3 +25,3 @@ .done(function (data, textStatus, jqXHR) { | ||
if (options.RAWRETURN) { | ||
return fulfill(data) | ||
return resolve(data) | ||
} | ||
@@ -35,3 +35,3 @@ | ||
// ? | ||
//if (jqXHR.status != '200') {} | ||
// if (jqXHR.status != '200') {} | ||
@@ -44,3 +44,4 @@ if (!jqXHR.responseJSON) { | ||
if (data.redirect && data.redirect.length > 0) { | ||
return window.location.href = data.redirect | ||
window.location.href = data.redirect | ||
return | ||
} | ||
@@ -62,3 +63,3 @@ | ||
data.errs = zzb.rob.sanitizeErrors(data.errs) | ||
data.err = null | ||
data.err = null | ||
} | ||
@@ -76,3 +77,3 @@ } | ||
// pass in self | ||
data.recs = zzb.rob.sanitizeRecords(data) | ||
data.recs = zzb.rob.sanitizeRecords(data) | ||
} | ||
@@ -83,3 +84,3 @@ } | ||
data.first = function () { | ||
return (data.recs && Array.isArray(data.recs) && data.recs.length > 0 ? data.recs[0] : null) | ||
return (data.recs && Array.isArray(data.recs) && data.recs.length > 0 ? data.recs[0] : null) | ||
} | ||
@@ -97,13 +98,13 @@ data.find = function (key, value) { | ||
data.length = function () { | ||
return (data.recs && Array.isArray(data.recs) ? data.recs.length : 0) | ||
return (data.recs && Array.isArray(data.recs) ? data.recs.length : 0) | ||
} | ||
fulfill(data) | ||
resolve(data) | ||
}) | ||
.fail(function (jqXHR, textStatus, errorThrown) { | ||
if (jqXHR.responseJSON) { | ||
if (data.redirect) { | ||
return window.location.href = data.redirect | ||
} | ||
} | ||
// if (jqXHR.responseJSON) { | ||
// if (data.redirect) { | ||
// return window.location.href = data.redirect | ||
// } | ||
// } | ||
reject(errorThrown) | ||
@@ -119,14 +120,14 @@ console.log(errorThrown) | ||
_ajax.prototype.get = function (options) { | ||
options.type = 'GET' | ||
options.contentType = 'application/json; charset=UTF-8' | ||
options.data = JSON.stringify(options.data) | ||
return this.ajax(options) | ||
options.type = 'GET' | ||
options.contentType = 'application/json; charset=UTF-8' | ||
options.data = JSON.stringify(options.data) | ||
return this.ajax(options) | ||
} | ||
_ajax.prototype.getJSON = function (options) { | ||
options.type = 'GET' | ||
options.dataType = 'json' | ||
options.contentType = 'application/json; charset=UTF-8' | ||
options.data = JSON.stringify(options.data) | ||
return this.ajax(options) | ||
options.type = 'GET' | ||
options.dataType = 'json' | ||
options.contentType = 'application/json; charset=UTF-8' | ||
options.data = JSON.stringify(options.data) | ||
return this.ajax(options) | ||
} | ||
@@ -164,5 +165,5 @@ | ||
var _dialogs = function() {} | ||
var _dialogs = function () {} | ||
_dialogs.prototype.showMessage = function(options) { | ||
_dialogs.prototype.showMessage = function (options) { | ||
options = _.merge({ | ||
@@ -184,9 +185,9 @@ type: BootstrapDialog.TYPE_DEFAULT, | ||
action: function (dialogRef) { | ||
dialogRef.close(); | ||
dialogRef.close() | ||
} | ||
}] | ||
}); | ||
}; | ||
}) | ||
} | ||
_dialogs.prototype.showMessageChoice = function(options) { | ||
_dialogs.prototype.showMessageChoice = function (options) { | ||
options = _.merge({ | ||
@@ -219,3 +220,3 @@ type: BootstrapDialog.TYPE_DEFAULT, | ||
} else { | ||
options.onButtonLeftClick(function(err) { | ||
options.onButtonLeftClick(function (err) { | ||
if (!err) { | ||
@@ -236,3 +237,3 @@ dialogRef.close() | ||
} else { | ||
options.onButtonRightClick(function(err) { | ||
options.onButtonRightClick(function (err) { | ||
if (!err) { | ||
@@ -257,4 +258,4 @@ dialogRef.close() | ||
_dialogs.prototype.handleError = function(options) { | ||
//this.dialogs.handleError({log: 'failed to retrieve login dialog form: ' + err, title: 'Unknown error', message: 'An unknown communications error occurred while retrieving the login form. Please check your connection settings and try again.'}) | ||
_dialogs.prototype.handleError = function (options) { | ||
// this.dialogs.handleError({log: 'failed to retrieve login dialog form: ' + err, title: 'Unknown error', message: 'An unknown communications error occurred while retrieving the login form. Please check your connection settings and try again.'}) | ||
options = _.merge({log: null, title: '', message: null, errs: null}, options) | ||
@@ -270,3 +271,3 @@ | ||
_.each(options.errs, function(err, index) { | ||
_.each(options.errs, function (err, index) { | ||
if (err.message && zzb.types.isNonEmptyString(err.message)) { | ||
@@ -278,3 +279,2 @@ arrHtml.push(zzb.strings.format('<div>{0}</div>', err.message)) | ||
if (arrHtml.length > 0) { | ||
if (!options.message) { | ||
@@ -314,6 +314,5 @@ options.message = '' | ||
var _forms = function() {} | ||
var _forms = function () {} | ||
var renderHtml_Popover = function (errs, options) { | ||
var arrHtml = [] | ||
@@ -331,4 +330,3 @@ var arrPopOver = [] | ||
_.each(errs, function(err, index) { | ||
_.each(errs, function (err, index) { | ||
if (!err.field) { | ||
@@ -348,3 +346,3 @@ err.field = '_system' | ||
// only once | ||
if (index == 0) { | ||
if (index === 0) { | ||
arrHtml.push(zzb.strings.format('<span class="glyphicon {0} {1}"></span>', typeFormat.glyph, typeFormat.textClass)) | ||
@@ -366,6 +364,6 @@ } | ||
reho.$elem.popover({ | ||
trigger:'hover', | ||
animation: false, | ||
content: reho.contentPopOver | ||
}); | ||
trigger: 'hover', | ||
animation: false, | ||
content: reho.contentPopOver | ||
}) | ||
} | ||
@@ -375,5 +373,5 @@ } | ||
_forms.prototype.displayUIErrors = function(options, callback) { | ||
options = _.merge({selector: null, $form: null, | ||
_forms.prototype.displayUIErrors = function (options, callback) { | ||
options = _.merge({selector: null, | ||
$form: null, | ||
selectorField: '.zzb-form-field', | ||
@@ -384,3 +382,3 @@ attrFieldname: 'zzb-fieldname', | ||
selectorError: '.zzb-form-field-error', | ||
errs: null, | ||
errs: null, | ||
err: null, | ||
@@ -399,6 +397,5 @@ hideWhenNoError: false, // this always shows the 'success' checkmark | ||
var success = false; | ||
var success = false | ||
if (options.renderErrorHtml) { | ||
if (options.$form) { | ||
@@ -411,9 +408,9 @@ options.selector = null // not required | ||
if (!options.$form || options.$form.length === 0) { | ||
return callback && callback(success); | ||
return callback && callback(success) | ||
} | ||
if (options.err && !Array.isArray(options.err)){ | ||
if (options.err && !Array.isArray(options.err)) { | ||
options.errs = [zzb.rob.createError(options.err)] | ||
options.err = null | ||
} else if (options.errs && !Array.isArray(options.errs)){ | ||
} else if (options.errs && !Array.isArray(options.errs)) { | ||
options.errs = [zzb.rob.createError(options.errs)] | ||
@@ -443,3 +440,3 @@ options.err = null | ||
console.log('discovered an error field and its parent field (eg zzb-form-field) but the fieldname attribute is empty (eg zzb-fieldname="")') | ||
return true | ||
return true | ||
} | ||
@@ -482,28 +479,2 @@ | ||
/* | ||
self.forms.toListFromErrors = function(errs) { | ||
var arrHtml = []; | ||
if (errs && Array.isArray(errs)) { | ||
var arrHtmlSystem = []; | ||
arrHtml.push('<ul class="panelErrorList">') | ||
_.each(errs, function(err) { | ||
if (err.field === '_system') { | ||
arrHtmlSystem.push(err.message) | ||
} else if (err.field) { | ||
arrHtml.push(_.formatArr('<li><strong>{0}</strong>: {1}</li>', _.capitalize(err.field.toLowerCase()), err.message)) | ||
} else { | ||
arrHtmlSystem.push(err.message) | ||
} | ||
}); | ||
if (arrHtmlSystem.length > 0) { | ||
arrHtml.push(_.formatArr('<li><strong>System Errors</strong>: {0}</li>', arrHtmlSystem.join(' '))) | ||
} | ||
arrHtml.push('</ul>') | ||
} | ||
return arrHtml.join(''); | ||
};*/ | ||
exports.forms = _forms | ||
@@ -519,3 +490,3 @@ | ||
var _rob = function() {} | ||
var _rob = function () {} | ||
@@ -558,3 +529,3 @@ // reduce the error array to an object | ||
case 'debug': | ||
options.isErr = false | ||
options.isErr = false | ||
break | ||
@@ -567,3 +538,3 @@ default: | ||
return options | ||
return options | ||
} | ||
@@ -576,3 +547,3 @@ | ||
return mergeErrorDefaults() | ||
} | ||
} | ||
if (zzb.types.isNonEmptyString(options1)) { | ||
@@ -596,3 +567,3 @@ return mergeErrorDefaults(_.merge({message: options1}, options2)) | ||
} | ||
if (!Array.isArray(errs)) { | ||
@@ -617,6 +588,70 @@ newErrs = [createError(errs)] | ||
return [recs] | ||
} | ||
} | ||
return recs | ||
} | ||
_rob.prototype.toListErrs = function (errs, defaultFormat, fieldsTemplate, systemTemplate) { | ||
var arrFields = [] | ||
var arrSystem = [] | ||
defaultFormat = defaultFormat || 'text' | ||
function getSystem (err) { | ||
if (systemTemplate) { | ||
return zzb.strings.format(systemTemplate, err.message) | ||
} else { | ||
if (defaultFormat === 'html') { | ||
return zzb.strings.format('<li>{0}</li>', err.message) | ||
} else { | ||
return zzb.strings.format('System: {0}', err.message) | ||
} | ||
} | ||
} | ||
function getField (err) { | ||
var title = err.title | ||
if (!err.title) { | ||
title = err.field // _.capitalize( | ||
} | ||
if (fieldsTemplate) { | ||
return zzb.strings.format(fieldsTemplate, title, err.message) | ||
} else { | ||
if (defaultFormat === 'html') { | ||
return zzb.strings.format('<li><strong>{0}</strong>: {1}</li>', title, err.message) | ||
} else { | ||
return zzb.strings.format('{0}: {1}', title, err.message) | ||
} | ||
} | ||
} | ||
if (errs && Array.isArray(errs) && errs.length > 0) { | ||
_.each(errs, function (err) { | ||
if (err.system === '_system') { | ||
arrSystem.push(getSystem(err)) | ||
} else if (err.field) { | ||
arrSystem.push(getField(err)) | ||
} else { | ||
arrSystem.push(getSystem(err)) | ||
} | ||
}) | ||
} | ||
return { | ||
system: arrSystem, | ||
fields: arrFields, | ||
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()) | ||
} | ||
} | ||
} | ||
exports.rob = _rob | ||
@@ -643,3 +678,3 @@ | ||
var _status = function() { | ||
var _status = function () { | ||
this.zzbStatus = null | ||
@@ -662,7 +697,7 @@ } | ||
// Try local storage first (if top-level page supports it) -> this function will delete it, if found | ||
if (typeof(Storage) !== "undefined" && sessionStorage.zzbStatus) { | ||
if (typeof Storage !== 'undefined' && sessionStorage.zzbStatus) { | ||
try { | ||
// using sessionStorage (not localStorage) | ||
tmpStatus = JSON.parse(sessionStorage.getItem('zzbStatus')) | ||
} catch(err) { | ||
} catch (err) { | ||
console.log('unable to parse zzbStatus from sessionStorage: ' + err) | ||
@@ -683,3 +718,3 @@ } | ||
tmpStatus = JSON.parse($('#zzbStatus').attr('status')) | ||
} catch(err) { | ||
} catch (err) { | ||
console.log('unable to parse zzbStatus from embedded attribute in #zzbStatus: ' + err) | ||
@@ -691,3 +726,3 @@ } | ||
} | ||
} | ||
} | ||
} | ||
@@ -702,10 +737,9 @@ | ||
zzb.ajax.postJSON( | ||
{ | ||
zzb.ajax.postJSON({ | ||
url: '/zzb/status', | ||
data: options | ||
}) | ||
.then(function(rob){ | ||
.then(function (rob) { | ||
if (rob.errs) { | ||
callback && callback(rob.errs, tmpStatus); | ||
callback && callback(rob.errs, tmpStatus) | ||
} else { | ||
@@ -718,3 +752,3 @@ if (setSelf) { | ||
}) | ||
.catch(function(err){ | ||
.catch(function (err) { | ||
console.log('failed to retrieve zzbStatus: using defaults') | ||
@@ -735,34 +769,37 @@ callback && callback(zzb.types.sanitizeErrors(err), tmpStatus) | ||
var _strings = function() {} | ||
var _strings = function () {} | ||
// ValueError :: String -> Error | ||
var formatValueError = function(message) { | ||
var err = new Error(message); | ||
err.name = 'ValueError'; | ||
return err; | ||
}; | ||
var formatValueError = function (message) { | ||
var err = new Error(message) | ||
err.name = 'ValueError' | ||
return err | ||
} | ||
// defaultTo :: a,a? -> a | ||
var formatDefaultTo = function(x, y) { | ||
return y == null ? x : y; | ||
}; | ||
var formatDefaultTo = function (x, y) { | ||
return y == null ? x : y | ||
} | ||
var formatLookup = function(obj, path) { | ||
var formatLookup = function (obj, path) { | ||
if (!/^\d+$/.test(path[0])) { | ||
path = ['0'].concat(path); | ||
path = ['0'].concat(path) | ||
} | ||
for (var idx = 0; idx < path.length; idx += 1) { | ||
var key = path[idx]; | ||
obj = typeof obj[key] === 'function' ? obj[key]() : obj[key]; | ||
var key = path[idx] | ||
obj = typeof obj[key] === 'function' ? obj[key]() : obj[key] | ||
} | ||
return obj; | ||
}; | ||
return obj | ||
} | ||
// https://github.com/davidchambers/string-format | ||
// create :: Object -> String,*... -> String | ||
var formatString = function(transformers) { | ||
return function(template) { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
var idx = 0; | ||
var state = 'UNDEFINED'; | ||
// zzb.strings.format('{0}, you have {1} mushroom{2}', 'Piggy', 2, 's') | ||
// zzb.strings.format('{0}, you have {1} mushroom{2}', ['Piggy', 2, 's']) | ||
// zzb.strings.format('{name}, you have {number} mushroom{ending}', {name: 'Piggy', number: 2, ending: 's'}) | ||
var formatString = function (transformers) { | ||
return function (template) { | ||
var args = Array.prototype.slice.call(arguments, 1) | ||
var idx = 0 | ||
var state = 'UNDEFINED' | ||
@@ -778,5 +815,5 @@ if (Array.isArray(args) && args.length > 0 && Array.isArray(args[0])) { | ||
/([{}])\1|[{](.*?)(?:!(.+?))?[}]/g, | ||
function(match, literal, key, xf) { | ||
function (match, literal, key, xf) { | ||
if (literal != null) { | ||
return literal; | ||
return literal | ||
} | ||
@@ -786,27 +823,27 @@ if (key.length > 0) { | ||
throw formatValueError('cannot switch from ' + | ||
'implicit to explicit numbering'); | ||
'implicit to explicit numbering') | ||
} | ||
state = 'EXPLICIT'; | ||
state = 'EXPLICIT' | ||
} else { | ||
if (state === 'EXPLICIT') { | ||
throw formatValueError('cannot switch from ' + | ||
'explicit to implicit numbering'); | ||
'explicit to implicit numbering') | ||
} | ||
state = 'IMPLICIT'; | ||
key = String(idx); | ||
idx += 1; | ||
state = 'IMPLICIT' | ||
key = String(idx) | ||
idx += 1 | ||
} | ||
var value = formatDefaultTo('', formatLookup(args, key.split('.'))); | ||
var value = formatDefaultTo('', formatLookup(args, key.split('.'))) | ||
if (xf == null) { | ||
return value; | ||
return value | ||
} else if (Object.prototype.hasOwnProperty.call(transformers, xf)) { | ||
return transformers[xf](value); | ||
return transformers[xf](value) | ||
} else { | ||
throw formatValueError('no transformer named "' + xf + '"'); | ||
throw formatValueError('no transformer named "' + xf + '"') | ||
} | ||
} | ||
); | ||
}; | ||
}; | ||
) | ||
} | ||
} | ||
@@ -830,13 +867,12 @@ _strings.prototype.format = formatString({}) | ||
**/ | ||
_strings.prototype.formatEmpty = function(template) { | ||
_strings.prototype.formatEmpty = function (template) { | ||
var args = Array.prototype.slice.call(arguments, 1) | ||
if (Array.isArray(args)) { | ||
return template.replace(/{(\d+)}/g, function (match, number) { | ||
return typeof args[number] != 'undefined' | ||
return typeof args[number] !== 'undefined' | ||
? args[number] | ||
: '' // match | ||
}) | ||
} else { | ||
return template.replace(/{((?:(?=([^{}]+|{{[^}]*}}))\2)*)}/g, function(match, key) { | ||
return template.replace(/{((?:(?=([^{}]+|{{[^}]*}}))\2)*)}/g, function (match, key) { | ||
// console.log(match + ' ' + key) | ||
@@ -863,3 +899,3 @@ return (args.length > 0 && args[0][key]) ? args[0][key] : '' // match | ||
*/ | ||
_strings.prototype.appendIfMoreThan = function(str, charsToAppend, ifMoreCharCount) { | ||
_strings.prototype.appendIfMoreThan = function (str, charsToAppend, ifMoreCharCount) { | ||
return ((str && (str.length > ifMoreCharCount)) ? str.substring(0, ifMoreCharCount) + charsToAppend : str) | ||
@@ -884,7 +920,7 @@ } | ||
*/ | ||
_strings.prototype.joinArrToCommas = function(arr, fieldName) { | ||
_strings.prototype.joinArrToCommas = function (arr, fieldName) { | ||
if (!arr || !Array.isArray(arr) || arr.length === 0) { | ||
return '' | ||
} | ||
return arr.map(arr, function(obj, idx){ | ||
return arr.map(arr, function (obj, idx) { | ||
var comma = '' | ||
@@ -918,3 +954,3 @@ if (idx < (arr.index - 1)) { | ||
*/ | ||
_strings.prototype.toPlural = function(word, number, options) { | ||
_strings.prototype.toPlural = function (word, number, options) { | ||
options = _.merge({forcePlural: false, suffix: null}, options) | ||
@@ -937,3 +973,3 @@ | ||
// client or server | ||
var _ = window._ | ||
// var _ = require('lodash') | ||
@@ -946,10 +982,10 @@ // --------------------------------------------------- | ||
_types.prototype.escapeJqueryId = function(id, prefix) { | ||
_types.prototype.escapeJqueryId = function (id, prefix) { | ||
// ref: https://learn.jquery.com/using-jquery-core/faq/how-do-i-select-an-element-by-an-id-that-has-characters-used-in-css-notation/ | ||
prefix = (prefix == null ? '#' : prefix) | ||
return prefix + id.replace( /(:|\.|\[|\]|,)/g, "\\$1" ) | ||
return prefix + id.replace(/(:|\.|\[|\]|,)/g, '\\$1') | ||
} | ||
// http://stackoverflow.com/questions/23252173/get-html-escaped-text-from-textarea-with-jquery | ||
_types.prototype.escapeHtml = function(unsafe) { | ||
_types.prototype.escapeHtml = function (unsafe) { | ||
if (!unsafe) { | ||
@@ -959,7 +995,7 @@ return '' | ||
return unsafe | ||
.replace(/&/g, "&") | ||
.replace(/</g, "<") | ||
.replace(/>/g, ">") | ||
.replace(/"/g, """) | ||
.replace(/'/g, "'") | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, ''') | ||
} | ||
@@ -981,3 +1017,3 @@ } | ||
_types.prototype.isNumber = function (o) { | ||
return !isNaN(o - 0) && o !== null && o !== "" && o !== false | ||
return !isNaN(o - 0) && o !== null && o !== '' && o !== false | ||
} | ||
@@ -1021,2 +1057,3 @@ | ||
exports.types = _types | ||
},{}],8:[function(require,module,exports){ | ||
@@ -1030,3 +1067,3 @@ // client or server | ||
var _uib = function() {} | ||
var _uib = function () {} | ||
@@ -1042,3 +1079,3 @@ /** | ||
var template = '<div id="panelGroup_{id}" class="panel-group {classPanelGroup}">{innerHtml}</div>' | ||
return zzb.strings.format(template, options) // _.formatObj(template, uie); | ||
return zzb.strings.format(template, options) // _.formatObj(template, uie) | ||
} | ||
@@ -1055,3 +1092,3 @@ | ||
var template = '<div id="panelBody_{id}" class="panel-body {classPanelBody}">{innerHtml}</div>' | ||
return zzb.strings.format(template, options) // _.formatObj(template, uie); | ||
return zzb.strings.format(template, options) // _.formatObj(template, uie) | ||
} | ||
@@ -1068,15 +1105,20 @@ | ||
_uib.prototype.createPanel = function (options) { | ||
options = _.merge({id: zzb.uuid.newV4(), className: '', attributesExtra: '', | ||
classPanelHeading: '', name: '', | ||
classPanelBody: '', innerHtml: ''}, options) | ||
options = _.merge({id: zzb.uuid.newV4(), | ||
className: '', | ||
attributesExtra: '', | ||
classPanelHeading: '', | ||
name: '', | ||
classPanelBody: '', | ||
innerHtml: '' | ||
}, options) | ||
var template = '<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(options) //'<div class="panel-body">{innerHtml}</div>' | ||
+ '</div>' | ||
+ '</div>' | ||
return zzb.strings.format(template, options) // _.formatObj(template, uie); | ||
var template = '<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(options) + // '<div class="panel-body">{innerHtml}</div>' | ||
'</div>' + | ||
'</div>' | ||
return zzb.strings.format(template, options) // _.formatObj(template, uie) | ||
} | ||
@@ -1094,31 +1136,38 @@ | ||
_uib.prototype.createPanelCollapsible = function (options) { | ||
options = _.merge({id: zzb.uuid.newV4(), className: '', attributesExtra: '', name: '', | ||
classPanelBody: '', innerHtml: '', | ||
isPanelCollapsed: false, classNamePanelCollapsed: '', | ||
titleHtmlExtra: '', titleHtmlExtraRight: ''}, options) | ||
options = _.merge({id: zzb.uuid.newV4(), | ||
className: '', | ||
attributesExtra: '', | ||
name: '', | ||
classPanelBody: '', | ||
innerHtml: '', | ||
isPanelCollapsed: false, | ||
classNamePanelCollapsed: '', | ||
titleHtmlExtra: '', | ||
titleHtmlExtraRight: '' | ||
}, options) | ||
if (options.isPanelCollapsed) { | ||
options._panelCollapsedClass1 ='collapsed'; | ||
options._panelCollapsedClass2 =''; | ||
options._panelCollapsedClass1 = 'collapsed' | ||
options._panelCollapsedClass2 = '' | ||
} else { | ||
options._panelCollapsedClass1 =''; | ||
options._panelCollapsedClass2 ='in'; | ||
options._panelCollapsedClass1 = '' | ||
options._panelCollapsedClass2 = 'in' | ||
} | ||
var template = '<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(options) //'<div class="panel-body">{innerHtml}</div>' | ||
+ '</div>' | ||
+ '</div>' | ||
var template = '<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(options) + // '<div class="panel-body">{innerHtml}</div>' | ||
'</div>' + | ||
'</div>' | ||
//var test = _.formatObj(template, uie); | ||
//console.log(test) | ||
//return test; | ||
// var test = _.formatObj(template, uie) | ||
// console.log(test) | ||
// return test | ||
return zzb.strings.format(template, options) // _.formatObj(template, uie) | ||
@@ -1137,28 +1186,35 @@ } | ||
_uib.prototype.createPanelCollapsibleBegin = function (options) { | ||
options = _.merge({id: zzb.uuid.newV4(), className: '', attributesExtra: '', name: '', | ||
classPanelBody: '', innerHtml: '', | ||
isPanelCollapsed: false, classNamePanelCollapsed: '', | ||
titleHtmlExtra: '', titleHtmlExtraRight: ''}, options) | ||
options = _.merge({id: zzb.uuid.newV4(), | ||
className: '', | ||
attributesExtra: '', | ||
name: '', | ||
classPanelBody: '', | ||
innerHtml: '', | ||
isPanelCollapsed: false, | ||
classNamePanelCollapsed: '', | ||
titleHtmlExtra: '', | ||
titleHtmlExtraRight: '' | ||
}, options) | ||
if (options.isPanelCollapsed) { | ||
options._panelCollapsedClass1 ='collapsed'; | ||
options._panelCollapsedClass2 =''; | ||
options._panelCollapsedClass1 = 'collapsed' | ||
options._panelCollapsedClass2 = '' | ||
} else { | ||
options._panelCollapsedClass1 =''; | ||
options._panelCollapsedClass2 ='in'; | ||
options._panelCollapsedClass1 = '' | ||
options._panelCollapsedClass2 = 'in' | ||
} | ||
var template = '<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}">' | ||
var template = '<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}">' | ||
return zzb.strings.format(template, options) // _.formatObj(template, uie) | ||
}; | ||
} | ||
@@ -1171,6 +1227,7 @@ /** | ||
_uib.prototype.createPanelCollapsibleEnd = function () { | ||
return '</div></div></div>'; | ||
}; | ||
return '</div></div></div>' | ||
} | ||
exports.uib = _uib | ||
},{}],9:[function(require,module,exports){ | ||
@@ -1205,3 +1262,3 @@ // client or server | ||
d = Math.floor(d / 16) | ||
return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16) | ||
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16) | ||
}) | ||
@@ -1289,3 +1346,3 @@ } | ||
} else { | ||
if (this.parent.getId() != this.data[parentField]) { | ||
if (this.parent.getId() !== this.data[parentField]) { | ||
this.data[parentField] = this.parent.getId() | ||
@@ -1299,15 +1356,15 @@ this.isDirty = true | ||
this.getData = function() { | ||
this.getData = function () { | ||
return this.data | ||
} | ||
this.getId = function() { | ||
this.getId = function () { | ||
return this.data[pkField] | ||
} | ||
this.getParent = function() { | ||
this.getParent = function () { | ||
return this.parent | ||
} | ||
this.getRoot = function() { | ||
this.getRoot = function () { | ||
if (this.parent === null) { | ||
@@ -1320,5 +1377,5 @@ return this | ||
this.removeChild = function(targetId) { | ||
this.removeChild = function (targetId) { | ||
if (this.children.length > 0) { | ||
var index = _.findIndex(this.children, function(obj){return obj.getId() === targetId}) | ||
var index = _.findIndex(this.children, function (obj) { return obj.getId() === targetId }) | ||
if (index > -1) { | ||
@@ -1330,6 +1387,6 @@ this.children.splice(index, 1) | ||
this.addChild = function(data, newPKField, newParentField) { | ||
this.addChild = function (data, newPKField, newParentField) { | ||
// already been added? | ||
var $this = this | ||
var child = _.find(this.children, function(ch) { | ||
var child = _.find(this.children, function (ch) { | ||
return ch.getId() === data[$this.pkField] | ||
@@ -1341,4 +1398,4 @@ }) | ||
child = new this.nodeConstructor(this, data, | ||
(newPKField ? newPKField : this.pkField), | ||
(newParentField ? newParentField : this.parentField) | ||
newPKField || this.pkField, | ||
newParentField || this.parentField | ||
) | ||
@@ -1350,10 +1407,9 @@ this.children.push(child) | ||
this.findChild = function(targetId, doSearchItems) { | ||
this.findChild = function (targetId, doSearchItems) { | ||
var hit = null | ||
if (this.getId() === targetId){ | ||
if (this.getId() === targetId) { | ||
hit = this | ||
} | ||
else { | ||
} else { | ||
if (doSearchItems && this.items.length > 0) { | ||
_.each(this.items, function(item){ | ||
_.each(this.items, function (item) { | ||
if (item.getId() === targetId) { | ||
@@ -1366,3 +1422,3 @@ hit = item | ||
if (!hit && this.children.length > 0) { | ||
_.each(this.children, function(ch){ | ||
_.each(this.children, function (ch) { | ||
hit = ch.findChild(targetId, doSearchItems) | ||
@@ -1385,10 +1441,10 @@ if (hit) { | ||
this.getItemOwner = function() { | ||
this.getItemOwner = function () { | ||
return this.itemOwner | ||
} | ||
this.addItem = function(data, newPKField, newParentField) { | ||
this.addItem = function (data, newPKField, newParentField) { | ||
// already been added? | ||
var $this = this | ||
var item = _.find(this.items, function(it) { | ||
var item = _.find(this.items, function (it) { | ||
return it.getId() === data[$this.pkField] | ||
@@ -1406,5 +1462,5 @@ }) | ||
this.removeItem = function(targetId) { | ||
this.removeItem = function (targetId) { | ||
if (this.items.length > 0) { | ||
var index = _.findIndex(this.items, function(obj){return obj.getId() === targetId}) | ||
var index = _.findIndex(this.items, function (obj) { return obj.getId() === targetId }) | ||
if (index > -1) { | ||
@@ -1416,6 +1472,6 @@ this.items.splice(index, 1) | ||
this.findItem = function(targetId) { | ||
this.findItem = function (targetId) { | ||
var hit = null | ||
if (this.items.length > 0) { | ||
_.each(this.items, function(item) { | ||
_.each(this.items, function (item) { | ||
if (item.getId() === targetId) { | ||
@@ -1428,3 +1484,3 @@ hit = item | ||
if (!hit && this.children.length > 0) { | ||
_.each(this.children, function(ch){ | ||
_.each(this.children, function (ch) { | ||
hit = ch.findItem(targetId) | ||
@@ -1439,3 +1495,3 @@ if (hit) { | ||
this.sortChildren = function(fn, noDeepSort) { | ||
this.sortChildren = function (fn, noDeepSort) { | ||
if (!fn) { | ||
@@ -1454,3 +1510,3 @@ return | ||
this.sortItems = function(fn, fnChildren, noDeepSort) { | ||
this.sortItems = function (fn, fnChildren, noDeepSort) { | ||
if (!fn) { | ||
@@ -1462,3 +1518,3 @@ return | ||
if (fnChildren) { | ||
_.each(this.items, function(item){ | ||
_.each(this.items, function (item) { | ||
if (!noDeepSort) { | ||
@@ -1472,3 +1528,3 @@ item.sortChildren(fnChildren, noDeepSort) | ||
this.getLevelDeep = function() { | ||
this.getLevelDeep = function () { | ||
var level = 0 | ||
@@ -1482,3 +1538,3 @@ if (this.parent) { | ||
this.branchCallFunction = function(fn, startRootFirst, tryItemOwner) { | ||
this.branchCallFunction = function (fn, startRootFirst, tryItemOwner) { | ||
if (!startRootFirst) { | ||
@@ -1488,6 +1544,6 @@ fn && fn(this) | ||
if (this.parent) { | ||
this.parent.branchCallFunction(fn,startRootFirst,tryItemOwner) | ||
this.parent.branchCallfunction(fn, startRootFirst, tryItemOwner) | ||
} | ||
if (tryItemOwner && this.itemOwner) { | ||
this.itemOwner.branchCallFunction(fn, startRootFirst, tryItemOwner) | ||
this.itemOwner.branchCallfunction(fn, startRootFirst, tryItemOwner) | ||
} | ||
@@ -1499,6 +1555,6 @@ if (startRootFirst) { | ||
this.branchCallFunctionChildren = function(fn, tryItems) { | ||
this.branchCallFunctionChildren = function (fn, tryItems) { | ||
fn && fn(this) | ||
if (this.children.length > 0) { | ||
_.each(this.children, function(ch){ | ||
_.each(this.children, function (ch) { | ||
ch.branchCallFunctionChildren(fn, tryItems) | ||
@@ -1508,3 +1564,3 @@ }) | ||
if (tryItems && this.items.length > 0) { | ||
_.each(this.items, function(item) { | ||
_.each(this.items, function (item) { | ||
item.branchCallFunctionChildren(fn, tryItems) | ||
@@ -1517,2 +1573,3 @@ }) | ||
module.exports.zzNode = zzNode | ||
},{}],11:[function(require,module,exports){ | ||
@@ -1537,9 +1594,10 @@ if (typeof jQuery === 'undefined') { | ||
} else if (typeof define === 'function' && define.amd) { | ||
define(factory); | ||
define(factory) | ||
} else if (typeof module === 'object' && module.exports) { | ||
module.exports = factory(); | ||
module.exports = factory() | ||
} else { | ||
throw new Error('could not locate global cache object in which to create zzb') | ||
throw new Error('could not locate global cache object in which to create zzb') | ||
} | ||
}(this, (function () { 'use strict'; | ||
}(this, (function () { | ||
'use strict' | ||
@@ -1546,0 +1604,0 @@ // --------------------------------------------------- |
//! zzb.js | ||
//! version: 0.2.7 | ||
//! version: 0.2.8 | ||
//! author(s): Jaret Pfluger | ||
@@ -4,0 +4,0 @@ //! license: MIT |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
'use strict' | ||
@@ -19,7 +19,7 @@ var gulp = require('gulp') | ||
var literalify = browserifyTools.makeRequireTransform('literalify', {excludeExtensions: ['json']}, function(args, opts, cb) { | ||
var literalify = browserifyTools.makeRequireTransform('literalify', {excludeExtensions: ['json']}, function (args, opts, cb) { | ||
if (opts.config && args[0] in opts.config) { | ||
return cb(null, opts.config[args[0]]); | ||
return cb(null, opts.config[args[0]]) | ||
} else { | ||
return cb(); | ||
return cb() | ||
} | ||
@@ -37,49 +37,50 @@ }) | ||
var paths = { | ||
dist: path.join(__dirname, 'dist'), | ||
js: './src/zzb.js', | ||
distJS: './dist/zzb.js', | ||
minJS: './dist/zzb.min.js' | ||
dist: path.join(__dirname, 'dist'), | ||
js: './src/zzb.js', | ||
distJS: './dist/zzb.js', | ||
minJS: './dist/zzb.min.js' | ||
} | ||
gulp.task('clean-js', function (cb) { | ||
rimraf(paths.dist, function() { | ||
fse.ensureDir(paths.dist, cb) | ||
}); | ||
rimraf(paths.dist, function () { | ||
fse.ensureDir(paths.dist, cb) | ||
}) | ||
}) | ||
gulp.task('lint-js', function() { | ||
return gulp.src([paths.js], {base: '.'}) | ||
.pipe(eslint({})) | ||
.pipe(eslint.format()) | ||
.pipe(eslint.failAfterError()) | ||
gulp.task('lint-js', function () { | ||
return gulp.src([paths.js], {base: '.'}) | ||
.pipe(eslint({})) | ||
.pipe(eslint.format()) | ||
.pipe(eslint.failAfterError()) | ||
}) | ||
gulp.task('dist-js', function (cb) { | ||
// http://blog.revathskumar.com/2016/02/browserify-with-gulp.html | ||
var appBundler = browserify({ | ||
entries: paths.js, | ||
transform: [[literalify.configure({ | ||
'jQuery': 'window.$', | ||
'BootstrapDialog': 'window.BootstrapDialog', | ||
'lodash': 'window._' | ||
})]], | ||
cache: {}, | ||
packageCache: {}, | ||
fullPaths: false | ||
}) | ||
// http://blog.revathskumar.com/2016/02/browserify-with-gulp.html | ||
var appBundler = browserify({ | ||
entries: paths.js, | ||
transform: [[literalify.configure({ | ||
'jQuery': 'window.$', | ||
'BootstrapDialog': 'window.BootstrapDialog', | ||
'lodash': 'window._' | ||
})]], | ||
cache: {}, packageCache: {}, fullPaths: false | ||
}); | ||
appBundler | ||
.bundle() | ||
.pipe(source(paths.distJS)) | ||
.pipe(buffer()) | ||
.pipe(insert.prepend(pckInfo.join('\n'))) | ||
.pipe(gulp.dest('.')) | ||
cb() | ||
appBundler | ||
.bundle() | ||
.pipe(source(paths.distJS)) | ||
.pipe(buffer()) | ||
.pipe(insert.prepend(pckInfo.join('\n'))) | ||
.pipe(gulp.dest('.')) | ||
cb() | ||
}) | ||
gulp.task('minify-js', function (cb) { | ||
return gulp.src([paths.distJS], {base: '.'}) | ||
.pipe(concat(paths.minJS)) | ||
.pipe(uglify()) | ||
.pipe(insert.prepend(pckInfo.join('\n'))) | ||
.pipe(gulp.dest('.')); | ||
return gulp.src([paths.distJS], {base: '.'}) | ||
.pipe(concat(paths.minJS)) | ||
.pipe(uglify()) | ||
.pipe(insert.prepend(pckInfo.join('\n'))) | ||
.pipe(gulp.dest('.')) | ||
}) | ||
@@ -86,0 +87,0 @@ |
{ | ||
"name": "zazzy-browser", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"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.", | ||
@@ -20,4 +20,6 @@ "engines": { | ||
"scripts": { | ||
"dist": "gulp default", | ||
"test": "mocha", | ||
"dist": "gulp default" | ||
"mocha": "mocha", | ||
"syntax": "standard" | ||
}, | ||
@@ -35,2 +37,3 @@ "keywords": [ | ||
"mocha": "^3.4.2", | ||
"standard": "^10.0.2", | ||
"gulp": "^3.9.1", | ||
@@ -47,3 +50,6 @@ "rimraf": "^2.6.1", | ||
"browserify-transform-tools": "^1.7.0" | ||
}, | ||
"standard": { | ||
"globals": [ "zzb", "_", "$", "jQuery", "define", "sessionStorage" ] | ||
} | ||
} |
@@ -13,3 +13,3 @@ // client only | ||
this.ajax = function (options) { | ||
return new Promise(function (fulfill, reject) { | ||
return new Promise(function (resolve, reject) { | ||
$.ajax(options) | ||
@@ -19,3 +19,3 @@ .done(function (data, textStatus, jqXHR) { | ||
if (options.RAWRETURN) { | ||
return fulfill(data) | ||
return resolve(data) | ||
} | ||
@@ -29,3 +29,3 @@ | ||
// ? | ||
//if (jqXHR.status != '200') {} | ||
// if (jqXHR.status != '200') {} | ||
@@ -38,3 +38,4 @@ if (!jqXHR.responseJSON) { | ||
if (data.redirect && data.redirect.length > 0) { | ||
return window.location.href = data.redirect | ||
window.location.href = data.redirect | ||
return | ||
} | ||
@@ -56,3 +57,3 @@ | ||
data.errs = zzb.rob.sanitizeErrors(data.errs) | ||
data.err = null | ||
data.err = null | ||
} | ||
@@ -70,3 +71,3 @@ } | ||
// pass in self | ||
data.recs = zzb.rob.sanitizeRecords(data) | ||
data.recs = zzb.rob.sanitizeRecords(data) | ||
} | ||
@@ -77,3 +78,3 @@ } | ||
data.first = function () { | ||
return (data.recs && Array.isArray(data.recs) && data.recs.length > 0 ? data.recs[0] : null) | ||
return (data.recs && Array.isArray(data.recs) && data.recs.length > 0 ? data.recs[0] : null) | ||
} | ||
@@ -91,13 +92,13 @@ data.find = function (key, value) { | ||
data.length = function () { | ||
return (data.recs && Array.isArray(data.recs) ? data.recs.length : 0) | ||
return (data.recs && Array.isArray(data.recs) ? data.recs.length : 0) | ||
} | ||
fulfill(data) | ||
resolve(data) | ||
}) | ||
.fail(function (jqXHR, textStatus, errorThrown) { | ||
if (jqXHR.responseJSON) { | ||
if (data.redirect) { | ||
return window.location.href = data.redirect | ||
} | ||
} | ||
// if (jqXHR.responseJSON) { | ||
// if (data.redirect) { | ||
// return window.location.href = data.redirect | ||
// } | ||
// } | ||
reject(errorThrown) | ||
@@ -113,14 +114,14 @@ console.log(errorThrown) | ||
_ajax.prototype.get = function (options) { | ||
options.type = 'GET' | ||
options.contentType = 'application/json; charset=UTF-8' | ||
options.data = JSON.stringify(options.data) | ||
return this.ajax(options) | ||
options.type = 'GET' | ||
options.contentType = 'application/json; charset=UTF-8' | ||
options.data = JSON.stringify(options.data) | ||
return this.ajax(options) | ||
} | ||
_ajax.prototype.getJSON = function (options) { | ||
options.type = 'GET' | ||
options.dataType = 'json' | ||
options.contentType = 'application/json; charset=UTF-8' | ||
options.data = JSON.stringify(options.data) | ||
return this.ajax(options) | ||
options.type = 'GET' | ||
options.dataType = 'json' | ||
options.contentType = 'application/json; charset=UTF-8' | ||
options.data = JSON.stringify(options.data) | ||
return this.ajax(options) | ||
} | ||
@@ -127,0 +128,0 @@ |
@@ -20,5 +20,5 @@ // client only | ||
var _dialogs = function() {} | ||
var _dialogs = function () {} | ||
_dialogs.prototype.showMessage = function(options) { | ||
_dialogs.prototype.showMessage = function (options) { | ||
options = _.merge({ | ||
@@ -40,9 +40,9 @@ type: BootstrapDialog.TYPE_DEFAULT, | ||
action: function (dialogRef) { | ||
dialogRef.close(); | ||
dialogRef.close() | ||
} | ||
}] | ||
}); | ||
}; | ||
}) | ||
} | ||
_dialogs.prototype.showMessageChoice = function(options) { | ||
_dialogs.prototype.showMessageChoice = function (options) { | ||
options = _.merge({ | ||
@@ -75,3 +75,3 @@ type: BootstrapDialog.TYPE_DEFAULT, | ||
} else { | ||
options.onButtonLeftClick(function(err) { | ||
options.onButtonLeftClick(function (err) { | ||
if (!err) { | ||
@@ -92,3 +92,3 @@ dialogRef.close() | ||
} else { | ||
options.onButtonRightClick(function(err) { | ||
options.onButtonRightClick(function (err) { | ||
if (!err) { | ||
@@ -113,4 +113,4 @@ dialogRef.close() | ||
_dialogs.prototype.handleError = function(options) { | ||
//this.dialogs.handleError({log: 'failed to retrieve login dialog form: ' + err, title: 'Unknown error', message: 'An unknown communications error occurred while retrieving the login form. Please check your connection settings and try again.'}) | ||
_dialogs.prototype.handleError = function (options) { | ||
// this.dialogs.handleError({log: 'failed to retrieve login dialog form: ' + err, title: 'Unknown error', message: 'An unknown communications error occurred while retrieving the login form. Please check your connection settings and try again.'}) | ||
options = _.merge({log: null, title: '', message: null, errs: null}, options) | ||
@@ -126,3 +126,3 @@ | ||
_.each(options.errs, function(err, index) { | ||
_.each(options.errs, function (err, index) { | ||
if (err.message && zzb.types.isNonEmptyString(err.message)) { | ||
@@ -134,3 +134,2 @@ arrHtml.push(zzb.strings.format('<div>{0}</div>', err.message)) | ||
if (arrHtml.length > 0) { | ||
if (!options.message) { | ||
@@ -137,0 +136,0 @@ options.message = '' |
@@ -11,6 +11,5 @@ // client only | ||
var _forms = function() {} | ||
var _forms = function () {} | ||
var renderHtml_Popover = function (errs, options) { | ||
var arrHtml = [] | ||
@@ -28,4 +27,3 @@ var arrPopOver = [] | ||
_.each(errs, function(err, index) { | ||
_.each(errs, function (err, index) { | ||
if (!err.field) { | ||
@@ -45,3 +43,3 @@ err.field = '_system' | ||
// only once | ||
if (index == 0) { | ||
if (index === 0) { | ||
arrHtml.push(zzb.strings.format('<span class="glyphicon {0} {1}"></span>', typeFormat.glyph, typeFormat.textClass)) | ||
@@ -63,6 +61,6 @@ } | ||
reho.$elem.popover({ | ||
trigger:'hover', | ||
animation: false, | ||
content: reho.contentPopOver | ||
}); | ||
trigger: 'hover', | ||
animation: false, | ||
content: reho.contentPopOver | ||
}) | ||
} | ||
@@ -72,5 +70,5 @@ } | ||
_forms.prototype.displayUIErrors = function(options, callback) { | ||
options = _.merge({selector: null, $form: null, | ||
_forms.prototype.displayUIErrors = function (options, callback) { | ||
options = _.merge({selector: null, | ||
$form: null, | ||
selectorField: '.zzb-form-field', | ||
@@ -81,3 +79,3 @@ attrFieldname: 'zzb-fieldname', | ||
selectorError: '.zzb-form-field-error', | ||
errs: null, | ||
errs: null, | ||
err: null, | ||
@@ -96,6 +94,5 @@ hideWhenNoError: false, // this always shows the 'success' checkmark | ||
var success = false; | ||
var success = false | ||
if (options.renderErrorHtml) { | ||
if (options.$form) { | ||
@@ -108,9 +105,9 @@ options.selector = null // not required | ||
if (!options.$form || options.$form.length === 0) { | ||
return callback && callback(success); | ||
return callback && callback(success) | ||
} | ||
if (options.err && !Array.isArray(options.err)){ | ||
if (options.err && !Array.isArray(options.err)) { | ||
options.errs = [zzb.rob.createError(options.err)] | ||
options.err = null | ||
} else if (options.errs && !Array.isArray(options.errs)){ | ||
} else if (options.errs && !Array.isArray(options.errs)) { | ||
options.errs = [zzb.rob.createError(options.errs)] | ||
@@ -140,3 +137,3 @@ options.err = null | ||
console.log('discovered an error field and its parent field (eg zzb-form-field) but the fieldname attribute is empty (eg zzb-fieldname="")') | ||
return true | ||
return true | ||
} | ||
@@ -179,28 +176,2 @@ | ||
/* | ||
self.forms.toListFromErrors = function(errs) { | ||
var arrHtml = []; | ||
if (errs && Array.isArray(errs)) { | ||
var arrHtmlSystem = []; | ||
arrHtml.push('<ul class="panelErrorList">') | ||
_.each(errs, function(err) { | ||
if (err.field === '_system') { | ||
arrHtmlSystem.push(err.message) | ||
} else if (err.field) { | ||
arrHtml.push(_.formatArr('<li><strong>{0}</strong>: {1}</li>', _.capitalize(err.field.toLowerCase()), err.message)) | ||
} else { | ||
arrHtmlSystem.push(err.message) | ||
} | ||
}); | ||
if (arrHtmlSystem.length > 0) { | ||
arrHtml.push(_.formatArr('<li><strong>System Errors</strong>: {0}</li>', arrHtmlSystem.join(' '))) | ||
} | ||
arrHtml.push('</ul>') | ||
} | ||
return arrHtml.join(''); | ||
};*/ | ||
exports.forms = _forms |
@@ -8,3 +8,3 @@ // client or server | ||
var _rob = function() {} | ||
var _rob = function () {} | ||
@@ -47,3 +47,3 @@ // reduce the error array to an object | ||
case 'debug': | ||
options.isErr = false | ||
options.isErr = false | ||
break | ||
@@ -56,3 +56,3 @@ default: | ||
return options | ||
return options | ||
} | ||
@@ -65,3 +65,3 @@ | ||
return mergeErrorDefaults() | ||
} | ||
} | ||
if (zzb.types.isNonEmptyString(options1)) { | ||
@@ -85,3 +85,3 @@ return mergeErrorDefaults(_.merge({message: options1}, options2)) | ||
} | ||
if (!Array.isArray(errs)) { | ||
@@ -106,6 +106,70 @@ newErrs = [createError(errs)] | ||
return [recs] | ||
} | ||
} | ||
return recs | ||
} | ||
_rob.prototype.toListErrs = function (errs, defaultFormat, fieldsTemplate, systemTemplate) { | ||
var arrFields = [] | ||
var arrSystem = [] | ||
defaultFormat = defaultFormat || 'text' | ||
function getSystem (err) { | ||
if (systemTemplate) { | ||
return zzb.strings.format(systemTemplate, err.message) | ||
} else { | ||
if (defaultFormat === 'html') { | ||
return zzb.strings.format('<li>{0}</li>', err.message) | ||
} else { | ||
return zzb.strings.format('System: {0}', err.message) | ||
} | ||
} | ||
} | ||
function getField (err) { | ||
var title = err.title | ||
if (!err.title) { | ||
title = err.field // _.capitalize( | ||
} | ||
if (fieldsTemplate) { | ||
return zzb.strings.format(fieldsTemplate, title, err.message) | ||
} else { | ||
if (defaultFormat === 'html') { | ||
return zzb.strings.format('<li><strong>{0}</strong>: {1}</li>', title, err.message) | ||
} else { | ||
return zzb.strings.format('{0}: {1}', title, err.message) | ||
} | ||
} | ||
} | ||
if (errs && Array.isArray(errs) && errs.length > 0) { | ||
_.each(errs, function (err) { | ||
if (err.system === '_system') { | ||
arrSystem.push(getSystem(err)) | ||
} else if (err.field) { | ||
arrSystem.push(getField(err)) | ||
} else { | ||
arrSystem.push(getSystem(err)) | ||
} | ||
}) | ||
} | ||
return { | ||
system: arrSystem, | ||
fields: arrFields, | ||
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()) | ||
} | ||
} | ||
} | ||
exports.rob = _rob |
@@ -19,3 +19,3 @@ // client only | ||
var _status = function() { | ||
var _status = function () { | ||
this.zzbStatus = null | ||
@@ -38,7 +38,7 @@ } | ||
// Try local storage first (if top-level page supports it) -> this function will delete it, if found | ||
if (typeof(Storage) !== "undefined" && sessionStorage.zzbStatus) { | ||
if (typeof Storage !== 'undefined' && sessionStorage.zzbStatus) { | ||
try { | ||
// using sessionStorage (not localStorage) | ||
tmpStatus = JSON.parse(sessionStorage.getItem('zzbStatus')) | ||
} catch(err) { | ||
} catch (err) { | ||
console.log('unable to parse zzbStatus from sessionStorage: ' + err) | ||
@@ -59,3 +59,3 @@ } | ||
tmpStatus = JSON.parse($('#zzbStatus').attr('status')) | ||
} catch(err) { | ||
} catch (err) { | ||
console.log('unable to parse zzbStatus from embedded attribute in #zzbStatus: ' + err) | ||
@@ -67,3 +67,3 @@ } | ||
} | ||
} | ||
} | ||
} | ||
@@ -78,10 +78,9 @@ | ||
zzb.ajax.postJSON( | ||
{ | ||
zzb.ajax.postJSON({ | ||
url: '/zzb/status', | ||
data: options | ||
}) | ||
.then(function(rob){ | ||
.then(function (rob) { | ||
if (rob.errs) { | ||
callback && callback(rob.errs, tmpStatus); | ||
callback && callback(rob.errs, tmpStatus) | ||
} else { | ||
@@ -94,3 +93,3 @@ if (setSelf) { | ||
}) | ||
.catch(function(err){ | ||
.catch(function (err) { | ||
console.log('failed to retrieve zzbStatus: using defaults') | ||
@@ -97,0 +96,0 @@ callback && callback(zzb.types.sanitizeErrors(err), tmpStatus) |
@@ -8,34 +8,37 @@ // client or server | ||
var _strings = function() {} | ||
var _strings = function () {} | ||
// ValueError :: String -> Error | ||
var formatValueError = function(message) { | ||
var err = new Error(message); | ||
err.name = 'ValueError'; | ||
return err; | ||
}; | ||
var formatValueError = function (message) { | ||
var err = new Error(message) | ||
err.name = 'ValueError' | ||
return err | ||
} | ||
// defaultTo :: a,a? -> a | ||
var formatDefaultTo = function(x, y) { | ||
return y == null ? x : y; | ||
}; | ||
var formatDefaultTo = function (x, y) { | ||
return y == null ? x : y | ||
} | ||
var formatLookup = function(obj, path) { | ||
var formatLookup = function (obj, path) { | ||
if (!/^\d+$/.test(path[0])) { | ||
path = ['0'].concat(path); | ||
path = ['0'].concat(path) | ||
} | ||
for (var idx = 0; idx < path.length; idx += 1) { | ||
var key = path[idx]; | ||
obj = typeof obj[key] === 'function' ? obj[key]() : obj[key]; | ||
var key = path[idx] | ||
obj = typeof obj[key] === 'function' ? obj[key]() : obj[key] | ||
} | ||
return obj; | ||
}; | ||
return obj | ||
} | ||
// https://github.com/davidchambers/string-format | ||
// create :: Object -> String,*... -> String | ||
var formatString = function(transformers) { | ||
return function(template) { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
var idx = 0; | ||
var state = 'UNDEFINED'; | ||
// zzb.strings.format('{0}, you have {1} mushroom{2}', 'Piggy', 2, 's') | ||
// zzb.strings.format('{0}, you have {1} mushroom{2}', ['Piggy', 2, 's']) | ||
// zzb.strings.format('{name}, you have {number} mushroom{ending}', {name: 'Piggy', number: 2, ending: 's'}) | ||
var formatString = function (transformers) { | ||
return function (template) { | ||
var args = Array.prototype.slice.call(arguments, 1) | ||
var idx = 0 | ||
var state = 'UNDEFINED' | ||
@@ -51,5 +54,5 @@ if (Array.isArray(args) && args.length > 0 && Array.isArray(args[0])) { | ||
/([{}])\1|[{](.*?)(?:!(.+?))?[}]/g, | ||
function(match, literal, key, xf) { | ||
function (match, literal, key, xf) { | ||
if (literal != null) { | ||
return literal; | ||
return literal | ||
} | ||
@@ -59,27 +62,27 @@ if (key.length > 0) { | ||
throw formatValueError('cannot switch from ' + | ||
'implicit to explicit numbering'); | ||
'implicit to explicit numbering') | ||
} | ||
state = 'EXPLICIT'; | ||
state = 'EXPLICIT' | ||
} else { | ||
if (state === 'EXPLICIT') { | ||
throw formatValueError('cannot switch from ' + | ||
'explicit to implicit numbering'); | ||
'explicit to implicit numbering') | ||
} | ||
state = 'IMPLICIT'; | ||
key = String(idx); | ||
idx += 1; | ||
state = 'IMPLICIT' | ||
key = String(idx) | ||
idx += 1 | ||
} | ||
var value = formatDefaultTo('', formatLookup(args, key.split('.'))); | ||
var value = formatDefaultTo('', formatLookup(args, key.split('.'))) | ||
if (xf == null) { | ||
return value; | ||
return value | ||
} else if (Object.prototype.hasOwnProperty.call(transformers, xf)) { | ||
return transformers[xf](value); | ||
return transformers[xf](value) | ||
} else { | ||
throw formatValueError('no transformer named "' + xf + '"'); | ||
throw formatValueError('no transformer named "' + xf + '"') | ||
} | ||
} | ||
); | ||
}; | ||
}; | ||
) | ||
} | ||
} | ||
@@ -103,13 +106,12 @@ _strings.prototype.format = formatString({}) | ||
**/ | ||
_strings.prototype.formatEmpty = function(template) { | ||
_strings.prototype.formatEmpty = function (template) { | ||
var args = Array.prototype.slice.call(arguments, 1) | ||
if (Array.isArray(args)) { | ||
return template.replace(/{(\d+)}/g, function (match, number) { | ||
return typeof args[number] != 'undefined' | ||
return typeof args[number] !== 'undefined' | ||
? args[number] | ||
: '' // match | ||
}) | ||
} else { | ||
return template.replace(/{((?:(?=([^{}]+|{{[^}]*}}))\2)*)}/g, function(match, key) { | ||
return template.replace(/{((?:(?=([^{}]+|{{[^}]*}}))\2)*)}/g, function (match, key) { | ||
// console.log(match + ' ' + key) | ||
@@ -136,3 +138,3 @@ return (args.length > 0 && args[0][key]) ? args[0][key] : '' // match | ||
*/ | ||
_strings.prototype.appendIfMoreThan = function(str, charsToAppend, ifMoreCharCount) { | ||
_strings.prototype.appendIfMoreThan = function (str, charsToAppend, ifMoreCharCount) { | ||
return ((str && (str.length > ifMoreCharCount)) ? str.substring(0, ifMoreCharCount) + charsToAppend : str) | ||
@@ -157,7 +159,7 @@ } | ||
*/ | ||
_strings.prototype.joinArrToCommas = function(arr, fieldName) { | ||
_strings.prototype.joinArrToCommas = function (arr, fieldName) { | ||
if (!arr || !Array.isArray(arr) || arr.length === 0) { | ||
return '' | ||
} | ||
return arr.map(arr, function(obj, idx){ | ||
return arr.map(arr, function (obj, idx) { | ||
var comma = '' | ||
@@ -191,3 +193,3 @@ if (idx < (arr.index - 1)) { | ||
*/ | ||
_strings.prototype.toPlural = function(word, number, options) { | ||
_strings.prototype.toPlural = function (word, number, options) { | ||
options = _.merge({forcePlural: false, suffix: null}, options) | ||
@@ -194,0 +196,0 @@ |
// client or server | ||
var _ = require('lodash') | ||
// var _ = require('lodash') | ||
@@ -10,10 +10,10 @@ // --------------------------------------------------- | ||
_types.prototype.escapeJqueryId = function(id, prefix) { | ||
_types.prototype.escapeJqueryId = function (id, prefix) { | ||
// ref: https://learn.jquery.com/using-jquery-core/faq/how-do-i-select-an-element-by-an-id-that-has-characters-used-in-css-notation/ | ||
prefix = (prefix == null ? '#' : prefix) | ||
return prefix + id.replace( /(:|\.|\[|\]|,)/g, "\\$1" ) | ||
return prefix + id.replace(/(:|\.|\[|\]|,)/g, '\\$1') | ||
} | ||
// http://stackoverflow.com/questions/23252173/get-html-escaped-text-from-textarea-with-jquery | ||
_types.prototype.escapeHtml = function(unsafe) { | ||
_types.prototype.escapeHtml = function (unsafe) { | ||
if (!unsafe) { | ||
@@ -23,7 +23,7 @@ return '' | ||
return unsafe | ||
.replace(/&/g, "&") | ||
.replace(/</g, "<") | ||
.replace(/>/g, ">") | ||
.replace(/"/g, """) | ||
.replace(/'/g, "'") | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, ''') | ||
} | ||
@@ -45,3 +45,3 @@ } | ||
_types.prototype.isNumber = function (o) { | ||
return !isNaN(o - 0) && o !== null && o !== "" && o !== false | ||
return !isNaN(o - 0) && o !== null && o !== '' && o !== false | ||
} | ||
@@ -84,2 +84,2 @@ | ||
exports.types = _types | ||
exports.types = _types |
139
src/uib.js
@@ -8,3 +8,3 @@ // client or server | ||
var _uib = function() {} | ||
var _uib = function () {} | ||
@@ -20,3 +20,3 @@ /** | ||
var template = '<div id="panelGroup_{id}" class="panel-group {classPanelGroup}">{innerHtml}</div>' | ||
return zzb.strings.format(template, options) // _.formatObj(template, uie); | ||
return zzb.strings.format(template, options) // _.formatObj(template, uie) | ||
} | ||
@@ -33,3 +33,3 @@ | ||
var template = '<div id="panelBody_{id}" class="panel-body {classPanelBody}">{innerHtml}</div>' | ||
return zzb.strings.format(template, options) // _.formatObj(template, uie); | ||
return zzb.strings.format(template, options) // _.formatObj(template, uie) | ||
} | ||
@@ -46,15 +46,20 @@ | ||
_uib.prototype.createPanel = function (options) { | ||
options = _.merge({id: zzb.uuid.newV4(), className: '', attributesExtra: '', | ||
classPanelHeading: '', name: '', | ||
classPanelBody: '', innerHtml: ''}, options) | ||
options = _.merge({id: zzb.uuid.newV4(), | ||
className: '', | ||
attributesExtra: '', | ||
classPanelHeading: '', | ||
name: '', | ||
classPanelBody: '', | ||
innerHtml: '' | ||
}, options) | ||
var template = '<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(options) //'<div class="panel-body">{innerHtml}</div>' | ||
+ '</div>' | ||
+ '</div>' | ||
return zzb.strings.format(template, options) // _.formatObj(template, uie); | ||
var template = '<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(options) + // '<div class="panel-body">{innerHtml}</div>' | ||
'</div>' + | ||
'</div>' | ||
return zzb.strings.format(template, options) // _.formatObj(template, uie) | ||
} | ||
@@ -72,31 +77,38 @@ | ||
_uib.prototype.createPanelCollapsible = function (options) { | ||
options = _.merge({id: zzb.uuid.newV4(), className: '', attributesExtra: '', name: '', | ||
classPanelBody: '', innerHtml: '', | ||
isPanelCollapsed: false, classNamePanelCollapsed: '', | ||
titleHtmlExtra: '', titleHtmlExtraRight: ''}, options) | ||
options = _.merge({id: zzb.uuid.newV4(), | ||
className: '', | ||
attributesExtra: '', | ||
name: '', | ||
classPanelBody: '', | ||
innerHtml: '', | ||
isPanelCollapsed: false, | ||
classNamePanelCollapsed: '', | ||
titleHtmlExtra: '', | ||
titleHtmlExtraRight: '' | ||
}, options) | ||
if (options.isPanelCollapsed) { | ||
options._panelCollapsedClass1 ='collapsed'; | ||
options._panelCollapsedClass2 =''; | ||
options._panelCollapsedClass1 = 'collapsed' | ||
options._panelCollapsedClass2 = '' | ||
} else { | ||
options._panelCollapsedClass1 =''; | ||
options._panelCollapsedClass2 ='in'; | ||
options._panelCollapsedClass1 = '' | ||
options._panelCollapsedClass2 = 'in' | ||
} | ||
var template = '<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(options) //'<div class="panel-body">{innerHtml}</div>' | ||
+ '</div>' | ||
+ '</div>' | ||
var template = '<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(options) + // '<div class="panel-body">{innerHtml}</div>' | ||
'</div>' + | ||
'</div>' | ||
//var test = _.formatObj(template, uie); | ||
//console.log(test) | ||
//return test; | ||
// var test = _.formatObj(template, uie) | ||
// console.log(test) | ||
// return test | ||
return zzb.strings.format(template, options) // _.formatObj(template, uie) | ||
@@ -115,28 +127,35 @@ } | ||
_uib.prototype.createPanelCollapsibleBegin = function (options) { | ||
options = _.merge({id: zzb.uuid.newV4(), className: '', attributesExtra: '', name: '', | ||
classPanelBody: '', innerHtml: '', | ||
isPanelCollapsed: false, classNamePanelCollapsed: '', | ||
titleHtmlExtra: '', titleHtmlExtraRight: ''}, options) | ||
options = _.merge({id: zzb.uuid.newV4(), | ||
className: '', | ||
attributesExtra: '', | ||
name: '', | ||
classPanelBody: '', | ||
innerHtml: '', | ||
isPanelCollapsed: false, | ||
classNamePanelCollapsed: '', | ||
titleHtmlExtra: '', | ||
titleHtmlExtraRight: '' | ||
}, options) | ||
if (options.isPanelCollapsed) { | ||
options._panelCollapsedClass1 ='collapsed'; | ||
options._panelCollapsedClass2 =''; | ||
options._panelCollapsedClass1 = 'collapsed' | ||
options._panelCollapsedClass2 = '' | ||
} else { | ||
options._panelCollapsedClass1 =''; | ||
options._panelCollapsedClass2 ='in'; | ||
options._panelCollapsedClass1 = '' | ||
options._panelCollapsedClass2 = 'in' | ||
} | ||
var template = '<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}">' | ||
var template = '<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}">' | ||
return zzb.strings.format(template, options) // _.formatObj(template, uie) | ||
}; | ||
} | ||
@@ -149,5 +168,5 @@ /** | ||
_uib.prototype.createPanelCollapsibleEnd = function () { | ||
return '</div></div></div>'; | ||
}; | ||
return '</div></div></div>' | ||
} | ||
exports.uib = _uib | ||
exports.uib = _uib |
@@ -29,3 +29,3 @@ // client or server | ||
d = Math.floor(d / 16) | ||
return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16) | ||
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16) | ||
}) | ||
@@ -32,0 +32,0 @@ } |
@@ -15,3 +15,3 @@ var _ = require('lodash') | ||
exports.zzbLoader = function(options) { | ||
exports.zzbLoader = function (options) { | ||
options = _.merge({name: 'zzb', overwriteCached: false}, options) | ||
@@ -26,6 +26,6 @@ | ||
_zzb.prototype.zzNode = _zzNode | ||
_zzb.prototype.types = new _types | ||
_zzb.prototype.uuid = new _uuid | ||
_zzb.prototype.strings = new _strings | ||
_zzb.prototype.rob = new _rob | ||
_zzb.prototype.types = new _types() | ||
_zzb.prototype.uuid = new _uuid() | ||
_zzb.prototype.strings = new _strings() | ||
_zzb.prototype.rob = new _rob() | ||
@@ -37,6 +37,6 @@ // always gets a copy b/c referenced libs depends on it | ||
global[options.name].zzNode = _zzNode | ||
global[options.name].types = new _types | ||
global[options.name].uuid = new _uuid | ||
global[options.name].strings = new _strings | ||
global[options.name].rob = new _rob | ||
global[options.name].types = new _types() | ||
global[options.name].uuid = new _uuid() | ||
global[options.name].strings = new _strings() | ||
global[options.name].rob = new _rob() | ||
} else { | ||
@@ -43,0 +43,0 @@ global[options.name] = global['zzb'] |
@@ -19,9 +19,10 @@ if (typeof jQuery === 'undefined') { | ||
} else if (typeof define === 'function' && define.amd) { | ||
define(factory); | ||
define(factory) | ||
} else if (typeof module === 'object' && module.exports) { | ||
module.exports = factory(); | ||
module.exports = factory() | ||
} else { | ||
throw new Error('could not locate global cache object in which to create zzb') | ||
throw new Error('could not locate global cache object in which to create zzb') | ||
} | ||
}(this, (function () { 'use strict'; | ||
}(this, (function () { | ||
'use strict' | ||
@@ -28,0 +29,0 @@ // --------------------------------------------------- |
@@ -43,3 +43,3 @@ // client or server | ||
} else { | ||
if (this.parent.getId() != this.data[parentField]) { | ||
if (this.parent.getId() !== this.data[parentField]) { | ||
this.data[parentField] = this.parent.getId() | ||
@@ -53,15 +53,15 @@ this.isDirty = true | ||
this.getData = function() { | ||
this.getData = function () { | ||
return this.data | ||
} | ||
this.getId = function() { | ||
this.getId = function () { | ||
return this.data[pkField] | ||
} | ||
this.getParent = function() { | ||
this.getParent = function () { | ||
return this.parent | ||
} | ||
this.getRoot = function() { | ||
this.getRoot = function () { | ||
if (this.parent === null) { | ||
@@ -74,5 +74,5 @@ return this | ||
this.removeChild = function(targetId) { | ||
this.removeChild = function (targetId) { | ||
if (this.children.length > 0) { | ||
var index = _.findIndex(this.children, function(obj){return obj.getId() === targetId}) | ||
var index = _.findIndex(this.children, function (obj) { return obj.getId() === targetId }) | ||
if (index > -1) { | ||
@@ -84,6 +84,6 @@ this.children.splice(index, 1) | ||
this.addChild = function(data, newPKField, newParentField) { | ||
this.addChild = function (data, newPKField, newParentField) { | ||
// already been added? | ||
var $this = this | ||
var child = _.find(this.children, function(ch) { | ||
var child = _.find(this.children, function (ch) { | ||
return ch.getId() === data[$this.pkField] | ||
@@ -95,4 +95,4 @@ }) | ||
child = new this.nodeConstructor(this, data, | ||
(newPKField ? newPKField : this.pkField), | ||
(newParentField ? newParentField : this.parentField) | ||
newPKField || this.pkField, | ||
newParentField || this.parentField | ||
) | ||
@@ -104,10 +104,9 @@ this.children.push(child) | ||
this.findChild = function(targetId, doSearchItems) { | ||
this.findChild = function (targetId, doSearchItems) { | ||
var hit = null | ||
if (this.getId() === targetId){ | ||
if (this.getId() === targetId) { | ||
hit = this | ||
} | ||
else { | ||
} else { | ||
if (doSearchItems && this.items.length > 0) { | ||
_.each(this.items, function(item){ | ||
_.each(this.items, function (item) { | ||
if (item.getId() === targetId) { | ||
@@ -120,3 +119,3 @@ hit = item | ||
if (!hit && this.children.length > 0) { | ||
_.each(this.children, function(ch){ | ||
_.each(this.children, function (ch) { | ||
hit = ch.findChild(targetId, doSearchItems) | ||
@@ -139,10 +138,10 @@ if (hit) { | ||
this.getItemOwner = function() { | ||
this.getItemOwner = function () { | ||
return this.itemOwner | ||
} | ||
this.addItem = function(data, newPKField, newParentField) { | ||
this.addItem = function (data, newPKField, newParentField) { | ||
// already been added? | ||
var $this = this | ||
var item = _.find(this.items, function(it) { | ||
var item = _.find(this.items, function (it) { | ||
return it.getId() === data[$this.pkField] | ||
@@ -160,5 +159,5 @@ }) | ||
this.removeItem = function(targetId) { | ||
this.removeItem = function (targetId) { | ||
if (this.items.length > 0) { | ||
var index = _.findIndex(this.items, function(obj){return obj.getId() === targetId}) | ||
var index = _.findIndex(this.items, function (obj) { return obj.getId() === targetId }) | ||
if (index > -1) { | ||
@@ -170,6 +169,6 @@ this.items.splice(index, 1) | ||
this.findItem = function(targetId) { | ||
this.findItem = function (targetId) { | ||
var hit = null | ||
if (this.items.length > 0) { | ||
_.each(this.items, function(item) { | ||
_.each(this.items, function (item) { | ||
if (item.getId() === targetId) { | ||
@@ -182,3 +181,3 @@ hit = item | ||
if (!hit && this.children.length > 0) { | ||
_.each(this.children, function(ch){ | ||
_.each(this.children, function (ch) { | ||
hit = ch.findItem(targetId) | ||
@@ -193,3 +192,3 @@ if (hit) { | ||
this.sortChildren = function(fn, noDeepSort) { | ||
this.sortChildren = function (fn, noDeepSort) { | ||
if (!fn) { | ||
@@ -208,3 +207,3 @@ return | ||
this.sortItems = function(fn, fnChildren, noDeepSort) { | ||
this.sortItems = function (fn, fnChildren, noDeepSort) { | ||
if (!fn) { | ||
@@ -216,3 +215,3 @@ return | ||
if (fnChildren) { | ||
_.each(this.items, function(item){ | ||
_.each(this.items, function (item) { | ||
if (!noDeepSort) { | ||
@@ -226,3 +225,3 @@ item.sortChildren(fnChildren, noDeepSort) | ||
this.getLevelDeep = function() { | ||
this.getLevelDeep = function () { | ||
var level = 0 | ||
@@ -236,3 +235,3 @@ if (this.parent) { | ||
this.branchCallFunction = function(fn, startRootFirst, tryItemOwner) { | ||
this.branchCallFunction = function (fn, startRootFirst, tryItemOwner) { | ||
if (!startRootFirst) { | ||
@@ -242,6 +241,6 @@ fn && fn(this) | ||
if (this.parent) { | ||
this.parent.branchCallFunction(fn,startRootFirst,tryItemOwner) | ||
this.parent.branchCallfunction(fn, startRootFirst, tryItemOwner) | ||
} | ||
if (tryItemOwner && this.itemOwner) { | ||
this.itemOwner.branchCallFunction(fn, startRootFirst, tryItemOwner) | ||
this.itemOwner.branchCallfunction(fn, startRootFirst, tryItemOwner) | ||
} | ||
@@ -253,6 +252,6 @@ if (startRootFirst) { | ||
this.branchCallFunctionChildren = function(fn, tryItems) { | ||
this.branchCallFunctionChildren = function (fn, tryItems) { | ||
fn && fn(this) | ||
if (this.children.length > 0) { | ||
_.each(this.children, function(ch){ | ||
_.each(this.children, function (ch) { | ||
ch.branchCallFunctionChildren(fn, tryItems) | ||
@@ -262,3 +261,3 @@ }) | ||
if (tryItems && this.items.length > 0) { | ||
_.each(this.items, function(item) { | ||
_.each(this.items, function (item) { | ||
item.branchCallFunctionChildren(fn, tryItems) | ||
@@ -270,2 +269,2 @@ }) | ||
module.exports.zzNode = zzNode | ||
module.exports.zzNode = zzNode |
@@ -1,3 +0,2 @@ | ||
var util = require('util') | ||
var _ = require('lodash') | ||
/* global describe, it */ | ||
var zzbLoader = require('../src/zzb-server.js').zzbLoader | ||
@@ -109,2 +108,2 @@ | ||
}) | ||
}) | ||
}) |
@@ -1,3 +0,2 @@ | ||
var util = require('util') | ||
var _ = require('lodash') | ||
/* global describe, it */ | ||
var zzbLoader = require('../src/zzb-server.js').zzbLoader | ||
@@ -7,3 +6,2 @@ | ||
var zzb = zzbLoader() | ||
var sPig = 'The pig smelled mushrooms.' | ||
@@ -34,2 +32,33 @@ var sPigSingle = 'The pig smelled 1 mushroom.' | ||
}) | ||
var sPig2 = 'Piggy, you have 2 mushrooms' | ||
var sPigTemplateNumber = '{0}, you have {1} mushroom{2}' | ||
var sPigTemplateNamed = '{name}, you have {number} mushroom{ending}' | ||
describe('zzb.strings.format', function () { | ||
it('should match template-number from strings', function (done) { | ||
var err = null | ||
var compare = zzb.strings.format(sPigTemplateNumber, 'Piggy', 2, 's') | ||
if (compare !== sPig2) { | ||
err = new Error('failed matcy from strings') | ||
} | ||
done(err) | ||
}) | ||
it('should match template-number from array', function (done) { | ||
var err = null | ||
var compare = zzb.strings.format(sPigTemplateNumber, ['Piggy', 2, 's']) | ||
if (compare !== sPig2) { | ||
err = new Error('failed matcy from strings') | ||
} | ||
done(err) | ||
}) | ||
it('should match template-named from object', function (done) { | ||
var err = null | ||
var compare = zzb.strings.format(sPigTemplateNamed, {name: 'Piggy', number: 2, ending: 's'}) | ||
if (compare !== sPig2) { | ||
err = new Error('failed matcy from strings') | ||
} | ||
done(err) | ||
}) | ||
}) | ||
}) |
@@ -1,3 +0,2 @@ | ||
var util = require('util') | ||
var _ = require('lodash') | ||
/* global describe, it, zzs */ | ||
var zzbLoader = require('../src/zzb-server.js').zzbLoader | ||
@@ -25,3 +24,2 @@ | ||
err = new Error('failed zzb.types.isNonEmptyString') | ||
} | ||
@@ -79,3 +77,3 @@ done(err) | ||
var robErr = zzb.rob.createError({message: sPig}) | ||
if (robErr.message != sPig) { | ||
if (robErr.message !== sPig) { | ||
err = new Error('unexpected robErr.message') | ||
@@ -89,10 +87,9 @@ } | ||
describe('Validate zzb-server defaults using zzs object (non-default)', function () { | ||
var sPig = 'The pig smelled the mushrooms.' | ||
global.zzs = new function() { | ||
global.zzs = new function () { | ||
this.getPig = function () { | ||
return sPig | ||
} | ||
} | ||
}() | ||
@@ -126,3 +123,2 @@ zzbLoader({name: 'zzs', overwriteCached: true}) | ||
err = new Error('failed zzb.types.isNonEmptyString') | ||
} | ||
@@ -180,3 +176,3 @@ done(err) | ||
var robErr = zzs.rob.createError({message: sPig}) | ||
if (robErr.message != sPig) { | ||
if (robErr.message !== sPig) { | ||
err = new Error('unexpected robErr.message') | ||
@@ -183,0 +179,0 @@ } |
133958
3243
13