00001 <?php
00002
00010 class TKSelectAction extends TKAction {
00011 protected $src;
00012 protected $selectActions;
00013 protected $deselectActions;
00014
00021 public function __construct($src, $selectActions, $deselectActions) {
00022 parent::__construct();
00023
00024 $this->src = $src;
00025 $this->selectActions = $selectActions;
00026 $this->deselectActions = $deselectActions;
00027 }
00028
00034 public function addActions($onSelect, $onDeselect) {
00035 array_push($this->selectActions, $onSelect);
00036 array_push($this->deselectActions, $onDeselect);
00037 }
00038
00040 public function getInvocation() {
00041 $srcId = $this->src->getId();
00042
00043 $needSelActions = false;
00044 $needDeselActions = false;
00045
00046 $selCollect = "function(idx){switch(idx){";
00047 foreach($this->selectActions as $i => $a) {
00048 $inv = $a->getInvocation();
00049 if($inv != "") {
00050 $selCollect .= "case $i:$inv;break;";
00051 $needSelActions = true;
00052 }
00053 }
00054 $selCollect .= "}};";
00055
00056 $deselCollect = "function(idx){switch(idx){";
00057 foreach($this->deselectActions as $i => $a) {
00058 $inv = $a->getInvocation();
00059 if($inv != "") {
00060 $deselCollect .= "case $i:$inv;break;";
00061 $needDeselActions = true;
00062 }
00063 }
00064 $deselCollect .= "}};";
00065
00066 if($needSelActions || $needDeselActions) {
00067 $selIdx = $this->src->getSelectedIndex();
00068 $collect = "Toolkit.\$selectIndices['$srcId'] = $selIdx;\n";
00069 if($needSelActions)
00070 $collect .= "Toolkit.\$selectActions['$srcId'] = $selCollect\n";
00071 if($needDeselActions)
00072 $collect .= "Toolkit.\$deselectActions['$srcId'] = $deselCollect\n";
00073 $this->addExtraJS("tkv_select_$srcId", $collect);
00074 $collect = "Toolkit.doSelect('$srcId')";
00075 return $collect;
00076 }
00077 else
00078 return "";
00079 }
00080
00082 public static function createFromXML($attrs, $children) {
00083 $srcId = (string)$attrs['src'];
00084 $src = Toolkit::getComponent($srcId);
00085 $selectActions = array();
00086 $deselectActions = array();
00087 foreach($children as $child) {
00088 if($child['tag'] == "event") {
00089 $which = $child['attrs']['which'];
00090 unset($child['attrs']['which']);
00091 if($which == 'sel')
00092 array_push($selectActions, self::convertAction($child));
00093 else
00094 array_push($deselectActions, self::convertAction($child));
00095 }
00096 }
00097 $obj = new TKSelectAction($src, $selectActions, $deselectActions);
00098 return $obj;
00099 }
00100 }
00101
00102 ?>