00001 <?php
00002
00007 class TKChangeStyleAction extends TKAction {
00008 protected $target;
00009 protected $newStyle;
00010
00017 public function __construct($target, $newStyle) {
00018 parent::__construct();
00019 if(!($target instanceof TKComponent)) {
00020 $this->setError("Target must be a Toolkit component");
00021 }
00022 else if(!is_array($newStyle)) {
00023 $this->setError("Style must be an array");
00024 }
00025 else {
00026 $this->target = $target;
00027 Toolkit::addAsTarget($this->target);
00028 $this->newStyle = $newStyle;
00029 }
00030 }
00031
00033 public function getInvocation() {
00034 $collect = "Toolkit.changeStyle('" . $this->target->getId() . "', ";
00035 $collect .= strtr(json_encode($this->newStyle), '"', "'") . ')';
00036 return $collect;
00037 }
00038
00040 public static function createFromXML($attrs, $children) {
00041 $targetId = (string)$attrs['target'];
00042 $target = Toolkit::getComponent($targetId);
00043 $styleStr = (string)$attrs['style'];
00044 $style = array();
00045 $tmp = split(";", $styleStr);
00046 foreach($tmp as $t) {
00047 if($t == '')
00048 continue;
00049 $tmp2 = split("::", $t);
00050 $style[$tmp2[0]] = $tmp2[1];
00051 }
00052 $obj = new TKChangeStyleAction($target, $style);
00053 return $obj;
00054 }
00055 }
00056
00057 ?>