stream_create: Refactor code to set default value for retention setting.

The message retention setting is only visible to owners in the
stream creation form, so the jquery code to hide the custom
input, set the default value for dropdown and listener to
show and hide the custom input should be called only for owners.
This commit is contained in:
Sahil Batra 2023-01-06 12:33:49 +05:30 committed by Tim Abbott
parent 1c1b911a42
commit 6f20d7c9ab
1 changed files with 17 additions and 10 deletions

View File

@ -317,17 +317,24 @@ export function show_new_stream_modal() {
// Select the first visible and enabled choice for stream privacy.
$("#make-invite-only input:visible:not([disabled])").first().prop("checked", true);
// Make the options default to the same each time
$("#stream_creation_form .stream-message-retention-days-input").hide();
$("#stream_creation_form select[name=stream_message_retention_setting]").val("realm_default");
// Add listener to .show stream-message-retention-days-input that we've hidden above
$("#stream_creation_form .stream_message_retention_setting").on("change", (e) => {
if (e.target.value === "custom_period") {
$("#stream_creation_form .stream-message-retention-days-input").show();
} else {
$("#stream_creation_form .stream-message-retention-days-input").hide();
}
});
// The message retention setting is visible to owners only. The below block
// sets the default state of setting if it is visible.
if (page_params.is_owner) {
$("#stream_creation_form .stream-message-retention-days-input").hide();
$("#stream_creation_form select[name=stream_message_retention_setting]").val(
"realm_default",
);
// Add listener to .show stream-message-retention-days-input that we've hidden above
$("#stream_creation_form .stream_message_retention_setting").on("change", (e) => {
if (e.target.value === "custom_period") {
$("#stream_creation_form .stream-message-retention-days-input").show();
} else {
$("#stream_creation_form .stream-message-retention-days-input").hide();
}
});
}
// set default state for "announce stream" option.
update_announce_stream_state();