ExtPHPæ¯ä¸ä¸ªåºäºThinkphpå¼åæ¡æ¶çExtJSå¼åç±»åºï¼ä½¿ç¨æ¤ç±»åºå¯ä»¥å¾æ¹ä¾¿ççæExtJSçJavaScript代ç ã
- /**
- * PHPExtJs åºç¡å¯¹è±¡
- * @License: ( http://www.apache.org/licenses/LICENSE-2.0 )
- * @Author: wb
- */
- class ExtBase {
- /**
- * ExtJSçåºæ¬ç®å½ï¼æ¤åæ°æ¯ä¸ªè·¯å¾
- * @var String
- */
- public $exthome = '';
- /**
- * ExtJSçè¯è¨ç¯å¢é
ç½®ï¼é»è®¤ä¸ºzh_cn (ä¸æ)
- * @var String
- */
- public $extlang = 'zh_cn';
- /**
- * ExtJSçè°è¯æ¨¡å¼ï¼é»è®¤ä¸ºfalse
- * @var Boolean
- */
- public $debugmode = false;
- /**
- * ExtJSçå
æ ¸æ¨¡å¼ï¼é»è®¤ä¸ºfalse
- * @var Boolean
- */
- public $coremode = false;
- /**
- * ExtJSçç¯å¢ç®å½çåºåç®å½
- * @var String
- */
- public $extbasedir = "";
- /**
- * ExtJSçåºæ¬ä»£ç
- * @var String
- */
- public $extbasecode = "";
- /**
- * 页é¢æéè¦çCssæ件
- * @var Array
- */
- public $pageCss = array();
- /**
- * 页é¢æéè¦çJsæ件
- * @var Array
- */
- public $pageJs = array();
- /**
- * ExtJsçcssæ件
- * @var String
- */
- private $extcss = "";
- /**
- * ExtJSç®å½ä¸çæææä»¶ç´¢å¼ æ ¼å¼ä¸ºï¼array(æ件å称=>æ件路å¾)
- * @var Array
- */
- public $ExtALLFiels = array();
- /**
- * å®ä¹ExtJSçåºæ¬è¿è¡æ件 æ ¼å¼ä¸ºï¼array(å称=>æ件å称)ï¼è¿éåªæ¯å®ä¹äºåºæ¬çå 个
- * å¦ï¼base,all,css,core,debug
- * @var Array
- */
- public $ExtBaseFile = array(
- 'base' => 'ext-base.js',
- 'all' => 'ext-all.js',
- 'css' => 'ext-all.css',
- 'core' => 'ext-core.js',
- 'debug' => 'ext-all-debug.js',
- );
- /**
- * æ ¹æ®åºæ¬åæ°è®¾ç½®Extjsçåºæ¬ç¯å¢
- *
- * @param string $exthome ExtJSæå¨ç®å½ï¼ç¸å¯¹äº$basedirææå®çç®å½
- * @param boolen $extdebue æ¯å¦å¼å¯è°è¯æ¨¡å¼
- * @param boolen $extcore æ¯å¦æ¯core模å¼
- * @param string $extlang 设置ExtJSè¯è¨
- * @param string $basedir $exthomeç®å½æå¨çç®å½
- */
- public function __construct($exthome = '', $basedir='', $extdebue=false, $extcore=false, $extlang='zh_cn') {
- //设置åºæ¬è¿è¡ç¯å¢
- $this->setExtBase($exthome, $basedir, $extdebue, $extcore, $extlang);
- }
- /**
- * 设置Extjsçåºæ¬ç®å½
- *
- * @param String $exthome ExtJsæ件æå¨çç®å½
- * @param String $basedir æå¨ç®å½æ¯åºäºé£ä¸ªç®å½ é»è®¤ä¸º â/â
- * @return Boolean
- */
- public function setExtHome($exthome="", $basedir="/") {
- //TODO - 设置Extjsçåºæ¬ç®å½
- if (!empty($basedir)) {
- $this->extbasedir = str_replace("/./", "/", $basedir);
- }
- if (!empty($exthome)) {
- $this->ReadALLFile($exthome, $this->ExtALLFiels);
- if (!empty($this->ReadALLFile[$this->ExtBaseFile['base']])) {
- throw new Exception("ä¸æ£ç¡®çexthomeç®å½($exthome)ï¼");
- }
- $this->exthome = $exthome;
- }
- return TRUE;
- }
- /**
- * 设置Extjsçåºæ¬ç¯å¢
- *
- * @param string $exthome ExtJSæå¨ç®å½ï¼ç¸å¯¹äº$basedirææå®çç®å½
- * @param boolen $extdebue æ¯å¦å¼å¯è°è¯æ¨¡å¼
- * @param boolen $extcore æ¯å¦æ¯core模å¼
- * @param string $extlang 设置ExtJSè¯è¨
- * @param string $basedir $exthomeç®å½æå¨çç®å½
- * @return Boolean
- */
- public function setExtBase($exthome = '', $basedir='', $extdebue=false, $extcore=false, $extlang='zh-CN') {
- //设置Extjsçåºæ¬ç¯å¢
- $this->setExtHome($exthome, $basedir);
- $this->setExtLang($extlang);
- $this->debugmode = $extdebue;
- return TRUE;
- }
- /**
- * 设置extjsçè¯è¨
- *
- * @param String $lang è¿éçè¯è¨åªè½æ¯ExtJsä¸è¯è¨æ件çæ件å称ä¸çè¯è¨é¨åï¼å¦ï¼
- * ext-lang-zh_cn.jsè¯è¨æ件ï¼åªè¦zh_cnå°±è¡
- */
- public function setExtLang($lang='') {
- //TODO - 设置extjsçè¯è¨
- if (!empty($lang))
- $this->extlang = $lang;
- }
- /**
- * è·å对象çStyel设置串
- */
- public function getExtBaseStyel() {
- $tmpstr = '';
- if (is_array($this->ExtALLFiels[$this->ExtBaseFile['css']])) {
- $cssfile = '';
- foreach ($this->ExtALLFiels[$this->ExtBaseFile['css']] as $v) {
- if (preg_match('/\/docs/i', $v) == FALSE) {
- $cssfile = $v;
- break;
- }
- }
- $tmpstr .= "extbasedir}{$cssfile}\">\n";
- } else {
- $tmpstr .= "extbasedir}{$this->ExtALLFiels[$this->ExtBaseFile['css']]}\">\n";
- }
- //设置å
¶å®css
- if (!empty($this->pageCss)) {
- foreach ($this->pageCss as $f) {
- if (is_array($f)) {
- $tmpstr .= "\n";
- } else {
- $tmpstr .= "\n";
- }
- }
- }
- return $tmpstr;
- }
- /**
- * è·å对象çScriptåºæ¬é
置串
- * @return String
- */
- public function getExtBaseScript() {
- $tmp = '';
- $tmpstr = '';
- if (is_array($this->ExtALLFiels[$this->ExtBaseFile['base']])) {
- foreach ($this->ExtALLFiels[$this->ExtBaseFile['base']] as $v) {
- if (preg_match('/source/i', $v) == FALSE) {
- $tmp = $v;
- break;
- }
- }
- if (empty($tmp))
- $tmp = $this->ExtALLFiels[$this->ExtBaseFile['base']][0];
- }else {
- $tmp = $this->ExtALLFiels[$this->ExtBaseFile['base']];
- }
- $tmpstr .= "\n";
- if ($this->debugmode) {
- $tmpstr .= "\n";
- } else {
- $tmpstr .= "\n";
- }
- if ($this->coremode) {
- $tmpstr .= "\n";
- }
- //设置è¯è¨
- $ExtLangJS = 'ext-lang-{lang}.js';
- if (!empty($this->extlang)) {
- $tmpfile = strtolower(str_replace("{lang}", $this->extlang, $ExtLangJS));
- if (isset($this->ExtALLFiels[$tmpfile])) {
- $tmpstr .= "\n";
- }
- }
-
- //并å
¥å
¶å®Jsæ件
- $tmpstr .= $this->getExtPageJs();
-
- return $tmpstr;
- }
- /**
- * è·åExtJsçå
¶å®è®¾ç½®
- * @return String
- */
- public function getExtPageJs(){
- $tmpstr = "";
- //设置å
¶å®js
- if (!empty($this->pageJs)) {
- foreach ($this->pageJs as $f) {
- if (is_array($f)) {
- $tmpstr .= "\n";
- } else {
- $tmpstr .= "\n";
- }
- }
- }
- return $tmpstr;
- }
-
- /**
- * è·åExtJsçåºæ¬é¡µé¢é
置串
- * @return string
- */
- public function getExtBaseJs() {
- //s.gif
- $tmpstr = '';
- $tmpstr .= "\n";
- if (!empty($this->extcss) && isset($this->ExtALLFiels[$this->extcss])) {
- $tmpstr .= "\n";
- }
- return $tmpstr;
- }
- /**
- * è·åExtJsçææé
置串
- * @return String
- */
- public function getExtBaseCode() {
- $this->extbasecode .= $this->getExtBaseStyel();
- $this->extbasecode .= $this->getExtBaseScript();
- $this->extbasecode .= $this->getExtBaseJs();
- return $this->extbasecode;
- }
- /**
- * 设置页é¢çå
¶å®cssæ件
- * @param String Cssæ件å称åè·¯å¾
- */
- public function setPageCssFile($fileName) {
- if (!empty($fileName)) {
- $this->pageCss[] = $fileName;
- }
- }
- /**
- * 设置页é¢çstyleæ ·å¼
- * @param $cssString æ ·å¼ä¸²
- */
- public function setPageCss($cssString) {
- if (!empty($cssString)) {
- $this->pageCss[] = array("sytle" => $cssString);
- }
- }
-
- /**
- * 设置页é¢çå
¶å®jsæ件
- * @param String JSæ件å称åè·¯å¾
- */
- public function setPageJsFile($fileName) {
- if (!empty($fileName)) {
- $this->pageJs[] = $fileName;
- }
- }
-
- /**
- * 设置页é¢çJS代ç
- * @param $Js å¯ä»¥æ¯ExtFunction对象ä¹å¯ä»¥æ¯js串
- */
- public function setPageJs($Js) {
- if (!empty($Js)) {
- $this->pageJs[] = array("js" => $Js);
- }
- }
-
- /**
- * 设置extjsçæ ·å¼
- *
- * @param String $cssName cssæ ·å¼å称 é»è®¤ä¸ºdefault
- */
- public function setExtCss($cssName="default") {
- if ($cssName != "default") {
- $this->extcss = "xtheme-" . $cssName . ".css";
- }
- }
-
- /**
- * æ$dataæ ¼å¼åæExtJsç对象Json串
- *
- * @param Array $data
- * @return String
- */
- public function ExtJsonFormat($data) {
- $i = 0;
- $retstr .= "{";
- foreach ($data as $k => $v) {
- if ($i > 0)
- $retstr .= ",";
- if (is_string($v) && !is_numeric($v) && strtolower($v) != "true" && strtolower($v) != "false") {
- $retstr .= "$k:'$v'";
- }
- else
- $retstr .= "$k:$v";
- $i++;
- }
- $retstr .= "}";
- return $retstr;
- }
-
- /**
- * 读åæç¹æ件夹$floderéé¢çææå
容ï¼å
æ¬æ件ãæ件夹ååæ件夹ä¸çææå
容ï¼
- *
- * @param String $floder æ件夹å称ï¼ç®å½åï¼å¯ä»¥æ¯ç¸å¯¹ç®å½
- * @param Array POT $retarr å
容åæ¾çæ°ç»æé
- */
- public function ReadALLFile($floder, &$retarr = array()) {
- //TODO - 读åææå®çæ件夹$floderéé¢çææå
容(å
æ¬æ件åæ件夹ï¼åæ件夹ä¸çå
容),è¿åç»$retarræé
- $tpath = '';
-
- $app_path = str_replace('\\', '/', getcwd()) . "/";
- //echo "APP_PATH:".$app_path." BASE:".$this->extbasedir."
\n";
- if (strpos($this->extbasedir, $app_path) == FALSE) {
- $tpath = $app_path . "/" . $floder;
- } else {
- $tpath = $this->extbasedir . "/" . $floder;
- }
- $tpath = preg_replace(array('/\{2,}/', '/\/{2,}/'), '/', $tpath);
- $tmparr = $this->ReadFloder($tpath);
-
- if ($tmparr != FALSE && is_array($tmparr)) {
- foreach ($tmparr[0] as $v) {
- $this->ReadALLFile($floder . '/' . $v, $retarr);
- }
- if (!empty($tmparr[1])) {
- foreach ($tmparr[1] as $v) {
- $k = strtolower($v);
- if (isset($retarr[$k])) {
- $tmpstr = preg_replace('/\/{2,}/', "/", $floder . '/' . $v);
- if (is_array($retarr[$k])) {
- $retarr[$k][] = $tmpstr;
- } else {
- $retarr[$k] = array($retarr[$k], $tmpstr);
- }
- } else {
- $retarr[$k] = preg_replace('/\/{2,}/', "/", $floder . '/' . $v);
- }
- }
- }
- }
- array_change_key_case($retarr);
- }
-
- /**
- * 读åææå®çæ件夹$floderéé¢çå
容(å
æ¬æ件åæ件夹)
- *
- * @param String $floder
- * @return Array
- */
- public function ReadFloder($floder) {
- //TODO - 读åææå®çæ件夹$floderéé¢çå
容(å
æ¬æ件åæ件夹)
- if (!is_dir($floder)) {
- throw new ThinkException("ä¸è½è®¾ç½®ExtJsçè¿è¡ç¯å¢ï¼è¯·æ£æ¥è®¾ç½®çç®å½ï¼$floder");
- }
- $flod = array();
- $files = array();
- $dh = opendir($floder);
- if (!$dh) {
- throw new ThinkException("æå¼ç®å½:" . dirname("../") . " é误ï¼");
- }
- while (false !== ($filename = readdir($dh))) {
- if ($filename != "." && $filename != "..") {
- if (strpos($filename, ".") $flod[] = $filename;
- else
- $files[] = $filename;
- }
- }
- return array($flod, $files);
- }
- /**
- * 设置对象çå±æ§
- * @param String $key
- * @param Mixed $val
- */
- public function __set($key, $val) {
- if (property_exists($this, $key)) {
- if ($key == "extlang") {
- $this->setExtLang($val);
- } else {
- $this->$key = $val;
- }
- }
- }
- /**
- * è·å对象å±æ§å¼
- * @param String $key
- * @return Mixed
- */
- public function __get($key) {
- if (empty($key))
- return false;
- if (property_exists($this, $key)) {
- if ($key == "extbasecode")
- return $this->getExtBaseCode();
- else
- return $this->$key;
- }
- return true;
- }
- /**
- * å°å¯¹è±¡ä»¥Stringçæ¹å¼è¿å
- * @return String
- */
- public function __toString() {
- return $this->getExtBaseCode();
- }
-
- }
- ?>
å¤å¶ä»£ç
- /**
- * PHPExtJsç对象çæç±»
- * @License: ( http://www.apache.org/licenses/LICENSE-2.0 )
- * @Author: wb
- */
- class ExtFunction {
- /**
- * 对象çåæ°é
- * @var Array åæ°é
- */
- protected $param = array();
- /**
- * 对象代ç
- * @var String 对象代ç 串
- */
-
- protected $code = '';
- /**
- * JS对象表示æ³çå称
- * @var String 对象å称
- */
- protected $clsname = '';
-
- /**
- * æ ¹æ®åæ°$paramã代ç $codeå$clsnames设置Ext function对象
- *
- * @param Mixed $param functionçåæ°å表 å¦ï¼"val,val1" æè
array("val","val1")
- * @param Mixed $code functiondç代ç ï¼å¯ä»¥è·å¯¹è±¡
- * @param String $clsname Extèªå®ä¹å¯¹è±¡å称
- *
- */
- public function __construct($param = null, $code = null, $clsname = null) {
- $this->SetParam($param);
- $this->SetCode($code);
- $this->clsname = $clsname;
- }
-
- /**
- * 设置对象çåæ°
- * @param String $param åæ° å¯ä»¥æ¯æ°ç»
- */
- public function SetParam($param) {
- if (is_array($param)) {
- $this->param = array_merge($this->param, $param);
- } elseif (is_string($param) && preg_match("/,/", $param)) {
- $this->param = array_merge($this->param, split(',', $param));
- } else {
- $this->param [$param] = $param;
- }
- }
-
- /**
- * 设置对象ç代ç
- * @param Mixed $code å¯ä»¥æ¯ä»£ç 串æè
æ¯PHPExtJSçå
¶å®å¯¹è±¡
- */
- public function SetCode($code) {
- if (!empty($this->code) && is_object($this->code) && method_exists($this->code, 'render')) {
- $this->code = $this->code->render();
- }
-
- if (is_object($code) && method_exists($code, 'render')) {
- $this->code .= $code->render();
- } else if (is_string($code)) {
- $this->code .= $code;
- }
- if (is_array($code)) {
- foreach ($code as $key => $val) {
- if ($key === "return") {
- //echo "KEY:$key
\n";
- $this->code .= "return ";
- }
- $this->SetCode($val);
- $this->code .= ";";
- }
- }
- }
-
- /**
- * @param String $name DOMå称
- * @param String $clsname 对象å称
- */
- public function render($name = '', $clsname = "") {
- $str = '';
- if (!empty($name)) {
- $str .= "var $name = function ";
- } else {
- $str .= "function ";
- }
-
- if (!empty($clsname))
- $this->clsname = $clsname;
- if (!empty($this->clsname)) {
- $str .= " " . $this->clsname . " ";
- $this->param = array();
- }
-
- $str .= "(" . implode(',', $this->param) . ")";
- if (!empty($this->code)) {
- $str .= "{";
- if (is_object($this->code) && method_exists($this->code, "render")) {
- $str .= $this->code->render();
- } elseif (is_string($this->code)) {
- $str .= $this->code;
- }
- $str .= "}";
- }
- if (!empty($name))
- $str .= ";";
- //å»é¤æ³¨éè¡
- $search = array(
- '/(\/\/.*)|(\/\*.*\*\/)/i', //å»æ注é
- '/[\f\n\r\t]*/i', //å»æå车符
- '/\{(\s)*/i',
- '/\}(\s)*\}/i',
- '/\}(\s)*/i',
- //'/\}(\s)*if/i',
- '/(\s)*}/',
- '/;(\s)*/',
- '/\,(\s)*/i'
- );
- $replace = array(
- '',
- '',
- '{',
- '}}',
- '}',
- //'}if',
- '}',
- ';',
- ','
- );
- $str = preg_replace($search, $replace, $str);
- return $str;
- }
-
- public function __toString() {
- return $this->render();
- }
-
- }
-
- ?>
å¤å¶ä»£ç
- require_once 'ExtData.class.php';
-
- class ExtObject {
-
- protected static $indent = '';
- public $state = Array();
- public $showkeys = true;
- public $extClass = '';
- public $rendername = '';
- public $extend = '';
-
- /**
- * æ ¹æ®$propertieså±æ§å建Ext对象
- *
- * @param String $ExtClass 对象å称 å¦ï¼Ext.TabPanelãExt.grid.GridPanel ç
- * @param Array $properties 对象å±æ§æ°ç» å¦ï¼
- * Array('labelWidth' => 150,
- * 'url' => 'part.submit.php',
- * 'frame' => true,
- * 'bodyStyle' => 'padding: 5px 5px 0',
- * 'width' => 500,
- * 'defaults' => new ExtObject(null, Array('width' => 290)),
- * 'defaultType' => 'textfield'
- * )
- * @param String $name varå称 ä¾å¦ï¼$name='test',å产ç 为 var test = new $ExtClass () {} ç代ç
- * @param Boolen $showkeys æ¯å¦æ¾ç¤ºé
ç½®æ°ç»$propertiesçæ ç¾
- */
- public function __construct($ExtClass = null, $properties = null, $name = null, $showkeys = true) {
- $this->extClass = $ExtClass;
- if (is_array($properties)) {
- $this->state = $properties;
- }
- $this->showkeys = $showkeys;
- $this->rendername = $name;
- }
-
- /**
- * 设置对象çå±æ§ å³ $key = $val;
- *
- * @param String $key å±æ§å称 å¿
须满足ExtJS个对象çè§å®
- * @param Anly_type $val
- */
- public function __set($key, $val) {
- if ($key == 'indent') {
- $this->indent = $val;
- } else {
- $this->state [$key] = $val;
- }
- }
-
- public function __get($key) {
- if (isset($this->state[$key]))
- return $this->state [$key];
- }
-
- public function __isset($key) {
- return isset($this->state [$key]);
- }
-
- public function del($key) {
- $this->__unset($key);
- }
-
- public function __unset($key) {
- unset($this->state [$key]);
- }
-
- public function __toString() {
- return $this->render();
- }
-
- /**
- * 设置å±æ§$nameçå±æ§å¼ä¸º $property
- *
- * @param String $name å±æ§å称
- * @param Mixed $property å±æ§å¼
- */
- public function setProperty($name, $property) {
- if (!empty($name)) {
- $this->state [$name] = $property;
- }
- }
-
- /**
- * æ ¹æ®é
ç½®æ°ç»$properties设置ExtClasså±æ§
- *
- * @param ConfigArray $properties é
ç½®æ°ç»
- */
- public function setProperties($properties) {
- $this->state = array_merge($this->state, $properties);
- }
-
- public function setExtendsClass($ExtClass) {
- $this->extend = $ExtClass;
- }
-
- public function JSRender($items, $showkeys = true, $isparam = false) {
- //self::$indent .= ' ';
- $str = '';
- $total = count($items);
- $cnt = 1;
- if ($isparam && $total == 2 && is_object($items [0]) && is_array($items [1])) {
- $str .= "{{$this->JSRender($items[0])}},";
- $str .= "[{$this->JSRender($items[1])}]";
- } else {
- foreach ($items as $element => $value) {
- if ($showkeys) {
- if (is_numeric($showkeys)) {
- $str .= self::$indent . "'$element':";
- } else {
- if (!is_numeric($element))
- $str .= self::$indent . "$element: ";
- }
- }
- if (is_string($value)) {
- $str .= "'$value'";
- } else if (is_bool($value)) {
- $str .= ( $value) ? "true" : "false";
- } else if (is_object($value)) {
- if (method_exists($value, 'render')) {
- $str .= $value->render();
- }
- } else if (is_array($value)) {
- if (count($value) == 1 && is_string($value [0])) {
- $str .= $value [0];
- } else {
- $str .= "[";
- $str .= $this->JSRender($value, false);
- $str .= self::$indent . "]";
- }
- } else if (is_numeric($value)) {
- $str .= $value;
- } else if ($value == '') {
- $str .= "''";
- } else {
- $str .= $value;
- }
- if ($cnt != $total) {
- $str .= ",";
- }
- $cnt++;
- }
- }
- self::$indent = substr(self::$indent, 0, - 2);
- return $str;
- }
-
- /**
- * è¿åæ建好çExtJs对象çJs代ç
- *
- * @param String $name
- * @return String
- */
- public function render($name = null) {
- $str = '';
- if (!empty($name))
- $this->rendername = $name;
-
- if (
- preg_match('/.alert/', $this->extClass) || preg_match('/.prompt/', $this->extClass)
- || preg_match('/.show/', $this->extClass) || preg_match('/.confirm/', $this->extClass)
- || preg_match('/.progress/', $this->extClass) || preg_match('/.wait/', $this->extClass)
- || preg_match('/.updateProgress/', $this->extClass)
- || preg_match('/.updateText/', $this->extClass)
- ) {
- if (!empty($this->rendername))
- $str = self::$indent . "var $this->rendername = $this->extClass(";
- else
- $str = self::$indent . "$this->extClass (";
- $str .= $this->JSRender($this->state, FALSE);
- $str .= ");";
- } elseif (
- preg_match('/.ColumnModel/', $this->extClass) || preg_match('/.Record.create/', $this->extClass)
- ) {
- if (!empty($this->rendername))
- $str = self::$indent . "var $this->rendername = new $this->extClass([";
- else
- $str = self::$indent . "new $this->extClass ([";
- $str .= $this->JSRender($this->state, TRUE);
- $str .= "])";
- if ($this->rendername) {
- $str .= ";";
- }
- } elseif (
- preg_match('/.JsonReader/', $this->extClass) || preg_match('/.ArrayReader/', $this->extClass)
- ) {
- if (!empty($this->rendername))
- $str = self::$indent . "var $this->rendername = new $this->extClass(";
- else
- $str = self::$indent . "new $this->extClass (";
- if (!empty($this->state['fields'])) {
- $str .= "{totalProperty:'" . $this->state['totalProperty'] . "', ";
- $str .= "root:'" . $this->state['root'] . "'},";
- $str .= "[" . $this->JSRender($this->state['fields'], TRUE) . "]";
- } else {
- $str .= $this->JSRender($this->state, TRUE);
- }
- $str .= ")";
- if ($this->rendername) {
- $str .= ";";
- }
- } elseif ($this->extend) { //å¦ææ¯æ©å±å¯¹è±¡
- $str = self::$indent . $this->extClass . " = Ext.extend( $this->extend ,{";
- $str .= $this->JSRender($this->state, TRUE);
- $str .= "});";
- } else {
- if ($this->rendername) {
- if ($this->extClass) {
- $str = self::$indent . "var $this->rendername = new $this->extClass({";
- } else {
- $str = self::$indent . "var $this->rendername = {";
- }
- } elseif ($this->extClass) {
- echo self::$indent;
- $str = self::$indent . "new $this->extClass({";
- } else {
- $str = self::$indent . "{";
- }
- $str .= $this->JSRender($this->state, $this->showkeys);
- $str .= self::$indent . "}";
- if ($this->extClass) {
- $str .= ")";
- }
- if ($this->rendername) {
- $str .= ";";
- }
- }
- return $str;
- }
-
- }
-
- ?>
å¤å¶ä»£ç
-
/**
- * PHPExtJs ExtJs页é¢å¯¹è±¡
- * @License: ( http://www.apache.org/licenses/LICENSE-2.0 )
- * @Author: wb
- */
-
- class ExtPage {
- public $extjs = '';
- public $extbase = '';
- public $body = '';
- public $bodyPapm = '';
- public $title = '';
- public $charset = '';
- public $template = "";
- /**
- * æ ¹æ®é¡µé¢æ¨¡æ¿è¾åºextjshtml代ç
- * 模æ¿ä¸å¯ä»¥å
æ¬{charset},{title},{extbase},{extjs},{body}
- *
- * @param String $title 页é¢æ é¢
- * @param String $extjs extjs代ç
- * @param String $body 页é¢body
- * @param String $charset 页é¢ç¼ç 设置ï¼é»è®¤ä¸ºUTF-8
- * @param String $template 页é¢æ¨¡æ¿
- */
- public function __construct($title='', $extjs='', $extbase='', $body='', $charset='utf-8', $template='') {
- $this->title = $title;
- $this->extjs = $extjs;
- $this->extbase = $extbase;
- $this->body = $body;
- $this->charset = $charset;
- if(!empty($template)) $this->template = $template;
- else $this->template = "
-
- {title}
- {extbase}
-
-
-
- {body}
-
- ";
- }
-
- public function render() {
- if(!empty($this->template)){
- $search = array("{charset}","{title}","{extbase}","{extjs}","{body}","{bodyPapm}");
- $replace = array($this->charset,$this->title,$this->extbase,$this->extjs,$this->body,$this->bodyPapm);
- $this->template = str_replace($search,$replace,$this->template);
- echo $this->template;
- }else{
- throw new Exception("页é¢æ¨¡æ¿ä¸ºç©º,请å
设置页é¢æ¨¡æ¿!");
- }
- }
-
- public function __set($key, $val) {
- switch($key) {
- case 'extjs':
- $this->extjs = $val;
- break;
- case 'body':
- $this->body = $val;
- break;
- case 'bodyPapm':
- $this->bodyPapm = $val;
- break;
- case 'charset':
- $this->body = $val;
- break;
- case 'template':
- $this->template = $val;
- break;
- case 'extbase':
- $this->extbase = $val;
- break;
- default:
- throw new Exception("éæ³çExtPageå±æ§ ExtPage::$key");
- }
- }
-
- public function __get($key) {
- switch($key) {
- case 'extjs':
- return $this->extjs;
- case 'body':
- return $this->body;
- case 'bodyPapm':
- return $this->bodyPapm;
- case 'charset':
- return $this->charset;
- case 'template':
- return $this->template;
- default:
- throw new Exception("éæ³çExtPageå±æ§ ExtPage::$key");
- }
- }
- }
å¤å¶ä»£ç
- vendor("com.qldx.ext.*");
-
- class FormWin extends Form {
-
- /**
- * çªä½å è½½åå§æ°æ®ç对象
- * @var ExtObject
- */
- public $formLoad = null;
- /**
- * çªä½è¯»åæ°æ®ç对象
- * @var ExtObject
- */
- public $formreader = null;
- /**
- * å è½½æ°æ®æ¶ä¼ éçåæ°
- * @var Mixed
- */
- public $formLoadParam = null;
- /**
- * çªå£å¯¹è±¡
- * @var ExtObject
- */
- public $windolg = null;
- /**
- * çªä½å段é
- * @var Array
- */
- public $fieldset = array();
- /**
- * åå§åçªä½å¯¹è±¡ç代ç
- * @var String
- */
- public $initcorde = '';
- /**
- * çªä½ä¸å«æé® é»è®¤ä¸ºfalseæ为å«ææé®
- * @var Bloon
- */
- public $noButton = false;
-
- /**
- * æé çªä½
- * @param String $formName çªä½å称
- * @param String $ModelName çªä½å
³èæ°æ®è¡¨æ¨¡åå
- * @param Mixed $dataId çªä½å
³èæ°æ®çID
- * @param Array $Properties çªä½å±æ§æ°ç»
- */
- public function __construct($formName = '', $ModelName = "", $dataId = "", $Properties = array()) {
- parent::__construct($formName, $ModelName, $dataId, $Properties);
- $this->formbody->setProperty("labelWidth", 80);
- $this->formbody->setProperty("defaults", array("{xtype:'textfield',anchor:'100%'}"));
- $this->windolg = new ExtObject("FormWin",
- array(
- 'id' => $this->formName,
- 'name' => $this->formName,
- 'dataID' => $this->dataId,
- 'title' => $this->formbody->title,
- 'collapsible' => true,
- 'maximizable' => true,
- 'layout' => 'fit',
- 'plain' => true,
- 'bodyStyle' => 'padding:5px;',
- 'buttonAlign' => 'center',
- "msk" => array("new Ext.LoadMask(Ext.getBody(), {msg : 'æ£å è½½æ°æ®ï¼è¯·ç¨ç...'})"),
- "createFormPanel" => null,
- "initComponent" => null
- )
- );
- $this->initcorde = new ExtFunction(NULL, "
- this.keys={
- key: Ext.EventObject.ENTER,
- fn: this.save,
- scope: this
- };
- FormWin.superclass.initComponent.call(this);
- this.fp=this.createFormPanel();
- this.add(this.fp);
- if(!this.dataID && this.loadParam.id){
- this.dataID = this.loadParam.id
- }
- ");
- }
-
- /**
- * 设置çªä½é»è®¤çåå§å代ç
- * @param Mixed $code 代ç 串æè
ExtObject对象
- */
- public function setFormInitCode($code) {
- $this->initcorde->SetCode($code);
- }
-
- /**
- * 设置çªä½å è½½äºä»¶ 注æï¼å½$obj为空æ¶æ·»å é»è®¤çLoader å¦æè¦ä¼ 第å
¶å®åæ°ï¼å¿
é¡»
- * å
éè¿setFormLoaderParamæ¹æ³è®¾ç½®å è½½æ¶çå
¶ä»å¯¹è±¡
- * @param ExtObject $obj formçLoader对象
- */
- public function setFormLoader($obj = null) {
- $tobj = null;
- $param = null;
- if ($this->dataId) {
- $param = new ExtObject(null, array('id' => $this->dataId));
- } else {
- $param = new ExtObject(null, array('id' => array('this.dataID')));
- }
-
- if (!empty($obj) && is_object($obj)) {
- if (!isset($obj->param) || empty($obj->param)) {
- $this->setProperty("loadParam", $obj->param);
- $this->del('param');
- } else { //å¦æå è½½ç对象ä¸å«paramå并å
¥é¢å
设置çloadParam
- $this->setProperty("loadParam", $param);
- }
- $obj->param = array("this.loadParam");
- $tobj = $obj;
- } else {
- $this->setProperty("loadParam", $param);
- $tobj = new ExtObject(null, array(
- "url" => __URL__ . "/getFormWinData",
- "params" => array('this.loadParam'),
- "success" => new ExtFunction(Null, "
- this.msk.hide();
- "),
- "scope" => array('this')
- ));
- }
-
- $this->formLoad = $tobj;
- }
-
- /**
- * 设置çªä½çæ°æ®å è½½Loader对象çå±æ§
- * @param String $attrib
- * @param Mixed $value
- */
- public function setFormLoaderProperty($attrib, $value) {
- $this->formLoad->setProperty($attrib, $value);
- }
-
- /**
- * 设置é¢å¤ççªä½å 载对象çåæ°
- * @param String $param åæ°å称
- * @param Mixed $value åæ°å¼
- */
- public function setFormLoaderParam($param, $value) {
- $this->formLoadParam->setProperty($param, $value);
- }
-
- /**
- * 设置çªå£å®¹å¨çå±æ§
- * @param String $attrib
- * @param Mixed $value
- */
- public function setWindowsProperty($attrib, $value) {
- $this->windolg->setProperty($attrib, $value);
- }
-
- /**
- * 设置çªä½è¯»æ°æ®æ è¯form reader
- */
- private function setFormReader() {
- $this->formreader = new ExtObject(
- 'Ext.data.JsonReader',
- array(
- new ExtObject(
- null,
- array("root" => "data")
- ),
- $this->fieldset
- )
- );
- }
-
- private function setFormInt() {
- $twidth = 0;
- $tmpwidth = 16;
- $tmpheight = 40;
-
- //formçªä½ç读åæ°æ®çæ å¿ å段å称å表
- foreach ($this->formFields as $n => $f) {
- $this->fieldset[] = new ExtObject(null, array('name' => $n, 'mapping' => $n));
- }
- //并ä¸è®¡ç®çªä½çé«åº¦
- if (empty($this->windolg->height)) {
- foreach ($this->formFields as $n => $f) {
- if (isset($f->height) && $f->height > 0) {
- $tmpheight += $f->height;
- } else {
- $tmpheight += 32;
- }
- if (isset($f->width) && $f->width > $tmpwidth) {
- $twidth = $f->width;
- }
- }
- } else {
- $tmpheight = $this->windolg->height;
- $twidth = $this->windolg->width;
- }
- if (empty($tmpheight)) {
- $tmpheight = 200;
- } elseif ($tmpheight > 750) {
- $tmpheight = 750;
- }
- if (empty($twidth)) {
- $tmpwidth += $twidth;
- }
- if (empty($tmpwidth) || $tmpwidth == 16) {
- $tmpwidth = 340;
- }
- $this->windolg->setProperty("width", $tmpwidth);
- $this->windolg->setProperty("height", $tmpheight);
- $this->windolg->setProperty("minWidth", $tmpwidth);
- $this->windolg->setProperty("minHeight", $tmpheight);
- }
-
- /**
- * æ·»å çªä½çé»è®¤æ·»å æé®
- * @param String $name é»è®¤ä¸ºï¼save
- * @param String $title é»è®¤ä¸ºï¼ä¿å
- * @param ExtFunction $hander é»è®¤çäºä»¶ååºå¯¹è±¡
- */
- public function addSaveButton($name = 'save', $title='ä¿å', $hander=null) {
- if (empty($hander)) {
- $hander = new ExtFunction(null, "
- if(this.fp.form.isValid()){
- var turl = '" . __URL__ . "/saveFormWinData';
- if(this.dataID){
- turl += '/id/'+ this.dataID;
- }
- var fw = this;
- this.fp.form.submit({
- waitTitle:'请ç¨å',
- waitMsg : 'æ£å¨å¤ç请æ±...',
- url : turl,
- params: this.loadParam,
- success : function(form, action){
- fw.close();
- if(form.rGrid){
- if(form.rGrid.root){
- form.rGrid.getLoader().load(form.rGrid.root);
- }else{
- form.rGrid.getLoader().load();
- }
- }
- },
- failure : function() {
- fw.close;
- Ext.Msg.alert('ç³»ç»é误','æå¡å¨åºç°é误请ç¨ååè¯ï¼');
- }
- });
- }
- ");
- }
- $this->addButton($name, $title);
- $this->setButtonAttrib($name, 'handler', $hander);
- }
-
- /**
- * æ·»å é»è®¤åæ¶æé®
- * @param String $name
- * @param String $title
- * @param ExtFunction $hander
- */
- public function addCancelButton($name = 'cancle', $title='åæ¶', $hander=null) {
- if (empty($hander)) {
- $hander = new ExtFunction(null, "
- this.close();
- ");
- }
- $this->addButton($name, $title);
- $this->setButtonAttrib($name, 'handler', $hander);
- }
-
- /**
- * æ ¹æ®model对象å称设置FormWinçæ°æ®model
- *
- * @param String $modelName model对象å称
- * @param Mixed $id è¦ç¼è¾å°è®°å½å·
- */
- public function setDataModel($modelObject, $id) {
- $this->setDataSource($modelObject, $id);
- }
-
- /**
- * æ ¹æ®model对象å称设置FormWinçæ°æ®model
- * @param String $modelName model对象å称
- */
- public function setDataModelByName($modelName) {
- if (!empty($modelName)) {
- $model = D($modelName);
- $this->setDataModel($model);
- }
- }
-
- /**
- * æ¬æ¹æ³è¿åæ¤å¯¹è±¡çJS串
- * @return String æ¬å¯¹è±¡çJS串
- */
- public function getJavascript() {
- $this->initForm();
- $this->setFormInt();
- $this->setFormReader();
- $this->setFormLoader();
- //并å
¥çªä½çæ°æ®å 载对象
- $this->setFormInitCode("
- this.fp.load(" . $this->formLoad->render() . ");
- ");
- //设置çªä½åºæ¬å±æ§
- if (empty($this->formbody->baseCls)) {
- $this->formbody->setproperty('baseCls', 'x-plain');
- }
- if (empty($this->formbody->reader)) {
- $this->formbody->setProperty("reader", $this->formreader);
- }
- $this->formbody->setProperty("items", $this->getElementArray());
- //å建çªå£
- $this->windolg->setProperty(
- "createFormPanel",
- new ExtFunction(null,
- array("return" => $this->formbody->render())
- )
- );
- //æ·»å æé®
- if (!$this->noButton) {
- if (!empty($this->formButtons) && is_array($this->formButtons)) {
- foreach ($this->formButtons as $k => $v) {
- $this->initcorde->SetCode("this.addButton('" . $v->text . "',this." . $k . ",this);");
- $this->windolg->setProperty($k, $v->handler);
- }
- } else {
- $this->initcorde->SetCode("
- this.addButton('ä¿å',this.save,this);
- this.addButton('åæ¶', function(){this.close();},this);
- ");
- }
- }
- $this->windolg->setProperty("initComponent", $this->initcorde);
- $this->windolg->setExtendsClass("Ext.Window");
- return $this->formExtendJs . $this->windolg->render();
- }
-
- }
-
- ?>
å¤å¶ä»£ç
|