if (!this.isSearch(f)) {
$('searchbar').hide();
- } else if (!this.search || this.search.flag) {
+ } else if (!this.search || !this.search.qsearch) {
$('qsearch').hide();
}
}
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'));
}
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')) {
}
},
+ 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'),
this.search = {
label: this.viewport.getMetaData('label'),
mbox: this.folder,
+ qsearch: true,
query: q
};
this.go('folder:' + DIMP.conf.qsearchid);
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. */
'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
);
*
* @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;
* 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
));
/* 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');
<?php endif; ?>
</div>
+<div class="context" id="ctx_filter" style="display:none">
+</div>
+
<div class="context" id="ctx_flag" style="display:none">
</div>
<div class="context" id="ctx_qsearchopts" style="display:none">
<a id="ctx_qsearchopts_by"><?php echo _("Search By") ?></a>
<div class="sep"></div>
+ <a id="ctx_qsearchopts_filter"><?php echo _("Filter By") ?></a>
<a id="ctx_qsearchopts_flag"><?php echo _("Show Only") ?></a>
<a id="ctx_qsearchopts_flagnot"><?php echo _("Don't Show") ?></a>
<div class="sep"></div>
* did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
*/
-$app_urls = $code = $flags = array();
+$app_urls = $code = $filters = $flags = array();
foreach (IMP_Dimp::menuList() as $app) {
$app_urls[$app] = strval(Horde::url($GLOBALS['registry']->getInitialPage($app), true)->add('ajaxui', 1));
}
}
+/* Generate filter array. */
+$imp_search = $GLOBALS['injector']->getInstance('IMP_Search');
+$imp_search->setIteratorFilter(IMP_Search::LIST_FILTER);
+foreach (iterator_to_array($imp_search) as $key => $val) {
+ if ($val->enabled) {
+ $filters[$key] = $val->label;
+ }
+}
+
/* Generate flag array. */
foreach ($GLOBALS['injector']->getInstance('IMP_Imap_Flags')->getList(array('fgcolor' => true)) as $val) {
$flags[$val['flag']] = array_filter(array(
'buffer_pages' => intval($GLOBALS['conf']['dimp']['viewport']['buffer_pages']),
'disable_compose' => !IMP::canCompose(),
'filter_any' => intval($GLOBALS['prefs']->getValue('filter_any_mailbox')),
+ 'filters' => $filters,
+ /* Needed to maintain flag ordering. */
+ 'filters_o' => array_keys($filters),
'fixed_folders' => empty($GLOBALS['conf']['server']['fixed_folders'])
? array()
: array_map(array('IMP_Dimp', 'appendedFolderPref'), $GLOBALS['conf']['server']['fixed_folders']),