From d35c8f0c810b21db754c507f2c9cd6c168dc4963 Mon Sep 17 00:00:00 2001 From: Zev Benjamin Date: Tue, 21 May 2013 13:34:15 -0400 Subject: [PATCH] Track what user action triggered a narrow (imported from commit 2b110dc27334e4b823810bfef13c3d10d36b3886) --- zephyr/static/js/hashchange.js | 3 ++- zephyr/static/js/hotkey.js | 6 +++--- zephyr/static/js/narrow.js | 25 +++++++++++++++---------- zephyr/static/js/search.js | 8 ++++---- zephyr/static/js/ui.js | 22 +++++++++++----------- 5 files changed, 35 insertions(+), 29 deletions(-) diff --git a/zephyr/static/js/hashchange.js b/zephyr/static/js/hashchange.js index 802d27ef5f..051bf4a3f2 100644 --- a/zephyr/static/js/hashchange.js +++ b/zephyr/static/js/hashchange.js @@ -118,7 +118,8 @@ function do_hashchange() { } narrow.activate(operators, { select_first_unread: true, - change_hash: false // already set + change_hash: false, // already set + trigger: 'hash change' }); ui.update_floating_recipient_bar(); return true; diff --git a/zephyr/static/js/hotkey.js b/zephyr/static/js/hotkey.js index f288ba9ee2..421d586fac 100644 --- a/zephyr/static/js/hotkey.js +++ b/zephyr/static/js/hotkey.js @@ -18,8 +18,8 @@ var directional_hotkeys_id = { var narrow_hotkeys = { 115: narrow.by_recipient, // 's' 83: narrow.by_subject, // 'S' - 118: function () { // 'v' - narrow.by('is', 'private-message'); + 118: function (target, opts) { // 'v' + narrow.by('is', 'private-message', opts); } }; @@ -138,7 +138,7 @@ function process_hotkey(e) { if (current_msg_list.empty()) { return false; } - narrow_hotkeys[code](current_msg_list.selected_id()); + narrow_hotkeys[code](current_msg_list.selected_id(), {trigger: 'hotkey'}); return true; } diff --git a/zephyr/static/js/narrow.js b/zephyr/static/js/narrow.js index efae80947c..7907ff1e1c 100644 --- a/zephyr/static/js/narrow.js +++ b/zephyr/static/js/narrow.js @@ -349,7 +349,8 @@ exports.activate = function (operators, opts) { opts = $.extend({}, { then_select_id: home_msg_list.selected_id(), select_first_unread: false, - change_hash: true + change_hash: true, + trigger: 'unknown' }, opts); if (opts.then_select_id === -1) { @@ -459,7 +460,8 @@ exports.activate = function (operators, opts) { compose.update_faded_messages(); $(document).trigger($.Event('narrow_activated.zephyr', {msg_list: narrowed_msg_list, - filter: current_filter})); + filter: current_filter, + trigger: opts.trigger})); }; // Activate narrowing with a single operator. @@ -468,36 +470,39 @@ exports.by = function (operator, operand, opts) { exports.activate([[operator, operand]], opts); }; -exports.by_subject = function (target_id) { +exports.by_subject = function (target_id, opts) { var original = current_msg_list.get(target_id); if (original.type !== 'stream') { // Only stream messages have subjects, but the // user wants us to narrow in some way. - exports.by_recipient(target_id); + exports.by_recipient(target_id, opts); return; } + opts = $.extend({}, {then_select_id: target_id}, opts); exports.activate([ ['stream', original.stream], ['subject', original.subject] - ], { then_select_id: target_id }); + ], opts); }; // Called for the 'narrow by stream' hotkey. -exports.by_recipient = function (target_id) { +exports.by_recipient = function (target_id, opts) { + opts = $.extend({}, {then_select_id: target_id}, opts); var message = current_msg_list.get(target_id); switch (message.type) { case 'private': - exports.by('pm-with', message.reply_to, { then_select_id: target_id }); + exports.by('pm-with', message.reply_to, opts); break; case 'stream': - exports.by('stream', message.stream, { then_select_id: target_id }); + exports.by('stream', message.stream, opts); break; } }; -exports.by_time_travel = function (target_id) { - narrow.activate([], { then_select_id: target_id }); +exports.by_time_travel = function (target_id, opts) { + opts = $.extend({}, {then_select_id: target_id}, opts); + narrow.activate([], opts); }; exports.deactivate = function () { diff --git a/zephyr/static/js/search.js b/zephyr/static/js/search.js index 59d34de56c..5055001506 100644 --- a/zephyr/static/js/search.js +++ b/zephyr/static/js/search.js @@ -112,7 +112,7 @@ function narrow_or_search_for_term(item) { ui.change_tab_to('#home'); switch (obj.action) { case 'stream': - narrow.by('stream', obj.query); + narrow.by('stream', obj.query, {trigger: 'search'}); // It's sort of annoying that this is not in a position to // blur the search box, because it means that Esc won't // unnarrow, it'll leave the searchbox. @@ -123,17 +123,17 @@ function narrow_or_search_for_term(item) { return search_query_box.val(); case 'private_message': - narrow.by('pm-with', obj.query.email); + narrow.by('pm-with', obj.query.email, {trigger: 'search'}); search_query_box.blur(); return search_query_box.val(); case 'sender': - narrow.by('sender', obj.query.email); + narrow.by('sender', obj.query.email, {trigger: 'search'}); search_query_box.blur(); return search_query_box.val(); case 'operators': - narrow.activate(obj.operators); + narrow.activate(obj.operators, {trigger: 'search'}); search_query_box.blur(); return search_query_box.val(); } diff --git a/zephyr/static/js/ui.js b/zephyr/static/js/ui.js index 3bb8326766..998cdfafcd 100644 --- a/zephyr/static/js/ui.js +++ b/zephyr/static/js/ui.js @@ -1121,9 +1121,9 @@ $(function () { var nearest = current_msg_list.get(rows.id($(this).closest(".recipient_row"))); var selected = current_msg_list.selected_message(); if (util.same_recipient(nearest, selected)) { - narrow.by_recipient(selected.id); + narrow.by_recipient(selected.id, {trigger: 'message header'}); } else { - narrow.by_recipient(nearest.id); + narrow.by_recipient(nearest.id, {trigger: 'message header'}); } }); @@ -1131,9 +1131,9 @@ $(function () { var nearest = current_msg_list.get(rows.id($(this).closest(".recipient_row"))); var selected = current_msg_list.selected_message(); if (util.same_recipient(nearest, selected)) { - narrow.by_subject(selected.id); + narrow.by_subject(selected.id, {trigger: 'message header'}); } else { - narrow.by_subject(nearest.id); + narrow.by_subject(nearest.id, {trigger: 'message header'}); } }); @@ -1233,7 +1233,7 @@ $(function () { ui.change_tab_to('#home'); } var stream = $(e.target).parents('li').attr('data-name'); - narrow.by('stream', stream, {select_first_unread: true}); + narrow.by('stream', stream, {select_first_unread: true, trigger: 'sidebar'}); e.preventDefault(); }); @@ -1264,7 +1264,7 @@ $(function () { narrow.activate([['stream', stream], ['subject', subject]], - {select_first_unread: true}); + {select_first_unread: true, trigger: 'sidebar'}); e.preventDefault(); }); @@ -1343,26 +1343,26 @@ $(function () { $('body').on('click', '.popover_narrow_by_subject_button', function (e) { var msgid = $(e.currentTarget).data('msgid'); ui.hide_actions_popover(); - narrow.by_subject(msgid); + narrow.by_subject(msgid, {trigger: 'popover'}); e.stopPropagation(); }); $('body').on('click', '.popover_narrow_by_recipient_button', function (e) { var msgid = $(e.currentTarget).data('msgid'); ui.hide_actions_popover(); - narrow.by_recipient(msgid); + narrow.by_recipient(msgid, {trigger: 'popover'}); e.stopPropagation(); }); $('body').on('click', '.popover_narrow_by_sender_button', function (e) { var msgid = $(e.currentTarget).data('msgid'); var sender_email = $(e.currentTarget).data('sender_email'); ui.hide_actions_popover(); - narrow.by('sender', sender_email, {then_select_id: msgid}); + narrow.by('sender', sender_email, {then_select_id: msgid, trigger: 'popover'}); e.stopPropagation(); }); $('body').on('click', '.popover_narrow_by_time_travel_button', function (e) { var msgid = $(e.currentTarget).data('msgid'); ui.hide_actions_popover(); - narrow.by_time_travel(msgid); + narrow.by_time_travel(msgid, {trigger: 'popover'}); e.stopPropagation(); }); $('body').on('click', '.popover_toggle_collapse', function (e) { @@ -1415,7 +1415,7 @@ $(function () { $('body').on('click', '.narrow_to_stream', function (e) { var stream = $(e.currentTarget).parents('ul').attr('data-name'); ui.hide_sidebar_popover(); - narrow.by('stream', stream, {select_first_unread: true}); + narrow.by('stream', stream, {select_first_unread: true, trigger: 'sidebar popover'}); e.stopPropagation(); });