//>>built
define("dojox/mvc/StatefulModel","dojo/_base/kernel dojo/_base/lang dojo/_base/array dojo/_base/declare dojo/Stateful ./getStateful ./getPlainValue ./StatefulArray".split(" "),function(l,e,g,m,p,h,f,k){l.deprecated("dojox/mvc/StatefulModel","Use dojox/mvc/getStateful, dojox/mvc/getPlainValue, dojox/mvc/StatefulArray or one of the dojox/mvc/*RefControllers instead");var d=m("dojox.mvc.StatefulModel",[p],{data:null,store:null,valid:!0,value:"",reset:function(){if(!e.isObject(this.data)||this.data instanceof
Date||this.data instanceof RegExp)this.set("value",this.data);else for(var a in this)this[a]&&e.isFunction(this[a].reset)&&this[a].reset()},commit:function(a){this._commit();(a=a||this.store)&&this._saveToStore(a)},toPlainObject:function(){return f(this,d.getPlainValueOptions)},splice:function(a,b){for(var c=(new k([])).splice.apply(this,e._toArray(arguments)),d=0;d<c.length;d++)(this._removals=this._removals||[]).push(c[d].toPlainObject());return c},add:function(a,b){if("number"===typeof this.get("length")&&
/^[0-9]+$/.test(a.toString())){if(this.get("length")<a-0)throw Error("Out of bounds insert attempted, must be contiguous.");this.splice(a-0,0,b)}else this.set(a,b)},remove:function(a){if("number"===typeof this.get("length")&&/^[0-9]+$/.test(a.toString()))if(this.get(a))this.splice(a-0,1);else throw Error("Out of bounds delete attempted - no such index: "+n);else{var b=this.get(a);if(b)this._removals=this._removals||[],this._removals.push(b.toPlainObject()),this.set(a,void 0),delete this[a];else throw Error("Illegal delete attempted - no such property: "+
a);}},valueOf:function(){return this.toPlainObject()},toString:function(){return""===this.value&&this.data?this.data.toString():this.value.toString()},constructor:function(a){this._createModel(a&&"data"in a?a.data:this.data)},_createModel:function(a){if(null!=a)if(a=h(a,d.getStatefulOptions),e.isArray(a))this.length=0,[].splice.apply(this,a);else if(e.isObject(a))for(var b in a)a.hasOwnProperty(b)&&(this[b]=a[b]);else this.set("value",a)},_commit:function(){for(var a in this)this[a]&&e.isFunction(this[a]._commit)&&
this[a]._commit();this.data=this.toPlainObject()},_saveToStore:function(a){this._removals&&(g.forEach(this._removals,function(b){a.remove(a.getIdentity(b))},this),delete this._removals);var b=this.toPlainObject();e.isArray(b)?g.forEach(b,function(b){a.put(b)},this):a.put(b)}});e.mixin(d,{getStatefulOptions:{getType:function(a){return e.isArray(a)?"array":null!=a&&"[object Object]"=={}.toString.call(a)?"object":"value"},getStatefulArray:function(a){var b=this,c=e.mixin(new k(g.map(a,function(a){return h(a,
b)}))),f;for(f in d.prototype)"set"!=f&&(c[f]=d.prototype[f]);c.data=a;return c},getStatefulObject:function(a){var b=new d;b.data=a;for(var c in a)b.set(c,h(a[c],this));return b},getStatefulValue:function(a){var b=new d;b.data=a;b.set("value",a);return b}},getPlainValueOptions:{getType:function(a){if(e.isArray(a))return"array";if(e.isObject(a))for(var b in a)if(a.hasOwnProperty(b)&&"value"!=b&&(a[b]||{}).get&&(a[b]||{}).watch)return"object";return"value"},getPlainArray:function(a){return g.map(a,
function(a){return f(a,this)},this)},getPlainObject:function(a){var b={},c;for(c in a)"_watchCallbacks"==c||c in d.prototype||(b[c]=f(a[c],this));return b},getPlainValue:function(a){return(a||{}).set&&(a||{}).watch?f(a.value,this):a}}});return d});