mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-08 01:18:39 +00:00
add an isObjectEmpty method to Ext to test to see if an object == {}
fix a couple of bugs in the options manager only call core.set_config if there are changed options call all the pages onApply method if they have one
This commit is contained in:
parent
b4547c0bf0
commit
9f3ef6556a
3 changed files with 32 additions and 16 deletions
|
@ -101,12 +101,17 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, {
|
||||||
* @returns {Object} the options value.
|
* @returns {Object} the options value.
|
||||||
*/
|
*/
|
||||||
get: function() {
|
get: function() {
|
||||||
|
if (arguments.length == 1) {
|
||||||
|
var option = arguments[0];
|
||||||
|
return (this.isDirty(option)) ? this.changed[option] : this.options[option];
|
||||||
|
} else {
|
||||||
var options = {};
|
var options = {};
|
||||||
Ext.each(arguments, function(option) {
|
Ext.each(arguments, function(option) {
|
||||||
if (!this.has(option)) return;
|
if (!this.has(option)) return;
|
||||||
options[option] = (this.isDirty(option)) ? this.changed[option] : this.options[option];
|
options[option] = (this.isDirty(option)) ? this.changed[option] : this.options[option];
|
||||||
}, this);
|
}, this);
|
||||||
return options;
|
return options;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -190,16 +195,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, {
|
||||||
this.update(key, option[key]);
|
this.update(key, option[key]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var oldValue = this.get(option);
|
|
||||||
if (oldValue == value) return;
|
|
||||||
|
|
||||||
var defaultValue = this.getDefault(option);
|
var defaultValue = this.getDefault(option);
|
||||||
if (defaultValue == value) {
|
|
||||||
if (this.isDirty(option)) delete this.changed[option];
|
|
||||||
this.fireEvent('changed', option, value, oldValue);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Ext.type(defaultValue) != Ext.type(value)) {
|
if (Ext.type(defaultValue) != Ext.type(value)) {
|
||||||
switch (Ext.type(defaultValue)) {
|
switch (Ext.type(defaultValue)) {
|
||||||
case 'string':
|
case 'string':
|
||||||
|
@ -214,6 +210,15 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var oldValue = this.get(option);
|
||||||
|
if (oldValue == value) return;
|
||||||
|
|
||||||
|
if (defaultValue == value) {
|
||||||
|
if (this.isDirty(option)) delete this.changed[option];
|
||||||
|
this.fireEvent('changed', option, value, oldValue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.changed[option] = value;
|
this.changed[option] = value;
|
||||||
this.fireEvent('changed', option, value, oldValue);
|
this.fireEvent('changed', option, value, oldValue);
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,20 +97,26 @@ Ext.deluge.PreferencesWindow = Ext.extend(Ext.Window, {
|
||||||
|
|
||||||
onApply: function(e) {
|
onApply: function(e) {
|
||||||
var changed = this.optionsManager.getDirty();
|
var changed = this.optionsManager.getDirty();
|
||||||
Deluge.Client.core.set_config(changed, {
|
if (!Ext.isObjectEmpty(changed)) {
|
||||||
success: this.onSetConfig,
|
Deluge.Client.core.set_config(changed, {
|
||||||
scope: this
|
success: this.onSetConfig,
|
||||||
});
|
scope: this
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var page in this.pages) {
|
||||||
|
if (this.pages[page].onApply) this.pages[page].onApply();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onClose: function() {
|
onClose: function() {
|
||||||
this.hide();
|
this.hide();
|
||||||
},
|
},
|
||||||
|
|
||||||
onOk: function() {
|
onOk: function() {
|
||||||
Deluge.Client.core.set_config(this.optionsManager.getDirty());
|
Deluge.Client.core.set_config(this.optionsManager.getDirty());
|
||||||
this.hide();
|
this.hide();
|
||||||
},
|
},
|
||||||
|
|
||||||
addPage: function(page) {
|
addPage: function(page) {
|
||||||
var store = this.categoriesGrid.getStore();
|
var store = this.categoriesGrid.getStore();
|
||||||
|
|
|
@ -45,6 +45,11 @@ Ext.namespace('Ext.deluge');
|
||||||
});
|
});
|
||||||
|
|
||||||
Ext.apply(Ext, {
|
Ext.apply(Ext, {
|
||||||
|
isObjectEmpty: function(obj) {
|
||||||
|
for(var i in obj) { return false; }
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
keys: function(obj) {
|
keys: function(obj) {
|
||||||
var keys = [];
|
var keys = [];
|
||||||
for (i in obj) if (obj.hasOwnProperty(i))
|
for (i in obj) if (obj.hasOwnProperty(i))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue