Dotclear

Changeset 1498:6d67bea812f3


Ignore:
Timestamp:
08/20/13 16:32:39 (12 years ago)
Author:
Dsls
Branch:
twig
Message:

formfilters improvement, added applied filters features

Files:
10 edited

Legend:

Unmodified
Added
Removed
  • admin/post.php

    r1497 r1498  
    302302           
    303303      
    304      $form_comment = new dcForm($core,'add-comment','post.php'); 
     304     $form_comment = new dcForm($core,'add-comment','comment.php'); 
    305305     $form_comment 
    306306          ->addField( 
     
    322322                    'required'     => true, 
    323323                    'label'        => __('Comment:')))) 
     324          ->addField( 
     325               new dcFieldHidden('post_id',$post_id)) 
    324326          ->addField( 
    325327               new dcFieldSubmit('add',__('Save'),array( 
  • admin/posts.php

    r1492 r1498  
    158158               'multiple' => true))) 
    159159     ->addFilter(new dcFilterRichCombo( 
    160           'category',__('Category'), __('Category'), 'cat_id', $categories_combo)) 
     160          'category',__('Category'), __('Category'), 'cat_id', $categories_combo,array( 
     161               'multiple' => true))) 
    161162     ->addFilter(new dcFilterRichCombo( 
    162163          'post_status',__('Status'), __('Status'), 'post_status', $status_combo)) 
     
    172173 
    173174$lfetcher = new PostsFetcher($core); 
    174 $lposts = new dcItemList ($core,array('lposts','form-entries'),$filterSet,$lfetcher,'posts_actions.php'); 
     175$lposts = new dcItemList ($core,array('lposts','form-entries'),$lfetcher,'posts_actions.php'); 
     176$lposts->setFilterSet($filterSet); 
    175177$lposts->addTemplate('posts_cols.html.twig'); 
    176178 
  • inc/admin/class.dc.filter.php

    r1491 r1498  
    382382          $fcontext = new ArrayObject(); 
    383383          $sfcontext = new ArrayObject(); 
     384          $afcontext = new ArrayObject(); 
    384385          foreach ($this->filters as $f) { 
    385386               if($f->isEnabled()) { 
     
    390391               $f->appendFilterContext($sfcontext); 
    391392          } 
     393          foreach ($this->filters as $f) { 
     394               if ($f->isApplied()) { 
     395                    $afcontext[] = $f->getAppliedFilterText(); 
     396               } 
     397          } 
    392398          return array( 
    393399               'active_filters' => $fcontext, 
    394400               'static_filters' => $sfcontext, 
     401               'applied_filters' => $afcontext, 
    395402               'hide_filters'  => $this->hide_filterset, 
    396403               'prefix'        => $this->form_prefix); 
     
    635642 
    636643     protected abstract function addValue($value=NULL); 
    637  
     644     protected abstract function getAppliedFilterText(); 
     645      
    638646    /** 
    639647     * add -- adds a value for the filter 
     
    832840          $params[$this->request_param]=$this->avalues['values'][0]; 
    833841     } 
     842      
     843     public function getAppliedFilterText() { 
     844          if ($this->isApplied()) { 
     845               return sprintf(__('%s contains : "%s"'),$this->desc,$this->avalues['values'][0]); 
     846          } 
     847     } 
    834848} 
    835849 
     
    860874     */ 
    861875     public function init() { 
     876          echo $this->name.":".($this->multiple?"MULTIPLE":"SIMPLE"); 
    862877          $this->field = new dcFieldCombo( 
    863878               $this->filter_id, 
    864879               NULL, 
    865                $this->combo); 
     880               $this->combo,array( 
     881                    'multiple' => $this->multiple)); 
    866882          $this->filterset->addField($this->field); 
    867883     } 
     
    913929               $params[$attr]=$this->avalues['values'][0]; 
    914930     } 
    915  
     931     public function getAppliedFilterText() { 
     932          if ($this->isApplied()) { 
     933               if (count($this->avalues['values'])) { 
     934                    return sprintf(__("%s is %s"),$this->desc,join(__(' OR '), $this->avalues['values'])); 
     935               } else { 
     936                    return sprintf(__('%s is %s'),$this->desc,$this->avalues['values'][0]); 
     937               } 
     938          } 
     939     } 
    916940} 
    917941 
     
    10011025          } 
    10021026     } 
     1027     public function getAppliedFilterText() { 
     1028          if ($this->isApplied()) { 
     1029               if ($this->avalues['verb'] == "is") { 
     1030                    $txt = __("%s is %s"); 
     1031                    $or = __(' or '); 
     1032               } else { 
     1033                    $txt = __("%s is not %s"); 
     1034                    $or = __(' nor '); 
     1035               } 
     1036               $texts = array(); 
     1037               foreach ($this->avalues['values'] as $v) { 
     1038                    $texts[] = $this->field->getTextForValue($v); 
     1039               } 
     1040               if (count($texts)>=1) { 
     1041                    return sprintf($txt,$this->desc,join($or, $texts)); 
     1042               } else { 
     1043                    return sprintf($txt,$this->desc,$texts); 
     1044               } 
     1045          } 
     1046     } 
    10031047 
    10041048} 
  • inc/admin/class.dc.form.php

    r1497 r1498  
    10641064     public function getAttributes($options=array()) 
    10651065     { 
    1066           $offset = isset($options['offset']) ? $options['offset'] : 0; 
    1067  
     1066          $offset = 0; 
    10681067          $attr = $this->options->getArrayCopy(); 
     1068          if (isset($options['offset'])) { 
     1069               $offset = $options['offset']; 
     1070               unset($attr['offset']); 
     1071          } 
     1072           
    10691073          if (isset($this->values[$offset])) { 
    10701074               $attr['value'] = $this->values[$offset]; 
     
    12411245     { 
    12421246          $val = array(); 
    1243           if (!is_array($values)) { 
     1247          if (!is_array($values) && $values !== null) { 
    12441248               $values = array("1" => !empty($values)); 
    12451249          } 
    1246           $this->checked = $values; 
    1247           parent::__construct($name,array_keys($values),$options); 
     1250 
     1251          if (is_array($values)) { 
     1252               $keys = array_keys($values); 
     1253               $this->checked = $values; 
     1254          } else { 
     1255               $keys = array(); 
     1256               $this->checked = array(); 
     1257          } 
     1258           
     1259          parent::__construct($name,$keys,$options); 
    12481260     } 
    12491261 
     
    13811393     } 
    13821394 
     1395     public function getTextForValue($value) { 
     1396          if (isset($this->combo_values[$value])) { 
     1397               return $this->combo_values[$value]; 
     1398          } else { 
     1399               return false; 
     1400          } 
     1401     } 
    13831402     public function getAttributes($options=array()) { 
    13841403          $attr = parent::getAttributes($options); 
  • inc/admin/class.dc.list.php

    r1491 r1498  
    1414 
    1515     protected $columns; 
     16     protected $columns_combo; 
    1617     protected $entries; 
    1718     protected $filterset; 
     
    5455     @param    form_prefix    <b>string</b>       form prefix to use for parameters 
    5556     */ 
    56      public function __construct($core,$name,$filterset,$fetcher,$action,$form_prefix="f_") { 
     57     public function __construct($core,$name,$fetcher,$action,$form_prefix="f_") { 
    5758          parent::__construct($core,$name,$action,'POST'); 
    5859          $this->entries = array(); 
     
    6061          $this->selection = new dcFieldCheckbox('entries',NULL,array('multiple' => true)); 
    6162          $this->addField($this->selection); 
    62           $this->filterset = $filterset; 
    6363          $this->fetcher = $fetcher; 
    64      } 
    65  
    66      public function setup() { 
    67           $this 
    68                ->addField(new dcFieldCombo('action','',array(), array( 
    69                     'label' => __('Selected entries action:')))) 
    70                ->addField(new dcFieldSubmit('ok',__('ok'), array())); 
    71           $columns_combo = array(); 
    72           foreach ($this->columns as $c) { 
    73                $columns_combo[$c->getID()] = $c->getName(); 
    74           } 
     64          $this->filterset = null; 
     65     } 
     66      
     67     protected function setupFilterset() { 
    7568          $this->sortby = new dcFilterCombo( 
    7669               'sortby', 
    7770               __('Sort By'),  
    78                __('Sort by'), 'sortby', $columns_combo,array('singleval'=> true,'static' => true)); 
     71               __('Sort by'), 'sortby', $this->columns_combo,array('singleval'=> true,'static' => true)); 
    7972          $this->filterset->addFilter($this->sortby); 
    8073          $order_combo = array('asc' => __('Ascending'),'desc' => __('Descending')); 
     
    8881          $this->filterset->addFilter($this->order); 
    8982          $this->filterset->addFilter($limit); 
    90           $this->filterset->setup(); 
     83          $this->filterset->setup();     
     84          $this->nb_items_per_page = $limit->getFields()->getValue(); 
     85 
     86     } 
     87      
     88     public function setup() { 
     89          $this 
     90               ->addField(new dcFieldCombo('action','',array(), array( 
     91                    'label' => __('Selected entries action:')))) 
     92               ->addField(new dcFieldSubmit('ok',__('ok'), array())); 
     93          $this->columns_combo = array(); 
     94          foreach ($this->columns as $c) { 
     95               $this->columns_combo[$c->getID()] = $c->getName(); 
     96          } 
     97          if ($this->filterset !== null) { 
     98               $this->setupFilterset(); 
     99          } 
    91100          parent::setup(); 
    92           $this->nb_items_per_page = $limit->getFields()->getValue(); 
    93101          if ($this->nb_items_per_page == 0) 
    94102               $this->nb_items_per_page = 10; 
     
    99107     protected function fetchEntries() { 
    100108          $params = new ArrayObject(); 
    101           $this->filterset->applyFilters($params); 
     109          if ($this->filterset != null) { 
     110               $this->filterset->applyFilters($params); 
     111          } 
    102112          $this->nb_items = $this->fetcher->getEntriesCount($params); 
    103113          $this->nb_pages = round($this->nb_items / $this->nb_items_per_page) + 1; 
  • inc/admin/default-templates/forms/formfilter_layout.html.twig

    r1491 r1498  
    4141</div> 
    4242</div> 
     43<p class="applied-filters">{{__('Applied filters :') }} </p> 
     44<ul> 
     45     {% for f in fenv.applied_filters %} 
     46          <li>{{f}}</li> 
     47     {% endfor %} 
     48</ul> 
    4349{%- endblock %} 
    4450 
     
    5763{% block filter_combo -%} 
    5864     {% if f.display_inline is defined -%} 
    59           <p id='{{f.filter_id}}'>{{form_field(f.ffield,{},{'label':f.desc,'nestedlabel': true, 'labelclass':'classic' })}}</p> 
     65          <p id='{{f.filter_id}}'>{{form_field(f.ffield,{'offset':f.foffset},{'label':f.desc,'nestedlabel': true, 'labelclass':'classic' })}}</p> 
    6066     {%- else -%} 
    6167          <td id='{{f.filter_id}}' title='{{f.desc}}' class="filter-title" colspan="2">{{f.desc}} : </td> 
    62           <td >{{ form_field(f.ffield) }}</td> 
     68          <td >{{ form_field(f.ffield,{'offset':f.foffset}) }}</td> 
    6369     {%- endif %} 
    6470{%- endblock %} 
     
    6672{% block filter_combo_cont -%} 
    6773     {% if f.display_inline is defined -%} 
    68           <p id='{{filter_id}}'>{{form_field(f.ffield,{'label':__('or :')})}}</p> 
     74          <p id='{{filter_id}}'>{{form_field(f.ffield,{'offset':f.foffset,'label':__('or :')})}}</p> 
    6975     {%- else -%} 
    70           <td id='{{filter_id}}' colspan="2">{{ __('or :') }} </td><td>{{ form_field(f.ffield) }}</td> 
     76          <td id='{{filter_id}}' colspan="2">{{ __('or :') }} </td><td>{{ form_field(f.ffield,{'offset':f.foffset}) }}</td> 
    7177     {%- endif %} 
    7278{%- endblock %} 
     
    7682     <td id='{{filterd_id}}' title='{{f.desc}}' class="filter-title">{{f.desc}} : </td> 
    7783     <td>{{ form_field(f.fverb)}}</td> 
    78      <td>{{ form_field(f.ffield) }}</td> 
     84     <td>{{ form_field(f.ffield,{'offset':f.foffset}) }}</td> 
    7985{%- endblock %} 
    8086 
     
    8288{% block filter_boolean -%} 
    8389     <td id='{{filterd_id}}' title='{{f.desc}}' class="filter-title" colspan="2">{{f.desc}}</td> 
    84      <td>{{ form_field(f.ffield) }}</td> 
     90     <td>{{ form_field(f.ffield,{'offset':f.foffset}) }}</td> 
    8591{%- endblock %} 
    8692 
    8793{% block filter_text -%} 
    8894     {% if f.display_inline is defined -%} 
    89           <p id='{{filter_id}}'>{{form_field(f.ffield,{},{'label':f.desc,'nestedlabel': true, 'labelclass':'classic' })}}</p> 
     95          <p id='{{filter_id}}'>{{form_field(f.ffield,{'offset':f.foffset},{'label':f.desc,'nestedlabel': true, 'labelclass':'classic' })}}</p> 
    9096     {%- else -%} 
    9197          <td id='{{filterd_id}}' title='{{f.desc}}' class="filter-title" colspan="2">{{f.desc}}</td> 
    92           <td>{{ form_field(f.ffield) }}</td> 
     98          <td>{{ form_field(f.ffield,{'offset':f.foffset}) }}</td> 
    9399     {%- endif %} 
    94100{%- endblock %} 
  • inc/admin/default-templates/forms/lists_layout.html.twig

    r1156 r1498  
    22{% set lenv = _context['list_' ~ listname] %} 
    33{% if lenv.entries %} 
    4 {% block list_pagination %} 
    5 <p>Page : {% for p in lenv.pages_links %} 
    6 {% if p == lenv.page or p == '...' %} 
    7 <b>{{p}}</b> 
    8 {% else %} 
    9 <a href="{{build_url(lenv.url,{'page':p})}}">{{p}}</a> 
    10 {% endif %} 
    11 {% endfor %}</p> 
     4{% block list_pagination -%} 
     5<p class="pagination">{{__('Page:')}} 
     6{% for p in lenv.pages_links -%} 
     7     {% if p == lenv.page or p == '...' %} 
     8          <b>{{p}}</b> 
     9     {% else %} 
     10          <a href="{{build_url(lenv.url,{'page':p})}}">{{p}}</a> 
     11     {% endif %} 
     12     {% if not loop.last %} - {% endif %} 
     13{%- endfor %}</p> 
    1214{% endblock %} 
    1315{% form listname -%} 
     
    1719          <tr> 
    1820          {% for h in lenv.cols -%} 
    19                <th scope="col">{{h.name}}</th> 
     21               <th scope="col"{% if loop.first %} colspan="2"{% endif %}>{{h.name}}</th> 
    2022          {%- endfor %} 
    2123          </tr> 
    2224          {% for e in lenv.entries %} 
    2325               {% block list_line_start %}<tr class="line">{% endblock %} 
     26               <td>{{widget('col_ref',{'e':e,'offset':loop.parent.loop.index0})}}</td> 
    2427               {% for h in lenv.cols %} 
    2528                    <td>{{widget(h.widget,{'e':e,'offset':loop.parent.loop.index0})}}</td> 
     
    4447{% endblock filter_checkbox %} 
    4548 
     49 
     50{% block col_ref %} 
     51     {{form_field('entries',{'offset':offset})}} 
     52{% endblock %} 
  • inc/admin/default-templates/post.html.twig

    r1493 r1498  
    11{% extends "layout.html.twig" %} 
    22{% import "js_helpers.html.twig" as js %} 
     3 
    34{% macro img_status(status) -%} 
    45     {% if status == 1 %} 
     
    1314     <img alt="{{title}}" title="{{title}}" src="images/{{src}}" /> 
    1415{%- endmacro %} 
     16 
    1517{% macro post_link(id,title,link) -%} 
    1618<a href="post.php?id={{id}}" title="{{title}}">{{link}}</a> 
     
    7577{% endform %} 
    7678</div> 
     79 
     80{# Trackbacks tab #} 
    7781{% if post_id is defined %} 
    7882<p><a href="trackbacks.php?id={{ post_id }}" class="multi-part">{{__('Ping blogs')}}</a></p> 
     83 
     84{# Comments list tab #} 
    7985<div class="multi-part" id="comments" title="{{__('Comments')}}"> 
    8086<!-- to be completed --> 
    8187</div> 
     88 
     89{# Add a comment tab #} 
    8290<div class="multi-part" id="add-comment" title="{{__('Add a comment')}}"> 
    8391<h3>{{__('Add a comment')}}</h3> 
  • inc/admin/default-templates/posts.html.twig

    r1491 r1498  
    2626{{ filterset('fposts') }} 
    2727 
    28 <p> Applied filters : {{filters}} </p> 
    29  
    3028{{ listitems('lposts')}} 
    3129 
  • inc/admin/default-templates/posts_cols.html.twig

    r1156 r1498  
    11 
    2 {% block col_ref %} 
    3      {{form_field('entries',{'offset':offset})}} 
    4 {% endblock %} 
    52 
    63{% block col_title %} 
    7      {{block('col_ref')}} 
    84     <a href="post.php?id={{e.post_id}}">{{e.post_title}}</a> 
    95{% endblock %} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map