Skip to content

Commit

Permalink
Add menuButtonSet
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucker committed Feb 19, 2024
1 parent 26612ce commit 41dde7b
Showing 1 changed file with 51 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ qx.Class.define("callbackery.ui.plugin.Action", {
this._urlActions = [];
this._buttonMap = {};
this._buttonSetMap = {};
this._menuButtonSetMap = {};
this._cfg = cfg;
this._populate(cfg, buttonClass, getFormData);
plugin.addOwnedQxObject(this, 'Action');
Expand Down Expand Up @@ -138,37 +139,57 @@ qx.Class.define("callbackery.ui.plugin.Action", {
win.print();
},
_populate(cfg, buttonClass, getFormData) {
var tm = this._tableMenu = new qx.ui.menu.Menu;
let tm = this._tableMenu = new qx.ui.menu.Menu;
let mm = this._mobileMenu = new qx.ui.menu.Menu;
var menues = {};
var mmMenues = {};
let menues = {};
let mmMenues = {};
cfg.action.forEach(function (btCfg) {
var button, menuButton, mmButton;
var label = btCfg.label ? this.xtr(btCfg.label) : null;
let button, menuButton, mmButton;
// label for form and context menu buttons
let label = btCfg.label ? this.xtr(btCfg.label) : null;
// label for mobile menu buttons
let menuLabel = btCfg.menuLabel ? this.xtr(btCfg.menuLabel) : null;
let bs = btCfg.buttonSet,
mbs = btCfg.menuButtonSet;
if (bs) {
if (bs.label) {
bs.label = this.xtr(bs.label);
}
}
if (mbs) {
if (mbs.label) {
mbs.label = this.xtr(mbs.label);
}
}
else if (bs) { // use buttonSet as menuButtonSet if no menuButtonSet is given
mbs = bs;
}

switch (btCfg.action) {
case 'menu':
var menu = menues[btCfg.key] = new qx.ui.menu.Menu;
var mmMenu = mmMenues[btCfg.key] = new qx.ui.menu.Menu;
let menu = menues[btCfg.key] = new qx.ui.menu.Menu;
let mmMenu = mmMenues[btCfg.key] = new qx.ui.menu.Menu;
if (btCfg.addToMenu != null) { // add submenu to menu
button = new qx.ui.menu.Button(label, null, null, menu)
mmButton = new qx.ui.menu.Button(label, null, null, mmMenu)
mmButton = new qx.ui.menu.Button(menuLabel || label, null, null, mmMenu)
menues[btCfg.addToMenu].add(button);
mmMenues[btCfg.addToMenu].add(mmButton);
}
else { // add menu to form
button = new qx.ui.form.MenuButton(label, null, menu);
mmButton = new qx.ui.menu.Button(label, null, null, mmMenu);
if (btCfg.buttonSet) {
var bs = btCfg.buttonSet;
if (bs.label) {
bs.label = this.xtr(bs.label);
}
mmButton = new qx.ui.menu.Button(menuLabel || label, null, null, mmMenu);
if (bs) {
button.set(bs);
mmButton.set(bs);
if (btCfg.key) {
this._buttonSetMap[btCfg.key] = bs;
}
}
if (mbs) {
mmButton.set(mbs);
if (btCfg.key) {
this._menuButtonSetMap[btCfg.key] = mbs;
}
}
this.add(button);
mm.add(mmButton);
}
Expand All @@ -182,7 +203,7 @@ qx.Class.define("callbackery.ui.plugin.Action", {
+ 'mmButton';
this.addOwnedQxObject(mmButton, mmBtnId);
}
this._bindButtonPropperties(button, mmButton);
this._bindButtonProperties(button, mmButton);
return;
case 'save':
case 'submitVerify':
Expand All @@ -193,7 +214,7 @@ qx.Class.define("callbackery.ui.plugin.Action", {
case 'cancel':
case 'download':
case 'display':
mmButton = new qx.ui.menu.Button(label);
mmButton = new qx.ui.menu.Button(menuLabel || label);
if (btCfg.addToMenu != null) {
button = new qx.ui.menu.Button(label);
}
Expand All @@ -211,17 +232,19 @@ qx.Class.define("callbackery.ui.plugin.Action", {
});
}
}
if (btCfg.buttonSet) {
var bs = btCfg.buttonSet;
if (bs.label) {
bs.label = this.xtr(bs.label);
}

if (bs) {
button.set(bs);
mmButton.set(bs);
if (btCfg.key) {
this._buttonSetMap[btCfg.key] = bs;
}
}
if (mbs) {
mmButton.set(mbs);
if (btCfg.key) {
this._menuButtonSetMap[btCfg.key] = mbs;
}
}

if (btCfg.addToContextMenu) {
menuButton = new qx.ui.menu.Button(label);
Expand Down Expand Up @@ -515,6 +538,7 @@ qx.Class.define("callbackery.ui.plugin.Action", {
}
}, this);
},

_makeUploadButton(cfg, btCfg, getFormData, buttonClass) {
var button;
var label = btCfg.label ? this.xtr(btCfg.label) : null;
Expand Down Expand Up @@ -559,7 +583,6 @@ qx.Class.define("callbackery.ui.plugin.Action", {
}
}, this);


return button;
},

Expand Down Expand Up @@ -618,6 +641,9 @@ qx.Class.define("callbackery.ui.plugin.Action", {
getButtonSetMap() {
return this._buttonSetMap;
},
getMenuButtonSetMap() {
return this._menuButtonSetMap;
},
_bindButtonProperties(button, mmButton) {
['visibility', 'enabled', 'label', 'icon'].forEach((prop) => {
button.bind(prop, mmButton, prop);
Expand All @@ -633,5 +659,5 @@ qx.Class.define("callbackery.ui.plugin.Action", {
btn.destroy();
}
},

});

0 comments on commit 41dde7b

Please sign in to comment.