00001 <?php
00002
00012 abstract class Toolkit extends SObject {
00013 private static $NEXT_ID = 0;
00014 private static $OBJECTS = array();
00015 private static $DEFAULT_THEME = null;
00016
00017 private static $extraCSS = array();
00018 private static $extraJS = array();
00019 private static $extraForms = array();
00020
00021 public static $INDIRECT = array();
00022 public static $TARGETS = array();
00023
00024 public static $ENABLE_PROP_TYPE_CHECKING = false;
00025 public static $ENABLE_PROP_EXIST_CHECKING = false;
00026
00027
00028
00029
00030
00036 public static function getDefaultTheme() {
00037 return self::$DEFAULT_THEME;
00038 }
00039
00048 public static function setDefaultTheme($theme, $updateAll = false) {
00049 $oldTheme = get_class(self::$DEFAULT_THEME);
00050 self::$DEFAULT_THEME = $theme;
00051 if($updateAll == true) {
00052 foreach(self::$OBJECTS as $o) {
00053 $otheme = $o->getTheme();
00054 if($otheme === null || get_class($otheme) == $oldTheme)
00055 $o->setTheme($theme);
00056 }
00057 }
00058 }
00059
00068 public static function getComponent($id) {
00069 if(isset(self::$OBJECTS[$id]))
00070 return self::$OBJECTS[$id];
00071 else
00072 return null;
00073 }
00074
00075
00076
00077
00078
00090 public static function globalAddExtraJS($slot, $js) {
00091 self::$extraJS[$slot] = $js;
00092 }
00093
00098 public static function issetJS($slot) {
00099 return isset(self::$extraJS[$slot]);
00100 }
00101
00113 public static function globalAddExtraCSS($slot, $js) {
00114 self::$extraCSS[$slot] = $js;
00115 }
00116
00124 public static function globalAddHiddenForm($name, $form) {
00125 self::$extraForms[$name] = $form;
00126 }
00127
00138 public static function classToString($class) {
00139 if(count($class) > 0)
00140 return " class=\"" . implode(" ", $class) . "\"";
00141 else
00142 return "";
00143 }
00144
00155 public static function styleToString($style) {
00156 if(count($style) > 0) {
00157 $collect = " style=\"";
00158 foreach($style as $attr => $value)
00159 $collect .= "$attr:$value;";
00160 $collect .= "\"";
00161 return $collect;
00162 }
00163 else
00164 return "";
00165 }
00166
00167
00168
00169
00170
00172 public static function getNextId() {
00173 $id = self::$NEXT_ID;
00174 self::$NEXT_ID++;
00175 return $id;
00176 }
00177
00179 public static function addObject($obj, $id) {
00180 self::$OBJECTS[$id] = $obj;
00181 }
00182
00183 public static function addAsTarget($obj) {
00184 self::$TARGETS[$obj->getId()] = true;
00185 }
00186
00187 public static function isTarget($id) {
00188 return isset(self::$TARGETS[$id]);
00189 }
00190
00192 public static function setObjectId($obj, $newId) {
00193 unset(self::$OBJECTS[$obj->getId()]);
00194 self::$OBJECTS[$newId] = $obj;
00195 if(isset(self::$TARGETS[$obj->getId()])) {
00196 unset(self::$TARGETs[$obj->getId()]);
00197 self::$TARGETS[$newId] = true;
00198 }
00199 }
00200
00202 public static function prm_getExtraCSS() {
00203 return implode("\n", self::$extraCSS);
00204 }
00205
00207 public static function prm_getExtraJS() {
00208 foreach(self::$extraJS as $key => $value) {
00209 self::$extraJS[$key] = trim($value);
00210 if(self::$extraJS[$key] == '')
00211 unset(self::$extraJS[$key]);
00212 }
00213 $ret = implode("\n", self::$extraJS);
00214 $ret .= self::prm_generateIndirectEventJS();
00215 return $ret;
00216 }
00217
00219 public static function prm_getJSSource() {
00220 $uiPath = SPath::getRelPath('UI');
00221 return "<script type=\"text/javascript\" src=\"$uiPath/tk/toolkit.js\"></script>";
00222 }
00223
00225 public static function prm_getCSSSource() {
00226 $uiPath = SPath::getRelPath('UI');
00227 return "<link rel=\"stylesheet\" type=\"text/css\" href=\"$uiPath/tk/toolkit.css\" />\n";
00228 }
00229
00231 public static function prm_getExtraForms() {
00232 return implode("\n", self::$extraForms);
00233 }
00234
00236 public static function prm_generateIndirectEventJS() {
00237 if(count(self::$INDIRECT) > 0) {
00238 $js = "\nToolkit.emit=function(to,what){";
00239 $js .= "switch(to+what){";
00240 foreach(self::$INDIRECT as $to => $events) {
00241 foreach($events as $what => $actions) {
00242 $actions = implode(';', $actions);
00243 $js .= "case '$to$what':$actions;break;";
00244 }
00245 }
00246 $js .= "}}\n";
00247 return $js;
00248 }
00249 else
00250 return '';
00251 }
00252
00254 public static function indirectExists($to, $what) {
00255 return isset(self::$INDIRECT[$to][$what]);
00256 }
00257 }
00258
00259 ?>