mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 17:36:27 +00:00
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:
@@ -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');
|
||||
_.each(alert_words.words, function (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});
|
||||
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) {
|
||||
var word = $(event.target).siblings('input').val();
|
||||
add_alert_word(word, event);
|
||||
@@ -63,5 +70,7 @@ $(function () {
|
||||
add_alert_word(word, event);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return exports;
|
||||
}());
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user