Switch toolbar to use Et2DropdownButton

NB: This doesn't actually work properly yet, there's something that closes the dropdown immediately that I haven't found the source of yet.
This commit is contained in:
nathan 2022-05-13 14:19:21 -06:00
parent 079ebf00b6
commit 56def486f0

View File

@ -19,12 +19,13 @@ import {et2_DOMWidget} from "./et2_core_DOMWidget";
import {et2_createWidget, et2_register_widget, WidgetConfig} from "./et2_core_widget"; import {et2_createWidget, et2_register_widget, WidgetConfig} from "./et2_core_widget";
import {ClassWithAttributes} from "./et2_core_inheritance"; import {ClassWithAttributes} from "./et2_core_inheritance";
import {egw_getObjectManager, egwActionObject, egwActionObjectManager} from '../egw_action/egw_action.js'; import {egw_getObjectManager, egwActionObject, egwActionObjectManager} from '../egw_action/egw_action.js';
import {et2_dropdown_button} from "./et2_widget_dropdown_button";
import {et2_checkbox} from "./et2_widget_checkbox"; import {et2_checkbox} from "./et2_widget_checkbox";
import {et2_IInput} from "./et2_core_interfaces"; import {et2_IInput} from "./et2_core_interfaces";
import {egw} from "../jsapi/egw_global"; import {egw} from "../jsapi/egw_global";
import {egwIsMobile} from "../egw_action/egw_action_common.js"; import {egwIsMobile} from "../egw_action/egw_action_common.js";
import {Et2Dialog} from "./Et2Dialog/Et2Dialog"; import {Et2Dialog} from "./Et2Dialog/Et2Dialog";
import {Et2DropdownButton} from "./Et2DropdownButton/Et2DropdownButton";
import {loadWebComponent} from "./Et2Widget/Et2Widget";
/** /**
* This toolbar gets its contents from its actions * This toolbar gets its contents from its actions
@ -339,6 +340,7 @@ export class et2_toolbar extends et2_DOMWidget implements et2_IInput
{ {
let info = { let info = {
id: id || root.children[id].id, id: id || root.children[id].id,
value: id || root.children[id].id,
label: root.children[id].caption label: root.children[id].caption
}; };
let childaction = {}; let childaction = {};
@ -378,7 +380,7 @@ export class et2_toolbar extends et2_DOMWidget implements et2_IInput
{ {
childaction['group'] = root.group; childaction['group'] = root.group;
} }
that._make_button (childaction); that._make_button(childaction);
} }
} }
}; };
@ -388,12 +390,26 @@ export class et2_toolbar extends et2_DOMWidget implements et2_IInput
continue; continue;
} }
let dropdown = <et2_dropdown_button>et2_createWidget("dropdown_button", { let dropdown = <Et2DropdownButton><unknown>loadWebComponent("et2-dropdown-button", {
id: action.id id: this.id + "-" + action.id,
},this); label: action.caption,
class: this.preference[action.id] ? 'et2_toolbar-dropdown et2_toolbar-dropdown-menulist' : 'et2_toolbar-dropdown',
onchange: function(selected, dropdown)
{
let action = that._actionManager.getActionById(selected.attr('data-id'));
dropdown.set_label(action.caption);
if(action)
{
this.value = action.id;
action.execute([]);
}
//console.debug(selected, this, action);
}.bind(action),
image: action.iconUrl || ''
}, this);
dropdown.select_options = Object.values(children);
dropdown.set_select_options(children);
dropdown.set_label (action.caption);
//Set default selected action //Set default selected action
if (typeof action.children !='undefined') if (typeof action.children !='undefined')
{ {
@ -401,23 +417,12 @@ export class et2_toolbar extends et2_DOMWidget implements et2_IInput
{ {
if(action.children[child].default) if(action.children[child].default)
{ {
dropdown.set_label(action.children[child].caption); dropdown.label = action.children[child].caption;
} }
} }
} }
dropdown.set_image (action.iconUrl||'');
dropdown.onchange = jQuery.proxy(function(selected, dropdown) dropdown.onclick = function(selected, dropdown)
{
let action = that._actionManager.getActionById(selected.attr('data-id'));
dropdown.set_label(action.caption);
if(action)
{
this.value = action.id;
action.execute([]);
}
//console.debug(selected, this, action);
},action);
dropdown.onclick = jQuery.proxy(function(selected, dropdown)
{ {
let action = that._actionManager.getActionById(this.getValue()); let action = that._actionManager.getActionById(this.getValue());
if(action) if(action)
@ -426,11 +431,8 @@ export class et2_toolbar extends et2_DOMWidget implements et2_IInput
action.execute([]); action.execute([]);
} }
//console.debug(selected, this, action); //console.debug(selected, this, action);
},dropdown); }.bind(dropdown);
jQuery(dropdown.getDOMNode()) jQuery(dropdown.getDOMNode()).appendTo(this.preference[action.id] ? this.actionbox.children()[1] : jQuery('[data-group=' + action.group + ']', this.actionlist));
.attr('id',this.id + '-' + dropdown.id)
.addClass(this.preference[action.id]?'et2_toolbar-dropdown et2_toolbar-dropdown-menulist':'et2_toolbar-dropdown')
.appendTo(this.preference[action.id]?this.actionbox.children()[1]:jQuery('[data-group='+action.group+']',this.actionlist));
} }
else else
{ {