From: Michael M Slusarz Date: Wed, 22 Sep 2010 21:36:05 +0000 (-0600) Subject: Add stored search filtering to dimp. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=5cf6024e5df05a355d3a53ab46486da04faeb27e;p=horde.git Add stored search filtering to dimp. --- diff --git a/imp/js/dimpbase.js b/imp/js/dimpbase.js index 0edd53825..0fa002707 100644 --- a/imp/js/dimpbase.js +++ b/imp/js/dimpbase.js @@ -350,7 +350,7 @@ var DimpBase = { if (!this.isSearch(f)) { $('searchbar').hide(); - } else if (!this.search || this.search.flag) { + } else if (!this.search || !this.search.qsearch) { $('qsearch').hide(); } } @@ -488,8 +488,15 @@ var DimpBase = { var p = $H(); if (this.folderswitch && this.isSearch(id, true)) { p.set('qsearchmbox', this.search.mbox); - if (this.search.flag) { - p.update({ qsearchflag: this.search.flag, qsearchflagnot: Number(this.convertFlag(this.search.flag, this.search.not)) }); + if (this.search.filter) { + p.update({ + qsearchfilter: this.search.filter + }); + } else if (this.search.flag) { + p.update({ + qsearchflag: this.search.flag, + qsearchflagnot: Number(this.convertFlag(this.search.flag, this.search.not)) + }); } else { p.set('qsearch', $F('qsearch_input')); } @@ -895,7 +902,14 @@ var DimpBase = { break; default: - if (menu.endsWith('_setflag') || menu.endsWith('_unsetflag')) { + if (menu == 'ctx_qsearchopts_filter') { + this.search = { + filter: elt.retrieve('filter'), + label: this.viewport.getMetaData('label'), + mbox: this.folder + } + this.go('folder:' + DIMP.conf.fsearchid); + } else if (menu.endsWith('_setflag') || menu.endsWith('_unsetflag')) { flag = elt.retrieve('flag'); this.flag(flag, this.convertFlag(flag, menu.endsWith('_setflag'))); } else if (menu.endsWith('_flag') || menu.endsWith('_flagnot')) { @@ -1010,6 +1024,13 @@ var DimpBase = { } }, + contextAddFilter: function(filter, label) + { + var a = new Element('A').insert(label.escapeHTML()); + $('ctx_filter').insert(a); + a.store('filter', filter); + }, + contextAddFlag: function(flag, f) { var a = new Element('A'), @@ -1581,6 +1602,7 @@ var DimpBase = { this.search = { label: this.viewport.getMetaData('label'), mbox: this.folder, + qsearch: true, query: q }; this.go('folder:' + DIMP.conf.qsearchid); @@ -3034,8 +3056,14 @@ var DimpBase = { type: 'qsearchopts' }); DM.addSubMenu('ctx_qsearchopts_by', 'ctx_qsearchby'); + DM.addSubMenu('ctx_qsearchopts_filter', 'ctx_filter'); DM.addSubMenu('ctx_qsearchopts_flag', 'ctx_flag'); DM.addSubMenu('ctx_qsearchopts_flagnot', 'ctx_flag'); + + /* Create flag entries. */ + DIMP.conf.filters_o.each(function(f) { + this.contextAddFilter(f, DIMP.conf.filters[f]); + }, this); } /* Store these text strings for updating purposes. */ diff --git a/imp/lib/Ajax/Application.php b/imp/lib/Ajax/Application.php index 8b212afe3..bb6c81083 100644 --- a/imp/lib/Ajax/Application.php +++ b/imp/lib/Ajax/Application.php @@ -1947,12 +1947,13 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application 'change' => $change, 'initial' => $this->_vars->initial, 'mbox' => $this->_vars->view, - 'rangeslice' => $this->_vars->rangeslice, - 'requestid' => $this->_vars->requestid, 'qsearch' => $this->_vars->qsearch, + 'qsearchfilter' => $this->_vars->qsearchfilter, 'qsearchflag' => $this->_vars->qsearchflag, - 'qsearchmbox' => $this->_vars->qsearchmbox, 'qsearchflagnot' => $this->_vars->qsearchflagnot, + 'qsearchmbox' => $this->_vars->qsearchmbox, + 'rangeslice' => $this->_vars->rangeslice, + 'requestid' => $this->_vars->requestid, 'sortby' => $this->_vars->sortby, 'sortdir' => $this->_vars->sortdir ); diff --git a/imp/lib/Search.php b/imp/lib/Search.php index 0b94593af..b2cf48825 100644 --- a/imp/lib/Search.php +++ b/imp/lib/Search.php @@ -320,17 +320,22 @@ class IMP_Search implements ArrayAccess, Iterator, Serializable * * @param string $id The mailbox ID of the filter. * @param array $mboxes The list of mailboxes to apply the filter on. + * @param string $mid Use as the mailbox ID. * * @return IMP_Search_Query The created query object. * @throws InvalidArgumentException */ - public function applyFilter($id, array $mboxes) + public function applyFilter($id, array $mboxes, $mid = null) { if (!$this->isFilter($id)) { throw new InvalidArgumentException('Invalid filter ID given.'); } - $q_ob = $this[$id]->toQuery($mboxes); + if (!is_null($mid)) { + $mid = $this->_strip($mid); + } + + $q_ob = $this[$id]->toQuery($mboxes, $mid); $this->_search['query'][$q_ob->id] = $q_ob; $this->changed = true; diff --git a/imp/lib/Search/Filter.php b/imp/lib/Search/Filter.php index 70f43deb8..ef4321db7 100644 --- a/imp/lib/Search/Filter.php +++ b/imp/lib/Search/Filter.php @@ -43,13 +43,15 @@ class IMP_Search_Filter extends IMP_Search_Query * Creates a query object from this filter. * * @param array $mboxes The list of mailboxes to apply the filter to. + * @param string $id The query ID to use. * * @return IMP_Search_Query A query object. */ - public function toQuery(array $mboxes) + public function toQuery(array $mboxes, $id = null) { return new IMP_Search_Query(array( 'add' => $this->_criteria, + 'id' => $id, 'label' => $this->label, 'mboxes' => $mboxes )); diff --git a/imp/lib/Views/ListMessages.php b/imp/lib/Views/ListMessages.php index d1c8fd38c..6ca9f8eed 100644 --- a/imp/lib/Views/ListMessages.php +++ b/imp/lib/Views/ListMessages.php @@ -30,59 +30,65 @@ class IMP_Views_ListMessages /* Check for quicksearch request. */ if (strlen($args['qsearchmbox'])) { - /* Create the search query. */ - $c_list = array(); - - if (strlen($args['qsearchflag'])) { - $c_list[] = new IMP_Search_Element_Flag( - $args['qsearchflag'], - empty($args['qsearchflagnot']) - ); - - $is_search = true; - } elseif (strlen($args['qsearch'])) { - $field = $GLOBALS['prefs']->getValue('dimp_qsearch_field'); + if (strlen($args['qsearchfilter'])) { + $imp_search = $GLOBALS['injector']->getInstance('IMP_Search'); + $imp_search->applyFilter($args['qsearchfilter'], array($args['qsearchmbox']), $mbox); $is_search = true; + } else { + /* Create the search query. */ + $c_list = array(); - switch ($field) { - case 'all': - case 'body': - $c_list[] = new IMP_Search_Element_Text( - $args['qsearch'], - ($field == 'body') + if (strlen($args['qsearchflag'])) { + $c_list[] = new IMP_Search_Element_Flag( + $args['qsearchflag'], + empty($args['qsearchflagnot']) ); - break; - case 'from': - case 'subject': - $c_list[] = new IMP_Search_Element_Header( - $args['qsearch'], - $field - ); + $is_search = true; + } elseif (strlen($args['qsearch'])) { + $field = $GLOBALS['prefs']->getValue('dimp_qsearch_field'); + $is_search = true; + + switch ($field) { + case 'all': + case 'body': + $c_list[] = new IMP_Search_Element_Text( + $args['qsearch'], + ($field == 'body') + ); + break; + + case 'from': + case 'subject': + $c_list[] = new IMP_Search_Element_Header( + $args['qsearch'], + $field + ); break; - case 'recip': - $c_list[] = new IMP_Search_Element_Recipient( - $args['qsearch'] - ); - break; + case 'recip': + $c_list[] = new IMP_Search_Element_Recipient( + $args['qsearch'] + ); + break; - default: - $is_search = false; - break; + default: + $is_search = false; + break; + } } - } - /* Store the search in the session. */ - if ($is_search) { - $imp_search = $GLOBALS['injector']->getInstance('IMP_Search'); - $imp_search->createQuery( - $c_list, - array($args['qsearchmbox']), - null, - IMP_Search::CREATE_QUERY, - $mbox - ); + /* Store the search in the session. */ + if ($is_search) { + $imp_search = $GLOBALS['injector']->getInstance('IMP_Search'); + $imp_search->createQuery( + $c_list, + array($args['qsearchmbox']), + null, + IMP_Search::CREATE_QUERY, + $mbox + ); + } } } else { $imp_search = $GLOBALS['injector']->getInstance('IMP_Search'); diff --git a/imp/templates/dimp/index.inc b/imp/templates/dimp/index.inc index 4f3c42655..945169d17 100644 --- a/imp/templates/dimp/index.inc +++ b/imp/templates/dimp/index.inc @@ -471,6 +471,9 @@ function _simpleButton($id, $text, $image, $nodisplay = false) + + @@ -487,6 +490,7 @@ function _simpleButton($id, $text, $image, $nodisplay = false)