From 1b16bcf78e898166fe5603353e9a27c22afae428 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Wed, 11 Feb 2015 08:49:12 -0500 Subject: [PATCH] LP#1402797 Make grid action context menu safe for multiple grids per page Signed-off-by: Mike Rylander Signed-off-by: Bill Erickson --- Open-ILS/web/js/ui/default/staff/services/grid.js | 36 ++++++++++------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/Open-ILS/web/js/ui/default/staff/services/grid.js b/Open-ILS/web/js/ui/default/staff/services/grid.js index 7ba2f78494..ccb9b40a2f 100644 --- a/Open-ILS/web/js/ui/default/staff/services/grid.js +++ b/Open-ILS/web/js/ui/default/staff/services/grid.js @@ -484,50 +484,46 @@ angular.module('egGridMod', + action.label + '" => ' + E + "\n" + E.stack); } - if ($scope.action_context_y || $scope.action_context_x) - $scope.hideActionContextMenu(); + if ($scope.action_context_showing) $scope.hideActionContextMenu(); } } $scope.hideActionContextMenu = function () { - var menu_dom = $('body').find('.grid-action-dropdown')[0]; - $(menu_dom).css({ + $($scope.menu_dom).css({ display: '', width: $scope.action_context_width, top: $scope.action_context_y, left: $scope.action_context_x }); - $($scope.action_context_parent).append(menu_dom); + $($scope.action_context_parent).append($scope.menu_dom); $scope.action_context_oldy = $scope.action_context_oldx = 0; - $('body').unbind('click.remove_context_menu'); + $('body').unbind('click.remove_context_menu_'+$scope.action_context_index); $scope.action_context_showing = false; } $scope.action_context_showing = false; $scope.showActionContextMenu = function ($event) { - if (!grid.getSelectedItems().length) // Nothing selected, fire the click event - $event.target.click(); - var current_parent = $scope.grid_element; - if ($scope.action_context_showing) { - current_parent = $('body'); - } + // Have to gather these here, instead of inside link() + if (!$scope.menu_dom) $scope.menu_dom = $($scope.grid_element).find('.grid-action-dropdown')[0]; + if (!$scope.action_context_parent) $scope.action_context_parent = $($scope.menu_dom).parent(); - var menu_dom = $(current_parent).find('.grid-action-dropdown')[0]; + if (!grid.getSelectedItems().length) // Nothing selected, fire the click event + $event.target.click(); if (!$scope.action_context_showing) { - $scope.action_context_width = $(menu_dom).css('width'); - $scope.action_context_y = $(menu_dom).css('top'); - $scope.action_context_x = $(menu_dom).css('left'); - $scope.action_context_parent = $(menu_dom).parent(); + $scope.action_context_width = $($scope.menu_dom).css('width'); + $scope.action_context_y = $($scope.menu_dom).css('top'); + $scope.action_context_x = $($scope.menu_dom).css('left'); $scope.action_context_showing = true; + $scope.action_context_index = Math.floor((Math.random() * 1000) + 1); - $('body').append($(menu_dom)); - $('body').bind('click.remove_context_menu', $scope.hideActionContextMenu); + $('body').append($($scope.menu_dom)); + $('body').bind('click.remove_context_menu_'+$scope.action_context_index, $scope.hideActionContextMenu); } - $(menu_dom).css({ + $($scope.menu_dom).css({ display: 'block', width: $scope.action_context_width, top: $event.pageY, -- 2.11.0