settings: Remove settings_org dependency from settings_list_widget.

Instead of taking a subsection option and calling the settings_org
function to update that subsection, we now take a callback function
as on_update. Also, we now store the value initial value of the
widget in opts.value instead of reading again from page_params.

These changes allow us to use this widget outside of settings_org
and for values other than settings that are in page_params.
This commit is contained in:
Rohitt Vashishtha
2020-04-30 16:39:48 +05:30
committed by Tim Abbott
parent f3ab8e66dc
commit b066ba1ff3
2 changed files with 10 additions and 4 deletions

View File

@@ -2,9 +2,11 @@ const DropdownListWidget = function (opts) {
opts = Object.assign({
null_value: null,
render_text: (item_name) => item_name,
on_update: () => {},
}, opts);
opts.container_id = `${opts.setting_name}_widget`;
opts.value_id = `id_${opts.setting_name}`;
opts.value = opts.value || page_params[opts.setting_name];
const render_dropdown_list = require("../templates/settings/dropdown_list.hbs");
@@ -30,7 +32,7 @@ const DropdownListWidget = function (opts) {
const update = (value) => {
render(value);
settings_org.save_discard_widget_status_handler($(`#org-${opts.subsection}`));
opts.on_update(value);
};
const register_event_handlers = () => {
@@ -96,7 +98,7 @@ const DropdownListWidget = function (opts) {
dropdown_toggle.trigger(custom_event);
});
render(page_params[opts.setting_name]);
render(opts.value);
register_event_handlers();
};

View File

@@ -549,7 +549,9 @@ exports.init_dropdown_widgets = () => {
};
return item;
}),
subsection: 'notifications',
on_update: () => {
exports.save_discard_widget_status_handler($(`#org-notifications`));
},
default_text: i18n.t("Disabled"),
render_text: (x) => {return `#${x}`;},
null_value: -1,
@@ -568,7 +570,9 @@ exports.init_dropdown_widgets = () => {
value: x,
};
}),
subsection: 'other-settings',
on_update: () => {
exports.save_discard_widget_status_handler($(`#org-other-settings`));
},
default_text: i18n.t("No language set"),
});
};