YUI.add("model",function(u,t){var e=YUI.namespace("Env.Model"),r=u.Lang,a=u.Array,o=u.Object,d="change",l="error",c="load",h="save";function f(){f.superclass.constructor.apply(this,arguments)}u.Model=u.extend(f,u.Base,{idAttribute:"id",_allowAdHocAttrs:!0,_isYUIModel:!0,initializer:function(t){this.changed={},this.lastChange={},this.lists=[]},destroy:function(e,n){var i=this;return"function"==typeof e&&(n=e,e=null),i.onceAfter("destroy",function(){function t(t){t||a.each(i.lists.concat(),function(t){t.remove(i,e)}),n&&n.apply(null,arguments)}e&&(e.remove||e["delete"])?i.sync("delete",e,t):t()}),f.superclass.destroy.call(i)},generateClientId:function(){return e.lastId||(e.lastId=0),this.constructor.NAME+"_"+(e.lastId+=1)},getAsHTML:function(t){t=this.get(t);return u.Escape.html(r.isValue(t)?String(t):"")},getAsURL:function(t){t=this.get(t);return encodeURIComponent(r.isValue(t)?String(t):"")},isModified:function(){return this.isNew()||!o.isEmpty(this.changed)},isNew:function(){return!r.isValue(this.get("id"))},load:function(s,r){var a=this;return"function"==typeof s&&(r=s,s={}),s=s||{},a.sync("read",s,function(t,e){var n,i={options:s,response:e};t?(i.error=t,i.src="load",a.fire(l,i)):(a._loadEvent||(a._loadEvent=a.publish(c,{preventable:!1})),n=i.parsed=a._parse(e),a.setAttrs(n,s),a.changed={},a.fire(c,i)),r&&r.apply(null,arguments)}),a},parse:function(t){if("string"==typeof t)try{return u.JSON.parse(t)}catch(e){return this.fire(l,{error:e,response:t,src:"parse"}),null}return t},save:function(s,r){var a=this;return"function"==typeof s&&(r=s,s={}),s=s||{},a._validate(a.toJSON(),function(t){t?r&&r.call(null,t):a.sync(a.isNew()?"create":"update",s,function(t,e){var n,i={options:s,response:e};t?(i.error=t,i.src="save",a.fire(l,i)):(a._saveEvent||(a._saveEvent=a.publish(h,{preventable:!1})),e&&(n=i.parsed=a._parse(e),a.setAttrs(n,s)),a.changed={},a.fire(h,i)),r&&r.apply(null,arguments)})}),a},set:function(t,e,n){var i={};return i[t]=e,this.setAttrs(i,n)},setAttrs:function(t,e){var n,i,s,r,a=this.idAttribute,l=(e=u.merge(e))._transaction={};for(s in"id"!==a&&(t=u.merge(t),o.owns(t,a)?t.id=t[a]:o.owns(t,"id")&&(t[a]=t.id)),t)o.owns(t,s)&&this._setAttr(s,t[s],e);if(!o.isEmpty(l)){for(s in n=this.changed,r=this.lastChange={},l)o.owns(l,s)&&(n[s]=(i=l[s]).newVal,r[s]={newVal:i.newVal,prevVal:i.prevVal,src:i.src||null});e.silent||(this._changeEvent||(this._changeEvent=this.publish(d,{preventable:!1})),e.changed=r,this.fire(d,e))}return this},sync:function(){var t=a(arguments,0,!0).pop();"function"==typeof t&&t()},toJSON:function(){var t=this.getAttrs();return delete t.clientId,delete t.destroyed,delete t.initialized,"id"!==this.idAttribute&&delete t.id,t},undo:function(t,e){var n,i=this.lastChange,s=this.idAttribute,r={};return t=t||o.keys(i),a.each(t,function(t){o.owns(i,t)&&(n=!0,r[t=t===s?"id":t]=i[t].prevVal)}),n?this.setAttrs(r,e):this},validate:function(t,e){e&&e()},addAttr:function(t,e,n){var i,s=this.idAttribute;return s&&t===s&&(s=this._isLazyAttr("id")||this._getAttrCfg("id"),i=e.value===e.defaultValue?null:e.value,r.isValue(i)||(i=s.value===s.defaultValue?null:s.value,r.isValue(i))||(i=(r.isValue(e.defaultValue)?e:s).defaultValue),e.value=i,s.value!==i)&&(s.value=i,this._isLazyAttr("id")?this._state.add("id","lazy",s):this._state.add("id","value",i)),f.superclass.addAttr.apply(this,arguments)},_parse:function(t){return this.parse(t)},_validate:function(e,n){var i=this;function t(t){r.isValue(t)?(i.fire(l,{attributes:e,error:t,src:"validate"}),n(t)):n()}1===i.validate.length?t(i.validate(e,t)):i.validate(e,t)},_setAttrVal:function(t,e,n,i,s,r){var a=f.superclass._setAttrVal.apply(this,arguments),l=s&&s._transaction,u=r&&r.initializing;return a&&l&&!u&&(l[t]={newVal:this.get(t),prevVal:n,src:s.src||null}),a}},{NAME:"model",ATTRS:{clientId:{valueFn:"generateClientId",readOnly:!0},id:{value:null}}})},"patched-v3.18.7",{requires:["base-build","escape","json-parse"]});