Changeset 1053:96e69ef76fc9 for inc
- Timestamp:
- 12/03/12 14:29:47 (13 years ago)
- Branch:
- twig
- Location:
- inc/admin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/admin/class.dc.admincontext.php
r1014 r1053 6 6 protected $js_var; 7 7 protected $head; 8 protected $globals; 8 9 9 10 protected $core; … … 16 17 $this->jsCommon(); 17 18 $this->blogs = array(); 19 $this->globals = array(); 18 20 if ($this->core->auth->blog_count > 1 && $this->core->auth->blog_count < 20) { 19 21 $rs_blogs = $core->getBlogs(array('order'=>'LOWER(blog_name)','limit'=>20)); … … 110 112 } 111 113 public function getGlobals() { 112 return array();114 return $this->globals; 113 115 } 114 116 public function getName() { 115 117 return 'AdminPage'; 116 118 } 119 120 public function setMessage($message) { 121 $this->globals['page_message'] = $message; 122 return $this; 123 } 124 125 public function addError($error) { 126 if (!isset($this->globals['page_errors'])) 127 $this->globals['page_errors']=array(); 128 $this->globals['page_errors'][] = $error; 129 return $this; 130 } 131 117 132 public function getFilters() 118 133 { -
inc/admin/class.dc.form.php
r1014 r1053 20 20 $this->getAttribute('name')."');\n") 21 21 ->subcompile($this->getNode('body')) 22 ->write("\$context['dc_form']->renderHiddenWidgets();\n") 22 23 ->write("\$context['dc_form']->endForm();\n") 23 24 ; … … 101 102 public function renderWidget($name,$attributes=array()) { 102 103 $field = $this->currentForm->$name; 103 if ($field) 104 echo $this->template->renderBlock( 105 $field->getWidgetBlock(), 106 array_merge($field->getAttributes(),array('attr'=>$attributes)), 107 $this->blocks); 108 104 if ($field) { 105 echo $this->template->renderBlock( 106 $field->getWidgetBlock(), 107 array_merge($field->getAttributes(),array('attr'=>$attributes)), 108 $this->blocks); 109 } 110 } 111 112 public function renderHiddenWidgets() { 113 foreach ($this->currentForm->getHiddenFields() as $h) { 114 $this->renderWidget($h->getName()); 115 } 109 116 } 110 117 … … 132 139 } 133 140 141 class InvalidFieldException extends Exception { 142 } 143 134 144 135 145 class dcForm { … … 138 148 protected $action; 139 149 protected $fields; 140 150 protected $method; 151 protected $submitfields; 152 protected $hiddenfields; 153 protected $errors; 154 155 private function addNonce() { 156 $this->addField(new dcFieldHidden(array('xd_check'), $this->core->getNonce())); 157 } 158 141 159 public function __construct($core,$name,$action, $method='POST') { 142 160 $this->core = $core; … … 146 164 $this->fields = array(); 147 165 $this->core->page->getExtension('dc_form')->addForm($this); 166 $this->submitfields = array(); 167 $this->hiddenfields = array(); 168 $this->errors = array(); 169 if ($method == 'POST') { 170 $this->addNonce(); 171 } 148 172 } 149 173 … … 152 176 } 153 177 178 public function getErrors() { 179 return $this->errors; 180 } 181 154 182 public function addField(dcField $f) { 183 184 if ($f instanceof dcFieldAction) { 185 $this->submitfields[$f->getName()]=$f; 186 } 187 if ($f instanceof dcFieldHidden) { 188 $this->hiddenfields[$f->getName()]=$f; 189 } 190 155 191 $this->fields[$f->getName()]=$f; 156 192 return $this; … … 184 220 } 185 221 222 public function isSubmitted() { 223 $from = ($this->method == 'POST')?$_POST:$_GET; 224 echo "form fields :\n"; 225 } 226 227 public function setup() { 228 $from = ($this->method=='POST')?$_POST:$_GET; 229 foreach ($this->fields as $f) { 230 $f->setup($from); 231 } 232 foreach ($this->submitfields as $f) { 233 if ($f->isDefined()) { 234 $ret = call_user_func ($f->getAction(),$this); 235 return; 236 } 237 } 238 } 239 240 public function check() { 241 foreach ($this->fields as $f) { 242 try { 243 $f->check(); 244 } catch (InvalidFieldException $e) { 245 $this->errors[]=$e->getMessage(); 246 } 247 } 248 } 249 250 public function getHiddenFields() { 251 return $this->hiddenfields; 252 } 253 186 254 } 187 255 … … 191 259 protected $value; 192 260 protected $id; 261 protected $defined; 193 262 194 263 protected function getNID($nid) { … … 208 277 $this->attributes['id'] = $this->id; 209 278 $this->attributes['value'] = $this->value; 279 $this->defined = false; 210 280 211 281 } … … 227 297 228 298 public function check() { 229 230 } 299 if (!$this->defined && $this->attributes['defined']) { 300 throw new InvalidFieldException(sprintf('Field "%s" is mandatory'),$this->attributes['label']); 301 } 302 303 } 304 305 public function setup($from) { 306 if (isset($from[$this->id])) { 307 $this->value = $from[$this->id]; 308 $this->defined = true; 309 } 310 } 311 312 public function isDefined() { 313 return $this->defined; 314 } 315 231 316 } 232 317 … … 264 349 } 265 350 266 class dcFieldSubmit extends dcField { 351 abstract class dcFieldAction extends dcField { 352 protected $action; 353 public function __construct($name, $value, $attributes = array()) { 354 parent::__construct($name, $value, $attributes); 355 if (isset($attributes['action'])) { 356 $this->action = $attributes['action']; 357 } 358 } 359 public function getAction() { 360 return $this->action; 361 } 362 } 363 364 class dcFieldSubmit extends dcFieldAction { 267 365 268 366 public function getWidgetBlock() { -
inc/admin/default-templates/layout.html.twig
r993 r1053 40 40 {% block content %} 41 41 <h2>Mon premier blog › <span class="page-title"></span></h2> 42 {% endblock %} 42 {% if page_message is not empty %} 43 <p class="message">{{page_message}}</p> 44 {% endif %} 45 {% if page_errors is not empty %} 46 <div class="error"> 47 <p><strong>Errors :</strong></p> 48 <ul> 49 {% for error in page_errors %} 50 <li>{{error}}</li> 51 {% endfor %} 52 </ul> 53 </div> 54 {% endif %} 55 {% endblock %} 56 43 57 </div> 44 58 </div>
Note: See TracChangeset
for help on using the changeset viewer.