From 1d678002d48a02f78fdedc658640a12ec4b81984 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 18 Jul 2022 12:17:37 -0400 Subject: [PATCH] Afform - Insta-refresh menubar when adding a navigation item --- .../ang/afGuiEditor/afGuiEditor.component.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js b/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js index 12f4d927de..a1bdb7a7aa 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js @@ -30,6 +30,7 @@ undoHistory = [], undoPosition = 0, undoAction = null, + lastSaved, sortableOptions = {}; // ngModelOptions to debounce input @@ -100,6 +101,7 @@ $scope.layoutHtml = ''; $scope.entities = {}; setEditorLayout(); + setLastSaved(); if (editor.afform.navigation) { loadNavigationMenu(); @@ -577,6 +579,13 @@ snapshot.saved = index === undoPosition; snapshot.afform.name = data[0].name; }); + if (!angular.equals(afform.navigation, lastSaved.navigation) || + (afform.server_route !== lastSaved.server_route && afform.navigation) + (afform.icon !== lastSaved.icon && afform.navigation) + ) { + refreshMenubar(); + } + setLastSaved(); }); }; @@ -590,6 +599,19 @@ } }); + // Sets last-saved form metadata (used to determine if the menubar needs refresh) + function setLastSaved() { + lastSaved = JSON.parse(angular.toJson(editor.afform)); + delete lastSaved.layout; + } + + // Force-refresh the menubar to instantly display the afform menu item + function refreshMenubar() { + CRM.menubar.destroy(); + CRM.menubar.cacheCode = Math.random(); + CRM.menubar.initialize(); + } + // Force editor panels to a fixed height, to avoid palette scrolling offscreen function fixEditorHeight() { var height = $(window).height() - $('#afGuiEditor').offset().top; -- 2.25.1