From c3a0a226619e0396c3a312b2cdf14ed1828d6998 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 21 Dec 2018 15:45:42 +0000 Subject: [PATCH] slash commands: Add undo for /day and /night. This also works for the synonyms /light and /dark. --- static/js/zcommand.js | 57 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/static/js/zcommand.js b/static/js/zcommand.js index 4fc23f795a..1ac474ce32 100644 --- a/static/js/zcommand.js +++ b/static/js/zcommand.js @@ -31,7 +31,9 @@ exports.send = function (opts) { url: '/json/zcommand', data: data, success: function (data) { - on_success(data); + if (on_success) { + on_success(data); + } }, error: function () { exports.tell_user('server did not respond'); @@ -48,14 +50,47 @@ exports.tell_user = function (msg) { $('#compose-error-msg').text(msg); }; -function update_setting(command) { +exports.enter_day_mode = function () { exports.send({ - command: command, + command: "/day", on_success: function (data) { - exports.tell_user(data.msg); + night_mode.disable(); + feedback_widget.show({ + populate: function (container) { + container.text(data.msg); + }, + on_undo: function () { + exports.send({ + command: "/night", + }); + }, + title_text: i18n.t("Day mode"), + undo_button_text: i18n.t("Night"), + }); }, }); -} +}; + +exports.enter_night_mode = function () { + exports.send({ + command: "/night", + on_success: function (data) { + night_mode.enable(); + feedback_widget.show({ + populate: function (container) { + container.text(data.msg); + }, + on_undo: function () { + exports.send({ + command: "/day", + }); + }, + title_text: i18n.t("Night mode"), + undo_button_text: i18n.t("Day"), + }); + }, + }); +}; exports.process = function (message_content) { @@ -77,9 +112,15 @@ exports.process = function (message_content) { return true; } - var mode_commands = ['/day', '/night', '/light', '/dark']; - if (mode_commands.indexOf(content) >= 0) { - update_setting(content); + var day_commands = ['/day', '/light']; + if (day_commands.indexOf(content) >= 0) { + exports.enter_day_mode(); + return true; + } + + var night_commands = ['/night', '/dark']; + if (night_commands.indexOf(content) >= 0) { + exports.enter_night_mode(); return true; }