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 $scope.context.page = 'list';
296 var provider = egGridDataProvider.instance();
297 provider.get = function(offset, count) {
301 $scope.gridDataProvider = egGridDataProvider.instance({
302 get : function(offset, count) {
303 //return provider.arrayNotifier(itemSvc.copies, offset, count);
304 return this.arrayNotifier(itemSvc.copies, offset, count);
308 // If a copy was just displayed in the detail view, ensure it's
309 // focused in the list view.
310 var selected = false;
311 var copyGrid = $scope.gridControls = {
312 itemRetrieved : function(item) {
313 if (selected || !itemSvc.copy) return;
314 if (itemSvc.copy.id() == item.id) {
315 copyGrid.selectItems([item.index]);
321 $scope.$watch('barcodesFromFile', function(newVal, oldVal) {
322 if (newVal && newVal != oldVal) {
323 $scope.args.barcode = '';
326 angular.forEach(newVal.split(/\n/), function(line) {
328 // scrub any trailing spaces or commas from the barcode
329 line = line.replace(/(.*?)($|\s.*|,.*)/,'$1');
333 // Serialize copy retrieval since there may be many, many copies.
334 function fetch_next_copy() {
335 var barcode = barcodes.pop();
336 egProgressDialog.increment();
338 if (!barcode) { // All done here.
339 egProgressDialog.close();
341 copyGrid.selectItems([itemSvc.copies[0].index]);
345 itemSvc.fetch(barcode).then(fetch_next_copy);
348 if (barcodes.length) {
349 egProgressDialog.open({value: 0, max: barcodes.length});
355 $scope.context.search = function(args) {
356 if (!args.barcode) return;
357 $scope.context.itemNotFound = false;
358 itemSvc.fetch(args.barcode).then(function(res) {
361 copyGrid.selectItems([res.index]);
362 $scope.args.barcode = '';
364 $scope.context.itemNotFound = true;
365 egCore.audio.play('warning.item_status.itemNotFound');
367 $scope.context.selectBarcode = true;
371 var add_barcode_to_list = function (b) {
372 //console.log('listCtrl: add_barcode_to_list',b);
373 $scope.context.search({barcode:b});
375 itemSvc.add_barcode_to_list = add_barcode_to_list;
377 $scope.context.toggleDisplay = function() {
378 var item = copyGrid.selectedItems()[0];
380 $location.path('/cat/item/' + item.id);
383 $scope.context.show_triggered_events = function() {
384 var item = copyGrid.selectedItems()[0];
386 $location.path('/cat/item/' + item.id + '/triggered_events');
389 function gatherSelectedRecordIds () {
392 copyGrid.selectedItems(),
394 if (rid_list.indexOf(item['call_number.record.id']) == -1)
395 rid_list.push(item['call_number.record.id'])
401 function gatherSelectedVolumeIds (rid) {
404 copyGrid.selectedItems(),
406 if (rid && item['call_number.record.id'] != rid) return;
407 if (cn_id_list.indexOf(item['call_number.id']) == -1)
408 cn_id_list.push(item['call_number.id'])
414 function gatherSelectedHoldingsIds (rid) {
417 copyGrid.selectedItems(),
419 if (rid && item['call_number.record.id'] != rid) return;
420 cp_id_list.push(item.id)
426 $scope.add_copies_to_bucket = function() {
427 var copy_list = gatherSelectedHoldingsIds();
428 itemSvc.add_copies_to_bucket(copy_list);
431 $scope.locateAcquisition = function() {
432 if (gatherSelectedHoldingsIds) {
433 var cp_list = gatherSelectedHoldingsIds();
435 if (cp_list.length > 0) {
436 $scope.openAcquisitionLineItem(cp_list);
442 $scope.update_inventory = function() {
443 var copy_list = gatherSelectedHoldingsIds();
444 itemSvc.updateInventory(copy_list, $scope.gridControls.allItems()).then(function(res) {
446 $scope.gridControls.allItems(res);
447 ngToast.create(egCore.strings.SUCCESS_UPDATE_INVENTORY);
449 ngToast.warning(egCore.strings.FAIL_UPDATE_INVENTORY);
454 $scope.need_one_selected = function() {
455 var items = $scope.gridControls.selectedItems();
456 if (items.length == 1) return false;
460 $scope.make_copies_bookable = function() {
461 itemSvc.make_copies_bookable(copyGrid.selectedItems());
464 $scope.book_copies_now = function() {
465 itemSvc.book_copies_now(copyGrid.selectedItems());
468 $scope.requestItems = function() {
469 var copy_list = gatherSelectedHoldingsIds();
470 itemSvc.requestItems(copy_list);
473 $scope.replaceBarcodes = function() {
474 itemSvc.replaceBarcodes(copyGrid.selectedItems());
477 $scope.attach_to_peer_bib = function() {
478 itemSvc.attach_to_peer_bib(copyGrid.selectedItems());
481 $scope.selectedHoldingsCopyDelete = function () {
482 itemSvc.selectedHoldingsCopyDelete(copyGrid.selectedItems());
485 $scope.selectedHoldingsItemStatusTgrEvt= function() {
486 var item = copyGrid.selectedItems()[0];
488 $location.path('/cat/item/' + item.id + '/triggered_events');
491 $scope.selectedHoldingsItemStatusHolds= function() {
492 var item = copyGrid.selectedItems()[0];
494 $location.path('/cat/item/' + item.id + '/holds');
497 $scope.cancel_transit = function () {
498 itemSvc.cancel_transit(copyGrid.selectedItems());
501 $scope.selectedHoldingsDamaged = function () {
502 itemSvc.selectedHoldingsDamaged(copyGrid.selectedItems());
505 $scope.selectedHoldingsMissing = function () {
506 itemSvc.selectedHoldingsMissing(copyGrid.selectedItems());
509 $scope.checkin = function () {
510 itemSvc.checkin(copyGrid.selectedItems());
513 $scope.renew = function () {
514 itemSvc.renew(copyGrid.selectedItems());
517 $scope.selectedHoldingsVolCopyAdd = function () {
518 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),true,false);
520 $scope.selectedHoldingsCopyAdd = function () {
521 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),false,true);
524 $scope.selectedHoldingsCopyAlertsAdd = function(items) {
526 angular.forEach(items, function(item) {
527 if (item.id) copy_ids.push(item.id);
529 egCirc.add_copy_alerts(copy_ids).then(function() {
530 // update grid items?
534 $scope.selectedHoldingsCopyAlertsEdit = function(items) {
536 angular.forEach(items, function(item) {
537 if (item.id) copy_ids.push(item.id);
539 egCirc.manage_copy_alerts(copy_ids).then(function() {
540 // update grid items?
544 $scope.gridCellHandlers = {};
545 $scope.gridCellHandlers.copyAlertsEdit = function(id) {
546 egCirc.manage_copy_alerts([id]).then(function() {
547 // update grid items?
551 $scope.showBibHolds = function () {
552 angular.forEach(gatherSelectedRecordIds(), function (r) {
553 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
554 $timeout(function() { $window.open(url, '_blank') });
558 $scope.selectedHoldingsVolCopyEdit = function () {
559 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,false);
561 $scope.selectedHoldingsVolEdit = function () {
562 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,true);
564 $scope.selectedHoldingsCopyEdit = function () {
565 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),true,false);
568 $scope.changeItemOwningLib = function() {
569 itemSvc.changeItemOwningLib(copyGrid.selectedItems());
572 $scope.transferItems = function (){
573 itemSvc.transferItems(copyGrid.selectedItems());
576 $scope.print_labels = function() {
579 'open-ils.actor.anon_cache.set_value',
580 null, 'print-labels-these-copies', {
581 copies : gatherSelectedHoldingsIds()
583 ).then(function(key) {
585 var url = egCore.env.basePath + 'cat/printlabels/' + key;
586 $timeout(function() { $window.open(url, '_blank') });
588 alert('Could not create anonymous cache key!');
593 $scope.print_list = function() {
594 var print_data = { copies : copyGrid.allItems() };
596 if (print_data.copies.length == 0) return $q.when();
598 return egCore.print.print({
599 template : 'item_status',
604 $scope.show_in_catalog = function(){
605 itemSvc.show_in_catalog(copyGrid.selectedItems());
608 if (copyId.length > 0) {
609 itemSvc.fetch(null,copyId).then(
619 * Detail view -- shows one copy
621 .controller('ViewCtrl',
622 ['$scope','$q','$location','$routeParams','$timeout','$window','egCore','egItem','egBilling','egCirc',
623 function($scope , $q , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling , egCirc) {
624 var copyId = $routeParams.id;
625 $scope.args.copyId = copyId;
626 $scope.tab = $routeParams.tab || 'summary';
627 $scope.context.page = 'detail';
628 $scope.summaryRecord = null;
631 if ($scope.tab == 'edit') {
632 $scope.tab = 'summary';
637 // use the cached record info
639 $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
640 return !aca.ack_time();
642 $scope.recordId = itemSvc.copy.call_number().record().id();
643 $scope.args.recordId = $scope.recordId;
644 $scope.args.cnId = itemSvc.copy.call_number().id();
645 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
646 $scope.args.cnLabel = itemSvc.copy.call_number().label();
647 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
648 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
649 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
650 $scope.args.copyBarcode = itemSvc.copy.barcode();
653 function loadCopy(barcode) {
654 $scope.context.itemNotFound = false;
656 // Avoid re-fetching the same copy while jumping tabs.
657 // In addition to being quicker, this helps to avoid flickering
658 // of the top panel which is always visible in the detail view.
660 // 'barcode' represents the loading of a new item - refetch it
661 // regardless of whether it matches the current item.
662 if (!barcode && itemSvc.copy && itemSvc.copy.id() == copyId) {
663 $scope.copy = itemSvc.copy;
664 if (itemSvc.latest_inventory && itemSvc.latest_inventory.copy() == copyId) {
665 $scope.latest_inventory = itemSvc.latest_inventory;
667 $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
668 return !aca.ack_time();
670 $scope.recordId = itemSvc.copy.call_number().record().id();
671 $scope.args.recordId = $scope.recordId;
672 $scope.args.cnId = itemSvc.copy.call_number().id();
673 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
674 $scope.args.cnLabel = itemSvc.copy.call_number().label();
675 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
676 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
677 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
678 $scope.args.copyBarcode = itemSvc.copy.barcode();
685 var deferred = $q.defer();
686 itemSvc.fetch(barcode, copyId, true).then(function(res) {
687 $scope.context.selectBarcode = true;
691 $scope.context.itemNotFound = true;
692 egCore.audio.play('warning.item_status.itemNotFound');
693 deferred.reject(); // avoid propagation of data fetch calls
699 if (res.latest_inventory) itemSvc.latest_inventory = res.latest_inventory;
703 $scope.latest_inventory = res.latest_inventory;
704 $scope.copy_alert_count = copy.copy_alerts().filter(function(aca) {
705 return !aca.ack_time();
707 console.debug($scope.copy_alert_count);
708 $scope.recordId = copy.call_number().record().id();
709 $scope.args.recordId = $scope.recordId;
710 $scope.args.cnId = itemSvc.copy.call_number().id();
711 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
712 $scope.args.cnLabel = itemSvc.copy.call_number().label();
713 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
714 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
715 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
716 $scope.args.copyBarcode = copy.barcode();
717 $scope.args.barcode = '';
719 // locally flesh org units
720 copy.circ_lib(egCore.org.get(copy.circ_lib()));
721 copy.call_number().owning_lib(
722 egCore.org.get(copy.call_number().owning_lib()));
724 var r = copy.call_number().record();
725 if (r.owner()) r.owner(egCore.org.get(r.owner()));
727 // make boolean for auto-magic true/false display
729 ['ref','opac_visible','holdable','circulate'],
730 function(field) { copy[field](Boolean(copy[field]() == 't')) }
733 // finally, if this is a different copy, redirect.
734 // Note that we flesh first since the copy we just
735 // fetched will be used after the redirect.
736 if (copyId && copyId != copy.id()) {
737 // if a new barcode is scanned in the detail view,
738 // update the url to match the ID of the new copy
739 $location.path('/cat/item/' + copy.id() + '/' + $scope.tab);
740 deferred.reject(); // avoid propagation of data fetch calls
748 return deferred.promise;
751 // load the two most recent circulations in /circs tab
752 function loadCurrentCirc() {
754 delete $scope.circ_summary;
755 delete $scope.prev_circ_summary;
756 delete $scope.prev_circ_usr;
760 itemSvc.copy.call_number().id() == -1 ?
761 itemSvc.copy.circ_lib().id() :
762 itemSvc.copy.call_number().owning_lib().id();
764 // since a user can still view patron checkout history here, check perms
765 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
766 .then(function(orgIds){
767 if(orgIds.indexOf(copy_org) == -1){
768 console.warn('User is not allowed to view circ history!');
772 return fetchMaxCircHistory();
774 .then(function(maxHistCount){
776 if (!maxHistCount) $scope.isMaxCircHistoryZero = true;
778 egCore.pcrud.search('aacs',
779 {target_copy : copyId},
785 'checkin_workstation',
788 'recurring_fine_rule'
792 order_by : {aacs : 'xact_start desc'},
796 ).then(null, null, function(circ) {
799 if (!circ) return $q.when();
801 // load the chain for this circ
804 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
805 egCore.auth.token(), $scope.circ.id()
806 ).then(function(summary) {
807 $scope.circ_summary = summary;
810 if (maxHistCount <= 1) return;
812 // load the chain for the previous circ, plus the user
815 'open-ils.circ.prev_renewal_chain.retrieve_by_circ.summary',
816 egCore.auth.token(), $scope.circ.id()
818 ).then(null, null, function(summary) {
819 $scope.prev_circ_summary = summary.summary;
821 if (summary.usr) { // aged circs have no 'usr'.
822 egCore.pcrud.retrieve('au', summary.usr,
823 {flesh : 1, flesh_fields : {au : ['card']}})
825 .then(function(user) { $scope.prev_circ_usr = user });
833 function fetchMaxCircHistory() {
834 if (maxHistory) return $q.when(maxHistory);
835 return egCore.org.settings(
836 'circ.item_checkout_history.max')
837 .then(function(set) {
838 maxHistory = set['circ.item_checkout_history.max'] || 4;
839 return Number(maxHistory);
843 $scope.addBilling = function(circ) {
844 egBilling.showBillDialog({
850 $scope.retrieveAllPatrons = function() {
851 var users = new Set();
852 angular.forEach($scope.circ_list.map(function(circ) { return circ.usr(); }),function(usr) {
853 // aged circs have no 'usr'.
854 if (usr) users.add(usr);
856 users.forEach(function(usr) {
857 $timeout(function() {
858 var url = $location.absUrl().replace(
860 '/circ/patron/' + usr.id() + '/checkout');
861 $window.open(url, '_blank')
866 // load data for /circ_list tab
867 function loadCircHistory() {
868 $scope.circ_list = [];
871 itemSvc.copy.call_number().id() == -1 ?
872 itemSvc.copy.circ_lib().id() :
873 itemSvc.copy.call_number().owning_lib().id();
875 // there is an extra layer of permissibility over circ
877 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
878 .then(function(orgIds) {
880 if (orgIds.indexOf(copy_org) == -1) {
881 console.log('User is not allowed to view circ history');
885 return fetchMaxCircHistory();
887 }).then(function(maxHistCount) {
889 if(!maxHistCount) $scope.isMaxCircHistoryZero = true;
891 egCore.pcrud.search('aacs',
892 {target_copy : copyId},
898 'checkin_workstation',
899 'recurring_fine_rule'
903 order_by : {aacs : 'xact_start desc'},
904 // fetch at least one to see if copy ever circulated
905 limit : $scope.isMaxCircHistoryZero ? 1 : maxHistCount
908 ).then(null, null, function(circ) {
912 // flesh circ_lib locally
913 circ.circ_lib(egCore.org.get(circ.circ_lib()));
914 circ.checkin_lib(egCore.org.get(circ.checkin_lib()));
915 $scope.circ_list.push(circ);
921 function loadCircCounts() {
923 delete $scope.circ_counts;
924 $scope.total_circs = 0;
925 $scope.total_circs_this_year = 0;
926 $scope.total_circs_prev_year = 0;
929 egCore.pcrud.search('circbyyr',
930 {copy : copyId}, null, {atomic : true})
932 .then(function(counts) {
933 $scope.circ_counts = counts;
935 angular.forEach(counts, function(count) {
936 $scope.total_circs += Number(count.count());
939 var this_year = counts.filter(function(c) {
940 return c.year() == new Date().getFullYear();
943 $scope.total_circs_this_year = (function() {
945 if (this_year.length == 2) {
946 total = (Number(this_year[0].count()) + Number(this_year[1].count()));
947 } else if (this_year.length == 1) {
948 total = Number(this_year[0].count());
953 var prev_year = counts.filter(function(c) {
954 return c.year() == new Date().getFullYear() - 1;
957 $scope.total_circs_prev_year = (function() {
959 if (prev_year.length == 2) {
960 total = (Number(prev_year[0].count()) + Number(prev_year[1].count()));
961 } else if (prev_year.length == 1) {
962 total = Number(prev_year[0].count());
970 function loadHolds() {
974 egCore.pcrud.search('ahr',
975 { current_copy : copyId,
977 fulfillment_time : null,
978 capture_time : {'<>' : null}
982 ahr : ['requestor', 'usr'],
986 ).then(null, null, function(hold) {
988 hold.pickup_lib(egCore.org.get(hold.pickup_lib()));
989 if (hold.current_shelf_lib()) {
990 hold.current_shelf_lib(
991 egCore.org.get(hold.current_shelf_lib()));
993 hold.behind_desk(Boolean(hold.behind_desk() == 't'));
997 function loadMostRecentTransit() {
998 delete $scope.transit;
999 delete $scope.hold_transit;
1000 if (!copyId) return;
1002 egCore.pcrud.search('atc',
1003 {target_copy : copyId},
1005 order_by : {atc : 'source_send_time DESC'},
1009 ).then(null, null, function(transit) {
1010 // use progress callback since we'll get up to one result
1011 $scope.transit = transit;
1012 transit.source(egCore.org.get(transit.source()));
1013 transit.dest(egCore.org.get(transit.dest()));
1018 // we don't need all data on all tabs, so fetch what's needed when needed.
1019 function loadTabData() {
1020 switch($scope.tab) {
1036 loadMostRecentTransit();
1039 case 'triggered_events':
1040 var url = $location.absUrl().replace(/\/staff.*/, '/actor/user/event_log');
1041 url += '?copy_id=' + encodeURIComponent(copyId);
1042 $scope.triggered_events_url = url;
1049 'open-ils.actor.anon_cache.set_value',
1050 null, 'edit-these-copies', {
1051 record_id: $scope.recordId,
1056 ).then(function(key) {
1058 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1059 $window.location.href = url;
1061 alert('Could not create anonymous cache key!');
1069 $scope.addCopyAlerts = function(copy_id) {
1070 egCirc.add_copy_alerts([copy_id]).then(function() {
1072 loadCopy($scope.copy.barcode()).then(loadTabData);
1075 $scope.manageCopyAlerts = function(copy_id) {
1076 egCirc.manage_copy_alerts([copy_id]).then(function() {
1078 loadCopy($scope.copy.barcode()).then(loadTabData);
1082 $scope.context.toggleDisplay = function() {
1083 $location.path('/cat/item/search');
1086 // handle the barcode scan box, which will replace our current copy
1087 $scope.context.search = function(args) {
1088 loadCopy(args.barcode).then(loadTabData);
1091 $scope.context.show_triggered_events = function() {
1092 $location.path('/cat/item/' + copyId + '/triggered_events');
1095 loadCopy().then(loadTabData);