diff options
Diffstat (limited to 'deluge/ui/webui/templates/ajax/static/js/deluge-preferences.js')
-rw-r--r-- | deluge/ui/webui/templates/ajax/static/js/deluge-preferences.js | 82 |
1 files changed, 48 insertions, 34 deletions
diff --git a/deluge/ui/webui/templates/ajax/static/js/deluge-preferences.js b/deluge/ui/webui/templates/ajax/static/js/deluge-preferences.js index 9c1c3600d..9ad32e6f5 100644 --- a/deluge/ui/webui/templates/ajax/static/js/deluge-preferences.js +++ b/deluge/ui/webui/templates/ajax/static/js/deluge-preferences.js @@ -3,11 +3,25 @@ Script: deluge-preferences.js Contains the classes that provides the preferences window with functionality -License: - General Public License v3 - -Copyright: - Damien Churchill (c) 2008 <damoxc@gmail.com> + * + * Copyright (C) Damien Churchill 2008 <damoxc@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * */ Deluge.Widgets.PreferencesCategory = new Class({ @@ -20,7 +34,7 @@ Deluge.Widgets.PluginPreferencesCategory = new Class({ Deluge.Widgets.GenericPreferences = new Class({ Extends: Deluge.Widgets.PreferencesCategory, - + initialize: function(name, options) { this.parent(name, options) this.core = true; @@ -41,16 +55,16 @@ Deluge.Widgets.GenericPreferences = new Class({ }); }.bindWithEvent(this)); }, - + update: function(config) { this.fireEvent('beforeUpdate'); - this.original = config; + this.original = config; this.changed = new Hash(); this.inputs = this.form.getElements('input, select'); this.inputs.each(function(input) { if (!input.name) return; if (!$defined(config[input.name])) return; - + widget = $$W(input); if (widget) { widget.setValue(config[input.name]); @@ -71,7 +85,7 @@ Deluge.Widgets.GenericPreferences = new Class({ input.checked = true; } } - + input.addEvent('change', function(el) { if (input.type == 'checkbox') { if (this.original[input.name] == input.checked) { @@ -111,18 +125,18 @@ Deluge.Widgets.GenericPreferences = new Class({ Deluge.Widgets.WebUIPreferences = new Class({ Extends: Deluge.Widgets.GenericPreferences, - + options: { url: '/template/render/html/preferences_webui.html' }, - + initialize: function() { this.parent('Web UI'); this.core = false; this.addEvent('beforeUpdate', this.beforeUpdate.bindWithEvent(this)); this.addEvent('update', this.updated.bindWithEvent(this)); }, - + beforeUpdate: function(event) { var templates = Deluge.Client.get_webui_templates({async: false}); this.form.template.empty(); @@ -132,16 +146,16 @@ Deluge.Widgets.WebUIPreferences = new Class({ this.form.template.grab(option); }, this); }, - + updated: function(event) { if (this.form.template.value != 'ajax') this.form.theme.disabled = true; else this.form.theme.disabled = false; - + var theme = this.form.theme.getElement('option[value="' + Cookie.read('theme') + '"]') theme.selected = true - + this.form.template.addEvent('change', function(e) { if (this.form.template.value != 'ajax') { this.form.theme.disabled = true; @@ -154,7 +168,7 @@ Deluge.Widgets.WebUIPreferences = new Class({ } }.bindWithEvent(this)); }, - + apply: function() { Deluge.UI.setTheme(this.form.theme.value); Deluge.Client.set_webui_config(this.changed, { @@ -173,7 +187,7 @@ Deluge.Widgets.PreferencesWindow = new Class({ title: 'Preferences', url: '/template/render/html/window_preferences.html' }, - + initialize: function() { this.parent(); this.categories = []; @@ -181,18 +195,18 @@ Deluge.Widgets.PreferencesWindow = new Class({ this.addEvent('loaded', this.loaded.bindWithEvent(this)); this.addEvent('beforeShow', this.beforeShown.bindWithEvent(this)); }, - + loaded: function(event) { this.catlist = this.content.getElement('.categories ul'); this.pages = this.content.getElement('.pref_pages'); this.title = this.pages.getElement('h3'); - + this.reset = this.content.getElement('.buttons .reset'); this.apply = this.content.getElement('.buttons .apply'); this.apply.addEvent('click', this.applied.bindWithEvent(this)); - + this.webui = new Deluge.Widgets.WebUIPreferences(); - + this.download = new Deluge.Widgets.GenericPreferences('Download', { url: '/template/render/html/preferences_download.html' }); @@ -208,7 +222,7 @@ Deluge.Widgets.PreferencesWindow = new Class({ this.queue = new Deluge.Widgets.GenericPreferences('Queue', { url: '/template/render/html/preferences_queue.html' }); - + this.addCategory(this.webui); this.addCategory(this.download); this.addCategory(this.network); @@ -216,11 +230,11 @@ Deluge.Widgets.PreferencesWindow = new Class({ this.addCategory(this.daemon); this.addCategory(this.queue); }, - + addCategory: function(category) { this.categories.include(category); var categoryIndex = this.categories.indexOf(category); - + var tab = new Element('li'); tab.set('text', category.name); tab.addEvent('click', function(e) { @@ -230,14 +244,14 @@ Deluge.Widgets.PreferencesWindow = new Class({ this.catlist.grab(tab); this.pages.grab(category.addClass('deluge-prefs-page')); - - + + if (this.currentPage < 0) { this.currentPage = categoryIndex; this.select(categoryIndex); }; }, - + select: function(id) { this.categories[this.currentPage].removeClass('deluge-prefs-page-active'); this.categories[this.currentPage].tab.removeClass('deluge-prefs-active'); @@ -247,13 +261,13 @@ Deluge.Widgets.PreferencesWindow = new Class({ this.currentPage = id; this.fireEvent('pageChanged'); }, - + applied: function(event) { var config = {}; this.categories.each(function(category) { config = $merge(config, category.getConfig()); }); - + if ($defined(config['end_listen_port']) || $defined(config['start_listen_port'])) { var startport = $pick(config['start_listen_port'], this.config['listen_ports'][0]); var endport = $pick(config['end_listen_port'], this.config['listen_ports'][1]); @@ -261,7 +275,7 @@ Deluge.Widgets.PreferencesWindow = new Class({ delete config['start_listen_port']; config['listen_ports'] = [startport, endport]; } - + if ($defined(config['end_outgoing_port']) || $defined(config['start_outgoing_port'])) { var startport = $pick(config['start_outgoing_port'], this.config['outgoing_ports'][0]); var endport = $pick(config['end_outgoing_port'], this.config['outgoing_ports'][1]); @@ -269,7 +283,7 @@ Deluge.Widgets.PreferencesWindow = new Class({ delete config['start_outgoing_port']; config['outgoing_ports'] = [startport, endport]; } - + Deluge.Client.set_config(config, { onSuccess: function(e) { this.hide(); @@ -286,7 +300,7 @@ Deluge.Widgets.PreferencesWindow = new Class({ // in order to not have to modify the generic preferences class. this.config['start_listen_port'] = this.config['listen_ports'][0]; this.config['end_listen_port'] = this.config['listen_ports'][1]; - + this.config['start_outgoing_port'] = this.config['outgoing_ports'][0]; this.config['end_outgoing_port'] = this.config['outgoing_ports'][1]; @@ -294,7 +308,7 @@ Deluge.Widgets.PreferencesWindow = new Class({ this.categories.each(function(category) { if (category.update && category.core) category.update(this.config); }, this); - + // Update the config for the webui pages. var webconfig = Deluge.Client.get_webui_config({async: false}); this.webui.update(webconfig); |