mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-22 16:03:47 +01:00
added tree method using dhtmlXTree version 1.2
This commit is contained in:
parent
f219bf221e
commit
383c45dad3
@ -1049,4 +1049,119 @@ class html
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* tree widget using dhtmlXtree
|
||||
*
|
||||
* Code inspired by Lars's Felamimail uiwidgets::createFolderTree()
|
||||
*
|
||||
* @author Lars Kneschke <lars-AT-kneschke.de> original code in felamimail
|
||||
* @param array $_folders array of folders: pairs path => node (string label or array with keys: label, (optional) image, (optional) title, (optional) checked)
|
||||
* @param string $_selected path of selected folder
|
||||
* @param mixed $_topFolder=false node of topFolder or false for none
|
||||
* @param string $_onNodeSelect='alert' js function to call if node gets selected
|
||||
* @param string $_divId='foldertree' id of the div
|
||||
* @param string $_divClass='' css class of the div
|
||||
* @param string $_leafImage='' default image of a leaf-node, ''=default of foldertree, set it eg. 'folderClosed.gif' to show leafs as folders
|
||||
* @param boolean/string $_onCheckHandler=false string with handler-name to display a checkbox for each folder, or false (default)
|
||||
* @param string $delimiter='/' path-delimiter, default /
|
||||
*
|
||||
* @return string the html code, to be added into the template
|
||||
*/
|
||||
function tree($_folders,$_selected,$_topFolder=false,$_onNodeSelect="null",$_divId='foldertree',$_divClass='',$_leafImage='',$_onCheckHandler=false,$delimiter='/')
|
||||
{
|
||||
$folderImageDir = $GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/templates/default/images/';
|
||||
|
||||
$html = $this->div("\n",'id="'.$_divId.'"',$_divClass);
|
||||
|
||||
static $tree_initialised=false;
|
||||
if (!$tree_initialised)
|
||||
{
|
||||
$html .= '<link rel="STYLESHEET" type="text/css" href="'.$GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/js/dhtmlxtree/css/dhtmlXTree.css">'."\n";
|
||||
$html .= "<script type='text/javascript' src='{$GLOBALS['egw_info']['server']['webserver_url']}/phpgwapi/js/dhtmlxtree/js/dhtmlXCommon.js'></script>\n";
|
||||
$html .= "<script type='text/javascript' src='{$GLOBALS['egw_info']['server']['webserver_url']}/phpgwapi/js/dhtmlxtree/js/dhtmlXTree.js'></script>\n";
|
||||
$tree_initialised = true;
|
||||
}
|
||||
$html .= "<script type='text/javascript'>\n";
|
||||
$html .= "tree=new dhtmlXTreeObject('$_divId','100%','100%',0);\n";
|
||||
$html .= "tree.setImagePath('$folderImageDir/dhtmlxtree/');\n";
|
||||
|
||||
if($_onCheckHandler)
|
||||
{
|
||||
$html .= "tree.enableCheckBoxes(1);\n";
|
||||
$html .= "tree.setOnCheckHandler('$_onCheckHandler');\n";
|
||||
}
|
||||
|
||||
$top = 0;
|
||||
if ($_topFolder)
|
||||
{
|
||||
$top = '--topfolder--';
|
||||
$topImage = '';
|
||||
if (is_array($_topFolder))
|
||||
{
|
||||
$label = $_topFolder['label'];
|
||||
if (isset($_topFolder['image']))
|
||||
{
|
||||
$topImage = $_topFolder['image'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$label = $_topFolder;
|
||||
}
|
||||
$html .= "\ntree.insertNewItem(0,'$top','".addslashes($label)."',$_onNodeSelect,'$topImage','$topImage','$topImage','CHILD,TOP');\n";
|
||||
|
||||
if (is_array($_topFolder) && isset($_topFolder['title']))
|
||||
{
|
||||
$html .= "tree.setItemText('$top','".addslashes($label)."','".addslashes($_topFolder['title'])."');\n";
|
||||
}
|
||||
}
|
||||
// evtl. remove leading delimiter
|
||||
if ($_selected{0} == $delimiter) $_selected = substr($_selected,1);
|
||||
foreach($_folders as $path => $data)
|
||||
{
|
||||
if (!is_array($data))
|
||||
{
|
||||
$data = array('label' => $data);
|
||||
}
|
||||
$image1 = $image2 = $image3 = '0';
|
||||
if (isset($data['image']))
|
||||
{
|
||||
$image1 = $image2 = $image3 = "'".$data['image']."'";
|
||||
}
|
||||
// evtl. remove leading delimiter
|
||||
if ($path{0} == $delimiter) $path = substr($path,1);
|
||||
$folderParts = explode($delimiter,$path);
|
||||
|
||||
//get rightmost folderpart
|
||||
$label = array_pop($folderParts);
|
||||
if (isset($data['label'])) $label = $data['label'];
|
||||
|
||||
// the rest of the array is the name of the parent
|
||||
$parentName = implode((array)$folderParts,$delimiter);
|
||||
if(empty($parentName)) $parentName = $top;
|
||||
|
||||
$entryOptions = 'CHILD,CHECKED';
|
||||
// highlight currently item
|
||||
if ($_selected === $path)
|
||||
{
|
||||
$entryOptions .= ',SELECT';
|
||||
}
|
||||
$html .= "tree.insertNewItem('".addslashes($parentName)."','".addslashes($path)."','".addslashes($label).
|
||||
"',$_onNodeSelect,$image1,$image2,$image3,'$entryOptions');\n";
|
||||
if (isset($data['title']))
|
||||
{
|
||||
$html .= "tree.setItemText('".addslashes($path)."','".addslashes($label)."','".addslashes($data['title'])."');\n";
|
||||
}
|
||||
if($_displayCheckBox)
|
||||
{
|
||||
$html .= "tree.setCheck('".addslashes($path)."','".(int)$data['checked']."');";
|
||||
}
|
||||
}
|
||||
$html .= "tree.closeAllItems(0);\n";
|
||||
$html .= "tree.openItem('".($_selected ? addslashes($_selected) : $top)."');\n";
|
||||
$html .= "</script>\n";
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user