5 angular.module('egItemStatus',
6 ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egGridMod', 'egUserMod'])
8 .filter('boolText', function(){
14 .config(function($routeProvider, $locationProvider, $compileProvider) {
15 $locationProvider.html5Mode(true);
16 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
18 var resolver = {delay : function(egStartup) {return egStartup.go()}};
20 // search page shows the list view by default
21 $routeProvider.when('/cat/item/search', {
22 templateUrl: './cat/item/t_list',
23 controller: 'ListCtrl',
27 // search page shows the list view by default
28 $routeProvider.when('/cat/item/search/:idList', {
29 templateUrl: './cat/item/t_list',
30 controller: 'ListCtrl',
34 $routeProvider.when('/cat/item/:id', {
35 templateUrl: './cat/item/t_view',
36 controller: 'ViewCtrl',
40 $routeProvider.when('/cat/item/:id/:tab', {
41 templateUrl: './cat/item/t_view',
42 controller: 'ViewCtrl',
46 // default page / bucket view
47 $routeProvider.otherwise({redirectTo : '/cat/item/search'});
55 copies : [], // copy barcode search results
56 index : 0 // search grid index
62 acp : ['call_number','location','status','location','floating','circ_modifier','age_protect'],
63 acn : ['record','prefix','suffix'],
64 bre : ['simple_record','creator','editor']
67 // avoid fleshing MARC on the bre
68 // note: don't add simple_record.. not sure why
69 bre : ['id','tcn_value','creator','editor'],
73 // resolved with the last received copy
74 service.fetch = function(barcode, id, noListDupes) {
78 promise = egCore.pcrud.search('acp',
79 {barcode : barcode, deleted : 'f'}, service.flesh);
81 promise = egCore.pcrud.retrieve('acp', id, service.flesh);
86 function() {return lastRes},
89 // notify reads the stream of copies, one at a time.
94 // use the existing copy if possible
95 flatCopy = service.copies.filter(
96 function(c) {return c.id == copy.id()})[0];
100 flatCopy = egCore.idl.toHash(copy, true);
101 flatCopy.index = service.index++;
102 service.copies.unshift(flatCopy);
107 index : flatCopy.index
117 * Search bar along the top of the page.
118 * Parent scope for list and detail views
120 .controller('SearchCtrl',
121 ['$scope','$location','egCore','egGridDataProvider','itemSvc',
122 function($scope , $location , egCore , egGridDataProvider , itemSvc) {
123 $scope.args = {}; // search args
125 // sub-scopes (search / detail-view) apply their version
126 // of retrieval function to $scope.context.search
127 // and display toggling via $scope.context.toggleDisplay
132 $scope.toggleView = function($event) {
133 $scope.context.toggleDisplay();
134 $event.preventDefault(); // avoid form submission
139 * List view - grid stuff
141 .controller('ListCtrl',
142 ['$scope','$q','$routeParams','$location','$timeout','$window','egCore','egGridDataProvider','itemSvc','egUser','$uibModal','egCirc','egConfirmDialog',
143 function($scope , $q , $routeParams , $location , $timeout , $window , egCore , egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog) {
145 var cp_list = $routeParams.idList;
147 copyId = cp_list.split(',');
150 $scope.context.page = 'list';
153 var provider = egGridDataProvider.instance();
154 provider.get = function(offset, count) {
158 $scope.gridDataProvider = egGridDataProvider.instance({
159 get : function(offset, count) {
160 //return provider.arrayNotifier(itemSvc.copies, offset, count);
161 return this.arrayNotifier(itemSvc.copies, offset, count);
165 // If a copy was just displayed in the detail view, ensure it's
166 // focused in the list view.
167 var selected = false;
168 var copyGrid = $scope.gridControls = {
169 itemRetrieved : function(item) {
170 if (selected || !itemSvc.copy) return;
171 if (itemSvc.copy.id() == item.id) {
172 copyGrid.selectItems([item.index]);
178 $scope.$watch('barcodesFromFile', function(newVal, oldVal) {
179 if (newVal && newVal != oldVal) {
180 $scope.args.barcode = '';
183 angular.forEach(newVal.split(/\n/), function(line) {
185 // scrub any trailing spaces or commas from the barcode
186 line = line.replace(/(.*?)($|\s.*|,.*)/,'$1');
190 itemSvc.fetch(barcodes).then(
193 copyGrid.selectItems([itemSvc.copies[0].index]);
199 $scope.context.search = function(args) {
200 if (!args.barcode) return;
201 $scope.context.itemNotFound = false;
202 itemSvc.fetch(args.barcode).then(function(res) {
205 copyGrid.selectItems([res.index]);
206 $scope.args.barcode = '';
208 $scope.context.itemNotFound = true;
210 $scope.context.selectBarcode = true;
214 var add_barcode_to_list = function (b) {
215 $scope.context.search({barcode:b});
218 $scope.context.toggleDisplay = function() {
219 var item = copyGrid.selectedItems()[0];
221 $location.path('/cat/item/' + item.id);
224 $scope.context.show_triggered_events = function() {
225 var item = copyGrid.selectedItems()[0];
227 $location.path('/cat/item/' + item.id + '/triggered_events');
230 function gatherSelectedRecordIds () {
233 copyGrid.selectedItems(),
235 if (rid_list.indexOf(item['call_number.record.id']) == -1)
236 rid_list.push(item['call_number.record.id'])
242 function gatherSelectedVolumeIds (rid) {
245 copyGrid.selectedItems(),
247 if (rid && item['call_number.record.id'] != rid) return;
248 if (cn_id_list.indexOf(item['call_number.id']) == -1)
249 cn_id_list.push(item['call_number.id'])
255 function gatherSelectedHoldingsIds (rid) {
258 copyGrid.selectedItems(),
260 if (rid && item['call_number.record.id'] != rid) return;
261 cp_id_list.push(item.id)
267 $scope.add_copies_to_bucket = function() {
268 var copy_list = gatherSelectedHoldingsIds();
269 if (copy_list.length == 0) return;
271 return $uibModal.open({
272 templateUrl: './cat/catalog/t_add_to_bucket',
276 ['$scope','$uibModalInstance',
277 function($scope , $uibModalInstance) {
279 $scope.bucket_id = 0;
280 $scope.newBucketName = '';
281 $scope.allBuckets = [];
285 'open-ils.actor.container.retrieve_by_class.authoritative',
286 egCore.auth.token(), egCore.auth.user().id(),
287 'copy', 'staff_client'
288 ).then(function(buckets) { $scope.allBuckets = buckets; });
290 $scope.add_to_bucket = function() {
292 angular.forEach(copy_list, function (cp) {
293 var item = new egCore.idl.ccbi()
294 item.bucket($scope.bucket_id);
295 item.target_copy(cp);
299 'open-ils.actor.container.item.create',
300 egCore.auth.token(), 'copy', item
304 return $q.all(promises).then(function() {
305 $uibModalInstance.close();
310 $scope.add_to_new_bucket = function() {
311 var bucket = new egCore.idl.ccb();
312 bucket.owner(egCore.auth.user().id());
313 bucket.name($scope.newBucketName);
314 bucket.description('');
315 bucket.btype('staff_client');
317 return egCore.net.request(
319 'open-ils.actor.container.create',
320 egCore.auth.token(), 'copy', bucket
321 ).then(function(bucket) {
322 $scope.bucket_id = bucket;
323 $scope.add_to_bucket();
327 $scope.cancel = function() {
328 $uibModalInstance.dismiss();
334 $scope.make_copies_bookable = function() {
336 var copies_by_record = {};
337 var record_list = [];
339 copyGrid.selectedItems(),
341 var record_id = item['call_number.record.id'];
342 if (typeof copies_by_record[ record_id ] == 'undefined') {
343 copies_by_record[ record_id ] = [];
344 record_list.push( record_id );
346 copies_by_record[ record_id ].push(item.id);
351 var combined_results = [];
352 angular.forEach(record_list, function(record_id) {
356 'open-ils.booking.resources.create_from_copies',
358 copies_by_record[record_id]
359 ).then(function(results) {
360 if (results && results['brsrc']) {
361 combined_results = combined_results.concat(results['brsrc']);
367 $q.all(promises).then(function() {
368 if (combined_results.length > 0) {
370 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
374 ['$scope','$location','egCore','$uibModalInstance',
375 function($scope , $location , egCore , $uibModalInstance) {
378 ses : egCore.auth.token(),
379 resultant_brsrc : combined_results.map(function(o) { return o[0]; })
382 var booking_path = '/eg/conify/global/booking/resource';
384 $scope.booking_admin_url =
385 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
392 $scope.requestItems = function() {
393 var copy_list = gatherSelectedHoldingsIds();
394 if (copy_list.length == 0) return;
396 return $uibModal.open({
397 templateUrl: './cat/catalog/t_request_items',
400 ['$scope','$uibModalInstance','egUser',
401 function($scope , $uibModalInstance , egUser) {
403 $scope.first_user_fetch = true;
407 copy_list : copy_list,
408 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
409 user : egCore.auth.user().id()
412 egUser.get( $scope.hold_data.user ).then(function(u) {
414 $scope.barcode = u.card().barcode();
415 $scope.user_name = egUser.format_name(u);
416 $scope.hold_data.user = u.id();
419 $scope.user_name = '';
421 $scope.$watch('barcode', function (n) {
422 if (!$scope.first_user_fetch) {
423 egUser.getByBarcode(n).then(function(u) {
425 $scope.user_name = egUser.format_name(u);
426 $scope.hold_data.user = u.id();
429 $scope.user_name = '';
430 delete $scope.hold_data.user;
433 $scope.first_user_fetch = false;
436 $scope.ok = function(h) {
439 hold_type : h.hold_type,
440 pickup_lib: h.pickup_lib.id(),
446 'open-ils.circ.holds.test_and_create.batch.override',
447 egCore.auth.token(), args, h.copy_list
450 $uibModalInstance.close();
453 $scope.cancel = function($event) {
454 $uibModalInstance.dismiss();
455 $event.preventDefault();
461 $scope.replaceBarcodes = function() {
462 angular.forEach(copyGrid.selectedItems(), function (cp) {
464 templateUrl: './cat/share/t_replace_barcode',
467 ['$scope','$uibModalInstance',
468 function($scope , $uibModalInstance) {
469 $scope.isModal = true;
470 $scope.focusBarcode = false;
471 $scope.focusBarcode2 = true;
472 $scope.barcode1 = cp.barcode;
474 $scope.updateBarcode = function() {
475 $scope.copyNotFound = false;
476 $scope.updateOK = false;
478 egCore.pcrud.search('acp',
479 {deleted : 'f', barcode : $scope.barcode1})
480 .then(function(copy) {
483 $scope.focusBarcode = true;
484 $scope.copyNotFound = true;
488 $scope.copyId = copy.id();
489 copy.barcode($scope.barcode2);
491 egCore.pcrud.update(copy).then(function(stat) {
492 $scope.updateOK = stat;
493 $scope.focusBarcode = true;
494 if (stat) add_barcode_to_list(copy.barcode());
498 $uibModalInstance.close();
501 $scope.cancel = function($event) {
502 $uibModalInstance.dismiss();
503 $event.preventDefault();
511 $scope.attach_to_peer_bib = function() {
512 if (copyGrid.selectedItems().length == 0) return;
514 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
515 if (!target_record) return;
517 return $uibModal.open({
518 templateUrl: './cat/catalog/t_conjoined_selector',
521 ['$scope','$uibModalInstance',
522 function($scope , $uibModalInstance) {
523 $scope.update = false;
525 $scope.peer_type = null;
526 $scope.peer_type_list = [];
528 get_peer_types = function() {
530 return $q.when(egCore.env.bpt.list);
532 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
533 .then(function(list) {
534 egCore.env.absorbList(list, 'bpt');
539 get_peer_types().then(function(list){
540 $scope.peer_type_list = list;
543 $scope.ok = function(type) {
546 angular.forEach(copyGrid.selectedItems(), function (cp) {
547 var n = new egCore.idl.bpbcm();
549 n.peer_record(target_record);
550 n.target_copy(cp.id);
552 promises.push(egCore.pcrud.create(n).then(function(){add_barcode_to_list(cp.barcode)}));
555 return $q.all(promises).then(function(){$uibModalInstance.close()});
558 $scope.cancel = function($event) {
559 $uibModalInstance.dismiss();
560 $event.preventDefault();
567 $scope.selectedHoldingsCopyDelete = function () {
568 var copy_list = gatherSelectedHoldingsIds();
569 if (copy_list.length == 0) return;
571 var copy_objects = [];
572 egCore.pcrud.search('acp',
573 {deleted : 'f', id : copy_list},
574 { flesh : 1, flesh_fields : { acp : ['call_number'] } }
575 ).then(function(copy) {
576 copy_objects.push(copy);
580 var perCnCopies = {};
590 var cn_id = cp.call_number().id();
591 if (!cnHash[cn_id]) {
592 cnHash[cn_id] = cp.call_number();
593 perCnCopies[cn_id] = [cp];
595 perCnCopies[cn_id].push(cp);
597 cp.call_number(cn_id); // prevent loops in JSON-ification
601 angular.forEach(perCnCopies, function (v, k) {
606 angular.forEach(cnHash, function (v, k) {
610 if (cnList.length == 0) return;
614 egConfirmDialog.open(
615 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
616 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
617 {copies : cp_count, volumes : cn_count}
618 ).result.then(function() {
621 'open-ils.cat.asset.volume.fleshed.batch.update.override',
622 egCore.auth.token(), cnList, 1, flags
624 angular.forEach(copyGrid.selectedItems(), function(cp){add_barcode_to_list(cp.barcode)});
630 $scope.selectedHoldingsItemStatusTgrEvt= function() {
631 var item = copyGrid.selectedItems()[0];
633 $location.path('/cat/item/' + item.id + '/triggered_events');
636 $scope.selectedHoldingsItemStatusHolds= function() {
637 var item = copyGrid.selectedItems()[0];
639 $location.path('/cat/item/' + item.id + '/holds');
642 $scope.cancel_transit = function () {
643 var initial_list = copyGrid.selectedItems();
644 angular.forEach(copyGrid.selectedItems(), function(cp) {
645 egCirc.find_copy_transit(null, {copy_barcode:cp.barcode})
646 .then(function(t) { return egCirc.abort_transit(t.id()) })
647 .then(function() { return add_barcode_to_list(cp.barcode) });
651 $scope.selectedHoldingsDamaged = function () {
652 var initial_list = copyGrid.selectedItems();
653 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function(){
654 angular.forEach(initial_list, function(cp){add_barcode_to_list(cp.barcode)});
658 $scope.selectedHoldingsMissing = function () {
659 var initial_list = copyGrid.selectedItems();
660 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function(){
661 angular.forEach(initial_list, function(cp){add_barcode_to_list(cp.barcode)});
665 $scope.checkin = function () {
666 angular.forEach(copyGrid.selectedItems(), function (cp) {
667 egCirc.checkin({copy_barcode:cp.barcode}).then(
668 function() { add_barcode_to_list(cp.barcode) }
673 $scope.renew = function () {
674 angular.forEach(copyGrid.selectedItems(), function (cp) {
675 egCirc.renew({copy_barcode:cp.barcode}).then(
676 function() { add_barcode_to_list(cp.barcode) }
682 var spawnHoldingsAdd = function (vols,copies){
683 angular.forEach(gatherSelectedRecordIds(), function (r) {
685 if (copies) { // just a copy on existing volumes
686 angular.forEach(gatherSelectedVolumeIds(r), function (v) {
687 raw.push( {callnumber : v} );
691 gatherSelectedHoldingsIds(r),
693 angular.forEach(copyGrid.selectedItems(), function(item) {
694 if (i == item.id) raw.push({owner : item['call_number.owning_lib']});
700 if (raw.length == 0) raw.push({});
704 'open-ils.actor.anon_cache.set_value',
705 null, 'edit-these-copies', {
711 ).then(function(key) {
713 var url = egCore.env.basePath + 'cat/volcopy/' + key;
714 $timeout(function() { $window.open(url, '_blank') });
716 alert('Could not create anonymous cache key!');
721 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
722 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
724 $scope.showBibHolds = function () {
725 angular.forEach(gatherSelectedRecordIds(), function (r) {
726 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
727 $timeout(function() { $window.open(url, '_blank') });
731 var spawnHoldingsEdit = function (hide_vols,hide_copies){
732 angular.forEach(gatherSelectedRecordIds(), function (r) {
735 'open-ils.actor.anon_cache.set_value',
736 null, 'edit-these-copies', {
738 copies: gatherSelectedHoldingsIds(r),
740 hide_vols : hide_vols,
741 hide_copies : hide_copies
743 ).then(function(key) {
745 var url = egCore.env.basePath + 'cat/volcopy/' + key;
746 $timeout(function() { $window.open(url, '_blank') });
748 alert('Could not create anonymous cache key!');
753 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
754 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
755 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
757 // this "transfers" selected copies to a new owning library,
758 // auto-creating volumes and deleting unused volumes as required.
759 $scope.changeItemOwningLib = function() {
760 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
761 var items = copyGrid.selectedItems();
762 if (!xfer_target || !items.length) {
765 var vols_to_move = {};
766 var copies_to_move = {};
767 angular.forEach(items, function(item) {
768 if (item['call_number.owning_lib'] != xfer_target) {
769 if (item['call_number.id'] in vols_to_move) {
770 copies_to_move[item['call_number.id']].push(item.id);
772 vols_to_move[item['call_number.id']] = {
773 label : item['call_number.label'],
774 label_class : item['call_number.label_class'],
775 record : item['call_number.record.id'],
776 prefix : item['call_number.prefix.id'],
777 suffix : item['call_number.suffix.id']
779 copies_to_move[item['call_number.id']] = new Array;
780 copies_to_move[item['call_number.id']].push(item.id);
786 angular.forEach(vols_to_move, function(vol) {
787 promises.push(egCore.net.request(
789 'open-ils.cat.call_number.find_or_create',
797 ).then(function(resp) {
798 var evt = egCore.evt.parse(resp);
800 return egCore.net.request(
802 'open-ils.cat.transfer_copies_to_volume',
805 copies_to_move[vol.id]
811 copyGrid.selectedItems(),
814 function(){ add_barcode_to_list(cp.barcode) }
821 $scope.transferItems = function (){
822 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
823 var copy_ids = gatherSelectedHoldingsIds();
824 if (xfer_target && copy_ids.length > 0) {
827 'open-ils.cat.transfer_copies_to_volume',
832 function(resp) { // oncomplete
833 var evt = egCore.evt.parse(resp);
834 egConfirmDialog.open(
835 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
836 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
837 {'evt_desc': evt.desc}
838 ).result.then(function() {
841 'open-ils.cat.transfer_copies_to_volume.override',
845 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
852 angular.forEach(copyGrid.selectedItems(), function(cp){add_barcode_to_list(cp.barcode)});
857 $scope.print_list = function() {
858 var print_data = { copies : copyGrid.allItems() };
860 if (print_data.copies.length == 0) return $q.when();
862 return egCore.print.print({
863 template : 'item_status',
868 if (copyId.length > 0) {
869 itemSvc.fetch(null,copyId).then(
879 * Detail view -- shows one copy
881 .controller('ViewCtrl',
882 ['$scope','$q','$location','$routeParams','$timeout','$window','egCore','itemSvc','egBilling',
883 function($scope , $q , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling) {
884 var copyId = $routeParams.id;
885 $scope.tab = $routeParams.tab || 'summary';
886 $scope.context.page = 'detail';
887 $scope.summaryRecord = null;
890 if ($scope.tab == 'edit') {
891 $scope.tab = 'summary';
896 // use the cached record info
898 $scope.recordId = itemSvc.copy.call_number().record().id();
900 function loadCopy(barcode) {
901 $scope.context.itemNotFound = false;
903 // Avoid re-fetching the same copy while jumping tabs.
904 // In addition to being quicker, this helps to avoid flickering
905 // of the top panel which is always visible in the detail view.
907 // 'barcode' represents the loading of a new item - refetch it
908 // regardless of whether it matches the current item.
909 if (!barcode && itemSvc.copy && itemSvc.copy.id() == copyId) {
910 $scope.copy = itemSvc.copy;
911 $scope.recordId = itemSvc.copy.call_number().record().id();
918 var deferred = $q.defer();
919 itemSvc.fetch(barcode, copyId, true).then(function(res) {
920 $scope.context.selectBarcode = true;
924 $scope.context.itemNotFound = true;
925 deferred.reject(); // avoid propagation of data fetch calls
934 $scope.recordId = copy.call_number().record().id();
935 $scope.args.barcode = '';
937 // locally flesh org units
938 copy.circ_lib(egCore.org.get(copy.circ_lib()));
939 copy.call_number().owning_lib(
940 egCore.org.get(copy.call_number().owning_lib()));
942 var r = copy.call_number().record();
943 if (r.owner()) r.owner(egCore.org.get(r.owner()));
945 // make boolean for auto-magic true/false display
947 ['ref','opac_visible','holdable','circulate'],
948 function(field) { copy[field](Boolean(copy[field]() == 't')) }
951 // finally, if this is a different copy, redirect.
952 // Note that we flesh first since the copy we just
953 // fetched will be used after the redirect.
954 if (copyId && copyId != copy.id()) {
955 // if a new barcode is scanned in the detail view,
956 // update the url to match the ID of the new copy
957 $location.path('/cat/item/' + copy.id() + '/' + $scope.tab);
958 deferred.reject(); // avoid propagation of data fetch calls
966 return deferred.promise;
969 // if loadPrev load the two most recent circulations
970 function loadCurrentCirc(loadPrev) {
972 delete $scope.circ_summary;
973 delete $scope.prev_circ_summary;
974 delete $scope.prev_circ_usr;
977 egCore.pcrud.search('circ',
978 {target_copy : copyId},
984 'checkin_workstation',
987 'recurring_fine_rule'
991 order_by : {circ : 'xact_start desc'},
995 ).then(null, null, function(circ) {
998 // load the chain for this circ
1001 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
1002 egCore.auth.token(), $scope.circ.id()
1003 ).then(function(summary) {
1004 $scope.circ_summary = summary.summary;
1007 if (!loadPrev) return;
1009 // load the chain for the previous circ, plus the user
1012 'open-ils.circ.prev_renewal_chain.retrieve_by_circ.summary',
1013 egCore.auth.token(), $scope.circ.id()
1015 ).then(null, null, function(summary) {
1016 $scope.prev_circ_summary = summary.summary;
1018 if (summary.usr) { // aged circs have no 'usr'.
1019 egCore.pcrud.retrieve('au', summary.usr,
1020 {flesh : 1, flesh_fields : {au : ['card']}})
1022 .then(function(user) { $scope.prev_circ_usr = user });
1029 function fetchMaxCircHistory() {
1030 if (maxHistory) return $q.when(maxHistory);
1031 return egCore.org.settings(
1032 'circ.item_checkout_history.max')
1033 .then(function(set) {
1034 maxHistory = set['circ.item_checkout_history.max'] || 4;
1039 $scope.addBilling = function(circ) {
1040 egBilling.showBillDialog({
1041 xact_id : circ.id(),
1046 $scope.retrieveAllPatrons = function() {
1047 var users = new Set();
1048 angular.forEach($scope.circ_list.map(function(circ) { return circ.usr(); }),function(usr) {
1049 // aged circs have no 'usr'.
1050 if (usr) users.add(usr);
1052 users.forEach(function(usr) {
1053 $timeout(function() {
1054 var url = $location.absUrl().replace(
1056 '/circ/patron/' + usr.id() + '/checkout');
1057 $window.open(url, '_blank')
1062 function loadCircHistory() {
1063 $scope.circ_list = [];
1066 itemSvc.copy.call_number().id() == -1 ?
1067 itemSvc.copy.circ_lib().id() :
1068 itemSvc.copy.call_number().owning_lib().id()
1070 // there is an extra layer of permissibility over circ
1072 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
1073 .then(function(orgIds) {
1075 if (orgIds.indexOf(copy_org) == -1) {
1076 console.log('User is not allowed to view circ history');
1080 return fetchMaxCircHistory();
1082 }).then(function(count) {
1084 egCore.pcrud.search('combcirc',
1085 {target_copy : copyId},
1091 'checkin_workstation',
1092 'recurring_fine_rule'
1096 order_by : {combcirc : 'xact_start desc'},
1100 ).then(null, null, function(circ) {
1102 // flesh circ_lib locally
1103 circ.circ_lib(egCore.org.get(circ.circ_lib()));
1104 circ.checkin_lib(egCore.org.get(circ.checkin_lib()));
1105 $scope.circ_list.push(circ);
1111 function loadCircCounts() {
1113 delete $scope.circ_counts;
1114 $scope.total_circs = 0;
1115 $scope.total_circs_this_year = 0;
1116 $scope.total_circs_prev_year = 0;
1117 if (!copyId) return;
1119 egCore.pcrud.search('circbyyr',
1120 {copy : copyId}, null, {atomic : true})
1122 .then(function(counts) {
1123 $scope.circ_counts = counts;
1125 angular.forEach(counts, function(count) {
1126 $scope.total_circs += Number(count.count());
1129 var this_year = counts.filter(function(c) {
1130 return c.year() == new Date().getFullYear();
1133 $scope.total_circs_this_year =
1134 this_year.length ? this_year[0].count() : 0;
1136 var prev_year = counts.filter(function(c) {
1137 return c.year() == new Date().getFullYear() - 1;
1140 $scope.total_circs_prev_year =
1141 prev_year.length ? prev_year[0].count() : 0;
1146 function loadHolds() {
1148 if (!copyId) return;
1150 egCore.pcrud.search('ahr',
1151 { current_copy : copyId,
1153 fulfillment_time : null,
1154 capture_time : {'<>' : null}
1158 ahr : ['requestor', 'usr'],
1162 ).then(null, null, function(hold) {
1164 hold.pickup_lib(egCore.org.get(hold.pickup_lib()));
1165 if (hold.current_shelf_lib()) {
1166 hold.current_shelf_lib(
1167 egCore.org.get(hold.current_shelf_lib()));
1169 hold.behind_desk(Boolean(hold.behind_desk() == 't'));
1173 function loadTransits() {
1174 delete $scope.transit;
1175 delete $scope.hold_transit;
1176 if (!copyId) return;
1178 egCore.pcrud.search('atc',
1179 {target_copy : copyId},
1180 {order_by : {atc : 'source_send_time DESC'}}
1182 ).then(null, null, function(transit) {
1183 $scope.transit = transit;
1184 transit.source(egCore.org.get(transit.source()));
1185 transit.dest(egCore.org.get(transit.dest()));
1190 // we don't need all data on all tabs, so fetch what's needed when needed.
1191 function loadTabData() {
1192 switch($scope.tab) {
1199 loadCurrentCirc(true);
1211 case 'triggered_events':
1212 var url = $location.absUrl().replace(/\/staff.*/, '/actor/user/event_log');
1213 url += '?copy_id=' + encodeURIComponent(copyId);
1214 $scope.triggered_events_url = url;
1221 'open-ils.actor.anon_cache.set_value',
1222 null, 'edit-these-copies', {
1223 record_id: $scope.recordId,
1228 ).then(function(key) {
1230 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1231 $window.location.href = url;
1233 alert('Could not create anonymous cache key!');
1241 $scope.context.toggleDisplay = function() {
1242 $location.path('/cat/item/search');
1245 // handle the barcode scan box, which will replace our current copy
1246 $scope.context.search = function(args) {
1247 loadCopy(args.barcode).then(loadTabData);
1250 $scope.context.show_triggered_events = function() {
1251 $location.path('/cat/item/' + copyId + '/triggered_events');
1254 loadCopy().then(loadTabData);