allow for the scope to be specified when calling the walkFileTree method

This commit is contained in:
Damien Churchill 2009-07-06 11:51:06 +00:00
commit 66243d1859
2 changed files with 22 additions and 25 deletions

View file

@ -215,7 +215,8 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
addTorrent: function(torrent) { addTorrent: function(torrent) {
this.torrents[torrent['info_hash']] = torrent; this.torrents[torrent['info_hash']] = torrent;
this.walkFileTree(torrent['files_tree'], function(filename, type, entry, parent) {
}, this);
}, },
clear: function() { clear: function() {
@ -263,23 +264,8 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
}); });
}, },
getFilePriorities: function() { getOptions: function(torrentId) {
var root = this.files.getRootNode();
var priorities = {};
function getCheckedState(node) {
if (node.ui.checkbox) {
return node.ui.checkbox.checked;
} else {
return getCheckedState(node.parentNode);
}
}
root.cascade(function(node) {
if (!node.isLeaf()) return;
priorities[node.attributes.fileindex] = getCheckedState(node);
});
return priorities;
}, },
setTorrent: function(torrentId) { setTorrent: function(torrentId) {
@ -292,11 +278,11 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
text: filename, text: filename,
checked: true checked: true
}); });
folder.on('checkchange', self.onFolderCheck, self); folder.on('checkchange', this.onFolderCheck, self);
parent.appendChild(folder); parent.appendChild(folder);
return folder; return folder;
} else { } else {
parent.appendChild(new Ext.tree.TreeNode({ var node = new Ext.tree.TreeNode({
filename: filename, filename: filename,
fileindex: entry[0], fileindex: entry[0],
text: filename, // this needs to be here for sorting reasons text: filename, // this needs to be here for sorting reasons
@ -305,20 +291,27 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
checked: entry[2], checked: entry[2],
iconCls: 'x-deluge-file', iconCls: 'x-deluge-file',
uiProvider: Ext.tree.ColumnNodeUI uiProvider: Ext.tree.ColumnNodeUI
})); });
node.on('checkchange', this.onNodeCheck, self);
parent.appendChild(node);
} }
}, root); }, this, root);
root.firstChild.expand(); root.firstChild.expand();
}, },
walkFileTree: function(files, callback, parent) { walkFileTree: function(files, callback, scope, parent) {
for (var filename in files) { for (var filename in files) {
var entry = files[filename]; var entry = files[filename];
var type = (Ext.type(entry) == 'object') ? 'dir' : 'file'; var type = (Ext.type(entry) == 'object') ? 'dir' : 'file';
var ret = callback(filename, type, entry, parent) if (scope) {
var ret = callback.apply(scope, [filename, type, entry, parent]);
} else {
var ret = callback(filename, type, entry, parent);
}
parent = (ret) ? ret : parent; parent = (ret) ? ret : parent;
if (type == 'dir') this.walkFileTree(entry, callback, parent); if (type == 'dir') this.walkFileTree(entry, callback, scope, parent);
} }
}, },
@ -327,6 +320,10 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
if (!child.ui.checkbox) return; if (!child.ui.checkbox) return;
child.ui.checkbox.checked = checked; child.ui.checkbox.checked = checked;
}, this); }, this);
},
onNodeCheck: function(node, checked) {
} }
}); });

File diff suppressed because one or more lines are too long