fire only one event per check, pass an array of nodes

implement #1161 for the webui
This commit is contained in:
Damien Churchill 2010-04-28 01:06:28 +01:00
commit 8414b9cfa9
2 changed files with 40 additions and 33 deletions

View file

@ -84,18 +84,24 @@ Deluge.add.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, {
}); });
}, },
setDownload: function(node, value) { setDownload: function(node, value, suppress) {
node.attributes.download = value; node.attributes.download = value;
node.ui.updateColumns(); node.ui.updateColumns();
if (node.isLeaf()) { if (node.isLeaf()) {
return this.fireEvent('filechecked', node, value, !value); if (!suppress) {
return this.fireEvent('fileschecked', [node], value, !value);
}
} else { } else {
var nodes = [node];
node.cascade(function(n) { node.cascade(function(n) {
n.attributes.download = value; n.attributes.download = value;
n.ui.updateColumns(); n.ui.updateColumns();
return this.fireEvent('filechecked', n, value, !value); nodes.push(n);
}, this); }, this);
if (!suppress) {
return this.fireEvent('fileschecked', nodes, value, !value);
}
} }
}, },

View file

@ -46,7 +46,7 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
this.files = this.add(new Deluge.add.FilesTab()); this.files = this.add(new Deluge.add.FilesTab());
this.form = this.add(new Deluge.add.OptionsTab()); this.form = this.add(new Deluge.add.OptionsTab());
this.files.on('filechecked', this.onFileChecked, this); this.files.on('fileschecked', this.onFilesChecked, this);
}, },
addTorrent: function(torrent) { addTorrent: function(torrent) {
@ -125,34 +125,35 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
} }
}, },
onFileChecked: function(node, newValue, oldValue) { onFilesChecked: function(nodes, newValue, oldValue) {
if (!Ext.isNumber(node.attributes.fileindex)) return; if (this.form.optionsManager.get('compact_allocation')) {
Ext.Msg.show({
// if (this.form.optionsManager.get('compact_allocation')) { title: _('Unable to set file priority!'),
// Ext.Msg.show({ msg: _('File prioritization is unavailable when using Compact allocation. Would you like to switch to Full allocation?'),
// title: _('Unable to set file priority!'), buttons: Ext.Msg.YESNO,
// msg: _('File prioritization is unavailable when using Compact allocation. Would you like to switch to Full allocation?'), fn: function(result) {
// buttons: Ext.Msg.YESNO, if (result == 'yes') {
// fn: function(result) { this.form.optionsManager.update('compact_allocation', false);
// if (result == 'yes') { Ext.each(nodes, function(node) {
// var priorities = this.form.optionsManager.get('file_priorities'); if (node.attributes.fileindex < 0) return;
// priorities[node.attributes.fileindex] = (result) ? newValue : oldValue; var priorities = this.form.optionsManager.get('file_priorities');
// this.form.optionsManager.update('file_priorities', priorities); priorities[node.attributes.fileindex] = newValue;
// } else { this.form.optionsManager.update('file_priorities', priorities);
// node.attributes.download = oldValue; }, this);
// node.ui.updateColumns(); } else {
// } this.files.setDownload(nodes[0], oldValue, true);
// }, }
// scope: this, },
// icon: Ext.MessageBox.QUESTION scope: this,
// }); icon: Ext.MessageBox.QUESTION
// } else { });
// var priorities = this.form.optionsManager.get('file_priorities'); } else {
// priorities[node.attributes.fileindex] = newValue; Ext.each(nodes, function(node) {
// this.form.optionsManager.update('file_priorities', priorities); if (node.attributes.fileindex < 0) return;
// } var priorities = this.form.optionsManager.get('file_priorities');
var priorities = this.form.optionsManager.get('file_priorities'); priorities[node.attributes.fileindex] = newValue;
priorities[node.attributes.fileindex] = newValue; this.form.optionsManager.update('file_priorities', priorities);
this.form.optionsManager.update('file_priorities', priorities); }, this);
}
} }
}); });