N°3634 - Lists: Fix shortcut not being added "live" to navigation menu on creation

This commit is contained in:
Molkobain
2021-03-30 18:18:01 +02:00
parent 0c87bd9aad
commit 95f328d2af
2 changed files with 68 additions and 18 deletions

View File

@@ -49,7 +49,8 @@ $(function()
menu_filter_hint_close: '[data-role="ibo-navigation-menu--menu-filter-hint-close"]',
user_menu_toggler: '[data-role="ibo-navigation-menu--user-menu--toggler"]',
user_menu_container: '[data-role="ibo-navigation-menu--user-menu-container"]',
user_menu: '[data-role="ibo-navigation-menu--user-menu-container"] > [data-role="ibo-popover-menu"]'
user_menu: '[data-role="ibo-navigation-menu--user-menu-container"] > [data-role="ibo-popover-menu"]',
menu_node: '[data-role="ibo-navigation-menu--menu-node"]',
},
filter_throttle_timeout: null,
@@ -100,6 +101,11 @@ $(function()
this.element.find(this.js_selectors.menu_filter_hint_close).on('click', function (oEvent) {
me._onFilterHintCloseClick(oEvent);
});
// External events
oBodyElem.on('add_shortcut_node.navigation_menu.itop', function (oEvent, oData) {
me._onAddShortcutNode(oData);
});
},
// Events callbacks
@@ -182,23 +188,24 @@ $(function()
// Position focus in the input for better UX
this._focusFilter();
},
_onFilterHintCloseClick: function(oEvent)
{
_onFilterHintCloseClick: function (oEvent) {
this.element.find(this.js_selectors.menu_filter_hint).hide();
// Save state in user preferences
SetUserPreference('navigation_menu.show_filter_hint', false, true);
},
_onAddShortcutNode: function (oData) {
this._addShortcut(oData.parent_menu_node_id, oData.new_menu_node_html_rendering);
},
// Methods
_checkIfClickShouldCloseDrawer: function(oEvent)
{
if(
_checkIfClickShouldCloseDrawer: function (oEvent) {
if (
$(oEvent.target.closest(this.js_selectors.menu_drawer)).length === 0
&& $(oEvent.target.closest('[data-role="ibo-navigation-menu--menu-group"]')).length === 0
&& $(oEvent.target.closest(this.js_selectors.menu_toggler)).length === 0
)
{
) {
this._closeDrawer();
}
},
@@ -352,13 +359,27 @@ $(function()
.done(function (data) {
if (data.code === "done") {
for (const [key, value] of Object.entries(data.counts)) {
let menuEntry = me.element.find('[data-menu-id="' + key + '"]');
let menuEntry = me.element.find('[data-menu-id="'+key+'"]');
menuEntry.html(value);
menuEntry.show();
}
}
});
}
},
/**
* @param sParentMenuNodeId {string} ID of the parent menu node the shortcut should be added to
* @param sNewMenuNodeHtmlRendering {string} HTML rendering of the new menu node to add
* @return {boolean}
*/
_addShortcut: function (sParentMenuNodeId, sNewMenuNodeHtmlRendering) {
const oNewMenuNodeContainerElem = this.element.find(this.js_selectors.menu_node+'[data-menu-node-id="'+sParentMenuNodeId+'"] > ul');
if (oNewMenuNodeContainerElem.length === 0) {
return false;
}
oNewMenuNodeContainerElem.append(sNewMenuNodeHtmlRendering);
return true;
}
});
});

View File

@@ -4,6 +4,7 @@
* @license http://opensource.org/licenses/AGPL-3.0
*/
use Combodo\iTop\Application\TwigBase\Twig\TwigHelper;
use Combodo\iTop\Controller\AjaxRenderController;
use Combodo\iTop\Controller\Base\Layout\ActivityPanelController;
use Combodo\iTop\Controller\PreferencesController;
@@ -1221,6 +1222,7 @@ EOF
$aContext = $oAppContext->GetAsHash();
$sContext = serialize($aContext);
// Create shortcut
/** @var ShortcutOQL $oShortcut */
$oShortcut = MetaModel::NewObject("ShortcutOQL");
$oShortcut->Set('user_id', UserRights::GetUserId());
@@ -1228,8 +1230,7 @@ EOF
$oShortcut->Set("name", $aValues['name']);
$oShortcut->Set("oql", $aValues['oql']);
$iAutoReload = (int)$aValues['auto_reload_sec'];
if (($aValues['auto_reload']) && ($iAutoReload > 0))
{
if (($aValues['auto_reload']) && ($iAutoReload > 0)) {
$oShortcut->Set("auto_reload_sec", max(MetaModel::GetConfig()->Get('min_reload_interval'), $iAutoReload));
$oShortcut->Set("auto_reload", 'custom');
}
@@ -1239,14 +1240,42 @@ EOF
$oShortcut->CloneTableSettings($aValues['table_settings']);
// Add the menu node in the right place
//
// Mmmm... already done because the newly created menu is read from the DB
// as soon as we invoke DisplayMenu
// Add shortcut to current menu
// - Init. app. menu
ApplicationMenu::LoadAdditionalMenus();
// Refresh the menu pane
$aExtraParams = array();
ApplicationMenu::DisplayMenu($oPage, $aExtraParams);
// - Find newly created shortcut
$aNewShortcutNode = null;
$sMenuGroupId = 'MyShortcuts';
$sMenuGroupIdx = ApplicationMenu::GetMenuIndexById($sMenuGroupId);
if (0 <= $sMenuGroupIdx) {
$sNewShortcutId = $sMenuGroupId.'_'.$oShortcut->GetKey();
$aShortcutsNodes = ApplicationMenu::GetSubMenuNodes($sMenuGroupIdx);
foreach ($aShortcutsNodes as $aShortcutNode) {
if ($sNewShortcutId === $aShortcutNode['sId']) {
$aNewShortcutNode = $aShortcutNode;
break;
}
}
}
// - If shortcut found, insert it in the navigation menu
if (!empty($aNewShortcutNode)) {
$sHtml = TwigHelper::RenderTemplate(
TwigHelper::GetTwigEnvironment(TwigHelper::ENUM_TEMPLATES_BASE_PATH_BACKOFFICE),
['aMenuNode' => $aNewShortcutNode],
'base/layouts/navigation-menu/menu-node'
);
// Important: Mind the back ticks to avoid line breaks to break the JS
$oPage->add_script(<<<JS
$('body').trigger('add_shortcut_node.navigation_menu.itop', {
parent_menu_node_id: '{$sMenuGroupId}',
new_menu_node_html_rendering: `{$sHtml}`
});
JS
);
}
break;
case 'shortcut_rename_dlg':