<?php
defined('ROOT_DIR') or die(__FILE__.' requires egConfig.inc.php');	
include_once(ROOT_DIR.'egBrowser.class.php');
include_once(ROOT_DIR.'egTreeNode.class.php');


// extends egList, egContainer
class egTreeList extends egList {
	var $containersList;
	// for compatibilty with egContainer class
	var $objectsList;
	var $name;

	function egTreeList($id, $title, $posX, $posY, $width, $height, $name) {
		parent::egList($id, $title, $posX, $posY, $width, $height);
		$this->containersList = array();
		$this->objectsList = array();
		$this->name = $name;
	}

	function insertRootNode(&$node) {
		$this->addListItem($node);
	}

	function isContainer() {
        return true;
  }

	function getClassName() {
        return 'egTreeList';
  }

	function getContainerName() {
		return $this->id;
	}

  function getContainerHTML($container = null) {
		$html = '';
		return $html;
  }

	function addContainer(&$container) {
		if (is_object($container)) {
			$this->containersList[$container->getId()] = &$container;
		}
	}

	function &getNodeHTML(&$node, &$parentNodeId) {
		if (!is_object($node)) return '';
		$childNodes = &$node->getChildNodes();
		$id = '';
		if(strlen($parentNodeId)) {
		  $id .= $parentNodeId."_";
		}
		$id .= $node->getId();
		//$html = "var treeNode_".$id." = new egTreeNode('".$node->getId()."', '{$parentNodeId}', '{$this->id}', '".$node->getTitle()."', '".$node->getValue()."', '".$node->getIconOff()."', '".$node->getIconOn()."', '".$node->getContainer()."', '".$node->getAction()."');";
		$html = "var treeNode_".$id." = new egTreeNode('".$id."', '{$parentNodeId}', '{$this->id}', '".$node->getTitle()."', '".$node->getValue()."', '".$node->getIconOff()."', '".$node->getIconOn()."', '".$node->getContainer()."', '".$node->getAction()."');";
	  foreach($childNodes as $childNode) {
			$html .= $this->getNodeHTML($childNode, $id);
			$childNodeId = $id."_".$childNode->getId();
			$html .= "treeNode_{$id}.addNode(treeNode_{$childNodeId});";
	  }
		return $html;
	}
	
  function getHTML($container = null) {
		$html = "var treeList_{$this->id} = new egTreeList('{$this->id}', '{$this->posX}', '{$this->posY}', '{$this->width}', '{$this->height}', '{$container}', '{$this->name}');";

		$parentNodeId = '';
		foreach($this->itemsList as $node) {
			$html.= $this->getNodeHTML($node, $parentNodeId);
			$html .= "treeList_{$this->id}.addRoot(treeNode_".$node->getId().");";
		}

		return $html;
  }

	/**
 	 *
	 *  @static
	 */
  function getScriptsFiles() {
    $scriptsArray = array();
    $scriptsArray[ALL] = "egTreeList_default.js";
    return $scriptsArray;
  }

	/**
 	 *
	 *  @static
	 */
  function getStylesFiles() {
    $stylesArray = array();
    $stylesArray[ALL] = "egTreeList_default.css";

    $stylesArray[INTERNET_EXPLORER] = array();

    $stylesArray[INTERNET_EXPLORER][ALL] = "egTreeList_ie60.css";

    $stylesArray[INTERNET_EXPLORER]['6'] = array();
    $stylesArray[INTERNET_EXPLORER]['6'][ALL] = "egTreeList_ie60.css";

    $stylesArray[INTERNET_EXPLORER]['7'] = array();
    $stylesArray[INTERNET_EXPLORER]['7'][ALL] = "egTreeList_ie60.css";


    $stylesArray[FIREFOX] = array();

    $stylesArray[FIREFOX][ALL] = "egTreeList_ff15.css";

    $stylesArray[FIREFOX]['1'] = array();
    $stylesArray[FIREFOX]['1'][ALL] = "egTreeList_ff15.css";
    $stylesArray[FIREFOX]['1']['5'] = "egTreeList_ff15.css";

    $stylesArray[FIREFOX]['2'] = array();
    $stylesArray[FIREFOX]['2'][ALL] = "egTreeList_ff15.css";


    return $stylesArray;
  }
}

?>