1 angular.module('egInHouseUseApp',
2 ['ngRoute', 'egCoreMod', 'egUiMod', 'egGridMod'])
4 .config(function($routeProvider, $locationProvider, $compileProvider) {
5 $locationProvider.html5Mode(true);
6 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
11 .controller('InHouseUseCtrl',
12 ['$scope','egCore','egGridDataProvider','egConfirmDialog', 'egAlertDialog',
13 function($scope, egCore, egGridDataProvider , egConfirmDialog, egAlertDialog) {
18 egCore.startup.go().then(function() {
20 // grab our non-cat types after startup
21 egCore.pcrud.search('cnct',
23 egCore.org.fullPath(egCore.auth.user().ws_ou(), true)},
25 ).then(function(list) {
26 egCore.env.absorbList(list, 'cnct');
27 $scope.nonCatTypes = list
30 // org settings for max and warning in-house-use counts
33 'ui.circ.in_house_use.entry_cap',
34 'ui.circ.in_house_use.entry_warn',
35 'circ.in_house_use.copy_alert',
36 'circ.in_house_use.checkin_alert'
37 ]).then(function(set) {
38 countWarn = set['ui.circ.in_house_use.entry_warn'] || 20;
39 $scope.countMax = countMax =
40 set['ui.circ.in_house_use.entry_cap'] || 99;
41 $scope.copyAlert = copyAlert =
42 set['circ.in_house_use.copy_alert'] || false;
43 $scope.checkinAlert = checkinAlert =
44 set['circ.in_house_use.checkin_alert'] || false;
48 $scope.useFocus = true;
49 $scope.args = {noncat_type : 'barcode', num_uses : 1, needsCountWarnModal: false };
52 var provider = egGridDataProvider.instance({});
53 provider.get = function(offset, count) {
54 return provider.arrayNotifier(checkouts, offset, count);
56 $scope.gridDataProvider = provider;
58 // currently selected non-cat type
59 $scope.selectedNcType = function() {
60 if (!egCore.env.cnct) return null; // too soon
61 var type = egCore.env.cnct.map[$scope.args.noncat_type];
62 return type ? type.name() : null;
65 $scope.onNumUsesChanged = function(){
66 $scope.args.needsCountWarnModal = countWarn < $scope.args.num_uses;
69 $scope.checkout = function(args){
70 if ($scope.args.needsCountWarnModal) {
71 // show modal to allow warning/confirmation
72 egConfirmDialog.open(egCore.strings.CONFIRM_IN_HOUSE_NUM_USES_COUNT_TITLE, '',
73 { num_uses: $scope.args.num_uses }
74 ).result.then(function(){
75 $scope.args.needsCountWarnModal = false
76 $scope.checkoutStart(args)
79 $scope.checkoutStart(args);
83 $scope.checkoutStart = function(args) {
84 $scope.copyNotFound = false;
87 count : args.num_uses,
88 'location' : egCore.auth.user().ws_ou()
91 if (args.noncat_type == 'barcode') {
93 egCore.pcrud.search('acp',
94 {barcode : args.barcode, deleted : 'f'},
97 acp : ['call_number','location'],
99 bre : ['simple_record']
101 select : { bre : ['id'] } // avoid fleshing MARC
103 ).then(function(copy) {
106 egCore.audio.play('error.in_house.copy_not_found');
107 $scope.copyNotFound = true;
111 coArgs.copyid = copy.id();
113 // LP1507807: Display the copy alert if the setting is on.
114 if ($scope.copyAlert && copy.alert_message()) {
115 egAlertDialog.open(copy.alert_message()).result;
118 // LP1507807: Display the location alert if the setting is on.
119 if ($scope.checkinAlert && copy.location().checkin_alert() == 't') {
120 egAlertDialog.open(egCore.strings.LOCATION_ALERT_MSG, {copy: copy}).result;
124 'open-ils.circ.in_house_use.create',
130 coArgs.non_cat_type = args.noncat_type;
132 'open-ils.circ.non_cat_in_house_use.create',
133 coArgs, {title : $scope.selectedNcType()}
136 $scope.args.barcode='';
139 function performCheckout(method, args, data) {
141 // FIXME: make this API stream
143 'open-ils.circ', method, egCore.auth.token(), args
145 ).then(function(resp) {
146 if (evt = egCore.evt.parse(resp)) {
147 egCore.audio.play('error.in_house');
151 egCore.audio.play('success.in_house');
153 var item = {num_uses : resp.length};
154 item.copy = data.copy;
155 item.title = data.title ||
156 data.copy.call_number().record().simple_record().title();
157 item.index = checkouts.length;
159 checkouts.unshift(item);
164 $scope.print_list = function() {
165 var print_data = { in_house_uses : [] };
167 if (checkouts.length == 0) return $q.when();
169 angular.forEach(checkouts, function(ihu) {
170 print_data.in_house_uses.push({
171 num_uses : ihu.num_uses,
172 copy : egCore.idl.toHash(ihu.copy),
177 return egCore.print.print({
178 template : 'in_house_use_list',