Skip to content
Snippets Groups Projects
Commit bda310c6 authored by Renaud Le Gac's avatar Renaud Le Gac
Browse files

Redesign the handler to alert the user in case of errors.

parent cf490701
No related branches found
No related tags found
No related merge requests found
...@@ -48,6 +48,11 @@ App.form.EntryFormPanel = Ext.extend(App.form.FormPanel, { ...@@ -48,6 +48,11 @@ App.form.EntryFormPanel = Ext.extend(App.form.FormPanel, {
* @cfg {String} tableTitle title of the table * @cfg {String} tableTitle title of the table
*/ */
tableTitle: null, tableTitle: null,
/**
* pre-defined configuration options
*/
url: App.dburl,
/** /**
* private method require by the ExtJs component model * private method require by the ExtJs component model
...@@ -60,9 +65,6 @@ App.form.EntryFormPanel = Ext.extend(App.form.FormPanel, { ...@@ -60,9 +65,6 @@ App.form.EntryFormPanel = Ext.extend(App.form.FormPanel, {
throw new Error("the property tablename is missing !!!"); throw new Error("the property tablename is missing !!!");
} }
// NOTE: mandatory to defined the url here.
this.url = App.dburl;
App.form.EntryFormPanel.superclass.initComponent.call(this); App.form.EntryFormPanel.superclass.initComponent.call(this);
this.buttonCreate.on("click", this.onSubmit, this); this.buttonCreate.on("click", this.onSubmit, this);
...@@ -77,19 +79,49 @@ App.form.EntryFormPanel = Ext.extend(App.form.FormPanel, { ...@@ -77,19 +79,49 @@ App.form.EntryFormPanel = Ext.extend(App.form.FormPanel, {
} }
}, },
/**
* Private handler to laert the user on failure
*/
onFailure: function (form, action) {
var msg, badFields;
function fieldsInError(form) {
var badFields = [];
form.items.each(function(field){
if (!field.validate()) {
badFields.push(field.fieldLabel);
}
});
return badFields;
}
switch (action.failureType) {
case Ext.form.Action.CLIENT_INVALID:
badFields = fieldsInError(form);
msg = 'Missing of wrong fields: ';
msg += badFields.join(', ');
Ext.Msg.alert('Failure', msg);
break;
case Ext.form.Action.CONNECT_FAILURE:
msg = action.response.statusText;
Ext.Msg.alert('Failure', msg);
break;
case Ext.form.Action.SERVER_INVALID:
msg = action.result.msg;
Ext.Msg.alert('Failure', msg);
break;
}
},
/** /**
* Private handler to submit values in the database * Private handler to submit values in the database
*/ */
onSubmit: function () { onSubmit: function () {
function onFailure(form, action) {
if (action.response) {
if (action.response.status !== 200) {
Ext.MessageBox.alert('Error', action.response.responseText);
}
}
}
this.getForm().submit({ this.getForm().submit({
clientValidation: true, clientValidation: true,
url: this.url, url: this.url,
...@@ -101,7 +133,7 @@ App.form.EntryFormPanel = Ext.extend(App.form.FormPanel, { ...@@ -101,7 +133,7 @@ App.form.EntryFormPanel = Ext.extend(App.form.FormPanel, {
}, },
reset: true, reset: true,
waitMsg: 'Saving Record...', waitMsg: 'Saving Record...',
failure: onFailure failure: this.onFailure
}); });
} }
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment