added more docu and some constants with sane names

This commit is contained in:
Ralf Becker 2015-02-13 09:40:50 +00:00
parent 17f83d89c7
commit 3ec789adfd

View File

@ -20,31 +20,82 @@ egw_framework::includeCSS('/phpgwapi/js/dhtmlxtree/codebase/dhtmlXTree.css');
* *
* Example initialisation of tree via $sel_options array: * Example initialisation of tree via $sel_options array:
* *
* use \etemplate_widget_tree as tree;
*
* $sel_options['tree'] = array( * $sel_options['tree'] = array(
* 'id' => 0, 'item' => array( * tree::ID => 0, tree::CHILDREN => array( // ID of root has to be 0!
* array('id' => '/INBOX', 'text' => 'INBOX', 'tooltip' => 'Your inbox', 'open' => 1, 'im1' => 'kfm_home.png', 'im2' => 'kfm_home.png', 'child' => '1', 'item' => array( * array(
* array('id' => '/INBOX/sub', 'text' => 'sub', 'im0' => 'folderClosed.gif'), * tree::ID => '/INBOX',
* array('id' => '/INBOX/sub2', 'text' => 'sub2', 'im0' => 'folderClosed.gif'), * tree::LABEL => 'INBOX', tree::TOOLTIP => 'Your inbox',
* )), * tree::OPEN => 1, tree::IMAGE_FOLDER_OPEN => 'kfm_home.png', tree::IMAGE_FOLDER_CLOSED => 'kfm_home.png',
* array('id' => '/user', 'text' => 'user', 'child' => '1', 'item' => array( * tree::CHILDREN => array(
* array('id' => '/user/birgit', 'text' => 'birgit', 'im0' => 'folderClosed.gif'), * array(tree::ID => '/INBOX/sub', tree::LABEL => 'sub', tree::IMAGE_LEAF => 'folderClosed.gif'),
* )), * array(tree::ID => '/INBOX/sub2', tree::LABEL => 'sub2', tree::IMAGE_LEAF => 'folderClosed.gif'),
* ),
* ),
* array(
* tree::ID => '/user',
* tree::LABEL => 'user',
* tree::CHILDREN => array(
* array(tree::ID => '/user/birgit', tree::LABEL => 'birgit', tree::IMAGE_LEAF => 'folderClosed.gif'),
* array(tree::ID => '/user/ralf', tree::LABEL => 'ralf', tree::AUTOLOAD_CHILDREN => 1),
* )
* ),
* )); * ));
* *
* Please note: * Please note:
* - id of root-item has to be 0, ids of sub-items can be strings or numbers * - for more info see class constants below
* - item has to be an array (not json object: numerical keys 0, 1, ...) * - all images have to be under url specified in attribute "image_path", default $websererUrl/phpgwapi/templates/default/image/dhtmlxtree
* - im0: leaf image (default: leaf.gif), im1: open folder image (default: folderOpen.gif), * - you can use attribute "std_images" to supply different standard images from default
* im2: closed folder (default: folderClosed.gif) * [ "leaf.gif", "folderOpen.gif", "folderClosed.gif" ]
* - for arbitrary image eg. $icon = common::image($app, 'navbar') use following code: * - images can also be specified as standard "app/image" string, client-side will convert them to url relativ to image_path
* list(,$icon) = explode($GLOBALS['egw_info']['server']['webserver_url'], $icon);
* $icon = '../../../../..'.$icon;
* - json autoloading uses identical data-structur and should use etemplate_widget_tree::send_quote_json($data) * - json autoloading uses identical data-structur and should use etemplate_widget_tree::send_quote_json($data)
* to send data to client, as it takes care of html-encoding of node text * to send data to client, as it takes care of html-encoding of node text
* - if autoloading is enabled, you have to validate returned results yourself, as widget does not know (all) valid id's * - if autoloading is enabled, you have to validate returned results yourself, as widget does not know (all) valid id's
*/ */
class etemplate_widget_tree extends etemplate_widget class etemplate_widget_tree extends etemplate_widget
{ {
/**
* key for id of node, has to be unique, eg. a path, nummerical id is allowed too
* if of root has to be 0!
*/
const ID = 'id';
/**
* key for label of node
*/
const LABEL = 'text';
/**
* key for tooltip / title of node
*/
const TOOLTIP = 'tooltip';
/**
* key for array of children (not json object: numerical keys 0, 1, ...)
*/
const CHILDREN = 'item';
/**
* key if children exist and should be autoloaded, set value to 1
*/
const AUTOLOAD_CHILDREN = 'child';
/**
* key of relative url of leaf image or standard "app/image" string
* used if node has not [AUTOLOAD_]CHILDREN set
*/
const IMAGE_LEAF = 'im0';
/**
* key of relative url of open folder image or standard "app/image" string
* used if node has [AUTOLOAD_]CHILDREN set AND is open
*/
const IMAGE_FOLDER_OPEN = 'im1';
/**
* key of relative url of closed folder image or standard "app/image" string
* used if node has [AUTOLOAD_]CHILDREN set AND is closed
*/
const IMAGE_FOLDER_CLOSED = 'im2';
/**
* key of flag if folder is open, default folder is closed
*/
const OPEN = 'open';
/** /**
* Parse and set extra attributes from xml in template object * Parse and set extra attributes from xml in template object
* *