frontend: realm_alias to realm_domain migration.

* Change the classes and ids of different widgets and modals
and make suitable changes in `admin.js`.

* Remove any other occurrences of `alias` or `realm_alias`
from admin.js.
This commit is contained in:
Harshit Bansal
2017-03-31 20:40:48 +00:00
committed by Tim Abbott
parent cebcfb8d29
commit 885ec07192
8 changed files with 58 additions and 55 deletions

View File

@@ -97,7 +97,7 @@ function render(template_name, args) {
(function admin_alias_list() {
var html = "<table>";
var args = {
alias: {
realm_domain: {
domain: 'zulip.org',
allow_subdomains: true,
},
@@ -111,7 +111,7 @@ function render(template_name, args) {
var subdomains_checkbox = row.find('.allow-subdomains');
assert.equal(button.text().trim(), "Remove");
assert(button.hasClass("delete_alias"));
assert(button.hasClass("delete_realm_domain"));
assert.equal(domain.text(), "zulip.org");
assert.equal(subdomains_checkbox.prop('checked'), true);

View File

@@ -333,13 +333,13 @@ exports.populate_filters = function (filters_data) {
loading.destroy_indicator($('#admin_page_filters_loading_indicator'));
};
exports.populate_realm_aliases = function (aliases) {
exports.populate_realm_domains = function (realm_domains) {
if (!meta.loaded) {
return;
}
var domains_list = _.map(aliases, function (alias) {
return (alias.allow_subdomains ? "*." + alias.domain : alias.domain);
var domains_list = _.map(realm_domains, function (realm_domain) {
return (realm_domain.allow_subdomains ? "*." + realm_domain.domain : realm_domain.domain);
});
var domains = domains_list.join(', ');
@@ -350,10 +350,10 @@ exports.populate_realm_aliases = function (aliases) {
}
$("#realm_restricted_to_domains_label").text(i18n.t("New users restricted to the following domains: __domains__", {domains: domains}));
var alias_table_body = $("#alias_table tbody").expectOne();
alias_table_body.find("tr").remove();
_.each(aliases, function (alias) {
alias_table_body.append(templates.render("admin-alias-list", {alias: alias}));
var realm_domains_table_body = $("#realm_domains_table tbody").expectOne();
realm_domains_table_body.find("tr").remove();
_.each(realm_domains, function (realm_domain) {
realm_domains_table_body.append(templates.render("admin-alias-list", {realm_domain: realm_domain}));
});
};
@@ -478,8 +478,8 @@ function _setup_page() {
// Populate filters table
exports.populate_filters(page_params.realm_filters);
// Populate realm aliases
exports.populate_realm_aliases(page_params.domains);
// Populate realm domains
exports.populate_realm_domains(page_params.domains);
// Setup click handlers
$(".admin_user_table").on("click", ".deactivate", function (e) {
@@ -1121,55 +1121,58 @@ function _setup_page() {
});
});
$("#alias_table").on("click", ".delete_alias", function () {
$("#realm_domains_table").on("click", ".delete_realm_domain", function () {
var domain = $(this).parents("tr").find(".domain").text();
var url = "/json/realm/domains/" + domain;
var aliases_info = $("#realm_aliases_modal").find(".aliases_info");
var realm_domains_info = $("#realm_domains_modal").find(".realm_domains_info");
channel.del({
url: url,
success: function () {
aliases_info.removeClass("text-error");
aliases_info.addClass("text-success");
aliases_info.text(i18n.t("Deleted successfully!"));
realm_domains_info.removeClass("text-error");
realm_domains_info.addClass("text-success");
realm_domains_info.text(i18n.t("Deleted successfully!"));
},
error: function (xhr) {
aliases_info.removeClass("text-success");
aliases_info.addClass("text-error");
aliases_info.text(JSON.parse(xhr.responseText).msg);
realm_domains_info.removeClass("text-success");
realm_domains_info.addClass("text-error");
realm_domains_info.text(JSON.parse(xhr.responseText).msg);
},
});
});
$("#submit-add-alias").click(function () {
var aliases_info = $("#realm_aliases_modal").find(".aliases_info");
$("#submit-add-realm-domain").click(function () {
var realm_domains_info = $("#realm_domains_modal").find(".realm_domains_info");
var widget = $("#add-realm-domain-widget");
var domain = widget.find(".new-realm-domain").val();
var allow_subdomains = widget.find(".new-realm-domain-allow-subdomains").prop("checked");
var data = {
domain: JSON.stringify($("#add-alias-widget .new-alias-domain").val()),
allow_subdomains: JSON.stringify($("#add-alias-widget .new-alias-allow-subdomains").prop("checked")),
domain: JSON.stringify(domain),
allow_subdomains: JSON.stringify(allow_subdomains),
};
channel.post({
url: "/json/realm/domains",
data: data,
success: function () {
$("#add-alias-widget .new-alias-domain").val("");
$("#add-alias-widget .new-alias-allow-subdomains").prop("checked", false);
$("#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);
aliases_info.removeClass("text-error");
aliases_info.addClass("text-success");
aliases_info.text(i18n.t("Added successfully!"));
realm_domains_info.removeClass("text-error");
realm_domains_info.addClass("text-success");
realm_domains_info.text(i18n.t("Added successfully!"));
},
error: function (xhr) {
aliases_info.removeClass("text-success");
aliases_info.addClass("text-error");
aliases_info.text(JSON.parse(xhr.responseText).msg);
realm_domains_info.removeClass("text-success");
realm_domains_info.addClass("text-error");
realm_domains_info.text(JSON.parse(xhr.responseText).msg);
},
});
});
$("#alias_table").on("change", ".allow-subdomains", function (e) {
$("#realm_domains_table").on("change", ".allow-subdomains", function (e) {
e.stopPropagation();
var aliases_info = $("#realm_aliases_modal").find(".aliases_info");
var realm_domains_info = $("#realm_domains_modal").find(".realm_domains_info");
var domain = $(this).parents("tr").find(".domain").text();
var allow_subdomains = $(this).prop('checked');
var url = '/json/realm/domains/' + domain;
@@ -1181,20 +1184,20 @@ function _setup_page() {
url: url,
data: data,
success: function () {
aliases_info.removeClass("text-error");
aliases_info.addClass("text-success");
realm_domains_info.removeClass("text-error");
realm_domains_info.addClass("text-success");
if (allow_subdomains) {
aliases_info.text(i18n.t("Update successful: Subdomains allowed for __domain__",
realm_domains_info.text(i18n.t("Update successful: Subdomains allowed for __domain__",
{domain: domain}));
} else {
aliases_info.text(i18n.t("Update successful: Subdomains no longer allowed for __domain__",
realm_domains_info.text(i18n.t("Update successful: Subdomains no longer allowed for __domain__",
{domain: domain}));
}
},
error: function (xhr) {
aliases_info.removeClass("text-success");
aliases_info.addClass("text-error");
aliases_info.text(JSON.parse(xhr.responseText).msg);
realm_domains_info.removeClass("text-success");
realm_domains_info.addClass("text-error");
realm_domains_info.text(JSON.parse(xhr.responseText).msg);
},
});
});

View File

@@ -156,7 +156,7 @@ function dispatch_normal_event(event) {
}
}
}
admin.populate_realm_aliases(page_params.domains);
admin.populate_realm_domains(page_params.domains);
break;
case 'realm_user':

View File

@@ -1040,13 +1040,13 @@ input[type=text]#settings_search {
padding: 10px 15px;
}
#administration .new-alias-domain {
#administration .new-realm-domain {
width: 130px;
margin-bottom: auto;
padding: 0px 2px;
}
#administration #submit-add-alias {
#administration #submit-add-realm-domain {
width: 75px;
}

View File

@@ -1,7 +1,7 @@
{{#with alias}}
{{#with realm_domain}}
<tr>
<td class="domain">{{domain}}</td>
<td><input type="checkbox" class="allow-subdomains" {{#if allow_subdomains}}checked{{/if}}></input></td>
<td><button class="btn btn-danger btn-sm delete_alias">{{t "Remove" }}</button></td>
<td><button class="btn btn-danger btn-sm delete_realm_domain">{{t "Remove" }}</button></td>
</tr>
{{/with}}

View File

@@ -35,7 +35,7 @@
title="{{#tr this}}If checked, only users with an e-mail address ending in these domains will be able to join the organization.{{/tr}}">
</label>
{{#if is_admin }}
<a data-toggle="modal" href="#realm_aliases_modal">{{t "[Add or Change]" }}</a>
<a data-toggle="modal" href="#realm_domains_modal">{{t "[Add or Change]" }}</a>
{{/if}}
</div>
<div class="input-group">

View File

@@ -1,10 +1,10 @@
<div id="realm_aliases_modal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="realm_aliases_modal_label" aria-hidden="true">
<div id="realm_domains_modal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="realm_domains_modal_label" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="realm_aliases_modal_label">{{t "Allowed domains" }}</h3>
<h3 id="realm_domains_modal_label">{{t "Allowed domains" }}</h3>
</div>
<div class="modal-body">
<table class="table table-condensed table-stripped" id="alias_table">
<table class="table table-condensed table-stripped" id="realm_domains_table">
<thead>
<th>{{t "Domain" }}</th>
<th>{{t "Allow subdomains"}}</th>
@@ -13,15 +13,15 @@
<tbody>
</tbody>
<tfoot>
<tr id="add-alias-widget">
<td><input type="text" class="new-alias-domain" placeholder="acme.com"></input></td>
<td><input type="checkbox" class="new-alias-allow-subdomains"></input></td>
<td><button type="button" class="btn btn-primary" id="submit-add-alias">{{t "Add" }}</button></td>
<tr id="add-realm-domain-widget">
<td><input type="text" class="new-realm-domain" placeholder="acme.com"></input></td>
<td><input type="checkbox" class="new-realm-domain-allow-subdomains"></input></td>
<td><button type="button" class="btn btn-primary" id="submit-add-realm-domain">{{t "Add" }}</button></td>
</tr>
</tfoot>
</table>
</div>
<div class="modal-footer centered-footer">
<div class="aliases_info"></div>
<div class="realm_domains_info"></div>
</div>
</div>

View File

@@ -480,7 +480,7 @@ def build_custom_checkers(by_lang):
'exclude_line': [('templates/zerver/register.html', 'placeholder="acme"'),
('templates/zerver/register.html', 'placeholder="Acme"'),
('static/templates/settings/realm-domains-modal.handlebars',
'<td><input type="text" class="new-alias-domain" placeholder="acme.com"></input></td>')],
'<td><input type="text" class="new-realm-domain" placeholder="acme.com"></input></td>')],
'exclude': set(["static/templates/settings/emoji-settings-admin.handlebars",
"static/templates/settings/realm-filter-settings-admin.handlebars",
"static/templates/settings/bot-settings.handlebars"])},