(function(){"use strict";u8.Base.Model=function(e){$.extend(this,u8.Base.Model.defaults,e);this.bind();this.bind("PropertyChange",this.onPropertiesChange);this.onPropertiesChange=this.onPropertyChange;this._properties=$.extend({},this.properties);delete this.properties};u8.Base.Model.makeClass({name:"Model",events:["PropertyChange"]});u8.Base.Model.defaults={properties:{}};$.extend(u8.Base.Model.prototype,{get:function(e,t){var r=this._properties[e];return typeof r=="undefined"?typeof t=="undefined"?this.defaultValue:t:r},set:function(e,t){if(arguments.length==1&&typeof e=="object"){var r=e;for(e in r){this.set(e,r[e])}return this}var n=this._properties[e];if(n===t){return this}this._properties[e]=t;this.raise("PropertyChange",{value:t,previousValue:n,propertyName:e});return this},getProperties:function(){return this._properties},setProperties:function(e){if(!e){return}var t;for(t in this._properties){if(!e.hasOwnProperty(t)){this.set(t,undefined)}}for(t in e){this.set(t,e[t])}},extendProperties:function(e){if(!e){return}for(var t in e){this.set(t,e[t])}},property:function(t,r){if(!this._computedProperties){this._computedProperties={}}if(!r){var n=this._computedProperties[t];if(n){n.unbind();delete this._computedProperties[t];this.set(t,undefined)}return this}var i=r.compute;var o=r.dependsOn;if(typeof i!="function"){i=e[i]}var s=this;var u=r.source||this;function a(e){return o.indexOf(e)>=0}function p(e,r){if(a(r.propertyName)){s.set(t,i?f():r.value)}}function f(){var e=[];for(var t=0;t<o.length;t++){e.push(u.get(o[t]))}return i.apply(s,e)}this._computedProperties[t]={unbind:function(){u.unbind("PropertyChange",p)}};this.set(t,i?f():u.get(t));u.bind("PropertyChange",p);return this},clone:function(){var e=new u8.Base.Model;$.extend(e,this);return e},dispose:function(){if(this._isDisposed){return}this._isDisposed=true;if(this._computedProperties){for(var e in this._computedProperties){this._computedProperties[e].unbind()}delete this._computedProperties}this.unbind()},bind:function(e,t,r){if(e=="PropertyChange"||typeof e!="string"||arguments.length<2){return u8.Base.EventSource.bind.apply(this,arguments)}var n=e.indexOf(":");if(n>0){e=e.substr(n+1)}var i=e=="*"?function(){return true}:u8.tools.isArray(e)?function(t){return e.contains(t)}:function(t){return t==e};var o=this;u8.Base.EventSource.bind.call(this,"PropertyChange",function(e,r){if(i(r.propertyName)){t.call(o,r.value,r.propertyName,r.previousValue)}},r);return this}});$.extend(u8.Base.Model,{define:function(e){var t=u8.Base.Model;var r=function(e){t.call(this,e)};r.prototype=Object.create(t.prototype);r._type=t._type;var n={};for(var i=0;i<arguments.length;i++){var o=arguments[i];if(typeof o=="string"){o=o.split(",")}if(u8.tools.isArray(o)){o=o.toObject(u8._.id,u8._.create())}for(var s in o){if(!o.hasOwnProperty(s)){continue}var u=o[s];if(!("get"in u)&&!("set"in u)&&u.writable!==false&&!("value"in u)){u.get=r.prototype.get.curry(s);u.set=r.prototype.set.curry(s)}n[s]=u}}Object.defineProperties(r.prototype,n);return r},toPlain:function(e){if(!e||typeof e!=="object"){return e}if(u8.tools.isInstanceOfClass(e,"Model")){return u8.Base.Model.toPlain(e.getProperties())}if(u8.tools.isArray(e)){return e.map(u8.Base.Model.toPlain)}var t={};for(var r in e){t[r]=u8.Base.Model.toPlain(e[r])}return t}});var e={or:function(){for(var e=0;e<arguments.length;e++){if(arguments[e]){return true}}return false},and:function(){for(var e=0;e<arguments.length;e++){if(!arguments[e]){return false}}return true},sum:function(){var e=0;for(var t=0;t<arguments.length;t++){var r=arguments[t];if(isNaN(r)){continue}e+=r}return e},nop:function(){return arguments[0]},not:function(){return!arguments[0]}};u8.Base.PropertyBag=u8.Base.Model})();