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 $scope.copyNotFound = true;
86 coArgs.copyid = copy.id();
89 'open-ils.circ.in_house_use.create',
95 coArgs.non_cat_type = args.noncat_type;
97 'open-ils.circ.non_cat_in_house_use.create',
98 coArgs, {title : $scope.selectedNcType()}
101 $scope.args.barcode='';
104 function performCheckout(method, args, data) {
106 // FIXME: make this API stream
108 'open-ils.circ', method, egCore.auth.token(), args
110 ).then(function(resp) {
111 if (evt = egCore.evt.parse(resp)) return alert(evt);
113 var item = {num_uses : resp.length};
114 item.copy = data.copy;
115 item.title = data.title ||
116 data.copy.call_number().record().simple_record().title();
117 item.index = checkouts.length;
119 checkouts.unshift(item);
124 $scope.print_list = function() {
125 var print_data = { in_house_uses : [] };
127 if (checkouts.length == 0) return $q.when();
129 angular.forEach(checkouts, function(ihu) {
130 print_data.in_house_uses.push({
131 num_uses : ihu.num_uses,
132 copy : egCore.idl.toHash(ihu.copy),
137 return egCore.print.print({
138 template : 'in_house_use_list',