org settings: Refactor the discard changes function.

This extract the logic of resetting the value of a single property element
at a time so that we can reuse this for real-time-syncing.
This commit is contained in:
Shubham Dhama 2018-03-25 18:41:25 +05:30 committed by Tim Abbott
parent a779fc6095
commit 84a5786b2e
1 changed files with 20 additions and 22 deletions

View File

@ -492,8 +492,7 @@ function _set_up() {
} }
}); });
function discard_subsection_changes(target) { function discard_property_element_changes(elem) {
_.each(get_subsection_property_elements(target), function (elem) {
elem = $(elem); elem = $(elem);
var property_name = exports.extract_property_name(elem); var property_name = exports.extract_property_name(elem);
// Check whether the id refers to a property whose name we can't // Check whether the id refers to a property whose name we can't
@ -513,13 +512,12 @@ function _set_up() {
// Triggering a change event to handle fading and showing of // Triggering a change event to handle fading and showing of
// dependent sub-settings correctly // dependent sub-settings correctly
elem.change(); elem.change();
});
} }
$('.organization').on('click', '.subsection-header .subsection-changes-discard button', function (e) { $('.organization').on('click', '.subsection-header .subsection-changes-discard button', function (e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
discard_subsection_changes(e.target); _.each(get_subsection_property_elements(e.target), discard_property_element_changes);
var subsection = $(e.target).closest('.org-subsection-parent'); var subsection = $(e.target).closest('.org-subsection-parent');
var change_process_buttons = subsection.find('.subsection-header .button'); var change_process_buttons = subsection.find('.subsection-header .button');
change_process_buttons.removeClass('show').addClass('hide'); change_process_buttons.removeClass('show').addClass('hide');