saving my work on the tree panel

git-svn-id: https://beef.googlecode.com/svn/trunk@626 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
This commit is contained in:
mosse.benjamin
2010-12-21 10:04:17 +00:00
parent 3f0fc4dd9e
commit 43e4e261f7
2 changed files with 118 additions and 64 deletions

View File

@@ -27,37 +27,36 @@ var ZombiesMgr = function(zombies_tree_lists) {
* @param: {Literal Object} an object containing the list of rules from the distributed engine.
*/
this.updateZombies = function(zombies, rules){
var offline_zombies = zombies["offline"];
var online_zombies = zombies["online"];
var offline_hooked_browsers = zombies["offline"];
var online_hooked_browsers = zombies["online"];
for(tree_type in this.zombies_tree_lists) {
hooked_browsers_tree = this.zombies_tree_lists[tree_type];
//we compare and remove the hooked browsers from online and offline branches for each tree.
hooked_browsers_tree.compareAndRemove(offline_zombies, false);
hooked_browsers_tree.compareAndRemove(online_zombies, true);
hooked_browsers_tree.compareAndRemove(zombies);
//add an offline browser to the tree
for(var i in offline_zombies) {
var offline_hooked_browser = this.zombieFactory(i, offline_zombies);
for(var i in offline_hooked_browsers) {
var offline_hooked_browser = this.zombieFactory(i, offline_hooked_browsers);
hooked_browsers_tree.addZombie(offline_hooked_browser, false);
}
//add an online browser to the tree
for(var i in online_zombies) {
var online_hooked_browser = this.zombieFactory(i, online_zombies);
for(var i in online_hooked_browsers) {
var online_hooked_browser = this.zombieFactory(i, online_hooked_browsers);
hooked_browsers_tree.addZombie(online_hooked_browser, true);
//TODO: add the rules here
}
//expand the online hooked browser tree lists
if(hooked_browsers_tree.online_zombies.childNodes.length > 0) {
hooked_browsers_tree.online_zombies.expand(true);
if(hooked_browsers_tree.online_hooked_browsers_treenode.childNodes.length > 0) {
hooked_browsers_tree.online_hooked_browsers_treenode.expand(true);
}
//expand the offline hooked browser tree lists
if(hooked_browsers_tree.offline_zombies.childNodes.length > 0) {
hooked_browsers_tree.offline_zombies.expand(true);
if(hooked_browsers_tree.offline_hooked_browsers_treenode.childNodes.length > 0) {
hooked_browsers_tree.offline_hooked_browsers_treenode.expand(true);
}
}
}

View File

@@ -17,7 +17,7 @@ zombiesTreeList = function(id) {
collapseFirst:false
});
this.online_zombies = this.root.appendChild(
this.online_hooked_browsers_treenode = this.root.appendChild(
new Ext.tree.TreeNode({
text:'Online Browsers',
cls:'online-zombies-node',
@@ -25,7 +25,7 @@ zombiesTreeList = function(id) {
})
);
this.offline_zombies = this.root.appendChild(
this.offline_hooked_browsers_treenode = this.root.appendChild(
new Ext.tree.TreeNode({
text:'Offline Browsers',
cls:'offline-zombies-node',
@@ -40,10 +40,26 @@ zombiesTreeList = function(id) {
*/
Ext.extend(zombiesTreeList, Ext.tree.TreePanel, {
//saves the configuration for the tree
tree_configuration: {
'sub-branch' : 'domain',
'distributed' : false
},
//store the list of online hooked browsers in an array
online_hooked_browsers_array: new Array,
//store the list of offline hooked browsers in an array
offline_hooked_browsers_array: new Array,
//store the distributed engine rules
distributed_engine_rules: null,
listeners: {
//creates a new hooked browser tab when a hooked browser is clicked
click: function(node, e) {
if(!node.leaf) return;
if(!mainPanel.get(node.attributes.session)) {
mainPanel.add(new ZombieTab(node.attributes));
}
@@ -52,52 +68,67 @@ Ext.extend(zombiesTreeList, Ext.tree.TreePanel, {
}
},
selectZombie: function(url){
this.getNodeById(url).select();
},
addZombie : function(attrs, online){
/*
* Adds a new hooked browser to the tree.
* @param: {Literal Object} the hooked browser object generated by the zombie manager.
* @param: {Boolean} true if the hooked browser is online, false if offline.
*/
addZombie : function(hooked_browser, online) {
var hb_id, mother_node, node;
if(online) {
var z_id = 'zombie-online-' + attrs.session;
hb_id = 'zombie-online-' + hooked_browser.session;
mother_node = this.online_hooked_browsers_treenode;
} else {
var z_id = 'zombie-offline-' + attrs.session;
hb_id = 'zombie-offline-' + hooked_browser.session;
mother_node = this.offline_hooked_browsers_treenode;
}
//window.console.log(this.online_hooked_browsers_array)
var exists = this.getNodeById(hb_id);
if(exists) return;
//save a new online HB
if(online && Ext.pluck(this.online_hooked_browsers_array, 'session').indexOf(hooked_browser.session)==-1) {
this.online_hooked_browsers_array.push(hooked_browser);
}
var exists = this.getNodeById(z_id);
if(exists){
return;
}
//save a new offline HB
if(!online && this.offline_hooked_browsers_array.indexOf(hooked_browser)==-1) {
this.offline_hooked_browsers_array.push(hooked_browser);
}
Ext.apply(attrs, {
//apply CSS styles and configuring the hooked browser for the tree
Ext.apply(hooked_browser, {
iconCls: 'feed-icon',
leaf:true,
id: z_id
id: hb_id
});
var node = new Ext.tree.TreeNode(attrs);
var mother_node;
//creates a new node for that hooed browser
node = new Ext.tree.TreeNode(hooked_browser);
//creates a sub-branch for that HB if necessary
mother_node = this.addSubFolder(mother_node, hooked_browser[this.tree_configuration['sub-branch']]);
if(online) {
mother_node = this.online_zombies;
mother_node = this.addSubFolder(mother_node, node.attributes.domain);
} else {
mother_node = this.offline_zombies;
mother_node = this.addSubFolder(mother_node, node.attributes.domain);
}
if(online) {
Ext.apply(attrs, {cls: 'zombie-online'});
//add the hooked browser to the online branch
Ext.apply(hooked_browser, {cls: 'zombie-online'});
mother_node.appendChild(node);
} else {
Ext.apply(attrs, {cls: 'zombie-offline'});
//add the hooked browser to the offline branch
Ext.apply(hooked_browser, {cls: 'zombie-offline'});
mother_node.appendChild(node);
}
return node;
},
addSubFolder: function(mother_node, folder, checked) {
/*
* Adds a sub-branch or sub-folder to the tree.
* @param: {Ext.tree.TreeNode} the mother node.
* @param: {String} the name of the new sub branch.
*/
addSubFolder: function(mother_node, folder) {
if(!folder) return mother_node;
if(mother_node.hasChildNodes()) {
@@ -110,8 +141,7 @@ Ext.extend(zombiesTreeList, Ext.tree.TreePanel, {
} else {
sub_folder_node = new Ext.tree.TreeNode({
id: 'sub-folder-'+folder,
text: folder,
'checked' : checked
text: folder
});
mother_node.appendChild(sub_folder_node);
@@ -121,28 +151,53 @@ Ext.extend(zombiesTreeList, Ext.tree.TreePanel, {
return mother_node;
},
removeAll : function(){
this.online_zombies.removeAll();
this.offline_zombies.removeAll();
},
compareAndRemove : function(zombies, online) {
for(var i in zombies) {
if(online) {
var z = 'zombie-offline-' + zombies[i].session;;
} else {
var z = 'zombie-online-' + zombies[i].session;;
}
/*
* Remove any duplicated hooked browsers in branches.
* @param: {Literal Object} object containing the list of hooked browsers.
*/
compareAndRemove: function(zombies) {
var arr = ['online', 'offline'];
Ext.each(arr, function(branch_type) {
var new_set_zombies = zombies[branch_type];
var new_set_zombies_array = new Array;
var exists = this.getNodeById(z);
//converts the new set of zombies to an array
Ext.iterate(new_set_zombies, function(key, hooked_browser) { new_set_zombies_array.push(hooked_browser); });
if(exists) {
if(!online) {
this.online_zombies.removeChild(exists, true);
} else {
this.offline_zombies.removeChild(exists, true);
//retrieves all the new hooked browsers' session id
var new_set_zombies_sessions = Ext.pluck(new_set_zombies_array, 'session');
if(!new_set_zombies_sessions) return;
//retrieves the branch that will be updated
var branch_node = eval('this.'+branch_type+'_hooked_browsers_treenode');
//retrieves the list of known hooked browsers in that branch
var hooked_browser_array = eval('this.'+branch_type+'_hooked_browsers_array');
if(hooked_browser_array.length == 0) return;
//we compare the list of known HBs to the new set of HBs retrieved. If a HB is missing
//we delete it from the tree.
Ext.iterate(hooked_browser_array, function(known_hooked_browser, key) {
if(!known_hooked_browser) return;
var hb_session = known_hooked_browser["session"];
if(new_set_zombies_sessions.indexOf(hb_session)==-1) {
var node = this.getNodeById('zombie-'+branch_type+'-'+hb_session);
if(node) {
//remove the node from the tree
branch_node.removeChild(node);
//because ExtJs has a bug with node.destroy() this is a hack to make it work for beef.
node.setId("hooked-browser-node-destroyed");
//update the array of hooked browser
hooked_browser_array = hooked_browser_array.slice(key, key+1);
eval('this.'+branch_type+'_hooked_browsers_array = hooked_browser_array');
}
}
}
}
}, this);
}, this);
}
});