      1 /*
      2 Script:
      3 	Deluge.OptionsManager.js
      4
      5 Copyright:
      6 	(C) Damien Churchill 2009 <damoxc@gmail.com>
      7 	This program is free software; you can redistribute it and/or modify
      8 	it under the terms of the GNU General Public License as published by
      9 	the Free Software Foundation; either version 3, or (at your option)
     10 	any later version.
     11
     12 	This program is distributed in the hope that it will be useful,
     13 	but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 	GNU General Public License for more details.
     16
     17 	You should have received a copy of the GNU General Public License
     18 	along with this program.  If not, write to:
     19 		The Free Software Foundation, Inc.,
     20 		51 Franklin Street, Fifth Floor
     21 		Boston, MA  02110-1301, USA.
     22
     23     In addition, as a special exception, the copyright holders give
     24     permission to link the code of portions of this program with the OpenSSL
     25     library.
     26     You must obey the GNU General Public License in all respects for all of
     27     the code used other than OpenSSL. If you modify file(s) with this
     28     exception, you may extend this exception to your version of the file(s),
     29     but you are not obligated to do so. If you do not wish to do so, delete
     30     this exception statement from your version. If you delete this exception
     31     statement from all source files in the program, then also delete it here.
     32 */
     33
     34 /**
     35  * @description A class that can be used to manage options throughout the ui.
     36  * @namespace Deluge
     37  * @class Deluge.OptionsManager
     38  */
     39 Deluge.OptionsManager = Ext.extend(Ext.util.Observable, {
     40
     41 	initComponent: function() {
     42 		Deluge.OptionsManager.superclass.initComponent.call(this);
     43 		this.changed = {};
     44 		this.options = {};
     45 	},
     46
     47 	/**
     48 	 * Add a set of options and values for an id to the options manager
     49 	 * @param {String} id
     50 	 * @param {Object} options The default options for the id.
     51 	 */
     52 	addOptions: function(id, options) {
     53 		this.options[id] = options;
     54 	},
     55
     56 	/**
     57 	 * Reset the options back to the default values for the specified id.
     58 	 * @param {String} id
     59 	 */
     60 	resetOptions: function(id) {
     61 		if (!this.changed[id]) return;
     62 		delete this.changed[id];
     63 	},
     64
     65 	/**
     66 	 * Set the specified option for the passed in id.
     67 	 * @param {String} id
     68 	 * @param {String} option
     69 	 * @param {Object...} value The new value for the option
     70 	 */
     71 	setOption: function(id, option, value) {
     72 		if (!this.changed[id]) this.changed[id] = {};
     73 		this.changed[id][option] = value;
     74 	},
     75
     76 	/**
     77 	 * Set the specified options for the passed in id.
     78 	 * @param {String} id
     79 	 * @param {object} options The option values to change.
     80 	 */
     81 	setOptions: function(id, options) {
     82 		if (!this.changed[id]) this.changed[id] = {};
     83 		this.changed[id] = Ext.extend(this.changed[id], options);
     84 	}
     85 });