mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	dropdown_list_widget: Separate setup method from constructor.
This refactoring is required so the next commit can reorder the constructor. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							5ee4f71701
						
					
				
				
					commit
					175dd999ac
				
			@@ -49,6 +49,7 @@ run_test("basic_functions", () => {
 | 
			
		||||
    const {$reset_button, $widget} = setup_dropdown_zjquery_data(opts.widget_name);
 | 
			
		||||
 | 
			
		||||
    const widget = new DropdownListWidget(opts);
 | 
			
		||||
    widget.setup();
 | 
			
		||||
 | 
			
		||||
    assert.equal(widget.value(), "one");
 | 
			
		||||
    assert.equal(updated_value, undefined); // We haven't 'updated' the widget yet.
 | 
			
		||||
@@ -88,6 +89,7 @@ run_test("no_default_value", () => {
 | 
			
		||||
    );
 | 
			
		||||
    setup_dropdown_zjquery_data(opts.widget_name);
 | 
			
		||||
    const widget = new DropdownListWidget(opts);
 | 
			
		||||
    widget.setup();
 | 
			
		||||
    assert.equal(widget.value(), "null-value");
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@@ -112,6 +114,7 @@ run_test("basic MDLW functions", () => {
 | 
			
		||||
 | 
			
		||||
    const {$reset_button, $widget} = setup_multiselect_dropdown_zjquery_data(opts.widget_name);
 | 
			
		||||
    const widget = new MultiSelectDropdownListWidget(opts);
 | 
			
		||||
    widget.setup();
 | 
			
		||||
 | 
			
		||||
    function set_dropdown_variables(widget, value) {
 | 
			
		||||
        widget.data_selected = value;
 | 
			
		||||
@@ -172,6 +175,7 @@ run_test("MDLW no_default_value", () => {
 | 
			
		||||
 | 
			
		||||
    setup_multiselect_dropdown_zjquery_data(opts.widget_name);
 | 
			
		||||
    const widget = new MultiSelectDropdownListWidget(opts);
 | 
			
		||||
    widget.setup();
 | 
			
		||||
 | 
			
		||||
    assert.equal(widget.value(), "null-value");
 | 
			
		||||
});
 | 
			
		||||
@@ -196,6 +200,7 @@ run_test("MDLW no_limit_set", () => {
 | 
			
		||||
 | 
			
		||||
    const {$widget} = setup_multiselect_dropdown_zjquery_data(opts.widget_name);
 | 
			
		||||
    const widget = new MultiSelectDropdownListWidget(opts);
 | 
			
		||||
    widget.setup();
 | 
			
		||||
 | 
			
		||||
    set_dropdown_variables(widget, ["one", "two", "three"]);
 | 
			
		||||
    widget.update(widget.data_selected);
 | 
			
		||||
 
 | 
			
		||||
@@ -662,6 +662,7 @@ test("set_up", ({override, override_rewire, mock_template}) => {
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    override_rewire(dropdown_list_widget, "DropdownListWidget", () => ({
 | 
			
		||||
        setup: noop,
 | 
			
		||||
        render: noop,
 | 
			
		||||
        update: noop,
 | 
			
		||||
    }));
 | 
			
		||||
 
 | 
			
		||||
@@ -35,9 +35,6 @@ export function DropdownListWidget({
 | 
			
		||||
        this.initial_value = null_value;
 | 
			
		||||
        blueslip.warn("dropdown-list-widget: Called without a default value; using null value");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Setting up dropdown_list_widget
 | 
			
		||||
    this.setup();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
DropdownListWidget.prototype.render_default_text = function ($elem) {
 | 
			
		||||
@@ -289,12 +286,15 @@ export function MultiSelectDropdownListWidget({
 | 
			
		||||
            "Multiselect dropdown-list-widget: Called without limit value; using 2 as the limit",
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    this.initialize_dropdown_values();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
MultiSelectDropdownListWidget.prototype = Object.create(DropdownListWidget.prototype);
 | 
			
		||||
 | 
			
		||||
MultiSelectDropdownListWidget.prototype.setup = function () {
 | 
			
		||||
    DropdownListWidget.prototype.setup.call(this);
 | 
			
		||||
    this.initialize_dropdown_values();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MultiSelectDropdownListWidget.prototype.initialize_dropdown_values = function () {
 | 
			
		||||
    // Stop the execution if value parameter is undefined and null_value is passed.
 | 
			
		||||
    if (!this.initial_value || this.initial_value === this.null_value) {
 | 
			
		||||
 
 | 
			
		||||
@@ -476,6 +476,7 @@ function edit_message($row, raw_content) {
 | 
			
		||||
 | 
			
		||||
    if (is_stream_editable) {
 | 
			
		||||
        stream_widget = new DropdownListWidget(opts);
 | 
			
		||||
        stream_widget.setup();
 | 
			
		||||
    }
 | 
			
		||||
    stream_bar.decorate(message.stream, $stream_header_colorblock, false);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -450,6 +450,7 @@ export function set_up() {
 | 
			
		||||
                value: bot.owner_id,
 | 
			
		||||
            };
 | 
			
		||||
            const owner_widget = new DropdownListWidget(opts);
 | 
			
		||||
            owner_widget.setup();
 | 
			
		||||
 | 
			
		||||
            const service = bot_data.get_services(bot_id)[0];
 | 
			
		||||
            if (bot.bot_type.toString() === OUTGOING_WEBHOOK_BOT_TYPE) {
 | 
			
		||||
 
 | 
			
		||||
@@ -798,11 +798,13 @@ export function init_dropdown_widgets() {
 | 
			
		||||
        value: page_params.realm_notifications_stream_id,
 | 
			
		||||
        ...notification_stream_options,
 | 
			
		||||
    });
 | 
			
		||||
    notifications_stream_widget.setup();
 | 
			
		||||
    signup_notifications_stream_widget = new DropdownListWidget({
 | 
			
		||||
        widget_name: "realm_signup_notifications_stream_id",
 | 
			
		||||
        value: page_params.realm_signup_notifications_stream_id,
 | 
			
		||||
        ...notification_stream_options,
 | 
			
		||||
    });
 | 
			
		||||
    signup_notifications_stream_widget.setup();
 | 
			
		||||
    default_code_language_widget = new DropdownListWidget({
 | 
			
		||||
        widget_name: "realm_default_code_block_language",
 | 
			
		||||
        data: Object.keys(pygments_data.langs).map((x) => ({
 | 
			
		||||
@@ -815,6 +817,7 @@ export function init_dropdown_widgets() {
 | 
			
		||||
        },
 | 
			
		||||
        default_text: $t({defaultMessage: "No language set"}),
 | 
			
		||||
    });
 | 
			
		||||
    default_code_language_widget.setup();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function register_save_discard_widget_handlers(
 | 
			
		||||
 
 | 
			
		||||
@@ -714,6 +714,7 @@ function handle_bot_form($tbody, $status_field) {
 | 
			
		||||
            // Note: Rendering this is quite expensive in
 | 
			
		||||
            // organizations with 10Ks of users.
 | 
			
		||||
            owner_widget = new DropdownListWidget(opts);
 | 
			
		||||
            owner_widget.setup();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        dialog_widget.launch({
 | 
			
		||||
 
 | 
			
		||||
@@ -492,6 +492,7 @@ function build_move_topic_to_stream_popover(e, current_stream_id, topic_name) {
 | 
			
		||||
            on_update: update_submit_button_disabled_state,
 | 
			
		||||
        };
 | 
			
		||||
        stream_widget = new DropdownListWidget(opts);
 | 
			
		||||
        stream_widget.setup();
 | 
			
		||||
 | 
			
		||||
        update_submit_button_disabled_state(stream_widget.value());
 | 
			
		||||
        $("#move_topic_modal .inline_topic_edit").on("input", () => {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user