From c06028159eae66137e60d37dc193ed80be065ab0 Mon Sep 17 00:00:00 2001 From: YJDave Date: Mon, 25 Dec 2017 22:19:46 +0530 Subject: [PATCH] org setting: Clean code of realm domain modal. Remove extra lines for reporting alert messages on modal and add predefined ui_report functions instead. --- frontend_tests/node_tests/settings_org.js | 28 +++++------------ static/js/settings_org.js | 30 ++++++------------- .../settings/realm-domains-modal.handlebars | 2 +- 3 files changed, 17 insertions(+), 43 deletions(-) diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js index 62be2124ca..bf490e7183 100644 --- a/frontend_tests/node_tests/settings_org.js +++ b/frontend_tests/node_tests/settings_org.js @@ -140,18 +140,10 @@ function test_realms_domain_modal(add_realm_domain) { assert(posted); success_callback(); - assert(!info.hasClass('text-error')); - assert(info.hasClass('text-success')); - assert.equal(info.text(), 'translated: Added successfully!'); + assert.equal(info.val(), 'translated: Added successfully!'); - var xhr = { - responseText: '{"msg": "no can do"}', - }; - - error_callback(xhr); - assert(info.hasClass('text-error')); - assert(!info.hasClass('text-success')); - assert.equal(info.text(), 'no can do'); + error_callback({}); + assert.equal(info.val(), 'translated: Failed'); } function test_submit_profile_form(submit_form) { @@ -449,23 +441,17 @@ function test_change_allow_subdomains(change_allow_subdomains) { change_allow_subdomains.apply('', [ev]); success_callback(); - assert.equal(info.text(), + assert.equal(info.val(), 'translated: Update successful: Subdomains allowed for example.com'); - assert(info.hasClass('text-success')); - var xhr = { - responseText: '{"msg": "no can do"}', - }; - - error_callback(xhr); - assert(info.hasClass('text-error')); - assert.equal(info.text(), 'no can do'); + error_callback({}); + assert.equal(info.val(), 'translated: Failed'); allow = false; elem_obj.prop('checked', allow); change_allow_subdomains.apply('', [ev]); success_callback(); - assert.equal(info.text(), + assert.equal(info.val(), 'translated: Update successful: Subdomains no longer allowed for example.com'); } diff --git a/static/js/settings_org.js b/static/js/settings_org.js index 0d809d29b1..04e154beef 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -617,14 +617,10 @@ function _set_up() { channel.del({ url: url, success: function () { - realm_domains_info.removeClass("text-error"); - realm_domains_info.addClass("text-success"); - realm_domains_info.text(i18n.t("Deleted successfully!")); + ui_report.success(i18n.t("Deleted successfully!"), realm_domains_info); }, error: function (xhr) { - realm_domains_info.removeClass("text-success"); - realm_domains_info.addClass("text-error"); - realm_domains_info.text(JSON.parse(xhr.responseText).msg); + ui_report.error(i18n.t("Failed"), xhr, realm_domains_info); }, }); }); @@ -646,14 +642,10 @@ function _set_up() { $("#add-realm-domain-widget .new-realm-domain").val(""); $("#add-realm-domain-widget .new-realm-domain-allow-subdomains").prop("checked", false); $("#id_realm_restricted_to_domain").prop("disabled", false); - realm_domains_info.removeClass("text-error"); - realm_domains_info.addClass("text-success"); - realm_domains_info.text(i18n.t("Added successfully!")); + ui_report.success(i18n.t("Added successfully!"), realm_domains_info); }, error: function (xhr) { - realm_domains_info.removeClass("text-success"); - realm_domains_info.addClass("text-error"); - realm_domains_info.text(JSON.parse(xhr.responseText).msg); + ui_report.error(i18n.t("Failed"), xhr, realm_domains_info); }, }); }); @@ -672,20 +664,16 @@ function _set_up() { url: url, data: data, success: function () { - realm_domains_info.removeClass("text-error"); - realm_domains_info.addClass("text-success"); if (allow_subdomains) { - realm_domains_info.text(i18n.t("Update successful: Subdomains allowed for __domain__", - {domain: domain})); + ui_report.success(i18n.t("Update successful: Subdomains allowed for __domain__", + {domain: domain}), realm_domains_info); } else { - realm_domains_info.text(i18n.t("Update successful: Subdomains no longer allowed for __domain__", - {domain: domain})); + ui_report.success(i18n.t("Update successful: Subdomains no longer allowed for __domain__", + {domain: domain}), realm_domains_info); } }, error: function (xhr) { - realm_domains_info.removeClass("text-success"); - realm_domains_info.addClass("text-error"); - realm_domains_info.text(JSON.parse(xhr.responseText).msg); + ui_report.error(i18n.t("Failed"), xhr, realm_domains_info); }, }); }); diff --git a/static/templates/settings/realm-domains-modal.handlebars b/static/templates/settings/realm-domains-modal.handlebars index 3f956a7024..8cbefc9b37 100644 --- a/static/templates/settings/realm-domains-modal.handlebars +++ b/static/templates/settings/realm-domains-modal.handlebars @@ -22,6 +22,6 @@