From 56aca8f2f9da48ca60ad5831f361914a7d1b6438 Mon Sep 17 00:00:00 2001 From: Damien Churchill Date: Thu, 20 Aug 2009 00:05:35 +0000 Subject: [PATCH] rewrite the interfaces preferences page as a class implement password changing --- .../ui/web/js/Deluge.Preferences.Interface.js | 193 ++++++++++++++---- 1 file changed, 149 insertions(+), 44 deletions(-) diff --git a/deluge/ui/web/js/Deluge.Preferences.Interface.js b/deluge/ui/web/js/Deluge.Preferences.Interface.js index d3563cfce..7c84971b7 100644 --- a/deluge/ui/web/js/Deluge.Preferences.Interface.js +++ b/deluge/ui/web/js/Deluge.Preferences.Interface.js @@ -1,48 +1,153 @@ -Deluge.Preferences.addPage({ - border: false, - title: _('Interface'), - xtype: 'form', - layout: 'form', - items: [{ - xtype: 'fieldset', - border: false, - title: _('Window'), - autoHeight: true, - labelWidth: 1, - items: [{ - xtype: 'checkbox', +Ext.namespace('Ext.deluge.preferences'); +Ext.deluge.preferences.Interface = Ext.extend(Ext.form.FormPanel, { + constructor: function(config) { + config = Ext.apply({ + border: false, + title: _('Interface'), + layout: 'form' + }, config); + Ext.deluge.preferences.Interface.superclass.constructor.call(this, config); + }, + + initComponent: function() { + Ext.deluge.preferences.Interface.superclass.initComponent.call(this); + + var optMan = this.optionsManager = new Deluge.OptionsManager(); + this.on('show', this.onShow, this); + + var fieldset = this.add({ + xtype: 'fieldset', + border: false, + title: _('Window'), + autoHeight: true, + labelWidth: 1, + defaultType: 'checkbox' + }); + optMan.bind('show_session_speed', fieldset.add({ + name: 'show_session_speed', fieldLabel: '', labelSeparator: '', - boxLabel: _('Show session speed in titlebar'), - id: 'show_session_speed' - }] - }, { - xtype: 'fieldset', - border: false, - title: _('Sidebar'), - autoHeight: true, - labelWidth: 1, - items: [{ - xtype: 'checkbox', + boxLabel: _('Show session speed in titlebar') + })); + + fieldset = this.add({ + xtype: 'fieldset', + border: false, + title: _('Sidebar'), + autoHeight: true, + labelWidth: 1, + defaultType: 'checkbox' + }); + optMan.bind('sidebar_show_zero', fieldset.add({ + name: 'sidebar_show_zero', fieldLabel: '', labelSeparator: '', - boxLabel: _('Hide filters with zero torrents'), - id: 'hide_sidebar_zero' - }] - }, { - xtype: 'fieldset', - border: false, - title: _('Password'), - autoHeight: true, - defaultType: 'textfield', - items: [{ - fieldLabel: 'New Password', - inputType: 'password', - id: 'new_password' - }, { - inputType: 'password', - fieldLabel: 'Confirm Password', - id: 'confirm_password' - }] - }] -}); \ No newline at end of file + boxLabel: _('Show filters with zero torrents') + })); + optMan.bind('sidebar_show_trackers', fieldset.add({ + name: 'sidebar_show_trackers', + fieldLabel: '', + labelSeparator: '', + boxLabel: _('Show trackers with zero torrents') + })); + + fieldset = this.add({ + xtype: 'fieldset', + border: false, + title: _('Password'), + autoHeight: true, + labelWidth: 110, + defaultType: 'textfield', + defaults: { + width: 180, + inputType: 'password' + } + }); + + this.oldPassword = fieldset.add({ + name: 'old_password', + fieldLabel: _('Old Password') + }); + this.newPassword = fieldset.add({ + name: 'new_password', + fieldLabel: _('New Password') + }); + this.confirmPassword = fieldset.add({ + name: 'confirm_password', + fieldLabel: _('Confirm Password') + }); + + var panel = fieldset.add({ + xtype: 'panel', + autoHeight: true, + border: false, + width: 320, + bodyStyle: 'padding-left: 230px' + }) + panel.add({ + xtype: 'button', + text: _('Change'), + listeners: { + 'click': { + fn: this.onPasswordChange, + scope: this + } + } + }); + }, + + onApply: function() { + alert('apply'); + }, + + onGotConfig: function(config) { + this.optionsManager.set(config); + }, + + onPasswordChange: function() { + if (this.newPassword.getValue() != this.confirmPassword.getValue()) { + Ext.MessageBox.show({ + title: _('Invalid Password'), + msg: _('Your passwords don\'t match!'), + buttons: Ext.MessageBox.OK, + modal: false, + icon: Ext.MessageBox.ERROR, + iconCls: 'x-deluge-icon-error' + }); + return; + } + + Deluge.Client.auth.change_password(this.oldPassword.getValue(), this.newPassword.getValue(), { + success: function(result) { + if (result) { + Ext.MessageBox.show({ + title: _('Password'), + msg: _('Your old password was incorrect!'), + buttons: Ext.MessageBox.OK, + modal: false, + icon: Ext.MessageBox.ERROR, + iconCls: 'x-deluge-icon-error' + }); + } else { + Ext.MessageBox.show({ + title: _('Change Successful'), + msg: _('Your password was successfully changed!'), + buttons: Ext.MessageBox.OK, + modal: false, + icon: Ext.MessageBox.INFO, + iconCls: 'x-deluge-icon-info' + }); + } + } + }); + }, + + onShow: function() { + Ext.deluge.preferences.Interface.superclass.onShow.call(this); + Deluge.Client.web.get_config({ + success: this.onGotConfig, + scope: this + }) + } +}); +Deluge.Preferences.addPage(new Ext.deluge.preferences.Interface()); \ No newline at end of file