mirror of https://github.com/zulip/zulip.git
dropdown-list-widget: Rename setting_name -> widget_name.
This change is another in a series of commits that allows us to use DLW outside of realm_settings.
This commit is contained in:
parent
9129da88af
commit
aeb247f528
|
@ -13,7 +13,7 @@ set_global('list_render', _list_render);
|
|||
run_test('basic_functions', () => {
|
||||
let updated_value;
|
||||
const opts = {
|
||||
setting_name: 'my_setting',
|
||||
widget_name: 'my_setting',
|
||||
data: ['one', 'two', 'three'].map(x => ({name: x, value: x})),
|
||||
value: 'one',
|
||||
on_update: (val) => { updated_value = val; },
|
||||
|
|
|
@ -4,16 +4,16 @@ const DropdownListWidget = function (opts) {
|
|||
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];
|
||||
opts.container_id = `${opts.widget_name}_widget`;
|
||||
opts.value_id = `id_${opts.widget_name}`;
|
||||
opts.value = opts.value || page_params[opts.widget_name];
|
||||
|
||||
const render_dropdown_list = require("../templates/settings/dropdown_list.hbs");
|
||||
|
||||
const render = (value) => {
|
||||
$(`#${opts.container_id} #${opts.value_id}`).data("value", value);
|
||||
|
||||
const elem = $(`#${opts.container_id} #${opts.setting_name}_name`);
|
||||
const elem = $(`#${opts.container_id} #${opts.widget_name}_name`);
|
||||
|
||||
if (!value || value === opts.null_value) {
|
||||
elem.text(opts.default_text);
|
||||
|
@ -37,7 +37,7 @@ const DropdownListWidget = function (opts) {
|
|||
|
||||
const register_event_handlers = () => {
|
||||
$(`#${opts.container_id} .dropdown-list-body`).on("click keypress", ".list_item", function (e) {
|
||||
const setting_elem = $(this).closest(`.${opts.setting_name}_setting`);
|
||||
const setting_elem = $(this).closest(`.${opts.widget_name}_setting`);
|
||||
if (e.type === "keypress") {
|
||||
if (e.which === 13) {
|
||||
setting_elem.find(".dropdown-menu").dropdown("toggle");
|
||||
|
@ -60,7 +60,7 @@ const DropdownListWidget = function (opts) {
|
|||
const dropdown_toggle = $(`#${opts.container_id} .dropdown-toggle`);
|
||||
|
||||
list_render.create(dropdown_list_body, opts.data, {
|
||||
name: `${opts.setting_name}_list`,
|
||||
name: `${opts.widget_name}_list`,
|
||||
modifier: function (item) {
|
||||
return render_dropdown_list({ item: item });
|
||||
},
|
||||
|
|
|
@ -566,13 +566,13 @@ exports.init_dropdown_widgets = () => {
|
|||
null_value: -1,
|
||||
};
|
||||
exports.notifications_stream_widget = dropdown_list_widget(
|
||||
Object.assign({setting_name: 'realm_notifications_stream_id'},
|
||||
Object.assign({widget_name: 'realm_notifications_stream_id'},
|
||||
notification_stream_options));
|
||||
exports.signup_notifications_stream_widget = dropdown_list_widget(
|
||||
Object.assign({setting_name: 'realm_signup_notifications_stream_id'},
|
||||
Object.assign({widget_name: 'realm_signup_notifications_stream_id'},
|
||||
notification_stream_options));
|
||||
exports.default_code_language_widget = dropdown_list_widget({
|
||||
setting_name: 'realm_default_code_block_language',
|
||||
widget_name: 'realm_default_code_block_language',
|
||||
data: Object.keys(pygments_data.langs).map(x => {
|
||||
return {
|
||||
name: x,
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<div class="input-group dropdown-list-widget" id="{{setting_name}}_widget">
|
||||
<label for="{{setting_name}}" id="{{setting_name}}_label" class="inline-block">
|
||||
<div class="input-group dropdown-list-widget" id="{{widget_name}}_widget">
|
||||
<label for="{{widget_name}}" id="{{widget_name}}_label" class="inline-block">
|
||||
{{ label }}
|
||||
<span class="{{setting_name}}_setting dropup actual-dropdown-menu prop-element" id="id_{{setting_name}}"
|
||||
name="{{setting_name}}" aria-labelledby="{{setting_name}}_label">
|
||||
<span class="{{widget_name}}_setting dropup actual-dropdown-menu prop-element" id="id_{{widget_name}}"
|
||||
name="{{widget_name}}" aria-labelledby="{{widget_name}}_label">
|
||||
<button class="button small rounded dropdown-toggle" data-toggle="dropdown">
|
||||
<span id="{{setting_name}}_name"></span>
|
||||
<span id="{{widget_name}}_name"></span>
|
||||
<i class="fa fa-pencil"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu modal-bg" role="menu">
|
||||
|
|
|
@ -103,13 +103,13 @@
|
|||
</div>
|
||||
|
||||
{{> dropdown_list_widget
|
||||
setting_name="realm_notifications_stream_id"
|
||||
widget_name="realm_notifications_stream_id"
|
||||
list_placeholder=(t 'Filter streams')
|
||||
reset_button_text=(t '[Disable]')
|
||||
label=admin_settings_label.realm_notifications_stream }}
|
||||
|
||||
{{> dropdown_list_widget
|
||||
setting_name="realm_signup_notifications_stream_id"
|
||||
widget_name="realm_signup_notifications_stream_id"
|
||||
list_placeholder=(t 'Filter streams')
|
||||
reset_button_text=(t '[Disable]')
|
||||
label=admin_settings_label.realm_notifications_stream }}
|
||||
|
@ -231,7 +231,7 @@
|
|||
</div>
|
||||
|
||||
{{> dropdown_list_widget
|
||||
setting_name="realm_default_code_block_language"
|
||||
widget_name="realm_default_code_block_language"
|
||||
list_placeholder=(t 'Filter languages')
|
||||
reset_button_text=(t '[Unset]')
|
||||
label=admin_settings_label.realm_default_code_block_language }}
|
||||
|
|
Loading…
Reference in New Issue