mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	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:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							f3ab8e66dc
						
					
				
				
					commit
					b066ba1ff3
				
			@@ -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();
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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"),
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user