PageRenderTime 21ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 64				break;
 65				case 'fckeditor':
 66					$js="{
 67						".$this->disable."
 68						xtype:'textarea',
 69						name:'{$this->name}',
 70						value:'',
 71						anchor:'98%',
 72						height:100,
 73						fieldLabel:'{$this->fieldLabel}',
 74						".$this->back."
 75						listeners:{
 76						     focus:function(f){
 77						     		var myMask = new Ext.LoadMask(Ext.getBody(), {msg:'???'});
 78									myMask.show();
 79									var w=f.getSize();
 80						            fckEditor = new FCKeditor('{$this->name}') ;
 81						            fckEditor.Height='{$config['height']}';
 82						            fckEditor.Width=w.width;
 83						            fckEditor.BasePath = '/plug-in/fck/' ;
 84						            fckEditor.ReplaceTextarea() ;
 85						            myMask.hide();
 86						                     }
 87						 }}
 88				";
 89				break;
 90				case 'swfupload':
 91					$js ="{
 92							".$this->disable."
 93					            xtype: 'fileuploadfield',
 94					            fieldLabel: '{$this->fieldLabel}',
 95					            ".$this->back."
 96					            anchor:'50%',
 97					            name: '{$this->name}',
 98					            buttonCfg: {
 99					                text: '',
100					                iconCls: 'upload-icon'
101					            }
102					        }
103					";
104				break;
105				case 'combo':
106					$js ="{
107							".$this->disable."
108							typeAhead: true,
109							name : '{$this->name}_',
110							hiddenName : '{$this->name}',
111							xtype: 'combo',
112							anchor:'30%',
113							fieldLabel : '{$this->fieldLabel}',
114							store:new Ext.data.SimpleStore({
115											fields:['name','value'],
116											data:[{$config['pair']}]}),
117							mode:'local',
118					        displayField:'name',
119					        ".$this->back."
120					        selectOnFocus:true,
121					        valueField :'value',
122					        triggerAction:'all'
123							}
124					";
125				break;
126				case 'radiogroup':
127					$config_num = count($config);
128					$items = '';
129					foreach($config as $id => $data){
130						if($data['checked']=='1'){
131							$checked = ", checked: true";
132						}else
133							$checked = "";
134
135						$items.= "{boxLabel: '{$data['name']}', name: '{$this->name}', inputValue: {$data['value']}{$checked}}";
136						if($id < $config_num-1){
137							$items.= ",";
138						}
139					}
140					$js ="{
141								".$this->disable."
142				                xtype: 'radiogroup',
143				                fieldLabel: '{$this->fieldLabel}',
144				                ".$this->back."
145				                columns: 5,
146				                anchor:'50%',
147				                items: [
148				                   {$items}
149				                ]
150				            }
151					";
152				break;
153				case 'checkboxgroup':
154					$config_num = count($config);
155					$items = '';
156					foreach($config as $id => $data){
157						if($data['checked']=='1'){
158							$checked = ", checked: true";
159						}else
160							$checked = "";
161						$items.= "{boxLabel: '{$data['name']}', name: '{$data['value']}'{$checked}}";
162						if($id < $config_num-1){
163							$items.= ",";
164						}
165					}
166					$js ="{
167							".$this->disable."
168				                xtype: 'checkboxgroup',
169				                fieldLabel: '{$this->fieldLabel}',
170				                ".$this->back."
171				                columns: 5,
172				                anchor:'50%',
173				                items: [
174				                   {$items}
175				                ]
176				            }
177					";
178				break;
179				case 'password':
180					$js ="{
181						".$this->disable."
182						xtype: 'textfield',
183						inputType: 'password',
184			            fieldLabel: '{$this->fieldLabel}',
185			            ".$this->back."
186			            name: '{$this->name}'
187		        	}";
188		        	if($config['confirm']){
189		        		$js .=',';
190		        		$js .="{
191		        		".$this->disable."
192				        fieldLabel: '??{$this->fieldLabel}',
193				        name: '{$this->name}-cfrm',
194				        xtype: 'textfield',
195				        inputType: 'password',
196				        vtype: 'password',
197				        ".$this->back."
198				        initialPassField: '{$this->name}'
199				      }";
200		        	}
201		        break;
202			default:
203					$js="{
204						disabled:'true',
205						xtype: '{$this->type}',
206			            fieldLabel: '{$this->fieldLabel}',
207			            name: '{$this->name}',
208			            ".$this->back."
209			            anchor:'60%'
210		        	}";
211		  }
212		  return $js;
213	}
214		function get_plugjs(){
215			switch($this->type){
216				case 'datefield':
217					$plugjs ='Date.dayNames = ["?", "?", "?", "?", "?", "?", "?"];
218						    if (Ext.DatePicker) {
219						        Ext.apply(Ext.DatePicker.prototype, {
220						            todayText: "??",
221						            minText: "?????????",
222						            maxText: "?????????",
223						            disabledDaysText: "",
224						            disabledDatesText: "",
225						            monthNames: Date.monthNames,
226						            dayNames: Date.dayNames,
227						            nextText: "?? (Control+Right)",
228						            prevText: "?? (Control+Left)",
229						            monthYearText: "????? (Control+Up/Down ????)",
230						            todayTip: "{0} (Spacebar)",
231						            okText: "??",
232						            cancelText: "??",
233						            format: "y?m?d?"
234						        });
235   					}';
236				break;
237			}
238
239		}
240 }
241?>