rewrite the interfaces preferences page as a class
implement password changing
This commit is contained in:
parent
c94c9c36e4
commit
56aca8f2f9
|
@ -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'
|
||||
}]
|
||||
}]
|
||||
});
|
||||
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());
|
Loading…
Reference in New Issue