/* Dynamic Folder Tree * Generates DHTML tree dynamically (on the fly). * License: GNU LGPL * * Copyright (c) 2004, Vinicius Cubas Brand, Raphael Derosso Pereira * {viniciuscb,raphaelpereira} at users.sourceforge.net * All rights reserved. * * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Chanded by Joao Alfredo Knopik Junior * joao.alfredo at gmail.com */ // NODE //Usage: a = new dNode({id:2, caption:'tree root', url:'http://www.w3.org'}); function dNode(arrayProps) { //mandatory fields this.id; //node id this.caption; //node caption //optional fields this.url; //url to open this.target; //target to open url this.onClick; //javascript to execute onclick this.onOpen; //javascript to execute when a node of the tree opens this.onClose; //javascript to execute when a node of the tree closes this.onFirstOpen; //javascript to execute only on the first open this.iconClosed; //img.src of closed icon this.iconOpen; //img.src of open icon this.runJS = true; //(bool) if true, runs the on* props defined above this.plusSign = true; //(bool) if the plus sign will appear or not this.captionClass = 'l'; //(string) the class for this node's caption //The parameters below are private this._opened = false; //already opened this._io = false; //is opened this._children = []; //references to children this._parent; //pointer to parent this._myTree; //pointer to myTree this._drawn = false; for (var i in arrayProps) { if (i.charAt(0) != '_') { eval('this.'+i+' = arrayProps[\''+i+'\'];'); } } } //changes node state from open to closed, and vice-versa dNode.prototype.changeState = function() { if (this._io) { this.close(); } else { this.open(); } //cons = COokie of Node Status //setCookie("cons"+this.id,this._io); } dNode.prototype.open = function () { //MAILARCHIVER-01 if(typeof(expresso_mail_archive) != 'undefined') if (expresso_mail_archive.enabled) expresso_mail_archive.drawdata.treeName = this._myTree.name; if (!this._io) { if (!this._opened && this.runJS && this.onFirstOpen != null) { eval(this.onFirstOpen); } else if (this.runJS && this.onOpen != null) { eval(this.onOpen); } //MAILARCHIVER-02 else if(this.id.substr(0,5) == 'local'){ if (this.id != 'local_root') expresso_mail_archive.getFoldersList(this.id.substr(6)); else expresso_mail_archive.getFoldersList(""); } this._debug = true; this._opened = true; this._io = true; this._refresh(); } } dNode.prototype.close = function() { if (this._io) { if (this.runJS && this.onClose != null) { eval(this.onClose); } this._io = false; this._refresh(); } } //alter node label and other properties dNode.prototype.alter = function(arrayProps) { for (var i in arrayProps) { if (i != 'id' && i.charAt(0) != '_') { eval('this.'+i+' = arrayProps[\''+i+'\'];'); } } } //css and dhtml refresh part dNode.prototype._refresh = function() { var nodeDiv = getObjectById("n"+this.id+this._myTree.name); var plusSpan = getObjectById("p"+this.id+this._myTree.name); var captionSpan = getObjectById("l"+this.id+this._myTree.name); var childrenDiv = getObjectById("ch"+this.id+this._myTree.name); if (nodeDiv != null) { //Handling open and close: checks this._io and changes class as needed if (!this._io) //just closed { childrenDiv.className = "closed"; } else //just opened { //prevents IE undesired behaviour when displaying empty DIVs /* if (this._children.length > 0) {*/ childrenDiv.className = "opened"; // } } plusSpan.innerHTML = this._properPlus(); captionSpan.innerHTML = this.caption; } //alter onLoad, etc } //gets the proper plus for this moment dNode.prototype._properPlus = function() { if (!this._io) { if (this._myTree.useIcons) { return (this.plusSign)?imageHTML(this._myTree.icons.plus):""; } else { return (this.plusSign)?"+":" "; } } else { if (this._myTree.useIcons) { return (this.plusSign)?imageHTML(this._myTree.icons.minus):""; } else { return (this.plusSign)?"-":" "; } } } //changes node to selected style class. Perform further actions. dNode.prototype._select = function() { var captionSpan; if (this._myTree._selected) { this._myTree._selected._unselect(); } this._myTree._selected = this; captionSpan = getObjectById("l"+this.id+this._myTree.name); if(document.getElementById("div_tree") != null){ if(ttree.FOLDER != ""){ ttree.FOLDER = ""; } ttree.FOLDER = this.id; } if(document.getElementById("div_folders_search") != null){ if(EsearchE.name_box_search != ""){ EsearchE.name_box_search = ""; } EsearchE.name_box_search = this.id; } //MailArchiver export folders addon if(document.getElementById("dftree_folders_tree") != null){ if(captionSpan.id.substr(0,7) == 'llocal_'){ var div_main_container = document.getElementById('div_buttons'); var div_local_export_criteria = document.createElement('div'); div_local_export_criteria.id = 'div_local_export_criteria'; var obj_label = document.createElement('label'); var obj_label_txt = document.createTextNode(get_lang('Include subfolders')); obj_label.setAttribute("for", "exp_local_recursive"); obj_label.id = 'lbl_exp_local_recursive'; obj_label.appendChild(obj_label_txt); var obj_check = document.createElement('input'); obj_check.type = "checkbox"; obj_check.name = 'exp_local_recursive'; obj_check.id = "exp_local_recursive"; obj_check.checked = false; var obj_combo = document.createElement('select'); obj_combo.name = 'exp_local_format'; obj_combo.id = 'exp_local_format'; var obj_opt1 = document.createElement('option'); var obj_opt2 = document.createElement('option'); var obj_opt3 = document.createElement('option'); var obj_opt4 = document.createElement('option'); var obj_opt5 = document.createElement('option'); var obj_opt6 = document.createElement('option'); var obj_opt7 = document.createElement('option'); var obj_opt8 = document.createElement('option'); obj_opt1.value = 'zip'; obj_opt1.text = get_lang('Zip format'); obj_combo.appendChild(obj_opt1); obj_opt2.value = 'jar'; obj_opt2.text = get_lang('Jar format'); obj_combo.appendChild(obj_opt2); obj_opt3.value = 'tar'; obj_opt3.text = get_lang('Tar format'); obj_combo.appendChild(obj_opt3); obj_opt4.value = 'tar.gz'; obj_opt4.text = get_lang('Tar.gz format'); obj_combo.appendChild(obj_opt4); obj_opt5.value = 'tgz'; obj_opt5.text = get_lang('Tgz format'); obj_combo.appendChild(obj_opt5); obj_opt6.value = 'tar.bz2'; obj_opt6.text = get_lang('Tar.bz2 format'); obj_combo.appendChild(obj_opt6); obj_opt7.value = 'tb2'; obj_opt7.text = get_lang('Tb2 format'); obj_combo.appendChild(obj_opt7); obj_opt8.value = 'tbz'; obj_opt8.text = get_lang('Tbz format'); obj_combo.appendChild(obj_opt8); obj_opt1.selected = true; div_local_export_criteria.appendChild(obj_check); div_local_export_criteria.appendChild(obj_label); div_local_export_criteria.appendChild(obj_combo); //div_main_container.appendChild(div_local_export_criteria); var mn_table = div_main_container.getElementsByTagName('table')[0]; var mn_tbody = mn_table.getElementsByTagName('tbody')[0]; var mn_row = mn_tbody.getElementsByTagName('tr')[4]; var mn_column = mn_row.getElementsByTagName('td')[0]; mn_row.removeChild(mn_column); var new_column = document.createElement('td'); mn_row.appendChild(new_column); new_column.appendChild(div_local_export_criteria); new_column.appendChild(document.createElement('br')); //window.alert('conteudo da coluna:' + mn_column.innerHTML); } else{ if(document.getElementById('div_local_export_criteria')){ var div_main_container = document.getElementById('div_buttons'); var mn_table = div_main_container.getElementsByTagName('table')[0]; var mn_tbody = mn_table.getElementsByTagName('tbody')[0]; var mn_row = mn_tbody.getElementsByTagName('tr')[4]; var mn_column = mn_row.getElementsByTagName('td')[0]; mn_row.removeChild(mn_column); var new_column = document.createElement('td'); mn_row.appendChild(new_column); new_column.appendChild(document.createElement('br')); new_column.appendChild(document.createElement('br')); new_column.appendChild(document.createElement('br')); new_column.appendChild(document.createElement('br')); } } //If local root selected, recursive allways must be checked if(captionSpan.id == 'llocal_rootfolders_tree'){ document.getElementById('exp_local_recursive').checked = true; document.getElementById('exp_local_recursive').disabled = true; document.getElementById('lbl_exp_local_recursive').style.color = 'gray'; } else { if(document.getElementById('exp_local_recursive')){ document.getElementById('exp_local_recursive').disabled = false; document.getElementById('lbl_exp_local_recursive').style.color = 'black'; } } } //changes class to selected link if (captionSpan) { captionSpan.className = 'sl'; } } //changes node background color. dNode.prototype._onMouseOver = function() { var captionSpan; if ((this.id != 'root') && (this.id != 'user') && (this.id !='local_root')){ captionSpan = getObjectById("l"+this.id+this._myTree.name); captionSpan.style.backgroundColor = 'white'; captionSpan.style.border = '1px solid black'; captionSpan.style.paddingTop = '0px'; captionSpan.style.paddingBottom = '0px'; } } //changes node background color. dNode.prototype._onMouseOut = function() { var captionSpan; if ((this.id != 'root') && (this.id != 'user') && (this.id !='local_root')){ captionSpan = getObjectById("l"+this.id+this._myTree.name); captionSpan.style.backgroundColor = ''; captionSpan.style.border = '0px'; captionSpan.style.paddingTop = '1px'; captionSpan.style.paddingBottom = '1px'; } } //changes node to unselected style class. Perform further actions. dNode.prototype._unselect = function() { var captionSpan = getObjectById("l"+this.id+this._myTree.name); this._myTree._lastSelected = this._myTree._selected; this._myTree._selected = null; //changes class to selected link if (captionSpan) { captionSpan.className = this.captionClass; } } //state can be open or closed //warning: if drawed node is not child or root, bugs will happen dNode.prototype._draw = function() { var str; var _this = this; var divN, divCH, spanP, spanL, parentChildrenDiv; var myClass = (this._io)? "opened" : "closed"; var myPlus = this._properPlus(); var append = true; var captionOnClickEvent = null; // var cook; var plusEventHandler = function(){ _this.changeState(); } var captionEventHandler = function(){ eval(captionOnClickEvent); } /* if (this.myTree.followCookies) { this._io = getCookie("cons"+this.id); }*/ //FIXME put this in a separate function, as this will be necessary in //various parts if (this.onClick) //FIXME when onclick && url { captionEventHandler = function () {_this._select();typeof(_this.onClick) == 'function' ? _this.onClick() : eval(_this.onClick);}; } else if (this.url && this.target) { captionEventHandler = function () {_this._select();window.open(_this.url,_this.target);}; } else if (this.url) { captionEventHandler = function () {_this._select();window.location=_this.url;}; } else //Nao tem onClick { if ((this.id != 'root') && (this.id != 'user') && (this.id !='local_root')) //e nao seja raiz(root) ou pastas compartilhadas(user). captionEventHandler = function () {_this._select();}; } //The div of this node divN = document.createElement('div'); divN.id = 'n'+this.id+this._myTree.name; //divN.className = 'son'; divN.className = (!this._parent) ? 'root' : 'son'; //divN.style.border = '1px solid black'; //The span that holds the plus/minus sign spanP = document.createElement('span'); spanP.id = 'p'+this.id+this._myTree.name; spanP.className = 'plus'; spanP.onclick = plusEventHandler; spanP.innerHTML = myPlus; //spanP.style.border = '1px solid green'; //The span that holds the label/caption spanL = document.createElement('span'); spanL.id = 'l'+this.id+this._myTree.name; spanL.className = this.captionClass; spanL.onclick = captionEventHandler; spanL.onmouseover = function () {_this._onMouseOver();}; spanL.onmouseout = function () {_this._onMouseOut();}; // spanL.style.border = '1px solid #f7f7f7'; spanL.innerHTML = this.caption; //spanL.style.border = '1px solid red'; //The div that holds the children divCH = document.createElement('div'); divCH.id = 'ch'+this.id+this._myTree.name; divCH.className = myClass; //divCH.style.border = '1px solid blue'; // div.innerHTML = str; divN.appendChild(spanP); divN.appendChild(spanL); divN.appendChild(divCH); if (this._parent != null) { parentChildrenDiv = getObjectById("ch"+this._parent.id+this._myTree.name); } else //is root { parentChildrenDiv = getObjectById("dftree_"+this._myTree.name); } if (parentChildrenDiv) { parentChildrenDiv.appendChild(divN); } } // TREE //Usage: t = new dFTree({name:t, caption:'tree root', url:'http://www.w3.org'}); function dFTree(arrayProps) { //mandatory fields this.name; //the value of this must be the name of the object //optional fields this.is_dynamic = true; //tree is dynamic, i.e. updated on the fly this.followCookies = true;//use previous state (o/c) of nodes this.useIcons = false; //use icons or not //arrayProps[icondir]: Icons Directory iconPath = (arrayProps['icondir'] != null)? arrayProps['icondir'] : ''; this.icons = { root : iconPath+'/foldertree_base.gif', folder : iconPath+'/foldertree_folder.gif', folderOpen : iconPath+'/foldertree_folderopen.gif', node : iconPath+'/foldertree_folder.gif', empty : iconPath+'/foldertree_empty.gif', line : iconPath+'/foldertree_line.gif', join : iconPath+'/foldertree_join.gif', joinBottom : iconPath+'/foldertree_joinbottom.gif', plus : iconPath+'/foldertree_plus.gif', plusBottom : iconPath+'/foldertree_plusbottom.gif', minus : iconPath+'/foldertree_minus.gif', minusBottom : iconPath+'/foldertree_minusbottom.gif', nlPlus : iconPath+'/foldertree_nolines_plus.gif', nlMinus : iconPath+'/foldertree_nolines_minus.gif' }; //private this._root = false; //reference to root node this._aNodes = []; this._lastSelected; //The last selected node this._selected; //The actual selected node this._folderPr = []; for (var i in arrayProps) { if (i.charAt(0) != '_') { eval('this.'+i+' = arrayProps[\''+i+'\'];'); } } } dFTree.prototype.draw = function(dest_element) { var main_div; if (!getObjectById("dftree_"+this.name) && dest_element) { main_div = document.createElement('div'); main_div.id = 'dftree_'+this.name; dest_element.appendChild(main_div); this._drawn = true; } if (this._root != false) { this._root._draw(); this._drawBranch(this._root._children); } } //Transforms tree in HTML code dFTree.prototype.toString = function() { var str = ''; if (!getObjectById("dftree_"+this.name)) { str = '
'; } return str; /* if (this.root != false) { this.root._draw(); this._drawBranch(this.root.children); }*/ } //Recursive function, draws children dFTree.prototype._drawBranch = function(childrenArray) { var a=0; for (a;a"; }