      1 /*
      2 Script: Deluge.Details.js
      3     Contains all objects and functions related to the lower details panel and
      4 	it's containing tabs.
      5
      6 Copyright:
      7 	(C) Damien Churchill 2009 <damoxc@gmail.com>
      8 	This program is free software; you can redistribute it and/or modify
      9 	it under the terms of the GNU General Public License as published by
     10 	the Free Software Foundation; either version 3, or (at your option)
     11 	any later version.
     12
     13 	This program is distributed in the hope that it will be useful,
     14 	but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 	GNU General Public License for more details.
     17
     18 	You should have received a copy of the GNU General Public License
     19 	along with this program.  If not, write to:
     20 		The Free Software Foundation, Inc.,
     21 		51 Franklin Street, Fifth Floor
     22 		Boston, MA  02110-1301, USA.
     23
     24     In addition, as a special exception, the copyright holders give
     25     permission to link the code of portions of this program with the OpenSSL
     26     library.
     27     You must obey the GNU General Public License in all respects for all of
     28     the code used other than OpenSSL. If you modify file(s) with this
     29     exception, you may extend this exception to your version of the file(s),
     30     but you are not obligated to do so. If you do not wish to do so, delete
     31     this exception statement from your version. If you delete this exception
     32     statement from all source files in the program, then also delete it here.
     33 */
     34
     35 (function() {
     36 	Ext.namespace('Ext.deluge.details');
     37 	Ext.deluge.details.TabPanel = Ext.extend(Ext.TabPanel, {
     38
     39 		constructor: function(config) {
     40 			config = Ext.apply({
     41 				region: 'south',
     42 				split: true,
     43 				height: 220,
     44 				minSize: 100,
     45 				collapsible: true,
     46 				margins: '0 5 5 5',
     47 				activeTab: 0
     48 			}, config);
     49 			Ext.deluge.details.TabPanel.superclass.constructor.call(this, config);
     50 		},
     51
     52 		clear: function() {
     53 			this.items.each(function(panel) {
     54 				if (panel.clear) panel.clear();
     55 			});
     56 		},
     57
     58
     59 		update: function(tab) {
     60 			var torrent = Deluge.Torrents.getSelected();
     61 			if (!torrent) {
     62 				this.items.each(function(tab) {
     63 					tab.disable();
     64 				});
     65 				return;
     66 			}
     67
     68 			this.items.each(function(tab) {
     69 				tab.enable();
     70 			});
     71
     72 			tab = tab || this.getActiveTab();
     73 			if (tab.update) tab.update(torrent.id);
     74 		},
     75
     76 		/* Event Handlers */
     77
     78 		// We need to add the events in onRender since Deluge.Torrents hasn't
     79 		// been created yet.
     80 		onRender: function(ct, position) {
     81 			Ext.deluge.details.TabPanel.superclass.onRender.call(this, ct, position);
     82 			Deluge.Events.on('disconnect', this.clear, this);
     83 			Deluge.Torrents.on('rowclick', this.onTorrentsClick, this);
     84 			this.on('tabchange', this.onTabChange, this);
     85
     86 			Deluge.Torrents.getSelectionModel().on('selectionchange', function(selModel) {
     87 				if (!selModel.hasSelection()) this.clear();
     88 			}, this);
     89 		},
     90
     91 		onTabChange: function(panel, tab) {
     92 			this.update(tab);
     93 		},
     94
     95 		onTorrentsClick: function(grid, rowIndex, e) {
     96 			this.update();
     97 		}
     98 	});
     99 	Deluge.Details = new Ext.deluge.details.TabPanel();
    100 })();
    101