From de6d5face1e70e34497e8d88326dd502298befac Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 10 Dec 2013 09:47:19 -0500 Subject: [PATCH] web staff : dynamic alert/confirm dialogs Create new services egAlertDialog and egConfirmDialog, which each load a TT-based template on demand. This allows us to re-use the templates instead of having to include one template per alert type, which will grow indefinitely. Experimenting with embedding dynamic strings within the TT template, so that they can be translated alongside other template strings. Signed-off-by: Bill Erickson --- .../src/templates/staff/circ/checkin/index.tt2 | 22 +++----- .../parts/{alert_dialog.tt2 => t_alert_dialog.tt2} | 11 ++-- .../{confirm_dialog.tt2 => t_confirm_dialog.tt2} | 13 ++--- .../web/js/ui/default/staff/circ/checkin/app.js | 64 ++++++++-------------- Open-ILS/web/js/ui/default/staff/services/ui.js | 58 +++++++++++++++++++- 5 files changed, 98 insertions(+), 70 deletions(-) rename Open-ILS/src/templates/staff/parts/{alert_dialog.tt2 => t_alert_dialog.tt2} (62%) rename Open-ILS/src/templates/staff/parts/{confirm_dialog.tt2 => t_confirm_dialog.tt2} (60%) diff --git a/Open-ILS/src/templates/staff/circ/checkin/index.tt2 b/Open-ILS/src/templates/staff/circ/checkin/index.tt2 index 2e112a898b..066e543af2 100644 --- a/Open-ILS/src/templates/staff/circ/checkin/index.tt2 +++ b/Open-ILS/src/templates/staff/circ/checkin/index.tt2 @@ -10,6 +10,15 @@ + [% END %] @@ -34,17 +43,4 @@ [% INCLUDE 'staff/circ/checkin/t_checkin_table.tt2' %] - - - - - - [% END %] diff --git a/Open-ILS/src/templates/staff/parts/alert_dialog.tt2 b/Open-ILS/src/templates/staff/parts/t_alert_dialog.tt2 similarity index 62% rename from Open-ILS/src/templates/staff/parts/alert_dialog.tt2 rename to Open-ILS/src/templates/staff/parts/t_alert_dialog.tt2 index ffb1a9f4f9..e327cf6877 100644 --- a/Open-ILS/src/templates/staff/parts/alert_dialog.tt2 +++ b/Open-ILS/src/templates/staff/parts/t_alert_dialog.tt2 @@ -9,11 +9,10 @@ ng-click="ok()" aria-hidden="true">× - + - - + + diff --git a/Open-ILS/src/templates/staff/parts/confirm_dialog.tt2 b/Open-ILS/src/templates/staff/parts/t_confirm_dialog.tt2 similarity index 60% rename from Open-ILS/src/templates/staff/parts/confirm_dialog.tt2 rename to Open-ILS/src/templates/staff/parts/t_confirm_dialog.tt2 index 3e4a118f18..8c8c018523 100644 --- a/Open-ILS/src/templates/staff/parts/confirm_dialog.tt2 +++ b/Open-ILS/src/templates/staff/parts/t_confirm_dialog.tt2 @@ -1,19 +1,14 @@ + + diff --git a/Open-ILS/web/js/ui/default/staff/circ/checkin/app.js b/Open-ILS/web/js/ui/default/staff/circ/checkin/app.js index d93cb1ccbf..6d9c92653f 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/checkin/app.js +++ b/Open-ILS/web/js/ui/default/staff/circ/checkin/app.js @@ -50,8 +50,10 @@ function($q, egOrg, egPCRUD) { * Manages checkin */ .controller('CheckinCtrl', - ['$scope','$q','$modal','egStartup','checkinSvc','egNet','egAuth','orgAddrSvc','egOrg','egPCRUD', -function($scope, $q, $modal, egStartup, checkinSvc, egNet, egAuth, orgAddrSvc, egOrg, egPCRUD) { + ['$scope','$q','$modal','egStartup','checkinSvc','egNet', 'egAuth', + 'orgAddrSvc','egOrg','egPCRUD','egAlertDialog','egConfirmDialog','egCheckinStrings', +function($scope, $q, $modal, egStartup, checkinSvc, egNet, egAuth, + orgAddrSvc, egOrg, egPCRUD, egAlertDialog, egConfirmDialog, egCheckinStrings) { // run egStartup here since it's not handled via resolver egStartup.go().then( @@ -119,10 +121,27 @@ function($scope, $q, $modal, egStartup, checkinSvc, egNet, egAuth, orgAdd openRouteDialog('./circ/checkin/t_transit_dialog', evt, args); break; case 'ASSET_COPY_NOT_FOUND': - openAlertDialog('uncat_alert_dialog', evt, args); + $scope.blurMe = true; + egAlertDialog.open(egCheckinStrings.UNCAT_ALERT_DIALOG, args) + .result.then(function() {$scope.focusMe = true}); break; case 'COPY_ALERT_MESSAGE': - openConfirmDialog('alert_msg_confirm_dialog', evt, args); + $scope.blurMe = true; + egConfirmDialog.open( + egCheckinStrings.COPY_ALERT_MSG_DIALOG_TITLE, + evt.payload, // payload == alert message text + { copy_barcode : args.copy_barcode, + ok : function() { + // on confirm, redo checkout w/ override + performCheckin(args, true) + }, + cancel : function() { + // on cancel, push the event on the list + // to show that it happened + checkinSvc.checkins.items.push(evt); + } + } + ).result.then(function() {$scope.focusMe = true}) break; default: console.warn('unhandled checkin response : ' + evt.textcode); @@ -133,43 +152,6 @@ function($scope, $q, $modal, egStartup, checkinSvc, egNet, egAuth, orgAdd } } - function openAlertDialog(id, evt, args) { - // avoid unintended checkins while the dialog is open - $scope.blurMe = true; - $modal.open({ - templateUrl: id, - controller: - ['$scope', '$modalInstance', - function($scope, $modalInstance) { - $scope.args = args; - $scope.ok = function() {$modalInstance.close()} - }] - }).result.then(function() {$scope.focusMe = true}); - } - - function openConfirmDialog(id, evt, args) { - // avoid unintended checkins while the dialog is open - $scope.blurMe = true; - $modal.open({ - templateUrl: id, - controller: - ['$scope', '$modalInstance', - function($scope, $modalInstance) { - $scope.args = args; - $scope.evt = evt; - $scope.ok = function() { - performCheckin(args, true); - $modalInstance.close() - } - $scope.cancel = function() { - $modalInstance.close() - checkinSvc.checkins.items.push(evt); - } - }] - }).result.then(function() {$scope.focusMe = true}); - } - - function openRouteDialog(tmpl, evt, args) { // avoid unintended checkins while the dialog is open $scope.blurMe = true; 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 4a9d892e6d..4eebe7d36f 100644 --- a/Open-ILS/web/js/ui/default/staff/services/ui.js +++ b/Open-ILS/web/js/ui/default/staff/services/ui.js @@ -1,7 +1,7 @@ /** * UI tools and directives. */ -angular.module('egUiMod', []) +angular.module('egUiMod', ['ui.bootstrap']) /** @@ -77,3 +77,59 @@ function($timeout, $parse) { return items.slice().reverse(); }; }) + + +/** + * egAlertDialog.open({message : 'hello {{name}}'}).result.then( + * function() { console.log('alert closed') }); + */ +.factory('egAlertDialog', function($modal, $interpolate) { + var service = {}; + + service.open = function(message, msg_scope) { + return $modal.open({ + templateUrl: './parts/t_alert_dialog', + controller: ['$scope', '$modalInstance', + function($scope, $modalInstance) { + $scope.message = $interpolate(message)(msg_scope); + $scope.ok = function() { + if (msg_scope.ok) msg_scope.ok(); + $modalInstance.close() + } + } + ] + }); + } + + return service; +}) + +/** + * egConfirmDialog.open("some message goes {{here}}", { + * here : 'foo', ok : function() {}, cancel : function() {}}); + */ +.factory('egConfirmDialog', function($modal, $interpolate) { + var service = {}; + + service.open = function(title, message, msg_scope) { + return $modal.open({ + templateUrl: './parts/t_confirm_dialog', + controller: ['$scope', '$modalInstance', + function($scope, $modalInstance) { + $scope.title = $interpolate(title)(msg_scope); + $scope.message = $interpolate(message)(msg_scope); + $scope.ok = function() { + if (msg_scope.ok) msg_scope.ok(); + $modalInstance.close() + } + $scope.cancel = function() { + if (msg_scope.cancel) msg_scope.cancel(); + $modalInstance.close() + } + } + ] + }) + } + + return service; +}) -- 2.11.0