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,4 +1,45 @@
$(function () { var alert_words_ui = (function () {
var exports = {};
function update_word_alerts() {
var words = _.map($('.alert-word-item'), function (e) {
return $(e).data('word');
});
words = _.filter(words, function (word) {
return word !== "";
});
channel.post({
url: '/json/set_alert_words',
idempotent: true,
data: {alert_words: JSON.stringify(words)}});
}
function add_alert_word(word, event) {
if (word === '') {
return;
}
var final_li = templates.render('alert_word_settings_item', {'word': word, editing: false});
var li = $(event.target).parent();
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) {
word_list.find('input').focus();
}
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'); var word_list = $('#word-alerts');
_.each(alert_words.words, function (word) { _.each(alert_words.words, function (word) {
var li = templates.render('alert_word_settings_item', {'word': word}); var li = templates.render('alert_word_settings_item', {'word': word});
@@ -7,40 +48,6 @@ $(function () {
var new_word = templates.render('alert_word_settings_item', {'word': '', editing: true}); var new_word = templates.render('alert_word_settings_item', {'word': '', editing: true});
word_list.append(new_word); word_list.append(new_word);
function update_word_alerts() {
var words = _.map($('.alert-word-item'), function (e) {
return $(e).data('word');
});
words = _.filter(words, function (word) {
return word !== "";
});
channel.post({
url: '/json/set_alert_words',
idempotent: true,
data: {alert_words: JSON.stringify(words)}});
}
function add_alert_word(word, event) {
if (word === '') {
return;
}
var final_li = templates.render('alert_word_settings_item', {'word': word, editing: false});
var li = $(event.target).parent();
li.replaceWith(final_li);
var new_word = templates.render('alert_word_settings_item', {'word': '', editing: true});
word_list.append(new_word);
if (word_list.find('input').length > 0) {
word_list.find('input').focus();
}
update_word_alerts();
}
$('#word-alerts').on('click', '.add-alert-word', function (event) { $('#word-alerts').on('click', '.add-alert-word', function (event) {
var word = $(event.target).siblings('input').val(); var word = $(event.target).siblings('input').val();
add_alert_word(word, event); add_alert_word(word, event);
@@ -63,5 +70,7 @@ $(function () {
add_alert_word(word, event); add_alert_word(word, event);
} }
}); });
}); };
return exports;
}());

View File

@@ -30,6 +30,8 @@ exports.setup_page = function () {
$("#notify-settings-status").hide(); $("#notify-settings-status").hide();
$("#ui-settings-status").hide(); $("#ui-settings-status").hide();
alert_words_ui.set_up_alert_words();
$("#api_key_value").text(""); $("#api_key_value").text("");
$("#get_api_key_box").hide(); $("#get_api_key_box").hide();
$("#show_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' + ' compose compose_fade rows hotkeys narrow reload notifications_bar search subs'
+ ' composebox_typeahead server_events typeahead_helper notifications hashchange' + ' composebox_typeahead server_events typeahead_helper notifications hashchange'
+ ' invite ui util activity timerender MessageList MessageListView blueslip unread stream_list' + ' 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' + ' avatar feature_flags search_suggestion referral stream_color Dict'
+ ' Filter summary admin stream_data muting WinChan muting_ui Socket channel' + ' Filter summary admin stream_data muting WinChan muting_ui Socket channel'
+ ' message_flags' + ' message_flags'