From 35342481dcfec7634470bcedc9b17db3e3bfb697 Mon Sep 17 00:00:00 2001 From: Zev Benjamin Date: Fri, 12 Oct 2012 13:14:59 -0400 Subject: [PATCH] Scope subject autocomplete to the stream (imported from commit 6e9972c93d5f56f29db37b522e20768b8fb641df) --- tools/jslint/check-all.js | 2 +- zephyr/static/js/ui.js | 9 +++++++-- zephyr/static/js/zephyr.js | 13 +++++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/tools/jslint/check-all.js b/tools/jslint/check-all.js index 072f1f8585..56f6833a47 100644 --- a/tools/jslint/check-all.js +++ b/tools/jslint/check-all.js @@ -38,7 +38,7 @@ var globals = // zephyr.js + ' message_array message_dict' - + ' status_classes clear_table add_to_table subject_list' + + ' status_classes clear_table add_to_table subject_dict' + ' keep_pointer_in_view move_pointer_at_page_top_and_bottom' + ' respond_to_message' + ' select_message select_message_by_id' diff --git a/zephyr/static/js/ui.js b/zephyr/static/js/ui.js index 3c7da92246..2d6ba94f21 100644 --- a/zephyr/static/js/ui.js +++ b/zephyr/static/js/ui.js @@ -112,7 +112,6 @@ var autocomplete_needs_update = false; function update_autocomplete() { stream_list.sort(); - subject_list.sort(); people_list.sort(); var huddle_typeahead_list = $.map(people_list, function (person) { @@ -125,7 +124,13 @@ function update_autocomplete() { items: 3 }); $( "#subject" ).typeahead({ - source: subject_list, + source: function (query, process) { + var stream_name = $("#stream").val(); + if (subject_dict.hasOwnProperty(stream_name)) { + return subject_dict[stream_name]; + } + return []; + }, items: 2 }); $( "#huddle_recipient" ).typeahead({ diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index e74536e9bf..95b56bf3b3 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -1,6 +1,6 @@ var message_array = []; var message_dict = {}; -var subject_list = []; +var subject_dict = {}; $(function () { var i; @@ -368,9 +368,14 @@ function add_message_metadata(dummy, message) { switch (message.type) { case 'stream': message.is_stream = true; - if ($.inArray(message.subject, subject_list) === -1) { - subject_list.push(message.subject); - autocomplete_needs_update = true; + if (! subject_dict.hasOwnProperty(message.display_recipient)) { + subject_dict[message.display_recipient] = []; + } + if ($.inArray(message.subject, subject_dict[message.display_recipient]) === -1) { + subject_dict[message.display_recipient].push(message.subject); + subject_dict[message.display_recipient].sort(); + // We don't need to update the autocomplete after this because + // the subject box's source is a function } message.reply_to = message.sender_email;