[6779] | 1 | /* Dynamic Folder Tree |
---|
| 2 | * Generates DHTML tree dynamically (on the fly). |
---|
| 3 | * License: GNU LGPL |
---|
| 4 | * |
---|
| 5 | * Copyright (c) 2004, Vinicius Cubas Brand, Raphael Derosso Pereira |
---|
| 6 | * {viniciuscb,raphaelpereira} at users.sourceforge.net |
---|
| 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * |
---|
| 10 | * This library is free software; you can redistribute it and/or |
---|
| 11 | * modify it under the terms of the GNU Lesser General Public |
---|
| 12 | * License as published by the Free Software Foundation; either |
---|
| 13 | * version 2.1 of the License, or (at your option) any later version. |
---|
| 14 | * |
---|
| 15 | * This library is distributed in the hope that it will be useful, |
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 18 | * Lesser General Public License for more details. |
---|
| 19 | * |
---|
| 20 | * You should have received a copy of the GNU Lesser General Public |
---|
| 21 | * License along with this library; if not, write to the Free Software |
---|
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 23 | */ |
---|
| 24 | /* |
---|
| 25 | * Chanded by Joao Alfredo Knopik Junior |
---|
| 26 | * joao.alfredo at gmail.com |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | // NODE |
---|
| 30 | //Usage: a = new dNode({id:2, caption:'tree root', url:'http://www.w3.org'}); |
---|
| 31 | function dNode(arrayProps) { |
---|
| 32 | //mandatory fields |
---|
| 33 | this.id; //node id |
---|
| 34 | this.caption; //node caption |
---|
| 35 | |
---|
| 36 | //optional fields |
---|
| 37 | this.url; //url to open |
---|
| 38 | this.target; //target to open url |
---|
| 39 | this.onClick; //javascript to execute onclick |
---|
| 40 | this.onOpen; //javascript to execute when a node of the tree opens |
---|
| 41 | this.onClose; //javascript to execute when a node of the tree closes |
---|
| 42 | this.onFirstOpen; //javascript to execute only on the first open |
---|
| 43 | this.iconClosed; //img.src of closed icon |
---|
| 44 | this.iconOpen; //img.src of open icon |
---|
| 45 | this.runJS = true; //(bool) if true, runs the on* props defined above |
---|
| 46 | this.plusSign = true; //(bool) if the plus sign will appear or not |
---|
| 47 | this.captionClass = 'l'; //(string) the class for this node's caption |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | //The parameters below are private |
---|
| 51 | this._opened = false; //already opened |
---|
| 52 | this._io = false; //is opened |
---|
| 53 | |
---|
| 54 | this._children = []; //references to children |
---|
| 55 | this._parent; //pointer to parent |
---|
| 56 | this._myTree; //pointer to myTree |
---|
| 57 | this._drawn = false; |
---|
| 58 | |
---|
| 59 | for (var i in arrayProps) |
---|
| 60 | { |
---|
| 61 | if (i.charAt(0) != '_') |
---|
| 62 | { |
---|
| 63 | eval('this.'+i+' = arrayProps[\''+i+'\'];'); |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | //changes node state from open to closed, and vice-versa |
---|
| 69 | dNode.prototype.changeState = function() |
---|
| 70 | { |
---|
| 71 | if (this._io) |
---|
| 72 | { |
---|
| 73 | this.close(); |
---|
| 74 | } |
---|
| 75 | else |
---|
| 76 | { |
---|
| 77 | this.open(); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | //cons = COokie of Node Status |
---|
| 81 | //setCookie("cons"+this.id,this._io); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | dNode.prototype.open = function () { |
---|
| 85 | //MAILARCHIVER-01 |
---|
| 86 | if(typeof(expresso_mail_archive) != 'undefined') |
---|
| 87 | if (expresso_mail_archive.enabled) |
---|
| 88 | expresso_mail_archive.drawdata.treeName = this._myTree.name; |
---|
| 89 | |
---|
| 90 | if (!this._io) |
---|
| 91 | { |
---|
| 92 | if (!this._opened && this.runJS && this.onFirstOpen != null) |
---|
| 93 | { |
---|
| 94 | eval(this.onFirstOpen); |
---|
| 95 | } |
---|
| 96 | else if (this.runJS && this.onOpen != null) |
---|
| 97 | { |
---|
| 98 | eval(this.onOpen); |
---|
| 99 | } |
---|
| 100 | //MAILARCHIVER-02 |
---|
| 101 | else if(this.id.substr(0,5) == 'local'){ |
---|
| 102 | if (this.id != 'local_root') |
---|
| 103 | expresso_mail_archive.getFoldersList(this.id.substr(6)); |
---|
| 104 | else |
---|
| 105 | expresso_mail_archive.getFoldersList(""); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | this._debug = true; |
---|
| 109 | this._opened = true; |
---|
| 110 | this._io = true; |
---|
| 111 | this._refresh(); |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | dNode.prototype.close = function() { |
---|
| 117 | if (this._io) |
---|
| 118 | { |
---|
| 119 | if (this.runJS && this.onClose != null) |
---|
| 120 | { |
---|
| 121 | eval(this.onClose); |
---|
| 122 | } |
---|
| 123 | this._io = false; |
---|
| 124 | this._refresh(); |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | //alter node label and other properties |
---|
| 129 | dNode.prototype.alter = function(arrayProps) |
---|
| 130 | { |
---|
| 131 | for (var i in arrayProps) |
---|
| 132 | { |
---|
| 133 | if (i != 'id' && i.charAt(0) != '_') |
---|
| 134 | { |
---|
| 135 | eval('this.'+i+' = arrayProps[\''+i+'\'];'); |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | //css and dhtml refresh part |
---|
| 141 | dNode.prototype._refresh = function() { |
---|
| 142 | var nodeDiv = getObjectById("n"+this.id+this._myTree.name); |
---|
| 143 | var plusSpan = getObjectById("p"+this.id+this._myTree.name); |
---|
| 144 | var captionSpan = getObjectById("l"+this.id+this._myTree.name); |
---|
| 145 | var childrenDiv = getObjectById("ch"+this.id+this._myTree.name); |
---|
| 146 | |
---|
| 147 | if (nodeDiv != null) |
---|
| 148 | { |
---|
| 149 | //Handling open and close: checks this._io and changes class as needed |
---|
| 150 | if (!this._io) //just closed |
---|
| 151 | { |
---|
| 152 | childrenDiv.className = "closed"; |
---|
| 153 | } |
---|
| 154 | else //just opened |
---|
| 155 | { |
---|
| 156 | //prevents IE undesired behaviour when displaying empty DIVs |
---|
| 157 | /* if (this._children.length > 0) |
---|
| 158 | {*/ |
---|
| 159 | childrenDiv.className = "opened"; |
---|
| 160 | // } |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | plusSpan.innerHTML = this._properPlus(); |
---|
| 164 | |
---|
| 165 | captionSpan.innerHTML = this.caption; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | //alter onLoad, etc |
---|
| 169 | |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | //gets the proper plus for this moment |
---|
| 173 | dNode.prototype._properPlus = function() |
---|
| 174 | { |
---|
| 175 | if (!this._io) |
---|
| 176 | { |
---|
| 177 | if (this._myTree.useIcons) |
---|
| 178 | { |
---|
| 179 | return (this.plusSign)?imageHTML(this._myTree.icons.plus):""; |
---|
| 180 | } |
---|
| 181 | else |
---|
| 182 | { |
---|
| 183 | return (this.plusSign)?"+":" "; |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | else |
---|
| 187 | { |
---|
| 188 | if (this._myTree.useIcons) |
---|
| 189 | { |
---|
| 190 | return (this.plusSign)?imageHTML(this._myTree.icons.minus):""; |
---|
| 191 | } |
---|
| 192 | else |
---|
| 193 | { |
---|
| 194 | return (this.plusSign)?"-":" "; |
---|
| 195 | } |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | //changes node to selected style class. Perform further actions. |
---|
| 200 | dNode.prototype._select = function() |
---|
| 201 | { |
---|
| 202 | var captionSpan; |
---|
| 203 | |
---|
| 204 | if (this._myTree._selected) |
---|
| 205 | { |
---|
| 206 | this._myTree._selected._unselect(); |
---|
| 207 | } |
---|
| 208 | this._myTree._selected = this; |
---|
| 209 | |
---|
| 210 | captionSpan = getObjectById("l"+this.id+this._myTree.name); |
---|
| 211 | |
---|
| 212 | if(document.getElementById("div_tree") != null){ |
---|
| 213 | if(ttree.FOLDER != ""){ |
---|
| 214 | ttree.FOLDER = ""; |
---|
| 215 | } |
---|
| 216 | ttree.FOLDER = this.id; |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | if(document.getElementById("div_folders_search") != null){ |
---|
| 220 | if(EsearchE.name_box_search != ""){ |
---|
| 221 | EsearchE.name_box_search = ""; |
---|
| 222 | } |
---|
| 223 | EsearchE.name_box_search = this.id; |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | //MailArchiver export folders addon |
---|
| 227 | if(document.getElementById("dftree_folders_tree") != null){ |
---|
| 228 | if(captionSpan.id.substr(0,7) == 'llocal_'){ |
---|
| 229 | var div_main_container = document.getElementById('div_buttons'); |
---|
| 230 | |
---|
| 231 | var div_local_export_criteria = document.createElement('div'); |
---|
| 232 | div_local_export_criteria.id = 'div_local_export_criteria'; |
---|
| 233 | |
---|
| 234 | var obj_label = document.createElement('label'); |
---|
| 235 | var obj_label_txt = document.createTextNode(get_lang('Include subfolders')); |
---|
| 236 | obj_label.setAttribute("for", "exp_local_recursive"); |
---|
| 237 | obj_label.id = 'lbl_exp_local_recursive'; |
---|
| 238 | obj_label.appendChild(obj_label_txt); |
---|
| 239 | |
---|
| 240 | var obj_check = document.createElement('input'); |
---|
| 241 | obj_check.type = "checkbox"; |
---|
| 242 | obj_check.name = 'exp_local_recursive'; |
---|
| 243 | obj_check.id = "exp_local_recursive"; |
---|
| 244 | obj_check.checked = false; |
---|
| 245 | |
---|
| 246 | var obj_combo = document.createElement('select'); |
---|
| 247 | obj_combo.name = 'exp_local_format'; |
---|
| 248 | obj_combo.id = 'exp_local_format'; |
---|
| 249 | var obj_opt1 = document.createElement('option'); |
---|
| 250 | var obj_opt2 = document.createElement('option'); |
---|
| 251 | var obj_opt3 = document.createElement('option'); |
---|
| 252 | var obj_opt4 = document.createElement('option'); |
---|
| 253 | var obj_opt5 = document.createElement('option'); |
---|
| 254 | var obj_opt6 = document.createElement('option'); |
---|
| 255 | var obj_opt7 = document.createElement('option'); |
---|
| 256 | var obj_opt8 = document.createElement('option'); |
---|
| 257 | |
---|
| 258 | obj_opt1.value = 'zip'; |
---|
| 259 | obj_opt1.text = get_lang('Zip format'); |
---|
| 260 | obj_combo.appendChild(obj_opt1); |
---|
| 261 | |
---|
| 262 | obj_opt2.value = 'jar'; |
---|
| 263 | obj_opt2.text = get_lang('Jar format'); |
---|
| 264 | obj_combo.appendChild(obj_opt2); |
---|
| 265 | |
---|
| 266 | obj_opt3.value = 'tar'; |
---|
| 267 | obj_opt3.text = get_lang('Tar format'); |
---|
| 268 | obj_combo.appendChild(obj_opt3); |
---|
| 269 | |
---|
| 270 | obj_opt4.value = 'tar.gz'; |
---|
| 271 | obj_opt4.text = get_lang('Tar.gz format'); |
---|
| 272 | obj_combo.appendChild(obj_opt4); |
---|
| 273 | |
---|
| 274 | obj_opt5.value = 'tgz'; |
---|
| 275 | obj_opt5.text = get_lang('Tgz format'); |
---|
| 276 | obj_combo.appendChild(obj_opt5); |
---|
| 277 | |
---|
| 278 | obj_opt6.value = 'tar.bz2'; |
---|
| 279 | obj_opt6.text = get_lang('Tar.bz2 format'); |
---|
| 280 | obj_combo.appendChild(obj_opt6); |
---|
| 281 | |
---|
| 282 | obj_opt7.value = 'tb2'; |
---|
| 283 | obj_opt7.text = get_lang('Tb2 format'); |
---|
| 284 | obj_combo.appendChild(obj_opt7); |
---|
| 285 | |
---|
| 286 | obj_opt8.value = 'tbz'; |
---|
| 287 | obj_opt8.text = get_lang('Tbz format'); |
---|
| 288 | obj_combo.appendChild(obj_opt8); |
---|
| 289 | |
---|
| 290 | obj_opt1.selected = true; |
---|
| 291 | |
---|
| 292 | div_local_export_criteria.appendChild(obj_check); |
---|
| 293 | div_local_export_criteria.appendChild(obj_label); |
---|
| 294 | div_local_export_criteria.appendChild(obj_combo); |
---|
| 295 | |
---|
| 296 | //div_main_container.appendChild(div_local_export_criteria); |
---|
| 297 | var mn_table = div_main_container.getElementsByTagName('table')[0]; |
---|
| 298 | var mn_tbody = mn_table.getElementsByTagName('tbody')[0]; |
---|
| 299 | var mn_row = mn_tbody.getElementsByTagName('tr')[4]; |
---|
| 300 | var mn_column = mn_row.getElementsByTagName('td')[0]; |
---|
| 301 | mn_row.removeChild(mn_column); |
---|
| 302 | |
---|
| 303 | var new_column = document.createElement('td'); |
---|
| 304 | mn_row.appendChild(new_column); |
---|
| 305 | new_column.appendChild(div_local_export_criteria); |
---|
| 306 | new_column.appendChild(document.createElement('br')); |
---|
| 307 | |
---|
| 308 | //window.alert('conteudo da coluna:' + mn_column.innerHTML); |
---|
| 309 | } |
---|
| 310 | else{ |
---|
| 311 | if(document.getElementById('div_local_export_criteria')){ |
---|
| 312 | var div_main_container = document.getElementById('div_buttons'); |
---|
| 313 | var mn_table = div_main_container.getElementsByTagName('table')[0]; |
---|
| 314 | var mn_tbody = mn_table.getElementsByTagName('tbody')[0]; |
---|
| 315 | var mn_row = mn_tbody.getElementsByTagName('tr')[4]; |
---|
| 316 | var mn_column = mn_row.getElementsByTagName('td')[0]; |
---|
| 317 | mn_row.removeChild(mn_column); |
---|
| 318 | var new_column = document.createElement('td'); |
---|
| 319 | mn_row.appendChild(new_column); |
---|
| 320 | new_column.appendChild(document.createElement('br')); |
---|
| 321 | new_column.appendChild(document.createElement('br')); |
---|
| 322 | new_column.appendChild(document.createElement('br')); |
---|
| 323 | new_column.appendChild(document.createElement('br')); |
---|
| 324 | } |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | //If local root selected, recursive allways must be checked |
---|
| 328 | if(captionSpan.id == 'llocal_rootfolders_tree'){ |
---|
| 329 | document.getElementById('exp_local_recursive').checked = true; |
---|
| 330 | document.getElementById('exp_local_recursive').disabled = true; |
---|
| 331 | document.getElementById('lbl_exp_local_recursive').style.color = 'gray'; |
---|
| 332 | } |
---|
| 333 | else { |
---|
| 334 | if(document.getElementById('exp_local_recursive')){ |
---|
| 335 | document.getElementById('exp_local_recursive').disabled = false; |
---|
| 336 | document.getElementById('lbl_exp_local_recursive').style.color = 'black'; |
---|
| 337 | } |
---|
| 338 | } |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | //changes class to selected link |
---|
| 342 | if (captionSpan) |
---|
| 343 | { |
---|
| 344 | captionSpan.className = 'sl'; |
---|
| 345 | } |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | //changes node background color. |
---|
| 349 | dNode.prototype._onMouseOver = function() |
---|
| 350 | { |
---|
| 351 | var captionSpan; |
---|
| 352 | if ((this.id != 'root') && (this.id != 'user') && (this.id !='local_root')){ |
---|
| 353 | captionSpan = getObjectById("l"+this.id+this._myTree.name); |
---|
| 354 | captionSpan.style.backgroundColor = 'white'; |
---|
| 355 | captionSpan.style.border = '1px solid black'; |
---|
| 356 | captionSpan.style.paddingTop = '0px'; |
---|
| 357 | captionSpan.style.paddingBottom = '0px'; |
---|
| 358 | } |
---|
| 359 | } |
---|
| 360 | //changes node background color. |
---|
| 361 | dNode.prototype._onMouseOut = function() |
---|
| 362 | { |
---|
| 363 | var captionSpan; |
---|
| 364 | if ((this.id != 'root') && (this.id != 'user') && (this.id !='local_root')){ |
---|
| 365 | captionSpan = getObjectById("l"+this.id+this._myTree.name); |
---|
| 366 | captionSpan.style.backgroundColor = ''; |
---|
| 367 | captionSpan.style.border = '0px'; |
---|
| 368 | captionSpan.style.paddingTop = '1px'; |
---|
| 369 | captionSpan.style.paddingBottom = '1px'; |
---|
| 370 | } |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | //changes node to unselected style class. Perform further actions. |
---|
| 374 | dNode.prototype._unselect = function() |
---|
| 375 | { |
---|
| 376 | var captionSpan = getObjectById("l"+this.id+this._myTree.name); |
---|
| 377 | |
---|
| 378 | this._myTree._lastSelected = this._myTree._selected; |
---|
| 379 | this._myTree._selected = null; |
---|
| 380 | |
---|
| 381 | //changes class to selected link |
---|
| 382 | if (captionSpan) |
---|
| 383 | { |
---|
| 384 | captionSpan.className = this.captionClass; |
---|
| 385 | } |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | |
---|
| 389 | //state can be open or closed |
---|
| 390 | //warning: if drawed node is not child or root, bugs will happen |
---|
| 391 | dNode.prototype._draw = function() |
---|
| 392 | { |
---|
| 393 | var str; |
---|
| 394 | var _this = this; |
---|
| 395 | var divN, divCH, spanP, spanL, parentChildrenDiv; |
---|
| 396 | var myClass = (this._io)? "opened" : "closed"; |
---|
| 397 | var myPlus = this._properPlus(); |
---|
| 398 | var append = true; |
---|
| 399 | var captionOnClickEvent = null; |
---|
| 400 | // var cook; |
---|
| 401 | |
---|
| 402 | var plusEventHandler = function(){ |
---|
| 403 | _this.changeState(); |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | var captionEventHandler = function(){ |
---|
| 407 | eval(captionOnClickEvent); |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | /* if (this.myTree.followCookies) |
---|
| 411 | { |
---|
| 412 | this._io = getCookie("cons"+this.id); |
---|
| 413 | }*/ |
---|
| 414 | |
---|
| 415 | //FIXME put this in a separate function, as this will be necessary in |
---|
| 416 | //various parts |
---|
| 417 | |
---|
| 418 | if (this.onClick) //FIXME when onclick && url |
---|
| 419 | { |
---|
| 420 | captionEventHandler = function () {_this._select();typeof(_this.onClick) == 'function' ? _this.onClick() : eval(_this.onClick);}; |
---|
| 421 | } |
---|
| 422 | else if (this.url && this.target) |
---|
| 423 | { |
---|
| 424 | captionEventHandler = function () {_this._select();window.open(_this.url,_this.target);}; |
---|
| 425 | } |
---|
| 426 | else if (this.url) |
---|
| 427 | { |
---|
| 428 | captionEventHandler = function () {_this._select();window.location=_this.url;}; |
---|
| 429 | } |
---|
| 430 | else //Nao tem onClick |
---|
| 431 | { |
---|
| 432 | if ((this.id != 'root') && (this.id != 'user') && (this.id !='local_root')) //e nao seja raiz(root) ou pastas compartilhadas(user). |
---|
| 433 | captionEventHandler = function () {_this._select();}; |
---|
| 434 | } |
---|
| 435 | |
---|
| 436 | //The div of this node |
---|
| 437 | divN = document.createElement('div'); |
---|
| 438 | divN.id = 'n'+this.id+this._myTree.name; |
---|
| 439 | //divN.className = 'son'; |
---|
| 440 | divN.className = (!this._parent) ? 'root' : 'son'; |
---|
| 441 | //divN.style.border = '1px solid black'; |
---|
| 442 | |
---|
| 443 | //The span that holds the plus/minus sign |
---|
| 444 | spanP = document.createElement('span'); |
---|
| 445 | spanP.id = 'p'+this.id+this._myTree.name; |
---|
| 446 | spanP.className = 'plus'; |
---|
| 447 | spanP.onclick = plusEventHandler; |
---|
| 448 | spanP.innerHTML = myPlus; |
---|
| 449 | //spanP.style.border = '1px solid green'; |
---|
| 450 | |
---|
| 451 | //The span that holds the label/caption |
---|
| 452 | spanL = document.createElement('span'); |
---|
| 453 | spanL.id = 'l'+this.id+this._myTree.name; |
---|
| 454 | spanL.className = this.captionClass; |
---|
| 455 | spanL.onclick = captionEventHandler; |
---|
| 456 | spanL.onmouseover = function () {_this._onMouseOver();}; |
---|
| 457 | spanL.onmouseout = function () {_this._onMouseOut();}; |
---|
| 458 | // spanL.style.border = '1px solid #f7f7f7'; |
---|
| 459 | spanL.innerHTML = this.caption; |
---|
| 460 | //spanL.style.border = '1px solid red'; |
---|
| 461 | |
---|
| 462 | //The div that holds the children |
---|
| 463 | divCH = document.createElement('div'); |
---|
| 464 | divCH.id = 'ch'+this.id+this._myTree.name; |
---|
| 465 | divCH.className = myClass; |
---|
| 466 | //divCH.style.border = '1px solid blue'; |
---|
| 467 | |
---|
| 468 | // div.innerHTML = str; |
---|
| 469 | divN.appendChild(spanP); |
---|
| 470 | divN.appendChild(spanL); |
---|
| 471 | divN.appendChild(divCH); |
---|
| 472 | |
---|
| 473 | |
---|
| 474 | if (this._parent != null) |
---|
| 475 | { |
---|
| 476 | parentChildrenDiv = getObjectById("ch"+this._parent.id+this._myTree.name); |
---|
| 477 | } |
---|
| 478 | else //is root |
---|
| 479 | { |
---|
| 480 | parentChildrenDiv = getObjectById("dftree_"+this._myTree.name); |
---|
| 481 | } |
---|
| 482 | |
---|
| 483 | if (parentChildrenDiv) |
---|
| 484 | { |
---|
| 485 | parentChildrenDiv.appendChild(divN); |
---|
| 486 | } |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | // TREE |
---|
| 490 | //Usage: t = new dFTree({name:t, caption:'tree root', url:'http://www.w3.org'}); |
---|
| 491 | function dFTree(arrayProps) { |
---|
| 492 | //mandatory fields |
---|
| 493 | this.name; //the value of this must be the name of the object |
---|
| 494 | |
---|
| 495 | //optional fields |
---|
| 496 | this.is_dynamic = true; //tree is dynamic, i.e. updated on the fly |
---|
| 497 | this.followCookies = true;//use previous state (o/c) of nodes |
---|
| 498 | this.useIcons = false; //use icons or not |
---|
| 499 | |
---|
| 500 | |
---|
| 501 | //arrayProps[icondir]: Icons Directory |
---|
| 502 | iconPath = (arrayProps['icondir'] != null)? arrayProps['icondir'] : ''; |
---|
| 503 | |
---|
| 504 | this.icons = { |
---|
| 505 | root : iconPath+'/foldertree_base.gif', |
---|
| 506 | folder : iconPath+'/foldertree_folder.gif', |
---|
| 507 | folderOpen : iconPath+'/foldertree_folderopen.gif', |
---|
| 508 | node : iconPath+'/foldertree_folder.gif', |
---|
| 509 | empty : iconPath+'/foldertree_empty.gif', |
---|
| 510 | line : iconPath+'/foldertree_line.gif', |
---|
| 511 | join : iconPath+'/foldertree_join.gif', |
---|
| 512 | joinBottom : iconPath+'/foldertree_joinbottom.gif', |
---|
| 513 | plus : iconPath+'/foldertree_plus.gif', |
---|
| 514 | plusBottom : iconPath+'/foldertree_plusbottom.gif', |
---|
| 515 | minus : iconPath+'/foldertree_minus.gif', |
---|
| 516 | minusBottom : iconPath+'/foldertree_minusbottom.gif', |
---|
| 517 | nlPlus : iconPath+'/foldertree_nolines_plus.gif', |
---|
| 518 | nlMinus : iconPath+'/foldertree_nolines_minus.gif' |
---|
| 519 | }; |
---|
| 520 | |
---|
| 521 | //private |
---|
| 522 | this._root = false; //reference to root node |
---|
| 523 | this._aNodes = []; |
---|
| 524 | this._lastSelected; //The last selected node |
---|
| 525 | this._selected; //The actual selected node |
---|
| 526 | this._folderPr = []; |
---|
| 527 | |
---|
| 528 | for (var i in arrayProps) |
---|
| 529 | { |
---|
| 530 | if (i.charAt(0) != '_') |
---|
| 531 | { |
---|
| 532 | eval('this.'+i+' = arrayProps[\''+i+'\'];'); |
---|
| 533 | } |
---|
| 534 | } |
---|
| 535 | } |
---|
| 536 | |
---|
| 537 | dFTree.prototype.draw = function(dest_element) { |
---|
| 538 | var main_div; |
---|
| 539 | |
---|
| 540 | if (!getObjectById("dftree_"+this.name) && dest_element) |
---|
| 541 | { |
---|
| 542 | main_div = document.createElement('div'); |
---|
| 543 | main_div.id = 'dftree_'+this.name; |
---|
| 544 | dest_element.appendChild(main_div); |
---|
| 545 | this._drawn = true; |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | if (this._root != false) |
---|
| 549 | { |
---|
| 550 | this._root._draw(); |
---|
| 551 | this._drawBranch(this._root._children); |
---|
| 552 | } |
---|
| 553 | |
---|
| 554 | } |
---|
| 555 | |
---|
| 556 | //Transforms tree in HTML code |
---|
| 557 | dFTree.prototype.toString = function() { |
---|
| 558 | var str = ''; |
---|
| 559 | |
---|
| 560 | if (!getObjectById("dftree_"+this.name)) |
---|
| 561 | { |
---|
| 562 | str = '<div id="dftree_'+this.name+'"></div>'; |
---|
| 563 | } |
---|
| 564 | return str; |
---|
| 565 | |
---|
| 566 | /* if (this.root != false) |
---|
| 567 | { |
---|
| 568 | this.root._draw(); |
---|
| 569 | this._drawBranch(this.root.children); |
---|
| 570 | }*/ |
---|
| 571 | } |
---|
| 572 | |
---|
| 573 | //Recursive function, draws children |
---|
| 574 | dFTree.prototype._drawBranch = function(childrenArray) { |
---|
| 575 | var a=0; |
---|
| 576 | for (a;a<childrenArray.length;a++) |
---|
| 577 | { |
---|
| 578 | childrenArray[a]._draw(); |
---|
| 579 | this._drawBranch(childrenArray[a]._children); |
---|
| 580 | } |
---|
| 581 | } |
---|
| 582 | |
---|
| 583 | //add into a position |
---|
| 584 | dFTree.prototype.add = function(node,pid) { |
---|
| 585 | var auxPos; |
---|
| 586 | var addNode = false; |
---|
| 587 | |
---|
| 588 | if (typeof (auxPos = this._searchNode(node.id)) != "number") |
---|
| 589 | { |
---|
| 590 | // if parent exists, add node as its child |
---|
| 591 | if (typeof (auxPos = this._searchNode(pid)) == "number") |
---|
| 592 | { |
---|
| 593 | node._parent = this._aNodes[auxPos]; |
---|
| 594 | this._aNodes[auxPos]._children[this._aNodes[auxPos]._children.length] = node; |
---|
| 595 | addNode = true; |
---|
| 596 | } |
---|
| 597 | else //if parent cannot be found and there is a tree root, ignores node |
---|
| 598 | { |
---|
| 599 | if (!this._root) |
---|
| 600 | { |
---|
| 601 | this._root = node; |
---|
| 602 | addNode = true; |
---|
| 603 | } |
---|
| 604 | } |
---|
| 605 | if (addNode) |
---|
| 606 | { |
---|
| 607 | this._aNodes[this._aNodes.length] = node; |
---|
| 608 | node._myTree = this; |
---|
| 609 | if (this.is_dynamic && this._drawn) |
---|
| 610 | { |
---|
| 611 | node._draw(); |
---|
| 612 | } |
---|
| 613 | } |
---|
| 614 | else |
---|
| 615 | { |
---|
| 616 | this._folderPr[this._folderPr.length] = node.id ; |
---|
| 617 | } |
---|
| 618 | |
---|
| 619 | } |
---|
| 620 | else { |
---|
| 621 | var arrayProps = new Array(); |
---|
| 622 | |
---|
| 623 | arrayProps['id'] = node.id; |
---|
| 624 | arrayProps['caption'] = node.caption; |
---|
| 625 | |
---|
| 626 | arrayProps['url'] = node.url; |
---|
| 627 | arrayProps['target'] = node.target; |
---|
| 628 | arrayProps['onClick'] = node.onClick; |
---|
| 629 | arrayProps['onOpen'] = node.onOpen; |
---|
| 630 | arrayProps['onClose'] = node.onClose; |
---|
| 631 | arrayProps['onFirstOpen'] = node.onFirstOpen; |
---|
| 632 | arrayProps['iconClosed'] = node.iconClosed; |
---|
| 633 | arrayProps['iconOpen'] = node.iconOpen; |
---|
| 634 | arrayProps['runJS'] = node.runJS; |
---|
| 635 | arrayProps['plusSign'] = node.plusSign; |
---|
| 636 | arrayProps['captionClass'] = node.captionClass; |
---|
| 637 | |
---|
| 638 | delete node; |
---|
| 639 | |
---|
| 640 | this.alter(arrayProps); |
---|
| 641 | } |
---|
| 642 | |
---|
| 643 | } |
---|
| 644 | |
---|
| 645 | //arrayProps: same properties of Node |
---|
| 646 | dFTree.prototype.alter = function(arrayProps) { |
---|
| 647 | this.getNodeById(arrayProps['id']).alter(arrayProps); |
---|
| 648 | } |
---|
| 649 | |
---|
| 650 | dFTree.prototype.getNodeById = function(nodeid) { |
---|
| 651 | return this._aNodes[this._searchNode(nodeid)]; |
---|
| 652 | } |
---|
| 653 | |
---|
| 654 | dFTree.prototype.openTo = function(nodeid) |
---|
| 655 | { |
---|
| 656 | var node = this.getNodeById(nodeid); |
---|
| 657 | |
---|
| 658 | if (node && node._parent) |
---|
| 659 | { |
---|
| 660 | node._parent.open(); |
---|
| 661 | this.openTo(node._parent.id); |
---|
| 662 | } |
---|
| 663 | } |
---|
| 664 | |
---|
| 665 | //Searches for a node in the node array, returning the position of the array 4it |
---|
| 666 | dFTree.prototype._searchNode = function(id) { |
---|
| 667 | var a=0; |
---|
| 668 | for (a;a<this._aNodes.length;a++) |
---|
| 669 | { |
---|
| 670 | if (this._aNodes[a].id == id) |
---|
| 671 | { |
---|
| 672 | return a; |
---|
| 673 | } |
---|
| 674 | } |
---|
| 675 | return false; |
---|
| 676 | } |
---|
| 677 | // By jakjr, retorna um array com os ids de todas as pastas (nodes) |
---|
| 678 | dFTree.prototype.getNodesList = function(imapDelimiter) { |
---|
| 679 | var a=0; |
---|
| 680 | var nodes=[]; |
---|
| 681 | for (a;a<this._aNodes.length;a++) |
---|
| 682 | { |
---|
| 683 | var node = this.getNodeById(this._aNodes[a].id); |
---|
| 684 | nodes[a]=[]; |
---|
| 685 | nodes[a].id = node.id; |
---|
| 686 | nodes[a].parent = node._parent ? node._parent.id : 'root'; |
---|
| 687 | var tmp = node.id.split(imapDelimiter); |
---|
| 688 | var tmp_caption = node.caption.split("<"); |
---|
| 689 | |
---|
| 690 | if (node.id == 'INBOX') |
---|
| 691 | nodes[a].caption = get_lang('Inbox'); |
---|
| 692 | else if (node.id == 'user') |
---|
| 693 | nodes[a].caption = get_lang("Shared Folders"); |
---|
| 694 | else |
---|
| 695 | nodes[a].caption = tmp_caption[0]; |
---|
| 696 | //nodes[a].caption = tmp[tmp.length-1] == 'INBOX' ? get_lang('Inbox') : tmp[tmp.length-1]; |
---|
| 697 | nodes[a].plusSign = node.plusSign; |
---|
| 698 | } |
---|
| 699 | return nodes; |
---|
| 700 | } |
---|
| 701 | |
---|
| 702 | //Auxiliar functions |
---|
| 703 | //For multi-browser compatibility |
---|
| 704 | function getObjectById(name) |
---|
| 705 | { |
---|
| 706 | if (document.getElementById) |
---|
| 707 | { |
---|
| 708 | return document.getElementById(name); |
---|
| 709 | } |
---|
| 710 | else if (document.all) |
---|
| 711 | { |
---|
| 712 | return document.all[name]; |
---|
| 713 | } |
---|
| 714 | else if (document.layers) |
---|
| 715 | { |
---|
| 716 | return document.layers[name]; |
---|
| 717 | } |
---|
| 718 | return false; |
---|
| 719 | } |
---|
| 720 | |
---|
| 721 | // [Cookie] Clears a cookie |
---|
| 722 | function clearCookie(cookieName) { |
---|
| 723 | var now = new Date(); |
---|
| 724 | var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24); |
---|
| 725 | this.setCookie(cookieName, 'cookieValue', yesterday); |
---|
| 726 | this.setCookie(cookieName, 'cookieValue', yesterday); |
---|
| 727 | }; |
---|
| 728 | |
---|
| 729 | // [Cookie] Sets value in a cookie |
---|
| 730 | function setCookie(cookieName, cookieValue, expires, path, domain, secure) { |
---|
| 731 | document.cookie = |
---|
| 732 | escape(cookieName) + '=' + escape(cookieValue) |
---|
| 733 | + (expires ? '; expires=' + expires.toGMTString() : '') |
---|
| 734 | + (path ? '; path=' + path : '') |
---|
| 735 | + (domain ? '; domain=' + domain : '') |
---|
| 736 | + (secure ? '; secure' : ''); |
---|
| 737 | }; |
---|
| 738 | |
---|
| 739 | // [Cookie] Gets a value from a cookie |
---|
| 740 | function getCookie(cookieName) { |
---|
| 741 | var cookieValue = ''; |
---|
| 742 | var posName = document.cookie.indexOf(escape(cookieName) + '='); |
---|
| 743 | if (posName != -1) { |
---|
| 744 | var posValue = posName + (escape(cookieName) + '=').length; |
---|
| 745 | var endPos = document.cookie.indexOf(';', posValue); |
---|
| 746 | if (endPos != -1) |
---|
| 747 | { |
---|
| 748 | cookieValue = unescape(document.cookie.substring(posValue, endPos)); |
---|
| 749 | } |
---|
| 750 | else |
---|
| 751 | { |
---|
| 752 | cookieValue = unescape(document.cookie.substring(posValue)); |
---|
| 753 | } |
---|
| 754 | } |
---|
| 755 | return (cookieValue); |
---|
| 756 | }; |
---|
| 757 | |
---|
| 758 | |
---|
| 759 | function imageHTML(src,attributes) { |
---|
| 760 | if (attributes != null) |
---|
| 761 | { |
---|
| 762 | attributes = ''; |
---|
| 763 | } |
---|
| 764 | return "<img "+attributes+" src=\""+src+"\">"; |
---|
| 765 | } |
---|