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?|mailto|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 * Search bar along the top of the page.
52 * Parent scope for list and detail views
54 .controller('SearchCtrl',
55 ['$scope','$q','$window','$location','$timeout','egCore','egNet','egGridDataProvider','egItem', 'egCirc', 'ngToast',
56 function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , egCirc, ngToast) {
57 $scope.args = {}; // search args
59 // sub-scopes (search / detail-view) apply their version
60 // of retrieval function to $scope.context.search
61 // and display toggling via $scope.context.toggleDisplay
66 $scope.toggleView = function($event) {
67 $scope.context.toggleDisplay();
68 $event.preventDefault(); // avoid form submission
71 // The functions that follow in this controller are never called
72 // when the List View is active, only the Detail View.
74 // In this context, we're only ever dealing with 1 item, so
75 // we can simply refresh the page. These various itemSvc
76 // functions used to live in the ListCtrl, but they're now
77 // shared between SearchCtrl (for Actions for the Detail View)
78 // and ListCtrl (Actions in the egGrid)
79 itemSvc.add_barcode_to_list = function(b) {
80 //console.log('SearchCtrl: add_barcode_to_list',b);
81 // timeout so audible can happen upon checkin
82 $timeout(function() { location.href = location.href; }, 1000);
85 $scope.add_copies_to_bucket = function() {
86 itemSvc.add_copies_to_bucket([$scope.args.copyId]);
89 $scope.add_records_to_bucket = function() {
90 itemSvc.add_records_to_bucket([$scope.args.recordId], 'biblio');
93 $scope.show_in_catalog = function() {
94 window.open('/eg2/staff/catalog/record/' + $scope.args.recordId, '_blank');
97 $scope.print_labels = function() {
98 itemSvc.print_spine_labels([$scope.args.copyId]);
102 $scope.make_copies_bookable = function() {
103 itemSvc.make_copies_bookable([{
104 id : $scope.args.copyId,
105 'call_number.record.id' : $scope.args.recordId
109 $scope.book_copies_now = function() {
110 itemSvc.book_copies_now([$scope.args.copyBarcode]);
113 $scope.findAcquisition = function() {
116 $scope.openAcquisitionLineItem([$scope.args.copyId]);
119 $scope.openAcquisitionLineItem = function (cp_list) {
120 var hasResults = false;
123 angular.forEach(cp_list, function (copyId) {
127 'open-ils.acq.lineitem.retrieve.by_copy_id',
130 ).then(function (acqData) {
133 acqData = egCore.idl.toHash(acqData);
134 var url = '/eg2/staff/acq/po/' + acqData.purchase_order + '#' + acqData.id;
135 $timeout(function () { $window.open(url, '_blank') });
143 $q.all(promises).then(function () {
144 !hasResults ? alert('There is no corresponding purchase order for this item.') : false;
148 $scope.manage_reservations = function() {
149 itemSvc.manage_reservations([$scope.args.copyBarcode]);
152 $scope.requestItems = function() {
153 itemSvc.requestItems([$scope.args.copyId],[$scope.args.recordId]);
156 $scope.update_inventory = function() {
157 itemSvc.updateInventory([$scope.args.copyId], null)
158 .then(function(res) {
160 ngToast.create(egCore.strings.SUCCESS_UPDATE_INVENTORY_SINGLE);
162 ngToast.warning(egCore.strings.FAIL_UPDATE_INVENTORY_SINGLE);
164 $timeout(function() { location.href = location.href; }, 1500);
168 $scope.show_triggered_events = function() {
169 window.open('/eg2/staff/circ/item/event-log/' + $scope.args.copyId, '_blank');
172 $scope.show_item_holds = function() {
173 $location.path('/cat/item/' + $scope.args.copyId + '/holds');
176 $scope.show_record_holds = function() {
177 window.open('/eg2/staff/catalog/record/' + $scope.args.recordId + '/holds', '_blank');
180 $scope.add_item_alerts = function() {
181 egCirc.add_copy_alerts([$scope.args.copyId]);
184 $scope.manage_item_alerts = function() {
185 egCirc.manage_copy_alerts([$scope.args.copyId]);
189 $scope.attach_to_peer_bib = function() {
190 itemSvc.attach_to_peer_bib([{
191 id : $scope.args.copyId,
192 barcode : $scope.args.copyBarcode
196 $scope.selectedHoldingsCopyDelete = function () {
197 itemSvc.selectedHoldingsCopyDelete([{
198 id : $scope.args.copyId,
199 barcode : $scope.args.copyBarcode
203 $scope.checkin = function () {
205 id : $scope.args.copyId,
206 barcode : $scope.args.copyBarcode
210 $scope.renew = function () {
212 id : $scope.args.copyId,
213 barcode : $scope.args.copyBarcode
217 $scope.cancel_transit = function () {
218 itemSvc.cancel_transit([{
219 id : $scope.args.copyId,
220 barcode : $scope.args.copyBarcode
224 $scope.selectedHoldingsDamaged = function () {
225 itemSvc.selectedHoldingsDamaged([{
226 id : $scope.args.copyId,
227 barcode : $scope.args.copyBarcode,
232 $scope.selectedHoldingsDiscard = function () {
233 itemSvc.selectedHoldingsDiscard([{
234 id : $scope.args.copyId,
235 barcode : $scope.args.barcode
239 $scope.selectedHoldingsMissing = function () {
240 itemSvc.selectedHoldingsMissing([{
241 id : $scope.args.copyId,
242 barcode : $scope.args.barcode
243 }]).catch(function(){});
246 $scope.selectedHoldingsVolCopyAdd = function () {
247 itemSvc.spawnHoldingsAdd([{
248 id : $scope.args.copyId,
249 'call_number.owning_lib' : $scope.args.cnOwningLib,
250 'call_number.record.id' : $scope.args.recordId,
251 barcode : $scope.args.copyBarcode
254 $scope.selectedHoldingsCopyAdd = function () {
255 itemSvc.spawnHoldingsAdd([{
256 id : $scope.args.copyId,
257 'call_number.id' : $scope.args.cnId,
258 'call_number.owning_lib' : $scope.args.cnOwningLib,
259 'call_number.record.id' : $scope.args.recordId,
260 barcode : $scope.args.copyBarcode
264 $scope.selectedHoldingsVolCopyEdit = function () {
265 itemSvc.spawnHoldingsEdit([{
266 id : $scope.args.copyId,
267 'call_number.id' : $scope.args.cnId,
268 'call_number.owning_lib' : $scope.args.cnOwningLib,
269 'call_number.record.id' : $scope.args.recordId,
270 barcode : $scope.args.copyBarcode
273 $scope.selectedHoldingsVolEdit = function () {
274 itemSvc.spawnHoldingsEdit([{
275 id : $scope.args.copyId,
276 'call_number.id' : $scope.args.cnId,
277 'call_number.owning_lib' : $scope.args.cnOwningLib,
278 'call_number.record.id' : $scope.args.recordId,
279 barcode : $scope.args.copyBarcode
282 $scope.selectedHoldingsCopyEdit = function () {
283 itemSvc.spawnHoldingsEdit([{
284 id : $scope.args.copyId,
285 'call_number.id' : $scope.args.cnId,
286 'call_number.owning_lib' : $scope.args.cnOwningLib,
287 'call_number.record.id' : $scope.args.recordId,
288 barcode : $scope.args.copyBarcode
292 $scope.replaceBarcodes = function() {
293 itemSvc.replaceBarcodes([{
294 id : $scope.args.copyId,
295 barcode : $scope.args.copyBarcode
299 $scope.changeItemOwningLib = function() {
300 itemSvc.changeItemOwningLib([{
301 id : $scope.args.copyId,
302 'call_number.id' : $scope.args.cnId,
303 'call_number.owning_lib' : $scope.args.cnOwningLib,
304 'call_number.record.id' : $scope.args.recordId,
305 'call_number.label' : $scope.args.cnLabel,
306 'call_number.label_class' : $scope.args.cnLabelClass,
307 'call_number.prefix.id' : $scope.args.cnPrefixId,
308 'call_number.suffix.id' : $scope.args.cnSuffixId,
309 barcode : $scope.args.copyBarcode
313 $scope.transferItems = function (){
314 itemSvc.transferItems([{
315 id : $scope.args.copyId,
316 barcode : $scope.args.copyBarcode
323 * List view - grid stuff
325 .controller('ListCtrl',
326 ['$scope','$q','$routeParams','$location','$timeout','$window','egCore',
327 'egGridDataProvider','egItem','egUser','$uibModal','egCirc','egConfirmDialog',
328 'egProgressDialog', 'ngToast',
329 // function($scope , $q , $routeParams , $location , $timeout , $window , egCore ,
330 // egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog,
331 // egProgressDialog, ngToast) {
332 function($scope , $q , $routeParams , $location , $timeout , $window , egCore , egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog,
333 egProgressDialog, ngToast) {
335 var cp_list = $routeParams.idList;
337 copyId = cp_list.split(',');
340 var modified_items = new Set();
342 $scope.context.page = 'list';
345 var provider = egGridDataProvider.instance();
346 provider.get = function(offset, count) {
350 $scope.gridDataProvider = egGridDataProvider.instance({
351 get : function(offset, count) {
352 //return provider.arrayNotifier(itemSvc.copies, offset, count);
353 return this.arrayNotifier(itemSvc.copies, offset, count);
357 // If a copy was just displayed in the detail view, ensure it's
358 // focused in the list view.
359 var selected = false;
360 var copyGrid = $scope.gridControls = {
361 itemRetrieved : function(item) {
362 if (selected || !itemSvc.copy) return;
363 if (itemSvc.copy.id() == item.id) {
364 copyGrid.selectItems([item.index]);
370 $scope.$watch('barcodesFromFile', function(newVal, oldVal) {
371 $scope.context.itemsNotFound = [];
372 $scope.context.fileDoneLoading = false;
373 $scope.context.numBarcodesInFile = 0;
374 if (newVal && newVal != oldVal) {
375 $scope.args.barcode = '';
378 angular.forEach(newVal.split(/\r?\n/), function(line) {
379 //remove all whitespace and commas
380 line = line.replace(/[\s,]+/g,'');
382 //Or remove leading/trailing whitespace
383 //line = line.replace(/(^[\s,]+|[\s,]+$/g,'');
389 // Serialize copy retrieval since there may be many, many copies.
390 function fetch_next_copy() {
391 var barcode = barcodes.pop();
392 egProgressDialog.increment();
394 if (barcode == undefined) { // All done here.
395 egProgressDialog.close();
397 if(itemSvc.copies[0]){ // Were any copies actually retrieved
398 copyGrid.selectItems([itemSvc.copies[0].index]);
400 $scope.context.fileDoneLoading = true;
404 itemSvc.fetch(barcode).then(function(item) {
406 $scope.context.itemsNotFound.push(barcode);
412 if (barcodes.length) {
413 $scope.context.numBarcodesInFile = barcodes.length;
414 egProgressDialog.open({value: 0, max: barcodes.length});
420 $scope.context.search = function(args, noGridRefresh) {
421 if (!args.barcode) return $q.when();
422 $scope.context.itemNotFound = false;
424 //check to see if there are multiple barcodes in CSV format
426 //split on commas and clean up barcodes
427 angular.forEach(args.barcode.split(/,/), function(line) {
428 //remove all whitespace and commas
429 line = line.replace(/[\s,]+/g,'');
431 //Or remove leading/trailing whitespace
432 //line = line.replace(/(^[\s,]+|[\s,]+$/g,'');
438 if(barcodes.length > 1){
439 //convert to newline seperated list and send to barcodesFromFile processor
440 $scope.barcodesFromFile = barcodes.join('\n');
441 //console.log('Barcodes: ',barcodes);
446 return itemSvc.fetch(args.barcode).then(function(res) {
448 if (!noGridRefresh) {
451 copyGrid.selectItems([res.index]);
452 $scope.args.barcode = '';
454 $scope.context.itemNotFound = true;
455 egCore.audio.play('warning.item_status.itemNotFound');
457 $scope.context.selectBarcode = true;
462 var add_barcode_to_list = function (b, noGridRefresh) {
463 // console.log('listCtrl: add_barcode_to_list',b);
464 return $scope.context.search({barcode:b}, noGridRefresh);
466 itemSvc.add_barcode_to_list = add_barcode_to_list;
468 $scope.context.toggleDisplay = function() {
469 var item = copyGrid.selectedItems()[0];
471 $location.path('/cat/item/' + item.id);
474 $scope.context.show_triggered_events = function() {
475 var item = copyGrid.selectedItems()[0];
477 window.open('/eg2/staff/circ/item/event-log/' + item.id, '_blank');
480 function gatherSelectedRecordIds () {
483 copyGrid.selectedItems(),
485 if (rid_list.indexOf(item['call_number.record.id']) == -1)
486 rid_list.push(item['call_number.record.id'])
492 function gatherSelectedVolumeIds (rid) {
495 copyGrid.selectedItems(),
497 if (rid && item['call_number.record.id'] != rid) return;
498 if (cn_id_list.indexOf(item['call_number.id']) == -1)
499 cn_id_list.push(item['call_number.id'])
505 function gatherSelectedHoldingsIds (rid) {
508 copyGrid.selectedItems(),
510 if (rid && item['call_number.record.id'] != rid) return;
511 cp_id_list.push(item.id)
517 function gatherSelectedHoldingsRecords() {
518 var record_id_list = [];
520 copyGrid.selectedItems(),
522 record_id_list.push(item['call_number.record.id']);
525 return record_id_list;
528 $scope.refreshGridData = function() {
529 var chain = $q.when();
530 var all_items = itemSvc.copies.map(function(item) {
533 angular.forEach(all_items.reverse(), function(i) {
534 itemSvc.copies.shift();
535 chain = chain.then(function() {
536 return itemSvc.fetch(null, i);
539 return chain.then(function() {
545 $scope.add_copies_to_bucket = function() {
546 var copy_list = gatherSelectedHoldingsIds();
547 itemSvc.add_copies_to_bucket(copy_list);
550 $scope.add_records_to_bucket = function() {
551 var record_list = gatherSelectedHoldingsRecords();
552 itemSvc.add_copies_to_bucket(record_list, 'biblio');
555 $scope.locateAcquisition = function() {
556 if (gatherSelectedHoldingsIds) {
557 var cp_list = gatherSelectedHoldingsIds();
559 if (cp_list.length > 0) {
560 $scope.openAcquisitionLineItem(cp_list);
566 $scope.update_inventory = function() {
567 var copy_list = gatherSelectedHoldingsIds();
568 itemSvc.updateInventory(copy_list, $scope.gridControls.allItems()).then(function(res) {
570 ngToast.create(egCore.strings.SUCCESS_UPDATE_INVENTORY);
572 ngToast.warning(egCore.strings.FAIL_UPDATE_INVENTORY);
577 $scope.need_one_selected = function() {
578 var items = $scope.gridControls.selectedItems();
579 if (items.length == 1) return false;
583 $scope.make_copies_bookable = function() {
584 itemSvc.make_copies_bookable(copyGrid.selectedItems());
587 $scope.book_copies_now = function() {
588 var item = copyGrid.selectedItems()[0];
590 itemSvc.book_copies_now(item.barcode);
593 $scope.manage_reservations = function() {
594 var item = copyGrid.selectedItems()[0];
596 itemSvc.manage_reservations(item.barcode);
599 $scope.requestItems = function() {
600 var copy_list = gatherSelectedHoldingsIds();
601 var record_list = gatherSelectedRecordIds();
602 itemSvc.requestItems(copy_list,record_list);
605 $scope.replaceBarcodes = function() {
606 itemSvc.replaceBarcodes(copyGrid.selectedItems());
609 $scope.attach_to_peer_bib = function() {
610 itemSvc.attach_to_peer_bib(copyGrid.selectedItems());
613 $scope.selectedHoldingsCopyDelete = function () {
614 itemSvc.selectedHoldingsCopyDelete(copyGrid.selectedItems());
617 $scope.selectedHoldingsItemStatusTgrEvt= function() {
618 var item = copyGrid.selectedItems()[0];
620 window.open('/eg2/staff/circ/item/event-log/' + item.id, '_blank');
623 $scope.selectedHoldingsItemStatusHolds= function() {
624 var item = copyGrid.selectedItems()[0];
626 $location.path('/cat/item/' + item.id + '/holds');
629 $scope.cancel_transit = function () {
630 itemSvc.cancel_transit(copyGrid.selectedItems());
633 $scope.selectedHoldingsDamaged = function () {
634 itemSvc.selectedHoldingsDamaged(copyGrid.selectedItems());
637 $scope.selectedHoldingsDiscard = function () {
638 itemSvc.selectedHoldingsDiscard(copyGrid.selectedItems());
641 $scope.selectedHoldingsMissing = function () {
642 var dialog = egProgressDialog.open();
643 dialog.opened.then(function() {
644 itemSvc.selectedHoldingsMissing(copyGrid.selectedItems())
646 console.debug('Marking missing complete, refreshing grid');
648 }).catch(function() {
649 }).finally(function() {
650 egProgressDialog.close();
655 $scope.checkin = function () {
656 itemSvc.checkin(copyGrid.selectedItems());
659 $scope.renew = function () {
660 itemSvc.renew(copyGrid.selectedItems());
663 $scope.selectedHoldingsVolCopyAdd = function () {
664 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),true,false);
666 $scope.selectedHoldingsCopyAdd = function () {
667 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),false,true);
670 $scope.selectedHoldingsCopyAlertsAdd = function(items) {
672 angular.forEach(items, function(item) {
673 if (item.id) copy_ids.push(item.id);
675 egCirc.add_copy_alerts(copy_ids).then(function() {
676 // update grid items?
680 $scope.selectedHoldingsCopyAlertsEdit = function(items) {
682 angular.forEach(items, function(item) {
683 if (item.id) copy_ids.push(item.id);
685 egCirc.manage_copy_alerts(copy_ids).then(function() {
686 // update grid items?
690 $scope.gridCellHandlers = {};
691 $scope.gridCellHandlers.copyAlertsEdit = function(id) {
692 egCirc.manage_copy_alerts([id]).then(function() {
693 // update grid items?
697 $scope.showBibHolds = function () {
698 angular.forEach(gatherSelectedRecordIds(), function (r) {
699 var url = '/eg2/staff/catalog/record/' + r + '/holds';
700 $timeout(function() { $window.open(url, '_blank') });
704 $scope.selectedHoldingsVolCopyEdit = function () {
705 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,false);
707 $scope.selectedHoldingsVolEdit = function () {
708 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,true);
710 $scope.selectedHoldingsCopyEdit = function () {
711 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),true,false);
714 $scope.changeItemOwningLib = function() {
715 itemSvc.changeItemOwningLib(copyGrid.selectedItems());
718 $scope.transferItems = function (){
719 itemSvc.transferItems(copyGrid.selectedItems());
722 $scope.print_labels = function() {
725 'open-ils.actor.anon_cache.set_value',
726 null, 'print-labels-these-copies', {
727 copies : gatherSelectedHoldingsIds()
729 ).then(function(key) {
731 var url = egCore.env.basePath + 'cat/printlabels/' + key;
732 $timeout(function() { $window.open(url, '_blank') });
734 alert('Could not create anonymous cache key!');
739 $scope.print_list = function() {
740 var print_data = { copies : copyGrid.allItems() };
742 if (print_data.copies.length == 0) return $q.when();
744 return egCore.print.print({
745 template : 'item_status',
750 $scope.show_in_catalog = function(){
751 itemSvc.show_in_catalog(copyGrid.selectedItems());
754 if (copyId.length > 0) {
756 angular.forEach(copyId, function (c) {
757 fetch_list.push(itemSvc.fetch(null,c));
760 return $q.all(fetch_list).then(function (res) { copyGrid.refresh(); });
763 $scope.statusIconColumn = {
765 template: function(item) {
767 if (modified_items.has(item['id'])) {
768 icon = '<span class="glyphicon glyphicon-floppy-saved"' +
769 'title="' + egCore.strings.ITEM_SUCCESSFULLY_MODIFIED + '" ' +
770 'aria-label="' + egCore.strings.ITEM_SUCCESSFULLY_MODIFIED + '">' +
777 if (typeof BroadcastChannel != 'undefined') {
778 var holdings_bChannel = new BroadcastChannel("eg.holdings.update");
779 holdings_bChannel.onmessage = function(e) {
780 angular.forEach(e.data.copies, function(i) {
781 modified_items.add(i);
783 ngToast.create(egCore.strings.ITEMS_SUCCESSFULLY_MODIFIED);
784 $scope.refreshGridData();
786 $scope.$on('$destroy', function() {
787 holdings_bChannel.close();
794 * Detail view -- shows one copy
796 .controller('ViewCtrl',
797 ['$scope','$q','egGridDataProvider','$location','$routeParams','$timeout','$window','egCore','egItem','egBilling','egCirc',
798 function($scope , $q , egGridDataProvider , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling , egCirc) {
799 var copyId = $routeParams.id;
800 $scope.args.copyId = copyId;
801 $scope.tab = $routeParams.tab || 'summary';
802 $scope.context.page = 'detail';
803 $scope.summaryRecord = null;
804 $scope.courseModulesOptIn = fetchCourseOptIn();
805 $scope.has_course_perms = fetchCoursePerms();
807 if ($scope.tab == 'edit') {
808 $scope.tab = 'summary';
812 // use the cached record info
814 $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
815 return !aca.ack_time();
817 $scope.recordId = itemSvc.copy.call_number().record().id();
818 $scope.args.recordId = $scope.recordId;
819 $scope.args.cnId = itemSvc.copy.call_number().id();
820 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
821 $scope.args.cnLabel = itemSvc.copy.call_number().label();
822 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
823 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
824 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
825 $scope.args.copyBarcode = itemSvc.copy.barcode();
828 function loadCopy(barcode) {
829 $scope.context.itemNotFound = false;
831 // Avoid re-fetching the same copy while jumping tabs.
832 // In addition to being quicker, this helps to avoid flickering
833 // of the top panel which is always visible in the detail view.
835 // 'barcode' represents the loading of a new item - refetch it
836 // regardless of whether it matches the current item.
837 if (!barcode && itemSvc.copy && itemSvc.copy.id() == copyId) {
838 $scope.copy = itemSvc.copy;
839 if (itemSvc.latest_inventory && itemSvc.latest_inventory.copy() == copyId) {
840 $scope.latest_inventory = itemSvc.latest_inventory;
842 $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
843 return !aca.ack_time();
845 $scope.recordId = itemSvc.copy.call_number().record().id();
846 $scope.args.recordId = $scope.recordId;
847 $scope.args.cnId = itemSvc.copy.call_number().id();
848 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
849 $scope.args.cnLabel = itemSvc.copy.call_number().label();
850 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
851 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
852 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
853 $scope.args.copyBarcode = itemSvc.copy.barcode();
860 var deferred = $q.defer();
861 itemSvc.fetch(barcode, copyId, true).then(function(res) {
862 $scope.context.selectBarcode = true;
866 $scope.context.itemNotFound = true;
867 egCore.audio.play('warning.item_status.itemNotFound');
868 deferred.reject(); // avoid propagation of data fetch calls
874 if (res.latest_inventory) itemSvc.latest_inventory = res.latest_inventory;
878 $scope.latest_inventory = res.latest_inventory;
879 $scope.copy_alert_count = copy.copy_alerts().filter(function(aca) {
880 return !aca.ack_time();
882 console.debug($scope.copy_alert_count);
883 $scope.recordId = copy.call_number().record().id();
884 $scope.args.recordId = $scope.recordId;
885 $scope.args.cnId = itemSvc.copy.call_number().id();
886 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
887 $scope.args.cnLabel = itemSvc.copy.call_number().label();
888 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
889 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
890 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
891 $scope.args.copyBarcode = copy.barcode();
892 $scope.args.barcode = '';
894 // locally flesh org units
895 copy.circ_lib(egCore.org.get(copy.circ_lib()));
896 copy.call_number().owning_lib(
897 egCore.org.get(copy.call_number().owning_lib()));
899 var r = copy.call_number().record();
900 if (r.owner()) r.owner(egCore.org.get(r.owner()));
902 // make boolean for auto-magic true/false display
904 ['ref','opac_visible','holdable','circulate'],
905 function(field) { copy[field](Boolean(copy[field]() == 't')) }
908 // finally, if this is a different copy, redirect.
909 // Note that we flesh first since the copy we just
910 // fetched will be used after the redirect.
911 if (copyId && copyId != copy.id()) {
912 // if a new barcode is scanned in the detail view,
913 // update the url to match the ID of the new copy
914 $location.path('/cat/item/' + copy.id() + '/' + $scope.tab);
915 deferred.reject(); // avoid propagation of data fetch calls
923 return deferred.promise;
926 // load the two most recent circulations in /circs tab
927 function loadCurrentCirc() {
929 delete $scope.circ_summary;
930 delete $scope.prev_circ_summary;
931 delete $scope.prev_circ_usr;
935 itemSvc.copy.call_number().id() == -1 ?
936 itemSvc.copy.circ_lib().id() :
937 itemSvc.copy.call_number().owning_lib().id();
939 // since a user can still view patron checkout history here, check perms
940 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
941 .then(function(orgIds){
942 if(orgIds.indexOf(copy_org) == -1){
943 console.warn('User is not allowed to view circ history!');
947 return fetchMaxCircHistory();
949 .then(function(maxHistCount){
951 if (!maxHistCount) $scope.isMaxCircHistoryZero = true;
953 egCore.pcrud.search('aacs',
954 {target_copy : copyId},
960 'checkin_workstation',
963 'recurring_fine_rule'
967 order_by : {aacs : 'xact_start desc'},
971 ).then(null, null, function(circ) {
974 if (!circ) return $q.when();
976 // load the chain for this circ
979 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
980 egCore.auth.token(), $scope.circ.id()
981 ).then(function(summary) {
982 $scope.circ_summary = summary;
985 if (maxHistCount <= 1) return;
987 // load the chain for the previous circ, plus the user
990 'open-ils.circ.prev_renewal_chain.retrieve_by_circ.summary',
991 egCore.auth.token(), $scope.circ.id()
993 ).then(null, null, function(summary) {
994 $scope.prev_circ_summary = summary.summary;
996 if (summary.usr) { // aged circs have no 'usr'.
997 egCore.pcrud.retrieve('au', summary.usr,
998 {flesh : 1, flesh_fields : {au : ['card']}})
1000 .then(function(user) { $scope.prev_circ_usr = user });
1008 function fetchMaxCircHistory() {
1009 if (maxHistory) return $q.when(maxHistory);
1010 return egCore.org.settings(
1011 'circ.item_checkout_history.max')
1012 .then(function(set) {
1013 maxHistory = set['circ.item_checkout_history.max'] || 4;
1014 return Number(maxHistory);
1018 // Check for Course Modules Opt-In to enable Course Info tab
1019 function fetchCourseOptIn() {
1020 return egCore.org.settings(
1021 'circ.course_materials_opt_in'
1022 ).then(function(set) {
1023 $scope.courseModulesOptIn = set['circ.course_materials_opt_in'];
1025 return $scope.courseModulesOptIn;
1029 function fetchCoursePerms() {
1030 return egCore.perm.hasPermAt('MANAGE RESERVES', true).then(function(orgIds) {
1031 if(orgIds.indexOf(egCore.auth.user().ws_ou()) != -1){
1032 $scope.has_course_perms = true;
1034 return $scope.has_course_perms;
1039 $scope.addBilling = function(circ) {
1040 egBilling.showBillDialog({
1041 xact_id : circ.id(),
1046 $scope.retrieveAllPatrons = function() {
1047 var users = new Set();
1048 angular.forEach($scope.circ_list.map(function(circ) { return circ.usr(); }),function(usr) {
1049 // aged circs have no 'usr'.
1050 if (usr) users.add(usr);
1052 users.forEach(function(usr) {
1053 $timeout(function() {
1054 var url = $location.absUrl().replace(
1056 '/circ/patron/' + usr.id() + '/checkout');
1057 $window.open(url, '_blank')
1062 // load data for /circ_list tab
1063 function loadCircHistory() {
1064 $scope.circ_list = [];
1067 itemSvc.copy.call_number().id() == -1 ?
1068 itemSvc.copy.circ_lib().id() :
1069 itemSvc.copy.call_number().owning_lib().id();
1071 // there is an extra layer of permissibility over circ
1073 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
1074 .then(function(orgIds) {
1076 if (orgIds.indexOf(copy_org) == -1) {
1077 console.log('User is not allowed to view circ history');
1081 return fetchMaxCircHistory();
1083 }).then(function(maxHistCount) {
1085 if(!maxHistCount) $scope.isMaxCircHistoryZero = true;
1087 egCore.pcrud.search('aacs',
1088 {target_copy : copyId},
1094 'checkin_workstation',
1095 'recurring_fine_rule',
1100 order_by : {aacs : 'xact_start desc'},
1101 // fetch at least one to see if copy ever circulated
1102 limit : $scope.isMaxCircHistoryZero ? 1 : maxHistCount
1105 ).then(null, null, function(circ) {
1109 // flesh circ_lib locally
1110 circ.circ_lib(egCore.org.get(circ.circ_lib()));
1111 circ.checkin_lib(egCore.org.get(circ.checkin_lib()));
1112 $scope.circ_list.push(circ);
1118 function loadCircCounts() {
1120 delete $scope.circ_counts;
1121 $scope.total_circs = 0;
1122 $scope.total_circs_this_year = 0;
1123 $scope.total_circs_prev_year = 0;
1124 $scope.circ_popover_placement = 'top';
1125 if (!copyId) return;
1127 egCore.pcrud.search('circbyyr',
1128 {copy : copyId}, null, {atomic : true})
1130 .then(function(counts) {
1131 var this_year = new Date().getFullYear();
1132 var prev_year = this_year - 1;
1134 $scope.circ_counts = counts.reduce(function(circ_counts, circbyyr) {
1135 var count = Number(circbyyr.count());
1136 var year = Number(circbyyr.year());
1138 var index = circ_counts.findIndex(function(existing_count) {
1139 return existing_count.year === year;
1143 circ_counts.push({count: count, year: year});
1145 circ_counts[index].count += count;
1148 $scope.total_circs += count;
1149 if (this_year === year) {
1150 $scope.total_circs_this_year += count;
1152 if (prev_year === year) {
1153 $scope.total_circs_prev_year += count;
1159 if ($scope.circ_counts.length > 15) {
1160 $scope.circ_popover_placement = 'right';
1165 function loadHolds() {
1167 if (!copyId) return;
1169 egCore.pcrud.search('ahr',
1170 { current_copy : copyId,
1172 fulfillment_time : null,
1173 capture_time : {'<>' : null}
1177 ahr : ['requestor', 'usr'],
1181 ).then(null, null, function(hold) {
1183 hold.pickup_lib(egCore.org.get(hold.pickup_lib()));
1184 if (hold.current_shelf_lib()) {
1185 hold.current_shelf_lib(
1186 egCore.org.get(hold.current_shelf_lib()));
1188 hold.behind_desk(Boolean(hold.behind_desk() == 't'));
1192 function loadMostRecentTransit() {
1193 delete $scope.transit;
1194 delete $scope.hold_transit;
1195 if (!copyId) return;
1197 egCore.pcrud.search('atc',
1198 {target_copy : copyId},
1200 order_by : {atc : 'source_send_time DESC'},
1204 ).then(null, null, function(transit) {
1205 // use progress callback since we'll get up to one result
1206 $scope.transit = transit;
1207 transit.source(egCore.org.get(transit.source()));
1208 transit.dest(egCore.org.get(transit.dest()));
1212 function loadCourseInfo() {
1213 delete $scope.courses;
1214 delete $scope.instructors;
1215 delete $scope.course_ids;
1216 delete $scope.instructors_exist;
1217 if (!copyId) return;
1218 $scope.course_ids = [];
1219 $scope.courses = [];
1220 $scope.instructors = {};
1222 egCore.pcrud.search('acmcm', {
1228 }, order_by: {acmc : 'id desc'}
1229 }).then(null, null, function(material) {
1231 $scope.courses.push(material.course());
1234 'open-ils.circ.course_users.retrieve',
1235 material.course().id()
1236 ).then(null, null, function(instructors) {
1237 angular.forEach(instructors, function(instructor) {
1238 var patron_id = instructor.patron_id.toString();
1239 if (!$scope.instructors[patron_id]) {
1240 $scope.instructors[patron_id] = instructor;
1241 $scope.instructors_exist = true;
1242 $scope.instructors[patron_id]._linked_course = [];
1244 $scope.instructors[patron_id]._linked_course.push({
1245 role: instructor.usr_role,
1246 course: material.course().name()
1254 // we don't need all data on all tabs, so fetch what's needed when needed.
1255 function loadTabData() {
1256 switch($scope.tab) {
1272 loadMostRecentTransit();
1279 case 'triggered_events':
1280 var url = $location.absUrl().replace(/\/staff\/.*/, '/actor/user/event_log');
1281 url += '?copy_id=' + encodeURIComponent(copyId);
1282 $scope.triggered_events_url = url;
1289 'open-ils.actor.anon_cache.set_value',
1290 null, 'edit-these-copies', {
1291 record_id: $scope.recordId,
1296 ).then(function(key) {
1298 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1299 $window.location.href = url;
1301 alert('Could not create anonymous cache key!');
1309 $scope.addCopyAlerts = function(copy_id) {
1310 egCirc.add_copy_alerts([copy_id]).then(function() {
1312 loadCopy($scope.copy.barcode()).then(loadTabData);
1315 $scope.manageCopyAlerts = function(copy_id) {
1316 egCirc.manage_copy_alerts([copy_id]).then(function() {
1318 loadCopy($scope.copy.barcode()).then(loadTabData);
1322 $scope.context.toggleDisplay = function() {
1323 $location.path('/cat/item/search');
1326 // handle the barcode scan box, which will replace our current copy
1327 $scope.context.search = function(args) {
1328 loadCopy(args.barcode).then(loadTabData);
1331 $scope.context.show_triggered_events = function() {
1332 window.open('/eg2/staff/circ/item/event-log/' + copyId, '_blank');
1335 loadCopy().then(loadTabData);