mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 10:57:58 +00:00
settings: Simplify settings_list_widget interface.
We move more common code into settings_lsit_widget for cleaner code in settings_org.js.
This commit is contained in:
committed by
Tim Abbott
parent
e79935dbf7
commit
41481a906c
@@ -8,31 +8,6 @@ const DropdownListWidget = function (opts) {
|
||||
|
||||
const render_dropdown_list = require("../templates/settings/dropdown_list.hbs");
|
||||
|
||||
const setup = () => {
|
||||
// populate the dropdown
|
||||
const dropdown_list_body = $(`#${opts.container_id} .dropdown-list-body`).expectOne();
|
||||
const search_input = $(`#${opts.container_id} .dropdown-search > input[type=text]`);
|
||||
list_render.create(dropdown_list_body, opts.data, {
|
||||
name: `${opts.setting_name}_list`,
|
||||
modifier: function (item) {
|
||||
return render_dropdown_list({ item: item });
|
||||
},
|
||||
filter: {
|
||||
element: search_input,
|
||||
predicate: function (item, value) {
|
||||
return item.name.toLowerCase().includes(value);
|
||||
},
|
||||
},
|
||||
});
|
||||
$(`#${opts.container_id} .dropdown-search`).click(function (e) {
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
$(`#${opts.container_id} .dropdown-toggle`).click(function () {
|
||||
search_input.val("").trigger("input");
|
||||
});
|
||||
};
|
||||
|
||||
const render = (value) => {
|
||||
$(`#${opts.container_id} #${opts.value_id}`).data("value", value);
|
||||
|
||||
@@ -76,6 +51,35 @@ const DropdownListWidget = function (opts) {
|
||||
});
|
||||
};
|
||||
|
||||
const setup = () => {
|
||||
// populate the dropdown
|
||||
const dropdown_list_body = $(`#${opts.container_id} .dropdown-list-body`).expectOne();
|
||||
const search_input = $(`#${opts.container_id} .dropdown-search > input[type=text]`);
|
||||
|
||||
list_render.create(dropdown_list_body, opts.data, {
|
||||
name: `${opts.setting_name}_list`,
|
||||
modifier: function (item) {
|
||||
return render_dropdown_list({ item: item });
|
||||
},
|
||||
filter: {
|
||||
element: search_input,
|
||||
predicate: function (item, value) {
|
||||
return item.name.toLowerCase().includes(value);
|
||||
},
|
||||
},
|
||||
});
|
||||
$(`#${opts.container_id} .dropdown-search`).click(function (e) {
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
$(`#${opts.container_id} .dropdown-toggle`).click(function () {
|
||||
search_input.val("").trigger("input");
|
||||
});
|
||||
|
||||
render(page_params[opts.setting_name]);
|
||||
register_event_handlers();
|
||||
};
|
||||
|
||||
const value = () => {
|
||||
let val = $(`#${opts.container_id} #${opts.value_id}`).data('value');
|
||||
if (val === null) {
|
||||
@@ -84,10 +88,11 @@ const DropdownListWidget = function (opts) {
|
||||
return val;
|
||||
};
|
||||
|
||||
// Run setup() automatically on initialization.
|
||||
setup();
|
||||
|
||||
return {
|
||||
setup,
|
||||
render,
|
||||
register_event_handlers,
|
||||
value,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user