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:
Damien Churchill 2009-08-19 23:17:50 +00:00
commit 9f3ef6556a
3 changed files with 32 additions and 16 deletions

View file

@ -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);
} }

View file

@ -97,10 +97,16 @@ Ext.deluge.PreferencesWindow = Ext.extend(Ext.Window, {
onApply: function(e) { onApply: function(e) {
var changed = this.optionsManager.getDirty(); var changed = this.optionsManager.getDirty();
if (!Ext.isObjectEmpty(changed)) {
Deluge.Client.core.set_config(changed, { Deluge.Client.core.set_config(changed, {
success: this.onSetConfig, success: this.onSetConfig,
scope: this scope: this
}); });
}
for (var page in this.pages) {
if (this.pages[page].onApply) this.pages[page].onApply();
}
}, },
onClose: function() { onClose: function() {

View file

@ -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))