mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 02:17:19 +00:00
org settings: Refactor check_property_changed.
In this refactor property values are handled more carefully i.e. we first check whether property_name refers to a property values which we can't get from the input elements like we do have in org permissions section for properties like realm_add_emoji_by_admins_only. Small refactor in property_value_element_refers is to prevent many return statements on further addition of property names.
This commit is contained in:
committed by
Tim Abbott
parent
393d4d320f
commit
6cdbcfd80c
@@ -420,7 +420,7 @@ function _set_up() {
|
|||||||
|
|
||||||
function property_value_element_refers(property_name) {
|
function property_value_element_refers(property_name) {
|
||||||
if (property_name === 'realm_message_content_edit_limit_minutes') {
|
if (property_name === 'realm_message_content_edit_limit_minutes') {
|
||||||
return Math.ceil(page_params.realm_message_content_edit_limit_seconds / 60);
|
return Math.ceil(page_params.realm_message_content_edit_limit_seconds / 60).toString();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -432,8 +432,14 @@ function _set_up() {
|
|||||||
function check_property_changed(elem) {
|
function check_property_changed(elem) {
|
||||||
elem = $(elem);
|
elem = $(elem);
|
||||||
var property_name = exports.extract_property_name(elem);
|
var property_name = exports.extract_property_name(elem);
|
||||||
var current_val = page_params[property_name];
|
|
||||||
var changed_val;
|
var changed_val;
|
||||||
|
// Check whether the id refers to a property whose name we can't
|
||||||
|
// extract from element's id.
|
||||||
|
var current_val = property_value_element_refers(property_name);
|
||||||
|
if (current_val === undefined) {
|
||||||
|
current_val = page_params[property_name];
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof current_val === 'boolean') {
|
if (typeof current_val === 'boolean') {
|
||||||
changed_val = elem.prop('checked');
|
changed_val = elem.prop('checked');
|
||||||
} else if (typeof current_val === 'string') {
|
} else if (typeof current_val === 'string') {
|
||||||
@@ -441,18 +447,10 @@ function _set_up() {
|
|||||||
} else if (typeof current_val === 'number') {
|
} else if (typeof current_val === 'number') {
|
||||||
current_val = current_val.toString();
|
current_val = current_val.toString();
|
||||||
changed_val = elem.val().trim();
|
changed_val = elem.val().trim();
|
||||||
} else {
|
|
||||||
// Check whether the id refers to a property whose name we can't
|
|
||||||
// extract from element's id.
|
|
||||||
current_val = property_value_element_refers(property_name);
|
|
||||||
|
|
||||||
if (current_val !== undefined) {
|
|
||||||
current_val = current_val.toString();
|
|
||||||
changed_val = elem.val().trim();
|
|
||||||
} else {
|
} else {
|
||||||
blueslip.error('Element refers to unknown property ' + property_name);
|
blueslip.error('Element refers to unknown property ' + property_name);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return current_val !== changed_val;
|
return current_val !== changed_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user