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
|
@ -101,12 +101,17 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, {
|
|||
* @returns {Object} the options value.
|
||||
*/
|
||||
get: function() {
|
||||
if (arguments.length == 1) {
|
||||
var option = arguments[0];
|
||||
return (this.isDirty(option)) ? this.changed[option] : this.options[option];
|
||||
} else {
|
||||
var options = {};
|
||||
Ext.each(arguments, function(option) {
|
||||
if (!this.has(option)) return;
|
||||
options[option] = (this.isDirty(option)) ? this.changed[option] : this.options[option];
|
||||
}, this);
|
||||
return options;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -190,16 +195,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, {
|
|||
this.update(key, option[key]);
|
||||
}
|
||||
} else {
|
||||
var oldValue = this.get(option);
|
||||
if (oldValue == value) return;
|
||||
|
||||
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)) {
|
||||
switch (Ext.type(defaultValue)) {
|
||||
case 'string':
|
||||
|
@ -212,6 +208,15 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, {
|
|||
value = Boolean(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -97,20 +97,26 @@ Ext.deluge.PreferencesWindow = Ext.extend(Ext.Window, {
|
|||
|
||||
onApply: function(e) {
|
||||
var changed = this.optionsManager.getDirty();
|
||||
Deluge.Client.core.set_config(changed, {
|
||||
success: this.onSetConfig,
|
||||
scope: this
|
||||
});
|
||||
if (!Ext.isObjectEmpty(changed)) {
|
||||
Deluge.Client.core.set_config(changed, {
|
||||
success: this.onSetConfig,
|
||||
scope: this
|
||||
});
|
||||
}
|
||||
|
||||
for (var page in this.pages) {
|
||||
if (this.pages[page].onApply) this.pages[page].onApply();
|
||||
}
|
||||
},
|
||||
|
||||
onClose: function() {
|
||||
this.hide();
|
||||
},
|
||||
|
||||
onOk: function() {
|
||||
onOk: function() {
|
||||
Deluge.Client.core.set_config(this.optionsManager.getDirty());
|
||||
this.hide();
|
||||
},
|
||||
this.hide();
|
||||
},
|
||||
|
||||
addPage: function(page) {
|
||||
var store = this.categoriesGrid.getStore();
|
||||
|
|
|
@ -45,6 +45,11 @@ Ext.namespace('Ext.deluge');
|
|||
});
|
||||
|
||||
Ext.apply(Ext, {
|
||||
isObjectEmpty: function(obj) {
|
||||
for(var i in obj) { return false; }
|
||||
return true;
|
||||
},
|
||||
|
||||
keys: function(obj) {
|
||||
var keys = [];
|
||||
for (i in obj) if (obj.hasOwnProperty(i))
|
||||
|
|
Loading…
Reference in New Issue