1 angular.module('egInHouseUseApp',
2 ['ngRoute', 'egCoreMod', 'egUiMod', 'egGridMod'])
4 .config(function($routeProvider, $locationProvider, $compileProvider) {
5 $locationProvider.html5Mode(true);
6 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|mailto|blob):/); // grid export
10 .controller('InHouseUseCtrl',
11 ['$scope','egCore','egGridDataProvider','egConfirmDialog',
12 'egAlertDialog','egBibDisplay',
13 function($scope , egCore , egGridDataProvider , egConfirmDialog,
14 egAlertDialog , egBibDisplay) {
19 egCore.startup.go().then(function() {
21 // grab our non-cat types after startup
22 egCore.pcrud.search('cnct',
24 egCore.org.fullPath(egCore.auth.user().ws_ou(), true)},
26 ).then(function(list) {
27 egCore.env.absorbList(list, 'cnct');
28 $scope.nonCatTypes = list
31 // org settings for max and warning in-house-use counts
34 'ui.circ.in_house_use.entry_cap',
35 'ui.circ.in_house_use.entry_warn',
36 'circ.in_house_use.copy_alert',
37 'circ.in_house_use.checkin_alert'
38 ]).then(function(set) {
39 countWarn = set['ui.circ.in_house_use.entry_warn'] || 20;
40 $scope.countMax = countMax =
41 set['ui.circ.in_house_use.entry_cap'] || 99;
42 $scope.copyAlert = copyAlert =
43 set['circ.in_house_use.copy_alert'] || false;
44 $scope.checkinAlert = checkinAlert =
45 set['circ.in_house_use.checkin_alert'] || false;
49 $scope.bcFocus = true;
50 $scope.args = {noncat_type : 'barcode', num_uses : 1, needsCountWarnModal: false };
53 var provider = egGridDataProvider.instance({});
54 provider.get = function(offset, count) {
55 return provider.arrayNotifier(checkouts, offset, count);
57 $scope.gridDataProvider = provider;
59 // currently selected non-cat type
60 $scope.selectedNcType = function() {
61 if (!egCore.env.cnct) return null; // too soon
62 var type = egCore.env.cnct.map[$scope.args.noncat_type];
63 return type ? type.name() : null;
66 $scope.onNumUsesChanged = function(){
67 $scope.args.needsCountWarnModal = countWarn < $scope.args.num_uses;
70 $scope.checkout = function(args){
71 if ($scope.args.needsCountWarnModal) {
72 // show modal to allow warning/confirmation
73 egConfirmDialog.open(egCore.strings.CONFIRM_IN_HOUSE_NUM_USES_COUNT_TITLE, '',
74 { num_uses: $scope.args.num_uses }
75 ).result.then(function(){
76 $scope.args.needsCountWarnModal = false
77 $scope.checkoutStart(args)
80 $scope.checkoutStart(args);
84 $scope.checkoutStart = function(args) {
85 $scope.copyNotFound = false;
88 count : args.num_uses,
89 'location' : egCore.auth.user().ws_ou()
92 if (args.noncat_type == 'barcode') {
94 egCore.pcrud.search('acp',
95 {barcode : args.barcode, deleted : 'f'},
98 acp : ['call_number','location'],
99 acn : ['record', 'prefix', 'suffix'],
100 // We don't need to display a wide range of bib
101 // fields in this UI. Fetch the flat display since
102 // it requires less DB-side munging (and as an example).
103 bre : ['flat_display_entries']
105 select : { bre : ['id'] } // avoid fleshing MARC
107 ).then(function(copy) {
110 egCore.audio.play('error.in_house.copy_not_found');
111 $scope.copyNotFound = true;
115 coArgs.copyid = copy.id();
117 copy.call_number().record().flat_display_entries(
118 egBibDisplay.mfdeToHash(
119 copy.call_number().record().flat_display_entries())
122 // LP1507807: Display the copy alert if the setting is on.
123 if ($scope.copyAlert && copy.alert_message()) {
124 egAlertDialog.open(copy.alert_message()).result;
127 // LP1507807: Display the location alert if the setting is on.
128 if ($scope.checkinAlert && copy.location().checkin_alert() == 't') {
129 egAlertDialog.open(egCore.strings.LOCATION_ALERT_MSG, {copy: copy}).result;
133 'open-ils.circ.in_house_use.create',
139 coArgs.non_cat_type = args.noncat_type;
141 'open-ils.circ.non_cat_in_house_use.create',
142 coArgs, {title : $scope.selectedNcType()}
145 $scope.args.barcode='';
148 function performCheckout(method, args, data) {
150 // FIXME: make this API stream
152 'open-ils.circ', method, egCore.auth.token(), args
154 ).then(function(resp) {
155 if (evt = egCore.evt.parse(resp)) {
156 egCore.audio.play('error.in_house');
160 egCore.audio.play('success.in_house');
162 var item = {num_uses : resp.length};
163 item.copy = data.copy;
164 item.title = data.title ||
165 data.copy.call_number().record().flat_display_entries().title;
166 item.index = checkouts.length;
168 checkouts.unshift(item);
173 $scope.print_list = function() {
174 var print_data = { in_house_uses : [] };
176 if (checkouts.length == 0) return $q.when();
178 angular.forEach(checkouts, function(ihu) {
179 print_data.in_house_uses.push({
180 num_uses : ihu.num_uses,
181 copy : egCore.idl.toHash(ihu.copy),
186 return egCore.print.print({
187 template : 'in_house_use_list',