Author: damoxc

Revision: 5684

Log:
        rewrite the interfaces preferences page as a class
implement password changing

Diff:
Modified: trunk/deluge/ui/web/js/Deluge.Preferences.Interface.js
===================================================================
--- trunk/deluge/ui/web/js/Deluge.Preferences.Interface.js      2009-08-20 
00:04:55 UTC (rev 5683)
+++ trunk/deluge/ui/web/js/Deluge.Preferences.Interface.js      2009-08-20 
00:05:35 UTC (rev 5684)
@@ -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



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to