From cdab4c76d7f8b077aa838b1b9208fb4e920c7aeb Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 16 Dec 2015 21:10:43 -0500 Subject: [PATCH] LP#1452950 page unload warning prompt service Signed-off-by: Bill Erickson Signed-off-by: Galen Charlton --- Open-ILS/src/templates/staff/base_js.tt2 | 8 +++++++ Open-ILS/web/js/ui/default/staff/services/ui.js | 28 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/Open-ILS/src/templates/staff/base_js.tt2 b/Open-ILS/src/templates/staff/base_js.tt2 index db4f85a550..c2b1abba74 100644 --- a/Open-ILS/src/templates/staff/base_js.tt2 +++ b/Open-ILS/src/templates/staff/base_js.tt2 @@ -48,5 +48,13 @@ // pending api_level thunking in C // OpenSRF.api_level = 2; OpenSRF.Session.transport = OSRF_TRANSPORT_TYPE_WS; + + // Here lie JS strings that may be used on any/all pages. + angular.module('egCoreMod').run(['egStrings', function(s) { + s.EG_UNLOAD_CTRL_PROMPT_MSG = + '[% l('This page may have unsaved data.\n\nAre you sure you want to leave this page?') %]'; + s.EG_UNLOAD_PAGE_PROMPT_MSG = + '[% l('This page may have unsaved data.') %]'; + }]); diff --git a/Open-ILS/web/js/ui/default/staff/services/ui.js b/Open-ILS/web/js/ui/default/staff/services/ui.js index 4fe04a7676..e2c6b9369a 100644 --- a/Open-ILS/web/js/ui/default/staff/services/ui.js +++ b/Open-ILS/web/js/ui/default/staff/services/ui.js @@ -184,6 +184,34 @@ function($modal, $interpolate) { return service; }]) +/** + * Warn on page unload and give the user a chance to avoid navigating + * away from the current page. + * NOTE: we can't use an egUnloadDialog as the dialog builder, because + * it renders asynchronously, which allows the page to redirect before + * the dialog appears. + */ +.factory('egUnloadPrompt', [ + '$window','egStrings', +function($window , egStrings) { + var service = {}; + + service.attach = function($scope, msg) { + + // handle page change + $($window).on('beforeunload', function() { + return msg || egStrings.EG_UNLOAD_PAGE_PROMPT_MSG; + }); + + // handle controller change (e.g. tabbed navigation) + $scope.$on('$locationChangeStart', function(evt, next, current) { + if (!confirm(msg || egStrings.EG_UNLOAD_CTRL_PROMPT_MSG)) + evt.preventDefault(); + }); + }; + return service; +}]) + .directive('aDisabled', function() { return { restrict : 'A', -- 2.11.0