MODx.Window=function(A){A=A||{};Ext.applyIf(A,{modal:false,layout:"auto",closeAction:"hide",shadow:true,resizable:true,collapsible:true,maximizable:true,autoHeight:true,allowDrop:true,width:450,cls:"modx-window",buttons:[{text:A.cancelBtnText||_("cancel"),scope:this,handler:function(){this.hide();}},{text:A.saveBtnText||_("save"),scope:this,handler:this.submit}],record:{},keys:[{key:Ext.EventObject.ENTER,fn:this.submit,scope:this}]});MODx.Window.superclass.constructor.call(this,A);this.options=A;this.config=A;this.addEvents({success:true,failure:true,beforeSubmit:true});this._loadForm();this.on("show",function(){if(this.config.blankValues){this.fp.getForm().reset();}if(this.config.allowDrop){this.loadDropZones();}this.syncSize();},this);};Ext.extend(MODx.Window,Ext.Window,{_loadForm:function(){if(this.checkIfLoaded(this.config.record||null)){return false;}var C=this.config.record;if(this.config.fields){var A=this.config.fields.length;for(var B=0;B<A;B++){var D=this.config.fields[B];if(C[D.name]){if(D.xtype=="checkbox"||D.xtype=="radio"){D.checked=C[D.name];}else{D.value=C[D.name];}}}}this.fp=this.createForm({url:this.config.url,baseParams:this.config.baseParams||{action:this.config.action||""},items:this.config.fields||[]});this.renderForm();},submit:function(){var A=this.fp.getForm();if(A.isValid()&&this.fireEvent("beforeSubmit",A.getValues())){A.submit({waitMsg:_("saving"),scope:this,failure:function(C,B){if(this.fireEvent("failure",{f:C,a:B})){MODx.form.Handler.errorExt(B.result,C);}},success:function(C,B){if(this.config.success){Ext.callback(this.config.success,this.config.scope||this,[C,B]);}this.fireEvent("success",{f:C,a:B});this.hide();}});}},createForm:function(A){A=A||{};Ext.applyIf(A,{labelAlign:this.config.labelAlign||"right",labelWidth:this.config.labelWidth||100,frame:this.config.formFrame||true,border:false,bodyBorder:false,autoHeight:true,errorReader:MODx.util.JSONReader,url:this.config.url,baseParams:this.config.baseParams||{},fileUpload:this.config.fileUpload||false});return new Ext.FormPanel(A);},renderForm:function(){this.add(this.fp);},checkIfLoaded:function(A){A=A||{};if(this.fp&&this.fp.getForm()){this.fp.getForm().reset();this.fp.getForm().setValues(A);return true;}return false;},setValues:function(A){if(A===null){return false;}this.fp.getForm().setValues(A);},reset:function(){this.fp.getForm().reset();},hideField:function(A){A.disable();A.hide();var B=A.getEl().up(".x-form-item");if(B){B.setDisplayed(false);}},showField:function(A){A.enable();A.show();var B=A.getEl().up(".x-form-item");if(B){B.setDisplayed(true);}},loadDropZones:function(){if(this._dzLoaded){return false;}var A=this.fp.getForm().items;A.each(function(B){if(B.isFormField&&(B.isXType("textfield")||B.isXType("textarea"))&&!B.isXType("combo")){new MODx.load({xtype:"modx-treedrop",target:B,targetEl:B.getEl().dom});}});this._dzLoaded=true;}});Ext.reg("modx-window",MODx.Window);