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'});
51 ['egCore','egCirc','$uibModal','$q','$timeout','$window','egConfirmDialog',
52 function(egCore , egCirc , $uibModal , $q , $timeout , $window , egConfirmDialog ) {
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
204 service.add_copies_to_bucket = function(copy_list) {
205 if (copy_list.length == 0) return;
207 return $uibModal.open({
208 templateUrl: './cat/catalog/t_add_to_bucket',
212 ['$scope','$uibModalInstance',
213 function($scope , $uibModalInstance) {
215 $scope.bucket_id = 0;
216 $scope.newBucketName = '';
217 $scope.allBuckets = [];
221 'open-ils.actor.container.retrieve_by_class.authoritative',
222 egCore.auth.token(), egCore.auth.user().id(),
223 'copy', 'staff_client'
224 ).then(function(buckets) { $scope.allBuckets = buckets; });
226 $scope.add_to_bucket = function() {
228 angular.forEach(copy_list, function (cp) {
229 var item = new egCore.idl.ccbi()
230 item.bucket($scope.bucket_id);
231 item.target_copy(cp);
235 'open-ils.actor.container.item.create',
236 egCore.auth.token(), 'copy', item
240 return $q.all(promises).then(function() {
241 $uibModalInstance.close();
246 $scope.add_to_new_bucket = function() {
247 var bucket = new egCore.idl.ccb();
248 bucket.owner(egCore.auth.user().id());
249 bucket.name($scope.newBucketName);
250 bucket.description('');
251 bucket.btype('staff_client');
253 return egCore.net.request(
255 'open-ils.actor.container.create',
256 egCore.auth.token(), 'copy', bucket
257 ).then(function(bucket) {
258 $scope.bucket_id = bucket;
259 $scope.add_to_bucket();
263 $scope.cancel = function() {
264 $uibModalInstance.dismiss();
270 service.make_copies_bookable = function(items) {
272 var copies_by_record = {};
273 var record_list = [];
277 var record_id = item['call_number.record.id'];
278 if (typeof copies_by_record[ record_id ] == 'undefined') {
279 copies_by_record[ record_id ] = [];
280 record_list.push( record_id );
282 copies_by_record[ record_id ].push(item.id);
287 var combined_results = [];
288 angular.forEach(record_list, function(record_id) {
292 'open-ils.booking.resources.create_from_copies',
294 copies_by_record[record_id]
295 ).then(function(results) {
296 if (results && results['brsrc']) {
297 combined_results = combined_results.concat(results['brsrc']);
303 $q.all(promises).then(function() {
304 if (combined_results.length > 0) {
306 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
310 ['$scope','$location','egCore','$uibModalInstance',
311 function($scope , $location , egCore , $uibModalInstance) {
314 ses : egCore.auth.token(),
315 resultant_brsrc : combined_results.map(function(o) { return o[0]; })
318 var booking_path = '/eg/conify/global/booking/resource';
320 $scope.booking_admin_url =
321 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
328 service.book_copies_now = function(items) {
329 var copies_by_record = {};
330 var record_list = [];
334 var record_id = item['call_number.record.id'];
335 if (typeof copies_by_record[ record_id ] == 'undefined') {
336 copies_by_record[ record_id ] = [];
337 record_list.push( record_id );
339 copies_by_record[ record_id ].push(item.id);
344 var combined_brt = [];
345 var combined_brsrc = [];
346 angular.forEach(record_list, function(record_id) {
350 'open-ils.booking.resources.create_from_copies',
352 copies_by_record[record_id]
353 ).then(function(results) {
354 if (results && results['brt']) {
355 combined_brt = combined_brt.concat(results['brt']);
357 if (results && results['brsrc']) {
358 combined_brsrc = combined_brsrc.concat(results['brsrc']);
364 $q.all(promises).then(function() {
365 if (combined_brt.length > 0 || combined_brsrc.length > 0) {
367 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
371 ['$scope','$location','egCore','$uibModalInstance',
372 function($scope , $location , egCore , $uibModalInstance) {
375 ses : egCore.auth.token(),
376 bresv_interface_opts : {
379 ,brsrc : combined_brsrc
384 var booking_path = '/eg/booking/reservation';
386 $scope.booking_admin_url =
387 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
395 service.requestItems = function(copy_list) {
396 if (copy_list.length == 0) return;
398 return $uibModal.open({
399 templateUrl: './cat/catalog/t_request_items',
402 ['$scope','$uibModalInstance','egUser',
403 function($scope , $uibModalInstance , egUser) {
405 $scope.first_user_fetch = true;
409 copy_list : copy_list,
410 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
411 user : egCore.auth.user().id()
414 egUser.get( $scope.hold_data.user ).then(function(u) {
416 $scope.barcode = u.card().barcode();
417 $scope.user_name = egUser.format_name(u);
418 $scope.hold_data.user = u.id();
421 $scope.user_name = '';
423 $scope.$watch('barcode', function (n) {
424 if (!$scope.first_user_fetch) {
425 egUser.getByBarcode(n).then(function(u) {
427 $scope.user_name = egUser.format_name(u);
428 $scope.hold_data.user = u.id();
431 $scope.user_name = '';
432 delete $scope.hold_data.user;
435 $scope.first_user_fetch = false;
438 $scope.ok = function(h) {
441 hold_type : h.hold_type,
442 pickup_lib: h.pickup_lib.id(),
448 'open-ils.circ.holds.test_and_create.batch.override',
449 egCore.auth.token(), args, h.copy_list
452 $uibModalInstance.close();
455 $scope.cancel = function($event) {
456 $uibModalInstance.dismiss();
457 $event.preventDefault();
463 service.attach_to_peer_bib = function(items) {
464 if (items.length == 0) return;
466 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
467 if (!target_record) return;
469 return $uibModal.open({
470 templateUrl: './cat/catalog/t_conjoined_selector',
473 ['$scope','$uibModalInstance',
474 function($scope , $uibModalInstance) {
475 $scope.update = false;
477 $scope.peer_type = null;
478 $scope.peer_type_list = [];
480 get_peer_types = function() {
482 return $q.when(egCore.env.bpt.list);
484 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
485 .then(function(list) {
486 egCore.env.absorbList(list, 'bpt');
491 get_peer_types().then(function(list){
492 $scope.peer_type_list = list;
495 $scope.ok = function(type) {
498 angular.forEach(items, function (cp) {
499 var n = new egCore.idl.bpbcm();
501 n.peer_record(target_record);
502 n.target_copy(cp.id);
504 promises.push(egCore.pcrud.create(n).then(function(){service.add_barcode_to_list(cp.barcode)}));
507 return $q.all(promises).then(function(){$uibModalInstance.close()});
510 $scope.cancel = function($event) {
511 $uibModalInstance.dismiss();
512 $event.preventDefault();
519 service.selectedHoldingsCopyDelete = function (items) {
520 if (items.length == 0) return;
522 var copy_objects = [];
523 egCore.pcrud.search('acp',
524 {deleted : 'f', id : items.map(function(el){return el.id;}) },
525 { flesh : 1, flesh_fields : { acp : ['call_number'] } }
526 ).then(function(copy) {
527 copy_objects.push(copy);
531 var perCnCopies = {};
541 var cn_id = cp.call_number().id();
542 if (!cnHash[cn_id]) {
543 cnHash[cn_id] = cp.call_number();
544 perCnCopies[cn_id] = [cp];
546 perCnCopies[cn_id].push(cp);
548 cp.call_number(cn_id); // prevent loops in JSON-ification
552 angular.forEach(perCnCopies, function (v, k) {
557 angular.forEach(cnHash, function (v, k) {
561 if (cnList.length == 0) return;
565 egConfirmDialog.open(
566 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
567 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
568 {copies : cp_count, volumes : cn_count}
569 ).result.then(function() {
572 'open-ils.cat.asset.volume.fleshed.batch.update.override',
573 egCore.auth.token(), cnList, 1, flags
575 angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
581 service.checkin = function (items) {
582 angular.forEach(items, function (cp) {
583 egCirc.checkin({copy_barcode:cp.barcode}).then(
584 function() { service.add_barcode_to_list(cp.barcode) }
589 service.renew = function (items) {
590 angular.forEach(items, function (cp) {
591 egCirc.renew({copy_barcode:cp.barcode}).then(
592 function() { service.add_barcode_to_list(cp.barcode) }
597 service.cancel_transit = function (items) {
598 angular.forEach(items, function(cp) {
599 egCirc.find_copy_transit(null, {copy_barcode:cp.barcode})
600 .then(function(t) { return egCirc.abort_transit(t.id()) })
601 .then(function() { return service.add_barcode_to_list(cp.barcode) });
605 service.selectedHoldingsDamaged = function (items) {
606 egCirc.mark_damaged(items.map(function(el){return el.id;})).then(function(){
607 angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
611 service.selectedHoldingsMissing = function (items) {
612 egCirc.mark_missing(items.map(function(el){return el.id;})).then(function(){
613 angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
617 service.gatherSelectedRecordIds = function (items) {
622 if (rid_list.indexOf(item['call_number.record.id']) == -1)
623 rid_list.push(item['call_number.record.id'])
629 service.gatherSelectedVolumeIds = function (items,rid) {
634 if (rid && item['call_number.record.id'] != rid) return;
635 if (cn_id_list.indexOf(item['call_number.id']) == -1)
636 cn_id_list.push(item['call_number.id'])
642 service.gatherSelectedHoldingsIds = function (items,rid) {
647 if (rid && item['call_number.record.id'] != rid) return;
648 cp_id_list.push(item.id)
654 service.spawnHoldingsAdd = function (items,use_vols,use_copies){
655 angular.forEach(service.gatherSelectedRecordIds(items), function (r) {
657 if (use_copies) { // just a copy on existing volumes
658 angular.forEach(service.gatherSelectedVolumeIds(items,r), function (v) {
659 raw.push( {callnumber : v} );
661 } else if (use_vols) {
663 service.gatherSelectedHoldingsIds(items,r),
665 angular.forEach(items, function(item) {
666 if (i == item.id) raw.push({owner : item['call_number.owning_lib']});
672 if (raw.length == 0) raw.push({});
676 'open-ils.actor.anon_cache.set_value',
677 null, 'edit-these-copies', {
683 ).then(function(key) {
685 var url = egCore.env.basePath + 'cat/volcopy/' + key;
686 $timeout(function() { $window.open(url, '_blank') });
688 alert('Could not create anonymous cache key!');
694 service.spawnHoldingsEdit = function (items,hide_vols,hide_copies){
695 angular.forEach(service.gatherSelectedRecordIds(items), function (r) {
698 'open-ils.actor.anon_cache.set_value',
699 null, 'edit-these-copies', {
701 copies: service.gatherSelectedHoldingsIds(items,r),
703 hide_vols : hide_vols,
704 hide_copies : hide_copies
706 ).then(function(key) {
708 var url = egCore.env.basePath + 'cat/volcopy/' + key;
709 $timeout(function() { $window.open(url, '_blank') });
711 alert('Could not create anonymous cache key!');
717 service.replaceBarcodes = function(items) {
718 angular.forEach(items, function (cp) {
720 templateUrl: './cat/share/t_replace_barcode',
723 ['$scope','$uibModalInstance',
724 function($scope , $uibModalInstance) {
725 $scope.isModal = true;
726 $scope.focusBarcode = false;
727 $scope.focusBarcode2 = true;
728 $scope.barcode1 = cp.barcode;
730 $scope.updateBarcode = function() {
731 $scope.copyNotFound = false;
732 $scope.updateOK = false;
734 egCore.pcrud.search('acp',
735 {deleted : 'f', barcode : $scope.barcode1})
736 .then(function(copy) {
739 $scope.focusBarcode = true;
740 $scope.copyNotFound = true;
744 $scope.copyId = copy.id();
745 copy.barcode($scope.barcode2);
747 egCore.pcrud.update(copy).then(function(stat) {
748 $scope.updateOK = stat;
749 $scope.focusBarcode = true;
750 if (stat) service.add_barcode_to_list(copy.barcode());
754 $uibModalInstance.close();
757 $scope.cancel = function($event) {
758 $uibModalInstance.dismiss();
759 $event.preventDefault();
767 // this "transfers" selected copies to a new owning library,
768 // auto-creating volumes and deleting unused volumes as required.
769 service.changeItemOwningLib = function(items) {
770 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
771 if (!xfer_target || !items.length) {
774 var vols_to_move = {};
775 var copies_to_move = {};
776 angular.forEach(items, function(item) {
777 if (item['call_number.owning_lib'] != xfer_target) {
778 if (item['call_number.id'] in vols_to_move) {
779 copies_to_move[item['call_number.id']].push(item.id);
781 vols_to_move[item['call_number.id']] = {
782 label : item['call_number.label'],
783 label_class : item['call_number.label_class'],
784 record : item['call_number.record.id'],
785 prefix : item['call_number.prefix.id'],
786 suffix : item['call_number.suffix.id']
788 copies_to_move[item['call_number.id']] = new Array;
789 copies_to_move[item['call_number.id']].push(item.id);
795 angular.forEach(vols_to_move, function(vol) {
796 promises.push(egCore.net.request(
798 'open-ils.cat.call_number.find_or_create',
806 ).then(function(resp) {
807 var evt = egCore.evt.parse(resp);
809 return egCore.net.request(
811 'open-ils.cat.transfer_copies_to_volume',
814 copies_to_move[vol.id]
823 function(){ service.add_barcode_to_list(cp.barcode) }
830 service.transferItems = function (items){
831 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
832 var copy_ids = service.gatherSelectedHoldingsIds(items);
833 if (xfer_target && copy_ids.length > 0) {
836 'open-ils.cat.transfer_copies_to_volume',
841 function(resp) { // oncomplete
842 var evt = egCore.evt.parse(resp);
843 console.log('evt',evt);
845 egConfirmDialog.open(
846 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
847 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
849 ).result.then(function() {
852 'open-ils.cat.transfer_copies_to_volume.override',
856 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
859 angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
862 angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
876 * Search bar along the top of the page.
877 * Parent scope for list and detail views
879 .controller('SearchCtrl',
880 ['$scope','$location','$timeout','egCore','egGridDataProvider','itemSvc',
881 function($scope , $location , $timeout , egCore , egGridDataProvider , itemSvc) {
882 $scope.args = {}; // search args
884 // sub-scopes (search / detail-view) apply their version
885 // of retrieval function to $scope.context.search
886 // and display toggling via $scope.context.toggleDisplay
891 $scope.toggleView = function($event) {
892 $scope.context.toggleDisplay();
893 $event.preventDefault(); // avoid form submission
896 // The functions that follow in this controller are never called
897 // when the List View is active, only the Detail View.
899 // In this context, we're only ever dealing with 1 item, so
900 // we can simply refresh the page. These various itemSvc
901 // functions used to live in the ListCtrl, but they're now
902 // shared between SearchCtrl (for Actions for the Detail View)
903 // and ListCtrl (Actions in the egGrid)
904 itemSvc.add_barcode_to_list = function(b) {
905 //console.log('SearchCtrl: add_barcode_to_list',b);
906 // timeout so audible can happen upon checkin
907 $timeout(function() { location.href = location.href; }, 1000);
910 $scope.add_copies_to_bucket = function() {
911 itemSvc.add_copies_to_bucket([$scope.args.copyId]);
914 $scope.make_copies_bookable = function() {
915 itemSvc.make_copies_bookable([{
916 id : $scope.args.copyId,
917 'call_number.record.id' : $scope.args.recordId
921 $scope.book_copies_now = function() {
922 itemSvc.book_copies_now([{
923 id : $scope.args.copyId,
924 'call_number.record.id' : $scope.args.recordId
928 $scope.requestItems = function() {
929 itemSvc.requestItems([$scope.args.copyId]);
932 $scope.attach_to_peer_bib = function() {
933 itemSvc.attach_to_peer_bib([{
934 id : $scope.args.copyId,
935 barcode : $scope.args.copyBarcode
939 $scope.selectedHoldingsCopyDelete = function () {
940 itemSvc.selectedHoldingsCopyDelete([{
941 id : $scope.args.copyId,
942 barcode : $scope.args.copyBarcode
946 $scope.checkin = function () {
948 id : $scope.args.copyId,
949 barcode : $scope.args.copyBarcode
953 $scope.renew = function () {
955 id : $scope.args.copyId,
956 barcode : $scope.args.copyBarcode
960 $scope.cancel_transit = function () {
961 itemSvc.cancel_transit([{
962 id : $scope.args.copyId,
963 barcode : $scope.args.copyBarcode
967 $scope.selectedHoldingsDamaged = function () {
968 itemSvc.selectedHoldingsDamaged([{
969 id : $scope.args.copyId,
970 barcode : $scope.args.copyBarcode
974 $scope.selectedHoldingsMissing = function () {
975 itemSvc.selectedHoldingsMissing([{
976 id : $scope.args.copyId,
977 barcode : $scope.args.copyBarcode
981 $scope.selectedHoldingsVolCopyAdd = function () {
982 itemSvc.spawnHoldingsAdd([{
983 id : $scope.args.copyId,
984 'call_number.owning_lib' : $scope.args.cnOwningLib,
985 'call_number.record.id' : $scope.args.recordId,
986 barcode : $scope.args.copyBarcode
989 $scope.selectedHoldingsCopyAdd = function () {
990 itemSvc.spawnHoldingsAdd([{
991 id : $scope.args.copyId,
992 'call_number.id' : $scope.args.cnId,
993 'call_number.owning_lib' : $scope.args.cnOwningLib,
994 'call_number.record.id' : $scope.args.recordId,
995 barcode : $scope.args.copyBarcode
999 $scope.selectedHoldingsVolCopyEdit = function () {
1000 itemSvc.spawnHoldingsEdit([{
1001 id : $scope.args.copyId,
1002 'call_number.id' : $scope.args.cnId,
1003 'call_number.owning_lib' : $scope.args.cnOwningLib,
1004 'call_number.record.id' : $scope.args.recordId,
1005 barcode : $scope.args.copyBarcode
1008 $scope.selectedHoldingsVolEdit = function () {
1009 itemSvc.spawnHoldingsEdit([{
1010 id : $scope.args.copyId,
1011 'call_number.id' : $scope.args.cnId,
1012 'call_number.owning_lib' : $scope.args.cnOwningLib,
1013 'call_number.record.id' : $scope.args.recordId,
1014 barcode : $scope.args.copyBarcode
1017 $scope.selectedHoldingsCopyEdit = function () {
1018 itemSvc.spawnHoldingsEdit([{
1019 id : $scope.args.copyId,
1020 'call_number.id' : $scope.args.cnId,
1021 'call_number.owning_lib' : $scope.args.cnOwningLib,
1022 'call_number.record.id' : $scope.args.recordId,
1023 barcode : $scope.args.copyBarcode
1027 $scope.replaceBarcodes = function() {
1028 itemSvc.replaceBarcodes([{
1029 id : $scope.args.copyId,
1030 barcode : $scope.args.copyBarcode
1034 $scope.changeItemOwningLib = function() {
1035 itemSvc.changeItemOwningLib([{
1036 id : $scope.args.copyId,
1037 'call_number.id' : $scope.args.cnId,
1038 'call_number.owning_lib' : $scope.args.cnOwningLib,
1039 'call_number.record.id' : $scope.args.recordId,
1040 'call_number.label' : $scope.args.cnLabel,
1041 'call_number.label_class' : $scope.args.cnLabelClass,
1042 'call_number.prefix.id' : $scope.args.cnPrefixId,
1043 'call_number.suffix.id' : $scope.args.cnSuffixId,
1044 barcode : $scope.args.copyBarcode
1048 $scope.transferItems = function (){
1049 itemSvc.transferItems([{
1050 id : $scope.args.copyId,
1051 barcode : $scope.args.copyBarcode
1058 * List view - grid stuff
1060 .controller('ListCtrl',
1061 ['$scope','$q','$routeParams','$location','$timeout','$window','egCore','egGridDataProvider','itemSvc','egUser','$uibModal','egCirc','egConfirmDialog',
1062 function($scope , $q , $routeParams , $location , $timeout , $window , egCore , egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog) {
1064 var cp_list = $routeParams.idList;
1066 copyId = cp_list.split(',');
1069 $scope.context.page = 'list';
1072 var provider = egGridDataProvider.instance();
1073 provider.get = function(offset, count) {
1077 $scope.gridDataProvider = egGridDataProvider.instance({
1078 get : function(offset, count) {
1079 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1080 return this.arrayNotifier(itemSvc.copies, offset, count);
1084 // If a copy was just displayed in the detail view, ensure it's
1085 // focused in the list view.
1086 var selected = false;
1087 var copyGrid = $scope.gridControls = {
1088 itemRetrieved : function(item) {
1089 if (selected || !itemSvc.copy) return;
1090 if (itemSvc.copy.id() == item.id) {
1091 copyGrid.selectItems([item.index]);
1097 $scope.$watch('barcodesFromFile', function(newVal, oldVal) {
1098 if (newVal && newVal != oldVal) {
1099 $scope.args.barcode = '';
1102 angular.forEach(newVal.split(/\n/), function(line) {
1104 // scrub any trailing spaces or commas from the barcode
1105 line = line.replace(/(.*?)($|\s.*|,.*)/,'$1');
1106 barcodes.push(line);
1109 itemSvc.fetch(barcodes).then(
1112 copyGrid.selectItems([itemSvc.copies[0].index]);
1118 $scope.context.search = function(args) {
1119 if (!args.barcode) return;
1120 $scope.context.itemNotFound = false;
1121 itemSvc.fetch(args.barcode).then(function(res) {
1124 copyGrid.selectItems([res.index]);
1125 $scope.args.barcode = '';
1127 $scope.context.itemNotFound = true;
1128 egCore.audio.play('warning.item_status.itemNotFound');
1130 $scope.context.selectBarcode = true;
1134 var add_barcode_to_list = function (b) {
1135 //console.log('listCtrl: add_barcode_to_list',b);
1136 $scope.context.search({barcode:b});
1138 itemSvc.add_barcode_to_list = add_barcode_to_list;
1140 $scope.context.toggleDisplay = function() {
1141 var item = copyGrid.selectedItems()[0];
1143 $location.path('/cat/item/' + item.id);
1146 $scope.context.show_triggered_events = function() {
1147 var item = copyGrid.selectedItems()[0];
1149 $location.path('/cat/item/' + item.id + '/triggered_events');
1152 function gatherSelectedRecordIds () {
1155 copyGrid.selectedItems(),
1157 if (rid_list.indexOf(item['call_number.record.id']) == -1)
1158 rid_list.push(item['call_number.record.id'])
1164 function gatherSelectedVolumeIds (rid) {
1165 var cn_id_list = [];
1167 copyGrid.selectedItems(),
1169 if (rid && item['call_number.record.id'] != rid) return;
1170 if (cn_id_list.indexOf(item['call_number.id']) == -1)
1171 cn_id_list.push(item['call_number.id'])
1177 function gatherSelectedHoldingsIds (rid) {
1178 var cp_id_list = [];
1180 copyGrid.selectedItems(),
1182 if (rid && item['call_number.record.id'] != rid) return;
1183 cp_id_list.push(item.id)
1189 $scope.add_copies_to_bucket = function() {
1190 var copy_list = gatherSelectedHoldingsIds();
1191 itemSvc.add_copies_to_bucket(copy_list);
1194 $scope.need_one_selected = function() {
1195 var items = $scope.gridControls.selectedItems();
1196 if (items.length == 1) return false;
1200 $scope.make_copies_bookable = function() {
1201 itemSvc.make_copies_bookable(copyGrid.selectedItems());
1204 $scope.book_copies_now = function() {
1205 itemSvc.book_copies_now(copyGrid.selectedItems());
1208 $scope.requestItems = function() {
1209 var copy_list = gatherSelectedHoldingsIds();
1210 itemSvc.requestItems(copy_list);
1213 $scope.replaceBarcodes = function() {
1214 itemSvc.replaceBarcodes(copyGrid.selectedItems());
1217 $scope.attach_to_peer_bib = function() {
1218 itemSvc.attach_to_peer_bib(copyGrid.selectedItems());
1221 $scope.selectedHoldingsCopyDelete = function () {
1222 itemSvc.selectedHoldingsCopyDelete(copyGrid.selectedItems());
1225 $scope.selectedHoldingsItemStatusTgrEvt= function() {
1226 var item = copyGrid.selectedItems()[0];
1228 $location.path('/cat/item/' + item.id + '/triggered_events');
1231 $scope.selectedHoldingsItemStatusHolds= function() {
1232 var item = copyGrid.selectedItems()[0];
1234 $location.path('/cat/item/' + item.id + '/holds');
1237 $scope.cancel_transit = function () {
1238 itemSvc.cancel_transit(copyGrid.selectedItems());
1241 $scope.selectedHoldingsDamaged = function () {
1242 itemSvc.selectedHoldingsDamaged(copyGrid.selectedItems());
1245 $scope.selectedHoldingsMissing = function () {
1246 itemSvc.selectedHoldingsMissing(copyGrid.selectedItems());
1249 $scope.checkin = function () {
1250 itemSvc.checkin(copyGrid.selectedItems());
1253 $scope.renew = function () {
1254 itemSvc.renew(copyGrid.selectedItems());
1257 $scope.selectedHoldingsVolCopyAdd = function () {
1258 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),true,false);
1260 $scope.selectedHoldingsCopyAdd = function () {
1261 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),false,true);
1264 $scope.showBibHolds = function () {
1265 angular.forEach(gatherSelectedRecordIds(), function (r) {
1266 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
1267 $timeout(function() { $window.open(url, '_blank') });
1271 $scope.selectedHoldingsVolCopyEdit = function () {
1272 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,false);
1274 $scope.selectedHoldingsVolEdit = function () {
1275 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,true);
1277 $scope.selectedHoldingsCopyEdit = function () {
1278 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),true,false);
1281 $scope.changeItemOwningLib = function() {
1282 itemSvc.changeItemOwningLib(copyGrid.selectedItems());
1285 $scope.transferItems = function (){
1286 itemSvc.transferItems(copyGrid.selectedItems());
1289 $scope.print_list = function() {
1290 var print_data = { copies : copyGrid.allItems() };
1292 if (print_data.copies.length == 0) return $q.when();
1294 return egCore.print.print({
1295 template : 'item_status',
1300 if (copyId.length > 0) {
1301 itemSvc.fetch(null,copyId).then(
1311 * Detail view -- shows one copy
1313 .controller('ViewCtrl',
1314 ['$scope','$q','$location','$routeParams','$timeout','$window','egCore','itemSvc','egBilling',
1315 function($scope , $q , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling) {
1316 var copyId = $routeParams.id;
1317 $scope.args.copyId = copyId;
1318 $scope.tab = $routeParams.tab || 'summary';
1319 $scope.context.page = 'detail';
1320 $scope.summaryRecord = null;
1322 $scope.edit = false;
1323 if ($scope.tab == 'edit') {
1324 $scope.tab = 'summary';
1329 // use the cached record info
1331 $scope.recordId = itemSvc.copy.call_number().record().id();
1332 $scope.args.recordId = $scope.recordId;
1333 $scope.args.cnId = itemSvc.copy.call_number().id();
1334 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
1335 $scope.args.cnLabel = itemSvc.copy.call_number().label();
1336 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
1337 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
1338 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
1339 $scope.args.copyBarcode = itemSvc.copy.barcode();
1342 function loadCopy(barcode) {
1343 $scope.context.itemNotFound = false;
1345 // Avoid re-fetching the same copy while jumping tabs.
1346 // In addition to being quicker, this helps to avoid flickering
1347 // of the top panel which is always visible in the detail view.
1349 // 'barcode' represents the loading of a new item - refetch it
1350 // regardless of whether it matches the current item.
1351 if (!barcode && itemSvc.copy && itemSvc.copy.id() == copyId) {
1352 $scope.copy = itemSvc.copy;
1353 $scope.recordId = itemSvc.copy.call_number().record().id();
1354 $scope.args.recordId = $scope.recordId;
1355 $scope.args.cnId = itemSvc.copy.call_number().id();
1356 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
1357 $scope.args.cnLabel = itemSvc.copy.call_number().label();
1358 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
1359 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
1360 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
1361 $scope.args.copyBarcode = itemSvc.copy.barcode();
1366 delete itemSvc.copy;
1368 var deferred = $q.defer();
1369 itemSvc.fetch(barcode, copyId, true).then(function(res) {
1370 $scope.context.selectBarcode = true;
1374 $scope.context.itemNotFound = true;
1375 egCore.audio.play('warning.item_status.itemNotFound');
1376 deferred.reject(); // avoid propagation of data fetch calls
1380 var copy = res.copy;
1381 itemSvc.copy = copy;
1385 $scope.recordId = copy.call_number().record().id();
1386 $scope.args.recordId = $scope.recordId;
1387 $scope.args.cnId = itemSvc.copy.call_number().id();
1388 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
1389 $scope.args.cnLabel = itemSvc.copy.call_number().label();
1390 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
1391 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
1392 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
1393 $scope.args.copyBarcode = copy.barcode();
1394 $scope.args.barcode = '';
1396 // locally flesh org units
1397 copy.circ_lib(egCore.org.get(copy.circ_lib()));
1398 copy.call_number().owning_lib(
1399 egCore.org.get(copy.call_number().owning_lib()));
1401 var r = copy.call_number().record();
1402 if (r.owner()) r.owner(egCore.org.get(r.owner()));
1404 // make boolean for auto-magic true/false display
1406 ['ref','opac_visible','holdable','circulate'],
1407 function(field) { copy[field](Boolean(copy[field]() == 't')) }
1410 // finally, if this is a different copy, redirect.
1411 // Note that we flesh first since the copy we just
1412 // fetched will be used after the redirect.
1413 if (copyId && copyId != copy.id()) {
1414 // if a new barcode is scanned in the detail view,
1415 // update the url to match the ID of the new copy
1416 $location.path('/cat/item/' + copy.id() + '/' + $scope.tab);
1417 deferred.reject(); // avoid propagation of data fetch calls
1425 return deferred.promise;
1428 // if loadPrev load the two most recent circulations
1429 function loadCurrentCirc(loadPrev) {
1431 delete $scope.circ_summary;
1432 delete $scope.prev_circ_summary;
1433 delete $scope.prev_circ_usr;
1434 if (!copyId) return;
1436 egCore.pcrud.search('circ',
1437 {target_copy : copyId},
1443 'checkin_workstation',
1446 'recurring_fine_rule'
1450 order_by : {circ : 'xact_start desc'},
1454 ).then(null, null, function(circ) {
1457 // load the chain for this circ
1460 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
1461 egCore.auth.token(), $scope.circ.id()
1462 ).then(function(summary) {
1463 $scope.circ_summary = summary.summary;
1466 if (!loadPrev) return;
1468 // load the chain for the previous circ, plus the user
1471 'open-ils.circ.prev_renewal_chain.retrieve_by_circ.summary',
1472 egCore.auth.token(), $scope.circ.id()
1474 ).then(null, null, function(summary) {
1475 $scope.prev_circ_summary = summary.summary;
1477 if (summary.usr) { // aged circs have no 'usr'.
1478 egCore.pcrud.retrieve('au', summary.usr,
1479 {flesh : 1, flesh_fields : {au : ['card']}})
1481 .then(function(user) { $scope.prev_circ_usr = user });
1488 function fetchMaxCircHistory() {
1489 if (maxHistory) return $q.when(maxHistory);
1490 return egCore.org.settings(
1491 'circ.item_checkout_history.max')
1492 .then(function(set) {
1493 maxHistory = set['circ.item_checkout_history.max'] || 4;
1498 $scope.addBilling = function(circ) {
1499 egBilling.showBillDialog({
1500 xact_id : circ.id(),
1505 $scope.retrieveAllPatrons = function() {
1506 var users = new Set();
1507 angular.forEach($scope.circ_list.map(function(circ) { return circ.usr(); }),function(usr) {
1508 // aged circs have no 'usr'.
1509 if (usr) users.add(usr);
1511 users.forEach(function(usr) {
1512 $timeout(function() {
1513 var url = $location.absUrl().replace(
1515 '/circ/patron/' + usr.id() + '/checkout');
1516 $window.open(url, '_blank')
1521 function loadCircHistory() {
1522 $scope.circ_list = [];
1525 itemSvc.copy.call_number().id() == -1 ?
1526 itemSvc.copy.circ_lib().id() :
1527 itemSvc.copy.call_number().owning_lib().id()
1529 // there is an extra layer of permissibility over circ
1531 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
1532 .then(function(orgIds) {
1534 if (orgIds.indexOf(copy_org) == -1) {
1535 console.log('User is not allowed to view circ history');
1539 return fetchMaxCircHistory();
1541 }).then(function(count) {
1543 egCore.pcrud.search('combcirc',
1544 {target_copy : copyId},
1550 'checkin_workstation',
1551 'recurring_fine_rule'
1555 order_by : {combcirc : 'xact_start desc'},
1559 ).then(null, null, function(circ) {
1561 // flesh circ_lib locally
1562 circ.circ_lib(egCore.org.get(circ.circ_lib()));
1563 circ.checkin_lib(egCore.org.get(circ.checkin_lib()));
1564 $scope.circ_list.push(circ);
1570 function loadCircCounts() {
1572 delete $scope.circ_counts;
1573 $scope.total_circs = 0;
1574 $scope.total_circs_this_year = 0;
1575 $scope.total_circs_prev_year = 0;
1576 if (!copyId) return;
1578 egCore.pcrud.search('circbyyr',
1579 {copy : copyId}, null, {atomic : true})
1581 .then(function(counts) {
1582 $scope.circ_counts = counts;
1584 angular.forEach(counts, function(count) {
1585 $scope.total_circs += Number(count.count());
1588 var this_year = counts.filter(function(c) {
1589 return c.year() == new Date().getFullYear();
1592 $scope.total_circs_this_year =
1593 this_year.length ? this_year[0].count() : 0;
1595 var prev_year = counts.filter(function(c) {
1596 return c.year() == new Date().getFullYear() - 1;
1599 $scope.total_circs_prev_year =
1600 prev_year.length ? prev_year[0].count() : 0;
1605 function loadHolds() {
1607 if (!copyId) return;
1609 egCore.pcrud.search('ahr',
1610 { current_copy : copyId,
1612 fulfillment_time : null,
1613 capture_time : {'<>' : null}
1617 ahr : ['requestor', 'usr'],
1621 ).then(null, null, function(hold) {
1623 hold.pickup_lib(egCore.org.get(hold.pickup_lib()));
1624 if (hold.current_shelf_lib()) {
1625 hold.current_shelf_lib(
1626 egCore.org.get(hold.current_shelf_lib()));
1628 hold.behind_desk(Boolean(hold.behind_desk() == 't'));
1632 function loadTransits() {
1633 delete $scope.transit;
1634 delete $scope.hold_transit;
1635 if (!copyId) return;
1637 egCore.pcrud.search('atc',
1638 {target_copy : copyId},
1639 {order_by : {atc : 'source_send_time DESC'}}
1641 ).then(null, null, function(transit) {
1642 $scope.transit = transit;
1643 transit.source(egCore.org.get(transit.source()));
1644 transit.dest(egCore.org.get(transit.dest()));
1649 // we don't need all data on all tabs, so fetch what's needed when needed.
1650 function loadTabData() {
1651 switch($scope.tab) {
1658 loadCurrentCirc(true);
1670 case 'triggered_events':
1671 var url = $location.absUrl().replace(/\/staff.*/, '/actor/user/event_log');
1672 url += '?copy_id=' + encodeURIComponent(copyId);
1673 $scope.triggered_events_url = url;
1680 'open-ils.actor.anon_cache.set_value',
1681 null, 'edit-these-copies', {
1682 record_id: $scope.recordId,
1687 ).then(function(key) {
1689 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1690 $window.location.href = url;
1692 alert('Could not create anonymous cache key!');
1700 $scope.context.toggleDisplay = function() {
1701 $location.path('/cat/item/search');
1704 // handle the barcode scan box, which will replace our current copy
1705 $scope.context.search = function(args) {
1706 loadCopy(args.barcode).then(loadTabData);
1709 $scope.context.show_triggered_events = function() {
1710 $location.path('/cat/item/' + copyId + '/triggered_events');
1713 loadCopy().then(loadTabData);