YUI.add("model-sync-rest",function(u,t){var s=u.Lang;function a(){}a.CSRF_TOKEN=YUI.Env.CSRF_TOKEN,a.EMULATE_HTTP=!1,a.HTTP_HEADERS={Accept:"application/json","Content-Type":"application/json"},a.HTTP_METHODS={create:"POST",read:"GET",update:"PUT","delete":"DELETE"},a.HTTP_TIMEOUT=3e4,a._NON_ATTRS_CFG=["root","url"],a.prototype={root:"",url:"",initializer:function(t){"root"in(t=t||{})&&(this.root=t.root||""),"url"in t&&(this.url=t.url||"")},getURL:function(t,e){var n=this.root,s=this.url;return this._isYUIModelList?s?this._substituteURL(s,u.merge(this.getAttrs(),e)):this.model.prototype.root:n&&("create"===t||this.isNew())?n:s?this._substituteURL(s,u.merge(this.getAttrs(),e)):this._joinURL(this.getAsURL("id")||"")},parseIOResponse:function(t){return t.responseText},serialize:function(t){return u.JSON.stringify(this)},sync:function(t,e,n){var s,i=this.getURL(t,e=e||{}),o=a.HTTP_METHODS[t],r=u.merge(a.HTTP_HEADERS,e.headers),c=e.timeout||a.HTTP_TIMEOUT,e=e.csrfToken||a.CSRF_TOKEN;"POST"===o||"PUT"===o?s=this.serialize(t):delete r["Content-Type"],!a.EMULATE_HTTP||"PUT"!==o&&"DELETE"!==o||(r["X-HTTP-Method-Override"]=o,o="POST"),!e||"POST"!==o&&"PUT"!==o&&"DELETE"!==o||(r["X-CSRF-Token"]=e),this._sendSyncIORequest({action:t,callback:n,entity:s,headers:r,method:o,timeout:c,url:i})},_joinURL:function(t){var e=this.root;return e||t?("/"===t.charAt(0)&&(t=t.substring(1)),e&&"/"===e.charAt(e.length-1)?e+t+"/":e+"/"+t):""},_parse:function(t){return"function"==typeof this.parseIOResponse&&(t=this.parseIOResponse(t)),this.parse(t)},_sendSyncIORequest:function(t){return u.io(t.url,{arguments:{action:t.action,callback:t.callback,url:t.url},context:this,data:t.entity,headers:t.headers,method:t.method,timeout:t.timeout,on:{start:this._onSyncIOStart,failure:this._onSyncIOFailure,success:this._onSyncIOSuccess,end:this._onSyncIOEnd}})},_substituteURL:function(t,e){var n;return t?(n={},u.Object.each(e,function(t,e){(s.isString(t)||s.isNumber(t))&&(n[e]=encodeURIComponent(t))}),s.sub(t,n)):""},_onSyncIOEnd:function(t,e){},_onSyncIOFailure:function(t,e,n){n=n.callback;n&&n({code:e.status,msg:e.statusText},e)},_onSyncIOSuccess:function(t,e,n){n=n.callback;n&&n(null,e)},_onSyncIOStart:function(t,e){}},u.namespace("ModelSync").REST=a},"patched-v3.18.7",{requires:["model","io-base","json-stringify"]});