From b368a437217dec5a401fdaa4cf9396ed3fb11793 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Mon, 13 Apr 2015 19:24:14 +0000 Subject: [PATCH] webstaff: always calculate context menu for egMarcEditEditable on the fly This way, the correct context menus get generated for a new field/subfield entry or when a field's tag is changed. Signed-off-by: Galen Charlton Signed-off-by: Jason Stephenson --- .../ui/default/staff/cat/services/marcedit.js | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js b/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js index aad3d007b5..d3029e3d10 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js +++ b/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js @@ -60,27 +60,27 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) if ($scope.contextItemContainer && angular.isArray($scope.$parent[$scope.contextItemContainer])) $scope.item_container = $scope.$parent[$scope.contextItemContainer]; else if ($scope.contextItemGenerator) - $scope.item_container = $scope.contextItemGenerator(); + $scope.item_generator = $scope.contextItemGenerator; $scope.showContext = function (event) { - if ($scope.context_menu_element) { - console.log('Reshowing context menu...'); - $('body').trigger('click'); - $($scope.context_menu_element).css({ display: 'block', top: event.pageY, left: event.pageX }); - $('body').on('click.context_menu',function() { - $($scope.context_menu_element).css('display','none'); - $('body').off('click.context_menu'); - }); - return false; + $scope.item_list = []; + if ($scope.item_container) { + $scope.item_list = $scope.item_container; + } else if ($scope.item_generator) { + // always recalculate; tag and/or subfield + // codes may have changed + $scope.item_list = $scope.item_generator(); + } else { + return true; } - if (angular.isArray($scope.item_container)) { // we have a list of values or transforms + if (angular.isArray($scope.item_list) && $scope.item_list.length > 0) { // we have a list of values or transforms console.log('Showing context menu...'); $('body').trigger('click'); var tmpl = ''; var tnode = angular.element(tmpl); @@ -92,8 +92,6 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) left: event.pageX }); - $scope.context_menu_element = tnode; - $timeout(function() { var e = $compile(tnode)($scope); }, 0); @@ -118,8 +116,7 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) element.bind('change', function (e) { element.size = scope.max || parseInt(scope.content.length * 1.1) }); - if (scope.item_container && scope.item_container.length) - element.bind('contextmenu', scope.showContext); + element.bind('contextmenu', scope.showContext); } } }]) -- 2.43.2