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.requestItems = function() {
335 var copy_list = gatherSelectedHoldingsIds();
336 if (copy_list.length == 0) return;
338 return $uibModal.open({
339 templateUrl: './cat/catalog/t_request_items',
342 ['$scope','$uibModalInstance','egUser',
343 function($scope , $uibModalInstance , egUser) {
345 $scope.first_user_fetch = true;
349 copy_list : copy_list,
350 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
351 user : egCore.auth.user().id()
354 egUser.get( $scope.hold_data.user ).then(function(u) {
356 $scope.barcode = u.card().barcode();
357 $scope.user_name = egUser.format_name(u);
358 $scope.hold_data.user = u.id();
361 $scope.user_name = '';
363 $scope.$watch('barcode', function (n) {
364 if (!$scope.first_user_fetch) {
365 egUser.getByBarcode(n).then(function(u) {
367 $scope.user_name = egUser.format_name(u);
368 $scope.hold_data.user = u.id();
371 $scope.user_name = '';
372 delete $scope.hold_data.user;
375 $scope.first_user_fetch = false;
378 $scope.ok = function(h) {
381 hold_type : h.hold_type,
382 pickup_lib: h.pickup_lib.id(),
388 'open-ils.circ.holds.test_and_create.batch.override',
389 egCore.auth.token(), args, h.copy_list
392 $uibModalInstance.close();
395 $scope.cancel = function($event) {
396 $uibModalInstance.dismiss();
397 $event.preventDefault();
403 $scope.replaceBarcodes = function() {
404 angular.forEach(copyGrid.selectedItems(), function (cp) {
406 templateUrl: './cat/share/t_replace_barcode',
409 ['$scope','$uibModalInstance',
410 function($scope , $uibModalInstance) {
411 $scope.isModal = true;
412 $scope.focusBarcode = false;
413 $scope.focusBarcode2 = true;
414 $scope.barcode1 = cp.barcode;
416 $scope.updateBarcode = function() {
417 $scope.copyNotFound = false;
418 $scope.updateOK = false;
420 egCore.pcrud.search('acp',
421 {deleted : 'f', barcode : $scope.barcode1})
422 .then(function(copy) {
425 $scope.focusBarcode = true;
426 $scope.copyNotFound = true;
430 $scope.copyId = copy.id();
431 copy.barcode($scope.barcode2);
433 egCore.pcrud.update(copy).then(function(stat) {
434 $scope.updateOK = stat;
435 $scope.focusBarcode = true;
436 if (stat) add_barcode_to_list(copy.barcode());
440 $uibModalInstance.close();
443 $scope.cancel = function($event) {
444 $uibModalInstance.dismiss();
445 $event.preventDefault();
453 $scope.attach_to_peer_bib = function() {
454 if (copyGrid.selectedItems().length == 0) return;
456 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
457 if (!target_record) return;
459 return $uibModal.open({
460 templateUrl: './cat/catalog/t_conjoined_selector',
463 ['$scope','$uibModalInstance',
464 function($scope , $uibModalInstance) {
465 $scope.update = false;
467 $scope.peer_type = null;
468 $scope.peer_type_list = [];
470 get_peer_types = function() {
472 return $q.when(egCore.env.bpt.list);
474 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
475 .then(function(list) {
476 egCore.env.absorbList(list, 'bpt');
481 get_peer_types().then(function(list){
482 $scope.peer_type_list = list;
485 $scope.ok = function(type) {
488 angular.forEach(copyGrid.selectedItems(), function (cp) {
489 var n = new egCore.idl.bpbcm();
491 n.peer_record(target_record);
492 n.target_copy(cp.id);
494 promises.push(egCore.pcrud.create(n).then(function(){add_barcode_to_list(cp.barcode)}));
497 return $q.all(promises).then(function(){$uibModalInstance.close()});
500 $scope.cancel = function($event) {
501 $uibModalInstance.dismiss();
502 $event.preventDefault();
509 $scope.selectedHoldingsCopyDelete = function () {
510 var copy_list = gatherSelectedHoldingsIds();
511 if (copy_list.length == 0) return;
513 var copy_objects = [];
514 egCore.pcrud.search('acp',
515 {deleted : 'f', id : copy_list},
516 { flesh : 1, flesh_fields : { acp : ['call_number'] } }
517 ).then(function(copy) {
518 copy_objects.push(copy);
522 var perCnCopies = {};
532 var cn_id = cp.call_number().id();
533 if (!cnHash[cn_id]) {
534 cnHash[cn_id] = cp.call_number();
535 perCnCopies[cn_id] = [cp];
537 perCnCopies[cn_id].push(cp);
539 cp.call_number(cn_id); // prevent loops in JSON-ification
543 angular.forEach(perCnCopies, function (v, k) {
548 angular.forEach(cnHash, function (v, k) {
552 if (cnList.length == 0) return;
556 egConfirmDialog.open(
557 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
558 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
559 {copies : cp_count, volumes : cn_count}
560 ).result.then(function() {
563 'open-ils.cat.asset.volume.fleshed.batch.update.override',
564 egCore.auth.token(), cnList, 1, flags
566 angular.forEach(copyGrid.selectedItems(), function(cp){add_barcode_to_list(cp.barcode)});
572 $scope.selectedHoldingsItemStatusTgrEvt= function() {
573 var item = copyGrid.selectedItems()[0];
575 $location.path('/cat/item/' + item.id + '/triggered_events');
578 $scope.selectedHoldingsItemStatusHolds= function() {
579 var item = copyGrid.selectedItems()[0];
581 $location.path('/cat/item/' + item.id + '/holds');
584 $scope.cancel_transit = function () {
585 var initial_list = copyGrid.selectedItems();
586 angular.forEach(copyGrid.selectedItems(), function(cp) {
587 egCirc.find_copy_transit(null, {copy_barcode:cp.barcode})
588 .then(function(t) { return egCirc.abort_transit(t.id()) })
589 .then(function() { return add_barcode_to_list(cp.barcode) });
593 $scope.selectedHoldingsDamaged = function () {
594 var initial_list = copyGrid.selectedItems();
595 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function(){
596 angular.forEach(initial_list, function(cp){add_barcode_to_list(cp.barcode)});
600 $scope.selectedHoldingsMissing = function () {
601 var initial_list = copyGrid.selectedItems();
602 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function(){
603 angular.forEach(initial_list, function(cp){add_barcode_to_list(cp.barcode)});
607 $scope.checkin = function () {
608 angular.forEach(copyGrid.selectedItems(), function (cp) {
609 egCirc.checkin({copy_barcode:cp.barcode}).then(
610 function() { add_barcode_to_list(cp.barcode) }
615 $scope.renew = function () {
616 angular.forEach(copyGrid.selectedItems(), function (cp) {
617 egCirc.renew({copy_barcode:cp.barcode}).then(
618 function() { add_barcode_to_list(cp.barcode) }
624 var spawnHoldingsAdd = function (vols,copies){
625 angular.forEach(gatherSelectedRecordIds(), function (r) {
627 if (copies) { // just a copy on existing volumes
628 angular.forEach(gatherSelectedVolumeIds(r), function (v) {
629 raw.push( {callnumber : v} );
633 gatherSelectedHoldingsIds(r),
635 angular.forEach(copyGrid.selectedItems(), function(item) {
636 if (i == item.id) raw.push({owner : item['call_number.owning_lib']});
642 if (raw.length == 0) raw.push({});
646 'open-ils.actor.anon_cache.set_value',
647 null, 'edit-these-copies', {
653 ).then(function(key) {
655 var url = egCore.env.basePath + 'cat/volcopy/' + key;
656 $timeout(function() { $window.open(url, '_blank') });
658 alert('Could not create anonymous cache key!');
663 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
664 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
666 $scope.showBibHolds = function () {
667 angular.forEach(gatherSelectedRecordIds(), function (r) {
668 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
669 $timeout(function() { $window.open(url, '_blank') });
673 var spawnHoldingsEdit = function (hide_vols,hide_copies){
674 angular.forEach(gatherSelectedRecordIds(), function (r) {
677 'open-ils.actor.anon_cache.set_value',
678 null, 'edit-these-copies', {
680 copies: gatherSelectedHoldingsIds(r),
682 hide_vols : hide_vols,
683 hide_copies : hide_copies
685 ).then(function(key) {
687 var url = egCore.env.basePath + 'cat/volcopy/' + key;
688 $timeout(function() { $window.open(url, '_blank') });
690 alert('Could not create anonymous cache key!');
695 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
696 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
697 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
699 // this "transfers" selected copies to a new owning library,
700 // auto-creating volumes and deleting unused volumes as required.
701 $scope.changeItemOwningLib = function() {
702 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
703 var items = copyGrid.selectedItems();
704 if (!xfer_target || !items.length) {
707 var vols_to_move = {};
708 var copies_to_move = {};
709 angular.forEach(items, function(item) {
710 if (item['call_number.owning_lib'] != xfer_target) {
711 if (item['call_number.id'] in vols_to_move) {
712 copies_to_move[item['call_number.id']].push(item.id);
714 vols_to_move[item['call_number.id']] = {
715 label : item['call_number.label'],
716 label_class : item['call_number.label_class'],
717 record : item['call_number.record.id'],
718 prefix : item['call_number.prefix.id'],
719 suffix : item['call_number.suffix.id']
721 copies_to_move[item['call_number.id']] = new Array;
722 copies_to_move[item['call_number.id']].push(item.id);
728 angular.forEach(vols_to_move, function(vol) {
729 promises.push(egCore.net.request(
731 'open-ils.cat.call_number.find_or_create',
739 ).then(function(resp) {
740 var evt = egCore.evt.parse(resp);
742 return egCore.net.request(
744 'open-ils.cat.transfer_copies_to_volume',
747 copies_to_move[vol.id]
753 copyGrid.selectedItems(),
756 function(){ add_barcode_to_list(cp.barcode) }
763 $scope.transferItems = function (){
764 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
765 var copy_ids = gatherSelectedHoldingsIds();
766 if (xfer_target && copy_ids.length > 0) {
769 'open-ils.cat.transfer_copies_to_volume',
774 function(resp) { // oncomplete
775 var evt = egCore.evt.parse(resp);
776 egConfirmDialog.open(
777 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
778 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
779 {'evt_desc': evt.desc}
780 ).result.then(function() {
783 'open-ils.cat.transfer_copies_to_volume.override',
787 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
794 angular.forEach(copyGrid.selectedItems(), function(cp){add_barcode_to_list(cp.barcode)});
799 $scope.print_list = function() {
800 var print_data = { copies : copyGrid.allItems() };
802 if (print_data.copies.length == 0) return $q.when();
804 return egCore.print.print({
805 template : 'item_status',
810 if (copyId.length > 0) {
811 itemSvc.fetch(null,copyId).then(
821 * Detail view -- shows one copy
823 .controller('ViewCtrl',
824 ['$scope','$q','$location','$routeParams','$timeout','$window','egCore','itemSvc','egBilling',
825 function($scope , $q , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling) {
826 var copyId = $routeParams.id;
827 $scope.tab = $routeParams.tab || 'summary';
828 $scope.context.page = 'detail';
829 $scope.summaryRecord = null;
832 if ($scope.tab == 'edit') {
833 $scope.tab = 'summary';
838 // use the cached record info
840 $scope.recordId = itemSvc.copy.call_number().record().id();
842 function loadCopy(barcode) {
843 $scope.context.itemNotFound = false;
845 // Avoid re-fetching the same copy while jumping tabs.
846 // In addition to being quicker, this helps to avoid flickering
847 // of the top panel which is always visible in the detail view.
849 // 'barcode' represents the loading of a new item - refetch it
850 // regardless of whether it matches the current item.
851 if (!barcode && itemSvc.copy && itemSvc.copy.id() == copyId) {
852 $scope.copy = itemSvc.copy;
853 $scope.recordId = itemSvc.copy.call_number().record().id();
860 var deferred = $q.defer();
861 itemSvc.fetch(barcode, copyId, true).then(function(res) {
862 $scope.context.selectBarcode = true;
866 $scope.context.itemNotFound = true;
867 deferred.reject(); // avoid propagation of data fetch calls
876 $scope.recordId = copy.call_number().record().id();
877 $scope.args.barcode = '';
879 // locally flesh org units
880 copy.circ_lib(egCore.org.get(copy.circ_lib()));
881 copy.call_number().owning_lib(
882 egCore.org.get(copy.call_number().owning_lib()));
884 var r = copy.call_number().record();
885 if (r.owner()) r.owner(egCore.org.get(r.owner()));
887 // make boolean for auto-magic true/false display
889 ['ref','opac_visible','holdable','circulate'],
890 function(field) { copy[field](Boolean(copy[field]() == 't')) }
893 // finally, if this is a different copy, redirect.
894 // Note that we flesh first since the copy we just
895 // fetched will be used after the redirect.
896 if (copyId && copyId != copy.id()) {
897 // if a new barcode is scanned in the detail view,
898 // update the url to match the ID of the new copy
899 $location.path('/cat/item/' + copy.id() + '/' + $scope.tab);
900 deferred.reject(); // avoid propagation of data fetch calls
908 return deferred.promise;
911 // if loadPrev load the two most recent circulations
912 function loadCurrentCirc(loadPrev) {
914 delete $scope.circ_summary;
915 delete $scope.prev_circ_summary;
916 delete $scope.prev_circ_usr;
919 egCore.pcrud.search('circ',
920 {target_copy : copyId},
926 'checkin_workstation',
929 'recurring_fine_rule'
933 order_by : {circ : 'xact_start desc'},
937 ).then(null, null, function(circ) {
940 // load the chain for this circ
943 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
944 egCore.auth.token(), $scope.circ.id()
945 ).then(function(summary) {
946 $scope.circ_summary = summary.summary;
949 if (!loadPrev) return;
951 // load the chain for the previous circ, plus the user
954 'open-ils.circ.prev_renewal_chain.retrieve_by_circ.summary',
955 egCore.auth.token(), $scope.circ.id()
957 ).then(null, null, function(summary) {
958 $scope.prev_circ_summary = summary.summary;
960 if (summary.usr) { // aged circs have no 'usr'.
961 egCore.pcrud.retrieve('au', summary.usr,
962 {flesh : 1, flesh_fields : {au : ['card']}})
964 .then(function(user) { $scope.prev_circ_usr = user });
971 function fetchMaxCircHistory() {
972 if (maxHistory) return $q.when(maxHistory);
973 return egCore.org.settings(
974 'circ.item_checkout_history.max')
975 .then(function(set) {
976 maxHistory = set['circ.item_checkout_history.max'] || 4;
981 $scope.addBilling = function(circ) {
982 egBilling.showBillDialog({
988 $scope.retrieveAllPatrons = function() {
989 var users = new Set();
990 angular.forEach($scope.circ_list.map(function(circ) { return circ.usr(); }),function(usr) {
991 // aged circs have no 'usr'.
992 if (usr) users.add(usr);
994 users.forEach(function(usr) {
995 $timeout(function() {
996 var url = $location.absUrl().replace(
998 '/circ/patron/' + usr.id() + '/checkout');
999 $window.open(url, '_blank')
1004 function loadCircHistory() {
1005 $scope.circ_list = [];
1008 itemSvc.copy.call_number().id() == -1 ?
1009 itemSvc.copy.circ_lib().id() :
1010 itemSvc.copy.call_number().owning_lib().id()
1012 // there is an extra layer of permissibility over circ
1014 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
1015 .then(function(orgIds) {
1017 if (orgIds.indexOf(copy_org) == -1) {
1018 console.log('User is not allowed to view circ history');
1022 return fetchMaxCircHistory();
1024 }).then(function(count) {
1026 egCore.pcrud.search('combcirc',
1027 {target_copy : copyId},
1033 'checkin_workstation',
1034 'recurring_fine_rule'
1038 order_by : {combcirc : 'xact_start desc'},
1042 ).then(null, null, function(circ) {
1044 // flesh circ_lib locally
1045 circ.circ_lib(egCore.org.get(circ.circ_lib()));
1046 circ.checkin_lib(egCore.org.get(circ.checkin_lib()));
1047 $scope.circ_list.push(circ);
1053 function loadCircCounts() {
1055 delete $scope.circ_counts;
1056 $scope.total_circs = 0;
1057 $scope.total_circs_this_year = 0;
1058 $scope.total_circs_prev_year = 0;
1059 if (!copyId) return;
1061 egCore.pcrud.search('circbyyr',
1062 {copy : copyId}, null, {atomic : true})
1064 .then(function(counts) {
1065 $scope.circ_counts = counts;
1067 angular.forEach(counts, function(count) {
1068 $scope.total_circs += Number(count.count());
1071 var this_year = counts.filter(function(c) {
1072 return c.year() == new Date().getFullYear();
1075 $scope.total_circs_this_year =
1076 this_year.length ? this_year[0].count() : 0;
1078 var prev_year = counts.filter(function(c) {
1079 return c.year() == new Date().getFullYear() - 1;
1082 $scope.total_circs_prev_year =
1083 prev_year.length ? prev_year[0].count() : 0;
1088 function loadHolds() {
1090 if (!copyId) return;
1092 egCore.pcrud.search('ahr',
1093 { current_copy : copyId,
1095 fulfillment_time : null,
1096 capture_time : {'<>' : null}
1100 ahr : ['requestor', 'usr'],
1104 ).then(null, null, function(hold) {
1106 hold.pickup_lib(egCore.org.get(hold.pickup_lib()));
1107 if (hold.current_shelf_lib()) {
1108 hold.current_shelf_lib(
1109 egCore.org.get(hold.current_shelf_lib()));
1111 hold.behind_desk(Boolean(hold.behind_desk() == 't'));
1115 function loadTransits() {
1116 delete $scope.transit;
1117 delete $scope.hold_transit;
1118 if (!copyId) return;
1120 egCore.pcrud.search('atc',
1121 {target_copy : copyId},
1122 {order_by : {atc : 'source_send_time DESC'}}
1124 ).then(null, null, function(transit) {
1125 $scope.transit = transit;
1126 transit.source(egCore.org.get(transit.source()));
1127 transit.dest(egCore.org.get(transit.dest()));
1132 // we don't need all data on all tabs, so fetch what's needed when needed.
1133 function loadTabData() {
1134 switch($scope.tab) {
1141 loadCurrentCirc(true);
1153 case 'triggered_events':
1154 var url = $location.absUrl().replace(/\/staff.*/, '/actor/user/event_log');
1155 url += '?copy_id=' + encodeURIComponent(copyId);
1156 $scope.triggered_events_url = url;
1163 'open-ils.actor.anon_cache.set_value',
1164 null, 'edit-these-copies', {
1165 record_id: $scope.recordId,
1170 ).then(function(key) {
1172 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1173 $window.location.href = url;
1175 alert('Could not create anonymous cache key!');
1183 $scope.context.toggleDisplay = function() {
1184 $location.path('/cat/item/search');
1187 // handle the barcode scan box, which will replace our current copy
1188 $scope.context.search = function(args) {
1189 loadCopy(args.barcode).then(loadTabData);
1192 $scope.context.show_triggered_events = function() {
1193 $location.path('/cat/item/' + copyId + '/triggered_events');
1196 loadCopy().then(loadTabData);