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',
13 function($scope, egCore, egGridDataProvider , egConfirmDialog) {
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 ]).then(function(set) {
36 countWarn = set['ui.circ.in_house_use.entry_warn'] || 20;
37 $scope.countMax = countMax =
38 set['ui.circ.in_house_use.entry_cap'] || 99;
42 $scope.useFocus = true;
43 $scope.args = {noncat_type : 'barcode', num_uses : 1};
46 var provider = egGridDataProvider.instance({});
47 provider.get = function(offset, count) {
48 return provider.arrayNotifier(checkouts, offset, count);
50 $scope.gridDataProvider = provider;
52 // currently selected non-cat type
53 $scope.selectedNcType = function() {
54 if (!egCore.env.cnct) return null; // too soon
55 var type = egCore.env.cnct.map[$scope.args.noncat_type];
56 return type ? type.name() : null;
59 $scope.checkout = function(args) {
60 $scope.copyNotFound = false;
63 count : args.num_uses,
64 'location' : egCore.auth.user().ws_ou()
67 if (args.noncat_type == 'barcode') {
69 egCore.pcrud.search('acp',
70 {barcode : args.barcode, deleted : 'f'},
73 acp : ['call_number','location'],
75 bre : ['simple_record']
77 select : { bre : ['id'] } // avoid fleshing MARC
79 ).then(function(copy) {
82 egCore.audio.play('error.in_house.copy_not_found');
83 $scope.copyNotFound = true;
87 coArgs.copyid = copy.id();
90 'open-ils.circ.in_house_use.create',
96 coArgs.non_cat_type = args.noncat_type;
98 'open-ils.circ.non_cat_in_house_use.create',
99 coArgs, {title : $scope.selectedNcType()}
102 $scope.args.barcode='';
105 function performCheckout(method, args, data) {
107 // FIXME: make this API stream
109 'open-ils.circ', method, egCore.auth.token(), args
111 ).then(function(resp) {
112 if (evt = egCore.evt.parse(resp)) {
113 egCore.audio.play('error.in_house');
117 egCore.audio.play('success.in_house');
119 var item = {num_uses : resp.length};
120 item.copy = data.copy;
121 item.title = data.title ||
122 data.copy.call_number().record().simple_record().title();
123 item.index = checkouts.length;
125 checkouts.unshift(item);
130 $scope.print_list = function() {
131 var print_data = { in_house_uses : [] };
133 if (checkouts.length == 0) return $q.when();
135 angular.forEach(checkouts, function(ihu) {
136 print_data.in_house_uses.push({
137 num_uses : ihu.num_uses,
138 copy : egCore.idl.toHash(ihu.copy),
143 return egCore.print.print({
144 template : 'in_house_use_list',