5 angular.module('egItemStatus',
6 ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egGridMod', 'egUserMod'])
8 .filter('boolText', function(){
14 .config(function($routeProvider, $locationProvider, $compileProvider) {
15 $locationProvider.html5Mode(true);
16 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|mailto|blob):/); // grid export
18 var resolver = {delay : function(egStartup) {return egStartup.go()}};
20 // search page shows the list view by default
21 $routeProvider.when('/cat/item/search', {
22 templateUrl: './cat/item/t_list',
23 controller: 'ListCtrl',
27 // search page shows the list view by default
28 $routeProvider.when('/cat/item/search/:idList', {
29 templateUrl: './cat/item/t_list',
30 controller: 'ListCtrl',
34 $routeProvider.when('/cat/item/:id', {
35 templateUrl: './cat/item/t_view',
36 controller: 'ViewCtrl',
40 $routeProvider.when('/cat/item/:id/:tab', {
41 templateUrl: './cat/item/t_view',
42 controller: 'ViewCtrl',
46 // default page / bucket view
47 $routeProvider.otherwise({redirectTo : '/cat/item/search'});
51 * Search bar along the top of the page.
52 * Parent scope for list and detail views
54 .controller('SearchCtrl',
55 ['$scope','$q','$window','$location','$timeout','egCore','egNet','egGridDataProvider','egItem', 'egCirc', 'ngToast',
56 function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc , egCirc, ngToast) {
57 $scope.args = {}; // search args
59 // sub-scopes (search / detail-view) apply their version
60 // of retrieval function to $scope.context.search
61 // and display toggling via $scope.context.toggleDisplay
66 $scope.toggleView = function($event) {
67 $scope.context.toggleDisplay();
68 $event.preventDefault(); // avoid form submission
71 // The functions that follow in this controller are never called
72 // when the List View is active, only the Detail View.
74 // In this context, we're only ever dealing with 1 item, so
75 // we can simply refresh the page. These various itemSvc
76 // functions used to live in the ListCtrl, but they're now
77 // shared between SearchCtrl (for Actions for the Detail View)
78 // and ListCtrl (Actions in the egGrid)
79 itemSvc.add_barcode_to_list = function(b) {
80 //console.log('SearchCtrl: add_barcode_to_list',b);
81 // timeout so audible can happen upon checkin
82 $timeout(function() { location.href = location.href; }, 1000);
85 $scope.add_copies_to_bucket = function() {
86 itemSvc.add_copies_to_bucket([$scope.args.copyId]);
89 $scope.add_records_to_bucket = function() {
90 itemSvc.add_records_to_bucket([$scope.args.recordId], 'biblio');
93 $scope.show_in_catalog = function() {
94 window.open('/eg2/staff/catalog/record/' + $scope.args.recordId, '_blank');
97 $scope.print_labels = function() {
98 itemSvc.print_spine_labels([$scope.args.copyId]);
102 $scope.make_copies_bookable = function() {
103 itemSvc.make_copies_bookable([{
104 id : $scope.args.copyId,
105 'call_number.record.id' : $scope.args.recordId
109 $scope.book_copies_now = function() {
110 itemSvc.book_copies_now([$scope.args.copyBarcode]);
113 $scope.findAcquisition = function() {
116 $scope.openAcquisitionLineItem([$scope.args.copyId]);
119 $scope.openAcquisitionLineItem = function (cp_list) {
120 var hasResults = false;
123 angular.forEach(cp_list, function (copyId) {
127 'open-ils.acq.lineitem.retrieve.by_copy_id',
130 ).then(function (acqData) {
133 acqData = egCore.idl.toHash(acqData);
134 var url = '/eg/acq/po/view/' + acqData.purchase_order + '/' + acqData.id;
135 $timeout(function () { $window.open(url, '_blank') });
143 $q.all(promises).then(function () {
144 !hasResults ? alert('There is no corresponding purchase order for this item.') : false;
148 $scope.manage_reservations = function() {
149 itemSvc.manage_reservations([$scope.args.copyBarcode]);
152 $scope.requestItems = function() {
153 itemSvc.requestItems([$scope.args.copyId],[$scope.args.recordId]);
156 $scope.update_inventory = function() {
157 itemSvc.updateInventory([$scope.args.copyId], null)
158 .then(function(res) {
160 ngToast.create(egCore.strings.SUCCESS_UPDATE_INVENTORY_SINGLE);
162 ngToast.warning(egCore.strings.FAIL_UPDATE_INVENTORY_SINGLE);
164 $timeout(function() { location.href = location.href; }, 1500);
168 $scope.show_triggered_events = function() {
169 window.open('/eg2/staff/circ/item/event-log/' + $scope.args.copyId, '_blank');
172 $scope.show_item_holds = function() {
173 $location.path('/cat/item/' + $scope.args.copyId + '/holds');
176 $scope.show_record_holds = function() {
177 window.open('/eg2/staff/catalog/record/' + $scope.args.recordId + '/holds', '_blank');
180 $scope.add_item_alerts = function() {
181 egCirc.add_copy_alerts([$scope.args.copyId]);
184 $scope.manage_item_alerts = function() {
185 egCirc.manage_copy_alerts([$scope.args.copyId]);
189 $scope.attach_to_peer_bib = function() {
190 itemSvc.attach_to_peer_bib([{
191 id : $scope.args.copyId,
192 barcode : $scope.args.copyBarcode
196 $scope.selectedHoldingsCopyDelete = function () {
197 itemSvc.selectedHoldingsCopyDelete([{
198 id : $scope.args.copyId,
199 barcode : $scope.args.copyBarcode
203 $scope.checkin = function () {
205 id : $scope.args.copyId,
206 barcode : $scope.args.copyBarcode
210 $scope.renew = function () {
212 id : $scope.args.copyId,
213 barcode : $scope.args.copyBarcode
217 $scope.cancel_transit = function () {
218 itemSvc.cancel_transit([{
219 id : $scope.args.copyId,
220 barcode : $scope.args.copyBarcode
224 $scope.selectedHoldingsDamaged = function () {
225 itemSvc.selectedHoldingsDamaged([{
226 id : $scope.args.copyId,
227 barcode : $scope.args.copyBarcode,
232 $scope.selectedHoldingsDiscard = function () {
233 itemSvc.selectedHoldingsDiscard([{
234 id : $scope.args.copyId,
235 barcode : $scope.args.barcode
239 $scope.selectedHoldingsMissing = function () {
240 itemSvc.selectedHoldingsMissing([{
241 id : $scope.args.copyId,
242 barcode : $scope.args.barcode
246 $scope.selectedHoldingsVolCopyAdd = function () {
247 itemSvc.spawnHoldingsAdd([{
248 id : $scope.args.copyId,
249 'call_number.owning_lib' : $scope.args.cnOwningLib,
250 'call_number.record.id' : $scope.args.recordId,
251 barcode : $scope.args.copyBarcode
254 $scope.selectedHoldingsCopyAdd = function () {
255 itemSvc.spawnHoldingsAdd([{
256 id : $scope.args.copyId,
257 'call_number.id' : $scope.args.cnId,
258 'call_number.owning_lib' : $scope.args.cnOwningLib,
259 'call_number.record.id' : $scope.args.recordId,
260 barcode : $scope.args.copyBarcode
264 $scope.selectedHoldingsVolCopyEdit = function () {
265 itemSvc.spawnHoldingsEdit([{
266 id : $scope.args.copyId,
267 'call_number.id' : $scope.args.cnId,
268 'call_number.owning_lib' : $scope.args.cnOwningLib,
269 'call_number.record.id' : $scope.args.recordId,
270 barcode : $scope.args.copyBarcode
273 $scope.selectedHoldingsVolEdit = function () {
274 itemSvc.spawnHoldingsEdit([{
275 id : $scope.args.copyId,
276 'call_number.id' : $scope.args.cnId,
277 'call_number.owning_lib' : $scope.args.cnOwningLib,
278 'call_number.record.id' : $scope.args.recordId,
279 barcode : $scope.args.copyBarcode
282 $scope.selectedHoldingsCopyEdit = function () {
283 itemSvc.spawnHoldingsEdit([{
284 id : $scope.args.copyId,
285 'call_number.id' : $scope.args.cnId,
286 'call_number.owning_lib' : $scope.args.cnOwningLib,
287 'call_number.record.id' : $scope.args.recordId,
288 barcode : $scope.args.copyBarcode
292 $scope.replaceBarcodes = function() {
293 itemSvc.replaceBarcodes([{
294 id : $scope.args.copyId,
295 barcode : $scope.args.copyBarcode
299 $scope.changeItemOwningLib = function() {
300 itemSvc.changeItemOwningLib([{
301 id : $scope.args.copyId,
302 'call_number.id' : $scope.args.cnId,
303 'call_number.owning_lib' : $scope.args.cnOwningLib,
304 'call_number.record.id' : $scope.args.recordId,
305 'call_number.label' : $scope.args.cnLabel,
306 'call_number.label_class' : $scope.args.cnLabelClass,
307 'call_number.prefix.id' : $scope.args.cnPrefixId,
308 'call_number.suffix.id' : $scope.args.cnSuffixId,
309 barcode : $scope.args.copyBarcode
313 $scope.transferItems = function (){
314 itemSvc.transferItems([{
315 id : $scope.args.copyId,
316 barcode : $scope.args.copyBarcode
323 * List view - grid stuff
325 .controller('ListCtrl',
326 ['$scope','$q','$routeParams','$location','$timeout','$window','egCore',
327 'egGridDataProvider','egItem','egUser','$uibModal','egCirc','egConfirmDialog',
328 'egProgressDialog', 'ngToast',
329 // function($scope , $q , $routeParams , $location , $timeout , $window , egCore ,
330 // egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog,
331 // egProgressDialog, ngToast) {
332 function($scope , $q , $routeParams , $location , $timeout , $window , egCore , egGridDataProvider , itemSvc , egUser , $uibModal , egCirc , egConfirmDialog,
333 egProgressDialog, ngToast) {
335 var cp_list = $routeParams.idList;
337 copyId = cp_list.split(',');
340 var modified_items = new Set();
342 $scope.context.page = 'list';
345 var provider = egGridDataProvider.instance();
346 provider.get = function(offset, count) {
350 $scope.gridDataProvider = egGridDataProvider.instance({
351 get : function(offset, count) {
352 //return provider.arrayNotifier(itemSvc.copies, offset, count);
353 return this.arrayNotifier(itemSvc.copies, offset, count);
357 // If a copy was just displayed in the detail view, ensure it's
358 // focused in the list view.
359 var selected = false;
360 var copyGrid = $scope.gridControls = {
361 itemRetrieved : function(item) {
362 if (selected || !itemSvc.copy) return;
363 if (itemSvc.copy.id() == item.id) {
364 copyGrid.selectItems([item.index]);
370 $scope.$watch('barcodesFromFile', function(newVal, oldVal) {
371 $scope.context.itemsNotFound = [];
372 $scope.context.fileDoneLoading = false;
373 $scope.context.numBarcodesInFile = 0;
374 if (newVal && newVal != oldVal) {
375 $scope.args.barcode = '';
378 angular.forEach(newVal.split(/\r?\n/), function(line) {
379 //remove all whitespace and commas
380 line = line.replace(/[\s,]+/g,'');
382 //Or remove leading/trailing whitespace
383 //line = line.replace(/(^[\s,]+|[\s,]+$/g,'');
389 // Serialize copy retrieval since there may be many, many copies.
390 function fetch_next_copy() {
391 var barcode = barcodes.pop();
392 egProgressDialog.increment();
394 if (barcode == undefined) { // All done here.
395 egProgressDialog.close();
397 if(itemSvc.copies[0]){ // Were any copies actually retrieved
398 copyGrid.selectItems([itemSvc.copies[0].index]);
400 $scope.context.fileDoneLoading = true;
404 itemSvc.fetch(barcode).then(function(item) {
406 $scope.context.itemsNotFound.push(barcode);
412 if (barcodes.length) {
413 $scope.context.numBarcodesInFile = barcodes.length;
414 egProgressDialog.open({value: 0, max: barcodes.length});
420 $scope.context.search = function(args, noGridRefresh) {
421 if (!args.barcode) return $q.when();
422 $scope.context.itemNotFound = false;
424 //check to see if there are multiple barcodes in CSV format
426 //split on commas and clean up barcodes
427 angular.forEach(args.barcode.split(/,/), function(line) {
428 //remove all whitespace and commas
429 line = line.replace(/[\s,]+/g,'');
431 //Or remove leading/trailing whitespace
432 //line = line.replace(/(^[\s,]+|[\s,]+$/g,'');
438 if(barcodes.length > 1){
439 //convert to newline seperated list and send to barcodesFromFile processor
440 $scope.barcodesFromFile = barcodes.join('\n');
441 //console.log('Barcodes: ',barcodes);
446 return itemSvc.fetch(args.barcode).then(function(res) {
448 if (!noGridRefresh) {
451 copyGrid.selectItems([res.index]);
452 $scope.args.barcode = '';
454 $scope.context.itemNotFound = true;
455 egCore.audio.play('warning.item_status.itemNotFound');
457 $scope.context.selectBarcode = true;
462 var add_barcode_to_list = function (b, noGridRefresh) {
463 // console.log('listCtrl: add_barcode_to_list',b);
464 return $scope.context.search({barcode:b}, noGridRefresh);
466 itemSvc.add_barcode_to_list = add_barcode_to_list;
468 $scope.context.toggleDisplay = function() {
469 var item = copyGrid.selectedItems()[0];
471 $location.path('/cat/item/' + item.id);
474 $scope.context.show_triggered_events = function() {
475 var item = copyGrid.selectedItems()[0];
477 window.open('/eg2/staff/circ/item/event-log/' + item.id, '_blank');
480 function gatherSelectedRecordIds () {
483 copyGrid.selectedItems(),
485 if (rid_list.indexOf(item['call_number.record.id']) == -1)
486 rid_list.push(item['call_number.record.id'])
492 function gatherSelectedVolumeIds (rid) {
495 copyGrid.selectedItems(),
497 if (rid && item['call_number.record.id'] != rid) return;
498 if (cn_id_list.indexOf(item['call_number.id']) == -1)
499 cn_id_list.push(item['call_number.id'])
505 function gatherSelectedHoldingsIds (rid) {
508 copyGrid.selectedItems(),
510 if (rid && item['call_number.record.id'] != rid) return;
511 cp_id_list.push(item.id)
517 function gatherSelectedHoldingsRecords() {
518 var record_id_list = [];
520 copyGrid.selectedItems(),
522 record_id_list.push(item['call_number.record.id']);
525 return record_id_list;
528 $scope.refreshGridData = function() {
529 var chain = $q.when();
530 var all_items = itemSvc.copies.map(function(item) {
533 angular.forEach(all_items.reverse(), function(i) {
534 itemSvc.copies.shift();
535 chain = chain.then(function() {
536 return itemSvc.fetch(null, i);
539 return chain.then(function() {
545 $scope.add_copies_to_bucket = function() {
546 var copy_list = gatherSelectedHoldingsIds();
547 itemSvc.add_copies_to_bucket(copy_list);
550 $scope.add_records_to_bucket = function() {
551 var record_list = gatherSelectedHoldingsRecords();
552 itemSvc.add_copies_to_bucket(record_list, 'biblio');
555 $scope.locateAcquisition = function() {
556 if (gatherSelectedHoldingsIds) {
557 var cp_list = gatherSelectedHoldingsIds();
559 if (cp_list.length > 0) {
560 $scope.openAcquisitionLineItem(cp_list);
566 $scope.update_inventory = function() {
567 var copy_list = gatherSelectedHoldingsIds();
568 itemSvc.updateInventory(copy_list, $scope.gridControls.allItems()).then(function(res) {
570 ngToast.create(egCore.strings.SUCCESS_UPDATE_INVENTORY);
572 ngToast.warning(egCore.strings.FAIL_UPDATE_INVENTORY);
577 $scope.need_one_selected = function() {
578 var items = $scope.gridControls.selectedItems();
579 if (items.length == 1) return false;
583 $scope.make_copies_bookable = function() {
584 itemSvc.make_copies_bookable(copyGrid.selectedItems());
587 $scope.book_copies_now = function() {
588 var item = copyGrid.selectedItems()[0];
590 itemSvc.book_copies_now(item.barcode);
593 $scope.manage_reservations = function() {
594 var item = copyGrid.selectedItems()[0];
596 itemSvc.manage_reservations(item.barcode);
599 $scope.requestItems = function() {
600 var copy_list = gatherSelectedHoldingsIds();
601 var record_list = gatherSelectedRecordIds();
602 itemSvc.requestItems(copy_list,record_list);
605 $scope.replaceBarcodes = function() {
606 itemSvc.replaceBarcodes(copyGrid.selectedItems());
609 $scope.attach_to_peer_bib = function() {
610 itemSvc.attach_to_peer_bib(copyGrid.selectedItems());
613 $scope.selectedHoldingsCopyDelete = function () {
614 itemSvc.selectedHoldingsCopyDelete(copyGrid.selectedItems());
617 $scope.selectedHoldingsItemStatusTgrEvt= function() {
618 var item = copyGrid.selectedItems()[0];
620 window.open('/eg2/staff/circ/item/event-log/' + item.id, '_blank');
623 $scope.selectedHoldingsItemStatusHolds= function() {
624 var item = copyGrid.selectedItems()[0];
626 $location.path('/cat/item/' + item.id + '/holds');
629 $scope.cancel_transit = function () {
630 itemSvc.cancel_transit(copyGrid.selectedItems());
633 $scope.selectedHoldingsDamaged = function () {
634 itemSvc.selectedHoldingsDamaged(copyGrid.selectedItems());
637 $scope.selectedHoldingsDiscard = function () {
638 itemSvc.selectedHoldingsDiscard(copyGrid.selectedItems());
641 $scope.selectedHoldingsMissing = function () {
642 egProgressDialog.open();
643 itemSvc.selectedHoldingsMissing(copyGrid.selectedItems())
645 egProgressDialog.close();
646 console.debug('Marking missing complete, refreshing grid');
651 $scope.checkin = function () {
652 itemSvc.checkin(copyGrid.selectedItems());
655 $scope.renew = function () {
656 itemSvc.renew(copyGrid.selectedItems());
659 $scope.selectedHoldingsVolCopyAdd = function () {
660 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),true,false);
662 $scope.selectedHoldingsCopyAdd = function () {
663 itemSvc.spawnHoldingsAdd(copyGrid.selectedItems(),false,true);
666 $scope.selectedHoldingsCopyAlertsAdd = function(items) {
668 angular.forEach(items, function(item) {
669 if (item.id) copy_ids.push(item.id);
671 egCirc.add_copy_alerts(copy_ids).then(function() {
672 // update grid items?
676 $scope.selectedHoldingsCopyAlertsEdit = function(items) {
678 angular.forEach(items, function(item) {
679 if (item.id) copy_ids.push(item.id);
681 egCirc.manage_copy_alerts(copy_ids).then(function() {
682 // update grid items?
686 $scope.gridCellHandlers = {};
687 $scope.gridCellHandlers.copyAlertsEdit = function(id) {
688 egCirc.manage_copy_alerts([id]).then(function() {
689 // update grid items?
693 $scope.showBibHolds = function () {
694 angular.forEach(gatherSelectedRecordIds(), function (r) {
695 var url = '/eg2/staff/catalog/record/' + r + '/holds';
696 $timeout(function() { $window.open(url, '_blank') });
700 $scope.selectedHoldingsVolCopyEdit = function () {
701 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,false);
703 $scope.selectedHoldingsVolEdit = function () {
704 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),false,true);
706 $scope.selectedHoldingsCopyEdit = function () {
707 itemSvc.spawnHoldingsEdit(copyGrid.selectedItems(),true,false);
710 $scope.changeItemOwningLib = function() {
711 itemSvc.changeItemOwningLib(copyGrid.selectedItems());
714 $scope.transferItems = function (){
715 itemSvc.transferItems(copyGrid.selectedItems());
718 $scope.print_labels = function() {
721 'open-ils.actor.anon_cache.set_value',
722 null, 'print-labels-these-copies', {
723 copies : gatherSelectedHoldingsIds()
725 ).then(function(key) {
727 var url = egCore.env.basePath + 'cat/printlabels/' + key;
728 $timeout(function() { $window.open(url, '_blank') });
730 alert('Could not create anonymous cache key!');
735 $scope.print_list = function() {
736 var print_data = { copies : copyGrid.allItems() };
738 if (print_data.copies.length == 0) return $q.when();
740 return egCore.print.print({
741 template : 'item_status',
746 $scope.show_in_catalog = function(){
747 itemSvc.show_in_catalog(copyGrid.selectedItems());
750 if (copyId.length > 0) {
752 angular.forEach(copyId, function (c) {
753 fetch_list.push(itemSvc.fetch(null,c));
756 return $q.all(fetch_list).then(function (res) { copyGrid.refresh(); });
759 $scope.statusIconColumn = {
761 template: function(item) {
763 if (modified_items.has(item['id'])) {
764 icon = '<span class="glyphicon glyphicon-floppy-saved"' +
765 'title="' + egCore.strings.ITEM_SUCCESSFULLY_MODIFIED + '" ' +
766 'aria-label="' + egCore.strings.ITEM_SUCCESSFULLY_MODIFIED + '">' +
773 if (typeof BroadcastChannel != 'undefined') {
774 var holdings_bChannel = new BroadcastChannel("eg.holdings.update");
775 holdings_bChannel.onmessage = function(e) {
776 angular.forEach(e.data.copies, function(i) {
777 modified_items.add(i);
779 ngToast.create(egCore.strings.ITEMS_SUCCESSFULLY_MODIFIED);
780 $scope.refreshGridData();
782 $scope.$on('$destroy', function() {
783 holdings_bChannel.close();
790 * Detail view -- shows one copy
792 .controller('ViewCtrl',
793 ['$scope','$q','egGridDataProvider','$location','$routeParams','$timeout','$window','egCore','egItem','egBilling','egCirc',
794 function($scope , $q , egGridDataProvider , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling , egCirc) {
795 var copyId = $routeParams.id;
796 $scope.args.copyId = copyId;
797 $scope.tab = $routeParams.tab || 'summary';
798 $scope.context.page = 'detail';
799 $scope.summaryRecord = null;
800 $scope.courseModulesOptIn = fetchCourseOptIn();
801 $scope.has_course_perms = fetchCoursePerms();
803 if ($scope.tab == 'edit') {
804 $scope.tab = 'summary';
808 // use the cached record info
810 $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
811 return !aca.ack_time();
813 $scope.recordId = itemSvc.copy.call_number().record().id();
814 $scope.args.recordId = $scope.recordId;
815 $scope.args.cnId = itemSvc.copy.call_number().id();
816 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
817 $scope.args.cnLabel = itemSvc.copy.call_number().label();
818 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
819 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
820 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
821 $scope.args.copyBarcode = itemSvc.copy.barcode();
824 function loadCopy(barcode) {
825 $scope.context.itemNotFound = false;
827 // Avoid re-fetching the same copy while jumping tabs.
828 // In addition to being quicker, this helps to avoid flickering
829 // of the top panel which is always visible in the detail view.
831 // 'barcode' represents the loading of a new item - refetch it
832 // regardless of whether it matches the current item.
833 if (!barcode && itemSvc.copy && itemSvc.copy.id() == copyId) {
834 $scope.copy = itemSvc.copy;
835 if (itemSvc.latest_inventory && itemSvc.latest_inventory.copy() == copyId) {
836 $scope.latest_inventory = itemSvc.latest_inventory;
838 $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
839 return !aca.ack_time();
841 $scope.recordId = itemSvc.copy.call_number().record().id();
842 $scope.args.recordId = $scope.recordId;
843 $scope.args.cnId = itemSvc.copy.call_number().id();
844 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
845 $scope.args.cnLabel = itemSvc.copy.call_number().label();
846 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
847 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
848 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
849 $scope.args.copyBarcode = itemSvc.copy.barcode();
856 var deferred = $q.defer();
857 itemSvc.fetch(barcode, copyId, true).then(function(res) {
858 $scope.context.selectBarcode = true;
862 $scope.context.itemNotFound = true;
863 egCore.audio.play('warning.item_status.itemNotFound');
864 deferred.reject(); // avoid propagation of data fetch calls
870 if (res.latest_inventory) itemSvc.latest_inventory = res.latest_inventory;
874 $scope.latest_inventory = res.latest_inventory;
875 $scope.copy_alert_count = copy.copy_alerts().filter(function(aca) {
876 return !aca.ack_time();
878 console.debug($scope.copy_alert_count);
879 $scope.recordId = copy.call_number().record().id();
880 $scope.args.recordId = $scope.recordId;
881 $scope.args.cnId = itemSvc.copy.call_number().id();
882 $scope.args.cnOwningLib = itemSvc.copy.call_number().owning_lib();
883 $scope.args.cnLabel = itemSvc.copy.call_number().label();
884 $scope.args.cnLabelClass = itemSvc.copy.call_number().label_class();
885 $scope.args.cnPrefixId = itemSvc.copy.call_number().prefix().id();
886 $scope.args.cnSuffixId = itemSvc.copy.call_number().suffix().id();
887 $scope.args.copyBarcode = copy.barcode();
888 $scope.args.barcode = '';
890 // locally flesh org units
891 copy.circ_lib(egCore.org.get(copy.circ_lib()));
892 copy.call_number().owning_lib(
893 egCore.org.get(copy.call_number().owning_lib()));
895 var r = copy.call_number().record();
896 if (r.owner()) r.owner(egCore.org.get(r.owner()));
898 // make boolean for auto-magic true/false display
900 ['ref','opac_visible','holdable','circulate'],
901 function(field) { copy[field](Boolean(copy[field]() == 't')) }
904 // finally, if this is a different copy, redirect.
905 // Note that we flesh first since the copy we just
906 // fetched will be used after the redirect.
907 if (copyId && copyId != copy.id()) {
908 // if a new barcode is scanned in the detail view,
909 // update the url to match the ID of the new copy
910 $location.path('/cat/item/' + copy.id() + '/' + $scope.tab);
911 deferred.reject(); // avoid propagation of data fetch calls
919 return deferred.promise;
922 // load the two most recent circulations in /circs tab
923 function loadCurrentCirc() {
925 delete $scope.circ_summary;
926 delete $scope.prev_circ_summary;
927 delete $scope.prev_circ_usr;
931 itemSvc.copy.call_number().id() == -1 ?
932 itemSvc.copy.circ_lib().id() :
933 itemSvc.copy.call_number().owning_lib().id();
935 // since a user can still view patron checkout history here, check perms
936 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
937 .then(function(orgIds){
938 if(orgIds.indexOf(copy_org) == -1){
939 console.warn('User is not allowed to view circ history!');
943 return fetchMaxCircHistory();
945 .then(function(maxHistCount){
947 if (!maxHistCount) $scope.isMaxCircHistoryZero = true;
949 egCore.pcrud.search('aacs',
950 {target_copy : copyId},
956 'checkin_workstation',
959 'recurring_fine_rule'
963 order_by : {aacs : 'xact_start desc'},
967 ).then(null, null, function(circ) {
970 if (!circ) return $q.when();
972 // load the chain for this circ
975 'open-ils.circ.renewal_chain.retrieve_by_circ.summary',
976 egCore.auth.token(), $scope.circ.id()
977 ).then(function(summary) {
978 $scope.circ_summary = summary;
981 if (maxHistCount <= 1) return;
983 // load the chain for the previous circ, plus the user
986 'open-ils.circ.prev_renewal_chain.retrieve_by_circ.summary',
987 egCore.auth.token(), $scope.circ.id()
989 ).then(null, null, function(summary) {
990 $scope.prev_circ_summary = summary.summary;
992 if (summary.usr) { // aged circs have no 'usr'.
993 egCore.pcrud.retrieve('au', summary.usr,
994 {flesh : 1, flesh_fields : {au : ['card']}})
996 .then(function(user) { $scope.prev_circ_usr = user });
1004 function fetchMaxCircHistory() {
1005 if (maxHistory) return $q.when(maxHistory);
1006 return egCore.org.settings(
1007 'circ.item_checkout_history.max')
1008 .then(function(set) {
1009 maxHistory = set['circ.item_checkout_history.max'] || 4;
1010 return Number(maxHistory);
1014 // Check for Course Modules Opt-In to enable Course Info tab
1015 function fetchCourseOptIn() {
1016 return egCore.org.settings(
1017 'circ.course_materials_opt_in'
1018 ).then(function(set) {
1019 $scope.courseModulesOptIn = set['circ.course_materials_opt_in'];
1021 return $scope.courseModulesOptIn;
1025 function fetchCoursePerms() {
1026 return egCore.perm.hasPermAt('MANAGE RESERVES', true).then(function(orgIds) {
1027 if(orgIds.indexOf(egCore.auth.user().ws_ou()) != -1){
1028 $scope.has_course_perms = true;
1030 return $scope.has_course_perms;
1035 $scope.addBilling = function(circ) {
1036 egBilling.showBillDialog({
1037 xact_id : circ.id(),
1042 $scope.retrieveAllPatrons = function() {
1043 var users = new Set();
1044 angular.forEach($scope.circ_list.map(function(circ) { return circ.usr(); }),function(usr) {
1045 // aged circs have no 'usr'.
1046 if (usr) users.add(usr);
1048 users.forEach(function(usr) {
1049 $timeout(function() {
1050 var url = $location.absUrl().replace(
1052 '/circ/patron/' + usr.id() + '/checkout');
1053 $window.open(url, '_blank')
1058 // load data for /circ_list tab
1059 function loadCircHistory() {
1060 $scope.circ_list = [];
1063 itemSvc.copy.call_number().id() == -1 ?
1064 itemSvc.copy.circ_lib().id() :
1065 itemSvc.copy.call_number().owning_lib().id();
1067 // there is an extra layer of permissibility over circ
1069 egCore.perm.hasPermAt('VIEW_COPY_CHECKOUT_HISTORY', true)
1070 .then(function(orgIds) {
1072 if (orgIds.indexOf(copy_org) == -1) {
1073 console.log('User is not allowed to view circ history');
1077 return fetchMaxCircHistory();
1079 }).then(function(maxHistCount) {
1081 if(!maxHistCount) $scope.isMaxCircHistoryZero = true;
1083 egCore.pcrud.search('aacs',
1084 {target_copy : copyId},
1090 'checkin_workstation',
1091 'recurring_fine_rule',
1096 order_by : {aacs : 'xact_start desc'},
1097 // fetch at least one to see if copy ever circulated
1098 limit : $scope.isMaxCircHistoryZero ? 1 : maxHistCount
1101 ).then(null, null, function(circ) {
1105 // flesh circ_lib locally
1106 circ.circ_lib(egCore.org.get(circ.circ_lib()));
1107 circ.checkin_lib(egCore.org.get(circ.checkin_lib()));
1108 $scope.circ_list.push(circ);
1114 function loadCircCounts() {
1116 delete $scope.circ_counts;
1117 $scope.total_circs = 0;
1118 $scope.total_circs_this_year = 0;
1119 $scope.total_circs_prev_year = 0;
1120 $scope.circ_popover_placement = 'top';
1121 if (!copyId) return;
1123 egCore.pcrud.search('circbyyr',
1124 {copy : copyId}, null, {atomic : true})
1126 .then(function(counts) {
1127 var this_year = new Date().getFullYear();
1128 var prev_year = this_year - 1;
1130 $scope.circ_counts = counts.reduce(function(circ_counts, circbyyr) {
1131 var count = Number(circbyyr.count());
1132 var year = circbyyr.year();
1134 var index = circ_counts.findIndex(function(existing_count) {
1135 return existing_count.year === year;
1139 circ_counts.push({count: count, year: year});
1141 circ_counts[index].count += count;
1144 $scope.total_circs += count;
1145 if (this_year === year) {
1146 $scope.total_circs_this_year += count;
1148 if (prev_year === year) {
1149 $scope.total_circs_prev_year += count;
1155 if ($scope.circ_counts.length > 15) {
1156 $scope.circ_popover_placement = 'right';
1161 function loadHolds() {
1163 if (!copyId) return;
1165 egCore.pcrud.search('ahr',
1166 { current_copy : copyId,
1168 fulfillment_time : null,
1169 capture_time : {'<>' : null}
1173 ahr : ['requestor', 'usr'],
1177 ).then(null, null, function(hold) {
1179 hold.pickup_lib(egCore.org.get(hold.pickup_lib()));
1180 if (hold.current_shelf_lib()) {
1181 hold.current_shelf_lib(
1182 egCore.org.get(hold.current_shelf_lib()));
1184 hold.behind_desk(Boolean(hold.behind_desk() == 't'));
1188 function loadMostRecentTransit() {
1189 delete $scope.transit;
1190 delete $scope.hold_transit;
1191 if (!copyId) return;
1193 egCore.pcrud.search('atc',
1194 {target_copy : copyId},
1196 order_by : {atc : 'source_send_time DESC'},
1200 ).then(null, null, function(transit) {
1201 // use progress callback since we'll get up to one result
1202 $scope.transit = transit;
1203 transit.source(egCore.org.get(transit.source()));
1204 transit.dest(egCore.org.get(transit.dest()));
1208 function loadCourseInfo() {
1209 delete $scope.courses;
1210 delete $scope.instructors;
1211 delete $scope.course_ids;
1212 delete $scope.instructors_exist;
1213 if (!copyId) return;
1214 $scope.course_ids = [];
1215 $scope.courses = [];
1216 $scope.instructors = {};
1218 egCore.pcrud.search('acmcm', {
1224 }, order_by: {acmc : 'id desc'}
1225 }).then(null, null, function(material) {
1227 $scope.courses.push(material.course());
1230 'open-ils.circ.course_users.retrieve',
1231 material.course().id()
1232 ).then(null, null, function(instructors) {
1233 angular.forEach(instructors, function(instructor) {
1234 var patron_id = instructor.patron_id.toString();
1235 if (!$scope.instructors[patron_id]) {
1236 $scope.instructors[patron_id] = instructor;
1237 $scope.instructors_exist = true;
1238 $scope.instructors[patron_id]._linked_course = [];
1240 $scope.instructors[patron_id]._linked_course.push({
1241 role: instructor.usr_role,
1242 course: material.course().name()
1250 // we don't need all data on all tabs, so fetch what's needed when needed.
1251 function loadTabData() {
1252 switch($scope.tab) {
1268 loadMostRecentTransit();
1275 case 'triggered_events':
1276 var url = $location.absUrl().replace(/\/staff.*/, '/actor/user/event_log');
1277 url += '?copy_id=' + encodeURIComponent(copyId);
1278 $scope.triggered_events_url = url;
1285 'open-ils.actor.anon_cache.set_value',
1286 null, 'edit-these-copies', {
1287 record_id: $scope.recordId,
1292 ).then(function(key) {
1294 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1295 $window.location.href = url;
1297 alert('Could not create anonymous cache key!');
1305 $scope.addCopyAlerts = function(copy_id) {
1306 egCirc.add_copy_alerts([copy_id]).then(function() {
1308 loadCopy($scope.copy.barcode()).then(loadTabData);
1311 $scope.manageCopyAlerts = function(copy_id) {
1312 egCirc.manage_copy_alerts([copy_id]).then(function() {
1314 loadCopy($scope.copy.barcode()).then(loadTabData);
1318 $scope.context.toggleDisplay = function() {
1319 $location.path('/cat/item/search');
1322 // handle the barcode scan box, which will replace our current copy
1323 $scope.context.search = function(args) {
1324 loadCopy(args.barcode).then(loadTabData);
1327 $scope.context.show_triggered_events = function() {
1328 window.open('/eg2/staff/circ/item/event-log/' + copyId, '_blank');
1331 loadCopy().then(loadTabData);