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',
63 'age_protect','circ_lib'],
64 acn : ['record','prefix','suffix','label_class'],
65 bre : ['simple_record','creator','editor']
68 // avoid fleshing MARC on the bre
69 // note: don't add simple_record.. not sure why
70 bre : ['id','tcn_value','creator','editor'],
80 'checkin_workstation',
88 order_by : {circ : 'xact_start desc'},
92 //Retrieve separate copy, combcirc, and accs information
93 service.getCopy = function(barcode, id) {
94 if (barcode) return egCore.pcrud.search(
95 'acp', {barcode : barcode, deleted : 'f'},
96 service.flesh).then(function(copy) {return copy});
98 return egCore.pcrud.retrieve( 'acp', id, service.flesh)
99 .then(function(copy) {return copy});
101 service.getCirc = function(id) {
102 return egCore.pcrud.search('combcirc', { target_copy : id },
103 service.circFlesh).then(function(circ) {return circ});
105 service.getSummary = function(id) {
106 return circ_summary = egCore.net.request(
108 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
109 egCore.auth.token(), id).then(
110 function(circ_summary) {return circ_summary});
113 //Combine copy, circ, and accs information
114 service.retrieveCopyData = function(barcode, id) {
117 var fetchCopy = function(barcode, id) {
118 return service.getCopy(barcode, id)
119 .then(function(copy) {
120 copyData.copy = copy;
124 var fetchCirc = function(copy) {
125 return service.getCirc(copy.id())
126 .then(function(circ) {
127 copyData.circ = circ;
131 var fetchSummary = function(circ) {
132 return service.getSummary(circ.id())
133 .then(function(summary) {
134 copyData.circ_summary = summary;
138 return fetchCopy(barcode, id).then(function(res) {
139 return fetchCirc(copyData.copy).then(function(res) {
141 return fetchSummary(copyData.circ).then(function() {
152 // resolved with the last received copy
153 service.fetch = function(barcode, id, noListDupes) {
159 return service.retrieveCopyData(barcode, id)
160 .then(function(copyData) {
161 //Make sure we're getting a completed copyData - no plain acp or circ objects
163 // flesh circ_lib locally
164 copyData.circ.circ_lib(egCore.org.get(copyData.circ.circ_lib()));
165 copyData.circ.checkin_workstation(
166 egCore.org.get(copyData.circ.checkin_workstation()));
171 // use the existing copy if possible
172 flatCopy = service.copies.filter(
173 function(c) {return c.id == copyData.copy.id()})[0];
177 flatCopy = egCore.idl.toHash(copyData.copy, true);
180 flatCopy._circ = egCore.idl.toHash(copyData.circ, true);
181 flatCopy._circ_summary = egCore.idl.toHash(copyData.circ_summary, true);
183 flatCopy.index = service.index++;
184 service.copies.unshift(flatCopy);
187 //Get in-house use count
188 egCore.pcrud.search('aihu',
189 {item : flatCopy.id}, {}, {idlist : true, atomic : true})
190 .then(function(uses) {
191 flatCopy._inHouseUseCount = uses.length;
192 copyData.copy._inHouseUseCount = uses.length;
196 copy : copyData.copy,
197 index : flatCopy.index
208 * Search bar along the top of the page.
209 * Parent scope for list and detail views
211 .controller('SearchCtrl',
212 ['$scope','$location','egCore','egGridDataProvider','itemSvc',
213 function($scope , $location , egCore , egGridDataProvider , itemSvc) {
214 $scope.args = {}; // search args
216 // sub-scopes (search / detail-view) apply their version
217 // of retrieval function to $scope.context.search
218 // and display toggling via $scope.context.toggleDisplay
223 $scope.toggleView = function($event) {
224 $scope.context.toggleDisplay();
225 $event.preventDefault(); // avoid form submission
230 * List view - grid stuff
232 .controller('ListCtrl',
233 ['$scope','$q','$routeParams','$location','$timeout','$window','egCore','egGridDataProvider','itemSvc','egUser','$uibModal','egCirc','egConfirmDialog',
234 function($scope , $q , $routeParams , $location , $timeout , $window , egCore , egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog) {
236 var cp_list = $routeParams.idList;
238 copyId = cp_list.split(',');
241 $scope.context.page = 'list';
244 var provider = egGridDataProvider.instance();
245 provider.get = function(offset, count) {
249 $scope.gridDataProvider = egGridDataProvider.instance({
250 get : function(offset, count) {
251 //return provider.arrayNotifier(itemSvc.copies, offset, count);
252 return this.arrayNotifier(itemSvc.copies, offset, count);
256 // If a copy was just displayed in the detail view, ensure it's
257 // focused in the list view.
258 var selected = false;
259 var copyGrid = $scope.gridControls = {
260 itemRetrieved : function(item) {
261 if (selected || !itemSvc.copy) return;
262 if (itemSvc.copy.id() == item.id) {
263 copyGrid.selectItems([item.index]);
269 $scope.$watch('barcodesFromFile', function(newVal, oldVal) {
270 if (newVal && newVal != oldVal) {
271 $scope.args.barcode = '';
274 angular.forEach(newVal.split(/\n/), function(line) {
276 // scrub any trailing spaces or commas from the barcode
277 line = line.replace(/(.*?)($|\s.*|,.*)/,'$1');
281 itemSvc.fetch(barcodes).then(
284 copyGrid.selectItems([itemSvc.copies[0].index]);
290 $scope.context.search = function(args) {
291 if (!args.barcode) return;
292 $scope.context.itemNotFound = false;
293 itemSvc.fetch(args.barcode).then(function(res) {
296 copyGrid.selectItems([res.index]);
297 $scope.args.barcode = '';
299 $scope.context.itemNotFound = true;
300 egCore.audio.play('warning.item_status.itemNotFound');
302 $scope.context.selectBarcode = true;
306 var add_barcode_to_list = function (b) {
307 $scope.context.search({barcode:b});
310 $scope.context.toggleDisplay = function() {
311 var item = copyGrid.selectedItems()[0];
313 $location.path('/cat/item/' + item.id);
316 $scope.context.show_triggered_events = function() {
317 var item = copyGrid.selectedItems()[0];
319 $location.path('/cat/item/' + item.id + '/triggered_events');
322 function gatherSelectedRecordIds () {
325 copyGrid.selectedItems(),
327 if (rid_list.indexOf(item['call_number.record.id']) == -1)
328 rid_list.push(item['call_number.record.id'])
334 function gatherSelectedVolumeIds (rid) {
337 copyGrid.selectedItems(),
339 if (rid && item['call_number.record.id'] != rid) return;
340 if (cn_id_list.indexOf(item['call_number.id']) == -1)
341 cn_id_list.push(item['call_number.id'])
347 function gatherSelectedHoldingsIds (rid) {
350 copyGrid.selectedItems(),
352 if (rid && item['call_number.record.id'] != rid) return;
353 cp_id_list.push(item.id)
359 $scope.add_copies_to_bucket = function() {
360 var copy_list = gatherSelectedHoldingsIds();
361 if (copy_list.length == 0) return;
363 return $uibModal.open({
364 templateUrl: './cat/catalog/t_add_to_bucket',
368 ['$scope','$uibModalInstance',
369 function($scope , $uibModalInstance) {
371 $scope.bucket_id = 0;
372 $scope.newBucketName = '';
373 $scope.allBuckets = [];
377 'open-ils.actor.container.retrieve_by_class.authoritative',
378 egCore.auth.token(), egCore.auth.user().id(),
379 'copy', 'staff_client'
380 ).then(function(buckets) { $scope.allBuckets = buckets; });
382 $scope.add_to_bucket = function() {
384 angular.forEach(copy_list, function (cp) {
385 var item = new egCore.idl.ccbi()
386 item.bucket($scope.bucket_id);
387 item.target_copy(cp);
391 'open-ils.actor.container.item.create',
392 egCore.auth.token(), 'copy', item
396 return $q.all(promises).then(function() {
397 $uibModalInstance.close();
402 $scope.add_to_new_bucket = function() {
403 var bucket = new egCore.idl.ccb();
404 bucket.owner(egCore.auth.user().id());
405 bucket.name($scope.newBucketName);
406 bucket.description('');
407 bucket.btype('staff_client');
409 return egCore.net.request(
411 'open-ils.actor.container.create',
412 egCore.auth.token(), 'copy', bucket
413 ).then(function(bucket) {
414 $scope.bucket_id = bucket;
415 $scope.add_to_bucket();
419 $scope.cancel = function() {
420 $uibModalInstance.dismiss();
426 $scope.need_one_selected = function() {
427 var items = $scope.gridControls.selectedItems();
428 if (items.length == 1) return false;
432 $scope.make_copies_bookable = function() {
434 var copies_by_record = {};
435 var record_list = [];
437 copyGrid.selectedItems(),
439 var record_id = item['call_number.record.id'];
440 if (typeof copies_by_record[ record_id ] == 'undefined') {
441 copies_by_record[ record_id ] = [];
442 record_list.push( record_id );
444 copies_by_record[ record_id ].push(item.id);
449 var combined_results = [];
450 angular.forEach(record_list, function(record_id) {
454 'open-ils.booking.resources.create_from_copies',
456 copies_by_record[record_id]
457 ).then(function(results) {
458 if (results && results['brsrc']) {
459 combined_results = combined_results.concat(results['brsrc']);
465 $q.all(promises).then(function() {
466 if (combined_results.length > 0) {
468 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
472 ['$scope','$location','egCore','$uibModalInstance',
473 function($scope , $location , egCore , $uibModalInstance) {
476 ses : egCore.auth.token(),
477 resultant_brsrc : combined_results.map(function(o) { return o[0]; })
480 var booking_path = '/eg/conify/global/booking/resource';
482 $scope.booking_admin_url =
483 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
490 $scope.book_copies_now = function() {
491 var copies_by_record = {};
492 var record_list = [];
494 copyGrid.selectedItems(),
496 var record_id = item['call_number.record.id'];
497 if (typeof copies_by_record[ record_id ] == 'undefined') {
498 copies_by_record[ record_id ] = [];
499 record_list.push( record_id );
501 copies_by_record[ record_id ].push(item.id);
506 var combined_brt = [];
507 var combined_brsrc = [];
508 angular.forEach(record_list, function(record_id) {
512 'open-ils.booking.resources.create_from_copies',
514 copies_by_record[record_id]
515 ).then(function(results) {
516 if (results && results['brt']) {
517 combined_brt = combined_brt.concat(results['brt']);
519 if (results && results['brsrc']) {
520 combined_brsrc = combined_brsrc.concat(results['brsrc']);
526 $q.all(promises).then(function() {
527 if (combined_brt.length > 0 || combined_brsrc.length > 0) {
529 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
533 ['$scope','$location','egCore','$uibModalInstance',
534 function($scope , $location , egCore , $uibModalInstance) {
537 ses : egCore.auth.token(),
538 bresv_interface_opts : {
541 ,brsrc : combined_brsrc
546 var booking_path = '/eg/booking/reservation';
548 $scope.booking_admin_url =
549 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
557 $scope.requestItems = function() {
558 var copy_list = gatherSelectedHoldingsIds();
559 if (copy_list.length == 0) return;
561 return $uibModal.open({
562 templateUrl: './cat/catalog/t_request_items',
565 ['$scope','$uibModalInstance','egUser',
566 function($scope , $uibModalInstance , egUser) {
568 $scope.first_user_fetch = true;
572 copy_list : copy_list,
573 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
574 user : egCore.auth.user().id()
577 egUser.get( $scope.hold_data.user ).then(function(u) {
579 $scope.barcode = u.card().barcode();
580 $scope.user_name = egUser.format_name(u);
581 $scope.hold_data.user = u.id();
584 $scope.user_name = '';
586 $scope.$watch('barcode', function (n) {
587 if (!$scope.first_user_fetch) {
588 egUser.getByBarcode(n).then(function(u) {
590 $scope.user_name = egUser.format_name(u);
591 $scope.hold_data.user = u.id();
594 $scope.user_name = '';
595 delete $scope.hold_data.user;
598 $scope.first_user_fetch = false;
601 $scope.ok = function(h) {
604 hold_type : h.hold_type,
605 pickup_lib: h.pickup_lib.id(),
611 'open-ils.circ.holds.test_and_create.batch.override',
612 egCore.auth.token(), args, h.copy_list
615 $uibModalInstance.close();
618 $scope.cancel = function($event) {
619 $uibModalInstance.dismiss();
620 $event.preventDefault();
626 $scope.replaceBarcodes = function() {
627 angular.forEach(copyGrid.selectedItems(), function (cp) {
629 templateUrl: './cat/share/t_replace_barcode',
632 ['$scope','$uibModalInstance',
633 function($scope , $uibModalInstance) {
634 $scope.isModal = true;
635 $scope.focusBarcode = false;
636 $scope.focusBarcode2 = true;
637 $scope.barcode1 = cp.barcode;
639 $scope.updateBarcode = function() {
640 $scope.copyNotFound = false;
641 $scope.updateOK = false;
643 egCore.pcrud.search('acp',
644 {deleted : 'f', barcode : $scope.barcode1})
645 .then(function(copy) {
648 $scope.focusBarcode = true;
649 $scope.copyNotFound = true;
653 $scope.copyId = copy.id();
654 copy.barcode($scope.barcode2);
656 egCore.pcrud.update(copy).then(function(stat) {
657 $scope.updateOK = stat;
658 $scope.focusBarcode = true;
659 if (stat) add_barcode_to_list(copy.barcode());
663 $uibModalInstance.close();
666 $scope.cancel = function($event) {
667 $uibModalInstance.dismiss();
668 $event.preventDefault();
676 $scope.attach_to_peer_bib = function() {
677 if (copyGrid.selectedItems().length == 0) return;
679 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
680 if (!target_record) return;
682 return $uibModal.open({
683 templateUrl: './cat/catalog/t_conjoined_selector',
686 ['$scope','$uibModalInstance',
687 function($scope , $uibModalInstance) {
688 $scope.update = false;
690 $scope.peer_type = null;
691 $scope.peer_type_list = [];
693 get_peer_types = function() {
695 return $q.when(egCore.env.bpt.list);
697 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
698 .then(function(list) {
699 egCore.env.absorbList(list, 'bpt');
704 get_peer_types().then(function(list){
705 $scope.peer_type_list = list;
708 $scope.ok = function(type) {
711 angular.forEach(copyGrid.selectedItems(), function (cp) {
712 var n = new egCore.idl.bpbcm();
714 n.peer_record(target_record);
715 n.target_copy(cp.id);
717 promises.push(egCore.pcrud.create(n).then(function(){add_barcode_to_list(cp.barcode)}));
720 return $q.all(promises).then(function(){$uibModalInstance.close()});
723 $scope.cancel = function($event) {
724 $uibModalInstance.dismiss();
725 $event.preventDefault();
732 $scope.selectedHoldingsCopyDelete = function () {
733 var copy_list = gatherSelectedHoldingsIds();
734 if (copy_list.length == 0) return;
736 var copy_objects = [];
737 egCore.pcrud.search('acp',
738 {deleted : 'f', id : copy_list},
739 { flesh : 1, flesh_fields : { acp : ['call_number'] } }
740 ).then(function(copy) {
741 copy_objects.push(copy);
745 var perCnCopies = {};
755 var cn_id = cp.call_number().id();
756 if (!cnHash[cn_id]) {
757 cnHash[cn_id] = cp.call_number();
758 perCnCopies[cn_id] = [cp];
760 perCnCopies[cn_id].push(cp);
762 cp.call_number(cn_id); // prevent loops in JSON-ification
766 angular.forEach(perCnCopies, function (v, k) {
771 angular.forEach(cnHash, function (v, k) {
775 if (cnList.length == 0) return;
779 egConfirmDialog.open(
780 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
781 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
782 {copies : cp_count, volumes : cn_count}
783 ).result.then(function() {
786 'open-ils.cat.asset.volume.fleshed.batch.update.override',
787 egCore.auth.token(), cnList, 1, flags
789 angular.forEach(copyGrid.selectedItems(), function(cp){add_barcode_to_list(cp.barcode)});
795 $scope.selectedHoldingsItemStatusTgrEvt= function() {
796 var item = copyGrid.selectedItems()[0];
798 $location.path('/cat/item/' + item.id + '/triggered_events');
801 $scope.selectedHoldingsItemStatusHolds= function() {
802 var item = copyGrid.selectedItems()[0];
804 $location.path('/cat/item/' + item.id + '/holds');
807 $scope.cancel_transit = function () {
808 var initial_list = copyGrid.selectedItems();
809 angular.forEach(copyGrid.selectedItems(), function(cp) {
810 egCirc.find_copy_transit(null, {copy_barcode:cp.barcode})
811 .then(function(t) { return egCirc.abort_transit(t.id()) })
812 .then(function() { return add_barcode_to_list(cp.barcode) });
816 $scope.selectedHoldingsDamaged = function () {
817 var initial_list = copyGrid.selectedItems();
818 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function(){
819 angular.forEach(initial_list, function(cp){add_barcode_to_list(cp.barcode)});
823 $scope.selectedHoldingsMissing = function () {
824 var initial_list = copyGrid.selectedItems();
825 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function(){
826 angular.forEach(initial_list, function(cp){add_barcode_to_list(cp.barcode)});
830 $scope.checkin = function () {
831 angular.forEach(copyGrid.selectedItems(), function (cp) {
832 egCirc.checkin({copy_barcode:cp.barcode}).then(
833 function() { add_barcode_to_list(cp.barcode) }
838 $scope.renew = function () {
839 angular.forEach(copyGrid.selectedItems(), function (cp) {
840 egCirc.renew({copy_barcode:cp.barcode}).then(
841 function() { add_barcode_to_list(cp.barcode) }
847 var spawnHoldingsAdd = function (vols,copies){
848 angular.forEach(gatherSelectedRecordIds(), function (r) {
850 if (copies) { // just a copy on existing volumes
851 angular.forEach(gatherSelectedVolumeIds(r), function (v) {
852 raw.push( {callnumber : v} );
856 gatherSelectedHoldingsIds(r),
858 angular.forEach(copyGrid.selectedItems(), function(item) {
859 if (i == item.id) raw.push({owner : item['call_number.owning_lib']});
865 if (raw.length == 0) raw.push({});
869 'open-ils.actor.anon_cache.set_value',
870 null, 'edit-these-copies', {
876 ).then(function(key) {
878 var url = egCore.env.basePath + 'cat/volcopy/' + key;
879 $timeout(function() { $window.open(url, '_blank') });
881 alert('Could not create anonymous cache key!');
886 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
887 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
889 $scope.showBibHolds = function () {
890 angular.forEach(gatherSelectedRecordIds(), function (r) {
891 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
892 $timeout(function() { $window.open(url, '_blank') });
896 var spawnHoldingsEdit = function (hide_vols,hide_copies){
897 angular.forEach(gatherSelectedRecordIds(), function (r) {
900 'open-ils.actor.anon_cache.set_value',
901 null, 'edit-these-copies', {
903 copies: gatherSelectedHoldingsIds(r),
905 hide_vols : hide_vols,
906 hide_copies : hide_copies
908 ).then(function(key) {
910 var url = egCore.env.basePath + 'cat/volcopy/' + key;
911 $timeout(function() { $window.open(url, '_blank') });
913 alert('Could not create anonymous cache key!');
918 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
919 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
920 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
922 // this "transfers" selected copies to a new owning library,
923 // auto-creating volumes and deleting unused volumes as required.
924 $scope.changeItemOwningLib = function() {
925 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
926 var items = copyGrid.selectedItems();
927 if (!xfer_target || !items.length) {
930 var vols_to_move = {};
931 var copies_to_move = {};
932 angular.forEach(items, function(item) {
933 if (item['call_number.owning_lib'] != xfer_target) {
934 if (item['call_number.id'] in vols_to_move) {
935 copies_to_move[item['call_number.id']].push(item.id);
937 vols_to_move[item['call_number.id']] = {
938 label : item['call_number.label'],
939 label_class : item['call_number.label_class'],
940 record : item['call_number.record.id'],
941 prefix : item['call_number.prefix.id'],
942 suffix : item['call_number.suffix.id']
944 copies_to_move[item['call_number.id']] = new Array;
945 copies_to_move[item['call_number.id']].push(item.id);
951 angular.forEach(vols_to_move, function(vol) {
952 promises.push(egCore.net.request(
954 'open-ils.cat.call_number.find_or_create',
962 ).then(function(resp) {
963 var evt = egCore.evt.parse(resp);
965 return egCore.net.request(
967 'open-ils.cat.transfer_copies_to_volume',
970 copies_to_move[vol.id]
976 copyGrid.selectedItems(),
979 function(){ add_barcode_to_list(cp.barcode) }
986 $scope.transferItems = function (){
987 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
988 var copy_ids = gatherSelectedHoldingsIds();
989 if (xfer_target && copy_ids.length > 0) {
992 'open-ils.cat.transfer_copies_to_volume',
997 function(resp) { // oncomplete
998 var evt = egCore.evt.parse(resp);
999 egConfirmDialog.open(
1000 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1001 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1002 {'evt_desc': evt.desc}
1003 ).result.then(function() {
1006 'open-ils.cat.transfer_copies_to_volume.override',
1007 egCore.auth.token(),
1010 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1017 angular.forEach(copyGrid.selectedItems(), function(cp){add_barcode_to_list(cp.barcode)});
1022 $scope.print_list = function() {
1023 var print_data = { copies : copyGrid.allItems() };
1025 if (print_data.copies.length == 0) return $q.when();
1027 return egCore.print.print({
1028 template : 'item_status',
1033 if (copyId.length > 0) {
1034 itemSvc.fetch(null,copyId).then(
1044 * Detail view -- shows one copy
1046 .controller('ViewCtrl',
1047 ['$scope','$q','$location','$routeParams','$timeout','$window','egCore','itemSvc','egBilling',
1048 function($scope , $q , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling) {
1049 var copyId = $routeParams.id;
1050 $scope.tab = $routeParams.tab || 'summary';
1051 $scope.context.page = 'detail';
1052 $scope.summaryRecord = null;
1054 $scope.edit = false;
1055 if ($scope.tab == 'edit') {
1056 $scope.tab = 'summary';
1061 // use the cached record info
1063 $scope.recordId = itemSvc.copy.call_number().record().id();
1065 function loadCopy(barcode) {
1066 $scope.context.itemNotFound = false;
1068 // Avoid re-fetching the same copy while jumping tabs.
1069 // In addition to being quicker, this helps to avoid flickering
1070 // of the top panel which is always visible in the detail view.
1072 // 'barcode' represents the loading of a new item - refetch it
1073 // regardless of whether it matches the current item.
1074 if (!barcode && itemSvc.copy && itemSvc.copy.id() == copyId) {
1075 $scope.copy = itemSvc.copy;
1076 $scope.recordId = itemSvc.copy.call_number().record().id();
1081 delete itemSvc.copy;
1083 var deferred = $q.defer();
1084 itemSvc.fetch(barcode, copyId, true).then(function(res) {
1085 $scope.context.selectBarcode = true;
1089 $scope.context.itemNotFound = true;
1090 egCore.audio.play('warning.item_status.itemNotFound');
1091 deferred.reject(); // avoid propagation of data fetch calls
1095 var copy = res.copy;
1096 itemSvc.copy = copy;
1100 $scope.recordId = copy.call_number().record().id();
1101 $scope.args.barcode = '';
1103 // locally flesh org units
1104 copy.circ_lib(egCore.org.get(copy.circ_lib()));
1105 copy.call_number().owning_lib(
1106 egCore.org.get(copy.call_number().owning_lib()));
1108 var r = copy.call_number().record();
1109 if (r.owner()) r.owner(egCore.org.get(r.owner()));
1111 // make boolean for auto-magic true/false display
1113 ['ref','opac_visible','holdable','circulate'],
1114 function(field) { copy[field](Boolean(copy[field]() == 't')) }
1117 // finally, if this is a different copy, redirect.
1118 // Note that we flesh first since the copy we just
1119 // fetched will be used after the redirect.
1120 if (copyId && copyId != copy.id()) {
1121 // if a new barcode is scanned in the detail view,
1122 // update the url to match the ID of the new copy
1123 $location.path('/cat/item/' + copy.id() + '/' + $scope.tab);
1124 deferred.reject(); // avoid propagation of data fetch calls
1132 return deferred.promise;
1135 // if loadPrev load the two most recent circulations
1136 function loadCurrentCirc(loadPrev) {
1138 delete $scope.circ_summary;
1139 delete $scope.prev_circ_summary;
1140 delete $scope.prev_circ_usr;
1141 if (!copyId) return;
1143 egCore.pcrud.search('circ',
1144 {target_copy : copyId},
1150 'checkin_workstation',
1153 'recurring_fine_rule'
1157 order_by : {circ : 'xact_start desc'},
1161 ).then(null, null, function(circ) {
1164 // load the chain for this circ
1167 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
1168 egCore.auth.token(), $scope.circ.id()
1169 ).then(function(summary) {
1170 $scope.circ_summary = summary.summary;
1173 if (!loadPrev) return;
1175 // load the chain for the previous circ, plus the user
1178 'open-ils.circ.prev_renewal_chain.retrieve_by_circ.summary',
1179 egCore.auth.token(), $scope.circ.id()
1181 ).then(null, null, function(summary) {
1182 $scope.prev_circ_summary = summary.summary;
1184 if (summary.usr) { // aged circs have no 'usr'.
1185 egCore.pcrud.retrieve('au', summary.usr,
1186 {flesh : 1, flesh_fields : {au : ['card']}})
1188 .then(function(user) { $scope.prev_circ_usr = user });
1195 function fetchMaxCircHistory() {
1196 if (maxHistory) return $q.when(maxHistory);
1197 return egCore.org.settings(
1198 'circ.item_checkout_history.max')
1199 .then(function(set) {
1200 maxHistory = set['circ.item_checkout_history.max'] || 4;
1205 $scope.addBilling = function(circ) {
1206 egBilling.showBillDialog({
1207 xact_id : circ.id(),
1212 $scope.retrieveAllPatrons = function() {
1213 var users = new Set();
1214 angular.forEach($scope.circ_list.map(function(circ) { return circ.usr(); }),function(usr) {
1215 // aged circs have no 'usr'.
1216 if (usr) users.add(usr);
1218 users.forEach(function(usr) {
1219 $timeout(function() {
1220 var url = $location.absUrl().replace(
1222 '/circ/patron/' + usr.id() + '/checkout');
1223 $window.open(url, '_blank')
1228 function loadCircHistory() {
1229 $scope.circ_list = [];
1232 itemSvc.copy.call_number().id() == -1 ?
1233 itemSvc.copy.circ_lib().id() :
1234 itemSvc.copy.call_number().owning_lib().id()
1236 // there is an extra layer of permissibility over circ
1238 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
1239 .then(function(orgIds) {
1241 if (orgIds.indexOf(copy_org) == -1) {
1242 console.log('User is not allowed to view circ history');
1246 return fetchMaxCircHistory();
1248 }).then(function(count) {
1250 egCore.pcrud.search('combcirc',
1251 {target_copy : copyId},
1257 'checkin_workstation',
1258 'recurring_fine_rule'
1262 order_by : {combcirc : 'xact_start desc'},
1266 ).then(null, null, function(circ) {
1268 // flesh circ_lib locally
1269 circ.circ_lib(egCore.org.get(circ.circ_lib()));
1270 circ.checkin_lib(egCore.org.get(circ.checkin_lib()));
1271 $scope.circ_list.push(circ);
1277 function loadCircCounts() {
1279 delete $scope.circ_counts;
1280 $scope.total_circs = 0;
1281 $scope.total_circs_this_year = 0;
1282 $scope.total_circs_prev_year = 0;
1283 if (!copyId) return;
1285 egCore.pcrud.search('circbyyr',
1286 {copy : copyId}, null, {atomic : true})
1288 .then(function(counts) {
1289 $scope.circ_counts = counts;
1291 angular.forEach(counts, function(count) {
1292 $scope.total_circs += Number(count.count());
1295 var this_year = counts.filter(function(c) {
1296 return c.year() == new Date().getFullYear();
1299 $scope.total_circs_this_year =
1300 this_year.length ? this_year[0].count() : 0;
1302 var prev_year = counts.filter(function(c) {
1303 return c.year() == new Date().getFullYear() - 1;
1306 $scope.total_circs_prev_year =
1307 prev_year.length ? prev_year[0].count() : 0;
1312 function loadHolds() {
1314 if (!copyId) return;
1316 egCore.pcrud.search('ahr',
1317 { current_copy : copyId,
1319 fulfillment_time : null,
1320 capture_time : {'<>' : null}
1324 ahr : ['requestor', 'usr'],
1328 ).then(null, null, function(hold) {
1330 hold.pickup_lib(egCore.org.get(hold.pickup_lib()));
1331 if (hold.current_shelf_lib()) {
1332 hold.current_shelf_lib(
1333 egCore.org.get(hold.current_shelf_lib()));
1335 hold.behind_desk(Boolean(hold.behind_desk() == 't'));
1339 function loadTransits() {
1340 delete $scope.transit;
1341 delete $scope.hold_transit;
1342 if (!copyId) return;
1344 egCore.pcrud.search('atc',
1345 {target_copy : copyId},
1346 {order_by : {atc : 'source_send_time DESC'}}
1348 ).then(null, null, function(transit) {
1349 $scope.transit = transit;
1350 transit.source(egCore.org.get(transit.source()));
1351 transit.dest(egCore.org.get(transit.dest()));
1356 // we don't need all data on all tabs, so fetch what's needed when needed.
1357 function loadTabData() {
1358 switch($scope.tab) {
1365 loadCurrentCirc(true);
1377 case 'triggered_events':
1378 var url = $location.absUrl().replace(/\/staff.*/, '/actor/user/event_log');
1379 url += '?copy_id=' + encodeURIComponent(copyId);
1380 $scope.triggered_events_url = url;
1387 'open-ils.actor.anon_cache.set_value',
1388 null, 'edit-these-copies', {
1389 record_id: $scope.recordId,
1394 ).then(function(key) {
1396 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1397 $window.location.href = url;
1399 alert('Could not create anonymous cache key!');
1407 $scope.context.toggleDisplay = function() {
1408 $location.path('/cat/item/search');
1411 // handle the barcode scan box, which will replace our current copy
1412 $scope.context.search = function(args) {
1413 loadCopy(args.barcode).then(loadTabData);
1416 $scope.context.show_triggered_events = function() {
1417 $location.path('/cat/item/' + copyId + '/triggered_events');
1420 loadCopy().then(loadTabData);