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.focusFirstField();},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();},focusFirstField:function(){if(this.fp&&this.fp.getForm()&&this.fp.getForm().items.getCount()>0){var A=this.findFirstTextField();if(A){A.focus(false,200);}}},findFirstTextField:function(B){B=B||0;var A=this.fp.getForm().items.itemAt(B);if(!A){return false;}if(A.isXType("combo")||A.isXType("checkbox")||A.isXType("radio")||A.isXType("displayfield")||A.isXType("statictextfield")||A.isXType("hidden")){B=B+1;A=this.findFirstTextField(B);}return A;},submit:function(B){B=B===false?false:true;var A=this.fp.getForm();if(A.isValid()&&this.fireEvent("beforeSubmit",A.getValues())){A.submit({waitMsg:_("saving"),scope:this,failure:function(D,C){if(this.fireEvent("failure",{f:D,a:C})){MODx.form.Handler.errorExt(C.result,D);}},success:function(D,C){if(this.config.success){Ext.callback(this.config.success,this.config.scope||this,[D,C]);}this.fireEvent("success",{f:D,a:C});if(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);