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',
56 function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc) {
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.make_copies_bookable = function() {
90 itemSvc.make_copies_bookable([{
91 id : $scope.args.copyId,
92 'call_number.record.id' : $scope.args.recordId
96 $scope.book_copies_now = function() {
97 itemSvc.book_copies_now([{
98 id : $scope.args.copyId,
99 'call_number.record.id' : $scope.args.recordId
103 $scope.findAcquisition = function() {
106 $scope.openAcquisitionLineItem([$scope.args.copyId]);
109 $scope.openAcquisitionLineItem = function (cp_list) {
110 var hasResults = false;
113 angular.forEach(cp_list, function (copyId) {
117 'open-ils.acq.lineitem.retrieve.by_copy_id',
120 ).then(function (acqData) {
123 acqData = egCore.idl.toHash(acqData);
124 var url = '/eg/acq/po/view/' + acqData.purchase_order + '/' + acqData.id;
125 $timeout(function () { $window.open(url, '_blank') });
133 $q.all(promises).then(function () {
134 !hasResults ? alert('There is no corresponding purchase order for this item.') : false;
138 $scope.requestItems = function() {
139 itemSvc.requestItems([$scope.args.copyId]);
142 $scope.update_inventory = function() {
143 itemSvc.updateInventory([$scope.args.copyId], null)
144 .then(function(res) {
145 $timeout(function() { location.href = location.href; }, 1000);
149 $scope.attach_to_peer_bib = function() {
150 itemSvc.attach_to_peer_bib([{
151 id : $scope.args.copyId,
152 barcode : $scope.args.copyBarcode
156 $scope.selectedHoldingsCopyDelete = function () {
157 itemSvc.selectedHoldingsCopyDelete([{
158 id : $scope.args.copyId,
159 barcode : $scope.args.copyBarcode
163 $scope.checkin = function () {
165 id : $scope.args.copyId,
166 barcode : $scope.args.copyBarcode
170 $scope.renew = function () {
172 id : $scope.args.copyId,
173 barcode : $scope.args.copyBarcode
177 $scope.cancel_transit = function () {
178 itemSvc.cancel_transit([{
179 id : $scope.args.copyId,
180 barcode : $scope.args.copyBarcode
184 $scope.selectedHoldingsDamaged = function () {
185 itemSvc.selectedHoldingsDamaged([{
186 id : $scope.args.copyId,
187 barcode : $scope.args.copyBarcode,
192 $scope.selectedHoldingsMissing = function () {
193 itemSvc.selectedHoldingsMissing([{
194 id : $scope.args.copyId,
195 barcode : $scope.args.copyBarcode
199 $scope.selectedHoldingsVolCopyAdd = function () {
200 itemSvc.spawnHoldingsAdd([{
201 id : $scope.args.copyId,
202 'call_number.owning_lib' : $scope.args.cnOwningLib,
203 'call_number.record.id' : $scope.args.recordId,
204 barcode : $scope.args.copyBarcode
207 $scope.selectedHoldingsCopyAdd = function () {
208 itemSvc.spawnHoldingsAdd([{
209 id : $scope.args.copyId,
210 'call_number.id' : $scope.args.cnId,
211 'call_number.owning_lib' : $scope.args.cnOwningLib,
212 'call_number.record.id' : $scope.args.recordId,
213 barcode : $scope.args.copyBarcode
217 $scope.selectedHoldingsVolCopyEdit = function () {
218 itemSvc.spawnHoldingsEdit([{
219 id : $scope.args.copyId,
220 'call_number.id' : $scope.args.cnId,
221 'call_number.owning_lib' : $scope.args.cnOwningLib,
222 'call_number.record.id' : $scope.args.recordId,
223 barcode : $scope.args.copyBarcode
226 $scope.selectedHoldingsVolEdit = function () {
227 itemSvc.spawnHoldingsEdit([{
228 id : $scope.args.copyId,
229 'call_number.id' : $scope.args.cnId,
230 'call_number.owning_lib' : $scope.args.cnOwningLib,
231 'call_number.record.id' : $scope.args.recordId,
232 barcode : $scope.args.copyBarcode
235 $scope.selectedHoldingsCopyEdit = function () {
236 itemSvc.spawnHoldingsEdit([{
237 id : $scope.args.copyId,
238 'call_number.id' : $scope.args.cnId,
239 'call_number.owning_lib' : $scope.args.cnOwningLib,
240 'call_number.record.id' : $scope.args.recordId,
241 barcode : $scope.args.copyBarcode
245 $scope.replaceBarcodes = function() {
246 itemSvc.replaceBarcodes([{
247 id : $scope.args.copyId,
248 barcode : $scope.args.copyBarcode
252 $scope.changeItemOwningLib = function() {
253 itemSvc.changeItemOwningLib([{
254 id : $scope.args.copyId,
255 'call_number.id' : $scope.args.cnId,
256 'call_number.owning_lib' : $scope.args.cnOwningLib,
257 'call_number.record.id' : $scope.args.recordId,
258 'call_number.label' : $scope.args.cnLabel,
259 'call_number.label_class' : $scope.args.cnLabelClass,
260 'call_number.prefix.id' : $scope.args.cnPrefixId,
261 'call_number.suffix.id' : $scope.args.cnSuffixId,
262 barcode : $scope.args.copyBarcode
266 $scope.transferItems = function (){
267 itemSvc.transferItems([{
268 id : $scope.args.copyId,
269 barcode : $scope.args.copyBarcode
276 * List view - grid stuff
278 .controller('ListCtrl',
279 ['$scope','$q','$routeParams','$location','$timeout','$window','egCore',
280 'egGridDataProvider','egItem','egUser','$uibModal','egCirc','egConfirmDialog',
281 'egProgressDialog', 'ngToast',
282 // function($scope , $q , $routeParams , $location , $timeout , $window , egCore ,
283 // egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog,
284 // egProgressDialog, ngToast) {
285 function($scope , $q , $routeParams , $location , $timeout , $window , egCore , egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog,
286 egProgressDialog, ngToast) {
288 var cp_list = $routeParams.idList;
290 copyId = cp_list.split(',');
293 var modified_items = new Set();
295 $scope.context.page = 'list';
298 var provider = egGridDataProvider.instance();
299 provider.get = function(offset, count) {
303 $scope.gridDataProvider = egGridDataProvider.instance({
304 get : function(offset, count) {
305 //return provider.arrayNotifier(itemSvc.copies, offset, count);
306 return this.arrayNotifier(itemSvc.copies, offset, count);
310 // If a copy was just displayed in the detail view, ensure it's
311 // focused in the list view.
312 var selected = false;
313 var copyGrid = $scope.gridControls = {
314 itemRetrieved : function(item) {
315 if (selected || !itemSvc.copy) return;
316 if (itemSvc.copy.id() == item.id) {
317 copyGrid.selectItems([item.index]);
323 $scope.$watch('barcodesFromFile', function(newVal, oldVal) {
324 if (newVal && newVal != oldVal) {
325 $scope.args.barcode = '';
328 angular.forEach(newVal.split(/\n/), function(line) {
330 // scrub any trailing spaces or commas from the barcode
331 line = line.replace(/(.*?)($|\s.*|,.*)/,'$1');
335 // Serialize copy retrieval since there may be many, many copies.
336 function fetch_next_copy() {
337 var barcode = barcodes.pop();
338 egProgressDialog.increment();
340 if (!barcode) { // All done here.
341 egProgressDialog.close();
343 copyGrid.selectItems([itemSvc.copies[0].index]);
347 itemSvc.fetch(barcode).then(fetch_next_copy);
350 if (barcodes.length) {
351 egProgressDialog.open({value: 0, max: barcodes.length});
357 $scope.context.search = function(args) {
358 if (!args.barcode) return;
359 $scope.context.itemNotFound = false;
360 itemSvc.fetch(args.barcode).then(function(res) {
363 copyGrid.selectItems([res.index]);
364 $scope.args.barcode = '';
366 $scope.context.itemNotFound = true;
367 egCore.audio.play('warning.item_status.itemNotFound');
369 $scope.context.selectBarcode = true;
373 var add_barcode_to_list = function (b) {
374 //console.log('listCtrl: add_barcode_to_list',b);
375 $scope.context.search({barcode:b});
377 itemSvc.add_barcode_to_list = add_barcode_to_list;
379 $scope.context.toggleDisplay = function() {
380 var item = copyGrid.selectedItems()[0];
382 $location.path('/cat/item/' + item.id);
385 $scope.context.show_triggered_events = function() {
386 var item = copyGrid.selectedItems()[0];
388 $location.path('/cat/item/' + item.id + '/triggered_events');
391 function gatherSelectedRecordIds () {
394 copyGrid.selectedItems(),
396 if (rid_list.indexOf(item['call_number.record.id']) == -1)
397 rid_list.push(item['call_number.record.id'])
403 function gatherSelectedVolumeIds (rid) {
406 copyGrid.selectedItems(),
408 if (rid && item['call_number.record.id'] != rid) return;
409 if (cn_id_list.indexOf(item['call_number.id']) == -1)
410 cn_id_list.push(item['call_number.id'])
416 function gatherSelectedHoldingsIds (rid) {
419 copyGrid.selectedItems(),
421 if (rid && item['call_number.record.id'] != rid) return;
422 cp_id_list.push(item.id)
428 $scope.refreshGridData = function() {
429 var chain = $q.when();
430 var all_items = itemSvc.copies.map((item) => {return item.id});
431 angular.forEach(all_items.reverse(), function(i) {
432 itemSvc.copies.shift();
433 chain = chain.then(function() {
434 return itemSvc.fetch(null, i);
437 return chain.then(function() {
443 $scope.add_copies_to_bucket = function() {
444 var copy_list = gatherSelectedHoldingsIds();
445 itemSvc.add_copies_to_bucket(copy_list);
448 $scope.locateAcquisition = function() {
449 if (gatherSelectedHoldingsIds) {
450 var cp_list = gatherSelectedHoldingsIds();
452 if (cp_list.length > 0) {
453 $scope.openAcquisitionLineItem(cp_list);
459 $scope.update_inventory = function() {
460 var copy_list = gatherSelectedHoldingsIds();
461 itemSvc.updateInventory(copy_list, $scope.gridControls.allItems()).then(function(res) {
463 $scope.gridControls.allItems(res);
464 ngToast.create(egCore.strings.SUCCESS_UPDATE_INVENTORY);
466 ngToast.warning(egCore.strings.FAIL_UPDATE_INVENTORY);
471 $scope.need_one_selected = function() {
472 var items = $scope.gridControls.selectedItems();
473 if (items.length == 1) return false;
477 $scope.make_copies_bookable = function() {
478 itemSvc.make_copies_bookable(copyGrid.selectedItems());
481 $scope.book_copies_now = function() {
482 itemSvc.book_copies_now(copyGrid.selectedItems());
485 $scope.requestItems = function() {
486 var copy_list = gatherSelectedHoldingsIds();
487 itemSvc.requestItems(copy_list);
490 $scope.replaceBarcodes = function() {
491 itemSvc.replaceBarcodes(copyGrid.selectedItems());
494 $scope.attach_to_peer_bib = function() {
495 itemSvc.attach_to_peer_bib(copyGrid.selectedItems());
498 $scope.selectedHoldingsCopyDelete = function () {
499 itemSvc.selectedHoldingsCopyDelete(copyGrid.selectedItems());
502 $scope.selectedHoldingsItemStatusTgrEvt= function() {
503 var item = copyGrid.selectedItems()[0];
505 $location.path('/cat/item/' + item.id + '/triggered_events');
508 $scope.selectedHoldingsItemStatusHolds= function() {
509 var item = copyGrid.selectedItems()[0];
511 $location.path('/cat/item/' + item.id + '/holds');
514 $scope.cancel_transit = function () {
515 itemSvc.cancel_transit(copyGrid.selectedItems());
518 $scope.selectedHoldingsDamaged = function () {
519 itemSvc.selectedHoldingsDamaged(copyGrid.selectedItems());
522 $scope.selectedHoldingsMissing = function () {
523 itemSvc.selectedHoldingsMissing(copyGrid.selectedItems());
526 $scope.checkin = function () {
527 itemSvc.checkin(copyGrid.selectedItems());
530 $scope.renew = function () {
531 itemSvc.renew(copyGrid.selectedItems());
534 $scope.selectedHoldingsVolCopyAdd = function () {
535 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),true,false);
537 $scope.selectedHoldingsCopyAdd = function () {
538 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),false,true);
541 $scope.selectedHoldingsCopyAlertsAdd = function(items) {
543 angular.forEach(items, function(item) {
544 if (item.id) copy_ids.push(item.id);
546 egCirc.add_copy_alerts(copy_ids).then(function() {
547 // update grid items?
551 $scope.selectedHoldingsCopyAlertsEdit = function(items) {
553 angular.forEach(items, function(item) {
554 if (item.id) copy_ids.push(item.id);
556 egCirc.manage_copy_alerts(copy_ids).then(function() {
557 // update grid items?
561 $scope.gridCellHandlers = {};
562 $scope.gridCellHandlers.copyAlertsEdit = function(id) {
563 egCirc.manage_copy_alerts([id]).then(function() {
564 // update grid items?
568 $scope.showBibHolds = function () {
569 angular.forEach(gatherSelectedRecordIds(), function (r) {
570 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
571 $timeout(function() { $window.open(url, '_blank') });
575 $scope.selectedHoldingsVolCopyEdit = function () {
576 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,false);
578 $scope.selectedHoldingsVolEdit = function () {
579 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,true);
581 $scope.selectedHoldingsCopyEdit = function () {
582 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),true,false);
585 $scope.changeItemOwningLib = function() {
586 itemSvc.changeItemOwningLib(copyGrid.selectedItems());
589 $scope.transferItems = function (){
590 itemSvc.transferItems(copyGrid.selectedItems());
593 $scope.print_labels = function() {
596 'open-ils.actor.anon_cache.set_value',
597 null, 'print-labels-these-copies', {
598 copies : gatherSelectedHoldingsIds()
600 ).then(function(key) {
602 var url = egCore.env.basePath + 'cat/printlabels/' + key;
603 $timeout(function() { $window.open(url, '_blank') });
605 alert('Could not create anonymous cache key!');
610 $scope.print_list = function() {
611 var print_data = { copies : copyGrid.allItems() };
613 if (print_data.copies.length == 0) return $q.when();
615 return egCore.print.print({
616 template : 'item_status',
621 $scope.show_in_catalog = function(){
622 itemSvc.show_in_catalog(copyGrid.selectedItems());
625 if (copyId.length > 0) {
627 angular.forEach(copyId, function (c) {
628 fetch_list.push(itemSvc.fetch(null,c));
631 return $q.all(fetch_list).then(function (res) { copyGrid.refresh(); });
634 $scope.statusIconColumn = {
636 template: function(item) {
638 if (modified_items.has(item['id'])) {
639 icon = '<span class="glyphicon glyphicon-floppy-saved"' +
640 'title="' + egCore.strings.ITEM_SUCCESSFULLY_MODIFIED + '" ' +
641 'aria-label="' + egCore.strings.ITEM_SUCCESSFULLY_MODIFIED + '">' +
648 if (typeof BroadcastChannel != 'undefined') {
649 var holdings_bChannel = new BroadcastChannel("eg.holdings.update");
650 holdings_bChannel.onmessage = function(e) {
651 angular.forEach(e.data.copies, function(i) {
652 modified_items.add(i);
654 ngToast.create(egCore.strings.ITEMS_SUCCESSFULLY_MODIFIED);
655 $scope.refreshGridData();
657 $scope.$on('$destroy', function() {
658 holdings_bChannel.close();
665 * Detail view -- shows one copy
667 .controller('ViewCtrl',
668 ['$scope','$q','$location','$routeParams','$timeout','$window','egCore','egItem','egBilling','egCirc',
669 function($scope , $q , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling , egCirc) {
670 var copyId = $routeParams.id;
671 $scope.args.copyId = copyId;
672 $scope.tab = $routeParams.tab || 'summary';
673 $scope.context.page = 'detail';
674 $scope.summaryRecord = null;
677 if ($scope.tab == 'edit') {
678 $scope.tab = 'summary';
683 // use the cached record info
685 $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
686 return !aca.ack_time();
688 $scope.recordId = itemSvc.copy.call_number().record().id();
689 $scope.args.recordId = $scope.recordId;
690 $scope.args.cnId = itemSvc.copy.call_number().id();
691 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
692 $scope.args.cnLabel = itemSvc.copy.call_number().label();
693 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
694 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
695 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
696 $scope.args.copyBarcode = itemSvc.copy.barcode();
699 function loadCopy(barcode) {
700 $scope.context.itemNotFound = false;
702 // Avoid re-fetching the same copy while jumping tabs.
703 // In addition to being quicker, this helps to avoid flickering
704 // of the top panel which is always visible in the detail view.
706 // 'barcode' represents the loading of a new item - refetch it
707 // regardless of whether it matches the current item.
708 if (!barcode && itemSvc.copy && itemSvc.copy.id() == copyId) {
709 $scope.copy = itemSvc.copy;
710 if (itemSvc.latest_inventory && itemSvc.latest_inventory.copy() == copyId) {
711 $scope.latest_inventory = itemSvc.latest_inventory;
713 $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
714 return !aca.ack_time();
716 $scope.recordId = itemSvc.copy.call_number().record().id();
717 $scope.args.recordId = $scope.recordId;
718 $scope.args.cnId = itemSvc.copy.call_number().id();
719 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
720 $scope.args.cnLabel = itemSvc.copy.call_number().label();
721 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
722 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
723 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
724 $scope.args.copyBarcode = itemSvc.copy.barcode();
731 var deferred = $q.defer();
732 itemSvc.fetch(barcode, copyId, true).then(function(res) {
733 $scope.context.selectBarcode = true;
737 $scope.context.itemNotFound = true;
738 egCore.audio.play('warning.item_status.itemNotFound');
739 deferred.reject(); // avoid propagation of data fetch calls
745 if (res.latest_inventory) itemSvc.latest_inventory = res.latest_inventory;
749 $scope.latest_inventory = res.latest_inventory;
750 $scope.copy_alert_count = copy.copy_alerts().filter(function(aca) {
751 return !aca.ack_time();
753 console.debug($scope.copy_alert_count);
754 $scope.recordId = copy.call_number().record().id();
755 $scope.args.recordId = $scope.recordId;
756 $scope.args.cnId = itemSvc.copy.call_number().id();
757 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
758 $scope.args.cnLabel = itemSvc.copy.call_number().label();
759 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
760 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
761 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
762 $scope.args.copyBarcode = copy.barcode();
763 $scope.args.barcode = '';
765 // locally flesh org units
766 copy.circ_lib(egCore.org.get(copy.circ_lib()));
767 copy.call_number().owning_lib(
768 egCore.org.get(copy.call_number().owning_lib()));
770 var r = copy.call_number().record();
771 if (r.owner()) r.owner(egCore.org.get(r.owner()));
773 // make boolean for auto-magic true/false display
775 ['ref','opac_visible','holdable','circulate'],
776 function(field) { copy[field](Boolean(copy[field]() == 't')) }
779 // finally, if this is a different copy, redirect.
780 // Note that we flesh first since the copy we just
781 // fetched will be used after the redirect.
782 if (copyId && copyId != copy.id()) {
783 // if a new barcode is scanned in the detail view,
784 // update the url to match the ID of the new copy
785 $location.path('/cat/item/' + copy.id() + '/' + $scope.tab);
786 deferred.reject(); // avoid propagation of data fetch calls
794 return deferred.promise;
797 // load the two most recent circulations in /circs tab
798 function loadCurrentCirc() {
800 delete $scope.circ_summary;
801 delete $scope.prev_circ_summary;
802 delete $scope.prev_circ_usr;
806 itemSvc.copy.call_number().id() == -1 ?
807 itemSvc.copy.circ_lib().id() :
808 itemSvc.copy.call_number().owning_lib().id();
810 // since a user can still view patron checkout history here, check perms
811 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
812 .then(function(orgIds){
813 if(orgIds.indexOf(copy_org) == -1){
814 console.warn('User is not allowed to view circ history!');
818 return fetchMaxCircHistory();
820 .then(function(maxHistCount){
822 if (!maxHistCount) $scope.isMaxCircHistoryZero = true;
824 egCore.pcrud.search('aacs',
825 {target_copy : copyId},
831 'checkin_workstation',
834 'recurring_fine_rule'
838 order_by : {aacs : 'xact_start desc'},
842 ).then(null, null, function(circ) {
845 if (!circ) return $q.when();
847 // load the chain for this circ
850 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
851 egCore.auth.token(), $scope.circ.id()
852 ).then(function(summary) {
853 $scope.circ_summary = summary;
856 if (maxHistCount <= 1) return;
858 // load the chain for the previous circ, plus the user
861 'open-ils.circ.prev_renewal_chain.retrieve_by_circ.summary',
862 egCore.auth.token(), $scope.circ.id()
864 ).then(null, null, function(summary) {
865 $scope.prev_circ_summary = summary.summary;
867 if (summary.usr) { // aged circs have no 'usr'.
868 egCore.pcrud.retrieve('au', summary.usr,
869 {flesh : 1, flesh_fields : {au : ['card']}})
871 .then(function(user) { $scope.prev_circ_usr = user });
879 function fetchMaxCircHistory() {
880 if (maxHistory) return $q.when(maxHistory);
881 return egCore.org.settings(
882 'circ.item_checkout_history.max')
883 .then(function(set) {
884 maxHistory = set['circ.item_checkout_history.max'] || 4;
885 return Number(maxHistory);
889 $scope.addBilling = function(circ) {
890 egBilling.showBillDialog({
896 $scope.retrieveAllPatrons = function() {
897 var users = new Set();
898 angular.forEach($scope.circ_list.map(function(circ) { return circ.usr(); }),function(usr) {
899 // aged circs have no 'usr'.
900 if (usr) users.add(usr);
902 users.forEach(function(usr) {
903 $timeout(function() {
904 var url = $location.absUrl().replace(
906 '/circ/patron/' + usr.id() + '/checkout');
907 $window.open(url, '_blank')
912 // load data for /circ_list tab
913 function loadCircHistory() {
914 $scope.circ_list = [];
917 itemSvc.copy.call_number().id() == -1 ?
918 itemSvc.copy.circ_lib().id() :
919 itemSvc.copy.call_number().owning_lib().id();
921 // there is an extra layer of permissibility over circ
923 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
924 .then(function(orgIds) {
926 if (orgIds.indexOf(copy_org) == -1) {
927 console.log('User is not allowed to view circ history');
931 return fetchMaxCircHistory();
933 }).then(function(maxHistCount) {
935 if(!maxHistCount) $scope.isMaxCircHistoryZero = true;
937 egCore.pcrud.search('aacs',
938 {target_copy : copyId},
944 'checkin_workstation',
945 'recurring_fine_rule'
949 order_by : {aacs : 'xact_start desc'},
950 // fetch at least one to see if copy ever circulated
951 limit : $scope.isMaxCircHistoryZero ? 1 : maxHistCount
954 ).then(null, null, function(circ) {
958 // flesh circ_lib locally
959 circ.circ_lib(egCore.org.get(circ.circ_lib()));
960 circ.checkin_lib(egCore.org.get(circ.checkin_lib()));
961 $scope.circ_list.push(circ);
967 function loadCircCounts() {
969 delete $scope.circ_counts;
970 $scope.total_circs = 0;
971 $scope.total_circs_this_year = 0;
972 $scope.total_circs_prev_year = 0;
975 egCore.pcrud.search('circbyyr',
976 {copy : copyId}, null, {atomic : true})
978 .then(function(counts) {
979 $scope.circ_counts = counts;
981 angular.forEach(counts, function(count) {
982 $scope.total_circs += Number(count.count());
985 var this_year = counts.filter(function(c) {
986 return c.year() == new Date().getFullYear();
989 $scope.total_circs_this_year = (function() {
991 if (this_year.length == 2) {
992 total = (Number(this_year[0].count()) + Number(this_year[1].count()));
993 } else if (this_year.length == 1) {
994 total = Number(this_year[0].count());
999 var prev_year = counts.filter(function(c) {
1000 return c.year() == new Date().getFullYear() - 1;
1003 $scope.total_circs_prev_year = (function() {
1005 if (prev_year.length == 2) {
1006 total = (Number(prev_year[0].count()) + Number(prev_year[1].count()));
1007 } else if (prev_year.length == 1) {
1008 total = Number(prev_year[0].count());
1016 function loadHolds() {
1018 if (!copyId) return;
1020 egCore.pcrud.search('ahr',
1021 { current_copy : copyId,
1023 fulfillment_time : null,
1024 capture_time : {'<>' : null}
1028 ahr : ['requestor', 'usr'],
1032 ).then(null, null, function(hold) {
1034 hold.pickup_lib(egCore.org.get(hold.pickup_lib()));
1035 if (hold.current_shelf_lib()) {
1036 hold.current_shelf_lib(
1037 egCore.org.get(hold.current_shelf_lib()));
1039 hold.behind_desk(Boolean(hold.behind_desk() == 't'));
1043 function loadMostRecentTransit() {
1044 delete $scope.transit;
1045 delete $scope.hold_transit;
1046 if (!copyId) return;
1048 egCore.pcrud.search('atc',
1049 {target_copy : copyId},
1051 order_by : {atc : 'source_send_time DESC'},
1055 ).then(null, null, function(transit) {
1056 // use progress callback since we'll get up to one result
1057 $scope.transit = transit;
1058 transit.source(egCore.org.get(transit.source()));
1059 transit.dest(egCore.org.get(transit.dest()));
1064 // we don't need all data on all tabs, so fetch what's needed when needed.
1065 function loadTabData() {
1066 switch($scope.tab) {
1082 loadMostRecentTransit();
1085 case 'triggered_events':
1086 var url = $location.absUrl().replace(/\/staff.*/, '/actor/user/event_log');
1087 url += '?copy_id=' + encodeURIComponent(copyId);
1088 $scope.triggered_events_url = url;
1095 'open-ils.actor.anon_cache.set_value',
1096 null, 'edit-these-copies', {
1097 record_id: $scope.recordId,
1102 ).then(function(key) {
1104 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1105 $window.location.href = url;
1107 alert('Could not create anonymous cache key!');
1115 $scope.addCopyAlerts = function(copy_id) {
1116 egCirc.add_copy_alerts([copy_id]).then(function() {
1118 loadCopy($scope.copy.barcode()).then(loadTabData);
1121 $scope.manageCopyAlerts = function(copy_id) {
1122 egCirc.manage_copy_alerts([copy_id]).then(function() {
1124 loadCopy($scope.copy.barcode()).then(loadTabData);
1128 $scope.context.toggleDisplay = function() {
1129 $location.path('/cat/item/search');
1132 // handle the barcode scan box, which will replace our current copy
1133 $scope.context.search = function(args) {
1134 loadCopy(args.barcode).then(loadTabData);
1137 $scope.context.show_triggered_events = function() {
1138 $location.path('/cat/item/' + copyId + '/triggered_events');
1141 loadCopy().then(loadTabData);