mozart-rails 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
- /*! Mozart v0.1.8 */
2
- (function(){var t=function(e,n){var i=t.resolve(e,n||"/"),r=t.modules[i];if(!r)throw Error("Failed to resolve module "+e+", tried "+i);var o=t.cache[i],s=o?o.exports:r();return s};t.paths=[],t.modules={},t.cache={},t.extensions=[".js",".coffee",".json"],t._core={assert:!0,events:!0,fs:!0,path:!0,vm:!0},t.resolve=function(){return function(e,n){function i(e){if(e=a.normalize(e),t.modules[e])return e;for(var n=0;t.extensions.length>n;n++){var i=t.extensions[n];if(t.modules[e+i])return e+i}}function r(e){e=e.replace(/\/+$/,"");var n=a.normalize(e+"/package.json");if(t.modules[n]){var r=t.modules[n](),o=r.browserify;if("object"==typeof o&&o.main){var s=i(a.resolve(e,o.main));if(s)return s}else if("string"==typeof o){var s=i(a.resolve(e,o));if(s)return s}else if(r.main){var s=i(a.resolve(e,r.main));if(s)return s}}return i(e+"/index")}function o(t,e){for(var n=s(e),o=0;n.length>o;o++){var a=n[o],l=i(a+"/"+t);if(l)return l;var h=r(a+"/"+t);if(h)return h}var l=i(t);return l?l:void 0}function s(t){var e;e="/"===t?[""]:a.normalize(t).split("/");for(var n=[],i=e.length-1;i>=0;i--)if("node_modules"!==e[i]){var r=e.slice(0,i+1).join("/")+"/node_modules";n.push(r)}return n}if(n||(n="/"),t._core[e])return e;var a=t.modules.path();n=a.resolve("/",n);var l=n||"/";if(e.match(/^(?:\.\.?\/|\/)/)){var h=i(a.resolve(l,e))||r(a.resolve(l,e));if(h)return h}var u=o(e,l);if(u)return u;throw Error("Cannot find module '"+e+"'")}}(),t.alias=function(e,n){var i=t.modules.path(),r=null;try{r=t.resolve(e+"/package.json","/")}catch(o){r=t.resolve(e,"/")}for(var s=i.dirname(r),a=(Object.keys||function(t){var e=[];for(var n in t)e.push(n);return e})(t.modules),l=0;a.length>l;l++){var h=a[l];if(h.slice(0,s.length+1)===s+"/"){var u=h.slice(s.length);t.modules[n+u]=t.modules[s+u]}else h===s&&(t.modules[n]=t.modules[s])}},function(){var e={},n="undefined"!=typeof window?window:{},i=!1;t.define=function(r,o){!i&&t.modules.__browserify_process&&(e=t.modules.__browserify_process(),i=!0);var s=t._core[r]?"":t.modules.path().dirname(r),a=function(e){var n=t(e,s),i=t.cache[t.resolve(e,s)];return i&&null===i.parent&&(i.parent=l),n};a.resolve=function(e){return t.resolve(e,s)},a.modules=t.modules,a.define=t.define,a.cache=t.cache;var l={id:r,filename:r,exports:{},loaded:!1,parent:null};t.modules[r]=function(){return t.cache[r]=l,o.call(l.exports,a,l,l.exports,s,r,e,n),l.loaded=!0,l.exports}}}(),t.define("path",function(t,e,n,i,r,o){function s(t,e){for(var n=[],i=0;t.length>i;i++)e(t[i],i,t)&&n.push(t[i]);return n}function a(t,e){for(var n=0,i=t.length;i>=0;i--){var r=t[i];"."==r?t.splice(i,1):".."===r?(t.splice(i,1),n++):n&&(t.splice(i,1),n--)}if(e)for(;n--;n)t.unshift("..");return t}var l=/^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;n.resolve=function(){for(var t="",e=!1,n=arguments.length;n>=-1&&!e;n--){var i=n>=0?arguments[n]:o.cwd();"string"==typeof i&&i&&(t=i+"/"+t,e="/"===i.charAt(0))}return t=a(s(t.split("/"),function(t){return!!t}),!e).join("/"),(e?"/":"")+t||"."},n.normalize=function(t){var e="/"===t.charAt(0),n="/"===t.slice(-1);return t=a(s(t.split("/"),function(t){return!!t}),!e).join("/"),t||e||(t="."),t&&n&&(t+="/"),(e?"/":"")+t},n.join=function(){var t=Array.prototype.slice.call(arguments,0);return n.normalize(s(t,function(t){return t&&"string"==typeof t}).join("/"))},n.dirname=function(t){var e=l.exec(t)[1]||"",n=!1;return e?1===e.length||n&&3>=e.length&&":"===e.charAt(1)?e:e.substring(0,e.length-1):"."},n.basename=function(t,e){var n=l.exec(t)[2]||"";return e&&n.substr(-1*e.length)===e&&(n=n.substr(0,n.length-e.length)),n},n.extname=function(t){return l.exec(t)[3]||""}}),t.define("__browserify_process",function(t,e,n,i,r,o){var o=e.exports={};o.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(e){var n=[];return window.addEventListener("message",function(t){if(t.source===window&&"browserify-tick"===t.data&&(t.stopPropagation(),n.length>0)){var e=n.shift();e()}},!0),function(t){n.push(t),window.postMessage("browserify-tick","*")}}return function(t){setTimeout(t,0)}}(),o.title="browser",o.browser=!0,o.env={},o.argv=[],o.binding=function(e){if("evals"===e)return t("vm");throw Error("No such module. (Possibly not yet loaded)")},function(){var e,n="/";o.cwd=function(){return n},o.chdir=function(i){e||(e=t("path")),n=e.resolve(i,n)}}()}),t.define("/collection.coffee",function(t,e,n){(function(){var e,i,r,o,s=function(t,e){return function(){return t.apply(e,arguments)}},a={}.hasOwnProperty,l=function(t,e){function n(){this.constructor=t}for(var i in e)a.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};o=t("./view").View,r=t("./util"),n.Collection=i=function(t){function e(){return this.draw=s(this.draw,this),this.createView=s(this.createView,this),this.refresh=s(this.refresh,this),this.afterRender=s(this.afterRender,this),this.release=s(this.release,this),this.init=s(this.init,this),e.__super__.constructor.apply(this,arguments)}return l(e,t),e.prototype.tag="ul",e.prototype.skipTemplate=!0,e.prototype.init=function(){var t,n;return e.__super__.init.apply(this,arguments),r.log("collection","init"),this.itemViews={},this.localMozartModel=r._getPath("Mozart.Model"),this.localMozartInstanceCollection=r._getPath("Mozart.InstanceCollection"),null!=this.filterAttribute&&(this.bind("change:filterAttribute",this.draw),this.bind("change:filterText",this.draw)),null!=this.sortAttribute&&(this.bind("change:sortAttribute",this.draw),this.bind("change:sortDescending",this.draw)),null==this.pageSize&&this.set("pageSize",1e4),null==this.pageCurrent&&this.set("pageCurrent",0),this.bind("change:pageSize",this.draw),this.bind("change:pageCurrent",this.draw),null==(n=this.method)&&(this.method="all"),this.bind("change:collection",this.afterRender),this.bind("change:method",this.afterRender),"function"==typeof(t=this.collection).bind?t.bind("change",this.afterRender):void 0},e.prototype.release=function(){var t;return"function"==typeof(t=this.collection).unbind&&t.unbind("change",this.afterRender),e.__super__.release.apply(this,arguments)},e.prototype.afterRender=function(){return this.refresh(),this.draw()},e.prototype.refresh=function(){var t,e,n,i,o,s,a,l,h,u,c,d,p,f,g,y;if(r.log("collection","refresh"),this.dataSet={},null!=this.collection)if(r.isObject(this.collection)){if(r.isFunction(this.collection[this.method+"AsMap"]))this.dataSet=this.collection[this.method+"AsMap"]();else if(r.isFunction(this.collection[this.method]))for(c=this.collecton[this.method](),o=0,l=c.length;l>o;o++)e=c[o],this.dataSet[e.id]=e}else if(r.isFunction(this.collection))for(d=this.collection(),s=0,h=d.length;h>s;s++)e=d[s],this.dataSet[e.id]=e;else if(r.isArray(this.collection))for(p=this.collection,a=0,u=p.length;u>a;a++)e=p[a],this.dataSet[e.id]=e;else console.error("Collection: "+typeof this.collection+" can't be iterated");n=[],f=this.itemViews;for(t in f)i=f[t],null==this.dataSet[t]&&n.push(t);for(y=[];n.length>0;)t=n.pop(),r.log("collection","destroyView",t,this.itemViews[t]),this.removeView(this.itemViews[t]),null!=(g=this.itemViews[t].element)&&g.remove(),this.layout.queueReleaseView(this.itemViews[t]),y.push(delete this.itemViews[t]);return y},e.prototype.createView=function(t){var e,n;return r.log("collection","createView",t,"layout",this.layout.rootElement),e={content:t,parent:this},this.viewClass===o&&(e.tag="li"),null!=this.viewClassTemplateName&&(e.templateName=this.viewClassTemplateName),null!=this.viewClassTemplateFunction&&(e.templateFunction=this.viewClassTemplateFunction),null!=this.collectionTag&&(e.tag=this.collectionTag),null!=this.collectionClassNames&&(e.classNames=this.collectionClassNames),null!=this.tooltips&&(e.tooltips=this.tooltips),n=this.layout.createView(this.viewClass,e),this.element.append(n.createElement()),this.itemViews[t.id]=n,this.addView(n),this.layout.queueRenderView(n)},e.prototype.draw=function(){var t,e,n,i,o,s,a,l,h,u,c,d,p,f,g,y,m,v,w,b,C,M;v=this.itemViews;for(o in v)u=v[o],null!=(w=u.element)&&w.detach();if(this.displayOrder=_(this.dataSet).values(),this.hidden={},null!=this.sortAttribute&&r.sortBy(this.displayOrder,this.sortAttribute),this.sortDescending&&this.displayOrder.reverse(),null!=this.filterText&&null!=this.filterAttribute&&this.filterText.length>0)for(a=(""+this.filterText).toLowerCase(),b=this.displayOrder,d=0,g=b.length;g>d;d++)for(s=b[d],i=!0,C=this.filterAttribute.split(","),p=0,y=C.length;y>p;p++)n=C[p],c=r.getPath(s,n),null!=c&&(i=i&&-1===(""+c).toLowerCase().indexOf(a)),i&&(this.hidden[s.id]=1);for(l=this.pageCurrent*this.pageSize,t=0,h=0,e=0,M=this.displayOrder,f=0,m=M.length;m>f;f++)s=M[f],null==this.hidden[s.id]&&(l>t||e>=this.pageSize||(null==this.itemViews[s.id]&&this.createView(s),this.element.append(this.itemViews[s.id].element),e++),h++),t++;return this.set("pageTotal",Math.ceil(h/this.pageSize)),this.pageCurrent>this.pageTotal?this.set("pageCurrent",this.pageTotal-1):void 0},e}(o),n.BoundView=e=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return l(e,t),e.prototype.init=function(){return e.__super__.init.apply(this,arguments),this.content.bind("change",this.redraw)},e.prototype.release=function(){return this.content.unbind("change",this.redraw),e.__super__.release.apply(this,arguments)},e}(o)}).call(this)}),t.define("/view.coffee",function(t,e,n){(function(){var e,i,r,o=function(t,e){return function(){return t.apply(e,arguments)}},s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var i in e)s.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=t("./object").MztObject,i=t("./util"),n.View=r=function(t){function e(){return this.copyHtmlAttrsToElement=o(this.copyHtmlAttrsToElement,this),this.getHtmlAttrsMap=o(this.getHtmlAttrsMap,this),this.createElement=o(this.createElement,this),this.release=o(this.release,this),this.hasAncestor=o(this.hasAncestor,this),this.removeView=o(this.removeView,this),this.namedChildViewExists=o(this.namedChildViewExists,this),this.childView=o(this.childView,this),this.addView=o(this.addView,this),this.redraw=o(this.redraw,this),this.postRender=o(this.postRender,this),this.replaceElement=o(this.replaceElement,this),this.findElementInPreparedContent=o(this.findElementInPreparedContent,this),this.reassignElements=o(this.reassignElements,this),this.prepareElement=o(this.prepareElement,this),this.init=o(this.init,this),e.__super__.constructor.apply(this,arguments)}return a(e,t),e.prototype.tag="div",e.prototype.disableHtmlAttributes=!1,e.prototype.idPrefix="view",e.prototype.init=function(){var t,e,n;return null==(t=this.id)&&(this.id=""+this.idPrefix+"-"+this._mozartId),this.childViews={},null==(e=this.context)&&(this.context={}),this.namedChildViews={},this.valid=!0,this.domBindings={},null==(n=this.display)&&(this.display=!0),null!=this.parent&&this.parent.addView(this),null==this.templateFunction&&null==this.skipTemplate&&(null==this.templateName&&i.error("View: View has no templateName or templateFunction","view",this),this.templateFunction=HandlebarsTemplates[this.templateName]),i.log("views","view "+this.id+" init"),this.bind("change:display",this.redraw)},e.prototype.prepareElement=function(){return this.released?void 0:(this.newElement=this.createElement(),!this.skipTemplate&&this.display?this.newElement.innerHTML=this.templateFunction(this,{data:this}):void 0)},e.prototype.reassignElements=function(){var t,e,n;n=this.childViews;for(t in n)e=n[t],e.reassignElements();return null!=this.parent?this.el=this.parent.findElementInPreparedContent(this.id):void 0},e.prototype.findElementInPreparedContent=function(t){var e;return this.newElement?e=this._find(this.newElement,t):null},e.prototype._find=function(t,e){var n,i,r,o,s;if(t.id===e)return t;for(s=t.children,r=0,o=s.length;o>r;r++)if(n=s[r],i=this._find(n,e),null!=i)return i;return null},e.prototype.replaceElement=function(){var t,e,n;if(!this.released&&this.el){n=this.childViews;for(t in n)e=n[t],e.replaceElement();return this.el!==this.newElement&&(this.oldEl=this.el,this.el.parentNode.replaceChild(this.newElement,this.el),null!=this.layout&&this.el===this.layout.rootEl&&(this.layout.rootEl=this.newElement),this.el=this.newElement,delete this.oldEl),this.element=$(this.el)}},e.prototype.beforeRender=function(){},e.prototype.afterRender=function(){},e.prototype.postRender=function(){return this.released?void 0:(this.createDomBinds(),this.afterRender())},e.prototype.redraw=function(){return this.released?void 0:this.layout.queueRenderView(this)},e.prototype.addView=function(t){return this.childViews[t.id]=t,null!=t.name?this.namedChildViews[t.name]=t:void 0},e.prototype.childView=function(t){return this.namedChildViews[t]},e.prototype.namedChildViewExists=function(t){return null!=this.namedChildViews[t]},e.prototype.releaseChildren=function(){var t,e,n;n=this.childViews;for(t in n)e=n[t],this.layout.queueReleaseView(e);return this.childViews={},this.namedChildViews={}},e.prototype.removeView=function(t){return null!=this.childViews?delete this.childViews[t.id]:void 0},e.prototype.hasAncestor=function(t){var e;for(e=this.parent;null!=e;){if(e.id===t.id)return!0;e=e.parent}return!1},e.prototype.release=function(){return this.released?void 0:(i.log("views",this.layout,"releasing view "+this.id),this.removeDomBinds(),this.unbind(),null!=this.parent&&this.parent.removeView(this),this.releaseChildren(),null!=this.element&&this.element.remove(),this.layout.releaseView(this),e.__super__.release.apply(this,arguments))},e.prototype.createElement=function(){var t,e,n,i;if(this.display===!1)return t=document.createElement("script"),t.setAttribute("id",this.id),t;if(t=document.createElement(this.tag),t.setAttribute("id",this.id),t.setAttribute("view",""),!this.disableHtmlAttributes){i=this.getHtmlAttrsMap();for(e in i)n=i[e],t.setAttribute(e,n)}return t},e.prototype.getHtmlAttrsMap=function(){var t,e,n;e={};for(t in this)n=this[t],"string"==typeof this[t]&&i.stringEndsWith(t,"Html")&&(e[i.sliceStringBefore(t,"Html")]=n);return e},e.prototype.copyHtmlAttrsToElement=function(t){return t.attr(this.getHtmlAttrsMap()),t},e.prototype.registerDomBind=function(t,e){var n,r,o,s;return s=i.parsePath(e),o=s[0],n=s[1],r=null!=o?i.getPath(this,o):this,null==r&&i.error("View.registerDomBind (bind helper) - cannot find object "+o),this.domBindings[t]={view:this,target:r,attribute:n,element:null}},e.prototype.createDomBinds=function(){var t,e,n,r;n=this.domBindings,r=[];for(t in n)e=n[t],e.element=$("#"+t),null==e.element&&i.error("View.createDomBinds - cannot find element "+t),e.target.bind("change:"+e.attribute,this.onDomBindChange,e),r.push(e.element.text(e.target[e.attribute]));return r},e.prototype.onDomBindChange=function(t,e){return e.element.text(e.target[e.attribute])},e.prototype.removeDomBinds=function(){var t,e,n;n=this.domBindings;for(t in n)e=n[t],true===e.element&&e.target.unbind("change:"+e.attribute,this.onDomBindChange);return this.domBindings={}},e}(e)}).call(this)}),t.define("/object.coffee",function(t,e,n){(function(){var e,i,r,o=function(t,e){return function(){return t.apply(e,arguments)}},s=[].indexOf||function(t){for(var e=0,n=this.length;n>e;e++)if(e in this&&this[e]===t)return e;return-1},a=[].slice,l={}.hasOwnProperty;r=t("./util"),e=t("./events").Events,n.MztObject=i=function(){function t(){this._createBinding=o(this._createBinding,this),this._mozartId=r.getId()}var n;return n=["extended","included"],t.NOTIFY=2,t.OBSERVE=1,t.SYNC=0,t.include=function(t){var e,i,r;for(e in t)i=t[e],0>s.call(n,e)&&(this[e]=i);return null!=(r=t.extended)&&r.apply(this),this},t.extend=function(t){var e,i,r;for(e in t)i=t[e],0>s.call(n,e)&&(this.prototype[e]=i);return null!=(r=t.included)&&r.apply(this),this},t.create=function(t){var e,n,i;e=new this;for(n in t)i=t[n],e[n]=i;return e._bindings={},e._bindings.notify={},e._bindings.observe={},e._bindings.stored={},e._createDeclaredBinds(),e._createLookups(),"function"==typeof e.init&&e.init(),e},t.prototype.toString=function(){return"obj-"+this._mozartId},t.prototype.get=function(t){return r.isFunction(this[t])?this[t].call(this):this[t]},t.prototype.set=function(t,e){var n,i,r,o,s,a,l;if(o=this[t],o!==e){if(o instanceof Mozart.MztObject&&(this._bindings.stored[t]={notify:o._stripNotifyBindings(!0),observe:o._stripObserveBindings(!0)},this._bindings.stored[t].notify==={}&&this._bindings.stored[t].observe==={}&&delete this._bindings.stored[t]),null!=this._bindings.stored[t]&&null!=this._bindings.stored[t].notify&&null===e){l=this._bindings.stored[t].notify;for(r in l)for(i=l[r],s=0,a=i.length;a>s;s++)n=i[s],n.target.set(n.attr,null)}return e instanceof Mozart.MztObject&&null!=this._bindings.stored[t]&&(this._bindings.stored[t].notify!=={}&&e._addNotifyBindings(this._bindings.stored[t].notify),this._bindings.stored[t].observe!=={}&&e._addObserveBindings(this._bindings.stored[t].observe),delete this._bindings.stored[t]),this[t]=e,this._doNotifyBinding(t),this.trigger("change"),this.trigger("change:"+t)}},t.prototype.bind=function(){var t;return t=arguments.length>=1?a.call(arguments,0):[],e.bind.apply(e,[this._mozartId].concat(a.call(t))),this},t.prototype.one=function(){var t;return t=arguments.length>=1?a.call(arguments,0):[],e.one.apply(e,[this._mozartId].concat(a.call(t))),this},t.prototype.trigger=function(){var t;return t=arguments.length>=1?a.call(arguments,0):[],e.trigger.apply(e,[this._mozartId].concat(a.call(t))),this},t.prototype.unbind=function(){var t;return t=arguments.length>=1?a.call(arguments,0):[],e.unbind.apply(e,[this._mozartId].concat(a.call(t))),this},t.prototype.release=function(){var t,e;if(!this.released){this._removeAllBindings(),this.unbind();for(t in this)l.call(this,t)&&(e=this[t],this[t]=void 0,delete this[t]);return this.released=!0}},t.prototype._stripNotifyBindings=function(e){var n,i,r,o,s,a,l;null==e&&(e=!1),i={},l=this._bindings.notify;for(o in l)for(r=l[o],i[o]=[],s=0,a=r.length;a>s;s++)n=r[s],(!e||n.transferable)&&(i[o].push(n),this._removeBinding(o,n.target,n.attr,t.NOTIFY));return i},t.prototype._addNotifyBindings=function(e){var n,i,r,o;o=[];for(r in e)i=e[r],o.push(function(){var e,o,s;for(s=[],e=0,o=i.length;o>e;e++)n=i[e],s.push(this._createBinding(r,n.target,n.attr,t.NOTIFY,n.transferable));return s}.call(this));return o},t.prototype._stripObserveBindings=function(e){var n,i,r,o,s,a,l;null==e&&(e=!1),i={},l=this._bindings.observe;for(o in l)for(r=l[o],i[o]=[],s=0,a=r.length;a>s;s++)n=r[s],(!e||n.transferable)&&(i[o].push(n),this._removeBinding(o,n.target,n.attr,t.OBSERVE,n.transferable));return i},t.prototype._addObserveBindings=function(e){var n,i,r,o;o=[];for(r in e)i=e[r],o.push(function(){var e,o,s;for(s=[],e=0,o=i.length;o>e;e++)n=i[e],s.push(this._createBinding(r,n.target,n.attr,t.OBSERVE,n.transferable));return s}.call(this));return o},t.prototype._createDeclaredBinds=function(){var e,n,i,o,s,a,l,h;h=[];for(n in this)a=this[n],!r.isFunction(this[n])&&r.stringEndsWith(n,"Binding")&&(n=r.sliceStringBefore(n,"Binding"),s=t.SYNC,r.stringEndsWith(n,"Observe")?(n=r.sliceStringBefore(n,"Observe"),s=t.OBSERVE):r.stringEndsWith(n,"Notify")&&(n=r.sliceStringBefore(n,"Notify"),s=t.NOTIFY),l=r.parsePath(a),o=l[0],e=l[1],i=null!=o?r._getPath(this,o):this,h.push(this._createBinding(n,i,e,s,r.isAbsolutePath(a))));return h},t.prototype._hasNotifyBinding=function(t,e,n){var i,r,o,s;if(null==this._bindings.notify[t])return!1;for(s=this._bindings.notify[t],r=0,o=s.length;o>r;r++)if(i=s[r],i.attr===n&&i.target===e)return!0;return!1},t.prototype._hasObserveBinding=function(t,e,n){var i,r,o,s;if(null==this._bindings.observe[t])return!1;for(s=this._bindings.observe[t],r=0,o=s.length;o>r;r++)if(i=s[r],i.attr===n&&i.target===e)return!0;return!1},t.prototype._createBinding=function(e,n,i,o,s){var a,l,h,u;switch(o){case t.NOTIFY:if(this._hasNotifyBinding(e,n,i,o))return;return null==(h=(a=this._bindings.notify)[e])&&(a[e]=[]),this._bindings.notify[e].push({attr:i,target:n,transferable:s}),n instanceof t&&n._createBinding(i,this,e,t.OBSERVE,s),this._doNotifyBinding(e);case t.OBSERVE:if(this._hasObserveBinding(e,n,i,o))return;return n instanceof t?(null==(u=(l=this._bindings.observe)[e])&&(l[e]=[]),this._bindings.observe[e].push({attr:i,target:n,transferable:s}),n._createBinding(i,this,e,t.NOTIFY,s)):(r.warn("Binding "+e+"ObserveBinding on",this,": target",n,"is not a MztObject"),void 0);case t.SYNC:return this._createBinding(e,n,i,t.OBSERVE,s),this._createBinding(e,n,i,t.NOTIFY,s)}},t.prototype._removeBinding=function(e,n,i,r){var o,s,a,l,h,u,c,d;switch(r){case t.NOTIFY:if(!this._hasNotifyBinding(e,n,i))return;for(s=[],c=this._bindings.notify[e],a=0,h=c.length;h>a;a++)o=c[a],o.attr!==i&&o.target!==n&&s.push(o);if(0===s.length?this._bindings.notify[e]=s:delete this._bindings.notify[e],n instanceof t)return n._removeBinding(i,this,e,t.OBSERVE);break;case t.OBSERVE:if(!this._hasObserveBinding(e,n,i))return;for(s=[],d=this._bindings.observe[e],l=0,u=d.length;u>l;l++)o=d[l],o.attr!==i&&o.target!==n&&s.push(o);if(0===s.length?this._bindings.observe[e]=s:delete this._bindings.observe[e],n instanceof t)return n._removeBinding(i,this,e,t.NOTIFY);break;case t.SYNC:return this._removeBinding(e,n,i,t.NOTIFY),this._removeBinding(e,n,i,t.OBSERVE)}},t.prototype._removeAllBindings=function(){return this._stripObserveBindings(!1),this._stripNotifyBindings(!1)},t.prototype._doNotifyBinding=function(t){var e,n,i,o,s;if(n=this._bindings.notify[t],null!=n){for(s=[],i=0,o=n.length;o>i;i++)e=n[i],null!=e?r.isFunction(e.target.set)?s.push(e.target.set(e.attr,this.get(t))):s.push(e.target[e.attr]=this.get(t)):s.push(void 0);return s}},t.prototype._createLookups=function(){var t,e,n;n=[];for(t in this)e=this[t],!r.isFunction(this[t])&&r.stringEndsWith(t,"Lookup")&&(t=r.sliceStringBefore(t,"Lookup"),n.push(this[t]=r._getPath(e)));return n},t}()}).call(this)}),t.define("/util.coffee",function(t,e){(function(){var t,n,i,r=[].slice,o={}.hasOwnProperty;i={},n=0,t=e.exports={toString:Object.prototype.toString,getType:function(t){return this.toString.call(t).match(/^\[object\s(.*)\]$/)[1]},isObject:function(t){return"Object"===this.getType(t)},isFunction:function(t){return"Function"===this.getType(t)},isArray:function(t){return"Array"===this.getType(t)},isString:function(t){return"String"===this.getType(t)},isBoolean:function(t){return"Boolean"===this.getType(t)},log:function(){var t,e;return e=arguments[0],t=arguments.length>=2?r.call(arguments,1):[],null!=i[e]&&"undefined"!=typeof console&&null!==console?console.log.apply(console,[e+":"].concat(r.call(t))):void 0},showLog:function(t){return i[t]=!0},hideLog:function(t){return i[t]=!1},error:function(){var t,e;throw e=arguments[0],t=arguments.length>=2?r.call(arguments,1):[],"undefined"!=typeof console&&null!==console&&console.error("Exception:",e,t),e},warn:function(){var t,e;return e=arguments[0],t=arguments.length>=2?r.call(arguments,1):[],"undefined"!=typeof console&&null!==console?console.log("Warning:",e,t):void 0},clone:function(t){return $.extend({},t)},getPath:function(t,e){var n;if(n=this._getPath(t,e),void 0===n)throw Error("Object "+t+" has no "+e);return n},isAbsolutePath:function(t){return t[0].toUpperCase()===t[0]},_getPath:function(e,n){var i,r,o;for(null!=e&&null==n&&(n=e,e=Mozart.root),t.isAbsolutePath(n)&&(e=Mozart.root),i=n.split(".");i.length>0;){if(r=i.shift(),"this"!==r){if(void 0===e[r])return void 0;if(o=t.isFunction(e.get)?e.get.call(e,r):e[r],null===o&&i.length>0)return void 0}else o=e;e=o}return o},getId:function(){return++n},parsePath:function(t){var e,n;return-1===t.indexOf(".")?[null,t]:(n=t.split("."),e=n.pop(),[n.join("."),e])},toMap:function(t,e){var n,i,r,o;for(null==e&&(e="id"),i={},r=0,o=t.length;o>r;r++)n=t[r],i[n[e]]=n;return i},sortBy:function(e,n){return n=t.parseSort(n),e.sort(function(t,e){var i,r,o,s,a;for(s=0,a=n.length;a>s;s++)if(o=n[s],i="function"==typeof t[o]?t[o]():t[o],r="function"==typeof e[o]?e[o]():e[o],null!=i&&null!=r){if(null==i)return-1;if(null==r)return 1;if(i=(""+i).toLowerCase(),r=(""+r).toLowerCase(),i>r)return 1;if(r>i)return-1}})},parseSort:function(t,e){var n,i,r;for(null==e&&(e={pos:0}),r=[],i="";e.pos<t.length;)switch(n=t[e.pos++]){case",":i.length>0&&(r.push(i),i="");break;case"[":if(i.length>0)throw Error("parseSort: Unexpected Character [ at "+(""+e.pos));r.push(this.parseSort(t,e));break;case"]":return i.length>0&&r.push(i),r;default:i+=n}return i.length>0&&(r.push(i),i=""),r},toCapsCase:function(t){var e;return e=t.replace(/^[a-z]{1,1}/g,function(t){return t.toUpperCase()}),e=e.replace(/_[a-z]{1,1}/g,function(t){return t.toUpperCase()}),e=e.replace(/_/g," ")},toSnakeCase:function(t){var e;return e=t.replace(/[A-Z]{1,1}/g,function(t){return"_"+t.toLowerCase()}),e.replace(/^_/,"")},sliceStringBefore:function(t,e){return t.slice(0,t.length-e.length)},sliceStringAfter:function(t,e){return t.slice(e.length)},stringEndsWith:function(t,e){var n;return n=e.length,t.length>=n&&t.slice(-n)===e},stringStartsWith:function(t,e){var n;return n=e.length,t.length>=n&&t.slice(0,n)===e},addBindingsParent:function(e){var n,i,r;r=[];for(n in e)o.call(e,n)&&(i=e[n],t.stringEndsWith(n,"Binding")&&null!=i&&null!=i.length&&i.length>0&&i[0]!==i[0].toUpperCase()?r.push(e[n]="parent."+e[n]):r.push(void 0));return r}}}).call(this)}),t.define("/events.coffee",function(t,e,n){(function(){var e,i;i=t("./util"),n.Events=e=function(){function t(){}return t.callbacks={},t.eventInit=function(e,n){var i,r,o,s;return null==(o=(i=t.callbacks)[e])&&(i[e]={count:0,events:{}}),null!=(s=(r=t.callbacks[e].events)[n])?s:r[n]={}},t.trigger=function(e,n,r){var o,s,a,l,h,u,c;if(null!=t.callbacks[e]&&null!=t.callbacks[e].events[n]){a=[],u=t.callbacks[e].events[n];for(s in u)o=u[s],null==o.fn.call&&i.log("general","callback issue ",o.fn),o.fn.call(this,r,o.binddata),o.once&&a.push({objectId:e,eventName:n,id:s});for(c=[],l=0,h=a.length;h>l;l++)o=a[l],c.push(delete t.callbacks[o.objectId].events[o.eventName][o.id]);return c}},t.one=function(e,n,i,r){return t.eventInit(e,n),t.callbacks[e].events[n][t.callbacks[e].count++]={fn:i,binddata:r,once:!0}},t.bind=function(e,n,i,r){return t.eventInit(e,n),t.callbacks[e].events[n][t.callbacks[e].count++]={fn:i,binddata:r}},t.unbind=function(e,n,i){var r,o,s,a,l,h;{if(null==i||null==t.callbacks[e]||null==t.callbacks[e].events[n])return null!=n&&null!=t.callbacks[e]&&null!=t.callbacks[e].events[n]?(delete t.callbacks[e].events[n],void 0):delete t.callbacks[e];s=[],h=t.callbacks[e].events[n];for(o in h)r=h[o],r.fn===i&&s.push(o);for(a=0,l=s.length;l>a;a++)o=s[a],delete t.callbacks[e].events[n][o]}},t.getBinds=function(e,n){return _(t.callbacks[e].events[n]).values()},t}()}).call(this)}),t.define("/control.coffee",function(t,e,n){(function(){var e,i,r=function(t,e){return function(){return t.apply(e,arguments)}},o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var i in e)o.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};i=t("./view").View,n.Control=e=function(t){function e(){return this.afterRender=r(this.afterRender,this),e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.idPrefix="control",e.prototype.error=function(t){return this.help=t,this.errorState=!0},e.prototype.afterRender=function(){return this.errorState?this.element.addClass("error"):void 0},e}(i)}).call(this)}),t.define("/controller.coffee",function(t,e,n){(function(){var e,i,r={}.hasOwnProperty,o=function(t,e){function n(){this.constructor=t}for(var i in e)r.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};i=t("./object").MztObject,n.Controller=e=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return o(e,t),e}(i)}).call(this)}),t.define("/data-index.coffee",function(t,e,n){(function(){var e,i,r,o,s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var i in e)s.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};o=t("./object").MztObject,n.DataIndex=i=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return a(e,t),e.indexTypes={},e.prototype.load=function(){throw Error("Mozart.DataIndex: Abstract, Not Implemented")},e.prototype.add=function(){throw Error("Mozart.DataIndex: Abstract, Not Implemented")},e.prototype.remove=function(){throw Error("Mozart.DataIndex: Abstract, Not Implemented")},e.prototype.update=function(){throw Error("Mozart.DataIndex: Abstract, Not Implemented")},e.prototype.rebuild=function(){throw Error("Mozart.DataIndex: Abstract, Not Implemented")},e.registerIndexClassType=function(t,e){return this.indexTypes[t]=e},e.getIndexClassType=function(t){return this.indexTypes[t]},e}(o),n.MapIndex=r=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return a(e,t),e.prototype.init=function(){return this.map={},this.rebuild()},e.prototype.load=function(t){return null!=this.map[t]?this.map[t]:{}},e.prototype.update=function(t,e,n){var i,r;return null!=this.map[e]&&(delete this.map[e][t.id],0===_(this.map[e]).keys().length&&delete this.map[e]),null==(r=(i=this.map)[n])&&(i[n]={}),this.map[n][t.id]=t},e.prototype.add=function(t){var e,n,i;return null==(i=(e=this.map)[n=t[this.attribute]])&&(e[n]={}),this.map[t[this.attribute]][t.id]=t},e.prototype.remove=function(t){var e,n,i,r;i=this.map,r=[];for(n in i)e=i[n],delete e[t.id],0===_(e).keys().length?r.push(delete this.map[n]):r.push(void 0);return r},e.prototype.rebuild=function(){var t,e,n,i,r;for(this.map={},i=this.modelClass.all(),r=[],e=0,n=i.length;n>e;e++)t=i[e],r.push(this.add(t));return r},e}(i),i.registerIndexClassType("map",r),n.BooleanIndex=e=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return a(e,t),e.prototype.init=function(){return this.value=this.options.value,this.rebuild()},e.prototype.load=function(t){return t===this.value?this.valueIds:this.nonValueIds},e.prototype.update=function(t,e,n){return e===this.value?delete this.valueIds[t.id]:delete this.nonValueIds[t.id],n===this.value?this.valueIds[t.id]=t:this.nonValueIds[t.id]=t},e.prototype.add=function(t){return t[this.attribute]===this.value?this.valueIds[t.id]=t:this.nonValueIds[t.id]=t},e.prototype.remove=function(t){return delete this.valueIds[t.id],delete this.nonValueIds[t.id]},e.prototype.rebuild=function(){var t,e,n,i,r;for(this.valueIds={},this.nonValueIds={},i=this.modelClass.all(),r=[],e=0,n=i.length;n>e;e++)t=i[e],r.push(this.add(t));return r},e}(i),i.registerIndexClassType("boolean",e)}).call(this)}),t.define("/dom-manager.coffee",function(t,e,n){(function(){var e,i,r,o=function(t,e){return function(){return t.apply(e,arguments)}},s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var i in e)s.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t},l=[].indexOf||function(t){for(var e=0,n=this.length;n>e;e++)if(e in this&&this[e]===t)return e;return-1};r=t("./util"),i=t("./object").MztObject,n.DOMManager=e=function(t){function e(){return this.getControlOptionsValues=o(this.getControlOptionsValues,this),this.onControlEvent=o(this.onControlEvent,this),this.onViewEvent=o(this.onViewEvent,this),this.onApplicationEvent=o(this.onApplicationEvent,this),this.release=o(this.release,this),this.checkClickOutside=o(this.checkClickOutside,this),this.checkClickInside=o(this.checkClickInside,this),this.find=o(this.find,this),e.__super__.constructor.apply(this,arguments)}var n;return a(e,t),n={click:"click",dblclick:"dblClick",focus:"focus",blur:"blur",keyup:"keyUp",keydown:"keyDown",keypress:"keyPress",focusout:"focusOut",focusin:"focusIn",change:"change",mouseover:"mouseOver",mouseout:"mouseOut"},e.prototype.init=function(){var t,e,i,r,o;this.element=$(this.rootElement);for(t in n)r=n[t],this.element.on(t,null,{eventName:r},this.onApplicationEvent);
3
- return e=function(){var t;t=[];for(i in n)o=n[i],t.push(i);return t}().join(" "),this.element.on(e,"[view]",this.onViewEvent),this.element.on(e,"[data-mozart-action]",this.onControlEvent),this.openElements={}},e.prototype.find=function(t){var e,n,i,o,s,a;for(a=this.layouts,o=0,s=a.length;s>o;o++){if(i=a[o],null!=i.views[t])return r.log("general",""+t+": view of",i.rootElement),i.views[t];if(e=i.getControl(t),null!=e)return r.log("general",""+t+": control of",i.rootElement),e}return n=$("#"+t),n.length>0?(r.log("general",""+t+" is a an element"),n[0]):r.log("general","Cannot find ID "+t)},e.prototype.checkClickInside=function(t){var e,n,i,o,s,a,l;if("click"===t.type){for(a=this.layouts,l=[],o=0,s=a.length;s>o;o++)n=a[o],l.push(function(){var o,s;o=n.hasClickInside,s=[];for(e in o)i=o[e],$(t.target).parents("#"+e).length>0?(r.log("events","clickInside on",i,"(",t,")"),s.push(i.clickInside())):s.push(void 0);return s}());return l}},e.prototype.checkClickOutside=function(t){var e,n,i,o,s,a,l;if("click"===t.type){for(a=this.layouts,l=[],o=0,s=a.length;s>o;o++)n=a[o],l.push(function(){var o,s;o=n.hasClickOutside,s=[];for(e in o)i=o[e],0===$(t.target).parents("#"+e).length?(r.log("events","clickOutside on",i,"(",t,")"),s.push(i.clickOutside())):s.push(void 0);return s}());return l}},e.prototype.release=function(){var t,i,r,o,s;for(t in n)o=n[t],this.element.off(t,null,this._checkRootEvent);return i=function(){var t;t=[];for(r in n)s=n[r],t.push(r);return t}().join(" "),this.element.off(i,"[view]",this.onViewEvent),this.element.off(i,"[data-mozart-action]",this.onControlEvent),e.__super__.release.apply(this,arguments)},e.prototype.onApplicationEvent=function(t){return this.trigger(t.data.eventName,t)},e.prototype.onViewEvent=function(t){var e,i,o,s,a,l,h,u;if(this.checkClickInside(t),a=null,e=s=t.currentTarget,null!=e){for(u=this.layouts,l=0,h=u.length;h>l;l++)i=u[l],a=i.views[e.id],null!=a&&(o=n[t.type],this.trigger("viewEvent",t,a),"function"==typeof a[o]&&(r.log("events",o,"on",a,"(",t,")"),a[o](t,a)));return this.checkClickOutside(t),!0}},e.prototype.onControlEvent=function(t){var e,n,i,o,s,a,h,u;for(this.checkClickInside(t),n=$(t.currentTarget),i=n.attr("data-mozart-action"),r.log("controls","action",t),h=this.layouts,s=0,a=h.length;a>s;s++)o=h[s],e=o.getControl(i),null!=e&&(null===e.events||(u=t.type,l.call(e.events,u)>=0))&&("function"==typeof e.view[e.action]?(r.log("events","method",e.action,"on",e.view,"(",t,")"),r.log("controls","action on control",e,t),this.trigger("controlEvent",t,e),e.view[e.action](n,this.getControlOptionsValues(e.view,e.options),t),e.allowDefault||t.preventDefault()):r.warn("Action "+e.action+" does not exist on view "+e.view.id+", "+e.view.name,e));return this.checkClickOutside(t),t.stopImmediatePropagation()},e.prototype.getControlOptionsValues=function(t,e){var n,i,o,s;o={};for(n in e)s=e[n],r.stringEndsWith(n,"Lookup")?(i=r.sliceStringBefore(n,"Lookup"),o[i]=r._getPath(t,s)):o[n]=s;return o},e}(i)}).call(this)}),t.define("/handlebars.coffee",function(t){(function(){var e,n,i,r,o,s;i=t("./util"),r=t("./view").View,n=t("./i18n-view").I18nView,e=t("./collection").Collection,o=function(t,e){return i._getPath(t,e)},s=function(t,e){var n;return"string"==typeof e?n=i._getPath(t,e):"function"==typeof e&&(n=e.call(t)),n},Handlebars.registerHelper("site",function(){return new Handlebars.SafeString("/#")}),Handlebars.registerHelper("bind",function(t,e){var n,r,o,s,a,l,h;i.log("handlebars","handlebars helper 'bind':",this,t,e),1===arguments.length&&i.error("Bind helper must have a target."),n="bind"+i.getId(),s=null!=(l=e.hash.tag)?l:"span",r="<"+s+" id='"+n+"'",h=e.hash;for(o in h)a=h[o],i.stringEndsWith(o,"Html")&&(r+=" "+i.sliceStringBefore(o,"Html")+'="'+a+'"');return r+="></"+s+">",e.data.registerDomBind(n,t),new Handlebars.SafeString(r)}),Handlebars.registerHelper("i18n",function(t,e){var n,r,o;return i.log("handlebars","handlebars helper 'i18n':",this,t,e),1===arguments.length?(n="",i.error("i18n helper usage must reference a key.")):(r=i._getPath(window,"i18n."+t),null==r?(i.error("i18n helper: key '"+t+"' does not exist in current language file."),n=""):(o=null!=e&&null!=e.hash?Mozart.MztObject.create(e.hash):{},n=i.getPath(window,"i18n."+t)(o))),new Handlebars.SafeString(n)}),Handlebars.registerHelper("bindI18n",function(t,e){var r,o,s,a,l,h,u;if(i.log("handlebars","handlebars helper 'bindI18n':",this,t,e),1===arguments.length&&i.error("bindI18n helper must have a target."),l={context:this,i18nTemplate:t,parent:e.data},null!=e.hash){i.addBindingsParent(e.hash),u=e.hash;for(o in u)a=u[o],l[o]=a}return h=l.parent.layout.createView(n,l),l.parent.addView(h),s=h.createElement(),r=s.outerHTML,null==r&&(r=""),l.parent.layout.queueRenderView(h),new Handlebars.SafeString(r)}),Handlebars.registerHelper("view",function(t,e){var n,o,s,a,l,h,u,c,d;if(i.log("handlebars","handlebars helper 'view':",this,t,e),1===arguments.length&&(e=t,t=null),s=e.data,u=null!=t?"string"==typeof t?i._getPath(t):t:r,null==u&&i.error("view handlebars helper: viewClass does not exist","context",t,"this",this),c={context:this,parent:s},null!=e.fn&&(c.templateFunction=e.fn),null!=e.hash){i.addBindingsParent(e.hash),d=e.hash;for(o in d)l=d[o],c[o]=l}return h=s.layout.createView(u,c),s.addView(h),a=h.createElement(),n=a.outerHTML,null==n&&(n=""),s.layout.queueRenderView(h),new Handlebars.SafeString(n)}),Handlebars.registerHelper("collection",function(t,n){var o,s,a,l,h,u,c,d,p,f;i.log("handlebars","handlebars helper 'collection':",this,i.clone(t),n),1===arguments.length?(n=t,t=null,d=r):(d=i.getPath(t),null==d&&i.error("View for collection does not exist","view name",t)),l=n.data,p={context:this,viewClass:d,parent:l},null!=n.fn&&(p.viewClassTemplateFunction=n.fn),i.addBindingsParent(n.hash),f=n.hash;for(a in f)u=f[a],p[a]=u;return o=null!=n.hash.collectionClass?i.getPath(n.hash.collectionClass):e,c=l.layout.createView(o,p),c.parent=l,l.addView(c),h=c.createElement(),s=h.outerHTML,null==s&&(s=""),l.layout.queueRenderView(c),new Handlebars.SafeString(s)}),Handlebars.registerHelper("linkTo",function(t,e){var n,r,o;return i.log("handlebars","handlebars helper 'linkTo':",this,t,e),1===arguments.length&&(e=t),"string"==typeof t?t=i._getPath(this,t):"function"==typeof t&&(t=t.call(this)),null!=t?(n="<a href='/#"+t.showUrl()+"'",null!=(null!=(o=e.hash)?o.classNames:void 0)&&(n+=" class='"+e.hash.classNames+"'"),n+=">",r=e.fn(this),null!=r&&r.length>0||(r="(Empty Value)"),n+=r,n+="</a>",new Handlebars.SafeString(n)):""}),Handlebars.registerHelper("valueOf",function(t,e){var n;return i.log("handlebars","handlebars helper 'valueOf':",this,t,e),1===arguments.length&&(e=t),n=i._getPath(this,t),null==n&&(n=""),new Handlebars.SafeString(n)}),Handlebars.registerHelper("rawPath",function(t,e){var n;return 1===arguments.length&&(e=t),n=i._getPath(this,t),null==n&&(n=""),n}),Handlebars.registerHelper("uriPath",function(t,e){var n;return 1===arguments.length&&(e=t),n=i._getPath(this,t),null==n&&(n=""),encodeURI(n)}),Handlebars.registerHelper("valueEach",function(t,e){var n,r,o,s,a,l;if(i.log("handlebars","handlebars helper 'valueEach':",this,t,e),1===arguments.length&&(e=t),t=i.getPath(this,t),null==t)return"";for(r="",o=0,s=t.length;s>o;o++)n=t[o],r+=e.fn(n),null!=(null!=e?null!=(a=e.hash)?a.seperator:void 0:void 0)&&(r+=e.hash.seperator);return null!=(null!=e?null!=(l=e.hash)?l.seperator:void 0:void 0)&&r.length>0&&(r=r.slice(0,r.length-e.hash.seperator.length)),new Handlebars.SafeString(r)}),Handlebars.registerHelper("yesNo",function(t,e){return i.log("handlebars","handlebars helper 'yesNo':",this,t,e),1===arguments.length&&(e=t),"string"==typeof t&&(t=i.getPath(this,t)),null==t?"No":t?"Yes":"No"}),Handlebars.registerHelper("valueIf",function(t,e){return i.log("handlebars","handlebars helper 'valueOf':",this,t,e),"string"==typeof t&&(t=i._getPath(this,t)),t?e.fn(this):e.inverse(this)}),Handlebars.registerHelper("valueUnless",function(t,e){return"string"==typeof t&&(t=i.getPath(this,t)),t?e.inverse(this):e.fn(this)}),Handlebars.registerHelper("action",function(t,e){var n,r,o,s,a;return i.log("handlebars","handlebars helper 'action':",this,t,e),1===arguments.length&&(e=record),a=e.data,null!=e.hash.target&&(a="parent"===e.hash.target?e.data.parent:i.getPath(e.data,e.hash.target)),n=i.getId(),s='data-mozart-action="'+n+'"',o=null!=e.hash.events?e.hash.events.split(","):["click"],r=e.hash.allowDefault&&!0,e.data.layout.addControl(n,{action:t,view:a,options:e.hash,events:o,allowDefault:r}),new Handlebars.SafeString(s)}),Handlebars.registerHelper("date",function(t){var e,n;return n=s(this,t),e=i.serverToLocalDate(n)||"(none)",new Handlebars.SafeString(e)}),Handlebars.registerHelper("dateTime",function(t){var e,n;return n=s(this,t),e=i.serverToLocalDateTime(n),new Handlebars.SafeString(e)}),Handlebars.registerHelper("timeAgo",function(t){var e,n;return n=s(this,t),e=i.serverToLocalTimeAgo(n),new Handlebars.SafeString(e)}),Handlebars.registerHelper("mozartversion",function(){return new Handlebars.SafeString(Mozart.version)}),Handlebars.registerHelper("mozartversiondate",function(){return new Handlebars.SafeString(Mozart.versionDate.toLocaleDateString())})}).call(this)}),t.define("/i18n-view.coffee",function(t,e,n){(function(){var e,i,r,o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var i in e)o.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};r=t("./view").View,i=t("./util"),n.I18nView=e=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.tag="span",e.prototype.idPrefix="i18nview",e.prototype.init=function(){if(e.__super__.init.apply(this,arguments),null==this.i18nTemplate)throw Error("Mozart.I18nView must have a i18nTemplate");return this.bind("change",this.redraw)},e.prototype.templateFunction=function(){try{return i.getPath(window,"i18n."+this.i18nTemplate)(this)}catch(t){return i.warn("MessageFormat failed with Error:",t),""}},e}(r)}).call(this)}),t.define("/http.coffee",function(t,e,n){(function(){var e,i,r,o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var i in e)o.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};i=t("./object").MztObject,r=t("./util"),n.HTTP=e=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.handleError=function(t,e,n,i){switch(t.status){case 401:return Mozart.Ajax.trigger("httpAuthorizationRequired",n,t);case 404:return Mozart.Ajax.trigger("httpForbidden",n,t);default:return r.error("Model.Ajax.handleError",t,e,i)}},e.prototype._xhrHandler=function(t,e,n,i,o){var s,a,l,h,u;return this.support.ajax?(u="object"==typeof t?this.support.cors?t.cors||t.proxy:t.proxy:t,l=e||"GET",h=i||{},s=o||{},a=n||{},o.success=o.success||function(t,n,i){return r.log("Mozart.HTTP",e,"success",t,n,i)},o.error=o.error||function(t,n,i){return r.log("Mozart.HTTP",e,"error",t,n,i)},o.complete=o.complete||function(t,n){return r.log("Mozart.HTTP",e,"complete",t,n)},this._request(u,l,a,h,s)):r.log("Mozart.HTTP","AJAX is not supported. Exiting")},e.prototype._request=function(t,e,n,i,r){return $.ajax({url:t,type:e,success:r.success,error:r.error,complete:r.complete,data:n,context:i.context||this,dataType:i.dataType||"json",contentType:i.contentType||"application/json"})},e.prototype.support={ajax:function(){try{return!!new XMLHttpRequest}catch(t){return!1}},cors:function(){return this.ajax&&"withCredentials"in new XMLHttpRequest}},e.prototype.get=function(t,e){var n,i,r;return e=e||{},i=e.data||{},r=e.options||{},n=e.callbacks||{},this._xhrHandler(t,"GET",i,r,n)},e.prototype.post=function(t,e){var n,i,r;return e=e||{},i=e.data||{},r=e.options||{},n=e.callbacks||{},this._xhrHandler(t,"POST",i,r,n)},e.prototype.put=function(t,e){var n,i,r;return e=e||{},i=e.data||{},r=e.options||{},n=e.callbacks||{},this._xhrHandler(t,"PUT",i,r,n)},e.prototype["delete"]=function(t,e){var n,i,r;return e=e||{},i=e.data||{},r=e.options||{},n=e.callbacks||{},this._xhrHandler(t,"DELETE",i,r,n)},e}(i)}).call(this)}),t.define("/layout.coffee",function(t,e,n){(function(){var e,i,r,o=function(t,e){return function(){return t.apply(e,arguments)}},s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var i in e)s.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};r=t("./util"),i=t("./router").Router,n.Layout=e=function(t){function e(){return this.releaseViewControls=o(this.releaseViewControls,this),this.removeControl=o(this.removeControl,this),this.getControl=o(this.getControl,this),this.addControl=o(this.addControl,this),this.releaseViews=o(this.releaseViews,this),this.releaseView=o(this.releaseView,this),this.queueReleaseView=o(this.queueReleaseView,this),this.release=o(this.release,this),this.processRenderQueue=o(this.processRenderQueue,this),this.queueRenderView=o(this.queueRenderView,this),this._transition=o(this._transition,this),this.doRoute=o(this.doRoute,this),this.resetRoute=o(this.resetRoute,this),this.bindRoot=o(this.bindRoot,this),this.createView=o(this.createView,this),this.init=o(this.init,this),e.__super__.constructor.apply(this,arguments)}return a(e,t),e.prototype.init=function(){var t,n,i,r,o;for(e.__super__.init.apply(this,arguments),this.viewRenderQueue=[],this.releaseMap={},this.views={},this.currentState=null,this.controls={},this.hasClickOutside={},this.hasClickInside={},r=this.states,o=[],n=0,i=r.length;i>n;n++)t=r[n],null!=t.path&&null!=t.viewClass&&o.push(this.register(t.path,this.doRoute,t));return o},e.prototype.createView=function(t,e){var n;return null==e&&(e={}),e.layout=this,n=t.create(e),this.views[n.id]=n,null!=n.clickInside&&(this.hasClickInside[n.id]=n),null!=n.clickOutside&&(this.hasClickOutside[n.id]=n),n},e.prototype.bindRoot=function(){return this.rootEl=$(this.rootElement)[0]},e.prototype.resetRoute=function(){return this.viewRenderQueue=[],this.currentState=null,this.releaseViews()},e.prototype.doRoute=function(t,e){return null==this.currentState||this.currentState.canExit()?(this.currentState=null,t.canEnter(e)?(this._transition(t),!0):(r.log("layout","cannot enter state",t,e),!1)):(r.log("layout","cannot exit state",this.currentState),!1)},e.prototype._transition=function(t){return this.resetRoute(),this.currentState=t,this.currentState.doTitle(),null!=this.currentState.viewClass?(null!=this.currentView&&(this.releaseMap[this.currentView.id]=this.currentView),this.currentView=this.createView(this.currentState.viewClass,this.currentState.viewOptions),this.currentView.el=this.rootEl,this.queueRenderView(this.currentView)):void 0},e.prototype.queueRenderView=function(t){var e,n,i;return r.log("layout",""+this._mozartId+" queueRenderView",t),null==(i=(e=this.views)[n=t.id])&&(e[n]=t),0===this.viewRenderQueue.length&&_.delay(this.processRenderQueue,0),this.viewRenderQueue.push(t)},e.prototype.processRenderQueue=function(){var t,e,n,i,o,s,a,l,h,u,c,d,p,f,g,y,m,v,w;if(!this.released&&0!==this.viewRenderQueue.length){for(r.log("layout",""+this._mozartId+" processRenderQueue with "+this.viewRenderQueue.length+" views"),e=[],n=[];this.viewRenderQueue.length>0;)s=this.viewRenderQueue.shift(),s.beforeRender(),s.releaseChildren(),s.prepareElement(),n.push(s);for(i=[],h=0,p=n.length;p>h;h++)for(a=n[h],u=0,f=n.length;f>u;u++)l=n[u],l!==a&&a.hasAncestor(l)&&!_.contains(i,a)&&i.push(a);for(o=_.difference(n,i),c=0,g=o.length;g>c;c++)s=o[c],s.reassignElements();for(d=0,y=o.length;y>d;d++)s=o[d],s.replaceElement();for(v=0,m=n.length;m>v;v++)s=n[v],s.postRender();w=this.releaseMap;for(t in w)s=w[t],null!=s&&s.release();return this.releaseMap={},r.log("layout",""+this._mozartId+" render finished"),this.trigger("render:complete")}},e.prototype.release=function(){return this.releaseViews(),e.__super__.release.apply(this,arguments)},e.prototype.queueReleaseView=function(t){return this.releaseMap[t.id]=t},e.prototype.releaseView=function(t){return this.releaseViewControls(t),delete this.views[t.id],delete this.hasClickOutside[t.id],delete this.hasClickInside[t.id]},e.prototype.releaseViews=function(){var t,e,n,i;n=this.views,i=[];for(t in n)e=n[t],r.log("layout","processRenderQueue:releasing",e.id,e),this.releaseMap[t]=e,i.push(this.processRenderQueue());return i},e.prototype.addControl=function(t,e){return r.log("layout","adding control",t,e),this.controls[t]=e},e.prototype.getControl=function(t){return this.controls[t]},e.prototype.removeControl=function(t){return r.log("layout","removing control",t),delete this.controls[t]},e.prototype.releaseViewControls=function(t){var e,n,i,o;i=this.controls,o=[];for(n in i)e=i[n],e.view===t&&(r.log("layout","releasing control for view",t,"control",e.action,e),o.push(delete this.controls[n]));return o},e}(i)}).call(this)}),t.define("/router.coffee",function(t,e,n){(function(){var e,i,r,o=function(t,e){return function(){return t.apply(e,arguments)}},s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var i in e)s.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=t("./object").MztObject,r=t("./util"),n.Router=i=function(t){function e(){return this.release=o(this.release,this),this.navigateRoute=o(this.navigateRoute,this),this.onPopState=o(this.onPopState,this),this.onNavigationEvent=o(this.onNavigationEvent,this),this.onHashChange=o(this.onHashChange,this),this.register=o(this.register,this),this.stop=o(this.stop,this),this.start=o(this.start,this),this.init=o(this.init,this),e.__super__.constructor.apply(this,arguments)}return a(e,t),e.prototype.init=function(){var t;return this.routes={},null!=(t=this.useHashRouting)?t:this.useHashRouting=!1},e.prototype.start=function(){return this.useHashRouting?($(window).bind("hashchange",this.onHashChange),this.onHashChange()):($("body").on("click","a",this.onNavigationEvent),$(window).on("popstate",this.onPopState),-1!==navigator.userAgent.indexOf("Firefox")?this.onPopState():void 0)},e.prototype.stop=function(){return this.useHashRouting?$(window).unbind("hashchange",this.onHashChange):($("body").off("click","a",this.onNavigationEvent),$(window).off("popstate",this.onPopState))},e.prototype.register=function(t,e,n){var i,o,s,a,l,h;for(r.log("routes","registering route",t,n),a=t.split("/"),i=[],o="",l=0,h=a.length;h>l;l++)s=a[l],":"===s[0]?(o+="([^\\/]+)\\/",i.push(s.substr(1))):o+=this._escForRegEx(s)+"\\/";return o.length>2&&(o=o.substr(0,o.length-2)),this.routes[t]={regex:RegExp("^"+o+"$","i"),params:i,callback:e,data:n}},e.prototype.onHashChange=function(){var t;return t=window.location.hash,t.length>0&&"#"===t[0]&&(t=t.substr(1)),this.navigateRoute(t)},e.prototype.onNavigationEvent=function(t){return t.target.host===document.location.host&&t.target.port===document.location.port&&t.target.protocol===document.location.protocol?this.navigateRoute(t.target.pathname)?(history.pushState({one:1},null,t.target.href),t.preventDefault()):void 0:void 0},e.prototype.onPopState=function(){return this.navigateRoute(window.location.pathname)},e.prototype.navigateRoute=function(t){var e,n,i,o,s,a,l,h,u,c;if(this.isNavigating=!0,null==t||0===t.length){if(a=this.routes["/"],null!=a)return a.callback(a.data,i),this.isNavigating=!1,!1;r.log("routemanager","WARNING: No Default route defined, no route for path",t)}u=this.routes;for(o in u)if(a=u[o],i={},n=a.regex.exec(t),null!==n){for(e=1,c=a.params,l=0,h=c.length;h>l;l++)s=c[l],n.length>e&&(i[s]=n[e++]);return a.callback(a.data,i),this.isNavigating=!1,!0}return this.isNavigating=!1,this.trigger("noroute",window.location.hash),!1},e.prototype.release=function(){return this.stop(),e.__super__.release.apply(this,arguments)},e.prototype._escForRegEx=function(t){var e,n,i,r;for(t.replace("\\","\\\\"),e="./+{}()*",i=0,r=e.length;r>i;i++)n=e[i],t=t.replace(n,"\\"+n);return t},e}(e)}).call(this)}),t.define("/model-instance.coffee",function(t,e,n){(function(){var e,i,r,o=function(t,e){return function(){return t.apply(e,arguments)}},s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var i in e)s.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t},l=[].indexOf||function(t){for(var e=0,n=this.length;n>e;e++)if(e in this&&this[e]===t)return e;return-1};r=t("./util"),i=t("./object").MztObject,n.Instance=e=function(t){function e(){return this.copyFrom=o(this.copyFrom,this),this.copyTo=o(this.copyTo,this),this.set=o(this.set,this),this.get=o(this.get,this),this.destroy=o(this.destroy,this),this.save=o(this.save,this),this.load=o(this.load,this),e.__super__.constructor.apply(this,arguments)}var n;return a(e,t),n=["id"],e.prototype.init=function(){return this._type=this.modelClass.modelName},e.prototype.load=function(t){return null==t&&(t={}),this.modelClass.loadInstance(this,t)},e.prototype.save=function(t){return null==t&&(t={}),this.modelClass.exists(this.id)?(this.modelClass.updateInstance(this,t),this.trigger("update")):(this.modelClass.createInstance(this,t),this.trigger("create")),this.trigger("change")},e.prototype.destroy=function(t){return null==t&&(t={}),this.trigger("destroy",t),this.trigger("change"),this.modelClass.destroyInstance(this,t)},e.prototype.get=function(t){if(this.modelClass.hasAttribute(t)||r.isFunction(this[t]))return r.isFunction(this[t])?this[t].apply(this):e.__super__.get.call(this,t);throw Error(""+this.modelClass.modelName+" has no attribute or relation '"+t+"' or foreign key '"+t+"_id'")},e.prototype.set=function(t,n){if(this.modelClass.hasAttribute(t)||r.isFunction(this[t]))return r.isFunction(this[t])?this[t](n):("id"!==t&&this.modelClass.hasIndex(t)&&this.modelClass.exists(this.id)&&this.modelClass.updateIndex(t,this,this[t],n),e.__super__.set.call(this,t,n));throw Error(""+this.modelClass.modelName+" has no attribute or relation '"+t+"' or foreign key '"+t+"_id'")},e.prototype.copyTo=function(t){var e,r,o;null==t&&(t=i.create()),o=this.modelClass.attrs;for(e in o)r=o[e],0>l.call(n,e)&&(null!=t.set?t.set(e,this[e]):t[e]=this[e]);return t},e.prototype.copyFrom=function(t){var e,i,r,o,s;i=!1;for(e in t)s=t[e],0>l.call(n,e)&&(o=this.modelClass.attrs[e],null!=o&&(r=s,"decimal"===o&&(r=parseFloat(r)),this[e]!==r&&(i=!0,this.set(e,r))));return i},e}(i)}).call(this)}),t.define("/model-instancecollection.coffee",function(t,e,n){(function(){var e,i,r,o=function(t,e){return function(){return t.apply(e,arguments)}},s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var i in e)s.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};r=t("./util"),i=t("./object").MztObject,n.InstanceCollection=e=function(t){function e(){return this.unBindEvents=o(this.unBindEvents,this),this.bindEvents=o(this.bindEvents,this),this.allAsMap=o(this.allAsMap,this),this.count=o(this.count,this),e.__super__.constructor.apply(this,arguments)}return a(e,t),e.prototype.count=function(){return this.all().length},e.prototype.allAsMap=function(){return r.toMap(this.all())},e.prototype.all=function(){return[]},e.prototype.bindEvents=function(t){var e,n,i,r;for(r=[],n=0,i=t.length;i>n;n++)e=t[n],e.bind("create",this.onModelChange),e.bind("update",this.onModelChange),r.push(e.bind("destroy",this.onModelChange));return r},e.prototype.unBindEvents=function(t){var e,n,i,r;for(r=[],n=0,i=t.length;i>n;n++)e=t[n],e.unbind("create",this.onModelChange),e.unbind("update",this.onModelChange),r.push(e.unbind("destroy",this.onModelChange));return r},e}(i)}).call(this)}),t.define("/model-onetomanycollection.coffee",function(t,e,n){(function(){var e,i,r=function(t,e){return function(){return t.apply(e,arguments)}},o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var i in e)o.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=t("./model-instancecollection").InstanceCollection,n.OneToManyCollection=i=function(t){function e(){return this.release=r(this.release,this),this.onModelChange=r(this.onModelChange,this),this.contains=r(this.contains,this),this.remove=r(this.remove,this),this.createFromValues=r(this.createFromValues,this),this.add=r(this.add,this),this.all=r(this.all,this),e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.init=function(){return this.bindEvents([this.otherModel])},e.prototype.all=function(){return this.otherModel.findByAttribute(this.fkname,this.record.id)},e.prototype.add=function(t){return t.set(this.fkname,this.record.id),t.save(),this.record.trigger("change:"+this.attribute)},e.prototype.createFromValues=function(t){var e;return e=this.otherModel.initInstance(t),this.add(e),e},e.prototype.remove=function(t){return t.set(this.fkname,null),this.record.trigger("change:"+this.attribute)},e.prototype.contains=function(){return this.otherModel.findByAttribute(this.fkname,this.record.id).length>0},e.prototype.onModelChange=function(t){return this.trigger("change",t)},e.prototype.release=function(){return this.unBindEvents([this.otherModel]),e.__super__.release.apply(this,arguments)},e}(e)}).call(this)}),t.define("/model-onetomanypolycollection.coffee",function(t,e,n){(function(){var e,i,r=function(t,e){return function(){return t.apply(e,arguments)}},o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var i in e)o.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=t("./model-instancecollection").InstanceCollection,n.OneToManyPolyCollection=i=function(t){function e(){return this.contains=r(this.contains,this),this.remove=r(this.remove,this),this.add=r(this.add,this),this.createFromValues=r(this.createFromValues,this),this.all=r(this.all,this),e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.all=function(){var t;return t={},t[this.thatFkAttr]=this.record.id,t[this.thatTypeAttr]=this.model.modelName,this.otherModel.findByAttributes(t)},e.prototype.createFromValues=function(t){var e;return e=this.otherModel.initInstance(t),this.add(e),e},e.prototype.add=function(t){return t.set(this.thatFkAttr,this.record.id),t.set(this.thatTypeAttr,this.model.modelName),t.save()},e.prototype.remove=function(t){return t.set(this.thatFkAttr,null),t.set(this.thatTypeAttr,null),t.save()},e.prototype.contains=function(){var t;return t={},t[this.thatFkAttr]=this.record.id,t[this.thatTypeAttr]=this.model.modelName,0!==this.otherModel.findByAttributes(t).length},e}(e)}).call(this)}),t.define("/model-manytomanycollection.coffee",function(t,e,n){(function(){var e,i,r=function(t,e){return function(){return t.apply(e,arguments)}},o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var i in e)o.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=t("./model-instancecollection").InstanceCollection,n.ManyToManyCollection=i=function(t){function e(){return this.release=r(this.release,this),this.onModelChange=r(this.onModelChange,this),this.contains=r(this.contains,this),this.remove=r(this.remove,this),this.createFromValues=r(this.createFromValues,this),this.add=r(this.add,this),this.all=r(this.all,this),e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.init=function(){return this.bindEvents([this.linkModel])},e.prototype.all=function(){var t,e,n,i,r;for(e=this.linkModel.findByAttribute(this.thisFkAttr,this.record.id),r=[],n=0,i=e.length;i>n;n++)t=e[n],r.push(this.otherModel.findById(t[this.thatFkAttr]));return r},e.prototype.add=function(t){var e,n;return n={},n[this.thisFkAttr]=this.record.id,n[this.thatFkAttr]=t.id,0===this.linkModel.findByAttributes(n).length?(e=this.linkModel.initInstance(),e.set(this.thisFkAttr,this.record.id),e.set(this.thatFkAttr,t.id),e.save(),e):void 0},e.prototype.createFromValues=function(t){var e;return e=this.otherModel.initInstance(t),e.save(),this.add(e),e},e.prototype.remove=function(t){var e,n,i,r,o,s;for(i={},i[this.thisFkAttr]=this.record.id,i[this.thatFkAttr]=t.id,n=this.linkModel.findByAttributes(i),s=[],r=0,o=n.length;o>r;r++)e=n[r],s.push(e.destroy());return s},e.prototype.contains=function(t){var e;return e={},e[this.thisFkAttr]=this.record.id,e[this.thatFkAttr]=t.id,0!==this.linkModel.findByAttributes(e).length},e.prototype.onModelChange=function(t){var e;return t.get(this.thisFkAttr)===this.record.id?(e=this.otherModel.findById(t[this.thatFkAttr]),this.trigger("change",e)):void 0},e.prototype.release=function(){return this.unBindEvents([this.linkModel]),e.__super__.release.apply(this,arguments)},e}(e)}).call(this)}),t.define("/model-manytomanypolycollection.coffee",function(t,e,n){(function(){var e,i,r=function(t,e){return function(){return t.apply(e,arguments)}},o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var i in e)o.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=t("./model-instancecollection").InstanceCollection,n.ManyToManyPolyCollection=i=function(t){function e(){return this.release=r(this.release,this),this.onModelChange=r(this.onModelChange,this),this.contains=r(this.contains,this),this.remove=r(this.remove,this),this.add=r(this.add,this),this.createFromValues=r(this.createFromValues,this),this.all=r(this.all,this),e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.init=function(){return this.bindEvents([this.linkModel])},e.prototype.all=function(){var t,e,n,i,r,o;for(n={},n[this.thisFkAttr]=this.record.id,n[this.thatTypeAttr]=this.otherModel.modelName,e=this.linkModel.findByAttributes(n),o=[],i=0,r=e.length;r>i;i++)t=e[i],o.push(this.otherModel.findById(t[this.thatFkAttr]));return o},e.prototype.createFromValues=function(t){var e;return e=this.otherModel.initInstance(t),e.save(),this.add(e),e},e.prototype.add=function(t){var e,n;return n={},n[this.thisFkAttr]=this.record.id,n[this.thatFkAttr]=t.id,n[this.thatTypeAttr]=this.otherModel.modelName,0===this.linkModel.findByAttributes(n).length?(e=this.linkModel.initInstance(),e.set(this.thisFkAttr,this.record.id),e.set(this.thatFkAttr,t.id),e.set(this.thatTypeAttr,this.otherModel.modelName),e.save(),e):void 0},e.prototype.remove=function(t){var e,n,i,r,o,s;for(n={},n[this.thisFkAttr]=this.record.id,n[this.thatFkAttr]=t.id,n[this.thatTypeAttr]=this.otherModel.modelName,o=this.linkModel.findByAttributes(n),s=[],i=0,r=o.length;r>i;i++)e=o[i],s.push(e.destroy());return s},e.prototype.contains=function(t){var e;return e={},e[this.thisFkAttr]=this.record.id,e[this.thatFkAttr]=t.id,e[this.thatTypeAttr]=this.otherModel.modelName,0!==this.linkModel.findByAttributes(e).length},e.prototype.onModelChange=function(t){var e;return t[this.thisFkAttr]===this.record.id&&t[this.thatTypeAttr]===this.otherModel.modelName?(e=this.otherModel.findById(t[this.thatFkAttr]),this.trigger("change",e)):void 0},e.prototype.release=function(){return this.unBindEvents([this.linkModel]),e.__super__.release.apply(this,arguments)},e}(e)}).call(this)}),t.define("/model-manytomanypolyreversecollection.coffee",function(t,e,n){(function(){var e,i,r=function(t,e){return function(){return t.apply(e,arguments)}},o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var i in e)o.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=t("./model-instancecollection").InstanceCollection,n.ManyToManyPolyReverseCollection=i=function(t){function e(){return this.release=r(this.release,this),this.onModelChange=r(this.onModelChange,this),this.contains=r(this.contains,this),this.remove=r(this.remove,this),this.add=r(this.add,this),this.createFromValues=r(this.createFromValues,this),this.all=r(this.all,this),e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.init=function(){return this.bindEvents([this.linkModel])},e.prototype.all=function(){var t,e,n,i,r,o;for(n={},n[this.thatFkAttr]=this.record.id,n[this.thatTypeAttr]=this.model.modelName,e=this.linkModel.findByAttributes(n),o=[],i=0,r=e.length;r>i;i++)t=e[i],o.push(this.otherModel.findById(t[this.thisFkAttr]));
4
- return o},e.prototype.createFromValues=function(t){var e;return e=this.otherModel.initInstance(t),e.save(),this.add(e),e},e.prototype.add=function(t){var e,n;return n={},n[this.thisFkAttr]=t.id,n[this.thatFkAttr]=this.record.id,n[this.thatTypeAttr]=this.model.modelName,0===this.linkModel.findByAttributes(n).length?(e=this.linkModel.initInstance(),e.set(this.thisFkAttr,t.id),e.set(this.thatFkAttr,this.record.id),e.set(this.thatTypeAttr,this.model.modelName),e.save(),e):void 0},e.prototype.remove=function(t){var e,n,i,r,o,s;for(n={},n[this.thisFkAttr]=t.id,n[this.thatFkAttr]=this.record.id,n[this.thatTypeAttr]=this.model.modelName,o=this.linkModel.findByAttributes(n),s=[],i=0,r=o.length;r>i;i++)e=o[i],s.push(e.destroy());return s},e.prototype.contains=function(t){var e;return e={},e[this.thisFkAttr]=t.id,e[this.thatFkAttr]=this.record.id,e[this.thatTypeAttr]=this.model.modelName,0!==this.linkModel.findByAttributes(e).length},e.prototype.onModelChange=function(t){var e;return t[this.thatFkAttr]===this.record.id&&t[this.thatTypeAttr]===this.model.modelName?(e=this.model.findById(t[this.thisFkAttr]),this.trigger("change",e)):void 0},e.prototype.release=function(){return this.unBindEvents([this.linkModel]),e.__super__.release.apply(this,arguments)},e}(e)}).call(this)}),t.define("/model-ajax.coffee",function(t){(function(){var e,n,i,r;e=t("./model").Model,n=t("./util"),r={},i={},e.extend({ajax:function(t){var e,o,s,a,l,h,u,c,d;for(h=["url","interface","plural"],o=0,s=h.length;s>o;o++)e=h[o],null!=t[e]&&(this[e]=t[e]);return this.bind("load",this.loadServer),this.bind("create",this.createServer),this.bind("update",this.updateServer),this.bind("destroy",this.destroyServer),null==(u=r[a=this.modelName])&&(r[a]={}),null==(c=i[l=this.modelName])&&(i[l]={}),null==(d=Mozart.Ajax)&&(Mozart.Ajax=Mozart.MztObject.create({handleError:function(t,e,i,r){switch(t.status){case 401:return Mozart.Ajax.trigger("httpAuthorizationRequired",i,t);case 404:return Mozart.Ajax.trigger("httpForbidden",i,t);default:return n.error("Model.Ajax.handleError",t,e,r)}}})),this.instanceClass.extend({getServerId:function(){return this.modelClass.getServerId(this.id)},existsOnServer:function(){return null!=this.modelClass.getServerId(this.id)},loadServer:function(){return this.modelClass.load(this.modelClass.getServerId(this.id))}})},registerServerId:function(t,e){if(null==r[this.modelName])throw Error("Model.registerServerId: "+this.modelName+" is not registered for ajax.");return r[this.modelName][e]=t,i[this.modelName][t]=e},unRegisterServerId:function(t,e){return delete r[this.modelName][e],delete i[this.modelName][t]},getServerId:function(t){return i[this.modelName][t]},getClientId:function(t){return r[this.modelName][t]},toServerObject:function(t){var n,i,r,o,s,a,l,h;r={},a=this.attrs;for(n in a)o=a[n],"id"!==n&&(r[n]=t[n]);r.id=this.getServerId(t.id),l=this.fks;for(n in l)i=l[n],r[n]=i.getServerId(t[n]);h=this.polyFks;for(n in h)s=h[n],r[n]=null!=t[s]?e.models[t[s]].getServerId(t[n]):null;return r},toClientObject:function(t){var n,i,r,o,s,a,l,h;r={},a=this.attrs;for(n in a)o=a[n],"id"!==n&&t[n]!==void 0&&(r[n]=t[n]);r.id=this.getClientId(t.id),l=this.fks;for(n in l)i=l[n],t[n]!==void 0&&(r[n]=i.getClientId(t[n]),r[n]===void 0&&(r[n]=null));h=this.polyFks;for(n in h)s=h[n],r[n]=t[n]!==void 0&&null!=t[s]?e.models[t[s]].getClientId(t[n]):null;return r},loadServer:function(t){var e;return e=t.modelClass.getServerId(t.id),null!=e?t.modelClass.load(e):void 0},createServer:function(t){return t.modelClass.createAjax(t.id,t.modelClass.toServerObject(t))},updateServer:function(t){var e;return e=t.modelClass.getServerId(t.id),null!=e?t.modelClass.updateAjax(e,t.id,t.modelClass.toServerObject(t)):void 0},destroyServer:function(t){var e;return e=t.modelClass.getServerId(t.id),null!=e?t.modelClass.destroyAjax(t.modelClass.getServerId(t.id),t.id):void 0},loadAll:function(){var t,e,i,r;return r=function(t,e){var n,i,r;for(null!=this.model.plural&&(t=t[this.model.plural]),i=0,r=t.length;r>i;i++)n=t[i],this.model._processLoad(n,this.model,e);return this.model.trigger("loadAllComplete")},i=function(t,e,n){return Mozart.Ajax.handleError(t,e,this,n)},e=function(t,e){return n.log("ajax","Model.loadAll.onComplete",t,e)},t=Mozart.HTTP.create(),t.get(this.url,{options:{context:{model:this}},callbacks:{success:r,error:i,complete:e}})},load:function(t){var e,i,r,o;return o=function(t,e){return null!=this.model.plural&&(t=t[this.model.plural]),this.model._processLoad(t,this.model,e)},r=function(t,e,n){return Mozart.Ajax.handleError(t,e,this,n)},i=function(t,e){return n.log("ajax","Model.load.onComplete",t,e)},e=Mozart.HTTP.create(),e.get(this.url+"/"+t,{options:{context:{model:this,id:t}},callbacks:{success:o,error:r,complete:i}})},_processLoad:function(t,e,i){var r,o,s;return s=t.id,r=e.toClientObject(t),o=e.findById(r.id),null==o&&(o=e.initInstance(t)),e.registerServerId(o.id,s),o.copyFrom(r),o.save({disableModelCreateEvent:!0,disableModelUpdateEvent:!0}),n.log("ajax","Model._processLoad.onSuccess",i,t),e.trigger("loadComplete",o)},createAjax:function(t,e){var i,r,o,s;return s=function(e,i){return this.model.registerServerId(this.clientId,e.id),n.log("ajax","Model.createAjax.onSuccess",i,e),this.model.trigger("createComplete",this.model.findById(t))},o=function(t,e,n){return Mozart.Ajax.handleError(t,e,this,n)},r=function(t,e){return n.log("ajax","Model.createAjax.onComplete",t,e)},i=Mozart.HTTP.create(),i.post(this.url,{data:JSON.stringify(e),options:{context:{model:this,clientId:t}},callbacks:{success:s,error:o,complete:r}})},updateAjax:function(t,e,i){var r,o,s,a;return a=function(t,i){return n.log("ajax","Model.updateAjax.onSuccess",i,t),this.model.trigger("updateComplete",this.model.findById(e))},s=function(t,e,n){return Mozart.Ajax.handleError(t,e,this,n)},o=function(t,e){return n.log("ajax","Model.updateAjax.onComplete",t,e)},r=Mozart.HTTP.create(),r.put(this.url+"/"+t,{data:JSON.stringify(i),options:{context:{model:this,clientId:this.clientId,serverId:this.serverId}},callbacks:{success:a,error:s,complete:o}})},destroyAjax:function(t,e){var i,r,o,s;return s=function(i,r){return this.model.unRegisterServerId(e,t),n.log("ajax","Model.destroyAjax.onSuccess",r,i),this.model.trigger("destroyComplete",t)},o=function(t,e,n){return Mozart.Ajax.handleError(t,e,this,n)},r=function(t,e){return n.log("ajax","Model.destroyAjax.onComplete",t,e)},i=Mozart.HTTP.create(),i["delete"](this.url+"/"+t,{options:{context:{model:this,clientId:e,serverId:t}},callbacks:{success:s,error:o,complete:r}})}})}).call(this)}),t.define("/model.coffee",function(t,e,n){(function(){var e,i,r,o,s,a,l,h,u,c,d,p=function(t,e){return function(){return t.apply(e,arguments)}},f={}.hasOwnProperty,g=function(t,e){function n(){this.constructor=t}for(var i in e)f.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};d=t("./util"),h=t("./object").MztObject,e=t("./data-index").DataIndex,i=t("./model-instance").Instance,r=t("./model-instancecollection").InstanceCollection,u=t("./model-onetomanycollection").OneToManyCollection,c=t("./model-onetomanypolycollection").OneToManyPolyCollection,o=t("./model-manytomanycollection").ManyToManyCollection,s=t("./model-manytomanypolycollection").ManyToManyPolyCollection,a=t("./model-manytomanypolyreversecollection").ManyToManyPolyReverseCollection,n.Model=l=function(t){function n(){return this.index=p(this.index,this),this._generateId=p(this._generateId,this),this._getInstance=p(this._getInstance,this),this.toSnakeCase=p(this.toSnakeCase,this),this.destroyInstance=p(this.destroyInstance,this),this.updateInstance=p(this.updateInstance,this),this.createInstance=p(this.createInstance,this),this.loadInstance=p(this.loadInstance,this),this.createFromValues=p(this.createFromValues,this),this.initInstance=p(this.initInstance,this),this.exists=p(this.exists,this),this.findByAttributes=p(this.findByAttributes,this),this.findByAttribute=p(this.findByAttribute,this),this.selectAsMap=p(this.selectAsMap,this),this.selectIds=p(this.selectIds,this),this.select=p(this.select,this),this.findAll=p(this.findAll,this),this.findById=p(this.findById,this),this.count=p(this.count,this),this.allAsMap=p(this.allAsMap,this),this.all=p(this.all,this),this.hasManyThrough=p(this.hasManyThrough,this),this.hasMany=p(this.hasMany,this),this.belongsToPoly=p(this.belongsToPoly,this),this.belongsTo=p(this.belongsTo,this),this.polyForeignKeys=p(this.polyForeignKeys,this),this.foreignKeys=p(this.foreignKeys,this),this.attributes=p(this.attributes,this),this.reset=p(this.reset,this),n.__super__.constructor.apply(this,arguments)}return g(n,t),n.idCount=1,n.indexForeignKeys=!0,n.models={},n.prototype.toString=function(){return"Model: "+this.modelName},n.prototype.init=function(){var t;if(null==this.modelName)throw Error("Model must have a modelName");return this.records={},this.fks={},this.polyFks={},this.attrs={id:"integer"},this.relations={},this.indexes={},n.models[this.modelName]=this,this.instanceClass=t=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return g(e,t),e}(i)},n.prototype.reset=function(){var t,e,n;n=this.records;for(t in n)e=n[t],e.release();return this.records={},this.rebuildAllIndexes()},n.prototype.attributes=function(t){var e,n,i;i=[];for(e in t)n=t[e],i.push(this.attrs[e]=n);return i},n.prototype.hasAttribute=function(t){return null!=this.attrs[t]||null!=this.fks[t+"_id"]},n.prototype.hasRelation=function(t){return null!=this.relations[t]},n.prototype.foreignKeys=function(t){var e,i,r;r=[];for(e in t)i=t[e],this.fks[e]=i,n.DataIndexForeignKeys?r.push(this.index(e)):r.push(void 0);return r},n.prototype.polyForeignKeys=function(t){var e,i,r;r=[];for(e in t)i=t[e],this.polyFks[e]=i,n.DataIndexForeignKeys?r.push(this.index(e)):r.push(void 0);return r},n.prototype.belongsTo=function(t,e,n){var i,r,o,s,a;return null==e&&null==e&&(e=this.toSnakeCase(t.modelName)),r={},null==n&&(n=e+"_id"),r[n]="integer",this.attributes(r),o={},o[n]=t,this.foreignKeys(o),s={},s[e]=function(i){var r;if(1===arguments.length){if(null!==i&&(null==i.modelClass||i.modelClass!==t))throw Error("Cannot assign "+i+" to belongsTo "+this.modelClass.modelName+":"+e+" (Value is not an Instance or incorrect ModelClass)");return null!=i?this.set(n,i.id):this.set(n,null)}return r=this[n],null==r?null:t.findById(r)},this.instanceClass.extend(s),i=this,a=function(e){var i,r,o,s,a;for(s=t.findByAttribute(n,e.id),a=[],r=0,o=s.length;o>r;r++)i=s[r],i.set(n,null),a.push(i.save());return a},t.bind("destroy",a)},n.prototype.hasOne=function(t,e,n){var i,r,o,s;return null==e&&(e=this.toSnakeCase(this.modelName)),r={},null==n&&(n=e+"_id"),r[n]="integer",t.attributes(r),o={},o[n]=this,t.foreignKeys(o),this.instanceClass.prototype[e]=function(i){var r,o,s,a,l;if(1===arguments.length){for(l=t.findByAttribute(n,this.id),s=0,a=l.length;a>s;s++)r=l[s],r!==i&&(r.set(n,null),r.save());if(null===i)return;return i.set(n,this.id),i.save(),this.trigger("change:"+e),this.trigger("change")}return o=t.findByAttribute(n,this.id),o.length>0?o[0]:null},i=this,s=function(e){var i,r,o,s,a;for(s=t.findByAttribute(n,e.id),a=[],r=0,o=s.length;o>r;r++)i=s[r],i.set(n,null),a.push(i.save());return a},this.bind("destroy",s)},n.prototype.belongsToPoly=function(t,e,i,r){var o,s,a,l,h,u,c,p,f;for(null==e&&(e=this.toSnakeCase(l.modelName)),s={},null==i&&(i=e+"_id"),s[i]="integer",null==r&&(r=e+"_type"),s[r]="string",this[e+"_allowed_models"]=t,this.attributes(s),a={},a[i]=r,this.polyForeignKeys(a),h={},h[e]=function(e,o){var s,a;return arguments.length>0?(null!=e?(_.contains(t,e.modelClass)||d.error("Cannot assign a model of type {{value.modelClass.modelName}} to this belongsToPoly - allowed model types are "+t.join(", ")),this.set(i,e.id),this.set(r,e.modelClass.modelName)):(this[i]=null,this[r]=null),this.save(o)):(s=this[i],a=n.models[this[r]],null==s||null==a?null:a.findById(s))},this.instanceClass.extend(h),o=this,u=function(t,e){var n,s,a,l,h,u;for(null==e&&(e={}),s={},s[i]=t.id,s[r]=t.modelClass.modelName,h=o.findByAttributes(s),u=[],a=0,l=h.length;l>a;a++)n=h[a],n.set(i,null),n.set(r,null),u.push(n.save(e));return u},f=[],c=0,p=t.length;p>c;c++)l=t[c],f.push(l.bind("destroy",u));return f},n.prototype.hasMany=function(t,e,n){var i,r,o,s,a;return null==e&&(e=this.toSnakeCase(t.modelName)),r={},null==n&&(n=this.toSnakeCase(this.modelName+"_id")),r[n]="integer",t.attributes(r),o={},o[n]=this,t.foreignKeys(o),this.relations[e]={type:"hasMany",otherModel:t,foreignKeyAttribute:n},i=this,s={},s[e]=function(){if(arguments.length>0)throw Error("Cannot set a hasMany relation");return null==this[e+"_hasMany_collection"]&&(this[e+"_hasMany_collection"]=u.create({record:this,attribute:this.attribute,model:i,otherModel:t,fkname:n})),this[e+"_hasMany_collection"]},this.instanceClass.extend(s),a=function(e,i){var r,o,s,a,l;for(null==i&&(i={}),a=t.findByAttribute(n,e.id),l=[],o=0,s=a.length;s>o;o++)r=a[o],r.set(n,null),l.push(r.save(i));return l},this.bind("destroy",a)},n.prototype.hasManyPoly=function(t,e,n,i){var r,o,s,a;return null==e&&(e=this.toSnakeCase(t.modelName)),null==n&&(n=e+"_id"),null==i&&(i=e+"_type"),o={},o[n]="integer",o[i]="string",t.attributes(o),s={},s[n]=i,t.polyForeignKeys(s),this.relations[e]={type:"hasManyPoly",otherModel:t,foreignKeyAttribute:n,foreignModelTypeAttribute:i},r=this,this.instanceClass.prototype[e]=function(){if(arguments.length>0)throw Error("Cannot set a hasManyPoly relation");return null==this[e+"_hasManyPoly_collection"]&&(this[e+"_hasManyPoly_collection"]=c.create({record:this,model:r,otherModel:t,thatFkAttr:n,thatTypeAttr:i})),this[e+"_hasManyPoly_collection"]},a=function(e,o){var s,a,l,h,u,c;for(null==o&&(o={}),a={},a[n]=e.id,a[i]=r.modelName,u=t.findByAttributes(a),c=[],l=0,h=u.length;h>l;l++)s=u[l],s.set(n,null),s.set(i,null),c.push(s.save(o));return c},this.bind("destroy",a)},n.prototype.hasManyThrough=function(t,e,n,i,r){var s,a,l,h,u;return null==e&&(e=this.toSnakeCase(t.modelName)),a={},null==i&&(i=this.toSnakeCase(this.modelName+"_id")),null==r&&(r=this.toSnakeCase(t.modelName)+"_id"),a[i]="integer",a[r]="integer",n.attributes(a),l={},l[i]=this,l[r]=t,n.foreignKeys(l),this.relations[e]={type:"hasManyThrough",otherModel:t,linkModel:n,foreignKeyAttribute:i,otherModelForeignKeyAttribute:r},s=this,this.instanceClass.prototype[e]=function(){if(arguments.length>0)throw Error("Cannot set a hasManyThrough relation");return null==this[e+"_hasManyThrough_collection"]&&(this[e+"_hasManyThrough_collection"]=o.create({record:this,model:s,otherModel:t,linkModel:n,thisFkAttr:i,thatFkAttr:r})),this[e+"_hasManyThrough_collection"]},u=function(t,e){var r,o,s,a,l;for(null==e&&(e={}),a=n.findByAttribute(i,t.id),l=[],o=0,s=a.length;s>o;o++)r=a[o],l.push(r.destroy(e));return l},this.bind("destroy",u),h=function(t,e){var i,o,s,a,l;for(null==e&&(e={}),a=n.findByAttribute(r,t.id),l=[],o=0,s=a.length;s>o;o++)i=a[o],l.push(i.destroy(e));return l},t.bind("destroy",h)},n.prototype.hasManyThroughPoly=function(t,e,n,i,r,o){var a,l,h,u,c;return null==e&&(e=this.toSnakeCase(t.modelName)),null==i&&(i=this.toSnakeCase(this.modelName+"_id")),null==r&&(r=e+"_id"),null==o&&(o=e+"_type"),l={},l[i]="integer",l[r]="integer",l[o]="string",n.attributes(l),h={},h[i]=this,n.foreignKeys(h),h={},h[r]=o,n.polyForeignKeys(h),this.relations[e]={type:"hasManyThroughPoly",otherModel:t,linkModel:n,foreignKeyAttribute:i,otherModelForeignKeyAttribute:r,otherModelModelTypeAttribute:o},a=this,this.instanceClass.prototype[e]=function(){if(arguments.length>0)throw Error("Cannot set a hasManyThroughPoly relation");return null==this[e+"_hasManyThroughPoly_collection"]&&(this[e+"_hasManyThroughPoly_collection"]=s.create({record:this,model:a,otherModel:t,linkModel:n,thisFkAttr:i,thatFkAttr:r,thatTypeAttr:o})),this[e+"_hasManyThroughPoly_collection"]},c=function(t,e){var r,o,s,a,l,h;for(null==e&&(e={}),o={},o[i]=t.id,l=n.findByAttributes(o),h=[],s=0,a=l.length;a>s;s++)r=l[s],h.push(r.destroy(e));return h},this.bind("destroy",c),u=function(t,e){var i,s,a,l,h,u;for(null==e&&(e={}),s={},s[r]=t.id,s[o]=t.modelClass.modelName,h=n.findByAttributes(s),u=[],a=0,l=h.length;l>a;a++)i=h[a],u.push(i.destroy(e));return u},t.bind("destroy",u)},n.prototype.hasManyThroughPolyReverse=function(t,e,n,i,r,o){var s;return null==e&&(e=this.toSnakeCase(t.modelName)),null==i&&(i=this.toSnakeCase(this.modelName+"_id")),null==r&&(r=e+"_id"),null==o&&(o=e+"_type"),this.relations[e]={type:"hasManyThroughPolyReverse",otherModel:t,linkModel:n,foreignKeyAttribute:i,otherModelForeignKeyAttribute:r,otherModelModelTypeAttribute:o},(null==n.fks[i]||null==n.polyFks[r]||n.polyFks[r]===(null!=o))&&console.error("WARNING: hasManyThroughPolyReverse - "+i+", "+r+" or "+o+" do not exist on link model '"+n.modelName+"' - there should be an existing hasManyThroughPoly to support this hasManyThroughPolyReverse"),s=this,this.instanceClass.prototype[e]=function(){if(arguments.length>0)throw Error("Cannot set a hasManyThroughPolyReverse relation");return null==this[e+"_hasManyThroughPolyReverse_collection"]&&(this[e+"_hasManyThroughPolyReverse_collection"]=a.create({record:this,model:s,otherModel:t,linkModel:n,thisFkAttr:i,thatFkAttr:r,thatTypeAttr:o})),this[e+"_hasManyThroughPolyReverse_collection"]}},n.prototype.all=function(){return _(this.records).values()},n.prototype.allAsMap=function(){return this.records},n.prototype.count=function(){return _(this.records).keys().length},n.prototype.findById=function(t){return null==t?void 0:this.records[t]},n.prototype.findAll=function(t){var e,n,i,r;for(n=[],i=0,r=t.length;r>i;i++)e=t[i],null!=this.exists(e)&&n.push(this.records[e]);return n},n.prototype.select=function(t){return this.findAll(this.selectIds(t))},n.prototype.selectIds=function(t){var e,n,i,r;i=[],r=this.records;for(e in r)n=r[e],t(n)&&i.push(e);return i},n.prototype.selectAsMap=function(t){var e,n,i,r;i={},r=this.records;for(e in r)n=r[e],t(n)&&(i[e]=n);return i},n.prototype.findByAttribute=function(t,e){var n;return n={},n[t]=e,this.findByAttributes(n)},n.prototype.findByAttributes=function(t){var e,n,i,r,o,s,a,l;s=[];for(e in t)l=t[e],this.hasIndex(e)?s.push(this.getIndexFor(e,l)):s.push(this.selectAsMap(function(t){return t[e]===l}));for(r=s.pop()||{};s.length>0;){a=s.pop(),o={};for(n in a)i=a[n],null!=r[n]&&(o[n]=i);r=o}return _(r).values()},n.prototype.exists=function(t){return null!=this.records[t]},n.prototype.initInstance=function(t){var e,n,i,r;e=this._getInstance(),r=this.attrs;for(n in r)i=r[n],null!=t&&null!=t[n]?e.set(n,t[n]):e.set(n,null);return e.set("id",this._generateId()),e},n.prototype.createFromValues=function(t){var e;return e=this.initInstance(t),e.save(),e},n.prototype.loadInstance=function(t,e){return null==e&&(e={}),this.trigger("load",t)},n.prototype.createInstance=function(t,e){var n;return null==e&&(e={}),n=t.id,this.exists(n)&&d.error("createInstance: ID Already Exists","collection","model",this.name,"id",n),this.records[n]=t,this.addToIndexes(t),e.disableModelCreateEvent||this.trigger("create",t,e),e.disableModelChangeEvent||this.trigger("change",t,e),t},n.prototype.updateInstance=function(t,e){var n;return null==e&&(e={}),e.disableModelUpdateEvent||this.trigger("update",t,e),e.disableModelChangeEvent||this.trigger("change",t,e),n=t.id,this.exists(n)?void 0:d.error("updateInstance: ID does not exist","collection","model",this.name,"id",n)},n.prototype.destroyInstance=function(t,e){var n;return null==e&&(e={}),n=t.id,this.exists(n)||d.error("destroyInstance: ID does not exist","collection","model",this.name,"id",n),delete this.records[t.id],t.modelClass.removeFromIndexes(t),e.disableModelDestroyEvent||this.trigger("destroy",t,e),e.disableModelChangeEvent?void 0:this.trigger("change",t,e)},n.prototype.toSnakeCase=function(t){var e;return e=t.replace(/[A-Z]{1,1}/g,function(t){return"_"+t.toLowerCase()}),e.replace(/^_/,"")},n.prototype._getInstance=function(){return this.instanceClass.create({modelClass:this})},n.prototype._generateId=function(){return"c-"+n.idCount++},n.prototype.index=function(t,n,i){var r;if(null==n&&(n="map"),null==this.indexes[t]){if(r=e.getIndexClassType(n),null!=r)return this.indexes[t]=r.create({modelClass:this,attribute:t,options:i});throw Error("Model: Index Type "+n+" is not supported")}return this.rebuildIndex(t)},n.prototype.hasIndex=function(t){return null!=this.indexes[t]},n.prototype.getIndexFor=function(t,e){if(null==this.indexes[t])throw Error("Model.rebuildIndex: Index "+t+" does not exist");return this.indexes[t].load(e)},n.prototype.updateIndex=function(t,e,n,i){if(null==this.indexes[t])throw Error("Model.rebuildIndex: Index "+t+" does not exist");return this.indexes[t].update(e,n,i)},n.prototype.addToIndexes=function(t){var e,n,i,r;i=this.indexes,r=[];for(e in i)n=i[e],r.push(n.add(t));return r},n.prototype.removeFromIndexes=function(t){var e,n,i,r;i=this.indexes,r=[];for(e in i)n=i[e],r.push(n.remove(t));return r},n.prototype.rebuildIndex=function(t){if(null==this.indexes[t])throw Error("Model.rebuildIndex: Index "+t+" does not exist");return this.indexes[t].rebuild()},n.prototype.dropIndex=function(t){return delete this.indexes[t]},n.prototype.rebuildAllIndexes=function(){var t,e,n,i,r;for(i=_(this.indexes).keys(),r=[],e=0,n=i.length;n>e;e++)t=i[e],r.push(this.rebuildIndex(t));return r},n}(h)}).call(this)}),t.define("/model-localstorage.coffee",function(t){(function(){var e,n,i,r;e=t("./model").Model,n=t("./util"),r={},i={},e.extend({localStorage:function(t){var e,n,o,s,a,l,h,u,c;return null==window.localStorage&&Mozart.error(this.modelName+".localStorage - localStorage not available in this browser"),null==t&&(t={}),null==(l=t.prefix)&&(t.prefix="MozartLS"),this.localStorageOptions=t,this.bind("load",this.loadLocalStorage),this.bind("create",this.createLocalStorage),this.bind("update",this.updateLocalStorage),this.bind("destroy",this.destroyLocalStorage),null==(h=r[s=this.modelName])&&(r[s]={}),null==(u=i[a=this.modelName])&&(i[a]={}),null==(c=Mozart.LocalStorage)&&(Mozart.LocalStorage=Mozart.MztObject.create({handleError:function(t,e,n){return Mozart.LocalStorage.trigger("notFound",t,e,n)}})),o=this.getLocalStoragePrefix(),this.instanceClass.extend({getLocalStorageId:function(){return this.modelClass.getLocalStorageId(this.id)},existsInLocalStorage:function(){var t;return t=this.modelClass.getLocalStorageId(this.id),null!=window.localStorage[this+("-"+t)]},loadLocalStorage:function(){return this.modelClass.loadLocalStorage(this)}}),n=window.localStorage[o+"-nextPK"],null==n&&(window.localStorage[o+"-nextPK"]="1"),e=window.localStorage[o+"-index"],null==e?window.localStorage[o+"-index"]="[]":void 0},getLocalStoragePrefix:function(){return this.localStorageOptions.prefix+"-"+this.modelName},registerLocalStorageId:function(t,e){if(null==r[this.modelName])throw Error("Model.registerLocalStorageId: "+this.modelName+" is not registered for localStorage.");return r[this.modelName][e]=t,i[this.modelName][t]=e},unRegisterLocalStorageId:function(t,e){return delete r[this.modelName][e],delete i[this.modelName][t]},getLocalStorageId:function(t){return i[this.modelName][t]},getLocalStorageClientId:function(t){return r[this.modelName][t]},toLocalStorageObject:function(t){var n,i,r,o,s,a,l,h;r={},a=this.attrs;for(n in a)o=a[n],"id"!==n&&(r[n]=t[n]);r.id=this.getLocalStorageId(t.id),l=this.fks;for(n in l)i=l[n],r[n]=i.getLocalStorageId(t[n]);h=this.polyFks;for(n in h)s=h[n],r[n]=null!=t[s]?e.models[t[s]].getLocalStorageId(t[n]):null;return r},toLocalStorageClientObject:function(t){var n,i,r,o,s,a,l,h;r={},a=this.attrs;for(n in a)o=a[n],"id"!==n&&(r[n]=t[n]);r.id=this.getLocalStorageClientId(t.id),l=this.fks;for(n in l)i=l[n],r[n]=i.getLocalStorageClientId(t[n]),r[n]===void 0&&(r[n]=null);h=this.polyFks;for(n in h)s=h[n],r[n]=null!=t[s]?e.models[t[s]].getLocalStorageClientId(t[n]):null;return r},loadAllLocalStorage:function(){var t,e,i,r,o,s;for(r=this.getLocalStoragePrefix(),e=JSON.parse(window.localStorage[r+"-index"]),o=0,s=e.length;s>o;o++)i=e[o],t=JSON.parse(window.localStorage[r+("-"+i)]),this._processLocalStorageLoad(i,t,this);return this.trigger("loadAllLocalStorageComplete"),n.log("localStorage","Model.loadAllLocalStorage.onComplete")},loadLocalStorage:function(t){var e;return e=t.modelClass.getLocalStorageId(t.id),this.loadLocalStorageId(e)},loadLocalStorageId:function(t){var e,n;return n=this.getLocalStoragePrefix(),e=window.localStorage[n+("-"+t)],null==e&&Mozart.LocalStorage.handleError(this,t,"record does not exist"),e=JSON.parse(e),e.id=t,this._processLocalStorageLoad(t,e,this)},_processLocalStorageLoad:function(t,e,i){var r,o,s;return r=i.getLocalStorageClientId(t),o=i.toLocalStorageClientObject(e),null!=r?(s=i.findById(r),s.copyFrom(o)):s=i.initInstance(e),s.save({disableModelCreateEvent:!0,disableModelUpdateEvent:!0}),i.registerLocalStorageId(s.id,t),n.log("localStorage","Model._processLocalStorageLoad.onSuccess",e,i),i.trigger("loadLocalStorageComplete",s)},createLocalStorage:function(t){var e,i,r,o;return e=t.modelClass.toLocalStorageObject(t),o=t.modelClass.getLocalStoragePrefix(),r=parseInt(window.localStorage[o+"-nextPK"]),window.localStorage[o+"-nextPK"]=""+(r+1),window.localStorage[o+("-"+r)]=JSON.stringify(e),t.modelClass.registerLocalStorageId(t.id,r),i=JSON.parse(window.localStorage[o+"-index"]),i.push(r),window.localStorage[o+"-index"]=JSON.stringify(i),n.log("localStorage","Model.createLocalStorageComplete",t),t.modelClass.trigger("createLocalStorageComplete",t)},updateLocalStorage:function(t){var e,i,r;return i=t.modelClass.getLocalStorageId(t.id),null!=i?(e=t.modelClass.toLocalStorageObject(t),r=t.modelClass.getLocalStoragePrefix(),null==window.localStorage[r+("-"+i)]&&Mozart.LocalStorage.handleError(t.modelClass,i,"updateLocalStorage: record does not exist"),window.localStorage[r+("-"+i)]=JSON.stringify(e),t.modelClass.trigger("updateLocalStorageComplete",t),n.log("localStorage","Model.updateLocalStorage.onComplete",t)):void 0},destroyLocalStorage:function(t){var e,i,r;return i=t.modelClass.getLocalStorageId(t.id),null!=i?(r=t.modelClass.getLocalStoragePrefix(),null==window.localStorage[r+("-"+i)]&&Mozart.LocalStorage.handleError(t.modelClass,i,"destroyLocalStorage: record does not exist"),window.localStorage.removeItem(r+("-"+i)),t.modelClass.unRegisterLocalStorageId(t.id,i),e=JSON.parse(window.localStorage[r+"-index"]),e=_.without(e,i),window.localStorage[r+"-index"]=JSON.stringify(e),n.log("localStorage","Model.destroyLocalStorage.onSuccess",t),t.modelClass.trigger("destroyLocalStorageComplete",i)):void 0},destroyAllLocalStorage:function(){var t,e,n,o,s;for(n=this.getLocalStoragePrefix(),e=JSON.parse(window.localStorage[n+"-index"]),o=0,s=e.length;s>o;o++)t=e[o],window.localStorage.removeItem(n+("-"+t));return window.localStorage[n+"-index"]="[]",window.localStorage[n+"-nextPK"]="1",r[this.modelName]={},i[this.modelName]={}}})}).call(this)}),t.define("/route.coffee",function(t,e,n){(function(){var e,i,r,o=function(t,e){return function(){return t.apply(e,arguments)}},s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var i in e)s.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};r=t("./util"),e=t("./object").MztObject,n.Route=i=function(t){function e(){return this.doTitle=o(this.doTitle,this),this.canEnter=o(this.canEnter,this),this.canExit=o(this.canExit,this),e.__super__.constructor.apply(this,arguments)}return a(e,t),e.prototype.init=function(){return null!=this.path&&this.path.length>0||r.warn("Route must have a path",this),null==this.viewClass?r.warn("Route must have a viewClass",this):void 0},e.prototype.canExit=function(){return!(null!=this.exit)||this.exit()===!0},e.prototype.canEnter=function(t){return!(null!=this.enter)||this.enter(t)===!0},e.prototype.doTitle=function(){return null!=this.title?document.title="function"==typeof this.title?this.title(this):this.title:void 0},e}(e)}).call(this)}),t.define("/switch-view.coffee",function(t,e,n){(function(){var e,i,r=function(t,e){return function(){return t.apply(e,arguments)}},o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var i in e)o.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};i=t("./view").View,n.SwitchView=e=function(t){function e(){return this.beforeRender=r(this.beforeRender,this),e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.beforeRender=function(){var t;return t=HandlebarsTemplates[this.templateBase+"/"+this.content[this.templateField]],null!=t?this.templateFunction=t:(Util.log("views","SwitchView: No view found for "+this.templateBase+"/"+this.content[this.templateField]),this.templateFunction=function(){return""})},e}(i)}).call(this)}),t.define("/dynamic-view.coffee",function(t,e,n){(function(){var e,i,r,o=function(t,e){return function(){return t.apply(e,arguments)}},s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var i in e)s.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};r=t("./view").View,i=t("./util"),n.DynamicView=e=function(t){function e(){return this.createText=o(this.createText,this),this.createView=o(this.createView,this),this.afterRender=o(this.afterRender,this),this.init=o(this.init,this),e.__super__.constructor.apply(this,arguments)}return a(e,t),e.prototype.skipTemplate=!0,e.prototype.init=function(){return e.__super__.init.apply(this,arguments),i.log("dynamicview","init"),null!=this.schema?this.bind("change:schema",this.afterRender):void 0},e.prototype.afterRender=function(){var t,e,n,r,o;if(this.releaseChildren(),this.element.empty(),!i.isArray(this.schema))return i.warn("DynamicView "+id+": schema is not an array"),void 0;for(r=this.schema,o=[],e=0,n=r.length;n>e;e++)t=r[e],null!=t.viewClass?o.push(this.createView(t)):o.push(this.createText(t));return o},e.prototype.createView=function(t){var e,n;return n=i._getPath(t.viewClass),delete t.viewClass,t.parent=this,e=this.layout.createView(n,t),this.element.append(e.createElement()),this.addView(e),this.layout.queueRenderView(e)},e.prototype.createText=function(t){return this.element.append(t)},e}(r)}).call(this)}),t.define("/cookies.coffee",function(t,e,n){(function(){var e,i,r={}.hasOwnProperty,o=function(t,e){function n(){this.constructor=t}for(var i in e)r.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};i=t("./object").MztObject,n.Cookies=e=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return o(e,t),e.setCookie=function(t,e,n){var i,r,o,s,a,l;return n=n||{},void 0!==document.cookie&&(n.path||(n.path="/"),s=""+encodeURIComponent(t)+"="+encodeURIComponent(e),a=n.path?";path="+n.path:"",i=n.domain?";domain="+n.domain:"",o=n["max-age"]?";max-age="+n["max-age"]:"",r="",n.expires instanceof Date&&(r=";expires="+n.expires.toUTCString()),l=n.secure?";secure":"",document.cookie=s+a+i+o+r+l),this},e.getCookie=function(t){var e,n,i,r,o,s;for(n=document.cookie.split(/;\s*/),o=0,s=n.length;s>o;o++)if(e=n[o],r=e.split("="),i=decodeURIComponent(r[0]),i===t)return decodeURIComponent(r[1]);return null},e.removeCookie=function(t){var e;return e=new Date,e.setTime(e.getTime()-1),this.setCookie(t,"",{expires:e}),this},e.hasCookie=function(t){return null!==this.getCookie(t)},e}(i)}).call(this)}),t.define("/mozart.coffee",function(t,e,n,i,r,o,s){(function(){var e,n,i,r,o,a,l,h,u={}.hasOwnProperty;for(e={version:"0.1.9",versionDate:new Date(2013,7,1),Plugins:{}},l=[t("./collection"),t("./control"),t("./controller"),t("./data-index"),t("./dom-manager"),t("./events"),t("./handlebars"),t("./http"),t("./layout"),t("./model-instance"),t("./model-instancecollection"),t("./model-onetomanycollection"),t("./model-onetomanypolycollection"),t("./model-manytomanycollection"),t("./model-manytomanypolycollection"),t("./model-manytomanypolyreversecollection"),t("./model-ajax"),t("./model-localstorage"),t("./model"),t("./object"),t("./route"),t("./router"),t("./switch-view"),t("./util"),t("./view"),t("./dynamic-view"),t("./cookies")],o=0,a=l.length;a>o;o++){i=l[o];
5
- for(r in i)u.call(i,r)&&(n=i[r],e[r]=n)}null!=s.module?i.exports=e:null!=(null!=(h=s.define)?h.amd:void 0)?define("mozart",e):s.Mozart=e}).call(this)}),t("/mozart.coffee")})();
1
+ (function(){var t=function(e,n){var r=t.resolve(e,n||"/"),i=t.modules[r];if(!i)throw Error("Failed to resolve module "+e+", tried "+r);var o=t.cache[r],s=o?o.exports:i();return s};t.paths=[],t.modules={},t.cache={},t.extensions=[".js",".coffee",".json"],t._core={assert:!0,events:!0,fs:!0,path:!0,vm:!0},t.resolve=function(){return function(e,n){function r(e){if(e=a.normalize(e),t.modules[e])return e;for(var n=0;t.extensions.length>n;n++){var r=t.extensions[n];if(t.modules[e+r])return e+r}}function i(e){e=e.replace(/\/+$/,"");var n=a.normalize(e+"/package.json");if(t.modules[n]){var i=t.modules[n](),o=i.browserify;if("object"==typeof o&&o.main){var s=r(a.resolve(e,o.main));if(s)return s}else if("string"==typeof o){var s=r(a.resolve(e,o));if(s)return s}else if(i.main){var s=r(a.resolve(e,i.main));if(s)return s}}return r(e+"/index")}function o(t,e){for(var n=s(e),o=0;n.length>o;o++){var a=n[o],l=r(a+"/"+t);if(l)return l;var h=i(a+"/"+t);if(h)return h}var l=r(t);return l?l:void 0}function s(t){var e;e="/"===t?[""]:a.normalize(t).split("/");for(var n=[],r=e.length-1;r>=0;r--)if("node_modules"!==e[r]){var i=e.slice(0,r+1).join("/")+"/node_modules";n.push(i)}return n}if(n||(n="/"),t._core[e])return e;var a=t.modules.path();n=a.resolve("/",n);var l=n||"/";if(e.match(/^(?:\.\.?\/|\/)/)){var h=r(a.resolve(l,e))||i(a.resolve(l,e));if(h)return h}var u=o(e,l);if(u)return u;throw Error("Cannot find module '"+e+"'")}}(),t.alias=function(e,n){var r=t.modules.path(),i=null;try{i=t.resolve(e+"/package.json","/")}catch(o){i=t.resolve(e,"/")}for(var s=r.dirname(i),a=(Object.keys||function(t){var e=[];for(var n in t)e.push(n);return e})(t.modules),l=0;a.length>l;l++){var h=a[l];if(h.slice(0,s.length+1)===s+"/"){var u=h.slice(s.length);t.modules[n+u]=t.modules[s+u]}else h===s&&(t.modules[n]=t.modules[s])}},function(){var e={},n="undefined"!=typeof window?window:{},r=!1;t.define=function(i,o){!r&&t.modules.__browserify_process&&(e=t.modules.__browserify_process(),r=!0);var s=t._core[i]?"":t.modules.path().dirname(i),a=function(e){var n=t(e,s),r=t.cache[t.resolve(e,s)];return r&&null===r.parent&&(r.parent=l),n};a.resolve=function(e){return t.resolve(e,s)},a.modules=t.modules,a.define=t.define,a.cache=t.cache;var l={id:i,filename:i,exports:{},loaded:!1,parent:null};t.modules[i]=function(){return t.cache[i]=l,o.call(l.exports,a,l,l.exports,s,i,e,n),l.loaded=!0,l.exports}}}(),t.define("path",function(t,e,n,r,i,o){function s(t,e){for(var n=[],r=0;t.length>r;r++)e(t[r],r,t)&&n.push(t[r]);return n}function a(t,e){for(var n=0,r=t.length;r>=0;r--){var i=t[r];"."==i?t.splice(r,1):".."===i?(t.splice(r,1),n++):n&&(t.splice(r,1),n--)}if(e)for(;n--;n)t.unshift("..");return t}var l=/^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;n.resolve=function(){for(var t="",e=!1,n=arguments.length;n>=-1&&!e;n--){var r=n>=0?arguments[n]:o.cwd();"string"==typeof r&&r&&(t=r+"/"+t,e="/"===r.charAt(0))}return t=a(s(t.split("/"),function(t){return!!t}),!e).join("/"),(e?"/":"")+t||"."},n.normalize=function(t){var e="/"===t.charAt(0),n="/"===t.slice(-1);return t=a(s(t.split("/"),function(t){return!!t}),!e).join("/"),t||e||(t="."),t&&n&&(t+="/"),(e?"/":"")+t},n.join=function(){var t=Array.prototype.slice.call(arguments,0);return n.normalize(s(t,function(t){return t&&"string"==typeof t}).join("/"))},n.dirname=function(t){var e=l.exec(t)[1]||"",n=!1;return e?1===e.length||n&&3>=e.length&&":"===e.charAt(1)?e:e.substring(0,e.length-1):"."},n.basename=function(t,e){var n=l.exec(t)[2]||"";return e&&n.substr(-1*e.length)===e&&(n=n.substr(0,n.length-e.length)),n},n.extname=function(t){return l.exec(t)[3]||""}}),t.define("__browserify_process",function(t,e,n,r,i,o){var o=e.exports={};o.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(e){var n=[];return window.addEventListener("message",function(t){if(t.source===window&&"browserify-tick"===t.data&&(t.stopPropagation(),n.length>0)){var e=n.shift();e()}},!0),function(t){n.push(t),window.postMessage("browserify-tick","*")}}return function(t){setTimeout(t,0)}}(),o.title="browser",o.browser=!0,o.env={},o.argv=[],o.binding=function(e){if("evals"===e)return t("vm");throw Error("No such module. (Possibly not yet loaded)")},function(){var e,n="/";o.cwd=function(){return n},o.chdir=function(r){e||(e=t("path")),n=e.resolve(r,n)}}()}),t.define("/collection.coffee",function(t,e,n){(function(){var e,r,i,o,s=function(t,e){return function(){return t.apply(e,arguments)}},a={}.hasOwnProperty,l=function(t,e){function n(){this.constructor=t}for(var r in e)a.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};o=t("./view").View,i=t("./util"),n.Collection=r=function(t){function e(){return this.draw=s(this.draw,this),this.createView=s(this.createView,this),this.refresh=s(this.refresh,this),this.afterRender=s(this.afterRender,this),this.release=s(this.release,this),this.init=s(this.init,this),e.__super__.constructor.apply(this,arguments)}return l(e,t),e.prototype.tag="ul",e.prototype.skipTemplate=!0,e.prototype.init=function(){var t,n;return e.__super__.init.apply(this,arguments),i.log("collection","init"),this.itemViews={},this.localMozartModel=i._getPath("Mozart.Model"),this.localMozartInstanceCollection=i._getPath("Mozart.InstanceCollection"),null!=this.filterAttribute&&(this.bind("change:filterAttribute",this.draw),this.bind("change:filterText",this.draw)),null!=this.sortAttribute&&(this.bind("change:sortAttribute",this.draw),this.bind("change:sortDescending",this.draw)),null==this.pageSize&&this.set("pageSize",1e4),null==this.pageCurrent&&this.set("pageCurrent",0),this.bind("change:pageSize",this.draw),this.bind("change:pageCurrent",this.draw),null==(n=this.method)&&(this.method="all"),this.bind("change:collection",this.afterRender),this.bind("change:method",this.afterRender),"function"==typeof(t=this.collection).bind?t.bind("change",this.afterRender):void 0},e.prototype.release=function(){var t;return"function"==typeof(t=this.collection).unbind&&t.unbind("change",this.afterRender),e.__super__.release.apply(this,arguments)},e.prototype.afterRender=function(){return this.refresh(),this.draw()},e.prototype.refresh=function(){var t,e,n,r,o,s,a,l,h,u,c,d,p,f,g,y;if(i.log("collection","refresh"),this.dataSet={},null!=this.collection)if(i.isObject(this.collection)){if(i.isFunction(this.collection[this.method+"AsMap"]))this.dataSet=this.collection[this.method+"AsMap"]();else if(i.isFunction(this.collection[this.method]))for(c=this.collecton[this.method](),o=0,l=c.length;l>o;o++)e=c[o],this.dataSet[e.id]=e}else if(i.isFunction(this.collection))for(d=this.collection(),s=0,h=d.length;h>s;s++)e=d[s],this.dataSet[e.id]=e;else if(i.isArray(this.collection))for(p=this.collection,a=0,u=p.length;u>a;a++)e=p[a],this.dataSet[e.id]=e;else console.error("Collection: "+typeof this.collection+" can't be iterated");n=[],f=this.itemViews;for(t in f)r=f[t],null==this.dataSet[t]&&n.push(t);for(y=[];n.length>0;)t=n.pop(),i.log("collection","destroyView",t,this.itemViews[t]),this.removeView(this.itemViews[t]),null!=(g=this.itemViews[t].element)&&g.remove(),this.layout.queueReleaseView(this.itemViews[t]),y.push(delete this.itemViews[t]);return y},e.prototype.createView=function(t){var e,n;return i.log("collection","createView",t,"layout",this.layout.rootElement),e={content:t,parent:this},this.viewClass===o&&(e.tag="li"),null!=this.viewClassTemplateName&&(e.templateName=this.viewClassTemplateName),null!=this.viewClassTemplateFunction&&(e.templateFunction=this.viewClassTemplateFunction),null!=this.collectionTag&&(e.tag=this.collectionTag),null!=this.collectionClassNames&&(e.classNames=this.collectionClassNames),null!=this.tooltips&&(e.tooltips=this.tooltips),n=this.layout.createView(this.viewClass,e),this.element.append(n.createElement()),this.itemViews[t.id]=n,this.addView(n),this.layout.queueRenderView(n)},e.prototype.draw=function(){var t,e,n,r,o,s,a,l,h,u,c,d,p,f,g,y,m,v,w,b,C,M;v=this.itemViews;for(o in v)u=v[o],null!=(w=u.element)&&w.detach();if(this.displayOrder=_(this.dataSet).values(),this.hidden={},null!=this.sortAttribute&&i.sortBy(this.displayOrder,this.sortAttribute),this.sortDescending&&this.displayOrder.reverse(),null!=this.filterText&&null!=this.filterAttribute&&this.filterText.length>0)for(a=(""+this.filterText).toLowerCase(),b=this.displayOrder,d=0,g=b.length;g>d;d++)for(s=b[d],r=!0,C=this.filterAttribute.split(","),p=0,y=C.length;y>p;p++)n=C[p],c=i.getPath(s,n),null!=c&&(r=r&&-1===(""+c).toLowerCase().indexOf(a)),r&&(this.hidden[s.id]=1);for(l=this.pageCurrent*this.pageSize,t=0,h=0,e=0,M=this.displayOrder,f=0,m=M.length;m>f;f++)s=M[f],null==this.hidden[s.id]&&(l>t||e>=this.pageSize||(null==this.itemViews[s.id]&&this.createView(s),this.element.append(this.itemViews[s.id].element),e++),h++),t++;return this.set("pageTotal",Math.ceil(h/this.pageSize)),this.pageCurrent>this.pageTotal?this.set("pageCurrent",this.pageTotal-1):void 0},e}(o),n.BoundView=e=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return l(e,t),e.prototype.init=function(){return e.__super__.init.apply(this,arguments),this.content.bind("change",this.redraw)},e.prototype.release=function(){return this.content.unbind("change",this.redraw),e.__super__.release.apply(this,arguments)},e}(o)}).call(this)}),t.define("/view.coffee",function(t,e,n){(function(){var e,r,i,o=function(t,e){return function(){return t.apply(e,arguments)}},s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var r in e)s.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=t("./object").MztObject,r=t("./util"),n.View=i=function(t){function e(){return this.copyHtmlAttrsToElement=o(this.copyHtmlAttrsToElement,this),this.getHtmlAttrsMap=o(this.getHtmlAttrsMap,this),this.createElement=o(this.createElement,this),this.release=o(this.release,this),this.hasAncestor=o(this.hasAncestor,this),this.removeView=o(this.removeView,this),this.namedChildViewExists=o(this.namedChildViewExists,this),this.childView=o(this.childView,this),this.addView=o(this.addView,this),this.redraw=o(this.redraw,this),this.postRender=o(this.postRender,this),this.replaceElement=o(this.replaceElement,this),this.findElementInPreparedContent=o(this.findElementInPreparedContent,this),this.reassignElements=o(this.reassignElements,this),this.prepareElement=o(this.prepareElement,this),this.init=o(this.init,this),e.__super__.constructor.apply(this,arguments)}return a(e,t),e.prototype.tag="div",e.prototype.disableHtmlAttributes=!1,e.prototype.idPrefix="view",e.prototype.init=function(){var t,e,n;return null==(t=this.id)&&(this.id=""+this.idPrefix+"-"+this._mozartId),this.childViews={},null==(e=this.context)&&(this.context={}),this.namedChildViews={},this.valid=!0,this.domBindings={},null==(n=this.display)&&(this.display=!0),null!=this.parent&&this.parent.addView(this),null==this.templateFunction&&null==this.skipTemplate&&(null==this.templateName&&r.error("View: View has no templateName or templateFunction","view",this),this.templateFunction=HandlebarsTemplates[this.templateName]),r.log("views","view "+this.id+" init"),this.bind("change:display",this.redraw)},e.prototype.prepareElement=function(){return this.released?void 0:(this.newElement=this.createElement(),!this.skipTemplate&&this.display?this.newElement.innerHTML=this.templateFunction(this,{data:this}):void 0)},e.prototype.reassignElements=function(){var t,e,n;n=this.childViews;for(t in n)e=n[t],e.reassignElements();return null!=this.parent?this.el=this.parent.findElementInPreparedContent(this.id):void 0},e.prototype.findElementInPreparedContent=function(t){var e;return this.newElement?e=this._find(this.newElement,t):null},e.prototype._find=function(t,e){var n,r,i,o,s;if(t.id===e)return t;for(s=t.children,i=0,o=s.length;o>i;i++)if(n=s[i],r=this._find(n,e),null!=r)return r;return null},e.prototype.replaceElement=function(){var t,e,n;if(!this.released&&this.el){n=this.childViews;for(t in n)e=n[t],e.replaceElement();return this.el!==this.newElement&&(this.oldEl=this.el,this.el.parentNode.replaceChild(this.newElement,this.el),null!=this.layout&&this.el===this.layout.rootEl&&(this.layout.rootEl=this.newElement),this.el=this.newElement,delete this.oldEl),this.element=$(this.el)}},e.prototype.beforeRender=function(){},e.prototype.afterRender=function(){},e.prototype.postRender=function(){return this.released?void 0:(this.createDomBinds(),this.afterRender())},e.prototype.redraw=function(){return this.released?void 0:this.layout.queueRenderView(this)},e.prototype.addView=function(t){return this.childViews[t.id]=t,null!=t.name?this.namedChildViews[t.name]=t:void 0},e.prototype.childView=function(t){return this.namedChildViews[t]},e.prototype.namedChildViewExists=function(t){return null!=this.namedChildViews[t]},e.prototype.releaseChildren=function(){var t,e,n;n=this.childViews;for(t in n)e=n[t],this.layout.queueReleaseView(e);return this.childViews={},this.namedChildViews={}},e.prototype.removeView=function(t){return null!=this.childViews?delete this.childViews[t.id]:void 0},e.prototype.hasAncestor=function(t){var e;for(e=this.parent;null!=e;){if(e.id===t.id)return!0;e=e.parent}return!1},e.prototype.release=function(){return this.released?void 0:(r.log("views",this.layout,"releasing view "+this.id),this.removeDomBinds(),this.unbind(),null!=this.parent&&this.parent.removeView(this),this.releaseChildren(),null!=this.element&&this.element.remove(),this.layout.releaseView(this),e.__super__.release.apply(this,arguments))},e.prototype.createElement=function(){var t,e,n,r;if(this.display===!1)return t=document.createElement("script"),t.setAttribute("id",this.id),t;if(t=document.createElement(this.tag),t.setAttribute("id",this.id),t.setAttribute("view",""),!this.disableHtmlAttributes){r=this.getHtmlAttrsMap();for(e in r)n=r[e],t.setAttribute(e,n)}return t},e.prototype.getHtmlAttrsMap=function(){var t,e,n;e={};for(t in this)n=this[t],"string"==typeof this[t]&&r.stringEndsWith(t,"Html")&&(e[r.sliceStringBefore(t,"Html")]=n);return e},e.prototype.copyHtmlAttrsToElement=function(t){return t.attr(this.getHtmlAttrsMap()),t},e.prototype.registerDomBind=function(t,e){var n,i,o,s;return s=r.parsePath(e),o=s[0],n=s[1],i=null!=o?r.getPath(this,o):this,null==i&&r.error("View.registerDomBind (bind helper) - cannot find object "+o),this.domBindings[t]={view:this,target:i,attribute:n,element:null}},e.prototype.createDomBinds=function(){var t,e,n,i;n=this.domBindings,i=[];for(t in n)e=n[t],e.element=$("#"+t),null==e.element&&r.error("View.createDomBinds - cannot find element "+t),e.target.bind("change:"+e.attribute,this.onDomBindChange,e),i.push(e.element.text(e.target[e.attribute]));return i},e.prototype.onDomBindChange=function(t,e){return e.element.text(e.target[e.attribute])},e.prototype.removeDomBinds=function(){var t,e,n;n=this.domBindings;for(t in n)e=n[t],true===e.element&&e.target.unbind("change:"+e.attribute,this.onDomBindChange);return this.domBindings={}},e}(e)}).call(this)}),t.define("/object.coffee",function(t,e,n){(function(){var e,r,i,o=[].indexOf||function(t){for(var e=0,n=this.length;n>e;e++)if(e in this&&this[e]===t)return e;return-1},s=[].slice,a={}.hasOwnProperty;i=t("./util"),e=t("./events").Events,n.MztObject=r=function(){function t(){this._mozartId=i.getId()}var n;return n=["extended","included"],t.NOTIFY=2,t.OBSERVE=1,t.SYNC=0,t.include=function(t){var e,r,i;for(e in t)r=t[e],0>o.call(n,e)&&(this[e]=r);return null!=(i=t.extended)&&i.apply(this),this},t.extend=function(t){var e,r,i;for(e in t)r=t[e],0>o.call(n,e)&&(this.prototype[e]=r);return null!=(i=t.included)&&i.apply(this),this},t.create=function(t){var e,n,r;e=new this;for(n in t)r=t[n],e[n]=r;return e._bindings={},e._bindings.notify={},e._bindings.observe={},e._bindings.stored={},e._createDeclaredBinds(),e._createLookups(),"function"==typeof e.init&&e.init(),e},t.prototype.toString=function(){return"obj-"+this._mozartId},t.prototype.get=function(t){return i.isFunction(this[t])?this[t].call(this):this[t]},t.prototype.set=function(t,e){var n,r,i,o,s,a,l;if(o=this[t],o!==e){if(o instanceof Mozart.MztObject&&(this._bindings.stored[t]={notify:o._stripNotifyBindings(!0),observe:o._stripObserveBindings(!0)},this._bindings.stored[t].notify==={}&&this._bindings.stored[t].observe==={}&&delete this._bindings.stored[t]),null!=this._bindings.stored[t]&&null!=this._bindings.stored[t].notify&&null===e){l=this._bindings.stored[t].notify;for(i in l)for(r=l[i],s=0,a=r.length;a>s;s++)n=r[s],n.target.set(n.attr,null)}return e instanceof Mozart.MztObject&&null!=this._bindings.stored[t]&&(this._bindings.stored[t].notify!=={}&&e._addNotifyBindings(this._bindings.stored[t].notify),this._bindings.stored[t].observe!=={}&&e._addObserveBindings(this._bindings.stored[t].observe),delete this._bindings.stored[t]),this[t]=e,this._doNotifyBinding(t),this.trigger("change"),this.trigger("change:"+t)}},t.prototype.bind=function(){var t;return t=arguments.length>=1?s.call(arguments,0):[],e.bind.apply(e,[this._mozartId].concat(s.call(t))),this},t.prototype.one=function(){var t;return t=arguments.length>=1?s.call(arguments,0):[],e.one.apply(e,[this._mozartId].concat(s.call(t))),this},t.prototype.trigger=function(){var t;return t=arguments.length>=1?s.call(arguments,0):[],e.trigger.apply(e,[this._mozartId].concat(s.call(t))),this},t.prototype.unbind=function(){var t;return t=arguments.length>=1?s.call(arguments,0):[],e.unbind.apply(e,[this._mozartId].concat(s.call(t))),this},t.prototype.release=function(){var t,e;if(!this.released){this._removeAllBindings(),this.unbind();for(t in this)a.call(this,t)&&(e=this[t],this[t]=void 0,delete this[t]);return this.released=!0}},t.prototype._stripNotifyBindings=function(e){var n,r,i,o,s,a,l;null==e&&(e=!1),r={},l=this._bindings.notify;for(o in l)for(i=l[o],r[o]=[],s=0,a=i.length;a>s;s++)n=i[s],(!e||n.transferable)&&(r[o].push(n),this._removeBinding(o,n.target,n.attr,t.NOTIFY));return r},t.prototype._addNotifyBindings=function(e){var n,r,i,o;o=[];for(i in e)r=e[i],o.push(function(){var e,o,s;for(s=[],e=0,o=r.length;o>e;e++)n=r[e],s.push(this._createBinding(i,n.target,n.attr,t.NOTIFY,n.transferable));return s}.call(this));return o},t.prototype._stripObserveBindings=function(e){var n,r,i,o,s,a,l;null==e&&(e=!1),r={},l=this._bindings.observe;for(o in l)for(i=l[o],r[o]=[],s=0,a=i.length;a>s;s++)n=i[s],(!e||n.transferable)&&(r[o].push(n),this._removeBinding(o,n.target,n.attr,t.OBSERVE));return r},t.prototype._addObserveBindings=function(e){var n,r,i,o;o=[];for(i in e)r=e[i],o.push(function(){var e,o,s;for(s=[],e=0,o=r.length;o>e;e++)n=r[e],s.push(this._createBinding(i,n.target,n.attr,t.OBSERVE,n.transferable));return s}.call(this));return o},t.prototype._createDeclaredBinds=function(){var e,n,r,o,s,a,l,h;h=[];for(n in this)a=this[n],!i.isFunction(this[n])&&i.stringEndsWith(n,"Binding")&&(n=i.sliceStringBefore(n,"Binding"),s=t.SYNC,i.stringEndsWith(n,"Observe")?(n=i.sliceStringBefore(n,"Observe"),s=t.OBSERVE):i.stringEndsWith(n,"Notify")&&(n=i.sliceStringBefore(n,"Notify"),s=t.NOTIFY),l=i.parsePath(a),o=l[0],e=l[1],r=null!=o?i._getPath(this,o):this,h.push(this._createBinding(n,r,e,s,i.isAbsolutePath(a))));return h},t.prototype._hasNotifyBinding=function(t,e,n){var r,i,o,s;if(null==this._bindings.notify[t])return!1;for(s=this._bindings.notify[t],i=0,o=s.length;o>i;i++)if(r=s[i],r.attr===n&&r.target._mozartId===e._mozartId)return!0;return!1},t.prototype._hasObserveBinding=function(t,e,n){var r,i,o,s;if(null==this._bindings.observe[t])return!1;for(s=this._bindings.observe[t],i=0,o=s.length;o>i;i++)if(r=s[i],r.attr===n&&r.target._mozartId===e._mozartId)return!0;return!1},t.prototype._createBinding=function(e,n,r,o,s){var a,l,h,u;switch(o){case t.NOTIFY:if(this._hasNotifyBinding(e,n,r,o))return;return null==(h=(a=this._bindings.notify)[e])&&(a[e]=[]),this._bindings.notify[e].push({attr:r,target:n,transferable:s}),n instanceof t&&n._createBinding(r,this,e,t.OBSERVE,s),this._doNotifyBinding(e);case t.OBSERVE:if(this._hasObserveBinding(e,n,r,o))return;return n instanceof t?(null==(u=(l=this._bindings.observe)[e])&&(l[e]=[]),this._bindings.observe[e].push({attr:r,target:n,transferable:s}),n._createBinding(r,this,e,t.NOTIFY,s)):(i.warn("Binding "+e+"ObserveBinding on",this,": target",n,"is not a MztObject"),void 0);case t.SYNC:return this._createBinding(e,n,r,t.OBSERVE,s),this._createBinding(e,n,r,t.NOTIFY,s)}},t.prototype._removeBinding=function(e,n,r,i){var o,s,a,l,h,u,c,d;switch(i){case t.NOTIFY:if(!this._hasNotifyBinding(e,n,r))return;for(s=[],c=this._bindings.notify[e],a=0,h=c.length;h>a;a++)o=c[a],(o.attr!==r||o.target._mozartId!==n._mozartId)&&s.push(o);if(0!==s.length?this._bindings.notify[e]=s:delete this._bindings.notify[e],n instanceof t)return n._removeBinding(r,this,e,t.OBSERVE);break;case t.OBSERVE:if(!this._hasObserveBinding(e,n,r))return;for(s=[],d=this._bindings.observe[e],l=0,u=d.length;u>l;l++)o=d[l],(o.attr!==r||o.target._mozartId!==n._mozartId)&&s.push(o);if(0!==s.length?this._bindings.observe[e]=s:delete this._bindings.observe[e],n instanceof t)return n._removeBinding(r,this,e,t.NOTIFY);break;case t.SYNC:return this._removeBinding(e,n,r,t.NOTIFY),this._removeBinding(e,n,r,t.OBSERVE)}},t.prototype._removeAllBindings=function(){return this._stripObserveBindings(!1),this._stripNotifyBindings(!1)},t.prototype._doNotifyBinding=function(t){var e,n,r,o,s;if(n=this._bindings.notify[t],null!=n){for(s=[],r=0,o=n.length;o>r;r++)e=n[r],null!=e?i.isFunction(e.target.set)?s.push(e.target.set(e.attr,this.get(t))):s.push(e.target[e.attr]=this.get(t)):s.push(void 0);return s}},t.prototype._createLookups=function(){var t,e,n;n=[];for(t in this)e=this[t],!i.isFunction(this[t])&&i.stringEndsWith(t,"Lookup")&&(t=i.sliceStringBefore(t,"Lookup"),n.push(this[t]=i._getPath(e)));return n},t}()}).call(this)}),t.define("/util.coffee",function(t,e){(function(){var t,n,r,i=[].slice,o={}.hasOwnProperty;r={},n=0,t=e.exports={toString:Object.prototype.toString,getType:function(t){return this.toString.call(t).match(/^\[object\s(.*)\]$/)[1]},isObject:function(t){return"Object"===this.getType(t)},isFunction:function(t){return"Function"===this.getType(t)},isArray:function(t){return"Array"===this.getType(t)},isString:function(t){return"String"===this.getType(t)},isBoolean:function(t){return"Boolean"===this.getType(t)},log:function(){var t,e;return e=arguments[0],t=arguments.length>=2?i.call(arguments,1):[],null!=r[e]&&"undefined"!=typeof console&&null!==console?console.log.apply(console,[e+":"].concat(i.call(t))):void 0},showLog:function(t){return r[t]=!0},hideLog:function(t){return r[t]=!1},error:function(){var t,e;throw e=arguments[0],t=arguments.length>=2?i.call(arguments,1):[],"undefined"!=typeof console&&null!==console&&console.error("Exception:",e,t),e},warn:function(){var t,e;return e=arguments[0],t=arguments.length>=2?i.call(arguments,1):[],"undefined"!=typeof console&&null!==console?console.log("Warning:",e,t):void 0},clone:function(t){return $.extend({},t)},getPath:function(t,e){var n;if(n=this._getPath(t,e),void 0===n)throw Error("Object "+t+" has no "+e);return n},isAbsolutePath:function(t){return t[0].toUpperCase()===t[0]},_getPath:function(e,n){var r,i,o;for(null!=e&&null==n&&(n=e,e=Mozart.root),t.isAbsolutePath(n)&&(e=Mozart.root),r=n.split(".");r.length>0;){if(i=r.shift(),"this"!==i){if(void 0===e[i])return void 0;if(o=t.isFunction(e.get)?e.get.call(e,i):e[i],null===o&&r.length>0)return void 0}else o=e;e=o}return o},getId:function(){return++n},parsePath:function(t){var e,n;return-1===t.indexOf(".")?[null,t]:(n=t.split("."),e=n.pop(),[n.join("."),e])},toMap:function(t,e){var n,r,i,o;for(null==e&&(e="id"),r={},i=0,o=t.length;o>i;i++)n=t[i],r[n[e]]=n;return r},sortBy:function(e,n){return n=t.parseSort(n),e.sort(function(t,e){var r,i,o,s,a;for(s=0,a=n.length;a>s;s++)if(o=n[s],r="function"==typeof t[o]?t[o]():t[o],i="function"==typeof e[o]?e[o]():e[o],null!=r&&null!=i){if(null==r)return-1;if(null==i)return 1;if(r=(""+r).toLowerCase(),i=(""+i).toLowerCase(),r>i)return 1;if(i>r)return-1}})},parseSort:function(t,e){var n,r,i;for(null==e&&(e={pos:0}),i=[],r="";e.pos<t.length;)switch(n=t[e.pos++]){case",":r.length>0&&(i.push(r),r="");break;case"[":if(r.length>0)throw Error("parseSort: Unexpected Character [ at "+(""+e.pos));i.push(this.parseSort(t,e));break;case"]":return r.length>0&&i.push(r),i;default:r+=n}return r.length>0&&(i.push(r),r=""),i},toCapsCase:function(t){var e;return e=t.replace(/^[a-z]{1,1}/g,function(t){return t.toUpperCase()}),e=e.replace(/_[a-z]{1,1}/g,function(t){return t.toUpperCase()}),e=e.replace(/_/g," ")},toSnakeCase:function(t){var e;return e=t.replace(/[A-Z]{1,1}/g,function(t){return"_"+t.toLowerCase()}),e.replace(/^_/,"")},sliceStringBefore:function(t,e){return t.slice(0,t.length-e.length)},sliceStringAfter:function(t,e){return t.slice(e.length)},stringEndsWith:function(t,e){var n;return n=e.length,t.length>=n&&t.slice(-n)===e},stringStartsWith:function(t,e){var n;return n=e.length,t.length>=n&&t.slice(0,n)===e},addBindingsParent:function(e){var n,r,i;i=[];for(n in e)o.call(e,n)&&(r=e[n],t.stringEndsWith(n,"Binding")&&null!=r&&null!=r.length&&r.length>0&&r[0]!==r[0].toUpperCase()?i.push(e[n]="parent."+e[n]):i.push(void 0));return i}}}).call(this)}),t.define("/events.coffee",function(t,e,n){(function(){var e,r;r=t("./util"),n.Events=e=function(){function t(){}return t.callbacks={},t.eventInit=function(e,n){var r,i,o,s;return null==(o=(r=t.callbacks)[e])&&(r[e]={count:0,events:{}}),null!=(s=(i=t.callbacks[e].events)[n])?s:i[n]={}},t.trigger=function(e,n,i){var o,s,a,l,h,u,c;if(null!=t.callbacks[e]&&null!=t.callbacks[e].events[n]){a=[],u=t.callbacks[e].events[n];for(s in u)o=u[s],null==o.fn.call&&r.log("general","callback issue ",o.fn),o.fn.call(this,i,o.binddata),o.once&&a.push({objectId:e,eventName:n,id:s});for(c=[],l=0,h=a.length;h>l;l++)o=a[l],c.push(delete t.callbacks[o.objectId].events[o.eventName][o.id]);return c}},t.one=function(e,n,r,i){return t.eventInit(e,n),t.callbacks[e].events[n][t.callbacks[e].count++]={fn:r,binddata:i,once:!0}},t.bind=function(e,n,r,i){return t.eventInit(e,n),t.callbacks[e].events[n][t.callbacks[e].count++]={fn:r,binddata:i}},t.unbind=function(e,n,r){var i,o,s,a,l,h;{if(null==r||null==t.callbacks[e]||null==t.callbacks[e].events[n])return null!=n&&null!=t.callbacks[e]&&null!=t.callbacks[e].events[n]?(delete t.callbacks[e].events[n],void 0):delete t.callbacks[e];s=[],h=t.callbacks[e].events[n];for(o in h)i=h[o],i.fn===r&&s.push(o);for(a=0,l=s.length;l>a;a++)o=s[a],delete t.callbacks[e].events[n][o]}},t.getBinds=function(e,n){return _(t.callbacks[e].events[n]).values()},t}()}).call(this)}),t.define("/control.coffee",function(t,e,n){(function(){var e,r,i=function(t,e){return function(){return t.apply(e,arguments)}},o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var r in e)o.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};r=t("./view").View,n.Control=e=function(t){function e(){return this.afterRender=i(this.afterRender,this),e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.idPrefix="control",e.prototype.error=function(t){return this.help=t,this.errorState=!0},e.prototype.afterRender=function(){return this.errorState?this.element.addClass("error"):void 0},e}(r)}).call(this)}),t.define("/controller.coffee",function(t,e,n){(function(){var e,r,i={}.hasOwnProperty,o=function(t,e){function n(){this.constructor=t}for(var r in e)i.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};r=t("./object").MztObject,n.Controller=e=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return o(e,t),e}(r)}).call(this)}),t.define("/data-index.coffee",function(t,e,n){(function(){var e,r,i,o,s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var r in e)s.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};o=t("./object").MztObject,n.DataIndex=r=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return a(e,t),e.indexTypes={},e.prototype.load=function(){throw Error("Mozart.DataIndex: Abstract, Not Implemented")},e.prototype.add=function(){throw Error("Mozart.DataIndex: Abstract, Not Implemented")},e.prototype.remove=function(){throw Error("Mozart.DataIndex: Abstract, Not Implemented")},e.prototype.update=function(){throw Error("Mozart.DataIndex: Abstract, Not Implemented")},e.prototype.rebuild=function(){throw Error("Mozart.DataIndex: Abstract, Not Implemented")},e.registerIndexClassType=function(t,e){return this.indexTypes[t]=e},e.getIndexClassType=function(t){return this.indexTypes[t]},e}(o),n.MapIndex=i=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return a(e,t),e.prototype.init=function(){return this.map={},this.rebuild()},e.prototype.load=function(t){return null!=this.map[t]?this.map[t]:{}},e.prototype.update=function(t,e,n){var r,i;return null!=this.map[e]&&(delete this.map[e][t.id],0===_(this.map[e]).keys().length&&delete this.map[e]),null==(i=(r=this.map)[n])&&(r[n]={}),this.map[n][t.id]=t},e.prototype.add=function(t){var e,n,r;return null==(r=(e=this.map)[n=t[this.attribute]])&&(e[n]={}),this.map[t[this.attribute]][t.id]=t},e.prototype.remove=function(t){var e,n,r,i;r=this.map,i=[];for(n in r)e=r[n],delete e[t.id],0===_(e).keys().length?i.push(delete this.map[n]):i.push(void 0);return i},e.prototype.rebuild=function(){var t,e,n,r,i;for(this.map={},r=this.modelClass.all(),i=[],e=0,n=r.length;n>e;e++)t=r[e],i.push(this.add(t));return i},e}(r),r.registerIndexClassType("map",i),n.BooleanIndex=e=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return a(e,t),e.prototype.init=function(){return this.value=this.options.value,this.rebuild()},e.prototype.load=function(t){return t===this.value?this.valueIds:this.nonValueIds},e.prototype.update=function(t,e,n){return e===this.value?delete this.valueIds[t.id]:delete this.nonValueIds[t.id],n===this.value?this.valueIds[t.id]=t:this.nonValueIds[t.id]=t},e.prototype.add=function(t){return t[this.attribute]===this.value?this.valueIds[t.id]=t:this.nonValueIds[t.id]=t},e.prototype.remove=function(t){return delete this.valueIds[t.id],delete this.nonValueIds[t.id]},e.prototype.rebuild=function(){var t,e,n,r,i;for(this.valueIds={},this.nonValueIds={},r=this.modelClass.all(),i=[],e=0,n=r.length;n>e;e++)t=r[e],i.push(this.add(t));return i},e}(r),r.registerIndexClassType("boolean",e)}).call(this)}),t.define("/dom-manager.coffee",function(t,e,n){(function(){var e,r,i,o=function(t,e){return function(){return t.apply(e,arguments)}},s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var r in e)s.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t},l=[].indexOf||function(t){for(var e=0,n=this.length;n>e;e++)if(e in this&&this[e]===t)return e;return-1};i=t("./util"),r=t("./object").MztObject,n.DOMManager=e=function(t){function e(){return this.getControlOptionsValues=o(this.getControlOptionsValues,this),this.onControlEvent=o(this.onControlEvent,this),this.onViewEvent=o(this.onViewEvent,this),this.onApplicationEvent=o(this.onApplicationEvent,this),this.release=o(this.release,this),this.checkClickOutside=o(this.checkClickOutside,this),this.checkClickInside=o(this.checkClickInside,this),this.find=o(this.find,this),e.__super__.constructor.apply(this,arguments)}var n;return a(e,t),n={click:"click",dblclick:"dblClick",focus:"focus",blur:"blur",keyup:"keyUp",keydown:"keyDown",keypress:"keyPress",focusout:"focusOut",focusin:"focusIn",change:"change",mouseover:"mouseOver",mouseout:"mouseOut"},e.prototype.init=function(){var t,e,r,i,o;this.element=$(this.rootElement);for(t in n)i=n[t],this.element.on(t,null,{eventName:i},this.onApplicationEvent);return e=function(){var t;
2
+ t=[];for(r in n)o=n[r],t.push(r);return t}().join(" "),this.element.on(e,"[view]",this.onViewEvent),this.element.on(e,"[data-mozart-action]",this.onControlEvent),this.openElements={}},e.prototype.find=function(t){var e,n,r,o,s,a;for(a=this.layouts,o=0,s=a.length;s>o;o++){if(r=a[o],null!=r.views[t])return i.log("general",""+t+": view of",r.rootElement),r.views[t];if(e=r.getControl(t),null!=e)return i.log("general",""+t+": control of",r.rootElement),e}return n=$("#"+t),n.length>0?(i.log("general",""+t+" is a an element"),n[0]):i.log("general","Cannot find ID "+t)},e.prototype.checkClickInside=function(t){var e,n,r,o,s,a,l;if("click"===t.type){for(a=this.layouts,l=[],o=0,s=a.length;s>o;o++)n=a[o],l.push(function(){var o,s;o=n.hasClickInside,s=[];for(e in o)r=o[e],$(t.target).parents("#"+e).length>0?(i.log("events","clickInside on",r,"(",t,")"),s.push(r.clickInside())):s.push(void 0);return s}());return l}},e.prototype.checkClickOutside=function(t){var e,n,r,o,s,a,l;if("click"===t.type){for(a=this.layouts,l=[],o=0,s=a.length;s>o;o++)n=a[o],l.push(function(){var o,s;o=n.hasClickOutside,s=[];for(e in o)r=o[e],0===$(t.target).parents("#"+e).length?(i.log("events","clickOutside on",r,"(",t,")"),s.push(r.clickOutside())):s.push(void 0);return s}());return l}},e.prototype.release=function(){var t,r,i,o,s;for(t in n)o=n[t],this.element.off(t,null,this._checkRootEvent);return r=function(){var t;t=[];for(i in n)s=n[i],t.push(i);return t}().join(" "),this.element.off(r,"[view]",this.onViewEvent),this.element.off(r,"[data-mozart-action]",this.onControlEvent),e.__super__.release.apply(this,arguments)},e.prototype.onApplicationEvent=function(t){return this.trigger(t.data.eventName,t)},e.prototype.onViewEvent=function(t){var e,r,o,s,a,l,h,u;if(this.checkClickInside(t),a=null,e=s=t.currentTarget,null!=e){for(u=this.layouts,l=0,h=u.length;h>l;l++)r=u[l],a=r.views[e.id],null!=a&&(o=n[t.type],this.trigger("viewEvent",t,a),"function"==typeof a[o]&&(i.log("events",o,"on",a,"(",t,")"),a[o](t,a)));return this.checkClickOutside(t),!0}},e.prototype.onControlEvent=function(t){var e,n,r,o,s,a,h,u;for(this.checkClickInside(t),n=$(t.currentTarget),r=n.attr("data-mozart-action"),i.log("controls","action",t),h=this.layouts,s=0,a=h.length;a>s;s++)o=h[s],e=o.getControl(r),null!=e&&(null===e.events||(u=t.type,l.call(e.events,u)>=0))&&("function"==typeof e.view[e.action]?(i.log("events","method",e.action,"on",e.view,"(",t,")"),i.log("controls","action on control",e,t),this.trigger("controlEvent",t,e),e.view[e.action](n,this.getControlOptionsValues(e.view,e.options),t),e.allowDefault||t.preventDefault()):i.warn("Action "+e.action+" does not exist on view "+e.view.id+", "+e.view.name,e));return this.checkClickOutside(t),t.stopImmediatePropagation()},e.prototype.getControlOptionsValues=function(t,e){var n,r,o,s;o={};for(n in e)s=e[n],i.stringEndsWith(n,"Lookup")?(r=i.sliceStringBefore(n,"Lookup"),o[r]=i._getPath(t,s)):o[n]=s;return o},e}(r)}).call(this)}),t.define("/handlebars.coffee",function(t){(function(){var e,n,r,i,o,s;r=t("./util"),i=t("./view").View,n=t("./i18n-view").I18nView,e=t("./collection").Collection,o=function(t,e){return r._getPath(t,e)},s=function(t,e){var n;return"string"==typeof e?n=r._getPath(t,e):"function"==typeof e&&(n=e.call(t)),n},Handlebars.registerHelper("site",function(){return new Handlebars.SafeString("/#")}),Handlebars.registerHelper("bind",function(t,e){var n,i,o,s,a,l,h;r.log("handlebars","handlebars helper 'bind':",this,t,e),1===arguments.length&&r.error("Bind helper must have a target."),n="bind"+r.getId(),s=null!=(l=e.hash.tag)?l:"span",i="<"+s+" id='"+n+"'",h=e.hash;for(o in h)a=h[o],r.stringEndsWith(o,"Html")&&(i+=" "+r.sliceStringBefore(o,"Html")+'="'+a+'"');return i+="></"+s+">",e.data.registerDomBind(n,t),new Handlebars.SafeString(i)}),Handlebars.registerHelper("i18n",function(t,e){var n,i,o;return r.log("handlebars","handlebars helper 'i18n':",this,t,e),1===arguments.length?(n="",r.error("i18n helper usage must reference a key.")):(i=r._getPath(window,"i18n."+t),null==i?(r.error("i18n helper: key '"+t+"' does not exist in current language file."),n=""):(o=null!=e&&null!=e.hash?Mozart.MztObject.create(e.hash):{},n=r.getPath(window,"i18n."+t)(o))),new Handlebars.SafeString(n)}),Handlebars.registerHelper("bindI18n",function(t,e){var i,o,s,a,l,h,u;if(r.log("handlebars","handlebars helper 'bindI18n':",this,t,e),1===arguments.length&&r.error("bindI18n helper must have a target."),l={context:this,i18nTemplate:t,parent:e.data},null!=e.hash){r.addBindingsParent(e.hash),u=e.hash;for(o in u)a=u[o],l[o]=a}return h=l.parent.layout.createView(n,l),l.parent.addView(h),s=h.createElement(),i=s.outerHTML,null==i&&(i=""),l.parent.layout.queueRenderView(h),new Handlebars.SafeString(i)}),Handlebars.registerHelper("view",function(t,e){var n,o,s,a,l,h,u,c,d;if(r.log("handlebars","handlebars helper 'view':",this,t,e),1===arguments.length&&(e=t,t=null),s=e.data,u=null!=t?"string"==typeof t?r._getPath(t):t:i,null==u&&r.error("view handlebars helper: viewClass does not exist","context",t,"this",this),c={context:this,parent:s},null!=e.fn&&(c.templateFunction=e.fn),null!=e.hash){r.addBindingsParent(e.hash),d=e.hash;for(o in d)l=d[o],c[o]=l}return h=s.layout.createView(u,c),s.addView(h),a=h.createElement(),n=a.outerHTML,null==n&&(n=""),s.layout.queueRenderView(h),new Handlebars.SafeString(n)}),Handlebars.registerHelper("collection",function(t,n){var o,s,a,l,h,u,c,d,p,f;r.log("handlebars","handlebars helper 'collection':",this,r.clone(t),n),1===arguments.length?(n=t,t=null,d=i):(d=r.getPath(t),null==d&&r.error("View for collection does not exist","view name",t)),l=n.data,p={context:this,viewClass:d,parent:l},null!=n.fn&&(p.viewClassTemplateFunction=n.fn),r.addBindingsParent(n.hash),f=n.hash;for(a in f)u=f[a],p[a]=u;return o=null!=n.hash.collectionClass?r.getPath(n.hash.collectionClass):e,c=l.layout.createView(o,p),c.parent=l,l.addView(c),h=c.createElement(),s=h.outerHTML,null==s&&(s=""),l.layout.queueRenderView(c),new Handlebars.SafeString(s)}),Handlebars.registerHelper("linkTo",function(t,e){var n,i,o;return r.log("handlebars","handlebars helper 'linkTo':",this,t,e),1===arguments.length&&(e=t),"string"==typeof t?t=r._getPath(this,t):"function"==typeof t&&(t=t.call(this)),null!=t?(n="<a href='/#"+t.showUrl()+"'",null!=(null!=(o=e.hash)?o.classNames:void 0)&&(n+=" class='"+e.hash.classNames+"'"),n+=">",i=e.fn(this),null!=i&&i.length>0||(i="(Empty Value)"),n+=i,n+="</a>",new Handlebars.SafeString(n)):""}),Handlebars.registerHelper("valueOf",function(t,e){var n;return r.log("handlebars","handlebars helper 'valueOf':",this,t,e),1===arguments.length&&(e=t),n=r._getPath(this,t),null==n&&(n=""),new Handlebars.SafeString(n)}),Handlebars.registerHelper("rawPath",function(t,e){var n;return 1===arguments.length&&(e=t),n=r._getPath(this,t),null==n&&(n=""),n}),Handlebars.registerHelper("uriPath",function(t,e){var n;return 1===arguments.length&&(e=t),n=r._getPath(this,t),null==n&&(n=""),encodeURI(n)}),Handlebars.registerHelper("valueEach",function(t,e){var n,i,o,s,a,l;if(r.log("handlebars","handlebars helper 'valueEach':",this,t,e),1===arguments.length&&(e=t),t=r.getPath(this,t),null==t)return"";for(i="",o=0,s=t.length;s>o;o++)n=t[o],i+=e.fn(n),null!=(null!=e?null!=(a=e.hash)?a.seperator:void 0:void 0)&&(i+=e.hash.seperator);return null!=(null!=e?null!=(l=e.hash)?l.seperator:void 0:void 0)&&i.length>0&&(i=i.slice(0,i.length-e.hash.seperator.length)),new Handlebars.SafeString(i)}),Handlebars.registerHelper("yesNo",function(t,e){return r.log("handlebars","handlebars helper 'yesNo':",this,t,e),1===arguments.length&&(e=t),"string"==typeof t&&(t=r.getPath(this,t)),null==t?"No":t?"Yes":"No"}),Handlebars.registerHelper("valueIf",function(t,e){return r.log("handlebars","handlebars helper 'valueOf':",this,t,e),"string"==typeof t&&(t=r._getPath(this,t)),t?e.fn(this):e.inverse(this)}),Handlebars.registerHelper("valueUnless",function(t,e){return"string"==typeof t&&(t=r.getPath(this,t)),t?e.inverse(this):e.fn(this)}),Handlebars.registerHelper("action",function(t,e){var n,i,o,s,a;return r.log("handlebars","handlebars helper 'action':",this,t,e),1===arguments.length&&(e=record),a=e.data,null!=e.hash.target&&(a="parent"===e.hash.target?e.data.parent:r.getPath(e.data,e.hash.target)),n=r.getId(),s='data-mozart-action="'+n+'"',o=null!=e.hash.events?e.hash.events.split(","):["click"],i=e.hash.allowDefault&&!0,e.data.layout.addControl(n,{action:t,view:a,options:e.hash,events:o,allowDefault:i}),new Handlebars.SafeString(s)}),Handlebars.registerHelper("date",function(t){var e,n;return n=s(this,t),e=r.serverToLocalDate(n)||"(none)",new Handlebars.SafeString(e)}),Handlebars.registerHelper("dateTime",function(t){var e,n;return n=s(this,t),e=r.serverToLocalDateTime(n),new Handlebars.SafeString(e)}),Handlebars.registerHelper("timeAgo",function(t){var e,n;return n=s(this,t),e=r.serverToLocalTimeAgo(n),new Handlebars.SafeString(e)}),Handlebars.registerHelper("mozartversion",function(){return new Handlebars.SafeString(Mozart.version)}),Handlebars.registerHelper("mozartversiondate",function(){return new Handlebars.SafeString(Mozart.versionDate.toLocaleDateString())})}).call(this)}),t.define("/i18n-view.coffee",function(t,e,n){(function(){var e,r,i,o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var r in e)o.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};i=t("./view").View,r=t("./util"),n.I18nView=e=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.tag="span",e.prototype.idPrefix="i18nview",e.prototype.init=function(){if(e.__super__.init.apply(this,arguments),null==this.i18nTemplate)throw Error("Mozart.I18nView must have a i18nTemplate");return this.bind("change",this.redraw)},e.prototype.templateFunction=function(){try{return r.getPath(window,"i18n."+this.i18nTemplate)(this)}catch(t){return r.warn("MessageFormat failed with Error:",t),""}},e}(i)}).call(this)}),t.define("/http.coffee",function(t,e,n){(function(){var e,r,i,o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var r in e)o.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};r=t("./object").MztObject,i=t("./util"),n.HTTP=e=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.handleError=function(t,e,n,r){switch(t.status){case 401:return Mozart.Ajax.trigger("httpAuthorizationRequired",n,t);case 404:return Mozart.Ajax.trigger("httpForbidden",n,t);default:return i.error("Model.Ajax.handleError",t,e,r)}},e.prototype._xhrHandler=function(t,e,n,r,o){var s,a,l,h,u;return this.support.ajax?(u="object"==typeof t?this.support.cors?t.cors||t.proxy:t.proxy:t,l=e||"GET",h=r||{},s=o||{},a=n||{},o.success=o.success||function(t,n,r){return i.log("Mozart.HTTP",e,"success",t,n,r)},o.error=o.error||function(t,n,r){return i.log("Mozart.HTTP",e,"error",t,n,r)},o.complete=o.complete||function(t,n){return i.log("Mozart.HTTP",e,"complete",t,n)},this._request(u,l,a,h,s)):i.log("Mozart.HTTP","AJAX is not supported. Exiting")},e.prototype._request=function(t,e,n,r,i){return $.ajax({url:t,type:e,success:i.success,error:i.error,complete:i.complete,data:n,context:r.context||this,dataType:r.dataType||"json",contentType:r.contentType||"application/json"})},e.prototype.support={ajax:function(){try{return!!new XMLHttpRequest}catch(t){return!1}},cors:function(){return this.ajax&&"withCredentials"in new XMLHttpRequest}},e.prototype.get=function(t,e){var n,r,i;return e=e||{},r=e.data||{},i=e.options||{},n=e.callbacks||{},this._xhrHandler(t,"GET",r,i,n)},e.prototype.post=function(t,e){var n,r,i;return e=e||{},r=e.data||{},i=e.options||{},n=e.callbacks||{},this._xhrHandler(t,"POST",r,i,n)},e.prototype.put=function(t,e){var n,r,i;return e=e||{},r=e.data||{},i=e.options||{},n=e.callbacks||{},this._xhrHandler(t,"PUT",r,i,n)},e.prototype["delete"]=function(t,e){var n,r,i;return e=e||{},r=e.data||{},i=e.options||{},n=e.callbacks||{},this._xhrHandler(t,"DELETE",r,i,n)},e}(r)}).call(this)}),t.define("/layout.coffee",function(t,e,n){(function(){var e,r,i,o=function(t,e){return function(){return t.apply(e,arguments)}},s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var r in e)s.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};i=t("./util"),r=t("./router").Router,n.Layout=e=function(t){function e(){return this.releaseViewControls=o(this.releaseViewControls,this),this.removeControl=o(this.removeControl,this),this.getControl=o(this.getControl,this),this.addControl=o(this.addControl,this),this.releaseViews=o(this.releaseViews,this),this.releaseView=o(this.releaseView,this),this.queueReleaseView=o(this.queueReleaseView,this),this.release=o(this.release,this),this.processRenderQueue=o(this.processRenderQueue,this),this.queueRenderView=o(this.queueRenderView,this),this._transition=o(this._transition,this),this.doRoute=o(this.doRoute,this),this.resetRoute=o(this.resetRoute,this),this.bindRoot=o(this.bindRoot,this),this.createView=o(this.createView,this),this.init=o(this.init,this),e.__super__.constructor.apply(this,arguments)}return a(e,t),e.prototype.init=function(){var t,n,r,i,o;for(e.__super__.init.apply(this,arguments),this.viewRenderQueue=[],this.releaseMap={},this.views={},this.currentState=null,this.controls={},this.hasClickOutside={},this.hasClickInside={},i=this.states,o=[],n=0,r=i.length;r>n;n++)t=i[n],null!=t.path&&null!=t.viewClass&&o.push(this.register(t.path,this.doRoute,t));return o},e.prototype.createView=function(t,e){var n;return null==e&&(e={}),e.layout=this,n=t.create(e),this.views[n.id]=n,null!=n.clickInside&&(this.hasClickInside[n.id]=n),null!=n.clickOutside&&(this.hasClickOutside[n.id]=n),n},e.prototype.bindRoot=function(){return this.rootEl=$(this.rootElement)[0]},e.prototype.resetRoute=function(){return this.viewRenderQueue=[],this.currentState=null,this.releaseViews()},e.prototype.doRoute=function(t,e){return null==this.currentState||this.currentState.canExit()?(this.currentState=null,t.canEnter(e)?(this._transition(t),!0):(i.log("layout","cannot enter state",t,e),!1)):(i.log("layout","cannot exit state",this.currentState),!1)},e.prototype._transition=function(t){return this.resetRoute(),this.currentState=t,this.currentState.doTitle(),null!=this.currentState.viewClass?(null!=this.currentView&&(this.releaseMap[this.currentView.id]=this.currentView),this.currentView=this.createView(this.currentState.viewClass,this.currentState.viewOptions),this.currentView.el=this.rootEl,this.queueRenderView(this.currentView)):void 0},e.prototype.queueRenderView=function(t){var e,n,r;return i.log("layout",""+this._mozartId+" queueRenderView",t),null==(r=(e=this.views)[n=t.id])&&(e[n]=t),0===this.viewRenderQueue.length&&_.delay(this.processRenderQueue,0),this.viewRenderQueue.push(t)},e.prototype.processRenderQueue=function(){var t,e,n,r,o,s,a,l,h,u,c,d,p,f,g,y,m,v,w;if(!this.released&&0!==this.viewRenderQueue.length){for(i.log("layout",""+this._mozartId+" processRenderQueue with "+this.viewRenderQueue.length+" views"),e=[],n=[];this.viewRenderQueue.length>0;)s=this.viewRenderQueue.shift(),s.beforeRender(),s.releaseChildren(),s.prepareElement(),n.push(s);for(r=[],h=0,p=n.length;p>h;h++)for(a=n[h],u=0,f=n.length;f>u;u++)l=n[u],l!==a&&a.hasAncestor(l)&&!_.contains(r,a)&&r.push(a);for(o=_.difference(n,r),c=0,g=o.length;g>c;c++)s=o[c],s.reassignElements();for(d=0,y=o.length;y>d;d++)s=o[d],s.replaceElement();for(v=0,m=n.length;m>v;v++)s=n[v],s.postRender();w=this.releaseMap;for(t in w)s=w[t],null!=s&&s.release();return this.releaseMap={},i.log("layout",""+this._mozartId+" render finished"),this.trigger("render:complete")}},e.prototype.release=function(){return this.releaseViews(),e.__super__.release.apply(this,arguments)},e.prototype.queueReleaseView=function(t){return this.releaseMap[t.id]=t},e.prototype.releaseView=function(t){return this.releaseViewControls(t),delete this.views[t.id],delete this.hasClickOutside[t.id],delete this.hasClickInside[t.id]},e.prototype.releaseViews=function(){var t,e,n,r;n=this.views,r=[];for(t in n)e=n[t],i.log("layout","processRenderQueue:releasing",e.id,e),this.releaseMap[t]=e,r.push(this.processRenderQueue());return r},e.prototype.addControl=function(t,e){return i.log("layout","adding control",t,e),this.controls[t]=e},e.prototype.getControl=function(t){return this.controls[t]},e.prototype.removeControl=function(t){return i.log("layout","removing control",t),delete this.controls[t]},e.prototype.releaseViewControls=function(t){var e,n,r,o;r=this.controls,o=[];for(n in r)e=r[n],e.view===t&&(i.log("layout","releasing control for view",t,"control",e.action,e),o.push(delete this.controls[n]));return o},e}(r)}).call(this)}),t.define("/router.coffee",function(t,e,n){(function(){var e,r,i,o=function(t,e){return function(){return t.apply(e,arguments)}},s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var r in e)s.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=t("./object").MztObject,i=t("./util"),n.Router=r=function(t){function e(){return this.release=o(this.release,this),this.navigateRoute=o(this.navigateRoute,this),this.onPopState=o(this.onPopState,this),this.onNavigationEvent=o(this.onNavigationEvent,this),this.onHashChange=o(this.onHashChange,this),this.register=o(this.register,this),this.stop=o(this.stop,this),this.start=o(this.start,this),this.init=o(this.init,this),e.__super__.constructor.apply(this,arguments)}return a(e,t),e.prototype.init=function(){var t;return this.routes={},null!=(t=this.useHashRouting)?t:this.useHashRouting=!1},e.prototype.start=function(){return this.useHashRouting?($(window).bind("hashchange",this.onHashChange),this.onHashChange()):($("body").on("click","a",this.onNavigationEvent),$(window).on("popstate",this.onPopState),this.onPopState())},e.prototype.stop=function(){return this.useHashRouting?$(window).unbind("hashchange",this.onHashChange):($("body").off("click","a",this.onNavigationEvent),$(window).off("popstate",this.onPopState))},e.prototype.register=function(t,e,n){var r,o,s,a,l,h;for(i.log("routes","registering route",t,n),a=t.split("/"),r=[],o="",l=0,h=a.length;h>l;l++)s=a[l],":"===s[0]?(o+="([^\\/]+)\\/",r.push(s.substr(1))):o+=this._escForRegEx(s)+"\\/";return o.length>2&&(o=o.substr(0,o.length-2)),this.routes[t]={regex:RegExp("^"+o+"$","i"),params:r,callback:e,data:n}},e.prototype.onHashChange=function(){var t;return t=window.location.hash,t.length>0&&"#"===t[0]&&(t=t.substr(1)),this.navigateRoute(t)},e.prototype.onNavigationEvent=function(t){return t.target.host===document.location.host&&t.target.port===document.location.port&&t.target.protocol===document.location.protocol?this.navigateRoute(t.target.pathname)?(history.pushState({one:1},null,t.target.href),t.preventDefault()):void 0:void 0},e.prototype.onPopState=function(){return this.navigateRoute(window.location.pathname)},e.prototype.navigateRoute=function(t){var e,n,r,o,s,a,l,h,u,c;if(this.isNavigating=!0,null==t||0===t.length){if(a=this.routes["/"],null!=a)return a.callback(a.data,r),this.isNavigating=!1,!1;i.log("routemanager","WARNING: No Default route defined, no route for path",t)}u=this.routes;for(o in u)if(a=u[o],r={},n=a.regex.exec(t),null!==n){for(e=1,c=a.params,l=0,h=c.length;h>l;l++)s=c[l],n.length>e&&(r[s]=n[e++]);return a.callback(a.data,r),this.isNavigating=!1,!0}return this.isNavigating=!1,this.trigger("noroute",window.location.hash),!1},e.prototype.release=function(){return this.stop(),e.__super__.release.apply(this,arguments)},e.prototype._escForRegEx=function(t){var e,n,r,i;for(t.replace("\\","\\\\"),e="./+{}()*",r=0,i=e.length;i>r;r++)n=e[r],t=t.replace(n,"\\"+n);return t},e}(e)}).call(this)}),t.define("/model-instance.coffee",function(t,e,n){(function(){var e,r,i,o=function(t,e){return function(){return t.apply(e,arguments)}},s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var r in e)s.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t},l=[].indexOf||function(t){for(var e=0,n=this.length;n>e;e++)if(e in this&&this[e]===t)return e;return-1};i=t("./util"),r=t("./object").MztObject,n.Instance=e=function(t){function e(){return this.copyFrom=o(this.copyFrom,this),this.copyTo=o(this.copyTo,this),this.set=o(this.set,this),this.get=o(this.get,this),this.destroy=o(this.destroy,this),this.save=o(this.save,this),this.load=o(this.load,this),e.__super__.constructor.apply(this,arguments)}var n;return a(e,t),n=["id"],e.prototype.init=function(){return this._type=this.modelClass.modelName},e.prototype.load=function(t){return null==t&&(t={}),this.modelClass.loadInstance(this,t)},e.prototype.save=function(t){return null==t&&(t={}),this.modelClass.exists(this.id)?(this.modelClass.updateInstance(this,t),this.trigger("update")):(this.modelClass.createInstance(this,t),this.trigger("create")),this.trigger("change")},e.prototype.destroy=function(t){return null==t&&(t={}),this.trigger("destroy",t),this.trigger("change"),this.modelClass.destroyInstance(this,t)},e.prototype.get=function(t){if(this.modelClass.hasAttribute(t)||i.isFunction(this[t]))return i.isFunction(this[t])?this[t].apply(this):e.__super__.get.call(this,t);throw Error(""+this.modelClass.modelName+" has no attribute or relation '"+t+"' or foreign key '"+t+"_id'")},e.prototype.set=function(t,n){if(this.modelClass.hasAttribute(t)||i.isFunction(this[t]))return i.isFunction(this[t])?this[t](n):("id"!==t&&this.modelClass.hasIndex(t)&&this.modelClass.exists(this.id)&&this.modelClass.updateIndex(t,this,this[t],n),e.__super__.set.call(this,t,n));throw Error(""+this.modelClass.modelName+" has no attribute or relation '"+t+"' or foreign key '"+t+"_id'")},e.prototype.copyTo=function(t){var e,i,o;null==t&&(t=r.create()),o=this.modelClass.attrs;for(e in o)i=o[e],0>l.call(n,e)&&(null!=t.set?t.set(e,this[e]):t[e]=this[e]);return t},e.prototype.copyFrom=function(t){var e,r,i,o,s;r=!1;for(e in t)s=t[e],0>l.call(n,e)&&(o=this.modelClass.attrs[e],null!=o&&(i=s,"decimal"===o&&(i=parseFloat(i)),this[e]!==i&&(r=!0,this.set(e,i))));return r},e}(r)}).call(this)}),t.define("/model-instancecollection.coffee",function(t,e,n){(function(){var e,r,i,o=function(t,e){return function(){return t.apply(e,arguments)}},s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var r in e)s.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};i=t("./util"),r=t("./object").MztObject,n.InstanceCollection=e=function(t){function e(){return this.unBindEvents=o(this.unBindEvents,this),this.bindEvents=o(this.bindEvents,this),this.allAsMap=o(this.allAsMap,this),this.count=o(this.count,this),e.__super__.constructor.apply(this,arguments)}return a(e,t),e.prototype.count=function(){return this.all().length},e.prototype.allAsMap=function(){return i.toMap(this.all())},e.prototype.all=function(){return[]},e.prototype.bindEvents=function(t){var e,n,r,i;for(i=[],n=0,r=t.length;r>n;n++)e=t[n],e.bind("create",this.onModelChange),e.bind("update",this.onModelChange),i.push(e.bind("destroy",this.onModelChange));return i},e.prototype.unBindEvents=function(t){var e,n,r,i;for(i=[],n=0,r=t.length;r>n;n++)e=t[n],e.unbind("create",this.onModelChange),e.unbind("update",this.onModelChange),i.push(e.unbind("destroy",this.onModelChange));return i},e}(r)}).call(this)}),t.define("/model-onetomanycollection.coffee",function(t,e,n){(function(){var e,r,i=function(t,e){return function(){return t.apply(e,arguments)}},o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var r in e)o.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=t("./model-instancecollection").InstanceCollection,n.OneToManyCollection=r=function(t){function e(){return this.release=i(this.release,this),this.onModelChange=i(this.onModelChange,this),this.contains=i(this.contains,this),this.remove=i(this.remove,this),this.createFromValues=i(this.createFromValues,this),this.add=i(this.add,this),this.all=i(this.all,this),e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.init=function(){return this.bindEvents([this.otherModel])},e.prototype.all=function(){return this.otherModel.findByAttribute(this.fkname,this.record.id)},e.prototype.add=function(t){return t.set(this.fkname,this.record.id),t.save(),this.record.trigger("change:"+this.attribute)},e.prototype.createFromValues=function(t){var e;return e=this.otherModel.initInstance(t),this.add(e),e},e.prototype.remove=function(t){return t.set(this.fkname,null),this.record.trigger("change:"+this.attribute)},e.prototype.contains=function(){return this.otherModel.findByAttribute(this.fkname,this.record.id).length>0},e.prototype.onModelChange=function(t){return this.trigger("change",t)},e.prototype.release=function(){return this.unBindEvents([this.otherModel]),e.__super__.release.apply(this,arguments)},e}(e)}).call(this)}),t.define("/model-onetomanypolycollection.coffee",function(t,e,n){(function(){var e,r,i=function(t,e){return function(){return t.apply(e,arguments)}},o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var r in e)o.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=t("./model-instancecollection").InstanceCollection,n.OneToManyPolyCollection=r=function(t){function e(){return this.contains=i(this.contains,this),this.remove=i(this.remove,this),this.add=i(this.add,this),this.createFromValues=i(this.createFromValues,this),this.all=i(this.all,this),e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.all=function(){var t;return t={},t[this.thatFkAttr]=this.record.id,t[this.thatTypeAttr]=this.model.modelName,this.otherModel.findByAttributes(t)},e.prototype.createFromValues=function(t){var e;return e=this.otherModel.initInstance(t),this.add(e),e},e.prototype.add=function(t){return t.set(this.thatFkAttr,this.record.id),t.set(this.thatTypeAttr,this.model.modelName),t.save()},e.prototype.remove=function(t){return t.set(this.thatFkAttr,null),t.set(this.thatTypeAttr,null),t.save()},e.prototype.contains=function(){var t;return t={},t[this.thatFkAttr]=this.record.id,t[this.thatTypeAttr]=this.model.modelName,0!==this.otherModel.findByAttributes(t).length},e}(e)}).call(this)}),t.define("/model-manytomanycollection.coffee",function(t,e,n){(function(){var e,r,i=function(t,e){return function(){return t.apply(e,arguments)}},o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var r in e)o.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=t("./model-instancecollection").InstanceCollection,n.ManyToManyCollection=r=function(t){function e(){return this.release=i(this.release,this),this.onModelChange=i(this.onModelChange,this),this.contains=i(this.contains,this),this.remove=i(this.remove,this),this.createFromValues=i(this.createFromValues,this),this.add=i(this.add,this),this.all=i(this.all,this),e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.init=function(){return this.bindEvents([this.linkModel])},e.prototype.all=function(){var t,e,n,r,i;for(e=this.linkModel.findByAttribute(this.thisFkAttr,this.record.id),i=[],n=0,r=e.length;r>n;n++)t=e[n],i.push(this.otherModel.findById(t[this.thatFkAttr]));return i},e.prototype.add=function(t){var e,n;return n={},n[this.thisFkAttr]=this.record.id,n[this.thatFkAttr]=t.id,0===this.linkModel.findByAttributes(n).length?(e=this.linkModel.initInstance(),e.set(this.thisFkAttr,this.record.id),e.set(this.thatFkAttr,t.id),e.save(),e):void 0},e.prototype.createFromValues=function(t){var e;return e=this.otherModel.initInstance(t),e.save(),this.add(e),e},e.prototype.remove=function(t){var e,n,r,i,o,s;for(r={},r[this.thisFkAttr]=this.record.id,r[this.thatFkAttr]=t.id,n=this.linkModel.findByAttributes(r),s=[],i=0,o=n.length;o>i;i++)e=n[i],s.push(e.destroy());return s},e.prototype.contains=function(t){var e;return e={},e[this.thisFkAttr]=this.record.id,e[this.thatFkAttr]=t.id,0!==this.linkModel.findByAttributes(e).length},e.prototype.onModelChange=function(t){var e;return t.get(this.thisFkAttr)===this.record.id?(e=this.otherModel.findById(t[this.thatFkAttr]),this.trigger("change",e)):void 0},e.prototype.release=function(){return this.unBindEvents([this.linkModel]),e.__super__.release.apply(this,arguments)},e}(e)}).call(this)}),t.define("/model-manytomanypolycollection.coffee",function(t,e,n){(function(){var e,r,i=function(t,e){return function(){return t.apply(e,arguments)}},o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var r in e)o.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=t("./model-instancecollection").InstanceCollection,n.ManyToManyPolyCollection=r=function(t){function e(){return this.release=i(this.release,this),this.onModelChange=i(this.onModelChange,this),this.contains=i(this.contains,this),this.remove=i(this.remove,this),this.add=i(this.add,this),this.createFromValues=i(this.createFromValues,this),this.all=i(this.all,this),e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.init=function(){return this.bindEvents([this.linkModel])},e.prototype.all=function(){var t,e,n,r,i,o;for(n={},n[this.thisFkAttr]=this.record.id,n[this.thatTypeAttr]=this.otherModel.modelName,e=this.linkModel.findByAttributes(n),o=[],r=0,i=e.length;i>r;r++)t=e[r],o.push(this.otherModel.findById(t[this.thatFkAttr]));return o},e.prototype.createFromValues=function(t){var e;return e=this.otherModel.initInstance(t),e.save(),this.add(e),e},e.prototype.add=function(t){var e,n;return n={},n[this.thisFkAttr]=this.record.id,n[this.thatFkAttr]=t.id,n[this.thatTypeAttr]=this.otherModel.modelName,0===this.linkModel.findByAttributes(n).length?(e=this.linkModel.initInstance(),e.set(this.thisFkAttr,this.record.id),e.set(this.thatFkAttr,t.id),e.set(this.thatTypeAttr,this.otherModel.modelName),e.save(),e):void 0},e.prototype.remove=function(t){var e,n,r,i,o,s;for(n={},n[this.thisFkAttr]=this.record.id,n[this.thatFkAttr]=t.id,n[this.thatTypeAttr]=this.otherModel.modelName,o=this.linkModel.findByAttributes(n),s=[],r=0,i=o.length;i>r;r++)e=o[r],s.push(e.destroy());return s},e.prototype.contains=function(t){var e;return e={},e[this.thisFkAttr]=this.record.id,e[this.thatFkAttr]=t.id,e[this.thatTypeAttr]=this.otherModel.modelName,0!==this.linkModel.findByAttributes(e).length},e.prototype.onModelChange=function(t){var e;return t[this.thisFkAttr]===this.record.id&&t[this.thatTypeAttr]===this.otherModel.modelName?(e=this.otherModel.findById(t[this.thatFkAttr]),this.trigger("change",e)):void 0},e.prototype.release=function(){return this.unBindEvents([this.linkModel]),e.__super__.release.apply(this,arguments)},e}(e)}).call(this)}),t.define("/model-manytomanypolyreversecollection.coffee",function(t,e,n){(function(){var e,r,i=function(t,e){return function(){return t.apply(e,arguments)}},o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var r in e)o.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=t("./model-instancecollection").InstanceCollection,n.ManyToManyPolyReverseCollection=r=function(t){function e(){return this.release=i(this.release,this),this.onModelChange=i(this.onModelChange,this),this.contains=i(this.contains,this),this.remove=i(this.remove,this),this.add=i(this.add,this),this.createFromValues=i(this.createFromValues,this),this.all=i(this.all,this),e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.init=function(){return this.bindEvents([this.linkModel])},e.prototype.all=function(){var t,e,n,r,i,o;for(n={},n[this.thatFkAttr]=this.record.id,n[this.thatTypeAttr]=this.model.modelName,e=this.linkModel.findByAttributes(n),o=[],r=0,i=e.length;i>r;r++)t=e[r],o.push(this.otherModel.findById(t[this.thisFkAttr]));
3
+ return o},e.prototype.createFromValues=function(t){var e;return e=this.otherModel.initInstance(t),e.save(),this.add(e),e},e.prototype.add=function(t){var e,n;return n={},n[this.thisFkAttr]=t.id,n[this.thatFkAttr]=this.record.id,n[this.thatTypeAttr]=this.model.modelName,0===this.linkModel.findByAttributes(n).length?(e=this.linkModel.initInstance(),e.set(this.thisFkAttr,t.id),e.set(this.thatFkAttr,this.record.id),e.set(this.thatTypeAttr,this.model.modelName),e.save(),e):void 0},e.prototype.remove=function(t){var e,n,r,i,o,s;for(n={},n[this.thisFkAttr]=t.id,n[this.thatFkAttr]=this.record.id,n[this.thatTypeAttr]=this.model.modelName,o=this.linkModel.findByAttributes(n),s=[],r=0,i=o.length;i>r;r++)e=o[r],s.push(e.destroy());return s},e.prototype.contains=function(t){var e;return e={},e[this.thisFkAttr]=t.id,e[this.thatFkAttr]=this.record.id,e[this.thatTypeAttr]=this.model.modelName,0!==this.linkModel.findByAttributes(e).length},e.prototype.onModelChange=function(t){var e;return t[this.thatFkAttr]===this.record.id&&t[this.thatTypeAttr]===this.model.modelName?(e=this.model.findById(t[this.thisFkAttr]),this.trigger("change",e)):void 0},e.prototype.release=function(){return this.unBindEvents([this.linkModel]),e.__super__.release.apply(this,arguments)},e}(e)}).call(this)}),t.define("/model-ajax.coffee",function(t){(function(){var e,n,r,i;e=t("./model").Model,n=t("./util"),i={},r={},e.extend({ajax:function(t){var e,o,s,a,l,h,u,c,d;for(h=["url","interface","plural"],o=0,s=h.length;s>o;o++)e=h[o],null!=t[e]&&(this[e]=t[e]);return this.bind("load",this.loadServer),this.bind("create",this.createServer),this.bind("update",this.updateServer),this.bind("destroy",this.destroyServer),null==(u=i[a=this.modelName])&&(i[a]={}),null==(c=r[l=this.modelName])&&(r[l]={}),null==(d=Mozart.Ajax)&&(Mozart.Ajax=Mozart.MztObject.create({handleError:function(t,e,r,i){switch(t.status){case 401:return Mozart.Ajax.trigger("httpAuthorizationRequired",r,t);case 404:return Mozart.Ajax.trigger("httpForbidden",r,t);default:return n.error("Model.Ajax.handleError",t,e,i)}}})),this.instanceClass.extend({getServerId:function(){return this.modelClass.getServerId(this.id)},existsOnServer:function(){return null!=this.modelClass.getServerId(this.id)},loadServer:function(){return this.modelClass.load(this.modelClass.getServerId(this.id))}})},registerServerId:function(t,e){if(null==i[this.modelName])throw Error("Model.registerServerId: "+this.modelName+" is not registered for ajax.");return i[this.modelName][e]=t,r[this.modelName][t]=e},unRegisterServerId:function(t,e){return delete i[this.modelName][e],delete r[this.modelName][t]},getServerId:function(t){return r[this.modelName][t]},getClientId:function(t){return i[this.modelName][t]},toServerObject:function(t){var n,r,i,o,s,a,l,h;i={},a=this.attrs;for(n in a)o=a[n],"id"!==n&&(i[n]=t[n]);i.id=this.getServerId(t.id),l=this.fks;for(n in l)r=l[n],i[n]=r.getServerId(t[n]);h=this.polyFks;for(n in h)s=h[n],i[n]=null!=t[s]?e.models[t[s]].getServerId(t[n]):null;return i},toClientObject:function(t){var n,r,i,o,s,a,l,h;i={},a=this.attrs;for(n in a)o=a[n],"id"!==n&&t[n]!==void 0&&(i[n]=t[n]);i.id=this.getClientId(t.id),l=this.fks;for(n in l)r=l[n],t[n]!==void 0&&(i[n]=r.getClientId(t[n]),i[n]===void 0&&(i[n]=null));h=this.polyFks;for(n in h)s=h[n],i[n]=t[n]!==void 0&&null!=t[s]?e.models[t[s]].getClientId(t[n]):null;return i},loadServer:function(t){var e;return e=t.modelClass.getServerId(t.id),null!=e?t.modelClass.load(e):void 0},createServer:function(t){return t.modelClass.createAjax(t.id,t.modelClass.toServerObject(t))},updateServer:function(t){var e;return e=t.modelClass.getServerId(t.id),null!=e?t.modelClass.updateAjax(e,t.id,t.modelClass.toServerObject(t)):void 0},destroyServer:function(t){var e;return e=t.modelClass.getServerId(t.id),null!=e?t.modelClass.destroyAjax(t.modelClass.getServerId(t.id),t.id):void 0},loadAll:function(){var t,e,r,i;return i=function(t,e){var n,r,i;for(null!=this.model.plural&&(t=t[this.model.plural]),r=0,i=t.length;i>r;r++)n=t[r],this.model._processLoad(n,this.model,e);return this.model.trigger("loadAllComplete")},r=function(t,e,n){return Mozart.Ajax.handleError(t,e,this,n)},e=function(t,e){return n.log("ajax","Model.loadAll.onComplete",t,e)},t=Mozart.HTTP.create(),t.get(this.url,{options:{context:{model:this}},callbacks:{success:i,error:r,complete:e}})},load:function(t){var e,r,i,o;return o=function(t,e){return null!=this.model.plural&&(t=t[this.model.plural]),this.model._processLoad(t,this.model,e)},i=function(t,e,n){return Mozart.Ajax.handleError(t,e,this,n)},r=function(t,e){return n.log("ajax","Model.load.onComplete",t,e)},e=Mozart.HTTP.create(),e.get(this.url+"/"+t,{options:{context:{model:this,id:t}},callbacks:{success:o,error:i,complete:r}})},_processLoad:function(t,e,r){var i,o,s;return s=t.id,i=e.toClientObject(t),o=e.findById(i.id),null==o&&(o=e.initInstance(t)),e.registerServerId(o.id,s),o.copyFrom(i),o.save({disableModelCreateEvent:!0,disableModelUpdateEvent:!0}),n.log("ajax","Model._processLoad.onSuccess",r,t),e.trigger("loadComplete",o)},createAjax:function(t,e){var r,i,o,s;return s=function(e,r){return this.model.registerServerId(this.clientId,e.id),n.log("ajax","Model.createAjax.onSuccess",r,e),this.model.trigger("createComplete",this.model.findById(t))},o=function(t,e,n){return Mozart.Ajax.handleError(t,e,this,n)},i=function(t,e){return n.log("ajax","Model.createAjax.onComplete",t,e)},r=Mozart.HTTP.create(),r.post(this.url,{data:JSON.stringify(e),options:{context:{model:this,clientId:t}},callbacks:{success:s,error:o,complete:i}})},updateAjax:function(t,e,r){var i,o,s,a;return a=function(t,r){return n.log("ajax","Model.updateAjax.onSuccess",r,t),this.model.trigger("updateComplete",this.model.findById(e))},s=function(t,e,n){return Mozart.Ajax.handleError(t,e,this,n)},o=function(t,e){return n.log("ajax","Model.updateAjax.onComplete",t,e)},i=Mozart.HTTP.create(),i.put(this.url+"/"+t,{data:JSON.stringify(r),options:{context:{model:this,clientId:this.clientId,serverId:this.serverId}},callbacks:{success:a,error:s,complete:o}})},destroyAjax:function(t,e){var r,i,o,s;return s=function(r,i){return this.model.unRegisterServerId(e,t),n.log("ajax","Model.destroyAjax.onSuccess",i,r),this.model.trigger("destroyComplete",t)},o=function(t,e,n){return Mozart.Ajax.handleError(t,e,this,n)},i=function(t,e){return n.log("ajax","Model.destroyAjax.onComplete",t,e)},r=Mozart.HTTP.create(),r["delete"](this.url+"/"+t,{options:{context:{model:this,clientId:e,serverId:t}},callbacks:{success:s,error:o,complete:i}})}})}).call(this)}),t.define("/model.coffee",function(t,e,n){(function(){var e,r,i,o,s,a,l,h,u,c,d,p=function(t,e){return function(){return t.apply(e,arguments)}},f={}.hasOwnProperty,g=function(t,e){function n(){this.constructor=t}for(var r in e)f.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};d=t("./util"),h=t("./object").MztObject,e=t("./data-index").DataIndex,r=t("./model-instance").Instance,i=t("./model-instancecollection").InstanceCollection,u=t("./model-onetomanycollection").OneToManyCollection,c=t("./model-onetomanypolycollection").OneToManyPolyCollection,o=t("./model-manytomanycollection").ManyToManyCollection,s=t("./model-manytomanypolycollection").ManyToManyPolyCollection,a=t("./model-manytomanypolyreversecollection").ManyToManyPolyReverseCollection,n.Model=l=function(t){function n(){return this.index=p(this.index,this),this._generateId=p(this._generateId,this),this._getInstance=p(this._getInstance,this),this.toSnakeCase=p(this.toSnakeCase,this),this.destroyInstance=p(this.destroyInstance,this),this.updateInstance=p(this.updateInstance,this),this.createInstance=p(this.createInstance,this),this.loadInstance=p(this.loadInstance,this),this.createFromValues=p(this.createFromValues,this),this.initInstance=p(this.initInstance,this),this.exists=p(this.exists,this),this.findByAttributes=p(this.findByAttributes,this),this.findByAttribute=p(this.findByAttribute,this),this.selectAsMap=p(this.selectAsMap,this),this.selectIds=p(this.selectIds,this),this.select=p(this.select,this),this.findAll=p(this.findAll,this),this.findById=p(this.findById,this),this.count=p(this.count,this),this.allAsMap=p(this.allAsMap,this),this.all=p(this.all,this),this.hasManyThrough=p(this.hasManyThrough,this),this.hasMany=p(this.hasMany,this),this.belongsToPoly=p(this.belongsToPoly,this),this.belongsTo=p(this.belongsTo,this),this.polyForeignKeys=p(this.polyForeignKeys,this),this.foreignKeys=p(this.foreignKeys,this),this.attributes=p(this.attributes,this),this.reset=p(this.reset,this),n.__super__.constructor.apply(this,arguments)}return g(n,t),n.idCount=1,n.indexForeignKeys=!0,n.models={},n.prototype.toString=function(){return"Model: "+this.modelName},n.prototype.init=function(){var t;if(null==this.modelName)throw Error("Model must have a modelName");return this.records={},this.fks={},this.polyFks={},this.attrs={id:"integer"},this.relations={},this.indexes={},n.models[this.modelName]=this,this.instanceClass=t=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return g(e,t),e}(r)},n.prototype.reset=function(){var t,e,n;n=this.records;for(t in n)e=n[t],e.release();return this.records={},this.rebuildAllIndexes()},n.prototype.attributes=function(t){var e,n,r;r=[];for(e in t)n=t[e],r.push(this.attrs[e]=n);return r},n.prototype.hasAttribute=function(t){return null!=this.attrs[t]||null!=this.fks[t+"_id"]},n.prototype.hasRelation=function(t){return null!=this.relations[t]},n.prototype.foreignKeys=function(t){var e,r,i;i=[];for(e in t)r=t[e],this.fks[e]=r,n.DataIndexForeignKeys?i.push(this.index(e)):i.push(void 0);return i},n.prototype.polyForeignKeys=function(t){var e,r,i;i=[];for(e in t)r=t[e],this.polyFks[e]=r,n.DataIndexForeignKeys?i.push(this.index(e)):i.push(void 0);return i},n.prototype.belongsTo=function(t,e,n){var r,i,o,s,a;return null==e&&null==e&&(e=this.toSnakeCase(t.modelName)),i={},null==n&&(n=e+"_id"),i[n]="integer",this.attributes(i),o={},o[n]=t,this.foreignKeys(o),s={},s[e]=function(r){var i;if(1===arguments.length){if(null!==r&&(null==r.modelClass||r.modelClass!==t))throw Error("Cannot assign "+r+" to belongsTo "+this.modelClass.modelName+":"+e+" (Value is not an Instance or incorrect ModelClass)");return null!=r?this.set(n,r.id):this.set(n,null)}return i=this[n],null==i?null:t.findById(i)},this.instanceClass.extend(s),r=this,a=function(e){var r,i,o,s,a;for(s=t.findByAttribute(n,e.id),a=[],i=0,o=s.length;o>i;i++)r=s[i],r.set(n,null),a.push(r.save());return a},t.bind("destroy",a)},n.prototype.hasOne=function(t,e,n){var r,i,o,s;return null==e&&(e=this.toSnakeCase(this.modelName)),i={},null==n&&(n=e+"_id"),i[n]="integer",t.attributes(i),o={},o[n]=this,t.foreignKeys(o),this.instanceClass.prototype[e]=function(r){var i,o,s,a,l;if(1===arguments.length){for(l=t.findByAttribute(n,this.id),s=0,a=l.length;a>s;s++)i=l[s],i!==r&&(i.set(n,null),i.save());if(null===r)return;return r.set(n,this.id),r.save(),this.trigger("change:"+e),this.trigger("change")}return o=t.findByAttribute(n,this.id),o.length>0?o[0]:null},r=this,s=function(e){var r,i,o,s,a;for(s=t.findByAttribute(n,e.id),a=[],i=0,o=s.length;o>i;i++)r=s[i],r.set(n,null),a.push(r.save());return a},this.bind("destroy",s)},n.prototype.belongsToPoly=function(t,e,r,i){var o,s,a,l,h,u,c,p,f;for(null==e&&(e=this.toSnakeCase(l.modelName)),s={},null==r&&(r=e+"_id"),s[r]="integer",null==i&&(i=e+"_type"),s[i]="string",this[e+"_allowed_models"]=t,this.attributes(s),a={},a[r]=i,this.polyForeignKeys(a),h={},h[e]=function(e,o){var s,a;return arguments.length>0?(null!=e?(_.contains(t,e.modelClass)||d.error("Cannot assign a model of type {{value.modelClass.modelName}} to this belongsToPoly - allowed model types are "+t.join(", ")),this.set(r,e.id),this.set(i,e.modelClass.modelName)):(this[r]=null,this[i]=null),this.save(o)):(s=this[r],a=n.models[this[i]],null==s||null==a?null:a.findById(s))},this.instanceClass.extend(h),o=this,u=function(t,e){var n,s,a,l,h,u;for(null==e&&(e={}),s={},s[r]=t.id,s[i]=t.modelClass.modelName,h=o.findByAttributes(s),u=[],a=0,l=h.length;l>a;a++)n=h[a],n.set(r,null),n.set(i,null),u.push(n.save(e));return u},f=[],c=0,p=t.length;p>c;c++)l=t[c],f.push(l.bind("destroy",u));return f},n.prototype.hasMany=function(t,e,n){var r,i,o,s,a;return null==e&&(e=this.toSnakeCase(t.modelName)),i={},null==n&&(n=this.toSnakeCase(this.modelName+"_id")),i[n]="integer",t.attributes(i),o={},o[n]=this,t.foreignKeys(o),this.relations[e]={type:"hasMany",otherModel:t,foreignKeyAttribute:n},r=this,s={},s[e]=function(){if(arguments.length>0)throw Error("Cannot set a hasMany relation");return null==this[e+"_hasMany_collection"]&&(this[e+"_hasMany_collection"]=u.create({record:this,attribute:this.attribute,model:r,otherModel:t,fkname:n})),this[e+"_hasMany_collection"]},this.instanceClass.extend(s),a=function(e,r){var i,o,s,a,l;for(null==r&&(r={}),a=t.findByAttribute(n,e.id),l=[],o=0,s=a.length;s>o;o++)i=a[o],i.set(n,null),l.push(i.save(r));return l},this.bind("destroy",a)},n.prototype.hasManyPoly=function(t,e,n,r){var i,o,s,a;return null==e&&(e=this.toSnakeCase(t.modelName)),null==n&&(n=e+"_id"),null==r&&(r=e+"_type"),o={},o[n]="integer",o[r]="string",t.attributes(o),s={},s[n]=r,t.polyForeignKeys(s),this.relations[e]={type:"hasManyPoly",otherModel:t,foreignKeyAttribute:n,foreignModelTypeAttribute:r},i=this,this.instanceClass.prototype[e]=function(){if(arguments.length>0)throw Error("Cannot set a hasManyPoly relation");return null==this[e+"_hasManyPoly_collection"]&&(this[e+"_hasManyPoly_collection"]=c.create({record:this,model:i,otherModel:t,thatFkAttr:n,thatTypeAttr:r})),this[e+"_hasManyPoly_collection"]},a=function(e,o){var s,a,l,h,u,c;for(null==o&&(o={}),a={},a[n]=e.id,a[r]=i.modelName,u=t.findByAttributes(a),c=[],l=0,h=u.length;h>l;l++)s=u[l],s.set(n,null),s.set(r,null),c.push(s.save(o));return c},this.bind("destroy",a)},n.prototype.hasManyThrough=function(t,e,n,r,i){var s,a,l,h,u;return null==e&&(e=this.toSnakeCase(t.modelName)),a={},null==r&&(r=this.toSnakeCase(this.modelName+"_id")),null==i&&(i=this.toSnakeCase(t.modelName)+"_id"),a[r]="integer",a[i]="integer",n.attributes(a),l={},l[r]=this,l[i]=t,n.foreignKeys(l),this.relations[e]={type:"hasManyThrough",otherModel:t,linkModel:n,foreignKeyAttribute:r,otherModelForeignKeyAttribute:i},s=this,this.instanceClass.prototype[e]=function(){if(arguments.length>0)throw Error("Cannot set a hasManyThrough relation");return null==this[e+"_hasManyThrough_collection"]&&(this[e+"_hasManyThrough_collection"]=o.create({record:this,model:s,otherModel:t,linkModel:n,thisFkAttr:r,thatFkAttr:i})),this[e+"_hasManyThrough_collection"]},u=function(t,e){var i,o,s,a,l;for(null==e&&(e={}),a=n.findByAttribute(r,t.id),l=[],o=0,s=a.length;s>o;o++)i=a[o],l.push(i.destroy(e));return l},this.bind("destroy",u),h=function(t,e){var r,o,s,a,l;for(null==e&&(e={}),a=n.findByAttribute(i,t.id),l=[],o=0,s=a.length;s>o;o++)r=a[o],l.push(r.destroy(e));return l},t.bind("destroy",h)},n.prototype.hasManyThroughPoly=function(t,e,n,r,i,o){var a,l,h,u,c;return null==e&&(e=this.toSnakeCase(t.modelName)),null==r&&(r=this.toSnakeCase(this.modelName+"_id")),null==i&&(i=e+"_id"),null==o&&(o=e+"_type"),l={},l[r]="integer",l[i]="integer",l[o]="string",n.attributes(l),h={},h[r]=this,n.foreignKeys(h),h={},h[i]=o,n.polyForeignKeys(h),this.relations[e]={type:"hasManyThroughPoly",otherModel:t,linkModel:n,foreignKeyAttribute:r,otherModelForeignKeyAttribute:i,otherModelModelTypeAttribute:o},a=this,this.instanceClass.prototype[e]=function(){if(arguments.length>0)throw Error("Cannot set a hasManyThroughPoly relation");return null==this[e+"_hasManyThroughPoly_collection"]&&(this[e+"_hasManyThroughPoly_collection"]=s.create({record:this,model:a,otherModel:t,linkModel:n,thisFkAttr:r,thatFkAttr:i,thatTypeAttr:o})),this[e+"_hasManyThroughPoly_collection"]},c=function(t,e){var i,o,s,a,l,h;for(null==e&&(e={}),o={},o[r]=t.id,l=n.findByAttributes(o),h=[],s=0,a=l.length;a>s;s++)i=l[s],h.push(i.destroy(e));return h},this.bind("destroy",c),u=function(t,e){var r,s,a,l,h,u;for(null==e&&(e={}),s={},s[i]=t.id,s[o]=t.modelClass.modelName,h=n.findByAttributes(s),u=[],a=0,l=h.length;l>a;a++)r=h[a],u.push(r.destroy(e));return u},t.bind("destroy",u)},n.prototype.hasManyThroughPolyReverse=function(t,e,n,r,i,o){var s;return null==e&&(e=this.toSnakeCase(t.modelName)),null==r&&(r=this.toSnakeCase(this.modelName+"_id")),null==i&&(i=e+"_id"),null==o&&(o=e+"_type"),this.relations[e]={type:"hasManyThroughPolyReverse",otherModel:t,linkModel:n,foreignKeyAttribute:r,otherModelForeignKeyAttribute:i,otherModelModelTypeAttribute:o},(null==n.fks[r]||null==n.polyFks[i]||n.polyFks[i]===(null!=o))&&console.error("WARNING: hasManyThroughPolyReverse - "+r+", "+i+" or "+o+" do not exist on link model '"+n.modelName+"' - there should be an existing hasManyThroughPoly to support this hasManyThroughPolyReverse"),s=this,this.instanceClass.prototype[e]=function(){if(arguments.length>0)throw Error("Cannot set a hasManyThroughPolyReverse relation");return null==this[e+"_hasManyThroughPolyReverse_collection"]&&(this[e+"_hasManyThroughPolyReverse_collection"]=a.create({record:this,model:s,otherModel:t,linkModel:n,thisFkAttr:r,thatFkAttr:i,thatTypeAttr:o})),this[e+"_hasManyThroughPolyReverse_collection"]}},n.prototype.all=function(){return _(this.records).values()},n.prototype.allAsMap=function(){return this.records},n.prototype.count=function(){return _(this.records).keys().length},n.prototype.findById=function(t){return null==t?void 0:this.records[t]},n.prototype.findAll=function(t){var e,n,r,i;for(n=[],r=0,i=t.length;i>r;r++)e=t[r],null!=this.exists(e)&&n.push(this.records[e]);return n},n.prototype.select=function(t){return this.findAll(this.selectIds(t))},n.prototype.selectIds=function(t){var e,n,r,i;r=[],i=this.records;for(e in i)n=i[e],t(n)&&r.push(e);return r},n.prototype.selectAsMap=function(t){var e,n,r,i;r={},i=this.records;for(e in i)n=i[e],t(n)&&(r[e]=n);return r},n.prototype.findByAttribute=function(t,e){var n;return n={},n[t]=e,this.findByAttributes(n)},n.prototype.findByAttributes=function(t){var e,n,r,i,o,s,a,l;s=[];for(e in t)l=t[e],this.hasIndex(e)?s.push(this.getIndexFor(e,l)):s.push(this.selectAsMap(function(t){return t[e]===l}));for(i=s.pop()||{};s.length>0;){a=s.pop(),o={};for(n in a)r=a[n],null!=i[n]&&(o[n]=r);i=o}return _(i).values()},n.prototype.exists=function(t){return null!=this.records[t]},n.prototype.initInstance=function(t){var e,n,r,i;e=this._getInstance(),i=this.attrs;for(n in i)r=i[n],null!=t&&null!=t[n]?e.set(n,t[n]):e.set(n,null);return e.set("id",this._generateId()),e},n.prototype.createFromValues=function(t){var e;return e=this.initInstance(t),e.save(),e},n.prototype.loadInstance=function(t,e){return null==e&&(e={}),this.trigger("load",t)},n.prototype.createInstance=function(t,e){var n;return null==e&&(e={}),n=t.id,this.exists(n)&&d.error("createInstance: ID Already Exists","collection","model",this.name,"id",n),this.records[n]=t,this.addToIndexes(t),e.disableModelCreateEvent||this.trigger("create",t,e),e.disableModelChangeEvent||this.trigger("change",t,e),t},n.prototype.updateInstance=function(t,e){var n;return null==e&&(e={}),e.disableModelUpdateEvent||this.trigger("update",t,e),e.disableModelChangeEvent||this.trigger("change",t,e),n=t.id,this.exists(n)?void 0:d.error("updateInstance: ID does not exist","collection","model",this.name,"id",n)},n.prototype.destroyInstance=function(t,e){var n;return null==e&&(e={}),n=t.id,this.exists(n)||d.error("destroyInstance: ID does not exist","collection","model",this.name,"id",n),delete this.records[t.id],t.modelClass.removeFromIndexes(t),e.disableModelDestroyEvent||this.trigger("destroy",t,e),e.disableModelChangeEvent?void 0:this.trigger("change",t,e)},n.prototype.toSnakeCase=function(t){var e;return e=t.replace(/[A-Z]{1,1}/g,function(t){return"_"+t.toLowerCase()}),e.replace(/^_/,"")},n.prototype._getInstance=function(){return this.instanceClass.create({modelClass:this})},n.prototype._generateId=function(){return"c-"+n.idCount++},n.prototype.index=function(t,n,r){var i;if(null==n&&(n="map"),null==this.indexes[t]){if(i=e.getIndexClassType(n),null!=i)return this.indexes[t]=i.create({modelClass:this,attribute:t,options:r});throw Error("Model: Index Type "+n+" is not supported")}return this.rebuildIndex(t)},n.prototype.hasIndex=function(t){return null!=this.indexes[t]},n.prototype.getIndexFor=function(t,e){if(null==this.indexes[t])throw Error("Model.rebuildIndex: Index "+t+" does not exist");return this.indexes[t].load(e)},n.prototype.updateIndex=function(t,e,n,r){if(null==this.indexes[t])throw Error("Model.rebuildIndex: Index "+t+" does not exist");return this.indexes[t].update(e,n,r)},n.prototype.addToIndexes=function(t){var e,n,r,i;r=this.indexes,i=[];for(e in r)n=r[e],i.push(n.add(t));return i},n.prototype.removeFromIndexes=function(t){var e,n,r,i;r=this.indexes,i=[];for(e in r)n=r[e],i.push(n.remove(t));return i},n.prototype.rebuildIndex=function(t){if(null==this.indexes[t])throw Error("Model.rebuildIndex: Index "+t+" does not exist");return this.indexes[t].rebuild()},n.prototype.dropIndex=function(t){return delete this.indexes[t]},n.prototype.rebuildAllIndexes=function(){var t,e,n,r,i;for(r=_(this.indexes).keys(),i=[],e=0,n=r.length;n>e;e++)t=r[e],i.push(this.rebuildIndex(t));return i},n}(h)}).call(this)}),t.define("/model-localstorage.coffee",function(t){(function(){var e,n,r,i;e=t("./model").Model,n=t("./util"),i={},r={},e.extend({localStorage:function(t){var e,n,o,s,a,l,h,u,c;return null==window.localStorage&&Mozart.error(this.modelName+".localStorage - localStorage not available in this browser"),null==t&&(t={}),null==(l=t.prefix)&&(t.prefix="MozartLS"),this.localStorageOptions=t,this.bind("load",this.loadLocalStorage),this.bind("create",this.createLocalStorage),this.bind("update",this.updateLocalStorage),this.bind("destroy",this.destroyLocalStorage),null==(h=i[s=this.modelName])&&(i[s]={}),null==(u=r[a=this.modelName])&&(r[a]={}),null==(c=Mozart.LocalStorage)&&(Mozart.LocalStorage=Mozart.MztObject.create({handleError:function(t,e,n){return Mozart.LocalStorage.trigger("notFound",t,e,n)}})),o=this.getLocalStoragePrefix(),this.instanceClass.extend({getLocalStorageId:function(){return this.modelClass.getLocalStorageId(this.id)},existsInLocalStorage:function(){var t;return t=this.modelClass.getLocalStorageId(this.id),null!=window.localStorage[this+("-"+t)]},loadLocalStorage:function(){return this.modelClass.loadLocalStorage(this)}}),n=window.localStorage[o+"-nextPK"],null==n&&(window.localStorage[o+"-nextPK"]="1"),e=window.localStorage[o+"-index"],null==e?window.localStorage[o+"-index"]="[]":void 0},getLocalStoragePrefix:function(){return this.localStorageOptions.prefix+"-"+this.modelName},registerLocalStorageId:function(t,e){if(null==i[this.modelName])throw Error("Model.registerLocalStorageId: "+this.modelName+" is not registered for localStorage.");return i[this.modelName][e]=t,r[this.modelName][t]=e},unRegisterLocalStorageId:function(t,e){return delete i[this.modelName][e],delete r[this.modelName][t]},getLocalStorageId:function(t){return r[this.modelName][t]},getLocalStorageClientId:function(t){return i[this.modelName][t]},toLocalStorageObject:function(t){var n,r,i,o,s,a,l,h;i={},a=this.attrs;for(n in a)o=a[n],"id"!==n&&(i[n]=t[n]);i.id=this.getLocalStorageId(t.id),l=this.fks;for(n in l)r=l[n],i[n]=r.getLocalStorageId(t[n]);h=this.polyFks;for(n in h)s=h[n],i[n]=null!=t[s]?e.models[t[s]].getLocalStorageId(t[n]):null;return i},toLocalStorageClientObject:function(t){var n,r,i,o,s,a,l,h;i={},a=this.attrs;for(n in a)o=a[n],"id"!==n&&(i[n]=t[n]);i.id=this.getLocalStorageClientId(t.id),l=this.fks;for(n in l)r=l[n],i[n]=r.getLocalStorageClientId(t[n]),i[n]===void 0&&(i[n]=null);h=this.polyFks;for(n in h)s=h[n],i[n]=null!=t[s]?e.models[t[s]].getLocalStorageClientId(t[n]):null;return i},loadAllLocalStorage:function(){var t,e,r,i,o,s;for(i=this.getLocalStoragePrefix(),e=JSON.parse(window.localStorage[i+"-index"]),o=0,s=e.length;s>o;o++)r=e[o],t=JSON.parse(window.localStorage[i+("-"+r)]),this._processLocalStorageLoad(r,t,this);return this.trigger("loadAllLocalStorageComplete"),n.log("localStorage","Model.loadAllLocalStorage.onComplete")},loadLocalStorage:function(t){var e;return e=t.modelClass.getLocalStorageId(t.id),this.loadLocalStorageId(e)},loadLocalStorageId:function(t){var e,n;return n=this.getLocalStoragePrefix(),e=window.localStorage[n+("-"+t)],null==e&&Mozart.LocalStorage.handleError(this,t,"record does not exist"),e=JSON.parse(e),e.id=t,this._processLocalStorageLoad(t,e,this)},_processLocalStorageLoad:function(t,e,r){var i,o,s;return i=r.getLocalStorageClientId(t),o=r.toLocalStorageClientObject(e),null!=i?(s=r.findById(i),s.copyFrom(o)):s=r.initInstance(e),s.save({disableModelCreateEvent:!0,disableModelUpdateEvent:!0}),r.registerLocalStorageId(s.id,t),n.log("localStorage","Model._processLocalStorageLoad.onSuccess",e,r),r.trigger("loadLocalStorageComplete",s)},createLocalStorage:function(t){var e,r,i,o;return e=t.modelClass.toLocalStorageObject(t),o=t.modelClass.getLocalStoragePrefix(),i=parseInt(window.localStorage[o+"-nextPK"]),window.localStorage[o+"-nextPK"]=""+(i+1),window.localStorage[o+("-"+i)]=JSON.stringify(e),t.modelClass.registerLocalStorageId(t.id,i),r=JSON.parse(window.localStorage[o+"-index"]),r.push(i),window.localStorage[o+"-index"]=JSON.stringify(r),n.log("localStorage","Model.createLocalStorageComplete",t),t.modelClass.trigger("createLocalStorageComplete",t)},updateLocalStorage:function(t){var e,r,i;return r=t.modelClass.getLocalStorageId(t.id),null!=r?(e=t.modelClass.toLocalStorageObject(t),i=t.modelClass.getLocalStoragePrefix(),null==window.localStorage[i+("-"+r)]&&Mozart.LocalStorage.handleError(t.modelClass,r,"updateLocalStorage: record does not exist"),window.localStorage[i+("-"+r)]=JSON.stringify(e),t.modelClass.trigger("updateLocalStorageComplete",t),n.log("localStorage","Model.updateLocalStorage.onComplete",t)):void 0},destroyLocalStorage:function(t){var e,r,i;return r=t.modelClass.getLocalStorageId(t.id),null!=r?(i=t.modelClass.getLocalStoragePrefix(),null==window.localStorage[i+("-"+r)]&&Mozart.LocalStorage.handleError(t.modelClass,r,"destroyLocalStorage: record does not exist"),window.localStorage.removeItem(i+("-"+r)),t.modelClass.unRegisterLocalStorageId(t.id,r),e=JSON.parse(window.localStorage[i+"-index"]),e=_.without(e,r),window.localStorage[i+"-index"]=JSON.stringify(e),n.log("localStorage","Model.destroyLocalStorage.onSuccess",t),t.modelClass.trigger("destroyLocalStorageComplete",r)):void 0},destroyAllLocalStorage:function(){var t,e,n,o,s;for(n=this.getLocalStoragePrefix(),e=JSON.parse(window.localStorage[n+"-index"]),o=0,s=e.length;s>o;o++)t=e[o],window.localStorage.removeItem(n+("-"+t));return window.localStorage[n+"-index"]="[]",window.localStorage[n+"-nextPK"]="1",i[this.modelName]={},r[this.modelName]={}}})}).call(this)}),t.define("/route.coffee",function(t,e,n){(function(){var e,r,i,o=function(t,e){return function(){return t.apply(e,arguments)}},s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var r in e)s.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};i=t("./util"),e=t("./object").MztObject,n.Route=r=function(t){function e(){return this.doTitle=o(this.doTitle,this),this.canEnter=o(this.canEnter,this),this.canExit=o(this.canExit,this),e.__super__.constructor.apply(this,arguments)}return a(e,t),e.prototype.init=function(){return null!=this.path&&this.path.length>0||i.warn("Route must have a path",this),null==this.viewClass?i.warn("Route must have a viewClass",this):void 0},e.prototype.canExit=function(){return!(null!=this.exit)||this.exit()===!0},e.prototype.canEnter=function(t){return!(null!=this.enter)||this.enter(t)===!0},e.prototype.doTitle=function(){return null!=this.title?document.title="function"==typeof this.title?this.title(this):this.title:void 0},e}(e)}).call(this)}),t.define("/switch-view.coffee",function(t,e,n){(function(){var e,r,i=function(t,e){return function(){return t.apply(e,arguments)}},o={}.hasOwnProperty,s=function(t,e){function n(){this.constructor=t}for(var r in e)o.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};r=t("./view").View,n.SwitchView=e=function(t){function e(){return this.beforeRender=i(this.beforeRender,this),e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.beforeRender=function(){var t;return t=HandlebarsTemplates[this.templateBase+"/"+this.content[this.templateField]],null!=t?this.templateFunction=t:(Util.log("views","SwitchView: No view found for "+this.templateBase+"/"+this.content[this.templateField]),this.templateFunction=function(){return""})},e}(r)}).call(this)}),t.define("/dynamic-view.coffee",function(t,e,n){(function(){var e,r,i,o=function(t,e){return function(){return t.apply(e,arguments)}},s={}.hasOwnProperty,a=function(t,e){function n(){this.constructor=t}for(var r in e)s.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};i=t("./view").View,r=t("./util"),n.DynamicView=e=function(t){function e(){return this.createText=o(this.createText,this),this.createView=o(this.createView,this),this.afterRender=o(this.afterRender,this),this.init=o(this.init,this),e.__super__.constructor.apply(this,arguments)}return a(e,t),e.prototype.skipTemplate=!0,e.prototype.init=function(){return e.__super__.init.apply(this,arguments),r.log("dynamicview","init"),null!=this.schema?this.bind("change:schema",this.afterRender):void 0},e.prototype.afterRender=function(){var t,e,n,i,o;if(this.releaseChildren(),this.element.empty(),!r.isArray(this.schema))return r.warn("DynamicView "+id+": schema is not an array"),void 0;for(i=this.schema,o=[],e=0,n=i.length;n>e;e++)t=i[e],null!=t.viewClass?o.push(this.createView(t)):o.push(this.createText(t));return o},e.prototype.createView=function(t){var e,n;return n=r._getPath(t.viewClass),delete t.viewClass,t.parent=this,e=this.layout.createView(n,t),this.element.append(e.createElement()),this.addView(e),this.layout.queueRenderView(e)},e.prototype.createText=function(t){return this.element.append(t)},e}(i)}).call(this)}),t.define("/cookies.coffee",function(t,e,n){(function(){var e,r,i={}.hasOwnProperty,o=function(t,e){function n(){this.constructor=t}for(var r in e)i.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};r=t("./object").MztObject,n.Cookies=e=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return o(e,t),e.setCookie=function(t,e,n){var r,i,o,s,a,l;return n=n||{},void 0!==document.cookie&&(n.path||(n.path="/"),s=""+encodeURIComponent(t)+"="+encodeURIComponent(e),a=n.path?";path="+n.path:"",r=n.domain?";domain="+n.domain:"",o=n["max-age"]?";max-age="+n["max-age"]:"",i="",n.expires instanceof Date&&(i=";expires="+n.expires.toUTCString()),l=n.secure?";secure":"",document.cookie=s+a+r+o+i+l),this},e.getCookie=function(t){var e,n,r,i,o,s;for(n=document.cookie.split(/;\s*/),o=0,s=n.length;s>o;o++)if(e=n[o],i=e.split("="),r=decodeURIComponent(i[0]),r===t)return decodeURIComponent(i[1]);return null},e.removeCookie=function(t){var e;return e=new Date,e.setTime(e.getTime()-1),this.setCookie(t,"",{expires:e}),this},e.hasCookie=function(t){return null!==this.getCookie(t)},e}(r)}).call(this)}),t.define("/mozart.coffee",function(t,e,n,r,i,o,s){(function(){var e,n,r,i,o,a,l,h,u={}.hasOwnProperty;for(e={version:"0.1.8",versionDate:new Date(2013,6,1),Plugins:{}},l=[t("./collection"),t("./control"),t("./controller"),t("./data-index"),t("./dom-manager"),t("./events"),t("./handlebars"),t("./http"),t("./layout"),t("./model-instance"),t("./model-instancecollection"),t("./model-onetomanycollection"),t("./model-onetomanypolycollection"),t("./model-manytomanycollection"),t("./model-manytomanypolycollection"),t("./model-manytomanypolyreversecollection"),t("./model-ajax"),t("./model-localstorage"),t("./model"),t("./object"),t("./route"),t("./router"),t("./switch-view"),t("./util"),t("./view"),t("./dynamic-view"),t("./cookies")],o=0,a=l.length;a>o;o++){r=l[o];
4
+ for(i in r)u.call(r,i)&&(n=r[i],e[i]=n)}null!=s.module?r.exports=e:null!=(null!=(h=s.define)?h.amd:void 0)?define("mozart",e):s.Mozart=e}).call(this)}),t("/mozart.coffee")})();
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mozart-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sasha Gerrand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-02 00:00:00.000000000 Z
11
+ date: 2013-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,7 +39,35 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: sass
42
+ name: handlebars-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jquery-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: underscore-rails
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
73
  - - ! '>='
@@ -67,14 +95,14 @@ files:
67
95
  - lib/mozart-rails.rb
68
96
  - lib/generators/mozart/install/install_generator.rb
69
97
  - lib/mozart/assert_select.rb
98
+ - lib/mozart/rails/assets.rb
70
99
  - lib/mozart/rails/engine.rb
71
100
  - lib/mozart/rails/railtie.rb
72
101
  - lib/mozart/rails/version.rb
73
102
  - lib/mozart/rails.rb
74
- - vendor/assets/javascripts/handlebars.js
75
- - vendor/assets/javascripts/jquery.js
103
+ - vendor/assets/javascripts/mozart-all.js
104
+ - vendor/assets/javascripts/mozart.js
76
105
  - vendor/assets/javascripts/mozart.min.js
77
- - vendor/assets/javascripts/underscore.js
78
106
  homepage: https://mozart.io
79
107
  licenses:
80
108
  - MIT
@@ -1,1920 +0,0 @@
1
- // lib/handlebars/base.js
2
-
3
- /*jshint eqnull:true*/
4
- this.Handlebars = {};
5
-
6
- (function(Handlebars) {
7
-
8
- Handlebars.VERSION = "1.0.rc.1";
9
-
10
- Handlebars.helpers = {};
11
- Handlebars.partials = {};
12
-
13
- Handlebars.registerHelper = function(name, fn, inverse) {
14
- if(inverse) { fn.not = inverse; }
15
- this.helpers[name] = fn;
16
- };
17
-
18
- Handlebars.registerPartial = function(name, str) {
19
- this.partials[name] = str;
20
- };
21
-
22
- Handlebars.registerHelper('helperMissing', function(arg) {
23
- if(arguments.length === 2) {
24
- return undefined;
25
- } else {
26
- throw new Error("Could not find property '" + arg + "'");
27
- }
28
- });
29
-
30
- var toString = Object.prototype.toString, functionType = "[object Function]";
31
-
32
- Handlebars.registerHelper('blockHelperMissing', function(context, options) {
33
- var inverse = options.inverse || function() {}, fn = options.fn;
34
-
35
-
36
- var ret = "";
37
- var type = toString.call(context);
38
-
39
- if(type === functionType) { context = context.call(this); }
40
-
41
- if(context === true) {
42
- return fn(this);
43
- } else if(context === false || context == null) {
44
- return inverse(this);
45
- } else if(type === "[object Array]") {
46
- if(context.length > 0) {
47
- return Handlebars.helpers.each(context, options);
48
- } else {
49
- return inverse(this);
50
- }
51
- } else {
52
- return fn(context);
53
- }
54
- });
55
-
56
- Handlebars.K = function() {};
57
-
58
- Handlebars.createFrame = Object.create || function(object) {
59
- Handlebars.K.prototype = object;
60
- var obj = new Handlebars.K();
61
- Handlebars.K.prototype = null;
62
- return obj;
63
- };
64
-
65
- Handlebars.registerHelper('each', function(context, options) {
66
- var fn = options.fn, inverse = options.inverse;
67
- var ret = "", data;
68
-
69
- if (options.data) {
70
- data = Handlebars.createFrame(options.data);
71
- }
72
-
73
- if(context && context.length > 0) {
74
- for(var i=0, j=context.length; i<j; i++) {
75
- if (data) { data.index = i; }
76
- ret = ret + fn(context[i], { data: data });
77
- }
78
- } else {
79
- ret = inverse(this);
80
- }
81
- return ret;
82
- });
83
-
84
- Handlebars.registerHelper('if', function(context, options) {
85
- var type = toString.call(context);
86
- if(type === functionType) { context = context.call(this); }
87
-
88
- if(!context || Handlebars.Utils.isEmpty(context)) {
89
- return options.inverse(this);
90
- } else {
91
- return options.fn(this);
92
- }
93
- });
94
-
95
- Handlebars.registerHelper('unless', function(context, options) {
96
- var fn = options.fn, inverse = options.inverse;
97
- options.fn = inverse;
98
- options.inverse = fn;
99
-
100
- return Handlebars.helpers['if'].call(this, context, options);
101
- });
102
-
103
- Handlebars.registerHelper('with', function(context, options) {
104
- return options.fn(context);
105
- });
106
-
107
- Handlebars.registerHelper('log', function(context) {
108
- Handlebars.log(context);
109
- });
110
-
111
- }(this.Handlebars));
112
- ;
113
- // lib/handlebars/compiler/parser.js
114
- /* Jison generated parser */
115
- var handlebars = (function(){
116
- var parser = {trace: function trace() { },
117
- yy: {},
118
- symbols_: {"error":2,"root":3,"program":4,"EOF":5,"statements":6,"simpleInverse":7,"statement":8,"openInverse":9,"closeBlock":10,"openBlock":11,"mustache":12,"partial":13,"CONTENT":14,"COMMENT":15,"OPEN_BLOCK":16,"inMustache":17,"CLOSE":18,"OPEN_INVERSE":19,"OPEN_ENDBLOCK":20,"path":21,"OPEN":22,"OPEN_UNESCAPED":23,"OPEN_PARTIAL":24,"params":25,"hash":26,"DATA":27,"param":28,"STRING":29,"INTEGER":30,"BOOLEAN":31,"hashSegments":32,"hashSegment":33,"ID":34,"EQUALS":35,"pathSegments":36,"SEP":37,"$accept":0,"$end":1},
119
- terminals_: {2:"error",5:"EOF",14:"CONTENT",15:"COMMENT",16:"OPEN_BLOCK",18:"CLOSE",19:"OPEN_INVERSE",20:"OPEN_ENDBLOCK",22:"OPEN",23:"OPEN_UNESCAPED",24:"OPEN_PARTIAL",27:"DATA",29:"STRING",30:"INTEGER",31:"BOOLEAN",34:"ID",35:"EQUALS",37:"SEP"},
120
- productions_: [0,[3,2],[4,3],[4,1],[4,0],[6,1],[6,2],[8,3],[8,3],[8,1],[8,1],[8,1],[8,1],[11,3],[9,3],[10,3],[12,3],[12,3],[13,3],[13,4],[7,2],[17,3],[17,2],[17,2],[17,1],[17,1],[25,2],[25,1],[28,1],[28,1],[28,1],[28,1],[28,1],[26,1],[32,2],[32,1],[33,3],[33,3],[33,3],[33,3],[33,3],[21,1],[36,3],[36,1]],
121
- performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
122
-
123
- var $0 = $$.length - 1;
124
- switch (yystate) {
125
- case 1: return $$[$0-1];
126
- break;
127
- case 2: this.$ = new yy.ProgramNode($$[$0-2], $$[$0]);
128
- break;
129
- case 3: this.$ = new yy.ProgramNode($$[$0]);
130
- break;
131
- case 4: this.$ = new yy.ProgramNode([]);
132
- break;
133
- case 5: this.$ = [$$[$0]];
134
- break;
135
- case 6: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
136
- break;
137
- case 7: this.$ = new yy.BlockNode($$[$0-2], $$[$0-1].inverse, $$[$0-1], $$[$0]);
138
- break;
139
- case 8: this.$ = new yy.BlockNode($$[$0-2], $$[$0-1], $$[$0-1].inverse, $$[$0]);
140
- break;
141
- case 9: this.$ = $$[$0];
142
- break;
143
- case 10: this.$ = $$[$0];
144
- break;
145
- case 11: this.$ = new yy.ContentNode($$[$0]);
146
- break;
147
- case 12: this.$ = new yy.CommentNode($$[$0]);
148
- break;
149
- case 13: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
150
- break;
151
- case 14: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
152
- break;
153
- case 15: this.$ = $$[$0-1];
154
- break;
155
- case 16: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
156
- break;
157
- case 17: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1], true);
158
- break;
159
- case 18: this.$ = new yy.PartialNode($$[$0-1]);
160
- break;
161
- case 19: this.$ = new yy.PartialNode($$[$0-2], $$[$0-1]);
162
- break;
163
- case 20:
164
- break;
165
- case 21: this.$ = [[$$[$0-2]].concat($$[$0-1]), $$[$0]];
166
- break;
167
- case 22: this.$ = [[$$[$0-1]].concat($$[$0]), null];
168
- break;
169
- case 23: this.$ = [[$$[$0-1]], $$[$0]];
170
- break;
171
- case 24: this.$ = [[$$[$0]], null];
172
- break;
173
- case 25: this.$ = [[new yy.DataNode($$[$0])], null];
174
- break;
175
- case 26: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
176
- break;
177
- case 27: this.$ = [$$[$0]];
178
- break;
179
- case 28: this.$ = $$[$0];
180
- break;
181
- case 29: this.$ = new yy.StringNode($$[$0]);
182
- break;
183
- case 30: this.$ = new yy.IntegerNode($$[$0]);
184
- break;
185
- case 31: this.$ = new yy.BooleanNode($$[$0]);
186
- break;
187
- case 32: this.$ = new yy.DataNode($$[$0]);
188
- break;
189
- case 33: this.$ = new yy.HashNode($$[$0]);
190
- break;
191
- case 34: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
192
- break;
193
- case 35: this.$ = [$$[$0]];
194
- break;
195
- case 36: this.$ = [$$[$0-2], $$[$0]];
196
- break;
197
- case 37: this.$ = [$$[$0-2], new yy.StringNode($$[$0])];
198
- break;
199
- case 38: this.$ = [$$[$0-2], new yy.IntegerNode($$[$0])];
200
- break;
201
- case 39: this.$ = [$$[$0-2], new yy.BooleanNode($$[$0])];
202
- break;
203
- case 40: this.$ = [$$[$0-2], new yy.DataNode($$[$0])];
204
- break;
205
- case 41: this.$ = new yy.IdNode($$[$0]);
206
- break;
207
- case 42: $$[$0-2].push($$[$0]); this.$ = $$[$0-2];
208
- break;
209
- case 43: this.$ = [$$[$0]];
210
- break;
211
- }
212
- },
213
- table: [{3:1,4:2,5:[2,4],6:3,8:4,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,11],22:[1,13],23:[1,14],24:[1,15]},{1:[3]},{5:[1,16]},{5:[2,3],7:17,8:18,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,19],20:[2,3],22:[1,13],23:[1,14],24:[1,15]},{5:[2,5],14:[2,5],15:[2,5],16:[2,5],19:[2,5],20:[2,5],22:[2,5],23:[2,5],24:[2,5]},{4:20,6:3,8:4,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,11],20:[2,4],22:[1,13],23:[1,14],24:[1,15]},{4:21,6:3,8:4,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,11],20:[2,4],22:[1,13],23:[1,14],24:[1,15]},{5:[2,9],14:[2,9],15:[2,9],16:[2,9],19:[2,9],20:[2,9],22:[2,9],23:[2,9],24:[2,9]},{5:[2,10],14:[2,10],15:[2,10],16:[2,10],19:[2,10],20:[2,10],22:[2,10],23:[2,10],24:[2,10]},{5:[2,11],14:[2,11],15:[2,11],16:[2,11],19:[2,11],20:[2,11],22:[2,11],23:[2,11],24:[2,11]},{5:[2,12],14:[2,12],15:[2,12],16:[2,12],19:[2,12],20:[2,12],22:[2,12],23:[2,12],24:[2,12]},{17:22,21:23,27:[1,24],34:[1,26],36:25},{17:27,21:23,27:[1,24],34:[1,26],36:25},{17:28,21:23,27:[1,24],34:[1,26],36:25},{17:29,21:23,27:[1,24],34:[1,26],36:25},{21:30,34:[1,26],36:25},{1:[2,1]},{6:31,8:4,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,11],22:[1,13],23:[1,14],24:[1,15]},{5:[2,6],14:[2,6],15:[2,6],16:[2,6],19:[2,6],20:[2,6],22:[2,6],23:[2,6],24:[2,6]},{17:22,18:[1,32],21:23,27:[1,24],34:[1,26],36:25},{10:33,20:[1,34]},{10:35,20:[1,34]},{18:[1,36]},{18:[2,24],21:41,25:37,26:38,27:[1,45],28:39,29:[1,42],30:[1,43],31:[1,44],32:40,33:46,34:[1,47],36:25},{18:[2,25]},{18:[2,41],27:[2,41],29:[2,41],30:[2,41],31:[2,41],34:[2,41],37:[1,48]},{18:[2,43],27:[2,43],29:[2,43],30:[2,43],31:[2,43],34:[2,43],37:[2,43]},{18:[1,49]},{18:[1,50]},{18:[1,51]},{18:[1,52],21:53,34:[1,26],36:25},{5:[2,2],8:18,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,11],20:[2,2],22:[1,13],23:[1,14],24:[1,15]},{14:[2,20],15:[2,20],16:[2,20],19:[2,20],22:[2,20],23:[2,20],24:[2,20]},{5:[2,7],14:[2,7],15:[2,7],16:[2,7],19:[2,7],20:[2,7],22:[2,7],23:[2,7],24:[2,7]},{21:54,34:[1,26],36:25},{5:[2,8],14:[2,8],15:[2,8],16:[2,8],19:[2,8],20:[2,8],22:[2,8],23:[2,8],24:[2,8]},{14:[2,14],15:[2,14],16:[2,14],19:[2,14],20:[2,14],22:[2,14],23:[2,14],24:[2,14]},{18:[2,22],21:41,26:55,27:[1,45],28:56,29:[1,42],30:[1,43],31:[1,44],32:40,33:46,34:[1,47],36:25},{18:[2,23]},{18:[2,27],27:[2,27],29:[2,27],30:[2,27],31:[2,27],34:[2,27]},{18:[2,33],33:57,34:[1,58]},{18:[2,28],27:[2,28],29:[2,28],30:[2,28],31:[2,28],34:[2,28]},{18:[2,29],27:[2,29],29:[2,29],30:[2,29],31:[2,29],34:[2,29]},{18:[2,30],27:[2,30],29:[2,30],30:[2,30],31:[2,30],34:[2,30]},{18:[2,31],27:[2,31],29:[2,31],30:[2,31],31:[2,31],34:[2,31]},{18:[2,32],27:[2,32],29:[2,32],30:[2,32],31:[2,32],34:[2,32]},{18:[2,35],34:[2,35]},{18:[2,43],27:[2,43],29:[2,43],30:[2,43],31:[2,43],34:[2,43],35:[1,59],37:[2,43]},{34:[1,60]},{14:[2,13],15:[2,13],16:[2,13],19:[2,13],20:[2,13],22:[2,13],23:[2,13],24:[2,13]},{5:[2,16],14:[2,16],15:[2,16],16:[2,16],19:[2,16],20:[2,16],22:[2,16],23:[2,16],24:[2,16]},{5:[2,17],14:[2,17],15:[2,17],16:[2,17],19:[2,17],20:[2,17],22:[2,17],23:[2,17],24:[2,17]},{5:[2,18],14:[2,18],15:[2,18],16:[2,18],19:[2,18],20:[2,18],22:[2,18],23:[2,18],24:[2,18]},{18:[1,61]},{18:[1,62]},{18:[2,21]},{18:[2,26],27:[2,26],29:[2,26],30:[2,26],31:[2,26],34:[2,26]},{18:[2,34],34:[2,34]},{35:[1,59]},{21:63,27:[1,67],29:[1,64],30:[1,65],31:[1,66],34:[1,26],36:25},{18:[2,42],27:[2,42],29:[2,42],30:[2,42],31:[2,42],34:[2,42],37:[2,42]},{5:[2,19],14:[2,19],15:[2,19],16:[2,19],19:[2,19],20:[2,19],22:[2,19],23:[2,19],24:[2,19]},{5:[2,15],14:[2,15],15:[2,15],16:[2,15],19:[2,15],20:[2,15],22:[2,15],23:[2,15],24:[2,15]},{18:[2,36],34:[2,36]},{18:[2,37],34:[2,37]},{18:[2,38],34:[2,38]},{18:[2,39],34:[2,39]},{18:[2,40],34:[2,40]}],
214
- defaultActions: {16:[2,1],24:[2,25],38:[2,23],55:[2,21]},
215
- parseError: function parseError(str, hash) {
216
- throw new Error(str);
217
- },
218
- parse: function parse(input) {
219
- var self = this, stack = [0], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
220
- this.lexer.setInput(input);
221
- this.lexer.yy = this.yy;
222
- this.yy.lexer = this.lexer;
223
- this.yy.parser = this;
224
- if (typeof this.lexer.yylloc == "undefined")
225
- this.lexer.yylloc = {};
226
- var yyloc = this.lexer.yylloc;
227
- lstack.push(yyloc);
228
- var ranges = this.lexer.options && this.lexer.options.ranges;
229
- if (typeof this.yy.parseError === "function")
230
- this.parseError = this.yy.parseError;
231
- function popStack(n) {
232
- stack.length = stack.length - 2 * n;
233
- vstack.length = vstack.length - n;
234
- lstack.length = lstack.length - n;
235
- }
236
- function lex() {
237
- var token;
238
- token = self.lexer.lex() || 1;
239
- if (typeof token !== "number") {
240
- token = self.symbols_[token] || token;
241
- }
242
- return token;
243
- }
244
- var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
245
- while (true) {
246
- state = stack[stack.length - 1];
247
- if (this.defaultActions[state]) {
248
- action = this.defaultActions[state];
249
- } else {
250
- if (symbol === null || typeof symbol == "undefined") {
251
- symbol = lex();
252
- }
253
- action = table[state] && table[state][symbol];
254
- }
255
- if (typeof action === "undefined" || !action.length || !action[0]) {
256
- var errStr = "";
257
- if (!recovering) {
258
- expected = [];
259
- for (p in table[state])
260
- if (this.terminals_[p] && p > 2) {
261
- expected.push("'" + this.terminals_[p] + "'");
262
- }
263
- if (this.lexer.showPosition) {
264
- errStr = "Parse error on line " + (yylineno + 1) + ":\n" + this.lexer.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'";
265
- } else {
266
- errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == 1?"end of input":"'" + (this.terminals_[symbol] || symbol) + "'");
267
- }
268
- this.parseError(errStr, {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected});
269
- }
270
- }
271
- if (action[0] instanceof Array && action.length > 1) {
272
- throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
273
- }
274
- switch (action[0]) {
275
- case 1:
276
- stack.push(symbol);
277
- vstack.push(this.lexer.yytext);
278
- lstack.push(this.lexer.yylloc);
279
- stack.push(action[1]);
280
- symbol = null;
281
- if (!preErrorSymbol) {
282
- yyleng = this.lexer.yyleng;
283
- yytext = this.lexer.yytext;
284
- yylineno = this.lexer.yylineno;
285
- yyloc = this.lexer.yylloc;
286
- if (recovering > 0)
287
- recovering--;
288
- } else {
289
- symbol = preErrorSymbol;
290
- preErrorSymbol = null;
291
- }
292
- break;
293
- case 2:
294
- len = this.productions_[action[1]][1];
295
- yyval.$ = vstack[vstack.length - len];
296
- yyval._$ = {first_line: lstack[lstack.length - (len || 1)].first_line, last_line: lstack[lstack.length - 1].last_line, first_column: lstack[lstack.length - (len || 1)].first_column, last_column: lstack[lstack.length - 1].last_column};
297
- if (ranges) {
298
- yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
299
- }
300
- r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
301
- if (typeof r !== "undefined") {
302
- return r;
303
- }
304
- if (len) {
305
- stack = stack.slice(0, -1 * len * 2);
306
- vstack = vstack.slice(0, -1 * len);
307
- lstack = lstack.slice(0, -1 * len);
308
- }
309
- stack.push(this.productions_[action[1]][0]);
310
- vstack.push(yyval.$);
311
- lstack.push(yyval._$);
312
- newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
313
- stack.push(newState);
314
- break;
315
- case 3:
316
- return true;
317
- }
318
- }
319
- return true;
320
- }
321
- };
322
- /* Jison generated lexer */
323
- var lexer = (function(){
324
- var lexer = ({EOF:1,
325
- parseError:function parseError(str, hash) {
326
- if (this.yy.parser) {
327
- this.yy.parser.parseError(str, hash);
328
- } else {
329
- throw new Error(str);
330
- }
331
- },
332
- setInput:function (input) {
333
- this._input = input;
334
- this._more = this._less = this.done = false;
335
- this.yylineno = this.yyleng = 0;
336
- this.yytext = this.matched = this.match = '';
337
- this.conditionStack = ['INITIAL'];
338
- this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0};
339
- if (this.options.ranges) this.yylloc.range = [0,0];
340
- this.offset = 0;
341
- return this;
342
- },
343
- input:function () {
344
- var ch = this._input[0];
345
- this.yytext += ch;
346
- this.yyleng++;
347
- this.offset++;
348
- this.match += ch;
349
- this.matched += ch;
350
- var lines = ch.match(/(?:\r\n?|\n).*/g);
351
- if (lines) {
352
- this.yylineno++;
353
- this.yylloc.last_line++;
354
- } else {
355
- this.yylloc.last_column++;
356
- }
357
- if (this.options.ranges) this.yylloc.range[1]++;
358
-
359
- this._input = this._input.slice(1);
360
- return ch;
361
- },
362
- unput:function (ch) {
363
- var len = ch.length;
364
- var lines = ch.split(/(?:\r\n?|\n)/g);
365
-
366
- this._input = ch + this._input;
367
- this.yytext = this.yytext.substr(0, this.yytext.length-len-1);
368
- //this.yyleng -= len;
369
- this.offset -= len;
370
- var oldLines = this.match.split(/(?:\r\n?|\n)/g);
371
- this.match = this.match.substr(0, this.match.length-1);
372
- this.matched = this.matched.substr(0, this.matched.length-1);
373
-
374
- if (lines.length-1) this.yylineno -= lines.length-1;
375
- var r = this.yylloc.range;
376
-
377
- this.yylloc = {first_line: this.yylloc.first_line,
378
- last_line: this.yylineno+1,
379
- first_column: this.yylloc.first_column,
380
- last_column: lines ?
381
- (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length:
382
- this.yylloc.first_column - len
383
- };
384
-
385
- if (this.options.ranges) {
386
- this.yylloc.range = [r[0], r[0] + this.yyleng - len];
387
- }
388
- return this;
389
- },
390
- more:function () {
391
- this._more = true;
392
- return this;
393
- },
394
- less:function (n) {
395
- this.unput(this.match.slice(n));
396
- },
397
- pastInput:function () {
398
- var past = this.matched.substr(0, this.matched.length - this.match.length);
399
- return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
400
- },
401
- upcomingInput:function () {
402
- var next = this.match;
403
- if (next.length < 20) {
404
- next += this._input.substr(0, 20-next.length);
405
- }
406
- return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, "");
407
- },
408
- showPosition:function () {
409
- var pre = this.pastInput();
410
- var c = new Array(pre.length + 1).join("-");
411
- return pre + this.upcomingInput() + "\n" + c+"^";
412
- },
413
- next:function () {
414
- if (this.done) {
415
- return this.EOF;
416
- }
417
- if (!this._input) this.done = true;
418
-
419
- var token,
420
- match,
421
- tempMatch,
422
- index,
423
- col,
424
- lines;
425
- if (!this._more) {
426
- this.yytext = '';
427
- this.match = '';
428
- }
429
- var rules = this._currentRules();
430
- for (var i=0;i < rules.length; i++) {
431
- tempMatch = this._input.match(this.rules[rules[i]]);
432
- if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
433
- match = tempMatch;
434
- index = i;
435
- if (!this.options.flex) break;
436
- }
437
- }
438
- if (match) {
439
- lines = match[0].match(/(?:\r\n?|\n).*/g);
440
- if (lines) this.yylineno += lines.length;
441
- this.yylloc = {first_line: this.yylloc.last_line,
442
- last_line: this.yylineno+1,
443
- first_column: this.yylloc.last_column,
444
- last_column: lines ? lines[lines.length-1].length-lines[lines.length-1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length};
445
- this.yytext += match[0];
446
- this.match += match[0];
447
- this.matches = match;
448
- this.yyleng = this.yytext.length;
449
- if (this.options.ranges) {
450
- this.yylloc.range = [this.offset, this.offset += this.yyleng];
451
- }
452
- this._more = false;
453
- this._input = this._input.slice(match[0].length);
454
- this.matched += match[0];
455
- token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]);
456
- if (this.done && this._input) this.done = false;
457
- if (token) return token;
458
- else return;
459
- }
460
- if (this._input === "") {
461
- return this.EOF;
462
- } else {
463
- return this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(),
464
- {text: "", token: null, line: this.yylineno});
465
- }
466
- },
467
- lex:function lex() {
468
- var r = this.next();
469
- if (typeof r !== 'undefined') {
470
- return r;
471
- } else {
472
- return this.lex();
473
- }
474
- },
475
- begin:function begin(condition) {
476
- this.conditionStack.push(condition);
477
- },
478
- popState:function popState() {
479
- return this.conditionStack.pop();
480
- },
481
- _currentRules:function _currentRules() {
482
- return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules;
483
- },
484
- topState:function () {
485
- return this.conditionStack[this.conditionStack.length-2];
486
- },
487
- pushState:function begin(condition) {
488
- this.begin(condition);
489
- }});
490
- lexer.options = {};
491
- lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
492
-
493
- var YYSTATE=YY_START
494
- switch($avoiding_name_collisions) {
495
- case 0:
496
- if(yy_.yytext.slice(-1) !== "\\") this.begin("mu");
497
- if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1), this.begin("emu");
498
- if(yy_.yytext) return 14;
499
-
500
- break;
501
- case 1: return 14;
502
- break;
503
- case 2:
504
- if(yy_.yytext.slice(-1) !== "\\") this.popState();
505
- if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1);
506
- return 14;
507
-
508
- break;
509
- case 3: return 24;
510
- break;
511
- case 4: return 16;
512
- break;
513
- case 5: return 20;
514
- break;
515
- case 6: return 19;
516
- break;
517
- case 7: return 19;
518
- break;
519
- case 8: return 23;
520
- break;
521
- case 9: return 23;
522
- break;
523
- case 10: yy_.yytext = yy_.yytext.substr(3,yy_.yyleng-5); this.popState(); return 15;
524
- break;
525
- case 11: return 22;
526
- break;
527
- case 12: return 35;
528
- break;
529
- case 13: return 34;
530
- break;
531
- case 14: return 34;
532
- break;
533
- case 15: return 37;
534
- break;
535
- case 16: /*ignore whitespace*/
536
- break;
537
- case 17: this.popState(); return 18;
538
- break;
539
- case 18: this.popState(); return 18;
540
- break;
541
- case 19: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\"/g,'"'); return 29;
542
- break;
543
- case 20: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\"/g,'"'); return 29;
544
- break;
545
- case 21: yy_.yytext = yy_.yytext.substr(1); return 27;
546
- break;
547
- case 22: return 31;
548
- break;
549
- case 23: return 31;
550
- break;
551
- case 24: return 30;
552
- break;
553
- case 25: return 34;
554
- break;
555
- case 26: yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 34;
556
- break;
557
- case 27: return 'INVALID';
558
- break;
559
- case 28: return 5;
560
- break;
561
- }
562
- };
563
- lexer.rules = [/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|$)))/,/^(?:\{\{>)/,/^(?:\{\{#)/,/^(?:\{\{\/)/,/^(?:\{\{\^)/,/^(?:\{\{\s*else\b)/,/^(?:\{\{\{)/,/^(?:\{\{&)/,/^(?:\{\{![\s\S]*?\}\})/,/^(?:\{\{)/,/^(?:=)/,/^(?:\.(?=[} ]))/,/^(?:\.\.)/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}\}\})/,/^(?:\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@[a-zA-Z]+)/,/^(?:true(?=[}\s]))/,/^(?:false(?=[}\s]))/,/^(?:[0-9]+(?=[}\s]))/,/^(?:[a-zA-Z0-9_$-]+(?=[=}\s\/.]))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:$)/];
564
- lexer.conditions = {"mu":{"rules":[3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28],"inclusive":false},"emu":{"rules":[2],"inclusive":false},"INITIAL":{"rules":[0,1,28],"inclusive":true}};
565
- return lexer;})()
566
- parser.lexer = lexer;
567
- function Parser () { this.yy = {}; }Parser.prototype = parser;parser.Parser = Parser;
568
- return new Parser;
569
- })();
570
- if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
571
- exports.parser = handlebars;
572
- exports.Parser = handlebars.Parser;
573
- exports.parse = function () { return handlebars.parse.apply(handlebars, arguments); }
574
- exports.main = function commonjsMain(args) {
575
- if (!args[1])
576
- throw new Error('Usage: '+args[0]+' FILE');
577
- var source, cwd;
578
- if (typeof process !== 'undefined') {
579
- source = require('fs').readFileSync(require('path').resolve(args[1]), "utf8");
580
- } else {
581
- source = require("file").path(require("file").cwd()).join(args[1]).read({charset: "utf-8"});
582
- }
583
- return exports.parser.parse(source);
584
- }
585
- if (typeof module !== 'undefined' && require.main === module) {
586
- exports.main(typeof process !== 'undefined' ? process.argv.slice(1) : require("system").args);
587
- }
588
- };
589
- ;
590
- // lib/handlebars/compiler/base.js
591
- Handlebars.Parser = handlebars;
592
-
593
- Handlebars.parse = function(string) {
594
- Handlebars.Parser.yy = Handlebars.AST;
595
- return Handlebars.Parser.parse(string);
596
- };
597
-
598
- Handlebars.print = function(ast) {
599
- return new Handlebars.PrintVisitor().accept(ast);
600
- };
601
-
602
- Handlebars.logger = {
603
- DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
604
-
605
- // override in the host environment
606
- log: function(level, str) {}
607
- };
608
-
609
- Handlebars.log = function(level, str) { Handlebars.logger.log(level, str); };
610
- ;
611
- // lib/handlebars/compiler/ast.js
612
- (function() {
613
-
614
- Handlebars.AST = {};
615
-
616
- Handlebars.AST.ProgramNode = function(statements, inverse) {
617
- this.type = "program";
618
- this.statements = statements;
619
- if(inverse) { this.inverse = new Handlebars.AST.ProgramNode(inverse); }
620
- };
621
-
622
- Handlebars.AST.MustacheNode = function(rawParams, hash, unescaped) {
623
- this.type = "mustache";
624
- this.escaped = !unescaped;
625
- this.hash = hash;
626
-
627
- var id = this.id = rawParams[0];
628
- var params = this.params = rawParams.slice(1);
629
-
630
- // a mustache is an eligible helper if:
631
- // * its id is simple (a single part, not `this` or `..`)
632
- var eligibleHelper = this.eligibleHelper = id.isSimple;
633
-
634
- // a mustache is definitely a helper if:
635
- // * it is an eligible helper, and
636
- // * it has at least one parameter or hash segment
637
- this.isHelper = eligibleHelper && (params.length || hash);
638
-
639
- // if a mustache is an eligible helper but not a definite
640
- // helper, it is ambiguous, and will be resolved in a later
641
- // pass or at runtime.
642
- };
643
-
644
- Handlebars.AST.PartialNode = function(id, context) {
645
- this.type = "partial";
646
-
647
- // TODO: disallow complex IDs
648
-
649
- this.id = id;
650
- this.context = context;
651
- };
652
-
653
- var verifyMatch = function(open, close) {
654
- if(open.original !== close.original) {
655
- throw new Handlebars.Exception(open.original + " doesn't match " + close.original);
656
- }
657
- };
658
-
659
- Handlebars.AST.BlockNode = function(mustache, program, inverse, close) {
660
- verifyMatch(mustache.id, close);
661
- this.type = "block";
662
- this.mustache = mustache;
663
- this.program = program;
664
- this.inverse = inverse;
665
-
666
- if (this.inverse && !this.program) {
667
- this.isInverse = true;
668
- }
669
- };
670
-
671
- Handlebars.AST.ContentNode = function(string) {
672
- this.type = "content";
673
- this.string = string;
674
- };
675
-
676
- Handlebars.AST.HashNode = function(pairs) {
677
- this.type = "hash";
678
- this.pairs = pairs;
679
- };
680
-
681
- Handlebars.AST.IdNode = function(parts) {
682
- this.type = "ID";
683
- this.original = parts.join(".");
684
-
685
- var dig = [], depth = 0;
686
-
687
- for(var i=0,l=parts.length; i<l; i++) {
688
- var part = parts[i];
689
-
690
- if(part === "..") { depth++; }
691
- else if(part === "." || part === "this") { this.isScoped = true; }
692
- else { dig.push(part); }
693
- }
694
-
695
- this.parts = dig;
696
- this.string = dig.join('.');
697
- this.depth = depth;
698
-
699
- // an ID is simple if it only has one part, and that part is not
700
- // `..` or `this`.
701
- this.isSimple = parts.length === 1 && !this.isScoped && depth === 0;
702
- };
703
-
704
- Handlebars.AST.DataNode = function(id) {
705
- this.type = "DATA";
706
- this.id = id;
707
- };
708
-
709
- Handlebars.AST.StringNode = function(string) {
710
- this.type = "STRING";
711
- this.string = string;
712
- };
713
-
714
- Handlebars.AST.IntegerNode = function(integer) {
715
- this.type = "INTEGER";
716
- this.integer = integer;
717
- };
718
-
719
- Handlebars.AST.BooleanNode = function(bool) {
720
- this.type = "BOOLEAN";
721
- this.bool = bool;
722
- };
723
-
724
- Handlebars.AST.CommentNode = function(comment) {
725
- this.type = "comment";
726
- this.comment = comment;
727
- };
728
-
729
- })();;
730
- // lib/handlebars/utils.js
731
- Handlebars.Exception = function(message) {
732
- var tmp = Error.prototype.constructor.apply(this, arguments);
733
-
734
- for (var p in tmp) {
735
- if (tmp.hasOwnProperty(p)) { this[p] = tmp[p]; }
736
- }
737
-
738
- this.message = tmp.message;
739
- };
740
- Handlebars.Exception.prototype = new Error();
741
-
742
- // Build out our basic SafeString type
743
- Handlebars.SafeString = function(string) {
744
- this.string = string;
745
- };
746
- Handlebars.SafeString.prototype.toString = function() {
747
- return this.string.toString();
748
- };
749
-
750
- (function() {
751
- var escape = {
752
- "&": "&amp;",
753
- "<": "&lt;",
754
- ">": "&gt;",
755
- '"': "&quot;",
756
- "'": "&#x27;",
757
- "`": "&#x60;"
758
- };
759
-
760
- var badChars = /[&<>"'`]/g;
761
- var possible = /[&<>"'`]/;
762
-
763
- var escapeChar = function(chr) {
764
- return escape[chr] || "&amp;";
765
- };
766
-
767
- Handlebars.Utils = {
768
- escapeExpression: function(string) {
769
- // don't escape SafeStrings, since they're already safe
770
- if (string instanceof Handlebars.SafeString) {
771
- return string.toString();
772
- } else if (string == null || string === false) {
773
- return "";
774
- }
775
-
776
- if(!possible.test(string)) { return string; }
777
- return string.replace(badChars, escapeChar);
778
- },
779
-
780
- isEmpty: function(value) {
781
- if (typeof value === "undefined") {
782
- return true;
783
- } else if (value === null) {
784
- return true;
785
- } else if (value === false) {
786
- return true;
787
- } else if(Object.prototype.toString.call(value) === "[object Array]" && value.length === 0) {
788
- return true;
789
- } else {
790
- return false;
791
- }
792
- }
793
- };
794
- })();;
795
- // lib/handlebars/compiler/compiler.js
796
-
797
- /*jshint eqnull:true*/
798
- Handlebars.Compiler = function() {};
799
- Handlebars.JavaScriptCompiler = function() {};
800
-
801
- (function(Compiler, JavaScriptCompiler) {
802
- // the foundHelper register will disambiguate helper lookup from finding a
803
- // function in a context. This is necessary for mustache compatibility, which
804
- // requires that context functions in blocks are evaluated by blockHelperMissing,
805
- // and then proceed as if the resulting value was provided to blockHelperMissing.
806
-
807
- Compiler.prototype = {
808
- compiler: Compiler,
809
-
810
- disassemble: function() {
811
- var opcodes = this.opcodes, opcode, out = [], params, param;
812
-
813
- for (var i=0, l=opcodes.length; i<l; i++) {
814
- opcode = opcodes[i];
815
-
816
- if (opcode.opcode === 'DECLARE') {
817
- out.push("DECLARE " + opcode.name + "=" + opcode.value);
818
- } else {
819
- params = [];
820
- for (var j=0; j<opcode.args.length; j++) {
821
- param = opcode.args[j];
822
- if (typeof param === "string") {
823
- param = "\"" + param.replace("\n", "\\n") + "\"";
824
- }
825
- params.push(param);
826
- }
827
- out.push(opcode.opcode + " " + params.join(" "));
828
- }
829
- }
830
-
831
- return out.join("\n");
832
- },
833
-
834
- guid: 0,
835
-
836
- compile: function(program, options) {
837
- this.children = [];
838
- this.depths = {list: []};
839
- this.options = options;
840
-
841
- // These changes will propagate to the other compiler components
842
- var knownHelpers = this.options.knownHelpers;
843
- this.options.knownHelpers = {
844
- 'helperMissing': true,
845
- 'blockHelperMissing': true,
846
- 'each': true,
847
- 'if': true,
848
- 'unless': true,
849
- 'with': true,
850
- 'log': true
851
- };
852
- if (knownHelpers) {
853
- for (var name in knownHelpers) {
854
- this.options.knownHelpers[name] = knownHelpers[name];
855
- }
856
- }
857
-
858
- return this.program(program);
859
- },
860
-
861
- accept: function(node) {
862
- return this[node.type](node);
863
- },
864
-
865
- program: function(program) {
866
- var statements = program.statements, statement;
867
- this.opcodes = [];
868
-
869
- for(var i=0, l=statements.length; i<l; i++) {
870
- statement = statements[i];
871
- this[statement.type](statement);
872
- }
873
- this.isSimple = l === 1;
874
-
875
- this.depths.list = this.depths.list.sort(function(a, b) {
876
- return a - b;
877
- });
878
-
879
- return this;
880
- },
881
-
882
- compileProgram: function(program) {
883
- var result = new this.compiler().compile(program, this.options);
884
- var guid = this.guid++, depth;
885
-
886
- this.usePartial = this.usePartial || result.usePartial;
887
-
888
- this.children[guid] = result;
889
-
890
- for(var i=0, l=result.depths.list.length; i<l; i++) {
891
- depth = result.depths.list[i];
892
-
893
- if(depth < 2) { continue; }
894
- else { this.addDepth(depth - 1); }
895
- }
896
-
897
- return guid;
898
- },
899
-
900
- block: function(block) {
901
- var mustache = block.mustache,
902
- program = block.program,
903
- inverse = block.inverse;
904
-
905
- if (program) {
906
- program = this.compileProgram(program);
907
- }
908
-
909
- if (inverse) {
910
- inverse = this.compileProgram(inverse);
911
- }
912
-
913
- var type = this.classifyMustache(mustache);
914
-
915
- if (type === "helper") {
916
- this.helperMustache(mustache, program, inverse);
917
- } else if (type === "simple") {
918
- this.simpleMustache(mustache);
919
-
920
- // now that the simple mustache is resolved, we need to
921
- // evaluate it by executing `blockHelperMissing`
922
- this.opcode('pushProgram', program);
923
- this.opcode('pushProgram', inverse);
924
- this.opcode('pushLiteral', '{}');
925
- this.opcode('blockValue');
926
- } else {
927
- this.ambiguousMustache(mustache, program, inverse);
928
-
929
- // now that the simple mustache is resolved, we need to
930
- // evaluate it by executing `blockHelperMissing`
931
- this.opcode('pushProgram', program);
932
- this.opcode('pushProgram', inverse);
933
- this.opcode('pushLiteral', '{}');
934
- this.opcode('ambiguousBlockValue');
935
- }
936
-
937
- this.opcode('append');
938
- },
939
-
940
- hash: function(hash) {
941
- var pairs = hash.pairs, pair, val;
942
-
943
- this.opcode('push', '{}');
944
-
945
- for(var i=0, l=pairs.length; i<l; i++) {
946
- pair = pairs[i];
947
- val = pair[1];
948
-
949
- this.accept(val);
950
- this.opcode('assignToHash', pair[0]);
951
- }
952
- },
953
-
954
- partial: function(partial) {
955
- var id = partial.id;
956
- this.usePartial = true;
957
-
958
- if(partial.context) {
959
- this.ID(partial.context);
960
- } else {
961
- this.opcode('push', 'depth0');
962
- }
963
-
964
- this.opcode('invokePartial', id.original);
965
- this.opcode('append');
966
- },
967
-
968
- content: function(content) {
969
- this.opcode('appendContent', content.string);
970
- },
971
-
972
- mustache: function(mustache) {
973
- var options = this.options;
974
- var type = this.classifyMustache(mustache);
975
-
976
- if (type === "simple") {
977
- this.simpleMustache(mustache);
978
- } else if (type === "helper") {
979
- this.helperMustache(mustache);
980
- } else {
981
- this.ambiguousMustache(mustache);
982
- }
983
-
984
- if(mustache.escaped && !options.noEscape) {
985
- this.opcode('appendEscaped');
986
- } else {
987
- this.opcode('append');
988
- }
989
- },
990
-
991
- ambiguousMustache: function(mustache, program, inverse) {
992
- var id = mustache.id, name = id.parts[0];
993
-
994
- this.opcode('getContext', id.depth);
995
-
996
- this.opcode('pushProgram', program);
997
- this.opcode('pushProgram', inverse);
998
-
999
- this.opcode('invokeAmbiguous', name);
1000
- },
1001
-
1002
- simpleMustache: function(mustache, program, inverse) {
1003
- var id = mustache.id;
1004
-
1005
- if (id.type === 'DATA') {
1006
- this.DATA(id);
1007
- } else if (id.parts.length) {
1008
- this.ID(id);
1009
- } else {
1010
- // Simplified ID for `this`
1011
- this.addDepth(id.depth);
1012
- this.opcode('getContext', id.depth);
1013
- this.opcode('pushContext');
1014
- }
1015
-
1016
- this.opcode('resolvePossibleLambda');
1017
- },
1018
-
1019
- helperMustache: function(mustache, program, inverse) {
1020
- var params = this.setupFullMustacheParams(mustache, program, inverse),
1021
- name = mustache.id.parts[0];
1022
-
1023
- if (this.options.knownHelpers[name]) {
1024
- this.opcode('invokeKnownHelper', params.length, name);
1025
- } else if (this.knownHelpersOnly) {
1026
- throw new Error("You specified knownHelpersOnly, but used the unknown helper " + name);
1027
- } else {
1028
- this.opcode('invokeHelper', params.length, name);
1029
- }
1030
- },
1031
-
1032
- ID: function(id) {
1033
- this.addDepth(id.depth);
1034
- this.opcode('getContext', id.depth);
1035
-
1036
- var name = id.parts[0];
1037
- if (!name) {
1038
- this.opcode('pushContext');
1039
- } else {
1040
- this.opcode('lookupOnContext', id.parts[0]);
1041
- }
1042
-
1043
- for(var i=1, l=id.parts.length; i<l; i++) {
1044
- this.opcode('lookup', id.parts[i]);
1045
- }
1046
- },
1047
-
1048
- DATA: function(data) {
1049
- this.options.data = true;
1050
- this.opcode('lookupData', data.id);
1051
- },
1052
-
1053
- STRING: function(string) {
1054
- this.opcode('pushString', string.string);
1055
- },
1056
-
1057
- INTEGER: function(integer) {
1058
- this.opcode('pushLiteral', integer.integer);
1059
- },
1060
-
1061
- BOOLEAN: function(bool) {
1062
- this.opcode('pushLiteral', bool.bool);
1063
- },
1064
-
1065
- comment: function() {},
1066
-
1067
- // HELPERS
1068
- opcode: function(name) {
1069
- this.opcodes.push({ opcode: name, args: [].slice.call(arguments, 1) });
1070
- },
1071
-
1072
- declare: function(name, value) {
1073
- this.opcodes.push({ opcode: 'DECLARE', name: name, value: value });
1074
- },
1075
-
1076
- addDepth: function(depth) {
1077
- if(isNaN(depth)) { throw new Error("EWOT"); }
1078
- if(depth === 0) { return; }
1079
-
1080
- if(!this.depths[depth]) {
1081
- this.depths[depth] = true;
1082
- this.depths.list.push(depth);
1083
- }
1084
- },
1085
-
1086
- classifyMustache: function(mustache) {
1087
- var isHelper = mustache.isHelper;
1088
- var isEligible = mustache.eligibleHelper;
1089
- var options = this.options;
1090
-
1091
- // if ambiguous, we can possibly resolve the ambiguity now
1092
- if (isEligible && !isHelper) {
1093
- var name = mustache.id.parts[0];
1094
-
1095
- if (options.knownHelpers[name]) {
1096
- isHelper = true;
1097
- } else if (options.knownHelpersOnly) {
1098
- isEligible = false;
1099
- }
1100
- }
1101
-
1102
- if (isHelper) { return "helper"; }
1103
- else if (isEligible) { return "ambiguous"; }
1104
- else { return "simple"; }
1105
- },
1106
-
1107
- pushParams: function(params) {
1108
- var i = params.length, param;
1109
-
1110
- while(i--) {
1111
- param = params[i];
1112
-
1113
- if(this.options.stringParams) {
1114
- if(param.depth) {
1115
- this.addDepth(param.depth);
1116
- }
1117
-
1118
- this.opcode('getContext', param.depth || 0);
1119
- this.opcode('pushStringParam', param.string);
1120
- } else {
1121
- this[param.type](param);
1122
- }
1123
- }
1124
- },
1125
-
1126
- setupMustacheParams: function(mustache) {
1127
- var params = mustache.params;
1128
- this.pushParams(params);
1129
-
1130
- if(mustache.hash) {
1131
- this.hash(mustache.hash);
1132
- } else {
1133
- this.opcode('pushLiteral', '{}');
1134
- }
1135
-
1136
- return params;
1137
- },
1138
-
1139
- // this will replace setupMustacheParams when we're done
1140
- setupFullMustacheParams: function(mustache, program, inverse) {
1141
- var params = mustache.params;
1142
- this.pushParams(params);
1143
-
1144
- this.opcode('pushProgram', program);
1145
- this.opcode('pushProgram', inverse);
1146
-
1147
- if(mustache.hash) {
1148
- this.hash(mustache.hash);
1149
- } else {
1150
- this.opcode('pushLiteral', '{}');
1151
- }
1152
-
1153
- return params;
1154
- }
1155
- };
1156
-
1157
- var Literal = function(value) {
1158
- this.value = value;
1159
- };
1160
-
1161
- JavaScriptCompiler.prototype = {
1162
- // PUBLIC API: You can override these methods in a subclass to provide
1163
- // alternative compiled forms for name lookup and buffering semantics
1164
- nameLookup: function(parent, name, type) {
1165
- if (/^[0-9]+$/.test(name)) {
1166
- return parent + "[" + name + "]";
1167
- } else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
1168
- return parent + "." + name;
1169
- }
1170
- else {
1171
- return parent + "['" + name + "']";
1172
- }
1173
- },
1174
-
1175
- appendToBuffer: function(string) {
1176
- if (this.environment.isSimple) {
1177
- return "return " + string + ";";
1178
- } else {
1179
- return "buffer += " + string + ";";
1180
- }
1181
- },
1182
-
1183
- initializeBuffer: function() {
1184
- return this.quotedString("");
1185
- },
1186
-
1187
- namespace: "Handlebars",
1188
- // END PUBLIC API
1189
-
1190
- compile: function(environment, options, context, asObject) {
1191
- this.environment = environment;
1192
- this.options = options || {};
1193
-
1194
- Handlebars.log(Handlebars.logger.DEBUG, this.environment.disassemble() + "\n\n");
1195
-
1196
- this.name = this.environment.name;
1197
- this.isChild = !!context;
1198
- this.context = context || {
1199
- programs: [],
1200
- aliases: { }
1201
- };
1202
-
1203
- this.preamble();
1204
-
1205
- this.stackSlot = 0;
1206
- this.stackVars = [];
1207
- this.registers = { list: [] };
1208
- this.compileStack = [];
1209
-
1210
- this.compileChildren(environment, options);
1211
-
1212
- var opcodes = environment.opcodes, opcode;
1213
-
1214
- this.i = 0;
1215
-
1216
- for(l=opcodes.length; this.i<l; this.i++) {
1217
- opcode = opcodes[this.i];
1218
-
1219
- if(opcode.opcode === 'DECLARE') {
1220
- this[opcode.name] = opcode.value;
1221
- } else {
1222
- this[opcode.opcode].apply(this, opcode.args);
1223
- }
1224
- }
1225
-
1226
- return this.createFunctionContext(asObject);
1227
- },
1228
-
1229
- nextOpcode: function() {
1230
- var opcodes = this.environment.opcodes, opcode = opcodes[this.i + 1];
1231
- return opcodes[this.i + 1];
1232
- },
1233
-
1234
- eat: function(opcode) {
1235
- this.i = this.i + 1;
1236
- },
1237
-
1238
- preamble: function() {
1239
- var out = [];
1240
-
1241
- if (!this.isChild) {
1242
- var namespace = this.namespace;
1243
- var copies = "helpers = helpers || " + namespace + ".helpers;";
1244
- if (this.environment.usePartial) { copies = copies + " partials = partials || " + namespace + ".partials;"; }
1245
- if (this.options.data) { copies = copies + " data = data || {};"; }
1246
- out.push(copies);
1247
- } else {
1248
- out.push('');
1249
- }
1250
-
1251
- if (!this.environment.isSimple) {
1252
- out.push(", buffer = " + this.initializeBuffer());
1253
- } else {
1254
- out.push("");
1255
- }
1256
-
1257
- // track the last context pushed into place to allow skipping the
1258
- // getContext opcode when it would be a noop
1259
- this.lastContext = 0;
1260
- this.source = out;
1261
- },
1262
-
1263
- createFunctionContext: function(asObject) {
1264
- var locals = this.stackVars.concat(this.registers.list);
1265
-
1266
- if(locals.length > 0) {
1267
- this.source[1] = this.source[1] + ", " + locals.join(", ");
1268
- }
1269
-
1270
- // Generate minimizer alias mappings
1271
- if (!this.isChild) {
1272
- var aliases = [];
1273
- for (var alias in this.context.aliases) {
1274
- this.source[1] = this.source[1] + ', ' + alias + '=' + this.context.aliases[alias];
1275
- }
1276
- }
1277
-
1278
- if (this.source[1]) {
1279
- this.source[1] = "var " + this.source[1].substring(2) + ";";
1280
- }
1281
-
1282
- // Merge children
1283
- if (!this.isChild) {
1284
- this.source[1] += '\n' + this.context.programs.join('\n') + '\n';
1285
- }
1286
-
1287
- if (!this.environment.isSimple) {
1288
- this.source.push("return buffer;");
1289
- }
1290
-
1291
- var params = this.isChild ? ["depth0", "data"] : ["Handlebars", "depth0", "helpers", "partials", "data"];
1292
-
1293
- for(var i=0, l=this.environment.depths.list.length; i<l; i++) {
1294
- params.push("depth" + this.environment.depths.list[i]);
1295
- }
1296
-
1297
- if (asObject) {
1298
- params.push(this.source.join("\n "));
1299
-
1300
- return Function.apply(this, params);
1301
- } else {
1302
- var functionSource = 'function ' + (this.name || '') + '(' + params.join(',') + ') {\n ' + this.source.join("\n ") + '}';
1303
- Handlebars.log(Handlebars.logger.DEBUG, functionSource + "\n\n");
1304
- return functionSource;
1305
- }
1306
- },
1307
-
1308
- // [blockValue]
1309
- //
1310
- // On stack, before: hash, inverse, program, value
1311
- // On stack, after: return value of blockHelperMissing
1312
- //
1313
- // The purpose of this opcode is to take a block of the form
1314
- // `{{#foo}}...{{/foo}}`, resolve the value of `foo`, and
1315
- // replace it on the stack with the result of properly
1316
- // invoking blockHelperMissing.
1317
- blockValue: function() {
1318
- this.context.aliases.blockHelperMissing = 'helpers.blockHelperMissing';
1319
-
1320
- var params = ["depth0"];
1321
- this.setupParams(0, params);
1322
-
1323
- this.replaceStack(function(current) {
1324
- params.splice(1, 0, current);
1325
- return current + " = blockHelperMissing.call(" + params.join(", ") + ")";
1326
- });
1327
- },
1328
-
1329
- // [ambiguousBlockValue]
1330
- //
1331
- // On stack, before: hash, inverse, program, value
1332
- // Compiler value, before: lastHelper=value of last found helper, if any
1333
- // On stack, after, if no lastHelper: same as [blockValue]
1334
- // On stack, after, if lastHelper: value
1335
- ambiguousBlockValue: function() {
1336
- this.context.aliases.blockHelperMissing = 'helpers.blockHelperMissing';
1337
-
1338
- var params = ["depth0"];
1339
- this.setupParams(0, params);
1340
-
1341
- var current = this.topStack();
1342
- params.splice(1, 0, current);
1343
-
1344
- this.source.push("if (!" + this.lastHelper + ") { " + current + " = blockHelperMissing.call(" + params.join(", ") + "); }");
1345
- },
1346
-
1347
- // [appendContent]
1348
- //
1349
- // On stack, before: ...
1350
- // On stack, after: ...
1351
- //
1352
- // Appends the string value of `content` to the current buffer
1353
- appendContent: function(content) {
1354
- this.source.push(this.appendToBuffer(this.quotedString(content)));
1355
- },
1356
-
1357
- // [append]
1358
- //
1359
- // On stack, before: value, ...
1360
- // On stack, after: ...
1361
- //
1362
- // Coerces `value` to a String and appends it to the current buffer.
1363
- //
1364
- // If `value` is truthy, or 0, it is coerced into a string and appended
1365
- // Otherwise, the empty string is appended
1366
- append: function() {
1367
- var local = this.popStack();
1368
- this.source.push("if(" + local + " || " + local + " === 0) { " + this.appendToBuffer(local) + " }");
1369
- if (this.environment.isSimple) {
1370
- this.source.push("else { " + this.appendToBuffer("''") + " }");
1371
- }
1372
- },
1373
-
1374
- // [appendEscaped]
1375
- //
1376
- // On stack, before: value, ...
1377
- // On stack, after: ...
1378
- //
1379
- // Escape `value` and append it to the buffer
1380
- appendEscaped: function() {
1381
- var opcode = this.nextOpcode(), extra = "";
1382
- this.context.aliases.escapeExpression = 'this.escapeExpression';
1383
-
1384
- if(opcode && opcode.opcode === 'appendContent') {
1385
- extra = " + " + this.quotedString(opcode.args[0]);
1386
- this.eat(opcode);
1387
- }
1388
-
1389
- this.source.push(this.appendToBuffer("escapeExpression(" + this.popStack() + ")" + extra));
1390
- },
1391
-
1392
- // [getContext]
1393
- //
1394
- // On stack, before: ...
1395
- // On stack, after: ...
1396
- // Compiler value, after: lastContext=depth
1397
- //
1398
- // Set the value of the `lastContext` compiler value to the depth
1399
- getContext: function(depth) {
1400
- if(this.lastContext !== depth) {
1401
- this.lastContext = depth;
1402
- }
1403
- },
1404
-
1405
- // [lookupOnContext]
1406
- //
1407
- // On stack, before: ...
1408
- // On stack, after: currentContext[name], ...
1409
- //
1410
- // Looks up the value of `name` on the current context and pushes
1411
- // it onto the stack.
1412
- lookupOnContext: function(name) {
1413
- this.pushStack(this.nameLookup('depth' + this.lastContext, name, 'context'));
1414
- },
1415
-
1416
- // [pushContext]
1417
- //
1418
- // On stack, before: ...
1419
- // On stack, after: currentContext, ...
1420
- //
1421
- // Pushes the value of the current context onto the stack.
1422
- pushContext: function() {
1423
- this.pushStackLiteral('depth' + this.lastContext);
1424
- },
1425
-
1426
- // [resolvePossibleLambda]
1427
- //
1428
- // On stack, before: value, ...
1429
- // On stack, after: resolved value, ...
1430
- //
1431
- // If the `value` is a lambda, replace it on the stack by
1432
- // the return value of the lambda
1433
- resolvePossibleLambda: function() {
1434
- this.context.aliases.functionType = '"function"';
1435
-
1436
- this.replaceStack(function(current) {
1437
- return "typeof " + current + " === functionType ? " + current + "() : " + current;
1438
- });
1439
- },
1440
-
1441
- // [lookup]
1442
- //
1443
- // On stack, before: value, ...
1444
- // On stack, after: value[name], ...
1445
- //
1446
- // Replace the value on the stack with the result of looking
1447
- // up `name` on `value`
1448
- lookup: function(name) {
1449
- this.replaceStack(function(current) {
1450
- return current + " == null || " + current + " === false ? " + current + " : " + this.nameLookup(current, name, 'context');
1451
- });
1452
- },
1453
-
1454
- // [lookupData]
1455
- //
1456
- // On stack, before: ...
1457
- // On stack, after: data[id], ...
1458
- //
1459
- // Push the result of looking up `id` on the current data
1460
- lookupData: function(id) {
1461
- this.pushStack(this.nameLookup('data', id, 'data'));
1462
- },
1463
-
1464
- // [pushStringParam]
1465
- //
1466
- // On stack, before: ...
1467
- // On stack, after: string, currentContext, ...
1468
- //
1469
- // This opcode is designed for use in string mode, which
1470
- // provides the string value of a parameter along with its
1471
- // depth rather than resolving it immediately.
1472
- pushStringParam: function(string) {
1473
- this.pushStackLiteral('depth' + this.lastContext);
1474
- this.pushString(string);
1475
- },
1476
-
1477
- // [pushString]
1478
- //
1479
- // On stack, before: ...
1480
- // On stack, after: quotedString(string), ...
1481
- //
1482
- // Push a quoted version of `string` onto the stack
1483
- pushString: function(string) {
1484
- this.pushStackLiteral(this.quotedString(string));
1485
- },
1486
-
1487
- // [push]
1488
- //
1489
- // On stack, before: ...
1490
- // On stack, after: expr, ...
1491
- //
1492
- // Push an expression onto the stack
1493
- push: function(expr) {
1494
- this.pushStack(expr);
1495
- },
1496
-
1497
- // [pushLiteral]
1498
- //
1499
- // On stack, before: ...
1500
- // On stack, after: value, ...
1501
- //
1502
- // Pushes a value onto the stack. This operation prevents
1503
- // the compiler from creating a temporary variable to hold
1504
- // it.
1505
- pushLiteral: function(value) {
1506
- this.pushStackLiteral(value);
1507
- },
1508
-
1509
- // [pushProgram]
1510
- //
1511
- // On stack, before: ...
1512
- // On stack, after: program(guid), ...
1513
- //
1514
- // Push a program expression onto the stack. This takes
1515
- // a compile-time guid and converts it into a runtime-accessible
1516
- // expression.
1517
- pushProgram: function(guid) {
1518
- if (guid != null) {
1519
- this.pushStackLiteral(this.programExpression(guid));
1520
- } else {
1521
- this.pushStackLiteral(null);
1522
- }
1523
- },
1524
-
1525
- // [invokeHelper]
1526
- //
1527
- // On stack, before: hash, inverse, program, params..., ...
1528
- // On stack, after: result of helper invocation
1529
- //
1530
- // Pops off the helper's parameters, invokes the helper,
1531
- // and pushes the helper's return value onto the stack.
1532
- //
1533
- // If the helper is not found, `helperMissing` is called.
1534
- invokeHelper: function(paramSize, name) {
1535
- this.context.aliases.helperMissing = 'helpers.helperMissing';
1536
-
1537
- var helper = this.lastHelper = this.setupHelper(paramSize, name);
1538
- this.register('foundHelper', helper.name);
1539
-
1540
- this.pushStack("foundHelper ? foundHelper.call(" +
1541
- helper.callParams + ") " + ": helperMissing.call(" +
1542
- helper.helperMissingParams + ")");
1543
- },
1544
-
1545
- // [invokeKnownHelper]
1546
- //
1547
- // On stack, before: hash, inverse, program, params..., ...
1548
- // On stack, after: result of helper invocation
1549
- //
1550
- // This operation is used when the helper is known to exist,
1551
- // so a `helperMissing` fallback is not required.
1552
- invokeKnownHelper: function(paramSize, name) {
1553
- var helper = this.setupHelper(paramSize, name);
1554
- this.pushStack(helper.name + ".call(" + helper.callParams + ")");
1555
- },
1556
-
1557
- // [invokeAmbiguous]
1558
- //
1559
- // On stack, before: hash, inverse, program, params..., ...
1560
- // On stack, after: result of disambiguation
1561
- //
1562
- // This operation is used when an expression like `{{foo}}`
1563
- // is provided, but we don't know at compile-time whether it
1564
- // is a helper or a path.
1565
- //
1566
- // This operation emits more code than the other options,
1567
- // and can be avoided by passing the `knownHelpers` and
1568
- // `knownHelpersOnly` flags at compile-time.
1569
- invokeAmbiguous: function(name) {
1570
- this.context.aliases.functionType = '"function"';
1571
-
1572
- this.pushStackLiteral('{}');
1573
- var helper = this.setupHelper(0, name);
1574
-
1575
- var helperName = this.lastHelper = this.nameLookup('helpers', name, 'helper');
1576
- this.register('foundHelper', helperName);
1577
-
1578
- var nonHelper = this.nameLookup('depth' + this.lastContext, name, 'context');
1579
- var nextStack = this.nextStack();
1580
-
1581
- this.source.push('if (foundHelper) { ' + nextStack + ' = foundHelper.call(' + helper.callParams + '); }');
1582
- this.source.push('else { ' + nextStack + ' = ' + nonHelper + '; ' + nextStack + ' = typeof ' + nextStack + ' === functionType ? ' + nextStack + '() : ' + nextStack + '; }');
1583
- },
1584
-
1585
- // [invokePartial]
1586
- //
1587
- // On stack, before: context, ...
1588
- // On stack after: result of partial invocation
1589
- //
1590
- // This operation pops off a context, invokes a partial with that context,
1591
- // and pushes the result of the invocation back.
1592
- invokePartial: function(name) {
1593
- var params = [this.nameLookup('partials', name, 'partial'), "'" + name + "'", this.popStack(), "helpers", "partials"];
1594
-
1595
- if (this.options.data) {
1596
- params.push("data");
1597
- }
1598
-
1599
- this.context.aliases.self = "this";
1600
- this.pushStack("self.invokePartial(" + params.join(", ") + ");");
1601
- },
1602
-
1603
- // [assignToHash]
1604
- //
1605
- // On stack, before: value, hash, ...
1606
- // On stack, after: hash, ...
1607
- //
1608
- // Pops a value and hash off the stack, assigns `hash[key] = value`
1609
- // and pushes the hash back onto the stack.
1610
- assignToHash: function(key) {
1611
- var value = this.popStack();
1612
- var hash = this.topStack();
1613
-
1614
- this.source.push(hash + "['" + key + "'] = " + value + ";");
1615
- },
1616
-
1617
- // HELPERS
1618
-
1619
- compiler: JavaScriptCompiler,
1620
-
1621
- compileChildren: function(environment, options) {
1622
- var children = environment.children, child, compiler;
1623
-
1624
- for(var i=0, l=children.length; i<l; i++) {
1625
- child = children[i];
1626
- compiler = new this.compiler();
1627
-
1628
- this.context.programs.push(''); // Placeholder to prevent name conflicts for nested children
1629
- var index = this.context.programs.length;
1630
- child.index = index;
1631
- child.name = 'program' + index;
1632
- this.context.programs[index] = compiler.compile(child, options, this.context);
1633
- }
1634
- },
1635
-
1636
- programExpression: function(guid) {
1637
- this.context.aliases.self = "this";
1638
-
1639
- if(guid == null) {
1640
- return "self.noop";
1641
- }
1642
-
1643
- var child = this.environment.children[guid],
1644
- depths = child.depths.list, depth;
1645
-
1646
- var programParams = [child.index, child.name, "data"];
1647
-
1648
- for(var i=0, l = depths.length; i<l; i++) {
1649
- depth = depths[i];
1650
-
1651
- if(depth === 1) { programParams.push("depth0"); }
1652
- else { programParams.push("depth" + (depth - 1)); }
1653
- }
1654
-
1655
- if(depths.length === 0) {
1656
- return "self.program(" + programParams.join(", ") + ")";
1657
- } else {
1658
- programParams.shift();
1659
- return "self.programWithDepth(" + programParams.join(", ") + ")";
1660
- }
1661
- },
1662
-
1663
- register: function(name, val) {
1664
- this.useRegister(name);
1665
- this.source.push(name + " = " + val + ";");
1666
- },
1667
-
1668
- useRegister: function(name) {
1669
- if(!this.registers[name]) {
1670
- this.registers[name] = true;
1671
- this.registers.list.push(name);
1672
- }
1673
- },
1674
-
1675
- pushStackLiteral: function(item) {
1676
- this.compileStack.push(new Literal(item));
1677
- return item;
1678
- },
1679
-
1680
- pushStack: function(item) {
1681
- this.source.push(this.incrStack() + " = " + item + ";");
1682
- this.compileStack.push("stack" + this.stackSlot);
1683
- return "stack" + this.stackSlot;
1684
- },
1685
-
1686
- replaceStack: function(callback) {
1687
- var item = callback.call(this, this.topStack());
1688
-
1689
- this.source.push(this.topStack() + " = " + item + ";");
1690
- return "stack" + this.stackSlot;
1691
- },
1692
-
1693
- nextStack: function(skipCompileStack) {
1694
- var name = this.incrStack();
1695
- this.compileStack.push("stack" + this.stackSlot);
1696
- return name;
1697
- },
1698
-
1699
- incrStack: function() {
1700
- this.stackSlot++;
1701
- if(this.stackSlot > this.stackVars.length) { this.stackVars.push("stack" + this.stackSlot); }
1702
- return "stack" + this.stackSlot;
1703
- },
1704
-
1705
- popStack: function() {
1706
- var item = this.compileStack.pop();
1707
-
1708
- if (item instanceof Literal) {
1709
- return item.value;
1710
- } else {
1711
- this.stackSlot--;
1712
- return item;
1713
- }
1714
- },
1715
-
1716
- topStack: function() {
1717
- var item = this.compileStack[this.compileStack.length - 1];
1718
-
1719
- if (item instanceof Literal) {
1720
- return item.value;
1721
- } else {
1722
- return item;
1723
- }
1724
- },
1725
-
1726
- quotedString: function(str) {
1727
- return '"' + str
1728
- .replace(/\\/g, '\\\\')
1729
- .replace(/"/g, '\\"')
1730
- .replace(/\n/g, '\\n')
1731
- .replace(/\r/g, '\\r') + '"';
1732
- },
1733
-
1734
- setupHelper: function(paramSize, name) {
1735
- var params = [];
1736
- this.setupParams(paramSize, params);
1737
- var foundHelper = this.nameLookup('helpers', name, 'helper');
1738
-
1739
- return {
1740
- params: params,
1741
- name: foundHelper,
1742
- callParams: ["depth0"].concat(params).join(", "),
1743
- helperMissingParams: ["depth0", this.quotedString(name)].concat(params).join(", ")
1744
- };
1745
- },
1746
-
1747
- // the params and contexts arguments are passed in arrays
1748
- // to fill in
1749
- setupParams: function(paramSize, params) {
1750
- var options = [], contexts = [], param, inverse, program;
1751
-
1752
- options.push("hash:" + this.popStack());
1753
-
1754
- inverse = this.popStack();
1755
- program = this.popStack();
1756
-
1757
- // Avoid setting fn and inverse if neither are set. This allows
1758
- // helpers to do a check for `if (options.fn)`
1759
- if (program || inverse) {
1760
- if (!program) {
1761
- this.context.aliases.self = "this";
1762
- program = "self.noop";
1763
- }
1764
-
1765
- if (!inverse) {
1766
- this.context.aliases.self = "this";
1767
- inverse = "self.noop";
1768
- }
1769
-
1770
- options.push("inverse:" + inverse);
1771
- options.push("fn:" + program);
1772
- }
1773
-
1774
- for(var i=0; i<paramSize; i++) {
1775
- param = this.popStack();
1776
- params.push(param);
1777
-
1778
- if(this.options.stringParams) {
1779
- contexts.push(this.popStack());
1780
- }
1781
- }
1782
-
1783
- if (this.options.stringParams) {
1784
- options.push("contexts:[" + contexts.join(",") + "]");
1785
- }
1786
-
1787
- if(this.options.data) {
1788
- options.push("data:data");
1789
- }
1790
-
1791
- params.push("{" + options.join(",") + "}");
1792
- return params.join(", ");
1793
- }
1794
- };
1795
-
1796
- var reservedWords = (
1797
- "break else new var" +
1798
- " case finally return void" +
1799
- " catch for switch while" +
1800
- " continue function this with" +
1801
- " default if throw" +
1802
- " delete in try" +
1803
- " do instanceof typeof" +
1804
- " abstract enum int short" +
1805
- " boolean export interface static" +
1806
- " byte extends long super" +
1807
- " char final native synchronized" +
1808
- " class float package throws" +
1809
- " const goto private transient" +
1810
- " debugger implements protected volatile" +
1811
- " double import public let yield"
1812
- ).split(" ");
1813
-
1814
- var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};
1815
-
1816
- for(var i=0, l=reservedWords.length; i<l; i++) {
1817
- compilerWords[reservedWords[i]] = true;
1818
- }
1819
-
1820
- JavaScriptCompiler.isValidJavaScriptVariableName = function(name) {
1821
- if(!JavaScriptCompiler.RESERVED_WORDS[name] && /^[a-zA-Z_$][0-9a-zA-Z_$]+$/.test(name)) {
1822
- return true;
1823
- }
1824
- return false;
1825
- };
1826
-
1827
- })(Handlebars.Compiler, Handlebars.JavaScriptCompiler);
1828
-
1829
- Handlebars.precompile = function(string, options) {
1830
- options = options || {};
1831
-
1832
- var ast = Handlebars.parse(string);
1833
- var environment = new Handlebars.Compiler().compile(ast, options);
1834
- return new Handlebars.JavaScriptCompiler().compile(environment, options);
1835
- };
1836
-
1837
- Handlebars.compile = function(string, options) {
1838
- options = options || {};
1839
-
1840
- var compiled;
1841
- function compile() {
1842
- var ast = Handlebars.parse(string);
1843
- var environment = new Handlebars.Compiler().compile(ast, options);
1844
- var templateSpec = new Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true);
1845
- return Handlebars.template(templateSpec);
1846
- }
1847
-
1848
- // Template is only compiled on first use and cached after that point.
1849
- return function(context, options) {
1850
- if (!compiled) {
1851
- compiled = compile();
1852
- }
1853
- return compiled.call(this, context, options);
1854
- };
1855
- };
1856
- ;
1857
- // lib/handlebars/runtime.js
1858
- Handlebars.VM = {
1859
- template: function(templateSpec) {
1860
- // Just add water
1861
- var container = {
1862
- escapeExpression: Handlebars.Utils.escapeExpression,
1863
- invokePartial: Handlebars.VM.invokePartial,
1864
- programs: [],
1865
- program: function(i, fn, data) {
1866
- var programWrapper = this.programs[i];
1867
- if(data) {
1868
- return Handlebars.VM.program(fn, data);
1869
- } else if(programWrapper) {
1870
- return programWrapper;
1871
- } else {
1872
- programWrapper = this.programs[i] = Handlebars.VM.program(fn);
1873
- return programWrapper;
1874
- }
1875
- },
1876
- programWithDepth: Handlebars.VM.programWithDepth,
1877
- noop: Handlebars.VM.noop
1878
- };
1879
-
1880
- return function(context, options) {
1881
- options = options || {};
1882
- return templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
1883
- };
1884
- },
1885
-
1886
- programWithDepth: function(fn, data, $depth) {
1887
- var args = Array.prototype.slice.call(arguments, 2);
1888
-
1889
- return function(context, options) {
1890
- options = options || {};
1891
-
1892
- return fn.apply(this, [context, options.data || data].concat(args));
1893
- };
1894
- },
1895
- program: function(fn, data) {
1896
- return function(context, options) {
1897
- options = options || {};
1898
-
1899
- return fn(context, options.data || data);
1900
- };
1901
- },
1902
- noop: function() { return ""; },
1903
- invokePartial: function(partial, name, context, helpers, partials, data) {
1904
- var options = { helpers: helpers, partials: partials, data: data };
1905
-
1906
- if(partial === undefined) {
1907
- throw new Handlebars.Exception("The partial " + name + " could not be found");
1908
- } else if(partial instanceof Function) {
1909
- return partial(context, options);
1910
- } else if (!Handlebars.compile) {
1911
- throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
1912
- } else {
1913
- partials[name] = Handlebars.compile(partial, {data: data !== undefined});
1914
- return partials[name](context, options);
1915
- }
1916
- }
1917
- };
1918
-
1919
- Handlebars.template = Handlebars.VM.template;
1920
- ;