diff --git a/js/settings/PasswdPanel.js b/js/settings/PasswdPanel.js index 2ae8615..8142b28 100644 --- a/js/settings/PasswdPanel.js +++ b/js/settings/PasswdPanel.js @@ -7,13 +7,6 @@ Ext.namespace('Zarafa.plugins.passwd.settings'); * Panel which holds a form that will be used to change the password */ Zarafa.plugins.passwd.settings.PasswdPanel = Ext.extend(Ext.form.FormPanel, { - /** - * @property - * @type Ext.LoadMask - * Save mask that will be displayed when request has been sent to server for password change - * and waiting for the response. - */ - saveMask : undefined, /** * @constructor @@ -69,7 +62,22 @@ Zarafa.plugins.passwd.settings.PasswdPanel = Ext.extend(Ext.form.FormPanel, { * @event userchange * Fires when a field is modified in the form panel */ - 'userchange' + 'userchange', + /** + * @event beforesave + * Fires when this form panel about to send request to server + */ + 'beforesave', + /** + * @event save + * Fires when this form panel has successfully changed password + */ + 'save', + /** + * @event exception + * Fires when this form panel was not able to change password + */ + 'exception' ); Zarafa.plugins.passwd.settings.PasswdPanel.superclass.constructor.apply(this, arguments); @@ -86,10 +94,6 @@ Zarafa.plugins.passwd.settings.PasswdPanel = Ext.extend(Ext.form.FormPanel, { this.getForm().setValues({ username : container.getUser().getUserName() }); - - this.saveMask = new Ext.LoadMask(this.getEl(), { - msg : _('Saving please wait ...') - }) }, /** @@ -107,8 +111,7 @@ Zarafa.plugins.passwd.settings.PasswdPanel = Ext.extend(Ext.form.FormPanel, { */ saveChanges : function() { - // show load mask - this.saveMask.show(); + this.fireEvent('beforesave', this); var data = this.getForm().getFieldValues(); @@ -136,8 +139,11 @@ Zarafa.plugins.passwd.settings.PasswdPanel = Ext.extend(Ext.form.FormPanel, { */ callbackFn : function(success, response) { - // hide load mask - this.saveMask.hide(); + if(success) { + this.fireEvent('save', this); + } else { + this.fireEvent('exception', this); + } } }); diff --git a/js/settings/SettingsPasswdCategory.js b/js/settings/SettingsPasswdCategory.js index 87f3753..a291bd5 100644 --- a/js/settings/SettingsPasswdCategory.js +++ b/js/settings/SettingsPasswdCategory.js @@ -27,6 +27,82 @@ Zarafa.plugins.passwd.settings.SettingsPasswdCategory = Ext.extend(Zarafa.settin }); Zarafa.plugins.passwd.settings.SettingsPasswdCategory.superclass.constructor.call(this, config); + }, + + /** + * Called by superclass when the Category has been deselected and is hidden from the user, + * this will unregister the {@link #onBeforeSaveRules} event handler. + * @private + */ + onHide : function() + { + Zarafa.common.settings.SettingsRuleCategory.superclass.onHide.apply(this, arguments); + + // Unregister the 'beforesave' event. This could be lingering when + // 'savesettings' was fired but it was cancelled by one of the + // event handlers. + var panel = this.get(0).passwdPanel; + this.mun(panel, 'beforesave', this.onBeforeSavePasswd, this); + }, + + /** + * Event handler for the + * {@link Zarafa.settings.SettingsContextModel ContextModel}#{@link Zarafa.settings.SettingsContextModel#beforesavesettings beforesavesettings} + * event. It will reset the {@link #savingElCounter} and his will register the event handler for + * {@link Zarafa.settings.SettingsModel#beforesave beforesave} event. + * @private + */ + onBeforeSaveSettingsModel : function() + { + Zarafa.common.settings.SettingsRuleCategory.superclass.onBeforeSaveSettingsModel.apply(this, arguments); + + var panel = this.get(0).passwdPanel; + this.mon(panel, 'beforesave', this.onBeforeSavePasswd, this, { single : true }); + }, + + /** + * Event handler which is fired when the {@link Zarafa.plugins.passwd.settings.PasswdPanel Passwd Panel} + * fires the 'beforesave' event. This will {@link #displaySavingMask show a notification} and register the + * event handlers for the completion of the save. + * @private + */ + onBeforeSavePasswd : function() + { + this.displaySavingMask(); + + var panel = this.get(0).passwdPanel; + this.mon(panel, 'save', this.onPasswdSave, this); + this.mon(panel, 'exception', this.onPasswdException, this); + }, + + /** + * Event handler which is fired when the {@link Zarafa.common.rules.data.RulesStore Rules Store} + * fires the 'save' event indicating the successfull save of the rules. This will + * {@link #hideSavingMask hide the notification}. + * @private + */ + onPasswdSave : function() + { + this.hideSavingMask(true); + + var panel = this.get(0).passwdPanel; + this.mun(panel, 'save', this.onPasswdSave, this); + this.mun(panel, 'exception', this.onPasswdException, this); + }, + + /** + * Event handler which is fired when the {@link Zarafa.common.rules.data.RulesStore Rules Store} + * fires the 'exception' event indicating a failing save of the rules. This will + * {@link #hideSavingMask hide the notification}. + * @private + */ + onPasswdException : function() + { + this.hideSavingMask(false); + + var panel = this.get(0).passwdPanel; + this.mun(panel, 'save', this.onPasswdSave, this); + this.mun(panel, 'exception', this.onPasswdException, this); } }); diff --git a/js/settings/SettingsPasswdWidget.js b/js/settings/SettingsPasswdWidget.js index 2143c45..b89fbc3 100644 --- a/js/settings/SettingsPasswdWidget.js +++ b/js/settings/SettingsPasswdWidget.js @@ -32,6 +32,8 @@ Zarafa.plugins.passwd.settings.SettingsPasswdWidget = Ext.extend(Zarafa.settings ref : 'passwdPanel', listeners : { userchange : this.setModelDirty, + beforesave : this.onBeforeSave, + scope : this } }] @@ -63,7 +65,10 @@ Zarafa.plugins.passwd.settings.SettingsPasswdWidget = Ext.extend(Zarafa.settings */ onSaveSettings : function() { - this.passwdPanel.saveChanges(); + // only save when this category is visible on screen + if(this.ownerCt.isVisible()) { + this.passwdPanel.saveChanges(); + } }, /**