Move update_autocomplete into typeahead_helper.

(imported from commit e15446e09869da482dbe554b824ea8bb6f060cf1)
This commit is contained in:
Waseem Daher
2012-11-18 19:09:40 -05:00
parent f9130369f2
commit 57d35649f3
4 changed files with 28 additions and 25 deletions

View File

@@ -13,16 +13,6 @@ var composebox_typeahead = (function () {
var exports = {}; var exports = {};
var autocomplete_needs_update = false;
exports.autocomplete_needs_update = function (needs_update) {
if (needs_update === undefined) {
return autocomplete_needs_update;
} else {
autocomplete_needs_update = needs_update;
}
};
var private_message_typeahead_list = []; var private_message_typeahead_list = [];
var private_message_mapped = {}; var private_message_mapped = {};
@@ -30,14 +20,7 @@ function render_pm_object(person) {
return person.full_name + " <" + person.email + ">"; return person.full_name + " <" + person.email + ">";
} }
exports.update_autocomplete = function () { exports.update_typeahead = function() {
stream_list.sort();
people_list.sort(function (x, y) {
if (x.email === y.email) return 0;
if (x.email < y.email) return -1;
return 1;
});
private_message_mapped = {}; private_message_mapped = {};
private_message_typeahead_list = []; private_message_typeahead_list = [];
$.each(people_list, function (i, obj) { $.each(people_list, function (i, obj) {
@@ -45,8 +28,6 @@ exports.update_autocomplete = function () {
private_message_mapped[label] = obj; private_message_mapped[label] = obj;
private_message_typeahead_list.push(label); private_message_typeahead_list.push(label);
}); });
autocomplete_needs_update = false;
}; };
function get_pm_recipients(query_string) { function get_pm_recipients(query_string) {
@@ -200,7 +181,7 @@ exports.initialize = function () {
$(this).val(recipients.join(", ")); $(this).val(recipients.join(", "));
}); });
composebox_typeahead.update_autocomplete(); typeahead_helper.update_autocomplete();
}; };
return exports; return exports;

View File

@@ -142,7 +142,7 @@ exports.unsubscribe = function (stream) {
ajaxSubscribe(name); ajaxSubscribe(name);
}); });
remove_from_stream_list(name); remove_from_stream_list(name);
composebox_typeahead.update_autocomplete(); typeahead_helper.update_autocomplete();
$("#streams").focus(); $("#streams").focus();
}, },
error: function (xhr) { error: function (xhr) {

View File

@@ -2,6 +2,28 @@ var typeahead_helper = (function () {
var exports = {}; var exports = {};
var autocomplete_needs_update = false;
exports.autocomplete_needs_update = function (needs_update) {
if (needs_update === undefined) {
return autocomplete_needs_update;
} else {
autocomplete_needs_update = needs_update;
}
};
exports.update_autocomplete = function () {
stream_list.sort();
people_list.sort(function (x, y) {
if (x.email === y.email) return 0;
if (x.email < y.email) return -1;
return 1;
});
composebox_typeahead.update_typeahead();
autocomplete_needs_update = false;
};
// Loosely based on Bootstrap's default highlighter, but with escaping added. // Loosely based on Bootstrap's default highlighter, but with escaping added.
exports.highlight_with_escaping = function (query, item) { exports.highlight_with_escaping = function (query, item) {
// query: The text currently in the searchbox // query: The text currently in the searchbox

View File

@@ -434,7 +434,7 @@ function add_message_metadata(dummy, message) {
if (! Object.prototype.hasOwnProperty.call(people_set, person.email)) { if (! Object.prototype.hasOwnProperty.call(people_set, person.email)) {
people_set[person.email] = true; people_set[person.email] = true;
people_list.push(person); people_list.push(person);
composebox_typeahead.autocomplete_needs_update(true); typeahead_helper.autocomplete_needs_update(true);
} }
}); });
@@ -496,8 +496,8 @@ function add_messages(messages, where, add_to_home) {
{then_scroll: true, update_server: false}); {then_scroll: true, update_server: false});
} }
if (composebox_typeahead.autocomplete_needs_update()) { if (typeahead_helper.autocomplete_needs_update()) {
composebox_typeahead.update_autocomplete(); typeahead_helper.update_autocomplete();
} }
} }