00001 <?php
00002
00007 class TKTreeAction extends TKAction {
00008 const COLLAPSE_ALL = 0;
00009 const EXPAND_ALL = 1;
00010 const COLLAPSE_NODE = 2;
00011 const EXPAND_NODE = 3;
00012 const DISABLE_NODE = 4;
00013 const ENABLE_NODE = 5;
00014
00015 protected $tree;
00016 protected $item;
00017 protected $which;
00018
00027 public function __construct($which, $tree, $item = null) {
00028 parent::__construct();
00029
00030 if($which > 1 && $item == null) {
00031 $this->setError("You must specify a tree item to collapse or expand!");
00032 return;
00033 }
00034
00035 $this->which = $which;
00036 $this->tree = $tree;
00037 $this->item = $item;
00038 }
00039
00041 public function getInvocation() {
00042 $expandClass = join(" ", $this->tree->get('bullet_expand_class'));
00043 $collapseClass = join(" ", $this->tree->get('bullet_collapse_class'));
00044 switch($this->which) {
00045 case self::COLLAPSE_ALL:
00046 $collect = "Toolkit.collapseTree('" . $this->tree->getId() . "', '$expandClass')";
00047 break;
00048 case self::EXPAND_ALL:
00049 $collect = "Toolkit.expandTree('" . $this->tree->getId() . "', '$collapseClass')";
00050 break;
00051 case self::COLLAPSE_NODE:
00052 $collect = "Toolkit.collapseNode('" . $this->tree->getId() . "', '" . $this->item->getId() . "', '$expandClass')";
00053 break;
00054 case self::EXPAND_NODE:
00055 $collect = "Toolkit.expandNode('" . $this->tree->getId() . "', '" . $this->item->getId() . "', '$collapseClass')";
00056 break;
00057 case self::DISABLE_NODE:
00058 $collect = "Toolkit.disableNode('" . $this->tree->getId() . "', '" . $this->item->getId() . "', '$expandClass')";
00059 break;
00060 case self::ENABLE_NODE:
00061 $collect = "Toolkit.enableNode('" . $this->tree->getId() . "', '" . $this->item->getId() . "')";
00062 break;
00063 }
00064
00065 return $collect;
00066 }
00067
00069 public static function createFromXML($attrs, $children) {
00070 $which = (string)$attrs['which'];
00071 $treeId = (string)$attrs['tree'];
00072 if(isset($attrs['item'])) {
00073 $itemId = (string)$attrs['item'];
00074 $item = Toolkit::getComponent($itemId);
00075 }
00076 else {
00077 $itemId = "";
00078 $item = null;
00079 }
00080 $tree = Toolkit::getComponent($treeId);
00081 $obj = new TKTreeAction($which, $tree, $item);
00082 return $obj;
00083 }
00084 }
00085
00086 ?>