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 $demode = falsebug
* ExtJS的核心模式,預設為false
* @var Boolean
*/
public $demode = falsebug
* ExtJS的環境目錄的基準目錄
* @var String
*/
public $demode = falsebug
* ExtJS的基本程式碼
* @var String
*/
public $demode = falsebug
* 頁面所需的Css檔
* @var Array
*/
public $demode = false 是> /**
* 頁面所需的Js檔
* @var Array
*/
public $coremode = false;
/**
* ExtJs的css檔
* @var String
*/
public $extbasedir = "";
/**
* ExtJS目錄下的所有檔案索引 格式為:array(檔案名稱=>檔案路徑)
* @var Array
* /
public $extbasecode = "";
/**
* 定義ExtJS的基本運作檔案格式為:array(name=>檔案名稱),這裡只是定義了基本的幾個
* 如:base,all,css,core,debug
* @ var Array
*/
public $pageCss = array();
/**
* 依照基本參數設定Extjs的基本環境
*
* @param string $exthome ExtJS所在目錄,相對於$basedir所指定的目錄
* @param boolen $extdebue 是否開啟調試模式
* @param boolen $extcore 是否是core模式
* @param string $extlang 設定ExtJS語言
* @param string $basedir $exthome目錄所在的目錄
*/
public $pageJs = array();
/**
* 設定Extjs的基本目錄
*
* @param String $exthome ExtJs檔案所在的目錄
* @param String $basedir 所在目錄是基於該目錄預設為'/'
* @return Boolean
*/
private $extcss = "";
/***/
public $ExtALLFiels = 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',
);
/***/
public function __construct($exthome = '', $basedir='', $extdebue=false, $extcore=false, $extcn='zh_' ) {
//設定基本運作環境
$this->setExtBase($exthome, $basedir, $extdebue, $extcore, $extlang);
}
/*** /
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
*/
公用函數 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 .= " n";
} else {
$tmpstr .= " n";
}
//設定其他css
if (!empty($this->pageCss)) {
foreach ($ this->pageCss as $f) {
if (is_array($ f)) {
$tmpstr .= "
複製程式碼
/**
* 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 參數 可以是陣列
*/
公用函數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的其它物件
*/
公用函數SetCode ($code) {
if (!empty($this->code) && is_object($this->code) && method_exists($this->code, 'render')) {
$this->程式碼= $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 = 函數";
} else {
$str .= "函數";
}
if (!empty($clsname))
$this->clsname = $clsname;
if (!empty($this->clsname)) {
$str . = " " 。 $這個->參數)。 " )";
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', // 刪除註解
'/[fnrt] */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 { 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 this this ->extClass = $ExtClass;
if (is_array($properties)) {
$this->state = $properties;
}
$this->showkeys = $showkeys ;
}
$this->showkeys = $showkeys ;
$this->rendername = $name;
}
/**
* 設定物件的屬性 即 $key = $val;
*
* @param String $key 屬性名稱 必須符合ExtJS個物件的規定
* @param Anly_type $val
*/
public function __set($key, $val) {
if ($key == '縮排') {
$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, $屬性) {
if (!empty($name)) {
$this->state [$name] = $property;
}
}
/**
* 依照組態陣列$properties設定ExtClass屬性
*
* @param ConfigArray $properties 設定陣列
*/
public function setProperties($properties) {
$this->state = array_merge($this->state, $properties );
}
public fClasstion set. ( $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 。 else {
if (!is_numeric($element))
$str .= self::$indent 。 "$element: ";
}
}
if (is_string($valueue )) {
$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('/.提示/', $this- >extClass)
|| preg_match('/.show/', $this->extClass) || preg_match('/.confirm/', $this->extClass)
|| preg_match('/.進度/', $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:: $縮排。 "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:'" . },";
$str .= "[ " . $this->JSRender($this ->state['fields'], TRUE) . "]";
} else {
$str .= $this->JSRender($this->state , TRUE);
}
$str .= ")";
if ($this->rendername) {
$str . = ";";
}
} elseif ($this->rendername) ;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 。
}
} 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 * @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}
{extjs}
{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;
中斷;
case '字元集':
$this->body = $val;
中斷;
case '模板':
$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 this) {
case 'extjs':
return $this 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") ;
}
}
}
複製程式碼
/**
* +--------------------------------------------- ----------- --------------------------
* | PHPExtJs
* +-- -------------------------------------------------- ---- --------------------------
* | @License: ( http://www.apache.org/licenses /LICENSE-2.0 )
* +------------------------ ---------------- ------------------------------------------
* | @作者: wb * +------------------------------------- ----------- --------------------------------------- -----------
*/
class ExtData 擴充 ExtBase {
public $Data = array () > public; $DataName = '';
public $isGridData = false
$this->setDataArray( $DataArray ); is_bool ( $isGridData )) {
$this->isGridData = $isGridData;
}
}
/**
* 新建ExtJs的資料集,如果是表格資料在自動格式化為表格的Json的資料格式
*
* @param Array $DataArray 資料集
* @param String $DataName 資料集名稱
* @param Blooen $isGridData 是否是表格資料
*/
public function setDataArray($DataArray) {
if (!empty ( $DataArray ) && is_array ( $DataArray )) {
$ this ->Data = $DataArray; public function getJavascript() {
$str='';
if(!empty($this->DataName)){
$str.="var$this - >DataName=";
}
if ($this->isGridData) {
$j = 0;
$count = count($this->Data); $count,root: [ ";
foreach($this->Data as $value) {
if($j>0) $str.=","; ".$this->JSRender($value)."] " ;
$j++;
}
$str.="]}";
} else {
$ str .= "[".$this->JSRender($this- > Data)."]";
//$str .= $this->;JSRender($this->Data);
}
if ( ! 空( $this - > DataName )) {
$str . = " ; " ;
}
return $str ; public function JSRender($Data = Array()) {
$str = "";
for數據資料為$element => $value ) {
if(!empty($str) ) $str .= ",";
/*if (!is_numeric($element)) {
$str . = "'$element':";
}*/
if ( is_string ( $value )) {
$str .= "'$value'"
} else if ( is_bool ( $ value )) {
$str .= ($value ) ? "true" : "false";
} else if (is_array($value)) {
if(count($value) == 1 && is_string($value[0])) {
$ str .= $value[0];
} else {
$str.="[";
$str.=$this->JSRender($value, false) .= "]"; ;
}
} else {
if(empty($value)){
$str .= "''";
}else{
$ str .= $value ;
}
}
}
return $str ;
}
public function render() {
return $this-> getJavascript ();}
public function show() {
echo $this->getJavascript();
}
public function __toString() {
return $this->getJavascript( ) ;
}
}
?
vendor("com.qldx.ext.*");
class FormWin 擴充 Form {
class FormWin 擴充 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,
'標題' =>; $this->formbody->title,
'可折疊' =>; true,
'可最大化' =>正確,
'佈局' => '適合',
'普通'=> true,
'bodyStyle ' =>; '填滿:5px;',
'按鈕對齊' =>; '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 .save, 範圍: 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) -> 參數)| |空($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",
"url" => __URL__ . "/getFormWinData",
"params" => array('this.loadParam'),
"success" => new ExtFunction(Null, "
this.msk.hide();
"),
"範圍" => 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 Ext,
null,
array("root" =>; "data")
),
$this->fieldset
)
);
}
函數setFormInt() {
$twidth = 0 ;
$tmpwidth = 16;
$tmpheight = 40;
// 表單名稱的讀取資料的標記欄位清單
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->;寬度;
}
}
} else {
$tmpheight = $this->windolg->height;
$twidth = $this->windolg->width;
}
if (empty($tmpheight)) {
$tmpheight = 200;
} elseif ($tmpheight > )第750章) || $tmpwidth == 16) {
$tmpwidth = 340;
}
$this->windolg->setProperty("width", $tmpwidth);
$this->windolg->setProperty ("height", $tmpeight);
$this->windolg->setProperty("minWidth", $tmpwidth);
$this->windolg-> setProperty("minHeight", $tmpeight);
}
/**
* 新增窗體的預設新增按鈕
* @param String $name 預設為:save
* @param String $title 預設為:儲存
* @param ExtFunction $hander 預設的事件回應對象
*/
public function addSaveButton($name = '儲存', $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->setFormIntInt ();
$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();
}
}
?>
複製程式碼