From bda310c6973658ef03a6261d3a2a83dac9449c35 Mon Sep 17 00:00:00 2001 From: Renaud Le Gac <renaud.legac@free.fr> Date: Sun, 30 Jan 2011 13:09:54 +0000 Subject: [PATCH] Redesign the handler to alert the user in case of errors. --- static/plugin_dbui/src/appform2.js | 56 +++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/static/plugin_dbui/src/appform2.js b/static/plugin_dbui/src/appform2.js index 17899426..d1f557a0 100644 --- a/static/plugin_dbui/src/appform2.js +++ b/static/plugin_dbui/src/appform2.js @@ -48,6 +48,11 @@ App.form.EntryFormPanel = Ext.extend(App.form.FormPanel, { * @cfg {String} tableTitle title of the table */ tableTitle: null, + + /** + * pre-defined configuration options + */ + url: App.dburl, /** * private method require by the ExtJs component model @@ -60,9 +65,6 @@ App.form.EntryFormPanel = Ext.extend(App.form.FormPanel, { 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); this.buttonCreate.on("click", this.onSubmit, this); @@ -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 */ onSubmit: function () { - function onFailure(form, action) { - if (action.response) { - if (action.response.status !== 200) { - Ext.MessageBox.alert('Error', action.response.responseText); - } - } - } - this.getForm().submit({ clientValidation: true, url: this.url, @@ -101,7 +133,7 @@ App.form.EntryFormPanel = Ext.extend(App.form.FormPanel, { }, reset: true, waitMsg: 'Saving Record...', - failure: onFailure + failure: this.onFailure }); } }); -- GitLab