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(/\r?\n/), function(line) {
329 //remove all whitespace and commas
330 line = line.replace(/[\s,]+/g,'');
332 //Or remove leading/trailing whitespace
333 //line = line.replace(/(^[\s,]+|[\s,]+$/g,'');
339 // Serialize copy retrieval since there may be many, many copies.
340 function fetch_next_copy() {
341 var barcode = barcodes.pop();
342 egProgressDialog.increment();
344 if (barcode == undefined) { // All done here.
345 egProgressDialog.close();
347 if(itemSvc.copies[0]){ // Were any copies actually retrieved
348 copyGrid.selectItems([itemSvc.copies[0].index]);
353 itemSvc.fetch(barcode).then(fetch_next_copy);
356 if (barcodes.length) {
357 egProgressDialog.open({value: 0, max: barcodes.length});
363 $scope.context.search = function(args) {
364 if (!args.barcode) return;
365 $scope.context.itemNotFound = false;
366 itemSvc.fetch(args.barcode).then(function(res) {
369 copyGrid.selectItems([res.index]);
370 $scope.args.barcode = '';
372 $scope.context.itemNotFound = true;
373 egCore.audio.play('warning.item_status.itemNotFound');
375 $scope.context.selectBarcode = true;
379 var add_barcode_to_list = function (b) {
380 //console.log('listCtrl: add_barcode_to_list',b);
381 $scope.context.search({barcode:b});
383 itemSvc.add_barcode_to_list = add_barcode_to_list;
385 $scope.context.toggleDisplay = function() {
386 var item = copyGrid.selectedItems()[0];
388 $location.path('/cat/item/' + item.id);
391 $scope.context.show_triggered_events = function() {
392 var item = copyGrid.selectedItems()[0];
394 $location.path('/cat/item/' + item.id + '/triggered_events');
397 function gatherSelectedRecordIds () {
400 copyGrid.selectedItems(),
402 if (rid_list.indexOf(item['call_number.record.id']) == -1)
403 rid_list.push(item['call_number.record.id'])
409 function gatherSelectedVolumeIds (rid) {
412 copyGrid.selectedItems(),
414 if (rid && item['call_number.record.id'] != rid) return;
415 if (cn_id_list.indexOf(item['call_number.id']) == -1)
416 cn_id_list.push(item['call_number.id'])
422 function gatherSelectedHoldingsIds (rid) {
425 copyGrid.selectedItems(),
427 if (rid && item['call_number.record.id'] != rid) return;
428 cp_id_list.push(item.id)
434 $scope.refreshGridData = function() {
435 var chain = $q.when();
436 var all_items = itemSvc.copies.map(function(item) {
439 angular.forEach(all_items.reverse(), function(i) {
440 itemSvc.copies.shift();
441 chain = chain.then(function() {
442 return itemSvc.fetch(null, i);
445 return chain.then(function() {
451 $scope.add_copies_to_bucket = function() {
452 var copy_list = gatherSelectedHoldingsIds();
453 itemSvc.add_copies_to_bucket(copy_list);
456 $scope.locateAcquisition = function() {
457 if (gatherSelectedHoldingsIds) {
458 var cp_list = gatherSelectedHoldingsIds();
460 if (cp_list.length > 0) {
461 $scope.openAcquisitionLineItem(cp_list);
467 $scope.update_inventory = function() {
468 var copy_list = gatherSelectedHoldingsIds();
469 itemSvc.updateInventory(copy_list, $scope.gridControls.allItems()).then(function(res) {
471 $scope.gridControls.allItems(res);
472 ngToast.create(egCore.strings.SUCCESS_UPDATE_INVENTORY);
474 ngToast.warning(egCore.strings.FAIL_UPDATE_INVENTORY);
479 $scope.need_one_selected = function() {
480 var items = $scope.gridControls.selectedItems();
481 if (items.length == 1) return false;
485 $scope.make_copies_bookable = function() {
486 itemSvc.make_copies_bookable(copyGrid.selectedItems());
489 $scope.book_copies_now = function() {
490 itemSvc.book_copies_now(copyGrid.selectedItems());
493 $scope.requestItems = function() {
494 var copy_list = gatherSelectedHoldingsIds();
495 itemSvc.requestItems(copy_list);
498 $scope.replaceBarcodes = function() {
499 itemSvc.replaceBarcodes(copyGrid.selectedItems());
502 $scope.attach_to_peer_bib = function() {
503 itemSvc.attach_to_peer_bib(copyGrid.selectedItems());
506 $scope.selectedHoldingsCopyDelete = function () {
507 itemSvc.selectedHoldingsCopyDelete(copyGrid.selectedItems());
510 $scope.selectedHoldingsItemStatusTgrEvt= function() {
511 var item = copyGrid.selectedItems()[0];
513 $location.path('/cat/item/' + item.id + '/triggered_events');
516 $scope.selectedHoldingsItemStatusHolds= function() {
517 var item = copyGrid.selectedItems()[0];
519 $location.path('/cat/item/' + item.id + '/holds');
522 $scope.cancel_transit = function () {
523 itemSvc.cancel_transit(copyGrid.selectedItems());
526 $scope.selectedHoldingsDamaged = function () {
527 itemSvc.selectedHoldingsDamaged(copyGrid.selectedItems());
530 $scope.selectedHoldingsMissing = function () {
531 itemSvc.selectedHoldingsMissing(copyGrid.selectedItems());
534 $scope.checkin = function () {
535 itemSvc.checkin(copyGrid.selectedItems());
538 $scope.renew = function () {
539 itemSvc.renew(copyGrid.selectedItems());
542 $scope.selectedHoldingsVolCopyAdd = function () {
543 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),true,false);
545 $scope.selectedHoldingsCopyAdd = function () {
546 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),false,true);
549 $scope.selectedHoldingsCopyAlertsAdd = function(items) {
551 angular.forEach(items, function(item) {
552 if (item.id) copy_ids.push(item.id);
554 egCirc.add_copy_alerts(copy_ids).then(function() {
555 // update grid items?
559 $scope.selectedHoldingsCopyAlertsEdit = function(items) {
561 angular.forEach(items, function(item) {
562 if (item.id) copy_ids.push(item.id);
564 egCirc.manage_copy_alerts(copy_ids).then(function() {
565 // update grid items?
569 $scope.gridCellHandlers = {};
570 $scope.gridCellHandlers.copyAlertsEdit = function(id) {
571 egCirc.manage_copy_alerts([id]).then(function() {
572 // update grid items?
576 $scope.showBibHolds = function () {
577 angular.forEach(gatherSelectedRecordIds(), function (r) {
578 var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
579 $timeout(function() { $window.open(url, '_blank') });
583 $scope.selectedHoldingsVolCopyEdit = function () {
584 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,false);
586 $scope.selectedHoldingsVolEdit = function () {
587 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,true);
589 $scope.selectedHoldingsCopyEdit = function () {
590 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),true,false);
593 $scope.changeItemOwningLib = function() {
594 itemSvc.changeItemOwningLib(copyGrid.selectedItems());
597 $scope.transferItems = function (){
598 itemSvc.transferItems(copyGrid.selectedItems());
601 $scope.print_labels = function() {
604 'open-ils.actor.anon_cache.set_value',
605 null, 'print-labels-these-copies', {
606 copies : gatherSelectedHoldingsIds()
608 ).then(function(key) {
610 var url = egCore.env.basePath + 'cat/printlabels/' + key;
611 $timeout(function() { $window.open(url, '_blank') });
613 alert('Could not create anonymous cache key!');
618 $scope.print_list = function() {
619 var print_data = { copies : copyGrid.allItems() };
621 if (print_data.copies.length == 0) return $q.when();
623 return egCore.print.print({
624 template : 'item_status',
629 $scope.show_in_catalog = function(){
630 itemSvc.show_in_catalog(copyGrid.selectedItems());
633 if (copyId.length > 0) {
635 angular.forEach(copyId, function (c) {
636 fetch_list.push(itemSvc.fetch(null,c));
639 return $q.all(fetch_list).then(function (res) { copyGrid.refresh(); });
642 $scope.statusIconColumn = {
644 template: function(item) {
646 if (modified_items.has(item['id'])) {
647 icon = '<span class="glyphicon glyphicon-floppy-saved"' +
648 'title="' + egCore.strings.ITEM_SUCCESSFULLY_MODIFIED + '" ' +
649 'aria-label="' + egCore.strings.ITEM_SUCCESSFULLY_MODIFIED + '">' +
656 if (typeof BroadcastChannel != 'undefined') {
657 var holdings_bChannel = new BroadcastChannel("eg.holdings.update");
658 holdings_bChannel.onmessage = function(e) {
659 angular.forEach(e.data.copies, function(i) {
660 modified_items.add(i);
662 ngToast.create(egCore.strings.ITEMS_SUCCESSFULLY_MODIFIED);
663 $scope.refreshGridData();
665 $scope.$on('$destroy', function() {
666 holdings_bChannel.close();
673 * Detail view -- shows one copy
675 .controller('ViewCtrl',
676 ['$scope','$q','$location','$routeParams','$timeout','$window','egCore','egItem','egBilling','egCirc',
677 function($scope , $q , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling , egCirc) {
678 var copyId = $routeParams.id;
679 $scope.args.copyId = copyId;
680 $scope.tab = $routeParams.tab || 'summary';
681 $scope.context.page = 'detail';
682 $scope.summaryRecord = null;
685 if ($scope.tab == 'edit') {
686 $scope.tab = 'summary';
691 // use the cached record info
693 $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
694 return !aca.ack_time();
696 $scope.recordId = itemSvc.copy.call_number().record().id();
697 $scope.args.recordId = $scope.recordId;
698 $scope.args.cnId = itemSvc.copy.call_number().id();
699 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
700 $scope.args.cnLabel = itemSvc.copy.call_number().label();
701 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
702 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
703 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
704 $scope.args.copyBarcode = itemSvc.copy.barcode();
707 function loadCopy(barcode) {
708 $scope.context.itemNotFound = false;
710 // Avoid re-fetching the same copy while jumping tabs.
711 // In addition to being quicker, this helps to avoid flickering
712 // of the top panel which is always visible in the detail view.
714 // 'barcode' represents the loading of a new item - refetch it
715 // regardless of whether it matches the current item.
716 if (!barcode && itemSvc.copy && itemSvc.copy.id() == copyId) {
717 $scope.copy = itemSvc.copy;
718 if (itemSvc.latest_inventory && itemSvc.latest_inventory.copy() == copyId) {
719 $scope.latest_inventory = itemSvc.latest_inventory;
721 $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
722 return !aca.ack_time();
724 $scope.recordId = itemSvc.copy.call_number().record().id();
725 $scope.args.recordId = $scope.recordId;
726 $scope.args.cnId = itemSvc.copy.call_number().id();
727 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
728 $scope.args.cnLabel = itemSvc.copy.call_number().label();
729 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
730 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
731 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
732 $scope.args.copyBarcode = itemSvc.copy.barcode();
739 var deferred = $q.defer();
740 itemSvc.fetch(barcode, copyId, true).then(function(res) {
741 $scope.context.selectBarcode = true;
745 $scope.context.itemNotFound = true;
746 egCore.audio.play('warning.item_status.itemNotFound');
747 deferred.reject(); // avoid propagation of data fetch calls
753 if (res.latest_inventory) itemSvc.latest_inventory = res.latest_inventory;
757 $scope.latest_inventory = res.latest_inventory;
758 $scope.copy_alert_count = copy.copy_alerts().filter(function(aca) {
759 return !aca.ack_time();
761 console.debug($scope.copy_alert_count);
762 $scope.recordId = copy.call_number().record().id();
763 $scope.args.recordId = $scope.recordId;
764 $scope.args.cnId = itemSvc.copy.call_number().id();
765 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
766 $scope.args.cnLabel = itemSvc.copy.call_number().label();
767 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
768 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
769 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
770 $scope.args.copyBarcode = copy.barcode();
771 $scope.args.barcode = '';
773 // locally flesh org units
774 copy.circ_lib(egCore.org.get(copy.circ_lib()));
775 copy.call_number().owning_lib(
776 egCore.org.get(copy.call_number().owning_lib()));
778 var r = copy.call_number().record();
779 if (r.owner()) r.owner(egCore.org.get(r.owner()));
781 // make boolean for auto-magic true/false display
783 ['ref','opac_visible','holdable','circulate'],
784 function(field) { copy[field](Boolean(copy[field]() == 't')) }
787 // finally, if this is a different copy, redirect.
788 // Note that we flesh first since the copy we just
789 // fetched will be used after the redirect.
790 if (copyId && copyId != copy.id()) {
791 // if a new barcode is scanned in the detail view,
792 // update the url to match the ID of the new copy
793 $location.path('/cat/item/' + copy.id() + '/' + $scope.tab);
794 deferred.reject(); // avoid propagation of data fetch calls
802 return deferred.promise;
805 // load the two most recent circulations in /circs tab
806 function loadCurrentCirc() {
808 delete $scope.circ_summary;
809 delete $scope.prev_circ_summary;
810 delete $scope.prev_circ_usr;
814 itemSvc.copy.call_number().id() == -1 ?
815 itemSvc.copy.circ_lib().id() :
816 itemSvc.copy.call_number().owning_lib().id();
818 // since a user can still view patron checkout history here, check perms
819 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
820 .then(function(orgIds){
821 if(orgIds.indexOf(copy_org) == -1){
822 console.warn('User is not allowed to view circ history!');
826 return fetchMaxCircHistory();
828 .then(function(maxHistCount){
830 if (!maxHistCount) $scope.isMaxCircHistoryZero = true;
832 egCore.pcrud.search('aacs',
833 {target_copy : copyId},
839 'checkin_workstation',
842 'recurring_fine_rule'
846 order_by : {aacs : 'xact_start desc'},
850 ).then(null, null, function(circ) {
853 if (!circ) return $q.when();
855 // load the chain for this circ
858 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
859 egCore.auth.token(), $scope.circ.id()
860 ).then(function(summary) {
861 $scope.circ_summary = summary;
864 if (maxHistCount <= 1) return;
866 // load the chain for the previous circ, plus the user
869 'open-ils.circ.prev_renewal_chain.retrieve_by_circ.summary',
870 egCore.auth.token(), $scope.circ.id()
872 ).then(null, null, function(summary) {
873 $scope.prev_circ_summary = summary.summary;
875 if (summary.usr) { // aged circs have no 'usr'.
876 egCore.pcrud.retrieve('au', summary.usr,
877 {flesh : 1, flesh_fields : {au : ['card']}})
879 .then(function(user) { $scope.prev_circ_usr = user });
887 function fetchMaxCircHistory() {
888 if (maxHistory) return $q.when(maxHistory);
889 return egCore.org.settings(
890 'circ.item_checkout_history.max')
891 .then(function(set) {
892 maxHistory = set['circ.item_checkout_history.max'] || 4;
893 return Number(maxHistory);
897 $scope.addBilling = function(circ) {
898 egBilling.showBillDialog({
904 $scope.retrieveAllPatrons = function() {
905 var users = new Set();
906 angular.forEach($scope.circ_list.map(function(circ) { return circ.usr(); }),function(usr) {
907 // aged circs have no 'usr'.
908 if (usr) users.add(usr);
910 users.forEach(function(usr) {
911 $timeout(function() {
912 var url = $location.absUrl().replace(
914 '/circ/patron/' + usr.id() + '/checkout');
915 $window.open(url, '_blank')
920 // load data for /circ_list tab
921 function loadCircHistory() {
922 $scope.circ_list = [];
925 itemSvc.copy.call_number().id() == -1 ?
926 itemSvc.copy.circ_lib().id() :
927 itemSvc.copy.call_number().owning_lib().id();
929 // there is an extra layer of permissibility over circ
931 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
932 .then(function(orgIds) {
934 if (orgIds.indexOf(copy_org) == -1) {
935 console.log('User is not allowed to view circ history');
939 return fetchMaxCircHistory();
941 }).then(function(maxHistCount) {
943 if(!maxHistCount) $scope.isMaxCircHistoryZero = true;
945 egCore.pcrud.search('aacs',
946 {target_copy : copyId},
952 'checkin_workstation',
953 'recurring_fine_rule'
957 order_by : {aacs : 'xact_start desc'},
958 // fetch at least one to see if copy ever circulated
959 limit : $scope.isMaxCircHistoryZero ? 1 : maxHistCount
962 ).then(null, null, function(circ) {
966 // flesh circ_lib locally
967 circ.circ_lib(egCore.org.get(circ.circ_lib()));
968 circ.checkin_lib(egCore.org.get(circ.checkin_lib()));
969 $scope.circ_list.push(circ);
975 function loadCircCounts() {
977 delete $scope.circ_counts;
978 $scope.total_circs = 0;
979 $scope.total_circs_this_year = 0;
980 $scope.total_circs_prev_year = 0;
983 egCore.pcrud.search('circbyyr',
984 {copy : copyId}, null, {atomic : true})
986 .then(function(counts) {
987 $scope.circ_counts = counts;
989 angular.forEach(counts, function(count) {
990 $scope.total_circs += Number(count.count());
993 var this_year = counts.filter(function(c) {
994 return c.year() == new Date().getFullYear();
997 $scope.total_circs_this_year = (function() {
999 if (this_year.length == 2) {
1000 total = (Number(this_year[0].count()) + Number(this_year[1].count()));
1001 } else if (this_year.length == 1) {
1002 total = Number(this_year[0].count());
1007 var prev_year = counts.filter(function(c) {
1008 return c.year() == new Date().getFullYear() - 1;
1011 $scope.total_circs_prev_year = (function() {
1013 if (prev_year.length == 2) {
1014 total = (Number(prev_year[0].count()) + Number(prev_year[1].count()));
1015 } else if (prev_year.length == 1) {
1016 total = Number(prev_year[0].count());
1024 function loadHolds() {
1026 if (!copyId) return;
1028 egCore.pcrud.search('ahr',
1029 { current_copy : copyId,
1031 fulfillment_time : null,
1032 capture_time : {'<>' : null}
1036 ahr : ['requestor', 'usr'],
1040 ).then(null, null, function(hold) {
1042 hold.pickup_lib(egCore.org.get(hold.pickup_lib()));
1043 if (hold.current_shelf_lib()) {
1044 hold.current_shelf_lib(
1045 egCore.org.get(hold.current_shelf_lib()));
1047 hold.behind_desk(Boolean(hold.behind_desk() == 't'));
1051 function loadMostRecentTransit() {
1052 delete $scope.transit;
1053 delete $scope.hold_transit;
1054 if (!copyId) return;
1056 egCore.pcrud.search('atc',
1057 {target_copy : copyId},
1059 order_by : {atc : 'source_send_time DESC'},
1063 ).then(null, null, function(transit) {
1064 // use progress callback since we'll get up to one result
1065 $scope.transit = transit;
1066 transit.source(egCore.org.get(transit.source()));
1067 transit.dest(egCore.org.get(transit.dest()));
1072 // we don't need all data on all tabs, so fetch what's needed when needed.
1073 function loadTabData() {
1074 switch($scope.tab) {
1090 loadMostRecentTransit();
1093 case 'triggered_events':
1094 var url = $location.absUrl().replace(/\/staff.*/, '/actor/user/event_log');
1095 url += '?copy_id=' + encodeURIComponent(copyId);
1096 $scope.triggered_events_url = url;
1103 'open-ils.actor.anon_cache.set_value',
1104 null, 'edit-these-copies', {
1105 record_id: $scope.recordId,
1110 ).then(function(key) {
1112 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1113 $window.location.href = url;
1115 alert('Could not create anonymous cache key!');
1123 $scope.addCopyAlerts = function(copy_id) {
1124 egCirc.add_copy_alerts([copy_id]).then(function() {
1126 loadCopy($scope.copy.barcode()).then(loadTabData);
1129 $scope.manageCopyAlerts = function(copy_id) {
1130 egCirc.manage_copy_alerts([copy_id]).then(function() {
1132 loadCopy($scope.copy.barcode()).then(loadTabData);
1136 $scope.context.toggleDisplay = function() {
1137 $location.path('/cat/item/search');
1140 // handle the barcode scan box, which will replace our current copy
1141 $scope.context.search = function(args) {
1142 loadCopy(args.barcode).then(loadTabData);
1145 $scope.context.show_triggered_events = function() {
1146 $location.path('/cat/item/' + copyId + '/triggered_events');
1149 loadCopy().then(loadTabData);