4 * currently, this app doesn't use routes for each sub-ui, because
5 * reloading the catalog each time is sloooow. better so far to
6 * swap out divs w/ ng-if / ng-show / ng-hide as needed.
10 angular.module('egCatalogApp', ['ui.bootstrap','ngRoute','ngLocationUpdate','egCoreMod','egGridMod', 'egMarcMod', 'egUserMod', 'egHoldingsMod', 'ngToast','egPatronSearchMod',
11 'egSerialsMod','egSerialsAppDep'])
13 .config(['ngToastProvider', function(ngToastProvider) {
14 ngToastProvider.configure({
15 verticalPosition: 'bottom',
20 .config(function($routeProvider, $locationProvider, $compileProvider) {
21 $locationProvider.html5Mode(true);
22 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|mailto|blob):/); // grid export
24 var resolver = {delay : function(egStartup) {return egStartup.go()}};
26 $routeProvider.when('/cat/catalog/index', {
27 templateUrl: './cat/catalog/t_catalog',
28 controller: 'CatalogCtrl',
32 // Jump directly to the results page. Any URL parameter
33 // supported by the embedded catalog is supported here.
34 $routeProvider.when('/cat/catalog/results', {
35 templateUrl: './cat/catalog/t_catalog',
36 controller: 'CatalogCtrl',
40 $routeProvider.when('/cat/catalog/retrieve_by_id', {
41 templateUrl: './cat/catalog/t_retrieve_by_id',
42 controller: 'CatalogRecordRetrieve',
46 $routeProvider.when('/cat/catalog/retrieve_by_tcn', {
47 templateUrl: './cat/catalog/t_retrieve_by_tcn',
48 controller: 'CatalogRecordRetrieve',
52 $routeProvider.when('/cat/catalog/retrieve_by_authority_id', {
53 templateUrl: './cat/catalog/t_retrieve_by_authority_id',
54 controller: 'CatalogRecordRetrieve',
58 $routeProvider.when('/cat/catalog/new_bib', {
59 templateUrl: './cat/catalog/t_new_bib',
60 controller: 'NewBibCtrl',
64 // create some catalog page-specific mappings
65 $routeProvider.when('/cat/catalog/record/:record_id', {
66 templateUrl: './cat/catalog/t_catalog',
67 controller: 'CatalogCtrl',
71 // create some catalog page-specific mappings
72 $routeProvider.when('/cat/catalog/record/:record_id/:record_tab', {
73 templateUrl: './cat/catalog/t_catalog',
74 controller: 'CatalogCtrl',
78 $routeProvider.when('/cat/catalog/batchEdit', {
79 templateUrl: './cat/catalog/t_batchedit',
80 controller: 'BatchEditCtrl',
84 $routeProvider.when('/cat/catalog/batchEdit/:container_type/:container_id', {
85 templateUrl: './cat/catalog/t_batchedit',
86 controller: 'BatchEditCtrl',
90 $routeProvider.when('/cat/catalog/vandelay', {
91 templateUrl: './cat/catalog/t_vandelay',
92 controller: 'VandelayCtrl',
96 $routeProvider.when('/cat/catalog/verifyURLs', {
97 templateUrl: './cat/catalog/t_verifyurls',
98 controller: 'URLVerifyCtrl',
102 $routeProvider.when('/cat/catalog/manageAuthorities', {
103 templateUrl: './cat/catalog/t_manageauthorities',
104 controller: 'ManageAuthoritiesCtrl',
108 $routeProvider.when('/cat/catalog/authority/:authority_id/marc_edit', {
109 templateUrl: './cat/catalog/t_authority',
110 controller: 'AuthorityCtrl',
114 $routeProvider.otherwise({redirectTo : '/cat/catalog/index'});
120 .controller('CatalogRecordRetrieve',
121 ['$scope','$routeParams','$location','$q','egCore',
122 function($scope , $routeParams , $location , $q , egCore ) {
124 $scope.focusMe = true;
126 // jump to the patron checkout UI
127 function loadRecord(record_id) {
129 .path('/cat/catalog/record/' + record_id);
132 function loadAuthorityRecord(record_id) {
134 .path('/cat/catalog/authority/' + record_id + '/marc_edit');
137 $scope.submitId = function(args) {
138 $scope.recordNotFound = null;
139 if (!args.record_id) return;
141 // blur so next time it's set to true it will re-apply select()
142 $scope.selectMe = false;
144 return loadRecord(args.record_id);
147 $scope.submitAuthorityId = function(args) {
148 if (!args.record_id) return;
150 // blur so next time it's set to true it will re-apply select()
151 $scope.selectMe = false;
153 return loadAuthorityRecord(args.record_id);
156 $scope.submitTCN = function(args) {
157 $scope.recordNotFound = null;
158 $scope.moreRecordsFound = null;
159 if (!args.record_tcn) return;
161 // blur so next time it's set to true it will re-apply select()
162 $scope.selectMe = false;
167 'open-ils.search.biblio.tcn',
170 .then(function(resp) { // get_barcodes
173 return $q.when(resp);
175 // Search again including deleted records
176 return egCore.net.request('open-ils.search',
177 'open-ils.search.biblio.tcn', args.record_tcn, true);
180 }).then(function(resp2) {
183 $scope.recordNotFound = args.record_tcn;
184 $scope.selectMe = true;
188 if (resp2.count > 1) {
189 $scope.moreRecordsFound = args.record_tcn;
190 $scope.selectMe = true;
194 var record_id = resp2.ids[0];
195 return loadRecord(record_id);
201 .controller('NewBibCtrl',
202 ['$scope','$routeParams','$location','$window','$q','egCore',
203 'egGridDataProvider','egHoldGridActions','$timeout','holdingsSvc',
204 function($scope , $routeParams , $location , $window , $q , egCore) {
206 $scope.have_template = false;
207 $scope.marc_template = '';
208 $scope.stop_unload = false;
209 $scope.template_list = [];
210 $scope.template_name = '';
211 $scope.new_bib_id = 0;
213 egCore.strings.setPageTitle(egCore.strings.PAGE_TITLE_CREATE_MARC);
217 'open-ils.cat.marc_template.types.retrieve'
218 ).then(function(resp) {
219 angular.forEach(resp, function(name) {
220 $scope.template_list.push(name);
222 $scope.template_list.sort();
224 $scope.template_name = egCore.hatch.getSessionItem('eg.cat.last_bib_marc_template');
225 if (!$scope.template_name) {
226 egCore.hatch.getItem('cat.default_bib_marc_template').then(function(template) {
227 $scope.template_name = template;
231 $scope.loadTemplate = function() {
232 if ($scope.template_name) {
235 'open-ils.cat.biblio.marc_template.retrieve',
237 ).then(function(template) {
238 $scope.marc_template = template;
239 $scope.have_template = true;
240 egCore.hatch.setSessionItem('eg.cat.last_bib_marc_template', $scope.template_name);
245 $scope.setDefaultTemplate = function() {
246 var hatch_key = "cat.default_bib_marc_template";
247 if ($scope.template_name) {
248 egCore.hatch.setItem(hatch_key, $scope.template_name);
250 egCore.hatch.removeItem(hatch_key);
254 $scope.$watch('new_bib_id', function(newVal, oldVal) {
256 location.href = '/eg2/staff/catalog/record/' + $scope.new_bib_id;
263 .directive('autoFocus', function($timeout) {
266 link: function(_scope, _element) {
274 .directive('focusOnShow', function($timeout) {
277 link: function($scope, $element, $attr) {
279 $scope.$watch($attr.ngShow, function(newValue){
288 $scope.$watch($attr.ngHide, function(newValue){
301 .controller('CatalogCtrl',
302 ['$scope','$routeParams','$location','$window','$q','egCore','egHolds','egCirc','egConfirmDialog','ngToast',
303 'egGridDataProvider','egHoldGridActions','egProgressDialog','$timeout','$uibModal','holdingsSvc','egUser','conjoinedSvc',
304 '$cookies','egSerialsCoreSvc',
305 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc , egConfirmDialog , ngToast ,
306 egGridDataProvider , egHoldGridActions , egProgressDialog , $timeout , $uibModal , holdingsSvc , egUser , conjoinedSvc,
307 $cookies , egSerialsCoreSvc
310 var holdingsSvcInst = new holdingsSvc();
312 // set record ID on page load if available...
313 $scope.record_id = $routeParams.record_id;
314 $scope.summary_pane_record;
316 if ($scope.record_id) {
317 // TODO: Apply tab-specific title contexts
318 egCore.strings.setPageTitle(
319 egCore.strings.PAGE_TITLE_BIB_DETAIL,
320 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT,
321 {record_id : $scope.record_id}
324 // Default to title = Catalog
325 egCore.strings.setPageTitle(
326 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT);
329 if ($routeParams.record_id) $scope.from_route = true;
330 else $scope.from_route = false;
332 // set search and preferred library cookies
333 egCore.hatch.getItem('eg.search.search_lib').then(function(val) {
334 $cookies.put('eg_search_lib', val, { path : '/' });
336 egCore.hatch.getItem('eg.search.pref_lib').then(function(val) {
337 $cookies.put('eg_pref_lib', val, { path : '/' });
340 // will hold a ref to the opac iframe
341 $scope.opac_iframe = null;
342 $scope.parts_iframe = null;
344 $scope.search_result_index = 1;
345 $scope.search_result_hit_count = 1;
348 'opac_iframe.dom.contentWindow.search_result_index',
350 if (!isNaN(parseInt(n)))
351 $scope.search_result_index = n + 1;
356 'opac_iframe.dom.contentWindow.search_result_hit_count',
358 if (!isNaN(parseInt(n)))
359 $scope.search_result_hit_count = n;
363 $scope.in_opac_call = false;
364 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
365 if ($scope.opac_iframe) {
366 if (force_opac_tab) $scope.record_tab = 'catalog';
367 $scope.in_opac_call = true;
368 $scope.opac_iframe.dom.contentWindow[opac_frame_function]();
369 if (opac_frame_function == 'rdetailBackToResults') {
370 $location.update_path('/cat/catalog/index');
375 $scope.add_cart_to_record_bucket = function() {
376 var cartkey = $cookies.get('cartcache');
377 if (!cartkey) return;
380 'open-ils.actor.anon_cache.get_value',
383 ).then(function(list) {
384 list = list.map(function(x) {
387 $scope.add_to_record_bucket(list);
391 $scope.add_to_record_bucket = function(recs) {
392 if (!angular.isArray(recs)) {
393 recs = [ $scope.record_id ];
395 return $uibModal.open({
396 templateUrl: './cat/catalog/t_add_to_bucket',
401 ['$scope','$uibModalInstance',
402 function($scope , $uibModalInstance) {
404 $scope.bucket_id = 0;
405 $scope.newBucketName = '';
406 $scope.allBuckets = [];
409 'open-ils.actor.container.retrieve_by_class.authoritative',
410 egCore.auth.token(), egCore.auth.user().id(),
411 'biblio', 'staff_client'
412 ).then(function(buckets) { $scope.allBuckets = buckets; });
414 $scope.add_to_bucket = function() {
416 angular.forEach(recs, function(recId) {
417 var item = new egCore.idl.cbrebi();
418 item.bucket($scope.bucket_id);
419 item.target_biblio_record_entry(recId);
420 promises.push(egCore.net.request(
422 'open-ils.actor.container.item.create',
423 egCore.auth.token(), 'biblio', item
426 $q.all(promises).then(function(resp) {
427 $uibModalInstance.close();
431 $scope.add_to_new_bucket = function() {
432 var bucket = new egCore.idl.cbreb();
433 bucket.owner(egCore.auth.user().id());
434 bucket.name($scope.newBucketName);
435 bucket.description('');
436 bucket.btype('staff_client');
440 'open-ils.actor.container.create',
441 egCore.auth.token(), 'biblio', bucket
442 ).then(function(bucket) {
443 $scope.bucket_id = bucket;
444 $scope.add_to_bucket();
448 $scope.cancel = function() {
449 $uibModalInstance.dismiss();
455 $scope.carousels_available = false;
458 'open-ils.actor.carousel.retrieve_manual_by_staff',
460 ).then(function(carousels) { $scope.carousels_available = true; });
462 $scope.add_to_carousel = function(recs) {
463 if (!angular.isArray(recs)) {
464 recs = [ $scope.record_id ];
466 return $uibModal.open({
467 templateUrl: './cat/catalog/t_add_to_carousel',
472 ['$scope','$uibModalInstance',
473 function($scope , $uibModalInstance) {
474 $scope.bucket_id = 0;
475 $scope.allCarousels = [];
478 'open-ils.actor.carousel.retrieve_manual_by_staff',
480 ).then(function(carousels) { $scope.allCarousels = carousels; });
482 $scope.add_to_carousel = function() {
483 // or more precisely, the carousel's bucket
485 angular.forEach(recs, function(recId) {
486 var item = new egCore.idl.cbrebi();
487 item.bucket($scope.bucket_id);
488 item.target_biblio_record_entry(recId);
489 promises.push(egCore.net.request(
491 'open-ils.actor.container.item.create',
492 egCore.auth.token(), 'biblio', item
495 $q.all(promises).then(function(resp) {
496 $uibModalInstance.close();
500 $scope.cancel = function() {
501 $uibModalInstance.dismiss();
507 $scope.current_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record');
508 $scope.current_transfer_target = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
509 $scope.current_conjoined_target = egCore.hatch.getLocalItem('eg.cat.marked_conjoined_record');
511 $scope.quickReceive = function () {
513 var next_per_stream = {};
515 var recId = $scope.record_id;
516 return $uibModal.open({
517 templateUrl: './share/t_subscription_select_dialog',
519 controller: ['$scope', '$uibModalInstance',
520 function($scope, $uibModalInstance) {
523 $scope.rememberMe = 'eg.serials.quickreceive.last_org';
524 $scope.record_id = recId;
525 $scope.ssubId = null;
527 $scope.ok = function() { $uibModalInstance.close($scope.ssubId) }
528 $scope.cancel = function() { $uibModalInstance.dismiss(); }
531 }).result.then(function(ssubId) {
534 promises.push(egSerialsCoreSvc.fetchItemsForSub(ssubId,{status:'Expected'}).then(function(){
535 angular.forEach(egSerialsCoreSvc.itemTree, function (item) {
536 if (next_per_stream[item.stream().id()]) return;
537 if (item.status() == 'Expected') {
538 next_per_stream[item.stream().id()] = item;
539 list.push(egCore.idl.Clone(item));
544 return $q.all(promises).then(function() {
547 ngToast.warning(egCore.strings.SERIALS_NO_ITEMS);
551 return egSerialsCoreSvc.process_items(
557 false, // print by default
558 function() { $scope.holdings_record_id_changed($scope.record_id) }
562 ngToast.warning(egCore.strings.SERIALS_NO_SUBS);
568 $scope.markConjoined = function () {
569 $scope.current_conjoined_target = $scope.record_id;
570 egCore.hatch.setLocalItem('eg.cat.marked_conjoined_record',$scope.record_id);
571 ngToast.create(egCore.strings.MARK_CONJ_TARGET);
574 $scope.markHoldingsTransfer = function () {
575 $scope.current_transfer_target = $scope.record_id;
576 egCore.hatch.setLocalItem('eg.cat.transfer_target_record',$scope.record_id);
577 egCore.hatch.removeLocalItem('eg.cat.transfer_target_lib');
578 egCore.hatch.removeLocalItem('eg.cat.transfer_target_vol');
579 ngToast.create(egCore.strings.MARK_HOLDINGS_TARGET);
582 $scope.markOverlay = function () {
583 $scope.current_overlay_target = $scope.record_id;
584 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.record_id);
585 ngToast.create(egCore.strings.MARK_OVERLAY_TARGET);
588 $scope.clearRecordMarks = function () {
589 $scope.current_overlay_target = null;
590 $scope.current_transfer_target = null;
591 $scope.current_conjoined_target = null;
592 $scope.current_hold_transfer_dest = null;
593 egCore.hatch.removeLocalItem('eg.cat.transfer_target_record');
594 egCore.hatch.removeLocalItem('eg.cat.marked_conjoined_record');
595 egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');
596 egCore.hatch.removeLocalItem('eg.circ.hold.title_transfer_target');
599 $scope.stop_unload = false;
600 $scope.$watch('stop_unload',
601 function(newVal, oldVal) {
602 if (newVal && newVal != oldVal && $scope.opac_iframe) {
603 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
604 return 'There is unsaved data in this record.'
607 if ($scope.opac_iframe)
608 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
613 // Set the "last bib" cookie, if we have that
614 if ($scope.record_id)
615 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
617 $scope.refresh_record_callback = function (record_id) {
618 egCore.pcrud.retrieve('bre', record_id, {
621 bre : ['simple_record','creator','editor']
623 }).then(function(rec) {
624 rec.owner(egCore.org.get(rec.owner()));
625 $scope.summary_pane_record = rec;
631 patron_search_dialog = function() {
632 return $uibModal.open({
633 templateUrl: './share/t_patron_selector',
638 ['$scope','$uibModalInstance','$controller',
639 function($scope , $uibModalInstance , $controller) {
640 angular.extend(this, $controller('BasePatronSearchCtrl', {$scope : $scope}));
642 $scope.need_one_selected = function() {
643 var items = $scope.gridControls.selectedItems();
644 return (items.length == 1) ? false : true
646 $scope.ok = function() {
647 var items = $scope.gridControls.selectedItems();
648 if (items.length == 1) {
649 $uibModalInstance.close(items[0].card().barcode());
651 $uibModalInstance.close()
654 $scope.cancel = function($event) {
655 $uibModalInstance.dismiss();
656 $event.preventDefault();
662 // Map the Angular catalog-only 'item_table' tab to the AngJS
664 function get_default_record_tab() {
665 var tab = egCore.hatch.getLocalItem('eg.cat.default_record_tab');
666 if (!tab || tab === 'item_table' || tab === 'staff_view' || tab === 'added-content' || tab === 'bibnotes' || tab === 'cnbrowse') { return 'catalog'; }
670 // also set it when the iframe changes to a new record
671 $scope.handle_page = function(url) {
673 if (!url || url == 'about:blank') {
674 // nothing loaded. If we already have a record ID, leave it.
678 var prev_record_id = $scope.record_id;
679 var match = url.match(/\/+opac\/+record\/+(\d+)/);
681 $scope.record_id = match[1];
682 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
683 $scope.holdings_record_id_changed($scope.record_id);
684 conjoinedSvc.fetch($scope.record_id).then(function(){
685 $scope.conjoinedGridDataProvider.refresh();
688 $scope.grid_actions.refresh();
689 $location.update_path('/cat/catalog/record/' + $scope.record_id);
690 // update_path() bypasses the controller for path
691 // /cat/catalog/record/:record_id. Manually set title here too.
692 egCore.strings.setPageTitle(
693 egCore.strings.PAGE_TITLE_BIB_DETAIL,
694 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT,
695 {record_id : $scope.record_id}
698 delete $scope.record_id;
699 $scope.from_route = false;
702 // child scope is executing this function, so our digest doesn't fire ... thus,
705 // don't change tabs if we are using the OPAC nav buttons,
706 // or we didn't change records on the OPAC load
707 if (!$scope.in_opac_call && ($scope.record_id != prev_record_id)) {
708 if ($scope.record_id) {
709 $scope.default_tab = get_default_record_tab();
710 tab = $routeParams.record_tab || $scope.default_tab;
712 tab = $routeParams.record_tab || 'catalog';
714 $scope.set_record_tab(tab);
716 $scope.in_opac_call = false;
719 if ($scope.opac_iframe && $location.path().match(/cat\/catalog/)) {
720 var doc = $scope.opac_iframe.dom.contentWindow.document;
721 $(doc).find('#hold_usr_search').show();
722 $(doc).find('#hold_usr_search').on('click', function() {
723 patron_search_dialog().result.then(function(barc) {
724 $(doc).find('#hold_usr_input').val(barc);
725 $(doc).find('#hold_usr_input').trigger($.Event('keydown', {which: 13}));
728 // Add Cart to Record Bucket, in two flavors:
729 // First, the traditional TPAC, which uses a <select> menu
730 $(doc).find('#select_basket_action').on('change', function() {
731 if (this.options[this.selectedIndex].value && this.options[this.selectedIndex].value == "add_cart_to_bucket") {
732 $scope.add_cart_to_record_bucket();
735 // Second, the bootstrap OPAC, which uses a bunch of <a>s styled as a dropdown
736 $(doc).find('a[href="add_cart_to_bucket"]').on('click', function (event) {
737 event.preventDefault();
738 $scope.add_cart_to_record_bucket();
744 // xulG catalog handlers
745 $scope.handlers = { }
747 // ------------------------------------------------------------------
750 $scope.conjoinedGridControls = {};
751 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
752 get : function(offset, count) {
753 return this.arrayNotifier(conjoinedSvc.items, offset, count);
757 $scope.changeConjoinedType = function () {
758 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
759 angular.forEach(peers, function (p) {
760 p.target_copy(p.target_copy().id());
761 p.peer_type(p.peer_type().id());
764 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
766 return $uibModal.open({
767 templateUrl: './cat/catalog/t_conjoined_selector',
771 ['$scope','$uibModalInstance',
772 function($scope , $uibModalInstance) {
773 $scope.update = true;
775 $scope.peer_type = null;
776 $scope.peer_type_list = [];
777 conjoinedSvc.get_peer_types().then(function(list){
778 $scope.peer_type_list = list;
781 $scope.ok = function(type) {
784 angular.forEach(peers, function (p) {
787 promises.push(egCore.pcrud.update(p));
790 return $q.all(promises)
791 .then(function(){$uibModalInstance.close()})
792 .then(function(){return conjoinedSvc.fetch()})
793 .then(function(){conjoinedGridDataProviderRef.refresh()});
796 $scope.cancel = function($event) {
797 $uibModalInstance.dismiss();
798 $event.preventDefault();
805 $scope.refreshConjoined = function () {
806 conjoinedSvc.fetch($scope.record_id)
807 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
810 $scope.deleteSelectedConjoined = function () {
811 var peers = $scope.conjoinedGridControls.selectedItems();
813 if (peers.length > 0) {
814 egConfirmDialog.open(
815 egCore.strings.CONFIRM_DELETE_PEERS,
816 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
817 {peers : peers.length}
818 ).result.then(function() {
819 angular.forEach(peers, function (p) {
823 egCore.pcrud.remove(peers).then(function() {
824 return conjoinedSvc.fetch();
826 $scope.conjoinedGridDataProvider.refresh();
831 if ($scope.record_id)
832 conjoinedSvc.fetch($scope.record_id);
834 // ------------------------------------------------------------------
837 $scope.holdingsGridControls = {
838 activateItem : function (item) {
839 $scope.selectedHoldingsVolCopyEdit();
842 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
843 get : function(offset, count) {
844 return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
848 $scope.add_copies_to_bucket = function() {
849 var copy_list = gatherSelectedHoldingsIds();
850 if (copy_list.length == 0) return;
852 return $uibModal.open({
853 templateUrl: './cat/catalog/t_add_to_bucket',
858 ['$scope','$uibModalInstance',
859 function($scope , $uibModalInstance) {
861 $scope.bucket_id = 0;
862 $scope.newBucketName = '';
863 $scope.allBuckets = [];
867 'open-ils.actor.container.retrieve_by_class.authoritative',
868 egCore.auth.token(), egCore.auth.user().id(),
869 'copy', 'staff_client'
870 ).then(function(buckets) { $scope.allBuckets = buckets; });
872 $scope.add_to_bucket = function() {
874 angular.forEach(copy_list, function (cp) {
875 var item = new egCore.idl.ccbi()
876 item.bucket($scope.bucket_id);
877 item.target_copy(cp);
881 'open-ils.actor.container.item.create',
882 egCore.auth.token(), 'copy', item
886 return $q.all(promises).then(function() {
887 $uibModalInstance.close();
892 $scope.add_to_new_bucket = function() {
893 var bucket = new egCore.idl.ccb();
894 bucket.owner(egCore.auth.user().id());
895 bucket.name($scope.newBucketName);
896 bucket.description('');
897 bucket.btype('staff_client');
899 return egCore.net.request(
901 'open-ils.actor.container.create',
902 egCore.auth.token(), 'copy', bucket
903 ).then(function(bucket) {
904 $scope.bucket_id = bucket;
905 $scope.add_to_bucket();
909 $scope.cancel = function() {
910 $uibModalInstance.dismiss();
916 // TODO: refactor common code between cat/catalog/app.js and cat/item/app.js
918 $scope.need_one_selected = function() {
919 var items = $scope.holdingsGridControls.selectedItems();
920 if (items.length == 1) return false;
924 $scope.make_copies_bookable = function() {
926 var copies_by_record = {};
927 var record_list = [];
929 $scope.holdingsGridControls.selectedItems(),
931 var record_id = item['call_number.record.id'];
932 if (typeof copies_by_record[ record_id ] == 'undefined') {
933 copies_by_record[ record_id ] = [];
934 record_list.push( record_id );
936 copies_by_record[ record_id ].push(item.id);
941 var combined_results = [];
942 angular.forEach(record_list, function(record_id) {
946 'open-ils.booking.resources.create_from_copies',
948 copies_by_record[record_id]
949 ).then(function(results) {
950 if (results && results['brsrc']) {
951 combined_results = combined_results.concat(results['brsrc']);
957 $q.all(promises).then(function() {
958 if (combined_results.length > 0) {
960 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
965 ['$scope','$location','egCore','$uibModalInstance',
966 function($scope , $location , egCore , $uibModalInstance) {
969 ses : egCore.auth.token(),
970 resultant_brsrc : combined_results.map(function(o) { return o[0]; })
973 var booking_path = '/eg/conify/global/booking/resource';
975 $scope.booking_admin_url =
976 $location.absUrl().replace(/\/eg\/staff\/.*/, booking_path);
983 $scope.book_copies_now = function(items) {
984 location.href = "/eg2/staff/booking/create_reservation/for_resource/" + items[0]['barcode'];
987 $scope.requestItems = function() {
988 var copy_list = gatherSelectedHoldingsIds();
989 if (copy_list.length == 0) return;
991 return $uibModal.open({
992 templateUrl: './cat/catalog/t_request_items',
995 ['$scope','$uibModalInstance',
996 function($scope , $uibModalInstance) {
998 $scope.first_user_fetch = true;
1000 $scope.hold_data = {
1002 copy_list : copy_list,
1003 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
1004 user : egCore.auth.user().id()
1007 egUser.get( $scope.hold_data.user ).then(function(u) {
1009 $scope.barcode = u.card().barcode();
1010 $scope.user_name = egUser.format_name(u);
1011 $scope.hold_data.user = u.id();
1014 $scope.user_name = '';
1015 $scope.barcode = '';
1016 $scope.$watch('barcode', function (n) {
1017 if (!$scope.first_user_fetch) {
1018 egUser.getByBarcode(n).then(function(u) {
1020 $scope.user_name = egUser.format_name(u);
1021 $scope.hold_data.user = u.id();
1024 $scope.user_name = '';
1025 delete $scope.hold_data.user;
1028 $scope.first_user_fetch = false;
1031 $scope.ok = function(h) {
1034 hold_type : h.hold_type,
1035 pickup_lib: h.pickup_lib.id(),
1041 'open-ils.circ.holds.test_and_create.batch.override',
1042 egCore.auth.token(), args, h.copy_list
1044 holds = []; // force the holds grid to refetch data.
1045 $uibModalInstance.close();
1049 $scope.cancel = function($event) {
1050 $uibModalInstance.dismiss();
1051 $event.preventDefault();
1057 $scope.manage_reservations = function() {
1058 var item = $scope.holdingsGridControls.selectedItems()[0];
1060 location.href = "/eg2/staff/booking/manage_reservations/by_resource/" + item.barcode;
1064 $scope.view_place_orders = function() {
1065 if (!$scope.record_id) return;
1066 var url = egCore.env.basePath + 'acq/legacy/lineitem/related/' + $scope.record_id + '?target=bib';
1067 $timeout(function() { $window.open(url, '_blank') });
1070 $scope.replaceBarcodes = function() {
1071 var copy_list = gatherSelectedRawCopies();
1072 if (copy_list.length == 0) return;
1074 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
1076 angular.forEach(copy_list, function (cp) {
1078 templateUrl: './cat/share/t_replace_barcode',
1082 ['$scope','$uibModalInstance',
1083 function($scope , $uibModalInstance) {
1084 $scope.duplicate_barcode = false;
1085 $scope.isModal = true;
1086 $scope.focusBarcode = false;
1087 $scope.focusBarcode2 = true;
1088 $scope.barcode1 = cp.barcode();
1090 // check input to see if it's a duplicate barcode
1091 $scope.checkCurrentBarcode = function() {
1092 if (!$scope.duplicate_barcode_string) {
1093 $scope.duplicate_barcode_string = window.duplicate_barcode_string;
1095 var searchParams = {
1097 'barcode' : $scope.barcode2,
1098 id : { '!=' : $scope.copyId }
1100 egCore.pcrud.search('acp', searchParams).then(function (res) {
1101 $scope.duplicate_barcode = res;
1105 $scope.updateBarcode = function() {
1106 $scope.copyNotFound = false;
1107 $scope.updateOK = false;
1109 egCore.pcrud.search('acp',
1110 {deleted : 'f', barcode : $scope.barcode1})
1111 .then(function(copy) {
1114 $scope.focusBarcode = true;
1115 $scope.copyNotFound = true;
1119 $scope.copyId = copy.id();
1123 'open-ils.cat.update_copy_barcode',
1124 egCore.auth.token(), $scope.copyId, $scope.barcode2
1125 ).then(function(resp) {
1126 var evt = egCore.evt.parse(resp);
1128 console.log('toast 0 here', evt);
1130 $scope.updateOK = stat;
1131 $scope.focusBarcode = true;
1132 holdingsSvc.fetchAgain().then(function (){
1133 holdingsGridDataProviderRef.refresh();
1139 console.log('toast 1 here',E);
1141 console.log('toast 2 here',E);
1143 $uibModalInstance.close();
1146 $scope.cancel = function($event) {
1147 $uibModalInstance.dismiss();
1148 $event.preventDefault();
1156 var holdings_bChannel = null;
1157 // subscribe to BroadcastChannel for any child VolCopy tabs
1158 // refresh grid if needed to show new updates
1159 // if ($scope.record_tab === 'holdings'){
1160 $scope.$watch('record_tab', function(n){
1162 if (n === 'holdings'){
1163 if (typeof BroadcastChannel != 'undefined') {
1164 // we're in holdings tab, connect 2 bChannel
1165 holdings_bChannel = new BroadcastChannel('eg.holdings.update');
1166 holdings_bChannel.onmessage = function(e){
1169 && e.data.records.length
1170 && e.data.records.includes(Number($scope.record_id))
1171 ){ // it's for us, refresh grid!
1172 console.log("Got broadcast from channel eg.holdings.update for records " + e.data.records);
1173 $scope.holdings_record_id_changed($scope.record_id);
1178 } else if (holdings_bChannel){ // we're leaving holding tab, close bChannel
1179 holdings_bChannel.close();
1184 // refresh the list of holdings when the record_id is changed.
1185 $scope.holdings_record_id_changed = function(id) {
1186 if ($scope.record_id != id) $scope.record_id = id;
1187 console.log('record id changed to ' + id + ', loading new holdings');
1188 holdingsSvcInst.fetch({
1189 rid : $scope.record_id,
1190 org : $scope.holdings_ou,
1191 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1192 vol : $scope.holdings_show_vols,
1193 empty: $scope.holdings_show_empty,
1194 empty_org: $scope.holdings_show_empty_org
1195 }).then(function() {
1196 $scope.holdingsGridDataProvider.refresh();
1200 // refresh the list of holdings when the filter lib is changed.
1201 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
1202 $scope.holdings_ou_changed = function(org) {
1203 $scope.holdings_ou = org;
1204 holdingsSvcInst.fetch({
1205 rid : $scope.record_id,
1206 org : $scope.holdings_ou,
1207 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1208 vol : $scope.holdings_show_vols,
1209 empty: $scope.holdings_show_empty,
1210 empty_org: $scope.holdings_show_empty_org
1211 }).then(function() {
1212 $scope.holdingsGridDataProvider.refresh();
1216 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
1217 $scope[cb] = newVal;
1218 var x = $scope.holdings_show_vols ? $scope.holdings_show_copies : false;
1219 $('#holdings_show_copies').prop('checked', x);
1220 egCore.hatch.setItem('cat.' + cb, newVal);
1221 if (!norefresh) holdingsSvcInst.fetch({
1222 rid : $scope.record_id,
1223 org : $scope.holdings_ou,
1224 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1225 vol : $scope.holdings_show_vols,
1226 empty: $scope.holdings_show_empty,
1227 empty_org: $scope.holdings_show_empty_org
1228 }).then(function() {
1229 $scope.holdingsGridDataProvider.refresh();
1233 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
1234 if (typeof x == 'undefined') x = true;
1235 $scope.holdings_cb_changed('holdings_show_vols',x,true);
1236 $('#holdings_show_vols').prop('checked', x);
1238 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
1239 if (typeof x == 'undefined') x = true;
1240 $scope.holdings_cb_changed('holdings_show_copies',x,true);
1241 x = $scope.holdings_show_vols ? x : false;
1242 $('#holdings_show_copies').prop('checked', x);
1244 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
1245 if (typeof x == 'undefined') x = true;
1246 $scope.holdings_cb_changed('holdings_show_empty',x);
1247 $('#holdings_show_empty').prop('checked', x);
1249 egCore.hatch.getItem('cat.holdings_show_empty_org').then(function(x){
1250 if (typeof x == 'undefined') x = true;
1251 $scope.holdings_cb_changed('holdings_show_empty_org',x);
1252 $('#holdings_show_empty_org').prop('checked', x);
1258 $scope.vols_not_shown = function () {
1259 return !$scope.holdings_show_vols;
1262 $scope.copies_not_shown = function () {
1263 return !$scope.holdings_show_copies;
1266 $scope.empty_org_not_shown = function () {
1267 return !$scope.holdings_show_empty_org;
1270 $scope.holdings_checkbox_handler = function (item) {
1271 $scope.holdings_cb_changed(item.checkbox,item.checked);
1274 function gatherSelectedHoldingsIds () {
1275 var cp_id_list = [];
1277 $scope.holdingsGridControls.selectedItems(),
1278 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
1283 function gatherSelectedRawCopies () {
1286 $scope.holdingsGridControls.selectedItems(),
1287 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
1292 function gatherSelectedEmptyVolumeIds () {
1293 var cn_id_list = [];
1295 $scope.holdingsGridControls.selectedItems(),
1297 if (item.copy_count == 0 || (!item.id && item.call_number))
1298 // we are in a compressed row with no copies, or we are in a single
1299 // call number row with no copy (testing for presence of 'id')
1300 // In either case, the call number is 'empty'
1301 cn_id_list.push(item.call_number.id)
1307 function gatherSelectedVolumeIds () {
1308 var cn_id_list = [];
1310 $scope.holdingsGridControls.selectedItems(),
1312 if (cn_id_list.indexOf(item.call_number.id) == -1)
1313 cn_id_list.push(item.call_number.id)
1319 $scope.selectedHoldingsDelete = function (vols, copies) {
1322 var perCnCopies = {};
1328 $scope.holdingsGridControls.selectedItems(),
1330 if (vols && item.raw_call_number) {
1331 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
1332 cnHash[item.call_number.id].isdeleted(1);
1334 } else if (copies) {
1335 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
1338 var cn_id = cp.call_number().id();
1339 if (!cnHash[cn_id]) {
1340 cnHash[cn_id] = cp.call_number();
1341 perCnCopies[cn_id] = [cp];
1343 perCnCopies[cn_id].push(cp);
1345 cp.call_number(cn_id); // prevent loops in JSON-ification
1352 angular.forEach(perCnCopies, function (v, k) {
1354 cnHash[k].isdeleted(1);
1357 cnHash[k].copies(v);
1361 angular.forEach(cnHash, function (v, k) {
1365 if (cnList.length == 0) return;
1368 if (vols && copies) flags.force_delete_copies = 1;
1370 egConfirmDialog.open(
1371 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
1372 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
1373 {copies : cp_count, volumes : cn_count}
1374 ).result.then(function() {
1377 'open-ils.cat.asset.volume.fleshed.batch.update',
1378 egCore.auth.token(), cnList, 1, flags
1379 ).then(function(resp) {
1380 var evt = egCore.evt.parse(resp);
1382 egConfirmDialog.open(
1383 egCore.strings.OVERRIDE_DELETE_ITEMS_FROM_CATALOG_TITLE,
1384 egCore.strings.OVERRIDE_DELETE_ITEMS_FROM_CATALOG_BODY,
1385 {'evt_desc': evt.desc}
1386 ).result.then(function() {
1389 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1390 egCore.auth.token(), cnList, 1,
1391 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1393 holdingsSvcInst.fetchAgain().then(function() {
1394 $scope.holdingsGridDataProvider.refresh();
1399 holdingsSvcInst.fetchAgain().then(function() {
1400 $scope.holdingsGridDataProvider.refresh();
1406 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
1407 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
1408 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
1410 spawnHoldingsAdd = function (add_vols,add_copies){
1412 if (!add_vols && add_copies) { // just a copy on existing volumes
1413 angular.forEach(gatherSelectedVolumeIds(), function (v) {
1414 raw.push( {callnumber : v} );
1416 } else if (add_vols) {
1417 if (typeof $scope.holdingsGridControls.selectedItems == "function" &&
1418 $scope.holdingsGridControls.selectedItems().length > 0) {
1419 angular.forEach($scope.holdingsGridControls.selectedItems(),
1422 owner : item.owner_id,
1423 label : ((item.call_number) ? item.call_number.label : null)
1428 owner : egCore.auth.user().ws_ou()
1433 if (raw.length == 0) raw.push({});
1437 'open-ils.actor.anon_cache.set_value',
1438 null, 'edit-these-copies', {
1439 record_id: $scope.record_id,
1442 hide_copies : !add_copies
1444 ).then(function(key) {
1446 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1447 $timeout(function() { $window.open(url, '_blank') });
1449 alert('Could not create anonymous cache key!');
1453 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,true) }
1454 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
1455 $scope.selectedHoldingsVolAdd = function () { spawnHoldingsAdd(true,false) }
1457 spawnHoldingsEdit = function (hide_vols,hide_copies){
1460 'open-ils.actor.anon_cache.set_value',
1461 null, 'edit-these-copies', {
1462 record_id: $scope.record_id,
1463 copies: gatherSelectedHoldingsIds(),
1464 raw: gatherSelectedEmptyVolumeIds().map(
1465 function(v){ return { callnumber : v } }
1467 hide_vols : hide_vols,
1468 hide_copies : hide_copies
1470 ).then(function(key) {
1472 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1473 $timeout(function() { $window.open(url, '_blank') });
1475 alert('Could not create anonymous cache key!');
1479 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
1480 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
1481 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
1483 $scope.selectedHoldingsItemStatus = function (){
1484 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
1485 $timeout(function() { $window.open(url, '_blank') });
1488 $scope.markFromSelectedAsHoldingsTarget = function() {
1489 egCore.hatch.setLocalItem(
1490 'eg.cat.transfer_target_lib',
1491 $scope.holdingsGridControls.selectedItems()[0].owner_id
1493 egCore.hatch.setLocalItem(
1494 'eg.cat.transfer_target_record',
1497 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed, or we are on an empty lib
1498 egCore.hatch.setLocalItem(
1499 'eg.cat.transfer_target_vol',
1500 $scope.holdingsGridControls.selectedItems()[0].call_number.id
1503 // clear out the stale value if we're on a lib-only
1504 // or vol-collapsed row
1505 egCore.hatch.removeLocalItem('eg.cat.transfer_target_vol');
1507 ngToast.create(egCore.strings.MARK_HOLDINGS_TARGET);
1510 $scope.selectedHoldingsItemStatusDetail = function (){
1512 gatherSelectedHoldingsIds(),
1514 var url = egCore.env.basePath +
1516 $timeout(function() { $window.open(url, '_blank') });
1521 $scope.transferVolumes = function (){
1522 var target_record = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
1523 var target_lib = egCore.hatch.getLocalItem('eg.cat.transfer_target_lib');
1525 && (!target_record || ($scope.record_id == target_record) )
1528 var vols_to_move = {};
1530 // we're moving volumes to a different library
1531 var vol_ids = gatherSelectedVolumeIds();
1532 if (vol_ids.length) {
1533 vols_to_move[target_lib] = vol_ids;
1535 // if we're *only* switching libs,
1536 // grab the current record as the target
1537 target_record = target_record || $scope.record_id;
1540 // we're moving volumes to the same library they exist in
1541 // currently, but on a different record
1542 var items = $scope.holdingsGridControls.selectedItems();
1543 angular.forEach(items, function(item) {
1544 if (!(item.call_number.owning_lib in vols_to_move)) {
1545 vols_to_move[item.call_number.owning_lib] = new Array;
1547 vols_to_move[item.call_number.owning_lib].push(item.call_number.id);
1552 angular.forEach(vols_to_move, function(vols, owning_lib) {
1553 promises.push(egCore.net.request(
1555 'open-ils.cat.asset.volume.batch.transfer.override',
1556 egCore.auth.token(), {
1557 docid : target_record,
1563 $q.all(promises).then(function(success) {
1565 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1566 holdingsSvcInst.fetchAgain().then(function() {
1567 $scope.holdingsGridDataProvider.refresh();
1570 alert('Could not transfer volumes!');
1575 // this "transfers" selected copies to a new owning library,
1576 // auto-creating volumes as required
1577 $scope.transferItemsAutoFill = function() {
1578 var target_record = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
1579 var target_lib = egCore.hatch.getLocalItem('eg.cat.transfer_target_lib');
1581 && (!target_record || ($scope.record_id == target_record) )
1584 var items = $scope.holdingsGridControls.selectedItems();
1585 if (!items.length) {
1589 var vols_to_move = {};
1590 var copies_to_move = {};
1591 angular.forEach(items, function(item) {
1592 var needs_move = false;
1594 && (item.call_number.owning_lib != target_lib)) {
1595 item.call_number.owning_lib = target_lib;
1599 && (item.call_number.record != target_record)) {
1600 item.call_number.record = target_record;
1604 if (item.call_number.id in vols_to_move) {
1605 copies_to_move[item.call_number.id].push(item.id);
1607 vols_to_move[item.call_number.id] = item.call_number;
1608 copies_to_move[item.call_number.id] = new Array;
1609 copies_to_move[item.call_number.id].push(item.id);
1615 angular.forEach(vols_to_move, function(vol) {
1616 promises.push(egCore.net.request(
1618 'open-ils.cat.call_number.find_or_create',
1619 egCore.auth.token(),
1621 vol.record, // may be new
1622 vol.owning_lib, // may be new
1626 ).then(function(resp) {
1627 var evt = egCore.evt.parse(resp);
1629 return egCore.net.request(
1631 'open-ils.cat.transfer_copies_to_volume',
1632 egCore.auth.token(),
1634 copies_to_move[vol.id]
1638 $q.all(promises).then(function() {
1639 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1640 holdingsSvcInst.fetchAgain().then(function() {
1641 $scope.holdingsGridDataProvider.refresh();
1646 $scope.gridCellHandlers = {};
1647 $scope.gridCellHandlers.copyAlertsEdit = function(id) {
1648 egCirc.manage_copy_alerts([id]).then(function() {
1649 // update grid items?
1653 $scope.transferItems = function (){
1654 var xfer_target = egCore.hatch.getLocalItem('eg.cat.transfer_target_vol');
1657 // we have no specific volume, let's try to fill in the
1659 return $scope.transferItemsAutoFill();
1662 var copy_ids = gatherSelectedHoldingsIds();
1663 if (copy_ids.length > 0) {
1666 'open-ils.cat.transfer_copies_to_volume',
1667 egCore.auth.token(),
1671 function(resp) { // oncomplete
1672 var evt = egCore.evt.parse(resp);
1674 egConfirmDialog.open(
1675 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1676 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1677 {'evt_desc': evt.desc}
1678 ).result.then(function() {
1681 'open-ils.cat.transfer_copies_to_volume.override',
1682 egCore.auth.token(),
1685 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1686 ).then(function(resp) {
1687 holdingsSvcInst.fetchAgain().then(function() {
1688 $scope.holdingsGridDataProvider.refresh();
1693 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1694 holdingsSvcInst.fetchAgain().then(function() {
1695 $scope.holdingsGridDataProvider.refresh();
1705 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1707 gatherSelectedHoldingsIds(),
1709 var url = '/eg2/staff/circ/item/event-log/' + cid;
1710 $timeout(function() { $window.open(url, '_blank') });
1715 $scope.selectedHoldingsItemStatusHolds = function (){
1717 gatherSelectedHoldingsIds(),
1719 var url = egCore.env.basePath +
1720 'cat/item/' + cid + '/holds';
1721 $timeout(function() { $window.open(url, '_blank') });
1726 $scope.selectedHoldingsPrintLabels = function() {
1729 'open-ils.actor.anon_cache.set_value',
1730 null, 'print-labels-these-copies', {
1731 copies : gatherSelectedHoldingsIds()
1733 ).then(function(key) {
1735 var url = egCore.env.basePath + 'cat/printlabels/' + key;
1736 $timeout(function() { $window.open(url, '_blank') });
1738 alert('Could not create anonymous cache key!');
1743 $scope.selectedHoldingsDamaged = function () {
1744 var copy_list = gatherSelectedRawCopies();
1745 if (copy_list.length == 0) return;
1747 angular.forEach(copy_list, function(cp) {
1748 egCirc.mark_damaged({
1750 barcode: cp.barcode(),
1751 circ_lib: cp.circ_lib().id()
1752 }).then(function() {
1753 holdingsSvcInst.fetchAgain().then(function() {
1754 $scope.holdingsGridDataProvider.refresh();
1760 $scope.selectedHoldingsDiscard = function () {
1761 var copy_list = gatherSelectedRawCopies();
1762 if (copy_list.length == 0) return;
1763 egCirc.mark_discard(copy_list.map(function(cp) {
1764 return {id: cp.id(), barcode: cp.barcode()};})).then(function() {
1765 holdingsSvcInst.fetchAgain().then(function() {
1766 $scope.holdingsGridDataProvider.refresh();
1771 $scope.selectedHoldingsMissing = function () {
1772 var copy_list = gatherSelectedRawCopies();
1773 if (copy_list.length == 0) return;
1774 egCirc.mark_missing(copy_list.map(function(cp) {
1775 return {id: cp.id(), barcode: cp.barcode()};})).then(function() {
1776 holdingsSvcInst.fetchAgain().then(function() {
1777 $scope.holdingsGridDataProvider.refresh();
1782 $scope.selectedHoldingsCopyAlertsAdd = function() {
1783 egCirc.add_copy_alerts(gatherSelectedHoldingsIds()).then(function() {
1784 // no need to refresh grid
1787 $scope.selectedHoldingsCopyAlertsManage = function() {
1788 egCirc.manage_copy_alerts(gatherSelectedHoldingsIds()).then(function() {
1789 // no need to refresh grid
1793 $scope.attach_to_peer_bib = function() {
1794 var copy_list = gatherSelectedHoldingsIds();
1795 if (copy_list.length == 0) return;
1797 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1798 if (!target_record) return;
1800 return $uibModal.open({
1801 templateUrl: './cat/catalog/t_conjoined_selector',
1805 ['$scope','$uibModalInstance',
1806 function($scope , $uibModalInstance) {
1807 $scope.update = false;
1809 $scope.peer_type = null;
1810 $scope.peer_type_list = [];
1811 conjoinedSvc.get_peer_types().then(function(list){
1812 $scope.peer_type_list = list;
1815 $scope.ok = function(type) {
1818 angular.forEach(copy_list, function (cp) {
1819 var n = new egCore.idl.bpbcm();
1821 n.peer_record(target_record);
1824 promises.push(egCore.pcrud.create(n));
1827 return $q.all(promises).then(function(){$uibModalInstance.close()});
1830 $scope.cancel = function($event) {
1831 $uibModalInstance.dismiss();
1832 $event.preventDefault();
1840 // ------------------------------------------------------------------
1842 var provider = egGridDataProvider.instance({});
1843 var holds = []; // current list of holds
1845 var hold_grid_load_promise;
1847 $scope.hold_grid_data_provider = provider;
1848 $scope.grid_actions = egHoldGridActions;
1849 $scope.grid_actions.refresh = function () { holds = []; hold_count = 0; provider.refresh() };
1850 $scope.hold_grid_controls = {};
1852 provider.get = function(offset, count) {
1853 if ($scope.record_tab != 'holds') return $q.when();
1855 if (hold_grid_load_promise) {
1856 // Active load in progress.
1857 console.debug('Exiting concurrent hold fetch');
1858 return hold_grid_load_promise;
1861 // see if we have the requested range cached
1862 if (holds[offset]) {
1864 'Serving holds from cache with pickup lib', $scope.pickup_ou.id());
1865 return provider.arrayNotifier(holds, offset, count);
1870 var restrictions = {
1871 is_staff_request : 'true',
1872 fulfillment_time : null,
1874 record_id : $scope.record_id,
1875 pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)
1878 var order_by = [{ request_time : null }];
1879 // NOTE: Server sort is disabled for now. See the comment on
1880 // similar code in circ/holds/app.js for details.
1881 if (false && provider.sort && provider.sort.length) {
1883 angular.forEach(provider.sort, function (c) {
1884 if (!angular.isObject(c)) {
1885 if (c.match(/^hold\./)) {
1886 var i = c.replace('hold.','');
1892 var i = Object.keys(c)[0];
1893 var direction = c[i];
1894 if (i.match(/^hold\./)) {
1895 i = i.replace('hold.','');
1897 ob[i] = {dir:direction};
1905 'Fetching holds from network with PU lib', $scope.pickup_ou.id());
1907 egProgressDialog.open({max : 1, value : 0});
1909 hold_grid_load_promise = egHolds.fetch_wide_holds(
1912 ).then(function () {
1913 hold_grid_load_promise = null;
1914 return provider.arrayNotifier(holds, offset, count);
1917 function(hold_data) {
1919 hold_count = hold_data;
1921 egProgressDialog.update({max:hold_count});
1923 egProgressDialog.increment();
1924 var new_item = { id : hold_data.id, hold : hold_data };
1925 new_item.status_string =
1926 egCore.strings['HOLD_STATUS_' + hold_data.hold_status]
1927 || hold_data.hold_status;
1929 holds.push(new_item);
1932 ).finally(function() {
1933 hold_grid_load_promise = null;
1934 egProgressDialog.close();
1937 return hold_grid_load_promise;
1940 $scope.detail_view = function(action, user_data, items) {
1942 $scope.detail_hold_id = h.hold.id;
1946 $scope.list_view = function(items) {
1947 $scope.detail_hold_id = null;
1950 // refresh the list of record holds when the pickup lib is changed.
1951 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1952 $scope.pickup_ou_changed = function(org) {
1953 if ($scope.pickup_ou && $scope.pickup_ou.id() == org.id()) {
1954 // This fires on every component render, even though the
1955 // value we already have may match. Avoid duplicate lookups.
1959 var promise = hold_grid_load_promise || $q.when();
1961 // Avoid refreshing the grid if it's currently loading data.
1962 promise.finally(function() {
1964 // Previous grid data load complete. Timeout gives the
1965 // grid a chance to mark itself as load-completed, which
1966 // happens after the data load promise is done.
1967 setTimeout(function() {
1968 console.debug('Refreshing holds after PU lib change to ', org.id());
1969 $scope.pickup_ou = org;
1977 function map_prefix_to_subhash (h,pf) {
1979 angular.forEach(Object.keys(h), function (k) {
1980 if (k.startsWith(pf)) {
1981 var nk = k.substr(pf.length);
1988 $scope.print_holds = function() {
1990 angular.forEach(holds, function(item) {
1993 status_string : item.status_string,
1994 patron_first : item.hold.usr_first_given_name,
1995 patron_last : item.hold.usr_family_name,
1996 patron_alias : item.hold.usr_alias,
1997 patron_barcode : item.hold.ucard_barcode,
1998 copy : map_prefix_to_subhash(item.hold,'cp_'),
1999 volume : map_prefix_to_subhash(item.hold,'cn_'),
2000 title : item.hold.title,
2001 author : item.hold.author
2005 egCore.print.print({
2006 context : 'receipt',
2007 template : 'holds_for_bib',
2008 scope : {holds : pholds}
2012 $scope.current_hold_transfer_dest = egCore.hatch.getLocalItem ('eg.circ.hold.title_transfer_target');
2014 $scope.mark_hold_transfer_dest = function() {
2015 $scope.current_hold_transfer_dest = $scope.record_id;
2016 egCore.hatch.setLocalItem(
2017 'eg.circ.hold.title_transfer_target', $scope.record_id);
2018 ngToast.create(egCore.strings.HOLD_TRANSFER_DEST_MARKED);
2021 // UI presents this option as "all holds"
2022 $scope.transfer_holds_to_marked = function() {
2023 var hold_ids = $scope.hold_grid_controls.allItems().map(
2024 function(hold_data) {return hold_data.hold.id});
2025 egHolds.transfer_to_marked_title(hold_ids);
2028 // ------------------------------------------------------------------
2029 // Initialize the selected tab
2031 // we explicitly initialize catalog_url because otherwise Firefox
2032 // ends up setting it to $BASE_URL/{{url}}, which then messes
2033 // things up. See LP#1708951
2034 $scope.catalog_url = '';
2036 function init_cat_url() {
2037 // Set the initial catalog URL. This only happens once.
2038 // The URL is otherwise generated through user navigation.
2039 if ($scope.catalog_url) return;
2041 var url = $location.absUrl().replace(/\/staff\/.*/, '/opac/advanced');
2043 // A record ID in the path indicates a request for the record-
2045 if ($routeParams.record_id) {
2046 url = url.replace(/\/advanced/, '/record/' + $scope.record_id);
2049 // Jumping directly to the results page by passing a search
2050 // query via the URL. Copy all URL params to the iframe url.
2051 if ($location.path().match(/catalog\/results/)) {
2052 url = url.replace(/\/advanced/, '/results?');
2054 angular.forEach($location.search(), function(val, key) {
2055 if (!first) url += '&';
2057 url += encodeURIComponent(key)
2058 + '=' + encodeURIComponent(val);
2062 // if we're displaying the advanced search form, select
2063 // whatever default pane the user has chosen via workstation
2065 if (url.match(/\/opac\/advanced$/)) {
2066 egCore.hatch.getItem('eg.search.adv_pane').then(function(adv_pane_val){
2068 url += '?pane=' + encodeURIComponent(adv_pane_val);
2071 $scope.catalog_url = url;
2074 $scope.catalog_url = url;
2079 function init_parts_url() {
2080 $scope.parts_url = $location
2084 '/conify/global/biblio/monograph_part?r='+$scope.record_id
2088 $scope.set_record_tab = function(tab) {
2089 $scope.record_tab = tab;
2102 $scope.detail_hold_record_id = $scope.record_id;
2103 // refresh the holds grid
2110 $scope.set_default_record_tab = function() {
2111 egCore.hatch.setLocalItem(
2112 'eg.cat.default_record_tab', $scope.record_tab);
2113 $timeout(function(){$scope.default_tab = $scope.record_tab});
2117 if ($scope.record_id) {
2118 $scope.default_tab = get_default_record_tab();
2119 tab = $routeParams.record_tab || $scope.default_tab;
2122 tab = $routeParams.record_tab || 'catalog';
2124 $scope.set_record_tab(tab);
2128 .controller('AuthorityCtrl',
2129 ['$scope','$routeParams','$location','$window','$q','egCore',
2130 function($scope , $routeParams , $location , $window , $q , egCore) {
2132 // set record ID on page load if available...
2133 $scope.authority_id = $routeParams.authority_id;
2135 if ($routeParams.authority_id) $scope.from_route = true;
2136 else $scope.from_route = false;
2138 $scope.stop_unload = false;
2141 .controller('URLVerifyCtrl',
2142 ['$scope','$location',
2143 function($scope , $location) {
2144 $scope.verifyurls_url = $location.absUrl().replace(/\/staff\/.*/, '/url_verify/sessions');
2147 .controller('VandelayCtrl',
2148 ['$scope','$location', 'egCore', '$uibModal',
2149 function($scope , $location, egCore, $uibModal) {
2150 $scope.vandelay_url = $location.absUrl().replace(/\/staff\/cat\/catalog\/vandelay/, '/vandelay/vandelay');
2152 $scope.funcs.edit_marc_modal = function(bre, callback){
2153 var marcArgs = { 'marc_xml': bre.marc() };
2154 var vqbibrecId = bre.id();
2156 templateUrl: './cat/catalog/t_edit_marc_modal',
2159 controller: ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
2160 $scope.focusMe = true;
2161 $scope.recordId = vqbibrecId;
2162 $scope.args = marcArgs;
2163 $scope.dirty_flag = false;
2164 $scope.ok = function(marg){
2165 $uibModalInstance.close(marg);
2167 $scope.cancel = function(){ $uibModalInstance.dismiss() }
2169 }).result.then(function(res){
2170 var new_xml = res.marc_xml;
2171 egCore.pcrud.retrieve('vqbr', vqbibrecId).then(function(vqbib){
2172 vqbib.marc(new_xml);
2173 egCore.pcrud.update(vqbib).then( function(){ callback(vqbibrecId); });
2179 .controller('ManageAuthoritiesCtrl',
2180 ['$scope','$location',
2181 function($scope , $location) {
2182 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff\/.*/, '/cat/authority/list');
2185 .controller('BatchEditCtrl',
2186 ['$scope','$location','$routeParams',
2187 function($scope , $location , $routeParams) {
2188 $scope.batchedit_url = $location.absUrl().replace(/\/eg\/.*/, '/opac/extras/merge_template');
2189 if ($routeParams.container_type) {
2190 switch ($routeParams.container_type) {
2192 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
2195 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
2202 .filter('boolText', function(){
2203 return function (v) {
2208 .factory('conjoinedSvc',
2210 function(egCore , $q) {
2213 items : [], // record search results
2214 index : 0, // search grid index
2221 bpbcm : ['target_copy','peer_type'],
2222 acp : ['call_number'],
2224 bre : ['simple_record']
2226 // avoid fetching the MARC blob by specifying which
2227 // fields on the bre to select. More may be needed.
2228 // note that fleshed fields are explicitly selected.
2229 select : { bre : ['id'] },
2230 order_by : { bpbcm : ['id'] },
2233 // resolved with the last received copy
2234 service.fetch = function(rid) {
2235 if (!rid && !service.rid) return $q.when();
2237 if (rid) service.rid = rid;
2241 return egCore.pcrud.search(
2243 {peer_record : service.rid},
2246 ).then( function(list) { // finished
2247 service.items = list;
2248 return service.items;
2252 // returns a promise resolved with the list of peer bib types
2253 service.get_peer_types = function() {
2255 return $q.when(egCore.env.bpt.list);
2257 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
2258 .then(function(list) {
2259 egCore.env.absorbList(list, 'bpt');