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, aacs, and accs information
93 service.getCopy = function(barcode, id) {
95 // handle barcode completion
96 return egCirc.handle_barcode_completion(barcode)
97 .then(function(actual_barcode) {
98 return egCore.pcrud.search(
99 'acp', {barcode : actual_barcode, deleted : 'f'},
100 service.flesh).then(function(copy) {return copy});
104 return egCore.pcrud.retrieve( 'acp', id, service.flesh)
105 .then(function(copy) {return copy});
107 service.getCirc = function(id) {
108 return egCore.pcrud.search('aacs', { target_copy : id },
109 service.circFlesh).then(function(circ) {return circ});
111 service.getSummary = function(id) {
112 return circ_summary = egCore.net.request(
114 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
115 egCore.auth.token(), id).then(
116 function(circ_summary) {return circ_summary});
119 //Combine copy, circ, and accs information
120 service.retrieveCopyData = function(barcode, id) {
123 var fetchCopy = function(barcode, id) {
124 return service.getCopy(barcode, id)
125 .then(function(copy) {
126 copyData.copy = copy;
130 var fetchCirc = function(copy) {
131 return service.getCirc(copy.id())
132 .then(function(circ) {
133 copyData.circ = circ;
137 var fetchSummary = function(circ) {
138 return service.getSummary(circ.id())
139 .then(function(summary) {
140 copyData.circ_summary = summary;
144 return fetchCopy(barcode, id).then(function(res) {
145 return fetchCirc(copyData.copy).then(function(res) {
147 return fetchSummary(copyData.circ).then(function() {
158 // resolved with the last received copy
159 service.fetch = function(barcode, id, noListDupes) {
165 return service.retrieveCopyData(barcode, id)
166 .then(function(copyData) {
167 //Make sure we're getting a completed copyData - no plain acp or circ objects
169 // flesh circ_lib locally
170 copyData.circ.circ_lib(egCore.org.get(copyData.circ.circ_lib()));
171 copyData.circ.checkin_workstation(
172 egCore.org.get(copyData.circ.checkin_workstation()));
177 // use the existing copy if possible
178 flatCopy = service.copies.filter(
179 function(c) {return c.id == copyData.copy.id()})[0];
183 flatCopy = egCore.idl.toHash(copyData.copy, true);
186 flatCopy._circ = egCore.idl.toHash(copyData.circ, true);
187 flatCopy._circ_summary = egCore.idl.toHash(copyData.circ_summary, true);
188 flatCopy._circ_lib = copyData.circ.circ_lib();
189 flatCopy._duration = copyData.circ.duration();
191 flatCopy.index = service.index++;
192 service.copies.unshift(flatCopy);
195 //Get in-house use count
196 egCore.pcrud.search('aihu',
197 {item : flatCopy.id}, {}, {idlist : true, atomic : true})
198 .then(function(uses) {
199 flatCopy._inHouseUseCount = uses.length;
200 copyData.copy._inHouseUseCount = uses.length;
204 copy : copyData.copy,
205 index : flatCopy.index
212 service.add_copies_to_bucket = function(copy_list) {
213 if (copy_list.length == 0) return;
215 return $uibModal.open({
216 templateUrl: './cat/catalog/t_add_to_bucket',
220 ['$scope','$uibModalInstance',
221 function($scope , $uibModalInstance) {
223 $scope.bucket_id = 0;
224 $scope.newBucketName = '';
225 $scope.allBuckets = [];
229 'open-ils.actor.container.retrieve_by_class.authoritative',
230 egCore.auth.token(), egCore.auth.user().id(),
231 'copy', 'staff_client'
232 ).then(function(buckets) { $scope.allBuckets = buckets; });
234 $scope.add_to_bucket = function() {
236 angular.forEach(copy_list, function (cp) {
237 var item = new egCore.idl.ccbi()
238 item.bucket($scope.bucket_id);
239 item.target_copy(cp);
243 'open-ils.actor.container.item.create',
244 egCore.auth.token(), 'copy', item
248 return $q.all(promises).then(function() {
249 $uibModalInstance.close();
254 $scope.add_to_new_bucket = function() {
255 var bucket = new egCore.idl.ccb();
256 bucket.owner(egCore.auth.user().id());
257 bucket.name($scope.newBucketName);
258 bucket.description('');
259 bucket.btype('staff_client');
261 return egCore.net.request(
263 'open-ils.actor.container.create',
264 egCore.auth.token(), 'copy', bucket
265 ).then(function(bucket) {
266 $scope.bucket_id = bucket;
267 $scope.add_to_bucket();
271 $scope.cancel = function() {
272 $uibModalInstance.dismiss();
278 service.make_copies_bookable = function(items) {
280 var copies_by_record = {};
281 var record_list = [];
285 var record_id = item['call_number.record.id'];
286 if (typeof copies_by_record[ record_id ] == 'undefined') {
287 copies_by_record[ record_id ] = [];
288 record_list.push( record_id );
290 copies_by_record[ record_id ].push(item.id);
295 var combined_results = [];
296 angular.forEach(record_list, function(record_id) {
300 'open-ils.booking.resources.create_from_copies',
302 copies_by_record[record_id]
303 ).then(function(results) {
304 if (results && results['brsrc']) {
305 combined_results = combined_results.concat(results['brsrc']);
311 $q.all(promises).then(function() {
312 if (combined_results.length > 0) {
314 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
318 ['$scope','$location','egCore','$uibModalInstance',
319 function($scope , $location , egCore , $uibModalInstance) {
322 ses : egCore.auth.token(),
323 resultant_brsrc : combined_results.map(function(o) { return o[0]; })
326 var booking_path = '/eg/conify/global/booking/resource';
328 $scope.booking_admin_url =
329 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
336 service.book_copies_now = function(items) {
337 var copies_by_record = {};
338 var record_list = [];
342 var record_id = item['call_number.record.id'];
343 if (typeof copies_by_record[ record_id ] == 'undefined') {
344 copies_by_record[ record_id ] = [];
345 record_list.push( record_id );
347 copies_by_record[ record_id ].push(item.id);
352 var combined_brt = [];
353 var combined_brsrc = [];
354 angular.forEach(record_list, function(record_id) {
358 'open-ils.booking.resources.create_from_copies',
360 copies_by_record[record_id]
361 ).then(function(results) {
362 if (results && results['brt']) {
363 combined_brt = combined_brt.concat(results['brt']);
365 if (results && results['brsrc']) {
366 combined_brsrc = combined_brsrc.concat(results['brsrc']);
372 $q.all(promises).then(function() {
373 if (combined_brt.length > 0 || combined_brsrc.length > 0) {
375 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
379 ['$scope','$location','egCore','$uibModalInstance',
380 function($scope , $location , egCore , $uibModalInstance) {
383 ses : egCore.auth.token(),
384 bresv_interface_opts : {
387 ,brsrc : combined_brsrc
392 var booking_path = '/eg/booking/reservation';
394 $scope.booking_admin_url =
395 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
403 service.requestItems = function(copy_list) {
404 if (copy_list.length == 0) return;
406 return $uibModal.open({
407 templateUrl: './cat/catalog/t_request_items',
410 ['$scope','$uibModalInstance','egUser',
411 function($scope , $uibModalInstance , egUser) {
413 $scope.first_user_fetch = true;
417 copy_list : copy_list,
418 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
419 user : egCore.auth.user().id()
422 egUser.get( $scope.hold_data.user ).then(function(u) {
424 $scope.barcode = u.card().barcode();
425 $scope.user_name = egUser.format_name(u);
426 $scope.hold_data.user = u.id();
429 $scope.user_name = '';
431 $scope.$watch('barcode', function (n) {
432 if (!$scope.first_user_fetch) {
433 egUser.getByBarcode(n).then(function(u) {
435 $scope.user_name = egUser.format_name(u);
436 $scope.hold_data.user = u.id();
439 $scope.user_name = '';
440 delete $scope.hold_data.user;
443 $scope.first_user_fetch = false;
446 $scope.ok = function(h) {
449 hold_type : h.hold_type,
450 pickup_lib: h.pickup_lib.id(),
456 'open-ils.circ.holds.test_and_create.batch.override',
457 egCore.auth.token(), args, h.copy_list
460 $uibModalInstance.close();
463 $scope.cancel = function($event) {
464 $uibModalInstance.dismiss();
465 $event.preventDefault();
471 service.attach_to_peer_bib = function(items) {
472 if (items.length == 0) return;
474 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
475 if (!target_record) return;
477 return $uibModal.open({
478 templateUrl: './cat/catalog/t_conjoined_selector',
481 ['$scope','$uibModalInstance',
482 function($scope , $uibModalInstance) {
483 $scope.update = false;
485 $scope.peer_type = null;
486 $scope.peer_type_list = [];
488 get_peer_types = function() {
490 return $q.when(egCore.env.bpt.list);
492 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
493 .then(function(list) {
494 egCore.env.absorbList(list, 'bpt');
499 get_peer_types().then(function(list){
500 $scope.peer_type_list = list;
503 $scope.ok = function(type) {
506 angular.forEach(items, function (cp) {
507 var n = new egCore.idl.bpbcm();
509 n.peer_record(target_record);
510 n.target_copy(cp.id);
512 promises.push(egCore.pcrud.create(n).then(function(){service.add_barcode_to_list(cp.barcode)}));
515 return $q.all(promises).then(function(){$uibModalInstance.close()});
518 $scope.cancel = function($event) {
519 $uibModalInstance.dismiss();
520 $event.preventDefault();
527 service.selectedHoldingsCopyDelete = function (items) {
528 if (items.length == 0) return;
530 var copy_objects = [];
531 egCore.pcrud.search('acp',
532 {deleted : 'f', id : items.map(function(el){return el.id;}) },
533 { flesh : 1, flesh_fields : { acp : ['call_number'] } }
534 ).then(function(copy) {
535 copy_objects.push(copy);
539 var perCnCopies = {};
549 var cn_id = cp.call_number().id();
550 if (!cnHash[cn_id]) {
551 cnHash[cn_id] = cp.call_number();
552 perCnCopies[cn_id] = [cp];
554 perCnCopies[cn_id].push(cp);
556 cp.call_number(cn_id); // prevent loops in JSON-ification
560 angular.forEach(perCnCopies, function (v, k) {
565 angular.forEach(cnHash, function (v, k) {
569 if (cnList.length == 0) return;
573 egConfirmDialog.open(
574 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
575 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
576 {copies : cp_count, volumes : cn_count}
577 ).result.then(function() {
580 'open-ils.cat.asset.volume.fleshed.batch.update.override',
581 egCore.auth.token(), cnList, 1, flags
583 angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
589 service.checkin = function (items) {
590 angular.forEach(items, function (cp) {
591 egCirc.checkin({copy_barcode:cp.barcode}).then(
592 function() { service.add_barcode_to_list(cp.barcode) }
597 service.renew = function (items) {
598 angular.forEach(items, function (cp) {
599 egCirc.renew({copy_barcode:cp.barcode}).then(
600 function() { service.add_barcode_to_list(cp.barcode) }
605 service.cancel_transit = function (items) {
606 angular.forEach(items, function(cp) {
607 egCirc.find_copy_transit(null, {copy_barcode:cp.barcode})
608 .then(function(t) { return egCirc.abort_transit(t.id()) })
609 .then(function() { return service.add_barcode_to_list(cp.barcode) });
613 service.selectedHoldingsDamaged = function (items) {
614 egCirc.mark_damaged(items.map(function(el){return el.id;})).then(function(){
615 angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
619 service.selectedHoldingsMissing = function (items) {
620 egCirc.mark_missing(items.map(function(el){return el.id;})).then(function(){
621 angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
625 service.gatherSelectedRecordIds = function (items) {
630 if (rid_list.indexOf(item['call_number.record.id']) == -1)
631 rid_list.push(item['call_number.record.id'])
637 service.gatherSelectedVolumeIds = function (items,rid) {
642 if (rid && item['call_number.record.id'] != rid) return;
643 if (cn_id_list.indexOf(item['call_number.id']) == -1)
644 cn_id_list.push(item['call_number.id'])
650 service.gatherSelectedHoldingsIds = function (items,rid) {
655 if (rid && item['call_number.record.id'] != rid) return;
656 cp_id_list.push(item.id)
662 service.spawnHoldingsAdd = function (items,use_vols,use_copies){
663 angular.forEach(service.gatherSelectedRecordIds(items), function (r) {
665 if (use_copies) { // just a copy on existing volumes
666 angular.forEach(service.gatherSelectedVolumeIds(items,r), function (v) {
667 raw.push( {callnumber : v} );
669 } else if (use_vols) {
671 service.gatherSelectedHoldingsIds(items,r),
673 angular.forEach(items, function(item) {
674 if (i == item.id) raw.push({owner : item['call_number.owning_lib']});
680 if (raw.length == 0) raw.push({});
684 'open-ils.actor.anon_cache.set_value',
685 null, 'edit-these-copies', {
691 ).then(function(key) {
693 var url = egCore.env.basePath + 'cat/volcopy/' + key;
694 $timeout(function() { $window.open(url, '_blank') });
696 alert('Could not create anonymous cache key!');
702 service.spawnHoldingsEdit = function (items,hide_vols,hide_copies){
703 angular.forEach(service.gatherSelectedRecordIds(items), function (r) {
706 'open-ils.actor.anon_cache.set_value',
707 null, 'edit-these-copies', {
709 copies: service.gatherSelectedHoldingsIds(items,r),
711 hide_vols : hide_vols,
712 hide_copies : hide_copies
714 ).then(function(key) {
716 var url = egCore.env.basePath + 'cat/volcopy/' + key;
717 $timeout(function() { $window.open(url, '_blank') });
719 alert('Could not create anonymous cache key!');
725 service.replaceBarcodes = function(items) {
726 angular.forEach(items, function (cp) {
728 templateUrl: './cat/share/t_replace_barcode',
731 ['$scope','$uibModalInstance',
732 function($scope , $uibModalInstance) {
733 $scope.isModal = true;
734 $scope.focusBarcode = false;
735 $scope.focusBarcode2 = true;
736 $scope.barcode1 = cp.barcode;
738 $scope.updateBarcode = function() {
739 $scope.copyNotFound = false;
740 $scope.updateOK = false;
742 egCore.pcrud.search('acp',
743 {deleted : 'f', barcode : $scope.barcode1})
744 .then(function(copy) {
747 $scope.focusBarcode = true;
748 $scope.copyNotFound = true;
752 $scope.copyId = copy.id();
753 copy.barcode($scope.barcode2);
755 egCore.pcrud.update(copy).then(function(stat) {
756 $scope.updateOK = stat;
757 $scope.focusBarcode = true;
758 if (stat) service.add_barcode_to_list(copy.barcode());
762 $uibModalInstance.close();
765 $scope.cancel = function($event) {
766 $uibModalInstance.dismiss();
767 $event.preventDefault();
775 // this "transfers" selected copies to a new owning library,
776 // auto-creating volumes and deleting unused volumes as required.
777 service.changeItemOwningLib = function(items) {
778 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
779 if (!xfer_target || !items.length) {
782 var vols_to_move = {};
783 var copies_to_move = {};
784 angular.forEach(items, function(item) {
785 if (item['call_number.owning_lib'] != xfer_target) {
786 if (item['call_number.id'] in vols_to_move) {
787 copies_to_move[item['call_number.id']].push(item.id);
789 vols_to_move[item['call_number.id']] = {
790 label : item['call_number.label'],
791 label_class : item['call_number.label_class'],
792 record : item['call_number.record.id'],
793 prefix : item['call_number.prefix.id'],
794 suffix : item['call_number.suffix.id']
796 copies_to_move[item['call_number.id']] = new Array;
797 copies_to_move[item['call_number.id']].push(item.id);
803 angular.forEach(vols_to_move, function(vol) {
804 promises.push(egCore.net.request(
806 'open-ils.cat.call_number.find_or_create',
814 ).then(function(resp) {
815 var evt = egCore.evt.parse(resp);
817 return egCore.net.request(
819 'open-ils.cat.transfer_copies_to_volume',
822 copies_to_move[vol.id]
831 function(){ service.add_barcode_to_list(cp.barcode) }
838 service.transferItems = function (items){
839 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
840 var copy_ids = service.gatherSelectedHoldingsIds(items);
841 if (xfer_target && copy_ids.length > 0) {
844 'open-ils.cat.transfer_copies_to_volume',
849 function(resp) { // oncomplete
850 var evt = egCore.evt.parse(resp);
852 egConfirmDialog.open(
853 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
854 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
856 ).result.then(function() {
859 'open-ils.cat.transfer_copies_to_volume.override',
863 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
866 angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
869 angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
883 * Search bar along the top of the page.
884 * Parent scope for list and detail views
886 .controller('SearchCtrl',
887 ['$scope','$location','$timeout','egCore','egGridDataProvider','itemSvc',
888 function($scope , $location , $timeout , egCore , egGridDataProvider , itemSvc) {
889 $scope.args = {}; // search args
891 // sub-scopes (search / detail-view) apply their version
892 // of retrieval function to $scope.context.search
893 // and display toggling via $scope.context.toggleDisplay
898 $scope.toggleView = function($event) {
899 $scope.context.toggleDisplay();
900 $event.preventDefault(); // avoid form submission
903 // The functions that follow in this controller are never called
904 // when the List View is active, only the Detail View.
906 // In this context, we're only ever dealing with 1 item, so
907 // we can simply refresh the page. These various itemSvc
908 // functions used to live in the ListCtrl, but they're now
909 // shared between SearchCtrl (for Actions for the Detail View)
910 // and ListCtrl (Actions in the egGrid)
911 itemSvc.add_barcode_to_list = function(b) {
912 //console.log('SearchCtrl: add_barcode_to_list',b);
913 // timeout so audible can happen upon checkin
914 $timeout(function() { location.href = location.href; }, 1000);
917 $scope.add_copies_to_bucket = function() {
918 itemSvc.add_copies_to_bucket([$scope.args.copyId]);
921 $scope.make_copies_bookable = function() {
922 itemSvc.make_copies_bookable([{
923 id : $scope.args.copyId,
924 'call_number.record.id' : $scope.args.recordId
928 $scope.book_copies_now = function() {
929 itemSvc.book_copies_now([{
930 id : $scope.args.copyId,
931 'call_number.record.id' : $scope.args.recordId
935 $scope.requestItems = function() {
936 itemSvc.requestItems([$scope.args.copyId]);
939 $scope.attach_to_peer_bib = function() {
940 itemSvc.attach_to_peer_bib([{
941 id : $scope.args.copyId,
942 barcode : $scope.args.copyBarcode
946 $scope.selectedHoldingsCopyDelete = function () {
947 itemSvc.selectedHoldingsCopyDelete([{
948 id : $scope.args.copyId,
949 barcode : $scope.args.copyBarcode
953 $scope.checkin = function () {
955 id : $scope.args.copyId,
956 barcode : $scope.args.copyBarcode
960 $scope.renew = function () {
962 id : $scope.args.copyId,
963 barcode : $scope.args.copyBarcode
967 $scope.cancel_transit = function () {
968 itemSvc.cancel_transit([{
969 id : $scope.args.copyId,
970 barcode : $scope.args.copyBarcode
974 $scope.selectedHoldingsDamaged = function () {
975 itemSvc.selectedHoldingsDamaged([{
976 id : $scope.args.copyId,
977 barcode : $scope.args.copyBarcode
981 $scope.selectedHoldingsMissing = function () {
982 itemSvc.selectedHoldingsMissing([{
983 id : $scope.args.copyId,
984 barcode : $scope.args.copyBarcode
988 $scope.selectedHoldingsVolCopyAdd = function () {
989 itemSvc.spawnHoldingsAdd([{
990 id : $scope.args.copyId,
991 'call_number.owning_lib' : $scope.args.cnOwningLib,
992 'call_number.record.id' : $scope.args.recordId,
993 barcode : $scope.args.copyBarcode
996 $scope.selectedHoldingsCopyAdd = function () {
997 itemSvc.spawnHoldingsAdd([{
998 id : $scope.args.copyId,
999 'call_number.id' : $scope.args.cnId,
1000 'call_number.owning_lib' : $scope.args.cnOwningLib,
1001 'call_number.record.id' : $scope.args.recordId,
1002 barcode : $scope.args.copyBarcode
1006 $scope.selectedHoldingsVolCopyEdit = function () {
1007 itemSvc.spawnHoldingsEdit([{
1008 id : $scope.args.copyId,
1009 'call_number.id' : $scope.args.cnId,
1010 'call_number.owning_lib' : $scope.args.cnOwningLib,
1011 'call_number.record.id' : $scope.args.recordId,
1012 barcode : $scope.args.copyBarcode
1015 $scope.selectedHoldingsVolEdit = function () {
1016 itemSvc.spawnHoldingsEdit([{
1017 id : $scope.args.copyId,
1018 'call_number.id' : $scope.args.cnId,
1019 'call_number.owning_lib' : $scope.args.cnOwningLib,
1020 'call_number.record.id' : $scope.args.recordId,
1021 barcode : $scope.args.copyBarcode
1024 $scope.selectedHoldingsCopyEdit = function () {
1025 itemSvc.spawnHoldingsEdit([{
1026 id : $scope.args.copyId,
1027 'call_number.id' : $scope.args.cnId,
1028 'call_number.owning_lib' : $scope.args.cnOwningLib,
1029 'call_number.record.id' : $scope.args.recordId,
1030 barcode : $scope.args.copyBarcode
1034 $scope.replaceBarcodes = function() {
1035 itemSvc.replaceBarcodes([{
1036 id : $scope.args.copyId,
1037 barcode : $scope.args.copyBarcode
1041 $scope.changeItemOwningLib = function() {
1042 itemSvc.changeItemOwningLib([{
1043 id : $scope.args.copyId,
1044 'call_number.id' : $scope.args.cnId,
1045 'call_number.owning_lib' : $scope.args.cnOwningLib,
1046 'call_number.record.id' : $scope.args.recordId,
1047 'call_number.label' : $scope.args.cnLabel,
1048 'call_number.label_class' : $scope.args.cnLabelClass,
1049 'call_number.prefix.id' : $scope.args.cnPrefixId,
1050 'call_number.suffix.id' : $scope.args.cnSuffixId,
1051 barcode : $scope.args.copyBarcode
1055 $scope.transferItems = function (){
1056 itemSvc.transferItems([{
1057 id : $scope.args.copyId,
1058 barcode : $scope.args.copyBarcode
1065 * List view - grid stuff
1067 .controller('ListCtrl',
1068 ['$scope','$q','$routeParams','$location','$timeout','$window','egCore','egGridDataProvider','itemSvc','egUser','$uibModal','egCirc','egConfirmDialog',
1069 function($scope , $q , $routeParams , $location , $timeout , $window , egCore , egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog) {
1071 var cp_list = $routeParams.idList;
1073 copyId = cp_list.split(',');
1076 $scope.context.page = 'list';
1079 var provider = egGridDataProvider.instance();
1080 provider.get = function(offset, count) {
1084 $scope.gridDataProvider = egGridDataProvider.instance({
1085 get : function(offset, count) {
1086 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1087 return this.arrayNotifier(itemSvc.copies, offset, count);
1091 // If a copy was just displayed in the detail view, ensure it's
1092 // focused in the list view.
1093 var selected = false;
1094 var copyGrid = $scope.gridControls = {
1095 itemRetrieved : function(item) {
1096 if (selected || !itemSvc.copy) return;
1097 if (itemSvc.copy.id() == item.id) {
1098 copyGrid.selectItems([item.index]);
1104 $scope.$watch('barcodesFromFile', function(newVal, oldVal) {
1105 if (newVal && newVal != oldVal) {
1106 $scope.args.barcode = '';
1109 angular.forEach(newVal.split(/\n/), function(line) {
1111 // scrub any trailing spaces or commas from the barcode
1112 line = line.replace(/(.*?)($|\s.*|,.*)/,'$1');
1113 barcodes.push(line);
1116 if (barcodes.length > 0) {
1118 angular.forEach(barcodes, function (b) {
1119 promises.push(itemSvc.fetch(b));
1122 $q.all(promises).then(
1125 copyGrid.selectItems([itemSvc.copies[0].index]);
1132 $scope.context.search = function(args) {
1133 if (!args.barcode) return;
1134 $scope.context.itemNotFound = false;
1135 itemSvc.fetch(args.barcode).then(function(res) {
1138 copyGrid.selectItems([res.index]);
1139 $scope.args.barcode = '';
1141 $scope.context.itemNotFound = true;
1142 egCore.audio.play('warning.item_status.itemNotFound');
1144 $scope.context.selectBarcode = true;
1148 var add_barcode_to_list = function (b) {
1149 //console.log('listCtrl: add_barcode_to_list',b);
1150 $scope.context.search({barcode:b});
1152 itemSvc.add_barcode_to_list = add_barcode_to_list;
1154 $scope.context.toggleDisplay = function() {
1155 var item = copyGrid.selectedItems()[0];
1157 $location.path('/cat/item/' + item.id);
1160 $scope.context.show_triggered_events = function() {
1161 var item = copyGrid.selectedItems()[0];
1163 $location.path('/cat/item/' + item.id + '/triggered_events');
1166 function gatherSelectedRecordIds () {
1169 copyGrid.selectedItems(),
1171 if (rid_list.indexOf(item['call_number.record.id']) == -1)
1172 rid_list.push(item['call_number.record.id'])
1178 function gatherSelectedVolumeIds (rid) {
1179 var cn_id_list = [];
1181 copyGrid.selectedItems(),
1183 if (rid && item['call_number.record.id'] != rid) return;
1184 if (cn_id_list.indexOf(item['call_number.id']) == -1)
1185 cn_id_list.push(item['call_number.id'])
1191 function gatherSelectedHoldingsIds (rid) {
1192 var cp_id_list = [];
1194 copyGrid.selectedItems(),
1196 if (rid && item['call_number.record.id'] != rid) return;
1197 cp_id_list.push(item.id)
1203 $scope.add_copies_to_bucket = function() {
1204 var copy_list = gatherSelectedHoldingsIds();
1205 itemSvc.add_copies_to_bucket(copy_list);
1208 $scope.need_one_selected = function() {
1209 var items = $scope.gridControls.selectedItems();
1210 if (items.length == 1) return false;
1214 $scope.make_copies_bookable = function() {
1215 itemSvc.make_copies_bookable(copyGrid.selectedItems());
1218 $scope.book_copies_now = function() {
1219 itemSvc.book_copies_now(copyGrid.selectedItems());
1222 $scope.requestItems = function() {
1223 var copy_list = gatherSelectedHoldingsIds();
1224 itemSvc.requestItems(copy_list);
1227 $scope.replaceBarcodes = function() {
1228 itemSvc.replaceBarcodes(copyGrid.selectedItems());
1231 $scope.attach_to_peer_bib = function() {
1232 itemSvc.attach_to_peer_bib(copyGrid.selectedItems());
1235 $scope.selectedHoldingsCopyDelete = function () {
1236 itemSvc.selectedHoldingsCopyDelete(copyGrid.selectedItems());
1239 $scope.selectedHoldingsItemStatusTgrEvt= function() {
1240 var item = copyGrid.selectedItems()[0];
1242 $location.path('/cat/item/' + item.id + '/triggered_events');
1245 $scope.selectedHoldingsItemStatusHolds= function() {
1246 var item = copyGrid.selectedItems()[0];
1248 $location.path('/cat/item/' + item.id + '/holds');
1251 $scope.cancel_transit = function () {
1252 itemSvc.cancel_transit(copyGrid.selectedItems());
1255 $scope.selectedHoldingsDamaged = function () {
1256 itemSvc.selectedHoldingsDamaged(copyGrid.selectedItems());
1259 $scope.selectedHoldingsMissing = function () {
1260 itemSvc.selectedHoldingsMissing(copyGrid.selectedItems());
1263 $scope.checkin = function () {
1264 itemSvc.checkin(copyGrid.selectedItems());
1267 $scope.renew = function () {
1268 itemSvc.renew(copyGrid.selectedItems());
1271 $scope.selectedHoldingsVolCopyAdd = function () {
1272 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),true,false);
1274 $scope.selectedHoldingsCopyAdd = function () {
1275 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),false,true);
1278 $scope.showBibHolds = function () {
1279 angular.forEach(gatherSelectedRecordIds(), function (r) {
1280 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
1281 $timeout(function() { $window.open(url, '_blank') });
1285 $scope.selectedHoldingsVolCopyEdit = function () {
1286 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,false);
1288 $scope.selectedHoldingsVolEdit = function () {
1289 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,true);
1291 $scope.selectedHoldingsCopyEdit = function () {
1292 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),true,false);
1295 $scope.changeItemOwningLib = function() {
1296 itemSvc.changeItemOwningLib(copyGrid.selectedItems());
1299 $scope.transferItems = function (){
1300 itemSvc.transferItems(copyGrid.selectedItems());
1303 $scope.print_labels = function() {
1306 'open-ils.actor.anon_cache.set_value',
1307 null, 'print-labels-these-copies', {
1308 copies : gatherSelectedHoldingsIds()
1310 ).then(function(key) {
1312 var url = egCore.env.basePath + 'cat/printlabels/' + key;
1313 $timeout(function() { $window.open(url, '_blank') });
1315 alert('Could not create anonymous cache key!');
1320 $scope.print_list = function() {
1321 var print_data = { copies : copyGrid.allItems() };
1323 if (print_data.copies.length == 0) return $q.when();
1325 return egCore.print.print({
1326 template : 'item_status',
1331 if (copyId.length > 0) {
1332 itemSvc.fetch(null,copyId).then(
1342 * Detail view -- shows one copy
1344 .controller('ViewCtrl',
1345 ['$scope','$q','$location','$routeParams','$timeout','$window','egCore','itemSvc','egBilling',
1346 function($scope , $q , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling) {
1347 var copyId = $routeParams.id;
1348 $scope.args.copyId = copyId;
1349 $scope.tab = $routeParams.tab || 'summary';
1350 $scope.context.page = 'detail';
1351 $scope.summaryRecord = null;
1353 $scope.edit = false;
1354 if ($scope.tab == 'edit') {
1355 $scope.tab = 'summary';
1360 // use the cached record info
1362 $scope.recordId = itemSvc.copy.call_number().record().id();
1363 $scope.args.recordId = $scope.recordId;
1364 $scope.args.cnId = itemSvc.copy.call_number().id();
1365 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
1366 $scope.args.cnLabel = itemSvc.copy.call_number().label();
1367 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
1368 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
1369 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
1370 $scope.args.copyBarcode = itemSvc.copy.barcode();
1373 function loadCopy(barcode) {
1374 $scope.context.itemNotFound = false;
1376 // Avoid re-fetching the same copy while jumping tabs.
1377 // In addition to being quicker, this helps to avoid flickering
1378 // of the top panel which is always visible in the detail view.
1380 // 'barcode' represents the loading of a new item - refetch it
1381 // regardless of whether it matches the current item.
1382 if (!barcode && itemSvc.copy && itemSvc.copy.id() == copyId) {
1383 $scope.copy = itemSvc.copy;
1384 $scope.recordId = itemSvc.copy.call_number().record().id();
1385 $scope.args.recordId = $scope.recordId;
1386 $scope.args.cnId = itemSvc.copy.call_number().id();
1387 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
1388 $scope.args.cnLabel = itemSvc.copy.call_number().label();
1389 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
1390 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
1391 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
1392 $scope.args.copyBarcode = itemSvc.copy.barcode();
1397 delete itemSvc.copy;
1399 var deferred = $q.defer();
1400 itemSvc.fetch(barcode, copyId, true).then(function(res) {
1401 $scope.context.selectBarcode = true;
1405 $scope.context.itemNotFound = true;
1406 egCore.audio.play('warning.item_status.itemNotFound');
1407 deferred.reject(); // avoid propagation of data fetch calls
1411 var copy = res.copy;
1412 itemSvc.copy = copy;
1416 $scope.recordId = copy.call_number().record().id();
1417 $scope.args.recordId = $scope.recordId;
1418 $scope.args.cnId = itemSvc.copy.call_number().id();
1419 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
1420 $scope.args.cnLabel = itemSvc.copy.call_number().label();
1421 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
1422 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
1423 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
1424 $scope.args.copyBarcode = copy.barcode();
1425 $scope.args.barcode = '';
1427 // locally flesh org units
1428 copy.circ_lib(egCore.org.get(copy.circ_lib()));
1429 copy.call_number().owning_lib(
1430 egCore.org.get(copy.call_number().owning_lib()));
1432 var r = copy.call_number().record();
1433 if (r.owner()) r.owner(egCore.org.get(r.owner()));
1435 // make boolean for auto-magic true/false display
1437 ['ref','opac_visible','holdable','circulate'],
1438 function(field) { copy[field](Boolean(copy[field]() == 't')) }
1441 // finally, if this is a different copy, redirect.
1442 // Note that we flesh first since the copy we just
1443 // fetched will be used after the redirect.
1444 if (copyId && copyId != copy.id()) {
1445 // if a new barcode is scanned in the detail view,
1446 // update the url to match the ID of the new copy
1447 $location.path('/cat/item/' + copy.id() + '/' + $scope.tab);
1448 deferred.reject(); // avoid propagation of data fetch calls
1456 return deferred.promise;
1459 // if loadPrev load the two most recent circulations
1460 function loadCurrentCirc(loadPrev) {
1462 delete $scope.circ_summary;
1463 delete $scope.prev_circ_summary;
1464 delete $scope.prev_circ_usr;
1465 if (!copyId) return;
1467 egCore.pcrud.search('aacs',
1468 {target_copy : copyId},
1474 'checkin_workstation',
1477 'recurring_fine_rule'
1481 order_by : {aacs : 'xact_start desc'},
1485 ).then(null, null, function(circ) {
1488 // load the chain for this circ
1491 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
1492 egCore.auth.token(), $scope.circ.id()
1493 ).then(function(summary) {
1494 $scope.circ_summary = summary;
1497 if (!loadPrev) return;
1499 // load the chain for the previous circ, plus the user
1502 'open-ils.circ.prev_renewal_chain.retrieve_by_circ.summary',
1503 egCore.auth.token(), $scope.circ.id()
1505 ).then(null, null, function(summary) {
1506 $scope.prev_circ_summary = summary.summary;
1508 if (summary.usr) { // aged circs have no 'usr'.
1509 egCore.pcrud.retrieve('au', summary.usr,
1510 {flesh : 1, flesh_fields : {au : ['card']}})
1512 .then(function(user) { $scope.prev_circ_usr = user });
1519 function fetchMaxCircHistory() {
1520 if (maxHistory) return $q.when(maxHistory);
1521 return egCore.org.settings(
1522 'circ.item_checkout_history.max')
1523 .then(function(set) {
1524 maxHistory = set['circ.item_checkout_history.max'] || 4;
1529 $scope.addBilling = function(circ) {
1530 egBilling.showBillDialog({
1531 xact_id : circ.id(),
1536 $scope.retrieveAllPatrons = function() {
1537 var users = new Set();
1538 angular.forEach($scope.circ_list.map(function(circ) { return circ.usr(); }),function(usr) {
1539 // aged circs have no 'usr'.
1540 if (usr) users.add(usr);
1542 users.forEach(function(usr) {
1543 $timeout(function() {
1544 var url = $location.absUrl().replace(
1546 '/circ/patron/' + usr.id() + '/checkout');
1547 $window.open(url, '_blank')
1552 function loadCircHistory() {
1553 $scope.circ_list = [];
1556 itemSvc.copy.call_number().id() == -1 ?
1557 itemSvc.copy.circ_lib().id() :
1558 itemSvc.copy.call_number().owning_lib().id()
1560 // there is an extra layer of permissibility over circ
1562 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
1563 .then(function(orgIds) {
1565 if (orgIds.indexOf(copy_org) == -1) {
1566 console.log('User is not allowed to view circ history');
1570 return fetchMaxCircHistory();
1572 }).then(function(count) {
1574 egCore.pcrud.search('aacs',
1575 {target_copy : copyId},
1581 'checkin_workstation',
1582 'recurring_fine_rule'
1586 order_by : {aacs : 'xact_start desc'},
1590 ).then(null, null, function(circ) {
1592 // flesh circ_lib locally
1593 circ.circ_lib(egCore.org.get(circ.circ_lib()));
1594 circ.checkin_lib(egCore.org.get(circ.checkin_lib()));
1595 $scope.circ_list.push(circ);
1601 function loadCircCounts() {
1603 delete $scope.circ_counts;
1604 $scope.total_circs = 0;
1605 $scope.total_circs_this_year = 0;
1606 $scope.total_circs_prev_year = 0;
1607 if (!copyId) return;
1609 egCore.pcrud.search('circbyyr',
1610 {copy : copyId}, null, {atomic : true})
1612 .then(function(counts) {
1613 $scope.circ_counts = counts;
1615 angular.forEach(counts, function(count) {
1616 $scope.total_circs += Number(count.count());
1619 var this_year = counts.filter(function(c) {
1620 return c.year() == new Date().getFullYear();
1623 $scope.total_circs_this_year =
1624 this_year.length ? this_year[0].count() : 0;
1626 var prev_year = counts.filter(function(c) {
1627 return c.year() == new Date().getFullYear() - 1;
1630 $scope.total_circs_prev_year =
1631 prev_year.length ? prev_year[0].count() : 0;
1636 function loadHolds() {
1638 if (!copyId) return;
1640 egCore.pcrud.search('ahr',
1641 { current_copy : copyId,
1643 fulfillment_time : null,
1644 capture_time : {'<>' : null}
1648 ahr : ['requestor', 'usr'],
1652 ).then(null, null, function(hold) {
1654 hold.pickup_lib(egCore.org.get(hold.pickup_lib()));
1655 if (hold.current_shelf_lib()) {
1656 hold.current_shelf_lib(
1657 egCore.org.get(hold.current_shelf_lib()));
1659 hold.behind_desk(Boolean(hold.behind_desk() == 't'));
1663 function loadTransits() {
1664 delete $scope.transit;
1665 delete $scope.hold_transit;
1666 if (!copyId) return;
1668 egCore.pcrud.search('atc',
1669 {target_copy : copyId},
1670 {order_by : {atc : 'source_send_time DESC'}}
1672 ).then(null, null, function(transit) {
1673 $scope.transit = transit;
1674 transit.source(egCore.org.get(transit.source()));
1675 transit.dest(egCore.org.get(transit.dest()));
1680 // we don't need all data on all tabs, so fetch what's needed when needed.
1681 function loadTabData() {
1682 switch($scope.tab) {
1689 loadCurrentCirc(true);
1701 case 'triggered_events':
1702 var url = $location.absUrl().replace(/\/staff.*/, '/actor/user/event_log');
1703 url += '?copy_id=' + encodeURIComponent(copyId);
1704 $scope.triggered_events_url = url;
1711 'open-ils.actor.anon_cache.set_value',
1712 null, 'edit-these-copies', {
1713 record_id: $scope.recordId,
1718 ).then(function(key) {
1720 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1721 $window.location.href = url;
1723 alert('Could not create anonymous cache key!');
1731 $scope.context.toggleDisplay = function() {
1732 $location.path('/cat/item/search');
1735 // handle the barcode scan box, which will replace our current copy
1736 $scope.context.search = function(args) {
1737 loadCopy(args.barcode).then(loadTabData);
1740 $scope.context.show_triggered_events = function() {
1741 $location.path('/cat/item/' + copyId + '/triggered_events');
1744 loadCopy().then(loadTabData);