From 0d77ec55648f6bfeb9e9be0b5be4e01257ff2616 Mon Sep 17 00:00:00 2001 From: Saket Patel Date: Thu, 17 Oct 2013 03:54:11 +0530 Subject: [PATCH] simplify code --- js/settings/PasswdPanel.js | 57 +------------------- js/settings/SettingsPasswdCategory.js | 76 --------------------------- js/settings/SettingsPasswdWidget.js | 16 ++++-- 3 files changed, 13 insertions(+), 136 deletions(-) diff --git a/js/settings/PasswdPanel.js b/js/settings/PasswdPanel.js index 8142b28..a9c9f70 100644 --- a/js/settings/PasswdPanel.js +++ b/js/settings/PasswdPanel.js @@ -62,22 +62,7 @@ Zarafa.plugins.passwd.settings.PasswdPanel = Ext.extend(Ext.form.FormPanel, { * @event userchange * Fires when a field is modified in the form panel */ - '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' + 'userchange' ); Zarafa.plugins.passwd.settings.PasswdPanel.superclass.constructor.apply(this, arguments); @@ -104,46 +89,6 @@ Zarafa.plugins.passwd.settings.PasswdPanel = Ext.extend(Ext.form.FormPanel, { onFieldChange : function(field, newValue, oldValue) { this.fireEvent('userchange', this); - }, - - /** - * Function will be called when user presses apply to change password. - */ - saveChanges : function() - { - this.fireEvent('beforesave', this); - - var data = this.getForm().getFieldValues(); - - // send request - container.getRequest().singleRequest('passwdmodule', 'save', data, new Zarafa.plugins.passwd.data.PasswdResponseHandler({ - callbackFn : this.callbackFn, - scope : this - })); - }, - - /** - * Function will be called when user presses discard button to reset - * fields. - */ - discardChanges : function() - { - // reset user changes - this.getForm().reset(); - }, - - /** - * Callback function that will be executed after response is received from server. - * @param {Boolean} success boolean to indicate response contains success/failure data. - * @param {Object} response response sent by server. - */ - callbackFn : function(success, response) - { - if(success) { - this.fireEvent('save', this); - } else { - this.fireEvent('exception', this); - } } }); diff --git a/js/settings/SettingsPasswdCategory.js b/js/settings/SettingsPasswdCategory.js index a291bd5..87f3753 100644 --- a/js/settings/SettingsPasswdCategory.js +++ b/js/settings/SettingsPasswdCategory.js @@ -27,82 +27,6 @@ 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 b89fbc3..ed2debb 100644 --- a/js/settings/SettingsPasswdWidget.js +++ b/js/settings/SettingsPasswdWidget.js @@ -32,8 +32,6 @@ Zarafa.plugins.passwd.settings.SettingsPasswdWidget = Ext.extend(Zarafa.settings ref : 'passwdPanel', listeners : { userchange : this.setModelDirty, - beforesave : this.onBeforeSave, - scope : this } }] @@ -67,7 +65,17 @@ Zarafa.plugins.passwd.settings.SettingsPasswdWidget = Ext.extend(Zarafa.settings { // only save when this category is visible on screen if(this.ownerCt.isVisible()) { - this.passwdPanel.saveChanges(); + this.ownerCt.displaySavingMask(); + + var data = this.passwdPanel.getForm().getFieldValues(); + + // send request + container.getRequest().singleRequest('passwdmodule', 'save', data, new Zarafa.plugins.passwd.data.PasswdResponseHandler({ + callbackFn : function(success, response) { + this.ownerCt.hideSavingMask(success); + }, + scope : this + })); } }, @@ -79,7 +87,7 @@ Zarafa.plugins.passwd.settings.SettingsPasswdWidget = Ext.extend(Zarafa.settings */ onDiscardSettings : function() { - this.passwdPanel.discardChanges(); + this.passwdPanel.getForm().reset(); }, /**