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',
56 function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , egCirc) {
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 = '/eg/acq/po/view/' + 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) {
159 $timeout(function() { location.href = location.href; }, 1000);
163 $scope.show_triggered_events = function() {
164 $location.path('/cat/item/' + $scope.args.copyId + '/triggered_events');
167 $scope.show_item_holds = function() {
168 $location.path('/cat/item/' + $scope.args.copyId + '/holds');
171 $scope.show_record_holds = function() {
172 window.open('/eg2/staff/catalog/record/' + $scope.args.recordId + '/holds', '_blank');
175 $scope.add_item_alerts = function() {
176 egCirc.add_copy_alerts([$scope.args.copyId]);
179 $scope.manage_item_alerts = function() {
180 egCirc.manage_copy_alerts([$scope.args.copyId]);
184 $scope.attach_to_peer_bib = function() {
185 itemSvc.attach_to_peer_bib([{
186 id : $scope.args.copyId,
187 barcode : $scope.args.copyBarcode
191 $scope.selectedHoldingsCopyDelete = function () {
192 itemSvc.selectedHoldingsCopyDelete([{
193 id : $scope.args.copyId,
194 barcode : $scope.args.copyBarcode
198 $scope.checkin = function () {
200 id : $scope.args.copyId,
201 barcode : $scope.args.copyBarcode
205 $scope.renew = function () {
207 id : $scope.args.copyId,
208 barcode : $scope.args.copyBarcode
212 $scope.cancel_transit = function () {
213 itemSvc.cancel_transit([{
214 id : $scope.args.copyId,
215 barcode : $scope.args.copyBarcode
219 $scope.selectedHoldingsDamaged = function () {
220 itemSvc.selectedHoldingsDamaged([{
221 id : $scope.args.copyId,
222 barcode : $scope.args.copyBarcode,
227 $scope.selectedHoldingsDiscard = function () {
228 itemSvc.selectedHoldingsDiscard([{
229 id : $scope.args.copyId,
230 barcode : $scope.args.barcode
234 $scope.selectedHoldingsMissing = function () {
235 itemSvc.selectedHoldingsMissing([{
236 id : $scope.args.copyId,
237 barcode : $scope.args.barcode
241 $scope.selectedHoldingsVolCopyAdd = function () {
242 itemSvc.spawnHoldingsAdd([{
243 id : $scope.args.copyId,
244 'call_number.owning_lib' : $scope.args.cnOwningLib,
245 'call_number.record.id' : $scope.args.recordId,
246 barcode : $scope.args.copyBarcode
249 $scope.selectedHoldingsCopyAdd = function () {
250 itemSvc.spawnHoldingsAdd([{
251 id : $scope.args.copyId,
252 'call_number.id' : $scope.args.cnId,
253 'call_number.owning_lib' : $scope.args.cnOwningLib,
254 'call_number.record.id' : $scope.args.recordId,
255 barcode : $scope.args.copyBarcode
259 $scope.selectedHoldingsVolCopyEdit = function () {
260 itemSvc.spawnHoldingsEdit([{
261 id : $scope.args.copyId,
262 'call_number.id' : $scope.args.cnId,
263 'call_number.owning_lib' : $scope.args.cnOwningLib,
264 'call_number.record.id' : $scope.args.recordId,
265 barcode : $scope.args.copyBarcode
268 $scope.selectedHoldingsVolEdit = function () {
269 itemSvc.spawnHoldingsEdit([{
270 id : $scope.args.copyId,
271 'call_number.id' : $scope.args.cnId,
272 'call_number.owning_lib' : $scope.args.cnOwningLib,
273 'call_number.record.id' : $scope.args.recordId,
274 barcode : $scope.args.copyBarcode
277 $scope.selectedHoldingsCopyEdit = function () {
278 itemSvc.spawnHoldingsEdit([{
279 id : $scope.args.copyId,
280 'call_number.id' : $scope.args.cnId,
281 'call_number.owning_lib' : $scope.args.cnOwningLib,
282 'call_number.record.id' : $scope.args.recordId,
283 barcode : $scope.args.copyBarcode
287 $scope.replaceBarcodes = function() {
288 itemSvc.replaceBarcodes([{
289 id : $scope.args.copyId,
290 barcode : $scope.args.copyBarcode
294 $scope.changeItemOwningLib = function() {
295 itemSvc.changeItemOwningLib([{
296 id : $scope.args.copyId,
297 'call_number.id' : $scope.args.cnId,
298 'call_number.owning_lib' : $scope.args.cnOwningLib,
299 'call_number.record.id' : $scope.args.recordId,
300 'call_number.label' : $scope.args.cnLabel,
301 'call_number.label_class' : $scope.args.cnLabelClass,
302 'call_number.prefix.id' : $scope.args.cnPrefixId,
303 'call_number.suffix.id' : $scope.args.cnSuffixId,
304 barcode : $scope.args.copyBarcode
308 $scope.transferItems = function (){
309 itemSvc.transferItems([{
310 id : $scope.args.copyId,
311 barcode : $scope.args.copyBarcode
318 * List view - grid stuff
320 .controller('ListCtrl',
321 ['$scope','$q','$routeParams','$location','$timeout','$window','egCore',
322 'egGridDataProvider','egItem','egUser','$uibModal','egCirc','egConfirmDialog',
323 'egProgressDialog', 'ngToast',
324 // function($scope , $q , $routeParams , $location , $timeout , $window , egCore ,
325 // egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog,
326 // egProgressDialog, ngToast) {
327 function($scope , $q , $routeParams , $location , $timeout , $window , egCore , egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog,
328 egProgressDialog, ngToast) {
330 var cp_list = $routeParams.idList;
332 copyId = cp_list.split(',');
335 var modified_items = new Set();
337 $scope.context.page = 'list';
340 var provider = egGridDataProvider.instance();
341 provider.get = function(offset, count) {
345 $scope.gridDataProvider = egGridDataProvider.instance({
346 get : function(offset, count) {
347 //return provider.arrayNotifier(itemSvc.copies, offset, count);
348 return this.arrayNotifier(itemSvc.copies, offset, count);
352 // If a copy was just displayed in the detail view, ensure it's
353 // focused in the list view.
354 var selected = false;
355 var copyGrid = $scope.gridControls = {
356 itemRetrieved : function(item) {
357 if (selected || !itemSvc.copy) return;
358 if (itemSvc.copy.id() == item.id) {
359 copyGrid.selectItems([item.index]);
365 $scope.$watch('barcodesFromFile', function(newVal, oldVal) {
366 $scope.context.itemsNotFound = [];
367 $scope.context.fileDoneLoading = false;
368 $scope.context.numBarcodesInFile = 0;
369 if (newVal && newVal != oldVal) {
370 $scope.args.barcode = '';
373 angular.forEach(newVal.split(/\r?\n/), function(line) {
374 //remove all whitespace and commas
375 line = line.replace(/[\s,]+/g,'');
377 //Or remove leading/trailing whitespace
378 //line = line.replace(/(^[\s,]+|[\s,]+$/g,'');
384 // Serialize copy retrieval since there may be many, many copies.
385 function fetch_next_copy() {
386 var barcode = barcodes.pop();
387 egProgressDialog.increment();
389 if (barcode == undefined) { // All done here.
390 egProgressDialog.close();
392 if(itemSvc.copies[0]){ // Were any copies actually retrieved
393 copyGrid.selectItems([itemSvc.copies[0].index]);
395 $scope.context.fileDoneLoading = true;
399 itemSvc.fetch(barcode).then(function(item) {
401 $scope.context.itemsNotFound.push(barcode);
407 if (barcodes.length) {
408 $scope.context.numBarcodesInFile = barcodes.length;
409 egProgressDialog.open({value: 0, max: barcodes.length});
415 $scope.context.search = function(args) {
416 if (!args.barcode) return;
417 $scope.context.itemNotFound = false;
418 itemSvc.fetch(args.barcode).then(function(res) {
421 copyGrid.selectItems([res.index]);
422 $scope.args.barcode = '';
424 $scope.context.itemNotFound = true;
425 egCore.audio.play('warning.item_status.itemNotFound');
427 $scope.context.selectBarcode = true;
431 var add_barcode_to_list = function (b) {
432 //console.log('listCtrl: add_barcode_to_list',b);
433 $scope.context.search({barcode:b});
435 itemSvc.add_barcode_to_list = add_barcode_to_list;
437 $scope.context.toggleDisplay = function() {
438 var item = copyGrid.selectedItems()[0];
440 $location.path('/cat/item/' + item.id);
443 $scope.context.show_triggered_events = function() {
444 var item = copyGrid.selectedItems()[0];
446 $location.path('/cat/item/' + item.id + '/triggered_events');
449 function gatherSelectedRecordIds () {
452 copyGrid.selectedItems(),
454 if (rid_list.indexOf(item['call_number.record.id']) == -1)
455 rid_list.push(item['call_number.record.id'])
461 function gatherSelectedVolumeIds (rid) {
464 copyGrid.selectedItems(),
466 if (rid && item['call_number.record.id'] != rid) return;
467 if (cn_id_list.indexOf(item['call_number.id']) == -1)
468 cn_id_list.push(item['call_number.id'])
474 function gatherSelectedHoldingsIds (rid) {
477 copyGrid.selectedItems(),
479 if (rid && item['call_number.record.id'] != rid) return;
480 cp_id_list.push(item.id)
486 function gatherSelectedHoldingsRecords() {
487 var record_id_list = [];
489 copyGrid.selectedItems(),
491 record_id_list.push(item['call_number.record.id']);
494 return record_id_list;
497 $scope.refreshGridData = function() {
498 var chain = $q.when();
499 var all_items = itemSvc.copies.map(function(item) {
502 angular.forEach(all_items.reverse(), function(i) {
503 itemSvc.copies.shift();
504 chain = chain.then(function() {
505 return itemSvc.fetch(null, i);
508 return chain.then(function() {
514 $scope.add_copies_to_bucket = function() {
515 var copy_list = gatherSelectedHoldingsIds();
516 itemSvc.add_copies_to_bucket(copy_list);
519 $scope.add_records_to_bucket = function() {
520 var record_list = gatherSelectedHoldingsRecords();
521 itemSvc.add_copies_to_bucket(record_list, 'biblio');
524 $scope.locateAcquisition = function() {
525 if (gatherSelectedHoldingsIds) {
526 var cp_list = gatherSelectedHoldingsIds();
528 if (cp_list.length > 0) {
529 $scope.openAcquisitionLineItem(cp_list);
535 $scope.update_inventory = function() {
536 var copy_list = gatherSelectedHoldingsIds();
537 itemSvc.updateInventory(copy_list, $scope.gridControls.allItems()).then(function(res) {
539 $scope.gridControls.allItems(res);
540 ngToast.create(egCore.strings.SUCCESS_UPDATE_INVENTORY);
542 ngToast.warning(egCore.strings.FAIL_UPDATE_INVENTORY);
547 $scope.need_one_selected = function() {
548 var items = $scope.gridControls.selectedItems();
549 if (items.length == 1) return false;
553 $scope.make_copies_bookable = function() {
554 itemSvc.make_copies_bookable(copyGrid.selectedItems());
557 $scope.book_copies_now = function() {
558 var item = copyGrid.selectedItems()[0];
560 itemSvc.book_copies_now(item.barcode);
563 $scope.manage_reservations = function() {
564 var item = copyGrid.selectedItems()[0];
566 itemSvc.manage_reservations(item.barcode);
569 $scope.requestItems = function() {
570 var copy_list = gatherSelectedHoldingsIds();
571 var record_list = gatherSelectedRecordIds();
572 itemSvc.requestItems(copy_list,record_list);
575 $scope.replaceBarcodes = function() {
576 itemSvc.replaceBarcodes(copyGrid.selectedItems());
579 $scope.attach_to_peer_bib = function() {
580 itemSvc.attach_to_peer_bib(copyGrid.selectedItems());
583 $scope.selectedHoldingsCopyDelete = function () {
584 itemSvc.selectedHoldingsCopyDelete(copyGrid.selectedItems());
587 $scope.selectedHoldingsItemStatusTgrEvt= function() {
588 var item = copyGrid.selectedItems()[0];
590 $location.path('/cat/item/' + item.id + '/triggered_events');
593 $scope.selectedHoldingsItemStatusHolds= function() {
594 var item = copyGrid.selectedItems()[0];
596 $location.path('/cat/item/' + item.id + '/holds');
599 $scope.cancel_transit = function () {
600 itemSvc.cancel_transit(copyGrid.selectedItems());
603 $scope.selectedHoldingsDamaged = function () {
604 itemSvc.selectedHoldingsDamaged(copyGrid.selectedItems());
607 $scope.selectedHoldingsDiscard = function () {
608 itemSvc.selectedHoldingsDiscard(copyGrid.selectedItems());
611 $scope.selectedHoldingsMissing = function () {
612 itemSvc.selectedHoldingsMissing(copyGrid.selectedItems());
615 $scope.checkin = function () {
616 itemSvc.checkin(copyGrid.selectedItems());
619 $scope.renew = function () {
620 itemSvc.renew(copyGrid.selectedItems());
623 $scope.selectedHoldingsVolCopyAdd = function () {
624 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),true,false);
626 $scope.selectedHoldingsCopyAdd = function () {
627 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),false,true);
630 $scope.selectedHoldingsCopyAlertsAdd = function(items) {
632 angular.forEach(items, function(item) {
633 if (item.id) copy_ids.push(item.id);
635 egCirc.add_copy_alerts(copy_ids).then(function() {
636 // update grid items?
640 $scope.selectedHoldingsCopyAlertsEdit = function(items) {
642 angular.forEach(items, function(item) {
643 if (item.id) copy_ids.push(item.id);
645 egCirc.manage_copy_alerts(copy_ids).then(function() {
646 // update grid items?
650 $scope.gridCellHandlers = {};
651 $scope.gridCellHandlers.copyAlertsEdit = function(id) {
652 egCirc.manage_copy_alerts([id]).then(function() {
653 // update grid items?
657 $scope.showBibHolds = function () {
658 angular.forEach(gatherSelectedRecordIds(), function (r) {
659 var url = '/eg2/staff/catalog/record/' + r + '/holds';
660 $timeout(function() { $window.open(url, '_blank') });
664 $scope.selectedHoldingsVolCopyEdit = function () {
665 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,false);
667 $scope.selectedHoldingsVolEdit = function () {
668 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,true);
670 $scope.selectedHoldingsCopyEdit = function () {
671 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),true,false);
674 $scope.changeItemOwningLib = function() {
675 itemSvc.changeItemOwningLib(copyGrid.selectedItems());
678 $scope.transferItems = function (){
679 itemSvc.transferItems(copyGrid.selectedItems());
682 $scope.print_labels = function() {
685 'open-ils.actor.anon_cache.set_value',
686 null, 'print-labels-these-copies', {
687 copies : gatherSelectedHoldingsIds()
689 ).then(function(key) {
691 var url = egCore.env.basePath + 'cat/printlabels/' + key;
692 $timeout(function() { $window.open(url, '_blank') });
694 alert('Could not create anonymous cache key!');
699 $scope.print_list = function() {
700 var print_data = { copies : copyGrid.allItems() };
702 if (print_data.copies.length == 0) return $q.when();
704 return egCore.print.print({
705 template : 'item_status',
710 $scope.show_in_catalog = function(){
711 itemSvc.show_in_catalog(copyGrid.selectedItems());
714 if (copyId.length > 0) {
716 angular.forEach(copyId, function (c) {
717 fetch_list.push(itemSvc.fetch(null,c));
720 return $q.all(fetch_list).then(function (res) { copyGrid.refresh(); });
723 $scope.statusIconColumn = {
725 template: function(item) {
727 if (modified_items.has(item['id'])) {
728 icon = '<span class="glyphicon glyphicon-floppy-saved"' +
729 'title="' + egCore.strings.ITEM_SUCCESSFULLY_MODIFIED + '" ' +
730 'aria-label="' + egCore.strings.ITEM_SUCCESSFULLY_MODIFIED + '">' +
737 if (typeof BroadcastChannel != 'undefined') {
738 var holdings_bChannel = new BroadcastChannel("eg.holdings.update");
739 holdings_bChannel.onmessage = function(e) {
740 angular.forEach(e.data.copies, function(i) {
741 modified_items.add(i);
743 ngToast.create(egCore.strings.ITEMS_SUCCESSFULLY_MODIFIED);
744 $scope.refreshGridData();
746 $scope.$on('$destroy', function() {
747 holdings_bChannel.close();
754 * Detail view -- shows one copy
756 .controller('ViewCtrl',
757 ['$scope','$q','$location','$routeParams','$timeout','$window','egCore','egItem','egBilling','egCirc',
758 function($scope , $q , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling , egCirc) {
759 var copyId = $routeParams.id;
760 $scope.args.copyId = copyId;
761 $scope.tab = $routeParams.tab || 'summary';
762 $scope.context.page = 'detail';
763 $scope.summaryRecord = null;
766 if ($scope.tab == 'edit') {
767 $scope.tab = 'summary';
772 // use the cached record info
774 $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
775 return !aca.ack_time();
777 $scope.recordId = itemSvc.copy.call_number().record().id();
778 $scope.args.recordId = $scope.recordId;
779 $scope.args.cnId = itemSvc.copy.call_number().id();
780 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
781 $scope.args.cnLabel = itemSvc.copy.call_number().label();
782 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
783 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
784 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
785 $scope.args.copyBarcode = itemSvc.copy.barcode();
788 function loadCopy(barcode) {
789 $scope.context.itemNotFound = false;
791 // Avoid re-fetching the same copy while jumping tabs.
792 // In addition to being quicker, this helps to avoid flickering
793 // of the top panel which is always visible in the detail view.
795 // 'barcode' represents the loading of a new item - refetch it
796 // regardless of whether it matches the current item.
797 if (!barcode && itemSvc.copy && itemSvc.copy.id() == copyId) {
798 $scope.copy = itemSvc.copy;
799 if (itemSvc.latest_inventory && itemSvc.latest_inventory.copy() == copyId) {
800 $scope.latest_inventory = itemSvc.latest_inventory;
802 $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
803 return !aca.ack_time();
805 $scope.recordId = itemSvc.copy.call_number().record().id();
806 $scope.args.recordId = $scope.recordId;
807 $scope.args.cnId = itemSvc.copy.call_number().id();
808 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
809 $scope.args.cnLabel = itemSvc.copy.call_number().label();
810 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
811 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
812 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
813 $scope.args.copyBarcode = itemSvc.copy.barcode();
820 var deferred = $q.defer();
821 itemSvc.fetch(barcode, copyId, true).then(function(res) {
822 $scope.context.selectBarcode = true;
826 $scope.context.itemNotFound = true;
827 egCore.audio.play('warning.item_status.itemNotFound');
828 deferred.reject(); // avoid propagation of data fetch calls
834 if (res.latest_inventory) itemSvc.latest_inventory = res.latest_inventory;
838 $scope.latest_inventory = res.latest_inventory;
839 $scope.copy_alert_count = copy.copy_alerts().filter(function(aca) {
840 return !aca.ack_time();
842 console.debug($scope.copy_alert_count);
843 $scope.recordId = copy.call_number().record().id();
844 $scope.args.recordId = $scope.recordId;
845 $scope.args.cnId = itemSvc.copy.call_number().id();
846 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
847 $scope.args.cnLabel = itemSvc.copy.call_number().label();
848 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
849 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
850 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
851 $scope.args.copyBarcode = copy.barcode();
852 $scope.args.barcode = '';
854 // locally flesh org units
855 copy.circ_lib(egCore.org.get(copy.circ_lib()));
856 copy.call_number().owning_lib(
857 egCore.org.get(copy.call_number().owning_lib()));
859 var r = copy.call_number().record();
860 if (r.owner()) r.owner(egCore.org.get(r.owner()));
862 // make boolean for auto-magic true/false display
864 ['ref','opac_visible','holdable','circulate'],
865 function(field) { copy[field](Boolean(copy[field]() == 't')) }
868 // finally, if this is a different copy, redirect.
869 // Note that we flesh first since the copy we just
870 // fetched will be used after the redirect.
871 if (copyId && copyId != copy.id()) {
872 // if a new barcode is scanned in the detail view,
873 // update the url to match the ID of the new copy
874 $location.path('/cat/item/' + copy.id() + '/' + $scope.tab);
875 deferred.reject(); // avoid propagation of data fetch calls
883 return deferred.promise;
886 // load the two most recent circulations in /circs tab
887 function loadCurrentCirc() {
889 delete $scope.circ_summary;
890 delete $scope.prev_circ_summary;
891 delete $scope.prev_circ_usr;
895 itemSvc.copy.call_number().id() == -1 ?
896 itemSvc.copy.circ_lib().id() :
897 itemSvc.copy.call_number().owning_lib().id();
899 // since a user can still view patron checkout history here, check perms
900 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
901 .then(function(orgIds){
902 if(orgIds.indexOf(copy_org) == -1){
903 console.warn('User is not allowed to view circ history!');
907 return fetchMaxCircHistory();
909 .then(function(maxHistCount){
911 if (!maxHistCount) $scope.isMaxCircHistoryZero = true;
913 egCore.pcrud.search('aacs',
914 {target_copy : copyId},
920 'checkin_workstation',
923 'recurring_fine_rule'
927 order_by : {aacs : 'xact_start desc'},
931 ).then(null, null, function(circ) {
934 if (!circ) return $q.when();
936 // load the chain for this circ
939 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
940 egCore.auth.token(), $scope.circ.id()
941 ).then(function(summary) {
942 $scope.circ_summary = summary;
945 if (maxHistCount <= 1) return;
947 // load the chain for the previous circ, plus the user
950 'open-ils.circ.prev_renewal_chain.retrieve_by_circ.summary',
951 egCore.auth.token(), $scope.circ.id()
953 ).then(null, null, function(summary) {
954 $scope.prev_circ_summary = summary.summary;
956 if (summary.usr) { // aged circs have no 'usr'.
957 egCore.pcrud.retrieve('au', summary.usr,
958 {flesh : 1, flesh_fields : {au : ['card']}})
960 .then(function(user) { $scope.prev_circ_usr = user });
968 function fetchMaxCircHistory() {
969 if (maxHistory) return $q.when(maxHistory);
970 return egCore.org.settings(
971 'circ.item_checkout_history.max')
972 .then(function(set) {
973 maxHistory = set['circ.item_checkout_history.max'] || 4;
974 return Number(maxHistory);
978 $scope.addBilling = function(circ) {
979 egBilling.showBillDialog({
985 $scope.retrieveAllPatrons = function() {
986 var users = new Set();
987 angular.forEach($scope.circ_list.map(function(circ) { return circ.usr(); }),function(usr) {
988 // aged circs have no 'usr'.
989 if (usr) users.add(usr);
991 users.forEach(function(usr) {
992 $timeout(function() {
993 var url = $location.absUrl().replace(
995 '/circ/patron/' + usr.id() + '/checkout');
996 $window.open(url, '_blank')
1001 // load data for /circ_list tab
1002 function loadCircHistory() {
1003 $scope.circ_list = [];
1006 itemSvc.copy.call_number().id() == -1 ?
1007 itemSvc.copy.circ_lib().id() :
1008 itemSvc.copy.call_number().owning_lib().id();
1010 // there is an extra layer of permissibility over circ
1012 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
1013 .then(function(orgIds) {
1015 if (orgIds.indexOf(copy_org) == -1) {
1016 console.log('User is not allowed to view circ history');
1020 return fetchMaxCircHistory();
1022 }).then(function(maxHistCount) {
1024 if(!maxHistCount) $scope.isMaxCircHistoryZero = true;
1026 egCore.pcrud.search('aacs',
1027 {target_copy : copyId},
1033 'checkin_workstation',
1034 'recurring_fine_rule'
1038 order_by : {aacs : 'xact_start desc'},
1039 // fetch at least one to see if copy ever circulated
1040 limit : $scope.isMaxCircHistoryZero ? 1 : maxHistCount
1043 ).then(null, null, function(circ) {
1047 // flesh circ_lib locally
1048 circ.circ_lib(egCore.org.get(circ.circ_lib()));
1049 circ.checkin_lib(egCore.org.get(circ.checkin_lib()));
1050 $scope.circ_list.push(circ);
1056 function loadCircCounts() {
1058 delete $scope.circ_counts;
1059 $scope.total_circs = 0;
1060 $scope.total_circs_this_year = 0;
1061 $scope.total_circs_prev_year = 0;
1062 if (!copyId) return;
1064 egCore.pcrud.search('circbyyr',
1065 {copy : copyId}, null, {atomic : true})
1067 .then(function(counts) {
1068 $scope.circ_counts = counts;
1070 angular.forEach(counts, function(count) {
1071 $scope.total_circs += Number(count.count());
1074 var this_year = counts.filter(function(c) {
1075 return c.year() == new Date().getFullYear();
1078 $scope.total_circs_this_year = (function() {
1080 if (this_year.length == 2) {
1081 total = (Number(this_year[0].count()) + Number(this_year[1].count()));
1082 } else if (this_year.length == 1) {
1083 total = Number(this_year[0].count());
1088 var prev_year = counts.filter(function(c) {
1089 return c.year() == new Date().getFullYear() - 1;
1092 $scope.total_circs_prev_year = (function() {
1094 if (prev_year.length == 2) {
1095 total = (Number(prev_year[0].count()) + Number(prev_year[1].count()));
1096 } else if (prev_year.length == 1) {
1097 total = Number(prev_year[0].count());
1105 function loadHolds() {
1107 if (!copyId) return;
1109 egCore.pcrud.search('ahr',
1110 { current_copy : copyId,
1112 fulfillment_time : null,
1113 capture_time : {'<>' : null}
1117 ahr : ['requestor', 'usr'],
1121 ).then(null, null, function(hold) {
1123 hold.pickup_lib(egCore.org.get(hold.pickup_lib()));
1124 if (hold.current_shelf_lib()) {
1125 hold.current_shelf_lib(
1126 egCore.org.get(hold.current_shelf_lib()));
1128 hold.behind_desk(Boolean(hold.behind_desk() == 't'));
1132 function loadMostRecentTransit() {
1133 delete $scope.transit;
1134 delete $scope.hold_transit;
1135 if (!copyId) return;
1137 egCore.pcrud.search('atc',
1138 {target_copy : copyId},
1140 order_by : {atc : 'source_send_time DESC'},
1144 ).then(null, null, function(transit) {
1145 // use progress callback since we'll get up to one result
1146 $scope.transit = transit;
1147 transit.source(egCore.org.get(transit.source()));
1148 transit.dest(egCore.org.get(transit.dest()));
1153 // we don't need all data on all tabs, so fetch what's needed when needed.
1154 function loadTabData() {
1155 switch($scope.tab) {
1171 loadMostRecentTransit();
1174 case 'triggered_events':
1175 var url = $location.absUrl().replace(/\/staff.*/, '/actor/user/event_log');
1176 url += '?copy_id=' + encodeURIComponent(copyId);
1177 $scope.triggered_events_url = url;
1184 'open-ils.actor.anon_cache.set_value',
1185 null, 'edit-these-copies', {
1186 record_id: $scope.recordId,
1191 ).then(function(key) {
1193 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1194 $window.location.href = url;
1196 alert('Could not create anonymous cache key!');
1204 $scope.addCopyAlerts = function(copy_id) {
1205 egCirc.add_copy_alerts([copy_id]).then(function() {
1207 loadCopy($scope.copy.barcode()).then(loadTabData);
1210 $scope.manageCopyAlerts = function(copy_id) {
1211 egCirc.manage_copy_alerts([copy_id]).then(function() {
1213 loadCopy($scope.copy.barcode()).then(loadTabData);
1217 $scope.context.toggleDisplay = function() {
1218 $location.path('/cat/item/search');
1221 // handle the barcode scan box, which will replace our current copy
1222 $scope.context.search = function(args) {
1223 loadCopy(args.barcode).then(loadTabData);
1226 $scope.context.show_triggered_events = function() {
1227 $location.path('/cat/item/' + copyId + '/triggered_events');
1230 loadCopy().then(loadTabData);