",i=e(n).children()}return i}return n},isEmpty:function(e,n){var i=this;if(t.isUndefined(e))return!0;if(null===e)return!0;if(e&&t.isObject(e)){var a=i.countProperties(e,n);if(0===a)return!0}return!1},countProperties:function(e,n){var i=0;if(e&&t.isObject(e))for(var a in e)e.hasOwnProperty(a)&&(n?i++:"function"!=typeof e[a]&&i++);return i},copyOf:function(n){var i=n;if(t.isArray(n)){i=[];for(var a=0;at;t++)lang.isNull(e[t])||lang.isUndefined(e[t])||n.push(e[t]);return n},removeAccents:function(e){return e.replace(/[àáâãäå]/g,"a").replace(/[èéêë]/g,"e").replace(/[ìíîï]/g,"i").replace(/[òóôõö]/g,"o").replace(/[ùúûü]/g,"u").replace(/[ýÿ]/g,"y").replace(/[ñ]/g,"n").replace(/[ç]/g,"c").replace(/[œ]/g,"oe").replace(/[æ]/g,"ae")},indexOf:function(e,n,i){var a,r=n.length;for(t.isFunction(i)||(i=function(e,t){return e===t}),a=0;r>a;a++)if(i.call({},e,n[a]))return a;return-1},uniqueIdCounter:0,defaultLocale:"en_US",defaultFocus:!0,defaultSort:function(e,t){return e.text>t.text?1:e.text3?"select":"radio":t.defaultSchemaFieldMapping[e.type],e.format&&t.defaultFormatFieldMapping[e.format]&&(n=t.defaultFormatFieldMapping[e.format]),n},views:{},generateViewId:function(){return"view-"+this.generateId()},registerView:function(e){var n=e.id;if(!n)return t.throwDefaultError("Cannot register view with missing view id: "+n);var i=this.views[n];if(i)t.mergeObject(i,e);else{this.views[n]=e,e.templates||(e.templates={});for(var a=t.TemplateEngineRegistry.ids(),r=0;r");if(n&&r.attr(n),i&&r.css(i),a)for(var o in a)r.addClass(o)},elementFromTemplate:function(n,i){var a=n;if(i)for(var r in i)a=t.replaceAll(a,"${"+r+"}",i[r]);return e(a)},generateId:function(){return t.uniqueIdCounter++,"alpaca"+t.uniqueIdCounter},later:function(t,n,i,a,r){t=t||0,n=n||{};var o,l,s=i,u=e.makeArray(a);if("string"==typeof i&&(s=n[i]),!s)throw{name:"TypeError",message:"The function is undefined."};return o=function(){s.apply(n,u)},l=r?setInterval(o,t):setTimeout(o,t),{id:l,interval:r,cancel:function(){this.interval?clearInterval(l):clearTimeout(l)}}},endsWith:function(e,t){return-1!==e.indexOf(t,e.length-t.length)},startsWith:function(e,t){return e.substr(0,t.length)===t},isUri:function(e){return t.isString(e)&&(t.startsWith(e,"http://")||t.startsWith(e,"https://")||t.startsWith(e,"/")||t.startsWith(e,"./")||t.startsWith(e,"../"))},traverseObject:function(e,n,i){t.isString(n)&&(n=n.split("."));var a=null,r=e,o=null;do o=n.shift(),i&&o===i&&(o=n.shift()),t.isEmpty(r[o])?n=[]:(r=r[o],0===n.length&&(a=r));while(n.length>0);return a},each:function(e,n){if(t.isArray(e))for(var i=0;i-1){var o=e.substring(0,r)+n[i]+e.substring(r+3);e=o}}return e},compareObject:function(e,t){return equiv(e,t)},compareArrayContent:function(t,n){var i=t&&n&&t.length===n.length;if(i)for(var a=t.length-1;a>=0;a--){var r=t[a];if(e.inArray(r,n)<0)return!1;
}return i},testRegex:function(e,t){var n=new RegExp(e);return n.test(t)},isValEmpty:function(n,i){var a=!1;return t.isEmpty(n,i)?a=!0:(t.isString(n)&&""===n&&(a=!0),t.isObject(n)&&e.isEmptyObject(n)&&(a=!0),t.isArray(n)&&0===n.length&&(a=!0)),a},init:function(e,n,i,a,r,o,l,s,u,c){var d=this;if(t.isObject(r)){var p=r.id;p||(r.id=this.generateViewId());var h=r.parent;h||(r.parent="bootstrap-edit"),this.registerView(r),r=r.id}this.compile(function(p){if(p.errors&&p.errors.length>0){for(var h=[],f=0;f0?u(e):o(e)};c()},getTemplateDescriptor:function(e,n,i){var a=null,r=null,o=null;if(e.templates&&e.templates[n]){o=t.makeCacheKey(e.id,"view",e.id,n);var l=e.templates[n];t.isObject(l)&&l.cacheKey&&(o=l.cacheKey)}if(i&&i.path){var s=i.path;if(e&&e.fields&&s&&s.length>1){var u=function(i,a,r){if(a!=i.length){var o=i.slice(),l=!1,s=i[a],c=s.indexOf("[");c>-1&&(s=s.substring(0,c),l=!0),o[a]=s;var d=o.join("/");if(e.fields[d]&&e.fields[d].templates&&e.fields[d].templates[n]){var p=t.makeCacheKey(e.id,"field",d,n);p&&r.push({path:d,cacheKey:p})}u(i,a+1,r),l&&u(o,a+1,r)}},c=s.split("/"),d=[];u(c,0,d),d.length>0&&(o=d[0].cacheKey)}}if("globalTemplate"!==n&&"global"!==n||(o=t.makeCacheKey(e.id,"global","global","globalTemplate")),"layoutTemplate"!==n&&"layout"!==n||(o=t.makeCacheKey(e.id,"layout","layout","layoutTemplate")),o){for(var p=t.TemplateEngineRegistry.ids(),h=0;h").append(this).html():e("").append(this.clone()).html()},e.fn.swapWith=function(t){return this.each(function(){var n=e(t).clone(),i=e(this).clone();e(t).replaceWith(i),e(this).replaceWith(n)})},e.fn.attrProp=function(n,i){return t.attrProp(e(this),n,i)},e.event.special.destroyed={remove:function(e){e.handler&&e.handler()}},t.pathParts=function(e){if("string"!=typeof e)return e;var n=e,i=null,a=n.indexOf("#");a>-1&&(i=n.substring(a+1),n=n.substring(0,a)),t.endsWith(n,"/")&&(n=n.substring(0,n.length-1));var r={};return r.path=n,i&&(r.id=i),r},t.resolveField=function(e,n){var i=null;if("string"==typeof n)if(0===n.indexOf("#/")&&propertyId.length>2);else if("#"===n||"#/"===n)i=e;else if(0===n.indexOf("#")){for(var a=e;a.parent;)a=a.parent;var r=n.substring(1);i=t.resolveFieldByReference(a,r)}else i=e.childrenByPropertyId[n];return i},t.resolveFieldByReference=function(e,n){if(e.schema&&e.schema.id==n)return e;if(e.children&&e.children.length>0)for(var i=0;i1){var s=e.slice(0);s.shift(),r(s,t,function(){l(i,a,function(){n()})})}else l(i,a,function(){n()})};r(n,a,function(){t(a)})},t.updateValidationStateForContext=function(e,n){for(var i=0;i0)for(var i=0;i=t.length&&i(null))}))})},r.forEach=r.each,r.eachSeries=function(e,t,n){if(n=n||function(){},!e.length)return n();var i=0,a=function(){t(e[i],function(t){t?(n(t),n=function(){}):(i+=1,i>=e.length?n(null):a())})};a()},r.forEachSeries=r.eachSeries,r.eachLimit=function(e,t,n,i){var a=c(t);a.apply(null,[e,n,i])},r.forEachLimit=r.eachLimit;var c=function(e){return function(t,n,i){if(i=i||function(){},!t.length||0>=e)return i();var a=0,r=0,o=0;!function l(){if(a>=t.length)return i();for(;e>o&&r=t.length?i():l())})}()}},d=function(e){return function(){var t=Array.prototype.slice.call(arguments);return e.apply(null,[r.each].concat(t))}},p=function(e,t){return function(){var n=Array.prototype.slice.call(arguments);return t.apply(null,[c(e)].concat(n))}},h=function(e){return function(){var t=Array.prototype.slice.call(arguments);return e.apply(null,[r.eachSeries].concat(t))}},f=function(e,t,n,i){var a=[];t=l(t,function(e,t){return{index:t,value:e}}),e(t,function(e,t){n(e.value,function(n,i){a[e.index]=i,t(n)})},function(e){i(e,a)})};r.map=d(f),r.mapSeries=h(f),r.mapLimit=function(e,t,n,i){return m(t)(e,n,i)};var m=function(e){return p(e,f)};r.reduce=function(e,t,n,i){r.eachSeries(e,function(e,i){n(t,e,function(e,n){t=n,i(e)})},function(e){i(e,t)})},r.inject=r.reduce,r.foldl=r.reduce,r.reduceRight=function(e,t,n,i){var a=l(e,function(e){return e}).reverse();r.reduce(a,t,n,i)},r.foldr=r.reduceRight;var g=function(e,t,n,i){var a=[];t=l(t,function(e,t){return{index:t,value:e}}),e(t,function(e,t){n(e.value,function(n){n&&a.push(e),t()})},function(e){i(l(a.sort(function(e,t){return e.index-t.index}),function(e){return e.value}))})};r.filter=d(g),r.filterSeries=h(g),r.select=r.filter,r.selectSeries=r.filterSeries;var v=function(e,t,n,i){var a=[];t=l(t,function(e,t){return{index:t,value:e}}),e(t,function(e,t){n(e.value,function(n){n||a.push(e),t()})},function(e){i(l(a.sort(function(e,t){return e.index-t.index}),function(e){return e.value}))})};r.reject=d(v),r.rejectSeries=h(v);var b=function(e,t,n,i){e(t,function(e,t){n(e,function(n){n?(i(e),i=function(){}):t()})},function(e){i()})};r.detect=d(b),r.detectSeries=h(b),r.some=function(e,t,n){r.each(e,function(e,i){t(e,function(e){e&&(n(!0),n=function(){}),i()})},function(e){n(!1)})},r.any=r.some,r.every=function(e,t,n){r.each(e,function(e,i){t(e,function(e){e||(n(!1),n=function(){}),i()})},function(e){n(!0)})},r.all=r.every,r.sortBy=function(e,t,n){r.map(e,function(e,n){t(e,function(t,i){t?n(t):n(null,{value:e,criteria:i})})},function(e,t){if(e)return n(e);var i=function(e,t){var n=e.criteria,i=t.criteria;return i>n?-1:n>i?1:0};n(null,l(t.sort(i),function(e){return e.value}))})},r.auto=function(e,t){t=t||function(){};var n=u(e);if(!n.length)return t(null);var i={},a=[],l=function(e){a.unshift(e)},c=function(e){for(var t=0;tt;t++)e[t].apply(null,arguments)}])))};return a.memo=n,a.unmemoized=e,a},r.unmemoize=function(e){return function(){return(e.unmemoized||e).apply(null,arguments)}},r.times=function(e,t,n){for(var i=[],a=0;e>a;a++)i.push(a);return r.map(i,t,n)},r.timesSeries=function(e,t,n){for(var i=[],a=0;e>a;a++)i.push(a);return r.mapSeries(i,t,n)},r.compose=function(){var e=Array.prototype.reverse.call(arguments);return function(){var t=this,n=Array.prototype.slice.call(arguments),i=n.pop();r.reduce(e,n,function(e,n,i){n.apply(t,e.concat([function(){var e=arguments[0],t=Array.prototype.slice.call(arguments,1);i(e,t)}]))},function(e,n){i.apply(t,[e].concat(n))})}};var E=function(e,t){var n=function(){var n=this,i=Array.prototype.slice.call(arguments),a=i.pop();return e(t,function(e,t){e.apply(n,i.concat([t]))},a)};if(arguments.length>2){var i=Array.prototype.slice.call(arguments,2);return n.apply(this,i)}return n};r.applyEach=d(E),r.applyEachSeries=h(E),r.forever=function(e,t){function n(i){if(i){if(t)return t(i);throw i}e(n)}n()},i.async=r;i.equiv=function(){var e,i=[],a=function(){function n(e,t){return e instanceof t.constructor||t instanceof e.constructor?t==e:t===e}return{string:n,"boolean":n,number:n,"null":n,undefined:n,nan:function(e){return isNaN(e)},date:function(e,n){return"date"===t(e)&&n.valueOf()===e.valueOf()},regexp:function(e,n){return"regexp"===t(e)&&n.source===e.source&&n.global===e.global&&n.ignoreCase===e.ignoreCase&&n.multiline===e.multiline},"function":function(){var e=i[i.length-1];return e!==Object&&"undefined"!=typeof e},array:function(n,i){var a,r;if("array"!==t(n))return!1;if(r=i.length,r!==n.length)return!1;for(a=0;r>a;a++)if(!e(i[a],n[a]))return!1;return!0},object:function(t,n){var a,r=!0,o=[],l=[];if(n.constructor!==t.constructor)return!1;i.push(n.constructor);for(a in n)o.push(a),e(n[a],t[a])||(r=!1);i.pop();for(a in t)l.push(a);return r&&e(o.sort(),l.sort())}}}();return e=function(){var e=Array.prototype.slice.apply(arguments);return e.length<2?!0:function(e,i){return e===i?!0:null===e||null===i||"undefined"==typeof e||"undefined"==typeof i||t(e)!==t(i)?!1:n(e,a,[i,e])}(e[0],e[1])&&arguments.callee.apply(this,e.splice(1,e.length-1))}}()}(),t.MARKER_CLASS_CONTROL_FIELD="alpaca-marker-control-field",t.MARKER_CLASS_CONTAINER_FIELD="alpaca-marker-container-field",t.MARKER_CLASS_CONTAINER_FIELD_ITEM="alpaca-marker-control-field-item",t.MARKER_DATA_CONTAINER_FIELD_ITEM_KEY="data-alpaca-container-field-item-key",t.MARKER_CLASS_FORM_ITEMS_FIELD="alpaca-marker-form-items-field",t.CLASS_CONTAINER="alpaca-container",t.CLASS_CONTROL="alpaca-control",t.MARKER_CLASS_INSERT="alpaca-marker-insert",t.MARKER_DATA_INSERT_KEY="data-alpaca-marker-insert-key",t.MARKER_CLASS_ARRAY_TOOLBAR="alpaca-marker-array-field-toolbar",t.MARKER_DATA_ARRAY_TOOLBAR_FIELD_ID="data-alpaca-array-field-toolbar-field-id",t.MARKER_CLASS_ARRAY_ITEM_ACTIONBAR="alpaca-marker-array-field-item-actionbar",t.MARKER_DATA_ARRAY_ITEM_KEY="data-alpaca-marker-array-field-item-key",t.MARKER_DATA_ARRAY_ITEM_PARENT_FIELD_ID="data-alpaca-marker-array-field-item-parent-field-id",t.MARKER_CLASS_CONTAINER_FIELD_ITEM_FIELD="alpaca-marker-container-field-item-field",t.makeCacheKey=function(e,t,n,i){return e+":"+t+":"+n+":"+i},t.splitCacheKey=function(e){var t={},n=e.indexOf(":"),i=e.lastIndexOf(":");t.viewId=e.substring(0,n),t.templateId=e.substring(i+1);var a=e.substring(n+1,i),r=a.indexOf(":");return t.scopeType=a.substring(0,r),t.scopeId=a.substring(r+1),t},t.createEmptyDataInstance=function(e){return e?"object"===e.type?{}:"array"===e.type?[]:"number"===e.type?-1:"boolean"===e.type?!1:"":""},t.animatedSwap=function(t,n,i,a){"function"==typeof i&&(a=i,i=500);var r=function(t,n,i,a){var r=e(t),o=e(n),l=r.offset(),s=o.offset(),u=r.clone(),c=o.clone(),d=s.top+o.height()-l.top,p=0,h=0,f=s.left+o.width()-l.left,m=0,g=0;r.css("opacity",0),o.css("opacity",0),u.insertAfter(r).css({position:"absolute",width:r.outerWidth(),height:r.outerHeight()}).offset(l).css("z-index","999"),c.insertAfter(o).css({position:"absolute",width:o.outerWidth(),height:o.outerHeight()}).offset(s).css("z-index","999"),l.top!==s.top&&(p=d-r.height()),h=d-o.height(),l.left!==s.left&&(m=f-r.width()),g=f-o.width(),u.animate({top:"+="+p+"px",left:"+="+m+"px"},i,function(){o.css("opacity",1),e(this).remove()}),c.animate({top:"-="+h+"px",left:"-="+g+"px"},i,function(){r.css("opacity",1),e(this).remove()}),window.setTimeout(function(){u.remove(),c.remove(),a()},i+1)};r(t,n,i,a)},t.animatedMove=function(t,n,i,a){"function"==typeof i&&(a=i,i=500);var r=function(t,n,i,a){var r=e(t),o=e(n),l=r.offset(),s=o.offset(),u=r.clone(),c=s.top+o.height()-l.top,d=0,p=0,h=s.left+o.width()-l.left,f=0,m=0;r.css("opacity",0),o.css("opacity",0),u.insertAfter(r).css({position:"absolute",width:r.outerWidth(),height:r.outerHeight()}).offset(l).css("z-index","999"),l.top!==s.top&&(d=c-r.height()),p=c-o.height(),l.left!==s.left&&(f=h-r.width()),m=h-o.width(),u.animate({top:"+="+d+"px",left:"+="+f+"px"},i,function(){o.css("opacity",1),e(this).remove()}),window.setTimeout(function(){u.remove(),a()},i+1)};r(t,n,i,a)},t.fireReady=function(e){if(e.children&&e.children.length>0)for(var n=0;n"+t+""),Alpaca.logDebug("Compiling template: "+this.id+", cacheKey: "+e+", template: "+t),this.doCompile(e,t,n)},doCompile:function(e,t,n){},execute:function(e,t,n){Alpaca.logDebug("Executing template for cache key: "+e);var i=this.doExecute(e,t,n);return i=this.cleanup(i)},doExecute:function(e,t,n){return null},fileExtension:function(){return"html"},supportedMimetypes:function(){return[]},isCached:function(e){return!1},findCacheKeys:function(e){return[]}})}(jQuery),function($,Handlebars,HandlebarsPrecompiled){var COMPILED_TEMPLATES={},helpers={};helpers.compare=function(e,t,n){if(arguments.length<3)throw new Error("Handlerbars Helper 'compare' needs 2 parameters");var i=n.hash.operator||"==",a={"==":function(e,t){return e==t},"===":function(e,t){return e===t},"!=":function(e,t){return e!=t},"!==":function(e,t){return e!==t},"<":function(e,t){return t>e},">":function(e,t){return e>t},"<=":function(e,t){return t>=e},">=":function(e,t){return e>=t},"typeof":function(e,t){return typeof e==t}};if(!a[i])throw new Error("Handlerbars Helper 'compare' doesn't know the operator "+i);var r=a[i](e,t);return r?n.fn(this):n.inverse(this)},helpers.ifnot=function(e,t){return e?t.inverse(this):t.fn(this)},helpers.times=function(e,t){for(var n="",i=0;e>i;++i)n+=t.fn(i);return n},helpers.control=function(e){return""},helpers.container=function(e){return""},helpers.item=function(e,t){return Alpaca.isObject(e)&&(t=e,e="div"),"<"+e+" class='"+Alpaca.MARKER_CLASS_CONTAINER_FIELD_ITEM+"' "+Alpaca.MARKER_DATA_CONTAINER_FIELD_ITEM_KEY+"='"+this.name+"'>"+e+">"},helpers.itemField=function(e,t){return Alpaca.isObject(e)&&(t=e,e="div"),"<"+e+" class='"+Alpaca.MARKER_CLASS_CONTAINER_FIELD_ITEM_FIELD+"'>"+e+">"},helpers.formItems=function(e){return""},helpers.insert=function(e){return""},helpers.str=function(e){return e===!1?"false":e===!0?"true":0===e?"0":"undefined"==typeof e?"":null===e?"":Alpaca.isString(e)?e:Alpaca.isNumber(e)?e:Alpaca.isObject(e)?JSON.stringify(e,null," "):Alpaca.isArray(e)?JSON.stringify(e,null," "):e},helpers.arrayToolbar=function(e){return""},helpers.arrayActionbar=function(e){return""},Handlebars.registerHelper("arrayToolbar",helpers.arrayToolbar),Handlebars.registerHelper("arrayActionbar",helpers.arrayActionbar),Handlebars.registerHelper("setIndex",function(e){this.index=Number(e)}),Handlebars.registerHelper("eachProperty",function(e,t){var n="";for(var i in e)n+=t.fn({key:i,value:e[i]});return n}),Handlebars.registerHelper("uploadErrorMessage",function(e){var t=e;return 1===e?t="File exceeds upload_max_filesize":2===e?t="File exceeds MAX_FILE_SIZE":3===e?t="File was only partially uploaded":4===e?t="No File was uploaded":5===e?t="Missing a temporary folder":6===e?t="Failed to write file to disk":7===e?t="File upload stopped by extension":"maxFileSize"===e?t="File is too big":"minFileSize"===e?t="File is too small":"acceptFileTypes"===e?t="Filetype not allowed":"maxNumberOfFiles"===e?t="Max number of files exceeded":"uploadedBytes"===e?t="Uploaded bytes exceed file size":"emptyResult"===e&&(t="Empty file upload result"),t}),Handlebars.registerHelper("disguise",function(e,t){for(var n="",i=0;i0)for(var i=0;i0)for(var i=0;i");i._processRender(r,function(){a.formFieldsContainer.before(i.field),a.formFieldsContainer.remove(),a.topControl=i,i.view.type&&"view"!==i.view.type&&a.initEvents(),i.form=a,i.postRender(function(){i.initializing=!1,i.form.afterInitialize(),e(i.field).bind("destroyed",function(e){i.form.destroy()}),n&&t.isFunction(n)&&n(i)})})})}else this._processRender(i.domEl,function(){i.postRender(function(){i.initializing=!1,n&&t.isFunction(n)&&n(i)})})},_processRender:function(e,t){var n=this;n.renderField(e,function(){n.fireCallback("field"),n.renderFieldElements(function(){t()})})},renderFieldDomElement:function(e){var n=this.getTemplateDescriptor();return t.tmpl(n,{id:this.getId(),options:this.options,schema:this.schema,data:e,view:this.view,path:this.path,name:this.name})},renderField:function(t,n){var i=this,a=this.data;this.isDisplayOnly()&&"object"==typeof a&&(a=JSON.stringify(a));var r=i.renderFieldDomElement(a);if(e(r).length>0){for(var o=null,l=0;l-1)for(a=n.split(","),i=0;i-1)for(a=n.split(" "),i=0;i");e(o).before(l),i.domEl=e(""),i.field=void 0,i.control=void 0,i.container=void 0,i.form=void 0,e(o).find("button").prop("disabled",!0),this.initializing=!0,i.setup(),i._render(function(){e(l).before(i.field),i.domEl=r;var s=e(o).attr("class");s&&e.each(s.split(" "),function(t,n){n&&0===!n.indexOf("alpaca-")&&e(i.field).addClass(n)}),e(o).hide(),e(l).remove(),i.refreshed=!0,"undefined"!=typeof a&&(t.isObject(a)||t.isArray(a))&&i.setValue(a),t.fireReady(i),n&&n(),e(o).remove(void 0,{nodestroy:!0})})},applyStyle:function(e,t){this.view.applyStyle(e,t)},fireCallback:function(e,t,n,i,a,r){this.view.fireCallback(this,e,t,n,i,a,r)},getFieldEl:function(){return this.field},getId:function(){return this.id},getParent:function(){return this.parent},getPath:function(){return this.path},getName:function(){return this.name},isTopLevel:function(){return t.isEmpty(this.parent)},top:function(){for(var e=this;e.parent;)e=e.parent;return e},getValue:function(){var e=this,t=this.data;return t=e.ensureProperType(t)},setValue:function(e){this.data=e,this.updateObservable(),this.triggerUpdate(),this.isDisplayOnly()&&!this.initializing&&(this.top&&this.top()&&this.top().initializing||this.refresh())},setDefault:function(){},getTemplateDescriptor:function(){return this.templateDescriptor},setTemplateDescriptor:function(e){this.templateDescriptor=e},displayMessage:function(n,i){var a=this;n&&t.isObject(n)&&(n=[n]),n&&t.isString(n)&&(n=[{id:"custom",message:n}]),e(this.getFieldEl()).children(".alpaca-message").remove(),n&&n.length>0&&this.options.maxMessages&&t.isNumber(this.options.maxMessages)&&this.options.maxMessages>-1&&(n=n.slice(0,this.options.maxMessages)),a.fireCallback("removeMessages"),n&&n.length>0&&e.each(n,function(n,i){var r=!1;a.hideInitValidationError&&(r=!0);var o=a.view.getTemplateDescriptor("message");if(o){var l=t.tmpl(o,{id:i.id,message:i.message,view:a.view});l.addClass("alpaca-message"),r&&l.addClass("alpaca-message-hidden"),e(a.getFieldEl()).append(l)}a.fireCallback("addMessage",n,i.id,i.message,r)})},refreshValidationState:function(e,n){var i=this,a=[],r=[],o=function(e,n){return function(i){t.nextTick(function(){t.compileValidationContext(e,function(e){n.push(e),i()})})}};if(e){var l=function(e,t){if(e.isValidationParticipant()){if(e.children&&e.children.length>0)for(var n=0;n=0){var c=o.indexOf("]",u+1);c>=0&&(s=parseInt(o.substring(u+1,c)),l=o.substring(0,u))}l&&(i=i.childrenByPropertyId[l],s>-1&&(i=i.children[s]))}n=i}return n},getControlsByFieldType:function(e){var t=[];if(e){var n=function(e,t,i){for(var a=0;adisplayReadonly attribute set to false, the read-only field will not appear.",type:"boolean","default":!1},required:{title:"Required",description:"Indicates whether the field's value is required. If set to true, the field must take on a valid value and cannnot be left empty or unassigned.",type:"boolean","default":!1},"default":{title:"Default",description:"The default value to be assigned for this property. If the data for the field is empty or not provided, this default value will be plugged in for you. Specify a default value when you want to pre-populate the field's value ahead of time.",type:"any"},type:{title:"Type",description:"Data type of the property.",type:"string",readonly:!0},format:{title:"Format",description:"Data format of the property.",type:"string"},disallow:{title:"Disallowed Values",description:"List of disallowed values for the property.",type:"array"},dependencies:{title:"Dependencies",description:"List of property dependencies.",type:"array"}}};return this.getType&&!t.isValEmpty(this.getType())&&(e.properties.type["default"]=this.getType(),e.properties.type["enum"]=[this.getType()]),e},getOptionsForSchema:function(){return{fields:{title:{helper:"Field short description",type:"text"},description:{helper:"Field detailed description",type:"textarea"},readonly:{helper:"Field will be read only if checked",rightLabel:"This field is read-only",type:"checkbox"},required:{helper:"Field value must be set if checked",rightLabel:"This field is required",type:"checkbox"},"default":{helper:"Field default value",type:"textarea"},type:{helper:"Field data type",type:"text"},format:{type:"select",dataSource:function(e){for(var n in t.defaultFormatFieldMapping)this.selectOptions.push({value:n,text:n});e()}},disallow:{helper:"Disallowed values for the field",itemLabel:"Value",type:"array"},dependencies:{helper:"Field Dependencies",multiple:!0,size:3,type:"select",dataSource:function(e,t){if(e.parent&&e.parent.schemaParent&&e.parent.schemaParent.parent)for(var n in e.parent.schemaParent.parent.childrenByPropertyId)n!=e.parent.schemaParent.propertyId&&e.selectOptions.push({value:n,text:n});t&&t()}}}}},getSchemaOfOptions:function(){var e={title:"Options for "+this.getTitle(),description:this.getDescription()+" (Options)",type:"object",properties:{form:{},id:{title:"Field Id",description:"Unique field id. Auto-generated if not provided.",type:"string"},type:{title:"Field Type",description:"Field type.",type:"string","default":this.getFieldType(),readonly:!0},validate:{title:"Validation",description:"Field validation is required if true.",type:"boolean",
"default":!0},showMessages:{title:"Show Messages",description:"Display validation messages if true.",type:"boolean","default":!0},disabled:{title:"Disabled",description:"Field will be disabled if true.",type:"boolean","default":!1},readonly:{title:"Readonly",description:"Field will be readonly if true.",type:"boolean","default":!1},hidden:{title:"Hidden",description:"Field will be hidden if true.",type:"boolean","default":!1},label:{title:"Label",description:"Field label.",type:"string"},helper:{title:"Helper",description:"Field help message.",type:"string"},helpers:{title:"Helpers",description:"An array of field help messages. Each message will be displayed on it's own line.",type:"array",items:{type:"string"}},fieldClass:{title:"CSS class",description:"Specifies one or more CSS classes that should be applied to the dom element for this field once it is rendered. Supports a single value, comma-delimited values, space-delimited values or values passed in as an array.",type:"string"},hideInitValidationError:{title:"Hide Initial Validation Errors",description:"Hide initial validation errors if true.",type:"boolean","default":!1},focus:{title:"Focus",description:"If true, the initial focus for the form will be set to the first child element (usually the first field in the form). If a field name or path is provided, then the specified child field will receive focus. For example, you might set focus to 'name' (selecting the 'name' field) or you might set it to 'client/name' which picks the 'name' field on the 'client' object.",type:"checkbox","default":!0},optionLabels:{title:"Enumerated Value Labels",description:"An array of string labels for items in the enum array",type:"array"},view:{title:"Override of the view for this field",description:"Allows for this field to be rendered with a different view (such as 'display' or 'create')",type:"string"}}};return this.isTopLevel()?e.properties.form={title:"Form",description:"Options for rendering the FORM tag.",type:"object",properties:{attributes:{title:"Form Attributes",description:"List of attributes for the FORM tag.",type:"object",properties:{id:{title:"Id",description:"Unique form id. Auto-generated if not provided.",type:"string"},action:{title:"Action",description:"Form submission endpoint",type:"string"},method:{title:"Method",description:"Form submission method","enum":["post","get"],type:"string"},rubyrails:{title:"Ruby On Rails",description:"Ruby on Rails Name Standard","enum":["true","false"],type:"string"},name:{title:"Name",description:"Form name",type:"string"},focus:{title:"Focus",description:"Focus Setting",type:"any"}}},buttons:{title:"Form Buttons",description:"Configuration for form-bound buttons",type:"object",properties:{submit:{type:"object",title:"Submit Button",required:!1},reset:{type:"object",title:"Reset button",required:!1}}},toggleSubmitValidState:{title:"Toggle Submit Valid State",description:"Toggle the validity state of the Submit button",type:"boolean","default":!0}}}:delete e.properties.form,e},getOptionsForOptions:function(){var e={type:"object",fields:{id:{type:"text",readonly:!0},type:{type:"text"},validate:{rightLabel:"Enforce validation",type:"checkbox"},showMessages:{rightLabel:"Show validation messages",type:"checkbox"},disabled:{rightLabel:"Disable this field",type:"checkbox"},hidden:{type:"checkbox",rightLabel:"Hide this field"},label:{type:"text"},helper:{type:"textarea"},helpers:{type:"array",items:{type:"textarea"}},fieldClass:{type:"text"},hideInitValidationError:{rightLabel:"Hide initial validation errors",type:"checkbox"},focus:{type:"checkbox",rightLabel:"Auto-focus first child field"},optionLabels:{type:"array",items:{type:"text"}},view:{type:"text"}}};return this.isTopLevel()&&(e.fields.form={type:"object",fields:{attributes:{type:"object",fields:{id:{type:"text",readonly:!0},action:{type:"text"},method:{type:"select"},name:{type:"text"}}}}}),e}}),t.registerMessages({disallowValue:"{0} are disallowed values.",notOptional:"This field is not optional."})}(jQuery),function(e){var t=e.alpaca;t.ControlField=t.Field.extend({onConstruct:function(){var t=this;this.isControlField=!0,this._getControlVal=function(n){var i=null;return this.control&&(i=e(this.control).val(),n&&(i=t.ensureProperType(i))),i}},setup:function(){var e=this;this.base();var n=e.resolveControlTemplateType();if(!n)return t.throwErrorWithCallback("Unable to find template descriptor for control: "+e.getFieldType());if(this.controlDescriptor=this.view.getTemplateDescriptor("control-"+n,e),"undefined"==typeof this.options.renderButtons&&(this.options.renderButtons=!0),this.options.buttons)for(var i in this.options.buttons)this.options.buttons[i].label&&(this.options.buttons[i].value=this.options.buttons[i].label),this.options.buttons[i].title&&(this.options.buttons[i].value=this.options.buttons[i].title),this.options.buttons[i].type||(this.options.buttons[i].type="button"),this.options.buttons[i].styles||(this.options.buttons[i].styles=this.view.styles.button)},getControlEl:function(){return this.control},resolveControlTemplateType:function(){var e=this,t=!1,n=null,i=this;do if(i.getFieldType){var a=this.view.getTemplateDescriptor("control-"+i.getFieldType(),e);a?(n=i.getFieldType(),t=!0):i=i.constructor.ancestor.prototype}else t=!0;while(!t);return n},onSetup:function(){},isAutoFocusable:function(){return!0},getTemplateDescriptorId:function(){return"control"},renderFieldElements:function(n){var i=this;this.control=e(this.field).find("."+t.MARKER_CLASS_CONTROL_FIELD),this.control.removeClass(t.MARKER_CLASS_CONTROL_FIELD),i.prepareControlModel(function(e){i.beforeRenderControl(e,function(){i.renderControl(e,function(a){a&&(i.control.replaceWith(a),i.control=a,i.control.addClass(t.CLASS_CONTROL)),i.fireCallback("control"),i.afterRenderControl(e,function(){n()})})})})},prepareControlModel:function(e){var t={};t.id=this.getId(),t.name=this.name,t.options=this.options,t.schema=this.schema,t.data=this.data,t.required=this.isRequired(),t.view=this.view,e(t)},beforeRenderControl:function(e,t){t()},afterRenderControl:function(t,n){var i=this;i.firstUpdateObservableFire||"undefined"==typeof i.data||null==i.data||(i.firstUpdateObservableFire=!0,i.updateObservable()),e(this.getFieldEl()).find(".alpaca-control-button").each(function(){e(this).click(function(t){e(this).attr("button-pushed",!0)});var t=e(this).attr("data-key");if(t){var n=i.options.buttons[t];n&&n.click&&e(this).click(function(e,t){return function(n){n.preventDefault(),t.call(e,n)}}(i,n.click))}}),n()},renderControl:function(e,n){var i=null;this.controlDescriptor&&(i=t.tmpl(this.controlDescriptor,e)),n(i)},postRender:function(e){this.base(function(){e()})},updateDOMElement:function(){this.base(),this.control.attr("name",this.getName())},setDefault:function(){var e=t.isEmpty(this.schema["default"])?"":this.schema["default"];this.setValue(e)},getValue:function(){var e=this,t=this.base();return this.isDisplayOnly()||(t=e.getControlValue()),t=e.ensureProperType(t)},getControlValue:function(){return this._getControlVal(!0)},_validateEnum:function(){if(!this.getEnum())return!0;var n=this.getValue();return!this.isRequired()&&t.isValEmpty(n)?!0:e.inArray(n,this.getEnum())>-1},handleValidate:function(){var e=this.base(),n=this.validation,i=this._validateEnum(),a=this.getEnum(),r=this.getOptionLabels();return r&&r.length>0&&(a=r),n.invalidValueOfEnum={message:i?"":t.substituteTokens(this.getMessage("invalidValueOfEnum"),[a.join(", "),this.getValue()]),status:i},e&&n.invalidValueOfEnum.status},initEvents:function(){this.base(),this.control&&this.control.length>0&&this.initControlEvents()},initControlEvents:function(){var e=this,t=this.control;t.click(function(t){e.onClick.call(e,t),e.trigger("click",t)}),t.change(function(t){setTimeout(function(){e.onChange.call(e,t),e.triggerWithPropagation("change",t)},200)}),t.focus(function(t){if(e.wasFocused=!0,!e.suspendBlurFocus){var n=e.onFocus.call(e,t);return n!==!1&&(n=e.trigger("focus",t)),n}}),t.blur(function(t){if(e.wasBlurred=!0,!e.suspendBlurFocus){var n=e.onBlur.call(e,t);return n!==!1&&(n=e.trigger("blur",t)),n}}),t.keypress(function(t){var n=e.onKeyPress.call(e,t);return n!==!1&&(n=e.trigger("keypress",t)),n}),t.keyup(function(t){var n=e.onKeyUp.call(e,t);return n!==!1&&(n=e.trigger("keyup",t)),n}),t.keydown(function(t){var n=e.onKeyDown.call(e,t);return n!==!1&&(n=e.trigger("keydown",t)),n})},onKeyPress:function(e){var t=this,n=!1;if(t.view.type&&"edit"===t.view.type){var i=this.isValid();i||(n=!0)}else if(t.view.type&&"create"===t.view.type){var i=this.isValid();!i&&t.wasBlurred&&(n=!0)}n&&window.setTimeout(function(){t.refreshValidationState()},50)},onKeyDown:function(e){},onKeyUp:function(e){},onClick:function(e){},disable:function(){this.base(),this.control&&this.control.length>0&&e(this.control).prop("disabled",!0)},enable:function(){this.base(),this.control&&this.control.length>0&&e(this.control).prop("disabled",!1)},isDisabled:function(){return e(this.control).prop("disabled")},getEnum:function(){var e=null;return this.schema&&this.schema["enum"]&&(e=this.schema["enum"]),e},setEnum:function(e){t.safeSetObjectArray(this.schema,"enum",e)},getOptionLabels:function(){var e=null;return this.options&&this.options.optionLabels&&(e=this.options.optionLabels),e},setOptionLabels:function(e){t.safeSetObjectArray(this.options,"optionLabels",e)},sortEnum:function(){var e=this.getEnum();if(e&&e.length>0){for(var n=this.getOptionLabels(),i=[],a=0;a=a+1&&(o=n[a]),i.push({value:r,text:o})}this.sortSelectableOptions(i);for(var l=[],s=[],a=0;a0)){r={};for(var o=0;o0?(e(a.container).addClass("alpaca-container-has-items"),e(a.container).attr("data-alpaca-container-item-count",n.items.length)):(e(a.container).removeClass("alpaca-container-has-items"),e(a.container).removeAttr("data-alpaca-container-item-count"));for(var o=0;o0&&(s.domEl=e(""),e(s.domEl).addClass("alpaca-layout-binding-holder"),e(s.domEl).attr("alpaca-layout-binding-field-name",s.name),d.append(s.domEl),s.domEl.append(s.containerItemEl))}e(u).remove()}else{var d=e(u).parent();e(u).replaceWith(s.containerItemEl),s.domEl=d}e(s.containerItemEl).addClass("alpaca-container-item"),0===o&&e(s.containerItemEl).addClass("alpaca-container-item-first"),o+1===n.items.length&&e(s.containerItemEl).addClass("alpaca-container-item-last"),e(s.containerItemEl).attr("data-alpaca-container-item-index",o),e(s.containerItemEl).attr("data-alpaca-container-item-name",s.name),e(s.containerItemEl).attr("data-alpaca-container-item-parent-field-id",a.getId()),a.registerChild(s,o)}a.options.collapsible&&a.fireCallback("collapsible"),a.triggerUpdate(),i()},afterApplyCreatedItems:function(e,t){t()},registerChild:function(e,n){t.isEmpty(n)?this.children.push(e):this.children.splice(n,0,e),this.childrenById[e.getId()]=e,e.propertyId&&(this.childrenByPropertyId[e.propertyId]=e),e.parent=this},unregisterChild:function(e){var n=this.children[e];n&&(t.isEmpty(e)||this.children.splice(e,1),delete this.childrenById[n.getId()],n.propertyId&&delete this.childrenByPropertyId[n.propertyId],n.parent=null)},updateDOMElement:function(){var t=this;this.base(),t.children.length>0?(e(t.getContainerEl()).addClass("alpaca-container-has-items"),e(t.getContainerEl()).attr("data-alpaca-container-item-count",t.children.length)):(e(t.getContainerEl()).removeClass("alpaca-container-has-items"),e(t.getContainerEl()).removeAttr("data-alpaca-container-item-count"));for(var n=0;n0&&(i=0),i>-1&&(a[i].focus(),t&&t(a[i]))},disable:function(){this.base();for(var e=0;e0&&(e=this.children[0]),e},lastChild:function(){var e=null;return this.children.length>0&&(e=this.children[this.children.length-1]),e},getSchemaOfOptions:function(){return t.merge(this.base(),{properties:{lazyLoading:{title:"Lazy Loading",description:"Child fields will only be rendered when the fieldset is expanded if this option is set true.",type:"boolean","default":!1},collapsible:{title:"Collapsible",description:"Field set is collapsible if true.",type:"boolean","default":!1},collapsed:{title:"Collapsed",description:"Field set is initially collapsed if true.",type:"boolean","default":!1},legendStyle:{title:"Legend Style",description:"Field set legend style.",type:"string","enum":["button","link"],"default":"button"},animate:{title:"Animate movements and transitions",description:"Up and down transitions will be animated",type:"boolean","default":!0}}})},getOptionsForOptions:function(){return t.merge(this.base(),{fields:{lazyLoading:{rightLabel:"Lazy loading child fields ?",helper:"Lazy loading will be enabled if checked.",type:"checkbox"},collapsible:{rightLabel:"Field set collapsible ?",helper:"Field set is collapsible if checked.",type:"checkbox"},collapsed:{rightLabel:"Field set initially collapsed ?",description:"Field set is initially collapsed if checked.",type:"checkbox"},legendStyle:{type:"select"},animate:{rightLabel:"Animate movements and transitions",type:"checkbox"}}})}})}(jQuery),function(e){var t=e.alpaca;t.Form=Base.extend({constructor:function(e,n,i,a,r){if(this.domEl=e,this.parent=null,this.connector=a,this.errorCallback=r,this.options=n,this.options.attributes?this.attributes=this.options.attributes:this.attributes={},this.options.buttons){this.options.buttons.submit&&(this.options.buttons.submit.type||(this.options.buttons.submit.type="submit"),this.options.buttons.submit.name||(this.options.buttons.submit.name="submit"),this.options.buttons.submit.value||(this.options.buttons.submit.value="Submit")),this.options.buttons.reset&&(this.options.buttons.reset.type||(this.options.buttons.reset.type="reset"),this.options.buttons.reset.name||(this.options.buttons.reset.name="reset"),this.options.buttons.reset.value||(this.options.buttons.reset.value="Reset"));for(var o in this.options.buttons)this.options.buttons[o].label&&(this.options.buttons[o].value=this.options.buttons[o].label),this.options.buttons[o].title&&(this.options.buttons[o].value=this.options.buttons[o].title),this.options.buttons[o].type||(this.options.buttons[o].type="button")}this.attributes.id?this.id=this.attributes.id:(this.id=t.generateId(),this.attributes.id=this.id),this.options.buttons&&this.options.buttons.submit&&t.isUndefined(this.options.toggleSubmitValidState)&&(this.options.toggleSubmitValidState=!0),this.viewType=n.viewType,this.view=new t.RuntimeView(i,this);for(var o in this.options.buttons)this.options.buttons[o].styles||(this.options.buttons[o].styles=this.view.styles.button)},render:function(e){var t=this;this.processRender(this.domEl,function(){t.form.appendTo(t.domEl),t.form.addClass("alpaca-form"),t.fireCallback("form"),e(t)})},afterInitialize:function(){var e=this;e.options.toggleSubmitValidState&&e.adjustSubmitButtonState()},isFormValid:function(){this.topControl.validate(!0);var e=this.topControl.isValid(!0);return e},isValid:function(){return this.isFormValid()},validate:function(e){return this.topControl.validate(e)},enableSubmitButton:function(){if(e(".alpaca-form-button-submit").attrProp("disabled",!1),e.mobile)try{e(".alpaca-form-button-submit").button("refresh")}catch(t){}},disableSubmitButton:function(){if(e(".alpaca-form-button-submit").attrProp("disabled",!0),e.mobile)try{e(".alpaca-form-button-submit").button("refresh")}catch(t){}},adjustSubmitButtonState:function(){this.disableSubmitButton(),this.isFormValid()&&this.enableSubmitButton()},processRender:function(n,i){var a=this;if(this.formDescriptor=this.view.getTemplateDescriptor("form"),!this.formDescriptor)return t.throwErrorWithCallback("Could not find template descriptor: form");var r=t.tmpl(this.formDescriptor,{id:this.getId(),options:this.options,view:this.view});r.appendTo(n),this.form=r,this.formFieldsContainer=e(this.form).find("."+t.MARKER_CLASS_FORM_ITEMS_FIELD),this.formFieldsContainer.removeClass(t.MARKER_CLASS_FORM_ITEMS_FIELD),t.isEmpty(this.form.attr("id"))&&this.form.attr("id",this.getId()+"-form-outer"),t.isEmpty(this.form.attr("data-alpaca-form-id"))&&this.form.attr("data-alpaca-form-id",this.getId()),e(n).find("form").attr(this.attributes),this.buttons={},e(n).find(".alpaca-form-button").each(function(){e(this).click(function(t){e(this).attr("button-pushed",!0)});var t=e(this).attr("data-key");if(t){var n=a.options.buttons[t];n&&n.click&&e(this).click(function(e,t){return function(n){n.preventDefault(),t.call(e,n)}}(a,n.click))}}),i()},getId:function(){return this.id},getType:function(){return this.type},getParent:function(){return this.parent},getValue:function(){return this.topControl.getValue()},setValue:function(e){this.topControl.setValue(e)},initEvents:function(){var t=this,n=e(this.domEl).find("form"),i=this.getValue();e(n).submit(i,function(e){return t.onSubmit(e,t)}),this.options.toggleSubmitValidState&&(e(t.topControl.getFieldEl()).bind("fieldupdate",function(){t.adjustSubmitButtonState()}),e(t.topControl.getFieldEl()).bind("fieldkeyup",function(){t.adjustSubmitButtonState()}),e(t.topControl.getFieldEl()).bind("fieldblur",function(){t.adjustSubmitButtonState()}))},getButtonEl:function(t){return e(this.domEl).find(".alpaca-form-button-"+t)},onSubmit:function(e,n){if(!this.isFormValid())return e.stopPropagation(),this.refreshValidationState(!0),!1;if(this.submitHandler){e.stopPropagation();var i=this.submitHandler(e,n);return t.isUndefined(i)&&(i=!1),i}},registerSubmitHandler:function(e){t.isFunction(e)&&(this.submitHandler=e)},refreshValidationState:function(e,t){this.topControl.refreshValidationState(e,t)},disable:function(){this.topControl.disable()},enable:function(){this.topControl.enable()},focus:function(e){this.topControl.focus(function(t){e&&e(t)})},destroy:function(e){this.getFormEl().remove(),!e&&this.parent&&this.parent.destroy()},show:function(){this.getFormEl().css({display:""})},hide:function(){this.getFormEl().css({display:"none"})},clear:function(e){this.topControl.clear(e)},isEmpty:function(){return this.topControl.isEmpty()},fireCallback:function(e,t,n,i,a,r){this.view.fireCallback(this,e,t,n,i,a,r)},getFormEl:function(){return this.form},submit:function(){this.form.submit()},ajaxSubmit:function(n){var i=this;n||(n={}),n.url=i.options.attributes.action,n.type=i.options.attributes.method,n.data||(n.data=this.getValue()),n.dataType||(n.dataType="json"),n.headers||(n.headers={});var a=i.determineCsrfToken();return a&&(n.headers[t.CSRF_HEADER_NAME]=a),e.ajax(n)},determineCsrfToken:function(){var e=t.CSRF_TOKEN;if(!e)for(var n=0;ni;i+=1)indent+=" ";else"string"==typeof n&&(indent=n);if(rep=t,t&&"function"!=typeof t&&("object"!=typeof t||"number"!=typeof t.length))throw new Error("JSON.stringify");return this.str("",{"":e})},i.prototype.quote=function(e){var t=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;return t.lastIndex=0,t.test(e)?'"'+e.replace(t,function(e){var t=meta[e];return"string"==typeof t?t:"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'},i.prototype.str=function(e,t){var n,i,a,r,o,l=gap,s=t[e];switch(s&&"object"==typeof s&&"function"==typeof s.toJSON&&(s=s.toJSON(e)),"function"==typeof rep&&(s=rep.call(t,e,s)),typeof s){case"string":return this.quote(s);case"number":return isFinite(s)?String(s):"null";
case"boolean":case"null":return String(s);case"object":if(!s)return"null";if(gap+=indent,o=[],"[object Array]"===Object.prototype.toString.apply(s)){for(r=s.length,n=0;r>n;n+=1)o[n]=this.str(n,s)||"null";return a=0===o.length?"[]":gap?"[\n"+gap+o.join(",\n"+gap)+"\n"+l+"]":"["+o.join(",")+"]",gap=l,a}if(rep&&"object"==typeof rep)for(r=rep.length,n=0;r>n;n+=1)i=rep[n],"string"==typeof i&&(a=this.str(i,s),a&&o.push(this.quote(i)+(gap?": ":":")+a));else for(i in s)Object.hasOwnProperty.call(s,i)&&(a=this.str(i,s),a&&o.push(this.quote(i)+(gap?": ":":")+a));return a=0===o.length?"{}":gap?"{\n"+gap+o.join(",\n"+gap)+"\n"+l+"}":"{"+o.join(",")+"}",gap=l,a}}}(jQuery),function(e){var t=e.alpaca;t.CloudCmsConnector=t.Connector.extend({connect:function(e,n){var i=this,a=function(t,a){return t?void n(t):(a&&(i.branch=Chain(a),i.bindHelperFunctions(i.branch)),void e())};t.globalContext&&t.globalContext.branch?a(null,t.globalContext.branch):(i.branch=null,i.doConnect(function(e,t){a(e,t)}))},doConnect:function(e){this.config.key||(this.config.key="default"),Gitana.connect(this.config,function(t){return t?void e(t):void(this.getDriver().getOriginalConfiguration().loadAppHelper?this.datastore("content").readBranch("master").then(function(){e(null,this)}):e())})},bindHelperFunctions:function(e){e.loadAlpacaSchema||(e.loadAlpacaSchema=function(t,n,i){var a=function(){return e.getUri()+"/alpaca/schema"},r={};return r.id=t,this.chainGetResponse(this,a,r).then(function(e){i.call(this,null,e)})}),e.loadAlpacaOptions||(e.loadAlpacaOptions=function(t,n,i){var a=function(){return e.getUri()+"/alpaca/options"},r={};return r.schemaId=n.schemaSource,r.id=t,this.chainGetResponse(this,a,r).then(function(e){i.call(this,null,e)})}),e.loadAlpacaData||(e.loadAlpacaData=function(t,n,i){var a=function(){return e.getUri()+"/alpaca/data"},r={};return r.id=t,this.chainGetResponse(this,a,r).then(function(e){i.call(this,null,e)})}),e.loadAlpacaDataSource||(e.loadAlpacaDataSource=function(n,i,a){var r={};i&&t.copyInto(r,i);var o=function(){return e.getUri()+"/alpaca/datasource"};return this.chainPostResponse(this,o,r,n).then(function(e){a.call(this,null,e.datasource)})})},loadData:function(e,t,n,i){var a=this;return a.branch?void a.branch.loadAlpacaData(e,t,function(e,t){if(e)return void i(e);var a=null;t&&(a=JSON.parse(JSON.stringify(t))),n(a)}):this.base(e,t,n,i)},loadSchema:function(e,t,n,i){var a=this;return a.branch?void a.branch.loadAlpacaSchema(e,t,function(e,t){return e?void i(e):void n(t)}):this.base(e,t,n,i)},loadOptions:function(e,n,i,a){var r=this;return r.branch?void r.branch.loadAlpacaOptions(e,n,function(e,n){return e?void a(e):(n||(n={}),n.form.buttons={submit:{title:"Submit",click:function(e){var t=this,n=this.getValue();n||(n={});var i=this.ajaxSubmit({xhrFields:{withCredentials:!0},crossDomain:!0,processData:!1,data:JSON.stringify(n),contentType:"application/json; charset=utf-8"});i.done(function(){t.topControl.trigger("formSubmitSuccess")}),i.fail(function(){t.topControl.trigger("formSubmitFail")})}}},"undefined"==typeof n.focus&&(n.focus=t.defaultFocus),n.form.attributes.action=r.config.baseURL+n.form.attributes.action,void i(n))}):this.base(e,n,i,a)},loadReferenceSchema:function(e,t,n){var i=this;return i.loadSchema(e,t,n)},loadReferenceOptions:function(e,t,n){var i=this;return i.loadOptions(e,t,n)},loadDataSource:function(e,t,n){var i=this;if(!i.branch)return this.base(e,t,n);var a=e.pagination;return delete e.pagination,i.branch.loadAlpacaDataSource(e,a,function(e,i){return e?void n(e):void t(i)})}}),t.registerConnectorClass("cloudcms",t.CloudCmsConnector)}(jQuery),function(e){var t=e.alpaca;t.Fields.TextField=t.ControlField.extend({getFieldType:function(){return"text"},setup:function(){this.base(),this.inputType||(this.inputType="text"),this.options.inputType&&(this.inputType=this.options.inputType),this.options.data||(this.options.data={}),this.options.attributes||(this.options.attributes={}),"undefined"==typeof this.options.allowOptionalEmpty&&(this.options.allowOptionalEmpty=!0),this.options.autocomplete&&"string"==typeof this.options.autocomplete&&("on"===this.options.autocomplete.toLowerCase()?this.options.autocomplete=!0:"true"===this.options.autocomplete.toLowerCase()?this.options.autocomplete=!0:"yes"===this.options.autocomplete.toLowerCase()?this.options.autocomplete=!0:this.options.autocomplete=!1),"undefined"==typeof this.options.autocomplete&&(this.options.autocomplete=!1),"undefined"==typeof this.options.disallowEmptySpaces&&(this.options.disallowEmptySpaces=!1),"undefined"==typeof this.options.disallowOnlyEmptySpaces&&(this.options.disallowOnlyEmptySpaces=!1)},destroy:function(){this.base(),this.control&&this.control.typeahead&&this.options.typeahead&&e(this.control).typeahead("destroy")},postRender:function(e){var t=this;this.base(function(){t.control&&(t.applyAutocomplete(),t.applyMask(),t.applyTypeAhead(),t.updateMaxLengthIndicator()),e()})},applyAutocomplete:function(){var t=this;"undefined"!=typeof t.options.autocomplete&&(e(t.field).addClass("alpaca-autocomplete"),e(t.control).attr("autocomplete",t.options.autocomplete?"on":"off"),t.fireCallback("autocomplete"))},applyMask:function(){var e=this;e.control.mask&&e.options.maskString&&e.control.mask(e.options.maskString)},applyTypeAhead:function(){var n=this;if(n.control.typeahead&&n.options.typeahead&&!t.isEmpty(n.options.typeahead)){var i=n.options.typeahead.config;i||(i={});var a=n.options.typeahead.datasets;a||(a={}),a.name||(a.name=n.getId());var r=n.options.typeahead.events;if(r||(r={}),"local"===a.type||"remote"===a.type||"prefetch"===a.type){var o={datumTokenizer:function(e){var t="";for(var n in e)(e.hasOwnProperty(n)||e[n])&&(t+=" "+e[n]);return Bloodhound.tokenizers.whitespace(t)},queryTokenizer:Bloodhound.tokenizers.whitespace};if("local"===a.type){var l=[];if("function"==typeof a.source)o.local=a.source;else{for(var s=0;s=0?a="You have "+o+" characters remaining":(a="Your message is too long by "+-1*o+" characters",i=!0);var l=e(n.field).find(".alpaca-field-text-max-length-indicator");0===l.length&&(l=e(""),e(n.control).after(l)),e(l).html(a),e(l).removeClass("err"),i&&e(l).addClass("err")}},getControlValue:function(){var t=this,n=this._getControlVal(!0);if(t.control.mask&&t.options.maskString){var i=e(this.control).data(e.mask.dataName);i&&(n=i(),n=t.ensureProperType(n))}return n},setValue:function(e){this.control&&this.control.length>0&&(t.isEmpty(e)?this.control.val(""):this.control.val(e)),this.base(e),this.updateMaxLengthIndicator()},handleValidate:function(){var e=this.base(),n=this.validation,i=this._validatePattern();return n.invalidPattern={message:i?"":t.substituteTokens(this.getMessage("invalidPattern"),[this.schema.pattern]),status:i},i=this._validateMaxLength(),n.stringTooLong={message:i?"":t.substituteTokens(this.getMessage("stringTooLong"),[this.schema.maxLength]),status:i},i=this._validateMinLength(),n.stringTooShort={message:i?"":t.substituteTokens(this.getMessage("stringTooShort"),[this.schema.minLength]),status:i},e&&n.invalidPattern.status&&n.stringTooLong.status&&n.stringTooShort.status},_validatePattern:function(){if(this.schema.pattern){var e=this.getValue();if(""===e&&this.options.allowOptionalEmpty&&!this.isRequired())return!0;if(t.isEmpty(e)&&(e=""),"string"==typeof e&&!e.match(this.schema.pattern))return!1}return!0},_validateMinLength:function(){if(!t.isEmpty(this.schema.minLength)){var e=this.getValue();if(e!==e&&(e=""),""===e&&this.options.allowOptionalEmpty&&!this.isRequired())return!0;if(t.isEmpty(e)&&(e=""),(""+e).lengththis.schema.maxLength)return!1}return!0},focus:function(t){if(this.control&&this.control.length>0){var n=e(this.control).get(0);try{var i=n.value?n.value.length:0;n.selectionStart=i,n.selectionEnd=i}catch(a){}n.focus(),t&&t(this)}},getType:function(){return"string"},onKeyPress:function(e){var n=this;if(9!==e.keyCode&&37!==e.keyCode&&38!==e.keyCode&&39!==e.keyCode&&40!==e.keyCode){if(8===e.keyCode){if(!t.isEmpty(n.schema.minLength)&&(n.options.constrainLengths||n.options.constrainMinLength)){var i=n.getValue()||"";i.length<=n.schema.minLength&&(e.preventDefault(),e.stopImmediatePropagation())}}else if(!t.isEmpty(n.schema.maxLength)&&(n.options.constrainLengths||n.options.constrainMaxLength)){var i=n.getValue()||"";i.length>=n.schema.maxLength&&(e.preventDefault(),e.stopImmediatePropagation())}32===e.keyCode&&n.options.disallowEmptySpaces&&(e.preventDefault(),e.stopImmediatePropagation())}},onKeyUp:function(t){var n=this;n.updateMaxLengthIndicator(),e(this.field).trigger("fieldkeyup")},getTitle:function(){return"Single-Line Text"},getDescription:function(){return"Text field for single-line text."},getSchemaOfSchema:function(){return t.merge(this.base(),{properties:{minLength:{title:"Minimal Length",description:"Minimal length of the property value.",type:"number"},maxLength:{title:"Maximum Length",description:"Maximum length of the property value.",type:"number"},pattern:{title:"Pattern",description:"Regular expression for the property value.",type:"string"}}})},getOptionsForSchema:function(){return t.merge(this.base(),{fields:{"default":{helper:"Field default value",type:"text"},minLength:{type:"integer"},maxLength:{type:"integer"},pattern:{type:"text"}}})},getSchemaOfOptions:function(){return t.merge(this.base(),{properties:{size:{title:"Field Size",description:"Field size.",type:"number","default":40},maskString:{title:"Mask Expression",description:"Expression for the field mask. Field masking will be enabled if not empty.",type:"string"},placeholder:{title:"Field Placeholder",description:"Field placeholder.",type:"string"},typeahead:{title:"Type Ahead",description:"Provides configuration for the $.typeahead plugin if it is available. For full configuration options, see: https://github.com/twitter/typeahead.js"},allowOptionalEmpty:{title:"Allow Optional Empty",description:"Allows this non-required field to validate when the value is empty"},inputType:{title:"HTML5 Input Type",description:"Allows for the override of the underlying HTML5 input type. If not specified, an assumed value is provided based on the kind of input control (i.e. 'text', 'date', 'email' and so forth)",type:"string"},data:{title:"Data attributes for the underlying DOM input control",description:"Allows you to specify a key/value map of data attributes that will be added as DOM attribuets for the underlying input control. The data attributes will be added as data-{name}='{value}'.",type:"object"},autocomplete:{title:"HTML autocomplete attribute for the underlying DOM input control",description:"Allows you to specify the autocomplete attribute for the underlying input control whether or not field should have autocomplete enabled.",type:"string"},disallowEmptySpaces:{title:"Disallow Empty Spaces",description:"Whether to disallow the entry of empty spaces in the text",type:"boolean","default":!1},disallowOnlyEmptySpaces:{title:"Disallow Only Empty Spaces",description:"Whether to disallow the entry of only empty spaces in the text",type:"boolean","default":!1}}})},getOptionsForOptions:function(){return t.merge(this.base(),{fields:{size:{type:"integer"},maskString:{helper:"a - an alpha character;9 - a numeric character;* - an alphanumeric character",type:"text"},typeahead:{type:"object"},allowOptionalEmpty:{type:"checkbox"},inputType:{type:"text"},data:{type:"object"}}})}}),t.registerMessages({invalidPattern:"This field should have pattern {0}",stringTooShort:"This field should contain at least {0} numbers or characters",stringTooLong:"This field should contain at most {0} numbers or characters"}),t.registerFieldClass("text",t.Fields.TextField),t.registerDefaultSchemaFieldMapping("string","text")}(jQuery),function(e){var t=e.alpaca;t.Fields.TextAreaField=t.Fields.TextField.extend({getFieldType:function(){return"textarea"},setup:function(){this.base(),this.options.rows||(this.options.rows=5),this.options.cols||(this.options.cols=40)},handleValidate:function(){var e=this.base(),n=this.validation,i=this._validateWordCount();return n.wordLimitExceeded={message:i?"":t.substituteTokens(this.getMessage("wordLimitExceeded"),[this.options.wordlimit]),status:i},e&&n.wordLimitExceeded.status},_validateWordCount:function(){if(this.options.wordlimit&&this.options.wordlimit>-1){var e=this.data;if(e){var t=e.split(" ").length;if(t>this.options.wordlimit)return!1}}return!0},getTitle:function(){return"Multi-Line Text"},getDescription:function(){return"Textarea field for multiple line text."},getSchemaOfOptions:function(){return t.merge(this.base(),{properties:{rows:{title:"Rows",description:"Number of rows",type:"number","default":5},cols:{title:"Columns",description:"Number of columns",type:"number","default":40},wordlimit:{title:"Word Limit",description:"Limits the number of words allowed in the text area.",type:"number","default":-1}}})},getOptionsForOptions:function(){return t.merge(this.base(),{fields:{rows:{type:"integer"},cols:{type:"integer"},wordlimit:{type:"integer"}}})}}),t.registerMessages({wordLimitExceeded:"The maximum word limit of {0} has been exceeded."}),t.registerFieldClass("textarea",t.Fields.TextAreaField)}(jQuery),function(e){var t=e.alpaca;t.Fields.CheckBoxField=t.ControlField.extend({getFieldType:function(){return"checkbox"},setup:function(){var n=this;if(n.base(),"undefined"==typeof n.options.multiple&&("array"===n.schema.type?n.options.multiple=!0:"undefined"!=typeof n.schema["enum"]&&(n.options.multiple=!0)),n.options.multiple){if(n.checkboxOptions=[],n.getEnum()){n.sortEnum();var i=n.getOptionLabels();e.each(n.getEnum(),function(e,a){var r=a;i&&(t.isEmpty(i[e])?t.isEmpty(i[a])||(r=i[a]):r=i[e]),n.checkboxOptions.push({value:a,text:r})})}n.options.datasource&&!n.options.dataSource&&(n.options.dataSource=n.options.datasource,delete n.options.datasource),"undefined"==typeof n.options.useDataSourceAsEnum&&(n.options.useDataSourceAsEnum=!0)}else this.options.rightLabel||(this.options.rightLabel="")},prepareControlModel:function(e){var t=this;this.base(function(n){t.checkboxOptions&&(n.checkboxOptions=t.checkboxOptions),e(n)})},getEnum:function(){var e=this.base();return e||this.schema&&this.schema.items&&this.schema.items["enum"]&&(e=this.schema.items["enum"]),e},getOptionLabels:function(){var e=this.base();return e||this.options&&this.options.items&&this.options.items.optionLabels&&(e=this.options.items.optionLabels),e},onClick:function(e){this.refreshValidationState()},beforeRenderControl:function(e,t){var n=this;this.base(e,function(){n.options.dataSource?(n.options.multiple=!0,n.checkboxOptions||(e.checkboxOptions=n.checkboxOptions=[]),n.checkboxOptions.length=0,n.invokeDataSource(n.checkboxOptions,e,function(e){if(n.options.useDataSourceAsEnum){for(var i=[],a=[],r=0;r0?t.checked(e(s[0])):!1}return i},setValue:function(n){var i=this,a=function(n){t.isString(n)&&(n="true"===n);var a=e(i.getFieldEl()).find("input");a.length>0&&t.checked(e(a[0]),n)},r=function(a){"string"==typeof a&&(a=a.split(","));for(var r=0;r0&&t.checked(e(l[0]),n)}},o=!1;i.options.multiple?"string"==typeof n?(r(n),o=!0):t.isArray(n)&&(r(n),o=!0):"boolean"==typeof n?(a(n),o=!0):"string"==typeof n&&(a(n),o=!0),!o&&n&&t.logError("CheckboxField cannot set value for schema.type="+i.schema.type+" and value="+n),this.base(n)},_validateEnum:function(){var e=this;if(!e.options.multiple)return!0;var n=e.getValue();return!e.isRequired()&&t.isValEmpty(n)?!0:("string"==typeof n&&(n=n.split(",")),t.anyEquality(n,e.getEnum()))},disable:function(){e(this.control).find("input").each(function(){e(this).disabled=!0,e(this).prop("disabled",!0)})},enable:function(){e(this.control).find("input").each(function(){e(this).disabled=!1,e(this).prop("disabled",!1)})},getType:function(){return"boolean"},getTitle:function(){return"Checkbox Field"},getDescription:function(){return"Checkbox Field for boolean (true/false), string ('true', 'false' or comma-delimited string of values) or data array."},getSchemaOfOptions:function(){return t.merge(this.base(),{properties:{rightLabel:{title:"Option Label",description:"Optional right-hand side label for single checkbox field.",type:"string"},multiple:{title:"Multiple",description:"Whether to render multiple checkboxes for multi-valued type (such as an array or a comma-delimited string)",type:"boolean"},dataSource:{title:"Option DataSource",description:"Data source for generating list of options. This can be a string or a function. If a string, it is considered to be a URI to a service that produces a object containing key/value pairs or an array of elements of structure {'text': '', 'value': ''}. This can also be a function that is called to produce the same list.",type:"string"},useDataSourceAsEnum:{title:"Use Data Source as Enumerated Values",description:"Whether to constrain the field's schema enum property to the values that come back from the data source.",type:"boolean","default":!0}}})},getOptionsForOptions:function(){return t.merge(this.base(),{fields:{rightLabel:{type:"text"},multiple:{type:"checkbox"},dataSource:{type:"text"}}})}}),t.registerFieldClass("checkbox",t.Fields.CheckBoxField),t.registerDefaultSchemaFieldMapping("boolean","checkbox")}(jQuery),function(e){var t=e.alpaca;t.Fields.FileField=t.Fields.TextField.extend({getFieldType:function(){return"file"},setValue:function(e){this.data=e,this.data=e,this.updateObservable(),this.triggerUpdate()},getControlValue:function(){return this.data},onChange:function(e){this.base(e),this.options.selectionHandler&&this.processSelectionHandler(e.target.files)},processSelectionHandler:function(e){if(e&&e.length>0&&"undefined"!=typeof FileReader){var t=[],n=0,i=new FileReader;i.onload=function(){var i=this;return function(a){var r=a.target.result;t.push(r),n++,n===e.length&&i.options.selectionHandler.call(i,e,t)}}.call(this);for(var a=0;a0&&(n.data=a[0])}n.options.datasource&&!n.options.dataSource&&(n.options.dataSource=n.options.datasource,delete n.options.datasource),"undefined"==typeof n.options.useDataSourceAsEnum&&(n.options.useDataSourceAsEnum=!0)},prepareControlModel:function(e){var t=this;this.base(function(n){"undefined"==typeof t.options.noneLabel&&(t.options.noneLabel=t.getMessage("noneLabel")),"undefined"==typeof t.options.hideNone&&("undefined"!=typeof t.options.removeDefaultNone?t.options.hideNone=t.options.removeDefaultNone:t.options.hideNone=t.isRequired()),e(n)})},convertValue:function(n){var i=this;return t.isArray(n)?e.each(n,function(t,a){e.each(i.selectOptions,function(e,i){i.value===a&&(n[t]=i.value)})}):e.each(this.selectOptions,function(e,t){t.value===n&&(n=t.value)}),n},beforeRenderControl:function(e,t){var n=this;this.base(e,function(){n.options.dataSource?(n.selectOptions.length=0,n.invokeDataSource(n.selectOptions,e,function(){if(n.options.useDataSourceAsEnum){for(var e=[],i=[],a=0;a0&&(a.data=a.selectOptions[0].value,0===e("input:radio:checked",a.control).length&&t.checked(e(a.control).find('input:radio[value="'+a.data+'"]'),"checked")),a.options.vertical?e(a.control).css("display","block"):e(a.control).css("display","inline-block"),i()})},onClick:function(t){var n=this,i=n.getValue();this.base(t);var a=e(t.currentTarget).find("input").val();"undefined"!=typeof a&&(n.setValue(a),n.refreshValidationState(),i!==a&&n.trigger("change"))},disable:function(){this.base(),this.getFieldEl().addClass("disabled")},enable:function(){this.base(),this.getFieldEl().removeClass("disabled")},getTitle:function(){return"Radio Group Field"},getDescription:function(){return"Radio Group Field with list of options."},getSchemaOfOptions:function(){return t.merge(this.base(),{properties:{name:{title:"Field name",description:"Field name.",type:"string"},emptySelectFirst:{title:"Empty Select First",description:"If the data is empty, then automatically select the first item in the list.",type:"boolean","default":!1},vertical:{title:"Position the radio selector items vertically",description:"By default, radio controls are stacked vertically. Set to false if you'd like radio controls to lay out horizontally.",type:"boolean","default":!0}}})}}),t.registerFieldClass("radio",t.Fields.RadioField)}(jQuery),function(e){var t=e.alpaca;t.Fields.SelectField=t.Fields.ListField.extend({getFieldType:function(){return"select"},setup:function(){this.base()},getControlValue:function(){var e=this._getControlVal(!0);return"undefined"==typeof e&&(e=this.data),this.convertValue(e)},setValue:function(e){t.isArray(e)?t.compareArrayContent(e,this.getValue())||(!t.isEmpty(e)&&this.control&&this.control.val(e),this.base(e)):e!==this.getValue()&&(this.control&&"undefined"!=typeof e&&null!=e&&this.control.val(e),this.base(e))},getEnum:function(){if(this.schema){if(this.schema["enum"])return this.schema["enum"];if(this.schema.type&&"array"===this.schema.type&&this.schema.items&&this.schema.items["enum"])return this.schema.items["enum"]}},initControlEvents:function(){var e=this;if(e.base(),e.options.multiple){var t=this.control.parent().find("button.multiselect");t.focus(function(t){e.suspendBlurFocus||(e.onFocus.call(e,t),e.trigger("focus",t))}),t.blur(function(t){e.suspendBlurFocus||(e.onBlur.call(e,t),e.trigger("blur",t))})}},beforeRenderControl:function(e,t){var n=this;this.base(e,function(){n.schema.type&&"array"===n.schema.type&&(n.options.multiple=!0),t()})},prepareControlModel:function(e){var t=this;this.base(function(n){n.selectOptions=t.selectOptions,e(n)})},afterRenderControl:function(n,i){var a=this;this.base(n,function(){if(t.isUndefined(a.data)&&a.options.emptySelectFirst&&a.selectOptions&&a.selectOptions.length>0&&(a.data=a.selectOptions[0].value),a.data&&a.setValue(a.data),a.options.multiple&&e.fn.multiselect){var n=null;n=a.options.multiselect?a.options.multiselect:{},n.nonSelectedText||(n.nonSelectedText="None",a.options.noneLabel&&(n.nonSelectedText=a.options.noneLabel)),a.options.hideNone&&delete n.nonSelectedText,e(a.getControlEl()).multiselect(n)}i()})},_validateEnum:function(){var n=this;if(this.schema["enum"]){var i=this.data;if(!this.isRequired()&&t.isValEmpty(i))return!0;if(this.options.multiple){var a=!0;return i||(i=[]),t.isArray(i)||t.isObject(i)||(i=[i]),e.each(i,function(t,i){return e.inArray(i,n.schema["enum"])<=-1?(a=!1,!1):void 0}),a}return t.isArray(i)&&(i=i[0]),e.inArray(i,this.schema["enum"])>-1}return!0},onChange:function(e){this.base(e);var n=this;t.later(25,this,function(){var e=n.getValue();n.setValue(e),n.refreshValidationState()})},_validateMinItems:function(){return!(this.schema.items&&this.schema.items.minItems&&e(":selected",this.control).lengththis.schema.items.maxItems)},handleValidate:function(){var e=this.base(),n=this.validation,i=this._validateMaxItems();return n.tooManyItems={message:i?"":t.substituteTokens(this.getMessage("tooManyItems"),[this.schema.items.maxItems]),status:i},i=this._validateMinItems(),n.notEnoughItems={message:i?"":t.substituteTokens(this.getMessage("notEnoughItems"),[this.schema.items.minItems]),status:i},e&&n.tooManyItems.status&&n.notEnoughItems.status},focus:function(t){if(this.control&&this.control.length>0){var n=e(this.control).get(0);n.focus(),t&&t(this)}},getTitle:function(){return"Select Field"},getDescription:function(){return"Select Field"},getSchemaOfOptions:function(){return t.merge(this.base(),{properties:{multiple:{title:"Mulitple Selection",description:"Allow multiple selection if true.",type:"boolean","default":!1},size:{title:"Displayed Options",description:"Number of options to be shown.",type:"number"},emptySelectFirst:{title:"Empty Select First",description:"If the data is empty, then automatically select the first item in the list.",type:"boolean","default":!1},multiselect:{title:"Multiselect Plugin Settings",description:"Multiselect plugin properties - http://davidstutz.github.io/bootstrap-multiselect",type:"any"}}})},getOptionsForOptions:function(){return t.merge(this.base(),{fields:{multiple:{rightLabel:"Allow multiple selection ?",helper:"Allow multiple selection if checked",type:"checkbox"},size:{type:"integer"},emptySelectFirst:{type:"checkbox",rightLabel:"Empty Select First"},multiselect:{type:"object",rightLabel:"Multiselect plugin properties - http://davidstutz.github.io/bootstrap-multiselect"}}})}}),t.registerFieldClass("select",t.Fields.SelectField)}(jQuery),function(e){var t=e.alpaca;t.Fields.NumberField=t.Fields.TextField.extend({setup:function(){this.base(),"undefined"==typeof this.options.numericEntry&&(this.options.numericEntry=!1)},getFieldType:function(){return"number"},postRender:function(e){var t=this;this.base(function(){t.control&&t.on("keypress",function(e){var n=e.charCode||e.keyCode||0,i=!0;return t.options.numericEntry&&(i=i&&n>=48&&57>=n),i||(e.preventDefault(),
e.stopImmediatePropagation()),i}),e()})},getControlValue:function(){var e=this._getControlVal(!0);return"undefined"==typeof e||""==e?e:parseFloat(e)},handleValidate:function(){var e=this.base(),n=this.validation,i=this._validateNumber();return n.stringNotANumber={message:i?"":this.getMessage("stringNotANumber"),status:i},i=this._validateDivisibleBy(),n.stringDivisibleBy={message:i?"":t.substituteTokens(this.getMessage("stringDivisibleBy"),[this.schema.divisibleBy]),status:i},i=this._validateMaximum(),n.stringValueTooLarge={message:"",status:i},i||(this.schema.exclusiveMaximum?n.stringValueTooLarge.message=t.substituteTokens(this.getMessage("stringValueTooLargeExclusive"),[this.schema.maximum]):n.stringValueTooLarge.message=t.substituteTokens(this.getMessage("stringValueTooLarge"),[this.schema.maximum])),i=this._validateMinimum(),n.stringValueTooSmall={message:"",status:i},i||(this.schema.exclusiveMinimum?n.stringValueTooSmall.message=t.substituteTokens(this.getMessage("stringValueTooSmallExclusive"),[this.schema.minimum]):n.stringValueTooSmall.message=t.substituteTokens(this.getMessage("stringValueTooSmall"),[this.schema.minimum])),i=this._validateMultipleOf(),n.stringValueNotMultipleOf={message:"",status:i},i||(n.stringValueNotMultipleOf.message=t.substituteTokens(this.getMessage("stringValueNotMultipleOf"),[this.schema.multipleOf])),e&&n.stringNotANumber.status&&n.stringDivisibleBy.status&&n.stringValueTooLarge.status&&n.stringValueTooSmall.status&&n.stringValueNotMultipleOf.status&&n.invalidPattern.status&&n.stringTooLong.status&&n.stringTooShort.status},_validateOptional:function(){return!this.isRequired()||!t.isValEmpty(e(this.control).val())},_validateNumber:function(){var e=this._getControlVal();if("number"==typeof e&&(e=""+e),t.isValEmpty(e))return!0;var n=t.testRegex(t.regexps.number,e);if(!n)return!1;var i=this.getValue();return!isNaN(i)},_validateDivisibleBy:function(){var e=this.getValue();return!(!t.isEmpty(this.schema.divisibleBy)&&e%this.schema.divisibleBy!==0)},_validateMaximum:function(){var e=this.getValue();if(!t.isEmpty(this.schema.maximum)){if(e>this.schema.maximum)return!1;if(!t.isEmpty(this.schema.exclusiveMaximum)&&e==this.schema.maximum&&this.schema.exclusiveMaximum)return!1}return!0},_validateMinimum:function(){var e=this.getValue();if(!t.isEmpty(this.schema.minimum)){if(e=n.schema.maxLength&&(e.preventDefault(),e.stopImmediatePropagation())}32===e.keyCode&&n.options.disallowEmptySpaces&&(e.preventDefault(),e.stopImmediatePropagation())}},onKeyUp:function(t){var n=this;n.updateMaxLengthIndicator(),e(this.field).trigger("fieldkeyup")},getSchemaOfSchema:function(){return t.merge(this.base(),{properties:{multipleOf:{title:"Multiple Of",description:"Property value must be a multiple of the multipleOf schema property such that division by this value yields an interger (mod zero).",type:"number"},minimum:{title:"Minimum",description:"Minimum value of the property.",type:"number"},maximum:{title:"Maximum",description:"Maximum value of the property.",type:"number"},exclusiveMinimum:{title:"Exclusive Minimum",description:"Property value can not equal the number defined by the minimum schema property.",type:"boolean","default":!1},exclusiveMaximum:{title:"Exclusive Maximum",description:"Property value can not equal the number defined by the maximum schema property.",type:"boolean","default":!1}}})},getOptionsForSchema:function(){return t.merge(this.base(),{fields:{multipleOf:{title:"Multiple Of",description:"The value must be a integral multiple of the property",type:"number"},minimum:{title:"Minimum",description:"Minimum value of the property",type:"number"},maximum:{title:"Maximum",description:"Maximum value of the property",type:"number"},exclusiveMinimum:{rightLabel:"Exclusive minimum ?",helper:"Field value must be greater than but not equal to this number if checked",type:"checkbox"},exclusiveMaximum:{rightLabel:"Exclusive Maximum ?",helper:"Field value must be less than but not equal to this number if checked",type:"checkbox"}}})},getSchemaOfOptions:function(){return t.merge(this.base(),{properties:{numericEntry:{title:"Numeric Entry",description:"Whether to constrain data entry key presses to numeric values (0-9)",type:"boolean","default":!1}}})},getTitle:function(){return"Number Field"},getDescription:function(){return"Field for float numbers."}}),t.registerMessages({stringValueTooSmall:"The minimum value for this field is {0}",stringValueTooLarge:"The maximum value for this field is {0}",stringValueTooSmallExclusive:"Value of this field must be greater than {0}",stringValueTooLargeExclusive:"Value of this field must be less than {0}",stringDivisibleBy:"The value must be divisible by {0}",stringNotANumber:"This value is not a number.",stringValueNotMultipleOf:"This value is not a multiple of {0}"}),t.registerFieldClass("number",t.Fields.NumberField),t.registerDefaultSchemaFieldMapping("number","number")}(jQuery),function(e){var t=e.alpaca;t.Fields.ArrayField=t.ContainerField.extend({getFieldType:function(){return"array"},setup:function(){var n=this;this.base();var i=n.resolveContainerItemTemplateType();if(!i)return t.throwErrorWithCallback("Unable to find template descriptor for container item: "+n.getFieldType());this.containerItemTemplateDescriptor=n.view.getTemplateDescriptor("container-"+i+"-item",n),this.options.toolbarStyle||(this.options.toolbarStyle=t.isEmpty(this.view.toolbarStyle)?"button":this.view.toolbarStyle),this.options.toolbarStyle||(this.options.toolbarStyle="button"),this.options.actionbarStyle||(this.options.actionbarStyle=t.isEmpty(this.view.actionbarStyle)?"top":this.view.actionbarStyle),this.options.actionbarStyle||(this.options.actionbarStyle="top"),this.schema.items||(this.schema.items={}),this.options.items||(this.options.items={}),this.schema.items.maxItems&&(this.schema.maxItems=this.schema.items.maxItems,delete this.schema.items.maxItems),this.schema.items.minItems&&(this.schema.minItems=this.schema.items.minItems,delete this.schema.items.minItems),this.schema.items.uniqueItems&&(this.schema.uniqueItems=this.schema.items.uniqueItems,delete this.schema.items.uniqueItems),this.options.rubyrails=!1,this.parent&&this.parent.options&&this.parent.options.form&&this.parent.options.form.attributes&&(t.isEmpty(this.parent.options.form.attributes.rubyrails)||(this.options.rubyrails=!0));var a=t.defaultToolbarSticky;if(t.isEmpty(this.view.toolbarSticky)||(a=this.view.toolbarSticky),t.isEmpty(this.options.toolbarSticky)||(a=this.options.toolbarSticky),this.options.toolbarSticky=a,"undefined"==typeof n.options.hideToolbarWithChildren&&(n.options.hideToolbarWithChildren=!0),this.schema.items&&this.schema.uniqueItems&&t.mergeObject(this.options,{forceRevalidation:!0}),"undefined"==typeof this.data&&(this.data=[]),null==this.data&&(this.data=[]),""==this.data&&(this.data=[]),t.isString(this.data))try{var r=t.parseJSON(this.data);if(!t.isArray(r)&&!t.isObject(r))return void t.logWarn("ArrayField parsed string data but it was not an array: "+this.data);this.data=r}catch(o){this.data=[this.data]}if(!t.isArray(this.data)&&!t.isObject(this.data))return void t.logWarn("ArrayField data is not an array: "+JSON.stringify(this.data,null," "));var l=function(e,t,i){var a=n.findAction(e,t);a||(a={core:!0},e.push(a));for(var r in i)a[r]||(a[r]=i[r])},s=function(e,t){var n=0;do"undefined"==typeof e[n].enabled&&(e[n].enabled=!0),t||delete e[n].label,e[n].enabled?n++:e.splice(n,1);while(ni?(a.setValue(e[i]),i++):n.removeItem(i)}while(i0?n.resolveItemSchemaOptions(function(a,r,o){if(o)return t.throwErrorWithCallback("Circular reference detected for schema: "+JSON.stringify(a),n.errorCallback);for(var l=[],s=0;s");s.alpaca({data:r,options:a,schema:i,view:this.view.id?this.view.id:this.view,connector:this.connector,error:function(e){l.destroy(),l.errorCallback.call(l,e)},notTopLevel:!0,render:function(e,t){e.parent=l,e.path=l.path+"["+n+"]",e.render(null,function(){l.updatePathAndName(),l.triggerUpdate(),t&&t()})},postRender:function(n){var i=t.tmpl(l.containerItemTemplateDescriptor,{id:l.getId(),name:n.name,parentFieldId:l.getId(),actionbarStyle:l.options.actionbarStyle,view:l.view,data:r}),a=e(i).find("."+t.MARKER_CLASS_CONTAINER_FIELD_ITEM_FIELD);return 0===a.length&&e(i).hasClass(t.MARKER_CLASS_CONTAINER_FIELD_ITEM_FIELD)&&(a=e(i)),0===a.length?void l.errorCallback.call(l,{message:"Cannot find insertion point for field: "+l.getId()}):(e(a).before(n.getFieldEl()),e(a).remove(),n.containerItemEl=i,t.fieldApplyFieldAndChildren(n,function(e){e.hideInitValidationError=!1}),t.isFunction(l.options.items.postRender)&&l.options.items.postRender.call(n,a),void(o&&o(n)))}})}},resolveItemSchemaOptions:function(e){var n,i=this,a=function(t,n,a){i.options.readonly&&(n.readonly=!0),e(t,n,a)};!n&&i.options&&i.options.fields&&i.options.fields.item&&(n=i.options.fields.item),!n&&i.options&&i.options.items&&(n=i.options.items);var r;if(i.schema&&i.schema.items&&(r=i.schema.items),r&&r.$ref){for(var o=r.$ref,l=this,s=[l];l.parent;)l=l.parent,s.push(l);var u=r,c=n;t.loadRefSchemaOptions(l,o,function(e,n){for(var i=0,r=0;r10,d={};u&&t.mergeObject(d,u),e&&t.mergeObject(d,e),delete d.id;var p={};c&&t.mergeObject(p,c),n&&t.mergeObject(p,n),t.nextTick(function(){a(d,p,l)})})}else t.nextTick(function(){a(r,n)})},handleValidate:function(){var e=this.base(),n=this.validation,i=this._validateUniqueItems();return n.valueNotUnique={message:i?"":this.getMessage("valueNotUnique"),status:i},i=this._validateMaxItems(),n.tooManyItems={message:i?"":t.substituteTokens(this.getMessage("tooManyItems"),[this.schema.maxItems]),status:i},i=this._validateMinItems(),n.notEnoughItems={message:i?"":t.substituteTokens(this.getMessage("notEnoughItems"),[this.schema.minItems]),status:i},e&&n.valueNotUnique.status&&n.tooManyItems.status&&n.notEnoughItems.status},_validateEqualMaxItems:function(){return!(this.schema.maxItems&&this.schema.maxItems>=0&&this.getSize()>=this.schema.maxItems)},_validateEqualMinItems:function(){return!(this.schema.minItems&&this.schema.minItems>=0&&this.getSize()<=this.schema.minItems)},_validateMinItems:function(){return!(this.schema.minItems&&this.schema.minItems>=0&&this.getSize()=0&&this.getSize()>this.schema.maxItems)},_validateUniqueItems:function(){if(this.schema.items&&this.schema.uniqueItems)for(var e={},t=0;t0&&e.each(this.children,function(t,i){var a=i.path.lastIndexOf("/"),r=i.path.substring(a+1);r.indexOf("[")<0&&r.indexOf("]")<0&&(r=r.substring(r.indexOf("[")+1,r.indexOf("]"))),r!==t&&(i.prePath=i.path,i.path=i.path.substring(0,a)+"/["+t+"]"),i.nameCalculated&&(i.preName=i.name,i.parent&&i.parent.name&&i.path?i.name=i.parent.name+"_"+t:i.path&&(i.name=i.path.replace(/\//g,"").replace(/\[/g,"_").replace(/\]/g,"")),this.parent.options.rubyrails?e(i.field).attr("name",i.parent.name):e(i.field).attr("name",i.name)),i.prePath||(i.prePath=i.path),n(i)})},updateToolbars:function(){var t=this;if("display"!==this.view.type&&!this.schema.readonly){t.toolbar&&(t.fireCallback("arrayToolbar",!0),t.fireCallback("arrayToolbar")),t.actionbar&&(t.fireCallback("arrayActionbars",!0),t.fireCallback("arrayActionbars"));var n=e(this.getFieldEl()).find(".alpaca-array-toolbar[data-alpaca-array-toolbar-field-id='"+t.getId()+"']");if(this.children.length>0&&t.options.hideToolbarWithChildren?e(n).hide():(e(n).show(),e(n).find("[data-alpaca-array-toolbar-action]").each(function(){var n=e(this).attr("data-alpaca-array-toolbar-action"),i=t.findAction(t.toolbar.actions,n);i&&e(this).off().click(function(e){e.preventDefault(),i.click.call(t,n,i)})})),"undefined"==typeof this.options.toolbarSticky||null===this.options.toolbarSticky){var i=this.getFieldEl().find(".alpaca-container-item[data-alpaca-container-item-parent-field-id='"+t.getId()+"']");e(i).each(function(n){var i=e(t.getFieldEl()).find(".alpaca-array-actionbar[data-alpaca-array-actionbar-parent-field-id='"+t.getId()+"'][data-alpaca-array-actionbar-item-index='"+n+"']");i&&i.length>0&&(e(this).hover(function(){e(i).show()},function(){e(i).hide()}),e(i).hide())})}else this.options.toolbarSticky?e(t.getFieldEl()).find(".alpaca-array-actionbar[data-alpaca-array-actionbar-parent-field-id='"+t.getId()+"']").css("display","inline-block"):this.options.toolbarSticky||e(t.getFieldEl()).find(".alpaca-array-actionbar[data-alpaca-array-actionbar-parent-field-id='"+t.getId()+"']").hide();var a=e(t.getFieldEl()).find(".alpaca-array-actionbar[data-alpaca-array-actionbar-parent-field-id='"+t.getId()+"']");e(a).each(function(){var n=e(this).attr("data-alpaca-array-actionbar-item-index");"string"==typeof n&&(n=parseInt(n,10)),e(this).children("[data-alpaca-array-actionbar-action]").each(function(){var i=e(this).attr("data-alpaca-array-actionbar-action"),a=t.findAction(t.actionbar.actions,i);a&&e(this).off().click(function(e){e.preventDefault(),a.click.call(t,i,a,n)})}),t._validateEqualMaxItems()?(e(this).children("[data-alpaca-array-toolbar-action='add']").each(function(n){e(this).removeClass("alpaca-button-disabled"),t.fireCallback("enableButton",this)}),e(this).children("[data-alpaca-array-actionbar-action='add']").each(function(n){e(this).removeClass("alpaca-button-disabled"),t.fireCallback("enableButton",this)})):(e(this).children("[data-alpaca-array-toolbar-action='add']").each(function(n){e(this).addClass("alpaca-button-disabled"),t.fireCallback("disableButton",this)}),e(this).children("[data-alpaca-array-actionbar-action='add']").each(function(n){e(this).addClass("alpaca-button-disabled"),t.fireCallback("disableButton",this)})),t._validateEqualMinItems()?e(this).children("[data-alpaca-array-actionbar-action='remove']").each(function(n){e(this).removeClass("alpaca-button-disabled"),t.fireCallback("enableButton",this)}):e(this).children("[data-alpaca-array-actionbar-action='remove']").each(function(n){e(this).addClass("alpaca-button-disabled"),t.fireCallback("disableButton",this)})}),e(a).first().children("[data-alpaca-array-actionbar-action='up']").each(function(){e(this).addClass("alpaca-button-disabled"),t.fireCallback("disableButton",this)}),e(a).last().children("[data-alpaca-array-actionbar-action='down']").each(function(){e(this).addClass("alpaca-button-disabled"),t.fireCallback("disableButton",this)})}},doResolveItemContainer:function(){var t=this;return e(t.container)},handleToolBarAddItemClick:function(e){var n=this;n.resolveItemSchemaOptions(function(i,a,r){if(r)return t.throwErrorWithCallback("Circular reference detected for schema: "+JSON.stringify(i),n.errorCallback);var o=n.children.length,l=t.createEmptyDataInstance(i);n.addItem(o,i,a,l,function(t){e&&e(t)})})},handleActionBarAddItemClick:function(e,n){var i=this;i.resolveItemSchemaOptions(function(a,r,o){if(o)return t.throwErrorWithCallback("Circular reference detected for schema: "+JSON.stringify(a),i.errorCallback);var l=t.createEmptyDataInstance(a);i.addItem(e+1,a,r,l,function(e){n&&n(e)})})},handleActionBarRemoveItemClick:function(e,t){var n=this;n.removeItem(e,function(){t&&t()})},handleActionBarMoveItemUpClick:function(e,t){var n=this;n.swapItem(e,e-1,n.options.animate,function(){t&&t()})},handleActionBarMoveItemDownClick:function(e,t){var n=this;n.swapItem(e,e+1,n.options.animate,function(){t&&t()})},doAddItem:function(n,i,a){var r=this,o=r.doResolveItemContainer();if(0===n)e(o).append(i.containerItemEl);else{var l=o.children("[data-alpaca-container-item-index='"+(n-1)+"']");l&&l.length>0&&l.after(i.containerItemEl)}r.doAfterAddItem(i,function(e){t.fireReady(i),a(e)})},doAfterAddItem:function(e,t){t()},addItem:function(e,t,n,i,a){var r=this;r._validateEqualMaxItems()&&r.createItem(e,t,n,i,function(t){r.registerChild(t,e),r.doAddItem(e,t,function(){r.handleRepositionDOMRefresh(),r.updateToolbars(),r.refreshValidationState(),r.trigger("add",t),r.triggerUpdate(),a&&a(t)})})},doRemoveItem:function(e,t){var n=this,i=n.doResolveItemContainer();i.children(".alpaca-container-item[data-alpaca-container-item-index='"+e+"']").remove(),n.doAfterRemoveItem(e,function(e){t(e)})},doAfterRemoveItem:function(e,t){t()},removeItem:function(e,t){var n=this;this._validateEqualMinItems()&&(n.unregisterChild(e),n.doRemoveItem(e,function(){n.handleRepositionDOMRefresh(),n.updateToolbars(),n.refreshValidationState(),n.trigger("remove",e),n.triggerUpdate(),t&&t()}))},moveItem:function(n,i,a,r){var o=this;if("function"==typeof a&&(r=a,a=o.options.animate),"undefined"==typeof a&&(a=o.options.animate?o.options.animate:!0),"string"==typeof n&&(n=parseInt(n,10)),"string"==typeof i&&(i=parseInt(i,10)),0>i&&(i=0),i>=o.children.length&&(i=o.children.length-1),-1!==i&&n!==i){var l=o.children[i];if(l){var s=function(){var e=i;i>n&&e--;var t=o.children.splice(n,1)[0];o.children.splice(e,0,t),o.data=o.getValue(),o.refresh(function(){o.refreshValidationState(),o.triggerUpdate(),o.trigger("move"),r&&r()})},u=0;if(a&&(u=500),u>0){var c=o.getId(),d=o.getContainerEl().find(".alpaca-container-item[data-alpaca-container-item-index='"+n+"'][data-alpaca-container-item-parent-field-id='"+c+"']"),p=o.getContainerEl().find(".alpaca-container-item[data-alpaca-container-item-index='"+i+"'][data-alpaca-container-item-parent-field-id='"+c+"']"),h=e("");d.before(h);var f=e("");p.before(f),t.animatedMove(d,p,u,function(){s()})}else s()}}},swapItem:function(n,i,a,r){var o=this;if("function"==typeof a&&(r=a,a=o.options.animate),"undefined"==typeof a&&(a=o.options.animate?o.options.animate:!0),"string"==typeof n&&(n=parseInt(n,10)),"string"==typeof i&&(i=parseInt(i,10)),0>i&&(i=0),i>=o.children.length&&(i=o.children.length-1),-1!==i&&n!==i){var l=o.children[i];if(l){var s=function(){var e=o.children[n],t=o.children[i];o.children[n]=t,o.children[i]=e,o.data=o.getValue(),o.refresh(function(){o.refreshValidationState(),o.triggerUpdate(),o.trigger("move"),r&&r()})},u=0;if(a&&(u=500),u>0){var c=o.getId(),d=o.getContainerEl().find(".alpaca-container-item[data-alpaca-container-item-index='"+n+"'][data-alpaca-container-item-parent-field-id='"+c+"']"),p=o.getContainerEl().find(".alpaca-container-item[data-alpaca-container-item-index='"+i+"'][data-alpaca-container-item-parent-field-id='"+c+"']"),h=e("");d.before(h);var f=e("");p.before(f),t.animatedSwap(d,p,u,function(){s()})}else s()}}},getType:function(){return"array"},getTitle:function(){return"Array Field"},getDescription:function(){return"Field for list of items with same data type or structure."},getSchemaOfSchema:function(){var e={properties:{items:{title:"Array Items",description:"Schema for array items.",type:"object"},minItems:{title:"Minimum Items",description:"Minimum number of items.",type:"number"},maxItems:{title:"Maximum Items",description:"Maximum number of items.",type:"number"},uniqueItems:{title:"Items Unique",description:"Item values should be unique if true.",type:"boolean","default":!1}}};return this.children&&this.children[0]&&t.merge(e.properties.items.properties,this.children[0].getSchemaOfSchema()),t.merge(this.base(),e)},getOptionsForSchema:function(){return t.merge(this.base(),{fields:{items:{type:"object"},minItems:{type:"integer"},maxItems:{type:"integer"},uniqueItems:{type:"checkbox"}}})},getSchemaOfOptions:function(){var e={properties:{toolbarSticky:{title:"Sticky Toolbar",description:"If true, the array item toolbar will always be enabled. If false, the toolbar is always disabled. If undefined or null, the toolbar will appear when hovered over.",type:"boolean","default":void 0},toolbarStyle:{title:"Toolbar Style",description:"The kind of top-level toolbar to render for the array field. Either 'button' or 'link'.",type:"string","default":"button"},actionbarStyle:{title:"Actionbar Style",description:"The kind of actionbar to render for each item in the array. Either 'top', 'bottom', 'left', or 'right'.",type:"string","default":"top"},toolbar:{type:"object",title:"Toolbar Configuration",properties:{showLabels:{type:"boolean","default":!0,title:"Whether to show labels next to actions"},actions:{type:"array",title:"Toolbar Actions Configuration",items:{action:{type:"string",title:"Action Key"},label:{type:"string",title:"Action Label"},iconClass:{type:"string",title:"Action CSS Classes for Icon"},click:{type:"function",title:"Action Click Handler"},enabled:{type:"boolean",title:"Whether to enable the action","default":!0}}}}},actionbar:{type:"object",properties:{showLabels:{type:"boolean","default":!1,title:"Whether to show labels next to actions"},actions:{type:"array",title:"Actions Bar Actions Configuration",items:{action:{type:"string",title:"Action Key"},label:{type:"string",title:"Action Label"},iconClass:{type:"string",title:"Action CSS Classes for Icon"},click:{type:"function",title:"Action Click Handler"},enabled:{type:"boolean",title:"Whether to enable the action","default":!0}}}}},hideToolbarWithChildren:{type:"boolean",title:"Hide Toolbar with Children",description:"Indicates whether to hide the top toolbar when child elements are available.","default":!0}}};return this.children&&this.children[0]&&t.merge(e.properties.items.properties,this.children[0].getSchemaOfSchema()),t.merge(this.base(),e)},getOptionsForOptions:function(){return t.merge(this.base(),{fields:{toolbarSticky:{type:"checkbox"},items:{type:"object",fields:{}}}})}}),t.registerMessages({notEnoughItems:"The minimum number of items is {0}",tooManyItems:"The maximum number of items is {0}",valueNotUnique:"Values are not unique",notAnArray:"This value is not an Array"}),t.registerFieldClass("array",t.Fields.ArrayField),t.registerDefaultSchemaFieldMapping("array","array"),t.registerMessages({addItemButtonLabel:"Add New Item",addButtonLabel:"Add",removeButtonLabel:"Remove",upButtonLabel:"Up",downButtonLabel:"Down"})}(jQuery),function(e){var t=e.alpaca;t.Fields.ObjectField=t.ContainerField.extend({getFieldType:function(){return"object"},setup:function(){var e=this;this.base();var n=e.resolveContainerItemTemplateType();if(!n){e.resolveContainerItemTemplateType();return t.throwErrorWithCallback("Unable to find template descriptor for container item: "+e.getFieldType())}if(this.containerItemTemplateDescriptor=e.view.getTemplateDescriptor("container-"+n+"-item",e),!t.isEmpty(this.data)&&""!==this.data&&!t.isObject(this.data)){if(!t.isString(this.data))return;try{if(this.data=t.parseJSON(this.data),!t.isObject(this.data))return void t.logWarn("ObjectField parsed data but it was not an object: "+JSON.stringify(this.data))}catch(i){return}}},setValue:function(e){if(e||(e={}),t.isObject(e)){var n={};for(var i in this.childrenById){var a=this.childrenById[i].propertyId;n[a]=this.childrenById[i]}var r={};for(var o in e)e.hasOwnProperty(o)&&(r[o]=e[o]);for(var a in r){var l=n[a];l&&(l.setValue(r[a]),delete n[a],delete r[a])}for(var a in n){var l=n[a];l.setValue(null)}}},getContainerValue:function(){if(0===this.children.length&&!this.isRequired())return{};for(var e={},n=0;n0&&t.logDebug("There were "+n.length+" extra data keys that were not part of the schema "+JSON.stringify(n)),e(i)},s=[];for(var u in o){var c=null;n.data&&n.data.hasOwnProperty(u)&&(c=n.data[u]);var d=function(e,a,r){return function(o){n.resolvePropertySchemaOptions(e,function(l,s,u){return u?t.throwErrorWithCallback("Circular reference detected for schema: "+JSON.stringify(l),n.errorCallback):(l||t.logDebug("Unable to resolve schema for property: "+e),void n.createItem(e,l,s,a,null,function(t){i.push(t),delete r[e],o()}))})}}(u,c,a);s.push(d)}t.nextTick(function(){t.series(s,function(e){for(var t=!1,n=0;n");u.alpaca({data:r,options:a,schema:i,view:this.view.id?this.view.id:this.view,connector:this.connector,error:function(e){s.destroy(),s.errorCallback.call(s,e)},notTopLevel:!0,render:function(e,t){e.parent=s,e.propertyId=n,"/"!==s.path?e.path=s.path+"/"+n:e.path=s.path+n,e.render(null,function(){t()})},postRender:function(n){var i=t.tmpl(s.containerItemTemplateDescriptor,{id:s.getId(),name:n.name,parentFieldId:s.getId(),actionbarStyle:s.options.actionbarStyle,view:s.view,data:r}),a=e(i).find("."+t.MARKER_CLASS_CONTAINER_FIELD_ITEM_FIELD);return 0===a.length&&e(i).hasClass(t.MARKER_CLASS_CONTAINER_FIELD_ITEM_FIELD)&&(a=e(i)),0===a.length?void s.errorCallback.call(s,{message:"Cannot find insertion point for field: "+s.getId()}):(e(a).before(n.getFieldEl()),e(a).remove(),n.containerItemEl=i,t.fieldApplyFieldAndChildren(n,function(e){e.hideInitValidationError=!1}),void(l&&l(n)))}})},resolvePropertySchemaOptions:function(e,n){var i=this,a=function(e,t,a){i.options.readonly&&(t.readonly=!0),n(e,t,a)},r=null;i.schema&&i.schema.properties&&i.schema.properties[e]&&(r=i.schema.properties[e]);var o={};if(i.options&&i.options.fields&&i.options.fields[e]&&(o=i.options.fields[e]),r&&r.$ref){for(var l=r.$ref,s=this,u=[s];s.parent;)s=s.parent,u.push(s);var c=r,d=o;t.loadRefSchemaOptions(s,l,function(e,n){for(var i=0,r=0;r1,s={};c&&t.mergeObject(s,c),e&&t.mergeObject(s,e),c&&c.id&&(s.id=c.id);var p={};d&&t.mergeObject(p,d),n&&t.mergeObject(p,n),t.nextTick(function(){a(s,p,o)})})}else t.nextTick(function(){a(r,o)})},applyCreatedItems:function(e,t){var n=this;this.base(e,function(){var i=function(a){if(a===e.items.length)return void t();var r=e.items[a],o=r.propertyId;n.showOrHidePropertyBasedOnDependencies(o),n.bindDependencyFieldUpdateEvent(o),n.refreshDependentFieldStates(o),i(a+1)};i(0)})},handleValidate:function(){var e=this.base(),n=this.validation,i=this._validateMaxProperties();return n.tooManyProperties={message:i?"":t.substituteTokens(this.getMessage("tooManyProperties"),[this.schema.maxProperties]),status:i},i=this._validateMinProperties(),n.tooFewProperties={message:i?"":t.substituteTokens(this.getMessage("tooManyItems"),[this.schema.minProperties]),status:i},e&&n.tooManyProperties.status&&n.tooFewProperties.status},_validateMaxProperties:function(){if("undefined"==typeof this.schema.maxProperties)return!0;var e=this.schema.maxProperties,t=0;for(var n in this.data)t++;return e>=t},_validateMinProperties:function(){if("undefined"==typeof this.schema.minProperties)return!0;var e=this.schema.minProperties,t=0;for(var n in this.data)t++;return t>=e},showOrHidePropertyBasedOnDependencies:function(e){var n=this,i=this.childrenByPropertyId[e];if(!i)return t.throwErrorWithCallback("Missing property: "+e,n.errorCallback);
var a=this.determineAllDependenciesValid(e);a?(i.show(),i.onDependentReveal()):(i.hide(),i.onDependentConceal()),i.getFieldEl().trigger("fieldupdate")},getChildDependencies:function(e){var t=null;if(this.schema.dependencies&&(t=this.schema.dependencies[e]),!t){var n=this.childrenByPropertyId[e];n&&(t=n.schema.dependencies)}return t},getChildConditionalDependencies:function(e){var t=null,n=this.childrenByPropertyId[e];return n&&(t=n.options.dependencies),t},determineAllDependenciesValid:function(n){var i=this,a=this.childrenByPropertyId[n];if(!a)return t.throwErrorWithCallback("Missing property: "+n,i.errorCallback);var r=i.getChildDependencies(n);if(!r)return!0;var o=!0;return t.isString(r)?o=i.determineSingleDependencyValid(n,r):t.isArray(r)&&e.each(r,function(e,t){o=o&&i.determineSingleDependencyValid(n,t)}),o},bindDependencyFieldUpdateEvent:function(n){var i=this,a=this.childrenByPropertyId[n];if(!a)return t.throwErrorWithCallback("Missing property: "+n,i.errorCallback);var r=i.getChildDependencies(n);if(!r)return!0;var o=function(e,n){var r=t.resolveField(i,n);r&&(r.getFieldEl().bind("fieldupdate",function(e,t,n,a){return function(t){i.showOrHidePropertyBasedOnDependencies(n),e.getFieldEl().trigger("fieldupdate")}}(a,r,e,n)),r.getFieldEl().trigger("fieldupdate"))};t.isString(r)?o(n,r):t.isArray(r)&&e.each(r,function(e,t){o(n,t)})},refreshDependentFieldStates:function(n){var i=this,a=this.childrenByPropertyId[n];if(!a)return t.throwErrorWithCallback("Missing property: "+n,i.errorCallback);var r=i.getChildDependencies(n);if(!r)return!0;var o=function(e){var n=t.resolveField(i,e);n&&n.getFieldEl().trigger("fieldupdate")};t.isString(r)?o(r):t.isArray(r)&&e.each(r,function(e,t){o(t)})},determineSingleDependencyValid:function(e,n){var i=this,a=t.resolveField(i,n);if(!a)return!1;var r=a.data,o=!1,l=this.getChildConditionalDependencies(e);if(l&&0!==l.length){"boolean"!==a.getType()||r||(r=!1);var s=l[n];!t.isEmpty(s)&&t.isFunction(s)?o=s.call(this,r):(o=!0,t.isArray(s)?t.anyEquality(r,s)||(o=!1):t.isEmpty(s)||t.anyEquality(s,r)||(o=!1))}else o="boolean"!==a.getType()||this.childrenByPropertyId[e].options.dependencies||r?!t.isValEmpty(a.data):!1;return a&&a.isHidden()&&(o=!1),o},getIndex:function(e){if(t.isEmpty(e))return-1;for(var n=0;n0&&r.after(i.containerItemEl)}else e(a.container).prepend(i.containerItemEl);a.doAfterAddItem(i,function(){t.fireReady(i)})},doAfterAddItem:function(e,t){t()},doResolveItemContainer:function(){var t=this;return e(t.container)},removeItem:function(t,n){var i=this,a=this.childrenByPropertyId[t];a?(this.children=e.grep(this.children,function(e,n){return e.propertyId!==t}),delete this.childrenByPropertyId[t],delete this.childrenById[a.getId()],i.doRemoveItem(a),this.refreshValidationState(!0,function(){i.handleRepositionDOMRefresh(),i.trigger("remove",a),i.triggerUpdate(),n&&n()})):n()},doRemoveItem:function(e){var t=this,n=t.doResolveItemContainer();n.children(".alpaca-container-item[data-alpaca-container-item-name='"+e.name+"']").remove(),e.destroy()},wizard:function(){var n=this,i=this.wizardConfigs.steps;i||(i=[]);var a=this.wizardConfigs.title,r=this.wizardConfigs.description,o=this.wizardConfigs.buttons;o||(o={}),o.previous||(o.previous={}),o.previous.title||(o.previous.title="Previous"),o.previous.align||(o.previous.align="left"),o.previous.type||(o.previous.type="button"),o.next||(o.next={}),o.next.title||(o.next.title="Next"),o.next.align||(o.next.align="right"),o.next.type||(o.next.type="button"),this.wizardConfigs.hideSubmitButton||(o.submit||(o.submit={}),o.submit.title||(o.submit.title="Submit"),o.submit.align||(o.submit.align="right"),o.submit.type||(o.submit.type="button"));for(var l in o)o[l].type||(o[l].type="button");var s=this.wizardConfigs.showSteps;"undefined"==typeof s&&(s=!0);var u=this.wizardConfigs.showProgressBar,c=this.wizardConfigs.validation;"undefined"==typeof c&&(c=!0);var a=e(this.field).attr("data-alpaca-wizard-title"),r=e(this.field).attr("data-alpaca-wizard-description"),d=e(this.field).attr("data-alpaca-wizard-validation");"undefined"!=typeof d&&(c=!!d);var p=e(this.field).attr("data-alpaca-wizard-show-steps");"undefined"!=typeof p&&(s=!!p);var h=e(this.field).attr("data-alpaca-wizard-show-progress-bar");"undefined"!=typeof h&&(u=!!h);var f=e(this.field).find("[data-alpaca-wizard-role='step']");0==i.length&&f.each(function(t){var n={},a=e(this).attr("data-alpaca-wizard-step-title");"undefined"!=typeof a&&(n.title=a),n.title||(n.title="Step "+t);var r=e(this).attr("data-alpaca-wizard-step-description");"undefined"!=typeof r&&(n.description=r),n.description||(n.description="Step "+t),i.push(n)}),"undefined"==typeof u&&i.length>1&&(u=!0);var m={};m.wizardTitle=a,m.wizardDescription=r,m.showSteps=s,m.performValidation=c,m.steps=i,m.buttons=o,m.schema=n.schema,m.options=n.options,m.data=n.data,m.showProgressBar=u,m.markAllStepsVisited=this.wizardConfigs.markAllStepsVisited,m.view=n.view;var g=n.view.getTemplateDescriptor("wizard",n);if(g){var v=t.tmpl(g,m);e(n.field).append(v);var b=e(v).find(".alpaca-wizard-nav"),y=e(v).find(".alpaca-wizard-steps"),w=e(v).find(".alpaca-wizard-buttons"),x=e(v).find(".alpaca-wizard-progress-bar");e(y).append(f),function(i,a,r,o){var l=0,s=e(r).find("[data-alpaca-wizard-button-key='previous']"),u=e(r).find("[data-alpaca-wizard-button-key='next']"),c=e(r).find("[data-alpaca-wizard-button-key='submit']"),d=function(){if(o.showSteps){if(o.visits||(o.visits={}),o.markAllStepsVisited)for(var t=e(i).find("[data-alpaca-wizard-step-index]"),n=0;nn?e(i).find("[data-alpaca-wizard-step-index='"+n+"']").addClass("completed"):n===l?e(i).find("[data-alpaca-wizard-step-index='"+n+"']").addClass("active"):o.visits&&o.visits[n]||e(i).find("[data-alpaca-wizard-step-index='"+n+"']").addClass("disabled"),o.visits&&o.visits[n]&&e(i).find("[data-alpaca-wizard-step-index='"+n+"']").addClass("visited")}if(o.showProgressBar){var r=l+1,d=o.steps.length+1,p=parseInt(r/d*100,10)+"%";e(x).find(".progress-bar").attr("aria-valuemax",d),e(x).find(".progress-bar").attr("aria-valuenow",r),e(x).find(".progress-bar").css("width",p)}s.hide(),u.hide(),c.hide(),1==o.steps.length?c.show():o.steps.length>1&&(l>0&&s.show(),u.show(),0==l?u.show():l==o.steps.length-1&&(u.hide(),c.show())),e(a).find("[data-alpaca-wizard-role='step']").hide(),e(e(a).find("[data-alpaca-wizard-role='step']")[l]).show()},p=function(i,r){if(!o.performValidation)return void r(!0);var s=[],u=e(e(a).find("[data-alpaca-wizard-role='step']")[l]);e(u).find(".alpaca-field").each(function(){var t=e(this).attr("data-alpaca-field-id");if(t){var i=n.childrenById[t];i&&s.push(i)}});for(var c=[],d=0;d=1){var t=o.buttons.previous;t&&t.click&&t.click.call(n,e),l--,d()}}),e(u).click(function(e){e.preventDefault(),l+1<=o.steps.length-1&&p("next",function(t){if(t){var i=o.buttons.next;i&&i.click&&i.click.call(n,e),l++,d()}else window.setTimeout(function(){n.focus(function(e){})},250)})}),e(c).click(function(e){e.preventDefault(),l===o.steps.length-1&&p("submit",function(t){if(t){var i=o.buttons.submit;i&&(i.click?i.click.call(n,e):n.form&&n.form.submit())}else window.setTimeout(function(){n.focus(function(e){})},250)})}),e(r).find("[data-alpaca-wizard-button-key]").each(function(){var t=e(this).attr("data-alpaca-wizard-button-key");if("submit"!=t&&"next"!=t&&"previous"!=t){var i=o.buttons[t];i&&i.click&&e(this).click(function(e){return function(t){e.click.call(n,t)}}(i))}}),e(i).find("[data-alpaca-wizard-step-index]").click(function(t){t.preventDefault();var n=e(this).attr("data-alpaca-wizard-step-index");n&&(n=parseInt(n,10),(n==l||o.visits&&o.visits[n])&&(l>n?(l=n,d()):n>l&&p(null,function(e){e&&(l=n,d())})))}),n.on("moveToStep",function(e){var t=e.index,n=e.skipValidation;"undefined"!=typeof t&&t<=o.steps.length-1&&(n?(l=t,d()):p(null,function(e){e&&(l=t,d())}))}),n.on("advanceOrSubmit",function(t){p(null,function(t){t&&(l===o.steps.length-1?e(c).click():e(u).click())})}),d()}(b,y,w,m)}},autoWizard:function(){var t=this.wizardConfigs.bindings;t||(t={});for(var n in this.childrenByPropertyId)t.hasOwnProperty(n)||(t[n]=1);var i=!0;e(this.field).find("[data-alpaca-wizard-role='step']").length>0&&(i=!1);var a=1,r=[];do{r=[];for(var n in t)t[n]===a&&this.childrenByPropertyId&&this.childrenByPropertyId[n]&&r.push(this.childrenByPropertyId[n]);if(r.length>0){var o=null;i?(o=e(''),e(this.field).append(o)):o=e(e(this.field).find("[data-alpaca-wizard-role='step']")[a-1]);for(var l=!1,s=0;s0);this.wizard(),0===e(this.container).children().length&&e(this.container).css("display","none")},getType:function(){return"object"},moveItem:function(n,i,a,r){var o=this;if("function"==typeof a&&(r=a,a=o.options.animate),"undefined"==typeof a&&(a=o.options.animate?o.options.animate:!0),"string"==typeof n&&(n=parseInt(n,10)),"string"==typeof i&&(i=parseInt(i,10)),0>i&&(i=0),i>=o.children.length&&(i=o.children.length-1),-1!==i){var l=o.children[i];if(l){var s=o.getContainerEl().children("[data-alpaca-container-item-index='"+n+"']"),u=o.getContainerEl().children("[data-alpaca-container-item-index='"+i+"']"),c=e("");s.before(c);var d=e("");u.before(d);var p=function(){for(var t=[],a=0;a').appendTo(t);var a=e('