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 egCore.pcrud.search('aihu',
95 {item : copy.id()}, {}, {idlist : true, atomic : true})
96 .then(function(uses) {
97 copy._inHouseUseCount = uses.length;
101 // use the existing copy if possible
102 flatCopy = service.copies.filter(
103 function(c) {return c.id == copy.id()})[0];
107 flatCopy = egCore.idl.toHash(copy, true);
108 flatCopy.index = service.index++;
109 service.copies.unshift(flatCopy);
114 index : flatCopy.index
124 * Search bar along the top of the page.
125 * Parent scope for list and detail views
127 .controller('SearchCtrl',
128 ['$scope','$location','egCore','egGridDataProvider','itemSvc',
129 function($scope , $location , egCore , egGridDataProvider , itemSvc) {
130 $scope.args = {}; // search args
132 // sub-scopes (search / detail-view) apply their version
133 // of retrieval function to $scope.context.search
134 // and display toggling via $scope.context.toggleDisplay
139 $scope.toggleView = function($event) {
140 $scope.context.toggleDisplay();
141 $event.preventDefault(); // avoid form submission
146 * List view - grid stuff
148 .controller('ListCtrl',
149 ['$scope','$q','$routeParams','$location','$timeout','$window','egCore','egGridDataProvider','itemSvc','egUser','$uibModal','egCirc','egConfirmDialog',
150 function($scope , $q , $routeParams , $location , $timeout , $window , egCore , egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog) {
152 var cp_list = $routeParams.idList;
154 copyId = cp_list.split(',');
157 $scope.context.page = 'list';
160 var provider = egGridDataProvider.instance();
161 provider.get = function(offset, count) {
165 $scope.gridDataProvider = egGridDataProvider.instance({
166 get : function(offset, count) {
167 //return provider.arrayNotifier(itemSvc.copies, offset, count);
168 return this.arrayNotifier(itemSvc.copies, offset, count);
172 // If a copy was just displayed in the detail view, ensure it's
173 // focused in the list view.
174 var selected = false;
175 var copyGrid = $scope.gridControls = {
176 itemRetrieved : function(item) {
177 if (selected || !itemSvc.copy) return;
178 if (itemSvc.copy.id() == item.id) {
179 copyGrid.selectItems([item.index]);
185 $scope.$watch('barcodesFromFile', function(newVal, oldVal) {
186 if (newVal && newVal != oldVal) {
187 $scope.args.barcode = '';
190 angular.forEach(newVal.split(/\n/), function(line) {
192 // scrub any trailing spaces or commas from the barcode
193 line = line.replace(/(.*?)($|\s.*|,.*)/,'$1');
197 itemSvc.fetch(barcodes).then(
200 copyGrid.selectItems([itemSvc.copies[0].index]);
206 $scope.context.search = function(args) {
207 if (!args.barcode) return;
208 $scope.context.itemNotFound = false;
209 itemSvc.fetch(args.barcode).then(function(res) {
212 copyGrid.selectItems([res.index]);
213 $scope.args.barcode = '';
215 $scope.context.itemNotFound = true;
216 egCore.audio.play('warning.item_status.itemNotFound');
218 $scope.context.selectBarcode = true;
222 var add_barcode_to_list = function (b) {
223 $scope.context.search({barcode:b});
226 $scope.context.toggleDisplay = function() {
227 var item = copyGrid.selectedItems()[0];
229 $location.path('/cat/item/' + item.id);
232 $scope.context.show_triggered_events = function() {
233 var item = copyGrid.selectedItems()[0];
235 $location.path('/cat/item/' + item.id + '/triggered_events');
238 function gatherSelectedRecordIds () {
241 copyGrid.selectedItems(),
243 if (rid_list.indexOf(item['call_number.record.id']) == -1)
244 rid_list.push(item['call_number.record.id'])
250 function gatherSelectedVolumeIds (rid) {
253 copyGrid.selectedItems(),
255 if (rid && item['call_number.record.id'] != rid) return;
256 if (cn_id_list.indexOf(item['call_number.id']) == -1)
257 cn_id_list.push(item['call_number.id'])
263 function gatherSelectedHoldingsIds (rid) {
266 copyGrid.selectedItems(),
268 if (rid && item['call_number.record.id'] != rid) return;
269 cp_id_list.push(item.id)
275 $scope.add_copies_to_bucket = function() {
276 var copy_list = gatherSelectedHoldingsIds();
277 if (copy_list.length == 0) return;
279 return $uibModal.open({
280 templateUrl: './cat/catalog/t_add_to_bucket',
284 ['$scope','$uibModalInstance',
285 function($scope , $uibModalInstance) {
287 $scope.bucket_id = 0;
288 $scope.newBucketName = '';
289 $scope.allBuckets = [];
293 'open-ils.actor.container.retrieve_by_class.authoritative',
294 egCore.auth.token(), egCore.auth.user().id(),
295 'copy', 'staff_client'
296 ).then(function(buckets) { $scope.allBuckets = buckets; });
298 $scope.add_to_bucket = function() {
300 angular.forEach(copy_list, function (cp) {
301 var item = new egCore.idl.ccbi()
302 item.bucket($scope.bucket_id);
303 item.target_copy(cp);
307 'open-ils.actor.container.item.create',
308 egCore.auth.token(), 'copy', item
312 return $q.all(promises).then(function() {
313 $uibModalInstance.close();
318 $scope.add_to_new_bucket = function() {
319 var bucket = new egCore.idl.ccb();
320 bucket.owner(egCore.auth.user().id());
321 bucket.name($scope.newBucketName);
322 bucket.description('');
323 bucket.btype('staff_client');
325 return egCore.net.request(
327 'open-ils.actor.container.create',
328 egCore.auth.token(), 'copy', bucket
329 ).then(function(bucket) {
330 $scope.bucket_id = bucket;
331 $scope.add_to_bucket();
335 $scope.cancel = function() {
336 $uibModalInstance.dismiss();
342 $scope.need_one_selected = function() {
343 var items = $scope.gridControls.selectedItems();
344 if (items.length == 1) return false;
348 $scope.make_copies_bookable = function() {
350 var copies_by_record = {};
351 var record_list = [];
353 copyGrid.selectedItems(),
355 var record_id = item['call_number.record.id'];
356 if (typeof copies_by_record[ record_id ] == 'undefined') {
357 copies_by_record[ record_id ] = [];
358 record_list.push( record_id );
360 copies_by_record[ record_id ].push(item.id);
365 var combined_results = [];
366 angular.forEach(record_list, function(record_id) {
370 'open-ils.booking.resources.create_from_copies',
372 copies_by_record[record_id]
373 ).then(function(results) {
374 if (results && results['brsrc']) {
375 combined_results = combined_results.concat(results['brsrc']);
381 $q.all(promises).then(function() {
382 if (combined_results.length > 0) {
384 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
388 ['$scope','$location','egCore','$uibModalInstance',
389 function($scope , $location , egCore , $uibModalInstance) {
392 ses : egCore.auth.token(),
393 resultant_brsrc : combined_results.map(function(o) { return o[0]; })
396 var booking_path = '/eg/conify/global/booking/resource';
398 $scope.booking_admin_url =
399 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
406 $scope.book_copies_now = function() {
407 var copies_by_record = {};
408 var record_list = [];
410 copyGrid.selectedItems(),
412 var record_id = item['call_number.record.id'];
413 if (typeof copies_by_record[ record_id ] == 'undefined') {
414 copies_by_record[ record_id ] = [];
415 record_list.push( record_id );
417 copies_by_record[ record_id ].push(item.id);
422 var combined_brt = [];
423 var combined_brsrc = [];
424 angular.forEach(record_list, function(record_id) {
428 'open-ils.booking.resources.create_from_copies',
430 copies_by_record[record_id]
431 ).then(function(results) {
432 if (results && results['brt']) {
433 combined_brt = combined_brt.concat(results['brt']);
435 if (results && results['brsrc']) {
436 combined_brsrc = combined_brsrc.concat(results['brsrc']);
442 $q.all(promises).then(function() {
443 if (combined_brt.length > 0 || combined_brsrc.length > 0) {
445 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
449 ['$scope','$location','egCore','$uibModalInstance',
450 function($scope , $location , egCore , $uibModalInstance) {
453 ses : egCore.auth.token(),
454 bresv_interface_opts : {
457 ,brsrc : combined_brsrc
462 var booking_path = '/eg/booking/reservation';
464 $scope.booking_admin_url =
465 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
473 $scope.requestItems = function() {
474 var copy_list = gatherSelectedHoldingsIds();
475 if (copy_list.length == 0) return;
477 return $uibModal.open({
478 templateUrl: './cat/catalog/t_request_items',
481 ['$scope','$uibModalInstance','egUser',
482 function($scope , $uibModalInstance , egUser) {
484 $scope.first_user_fetch = true;
488 copy_list : copy_list,
489 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
490 user : egCore.auth.user().id()
493 egUser.get( $scope.hold_data.user ).then(function(u) {
495 $scope.barcode = u.card().barcode();
496 $scope.user_name = egUser.format_name(u);
497 $scope.hold_data.user = u.id();
500 $scope.user_name = '';
502 $scope.$watch('barcode', function (n) {
503 if (!$scope.first_user_fetch) {
504 egUser.getByBarcode(n).then(function(u) {
506 $scope.user_name = egUser.format_name(u);
507 $scope.hold_data.user = u.id();
510 $scope.user_name = '';
511 delete $scope.hold_data.user;
514 $scope.first_user_fetch = false;
517 $scope.ok = function(h) {
520 hold_type : h.hold_type,
521 pickup_lib: h.pickup_lib.id(),
527 'open-ils.circ.holds.test_and_create.batch.override',
528 egCore.auth.token(), args, h.copy_list
531 $uibModalInstance.close();
534 $scope.cancel = function($event) {
535 $uibModalInstance.dismiss();
536 $event.preventDefault();
542 $scope.replaceBarcodes = function() {
543 angular.forEach(copyGrid.selectedItems(), function (cp) {
545 templateUrl: './cat/share/t_replace_barcode',
548 ['$scope','$uibModalInstance',
549 function($scope , $uibModalInstance) {
550 $scope.isModal = true;
551 $scope.focusBarcode = false;
552 $scope.focusBarcode2 = true;
553 $scope.barcode1 = cp.barcode;
555 $scope.updateBarcode = function() {
556 $scope.copyNotFound = false;
557 $scope.updateOK = false;
559 egCore.pcrud.search('acp',
560 {deleted : 'f', barcode : $scope.barcode1})
561 .then(function(copy) {
564 $scope.focusBarcode = true;
565 $scope.copyNotFound = true;
569 $scope.copyId = copy.id();
570 copy.barcode($scope.barcode2);
572 egCore.pcrud.update(copy).then(function(stat) {
573 $scope.updateOK = stat;
574 $scope.focusBarcode = true;
575 if (stat) add_barcode_to_list(copy.barcode());
579 $uibModalInstance.close();
582 $scope.cancel = function($event) {
583 $uibModalInstance.dismiss();
584 $event.preventDefault();
592 $scope.attach_to_peer_bib = function() {
593 if (copyGrid.selectedItems().length == 0) return;
595 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
596 if (!target_record) return;
598 return $uibModal.open({
599 templateUrl: './cat/catalog/t_conjoined_selector',
602 ['$scope','$uibModalInstance',
603 function($scope , $uibModalInstance) {
604 $scope.update = false;
606 $scope.peer_type = null;
607 $scope.peer_type_list = [];
609 get_peer_types = function() {
611 return $q.when(egCore.env.bpt.list);
613 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
614 .then(function(list) {
615 egCore.env.absorbList(list, 'bpt');
620 get_peer_types().then(function(list){
621 $scope.peer_type_list = list;
624 $scope.ok = function(type) {
627 angular.forEach(copyGrid.selectedItems(), function (cp) {
628 var n = new egCore.idl.bpbcm();
630 n.peer_record(target_record);
631 n.target_copy(cp.id);
633 promises.push(egCore.pcrud.create(n).then(function(){add_barcode_to_list(cp.barcode)}));
636 return $q.all(promises).then(function(){$uibModalInstance.close()});
639 $scope.cancel = function($event) {
640 $uibModalInstance.dismiss();
641 $event.preventDefault();
648 $scope.selectedHoldingsCopyDelete = function () {
649 var copy_list = gatherSelectedHoldingsIds();
650 if (copy_list.length == 0) return;
652 var copy_objects = [];
653 egCore.pcrud.search('acp',
654 {deleted : 'f', id : copy_list},
655 { flesh : 1, flesh_fields : { acp : ['call_number'] } }
656 ).then(function(copy) {
657 copy_objects.push(copy);
661 var perCnCopies = {};
671 var cn_id = cp.call_number().id();
672 if (!cnHash[cn_id]) {
673 cnHash[cn_id] = cp.call_number();
674 perCnCopies[cn_id] = [cp];
676 perCnCopies[cn_id].push(cp);
678 cp.call_number(cn_id); // prevent loops in JSON-ification
682 angular.forEach(perCnCopies, function (v, k) {
687 angular.forEach(cnHash, function (v, k) {
691 if (cnList.length == 0) return;
695 egConfirmDialog.open(
696 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
697 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
698 {copies : cp_count, volumes : cn_count}
699 ).result.then(function() {
702 'open-ils.cat.asset.volume.fleshed.batch.update.override',
703 egCore.auth.token(), cnList, 1, flags
705 angular.forEach(copyGrid.selectedItems(), function(cp){add_barcode_to_list(cp.barcode)});
711 $scope.selectedHoldingsItemStatusTgrEvt= function() {
712 var item = copyGrid.selectedItems()[0];
714 $location.path('/cat/item/' + item.id + '/triggered_events');
717 $scope.selectedHoldingsItemStatusHolds= function() {
718 var item = copyGrid.selectedItems()[0];
720 $location.path('/cat/item/' + item.id + '/holds');
723 $scope.cancel_transit = function () {
724 var initial_list = copyGrid.selectedItems();
725 angular.forEach(copyGrid.selectedItems(), function(cp) {
726 egCirc.find_copy_transit(null, {copy_barcode:cp.barcode})
727 .then(function(t) { return egCirc.abort_transit(t.id()) })
728 .then(function() { return add_barcode_to_list(cp.barcode) });
732 $scope.selectedHoldingsDamaged = function () {
733 var initial_list = copyGrid.selectedItems();
734 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function(){
735 angular.forEach(initial_list, function(cp){add_barcode_to_list(cp.barcode)});
739 $scope.selectedHoldingsMissing = function () {
740 var initial_list = copyGrid.selectedItems();
741 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function(){
742 angular.forEach(initial_list, function(cp){add_barcode_to_list(cp.barcode)});
746 $scope.checkin = function () {
747 angular.forEach(copyGrid.selectedItems(), function (cp) {
748 egCirc.checkin({copy_barcode:cp.barcode}).then(
749 function() { add_barcode_to_list(cp.barcode) }
754 $scope.renew = function () {
755 angular.forEach(copyGrid.selectedItems(), function (cp) {
756 egCirc.renew({copy_barcode:cp.barcode}).then(
757 function() { add_barcode_to_list(cp.barcode) }
763 var spawnHoldingsAdd = function (vols,copies){
764 angular.forEach(gatherSelectedRecordIds(), function (r) {
766 if (copies) { // just a copy on existing volumes
767 angular.forEach(gatherSelectedVolumeIds(r), function (v) {
768 raw.push( {callnumber : v} );
772 gatherSelectedHoldingsIds(r),
774 angular.forEach(copyGrid.selectedItems(), function(item) {
775 if (i == item.id) raw.push({owner : item['call_number.owning_lib']});
781 if (raw.length == 0) raw.push({});
785 'open-ils.actor.anon_cache.set_value',
786 null, 'edit-these-copies', {
792 ).then(function(key) {
794 var url = egCore.env.basePath + 'cat/volcopy/' + key;
795 $timeout(function() { $window.open(url, '_blank') });
797 alert('Could not create anonymous cache key!');
802 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
803 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
805 $scope.showBibHolds = function () {
806 angular.forEach(gatherSelectedRecordIds(), function (r) {
807 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
808 $timeout(function() { $window.open(url, '_blank') });
812 var spawnHoldingsEdit = function (hide_vols,hide_copies){
813 angular.forEach(gatherSelectedRecordIds(), function (r) {
816 'open-ils.actor.anon_cache.set_value',
817 null, 'edit-these-copies', {
819 copies: gatherSelectedHoldingsIds(r),
821 hide_vols : hide_vols,
822 hide_copies : hide_copies
824 ).then(function(key) {
826 var url = egCore.env.basePath + 'cat/volcopy/' + key;
827 $timeout(function() { $window.open(url, '_blank') });
829 alert('Could not create anonymous cache key!');
834 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
835 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
836 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
838 // this "transfers" selected copies to a new owning library,
839 // auto-creating volumes and deleting unused volumes as required.
840 $scope.changeItemOwningLib = function() {
841 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
842 var items = copyGrid.selectedItems();
843 if (!xfer_target || !items.length) {
846 var vols_to_move = {};
847 var copies_to_move = {};
848 angular.forEach(items, function(item) {
849 if (item['call_number.owning_lib'] != xfer_target) {
850 if (item['call_number.id'] in vols_to_move) {
851 copies_to_move[item['call_number.id']].push(item.id);
853 vols_to_move[item['call_number.id']] = {
854 label : item['call_number.label'],
855 label_class : item['call_number.label_class'],
856 record : item['call_number.record.id'],
857 prefix : item['call_number.prefix.id'],
858 suffix : item['call_number.suffix.id']
860 copies_to_move[item['call_number.id']] = new Array;
861 copies_to_move[item['call_number.id']].push(item.id);
867 angular.forEach(vols_to_move, function(vol) {
868 promises.push(egCore.net.request(
870 'open-ils.cat.call_number.find_or_create',
878 ).then(function(resp) {
879 var evt = egCore.evt.parse(resp);
881 return egCore.net.request(
883 'open-ils.cat.transfer_copies_to_volume',
886 copies_to_move[vol.id]
892 copyGrid.selectedItems(),
895 function(){ add_barcode_to_list(cp.barcode) }
902 $scope.transferItems = function (){
903 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
904 var copy_ids = gatherSelectedHoldingsIds();
905 if (xfer_target && copy_ids.length > 0) {
908 'open-ils.cat.transfer_copies_to_volume',
913 function(resp) { // oncomplete
914 var evt = egCore.evt.parse(resp);
915 egConfirmDialog.open(
916 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
917 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
918 {'evt_desc': evt.desc}
919 ).result.then(function() {
922 'open-ils.cat.transfer_copies_to_volume.override',
926 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
933 angular.forEach(copyGrid.selectedItems(), function(cp){add_barcode_to_list(cp.barcode)});
938 $scope.print_list = function() {
939 var print_data = { copies : copyGrid.allItems() };
941 if (print_data.copies.length == 0) return $q.when();
943 return egCore.print.print({
944 template : 'item_status',
949 if (copyId.length > 0) {
950 itemSvc.fetch(null,copyId).then(
960 * Detail view -- shows one copy
962 .controller('ViewCtrl',
963 ['$scope','$q','$location','$routeParams','$timeout','$window','egCore','itemSvc','egBilling',
964 function($scope , $q , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling) {
965 var copyId = $routeParams.id;
966 $scope.tab = $routeParams.tab || 'summary';
967 $scope.context.page = 'detail';
968 $scope.summaryRecord = null;
971 if ($scope.tab == 'edit') {
972 $scope.tab = 'summary';
977 // use the cached record info
979 $scope.recordId = itemSvc.copy.call_number().record().id();
981 function loadCopy(barcode) {
982 $scope.context.itemNotFound = false;
984 // Avoid re-fetching the same copy while jumping tabs.
985 // In addition to being quicker, this helps to avoid flickering
986 // of the top panel which is always visible in the detail view.
988 // 'barcode' represents the loading of a new item - refetch it
989 // regardless of whether it matches the current item.
990 if (!barcode && itemSvc.copy && itemSvc.copy.id() == copyId) {
991 $scope.copy = itemSvc.copy;
992 $scope.recordId = itemSvc.copy.call_number().record().id();
999 var deferred = $q.defer();
1000 itemSvc.fetch(barcode, copyId, true).then(function(res) {
1001 $scope.context.selectBarcode = true;
1005 $scope.context.itemNotFound = true;
1006 egCore.audio.play('warning.item_status.itemNotFound');
1007 deferred.reject(); // avoid propagation of data fetch calls
1011 var copy = res.copy;
1012 itemSvc.copy = copy;
1016 $scope.recordId = copy.call_number().record().id();
1017 $scope.args.barcode = '';
1019 // locally flesh org units
1020 copy.circ_lib(egCore.org.get(copy.circ_lib()));
1021 copy.call_number().owning_lib(
1022 egCore.org.get(copy.call_number().owning_lib()));
1024 var r = copy.call_number().record();
1025 if (r.owner()) r.owner(egCore.org.get(r.owner()));
1027 // make boolean for auto-magic true/false display
1029 ['ref','opac_visible','holdable','circulate'],
1030 function(field) { copy[field](Boolean(copy[field]() == 't')) }
1033 // finally, if this is a different copy, redirect.
1034 // Note that we flesh first since the copy we just
1035 // fetched will be used after the redirect.
1036 if (copyId && copyId != copy.id()) {
1037 // if a new barcode is scanned in the detail view,
1038 // update the url to match the ID of the new copy
1039 $location.path('/cat/item/' + copy.id() + '/' + $scope.tab);
1040 deferred.reject(); // avoid propagation of data fetch calls
1048 return deferred.promise;
1051 // if loadPrev load the two most recent circulations
1052 function loadCurrentCirc(loadPrev) {
1054 delete $scope.circ_summary;
1055 delete $scope.prev_circ_summary;
1056 delete $scope.prev_circ_usr;
1057 if (!copyId) return;
1059 egCore.pcrud.search('circ',
1060 {target_copy : copyId},
1066 'checkin_workstation',
1069 'recurring_fine_rule'
1073 order_by : {circ : 'xact_start desc'},
1077 ).then(null, null, function(circ) {
1080 // load the chain for this circ
1083 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
1084 egCore.auth.token(), $scope.circ.id()
1085 ).then(function(summary) {
1086 $scope.circ_summary = summary.summary;
1089 if (!loadPrev) return;
1091 // load the chain for the previous circ, plus the user
1094 'open-ils.circ.prev_renewal_chain.retrieve_by_circ.summary',
1095 egCore.auth.token(), $scope.circ.id()
1097 ).then(null, null, function(summary) {
1098 $scope.prev_circ_summary = summary.summary;
1100 if (summary.usr) { // aged circs have no 'usr'.
1101 egCore.pcrud.retrieve('au', summary.usr,
1102 {flesh : 1, flesh_fields : {au : ['card']}})
1104 .then(function(user) { $scope.prev_circ_usr = user });
1111 function fetchMaxCircHistory() {
1112 if (maxHistory) return $q.when(maxHistory);
1113 return egCore.org.settings(
1114 'circ.item_checkout_history.max')
1115 .then(function(set) {
1116 maxHistory = set['circ.item_checkout_history.max'] || 4;
1121 $scope.addBilling = function(circ) {
1122 egBilling.showBillDialog({
1123 xact_id : circ.id(),
1128 $scope.retrieveAllPatrons = function() {
1129 var users = new Set();
1130 angular.forEach($scope.circ_list.map(function(circ) { return circ.usr(); }),function(usr) {
1131 // aged circs have no 'usr'.
1132 if (usr) users.add(usr);
1134 users.forEach(function(usr) {
1135 $timeout(function() {
1136 var url = $location.absUrl().replace(
1138 '/circ/patron/' + usr.id() + '/checkout');
1139 $window.open(url, '_blank')
1144 function loadCircHistory() {
1145 $scope.circ_list = [];
1148 itemSvc.copy.call_number().id() == -1 ?
1149 itemSvc.copy.circ_lib().id() :
1150 itemSvc.copy.call_number().owning_lib().id()
1152 // there is an extra layer of permissibility over circ
1154 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
1155 .then(function(orgIds) {
1157 if (orgIds.indexOf(copy_org) == -1) {
1158 console.log('User is not allowed to view circ history');
1162 return fetchMaxCircHistory();
1164 }).then(function(count) {
1166 egCore.pcrud.search('combcirc',
1167 {target_copy : copyId},
1173 'checkin_workstation',
1174 'recurring_fine_rule'
1178 order_by : {combcirc : 'xact_start desc'},
1182 ).then(null, null, function(circ) {
1184 // flesh circ_lib locally
1185 circ.circ_lib(egCore.org.get(circ.circ_lib()));
1186 circ.checkin_lib(egCore.org.get(circ.checkin_lib()));
1187 $scope.circ_list.push(circ);
1193 function loadCircCounts() {
1195 delete $scope.circ_counts;
1196 $scope.total_circs = 0;
1197 $scope.total_circs_this_year = 0;
1198 $scope.total_circs_prev_year = 0;
1199 if (!copyId) return;
1201 egCore.pcrud.search('circbyyr',
1202 {copy : copyId}, null, {atomic : true})
1204 .then(function(counts) {
1205 $scope.circ_counts = counts;
1207 angular.forEach(counts, function(count) {
1208 $scope.total_circs += Number(count.count());
1211 var this_year = counts.filter(function(c) {
1212 return c.year() == new Date().getFullYear();
1215 $scope.total_circs_this_year =
1216 this_year.length ? this_year[0].count() : 0;
1218 var prev_year = counts.filter(function(c) {
1219 return c.year() == new Date().getFullYear() - 1;
1222 $scope.total_circs_prev_year =
1223 prev_year.length ? prev_year[0].count() : 0;
1228 function loadHolds() {
1230 if (!copyId) return;
1232 egCore.pcrud.search('ahr',
1233 { current_copy : copyId,
1235 fulfillment_time : null,
1236 capture_time : {'<>' : null}
1240 ahr : ['requestor', 'usr'],
1244 ).then(null, null, function(hold) {
1246 hold.pickup_lib(egCore.org.get(hold.pickup_lib()));
1247 if (hold.current_shelf_lib()) {
1248 hold.current_shelf_lib(
1249 egCore.org.get(hold.current_shelf_lib()));
1251 hold.behind_desk(Boolean(hold.behind_desk() == 't'));
1255 function loadTransits() {
1256 delete $scope.transit;
1257 delete $scope.hold_transit;
1258 if (!copyId) return;
1260 egCore.pcrud.search('atc',
1261 {target_copy : copyId},
1262 {order_by : {atc : 'source_send_time DESC'}}
1264 ).then(null, null, function(transit) {
1265 $scope.transit = transit;
1266 transit.source(egCore.org.get(transit.source()));
1267 transit.dest(egCore.org.get(transit.dest()));
1272 // we don't need all data on all tabs, so fetch what's needed when needed.
1273 function loadTabData() {
1274 switch($scope.tab) {
1281 loadCurrentCirc(true);
1293 case 'triggered_events':
1294 var url = $location.absUrl().replace(/\/staff.*/, '/actor/user/event_log');
1295 url += '?copy_id=' + encodeURIComponent(copyId);
1296 $scope.triggered_events_url = url;
1303 'open-ils.actor.anon_cache.set_value',
1304 null, 'edit-these-copies', {
1305 record_id: $scope.recordId,
1310 ).then(function(key) {
1312 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1313 $window.location.href = url;
1315 alert('Could not create anonymous cache key!');
1323 $scope.context.toggleDisplay = function() {
1324 $location.path('/cat/item/search');
1327 // handle the barcode scan box, which will replace our current copy
1328 $scope.context.search = function(args) {
1329 loadCopy(args.barcode).then(loadTabData);
1332 $scope.context.show_triggered_events = function() {
1333 $location.path('/cat/item/' + copyId + '/triggered_events');
1336 loadCopy().then(loadTabData);