From 1bbf8c48868efb87baab7ae71721f2c9ad408e65 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Mon, 20 Jan 2014 10:05:36 +0100 Subject: - Make search scope selectable in UI - Disable thread mode when searching over multiple folders - Encode UID values for HTML message row identifiers --- program/js/app.js | 45 ++++++++++++++++++++++------------- program/js/list.js | 29 ++++++++++++---------- program/lib/Roundcube/rcube_imap.php | 4 ++++ program/localization/en_US/labels.inc | 4 ++++ program/steps/mail/func.inc | 3 +++ program/steps/mail/search.inc | 13 ++++++++-- skins/larry/templates/mail.html | 13 +++++----- skins/larry/ui.js | 27 +++++++++++++++------ 8 files changed, 93 insertions(+), 45 deletions(-) diff --git a/program/js/app.js b/program/js/app.js index 5eae82351..2401e1e0c 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -217,6 +217,7 @@ function rcube_webmail() this.gui_objects.messagelist.parentNode.onmousedown = function(e){ return p.click_on_list(e); }; this.enable_command('toggle_status', 'toggle_flag', 'sort', true); + this.enable_command('set-listmode', this.env.threads && !this.env.search_request); // load messages this.command('list'); @@ -709,6 +710,10 @@ function rcube_webmail() this.list_contacts(props); break; + case 'set-listmode': + this.set_list_options(null, undefined, undefined, props == 'threads' ? 1 : 0); + break; + case 'sort': var sort_order = this.env.sort_order, sort_col = !this.env.disabled_sort_col ? props : this.env.sort_col; @@ -1753,7 +1758,7 @@ function rcube_webmail() this.init_message_row = function(row) { var i, fn = {}, self = this, uid = row.uid, - status_icon = (this.env.status_col != null ? 'status' : 'msg') + 'icn' + row.uid; + status_icon = (this.env.status_col != null ? 'status' : 'msg') + 'icn' + row.id; if (uid && this.env.messages[uid]) $.extend(row, this.env.messages[uid]); @@ -1765,17 +1770,17 @@ function rcube_webmail() // save message icon position too if (this.env.status_col != null) - row.msgicon = document.getElementById('msgicn'+row.uid); + row.msgicon = document.getElementById('msgicn'+row.id); else row.msgicon = row.icon; // set eventhandler to flag icon - if (this.env.flagged_col != null && (row.flagicon = document.getElementById('flagicn'+row.uid))) { + if (this.env.flagged_col != null && (row.flagicon = document.getElementById('flagicn'+row.id))) { fn.flagicon = function(e) { self.command('toggle_flag', uid); }; } // set event handler to thread expand/collapse icon - if (!row.depth && row.has_children && (row.expando = document.getElementById('rcmexpando'+row.uid))) { + if (!row.depth && row.has_children && (row.expando = document.getElementById('rcmexpando'+row.id))) { fn.expando = function(e) { self.expand_message_row(e, uid); }; } @@ -1837,7 +1842,7 @@ function rcube_webmail() + (flags.deleted ? ' deleted' : '') + (flags.flagged ? ' flagged' : '') + (message.selected ? ' selected' : ''), - row = { cols:[], style:{}, id:'rcmrow'+uid }; + row = { cols:[], style:{}, id:'rcmrow'+this.html_identifier(uid,true), uid:uid }; // message status icons css_class = 'msgicon'; @@ -1863,7 +1868,7 @@ function rcube_webmail() if (this.env.threading) { if (message.depth) { // This assumes that div width is hardcoded to 15px, - tree += '  '; + tree += '  '; if ((rows[message.parent_uid] && rows[message.parent_uid].expanded === false) || ((this.env.autoexpand_threads == 0 || this.env.autoexpand_threads == 2) && @@ -1882,7 +1887,7 @@ function rcube_webmail() message.expanded = true; } - expando = '
  
'; + expando = '
  
'; row_class += ' thread' + (message.expanded? ' expanded' : ''); } @@ -1890,14 +1895,14 @@ function rcube_webmail() row_class += ' unroot'; } - tree += ' '; + tree += ' '; row.className = row_class; // build subject link if (!bw.ie && cols.subject) { var action = flags.mbox == this.env.drafts_mailbox ? 'compose' : 'show'; var uid_param = flags.mbox == this.env.drafts_mailbox ? '_draft_uid' : '_uid'; - cols.subject = ''+cols.subject+''; } @@ -1908,7 +1913,7 @@ function rcube_webmail() if (c == 'flag') { css_class = (flags.flagged ? 'flagged' : 'unflagged'); - html = ' '; + html = ' '; } else if (c == 'attachment') { if (/application\/|multipart\/(m|signed)/.test(flags.ctype)) @@ -1927,7 +1932,7 @@ function rcube_webmail() css_class = 'unreadchildren'; else css_class = 'msgicon'; - html = ' '; + html = ' '; } else if (c == 'threads') html = expando; @@ -2390,7 +2395,7 @@ function rcube_webmail() } if (html) - $('#rcmtab'+uid).html(html); + $('#rcmtab'+this.html_identifier(uid, true)).html(html); }; // update parent in a thread @@ -2454,14 +2459,14 @@ function rcube_webmail() r.depth--; // move left // reset width and clear the content of a tab, icons will be added later - $('#rcmtab'+r.uid).width(r.depth * 15).html(''); + $('#rcmtab'+r.id).width(r.depth * 15).html(''); if (!r.depth) { // a new root count++; // increase roots count r.parent_uid = 0; if (r.has_children) { // replace 'leaf' with 'collapsed' - $('#rcmrow'+r.uid+' '+'.leaf:first') - .attr('id', 'rcmexpando' + r.uid) + $('#'+r.id+' .leaf:first') + .attr('id', 'rcmexpando' + r.id) .attr('class', (r.obj.style.display != 'none' ? 'expanded' : 'collapsed')) .bind('mousedown', {uid:r.uid, p:this}, function(e) { return e.data.p.expand_message_row(e, e.data.uid); }); @@ -4118,6 +4123,7 @@ function rcube_webmail() r = this.http_request(action, url, lock); this.env.qsearch = {lock: lock, request: r}; + this.enable_command('set-listmode', this.env.threads && (this.env.search_scope || 'base') == 'base'); } }; @@ -4126,7 +4132,8 @@ function rcube_webmail() { var n, url = {}, mods_arr = [], mods = this.env.search_mods, - mbox = this.env.mailbox; + mbox = this.env.mailbox, + scope = this.env.search_scope || 'base'; if (!filter && this.gui_objects.search_filter) filter = this.gui_objects.search_filter.value; @@ -4150,7 +4157,9 @@ function rcube_webmail() } } - if (mbox) + if (scope) + url._scope = scope; + if (mbox && scope != 'all') url._mbox = mbox; return url; @@ -4168,6 +4177,8 @@ function rcube_webmail() this.env.qsearch = null; this.env.search_request = null; this.env.search_id = null; + + this.enable_command('set-listmode', this.env.threads); }; this.sent_successfully = function(type, msg, folders) diff --git a/program/js/list.js b/program/js/list.js index 319807eae..c026ccb4a 100644 --- a/program/js/list.js +++ b/program/js/list.js @@ -107,11 +107,15 @@ init: function() */ init_row: function(row) { - // make references in internal array and set event handlers - if (row && String(row.id).match(this.id_regexp)) { - var self = this, - uid = RegExp.$1; + var uid; + if (row && (uid = $(row).data('uid'))) row.uid = uid; + else if (row && String(row.id).match(this.id_regexp)) + row.uid = RegExp.$1; + + // make references in internal array and set event handlers + if (row && row.uid) { + var self = this, uid = row.uid; this.rows[uid] = {uid:uid, id:row.id, obj:row}; // set eventhandlers to table row @@ -291,6 +295,7 @@ insert_row: function(row, before) if (row.id) domrow.id = row.id; if (row.className) domrow.className = row.className; if (row.style) $.extend(domrow.style, row.style); + if (row.uid) $(domrow).data('uid', row.uid); for (var domcell, col, i=0; row.cols && i < row.cols.length; i++) { col = row.cols[i]; @@ -589,7 +594,7 @@ expand: function(row) row.expanded = true; depth = row.depth; new_row = row.obj.nextSibling; - this.update_expando(row.uid, true); + this.update_expando(row.id, true); this.triggerEvent('expandcollapse', { uid:row.uid, expanded:row.expanded, obj:row.obj }); } else { @@ -639,7 +644,7 @@ collapse_all: function(row) row.expanded = false; depth = row.depth; new_row = row.obj.nextSibling; - this.update_expando(row.uid); + this.update_expando(row.id); this.triggerEvent('expandcollapse', { uid:row.uid, expanded:row.expanded, obj:row.obj }); // don't collapse sub-root tree in multiexpand mode @@ -661,7 +666,7 @@ collapse_all: function(row) $(new_row).css('display', 'none'); if (r.has_children && r.expanded) { r.expanded = false; - this.update_expando(r.uid, false); + this.update_expando(r.id, false); this.triggerEvent('expandcollapse', { uid:r.uid, expanded:r.expanded, obj:new_row }); } } @@ -683,7 +688,7 @@ expand_all: function(row) row.expanded = true; depth = row.depth; new_row = row.obj.nextSibling; - this.update_expando(row.uid, true); + this.update_expando(row.id, true); this.triggerEvent('expandcollapse', { uid:row.uid, expanded:row.expanded, obj:row.obj }); } else { @@ -700,7 +705,7 @@ expand_all: function(row) $(new_row).css('display', ''); if (r.has_children && !r.expanded) { r.expanded = true; - this.update_expando(r.uid, true); + this.update_expando(r.id, true); this.triggerEvent('expandcollapse', { uid:r.uid, expanded:r.expanded, obj:new_row }); } } @@ -714,9 +719,9 @@ expand_all: function(row) }, -update_expando: function(uid, expanded) +update_expando: function(id, expanded) { - var expando = document.getElementById('rcmexpando' + uid); + var expando = document.getElementById('rcmexpando' + id); if (expando) expando.className = expanded ? 'expanded' : 'collapsed'; }, @@ -1267,7 +1272,7 @@ use_arrow_key: function(keyCode, mod_key) this.collapse(selected_row); } - this.update_expando(selected_row.uid, selected_row.expanded); + this.update_expando(selected_row.id, selected_row.expanded); return false; } diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index 698d0daf3..dd0501c2d 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -953,6 +953,7 @@ class rcube_imap extends rcube_storage $this->sort_field = null; $this->page_size = 1000; // fetch up to 1000 matching messages per folder + $this->threading = false; $a_msg_headers = array(); foreach ($search_set->sets as $resultset) { @@ -1487,6 +1488,9 @@ class rcube_imap extends rcube_storage // connect IMAP to have all the required classes and settings loaded $this->check_connection(); + // disable threading + $this->threading = false; + $searcher = new rcube_imap_search($this->options, $this->conn); $results = $searcher->exec( $folder, diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc index 61890a642..05eab6713 100644 --- a/program/localization/en_US/labels.inc +++ b/program/localization/en_US/labels.inc @@ -208,6 +208,10 @@ $labels['msgtext'] = 'Entire message'; $labels['body'] = 'Body'; $labels['type'] = 'Type'; $labels['namex'] = 'Name'; +$labels['searchscope'] = 'Scope'; +$labels['currentfolder'] = 'Current folder'; +$labels['subfolders'] = 'This and subfolders'; +$labels['allfolders'] = 'All folders'; $labels['openinextwin'] = 'Open in new window'; $labels['emlsave'] = 'Download (.eml)'; diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 45d4242f9..fd321e294 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -105,6 +105,9 @@ if (empty($RCMAIL->action) || $RCMAIL->action == 'list') { } $OUTPUT->set_env('search_mods', rcmail_search_mods()); + + if (!empty($_SESSION['search_scope'])) + $OUTPUT->set_env('search_scope', $_SESSION['search_scope']); } $threading = (bool) $RCMAIL->storage->get_threading(); diff --git a/program/steps/mail/search.inc b/program/steps/mail/search.inc index b45cdc0de..88bbe6eda 100644 --- a/program/steps/mail/search.inc +++ b/program/steps/mail/search.inc @@ -35,6 +35,7 @@ $str = rcube_utils::get_input_value('_q', rcube_utils::INPUT_GET, true); $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_GET, true); $filter = rcube_utils::get_input_value('_filter', rcube_utils::INPUT_GET); $headers = rcube_utils::get_input_value('_headers', rcube_utils::INPUT_GET); +$scope = rcube_utils::get_input_value('_scope', rcube_utils::INPUT_GET); $subject = array(); $search_request = md5($mbox.$filter.$str); @@ -106,8 +107,15 @@ if (!empty($subject)) { $search_str = trim($search_str); $sort_column = rcmail_sort_column(); -// TEMPORARY: search all folders -$mboxes = $RCMAIL->storage->list_folders_subscribed('', '*', 'mail'); +// search all, current or subfolders folders +if ($scope == 'all') { + $mboxes = $RCMAIL->storage->list_folders_subscribed('', '*', 'mail'); +} +else if ($scope == 'sub') { + $mboxes = $RCMAIL->storage->list_folders_subscribed($mbox, '*', 'mail'); + if ($mbox != 'INBOX' && $mboxes[0] == 'INBOX') + array_shift($mboxes); +} // execute IMAP search if ($search_str) { @@ -128,6 +136,7 @@ if ($search_str) { $_SESSION['last_text_search'] = $str; } $_SESSION['search_request'] = $search_request; +$_SESSION['search_scope'] = $scope; // Add 'folder' column to list if ($_SESSION['search'][1]->multi) { diff --git a/skins/larry/templates/mail.html b/skins/larry/templates/mail.html index ff5f7549c..e2bf8901c 100644 --- a/skins/larry/templates/mail.html +++ b/skins/larry/templates/mail.html @@ -76,13 +76,8 @@
- - List - Threads - - List - Threads - + +
@@ -132,6 +127,10 @@
  • +
  • +
  • +
  • +
  • diff --git a/skins/larry/ui.js b/skins/larry/ui.js index 44fc727f6..2030b05cd 100644 --- a/skins/larry/ui.js +++ b/skins/larry/ui.js @@ -41,6 +41,7 @@ function rcube_mail_ui() this.show_popup = show_popup; this.add_popup = add_popup; this.set_searchmod = set_searchmod; + this.set_searchscope = set_searchscope; this.show_uploadform = show_uploadform; this.show_header_row = show_header_row; this.hide_header_row = hide_header_row; @@ -731,11 +732,10 @@ function rcube_mail_ui() */ function switch_view_mode(mode) { - if (rcmail.env.threading != (mode == 'thread')) - rcmail.set_list_options(null, undefined, undefined, mode == 'thread' ? 1 : 0); - - $('#maillistmode, #mailthreadmode').removeClass('selected'); - $('#mail'+mode+'mode').addClass('selected'); + if (!$('#mail'+mode+'mode').hasClass('disabled')) { + $('#maillistmode, #mailthreadmode').removeClass('selected'); + $('#mail'+mode+'mode').addClass('selected'); + } } @@ -761,11 +761,15 @@ function rcube_mail_ui() obj = popups['searchmenu'], list = $('input:checkbox[name="s_mods[]"]', obj), mbox = rcmail.env.mailbox, - mods = rcmail.env.search_mods; + mods = rcmail.env.search_mods, + scope = rcmail.env.search_scope || 'base'; if (rcmail.env.task == 'mail') { + if (scope == 'all') + mbox = '*'; mods = mods[mbox] ? mods[mbox] : mods['*']; all = 'text'; + $('#s_scope_'+scope).prop('checked', true); } else { all = '*'; @@ -896,7 +900,11 @@ function rcube_mail_ui() { var all, m, task = rcmail.env.task, mods = rcmail.env.search_mods, - mbox = rcmail.env.mailbox; + mbox = rcmail.env.mailbox, + scope = $('input[name="s_scope"]:checked').val(); + + if (scope == 'all') + mbox = '*'; if (!mods) mods = {}; @@ -937,6 +945,11 @@ function rcube_mail_ui() }); } + function set_searchscope(elem) + { + rcmail.env.search_scope = elem.value; + } + function push_contactgroup(p) { // lets the contacts list swipe to the left, nice! -- cgit v1.2.3