mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-31 05:35:31 +00:00
big bunch of fixes to the M.O.M along with a couple to the O.M
This commit is contained in:
parent
4a00edc066
commit
04217e16d4
@ -39,52 +39,9 @@ Copyright:
|
|||||||
Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, {
|
Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, {
|
||||||
|
|
||||||
constructor: function(config) {
|
constructor: function(config) {
|
||||||
config = config || {};
|
this.currentId = null;
|
||||||
this.options = {};
|
this.stored = {};
|
||||||
this.binds = {};
|
Deluge.MultiOptionsManager.superclass.constructor.call(this, config);
|
||||||
this.changed = {};
|
|
||||||
this.defaults = (config && config['defaults']) || {};
|
|
||||||
|
|
||||||
this.addEvents({
|
|
||||||
'add': true,
|
|
||||||
'changed': true,
|
|
||||||
'reset': true
|
|
||||||
});
|
|
||||||
this.on('changed', this.onChange, this);
|
|
||||||
|
|
||||||
Deluge.MultiOptionsManager.superclass.constructor.call(this);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a set of default options and values to the options manager
|
|
||||||
* @param {String} id
|
|
||||||
* @param {Object} options The default options.
|
|
||||||
*/
|
|
||||||
addOptions: function(options) {
|
|
||||||
this.options[id] = options;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Binds a form field to the specified option.
|
|
||||||
* @param {String} option
|
|
||||||
* @param {Ext.form.Field} field
|
|
||||||
*/
|
|
||||||
bind: function(option, field) {
|
|
||||||
this.binds[option] = field;
|
|
||||||
this.binds[field] = option;
|
|
||||||
|
|
||||||
switch (field.getXType()) {
|
|
||||||
case 'checkbox':
|
|
||||||
case 'radiogroup':
|
|
||||||
field.on('check', this.onFieldChange, this);
|
|
||||||
break;
|
|
||||||
case 'uxspinner':
|
|
||||||
field.on('spin', this.onFieldChange, this);
|
|
||||||
field.on('keypress', this.onFieldChange, this);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,39 +50,44 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, {
|
|||||||
*/
|
*/
|
||||||
changeId: function(id) {
|
changeId: function(id) {
|
||||||
this.currentId = id;
|
this.currentId = id;
|
||||||
for (var option in this.defaults) {
|
for (var option in this.options) {
|
||||||
if (!this.binds[option]) continue;
|
if (!this.binds[option]) continue;
|
||||||
this.binds[option].setValue(this.get(id, option));
|
Ext.each(this.binds[option], function(bind) {
|
||||||
|
bind.setValue(this.get(id, option));
|
||||||
|
}, this);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes all the changed values to be the default values
|
||||||
|
* @param {String} id
|
||||||
|
*/
|
||||||
|
commit: function(id) {
|
||||||
|
this.stored[id] = Ext.apply(this.stored[id], this.changed[id]);
|
||||||
|
this.reset(id);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value for an option
|
* Get the value for an option
|
||||||
* @param {String} id
|
* @param {String} id
|
||||||
* @param {String|Array} [option] A single option or an array of options to return.
|
* @param {String|Array} [option] A single option or an array of options to return.
|
||||||
* @returns {Object} the options value.
|
* @returns {Object} the options value.
|
||||||
*/
|
*/
|
||||||
get: function(id, option) {
|
get: function() {
|
||||||
if (!option) {
|
var id = arguments[0];
|
||||||
var values = {};
|
if (arguments.length == 2) {
|
||||||
for (var key in this.defaults) {
|
var option = arguments[1];
|
||||||
values[key] = this.get(id, key);
|
return (this.isDirty(id, option)) ? this.changed[id][option] : this.getDefault(id, option);
|
||||||
}
|
|
||||||
return values;
|
|
||||||
} else {
|
} else {
|
||||||
return (this.hasChanged(id, option)) ? this.changed[id][option] : this.getDefault(id, option);
|
var options = {};
|
||||||
|
Ext.each(arguments, function(option) {
|
||||||
|
if (option == id) return;
|
||||||
|
options[option] = (this.isDirty(id, option)) ? this.changed[id][option] : this.getDefault(id, option);
|
||||||
|
}, this);
|
||||||
|
return options;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the changed values.
|
|
||||||
* @param {String} id
|
|
||||||
* @returns {Object} the changed options
|
|
||||||
*/
|
|
||||||
getChanged: function(id) {
|
|
||||||
return (this.changed[id]) ? this.changed[id] : {};
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the default value for an option.
|
* Get the default value for an option.
|
||||||
* @param {String} id
|
* @param {String} id
|
||||||
@ -133,7 +95,16 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, {
|
|||||||
* @returns {Object} the value of the option
|
* @returns {Object} the value of the option
|
||||||
*/
|
*/
|
||||||
getDefault: function(id, option) {
|
getDefault: function(id, option) {
|
||||||
return (this.hasOption(id, option)) ? this.options[id][option] : this.defaults[option];
|
return (this.has(id, option)) ? this.stored[id][option] : this.options[option];
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the dirty (changed) values.
|
||||||
|
* @param {String} id
|
||||||
|
* @returns {Object} the changed options
|
||||||
|
*/
|
||||||
|
getDirty: function(id) {
|
||||||
|
return (this.changed[id]) ? this.changed[id] : {};
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -142,7 +113,7 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, {
|
|||||||
* @param {String} option
|
* @param {String} option
|
||||||
* @returns {Boolean} true if the option has been changed, else false.
|
* @returns {Boolean} true if the option has been changed, else false.
|
||||||
*/
|
*/
|
||||||
hasChanged: function(id, option) {
|
isDirty: function(id, option) {
|
||||||
return (this.changed[id] && !Ext.isEmpty(this.changed[id][option]));
|
return (this.changed[id] && !Ext.isEmpty(this.changed[id][option]));
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -153,8 +124,8 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, {
|
|||||||
* @param {String} option
|
* @param {String} option
|
||||||
* @returns {Boolean} true if the id has an option, else false.
|
* @returns {Boolean} true if the id has an option, else false.
|
||||||
*/
|
*/
|
||||||
hasOption: function(id, option) {
|
has: function(id, option) {
|
||||||
return (this.options[id] && !Ext.isEmpty(this.options[id][option]));
|
return (this.stored[id] && !Ext.isEmpty(this.stored[id][option]));
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -178,8 +149,8 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, {
|
|||||||
this.set(id, key, option[key]);
|
this.set(id, key, option[key]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!this.options[id]) this.options[id] = {};
|
if (!this.changed[id]) this.changed[id] = {};
|
||||||
this.options[id][option] = value;
|
this.changed[id][option] = value;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -190,59 +161,51 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, {
|
|||||||
* @param {Object} [value];
|
* @param {Object} [value];
|
||||||
*/
|
*/
|
||||||
update: function(id, option, value) {
|
update: function(id, option, value) {
|
||||||
if (typeof value === undefined) {
|
if (value === undefined) {
|
||||||
for (var key in option) {
|
for (var key in option) {
|
||||||
this.update(id, key, option[key]);
|
this.update(id, key, option[key]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!this.changed[id]) this.changed[id] = {};
|
if (!this.changed[id]) this.changed[id] = {};
|
||||||
|
|
||||||
|
var defaultValue = this.getDefault(id, option);
|
||||||
|
value = this.convertValueType(defaultValue, value);
|
||||||
|
|
||||||
var oldValue = this.get(id, option);
|
var oldValue = this.get(id, option);
|
||||||
if (oldValue == value) return;
|
if (oldValue == value) return;
|
||||||
|
|
||||||
var defaultValue = this.getDefault(id, option);
|
|
||||||
if (defaultValue == value) {
|
if (defaultValue == value) {
|
||||||
if (this.hasChanged(id, option)) delete this.changed[id][option];
|
if (this.isDirty(id, option)) delete this.changed[id][option];
|
||||||
this.fireEvent('changed', id, option, value, oldValue);
|
this.fireEvent('changed', id, option, value, oldValue);
|
||||||
return;
|
return;
|
||||||
}
|
} else {
|
||||||
|
|
||||||
if (Ext.type(defaultValue) != Ext.type(value)) {
|
|
||||||
switch (Ext.type(defaultValue)) {
|
|
||||||
case 'string':
|
|
||||||
value = String(value);
|
|
||||||
break;
|
|
||||||
case 'number':
|
|
||||||
value = Number(value);
|
|
||||||
break;
|
|
||||||
case 'boolean':
|
|
||||||
value = Boolean(value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.changed[id][option] = value;
|
this.changed[id][option] = value;
|
||||||
this.fireEvent('changed', id, option, value, oldValue);
|
this.fireEvent('changed', id, option, value, oldValue);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/* Event Handlers */
|
/******************
|
||||||
|
* Event Handlers *
|
||||||
|
******************/
|
||||||
/**
|
/**
|
||||||
* Stops a form fields value from being blocked by the change functions
|
* Stops a form fields value from being blocked by the change functions
|
||||||
* @param {Ext.form.Field} field
|
* @param {Ext.form.Field} field
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
onFieldChange: function(field) {
|
onFieldChange: function(field, event) {
|
||||||
var option = this.binds[field];
|
this.update(this.currentId, field._doption, field.getValue());
|
||||||
this.update(this.currentId, option, field.getValue());
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onChange: function(id, option, newValue, oldValue) {
|
onChange: function(id, option, newValue, oldValue) {
|
||||||
// If we don't have a bind there's nothing to do.
|
// If we don't have a bind there's nothing to do.
|
||||||
if (Ext.isEmpty(this.binds[option])) return;
|
if (Ext.isEmpty(this.binds[option])) return;
|
||||||
|
Ext.each(this.binds[option], function(bind) {
|
||||||
|
// The field is currently focused so we don't want to
|
||||||
|
// change it.
|
||||||
|
if (bind == this.focused) return;
|
||||||
// Set the form field to the new value.
|
// Set the form field to the new value.
|
||||||
this.binds[option].setValue(newValue);
|
bind.setValue(newValue);
|
||||||
|
}, this);
|
||||||
}
|
}
|
||||||
});
|
});
|
@ -113,7 +113,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, {
|
|||||||
case 'boolean':
|
case 'boolean':
|
||||||
if (Ext.type(value) == 'string') {
|
if (Ext.type(value) == 'string') {
|
||||||
value = value.toLowerCase();
|
value = value.toLowerCase();
|
||||||
value = (value == 'true' || newValue == '1' || value == 'on') ? true : false;
|
value = (value == 'true' || value == '1' || value == 'on') ? true : false;
|
||||||
} else {
|
} else {
|
||||||
value = Boolean(value);
|
value = Boolean(value);
|
||||||
}
|
}
|
||||||
@ -167,16 +167,6 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, {
|
|||||||
return !Ext.isEmpty(this.changed[option]);
|
return !Ext.isEmpty(this.changed[option]);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Check to see if the option has been changed.
|
|
||||||
* @param {String} id
|
|
||||||
* @param {String} option
|
|
||||||
* @returns {Boolean} true if the option has been changed, else false.
|
|
||||||
*/
|
|
||||||
hasChanged: function(id, option) {
|
|
||||||
return (this.changed[id] && !Ext.isEmpty(this.changed[id][option]));
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check to see if an option exists in the options manager
|
* Check to see if an option exists in the options manager
|
||||||
* @param {String} option
|
* @param {String} option
|
||||||
@ -188,7 +178,6 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset the options back to the default values.
|
* Reset the options back to the default values.
|
||||||
* @param {String} id
|
|
||||||
*/
|
*/
|
||||||
reset: function() {
|
reset: function() {
|
||||||
this.changed = {};
|
this.changed = {};
|
||||||
@ -218,7 +207,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, {
|
|||||||
* @param {Object} [value];
|
* @param {Object} [value];
|
||||||
*/
|
*/
|
||||||
update: function(option, value) {
|
update: function(option, value) {
|
||||||
if (typeof value === undefined) {
|
if (value === undefined) {
|
||||||
for (var key in option) {
|
for (var key in option) {
|
||||||
this.update(key, option[key]);
|
this.update(key, option[key]);
|
||||||
}
|
}
|
||||||
@ -240,7 +229,9 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/* Event Handlers */
|
/******************
|
||||||
|
* Event Handlers *
|
||||||
|
******************/
|
||||||
/**
|
/**
|
||||||
* Lets the option manager know when a field is blurred so if a value
|
* Lets the option manager know when a field is blurred so if a value
|
||||||
* so value changing operations can continue on that field.
|
* so value changing operations can continue on that field.
|
||||||
@ -272,14 +263,12 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, {
|
|||||||
onChange: function(option, newValue, oldValue) {
|
onChange: function(option, newValue, oldValue) {
|
||||||
// If we don't have a bind there's nothing to do.
|
// If we don't have a bind there's nothing to do.
|
||||||
if (Ext.isEmpty(this.binds[option])) return;
|
if (Ext.isEmpty(this.binds[option])) return;
|
||||||
|
|
||||||
Ext.each(this.binds[option], function(bind) {
|
Ext.each(this.binds[option], function(bind) {
|
||||||
// The field is currently focused so we don't want to
|
// The field is currently focused so we don't want to
|
||||||
// change it.
|
// change it.
|
||||||
if (bind == this.focused) return;
|
if (bind == this.focused) return;
|
||||||
|
|
||||||
// Set the form field to the new value.
|
// Set the form field to the new value.
|
||||||
bind.setValue(newValue);
|
bind.setValue(newValue);
|
||||||
}, this)
|
}, this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user