Author: damoxc
Revision: 5844
Log:
big bunch of fixes to the M.O.M along with a couple to the O.M
Diff:
Modified: branches/1.2_RC/deluge/ui/web/js/Deluge.MultiOptionsManager.js
===================================================================
--- branches/1.2_RC/deluge/ui/web/js/Deluge.MultiOptionsManager.js
2009-10-13 15:22:24 UTC (rev 5843)
+++ branches/1.2_RC/deluge/ui/web/js/Deluge.MultiOptionsManager.js
2009-10-13 16:21:28 UTC (rev 5844)
@@ -20,15 +20,15 @@
51 Franklin Street, Fifth Floor
Boston, MA 02110-1301, USA.
- In addition, as a special exception, the copyright holders give
- permission to link the code of portions of this program with the OpenSSL
- library.
- You must obey the GNU General Public License in all respects for all of
- the code used other than OpenSSL. If you modify file(s) with this
- exception, you may extend this exception to your version of the file(s),
- but you are not obligated to do so. If you do not wish to do so, delete
- this exception statement from your version. If you delete this exception
- statement from all source files in the program, then also delete it here.
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of portions of this program with the OpenSSL
+ library.
+ You must obey the GNU General Public License in all respects for all of
+ the code used other than OpenSSL. If you modify file(s) with this
+ exception, you may extend this exception to your version of the file(s),
+ but you are not obligated to do so. If you do not wish to do so, delete
+ this exception statement from your version. If you delete this exception
+ statement from all source files in the program, then also delete it
here.
*/
/**
@@ -37,67 +37,35 @@
* @class Deluge.MultiOptionsManager
*/
Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, {
-
+
constructor: function(config) {
- config = config || {};
- this.options = {};
- this.binds = {};
- 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);
+ this.currentId = null;
+ this.stored = {};
+ Deluge.MultiOptionsManager.superclass.constructor.call(this,
config);
},
/**
- * 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;
- }
- },
-
- /**
* Changes bound fields to use the specified id.
* @param {String} id
*/
changeId: function(id) {
this.currentId = id;
- for (var option in this.defaults) {
+ for (var option in this.options) {
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
@@ -105,47 +73,50 @@
* @param {String|Array} [option] A single option or an array of
options to return.
* @returns {Object} the options value.
*/
- get: function(id, option) {
- if (!option) {
- var values = {};
- for (var key in this.defaults) {
- values[key] = this.get(id, key);
- }
- return values;
+ get: function() {
+ var id = arguments[0];
+ if (arguments.length == 2) {
+ var option = arguments[1];
+ return (this.isDirty(id, option)) ?
this.changed[id][option] : this.getDefault(id, option);
} 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.
* @param {String} id
* @param {String|Array} [option] A single option or an array of
options to return.
* @returns {Object} the value of the 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] : {};
+ },
+
+ /**
* 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) {
+ isDirty: function(id, option) {
return (this.changed[id] &&
!Ext.isEmpty(this.changed[id][option]));
},
-
+
/**
* Check to see if an id has had an option set to something other than
the
* default value.
@@ -153,8 +124,8 @@
* @param {String} option
* @returns {Boolean} true if the id has an option, else false.
*/
- hasOption: function(id, option) {
- return (this.options[id] &&
!Ext.isEmpty(this.options[id][option]));
+ has: function(id, option) {
+ return (this.stored[id] &&
!Ext.isEmpty(this.stored[id][option]));
},
/**
@@ -165,7 +136,7 @@
if (!this.changed[id]) return;
delete this.changed[id];
},
-
+
/**
* Sets the value of specified option for the passed in id.
* @param {String} id
@@ -178,11 +149,11 @@
this.set(id, key, option[key]);
}
} else {
- if (!this.options[id]) this.options[id] = {};
- this.options[id][option] = value;
+ if (!this.changed[id]) this.changed[id] = {};
+ this.changed[id][option] = value;
}
},
-
+
/**
* Update the value for the specified option and id.
* @param {String} id
@@ -190,59 +161,51 @@
* @param {Object} [value];
*/
update: function(id, option, value) {
- if (typeof value === undefined) {
+ if (value === undefined) {
for (var key in option) {
this.update(id, key, option[key]);
}
} else {
if (!this.changed[id]) this.changed[id] = {};
+
+ var defaultValue = this.getDefault(id, option);
+ value = this.convertValueType(defaultValue, value);
var oldValue = this.get(id, option);
if (oldValue == value) return;
-
- var defaultValue = this.getDefault(id, option);
+
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);
return;
+ } else {
+ this.changed[id][option] = value;
+ this.fireEvent('changed', id, option, value,
oldValue);
}
-
- 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.fireEvent('changed', id, option, value, oldValue);
}
},
-
- /* Event Handlers */
-
+
+ /******************
+ * Event Handlers *
+ ******************/
/**
* Stops a form fields value from being blocked by the change functions
* @param {Ext.form.Field} field
* @private
*/
- onFieldChange: function(field) {
- var option = this.binds[field];
- this.update(this.currentId, option, field.getValue());
+ onFieldChange: function(field, event) {
+ this.update(this.currentId, field._doption, field.getValue());
},
-
+
onChange: function(id, option, newValue, oldValue) {
// If we don't have a bind there's nothing to do.
if (Ext.isEmpty(this.binds[option])) return;
-
- // Set the form field to the new value.
- this.binds[option].setValue(newValue);
+ 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.
+ bind.setValue(newValue);
+ }, this);
}
-});
\ No newline at end of file
+});
Modified: branches/1.2_RC/deluge/ui/web/js/Deluge.OptionsManager.js
===================================================================
--- branches/1.2_RC/deluge/ui/web/js/Deluge.OptionsManager.js 2009-10-13
15:22:24 UTC (rev 5843)
+++ branches/1.2_RC/deluge/ui/web/js/Deluge.OptionsManager.js 2009-10-13
16:21:28 UTC (rev 5844)
@@ -95,7 +95,7 @@
this.options = Ext.apply(this.options, this.changed);
this.reset();
},
-
+
/**
* Converts the value so it matches the originals type
* @param {Mixed} oldValue The original value
@@ -103,183 +103,172 @@
*/
convertValueType: function(oldValue, value) {
if (Ext.type(oldValue) != Ext.type(value)) {
- switch (Ext.type(oldValue)) {
- case 'string':
- value = String(value);
- break;
- case 'number':
- value = Number(value);
- break;
- case 'boolean':
- if (Ext.type(value) == 'string') {
- value = value.toLowerCase();
- value = (value == 'true' || newValue == '1' ||
value == 'on') ? true : false;
- } else {
- value = Boolean(value);
+ switch (Ext.type(oldValue)) {
+ case 'string':
+ value = String(value);
+ break;
+ case 'number':
+ value = Number(value);
+ break;
+ case 'boolean':
+ if (Ext.type(value) == 'string') {
+ value = value.toLowerCase();
+ value = (value == 'true' ||
value == '1' || value == 'on') ? true : false;
+ } else {
+ value = Boolean(value);
+ }
+ break;
}
- break;
}
- }
- return value;
+ return value;
},
-
+
/**
* Get the value for an option or options.
* @param {String} [option] A single option or an array of options to
return.
* @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;
- }
+ 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;
+ }
},
-
+
/**
* Get the default value for an option or options.
* @param {String|Array} [option] A single option or an array of
options to return.
* @returns {Object} the value of the option
*/
getDefault: function(option) {
- return this.options[option];
+ return this.options[option];
},
-
+
/**
* Returns the dirty (changed) values.
* @returns {Object} the changed options
*/
getDirty: function() {
- return this.changed;
+ return this.changed;
},
-
+
/**
* @param {String} [option] The option to check
* @returns {Boolean} true if the option has been changed from the
default.
*/
isDirty: function(option) {
- 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
* @param {String} option
* @returns {Boolean} true if the option exists, else false.
*/
has: function(option) {
- return (this.options[option]);
+ return (this.options[option]);
},
/**
* Reset the options back to the default values.
- * @param {String} id
*/
reset: function() {
- this.changed = {};
+ this.changed = {};
},
-
+
/**
* Sets the value of specified option(s) for the passed in id.
* @param {String} option
* @param {Object} value The value for the option
*/
set: function(option, value) {
- if (typeof option == 'object') {
- var options = option;
- this.options = Ext.apply(this.options, options);
- for (var option in options) {
- this.onChange(option, options[option]);
+ if (typeof option == 'object') {
+ var options = option;
+ this.options = Ext.apply(this.options, options);
+ for (var option in options) {
+ this.onChange(option, options[option]);
+ }
+ } else {
+ this.options[option] = value;
+ this.onChange(option, value)
}
- } else {
- this.options[option] = value;
- this.onChange(option, value)
- }
},
-
+
/**
* Update the value for the specified option and id.
* @param {String|Object} option or options to update
* @param {Object} [value];
*/
update: function(option, value) {
- if (typeof value === undefined) {
- for (var key in option) {
- this.update(key, option[key]);
- }
- } else {
- var defaultValue = this.getDefault(option);
- value = this.convertValueType(defaultValue, value);
-
- 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;
- }
+ if (value === undefined) {
+ for (var key in option) {
+ this.update(key, option[key]);
+ }
+ } else {
+ var defaultValue = this.getDefault(option);
+ value = this.convertValueType(defaultValue, value);
- this.changed[option] = value;
- this.fireEvent('changed', option, value, oldValue);
- }
+ 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.fireEvent('changed', option, value, oldValue);
+ }
},
-
- /* Event Handlers */
+
+ /******************
+ * Event Handlers *
+ ******************/
/**
* Lets the option manager know when a field is blurred so if a value
* so value changing operations can continue on that field.
*/
onFieldBlur: function(field, event) {
- if (this.focused == field) {
- this.focused = null;
- }
+ if (this.focused == field) {
+ this.focused = null;
+ }
},
-
+
/**
* Stops a form fields value from being blocked by the change functions
* @param {Ext.form.Field} field
* @private
*/
onFieldChange: function(field, event) {
- this.update(field._doption, field.getValue());
+ this.update(field._doption, field.getValue());
},
-
+
/**
* Lets the option manager know when a field is focused so if a value
* changing operation is performed it won't change the value of the
* field.
*/
onFieldFocus: function(field, event) {
- this.focused = field;
+ this.focused = field;
},
-
- onChange: function(option, newValue, oldValue) {
- // If we don't have a bind there's nothing to do.
- 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.
- bind.setValue(newValue);
- }, this)
+ onChange: function(option, newValue, oldValue) {
+ // If we don't have a bind there's nothing to do.
+ 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.
+ bind.setValue(newValue);
+ }, this);
}
});
Modified: trunk/deluge/ui/web/js/Deluge.MultiOptionsManager.js
===================================================================
--- trunk/deluge/ui/web/js/Deluge.MultiOptionsManager.js 2009-10-13
15:22:24 UTC (rev 5843)
+++ trunk/deluge/ui/web/js/Deluge.MultiOptionsManager.js 2009-10-13
16:21:28 UTC (rev 5844)
@@ -20,15 +20,15 @@
51 Franklin Street, Fifth Floor
Boston, MA 02110-1301, USA.
- In addition, as a special exception, the copyright holders give
- permission to link the code of portions of this program with the OpenSSL
- library.
- You must obey the GNU General Public License in all respects for all of
- the code used other than OpenSSL. If you modify file(s) with this
- exception, you may extend this exception to your version of the file(s),
- but you are not obligated to do so. If you do not wish to do so, delete
- this exception statement from your version. If you delete this exception
- statement from all source files in the program, then also delete it here.
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of portions of this program with the OpenSSL
+ library.
+ You must obey the GNU General Public License in all respects for all of
+ the code used other than OpenSSL. If you modify file(s) with this
+ exception, you may extend this exception to your version of the file(s),
+ but you are not obligated to do so. If you do not wish to do so, delete
+ this exception statement from your version. If you delete this exception
+ statement from all source files in the program, then also delete it
here.
*/
/**
@@ -37,67 +37,35 @@
* @class Deluge.MultiOptionsManager
*/
Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, {
-
+
constructor: function(config) {
- config = config || {};
- this.options = {};
- this.binds = {};
- 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);
+ this.currentId = null;
+ this.stored = {};
+ Deluge.MultiOptionsManager.superclass.constructor.call(this,
config);
},
/**
- * 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;
- }
- },
-
- /**
* Changes bound fields to use the specified id.
* @param {String} id
*/
changeId: function(id) {
this.currentId = id;
- for (var option in this.defaults) {
+ for (var option in this.options) {
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
@@ -105,47 +73,50 @@
* @param {String|Array} [option] A single option or an array of
options to return.
* @returns {Object} the options value.
*/
- get: function(id, option) {
- if (!option) {
- var values = {};
- for (var key in this.defaults) {
- values[key] = this.get(id, key);
- }
- return values;
+ get: function() {
+ var id = arguments[0];
+ if (arguments.length == 2) {
+ var option = arguments[1];
+ return (this.isDirty(id, option)) ?
this.changed[id][option] : this.getDefault(id, option);
} 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.
* @param {String} id
* @param {String|Array} [option] A single option or an array of
options to return.
* @returns {Object} the value of the 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] : {};
+ },
+
+ /**
* 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) {
+ isDirty: function(id, option) {
return (this.changed[id] &&
!Ext.isEmpty(this.changed[id][option]));
},
-
+
/**
* Check to see if an id has had an option set to something other than
the
* default value.
@@ -153,8 +124,8 @@
* @param {String} option
* @returns {Boolean} true if the id has an option, else false.
*/
- hasOption: function(id, option) {
- return (this.options[id] &&
!Ext.isEmpty(this.options[id][option]));
+ has: function(id, option) {
+ return (this.stored[id] &&
!Ext.isEmpty(this.stored[id][option]));
},
/**
@@ -165,7 +136,7 @@
if (!this.changed[id]) return;
delete this.changed[id];
},
-
+
/**
* Sets the value of specified option for the passed in id.
* @param {String} id
@@ -178,11 +149,11 @@
this.set(id, key, option[key]);
}
} else {
- if (!this.options[id]) this.options[id] = {};
- this.options[id][option] = value;
+ if (!this.changed[id]) this.changed[id] = {};
+ this.changed[id][option] = value;
}
},
-
+
/**
* Update the value for the specified option and id.
* @param {String} id
@@ -190,59 +161,51 @@
* @param {Object} [value];
*/
update: function(id, option, value) {
- if (typeof value === undefined) {
+ if (value === undefined) {
for (var key in option) {
this.update(id, key, option[key]);
}
} else {
if (!this.changed[id]) this.changed[id] = {};
+
+ var defaultValue = this.getDefault(id, option);
+ value = this.convertValueType(defaultValue, value);
var oldValue = this.get(id, option);
if (oldValue == value) return;
-
- var defaultValue = this.getDefault(id, option);
+
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);
return;
+ } else {
+ this.changed[id][option] = value;
+ this.fireEvent('changed', id, option, value,
oldValue);
}
-
- 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.fireEvent('changed', id, option, value, oldValue);
}
},
-
- /* Event Handlers */
-
+
+ /******************
+ * Event Handlers *
+ ******************/
/**
* Stops a form fields value from being blocked by the change functions
* @param {Ext.form.Field} field
* @private
*/
- onFieldChange: function(field) {
- var option = this.binds[field];
- this.update(this.currentId, option, field.getValue());
+ onFieldChange: function(field, event) {
+ this.update(this.currentId, field._doption, field.getValue());
},
-
+
onChange: function(id, option, newValue, oldValue) {
// If we don't have a bind there's nothing to do.
if (Ext.isEmpty(this.binds[option])) return;
-
- // Set the form field to the new value.
- this.binds[option].setValue(newValue);
+ 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.
+ bind.setValue(newValue);
+ }, this);
}
-});
\ No newline at end of file
+});
Modified: trunk/deluge/ui/web/js/Deluge.OptionsManager.js
===================================================================
--- trunk/deluge/ui/web/js/Deluge.OptionsManager.js 2009-10-13 15:22:24 UTC
(rev 5843)
+++ trunk/deluge/ui/web/js/Deluge.OptionsManager.js 2009-10-13 16:21:28 UTC
(rev 5844)
@@ -95,7 +95,7 @@
this.options = Ext.apply(this.options, this.changed);
this.reset();
},
-
+
/**
* Converts the value so it matches the originals type
* @param {Mixed} oldValue The original value
@@ -103,183 +103,172 @@
*/
convertValueType: function(oldValue, value) {
if (Ext.type(oldValue) != Ext.type(value)) {
- switch (Ext.type(oldValue)) {
- case 'string':
- value = String(value);
- break;
- case 'number':
- value = Number(value);
- break;
- case 'boolean':
- if (Ext.type(value) == 'string') {
- value = value.toLowerCase();
- value = (value == 'true' || newValue == '1' ||
value == 'on') ? true : false;
- } else {
- value = Boolean(value);
+ switch (Ext.type(oldValue)) {
+ case 'string':
+ value = String(value);
+ break;
+ case 'number':
+ value = Number(value);
+ break;
+ case 'boolean':
+ if (Ext.type(value) == 'string') {
+ value = value.toLowerCase();
+ value = (value == 'true' ||
value == '1' || value == 'on') ? true : false;
+ } else {
+ value = Boolean(value);
+ }
+ break;
}
- break;
}
- }
- return value;
+ return value;
},
-
+
/**
* Get the value for an option or options.
* @param {String} [option] A single option or an array of options to
return.
* @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;
- }
+ 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;
+ }
},
-
+
/**
* Get the default value for an option or options.
* @param {String|Array} [option] A single option or an array of
options to return.
* @returns {Object} the value of the option
*/
getDefault: function(option) {
- return this.options[option];
+ return this.options[option];
},
-
+
/**
* Returns the dirty (changed) values.
* @returns {Object} the changed options
*/
getDirty: function() {
- return this.changed;
+ return this.changed;
},
-
+
/**
* @param {String} [option] The option to check
* @returns {Boolean} true if the option has been changed from the
default.
*/
isDirty: function(option) {
- 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
* @param {String} option
* @returns {Boolean} true if the option exists, else false.
*/
has: function(option) {
- return (this.options[option]);
+ return (this.options[option]);
},
/**
* Reset the options back to the default values.
- * @param {String} id
*/
reset: function() {
- this.changed = {};
+ this.changed = {};
},
-
+
/**
* Sets the value of specified option(s) for the passed in id.
* @param {String} option
* @param {Object} value The value for the option
*/
set: function(option, value) {
- if (typeof option == 'object') {
- var options = option;
- this.options = Ext.apply(this.options, options);
- for (var option in options) {
- this.onChange(option, options[option]);
+ if (typeof option == 'object') {
+ var options = option;
+ this.options = Ext.apply(this.options, options);
+ for (var option in options) {
+ this.onChange(option, options[option]);
+ }
+ } else {
+ this.options[option] = value;
+ this.onChange(option, value)
}
- } else {
- this.options[option] = value;
- this.onChange(option, value)
- }
},
-
+
/**
* Update the value for the specified option and id.
* @param {String|Object} option or options to update
* @param {Object} [value];
*/
update: function(option, value) {
- if (typeof value === undefined) {
- for (var key in option) {
- this.update(key, option[key]);
- }
- } else {
- var defaultValue = this.getDefault(option);
- value = this.convertValueType(defaultValue, value);
-
- 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;
- }
+ if (value === undefined) {
+ for (var key in option) {
+ this.update(key, option[key]);
+ }
+ } else {
+ var defaultValue = this.getDefault(option);
+ value = this.convertValueType(defaultValue, value);
- this.changed[option] = value;
- this.fireEvent('changed', option, value, oldValue);
- }
+ 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.fireEvent('changed', option, value, oldValue);
+ }
},
-
- /* Event Handlers */
+
+ /******************
+ * Event Handlers *
+ ******************/
/**
* Lets the option manager know when a field is blurred so if a value
* so value changing operations can continue on that field.
*/
onFieldBlur: function(field, event) {
- if (this.focused == field) {
- this.focused = null;
- }
+ if (this.focused == field) {
+ this.focused = null;
+ }
},
-
+
/**
* Stops a form fields value from being blocked by the change functions
* @param {Ext.form.Field} field
* @private
*/
onFieldChange: function(field, event) {
- this.update(field._doption, field.getValue());
+ this.update(field._doption, field.getValue());
},
-
+
/**
* Lets the option manager know when a field is focused so if a value
* changing operation is performed it won't change the value of the
* field.
*/
onFieldFocus: function(field, event) {
- this.focused = field;
+ this.focused = field;
},
-
- onChange: function(option, newValue, oldValue) {
- // If we don't have a bind there's nothing to do.
- 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.
- bind.setValue(newValue);
- }, this)
+ onChange: function(option, newValue, oldValue) {
+ // If we don't have a bind there's nothing to do.
+ 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.
+ bind.setValue(newValue);
+ }, this);
}
});
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---