settings: Call insert_tip_box from admin.build_page and move it to admin.js.

The organization_settings_tip is not visible if organization settings
overlay is opened with any section other than organization profile,
settings and permissions. This is because insert_tip_box is called from
settings_org.build_page, which is called only when we open any of the
above three sections after opening the overlay and not others.

We should call insert_tip_box function from admin.build_page instead
of settings_org.build_page because we need to insert the admin tips
each time the organization settings overlay is opened, irrespective
of the section which opens first.

The function insert_tip_box is moved to admin.js from settings_org.js,
because settings_org.js file handles the organization profile,
settings and permissions page only, while we display the tips in many
other sections including bots, custom emoji, etc.
Thus, it makes sense to move insert_tip_box function to admin.js, which
renders the complete organization settings overlay using render_admin_tab.
This commit is contained in:
sahil839 2020-06-28 19:57:54 +05:30 committed by Tim Abbott
parent 166314de78
commit 65168c36dc
3 changed files with 15 additions and 26 deletions

View File

@ -91,17 +91,6 @@ run_test('unloaded', () => {
settings_org.populate_auth_methods(); settings_org.populate_auth_methods();
}); });
function simulate_tip_box() {
const non_editables = $.create('auth-methods-not-edit-stub');
$('.organization-box').set_find_results(
'.settings-section:not(.can-edit)',
non_editables
);
non_editables.not = function () { return this; };
non_editables.prepend = noop;
}
function simulate_realm_domains_table() { function simulate_realm_domains_table() {
$('#realm_domains_table tbody').set_find_results( $('#realm_domains_table tbody').set_find_results(
'tr', 'tr',
@ -764,7 +753,6 @@ run_test('set_up', () => {
name: "Big Blue Button", name: "Big Blue Button",
}, },
}; };
simulate_tip_box();
$('#id_realm_video_chat_provider').change = set_callback('realm_video_chat_provider'); $('#id_realm_video_chat_provider').change = set_callback('realm_video_chat_provider');
$("#id_realm_org_join_restrictions").change = set_callback('change_org_join_restrictions'); $("#id_realm_org_join_restrictions").change = set_callback('change_org_join_restrictions');

View File

@ -1,6 +1,7 @@
const settings_config = require("./settings_config"); const settings_config = require("./settings_config");
const settings_data = require("./settings_data"); const settings_data = require("./settings_data");
const render_admin_tab = require('../templates/admin_tab.hbs'); const render_admin_tab = require('../templates/admin_tab.hbs');
const render_settings_organization_settings_tip = require("../templates/settings/organization_settings_tip.hbs");
const admin_settings_label = { const admin_settings_label = {
// Organization settings // Organization settings
@ -24,6 +25,18 @@ const admin_settings_label = {
realm_avatar_changes_disabled: i18n.t("Prevent users from changing their avatar"), realm_avatar_changes_disabled: i18n.t("Prevent users from changing their avatar"),
}; };
function insert_tip_box() {
if (page_params.is_admin) {
return;
}
const tip_box = render_settings_organization_settings_tip({is_admin: page_params.is_admin});
$(".organization-box").find(".settings-section:not(.can-edit)")
.not("#emoji-settings")
.not("#user-groups-admin")
.not("#organization-auth-settings")
.prepend(tip_box);
}
exports.build_page = function () { exports.build_page = function () {
const options = { const options = {
custom_profile_field_types: page_params.custom_profile_field_types, custom_profile_field_types: page_params.custom_profile_field_types,
@ -101,6 +114,8 @@ exports.build_page = function () {
$("#settings_content .alert").removeClass("show"); $("#settings_content .alert").removeClass("show");
settings_bots.update_bot_settings_tip(); settings_bots.update_bot_settings_tip();
insert_tip_box();
$("#id_realm_bot_creation_policy").val(page_params.realm_bot_creation_policy); $("#id_realm_bot_creation_policy").val(page_params.realm_bot_creation_policy);
$("#id_realm_email_address_visibility").val(page_params.realm_email_address_visibility); $("#id_realm_email_address_visibility").val(page_params.realm_email_address_visibility);

View File

@ -1,7 +1,6 @@
const settings_config = require("./settings_config"); const settings_config = require("./settings_config");
const render_settings_admin_auth_methods_list = require('../templates/settings/admin_auth_methods_list.hbs'); const render_settings_admin_auth_methods_list = require('../templates/settings/admin_auth_methods_list.hbs');
const render_settings_admin_realm_domains_list = require("../templates/settings/admin_realm_domains_list.hbs"); const render_settings_admin_realm_domains_list = require("../templates/settings/admin_realm_domains_list.hbs");
const render_settings_organization_settings_tip = require("../templates/settings/organization_settings_tip.hbs");
const pygments_data = require("../generated/pygments_data.json"); const pygments_data = require("../generated/pygments_data.json");
const meta = { const meta = {
@ -311,18 +310,6 @@ exports.populate_auth_methods = function (auth_methods) {
auth_methods_table.html(rendered_auth_method_rows); auth_methods_table.html(rendered_auth_method_rows);
}; };
function insert_tip_box() {
if (page_params.is_admin) {
return;
}
const tip_box = render_settings_organization_settings_tip({is_admin: page_params.is_admin});
$(".organization-box").find(".settings-section:not(.can-edit)")
.not("#emoji-settings")
.not("#user-groups-admin")
.not("#organization-auth-settings")
.prepend(tip_box);
}
function update_dependent_subsettings(property_name) { function update_dependent_subsettings(property_name) {
if (simple_dropdown_properties.includes(property_name)) { if (simple_dropdown_properties.includes(property_name)) {
set_property_dropdown_value(property_name); set_property_dropdown_value(property_name);
@ -614,7 +601,6 @@ exports.build_page = function () {
// Populate authentication methods table // Populate authentication methods table
exports.populate_auth_methods(page_params.realm_authentication_methods); exports.populate_auth_methods(page_params.realm_authentication_methods);
insert_tip_box();
simple_dropdown_properties.forEach(set_property_dropdown_value); simple_dropdown_properties.forEach(set_property_dropdown_value);