Changeset 1154:e85c1417b8a4 for inc/admin
- Timestamp:
- 04/09/13 09:08:48 (12 years ago)
- Branch:
- twig
- Location:
- inc/admin
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/admin/class.dc.filter.php
r1152 r1154 20 20 protected $form_prefix; /// <b>string</b> displayed form prefix 21 21 protected $action; /// <b>string</b> form action page 22 protected $hide form; /// <b>boolean</b> start form display hidden by default or not22 protected $hide_filterset; /// <b>boolean</b> start form display hidden by default or not 23 23 protected $name; /// <b>string</b> filterset name 24 24 protected $core; … … 115 115 } 116 116 } 117 117 $this->hide_filterset = true; 118 118 if ($action !== false) { 119 119 // Use case (1) … … 126 126 $this->filters[$_POST[$fname]]->add(); 127 127 } 128 $this->hide_filterset = false; 128 129 } elseif (strpos($action,'del_') === 0) { 129 130 $count = preg_match('#del_(.+)_([0-9]+)#',$action,$match); … … 131 132 $this->filters[$match[1]]->remove($match[2]); 132 133 } 134 $this->hide_filterset = false; 133 135 } elseif ($action=="apply") { 134 136 $data = $this->saveFilters(); … … 153 155 } 154 156 } 155 $this->hideform=false;157 156 158 } else { 157 159 // Use case (2) … … 183 185 } 184 186 187 public function getURLParams() { 188 return $this->getAppliedFilters(); 189 } 190 185 191 /** 186 192 Saves user filters to preferences … … 214 220 */ 215 221 protected function setupEditFilters ($filters,$form_data) { 216 $this->hideform = true;217 222 foreach ($filters as $filter) { 218 223 $filter->setupFields ($form_data); … … 276 281 'active_filters' => $fcontext, 277 282 'static_filters' => $sfcontext, 278 'prefix'=>$this->form_prefix); 283 'hide_filters' => $this->hide_filterset, 284 'prefix' => $this->form_prefix); 279 285 } 280 286 … … 480 486 } 481 487 488 public function getFields() { 489 return $this->field; 490 } 491 482 492 } 483 493 -
inc/admin/class.dc.form.php
r1153 r1154 20 20 class dcFormNode extends Twig_Node 21 21 { 22 public function __construct($name,Twig_NodeInterface $body,$ lineno,$tag=null)23 { 24 parent::__construct(array('body' => $body),array('name' => $name ),$lineno,$tag);22 public function __construct($name,Twig_NodeInterface $body,$attr,$lineno,$tag=null) 23 { 24 parent::__construct(array('body' => $body),array('name' => $name, 'attr' => $attr),$lineno,$tag); 25 25 } 26 26 … … 36 36 $compiler 37 37 ->write("\$context['dc_form']->beginForm(") 38 ->subcompile($this->getAttribute('name')) 38 ->subcompile($this->getAttribute('name')); 39 if ($this->getAttribute('attr') !== null) { 40 $compiler 41 ->write(',') 42 ->subcompile($this->getAttribute('attr')); 43 } 44 $compiler 39 45 ->write(");\n"); 40 46 $compiler … … 56 62 $stream = $this->parser->getStream(); 57 63 $name = $this->parser->getExpressionParser()->parseExpression(); 64 $attr = null; 65 if ($stream->test(Twig_Token::NAME_TYPE, 'with')) { 66 $stream->next(); 67 $attr = $this->parser->getExpressionParser()->parseExpression(); 68 } 58 69 $stream->expect(Twig_Token::BLOCK_END_TYPE); 59 70 $body = $this->parser->subparse(array($this,'decideBlockEnd'),true); 60 71 $stream->expect(Twig_Token::BLOCK_END_TYPE); 61 72 62 return new dcFormNode($name,$body,$ token->getLine(),$this->getTag());73 return new dcFormNode($name,$body,$attr,$token->getLine(),$this->getTag()); 63 74 } 64 75 … … 219 230 } 220 231 221 public function beginForm($name )232 public function beginForm($name,$attr=array()) 222 233 { 223 234 if (isset($this->forms[$name])) { 224 235 $this->currentForm = $this->forms[$name]; 225 $this->currentForm->begin( );236 $this->currentForm->begin($attr); 226 237 } 227 238 else { … … 381 392 } 382 393 } 383 public function begin() 384 { 385 echo sprintf( 386 '<form%s method="%s" action="%s">', 387 empty($this->id) ? '' : ' id="'.$this->id.'"', 388 $this->method, 389 $this->action 390 ); 394 public function begin($attr=array()) 395 { 396 $attr['method'] = $this->method; 397 $attr['action'] = $this->action; 398 if (!empty($this->id)) { 399 $attr['id'] = $this->id; 400 } 401 $this->core->tpl->getExtension('dc_form')->renderWidget( 402 'beginform', 403 $attr); 391 404 } 392 405 -
inc/admin/class.dc.list.php
r1152 r1154 16 16 protected $entries; 17 17 protected $filterset; 18 protected $fetcher; 18 19 protected $selection; 20 protected $current_page; 21 protected $nb_items; 22 protected $nb_items_per_page; 19 23 20 24 … … 46 50 @param form_prefix <b>string</b> form prefix to use for parameters 47 51 */ 48 public function __construct($core,$name,$ action,$form_prefix="f_") {52 public function __construct($core,$name,$filterset,$fetcher,$action,$form_prefix="f_") { 49 53 parent::__construct($core,$name,$action,'POST'); 50 54 $this->entries = array(); … … 52 56 $this->selection = new dcFieldCheckbox('entries',NULL,array('multiple' => true)); 53 57 $this->addField($this->selection); 58 $this->filterset = $filterset; 59 $this->fetcher = $fetcher; 54 60 } 55 61 56 62 public function setup() { 57 parent::setup();58 63 $this 59 64 ->addField(new dcFieldCombo('action',$this->actions_combo, '', array( 60 65 'label' => __('Selected entries action:')))) 61 ->addField(new dcFieldSubmit('ok',__('ok'), array())); 66 ->addField(new dcFieldSubmit('ok',__('ok'), array())) 67 ->addField(new dcFieldHidden('page','1')); 62 68 $columns_combo = array(); 63 69 foreach ($this->columns as $c) { … … 73 79 __('Order'), 74 80 __('Order'), 'orderby', $order_combo,array('singleval'=> true, 'static' => true))); 75 $ this->filterset->addFilter(new dcFilterText(81 $limit = new dcFilterText( 76 82 'limit', 77 __('Limit'), __('Limit'), 'limit',array('singleval'=> true,'static' =>true))); 83 __('Limit'), __('Limit'), 'limit',array('singleval'=> true,'static' =>true)); 84 $this->filterset->addFilter($limit); 85 $this->filterset->setup(); 86 parent::setup(); 87 $this->nb_items_per_page = $limit->getFields()->getValue(); 88 $this->fetchEntries(); 89 90 } 91 92 protected function fetchEntries() { 93 $params = new ArrayObject(); 94 $offset = $this->nb_items_per_page*($this->page->getValue()-1); 95 $this->filterset->applyFilters($params); 96 $this->nb_items = $this->fetcher->getEntriesCount($params); 97 $entries = $this->fetcher->getEntries($params,$offset,$this->nb_items_per_page); 98 $this->setEntries($entries); 99 /*echo "LIMIT:".$this->nb_items_per_page; 100 echo 'count :'.print_r($this->nb_items,true); 101 echo 'page'.$this->page;*/ 78 102 } 79 103 … … 104 128 public function setFilterSet($fs) { 105 129 $this->filterset = $fs; 106 }107 108 }109 110 class dcFilterCheckbox extends dcFilter {111 112 public function __construct($id,$name,$desc) {113 parent::__construct($id,$name,$desc,$request_param);114 }115 116 117 118 public function appendSingleLine($line,$pos) {119 $f = $this->fields[$pos];120 $line['ffield'] = $f->getName();121 if ($this->static) {122 $line['display_inline'] = true;123 }124 125 if ($pos == 0) {126 $line['fwidget']='filter_checkbox';127 $line['desc']=$this->desc;128 };129 }130 131 public function addValue($value=NULL) {132 if (count($this->fields)>0)133 return;134 if ($value === NULL) {135 $value = 1;136 }137 $f = new dcFieldCheckbox(138 $this->getFieldID($pos),139 $value,140 array());141 $this->filterset->addField($f);142 $this->fields[]=$f;143 }144 145 public function applyFilter($params) {146 130 } 147 131 … … 186 170 } 187 171 172 abstract class dcListFetcher { 173 protected $core; 174 public function __construct($core) { 175 $this->core = $core; 176 } 177 178 abstract function getEntries($params,$offset,$limit); 179 abstract function getEntriesCount($params); 180 } 188 181 189 182 dcItemList::__init__($GLOBALS['core']->tpl); -
inc/admin/default-templates/forms/form_layout.html.twig
r1153 r1154 126 126 {% endblock endlabel %} 127 127 128 {%- block beginform -%} 129 <form {% if class is not empty -%} class="{{class|join(' ')}}" {%- endif %} {% if id is not empty -%} id="{{id}}" {%- endif %} 130 method="{{method}}" action="{{action}}"> 131 {%- endblock beginform -%} 132 133 {% block endform -%} 134 </form> 135 {%- endblock endform %} -
inc/admin/default-templates/forms/formfilter_layout.html.twig
r1152 r1154 2 2 3 3 4 {% block filterset %}4 {% block filterset -%} 5 5 <p> 6 6 <a href="#" id="toggle-filters">{{ __('Toggle filters and display options') }} </a> 7 7 </p> 8 8 <div class="two-cols"> 9 {% form filtersetname%}10 {% set fenv = _context['filterset_' ~ filtersetname]%}9 {% set fenv = _context['filterset_' ~ filtersetname] %} 10 {% form filtersetname with {'class':fenv.hide_filters?'hidden':'opened' } -%} 11 11 <div class="col70"> 12 12 <h3>{{__('Entries filters')}}</h3> 13 13 <table summary="{{__('Query filters')}}" id="tfilters"> 14 14 <tbody> 15 {% for f in fenv.active_filters%}15 {%- for f in fenv.active_filters -%} 16 16 <tr class="{{f.id}}"> 17 17 <td>{{form_field(f.del_id)}}</td> 18 18 {{block(f.fwidget)}} 19 19 </tr> 20 {% endfor%}20 {%- endfor -%} 21 21 </tbody> 22 22 </table> … … 31 31 </div> 32 32 <div class="col30"> 33 {% for f in fenv.static_filters%}33 {%- for f in fenv.static_filters -%} 34 34 {{block(f.fwidget)}} 35 {% endfor%}35 {%- endfor -%} 36 36 </div> 37 37 <p class="clear margintop"></p> 38 {% endform%}38 {%- endform -%} 39 39 </div> 40 {% endblock %}40 {%- endblock %} 41 41 42 42 43 {% block filterenabled %}43 {% block filterenabled -%} 44 44 <tr class="{{ id }}">'; 45 45 <td> … … 49 49 {{ block(filter) }} 50 50 </tr> 51 {% endblock %}51 {%- endblock %} 52 52 53 53 54 {% block filter_combo %}54 {% block filter_combo -%} 55 55 {% if f.display_inline is defined -%} 56 56 <p id='{{f.filter_id}}'>{{form_field(f.ffield,{},{'label':f.desc,'nestedlabel': true, 'labelclass':'classic' })}}</p> … … 59 59 <td >{{ form_field(f.ffield) }}</td> 60 60 {%- endif %} 61 {% endblock %}61 {%- endblock %} 62 62 63 {% block filter_combo_cont %}63 {% block filter_combo_cont -%} 64 64 {% if f.display_inline is defined -%} 65 65 <p id='{{filter_id}}'>{{form_field(f.ffield,{'label':__('or :')})}}</p> … … 67 67 <td id='{{filter_id}}' colspan="2">{{ __('or :') }} </td><td>{{ form_field(f.ffield) }}</td> 68 68 {%- endif %} 69 {% endblock %}69 {%- endblock %} 70 70 71 71 72 {% block filter_richcombo %}72 {% block filter_richcombo -%} 73 73 <td id='{{filterd_id}}' title='{{f.desc}}' class="filter-title">{{f.desc}} : </td> 74 74 <td>{{ form_field(f.fverb)}}</td> 75 75 <td>{{ form_field(f.ffield) }}</td> 76 {% endblock %}76 {%- endblock %} 77 77 78 78 79 {% block filter_boolean %}79 {% block filter_boolean -%} 80 80 <td id='{{filterd_id}}' title='{{f.desc}}' class="filter-title" colspan="2">{{f.desc}}</td> 81 81 <td>{{ form_field(f.ffield) }}</td> 82 {% endblock %}82 {%- endblock %} 83 83 84 {% block filter_text %}84 {% block filter_text -%} 85 85 {% if f.display_inline is defined -%} 86 86 <p id='{{filter_id}}'>{{form_field(f.ffield,{},{'label':f.desc,'nestedlabel': true, 'labelclass':'classic' })}}</p> … … 88 88 <td id='{{filterd_id}}' title='{{f.desc}}' class="filter-title" colspan="2">{{f.desc}}</td> 89 89 <td>{{ form_field(f.ffield) }}</td> 90 {% endif %}91 {% endblock %}90 {%- endif %} 91 {%- endblock %} 92 92 93 93 -
inc/admin/default-templates/forms/lists_layout.html.twig
r1152 r1154 2 2 {% set lenv = _context['list_' ~ listname] %} 3 3 {% if lenv.entries %} 4 <p>Pages:</p> 4 5 {% form listname -%} 5 6 {% spaceless %}
Note: See TracChangeset
for help on using the changeset viewer.