org setting: Clean code of realm domain modal.

Remove extra lines for reporting alert messages on modal
and add predefined ui_report functions instead.
This commit is contained in:
YJDave 2017-12-25 22:19:46 +05:30 committed by showell
parent de62e11c23
commit c06028159e
3 changed files with 17 additions and 43 deletions

View File

@ -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('<elem html>', [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('<elem html>', [ev]);
success_callback();
assert.equal(info.text(),
assert.equal(info.val(),
'translated: Update successful: Subdomains no longer allowed for example.com');
}

View File

@ -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);
},
});
});

View File

@ -22,6 +22,6 @@
</table>
</div>
<div class="modal-footer centered-footer">
<div class="realm_domains_info"></div>
<div class="alert realm_domains_info"></div>
</div>
</div>