mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	org settings: Change message_edit settings to dropdown.
This coverts the "checkbox" for `realm_allow_message_editing` and "input" for `realm_message_content_edit_limit_seconds` into a dropdown with the option for custom time limit option.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							8e38b8462b
						
					
				
				
					commit
					f19b0b3254
				
			@@ -6,22 +6,6 @@ function heading(heading_str) {
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function submit_checked() {
 | 
			
		||||
    casper.then(function () {
 | 
			
		||||
        casper.waitUntilVisible('input:checked[type="checkbox"][id="id_realm_allow_message_editing"] + span', function () {
 | 
			
		||||
            casper.click('#org-submit-msg-editing');
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function submit_unchecked() {
 | 
			
		||||
    casper.then(function () {
 | 
			
		||||
        casper.waitUntilVisible('input:not(:checked)[type="checkbox"][id="id_realm_allow_message_editing"] + span', function () {
 | 
			
		||||
            casper.click('#org-submit-msg-editing');
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
common.start_and_log_in();
 | 
			
		||||
 | 
			
		||||
// For clarity these should be different than what 08-edit uses, until
 | 
			
		||||
@@ -94,23 +78,34 @@ casper.then(function () {
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
function submit_edit_limit_changed() {
 | 
			
		||||
    casper.test.assertSelectorHasText('#org-submit-msg-editing', "Save");
 | 
			
		||||
    casper.click('#org-submit-msg-editing');
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DEACTIVATE
 | 
			
		||||
 | 
			
		||||
heading("DEACTIVATE");
 | 
			
		||||
common.then_click("li[data-section='organization-settings']");
 | 
			
		||||
 | 
			
		||||
// deactivate "allow message editing"
 | 
			
		||||
common.then_click('input[type="checkbox"][id="id_realm_allow_message_editing"] + span');
 | 
			
		||||
 | 
			
		||||
submit_unchecked();
 | 
			
		||||
casper.then(function () {
 | 
			
		||||
    casper.test.info("Changing message edit limit setting");
 | 
			
		||||
    casper.waitUntilVisible("#id_realm_msg_edit_limit_setting", function () {
 | 
			
		||||
        casper.evaluate(function () {
 | 
			
		||||
            $("#id_realm_msg_edit_limit_setting").val("never").change();
 | 
			
		||||
        });
 | 
			
		||||
        submit_edit_limit_changed();
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
casper.then(function () {
 | 
			
		||||
    casper.waitUntilVisible('#org-submit-msg-editing[data-status="saved"]', function () {
 | 
			
		||||
        casper.test.assertSelectorHasText('#org-submit-msg-editing',
 | 
			
		||||
                                          'Saved');
 | 
			
		||||
        casper.test.assertEval(function () {
 | 
			
		||||
            return !(document.querySelector('input[type="checkbox"][id="id_realm_allow_message_editing"]').checked);
 | 
			
		||||
        }, 'Allow message editing Setting de-activated');
 | 
			
		||||
            return (document.querySelector('#id_realm_msg_edit_limit_setting').value === "never");
 | 
			
		||||
        }, 'Message editing Setting disabled');
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@@ -155,76 +150,47 @@ heading("REACTIVATE");
 | 
			
		||||
common.then_click('#settings-dropdown');
 | 
			
		||||
common.then_click('a[href^="#organization"]');
 | 
			
		||||
common.then_click("li[data-section='organization-settings']");
 | 
			
		||||
common.then_click('input[type="checkbox"][id="id_realm_allow_message_editing"] + span');
 | 
			
		||||
submit_checked();
 | 
			
		||||
 | 
			
		||||
casper.then(function () {
 | 
			
		||||
    casper.waitUntilVisible('#org-submit-msg-editing[data-status="saved"]', function () {
 | 
			
		||||
        casper.test.assertSelectorHasText('#org-submit-msg-editing',
 | 
			
		||||
                                          'Saved');
 | 
			
		||||
        casper.test.assertEval(function () {
 | 
			
		||||
            return document.querySelector('input[type="checkbox"][id="id_realm_allow_message_editing"]').checked;
 | 
			
		||||
        }, 'Allow message editing Setting re-activated');
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// DEACTIVATE
 | 
			
		||||
 | 
			
		||||
heading("DEACTIVATE");
 | 
			
		||||
 | 
			
		||||
// go to admin page
 | 
			
		||||
casper.then(function () {
 | 
			
		||||
    casper.test.info('Organization page');
 | 
			
		||||
    casper.click('a[href^="#organization"]');
 | 
			
		||||
    casper.test.assertUrlMatch(/^http:\/\/[^\/]+\/#organization/, 'URL suggests we are on organization page');
 | 
			
		||||
    casper.test.assertExists('#settings_overlay_container.show', 'Organization page is active');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
casper.then(function () {
 | 
			
		||||
    casper.waitUntilVisible('form.admin-realm-form button.button');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// deactivate message editing
 | 
			
		||||
casper.then(function () {
 | 
			
		||||
    casper.waitUntilVisible('input[type="checkbox"][id="id_realm_allow_message_editing"] + span', function () {
 | 
			
		||||
    casper.test.info("Changing message edit limit setting");
 | 
			
		||||
    casper.waitUntilVisible("#id_realm_msg_edit_limit_setting", function () {
 | 
			
		||||
        casper.evaluate(function () {
 | 
			
		||||
            $('input[type="text"][id="id_realm_message_content_edit_limit_minutes"]').val('4');
 | 
			
		||||
            $("#id_realm_msg_edit_limit_setting").val("upto_ten_min").change();
 | 
			
		||||
        });
 | 
			
		||||
        submit_edit_limit_changed();
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
common.then_click('input[type="checkbox"][id="id_realm_allow_message_editing"] + span');
 | 
			
		||||
submit_unchecked();
 | 
			
		||||
 | 
			
		||||
casper.then(function () {
 | 
			
		||||
    casper.waitUntilVisible('#org-submit-msg-editing[data-status="saved"]', function () {
 | 
			
		||||
        casper.test.assertSelectorHasText('#org-submit-msg-editing',
 | 
			
		||||
                                          'Saved');
 | 
			
		||||
        casper.test.assertEval(function () {
 | 
			
		||||
            return !(document.querySelector('input[type="checkbox"][id="id_realm_allow_message_editing"]').checked);
 | 
			
		||||
        }, 'Allow message editing Setting de-activated');
 | 
			
		||||
        casper.test.assertEval(function () {
 | 
			
		||||
            return $('input[type="text"][id="id_realm_message_content_edit_limit_minutes"]').val() === '4';
 | 
			
		||||
        }, 'Message content edit limit now 4');
 | 
			
		||||
            return (document.querySelector('#id_realm_msg_edit_limit_setting').value === "upto_ten_min");
 | 
			
		||||
        }, 'Allow message editing Setting re-activated and set to 10 minutes');
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// REACTIVATE
 | 
			
		||||
heading("REACTIVATE");
 | 
			
		||||
// SET LIMIT TO 1 WEEK
 | 
			
		||||
heading("LIMIT TO 1 WEEK");
 | 
			
		||||
 | 
			
		||||
common.then_click('input[type="checkbox"][id="id_realm_allow_message_editing"] + span');
 | 
			
		||||
submit_checked();
 | 
			
		||||
casper.then(function () {
 | 
			
		||||
    casper.test.info("Changing message edit limit setting");
 | 
			
		||||
    casper.waitUntilVisible("#id_realm_msg_edit_limit_setting", function () {
 | 
			
		||||
        casper.evaluate(function () {
 | 
			
		||||
            $("#id_realm_msg_edit_limit_setting").val("upto_one_week").change();
 | 
			
		||||
        });
 | 
			
		||||
        submit_edit_limit_changed();
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
casper.then(function () {
 | 
			
		||||
    casper.waitUntilVisible('#org-submit-msg-editing[data-status="saved"]', function () {
 | 
			
		||||
        casper.test.assertSelectorHasText('#org-submit-msg-editing',
 | 
			
		||||
                                          'Saved');
 | 
			
		||||
        casper.test.assertEval(function () {
 | 
			
		||||
            return document.querySelector('input[type="checkbox"][id="id_realm_allow_message_editing"]').checked;
 | 
			
		||||
        }, 'Allow message editing Setting activated');
 | 
			
		||||
        casper.test.assertEval(function () {
 | 
			
		||||
            return $('input[type="text"][id="id_realm_message_content_edit_limit_minutes"]').val() === '4';
 | 
			
		||||
        }, 'Message content edit limit still 4');
 | 
			
		||||
            return (document.querySelector('#id_realm_msg_edit_limit_setting').value === "upto_one_week");
 | 
			
		||||
        }, 'Message edit limit set to one week');
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@@ -232,52 +198,78 @@ casper.then(function () {
 | 
			
		||||
heading("NO LIMIT");
 | 
			
		||||
 | 
			
		||||
casper.then(function () {
 | 
			
		||||
    // allow arbitrary message editing
 | 
			
		||||
    casper.waitUntilVisible('input[type="checkbox"][id="id_realm_allow_message_editing"] + span', function () {
 | 
			
		||||
    casper.test.info("Changing message edit limit setting");
 | 
			
		||||
    casper.waitUntilVisible("#id_realm_msg_edit_limit_setting", function () {
 | 
			
		||||
        casper.evaluate(function () {
 | 
			
		||||
            $('input[type="text"][id="id_realm_message_content_edit_limit_minutes"]').val('0');
 | 
			
		||||
            $("#id_realm_msg_edit_limit_setting").val("any_time").change();
 | 
			
		||||
        });
 | 
			
		||||
        submit_edit_limit_changed();
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
submit_checked();
 | 
			
		||||
 | 
			
		||||
casper.then(function () {
 | 
			
		||||
    casper.waitUntilVisible('#org-submit-msg-editing[data-status="saved"]', function () {
 | 
			
		||||
        casper.test.assertSelectorHasText('#org-submit-msg-editing',
 | 
			
		||||
                                          'Saved');
 | 
			
		||||
        casper.test.assertEval(function () {
 | 
			
		||||
            return document.querySelector('input[type="checkbox"][id="id_realm_allow_message_editing"]').checked;
 | 
			
		||||
        }, 'Allow message editing Setting still activated');
 | 
			
		||||
        casper.test.assertEval(function () {
 | 
			
		||||
            return $('input[type="text"][id="id_realm_message_content_edit_limit_minutes"]').val() === '0';
 | 
			
		||||
        }, 'Message content edit limit is 0');
 | 
			
		||||
            return (document.querySelector('#id_realm_msg_edit_limit_setting').value === "any_time");
 | 
			
		||||
        }, 'Message can be edited any time');
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// ILLEGAL LIMIT
 | 
			
		||||
heading("ILLEGAL LIMIT");
 | 
			
		||||
// CUSTOM LIMIT
 | 
			
		||||
heading("CUSTOM LIMIT");
 | 
			
		||||
 | 
			
		||||
casper.then(function () {
 | 
			
		||||
    // disallow message editing, with illegal edit limit value. should be fixed by admin.js
 | 
			
		||||
    casper.waitUntilVisible('input[type="checkbox"][id="id_realm_allow_message_editing"] + span', function () {
 | 
			
		||||
    casper.test.info("Changing message edit limit setting");
 | 
			
		||||
    casper.waitUntilVisible("#id_realm_msg_edit_limit_setting", function () {
 | 
			
		||||
        casper.evaluate(function () {
 | 
			
		||||
            $('input[type="text"][id="id_realm_message_content_edit_limit_minutes"]').val('moo');
 | 
			
		||||
            $("#id_realm_msg_edit_limit_setting").val("custom_limit").change();
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
    casper.waitUntilVisible('#id_realm_message_content_edit_limit_minutes', function () {
 | 
			
		||||
        casper.evaluate(function () {
 | 
			
		||||
            $('#id_realm_message_content_edit_limit_minutes').val("100");
 | 
			
		||||
        });
 | 
			
		||||
        submit_edit_limit_changed();
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
common.then_click('input[type="checkbox"][id="id_realm_allow_message_editing"] + span');
 | 
			
		||||
submit_unchecked();
 | 
			
		||||
 | 
			
		||||
casper.then(function () {
 | 
			
		||||
    casper.waitUntilVisible('#org-submit-msg-editing[data-status="saved"]', function () {
 | 
			
		||||
        casper.test.assertSelectorHasText('#org-submit-msg-editing',
 | 
			
		||||
                                          'Saved');
 | 
			
		||||
        casper.test.assertEval(function () {
 | 
			
		||||
            return !(document.querySelector('input[type="checkbox"][id="id_realm_allow_message_editing"]').checked);
 | 
			
		||||
        }, 'Allow message editing Setting de-activated');
 | 
			
		||||
            return $('#id_realm_msg_edit_limit_setting').val() === "custom_limit";
 | 
			
		||||
        }, 'Custom message edit limit set');
 | 
			
		||||
        casper.test.assertEval(function () {
 | 
			
		||||
            return $('input[type="text"][id="id_realm_message_content_edit_limit_minutes"]').val() === '10';
 | 
			
		||||
        }, 'Message content edit limit has been reset to its default');
 | 
			
		||||
            return $('#id_realm_message_content_edit_limit_minutes').val() === "100";
 | 
			
		||||
        }, 'Message edit limit set to 100 minutes');
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// INVALID LIMIT
 | 
			
		||||
heading("INVALID LIMIT");
 | 
			
		||||
 | 
			
		||||
casper.then(function () {
 | 
			
		||||
    casper.test.info("Changing message edit limit setting");
 | 
			
		||||
    casper.waitUntilVisible("#id_realm_msg_edit_limit_setting", function () {
 | 
			
		||||
        casper.evaluate(function () {
 | 
			
		||||
            $("#id_realm_msg_edit_limit_setting").val("custom_limit").change();
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
    casper.waitUntilVisible('#id_realm_message_content_edit_limit_minutes', function () {
 | 
			
		||||
        casper.evaluate(function () {
 | 
			
		||||
            $('#id_realm_message_content_edit_limit_minutes').val("-100");
 | 
			
		||||
        });
 | 
			
		||||
        submit_edit_limit_changed();
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
casper.then(function () {
 | 
			
		||||
    casper.waitUntilVisible('.admin-realm-failed-change-status', function () {
 | 
			
		||||
        casper.test.assertSelectorHasText('#org-submit-msg-editing',
 | 
			
		||||
                                          'Save');
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -316,20 +316,6 @@ function test_upload_realm_icon(upload_realm_icon) {
 | 
			
		||||
    assert(posted);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function test_change_message_editing(change_message_editing) {
 | 
			
		||||
    var parent_elem = $.create('editing-parent-stub');
 | 
			
		||||
 | 
			
		||||
    $('#id_realm_message_content_edit_limit_minutes_label').set_parent(parent_elem);
 | 
			
		||||
 | 
			
		||||
    change_message_editing.apply({checked: false});
 | 
			
		||||
    assert(parent_elem.hasClass('control-label-disabled'));
 | 
			
		||||
    assert.equal($('#id_realm_message_content_edit_limit_minutes').attr('disabled'), 'disabled');
 | 
			
		||||
 | 
			
		||||
    change_message_editing.apply({checked: true});
 | 
			
		||||
    assert(!parent_elem.hasClass('control-label-disabled'));
 | 
			
		||||
    assert.equal($('#id_realm_message_content_edit_limit_minutes').attr('disabled'), false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function test_change_invite_required(change_invite_required) {
 | 
			
		||||
    var parent_elem = $.create('invite-parent-stub');
 | 
			
		||||
 | 
			
		||||
@@ -496,7 +482,6 @@ function test_sync_realm_settings() {
 | 
			
		||||
    $('#id_realm_video_chat_provider').change = set_callback('realm_video_chat_provider');
 | 
			
		||||
    $('#id_realm_invite_required').change = set_callback('change_invite_required');
 | 
			
		||||
    $('#id_realm_restricted_to_domain').change = set_callback('id_realm_restricted_to_domain');
 | 
			
		||||
    $('#id_realm_allow_message_editing').change = set_callback('change_message_editing');
 | 
			
		||||
    $('#submit-add-realm-domain').click = set_callback('add_realm_domain');
 | 
			
		||||
    $('.notifications-stream-disable').click = set_callback('disable_notifications_stream');
 | 
			
		||||
    $('.signup-notifications-stream-disable').click = set_callback('disable_signup_notifications_stream');
 | 
			
		||||
@@ -524,6 +509,8 @@ function test_sync_realm_settings() {
 | 
			
		||||
 | 
			
		||||
    var stub_render_notifications_stream_ui = settings_org.render_notifications_stream_ui;
 | 
			
		||||
    settings_org.render_notifications_stream_ui = noop;
 | 
			
		||||
    $("#id_realm_message_content_edit_limit_minutes").set_parent($.create('<stub edit limit parent>'));
 | 
			
		||||
    $("#id_realm_msg_edit_limit_setting").change = noop;
 | 
			
		||||
    var parent_elem = $.create('waiting-period-parent-stub');
 | 
			
		||||
    $('#id_realm_waiting_period_threshold').set_parent(parent_elem);
 | 
			
		||||
    // TEST set_up() here, but this mostly just allows us to
 | 
			
		||||
@@ -536,7 +523,6 @@ function test_sync_realm_settings() {
 | 
			
		||||
    test_submit_settings_form(submit_settings_form);
 | 
			
		||||
    test_upload_realm_icon(upload_realm_icon);
 | 
			
		||||
    test_change_invite_required(callbacks.change_invite_required);
 | 
			
		||||
    test_change_message_editing(callbacks.change_message_editing);
 | 
			
		||||
    test_disable_notifications_stream(callbacks.disable_notifications_stream);
 | 
			
		||||
    test_disable_signup_notifications_stream(callbacks.disable_signup_notifications_stream);
 | 
			
		||||
    test_change_allow_subdomains(change_allow_subdomains);
 | 
			
		||||
 
 | 
			
		||||
@@ -82,6 +82,7 @@ function _setup_page() {
 | 
			
		||||
        realm_email_changes_disabled : i18n.t("Prevent users from changing their email address"),
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    options.msg_edit_limit_dropdown_values = settings_org.msg_edit_limit_dropdown_values;
 | 
			
		||||
    options.bot_creation_policy_values = settings_bots.bot_creation_policy_values;
 | 
			
		||||
    var rendered_admin_tab = templates.render('admin_tab', options);
 | 
			
		||||
    $("#settings_content .organization-box").html(rendered_admin_tab);
 | 
			
		||||
 
 | 
			
		||||
@@ -122,6 +122,17 @@ function get_property_value(property_name) {
 | 
			
		||||
            return "by_admins_only";
 | 
			
		||||
        }
 | 
			
		||||
        return "by_anyone";
 | 
			
		||||
    } else if (property_name === 'realm_msg_edit_limit_setting') {
 | 
			
		||||
        if (!page_params.realm_allow_message_editing) {
 | 
			
		||||
            return "never";
 | 
			
		||||
        }
 | 
			
		||||
        var value = _.findKey(exports.msg_edit_limit_dropdown_values, function (elem) {
 | 
			
		||||
            return elem.seconds === page_params.realm_message_content_edit_limit_seconds;
 | 
			
		||||
        });
 | 
			
		||||
        if (value === undefined) {
 | 
			
		||||
            return "custom_limit";
 | 
			
		||||
        }
 | 
			
		||||
        return value;
 | 
			
		||||
    }
 | 
			
		||||
    return page_params[property_name];
 | 
			
		||||
}
 | 
			
		||||
@@ -155,6 +166,51 @@ function set_video_chat_provider_dropdown() {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.setup_msg_edit_limit_dropdown_values = function () {
 | 
			
		||||
    exports.msg_edit_limit_dropdown_values = {
 | 
			
		||||
        any_time: {
 | 
			
		||||
            text: i18n.t("Any time"),
 | 
			
		||||
            seconds: 0,
 | 
			
		||||
        },
 | 
			
		||||
        never: {
 | 
			
		||||
            text: i18n.t("Never"),
 | 
			
		||||
        },
 | 
			
		||||
        upto_two_min: {
 | 
			
		||||
            text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("2 minutes")}),
 | 
			
		||||
            seconds: 2*60,
 | 
			
		||||
        },
 | 
			
		||||
        upto_ten_min: {
 | 
			
		||||
            text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("10 minutes")}),
 | 
			
		||||
            seconds: 10*60,
 | 
			
		||||
        },
 | 
			
		||||
        upto_one_hour: {
 | 
			
		||||
            text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("1 hour")}),
 | 
			
		||||
            seconds: 60*60,
 | 
			
		||||
        },
 | 
			
		||||
        upto_one_day: {
 | 
			
		||||
            text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("1 day")}),
 | 
			
		||||
            seconds: 24*60*60,
 | 
			
		||||
        },
 | 
			
		||||
        upto_one_week: {
 | 
			
		||||
            text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("1 week")}),
 | 
			
		||||
            seconds: 7*24*60*60,
 | 
			
		||||
        },
 | 
			
		||||
        custom_limit: {
 | 
			
		||||
            text: i18n.t("Custom time limit after posting"),
 | 
			
		||||
        },
 | 
			
		||||
    };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
function set_msg_edit_limit_dropdown() {
 | 
			
		||||
    var value = get_property_value("realm_msg_edit_limit_setting");
 | 
			
		||||
    $("#id_realm_msg_edit_limit_setting").val(value);
 | 
			
		||||
    if (value === "custom_limit") {
 | 
			
		||||
        $("#id_realm_message_content_edit_limit_minutes").parent().show();
 | 
			
		||||
    } else {
 | 
			
		||||
        $("#id_realm_message_content_edit_limit_minutes").parent().hide();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.populate_realm_domains = function (realm_domains) {
 | 
			
		||||
    if (!meta.loaded) {
 | 
			
		||||
        return;
 | 
			
		||||
@@ -301,6 +357,8 @@ function update_dependent_subsettings(property_name) {
 | 
			
		||||
            "id_realm_disallow_disposable_email_addresses", false);
 | 
			
		||||
    } else if (property_name === 'realm_video_chat_provider' || property_name === 'realm_google_hangouts_domain') {
 | 
			
		||||
        set_video_chat_provider_dropdown();
 | 
			
		||||
    } else if (property_name === 'realm_msg_edit_limit_setting' || property_name === 'realm_message_content_edit_limit_minutes') {
 | 
			
		||||
        set_msg_edit_limit_dropdown();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -329,6 +387,8 @@ exports.sync_realm_settings = function (property) {
 | 
			
		||||
        property = 'message_content_edit_limit_minutes';
 | 
			
		||||
    } else if (property === 'create_stream_by_admins_only') {
 | 
			
		||||
        property = 'create_stream_permission';
 | 
			
		||||
    } else if (property === 'allow_message_editing') {
 | 
			
		||||
        property = 'msg_edit_limit_setting';
 | 
			
		||||
    }
 | 
			
		||||
    var element =  $('#id_realm_'+property);
 | 
			
		||||
    if (element.length) {
 | 
			
		||||
@@ -419,6 +479,7 @@ function _set_up() {
 | 
			
		||||
    set_create_stream_permission_dropdown();
 | 
			
		||||
    set_add_emoji_permission_dropdown();
 | 
			
		||||
    set_video_chat_provider_dropdown();
 | 
			
		||||
    set_msg_edit_limit_dropdown();
 | 
			
		||||
 | 
			
		||||
    $("#id_realm_restricted_to_domain").change(function () {
 | 
			
		||||
        settings_ui.disable_sub_setting_onchange(this.checked, "id_realm_disallow_disposable_email_addresses", false);
 | 
			
		||||
@@ -428,11 +489,6 @@ function _set_up() {
 | 
			
		||||
        settings_ui.disable_sub_setting_onchange(this.checked, "id_realm_invite_by_admins_only", true);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    $("#id_realm_allow_message_editing").change(function () {
 | 
			
		||||
        settings_ui.disable_sub_setting_onchange(this.checked, "id_realm_message_content_edit_limit_minutes", true);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    function check_property_changed(elem) {
 | 
			
		||||
        elem = $(elem);
 | 
			
		||||
        var property_name = exports.extract_property_name(elem);
 | 
			
		||||
@@ -511,38 +567,18 @@ function _set_up() {
 | 
			
		||||
    function get_complete_data_for_subsection(subsection) {
 | 
			
		||||
        var opts = {};
 | 
			
		||||
        if (subsection === 'msg_editing') {
 | 
			
		||||
            var compose_textarea_edit_limit_minutes = $("#id_realm_message_content_edit_limit_minutes").val();
 | 
			
		||||
            var new_allow_message_editing = $("#id_realm_allow_message_editing").prop("checked");
 | 
			
		||||
            // If allow_message_editing is unchecked, message_content_edit_limit_minutes
 | 
			
		||||
            // is irrelevant.  Hence if allow_message_editing is unchecked, and
 | 
			
		||||
            // message_content_edit_limit_minutes is poorly formed, we set the latter to
 | 
			
		||||
            // a default value to prevent the server from returning an error.
 | 
			
		||||
            if (!new_allow_message_editing) {
 | 
			
		||||
                if ((parseInt(compose_textarea_edit_limit_minutes, 10).toString() !==
 | 
			
		||||
                     compose_textarea_edit_limit_minutes) ||
 | 
			
		||||
                        compose_textarea_edit_limit_minutes < 0) {
 | 
			
		||||
                    // Realm.DEFAULT_MESSAGE_CONTENT_EDIT_LIMIT_SECONDS / 60
 | 
			
		||||
                    compose_textarea_edit_limit_minutes = 10;
 | 
			
		||||
                }
 | 
			
		||||
            var edit_limit_setting_value = $("#id_realm_msg_edit_limit_setting").val();
 | 
			
		||||
            opts.data = {};
 | 
			
		||||
            if (edit_limit_setting_value === 'never') {
 | 
			
		||||
                opts.data.allow_message_editing = false;
 | 
			
		||||
            } else if (edit_limit_setting_value === 'custom_limit') {
 | 
			
		||||
                opts.data.allow_message_editing = true;
 | 
			
		||||
                opts.data.message_content_edit_limit_seconds = parseInt($("#id_realm_message_content_edit_limit_minutes").val(), 10) * 60;
 | 
			
		||||
            } else {
 | 
			
		||||
                opts.data.allow_message_editing = true;
 | 
			
		||||
                opts.data.message_content_edit_limit_seconds =
 | 
			
		||||
                    exports.msg_edit_limit_dropdown_values[edit_limit_setting_value].seconds;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            opts.data = {
 | 
			
		||||
                allow_message_editing: JSON.stringify(new_allow_message_editing),
 | 
			
		||||
                message_content_edit_limit_seconds:
 | 
			
		||||
                    JSON.stringify(parseInt(compose_textarea_edit_limit_minutes, 10) * 60),
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            opts.success_continuation = function (response_data) {
 | 
			
		||||
                if (response_data.allow_message_editing !== undefined) {
 | 
			
		||||
                   // We expect message_content_edit_limit_seconds was sent in the
 | 
			
		||||
                   // response as well
 | 
			
		||||
                   var data_message_content_edit_limit_minutes =
 | 
			
		||||
                   Math.ceil(response_data.message_content_edit_limit_seconds / 60);
 | 
			
		||||
                   // message_content_edit_limit_seconds could have been changed earlier
 | 
			
		||||
                   // in this function, so update the field just in case
 | 
			
		||||
                   $("#id_realm_message_content_edit_limit_minutes").val(data_message_content_edit_limit_minutes);
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
        } else if (subsection === 'other_permissions') {
 | 
			
		||||
            var create_stream_permission = $("#id_realm_create_stream_permission").val();
 | 
			
		||||
            var add_emoji_permission = $("#id_realm_add_emoji_by_admins_only").val();
 | 
			
		||||
@@ -605,6 +641,16 @@ function _set_up() {
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    $("#id_realm_msg_edit_limit_setting").change(function (e) {
 | 
			
		||||
        var create_stream_permission = e.target.value;
 | 
			
		||||
        var node = $("#id_realm_message_content_edit_limit_minutes").parent();
 | 
			
		||||
        if (create_stream_permission === 'custom_limit') {
 | 
			
		||||
            node.show();
 | 
			
		||||
        } else {
 | 
			
		||||
            node.hide();
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    $("#id_realm_create_stream_permission").change(function () {
 | 
			
		||||
        var create_stream_permission = this.value;
 | 
			
		||||
        var node = $("#id_realm_waiting_period_threshold").parent();
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,7 @@ function _initialize() {
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    settings_bots.setup_bot_creation_policy_values();
 | 
			
		||||
    settings_org.setup_msg_edit_limit_dropdown_values();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.initialize = function () {
 | 
			
		||||
 
 | 
			
		||||
@@ -1371,7 +1371,8 @@ input[type=checkbox].inline-block {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#id_realm_create_stream_permission,
 | 
			
		||||
#id_realm_bot_creation_policy {
 | 
			
		||||
#id_realm_bot_creation_policy,
 | 
			
		||||
#id_realm_msg_edit_limit_setting {
 | 
			
		||||
    width: 100%;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -10,22 +10,23 @@
 | 
			
		||||
                {{ partial "settings-save-discard-widget" "section_name" "msg-editing" }}
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="inline-block organization-settings-parent">
 | 
			
		||||
                {{partial "settings_checkbox"
 | 
			
		||||
                  "setting_name" "realm_allow_message_editing"
 | 
			
		||||
                  "prefix" "id_"
 | 
			
		||||
                  "is_checked" realm_allow_message_editing
 | 
			
		||||
                  "label" admin_settings_label.realm_allow_message_editing}}
 | 
			
		||||
                <div class="input-group">
 | 
			
		||||
                    <label for="realm_msg_edit_limit_setting" class="dropdown-title">{{t "Allow message editing" }}</label>
 | 
			
		||||
                    <select name="realm_msg_edit_limit_setting" id="id_realm_msg_edit_limit_setting">
 | 
			
		||||
                        {{#each msg_edit_limit_dropdown_values}}
 | 
			
		||||
                        <option value="{{@key}}">{{this.text}}</option>
 | 
			
		||||
                        {{/each}}
 | 
			
		||||
                    </select>
 | 
			
		||||
                </div>
 | 
			
		||||
 | 
			
		||||
                <div class="input-group disableable {{#unless realm_allow_message_editing}}control-label-disabled{{/unless}}">
 | 
			
		||||
                    <label for="id_realm_message_content_edit_limit_minutes"
 | 
			
		||||
                      id="id_realm_message_content_edit_limit_minutes_label">
 | 
			
		||||
                        {{t 'Message edit limit in minutes (0 for no limit)' }}
 | 
			
		||||
                <div class="input-group">
 | 
			
		||||
                    <label for="id_realm_message_content_edit_limit_minutes" class="inline-block">
 | 
			
		||||
                        {{t 'Time limit in minutes after posting' }}:
 | 
			
		||||
                    </label>
 | 
			
		||||
                    <input type="text" id="id_realm_message_content_edit_limit_minutes"
 | 
			
		||||
                      name="realm_message_content_edit_limit_minutes"
 | 
			
		||||
                      class="admin-realm-message-content-edit-limit-minutes"
 | 
			
		||||
                      value="{{ realm_message_content_edit_limit_minutes }}"
 | 
			
		||||
                      {{#unless realm_allow_message_editing}}disabled="disabled"{{/unless}} />
 | 
			
		||||
                      value="{{ realm_message_content_edit_limit_minutes }}"/>
 | 
			
		||||
                </div>
 | 
			
		||||
 | 
			
		||||
                <div class="input-group">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user