[Javascript]
/**
* Submit a form
*/
Function $ postForm (){
If (a. formPanel. getForm (). isValid ()){
Var B = a. scope? A. scope: this;
A. formPanel. getForm (). submit ({
Scope: B,
Url: a. url,
Method: "post ",
Params: a. params,
WaitMsg: "submitting data ...",
Success: function (c, d ){
Ext. ux. Toast. msg ("operation information", "saved successfully! ");
If (a. callback ){
A. callback. call (B, c, d );
}
},
Failure: function (c, d ){
Ext. MessageBox. show ({
Title: "operation information ",
Msg: "An error occurred while saving the information. Please contact the administrator! ",
Buttons: Ext. MessageBox. OK,
Icon: "ext-mb-error"
});
If (a. callback ){
A. callback. call (B );
}
}
});
}
}
/**
* Submit a form
*/
Function $ postForm (){
If (a. formPanel. getForm (). isValid ()){
Var B = a. scope? A. scope: this;
A. formPanel. getForm (). submit ({
Scope: B,
Url: a. url,
Method: "post ",
Params: a. params,
WaitMsg: "submitting data ...",
Success: function (c, d ){
Ext. ux. Toast. msg ("operation information", "saved successfully! ");
If (a. callback ){
A. callback. call (B, c, d );
}
},
Failure: function (c, d ){
Ext. MessageBox. show ({
Title: "operation information ",
Msg: "An error occurred while saving the information. Please contact the administrator! ",
Buttons: Ext. MessageBox. OK,
Icon: "ext-mb-error"
});
If (a. callback ){
A. callback. call (B );
}
}
});
}
}
To use the modified Code, only 13 lines of original code need 25-30 lines of code. For example:
[Javascript]
SaveRecord: function (){
$ PostForm ({
FormPanel: this. formPanel,
Scope: this,
Url: _ ctxPath + "/basedata/saveStudentDepartment. action ",
Params :{},
Callback: function (d, f ){
Var e = Ext. getCmp ("StudentDepartmentGrid ");
If (e! = Null ){
E. getStore (). reload ();
}
B. close ();
}
});
SaveRecord: function (){
$ PostForm ({
FormPanel: this. formPanel,
Scope: this,
Url: _ ctxPath + "/basedata/saveStudentDepartment. action ",
Params :{},
Callback: function (d, f ){
Var e = Ext. getCmp ("StudentDepartmentGrid ");
If (e! = Null ){
E. getStore (). reload ();
}
B. close ();
}
});