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','$location','$timeout','egCore','egGridDataProvider','egItem',
56 function($scope , $location , $timeout , egCore , 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.requestItems = function() {
104 itemSvc.requestItems([$scope.args.copyId]);
107 $scope.update_inventory = function() {
108 itemSvc.updateInventory([$scope.args.copyId], null)
109 .then(function(res) {
110 $timeout(function() { location.href = location.href; }, 1000);
114 $scope.attach_to_peer_bib = function() {
115 itemSvc.attach_to_peer_bib([{
116 id : $scope.args.copyId,
117 barcode : $scope.args.copyBarcode
121 $scope.selectedHoldingsCopyDelete = function () {
122 itemSvc.selectedHoldingsCopyDelete([{
123 id : $scope.args.copyId,
124 barcode : $scope.args.copyBarcode
128 $scope.checkin = function () {
130 id : $scope.args.copyId,
131 barcode : $scope.args.copyBarcode
135 $scope.renew = function () {
137 id : $scope.args.copyId,
138 barcode : $scope.args.copyBarcode
142 $scope.cancel_transit = function () {
143 itemSvc.cancel_transit([{
144 id : $scope.args.copyId,
145 barcode : $scope.args.copyBarcode
149 $scope.selectedHoldingsDamaged = function () {
150 itemSvc.selectedHoldingsDamaged([{
151 id : $scope.args.copyId,
152 barcode : $scope.args.copyBarcode,
157 $scope.selectedHoldingsMissing = function () {
158 itemSvc.selectedHoldingsMissing([{
159 id : $scope.args.copyId,
160 barcode : $scope.args.copyBarcode
164 $scope.selectedHoldingsVolCopyAdd = function () {
165 itemSvc.spawnHoldingsAdd([{
166 id : $scope.args.copyId,
167 'call_number.owning_lib' : $scope.args.cnOwningLib,
168 'call_number.record.id' : $scope.args.recordId,
169 barcode : $scope.args.copyBarcode
172 $scope.selectedHoldingsCopyAdd = function () {
173 itemSvc.spawnHoldingsAdd([{
174 id : $scope.args.copyId,
175 'call_number.id' : $scope.args.cnId,
176 'call_number.owning_lib' : $scope.args.cnOwningLib,
177 'call_number.record.id' : $scope.args.recordId,
178 barcode : $scope.args.copyBarcode
182 $scope.selectedHoldingsVolCopyEdit = function () {
183 itemSvc.spawnHoldingsEdit([{
184 id : $scope.args.copyId,
185 'call_number.id' : $scope.args.cnId,
186 'call_number.owning_lib' : $scope.args.cnOwningLib,
187 'call_number.record.id' : $scope.args.recordId,
188 barcode : $scope.args.copyBarcode
191 $scope.selectedHoldingsVolEdit = function () {
192 itemSvc.spawnHoldingsEdit([{
193 id : $scope.args.copyId,
194 'call_number.id' : $scope.args.cnId,
195 'call_number.owning_lib' : $scope.args.cnOwningLib,
196 'call_number.record.id' : $scope.args.recordId,
197 barcode : $scope.args.copyBarcode
200 $scope.selectedHoldingsCopyEdit = function () {
201 itemSvc.spawnHoldingsEdit([{
202 id : $scope.args.copyId,
203 'call_number.id' : $scope.args.cnId,
204 'call_number.owning_lib' : $scope.args.cnOwningLib,
205 'call_number.record.id' : $scope.args.recordId,
206 barcode : $scope.args.copyBarcode
210 $scope.replaceBarcodes = function() {
211 itemSvc.replaceBarcodes([{
212 id : $scope.args.copyId,
213 barcode : $scope.args.copyBarcode
217 $scope.changeItemOwningLib = function() {
218 itemSvc.changeItemOwningLib([{
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 'call_number.label' : $scope.args.cnLabel,
224 'call_number.label_class' : $scope.args.cnLabelClass,
225 'call_number.prefix.id' : $scope.args.cnPrefixId,
226 'call_number.suffix.id' : $scope.args.cnSuffixId,
227 barcode : $scope.args.copyBarcode
231 $scope.transferItems = function (){
232 itemSvc.transferItems([{
233 id : $scope.args.copyId,
234 barcode : $scope.args.copyBarcode
241 * List view - grid stuff
243 .controller('ListCtrl',
244 ['$scope','$q','$routeParams','$location','$timeout','$window','egCore',
245 'egGridDataProvider','egItem','egUser','$uibModal','egCirc','egConfirmDialog',
246 'egProgressDialog', 'ngToast',
247 function($scope , $q , $routeParams , $location , $timeout , $window , egCore ,
248 egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog,
249 egProgressDialog, ngToast) {
252 var cp_list = $routeParams.idList;
254 copyId = cp_list.split(',');
257 $scope.context.page = 'list';
260 var provider = egGridDataProvider.instance();
261 provider.get = function(offset, count) {
265 $scope.gridDataProvider = egGridDataProvider.instance({
266 get : function(offset, count) {
267 //return provider.arrayNotifier(itemSvc.copies, offset, count);
268 return this.arrayNotifier(itemSvc.copies, offset, count);
272 // If a copy was just displayed in the detail view, ensure it's
273 // focused in the list view.
274 var selected = false;
275 var copyGrid = $scope.gridControls = {
276 itemRetrieved : function(item) {
277 if (selected || !itemSvc.copy) return;
278 if (itemSvc.copy.id() == item.id) {
279 copyGrid.selectItems([item.index]);
285 $scope.$watch('barcodesFromFile', function(newVal, oldVal) {
286 if (newVal && newVal != oldVal) {
287 $scope.args.barcode = '';
290 angular.forEach(newVal.split(/\n/), function(line) {
292 // scrub any trailing spaces or commas from the barcode
293 line = line.replace(/(.*?)($|\s.*|,.*)/,'$1');
297 // Serialize copy retrieval since there may be many, many copies.
298 function fetch_next_copy() {
299 var barcode = barcodes.pop();
300 egProgressDialog.increment();
302 if (!barcode) { // All done here.
303 egProgressDialog.close();
305 copyGrid.selectItems([itemSvc.copies[0].index]);
309 itemSvc.fetch(barcode).then(fetch_next_copy);
312 if (barcodes.length) {
313 egProgressDialog.open({value: 0, max: barcodes.length});
319 $scope.context.search = function(args) {
320 if (!args.barcode) return;
321 $scope.context.itemNotFound = false;
322 itemSvc.fetch(args.barcode).then(function(res) {
325 copyGrid.selectItems([res.index]);
326 $scope.args.barcode = '';
328 $scope.context.itemNotFound = true;
329 egCore.audio.play('warning.item_status.itemNotFound');
331 $scope.context.selectBarcode = true;
335 var add_barcode_to_list = function (b) {
336 //console.log('listCtrl: add_barcode_to_list',b);
337 $scope.context.search({barcode:b});
339 itemSvc.add_barcode_to_list = add_barcode_to_list;
341 $scope.context.toggleDisplay = function() {
342 var item = copyGrid.selectedItems()[0];
344 $location.path('/cat/item/' + item.id);
347 $scope.context.show_triggered_events = function() {
348 var item = copyGrid.selectedItems()[0];
350 $location.path('/cat/item/' + item.id + '/triggered_events');
353 function gatherSelectedRecordIds () {
356 copyGrid.selectedItems(),
358 if (rid_list.indexOf(item['call_number.record.id']) == -1)
359 rid_list.push(item['call_number.record.id'])
365 function gatherSelectedVolumeIds (rid) {
368 copyGrid.selectedItems(),
370 if (rid && item['call_number.record.id'] != rid) return;
371 if (cn_id_list.indexOf(item['call_number.id']) == -1)
372 cn_id_list.push(item['call_number.id'])
378 function gatherSelectedHoldingsIds (rid) {
381 copyGrid.selectedItems(),
383 if (rid && item['call_number.record.id'] != rid) return;
384 cp_id_list.push(item.id)
390 $scope.add_copies_to_bucket = function() {
391 var copy_list = gatherSelectedHoldingsIds();
392 itemSvc.add_copies_to_bucket(copy_list);
395 $scope.update_inventory = function() {
396 var copy_list = gatherSelectedHoldingsIds();
397 itemSvc.updateInventory(copy_list, $scope.gridControls.allItems()).then(function(res) {
399 $scope.gridControls.allItems(res);
400 ngToast.create(egCore.strings.SUCCESS_UPDATE_INVENTORY);
402 ngToast.warning(egCore.strings.FAIL_UPDATE_INVENTORY);
407 $scope.need_one_selected = function() {
408 var items = $scope.gridControls.selectedItems();
409 if (items.length == 1) return false;
413 $scope.make_copies_bookable = function() {
414 itemSvc.make_copies_bookable(copyGrid.selectedItems());
417 $scope.book_copies_now = function() {
418 itemSvc.book_copies_now(copyGrid.selectedItems());
421 $scope.requestItems = function() {
422 var copy_list = gatherSelectedHoldingsIds();
423 itemSvc.requestItems(copy_list);
426 $scope.replaceBarcodes = function() {
427 itemSvc.replaceBarcodes(copyGrid.selectedItems());
430 $scope.attach_to_peer_bib = function() {
431 itemSvc.attach_to_peer_bib(copyGrid.selectedItems());
434 $scope.selectedHoldingsCopyDelete = function () {
435 itemSvc.selectedHoldingsCopyDelete(copyGrid.selectedItems());
438 $scope.selectedHoldingsItemStatusTgrEvt= function() {
439 var item = copyGrid.selectedItems()[0];
441 $location.path('/cat/item/' + item.id + '/triggered_events');
444 $scope.selectedHoldingsItemStatusHolds= function() {
445 var item = copyGrid.selectedItems()[0];
447 $location.path('/cat/item/' + item.id + '/holds');
450 $scope.cancel_transit = function () {
451 itemSvc.cancel_transit(copyGrid.selectedItems());
454 $scope.selectedHoldingsDamaged = function () {
455 itemSvc.selectedHoldingsDamaged(copyGrid.selectedItems());
458 $scope.selectedHoldingsMissing = function () {
459 itemSvc.selectedHoldingsMissing(copyGrid.selectedItems());
462 $scope.checkin = function () {
463 itemSvc.checkin(copyGrid.selectedItems());
466 $scope.renew = function () {
467 itemSvc.renew(copyGrid.selectedItems());
470 $scope.selectedHoldingsVolCopyAdd = function () {
471 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),true,false);
473 $scope.selectedHoldingsCopyAdd = function () {
474 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),false,true);
477 $scope.selectedHoldingsCopyAlertsAdd = function(items) {
479 angular.forEach(items, function(item) {
480 if (item.id) copy_ids.push(item.id);
482 egCirc.add_copy_alerts(copy_ids).then(function() {
483 // update grid items?
487 $scope.selectedHoldingsCopyAlertsEdit = function(items) {
489 angular.forEach(items, function(item) {
490 if (item.id) copy_ids.push(item.id);
492 egCirc.manage_copy_alerts(copy_ids).then(function() {
493 // update grid items?
497 $scope.gridCellHandlers = {};
498 $scope.gridCellHandlers.copyAlertsEdit = function(id) {
499 egCirc.manage_copy_alerts([id]).then(function() {
500 // update grid items?
504 $scope.showBibHolds = function () {
505 angular.forEach(gatherSelectedRecordIds(), function (r) {
506 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
507 $timeout(function() { $window.open(url, '_blank') });
511 $scope.selectedHoldingsVolCopyEdit = function () {
512 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,false);
514 $scope.selectedHoldingsVolEdit = function () {
515 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,true);
517 $scope.selectedHoldingsCopyEdit = function () {
518 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),true,false);
521 $scope.changeItemOwningLib = function() {
522 itemSvc.changeItemOwningLib(copyGrid.selectedItems());
525 $scope.transferItems = function (){
526 itemSvc.transferItems(copyGrid.selectedItems());
529 $scope.print_labels = function() {
532 'open-ils.actor.anon_cache.set_value',
533 null, 'print-labels-these-copies', {
534 copies : gatherSelectedHoldingsIds()
536 ).then(function(key) {
538 var url = egCore.env.basePath + 'cat/printlabels/' + key;
539 $timeout(function() { $window.open(url, '_blank') });
541 alert('Could not create anonymous cache key!');
546 $scope.print_list = function() {
547 var print_data = { copies : copyGrid.allItems() };
549 if (print_data.copies.length == 0) return $q.when();
551 return egCore.print.print({
552 template : 'item_status',
557 if (copyId.length > 0) {
558 itemSvc.fetch(null,copyId).then(
568 * Detail view -- shows one copy
570 .controller('ViewCtrl',
571 ['$scope','$q','$location','$routeParams','$timeout','$window','egCore','egItem','egBilling','egCirc',
572 function($scope , $q , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling , egCirc) {
573 var copyId = $routeParams.id;
574 $scope.args.copyId = copyId;
575 $scope.tab = $routeParams.tab || 'summary';
576 $scope.context.page = 'detail';
577 $scope.summaryRecord = null;
580 if ($scope.tab == 'edit') {
581 $scope.tab = 'summary';
586 // use the cached record info
588 $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
589 return !aca.ack_time();
591 $scope.recordId = itemSvc.copy.call_number().record().id();
592 $scope.args.recordId = $scope.recordId;
593 $scope.args.cnId = itemSvc.copy.call_number().id();
594 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
595 $scope.args.cnLabel = itemSvc.copy.call_number().label();
596 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
597 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
598 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
599 $scope.args.copyBarcode = itemSvc.copy.barcode();
602 function loadCopy(barcode) {
603 $scope.context.itemNotFound = false;
605 // Avoid re-fetching the same copy while jumping tabs.
606 // In addition to being quicker, this helps to avoid flickering
607 // of the top panel which is always visible in the detail view.
609 // 'barcode' represents the loading of a new item - refetch it
610 // regardless of whether it matches the current item.
611 if (!barcode && itemSvc.copy && itemSvc.copy.id() == copyId) {
612 $scope.copy = itemSvc.copy;
613 if (itemSvc.last_copy_inventory && itemSvc.last_copy_inventory.copy() == copyId) {
614 $scope.last_copy_inventory = itemSvc.last_copy_inventory;
616 $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
617 return !aca.ack_time();
619 $scope.recordId = itemSvc.copy.call_number().record().id();
620 $scope.args.recordId = $scope.recordId;
621 $scope.args.cnId = itemSvc.copy.call_number().id();
622 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
623 $scope.args.cnLabel = itemSvc.copy.call_number().label();
624 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
625 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
626 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
627 $scope.args.copyBarcode = itemSvc.copy.barcode();
634 var deferred = $q.defer();
635 itemSvc.fetch(barcode, copyId, true).then(function(res) {
636 $scope.context.selectBarcode = true;
640 $scope.context.itemNotFound = true;
641 egCore.audio.play('warning.item_status.itemNotFound');
642 deferred.reject(); // avoid propagation of data fetch calls
648 if (res.last_copy_inventory) itemSvc.last_copy_inventory = res.last_copy_inventory;
652 $scope.last_copy_inventory = res.last_copy_inventory;
653 $scope.copy_alert_count = copy.copy_alerts().filter(function(aca) {
654 return !aca.ack_time();
656 console.debug($scope.copy_alert_count);
657 $scope.recordId = copy.call_number().record().id();
658 $scope.args.recordId = $scope.recordId;
659 $scope.args.cnId = itemSvc.copy.call_number().id();
660 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
661 $scope.args.cnLabel = itemSvc.copy.call_number().label();
662 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
663 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
664 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
665 $scope.args.copyBarcode = copy.barcode();
666 $scope.args.barcode = '';
668 // locally flesh org units
669 copy.circ_lib(egCore.org.get(copy.circ_lib()));
670 copy.call_number().owning_lib(
671 egCore.org.get(copy.call_number().owning_lib()));
673 var r = copy.call_number().record();
674 if (r.owner()) r.owner(egCore.org.get(r.owner()));
676 // make boolean for auto-magic true/false display
678 ['ref','opac_visible','holdable','circulate'],
679 function(field) { copy[field](Boolean(copy[field]() == 't')) }
682 // finally, if this is a different copy, redirect.
683 // Note that we flesh first since the copy we just
684 // fetched will be used after the redirect.
685 if (copyId && copyId != copy.id()) {
686 // if a new barcode is scanned in the detail view,
687 // update the url to match the ID of the new copy
688 $location.path('/cat/item/' + copy.id() + '/' + $scope.tab);
689 deferred.reject(); // avoid propagation of data fetch calls
697 return deferred.promise;
700 // load the two most recent circulations in /circs tab
701 function loadCurrentCirc() {
703 delete $scope.circ_summary;
704 delete $scope.prev_circ_summary;
705 delete $scope.prev_circ_usr;
709 itemSvc.copy.call_number().id() == -1 ?
710 itemSvc.copy.circ_lib().id() :
711 itemSvc.copy.call_number().owning_lib().id();
713 // since a user can still view patron checkout history here, check perms
714 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
715 .then(function(orgIds){
716 if(orgIds.indexOf(copy_org) == -1){
717 console.warn('User is not allowed to view circ history!');
721 return fetchMaxCircHistory();
723 .then(function(maxHistCount){
725 if (!maxHistCount) $scope.isMaxCircHistoryZero = true;
727 egCore.pcrud.search('aacs',
728 {target_copy : copyId},
734 'checkin_workstation',
737 'recurring_fine_rule'
741 order_by : {aacs : 'xact_start desc'},
745 ).then(null, null, function(circ) {
748 if (!circ) return $q.when();
750 // load the chain for this circ
753 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
754 egCore.auth.token(), $scope.circ.id()
755 ).then(function(summary) {
756 $scope.circ_summary = summary;
759 if (maxHistCount <= 1) return;
761 // load the chain for the previous circ, plus the user
764 'open-ils.circ.prev_renewal_chain.retrieve_by_circ.summary',
765 egCore.auth.token(), $scope.circ.id()
767 ).then(null, null, function(summary) {
768 $scope.prev_circ_summary = summary.summary;
770 if (summary.usr) { // aged circs have no 'usr'.
771 egCore.pcrud.retrieve('au', summary.usr,
772 {flesh : 1, flesh_fields : {au : ['card']}})
774 .then(function(user) { $scope.prev_circ_usr = user });
782 function fetchMaxCircHistory() {
783 if (maxHistory) return $q.when(maxHistory);
784 return egCore.org.settings(
785 'circ.item_checkout_history.max')
786 .then(function(set) {
787 maxHistory = set['circ.item_checkout_history.max'] || 4;
788 return Number(maxHistory);
792 $scope.addBilling = function(circ) {
793 egBilling.showBillDialog({
799 $scope.retrieveAllPatrons = function() {
800 var users = new Set();
801 angular.forEach($scope.circ_list.map(function(circ) { return circ.usr(); }),function(usr) {
802 // aged circs have no 'usr'.
803 if (usr) users.add(usr);
805 users.forEach(function(usr) {
806 $timeout(function() {
807 var url = $location.absUrl().replace(
809 '/circ/patron/' + usr.id() + '/checkout');
810 $window.open(url, '_blank')
815 // load data for /circ_list tab
816 function loadCircHistory() {
817 $scope.circ_list = [];
820 itemSvc.copy.call_number().id() == -1 ?
821 itemSvc.copy.circ_lib().id() :
822 itemSvc.copy.call_number().owning_lib().id();
824 // there is an extra layer of permissibility over circ
826 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
827 .then(function(orgIds) {
829 if (orgIds.indexOf(copy_org) == -1) {
830 console.log('User is not allowed to view circ history');
834 return fetchMaxCircHistory();
836 }).then(function(maxHistCount) {
838 if(!maxHistCount) $scope.isMaxCircHistoryZero = true;
840 egCore.pcrud.search('aacs',
841 {target_copy : copyId},
847 'checkin_workstation',
848 'recurring_fine_rule'
852 order_by : {aacs : 'xact_start desc'},
853 // fetch at least one to see if copy ever circulated
854 limit : $scope.isMaxCircHistoryZero ? 1 : maxHistCount
857 ).then(null, null, function(circ) {
861 // flesh circ_lib locally
862 circ.circ_lib(egCore.org.get(circ.circ_lib()));
863 circ.checkin_lib(egCore.org.get(circ.checkin_lib()));
864 $scope.circ_list.push(circ);
870 function loadCircCounts() {
872 delete $scope.circ_counts;
873 $scope.total_circs = 0;
874 $scope.total_circs_this_year = 0;
875 $scope.total_circs_prev_year = 0;
878 egCore.pcrud.search('circbyyr',
879 {copy : copyId}, null, {atomic : true})
881 .then(function(counts) {
882 $scope.circ_counts = counts;
884 angular.forEach(counts, function(count) {
885 $scope.total_circs += Number(count.count());
888 var this_year = counts.filter(function(c) {
889 return c.year() == new Date().getFullYear();
892 $scope.total_circs_this_year = (function() {
894 if (this_year.length == 2) {
895 total = (Number(this_year[0].count()) + Number(this_year[1].count()));
896 } else if (this_year.length == 1) {
897 total = Number(this_year[0].count());
902 var prev_year = counts.filter(function(c) {
903 return c.year() == new Date().getFullYear() - 1;
906 $scope.total_circs_prev_year = (function() {
908 if (prev_year.length == 2) {
909 total = (Number(prev_year[0].count()) + Number(prev_year[1].count()));
910 } else if (prev_year.length == 1) {
911 total = Number(prev_year[0].count());
919 function loadHolds() {
923 egCore.pcrud.search('ahr',
924 { current_copy : copyId,
926 fulfillment_time : null,
927 capture_time : {'<>' : null}
931 ahr : ['requestor', 'usr'],
935 ).then(null, null, function(hold) {
937 hold.pickup_lib(egCore.org.get(hold.pickup_lib()));
938 if (hold.current_shelf_lib()) {
939 hold.current_shelf_lib(
940 egCore.org.get(hold.current_shelf_lib()));
942 hold.behind_desk(Boolean(hold.behind_desk() == 't'));
946 function loadMostRecentTransit() {
947 delete $scope.transit;
948 delete $scope.hold_transit;
951 egCore.pcrud.search('atc',
952 {target_copy : copyId},
954 order_by : {atc : 'source_send_time DESC'},
958 ).then(null, null, function(transit) {
959 // use progress callback since we'll get up to one result
960 $scope.transit = transit;
961 transit.source(egCore.org.get(transit.source()));
962 transit.dest(egCore.org.get(transit.dest()));
967 // we don't need all data on all tabs, so fetch what's needed when needed.
968 function loadTabData() {
985 loadMostRecentTransit();
988 case 'triggered_events':
989 var url = $location.absUrl().replace(/\/staff.*/, '/actor/user/event_log');
990 url += '?copy_id=' + encodeURIComponent(copyId);
991 $scope.triggered_events_url = url;
998 'open-ils.actor.anon_cache.set_value',
999 null, 'edit-these-copies', {
1000 record_id: $scope.recordId,
1005 ).then(function(key) {
1007 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1008 $window.location.href = url;
1010 alert('Could not create anonymous cache key!');
1018 $scope.addCopyAlerts = function(copy_id) {
1019 egCirc.add_copy_alerts([copy_id]).then(function() {
1021 loadCopy($scope.copy.barcode()).then(loadTabData);
1024 $scope.manageCopyAlerts = function(copy_id) {
1025 egCirc.manage_copy_alerts([copy_id]).then(function() {
1027 loadCopy($scope.copy.barcode()).then(loadTabData);
1031 $scope.context.toggleDisplay = function() {
1032 $location.path('/cat/item/search');
1035 // handle the barcode scan box, which will replace our current copy
1036 $scope.context.search = function(args) {
1037 loadCopy(args.barcode).then(loadTabData);
1040 $scope.context.show_triggered_events = function() {
1041 $location.path('/cat/item/' + copyId + '/triggered_events');
1044 loadCopy().then(loadTabData);