Skip to content

Commit

Permalink
Fix mobile menu for cards (#224)
Browse files Browse the repository at this point in the history
* Make foreach function calls consistent

* Add menuButtonSet

* Add missing members

* Update CHANGES
  • Loading branch information
zaucker authored Feb 19, 2024
1 parent 178aa75 commit ac1c9a8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 25 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- Add menuButtonSet and menuLabel to Actions.js to allow
separate config of mobile and regular menus

- Translate tooltip and placeholder in Card.js
- Make foreach function calls consistent in Card.js and Auto.js

Expand Down
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 @@ -124,6 +125,8 @@ qx.Class.define("callbackery.ui.plugin.Action", {
_tableMenu: null,
_defaultAction: null,
_buttonMap: null,
_buttonSetMap: null,
_menuButtonSetMap: null,
_urlActions: null,
_mobileMenu: null,
_print(content, left, top) {
Expand All @@ -138,37 +141,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 +205,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 +216,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 +234,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 +540,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 +585,6 @@ qx.Class.define("callbackery.ui.plugin.Action", {
}
}, this);


return button;
},

Expand Down Expand Up @@ -618,6 +643,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 +661,5 @@ qx.Class.define("callbackery.ui.plugin.Action", {
btn.destroy();
}
},

});

0 comments on commit ac1c9a8

Please sign in to comment.