      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 				id: 'torrentDetails',
     43 				split: true,
     44 				height: 220,
     45 				minSize: 100,
     46 				collapsible: true,
     47 				margins: '0 5 5 5',
     48 				activeTab: 0
     49 			}, config);
     50 			Ext.deluge.details.TabPanel.superclass.constructor.call(this, config);
     51 		},
     52
     53 		clear: function() {
     54 			this.items.each(function(panel) {
     55 				if (panel.clear) {
     56 					panel.clear.defer(100, panel);
     57 					panel.disable();
     58 				}
     59 			});
     60 		},
     61
     62
     63 		update: function(tab) {
     64 			var torrent = Deluge.Torrents.getSelected();
     65 			if (!torrent) {
     66 				this.clear();
     67 				return;
     68 			}
     69
     70 			this.items.each(function(tab) {
     71 				if (tab.disabled) tab.enable();
     72 			});
     73
     74 			tab = tab || this.getActiveTab();
     75 			if (tab.update) tab.update(torrent.id);
     76 		},
     77
     78 		/* Event Handlers */
     79
     80 		// We need to add the events in onRender since Deluge.Torrents hasn't
     81 		// been created yet.
     82 		onRender: function(ct, position) {
     83 			Ext.deluge.details.TabPanel.superclass.onRender.call(this, ct, position);
     84 			Deluge.Events.on('disconnect', this.clear, this);
     85 			Deluge.Torrents.on('rowclick', this.onTorrentsClick, this);
     86 			this.on('tabchange', this.onTabChange, this);
     87
     88 			Deluge.Torrents.getSelectionModel().on('selectionchange', function(selModel) {
     89 				if (!selModel.hasSelection()) this.clear();
     90 			}, this);
     91 		},
     92
     93 		onTabChange: function(panel, tab) {
     94 			this.update(tab);
     95 		},
     96
     97 		onTorrentsClick: function(grid, rowIndex, e) {
     98 			this.update();
     99 		}
    100 	});
    101 	Deluge.Details = new Ext.deluge.details.TabPanel();
    102 })();
    103