diff --git a/deluge/ui/web/js/Deluge.Details.Options.js b/deluge/ui/web/js/Deluge.Details.Options.js index 15a237b68..155747129 100644 --- a/deluge/ui/web/js/Deluge.Details.Options.js +++ b/deluge/ui/web/js/Deluge.Details.Options.js @@ -51,13 +51,13 @@ Ext.deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { }, config); Ext.deluge.details.OptionsTab.superclass.constructor.call(this, config); }, - + initComponent: function() { Ext.deluge.details.OptionsTab.superclass.initComponent.call(this); this.fieldsets = {}, this.fields = {}; this.optionsManager = new Deluge.MultiOptionsManager({ - defaults: { + options: { 'max_download_speed': -1, 'max_upload_speed': -1, 'max_connections': -1, @@ -209,9 +209,10 @@ Ext.deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { }); this.fields.is_auto_managed = this.fieldsets.queue.add({ + xtype: 'checkbox', fieldLabel: '', labelSeparator: '', - id: 'is_auto_managed', + name: 'is_auto_managed', boxLabel: _('Auto Managed'), width: 200, colspan: 2 @@ -364,13 +365,14 @@ Ext.deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { }, reset: function() { - if (this.torrentId) { - this.optionsManager.reset(this.torrentId); - } + if (this.torrentId) this.optionsManager.reset(this.torrentId); }, update: function(torrentId) { - this.torrentId = torrentId; + if (this.torrentId != torrentId) { + this.torrentId = torrentId; + this.optionsManager.changeId(torrentId); + } Deluge.Client.core.get_torrent_status(torrentId, Deluge.Keys.Options, { success: this.onRequestComplete, scope: this @@ -378,7 +380,7 @@ Ext.deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { }, onApply: function() { - var changed = this.optionsManager.getChanged(this.torrentId); + var changed = this.optionsManager.getDirty(this.torrentId); if (!Ext.isEmpty(changed['prioritize_first_last'])) { var value = changed['prioritize_first_last']; Deluge.Client.core.set_torrent_prioritize_first_last(this.torrentId, value, { @@ -390,8 +392,7 @@ Ext.deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { } Deluge.Client.core.set_torrent_options([this.torrentId], changed, { success: function() { - this.optionsManager.set(this.torrentId, changed); - this.optionsManager.reset(this.torrentId); + this.optionsManager.commit(this.torrentId); }, scope: this }); @@ -411,8 +412,7 @@ Ext.deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { onRequestComplete: function(torrent, options) { this.fields['private'].setDisabled(!torrent['private']); delete torrent['private']; - - this.optionsManager.update(this.torrentId, torrent); + this.optionsManager.setDefault(this.torrentId, torrent); } }); Deluge.Details.add(new Ext.deluge.details.OptionsTab()); diff --git a/deluge/ui/web/js/Deluge.MultiOptionsManager.js b/deluge/ui/web/js/Deluge.MultiOptionsManager.js index a052d6885..6fa3430c8 100644 --- a/deluge/ui/web/js/Deluge.MultiOptionsManager.js +++ b/deluge/ui/web/js/Deluge.MultiOptionsManager.js @@ -149,14 +149,26 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, { * @param {String} option * @param {Object} value The value for the option */ - set: function(id, option, value) { - if (typeof value === undefined) { + setDefault: function(id, option, value) { + if (value === undefined) { for (var key in option) { - this.set(id, key, option[key]); + this.setDefault(id, key, option[key]); } } else { - if (!this.changed[id]) this.changed[id] = {}; - this.changed[id][option] = value; + var oldValue = this.getDefault(id, option); + value = this.convertValueType(oldValue, value); + + // If the value is the same as the old value there is + // no point in setting it again. + if (oldValue == value) return; + + // Store the new default + if (!this.stored[id]) this.stored[id] = {}; + this.stored[id][option] = value; + + if (!this.isDirty(id, option)) { + this.fireEvent('changed', id, option, value, oldValue); + } } },