extphp是一个基于thinkphp开发框架的extjs开发类库,使用此类库可以很方便的生成extjs的javascript代码。
文件路径) * @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(); }}?>
复制代码
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(); }}?>
复制代码
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; }}?>
复制代码
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); } }}
复制代码
setdataarray ( $dataarray ); if (! empty ( $dataname )) { $this->dataname = $dataname; } if (is_bool ( $isgriddata )) { $this->isgriddata = $isgriddata; } } /** * 设置extdata对象的数据集 * * @param array $dataarray */ public function setdataarray($dataarray) { if (! empty ( $dataarray ) && is_array ( $dataarray )) { $this->data = $dataarray; } } /** *获取对象的js串 * @return string */ public function getjavascript() { $str = ''; if (! empty ( $this->dataname )) { $str .= var $this->dataname = ; } if ($this->isgriddata) { $j = 0; $count = count ( $this->data ); $str .= {totalproperty:$count,root:[; foreach ( $this->data as $value ) { if($j>0) $str .= ,; $str .= [.$this->jsrender ( $value ).]; $j ++; } $str .= ]}; } else { $str .= [.$this->jsrender ( $this->data ).]; //$str .= $this->jsrender ( $this->data ); } if (! empty ( $this->dataname )) { $str .= ;; } return $str; } /** * 以js的方式输出$data的数据 * * @param array $data 要输出的数据 */ public function jsrender($data = array()) { $str = ; foreach ( $data as $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 ); $str .= ]; } } 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 (); }}?>
复制代码
$v){ if($k == 'items') continue; $this->setproperty($k,$v); } if( !empty($config['items'])){ if( is_array($config['items']) ){ foreach ($config['items'] as $v){ $this->additems($v); } }else{ $this->additems($v); } } } } /** * 根据属性值$value设置$property属性 * * @param string $property 属性名称 * @param mixed $value 属性值 */ public function setproperty($property,$value){ if(!empty($property) && !empty($value)) $this->property[$property] = $value; } /** * 添加viewport的显示对象 * * @param extobject $object */ public function additems($object){ if(!empty($object)){ $this->items[] = $object; } } /** * 初始化viewport */ private function init(){ $obj = new extobject(ext.viewport,array()); $obj->setproperties($this->property); $obj->setproperty(items,$this->items); $this->vpbody = $obj; } /** * 获取viewport的js * * @return string */ public function getjavascript(){ $this->init(); return $this->vpbody->render(vport); } /** * */ public function render(){ $js = $this->getjavascript (); $default = isset ( $_cookie ['exttheme'] ) ? $_cookie ['exttheme'] : $_session ['sys_them']; if (! empty ( $default )) $this->setextcss ( $default ); //设置extjs的显示样式 //建立extjs的页面并设置页面的基本ext执行环境 $page = new extpage ( ); $page->extbase = $this->getextbasecode (); //设置extbase $page->extjs .= ext.onready(function(){; $page->extjs .= $js; $page->extjs .= });; //$page->body =
; $page->render (); } public function show(){ $this->render(); } public function __tostring(){ return $this->getjavascript(); }}?>
复制代码
winname = $name; } if (! empty ( $config ) && is_array ( $config )) { foreach ( $config as $k => $v ) { if ($k == 'items' || $k == 'bbar' || $k == 'buttons') continue; $this->setproperty ( $k, $v ); } if (! empty ( $config ['items'] )) { if (is_array ( $config ['items'] )) { foreach ( $config ['items'] as $v ) { $this->additems ( $v ); } } else { $this->additems ( $v ); } } if (! empty ( $config ['bbar'] )) { if (is_array ( $config ['bbar'] )) { foreach ( $config ['bbar'] as $v ) { $this->addbbar ( $v ); } } else { $this->addbbar ( $v ); } } if (! empty ( $config ['buttons'] )) { if (is_array ( $config ['buttons'] )) { foreach ( $config ['buttons'] as $v ) { $this->addbbar ( $v ); } } else { $this->addbbar ( $v ); } } } } /** * 根据属性值$value设置$property属性 * * @param string $property 属性名称 * @param mixed $value 属性值 */ public function setproperty($property, $value) { if (! empty ( $property ) && ! empty ( $value )) $this->property [$property] = $value; } /** * 添加windows的显示对象 * * @param extobject $object */ public function additems($object) { if (! empty ( $object )) { $this->winitems [] = $object; } } /** * 添加windows的工具 * * @param mixed $object */ public function addbbar($object) { if (! empty ( $object )) { $this->winbbar [] = $object; } } /** * 添加windows的按钮 * * @param mixed $object */ public function addbutton($object) { if (! empty ( $object )) { $this->winbutton [] = $object; } } private function init() { $obj = new extobject ( ext.window, array () ); $obj->setproperties ( $this->property ); if (! empty ( $this->winbbar )) $obj->setproperty ( bbar, $this->winbbar ); if (! empty ( $this->winitems )) $obj->setproperty ( items, $this->winitems ); if (! empty ( $this->winbutton )) $obj->setproperty ( buttons, $this->winbutton ); $this->winbody = $obj; } /** * 获得windows对象的js * * @param string $winname */ public function getjavascript() { $this->init (); if (! empty ( $this->winname )) return $this->winbody->render ( $this->winname ) . {$this->winname}.show();; else return $this->winbody->render (); } public function render($winname = '') { $js = $this->getjavascript ( $winname ); //建立extjs的页面并设置页面的基本ext执行环境 $page = new extpage (); $page->extbase = $this->getextbasecode (); //设置extbase $page->extjs .= ext.onready(function(){; $page->extjs .= $js; $page->extjs .= });; $page->render (); } public function show($winname = 'win1') { $this->render ( $winname ); } public function __tostring() { return $this->getjavascript (); }}?>
复制代码
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(); }}?>
复制代码