diff --git a/src/public/javascripts/services/context_menu.js b/src/public/javascripts/services/context_menu.js index d3ac95686..a060a3764 100644 --- a/src/public/javascripts/services/context_menu.js +++ b/src/public/javascripts/services/context_menu.js @@ -5,42 +5,60 @@ function initContextMenu(event, itemContainer, selectContextMenuItem) { $contextMenuContainer.empty(); - for (const item of itemContainer.getItems()) { - if (item.title === '----') { - $contextMenuContainer.append($("
").addClass("dropdown-divider")); - } else { - const $icon = $(""); - - if (item.uiIcon) { - $icon.addClass("jam jam-" + item.uiIcon); + function addItems($parent, items) { + for (const item of items) { + if (item.title === '----') { + $parent.append($("
").addClass("dropdown-divider")); } else { - $icon.append(" "); + const $icon = $(""); + + if (item.uiIcon) { + $icon.addClass("jam jam-" + item.uiIcon); + } else { + $icon.append(" "); + } + + const $item = $("
  • ") + .addClass("dropdown-item"); + + const $link = $("") + .append($icon) + .append("   ") // some space between icon and text + .prop("data-cmd", item.cmd) + .append(item.title); + + $item.append($link); + + if (item.enabled !== undefined && !item.enabled) { + $link.addClass("disabled"); + } + + $link.click(async function (e) { + const cmd = $(e.target).prop("data-cmd"); + + e.originalTarget = event.target; + + await selectContextMenuItem(e, cmd); + }); + + if (item.items) { + $item.addClass("dropdown-submenu"); + $link.addClass("dropdown-toggle"); + + const $subMenu = $("