From dd1716c2400c9a15556634a1650f9949149968e9 Mon Sep 17 00:00:00 2001 From: Damien Churchill Date: Mon, 19 Apr 2010 13:59:21 +0100 Subject: [PATCH] improve the selective downloading adding support for directories and don't recreate treenodes --- deluge/ui/web/js/deluge-all/add/FilesTab.js | 36 ++++++------ .../ui/web/js/deluge-all/add/OptionsPanel.js | 55 ++++++++++++------- 2 files changed, 53 insertions(+), 38 deletions(-) diff --git a/deluge/ui/web/js/deluge-all/add/FilesTab.js b/deluge/ui/web/js/deluge-all/add/FilesTab.js index 7d7db7112..128ff3aca 100644 --- a/deluge/ui/web/js/deluge-all/add/FilesTab.js +++ b/deluge/ui/web/js/deluge-all/add/FilesTab.js @@ -65,7 +65,7 @@ Deluge.add.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { dataIndex: 'download', tpl: new Ext.XTemplate('{download:this.format}', { format: function(v) { - return '
'; + return '
'; } }) }], @@ -84,23 +84,25 @@ Deluge.add.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { }); }, - onNodeClick: function(node, e) { - node.attributes.download = !node.attributes.download; - var newNode = new Ext.tree.TreeNode(node.attributes); - node.parentNode.replaceChild(newNode, node); - this.fireEvent('filechecked', newNode, node.attributes.download, !node.attributes.download); + setDownload: function(node, value) { + node.attributes.download = value; + node.ui.updateColumns(); + + if (node.isLeaf()) { + return this.fireEvent('filechecked', node, value, !value); + } else { + node.cascade(function(n) { + n.attributes.download = value; + n.ui.updateColumns(); + return this.fireEvent('filechecked', n, value, !value); + }, this); + } }, - onFolderCheck: function(node, checked) { - var priorities = this.optionsManager.get('file_priorities'); - node.cascade(function(child) { - if (!child.ui.checkbox) { - child.attributes.checked = checked; - } else { - child.ui.checkbox.checked = checked; - } - priorities[child.attributes.fileindex] = checked; - }, this); - this.optionsManager.setDefault('file_priorities', priorities); + onNodeClick: function(node, e) { + var el = new Ext.Element(e.target); + if (el.getAttribute('rel') == 'chkbox') { + this.setDownload(node, !node.attributes.download); + } } }); diff --git a/deluge/ui/web/js/deluge-all/add/OptionsPanel.js b/deluge/ui/web/js/deluge-all/add/OptionsPanel.js index b925d26a1..b6e1a55fd 100644 --- a/deluge/ui/web/js/deluge-all/add/OptionsPanel.js +++ b/deluge/ui/web/js/deluge-all/add/OptionsPanel.js @@ -97,27 +97,15 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, { var priorities = this.form.optionsManager.get('file_priorities'); this.walkFileTree(this.torrents[torrentId]['files_tree'], function(filename, type, entry, parentNode) { - if (type == 'dir') { - var folder = new Ext.tree.TreeNode({ - filename: filename, - size: entry.length, - download: true - }); - folder.on('checkchange', this.onFolderCheck, this); - parentNode.appendChild(folder); - return folder; - } else { - var node = new Ext.tree.TreeNode({ - filename: filename, - fileindex: entry.index, - size: entry.length, - leaf: true, - download: priorities[entry.index], - uiProvider: Ext.tree.ColumnNodeUI - }); - node.on('checkchange', this.onNodeCheck, this); - parentNode.appendChild(node); - } + var node = new Ext.tree.TreeNode({ + download: (entry.index) ? priorities[entry.index] : true, + filename: filename, + fileindex: entry.index, + leaf: type != 'dir', + size: entry.length + }); + parentNode.appendChild(node); + if (type == 'dir') return node; }, this, root); root.firstChild.expand(); }, @@ -138,6 +126,31 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, { }, onFileChecked: function(node, newValue, oldValue) { + if (!Ext.isNumber(node.attributes.fileindex)) return; + +// if (this.form.optionsManager.get('compact_allocation')) { +// Ext.Msg.show({ +// title: _('Unable to set file priority!'), +// msg: _('File prioritization is unavailable when using Compact allocation. Would you like to switch to Full allocation?'), +// buttons: Ext.Msg.YESNO, +// fn: function(result) { +// if (result == 'yes') { +// var priorities = this.form.optionsManager.get('file_priorities'); +// priorities[node.attributes.fileindex] = (result) ? newValue : oldValue; +// this.form.optionsManager.update('file_priorities', priorities); +// } else { +// node.attributes.download = oldValue; +// node.ui.updateColumns(); +// } +// }, +// scope: this, +// icon: Ext.MessageBox.QUESTION +// }); +// } else { +// var priorities = this.form.optionsManager.get('file_priorities'); +// priorities[node.attributes.fileindex] = newValue; +// this.form.optionsManager.update('file_priorities', priorities); +// } var priorities = this.form.optionsManager.get('file_priorities'); priorities[node.attributes.fileindex] = newValue; this.form.optionsManager.update('file_priorities', priorities);