Skip to content

Commit

Permalink
Afform - Insta-refresh menubar when adding a navigation item
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Jul 18, 2022
1 parent cd6134c commit 1d67800
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
undoHistory = [],
undoPosition = 0,
undoAction = null,
lastSaved,
sortableOptions = {};

// ngModelOptions to debounce input
Expand Down Expand Up @@ -100,6 +101,7 @@
$scope.layoutHtml = '';
$scope.entities = {};
setEditorLayout();
setLastSaved();

if (editor.afform.navigation) {
loadNavigationMenu();
Expand Down Expand Up @@ -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();
});
};

Expand All @@ -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;
Expand Down

0 comments on commit 1d67800

Please sign in to comment.