1 /* 2 Script: Deluge.Preferences.js 3 Contains the preferences window. 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 (function() { 36 Ext.deluge.PreferencesWindow = Ext.extend(Ext.Window, { 37 constructor: function(config) { 38 config = Ext.apply({ 39 layout: 'border', 40 width: 485, 41 height: 500, 42 buttonAlign: 'right', 43 closeAction: 'hide', 44 closable: true, 45 iconCls: 'x-deluge-preferences', 46 plain: true, 47 resizable: true, 48 title: _('Preferences'), 49 50 buttons: [{ 51 text: _('Close'), 52 handler: this.onCloseButtonClick, 53 scope: this 54 },{ 55 text: _('Apply') 56 },{ 57 text: _('Ok') 58 }], 59 60 currentPage: false, 61 items: [{ 62 xtype: 'grid', 63 region: 'west', 64 title: _('Categories'), 65 store: new Ext.data.SimpleStore({ 66 fields: [{name: 'name', mapping: 0}] 67 }), 68 columns: [{id: 'name', renderer: fplain, dataIndex: 'name'}], 69 sm: new Ext.grid.RowSelectionModel({ 70 singleSelect: true, 71 listeners: {'rowselect': {fn: this.onPageSelect, scope: this}} 72 }), 73 hideHeaders: true, 74 autoExpandColumn: 'name', 75 deferredRender: false, 76 autoScroll: true, 77 margins: '5 0 5 5', 78 cmargins: '5 0 5 5', 79 width: 120, 80 collapsible: true 81 }, { 82 region: 'center', 83 header: false, 84 layout: 'fit', 85 height: 400, 86 margins: '5 5 5 5', 87 cmargins: '5 5 5 5' 88 }] 89 }, config); 90 Ext.deluge.PreferencesWindow.superclass.constructor.call(this, config); 91 }, 92 93 initComponent: function() { 94 Ext.deluge.PreferencesWindow.superclass.initComponent.call(this); 95 this.categoriesGrid = this.items.get(0); 96 this.configPanel = this.items.get(1); 97 this.pages = {}; 98 this.on('show', this.onShow, this); 99 }, 100 101 onCloseButtonClick: function() { 102 this.hide(); 103 }, 104 105 addPage: function(page) { 106 var store = this.categoriesGrid.getStore(); 107 var name = page.title; 108 store.loadData([[name]], true); 109 page['bodyStyle'] = 'margin: 5px'; 110 this.pages[name] = this.configPanel.add(page); 111 this.pages[name].hide(); 112 }, 113 114 onPageSelect: function(selModel, rowIndex, r) { 115 if (this.currentPage) { 116 this.currentPage.hide(); 117 } 118 var name = r.get('name'); 119 120 this.pages[name].show(); 121 this.currentPage = this.pages[name]; 122 this.configPanel.doLayout(); 123 }, 124 125 onShow: function() { 126 if (!this.categoriesGrid.getSelectionModel().hasSelection()) { 127 this.categoriesGrid.getSelectionModel().selectFirstRow(); 128 } 129 } 130 }); 131 132 Deluge.Preferences = new Ext.deluge.PreferencesWindow(); 133 })();