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