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 itemSvc.fetch(barcodes).then(
1113 copyGrid.selectItems([itemSvc.copies[0].index]);
1119 $scope.context.search = function(args) {
1120 if (!args.barcode) return;
1121 $scope.context.itemNotFound = false;
1122 itemSvc.fetch(args.barcode).then(function(res) {
1125 copyGrid.selectItems([res.index]);
1126 $scope.args.barcode = '';
1128 $scope.context.itemNotFound = true;
1129 egCore.audio.play('warning.item_status.itemNotFound');
1131 $scope.context.selectBarcode = true;
1135 var add_barcode_to_list = function (b) {
1136 //console.log('listCtrl: add_barcode_to_list',b);
1137 $scope.context.search({barcode:b});
1139 itemSvc.add_barcode_to_list = add_barcode_to_list;
1141 $scope.context.toggleDisplay = function() {
1142 var item = copyGrid.selectedItems()[0];
1144 $location.path('/cat/item/' + item.id);
1147 $scope.context.show_triggered_events = function() {
1148 var item = copyGrid.selectedItems()[0];
1150 $location.path('/cat/item/' + item.id + '/triggered_events');
1153 function gatherSelectedRecordIds () {
1156 copyGrid.selectedItems(),
1158 if (rid_list.indexOf(item['call_number.record.id']) == -1)
1159 rid_list.push(item['call_number.record.id'])
1165 function gatherSelectedVolumeIds (rid) {
1166 var cn_id_list = [];
1168 copyGrid.selectedItems(),
1170 if (rid && item['call_number.record.id'] != rid) return;
1171 if (cn_id_list.indexOf(item['call_number.id']) == -1)
1172 cn_id_list.push(item['call_number.id'])
1178 function gatherSelectedHoldingsIds (rid) {
1179 var cp_id_list = [];
1181 copyGrid.selectedItems(),
1183 if (rid && item['call_number.record.id'] != rid) return;
1184 cp_id_list.push(item.id)
1190 $scope.add_copies_to_bucket = function() {
1191 var copy_list = gatherSelectedHoldingsIds();
1192 itemSvc.add_copies_to_bucket(copy_list);
1195 $scope.need_one_selected = function() {
1196 var items = $scope.gridControls.selectedItems();
1197 if (items.length == 1) return false;
1201 $scope.make_copies_bookable = function() {
1202 itemSvc.make_copies_bookable(copyGrid.selectedItems());
1205 $scope.book_copies_now = function() {
1206 itemSvc.book_copies_now(copyGrid.selectedItems());
1209 $scope.requestItems = function() {
1210 var copy_list = gatherSelectedHoldingsIds();
1211 itemSvc.requestItems(copy_list);
1214 $scope.replaceBarcodes = function() {
1215 itemSvc.replaceBarcodes(copyGrid.selectedItems());
1218 $scope.attach_to_peer_bib = function() {
1219 itemSvc.attach_to_peer_bib(copyGrid.selectedItems());
1222 $scope.selectedHoldingsCopyDelete = function () {
1223 itemSvc.selectedHoldingsCopyDelete(copyGrid.selectedItems());
1226 $scope.selectedHoldingsItemStatusTgrEvt= function() {
1227 var item = copyGrid.selectedItems()[0];
1229 $location.path('/cat/item/' + item.id + '/triggered_events');
1232 $scope.selectedHoldingsItemStatusHolds= function() {
1233 var item = copyGrid.selectedItems()[0];
1235 $location.path('/cat/item/' + item.id + '/holds');
1238 $scope.cancel_transit = function () {
1239 itemSvc.cancel_transit(copyGrid.selectedItems());
1242 $scope.selectedHoldingsDamaged = function () {
1243 itemSvc.selectedHoldingsDamaged(copyGrid.selectedItems());
1246 $scope.selectedHoldingsMissing = function () {
1247 itemSvc.selectedHoldingsMissing(copyGrid.selectedItems());
1250 $scope.checkin = function () {
1251 itemSvc.checkin(copyGrid.selectedItems());
1254 $scope.renew = function () {
1255 itemSvc.renew(copyGrid.selectedItems());
1258 $scope.selectedHoldingsVolCopyAdd = function () {
1259 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),true,false);
1261 $scope.selectedHoldingsCopyAdd = function () {
1262 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),false,true);
1265 $scope.showBibHolds = function () {
1266 angular.forEach(gatherSelectedRecordIds(), function (r) {
1267 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
1268 $timeout(function() { $window.open(url, '_blank') });
1272 $scope.selectedHoldingsVolCopyEdit = function () {
1273 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,false);
1275 $scope.selectedHoldingsVolEdit = function () {
1276 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,true);
1278 $scope.selectedHoldingsCopyEdit = function () {
1279 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),true,false);
1282 $scope.changeItemOwningLib = function() {
1283 itemSvc.changeItemOwningLib(copyGrid.selectedItems());
1286 $scope.transferItems = function (){
1287 itemSvc.transferItems(copyGrid.selectedItems());
1290 $scope.print_labels = function() {
1293 'open-ils.actor.anon_cache.set_value',
1294 null, 'print-labels-these-copies', {
1295 copies : gatherSelectedHoldingsIds()
1297 ).then(function(key) {
1299 var url = egCore.env.basePath + 'cat/printlabels/' + key;
1300 $timeout(function() { $window.open(url, '_blank') });
1302 alert('Could not create anonymous cache key!');
1307 $scope.print_list = function() {
1308 var print_data = { copies : copyGrid.allItems() };
1310 if (print_data.copies.length == 0) return $q.when();
1312 return egCore.print.print({
1313 template : 'item_status',
1318 if (copyId.length > 0) {
1319 itemSvc.fetch(null,copyId).then(
1329 * Detail view -- shows one copy
1331 .controller('ViewCtrl',
1332 ['$scope','$q','$location','$routeParams','$timeout','$window','egCore','itemSvc','egBilling',
1333 function($scope , $q , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling) {
1334 var copyId = $routeParams.id;
1335 $scope.args.copyId = copyId;
1336 $scope.tab = $routeParams.tab || 'summary';
1337 $scope.context.page = 'detail';
1338 $scope.summaryRecord = null;
1340 $scope.edit = false;
1341 if ($scope.tab == 'edit') {
1342 $scope.tab = 'summary';
1347 // use the cached record info
1349 $scope.recordId = itemSvc.copy.call_number().record().id();
1350 $scope.args.recordId = $scope.recordId;
1351 $scope.args.cnId = itemSvc.copy.call_number().id();
1352 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
1353 $scope.args.cnLabel = itemSvc.copy.call_number().label();
1354 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
1355 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
1356 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
1357 $scope.args.copyBarcode = itemSvc.copy.barcode();
1360 function loadCopy(barcode) {
1361 $scope.context.itemNotFound = false;
1363 // Avoid re-fetching the same copy while jumping tabs.
1364 // In addition to being quicker, this helps to avoid flickering
1365 // of the top panel which is always visible in the detail view.
1367 // 'barcode' represents the loading of a new item - refetch it
1368 // regardless of whether it matches the current item.
1369 if (!barcode && itemSvc.copy && itemSvc.copy.id() == copyId) {
1370 $scope.copy = itemSvc.copy;
1371 $scope.recordId = itemSvc.copy.call_number().record().id();
1372 $scope.args.recordId = $scope.recordId;
1373 $scope.args.cnId = itemSvc.copy.call_number().id();
1374 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
1375 $scope.args.cnLabel = itemSvc.copy.call_number().label();
1376 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
1377 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
1378 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
1379 $scope.args.copyBarcode = itemSvc.copy.barcode();
1384 delete itemSvc.copy;
1386 var deferred = $q.defer();
1387 itemSvc.fetch(barcode, copyId, true).then(function(res) {
1388 $scope.context.selectBarcode = true;
1392 $scope.context.itemNotFound = true;
1393 egCore.audio.play('warning.item_status.itemNotFound');
1394 deferred.reject(); // avoid propagation of data fetch calls
1398 var copy = res.copy;
1399 itemSvc.copy = copy;
1403 $scope.recordId = copy.call_number().record().id();
1404 $scope.args.recordId = $scope.recordId;
1405 $scope.args.cnId = itemSvc.copy.call_number().id();
1406 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
1407 $scope.args.cnLabel = itemSvc.copy.call_number().label();
1408 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
1409 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
1410 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
1411 $scope.args.copyBarcode = copy.barcode();
1412 $scope.args.barcode = '';
1414 // locally flesh org units
1415 copy.circ_lib(egCore.org.get(copy.circ_lib()));
1416 copy.call_number().owning_lib(
1417 egCore.org.get(copy.call_number().owning_lib()));
1419 var r = copy.call_number().record();
1420 if (r.owner()) r.owner(egCore.org.get(r.owner()));
1422 // make boolean for auto-magic true/false display
1424 ['ref','opac_visible','holdable','circulate'],
1425 function(field) { copy[field](Boolean(copy[field]() == 't')) }
1428 // finally, if this is a different copy, redirect.
1429 // Note that we flesh first since the copy we just
1430 // fetched will be used after the redirect.
1431 if (copyId && copyId != copy.id()) {
1432 // if a new barcode is scanned in the detail view,
1433 // update the url to match the ID of the new copy
1434 $location.path('/cat/item/' + copy.id() + '/' + $scope.tab);
1435 deferred.reject(); // avoid propagation of data fetch calls
1443 return deferred.promise;
1446 // if loadPrev load the two most recent circulations
1447 function loadCurrentCirc(loadPrev) {
1449 delete $scope.circ_summary;
1450 delete $scope.prev_circ_summary;
1451 delete $scope.prev_circ_usr;
1452 if (!copyId) return;
1454 egCore.pcrud.search('aacs',
1455 {target_copy : copyId},
1461 'checkin_workstation',
1464 'recurring_fine_rule'
1468 order_by : {aacs : 'xact_start desc'},
1472 ).then(null, null, function(circ) {
1475 // load the chain for this circ
1478 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
1479 egCore.auth.token(), $scope.circ.id()
1480 ).then(function(summary) {
1481 $scope.circ_summary = summary;
1484 if (!loadPrev) return;
1486 // load the chain for the previous circ, plus the user
1489 'open-ils.circ.prev_renewal_chain.retrieve_by_circ.summary',
1490 egCore.auth.token(), $scope.circ.id()
1492 ).then(null, null, function(summary) {
1493 $scope.prev_circ_summary = summary.summary;
1495 if (summary.usr) { // aged circs have no 'usr'.
1496 egCore.pcrud.retrieve('au', summary.usr,
1497 {flesh : 1, flesh_fields : {au : ['card']}})
1499 .then(function(user) { $scope.prev_circ_usr = user });
1506 function fetchMaxCircHistory() {
1507 if (maxHistory) return $q.when(maxHistory);
1508 return egCore.org.settings(
1509 'circ.item_checkout_history.max')
1510 .then(function(set) {
1511 maxHistory = set['circ.item_checkout_history.max'] || 4;
1516 $scope.addBilling = function(circ) {
1517 egBilling.showBillDialog({
1518 xact_id : circ.id(),
1523 $scope.retrieveAllPatrons = function() {
1524 var users = new Set();
1525 angular.forEach($scope.circ_list.map(function(circ) { return circ.usr(); }),function(usr) {
1526 // aged circs have no 'usr'.
1527 if (usr) users.add(usr);
1529 users.forEach(function(usr) {
1530 $timeout(function() {
1531 var url = $location.absUrl().replace(
1533 '/circ/patron/' + usr.id() + '/checkout');
1534 $window.open(url, '_blank')
1539 function loadCircHistory() {
1540 $scope.circ_list = [];
1543 itemSvc.copy.call_number().id() == -1 ?
1544 itemSvc.copy.circ_lib().id() :
1545 itemSvc.copy.call_number().owning_lib().id()
1547 // there is an extra layer of permissibility over circ
1549 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
1550 .then(function(orgIds) {
1552 if (orgIds.indexOf(copy_org) == -1) {
1553 console.log('User is not allowed to view circ history');
1557 return fetchMaxCircHistory();
1559 }).then(function(count) {
1561 egCore.pcrud.search('aacs',
1562 {target_copy : copyId},
1568 'checkin_workstation',
1569 'recurring_fine_rule'
1573 order_by : {aacs : 'xact_start desc'},
1577 ).then(null, null, function(circ) {
1579 // flesh circ_lib locally
1580 circ.circ_lib(egCore.org.get(circ.circ_lib()));
1581 circ.checkin_lib(egCore.org.get(circ.checkin_lib()));
1582 $scope.circ_list.push(circ);
1588 function loadCircCounts() {
1590 delete $scope.circ_counts;
1591 $scope.total_circs = 0;
1592 $scope.total_circs_this_year = 0;
1593 $scope.total_circs_prev_year = 0;
1594 if (!copyId) return;
1596 egCore.pcrud.search('circbyyr',
1597 {copy : copyId}, null, {atomic : true})
1599 .then(function(counts) {
1600 $scope.circ_counts = counts;
1602 angular.forEach(counts, function(count) {
1603 $scope.total_circs += Number(count.count());
1606 var this_year = counts.filter(function(c) {
1607 return c.year() == new Date().getFullYear();
1610 $scope.total_circs_this_year =
1611 this_year.length ? this_year[0].count() : 0;
1613 var prev_year = counts.filter(function(c) {
1614 return c.year() == new Date().getFullYear() - 1;
1617 $scope.total_circs_prev_year =
1618 prev_year.length ? prev_year[0].count() : 0;
1623 function loadHolds() {
1625 if (!copyId) return;
1627 egCore.pcrud.search('ahr',
1628 { current_copy : copyId,
1630 fulfillment_time : null,
1631 capture_time : {'<>' : null}
1635 ahr : ['requestor', 'usr'],
1639 ).then(null, null, function(hold) {
1641 hold.pickup_lib(egCore.org.get(hold.pickup_lib()));
1642 if (hold.current_shelf_lib()) {
1643 hold.current_shelf_lib(
1644 egCore.org.get(hold.current_shelf_lib()));
1646 hold.behind_desk(Boolean(hold.behind_desk() == 't'));
1650 function loadTransits() {
1651 delete $scope.transit;
1652 delete $scope.hold_transit;
1653 if (!copyId) return;
1655 egCore.pcrud.search('atc',
1656 {target_copy : copyId},
1657 {order_by : {atc : 'source_send_time DESC'}}
1659 ).then(null, null, function(transit) {
1660 $scope.transit = transit;
1661 transit.source(egCore.org.get(transit.source()));
1662 transit.dest(egCore.org.get(transit.dest()));
1667 // we don't need all data on all tabs, so fetch what's needed when needed.
1668 function loadTabData() {
1669 switch($scope.tab) {
1676 loadCurrentCirc(true);
1688 case 'triggered_events':
1689 var url = $location.absUrl().replace(/\/staff.*/, '/actor/user/event_log');
1690 url += '?copy_id=' + encodeURIComponent(copyId);
1691 $scope.triggered_events_url = url;
1698 'open-ils.actor.anon_cache.set_value',
1699 null, 'edit-these-copies', {
1700 record_id: $scope.recordId,
1705 ).then(function(key) {
1707 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1708 $window.location.href = url;
1710 alert('Could not create anonymous cache key!');
1718 $scope.context.toggleDisplay = function() {
1719 $location.path('/cat/item/search');
1722 // handle the barcode scan box, which will replace our current copy
1723 $scope.context.search = function(args) {
1724 loadCopy(args.barcode).then(loadTabData);
1727 $scope.context.show_triggered_events = function() {
1728 $location.path('/cat/item/' + copyId + '/triggered_events');
1731 loadCopy().then(loadTabData);