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) {
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('aacs', { 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);
182 flatCopy._circ_lib = copyData.circ.circ_lib();
183 flatCopy._duration = copyData.circ.duration();
185 flatCopy.index = service.index++;
186 service.copies.unshift(flatCopy);
189 //Get in-house use count
190 egCore.pcrud.search('aihu',
191 {item : flatCopy.id}, {}, {idlist : true, atomic : true})
192 .then(function(uses) {
193 flatCopy._inHouseUseCount = uses.length;
194 copyData.copy._inHouseUseCount = uses.length;
198 copy : copyData.copy,
199 index : flatCopy.index
206 service.add_copies_to_bucket = function(copy_list) {
207 if (copy_list.length == 0) return;
209 return $uibModal.open({
210 templateUrl: './cat/catalog/t_add_to_bucket',
214 ['$scope','$uibModalInstance',
215 function($scope , $uibModalInstance) {
217 $scope.bucket_id = 0;
218 $scope.newBucketName = '';
219 $scope.allBuckets = [];
223 'open-ils.actor.container.retrieve_by_class.authoritative',
224 egCore.auth.token(), egCore.auth.user().id(),
225 'copy', 'staff_client'
226 ).then(function(buckets) { $scope.allBuckets = buckets; });
228 $scope.add_to_bucket = function() {
230 angular.forEach(copy_list, function (cp) {
231 var item = new egCore.idl.ccbi()
232 item.bucket($scope.bucket_id);
233 item.target_copy(cp);
237 'open-ils.actor.container.item.create',
238 egCore.auth.token(), 'copy', item
242 return $q.all(promises).then(function() {
243 $uibModalInstance.close();
248 $scope.add_to_new_bucket = function() {
249 var bucket = new egCore.idl.ccb();
250 bucket.owner(egCore.auth.user().id());
251 bucket.name($scope.newBucketName);
252 bucket.description('');
253 bucket.btype('staff_client');
255 return egCore.net.request(
257 'open-ils.actor.container.create',
258 egCore.auth.token(), 'copy', bucket
259 ).then(function(bucket) {
260 $scope.bucket_id = bucket;
261 $scope.add_to_bucket();
265 $scope.cancel = function() {
266 $uibModalInstance.dismiss();
272 service.make_copies_bookable = function(items) {
274 var copies_by_record = {};
275 var record_list = [];
279 var record_id = item['call_number.record.id'];
280 if (typeof copies_by_record[ record_id ] == 'undefined') {
281 copies_by_record[ record_id ] = [];
282 record_list.push( record_id );
284 copies_by_record[ record_id ].push(item.id);
289 var combined_results = [];
290 angular.forEach(record_list, function(record_id) {
294 'open-ils.booking.resources.create_from_copies',
296 copies_by_record[record_id]
297 ).then(function(results) {
298 if (results && results['brsrc']) {
299 combined_results = combined_results.concat(results['brsrc']);
305 $q.all(promises).then(function() {
306 if (combined_results.length > 0) {
308 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
312 ['$scope','$location','egCore','$uibModalInstance',
313 function($scope , $location , egCore , $uibModalInstance) {
316 ses : egCore.auth.token(),
317 resultant_brsrc : combined_results.map(function(o) { return o[0]; })
320 var booking_path = '/eg/conify/global/booking/resource';
322 $scope.booking_admin_url =
323 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
330 service.book_copies_now = function(items) {
331 var copies_by_record = {};
332 var record_list = [];
336 var record_id = item['call_number.record.id'];
337 if (typeof copies_by_record[ record_id ] == 'undefined') {
338 copies_by_record[ record_id ] = [];
339 record_list.push( record_id );
341 copies_by_record[ record_id ].push(item.id);
346 var combined_brt = [];
347 var combined_brsrc = [];
348 angular.forEach(record_list, function(record_id) {
352 'open-ils.booking.resources.create_from_copies',
354 copies_by_record[record_id]
355 ).then(function(results) {
356 if (results && results['brt']) {
357 combined_brt = combined_brt.concat(results['brt']);
359 if (results && results['brsrc']) {
360 combined_brsrc = combined_brsrc.concat(results['brsrc']);
366 $q.all(promises).then(function() {
367 if (combined_brt.length > 0 || combined_brsrc.length > 0) {
369 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
373 ['$scope','$location','egCore','$uibModalInstance',
374 function($scope , $location , egCore , $uibModalInstance) {
377 ses : egCore.auth.token(),
378 bresv_interface_opts : {
381 ,brsrc : combined_brsrc
386 var booking_path = '/eg/booking/reservation';
388 $scope.booking_admin_url =
389 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
397 service.requestItems = function(copy_list) {
398 if (copy_list.length == 0) return;
400 return $uibModal.open({
401 templateUrl: './cat/catalog/t_request_items',
404 ['$scope','$uibModalInstance','egUser',
405 function($scope , $uibModalInstance , egUser) {
407 $scope.first_user_fetch = true;
411 copy_list : copy_list,
412 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
413 user : egCore.auth.user().id()
416 egUser.get( $scope.hold_data.user ).then(function(u) {
418 $scope.barcode = u.card().barcode();
419 $scope.user_name = egUser.format_name(u);
420 $scope.hold_data.user = u.id();
423 $scope.user_name = '';
425 $scope.$watch('barcode', function (n) {
426 if (!$scope.first_user_fetch) {
427 egUser.getByBarcode(n).then(function(u) {
429 $scope.user_name = egUser.format_name(u);
430 $scope.hold_data.user = u.id();
433 $scope.user_name = '';
434 delete $scope.hold_data.user;
437 $scope.first_user_fetch = false;
440 $scope.ok = function(h) {
443 hold_type : h.hold_type,
444 pickup_lib: h.pickup_lib.id(),
450 'open-ils.circ.holds.test_and_create.batch.override',
451 egCore.auth.token(), args, h.copy_list
454 $uibModalInstance.close();
457 $scope.cancel = function($event) {
458 $uibModalInstance.dismiss();
459 $event.preventDefault();
465 service.attach_to_peer_bib = function(items) {
466 if (items.length == 0) return;
468 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
469 if (!target_record) return;
471 return $uibModal.open({
472 templateUrl: './cat/catalog/t_conjoined_selector',
475 ['$scope','$uibModalInstance',
476 function($scope , $uibModalInstance) {
477 $scope.update = false;
479 $scope.peer_type = null;
480 $scope.peer_type_list = [];
482 get_peer_types = function() {
484 return $q.when(egCore.env.bpt.list);
486 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
487 .then(function(list) {
488 egCore.env.absorbList(list, 'bpt');
493 get_peer_types().then(function(list){
494 $scope.peer_type_list = list;
497 $scope.ok = function(type) {
500 angular.forEach(items, function (cp) {
501 var n = new egCore.idl.bpbcm();
503 n.peer_record(target_record);
504 n.target_copy(cp.id);
506 promises.push(egCore.pcrud.create(n).then(function(){service.add_barcode_to_list(cp.barcode)}));
509 return $q.all(promises).then(function(){$uibModalInstance.close()});
512 $scope.cancel = function($event) {
513 $uibModalInstance.dismiss();
514 $event.preventDefault();
521 service.selectedHoldingsCopyDelete = function (items) {
522 if (items.length == 0) return;
524 var copy_objects = [];
525 egCore.pcrud.search('acp',
526 {deleted : 'f', id : items.map(function(el){return el.id;}) },
527 { flesh : 1, flesh_fields : { acp : ['call_number'] } }
528 ).then(function(copy) {
529 copy_objects.push(copy);
533 var perCnCopies = {};
543 var cn_id = cp.call_number().id();
544 if (!cnHash[cn_id]) {
545 cnHash[cn_id] = cp.call_number();
546 perCnCopies[cn_id] = [cp];
548 perCnCopies[cn_id].push(cp);
550 cp.call_number(cn_id); // prevent loops in JSON-ification
554 angular.forEach(perCnCopies, function (v, k) {
559 angular.forEach(cnHash, function (v, k) {
563 if (cnList.length == 0) return;
567 egConfirmDialog.open(
568 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
569 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
570 {copies : cp_count, volumes : cn_count}
571 ).result.then(function() {
574 'open-ils.cat.asset.volume.fleshed.batch.update.override',
575 egCore.auth.token(), cnList, 1, flags
577 angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
583 service.checkin = function (items) {
584 angular.forEach(items, function (cp) {
585 egCirc.checkin({copy_barcode:cp.barcode}).then(
586 function() { service.add_barcode_to_list(cp.barcode) }
591 service.renew = function (items) {
592 angular.forEach(items, function (cp) {
593 egCirc.renew({copy_barcode:cp.barcode}).then(
594 function() { service.add_barcode_to_list(cp.barcode) }
599 service.cancel_transit = function (items) {
600 angular.forEach(items, function(cp) {
601 egCirc.find_copy_transit(null, {copy_barcode:cp.barcode})
602 .then(function(t) { return egCirc.abort_transit(t.id()) })
603 .then(function() { return service.add_barcode_to_list(cp.barcode) });
607 service.selectedHoldingsDamaged = function (items) {
608 egCirc.mark_damaged(items.map(function(el){return el.id;})).then(function(){
609 angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
613 service.selectedHoldingsMissing = function (items) {
614 egCirc.mark_missing(items.map(function(el){return el.id;})).then(function(){
615 angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
619 service.gatherSelectedRecordIds = function (items) {
624 if (rid_list.indexOf(item['call_number.record.id']) == -1)
625 rid_list.push(item['call_number.record.id'])
631 service.gatherSelectedVolumeIds = function (items,rid) {
636 if (rid && item['call_number.record.id'] != rid) return;
637 if (cn_id_list.indexOf(item['call_number.id']) == -1)
638 cn_id_list.push(item['call_number.id'])
644 service.gatherSelectedHoldingsIds = function (items,rid) {
649 if (rid && item['call_number.record.id'] != rid) return;
650 cp_id_list.push(item.id)
656 service.spawnHoldingsAdd = function (items,use_vols,use_copies){
657 angular.forEach(service.gatherSelectedRecordIds(items), function (r) {
659 if (use_copies) { // just a copy on existing volumes
660 angular.forEach(service.gatherSelectedVolumeIds(items,r), function (v) {
661 raw.push( {callnumber : v} );
663 } else if (use_vols) {
665 service.gatherSelectedHoldingsIds(items,r),
667 angular.forEach(items, function(item) {
668 if (i == item.id) raw.push({owner : item['call_number.owning_lib']});
674 if (raw.length == 0) raw.push({});
678 'open-ils.actor.anon_cache.set_value',
679 null, 'edit-these-copies', {
685 ).then(function(key) {
687 var url = egCore.env.basePath + 'cat/volcopy/' + key;
688 $timeout(function() { $window.open(url, '_blank') });
690 alert('Could not create anonymous cache key!');
696 service.spawnHoldingsEdit = function (items,hide_vols,hide_copies){
697 angular.forEach(service.gatherSelectedRecordIds(items), function (r) {
700 'open-ils.actor.anon_cache.set_value',
701 null, 'edit-these-copies', {
703 copies: service.gatherSelectedHoldingsIds(items,r),
705 hide_vols : hide_vols,
706 hide_copies : hide_copies
708 ).then(function(key) {
710 var url = egCore.env.basePath + 'cat/volcopy/' + key;
711 $timeout(function() { $window.open(url, '_blank') });
713 alert('Could not create anonymous cache key!');
719 service.replaceBarcodes = function(items) {
720 angular.forEach(items, function (cp) {
722 templateUrl: './cat/share/t_replace_barcode',
725 ['$scope','$uibModalInstance',
726 function($scope , $uibModalInstance) {
727 $scope.isModal = true;
728 $scope.focusBarcode = false;
729 $scope.focusBarcode2 = true;
730 $scope.barcode1 = cp.barcode;
732 $scope.updateBarcode = function() {
733 $scope.copyNotFound = false;
734 $scope.updateOK = false;
736 egCore.pcrud.search('acp',
737 {deleted : 'f', barcode : $scope.barcode1})
738 .then(function(copy) {
741 $scope.focusBarcode = true;
742 $scope.copyNotFound = true;
746 $scope.copyId = copy.id();
747 copy.barcode($scope.barcode2);
749 egCore.pcrud.update(copy).then(function(stat) {
750 $scope.updateOK = stat;
751 $scope.focusBarcode = true;
752 if (stat) service.add_barcode_to_list(copy.barcode());
756 $uibModalInstance.close();
759 $scope.cancel = function($event) {
760 $uibModalInstance.dismiss();
761 $event.preventDefault();
769 // this "transfers" selected copies to a new owning library,
770 // auto-creating volumes and deleting unused volumes as required.
771 service.changeItemOwningLib = function(items) {
772 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
773 if (!xfer_target || !items.length) {
776 var vols_to_move = {};
777 var copies_to_move = {};
778 angular.forEach(items, function(item) {
779 if (item['call_number.owning_lib'] != xfer_target) {
780 if (item['call_number.id'] in vols_to_move) {
781 copies_to_move[item['call_number.id']].push(item.id);
783 vols_to_move[item['call_number.id']] = {
784 label : item['call_number.label'],
785 label_class : item['call_number.label_class'],
786 record : item['call_number.record.id'],
787 prefix : item['call_number.prefix.id'],
788 suffix : item['call_number.suffix.id']
790 copies_to_move[item['call_number.id']] = new Array;
791 copies_to_move[item['call_number.id']].push(item.id);
797 angular.forEach(vols_to_move, function(vol) {
798 promises.push(egCore.net.request(
800 'open-ils.cat.call_number.find_or_create',
808 ).then(function(resp) {
809 var evt = egCore.evt.parse(resp);
811 return egCore.net.request(
813 'open-ils.cat.transfer_copies_to_volume',
816 copies_to_move[vol.id]
825 function(){ service.add_barcode_to_list(cp.barcode) }
832 service.transferItems = function (items){
833 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
834 var copy_ids = service.gatherSelectedHoldingsIds(items);
835 if (xfer_target && copy_ids.length > 0) {
838 'open-ils.cat.transfer_copies_to_volume',
843 function(resp) { // oncomplete
844 var evt = egCore.evt.parse(resp);
846 egConfirmDialog.open(
847 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
848 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
850 ).result.then(function() {
853 'open-ils.cat.transfer_copies_to_volume.override',
857 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
860 angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
863 angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
877 * Search bar along the top of the page.
878 * Parent scope for list and detail views
880 .controller('SearchCtrl',
881 ['$scope','$location','$timeout','egCore','egGridDataProvider','itemSvc',
882 function($scope , $location , $timeout , egCore , egGridDataProvider , itemSvc) {
883 $scope.args = {}; // search args
885 // sub-scopes (search / detail-view) apply their version
886 // of retrieval function to $scope.context.search
887 // and display toggling via $scope.context.toggleDisplay
892 $scope.toggleView = function($event) {
893 $scope.context.toggleDisplay();
894 $event.preventDefault(); // avoid form submission
897 // The functions that follow in this controller are never called
898 // when the List View is active, only the Detail View.
900 // In this context, we're only ever dealing with 1 item, so
901 // we can simply refresh the page. These various itemSvc
902 // functions used to live in the ListCtrl, but they're now
903 // shared between SearchCtrl (for Actions for the Detail View)
904 // and ListCtrl (Actions in the egGrid)
905 itemSvc.add_barcode_to_list = function(b) {
906 //console.log('SearchCtrl: add_barcode_to_list',b);
907 // timeout so audible can happen upon checkin
908 $timeout(function() { location.href = location.href; }, 1000);
911 $scope.add_copies_to_bucket = function() {
912 itemSvc.add_copies_to_bucket([$scope.args.copyId]);
915 $scope.make_copies_bookable = function() {
916 itemSvc.make_copies_bookable([{
917 id : $scope.args.copyId,
918 'call_number.record.id' : $scope.args.recordId
922 $scope.book_copies_now = function() {
923 itemSvc.book_copies_now([{
924 id : $scope.args.copyId,
925 'call_number.record.id' : $scope.args.recordId
929 $scope.requestItems = function() {
930 itemSvc.requestItems([$scope.args.copyId]);
933 $scope.attach_to_peer_bib = function() {
934 itemSvc.attach_to_peer_bib([{
935 id : $scope.args.copyId,
936 barcode : $scope.args.copyBarcode
940 $scope.selectedHoldingsCopyDelete = function () {
941 itemSvc.selectedHoldingsCopyDelete([{
942 id : $scope.args.copyId,
943 barcode : $scope.args.copyBarcode
947 $scope.checkin = function () {
949 id : $scope.args.copyId,
950 barcode : $scope.args.copyBarcode
954 $scope.renew = function () {
956 id : $scope.args.copyId,
957 barcode : $scope.args.copyBarcode
961 $scope.cancel_transit = function () {
962 itemSvc.cancel_transit([{
963 id : $scope.args.copyId,
964 barcode : $scope.args.copyBarcode
968 $scope.selectedHoldingsDamaged = function () {
969 itemSvc.selectedHoldingsDamaged([{
970 id : $scope.args.copyId,
971 barcode : $scope.args.copyBarcode
975 $scope.selectedHoldingsMissing = function () {
976 itemSvc.selectedHoldingsMissing([{
977 id : $scope.args.copyId,
978 barcode : $scope.args.copyBarcode
982 $scope.selectedHoldingsVolCopyAdd = function () {
983 itemSvc.spawnHoldingsAdd([{
984 id : $scope.args.copyId,
985 'call_number.owning_lib' : $scope.args.cnOwningLib,
986 'call_number.record.id' : $scope.args.recordId,
987 barcode : $scope.args.copyBarcode
990 $scope.selectedHoldingsCopyAdd = function () {
991 itemSvc.spawnHoldingsAdd([{
992 id : $scope.args.copyId,
993 'call_number.id' : $scope.args.cnId,
994 'call_number.owning_lib' : $scope.args.cnOwningLib,
995 'call_number.record.id' : $scope.args.recordId,
996 barcode : $scope.args.copyBarcode
1000 $scope.selectedHoldingsVolCopyEdit = function () {
1001 itemSvc.spawnHoldingsEdit([{
1002 id : $scope.args.copyId,
1003 'call_number.id' : $scope.args.cnId,
1004 'call_number.owning_lib' : $scope.args.cnOwningLib,
1005 'call_number.record.id' : $scope.args.recordId,
1006 barcode : $scope.args.copyBarcode
1009 $scope.selectedHoldingsVolEdit = function () {
1010 itemSvc.spawnHoldingsEdit([{
1011 id : $scope.args.copyId,
1012 'call_number.id' : $scope.args.cnId,
1013 'call_number.owning_lib' : $scope.args.cnOwningLib,
1014 'call_number.record.id' : $scope.args.recordId,
1015 barcode : $scope.args.copyBarcode
1018 $scope.selectedHoldingsCopyEdit = function () {
1019 itemSvc.spawnHoldingsEdit([{
1020 id : $scope.args.copyId,
1021 'call_number.id' : $scope.args.cnId,
1022 'call_number.owning_lib' : $scope.args.cnOwningLib,
1023 'call_number.record.id' : $scope.args.recordId,
1024 barcode : $scope.args.copyBarcode
1028 $scope.replaceBarcodes = function() {
1029 itemSvc.replaceBarcodes([{
1030 id : $scope.args.copyId,
1031 barcode : $scope.args.copyBarcode
1035 $scope.changeItemOwningLib = function() {
1036 itemSvc.changeItemOwningLib([{
1037 id : $scope.args.copyId,
1038 'call_number.id' : $scope.args.cnId,
1039 'call_number.owning_lib' : $scope.args.cnOwningLib,
1040 'call_number.record.id' : $scope.args.recordId,
1041 'call_number.label' : $scope.args.cnLabel,
1042 'call_number.label_class' : $scope.args.cnLabelClass,
1043 'call_number.prefix.id' : $scope.args.cnPrefixId,
1044 'call_number.suffix.id' : $scope.args.cnSuffixId,
1045 barcode : $scope.args.copyBarcode
1049 $scope.transferItems = function (){
1050 itemSvc.transferItems([{
1051 id : $scope.args.copyId,
1052 barcode : $scope.args.copyBarcode
1059 * List view - grid stuff
1061 .controller('ListCtrl',
1062 ['$scope','$q','$routeParams','$location','$timeout','$window','egCore','egGridDataProvider','itemSvc','egUser','$uibModal','egCirc','egConfirmDialog',
1063 function($scope , $q , $routeParams , $location , $timeout , $window , egCore , egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog) {
1065 var cp_list = $routeParams.idList;
1067 copyId = cp_list.split(',');
1070 $scope.context.page = 'list';
1073 var provider = egGridDataProvider.instance();
1074 provider.get = function(offset, count) {
1078 $scope.gridDataProvider = egGridDataProvider.instance({
1079 get : function(offset, count) {
1080 //return provider.arrayNotifier(itemSvc.copies, offset, count);
1081 return this.arrayNotifier(itemSvc.copies, offset, count);
1085 // If a copy was just displayed in the detail view, ensure it's
1086 // focused in the list view.
1087 var selected = false;
1088 var copyGrid = $scope.gridControls = {
1089 itemRetrieved : function(item) {
1090 if (selected || !itemSvc.copy) return;
1091 if (itemSvc.copy.id() == item.id) {
1092 copyGrid.selectItems([item.index]);
1098 $scope.$watch('barcodesFromFile', function(newVal, oldVal) {
1099 if (newVal && newVal != oldVal) {
1100 $scope.args.barcode = '';
1103 angular.forEach(newVal.split(/\n/), function(line) {
1105 // scrub any trailing spaces or commas from the barcode
1106 line = line.replace(/(.*?)($|\s.*|,.*)/,'$1');
1107 barcodes.push(line);
1110 if (barcodes.length > 0) {
1112 angular.forEach(barcodes, function (b) {
1113 promises.push(itemSvc.fetch(b));
1116 $q.all(promises).then(
1119 copyGrid.selectItems([itemSvc.copies[0].index]);
1126 $scope.context.search = function(args) {
1127 if (!args.barcode) return;
1128 $scope.context.itemNotFound = false;
1129 itemSvc.fetch(args.barcode).then(function(res) {
1132 copyGrid.selectItems([res.index]);
1133 $scope.args.barcode = '';
1135 $scope.context.itemNotFound = true;
1136 egCore.audio.play('warning.item_status.itemNotFound');
1138 $scope.context.selectBarcode = true;
1142 var add_barcode_to_list = function (b) {
1143 //console.log('listCtrl: add_barcode_to_list',b);
1144 $scope.context.search({barcode:b});
1146 itemSvc.add_barcode_to_list = add_barcode_to_list;
1148 $scope.context.toggleDisplay = function() {
1149 var item = copyGrid.selectedItems()[0];
1151 $location.path('/cat/item/' + item.id);
1154 $scope.context.show_triggered_events = function() {
1155 var item = copyGrid.selectedItems()[0];
1157 $location.path('/cat/item/' + item.id + '/triggered_events');
1160 function gatherSelectedRecordIds () {
1163 copyGrid.selectedItems(),
1165 if (rid_list.indexOf(item['call_number.record.id']) == -1)
1166 rid_list.push(item['call_number.record.id'])
1172 function gatherSelectedVolumeIds (rid) {
1173 var cn_id_list = [];
1175 copyGrid.selectedItems(),
1177 if (rid && item['call_number.record.id'] != rid) return;
1178 if (cn_id_list.indexOf(item['call_number.id']) == -1)
1179 cn_id_list.push(item['call_number.id'])
1185 function gatherSelectedHoldingsIds (rid) {
1186 var cp_id_list = [];
1188 copyGrid.selectedItems(),
1190 if (rid && item['call_number.record.id'] != rid) return;
1191 cp_id_list.push(item.id)
1197 $scope.add_copies_to_bucket = function() {
1198 var copy_list = gatherSelectedHoldingsIds();
1199 itemSvc.add_copies_to_bucket(copy_list);
1202 $scope.need_one_selected = function() {
1203 var items = $scope.gridControls.selectedItems();
1204 if (items.length == 1) return false;
1208 $scope.make_copies_bookable = function() {
1209 itemSvc.make_copies_bookable(copyGrid.selectedItems());
1212 $scope.book_copies_now = function() {
1213 itemSvc.book_copies_now(copyGrid.selectedItems());
1216 $scope.requestItems = function() {
1217 var copy_list = gatherSelectedHoldingsIds();
1218 itemSvc.requestItems(copy_list);
1221 $scope.replaceBarcodes = function() {
1222 itemSvc.replaceBarcodes(copyGrid.selectedItems());
1225 $scope.attach_to_peer_bib = function() {
1226 itemSvc.attach_to_peer_bib(copyGrid.selectedItems());
1229 $scope.selectedHoldingsCopyDelete = function () {
1230 itemSvc.selectedHoldingsCopyDelete(copyGrid.selectedItems());
1233 $scope.selectedHoldingsItemStatusTgrEvt= function() {
1234 var item = copyGrid.selectedItems()[0];
1236 $location.path('/cat/item/' + item.id + '/triggered_events');
1239 $scope.selectedHoldingsItemStatusHolds= function() {
1240 var item = copyGrid.selectedItems()[0];
1242 $location.path('/cat/item/' + item.id + '/holds');
1245 $scope.cancel_transit = function () {
1246 itemSvc.cancel_transit(copyGrid.selectedItems());
1249 $scope.selectedHoldingsDamaged = function () {
1250 itemSvc.selectedHoldingsDamaged(copyGrid.selectedItems());
1253 $scope.selectedHoldingsMissing = function () {
1254 itemSvc.selectedHoldingsMissing(copyGrid.selectedItems());
1257 $scope.checkin = function () {
1258 itemSvc.checkin(copyGrid.selectedItems());
1261 $scope.renew = function () {
1262 itemSvc.renew(copyGrid.selectedItems());
1265 $scope.selectedHoldingsVolCopyAdd = function () {
1266 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),true,false);
1268 $scope.selectedHoldingsCopyAdd = function () {
1269 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),false,true);
1272 $scope.showBibHolds = function () {
1273 angular.forEach(gatherSelectedRecordIds(), function (r) {
1274 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
1275 $timeout(function() { $window.open(url, '_blank') });
1279 $scope.selectedHoldingsVolCopyEdit = function () {
1280 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,false);
1282 $scope.selectedHoldingsVolEdit = function () {
1283 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,true);
1285 $scope.selectedHoldingsCopyEdit = function () {
1286 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),true,false);
1289 $scope.changeItemOwningLib = function() {
1290 itemSvc.changeItemOwningLib(copyGrid.selectedItems());
1293 $scope.transferItems = function (){
1294 itemSvc.transferItems(copyGrid.selectedItems());
1297 $scope.print_labels = function() {
1300 'open-ils.actor.anon_cache.set_value',
1301 null, 'print-labels-these-copies', {
1302 copies : gatherSelectedHoldingsIds()
1304 ).then(function(key) {
1306 var url = egCore.env.basePath + 'cat/printlabels/' + key;
1307 $timeout(function() { $window.open(url, '_blank') });
1309 alert('Could not create anonymous cache key!');
1314 $scope.print_list = function() {
1315 var print_data = { copies : copyGrid.allItems() };
1317 if (print_data.copies.length == 0) return $q.when();
1319 return egCore.print.print({
1320 template : 'item_status',
1325 if (copyId.length > 0) {
1326 itemSvc.fetch(null,copyId).then(
1336 * Detail view -- shows one copy
1338 .controller('ViewCtrl',
1339 ['$scope','$q','$location','$routeParams','$timeout','$window','egCore','itemSvc','egBilling',
1340 function($scope , $q , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling) {
1341 var copyId = $routeParams.id;
1342 $scope.args.copyId = copyId;
1343 $scope.tab = $routeParams.tab || 'summary';
1344 $scope.context.page = 'detail';
1345 $scope.summaryRecord = null;
1347 $scope.edit = false;
1348 if ($scope.tab == 'edit') {
1349 $scope.tab = 'summary';
1354 // use the cached record info
1356 $scope.recordId = itemSvc.copy.call_number().record().id();
1357 $scope.args.recordId = $scope.recordId;
1358 $scope.args.cnId = itemSvc.copy.call_number().id();
1359 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
1360 $scope.args.cnLabel = itemSvc.copy.call_number().label();
1361 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
1362 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
1363 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
1364 $scope.args.copyBarcode = itemSvc.copy.barcode();
1367 function loadCopy(barcode) {
1368 $scope.context.itemNotFound = false;
1370 // Avoid re-fetching the same copy while jumping tabs.
1371 // In addition to being quicker, this helps to avoid flickering
1372 // of the top panel which is always visible in the detail view.
1374 // 'barcode' represents the loading of a new item - refetch it
1375 // regardless of whether it matches the current item.
1376 if (!barcode && itemSvc.copy && itemSvc.copy.id() == copyId) {
1377 $scope.copy = itemSvc.copy;
1378 $scope.recordId = itemSvc.copy.call_number().record().id();
1379 $scope.args.recordId = $scope.recordId;
1380 $scope.args.cnId = itemSvc.copy.call_number().id();
1381 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
1382 $scope.args.cnLabel = itemSvc.copy.call_number().label();
1383 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
1384 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
1385 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
1386 $scope.args.copyBarcode = itemSvc.copy.barcode();
1391 delete itemSvc.copy;
1393 var deferred = $q.defer();
1394 itemSvc.fetch(barcode, copyId, true).then(function(res) {
1395 $scope.context.selectBarcode = true;
1399 $scope.context.itemNotFound = true;
1400 egCore.audio.play('warning.item_status.itemNotFound');
1401 deferred.reject(); // avoid propagation of data fetch calls
1405 var copy = res.copy;
1406 itemSvc.copy = copy;
1410 $scope.recordId = copy.call_number().record().id();
1411 $scope.args.recordId = $scope.recordId;
1412 $scope.args.cnId = itemSvc.copy.call_number().id();
1413 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
1414 $scope.args.cnLabel = itemSvc.copy.call_number().label();
1415 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
1416 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
1417 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
1418 $scope.args.copyBarcode = copy.barcode();
1419 $scope.args.barcode = '';
1421 // locally flesh org units
1422 copy.circ_lib(egCore.org.get(copy.circ_lib()));
1423 copy.call_number().owning_lib(
1424 egCore.org.get(copy.call_number().owning_lib()));
1426 var r = copy.call_number().record();
1427 if (r.owner()) r.owner(egCore.org.get(r.owner()));
1429 // make boolean for auto-magic true/false display
1431 ['ref','opac_visible','holdable','circulate'],
1432 function(field) { copy[field](Boolean(copy[field]() == 't')) }
1435 // finally, if this is a different copy, redirect.
1436 // Note that we flesh first since the copy we just
1437 // fetched will be used after the redirect.
1438 if (copyId && copyId != copy.id()) {
1439 // if a new barcode is scanned in the detail view,
1440 // update the url to match the ID of the new copy
1441 $location.path('/cat/item/' + copy.id() + '/' + $scope.tab);
1442 deferred.reject(); // avoid propagation of data fetch calls
1450 return deferred.promise;
1453 // if loadPrev load the two most recent circulations
1454 function loadCurrentCirc(loadPrev) {
1456 delete $scope.circ_summary;
1457 delete $scope.prev_circ_summary;
1458 delete $scope.prev_circ_usr;
1459 if (!copyId) return;
1461 egCore.pcrud.search('aacs',
1462 {target_copy : copyId},
1468 'checkin_workstation',
1471 'recurring_fine_rule'
1475 order_by : {aacs : 'xact_start desc'},
1479 ).then(null, null, function(circ) {
1482 // load the chain for this circ
1485 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
1486 egCore.auth.token(), $scope.circ.id()
1487 ).then(function(summary) {
1488 $scope.circ_summary = summary;
1491 if (!loadPrev) return;
1493 // load the chain for the previous circ, plus the user
1496 'open-ils.circ.prev_renewal_chain.retrieve_by_circ.summary',
1497 egCore.auth.token(), $scope.circ.id()
1499 ).then(null, null, function(summary) {
1500 $scope.prev_circ_summary = summary.summary;
1502 if (summary.usr) { // aged circs have no 'usr'.
1503 egCore.pcrud.retrieve('au', summary.usr,
1504 {flesh : 1, flesh_fields : {au : ['card']}})
1506 .then(function(user) { $scope.prev_circ_usr = user });
1513 function fetchMaxCircHistory() {
1514 if (maxHistory) return $q.when(maxHistory);
1515 return egCore.org.settings(
1516 'circ.item_checkout_history.max')
1517 .then(function(set) {
1518 maxHistory = set['circ.item_checkout_history.max'] || 4;
1523 $scope.addBilling = function(circ) {
1524 egBilling.showBillDialog({
1525 xact_id : circ.id(),
1530 $scope.retrieveAllPatrons = function() {
1531 var users = new Set();
1532 angular.forEach($scope.circ_list.map(function(circ) { return circ.usr(); }),function(usr) {
1533 // aged circs have no 'usr'.
1534 if (usr) users.add(usr);
1536 users.forEach(function(usr) {
1537 $timeout(function() {
1538 var url = $location.absUrl().replace(
1540 '/circ/patron/' + usr.id() + '/checkout');
1541 $window.open(url, '_blank')
1546 function loadCircHistory() {
1547 $scope.circ_list = [];
1550 itemSvc.copy.call_number().id() == -1 ?
1551 itemSvc.copy.circ_lib().id() :
1552 itemSvc.copy.call_number().owning_lib().id()
1554 // there is an extra layer of permissibility over circ
1556 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
1557 .then(function(orgIds) {
1559 if (orgIds.indexOf(copy_org) == -1) {
1560 console.log('User is not allowed to view circ history');
1564 return fetchMaxCircHistory();
1566 }).then(function(count) {
1568 egCore.pcrud.search('aacs',
1569 {target_copy : copyId},
1575 'checkin_workstation',
1576 'recurring_fine_rule'
1580 order_by : {aacs : 'xact_start desc'},
1584 ).then(null, null, function(circ) {
1586 // flesh circ_lib locally
1587 circ.circ_lib(egCore.org.get(circ.circ_lib()));
1588 circ.checkin_lib(egCore.org.get(circ.checkin_lib()));
1589 $scope.circ_list.push(circ);
1595 function loadCircCounts() {
1597 delete $scope.circ_counts;
1598 $scope.total_circs = 0;
1599 $scope.total_circs_this_year = 0;
1600 $scope.total_circs_prev_year = 0;
1601 if (!copyId) return;
1603 egCore.pcrud.search('circbyyr',
1604 {copy : copyId}, null, {atomic : true})
1606 .then(function(counts) {
1607 $scope.circ_counts = counts;
1609 angular.forEach(counts, function(count) {
1610 $scope.total_circs += Number(count.count());
1613 var this_year = counts.filter(function(c) {
1614 return c.year() == new Date().getFullYear();
1617 $scope.total_circs_this_year =
1618 this_year.length ? this_year[0].count() : 0;
1620 var prev_year = counts.filter(function(c) {
1621 return c.year() == new Date().getFullYear() - 1;
1624 $scope.total_circs_prev_year =
1625 prev_year.length ? prev_year[0].count() : 0;
1630 function loadHolds() {
1632 if (!copyId) return;
1634 egCore.pcrud.search('ahr',
1635 { current_copy : copyId,
1637 fulfillment_time : null,
1638 capture_time : {'<>' : null}
1642 ahr : ['requestor', 'usr'],
1646 ).then(null, null, function(hold) {
1648 hold.pickup_lib(egCore.org.get(hold.pickup_lib()));
1649 if (hold.current_shelf_lib()) {
1650 hold.current_shelf_lib(
1651 egCore.org.get(hold.current_shelf_lib()));
1653 hold.behind_desk(Boolean(hold.behind_desk() == 't'));
1657 function loadTransits() {
1658 delete $scope.transit;
1659 delete $scope.hold_transit;
1660 if (!copyId) return;
1662 egCore.pcrud.search('atc',
1663 {target_copy : copyId},
1664 {order_by : {atc : 'source_send_time DESC'}}
1666 ).then(null, null, function(transit) {
1667 $scope.transit = transit;
1668 transit.source(egCore.org.get(transit.source()));
1669 transit.dest(egCore.org.get(transit.dest()));
1674 // we don't need all data on all tabs, so fetch what's needed when needed.
1675 function loadTabData() {
1676 switch($scope.tab) {
1683 loadCurrentCirc(true);
1695 case 'triggered_events':
1696 var url = $location.absUrl().replace(/\/staff.*/, '/actor/user/event_log');
1697 url += '?copy_id=' + encodeURIComponent(copyId);
1698 $scope.triggered_events_url = url;
1705 'open-ils.actor.anon_cache.set_value',
1706 null, 'edit-these-copies', {
1707 record_id: $scope.recordId,
1712 ).then(function(key) {
1714 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1715 $window.location.href = url;
1717 alert('Could not create anonymous cache key!');
1725 $scope.context.toggleDisplay = function() {
1726 $location.path('/cat/item/search');
1729 // handle the barcode scan box, which will replace our current copy
1730 $scope.context.search = function(args) {
1731 loadCopy(args.barcode).then(loadTabData);
1734 $scope.context.show_triggered_events = function() {
1735 $location.path('/cat/item/' + copyId + '/triggered_events');
1738 loadCopy().then(loadTabData);