</label>
</div>
<div class="pad-horiz">
- <button class="btn btn-default"
- ng-click="print_receipt()">[% l('Print Receipt') %]</button>
+ <span ng-show="may_email_receipt()" class="glyphicon glyphicon-envelope" aria-label="[% l('Send Email Receipt') %]"></span>
+ <span ng-show="!may_email_receipt()" class="glyphicon glyphicon-print" aria-label="[% l('Print Receipt') %]"></span>
+ <div class="btn-group" uib-dropdown>
+ <button ng-click="print_or_email_receipt()" id="quick-button" type="button" ng-disabled="checkouts.length == 0" class="btn btn-default">[% l('Quick Receipt') %]</button>
+ <button type="button" ng-disabled="checkouts.length == 0" class="btn btn-default" uib-dropdown-toggle>
+ <span class="caret"></span>
+ <span class="sr-only">[% l('receipt option') %]</span>
+ </button>
+ <ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby="quick-button">
+ <li role="menuitem" ng-class="{disabled : !has_email_address()}"><a ng-click="email_receipt()" a-disabled="!has_email_address()" href="#">[% l('Email Receipt') %]</a></li>
+ <li role="menuitem"><a ng-click="print_receipt()" href="#">[% l('Print Receipt') %]</a></li>
+ </ul>
+ </div>
</div>
- <div>
+ <div class="btn-group" uib-dropdown>
<button class="btn btn-default"
- ng-click="done()">[% l('Done') %]</button>
+ id="done-button" type="button"
+ ng-click="done_auto_receipt()">[% l('Done') %]</button>
+ <button type="button" class="btn btn-default" uib-dropdown-toggle>
+ <span class="caret"></span>
+ <span class="sr-only">[% l('receipt option') %]</span>
+ </button>
+ <ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby="done-button">
+ <li role="menuitem"><a ng-click="done_no_receipt()" href="#">[% l('No Receipt') %]</a></li>
+ <li role="menuitem" ng-class="{disabled : !has_email_address()}"><a ng-click="done_email_receipt()" a-disabled="!has_email_address()" href="#">[% l('Email Receipt') %]</a></li>
+ <li role="menuitem"><a ng-click="done_print_receipt()" href="#">[% l('Print Receipt') %]</a></li>
+ </ul>
</div>
</div>
angular.module('egPatronApp').controller('PatronCheckoutCtrl',
['$scope','$q','$routeParams','egCore','egUser','patronSvc',
- 'egGridDataProvider','$location','$timeout','egCirc',
+ 'egGridDataProvider','$location','$timeout','egCirc','ngToast',
function($scope , $q , $routeParams , egCore , egUser , patronSvc ,
- egGridDataProvider , $location , $timeout , egCirc) {
+ egGridDataProvider , $location , $timeout , egCirc , ngToast) {
$scope.initTab('checkout', $routeParams.id).finally(function(){
$scope.focusMe = true;
);
}
+ function setting_value (user, setting) {
+ if (user) {
+ var list = user.settings().filter(function(s){
+ return s.name() == setting;
+ });
+
+ if (list.length) return list[0].value();
+ }
+ }
+
+ $scope.has_email_address = function() {
+ return (
+ patronSvc.current &&
+ patronSvc.current.email() &&
+ patronSvc.current.email().match(/.*@.*/).length
+ );
+ }
+
+ $scope.may_email_receipt = function() {
+ return (
+ $scope.has_email_address() &&
+ setting_value(
+ patronSvc.current,
+ 'circ.send_email_checkout_receipts'
+ ) == 'true'
+ );
+ }
+
$scope.using_hatch = egCore.hatch.usingHatch();
egCore.hatch.getItem('circ.checkout.strict_barcode')
});
}
- // Redirect the user to the barcode entry page to load a new patron.
- // If configured to do so, print the receipt first
- $scope.done = function() {
- if (printOnComplete) {
-
- $scope.print_receipt().then(function() {
- $location.path('/circ/patron/bcsearch');
+ $scope.email_receipt = function() {
+ if ($scope.has_email_address() && $scope.checkouts.length) {
+ return egCore.net.request(
+ 'open-ils.circ',
+ 'open-ils.circ.checkout.batch_notify.session.atomic',
+ egCore.auth.token(),
+ patronSvc.current.id(),
+ $scope.checkouts.map(function (c) { return c.circ.id() })
+ ).then(function() {
+ ngToast.create(egCore.strings.EMAILED_CHECKOUT_RECEIPT);
+ return $q.when();
});
+ }
+ return $q.when();
+ }
+
+ $scope.print_or_email_receipt = function() {
+ if ($scope.may_email_receipt()) return $scope.email_receipt();
+ $scope.print_receipt();
+ }
+ // set of functions to issue a receipt (if desired), then
+ // redirect
+ $scope.done_auto_receipt = function() {
+ if ($scope.may_email_receipt()) {
+ $scope.email_receipt().then(function() {
+ $scope.done_redirect();
+ });
} else {
- $location.path('/circ/patron/bcsearch');
+ if (printOnComplete) {
+
+ $scope.print_receipt().then(function() {
+ $scope.done_redirect();
+ });
+
+ } else {
+ $scope.done_redirect();
+ }
}
}
+ $scope.done_print_receipt = function() {
+ $scope.print_receipt().then( function () {
+ $scope.done_redirect();
+ });
+ }
+ $scope.done_email_receipt = function() {
+ $scope.email_receipt().then( function () {
+ $scope.done_redirect();
+ });
+ }
+ $scope.done_no_receipt = function() {
+ $scope.done_redirect();
+ }
+
+ // Redirect the user to the barcode entry page to load a new patron.
+ $scope.done_redirect = function() {
+ $location.path('/circ/patron/bcsearch');
+ }
}])