Unbreak custom alert words on the settings page.

This doesn't change the alerting UI logic, it just turns
alert_words_ui into a module and calls the setup code from settings.js
when the settings page is rendered.

(imported from commit 05f95383b046086641280f82f648be58688efe61)
This commit is contained in:
Jessica McKellar
2014-03-04 17:37:29 -05:00
parent f445202ba5
commit 5f7df38b8a
3 changed files with 48 additions and 37 deletions

View File

@@ -1,11 +1,6 @@
$(function () {
var word_list = $('#word-alerts');
_.each(alert_words.words, function (word) {
var li = templates.render('alert_word_settings_item', {'word': word});
word_list.append(li);
});
var new_word = templates.render('alert_word_settings_item', {'word': '', editing: true});
word_list.append(new_word);
var alert_words_ui = (function () {
var exports = {};
function update_word_alerts() {
var words = _.map($('.alert-word-item'), function (e) {
@@ -32,6 +27,7 @@ $(function () {
li.replaceWith(final_li);
var new_word = templates.render('alert_word_settings_item', {'word': '', editing: true});
var word_list = $('#word-alerts');
word_list.append(new_word);
if (word_list.find('input').length > 0) {
@@ -41,6 +37,17 @@ $(function () {
update_word_alerts();
}
exports.set_up_alert_words = function () {
// The settings page must be rendered before this function gets called.
var word_list = $('#word-alerts');
_.each(alert_words.words, function (word) {
var li = templates.render('alert_word_settings_item', {'word': word});
word_list.append(li);
});
var new_word = templates.render('alert_word_settings_item', {'word': '', editing: true});
word_list.append(new_word);
$('#word-alerts').on('click', '.add-alert-word', function (event) {
var word = $(event.target).siblings('input').val();
add_alert_word(word, event);
@@ -63,5 +70,7 @@ $(function () {
add_alert_word(word, event);
}
});
});
};
return exports;
}());

View File

@@ -30,6 +30,8 @@ exports.setup_page = function () {
$("#notify-settings-status").hide();
$("#ui-settings-status").hide();
alert_words_ui.set_up_alert_words();
$("#api_key_value").text("");
$("#get_api_key_box").hide();
$("#show_api_key_box").hide();

View File

@@ -25,7 +25,7 @@ var globals =
+ ' compose compose_fade rows hotkeys narrow reload notifications_bar search subs'
+ ' composebox_typeahead server_events typeahead_helper notifications hashchange'
+ ' invite ui util activity timerender MessageList MessageListView blueslip unread stream_list'
+ ' message_edit tab_bar emoji popovers navigate people settings message_store'
+ ' message_edit tab_bar emoji popovers navigate people settings alert_words_ui message_store'
+ ' avatar feature_flags search_suggestion referral stream_color Dict'
+ ' Filter summary admin stream_data muting WinChan muting_ui Socket channel'
+ ' message_flags'