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', 'egAlertDialog',
12 function($scope, egCore, egGridDataProvider , egConfirmDialog, egAlertDialog) {
17 egCore.startup.go().then(function() {
19 // grab our non-cat types after startup
20 egCore.pcrud.search('cnct',
22 egCore.org.fullPath(egCore.auth.user().ws_ou(), true)},
24 ).then(function(list) {
25 egCore.env.absorbList(list, 'cnct');
26 $scope.nonCatTypes = list
29 // org settings for max and warning in-house-use counts
32 'ui.circ.in_house_use.entry_cap',
33 'ui.circ.in_house_use.entry_warn',
34 'circ.in_house_use.copy_alert',
35 'circ.in_house_use.checkin_alert'
36 ]).then(function(set) {
37 countWarn = set['ui.circ.in_house_use.entry_warn'] || 20;
38 $scope.countMax = countMax =
39 set['ui.circ.in_house_use.entry_cap'] || 99;
40 $scope.copyAlert = copyAlert =
41 set['circ.in_house_use.copy_alert'] || false;
42 $scope.checkinAlert = checkinAlert =
43 set['circ.in_house_use.checkin_alert'] || false;
47 $scope.useFocus = true;
48 $scope.args = {noncat_type : 'barcode', num_uses : 1, needsCountWarnModal: false };
51 var provider = egGridDataProvider.instance({});
52 provider.get = function(offset, count) {
53 return provider.arrayNotifier(checkouts, offset, count);
55 $scope.gridDataProvider = provider;
57 // currently selected non-cat type
58 $scope.selectedNcType = function() {
59 if (!egCore.env.cnct) return null; // too soon
60 var type = egCore.env.cnct.map[$scope.args.noncat_type];
61 return type ? type.name() : null;
64 $scope.onNumUsesChanged = function(){
65 $scope.args.needsCountWarnModal = countWarn < $scope.args.num_uses;
68 $scope.checkout = function(args){
69 if ($scope.args.needsCountWarnModal) {
70 // show modal to allow warning/confirmation
71 egConfirmDialog.open(egCore.strings.CONFIRM_IN_HOUSE_NUM_USES_COUNT_TITLE, '',
72 { num_uses: $scope.args.num_uses }
73 ).result.then(function(){
74 $scope.args.needsCountWarnModal = false
75 $scope.checkoutStart(args)
78 $scope.checkoutStart(args);
82 $scope.checkoutStart = function(args) {
83 $scope.copyNotFound = false;
86 count : args.num_uses,
87 'location' : egCore.auth.user().ws_ou()
90 if (args.noncat_type == 'barcode') {
92 egCore.pcrud.search('acp',
93 {barcode : args.barcode, deleted : 'f'},
96 acp : ['call_number','location'],
97 acn : ['record', 'prefix', 'suffix'],
98 bre : ['simple_record']
100 select : { bre : ['id'] } // avoid fleshing MARC
102 ).then(function(copy) {
105 egCore.audio.play('error.in_house.copy_not_found');
106 $scope.copyNotFound = true;
110 coArgs.copyid = copy.id();
112 // LP1507807: Display the copy alert if the setting is on.
113 if ($scope.copyAlert && copy.alert_message()) {
114 egAlertDialog.open(copy.alert_message()).result;
117 // LP1507807: Display the location alert if the setting is on.
118 if ($scope.checkinAlert && copy.location().checkin_alert() == 't') {
119 egAlertDialog.open(egCore.strings.LOCATION_ALERT_MSG, {copy: copy}).result;
123 'open-ils.circ.in_house_use.create',
129 coArgs.non_cat_type = args.noncat_type;
131 'open-ils.circ.non_cat_in_house_use.create',
132 coArgs, {title : $scope.selectedNcType()}
135 $scope.args.barcode='';
138 function performCheckout(method, args, data) {
140 // FIXME: make this API stream
142 'open-ils.circ', method, egCore.auth.token(), args
144 ).then(function(resp) {
145 if (evt = egCore.evt.parse(resp)) {
146 egCore.audio.play('error.in_house');
150 egCore.audio.play('success.in_house');
152 var item = {num_uses : resp.length};
153 item.copy = data.copy;
154 item.title = data.title ||
155 data.copy.call_number().record().simple_record().title();
156 item.index = checkouts.length;
158 checkouts.unshift(item);
163 $scope.print_list = function() {
164 var print_data = { in_house_uses : [] };
166 if (checkouts.length == 0) return $q.when();
168 angular.forEach(checkouts, function(ihu) {
169 print_data.in_house_uses.push({
170 num_uses : ihu.num_uses,
171 copy : egCore.idl.toHash(ihu.copy),
176 return egCore.print.print({
177 template : 'in_house_use_list',