Dotclear

Changeset 756:5127beea4a3a


Ignore:
Timestamp:
11/10/11 16:12:01 (14 years ago)
Author:
Dsls <dsls@…>
Branch:
formfilters
Message:
  • Adapted comments.php do new filters
  • added author filter, with autocompletion
  • added comment_author parameter to dcBlog::getComments
  • removed jquery.autocomplete
  • added jquery UI (should be refined, this is quite raw...)
  • added dcPager::jqueryUI
  • adapted tags plugin to new jquery ui autocomplete
Files:
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • admin/comments.php

    r523 r756  
    1414 
    1515dcPage::check('usage,contentadmin'); 
     16 
     17class authorFilter extends textFilter { 
     18     public function header() { 
     19          return  
     20               dcPage::jqueryUI(). 
     21               dcPage::jsLoad('js/author_filter.js') 
     22               ; 
     23     } 
     24     public function applyFilter($params) { 
     25          $val = preg_split("/[\s,]+/",$this->values[0]); 
     26          $params[$this->request_param]=$val; 
     27     } 
     28} 
     29 
    1630 
    1731# Creating filter combo boxes 
     
    5468$filterSet = new dcFilterSet('comments','comments.php'); 
    5569 
    56 $authorFilter = new textFilter( 
    57           'author',__('Author'), __('Author'),'q_author',20,255); 
     70$authorFilter = new authorFilter( 
     71          'author',__('Author'), __('Author'),'comment_author',20,255); 
    5872$filterSet 
    5973     ->addFilter(new comboFilter( 
     
    6781$core->callBehavior('adminCommentsFilters',$filterSet); 
    6882 
    69 $filterSet->setFormValues($_GET); 
     83$filterSet->setup($_GET,$_POST); 
    7084if (isset($_GET['author'])) { 
    7185     $authorFilter->add(); 
     
    91105     $core->error->add($e->getMessage()); 
    92106} 
    93 $filterSet->setColumnsForm($comment_list->getColumnsForm()); 
     107$filterSet->setExtraData($comment_list->getColumnsForm()); 
    94108 
    95109/* DISPLAY 
    96110-------------------------------------------------------- */ 
    97 $starting_script = dcPage::jsLoad('js/_comments.js').$filterSet->header();; 
     111$starting_script = dcPage::jsLoad('js/_comments.js').$filterSet->header(); 
    98112 
    99113# --BEHAVIOR-- adminCommentsHeaders 
  • admin/posts.php

    r755 r756  
    138138     ->addFilter(new comboFilter( 
    139139          'users',__('Author'), __('Author'), 'user_id', $users_combo)) 
    140      ->addFilter(new comboFilter( 
     140     ->addFilter(new categoryFilter( 
    141141          'category',__('Category'), __('Category'), 'cat_id', $categories_combo)) 
    142142     ->addFilter(new comboFilter( 
     
    147147          'lang',__('Lang'), __('Lang'), 'post_lang', $lang_combo)) 
    148148     ->addFilter(new monthComboFilter( 
    149           'month',__('Month'),__('Month'), 'post_month', $dt_m_combo,array('singleval' => 1))); 
     149          'month',__('Month'),__('Month'), 'post_month', $dt_m_combo,array('singleval' => 1))) 
     150     ->addFilter(new textFilter( 
     151          'search',__('Contains'),__('The entry contains'), 'search',20,255)); 
    150152 
    151153$core->callBehavior('adminPostsFilters',$filterSet); 
     
    165167     } else { 
    166168          $page_title = __('Entries'); 
     169          $filters_info = ''; 
    167170     } 
    168171     $post_list->setItems($posts,$counter->f(0)); 
  • admin/services.php

    r0 r756  
    2525$core->rest->addFunction('delMeta',array('dcRestMethods','delMeta')); 
    2626$core->rest->addFunction('setPostMeta',array('dcRestMethods','setPostMeta')); 
     27$core->rest->addFunction('searchCommentAuthor',array('dcRestMethods','searchCommentAuthor')); 
    2728$core->rest->addFunction('searchMeta',array('dcRestMethods','searchMeta')); 
    2829 
     
    393394          return $rsp; 
    394395     } 
     396 
     397     public static function searchCommentAuthor($core,$get) 
     398     { 
     399          $q = !empty($get['q']) ? strtoupper($get['q']) : null; 
     400           
     401          $strReq = 'SELECT DISTINCT C.comment_author '. 
     402               'FROM '.$core->prefix.'comment C '. 
     403               'INNER JOIN '.$core->prefix.'post P on C.post_id = P.post_id '. 
     404               'WHERE P.blog_id = \''.$core->blog->id.'\' '. 
     405               'AND UPPER(comment_author) like \'%'.$core->con->escape($q).'%\'' 
     406               ; 
     407          //echo $strReq; 
     408          $rs = $core->con->select($strReq); 
     409          $rsp = new xmlTag(); 
     410           
     411          while ($rs->fetch()) 
     412          { 
     413               $author = new xmlTag('author'); 
     414               $author->name=$rs->comment_author; 
     415               $rsp->insertNode($author); 
     416          } 
     417           
     418          return $rsp; 
     419     } 
     420 
    395421} 
    396422?> 
  • inc/admin/class.dc.filter.php

    r755 r756  
    4141          $this->action = $action; 
    4242          $this->extra_data = ''; 
     43          $this->filtered = false; 
    4344     } 
    4445      
     
    6263          $ser = array(); 
    6364          $ws = $GLOBALS['core']->auth->user_prefs->addWorkspace('filters'); 
    64           foreach($this->lfilters as $filter) { 
    65                $ser[$filter->id]=$filter->serialize(); 
    66           } 
    67           $ws->put($this->name,serialize($ser),'string'); 
     65          $data = array(); 
     66          $data= $this->getFiltersAsParams($this->efilters); 
     67          $ws->put($this->name,serialize($data->getArrayCopy()),'string'); 
     68          return $data; 
    6869     } 
    6970      
     
    7374     protected function loadFilters() { 
    7475          $ws = $GLOBALS['core']->auth->user_prefs->addWorkspace('filters'); 
    75            
    76           $settings = !is_null($ws->{$this->name}) ? unserialize($ws->{$this->name}) : array(); 
    77           foreach($settings as $k => $v) { 
    78                $this->lfilters[$k]->unserialize($v); 
    79           } 
     76          $data = (!is_null($ws->{$this->name})) ? unserialize($ws->{$this->name}) : array(); 
     77          if (is_array($data)) 
     78               return $data; 
     79          else 
     80               return array(); 
    8081     } 
    8182      
     
    152153                         if (isset($post['add_filter'])  
    153154                              && isset($this->efilters[$post['add_filter']])) { 
    154                               echo 'addadd'; 
    155155                         $this->efilters[$post['add_filter']]->add(); 
    156156                         } 
     
    162162                         } 
    163163                    } elseif ($action=="apply") { 
    164                          http::redirect($this->action.'?'.http_build_query($this->getFiltersAsParams($this->efilters),'','&')); 
     164                         $data = $this->saveFilters(); 
     165                         http::redirect($this->action.'?'.http_build_query($data,'','&')); 
    165166                         exit; 
    166167                    } 
     
    175176               $this->hideform=false; 
    176177          } else { 
     178               // Use case (2) 
     179               if (count($get)==0) { 
     180                    $get = $this->loadFilters(); 
     181               } 
    177182               $this->initializeFromData($this->efilters, $get); 
    178183               $this->initializeFromData($this->lfilters, $get); 
     
    192197               $formclass=''; 
    193198          } 
     199           
    194200          $ret .= '<p><img alt="" src="images/minus.png" /> '. 
    195201               '<a href="#" id="toggle-filters">'. 
    196202               __('Toggle filters and display options'). 
    197                '</a></p>'; 
    198            
    199           $ret .= 
     203               '</a></p>'. 
    200204               '<div class="two-cols">'. 
    201205               '<form id="filters" action="'.$this->action.'" method="post"'.$formclass.'>'. 
     
    217221          } 
    218222          $ret .= '</tbody></table>'. 
    219                '<p class="clear"><input class="delete" type="submit" value="'.__('Delete all filters').'" name="'. 
    220                $this->form_prefix.'clear_filters" />'. 
    221                '&nbsp;<input  type="submit" value="'.__('Reset').'" name="'. 
    222                $this->form_prefix.'reset" /></p>'. 
    223223               '<h3 class="margintop">'.__('Add a filter').'</h3>'. 
    224224               '<p id="available_filters">'. 
     
    226226               '<input type="submit" value=" + " title="'.__('Add this filter').'" name="'.$this->form_prefix.'add" />'. 
    227227               '</p>'. 
     228               '<p class="clear"><input class="delete" type="submit" value="'.__('Delete all filters').'" name="'. 
     229               $this->form_prefix.'clear_filters" />'. 
     230               '&nbsp;<input  type="submit" value="'.__('Reset').'" name="'. 
     231               $this->form_prefix.'reset" /></p>'. 
    228232               '</div>'; 
    229233          if ($this->extra_data != '') { 
     
    261265     } 
    262266      
    263      protected function displayFilters($filters) { 
    264           $ret = '<ul>'; 
    265           foreach ($filters as $f) { 
     267     public function getFiltersText() { 
     268          $ret = '<p>'.__('Currently applied filters :').'</p><ul>'; 
     269          foreach ($this->lfilters as $f) { 
    266270               if ($f->isEnabled()) 
    267                $ret .= '<li>'.$f->getAsText().'</li>'."\n"; 
     271                    $ret .= '<li>'.$f->getAsText().'</li>'."\n"; 
    268272          } 
    269273          $ret .= '</ul>'; 
     
    276280     */ 
    277281     public function header() { 
    278           return dcPage::jsLoad('js/filters.js'); 
     282          $ret = dcPage::jsLoad('js/filters.js'); 
     283          foreach($this->efilters as $f) { 
     284               $ret .= $f->header(); 
     285          } 
     286          return $ret; 
    279287     } 
    280288      
     
    295303     */ 
    296304     public function applyFilters($params) { 
    297           $filtered = false; 
    298305          foreach ($this->lfilters as $filter) { 
    299306               if ($filter->isEnabled()) { 
    300307                    $filter->applyFilter($params); 
    301                     $filtered = true; 
     308                    $this->filtered = true; 
    302309               } 
    303310          } 
    304           return $filtered; 
     311          return $this->filtered; 
    305312     } 
    306313      
     
    488495     } 
    489496 
     497     public function header() { 
     498          return ''; 
     499     } 
     500      
    490501     public abstract function getAsText(); 
    491502 
     
    602613      
    603614     public function getAsText() { 
    604           return sprintf("%s %s %s",$this->desc,$this->verb,join(',',$this->values)); 
     615          $arr=array(); 
     616          foreach ($this->values as $value) { 
     617               $arr[]=array_search($value,$this->options); 
     618          } 
     619          return sprintf("%s %s %s",$this->desc,$this->verb,join(',',$arr)); 
    605620     } 
    606621} 
    607622 
     623 
     624class categoryFilter extends comboFilter { 
     625     public function getAsText() { 
     626          $arr=array(); 
     627          foreach ($this->values as $value) { 
     628               $cat=array_search($value,$this->options); 
     629               $arr[]=preg_replace("#^.* ([^ ]+) .*$#",'$1',$cat); 
     630          } 
     631          return sprintf("%s %s %s",$this->desc,$this->verb,join(',',$arr)); 
     632     } 
     633} 
    608634/** 
    609635@ingroup DC_CORE 
     
    632658 
    633659     public function getFormFields($pos=0) { 
    634           return '<td><span class="'.$labelclass.'">'.$this->desc.'</span></td><td>'. 
     660          return '<td colspan="2">'.$this->desc.'</td><td>'. 
    635661               form::combo($this->getFieldId($pos),$this->options,$this->values[$pos], 
    636662                    '','',false,'title="'.__('Choose an option').'"').'</td>'; 
     
    668694 
    669695     public function getFormFields($pos=0) { 
    670           return '<span class="'.$labelclass.'">'.$this->desc.'</span>'. 
    671                form::field($this->getFieldId($pos),$this->size,$this->max,html::escapeHTML($this->values[0])); 
     696          return '<td colspan="2">'.$this->desc.'</td><td>'. 
     697               form::field($this->getFieldId($pos),$this->size,$this->max,html::escapeHTML($this->values[0])). 
     698               '</td>'; 
    672699     } 
    673700      
  • inc/admin/lib.dc.page.php

    r224 r756  
    501501     } 
    502502      
     503     public static function jqueryUI() 
     504     { 
     505          return 
     506          '<link rel="stylesheet" type="text/css" href="style/jquery-ui-1.8.16.custom.css" />'."\n". 
     507          self::jsLoad('js/jquery/jquery-ui-1.8.16.custom.min.js'); 
     508     } 
     509 
    503510     public static function jsColorPicker() 
    504511     { 
  • inc/core/class.dc.blog.php

    r506 r756  
    18311831               $strReq .= "AND LOWER(comment_author) LIKE '".$q_author."' "; 
    18321832          } 
     1833          if (isset($params['comment_author'])) { 
     1834               $strReq .= "AND comment_author ".$this->con->in($params['comment_author']).' '; 
     1835          } 
    18331836           
    18341837          if (!empty($params['search'])) 
  • inc/prepend.php

    r522 r756  
    7575$__autoload['dcFilterSet']              = dirname(__FILE__).'/admin/class.dc.filter.php'; 
    7676$__autoload['dcFilter']                 = dirname(__FILE__).'/admin/class.dc.filter.php'; 
     77$__autoload['textFilter']                    = dirname(__FILE__).'/admin/class.dc.filter.php'; 
     78$__autoload['comboFilter']                   = dirname(__FILE__).'/admin/class.dc.filter.php'; 
    7779 
    7880$__autoload['dcTemplate']               = dirname(__FILE__).'/public/class.dc.template.php'; 
  • plugins/tags/_admin.php

    r217 r756  
    108108           
    109109          return  
    110           '<script type="text/javascript" src="index.php?pf=tags/js/jquery.autocomplete.min.js"></script>'. 
     110          dcPage::jqueryUI(). 
    111111          '<script type="text/javascript" src="index.php?pf=tags/js/post.js"></script>'. 
    112112          '<script type="text/javascript">'."\n". 
     
    137137           
    138138          return  
    139           '<script type="text/javascript" src="index.php?pf=tags/js/jquery.autocomplete.min.js"></script>'. 
    140           '<script type="text/javascript" src="index.php?pf=tags/js/posts_actions.js"></script>'. 
    141139          '<script type="text/javascript">'."\n". 
    142140          "//<![CDATA[\n". 
     
    153151          "\n//]]>\n". 
    154152          "</script>\n". 
     153          '<script type="text/javascript" src="index.php?pf=tags/js/posts_actions.js"></script>'. 
     154          dcPage::jqueryUI(). 
    155155          '<link rel="stylesheet" type="text/css" href="index.php?pf=tags/style.css" />'; 
    156156     } 
  • plugins/tags/js/post.js

    r0 r756  
    11$(function() { 
     2     function split( val ) { 
     3          return val.split( /,\s*/ ); 
     4     } 
     5     function extractLast(term) { 
     6          return split(term).pop(); 
     7     } 
    28     $('#edit-entry').onetabload(function() { 
    39          var tags_edit = $('#tags-edit'); 
     
    1824          } 
    1925           
    20           $('#post_meta_input').autocomplete(mEdit.service_uri, { 
    21                extraParams: { 
    22                     'f': 'searchMeta', 
    23                     'metaType': 'tag' 
    24                }, 
    25                delay: 1000, 
    26                multiple: true, 
    27                matchSubset: false, 
    28                matchContains: true, 
    29                parse: function(xml) {  
    30                     var results = []; 
    31                     $(xml).find('meta').each(function(){ 
    32                          results[results.length] = { 
    33                               data: { 
    34                                    "id": $(this).text(), 
    35                                    "count": $(this).attr("count"), 
    36                                    "percent":  $(this).attr("roundpercent") 
    37                               }, 
    38                               result: $(this).text() 
    39                          };  
    40                     }); 
    41                     return results; 
    42                }, 
    43                formatItem: function(tag) { 
    44                     return tag.id + ' <em>(' + 
    45                     dotclear.msg.tags_autocomplete. 
    46                          replace('%p',tag.percent). 
    47                          replace('%e',tag.count + ' ' + 
    48                               (tag.count > 1 ? 
    49                               dotclear.msg.entries : 
    50                               dotclear.msg.entry) 
    51                          ) + 
    52                     ')</em>'; 
    53                }, 
    54                formatResult: function(tag) {  
    55                     return tag.result;  
     26          $('#post_meta_input') 
     27               .bind( "keydown", function( event ) { 
     28          if ( event.keyCode === $.ui.keyCode.TAB && 
     29                    $( this ).data( "autocomplete" ).menu.active ) { 
     30               event.preventDefault(); 
     31          } 
     32     }) 
     33     .autocomplete({ 
     34          minLength: 2, 
     35          delay: 1000, 
     36          source: function(request,response) { 
     37               $.ajax({ 
     38                    url: mEdit.service_uri, 
     39                    data: { 
     40                         'f': 'searchMeta', 
     41                         'metaType': 'tag', 
     42                         'q': extractLast(request.term) 
     43                    }, 
     44                    success:function(data) { 
     45                         results = []; 
     46                         $(data).find('meta').each(function(){ 
     47                              var id = $(this).text(); 
     48                              var roundpercent = $(this).attr("roundpercent"); 
     49                              var count = $(this).attr("count"); 
     50                              console.log(id); 
     51                              console.log(roundpercent); 
     52                              console.log(count); 
     53                              var label = id + ' (' + 
     54                                   dotclear.msg.tags_autocomplete. 
     55                                        replace('%p',roundpercent). 
     56                                        replace('%e',count + ' ' + 
     57                                        ((count > 1) ? 
     58                                             dotclear.msg.entries : 
     59                                             dotclear.msg.entry 
     60                                        )) + ')'; 
     61                                   console.log(label); 
     62                              results.push({label:label,value:id}); 
     63                         }); 
     64                         response(results); 
     65                    } 
     66               }); 
     67          }, 
     68          search: function() { 
     69               var term = extractLast( this.value ); 
     70               if ( term.length < 2 ) { 
     71                    return false; 
    5672               } 
    57           }); 
     73          }, 
     74          focus: function() { 
     75               // prevent value inserted on focus 
     76               return false; 
     77          }, 
     78          select: function( event, ui ) { 
     79               var terms = split( this.value ); 
     80               // remove the current input 
     81               terms.pop(); 
     82               // add the selected item 
     83               terms.push( ui.item.value ); 
     84               // add placeholder to get the comma-and-space at the end 
     85               terms.push( "" ); 
     86               this.value = terms.join( ", " ); 
     87               return false; 
     88          }          
     89     }); 
     90 
    5891     }); 
    5992}); 
  • plugins/tags/js/posts_actions.js

    r0 r756  
    11$(function() { 
     2     function split( val ) { 
     3          return val.split( /,\s*/ ); 
     4     } 
     5     function extractLast(term) { 
     6          return split(term).pop(); 
     7     } 
    28     var tag_field = $('#new_tags'); 
    39      
     
    1925     }); 
    2026      
    21      $('#post_meta_input').autocomplete(mEdit.service_uri, { 
    22           extraParams: { 
    23                'f': 'searchMeta', 
    24                'metaType': 'tag' 
     27     $('#post_meta_input') 
     28     .bind( "keydown", function( event ) { 
     29          if ( event.keyCode === $.ui.keyCode.TAB && 
     30                    $( this ).data( "autocomplete" ).menu.active ) { 
     31               event.preventDefault(); 
     32          } 
     33     }) 
     34     .autocomplete({ 
     35          minLength: 2, 
     36          delay: 1000, 
     37          source: function(request,response) { 
     38               $.ajax({ 
     39                    url: mEdit.service_uri, 
     40                    data: { 
     41                         'f': 'searchMeta', 
     42                         'metaType': 'tag', 
     43                         'q': extractLast(request.term) 
     44                    }, 
     45                    success:function(data) { 
     46                         results = []; 
     47                         $(data).find('meta').each(function(){ 
     48                              var id = $(this).text(); 
     49                              var roundpercent = $(this).attr("roundpercent"); 
     50                              var count = $(this).attr("count"); 
     51                              console.log(id); 
     52                              console.log(roundpercent); 
     53                              console.log(count); 
     54                              var label = id + ' (' + 
     55                                   dotclear.msg.tags_autocomplete. 
     56                                        replace('%p',roundpercent). 
     57                                        replace('%e',count + ' ' + 
     58                                        ((count > 1) ? 
     59                                             dotclear.msg.entries : 
     60                                             dotclear.msg.entry 
     61                                        )) + ')'; 
     62                                   console.log(label); 
     63                              results.push({label:label,value:id}); 
     64                         }); 
     65                         response(results); 
     66                    } 
     67               }); 
    2568          }, 
    26           delay: 1000, 
    27           multiple: true, 
    28           matchSubset: false, 
    29           matchContains: true, 
    30           parse: function(xml) {  
    31                var results = []; 
    32                $(xml).find('meta').each(function(){ 
    33                     results[results.length] = { 
    34                          data: { 
    35                               "id": $(this).text(), 
    36                               "count": $(this).attr("count"), 
    37                               "percent":  $(this).attr("roundpercent") 
    38                          }, 
    39                          result: $(this).text() 
    40                     };  
    41                }); 
    42                return results; 
     69          search: function() { 
     70               var term = extractLast( this.value ); 
     71               if ( term.length < 2 ) { 
     72                    return false; 
     73               } 
    4374          }, 
    44           formatItem: function(tag) { 
    45                return tag.id + ' <em>(' + 
    46                dotclear.msg.tags_autocomplete. 
    47                     replace('%p',tag.percent). 
    48                     replace('%e',tag.count + ' ' + 
    49                          (tag.count > 1 ? 
    50                          dotclear.msg.entries : 
    51                          dotclear.msg.entry) 
    52                     ) + 
    53                ')</em>'; 
     75          focus: function() { 
     76               // prevent value inserted on focus 
     77               return false; 
    5478          }, 
    55           formatResult: function(tag) {  
    56                return tag.result;  
    57           } 
     79          select: function( event, ui ) { 
     80               var terms = split( this.value ); 
     81               // remove the current input 
     82               terms.pop(); 
     83               // add the selected item 
     84               terms.push( ui.item.value ); 
     85               // add placeholder to get the comma-and-space at the end 
     86               terms.push( "" ); 
     87               this.value = terms.join( ", " ); 
     88               return false; 
     89          }          
    5890     }); 
    5991}); 
Note: See TracChangeset for help on using the changeset viewer.

Sites map