this.resetCriteria();
criteria.each(function(c) {
+ if (c.t == 'or') {
+ this.insertOr();
+ return;
+ }
+
switch (this.data.types[c.t]) {
case 'header':
case 'body':
// TODO: type
},
- resetCriteria: function()
- {
- $('search_criteria_table').childElements().invoke('remove');
- },
-
changeHandler: function(e)
{
var elt = e.element(), val = $F(elt);
break;
case 'search_criteria':
+ if (val == 'or') {
+ this.insertOr();
+ break;
+ }
+
switch (this.data.types[val]) {
case 'header':
case 'body':
return $('search_criteria').down('[value=' + id + ']').getText() + ': ';
},
- insertCriteria: function(tds)
+ deleteCriteria: function(tr)
+ {
+ delete this.criteria[tr.identify()];
+ tr.remove();
+ if ($('search_criteria_table').childElements().size()) {
+ $('search_criteria_table').down('TR TD').update('');
+ } else {
+ $('search_criteria').down('[value="or"]').hide().next().hide();
+ }
+ },
+
+ resetCriteria: function()
+ {
+ $('search_criteria_table').childElements().each(this.deleteCriteria.bind(this));
+ },
+
+ insertCriteria: function(tds, or)
{
var tr = new Element('TR'),
td = new Element('TD');
- if ($('search_criteria_table').childElements().size()) {
+ if (!or &&
+ $('search_criteria_table').childElements().size() &&
+ this.criteria[$('search_criteria_table').childElements().last().readAttribute('id')].t != 'or') {
tds.unshift(new Element('EM', { className: 'join' }).insert(this.text.and));
} else {
tds.unshift('');
+ if (!or) {
+ $('search_criteria').down('[value="or"]').show().next().show();
+ }
}
tds.each(function(node) {
return tr.identify();
},
+ insertOr: function()
+ {
+ this.criteria[this.insertCriteria([ new Element('EM', { className: 'join' }).insert(this.text.or + ' ') ], true)] = { t: 'or' };
+ },
+
insertText: function(id, text, not)
{
var tmp = [
tmp.each(function(c) {
var tmp2;
+ if (this.criteria[c].t == 'or') {
+ data.push(this.criteria[c]);
+ return;
+ }
+
switch (this.data.types[this.criteria[c].t]) {
case 'header':
case 'body':
elt.next('SPAN.searchuiFoldersActions').toggle();
}
} else if (elt.hasClassName('searchuiDelete')) {
- tmp = elt.up('TR');
- delete this.criteria[tmp.identify()];
- tmp.remove();
- if ($('search_criteria_table').childElements().size()) {
- $('search_criteria_table').down('TR TD').update('');
- }
+ this.deleteCriteria(elt.up('TR'));
e.stop();
return;
} else if (elt.hasClassName('searchuiCalendar')) {
$ui = $vfolder['uiinfo'];
- // TODO: match == 'or' ($ob['match']
- if ($ui['match'] == 'or') {
- $GLOBALS['imp_search']->deleteSearchQuery($id);
- continue;
- }
+ $or_match = ($ui['match'] == 'or');
/* BC: Convert old (IMP < 4.2.1) style w/separate flag entry to
* new style where flags are part of the fields to query. */
}
$rules[] = $tmp;
+
+ if ($or_match) {
+ $tmp = new stdClass;
+ $tmp->t = 'or';
+ $rules[] = $tmp;
+ }
}
/* This will overwrite the existing entry. */
* array(
* stdClass object {
* 't' => (string) 'Type' - The criteria type
- * Values: Keys from self::searchFields() and 'flag'.
+ * Values: Keys from self::searchFields(), 'flag', and 'or'.
* 'v' => (mixed) 'Value' - The data used to build the search
* 'header' - (string) The value to search for in the header
* 'customhdr' - (stdClass object) Contains 2 elements:
? $searchfields[$field]['type']
: $field;
+ if ($field == 'or') {
+ $text .= implode(' ' . _("and") . ' ', $text_array) . ' ' . _("OR") . ' ';
+ $text_array = array();
+ continue;
+ }
+
switch ($searchfields[$field]['type']) {
case 'flag':
if (isset($flagfields[$rule->v])) {
$search_fields = $GLOBALS['imp_search']->searchFields();
$flag_fields = $GLOBALS['imp_search']->flagFields();
$imp_flags = IMP_Imap_Flags::singleton();
+ $or_search = false;
foreach ($search as $rule) {
$ob = new Horde_Imap_Client_Search_Query();
: $rule->t;
switch ($type) {
+ case 'or':
+ $query->orSearch($search_array);
+ $search_array = array();
+ $or_search = true;
+ break;
+
case 'flag':
if (isset($flag_fields[$rule->v])) {
$val = $imp_flags->parseFormId($rule->t);
}
}
- $query->andSearch($search_array);
+ if ($or_search) {
+ $query->orSearch($search_array);
+ } else {
+ $query->andSearch($search_array);
+ }
return $query;
}
/* Gettext strings for this page. */
$gettext_strings = array(
- 'and' => _("AND"),
+ 'and' => _("and"),
'customhdr' => _("Custom Header:"),
'dateselection' => _("Date Selection"),
'flag' => _("Flag:"),
'need_folder' => _("Please select at least one folder to search."),
'need_label' => _("Saved searches require a label."),
'not_match' => _("Do NOT Match"),
+ 'or' => _("OR"),
'search_term' => _("Search Term:")
);
<select id="search_criteria">
<option value=""><gettext>Add search criteria:</gettext></option>
<option value="" disabled="disabled">- - - - - - - - -</option>
+ <option value="or" style="display:none"><gettext>Add OR clause</gettext></option>
+ <option value="" disabled="disabled" style="display:none">- - - - - - - - -</option>
<loop:s_fields>
<option value="<tag:s_fields.val />"><tag:s_fields.label /></option>
</loop:s_fields>