/source/includes/classes/render.php

http://prosporous.googlecode.com/ · PHP · 241 lines · 232 code · 3 blank · 6 comment · 5 complexity · ba42c2811472166f85d5c1994f6111b1 MD5 · raw file

  1. <?php
  2. /**
  3. * Created on 2010-4-30
  4. *
  5. * @author Niap <zpr9527@163.com>
  6. *
  7. */
  8. class render{
  9. private $name;
  10. private $fieldLabel;
  11. private $type;
  12. private $config;
  13. private $back = "";
  14. private $disable = false;
  15. function set_name($name){
  16. $this->name = $name;
  17. }
  18. function set_fieldLabel($fieldLabel){
  19. $this->fieldLabel = $fieldLabel;
  20. }
  21. function set_type($type){
  22. $this->type = $type;
  23. }
  24. function set_config($config){
  25. $this->config = $config;
  26. }
  27. function get_js(){
  28. $config = json_decode($this->config,true);
  29. $this->config = $this->config?"disabled:'true',":"";
  30. switch($this->type){
  31. case 'datefield':
  32. $js ="{
  33. ".$this->disable."
  34. xtype: 'datefield',
  35. fieldLabel: '{$this->fieldLabel}',
  36. name: '{$this->name}',
  37. format:'{$config['format']}',
  38. ".$this->back."
  39. anchor:'30%'
  40. }";
  41. break;
  42. case 'textarea':
  43. $js ="{
  44. ".$this->disable."
  45. xtype: 'textarea',
  46. fieldLabel: '{$this->fieldLabel}',
  47. name: '{$this->name}',
  48. anchor:'98%',
  49. ".$this->back."
  50. height:{$config['height']}
  51. }";
  52. break;
  53. case 'htmleditor':
  54. $js="{
  55. ".$this->disable."
  56. xtype:'htmleditor',
  57. name:'{$this->name}',
  58. fieldLabel:'{$this->fieldLabel}',
  59. height:{$config['height']},
  60. ".$this->back."
  61. anchor:'98%'
  62. }";
  63. break;
  64. case 'fckeditor':
  65. $js="{
  66. ".$this->disable."
  67. xtype:'textarea',
  68. name:'{$this->name}',
  69. value:'',
  70. anchor:'98%',
  71. height:100,
  72. fieldLabel:'{$this->fieldLabel}',
  73. ".$this->back."
  74. listeners:{
  75. focus:function(f){
  76. var myMask = new Ext.LoadMask(Ext.getBody(), {msg:'???'});
  77. myMask.show();
  78. var w=f.getSize();
  79. fckEditor = new FCKeditor('{$this->name}') ;
  80. fckEditor.Height='{$config['height']}';
  81. fckEditor.Width=w.width;
  82. fckEditor.BasePath = '/plug-in/fck/' ;
  83. fckEditor.ReplaceTextarea() ;
  84. myMask.hide();
  85. }
  86. }}
  87. ";
  88. break;
  89. case 'swfupload':
  90. $js ="{
  91. ".$this->disable."
  92. xtype: 'fileuploadfield',
  93. fieldLabel: '{$this->fieldLabel}',
  94. ".$this->back."
  95. anchor:'50%',
  96. name: '{$this->name}',
  97. buttonCfg: {
  98. text: '',
  99. iconCls: 'upload-icon'
  100. }
  101. }
  102. ";
  103. break;
  104. case 'combo':
  105. $js ="{
  106. ".$this->disable."
  107. typeAhead: true,
  108. name : '{$this->name}_',
  109. hiddenName : '{$this->name}',
  110. xtype: 'combo',
  111. anchor:'30%',
  112. fieldLabel : '{$this->fieldLabel}',
  113. store:new Ext.data.SimpleStore({
  114. fields:['name','value'],
  115. data:[{$config['pair']}]}),
  116. mode:'local',
  117. displayField:'name',
  118. ".$this->back."
  119. selectOnFocus:true,
  120. valueField :'value',
  121. triggerAction:'all'
  122. }
  123. ";
  124. break;
  125. case 'radiogroup':
  126. $config_num = count($config);
  127. $items = '';
  128. foreach($config as $id => $data){
  129. if($data['checked']=='1'){
  130. $checked = ", checked: true";
  131. }else
  132. $checked = "";
  133. $items.= "{boxLabel: '{$data['name']}', name: '{$this->name}', inputValue: {$data['value']}{$checked}}";
  134. if($id < $config_num-1){
  135. $items.= ",";
  136. }
  137. }
  138. $js ="{
  139. ".$this->disable."
  140. xtype: 'radiogroup',
  141. fieldLabel: '{$this->fieldLabel}',
  142. ".$this->back."
  143. columns: 5,
  144. anchor:'50%',
  145. items: [
  146. {$items}
  147. ]
  148. }
  149. ";
  150. break;
  151. case 'checkboxgroup':
  152. $config_num = count($config);
  153. $items = '';
  154. foreach($config as $id => $data){
  155. if($data['checked']=='1'){
  156. $checked = ", checked: true";
  157. }else
  158. $checked = "";
  159. $items.= "{boxLabel: '{$data['name']}', name: '{$data['value']}'{$checked}}";
  160. if($id < $config_num-1){
  161. $items.= ",";
  162. }
  163. }
  164. $js ="{
  165. ".$this->disable."
  166. xtype: 'checkboxgroup',
  167. fieldLabel: '{$this->fieldLabel}',
  168. ".$this->back."
  169. columns: 5,
  170. anchor:'50%',
  171. items: [
  172. {$items}
  173. ]
  174. }
  175. ";
  176. break;
  177. case 'password':
  178. $js ="{
  179. ".$this->disable."
  180. xtype: 'textfield',
  181. inputType: 'password',
  182. fieldLabel: '{$this->fieldLabel}',
  183. ".$this->back."
  184. name: '{$this->name}'
  185. }";
  186. if($config['confirm']){
  187. $js .=',';
  188. $js .="{
  189. ".$this->disable."
  190. fieldLabel: '??{$this->fieldLabel}',
  191. name: '{$this->name}-cfrm',
  192. xtype: 'textfield',
  193. inputType: 'password',
  194. vtype: 'password',
  195. ".$this->back."
  196. initialPassField: '{$this->name}'
  197. }";
  198. }
  199. break;
  200. default:
  201. $js="{
  202. disabled:'true',
  203. xtype: '{$this->type}',
  204. fieldLabel: '{$this->fieldLabel}',
  205. name: '{$this->name}',
  206. ".$this->back."
  207. anchor:'60%'
  208. }";
  209. }
  210. return $js;
  211. }
  212. function get_plugjs(){
  213. switch($this->type){
  214. case 'datefield':
  215. $plugjs ='Date.dayNames = ["?", "?", "?", "?", "?", "?", "?"];
  216. if (Ext.DatePicker) {
  217. Ext.apply(Ext.DatePicker.prototype, {
  218. todayText: "??",
  219. minText: "?????????",
  220. maxText: "?????????",
  221. disabledDaysText: "",
  222. disabledDatesText: "",
  223. monthNames: Date.monthNames,
  224. dayNames: Date.dayNames,
  225. nextText: "?? (Control+Right)",
  226. prevText: "?? (Control+Left)",
  227. monthYearText: "????? (Control+Up/Down ????)",
  228. todayTip: "{0} (Spacebar)",
  229. okText: "??",
  230. cancelText: "??",
  231. format: "y?m?d?"
  232. });
  233. }';
  234. break;
  235. }
  236. }
  237. }
  238. ?>