1var storageList = function(cookieName) { 2 var storageName = cookieName; 3 var storage = new myStorage(); 4 5 //Load the items or a new array if null. 6 var items = storage.get(cookieName) ? storage.get(cookieName).split(/,/) : new Array(); 7 8 return { 9 "add": function(val) { 10 11 if(items.contains(val)){ 12 return; 13 } 14 15 //Add to the items. 16 items.push(val); 17 18 //Save the items to a storage. 19 storage.set(storageName, items.join(',')); 20 }, 21 "clear": function() { 22 items = null; 23 storage.set(storageName, ''); 24 }, 25 "items": function() { 26 //items.sort(); 27 return items; 28 }, 29 "size": function() { 30 return items.length; 31 }, 32 "isUIDExists": function(uid) { 33 for (var i=0; i< items.length; i++) { 34 var nodeValues = items[i].split("|"); 35 if (nodeValues[2] == uid) return true; 36 } 37 38 return false; 39 }, 40 "removeByPID": function(pid){ 41 for (var i=0; i< items.length; i++) { 42 var nodeValues = items[i].split("|"); 43 if (nodeValues[1] == pid){ 44 items.splice(i,1); 45 i--; 46 } 47 } 48 } 49 } 50}; 51 52// Arrays for nodes and icons 53var nodes = new Array();; 54var openNodes = new Array(); 55var icons = new Array(6); 56var s = ''; 57 58// Loads all icons that are used in the tree 59function preloadIcons() { 60 icons[0] = new Image(); 61 icons[0].src = "/smb/css/img/plus.gif"; 62 icons[1] = new Image(); 63 icons[1].src = "/smb/css/img/plusbottom.gif"; 64 icons[2] = new Image(); 65 icons[2].src = "/smb/css/img/minus.gif"; 66 icons[3] = new Image(); 67 icons[3].src = "/smb/css/img/minusbottom.gif"; 68 icons[4] = new Image(); 69 icons[4].src = "/smb/css/img/folder.png"; 70 icons[5] = new Image(); 71 icons[5].src = "/smb/css/img/folderopen.png"; 72 icons[6] = new Image(); 73 icons[6].src = "/smb/css/img/computer.png"; 74 icons[7] = new Image(); 75 icons[7].src = "/smb/css/img/usb.png"; 76} 77// Create the tree 78function createTree(root_name, arrName, startNode, openNode, selectNodeCallbackFunc) { 79 nodes = arrName; 80 var tree_div = document.getElementById("tree"); 81 s = ''; 82 83 if (nodes.length > 0) { 84 preloadIcons(); 85 if (startNode == null) startNode = 0; 86 87 if (openNode != 0 || openNode != null) setOpenNodes(openNode); 88 89 if (startNode !=0) { 90 var nodeValues = nodes[getArrayId(startNode)].split("|"); 91 s += "<a href=\"" + nodeValues[0] + "\" onmouseover=\"window.status='" + nodeValues[0] + "';return true;\" onmouseout=\"window.status=' ';return true;\"><img src=\"/smb/css/img/folderopen.png\" align=\"absbottom\" alt=\"\" />" + mydecodeURI(nodeValues[0]) + "</a><br />"; 92 } 93 else{ 94 s += "<a link=\"\" nodeid=\"0\" parentid=\"0\" onmouseover=\"window.status='/';return true;\" onmouseout=\"window.status=' ';return true;\">"; 95 s += "<img src=\"/smb/css/img/base.png\" href=\"/\" align=\"absbottom\" alt=\"\" />" + root_name + "</a><br/>"; 96 } 97 98 var recursedNodes = new Array(); 99 addNode(startNode, recursedNodes); 100 101 tree_div.innerHTML = s; 102 } 103 104 $('div#tree a').click(function(){ 105 if(selectNodeCallbackFunc){ 106 107 var full_path = ""; 108 var parentid = $(this).attr('parentid'); 109 var nodename, nodeip; 110 111 if(parentid==undefined) 112 return; 113 114 var a = getNodeName(parentid); 115 116 while(a!=null){ 117 parentid = a[1]; 118 nodename = a[0]; 119 nodeip = a[2]; 120 121 a = getNodeName(parentid); 122 123 full_path = "/" + nodename + full_path; 124 } 125 126 full_path = full_path+'/'+$(this).attr('link'); 127 128 selectNodeCallbackFunc(full_path, $(this).attr('nodeid'), $(this).attr('parentid'), $(this).attr('online'), $(this).attr('mac'), $(this).attr('type')); 129 } 130 }); 131 132} 133 134function getNodeName(id){ 135 for (var i=0; i<nodes.length; i++) { 136 var nodeValues = nodes[i].split("|"); 137 138 if (nodeValues[2]==id) { 139 //- [nadeName, parentid, nodeServerIP] 140 return [ nodeValues[0], nodeValues[1], nodeValues[6] ]; 141 } 142 } 143 144 return null; 145} 146 147// Returns the position of a node in the array 148function getArrayId(node) { 149 for (i=0; i<nodes.length; i++) { 150 var nodeValues = nodes[i].split("|"); 151 if (nodeValues[2]==node) return i; 152 } 153} 154// Puts in array nodes that will be open 155function setOpenNodes(openNode) { 156 for (i=0; i<nodes.length; i++) { 157 var nodeValues = nodes[i].split("|"); 158 if (nodeValues[2]==openNode) { 159 160 if(!openNodes.contains(openNode)) 161 openNodes.push(openNode); 162 163 setOpenNodes(nodeValues[1]); 164 } 165 } 166} 167// Checks if a node is open 168function isNodeOpen(node) { 169 for (i=0; i<openNodes.length; i++) 170 if (openNodes[i]==node) return true; 171 return false; 172} 173// Checks if a node has any children 174function hasChildNode(parentNode) { 175 for (i=0; i< nodes.length; i++) { 176 var nodeValues = nodes[i].split("|"); 177 if (nodeValues[1] == parentNode) return true; 178 } 179 return false; 180} 181// Checks if a node is the last sibling 182function lastSibling (node, parentNode) { 183 var lastChild = 0; 184 for (i=0; i< nodes.length; i++) { 185 var nodeValues = nodes[i].split("|"); 186 if (nodeValues[1] == parentNode) 187 lastChild = nodeValues[2]; 188 } 189 if (lastChild==node) return true; 190 return false; 191} 192 193function getNode(id){ 194 for (i=0; i< nodes.length; i++) { 195 var nodeValues = nodes[i].split("|"); 196 if (nodeValues[2] == id) 197 return nodes[i]; 198 } 199 200 return ""; 201} 202 203// Adds a new node to the tree 204function addNode(parentNode, recursedNodes) { 205 var tree_div = $('div.tree'); 206 207 for (var i = 0; i < nodes.length; i++) { 208 209 var nodeValues = nodes[i].split("|"); 210 if (nodeValues[1] == parentNode) { 211 212 var ls = lastSibling(nodeValues[2], nodeValues[1]); 213 var hcn = hasChildNode(nodeValues[2]); 214 var ino = isNodeOpen(nodeValues[2]); 215 216 // Write out line & empty icons 217 for (g=0; g<recursedNodes.length; g++) { 218 if (recursedNodes[g] == 1) 219 s += "<img src=\"/smb/css/img/line.gif\" align=\"absbottom\" alt=\"\" />"; 220 else 221 s += "<img src=\"/smb/css/img/empty.gif\" align=\"absbottom\" alt=\"\" />"; 222 } 223 224 // put in array line & empty icons 225 if (ls) recursedNodes.push(0); 226 else recursedNodes.push(1); 227 228 // Write out join icons 229 if (hcn) { 230 if (ls) { 231 s += "<a href=\"javascript: oc('" + nodeValues[0] + "', '" + nodeValues[1] + "', '" + nodeValues[2] + "', '" + nodeValues[5] +"', 1);\"><img id=\"join" + nodeValues[2] + "\" src=\"/smb/css/img/"; 232 if (ino) 233 s += "minus"; 234 else 235 s += "plus"; 236 s += "bottom.gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>"; 237 } 238 else { 239 s += "<a href=\"javascript: oc('" + nodeValues[0] + "', '" + nodeValues[1] + "', '" + nodeValues[2] + "', '" + nodeValues[5] + "', 0);\"><img id=\"join" + nodeValues[2] + "\" src=\"/smb/css/img/"; 240 if (ino) 241 s += "minus"; 242 else 243 s += "plus"; 244 s += ".gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>"; 245 } 246 } 247 else { 248 if(ls) 249 s += "<img src=\"/smb/css/img/joinbottom.gif\" align=\"absbottom\" alt=\"\" />"; 250 else 251 s += "<img src=\"/smb/css/img/join.gif\" align=\"absbottom\" alt=\"\" />"; 252 } 253 254 // Start link 255 s += "<a link=\"" + nodeValues[0] + "\" "; 256 s += "nodeid=\"" + nodeValues[2] + "\" "; 257 s += "parentid=\"" + nodeValues[1] + "\" "; 258 s += "online=\"" + nodeValues[3] + "\" "; 259 s += "ip=\"" + nodeValues[6] + "\" "; 260 s += "mac=\"" + nodeValues[4] + "\" "; 261 s += "type=\"" + nodeValues[5] + "\" "; 262 s += "title=\"" + mydecodeURI(nodeValues[0]) + " - " + nodeValues[6] + "\" "; 263 //s += "title=\"" + mydecodeURI(nodeValues[0]) + "\" "; 264 s += "onmouseover=\"window.status='" + nodeValues[0] + "';return true;\" onmouseout=\"window.status=' ';return true;\">"; 265 266 // Write out folder & page icons 267 if (hcn) { 268 if(nodeValues[1]==0){ 269 270 if(nodeValues[5]=="usbdisk"){ 271 //- USB Node 272 s += "<img id=\"icon" + nodeValues[2] + "\" src=\"/smb/css/img/usb"; 273 s += ".png\" align=\"absbottom\" alt=\"Computer\" />"; 274 } 275 else{ 276 //- Computer Node 277 s += "<img id=\"icon" + nodeValues[2] + "\" src=\"/smb/css/img/computer"; 278 if (nodeValues[3]==0) s += "off"; 279 s += ".png\" align=\"absbottom\" alt=\"Computer\" />"; 280 } 281 } 282 else{ 283 s += "<img id=\"icon" + nodeValues[2] + "\" src=\"/smb/css/img/folder"; 284 if (ino) s += "open"; 285 s += ".png\" align=\"absbottom\" alt=\"Folder\" />"; 286 } 287 } 288 else{ 289 if(nodeValues[1]==0){ 290 if(nodeValues[5]=="usbdisk"){ 291 //- USB Node 292 s += "<img id=\"icon" + nodeValues[2] + "\" class='page' src=\"/smb/css/img/usb.png\" align=\"absbottom\" alt=\"Computer\" />"; 293 } 294 else{ 295 //- Computer Node 296 s += "<img id=\"icon" + nodeValues[2] + "\" class='page' src=\"/smb/css/img/computer"; 297 if (nodeValues[3]==0) s += "off"; 298 s += ".png\" align=\"absbottom\" alt=\"Computer\" />"; 299 } 300 } 301 else 302 s += "<img id=\"icon" + nodeValues[2] + "\" class='page' src=\"/smb/css/img/folder.png\" align=\"absbottom\" alt=\"Page\" />"; 303 } 304 305 // Write out node name 306 s += mydecodeURI(nodeValues[0]); 307 308 if(nodeValues[1]==0&&nodeValues[3]=="0") 309 s += "(" + m.getString("title_offline") + ")"; 310 311 // End link 312 s += "</a><br />"; 313 314 // If node has children write out divs and go deeper 315 if (hcn) { 316 s += "<div id=\"div" + nodeValues[2] + "\""; 317 if (!ino) s += " style=\"display: none;\""; 318 s += ">"; 319 addNode(nodeValues[2], recursedNodes); 320 s += "</div>"; 321 } 322 323 // remove last line or empty icon 324 recursedNodes.pop(); 325 } 326 } 327} 328 329 330function openNode(node){ 331 if(!openNodes.contains(node)){ 332 openNodes.push(node); 333 //var openuid = g_storage.get('openuid'); 334 335 g_storage.set('openuid', node); 336 } 337} 338 339function closeNode(node){ 340 if(openNodes.contains(node)){ 341 var node_info = getNodeName(node); 342 343 for (var i = 0; i < nodes.length; i++) { 344 345 var nodeValues = nodes[i].split("|"); 346 347 if (nodeValues[1]==node) { 348 closeNode(nodeValues[2]); 349 } 350 } 351 352 //alert('close: ' + node_info[0]); 353 openNodes.removeItem(node); 354 355 } 356} 357 358// Opens or closes a node 359function oc(nodename, pnode, node, type, bottom) { 360 var theDiv = document.getElementById("div" + node); 361 var theJoin = document.getElementById("join" + node); 362 var theIcon = document.getElementById("icon" + node); 363 364 if (theDiv.style.display == 'none') { 365 //- Open Node 366 openNode(node); 367 368 if (bottom==1) theJoin.src = icons[3].src; 369 else theJoin.src = icons[2].src; 370 371 if(pnode=="0"){ 372 if(type=="usbdisk") 373 theIcon.src = icons[7].src; 374 else 375 theIcon.src = icons[6].src; 376 } 377 else 378 theIcon.src = icons[5].src; 379 theDiv.style.display = ''; 380 } else { 381 //- Close Node 382 closeNode(node); 383 /* 384 for (var i = 0; i < nodes.length; i++) { 385 386 var nodeValues = nodes[i].split("|"); 387 388 if (nodeValues[2]==node) { 389 //- Set parent node to open node 390 g_storage.set('openuid', nodeValues[1]); 391 alert("open " + getNodeName(nodeValues[1])[0] + ", " + nodeValues[1]); 392 } 393 } 394 */ 395 if (bottom==1) theJoin.src = icons[1].src; 396 else theJoin.src = icons[0].src; 397 398 if(pnode=="0"){ 399 if(type=="usbdisk") 400 theIcon.src = icons[7].src; 401 else 402 theIcon.src = icons[6].src; 403 } 404 else 405 theIcon.src = icons[4].src; 406 theDiv.style.display = 'none'; 407 } 408} 409 410// Push and pop not implemented in IE 411if(!Array.prototype.push) { 412 function array_push() { 413 for(var i=0;i<arguments.length;i++) 414 this[this.length]=arguments[i]; 415 return this.length; 416 } 417 Array.prototype.push = array_push; 418} 419if(!Array.prototype.pop) { 420 function array_pop(){ 421 lastElement = this[this.length-1]; 422 this.length = Math.max(this.length-1,0); 423 return lastElement; 424 } 425 Array.prototype.pop = array_pop; 426} 427 428if(!Array.prototype.contains) { 429 function array_contains(obj){ 430 for (var i = 0; i < this.length; i++) { 431 if (this[i] === obj) { 432 return true; 433 } 434 } 435 return false; 436 } 437 Array.prototype.contains = array_contains; 438} 439 440if(!Array.prototype.removeItem) { 441 function array_removeItem(obj){ 442 for (var i = 0; i < this.length; i++) { 443 if (this[i] === obj) { 444 this.splice(i,1); 445 //alert('remove: ' + obj + ', ' + this.length); 446 return true; 447 } 448 } 449 return false; 450 } 451 Array.prototype.removeItem = array_removeItem; 452}