From: Bill Erickson Date: Tue, 10 Dec 2013 14:47:19 +0000 (-0500) Subject: web staff : dynamic alert/confirm dialogs X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=de6d5face1e70e34497e8d88326dd502298befac;p=working%2FEvergreen.git 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 --- 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/alert_dialog.tt2 deleted file mode 100644 index ffb1a9f4f9..0000000000 --- a/Open-ILS/src/templates/staff/parts/alert_dialog.tt2 +++ /dev/null @@ -1,19 +0,0 @@ - - diff --git a/Open-ILS/src/templates/staff/parts/confirm_dialog.tt2 b/Open-ILS/src/templates/staff/parts/confirm_dialog.tt2 deleted file mode 100644 index 3e4a118f18..0000000000 --- a/Open-ILS/src/templates/staff/parts/confirm_dialog.tt2 +++ /dev/null @@ -1,25 +0,0 @@ - - diff --git a/Open-ILS/src/templates/staff/parts/t_alert_dialog.tt2 b/Open-ILS/src/templates/staff/parts/t_alert_dialog.tt2 new file mode 100644 index 0000000000..e327cf6877 --- /dev/null +++ b/Open-ILS/src/templates/staff/parts/t_alert_dialog.tt2 @@ -0,0 +1,18 @@ + + diff --git a/Open-ILS/src/templates/staff/parts/t_confirm_dialog.tt2 b/Open-ILS/src/templates/staff/parts/t_confirm_dialog.tt2 new file mode 100644 index 0000000000..8c8c018523 --- /dev/null +++ b/Open-ILS/src/templates/staff/parts/t_confirm_dialog.tt2 @@ -0,0 +1,20 @@ + + 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; +})