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 : ['egCore','egStartup','egUser', function(egCore, egStartup, egUser) {
25 egCore.env.classLoaders.aous = function() {
26 return egCore.org.settings([
27 'cat.marc_control_number_identifier'
28 ]).then(function(settings) {
29 // local settings are cached within egOrg. Caching them
30 // again in egEnv just simplifies the syntax for access.
31 egCore.env.aous = settings;
34 egCore.env.loadClasses.push('aous');
38 $routeProvider.when('/cat/catalog/index', {
39 templateUrl: './cat/catalog/t_catalog',
40 controller: 'CatalogCtrl',
44 // Jump directly to the results page. Any URL parameter
45 // supported by the embedded catalog is supported here.
46 $routeProvider.when('/cat/catalog/results', {
47 templateUrl: './cat/catalog/t_catalog',
48 controller: 'CatalogCtrl',
52 $routeProvider.when('/cat/catalog/retrieve_by_id', {
53 templateUrl: './cat/catalog/t_retrieve_by_id',
54 controller: 'CatalogRecordRetrieve',
58 $routeProvider.when('/cat/catalog/retrieve_by_tcn', {
59 templateUrl: './cat/catalog/t_retrieve_by_tcn',
60 controller: 'CatalogRecordRetrieve',
64 $routeProvider.when('/cat/catalog/retrieve_by_authority_id', {
65 templateUrl: './cat/catalog/t_retrieve_by_authority_id',
66 controller: 'CatalogRecordRetrieve',
70 $routeProvider.when('/cat/catalog/new_bib', {
71 templateUrl: './cat/catalog/t_new_bib',
72 controller: 'NewBibCtrl',
76 // create some catalog page-specific mappings
77 $routeProvider.when('/cat/catalog/record/:record_id', {
78 templateUrl: './cat/catalog/t_catalog',
79 controller: 'CatalogCtrl',
83 // create some catalog page-specific mappings
84 $routeProvider.when('/cat/catalog/record/:record_id/:record_tab', {
85 templateUrl: './cat/catalog/t_catalog',
86 controller: 'CatalogCtrl',
90 $routeProvider.when('/cat/catalog/batchEdit', {
91 templateUrl: './cat/catalog/t_batchedit',
92 controller: 'BatchEditCtrl',
96 $routeProvider.when('/cat/catalog/batchEdit/:container_type/:container_id', {
97 templateUrl: './cat/catalog/t_batchedit',
98 controller: 'BatchEditCtrl',
102 $routeProvider.when('/cat/catalog/vandelay', {
103 templateUrl: './cat/catalog/t_vandelay',
104 controller: 'VandelayCtrl',
108 $routeProvider.when('/cat/catalog/verifyURLs', {
109 templateUrl: './cat/catalog/t_verifyurls',
110 controller: 'URLVerifyCtrl',
114 $routeProvider.when('/cat/catalog/manageAuthorities', {
115 templateUrl: './cat/catalog/t_manageauthorities',
116 controller: 'ManageAuthoritiesCtrl',
120 $routeProvider.when('/cat/catalog/authority/:authority_id/marc_edit', {
121 templateUrl: './cat/catalog/t_authority',
122 controller: 'AuthorityCtrl',
126 $routeProvider.otherwise({redirectTo : '/cat/catalog/index'});
132 .controller('CatalogRecordRetrieve',
133 ['$scope','$routeParams','$location','$q','egCore',
134 function($scope , $routeParams , $location , $q , egCore ) {
136 $scope.focusMe = true;
138 // jump to the patron checkout UI
139 function loadRecord(record_id) {
141 .path('/cat/catalog/record/' + record_id);
144 function loadAuthorityRecord(record_id) {
146 .path('/cat/catalog/authority/' + record_id + '/marc_edit');
149 $scope.submitId = function(args) {
150 $scope.recordNotFound = null;
151 if (!args.record_id) return;
153 // blur so next time it's set to true it will re-apply select()
154 $scope.selectMe = false;
156 return loadRecord(args.record_id);
159 $scope.submitAuthorityId = function(args) {
160 if (!args.record_id) return;
162 // blur so next time it's set to true it will re-apply select()
163 $scope.selectMe = false;
165 return loadAuthorityRecord(args.record_id);
168 $scope.submitTCN = function(args) {
169 $scope.recordNotFound = null;
170 $scope.moreRecordsFound = null;
171 if (!args.record_tcn) return;
173 // blur so next time it's set to true it will re-apply select()
174 $scope.selectMe = false;
179 'open-ils.search.biblio.tcn',
182 .then(function(resp) { // get_barcodes
185 return $q.when(resp);
187 // Search again including deleted records
188 return egCore.net.request('open-ils.search',
189 'open-ils.search.biblio.tcn', args.record_tcn, true);
192 }).then(function(resp2) {
195 $scope.recordNotFound = args.record_tcn;
196 $scope.selectMe = true;
200 if (resp2.count > 1) {
201 $scope.moreRecordsFound = args.record_tcn;
202 $scope.selectMe = true;
206 var record_id = resp2.ids[0];
207 return loadRecord(record_id);
213 .controller('NewBibCtrl',
214 ['$scope','$routeParams','$location','$window','$q','egCore',
215 'egGridDataProvider','egHoldGridActions','$timeout','holdingsSvc',
216 function($scope , $routeParams , $location , $window , $q , egCore) {
218 $scope.have_template = false;
219 $scope.marc_template = '';
220 $scope.stop_unload = false;
221 $scope.template_list = [];
222 $scope.template_name = '';
223 $scope.new_bib_id = 0;
227 'open-ils.cat.marc_template.types.retrieve'
228 ).then(function(resp) {
229 angular.forEach(resp, function(name) {
230 $scope.template_list.push(name);
232 $scope.template_list.sort();
234 $scope.template_name = egCore.hatch.getSessionItem('eg.cat.last_bib_marc_template');
235 if (!$scope.template_name) {
236 egCore.hatch.getItem('cat.default_bib_marc_template').then(function(template) {
237 $scope.template_name = template;
241 $scope.loadTemplate = function() {
242 if ($scope.template_name) {
245 'open-ils.cat.biblio.marc_template.retrieve',
247 ).then(function(template) {
248 $scope.marc_template = template;
249 $scope.have_template = true;
250 egCore.hatch.setSessionItem('eg.cat.last_bib_marc_template', $scope.template_name);
255 $scope.setDefaultTemplate = function() {
256 var hatch_key = "cat.default_bib_marc_template";
257 if ($scope.template_name) {
258 egCore.hatch.setItem(hatch_key, $scope.template_name);
260 egCore.hatch.removeItem(hatch_key);
264 $scope.$watch('new_bib_id', function(newVal, oldVal) {
266 $location.path('/cat/catalog/record/' + $scope.new_bib_id);
272 .controller('CatalogCtrl',
273 ['$scope','$routeParams','$location','$window','$q','egCore','egHolds','egCirc','egConfirmDialog','ngToast',
274 'egGridDataProvider','egHoldGridActions','egProgressDialog','$timeout','$uibModal','holdingsSvc','egUser','conjoinedSvc',
275 '$cookies','egSerialsCoreSvc',
276 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc , egConfirmDialog , ngToast ,
277 egGridDataProvider , egHoldGridActions , egProgressDialog , $timeout , $uibModal , holdingsSvc , egUser , conjoinedSvc,
278 $cookies , egSerialsCoreSvc
281 var holdingsSvcInst = new holdingsSvc();
283 // set record ID on page load if available...
284 $scope.record_id = $routeParams.record_id;
285 $scope.summary_pane_record;
287 if ($scope.record_id) {
288 // TODO: Apply tab-specific title contexts
289 egCore.strings.setPageTitle(
290 egCore.strings.PAGE_TITLE_BIB_DETAIL,
291 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT,
292 {record_id : $scope.record_id}
295 // Default to title = Catalog
296 egCore.strings.setPageTitle(
297 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT);
300 if ($routeParams.record_id) $scope.from_route = true;
301 else $scope.from_route = false;
303 // set search and preferred library cookies
304 egCore.hatch.getItem('eg.search.search_lib').then(function(val) {
305 $cookies.put('eg_search_lib', val, { path : '/' });
307 egCore.hatch.getItem('eg.search.pref_lib').then(function(val) {
308 $cookies.put('eg_pref_lib', val, { path : '/' });
311 // will hold a ref to the opac iframe
312 $scope.opac_iframe = null;
313 $scope.parts_iframe = null;
315 $scope.search_result_index = 1;
316 $scope.search_result_hit_count = 1;
319 'opac_iframe.dom.contentWindow.search_result_index',
321 if (!isNaN(parseInt(n)))
322 $scope.search_result_index = n + 1;
327 'opac_iframe.dom.contentWindow.search_result_hit_count',
329 if (!isNaN(parseInt(n)))
330 $scope.search_result_hit_count = n;
334 $scope.in_opac_call = false;
335 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
336 if ($scope.opac_iframe) {
337 if (force_opac_tab) $scope.record_tab = 'catalog';
338 $scope.in_opac_call = true;
339 $scope.opac_iframe.dom.contentWindow[opac_frame_function]();
340 if (opac_frame_function == 'rdetailBackToResults') {
341 $location.update_path('/cat/catalog/index');
346 $scope.add_cart_to_record_bucket = function() {
347 var cartkey = $cookies.get('cartcache');
348 if (!cartkey) return;
351 'open-ils.actor.anon_cache.get_value',
354 ).then(function(list) {
355 list = list.map(function(x) {
358 $scope.add_to_record_bucket(list);
362 $scope.add_to_record_bucket = function(recs) {
363 if (!angular.isArray(recs)) {
364 recs = [ $scope.record_id ];
366 return $uibModal.open({
367 templateUrl: './cat/catalog/t_add_to_bucket',
372 ['$scope','$uibModalInstance',
373 function($scope , $uibModalInstance) {
375 $scope.bucket_id = 0;
376 $scope.newBucketName = '';
377 $scope.allBuckets = [];
380 'open-ils.actor.container.retrieve_by_class.authoritative',
381 egCore.auth.token(), egCore.auth.user().id(),
382 'biblio', 'staff_client'
383 ).then(function(buckets) { $scope.allBuckets = buckets; });
385 $scope.add_to_bucket = function() {
387 angular.forEach(recs, function(recId) {
388 var item = new egCore.idl.cbrebi();
389 item.bucket($scope.bucket_id);
390 item.target_biblio_record_entry(recId);
391 promises.push(egCore.net.request(
393 'open-ils.actor.container.item.create',
394 egCore.auth.token(), 'biblio', item
397 $q.all(promises).then(function(resp) {
398 $uibModalInstance.close();
402 $scope.add_to_new_bucket = function() {
403 var bucket = new egCore.idl.cbreb();
404 bucket.owner(egCore.auth.user().id());
405 bucket.name($scope.newBucketName);
406 bucket.description('');
407 bucket.btype('staff_client');
411 'open-ils.actor.container.create',
412 egCore.auth.token(), 'biblio', bucket
413 ).then(function(bucket) {
414 $scope.bucket_id = bucket;
415 $scope.add_to_bucket();
419 $scope.cancel = function() {
420 $uibModalInstance.dismiss();
426 $scope.carousels_available = false;
429 'open-ils.actor.carousel.retrieve_manual_by_staff',
431 ).then(function(carousels) { $scope.carousels_available = true; });
433 $scope.add_to_carousel = function(recs) {
434 if (!angular.isArray(recs)) {
435 recs = [ $scope.record_id ];
437 return $uibModal.open({
438 templateUrl: './cat/catalog/t_add_to_carousel',
443 ['$scope','$uibModalInstance',
444 function($scope , $uibModalInstance) {
445 $scope.bucket_id = 0;
446 $scope.allCarousels = [];
449 'open-ils.actor.carousel.retrieve_manual_by_staff',
451 ).then(function(carousels) { $scope.allCarousels = carousels; });
453 $scope.add_to_carousel = function() {
454 // or more precisely, the carousel's bucket
456 angular.forEach(recs, function(recId) {
457 var item = new egCore.idl.cbrebi();
458 item.bucket($scope.bucket_id);
459 item.target_biblio_record_entry(recId);
460 promises.push(egCore.net.request(
462 'open-ils.actor.container.item.create',
463 egCore.auth.token(), 'biblio', item
466 $q.all(promises).then(function(resp) {
467 $uibModalInstance.close();
471 $scope.cancel = function() {
472 $uibModalInstance.dismiss();
478 $scope.current_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record');
479 $scope.current_transfer_target = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
480 $scope.current_conjoined_target = egCore.hatch.getLocalItem('eg.cat.marked_conjoined_record');
482 $scope.quickReceive = function () {
484 var next_per_stream = {};
486 var recId = $scope.record_id;
487 return $uibModal.open({
488 templateUrl: './share/t_subscription_select_dialog',
490 controller: ['$scope', '$uibModalInstance',
491 function($scope, $uibModalInstance) {
494 $scope.rememberMe = 'eg.serials.quickreceive.last_org';
495 $scope.record_id = recId;
496 $scope.ssubId = null;
498 $scope.ok = function() { $uibModalInstance.close($scope.ssubId) }
499 $scope.cancel = function() { $uibModalInstance.dismiss(); }
502 }).result.then(function(ssubId) {
505 promises.push(egSerialsCoreSvc.fetchItemsForSub(ssubId,{status:'Expected'}).then(function(){
506 angular.forEach(egSerialsCoreSvc.itemTree, function (item) {
507 if (next_per_stream[item.stream().id()]) return;
508 if (item.status() == 'Expected') {
509 next_per_stream[item.stream().id()] = item;
510 list.push(egCore.idl.Clone(item));
515 return $q.all(promises).then(function() {
518 ngToast.warning(egCore.strings.SERIALS_NO_ITEMS);
522 return egSerialsCoreSvc.process_items(
528 false, // print by default
529 function() { $scope.holdings_record_id_changed($scope.record_id) }
533 ngToast.warning(egCore.strings.SERIALS_NO_SUBS);
539 $scope.markConjoined = function () {
540 $scope.current_conjoined_target = $scope.record_id;
541 egCore.hatch.setLocalItem('eg.cat.marked_conjoined_record',$scope.record_id);
542 ngToast.create(egCore.strings.MARK_CONJ_TARGET);
545 $scope.markHoldingsTransfer = function () {
546 $scope.current_transfer_target = $scope.record_id;
547 egCore.hatch.setLocalItem('eg.cat.transfer_target_record',$scope.record_id);
548 egCore.hatch.removeLocalItem('eg.cat.transfer_target_lib');
549 egCore.hatch.removeLocalItem('eg.cat.transfer_target_vol');
550 ngToast.create(egCore.strings.MARK_HOLDINGS_TARGET);
553 $scope.markOverlay = function () {
554 $scope.current_overlay_target = $scope.record_id;
555 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.record_id);
556 ngToast.create(egCore.strings.MARK_OVERLAY_TARGET);
559 $scope.clearRecordMarks = function () {
560 $scope.current_overlay_target = null;
561 $scope.current_transfer_target = null;
562 $scope.current_conjoined_target = null;
563 $scope.current_hold_transfer_dest = null;
564 egCore.hatch.removeLocalItem('eg.cat.transfer_target_record');
565 egCore.hatch.removeLocalItem('eg.cat.marked_conjoined_record');
566 egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');
567 egCore.hatch.removeLocalItem('eg.circ.hold.title_transfer_target');
570 $scope.stop_unload = false;
571 $scope.$watch('stop_unload',
572 function(newVal, oldVal) {
573 if (newVal && newVal != oldVal && $scope.opac_iframe) {
574 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
575 return 'There is unsaved data in this record.'
578 if ($scope.opac_iframe)
579 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
584 // Set the "last bib" cookie, if we have that
585 if ($scope.record_id)
586 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
588 $scope.refresh_record_callback = function (record_id) {
589 egCore.pcrud.retrieve('bre', record_id, {
592 bre : ['simple_record','creator','editor']
594 }).then(function(rec) {
595 rec.owner(egCore.org.get(rec.owner()));
596 $scope.summary_pane_record = rec;
602 patron_search_dialog = function() {
603 return $uibModal.open({
604 templateUrl: './share/t_patron_selector',
609 ['$scope','$uibModalInstance','$controller',
610 function($scope , $uibModalInstance , $controller) {
611 angular.extend(this, $controller('BasePatronSearchCtrl', {$scope : $scope}));
613 $scope.need_one_selected = function() {
614 var items = $scope.gridControls.selectedItems();
615 return (items.length == 1) ? false : true
617 $scope.ok = function() {
618 var items = $scope.gridControls.selectedItems();
619 if (items.length == 1) {
620 $uibModalInstance.close(items[0].card().barcode());
622 $uibModalInstance.close()
625 $scope.cancel = function($event) {
626 $uibModalInstance.dismiss();
627 $event.preventDefault();
633 // also set it when the iframe changes to a new record
634 $scope.handle_page = function(url) {
636 if (!url || url == 'about:blank') {
637 // nothing loaded. If we already have a record ID, leave it.
641 var prev_record_id = $scope.record_id;
642 var match = url.match(/\/+opac\/+record\/+(\d+)/);
644 $scope.record_id = match[1];
645 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
646 $scope.holdings_record_id_changed($scope.record_id);
647 conjoinedSvc.fetch($scope.record_id).then(function(){
648 $scope.conjoinedGridDataProvider.refresh();
651 $scope.grid_actions.refresh();
652 $location.update_path('/cat/catalog/record/' + $scope.record_id);
653 // update_path() bypasses the controller for path
654 // /cat/catalog/record/:record_id. Manually set title here too.
655 egCore.strings.setPageTitle(
656 egCore.strings.PAGE_TITLE_BIB_DETAIL,
657 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT,
658 {record_id : $scope.record_id}
661 delete $scope.record_id;
662 $scope.from_route = false;
665 // child scope is executing this function, so our digest doesn't fire ... thus,
668 // don't change tabs if we are using the OPAC nav buttons,
669 // or we didn't change records on the OPAC load
670 if (!$scope.in_opac_call && ($scope.record_id != prev_record_id)) {
671 if ($scope.record_id) {
672 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
673 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
675 tab = $routeParams.record_tab || 'catalog';
677 $scope.set_record_tab(tab);
679 $scope.in_opac_call = false;
682 if ($scope.opac_iframe && $location.path().match(/cat\/catalog/)) {
683 var doc = $scope.opac_iframe.dom.contentWindow.document;
684 $(doc).find('#hold_usr_search').show();
685 $(doc).find('#hold_usr_search').on('click', function() {
686 patron_search_dialog().result.then(function(barc) {
687 $(doc).find('#hold_usr_input').val(barc);
688 $(doc).find('#hold_usr_input').change();
691 $(doc).find('#select_basket_action').on('change', function() {
692 if (this.options[this.selectedIndex].value && this.options[this.selectedIndex].value == "add_cart_to_bucket") {
693 $scope.add_cart_to_record_bucket();
700 // xulG catalog handlers
701 $scope.handlers = { }
703 // ------------------------------------------------------------------
706 $scope.conjoinedGridControls = {};
707 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
708 get : function(offset, count) {
709 return this.arrayNotifier(conjoinedSvc.items, offset, count);
713 $scope.changeConjoinedType = function () {
714 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
715 angular.forEach(peers, function (p) {
716 p.target_copy(p.target_copy().id());
717 p.peer_type(p.peer_type().id());
720 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
722 return $uibModal.open({
723 templateUrl: './cat/catalog/t_conjoined_selector',
727 ['$scope','$uibModalInstance',
728 function($scope , $uibModalInstance) {
729 $scope.update = true;
731 $scope.peer_type = null;
732 $scope.peer_type_list = [];
733 conjoinedSvc.get_peer_types().then(function(list){
734 $scope.peer_type_list = list;
737 $scope.ok = function(type) {
740 angular.forEach(peers, function (p) {
743 promises.push(egCore.pcrud.update(p));
746 return $q.all(promises)
747 .then(function(){$uibModalInstance.close()})
748 .then(function(){return conjoinedSvc.fetch()})
749 .then(function(){conjoinedGridDataProviderRef.refresh()});
752 $scope.cancel = function($event) {
753 $uibModalInstance.dismiss();
754 $event.preventDefault();
761 $scope.refreshConjoined = function () {
762 conjoinedSvc.fetch($scope.record_id)
763 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
766 $scope.deleteSelectedConjoined = function () {
767 var peers = $scope.conjoinedGridControls.selectedItems();
769 if (peers.length > 0) {
770 egConfirmDialog.open(
771 egCore.strings.CONFIRM_DELETE_PEERS,
772 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
773 {peers : peers.length}
774 ).result.then(function() {
775 angular.forEach(peers, function (p) {
779 egCore.pcrud.remove(peers).then(function() {
780 return conjoinedSvc.fetch();
782 $scope.conjoinedGridDataProvider.refresh();
787 if ($scope.record_id)
788 conjoinedSvc.fetch($scope.record_id);
790 // ------------------------------------------------------------------
793 $scope.holdingsGridControls = {
794 activateItem : function (item) {
795 $scope.selectedHoldingsVolCopyEdit();
798 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
799 get : function(offset, count) {
800 return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
804 $scope.add_copies_to_bucket = function() {
805 var copy_list = gatherSelectedHoldingsIds();
806 if (copy_list.length == 0) return;
808 return $uibModal.open({
809 templateUrl: './cat/catalog/t_add_to_bucket',
814 ['$scope','$uibModalInstance',
815 function($scope , $uibModalInstance) {
817 $scope.bucket_id = 0;
818 $scope.newBucketName = '';
819 $scope.allBuckets = [];
823 'open-ils.actor.container.retrieve_by_class.authoritative',
824 egCore.auth.token(), egCore.auth.user().id(),
825 'copy', 'staff_client'
826 ).then(function(buckets) { $scope.allBuckets = buckets; });
828 $scope.add_to_bucket = function() {
830 angular.forEach(copy_list, function (cp) {
831 var item = new egCore.idl.ccbi()
832 item.bucket($scope.bucket_id);
833 item.target_copy(cp);
837 'open-ils.actor.container.item.create',
838 egCore.auth.token(), 'copy', item
842 return $q.all(promises).then(function() {
843 $uibModalInstance.close();
848 $scope.add_to_new_bucket = function() {
849 var bucket = new egCore.idl.ccb();
850 bucket.owner(egCore.auth.user().id());
851 bucket.name($scope.newBucketName);
852 bucket.description('');
853 bucket.btype('staff_client');
855 return egCore.net.request(
857 'open-ils.actor.container.create',
858 egCore.auth.token(), 'copy', bucket
859 ).then(function(bucket) {
860 $scope.bucket_id = bucket;
861 $scope.add_to_bucket();
865 $scope.cancel = function() {
866 $uibModalInstance.dismiss();
872 // TODO: refactor common code between cat/catalog/app.js and cat/item/app.js
874 $scope.need_one_selected = function() {
875 var items = $scope.holdingsGridControls.selectedItems();
876 if (items.length == 1) return false;
880 $scope.make_copies_bookable = function() {
882 var copies_by_record = {};
883 var record_list = [];
885 $scope.holdingsGridControls.selectedItems(),
887 var record_id = item['call_number.record.id'];
888 if (typeof copies_by_record[ record_id ] == 'undefined') {
889 copies_by_record[ record_id ] = [];
890 record_list.push( record_id );
892 copies_by_record[ record_id ].push(item.id);
897 var combined_results = [];
898 angular.forEach(record_list, function(record_id) {
902 'open-ils.booking.resources.create_from_copies',
904 copies_by_record[record_id]
905 ).then(function(results) {
906 if (results && results['brsrc']) {
907 combined_results = combined_results.concat(results['brsrc']);
913 $q.all(promises).then(function() {
914 if (combined_results.length > 0) {
916 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
921 ['$scope','$location','egCore','$uibModalInstance',
922 function($scope , $location , egCore , $uibModalInstance) {
925 ses : egCore.auth.token(),
926 resultant_brsrc : combined_results.map(function(o) { return o[0]; })
929 var booking_path = '/eg/conify/global/booking/resource';
931 $scope.booking_admin_url =
932 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
939 $scope.book_copies_now = function() {
940 var copies_by_record = {};
941 var record_list = [];
943 $scope.holdingsGridControls.selectedItems(),
945 var record_id = item['call_number.record.id'];
946 if (typeof copies_by_record[ record_id ] == 'undefined') {
947 copies_by_record[ record_id ] = [];
948 record_list.push( record_id );
950 copies_by_record[ record_id ].push(item.id);
955 var combined_brt = [];
956 var combined_brsrc = [];
957 angular.forEach(record_list, function(record_id) {
961 'open-ils.booking.resources.create_from_copies',
963 copies_by_record[record_id]
964 ).then(function(results) {
965 if (results && results['brt']) {
966 combined_brt = combined_brt.concat(results['brt']);
968 if (results && results['brsrc']) {
969 combined_brsrc = combined_brsrc.concat(results['brsrc']);
975 $q.all(promises).then(function() {
976 if (combined_brt.length > 0 || combined_brsrc.length > 0) {
978 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
983 ['$scope','$location','egCore','$uibModalInstance',
984 function($scope , $location , egCore , $uibModalInstance) {
987 ses : egCore.auth.token(),
988 bresv_interface_opts : {
991 ,brsrc : combined_brsrc
996 var booking_path = '/eg/booking/reservation';
998 $scope.booking_admin_url =
999 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
1008 $scope.requestItems = function() {
1009 var copy_list = gatherSelectedHoldingsIds();
1010 if (copy_list.length == 0) return;
1012 return $uibModal.open({
1013 templateUrl: './cat/catalog/t_request_items',
1016 ['$scope','$uibModalInstance',
1017 function($scope , $uibModalInstance) {
1019 $scope.first_user_fetch = true;
1021 $scope.hold_data = {
1023 copy_list : copy_list,
1024 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
1025 user : egCore.auth.user().id()
1028 egUser.get( $scope.hold_data.user ).then(function(u) {
1030 $scope.barcode = u.card().barcode();
1031 $scope.user_name = egUser.format_name(u);
1032 $scope.hold_data.user = u.id();
1035 $scope.user_name = '';
1036 $scope.barcode = '';
1037 $scope.$watch('barcode', function (n) {
1038 if (!$scope.first_user_fetch) {
1039 egUser.getByBarcode(n).then(function(u) {
1041 $scope.user_name = egUser.format_name(u);
1042 $scope.hold_data.user = u.id();
1045 $scope.user_name = '';
1046 delete $scope.hold_data.user;
1049 $scope.first_user_fetch = false;
1052 $scope.ok = function(h) {
1055 hold_type : h.hold_type,
1056 pickup_lib: h.pickup_lib.id(),
1062 'open-ils.circ.holds.test_and_create.batch.override',
1063 egCore.auth.token(), args, h.copy_list
1066 $uibModalInstance.close();
1069 $scope.cancel = function($event) {
1070 $uibModalInstance.dismiss();
1071 $event.preventDefault();
1077 $scope.view_place_orders = function() {
1078 if (!$scope.record_id) return;
1079 var url = egCore.env.basePath + 'acq/legacy/lineitem/related/' + $scope.record_id + '?target=bib';
1080 $timeout(function() { $window.open(url, '_blank') });
1083 $scope.replaceBarcodes = function() {
1084 var copy_list = gatherSelectedRawCopies();
1085 if (copy_list.length == 0) return;
1087 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
1089 angular.forEach(copy_list, function (cp) {
1091 templateUrl: './cat/share/t_replace_barcode',
1095 ['$scope','$uibModalInstance',
1096 function($scope , $uibModalInstance) {
1097 $scope.isModal = true;
1098 $scope.focusBarcode = false;
1099 $scope.focusBarcode2 = true;
1100 $scope.barcode1 = cp.barcode();
1102 $scope.updateBarcode = function() {
1103 $scope.copyNotFound = false;
1104 $scope.updateOK = false;
1106 egCore.pcrud.search('acp',
1107 {deleted : 'f', barcode : $scope.barcode1})
1108 .then(function(copy) {
1111 $scope.focusBarcode = true;
1112 $scope.copyNotFound = true;
1116 $scope.copyId = copy.id();
1117 copy.barcode($scope.barcode2);
1119 egCore.pcrud.update(copy).then(function(stat) {
1120 $scope.updateOK = stat;
1121 $scope.focusBarcode = true;
1122 holdingsSvc.fetchAgain().then(function (){
1123 holdingsGridDataProviderRef.refresh();
1128 $uibModalInstance.close();
1131 $scope.cancel = function($event) {
1132 $uibModalInstance.dismiss();
1133 $event.preventDefault();
1141 var holdings_bChannel = null;
1142 // subscribe to BroadcastChannel for any child VolCopy tabs
1143 // refresh grid if needed to show new updates
1144 // if ($scope.record_tab === 'holdings'){
1145 $scope.$watch('record_tab', function(n){
1147 if (n === 'holdings'){
1148 if (typeof BroadcastChannel != 'undefined') {
1149 // we're in holdings tab, connect 2 bChannel
1150 holdings_bChannel = new BroadcastChannel('eg.holdings.update');
1151 holdings_bChannel.onmessage = function(e){
1154 && e.data.records.length
1155 && e.data.records.includes(Number($scope.record_id))
1156 ){ // it's for us, refresh grid!
1157 console.log("Got broadcast from channel eg.holdings.update for records " + e.data.records);
1158 $scope.holdings_record_id_changed($scope.record_id);
1163 } else if (holdings_bChannel){ // we're leaving holding tab, close bChannel
1164 holdings_bChannel.close();
1169 // refresh the list of holdings when the record_id is changed.
1170 $scope.holdings_record_id_changed = function(id) {
1171 if ($scope.record_id != id) $scope.record_id = id;
1172 console.log('record id changed to ' + id + ', loading new holdings');
1173 holdingsSvcInst.fetch({
1174 rid : $scope.record_id,
1175 org : $scope.holdings_ou,
1176 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1177 vol : $scope.holdings_show_vols,
1178 empty: $scope.holdings_show_empty,
1179 empty_org: $scope.holdings_show_empty_org
1180 }).then(function() {
1181 $scope.holdingsGridDataProvider.refresh();
1185 // refresh the list of holdings when the filter lib is changed.
1186 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
1187 $scope.holdings_ou_changed = function(org) {
1188 $scope.holdings_ou = org;
1189 holdingsSvcInst.fetch({
1190 rid : $scope.record_id,
1191 org : $scope.holdings_ou,
1192 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1193 vol : $scope.holdings_show_vols,
1194 empty: $scope.holdings_show_empty,
1195 empty_org: $scope.holdings_show_empty_org
1196 }).then(function() {
1197 $scope.holdingsGridDataProvider.refresh();
1201 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
1202 $scope[cb] = newVal;
1203 var x = $scope.holdings_show_vols ? $scope.holdings_show_copies : false;
1204 $('#holdings_show_copies').prop('checked', x);
1205 egCore.hatch.setItem('cat.' + cb, newVal);
1206 if (!norefresh) holdingsSvcInst.fetch({
1207 rid : $scope.record_id,
1208 org : $scope.holdings_ou,
1209 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1210 vol : $scope.holdings_show_vols,
1211 empty: $scope.holdings_show_empty,
1212 empty_org: $scope.holdings_show_empty_org
1213 }).then(function() {
1214 $scope.holdingsGridDataProvider.refresh();
1218 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
1219 if (typeof x == 'undefined') x = true;
1220 $scope.holdings_cb_changed('holdings_show_vols',x,true);
1221 $('#holdings_show_vols').prop('checked', x);
1223 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
1224 if (typeof x == 'undefined') x = true;
1225 $scope.holdings_cb_changed('holdings_show_copies',x,true);
1226 x = $scope.holdings_show_vols ? x : false;
1227 $('#holdings_show_copies').prop('checked', x);
1229 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
1230 if (typeof x == 'undefined') x = true;
1231 $scope.holdings_cb_changed('holdings_show_empty',x);
1232 $('#holdings_show_empty').prop('checked', x);
1234 egCore.hatch.getItem('cat.holdings_show_empty_org').then(function(x){
1235 if (typeof x == 'undefined') x = true;
1236 $scope.holdings_cb_changed('holdings_show_empty_org',x);
1237 $('#holdings_show_empty_org').prop('checked', x);
1243 $scope.vols_not_shown = function () {
1244 return !$scope.holdings_show_vols;
1247 $scope.copies_not_shown = function () {
1248 return !$scope.holdings_show_copies;
1251 $scope.empty_org_not_shown = function () {
1252 return !$scope.holdings_show_empty_org;
1255 $scope.holdings_checkbox_handler = function (item) {
1256 $scope.holdings_cb_changed(item.checkbox,item.checked);
1259 function gatherSelectedHoldingsIds () {
1260 var cp_id_list = [];
1262 $scope.holdingsGridControls.selectedItems(),
1263 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
1268 function gatherSelectedRawCopies () {
1271 $scope.holdingsGridControls.selectedItems(),
1272 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
1277 function gatherSelectedEmptyVolumeIds () {
1278 var cn_id_list = [];
1280 $scope.holdingsGridControls.selectedItems(),
1282 if (item.copy_count == 0 || (!item.id && item.call_number))
1283 // we are in a compressed row with no copies, or we are in a single
1284 // call number row with no copy (testing for presence of 'id')
1285 // In either case, the call number is 'empty'
1286 cn_id_list.push(item.call_number.id)
1292 function gatherSelectedVolumeIds () {
1293 var cn_id_list = [];
1295 $scope.holdingsGridControls.selectedItems(),
1297 if (cn_id_list.indexOf(item.call_number.id) == -1)
1298 cn_id_list.push(item.call_number.id)
1304 $scope.selectedHoldingsDelete = function (vols, copies) {
1307 var perCnCopies = {};
1313 $scope.holdingsGridControls.selectedItems(),
1315 if (vols && item.raw_call_number) {
1316 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
1317 cnHash[item.call_number.id].isdeleted(1);
1319 } else if (copies) {
1320 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
1323 var cn_id = cp.call_number().id();
1324 if (!cnHash[cn_id]) {
1325 cnHash[cn_id] = cp.call_number();
1326 perCnCopies[cn_id] = [cp];
1328 perCnCopies[cn_id].push(cp);
1330 cp.call_number(cn_id); // prevent loops in JSON-ification
1337 angular.forEach(perCnCopies, function (v, k) {
1339 cnHash[k].isdeleted(1);
1342 cnHash[k].copies(v);
1346 angular.forEach(cnHash, function (v, k) {
1350 if (cnList.length == 0) return;
1353 if (vols && copies) flags.force_delete_copies = 1;
1355 egConfirmDialog.open(
1356 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
1357 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
1358 {copies : cp_count, volumes : cn_count}
1359 ).result.then(function() {
1362 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1363 egCore.auth.token(), cnList, 1, flags
1364 ).then(function(update_count) {
1365 holdingsSvcInst.fetchAgain().then(function() {
1366 $scope.holdingsGridDataProvider.refresh();
1371 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
1372 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
1373 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
1375 spawnHoldingsAdd = function (add_vols,add_copies){
1377 if (!add_vols && add_copies) { // just a copy on existing volumes
1378 angular.forEach(gatherSelectedVolumeIds(), function (v) {
1379 raw.push( {callnumber : v} );
1381 } else if (add_vols) {
1382 if (typeof $scope.holdingsGridControls.selectedItems == "function" &&
1383 $scope.holdingsGridControls.selectedItems().length > 0) {
1384 angular.forEach($scope.holdingsGridControls.selectedItems(),
1387 owner : item.owner_id,
1388 label : ((item.call_number) ? item.call_number.label : null)
1393 owner : egCore.auth.user().ws_ou()
1398 if (raw.length == 0) raw.push({});
1402 'open-ils.actor.anon_cache.set_value',
1403 null, 'edit-these-copies', {
1404 record_id: $scope.record_id,
1407 hide_copies : !add_copies
1409 ).then(function(key) {
1411 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1412 $timeout(function() { $window.open(url, '_blank') });
1414 alert('Could not create anonymous cache key!');
1418 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,true) }
1419 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
1420 $scope.selectedHoldingsVolAdd = function () { spawnHoldingsAdd(true,false) }
1422 spawnHoldingsEdit = function (hide_vols,hide_copies){
1425 'open-ils.actor.anon_cache.set_value',
1426 null, 'edit-these-copies', {
1427 record_id: $scope.record_id,
1428 copies: gatherSelectedHoldingsIds(),
1429 raw: gatherSelectedEmptyVolumeIds().map(
1430 function(v){ return { callnumber : v } }
1432 hide_vols : hide_vols,
1433 hide_copies : hide_copies
1435 ).then(function(key) {
1437 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1438 $timeout(function() { $window.open(url, '_blank') });
1440 alert('Could not create anonymous cache key!');
1444 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
1445 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
1446 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
1448 $scope.selectedHoldingsItemStatus = function (){
1449 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
1450 $timeout(function() { $window.open(url, '_blank') });
1453 $scope.markFromSelectedAsHoldingsTarget = function() {
1454 egCore.hatch.setLocalItem(
1455 'eg.cat.transfer_target_lib',
1456 $scope.holdingsGridControls.selectedItems()[0].owner_id
1458 egCore.hatch.setLocalItem(
1459 'eg.cat.transfer_target_record',
1462 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed, or we are on an empty lib
1463 egCore.hatch.setLocalItem(
1464 'eg.cat.transfer_target_vol',
1465 $scope.holdingsGridControls.selectedItems()[0].call_number.id
1468 // clear out the stale value if we're on a lib-only
1469 // or vol-collapsed row
1470 egCore.hatch.removeLocalItem('eg.cat.transfer_target_vol');
1472 ngToast.create(egCore.strings.MARK_HOLDINGS_TARGET);
1475 $scope.selectedHoldingsItemStatusDetail = function (){
1477 gatherSelectedHoldingsIds(),
1479 var url = egCore.env.basePath +
1481 $timeout(function() { $window.open(url, '_blank') });
1486 $scope.transferVolumes = function (){
1487 var target_record = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
1488 var target_lib = egCore.hatch.getLocalItem('eg.cat.transfer_target_lib');
1490 && (!target_record || ($scope.record_id == target_record) )
1493 var vols_to_move = {};
1495 // we're moving volumes to a different library
1496 var vol_ids = gatherSelectedVolumeIds();
1497 if (vol_ids.length) {
1498 vols_to_move[target_lib] = vol_ids;
1500 // if we're *only* switching libs,
1501 // grab the current record as the target
1502 target_record = target_record || $scope.record_id;
1505 // we're moving volumes to the same library they exist in
1506 // currently, but on a different record
1507 var items = $scope.holdingsGridControls.selectedItems();
1508 angular.forEach(items, function(item) {
1509 if (!(item.call_number.owning_lib in vols_to_move)) {
1510 vols_to_move[item.call_number.owning_lib] = new Array;
1512 vols_to_move[item.call_number.owning_lib].push(item.call_number.id);
1517 angular.forEach(vols_to_move, function(vols, owning_lib) {
1518 promises.push(egCore.net.request(
1520 'open-ils.cat.asset.volume.batch.transfer.override',
1521 egCore.auth.token(), {
1522 docid : target_record,
1528 $q.all(promises).then(function(success) {
1530 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1531 holdingsSvcInst.fetchAgain().then(function() {
1532 $scope.holdingsGridDataProvider.refresh();
1535 alert('Could not transfer volumes!');
1540 // this "transfers" selected copies to a new owning library,
1541 // auto-creating volumes as required
1542 $scope.transferItemsAutoFill = function() {
1543 var target_record = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
1544 var target_lib = egCore.hatch.getLocalItem('eg.cat.transfer_target_lib');
1546 && (!target_record || ($scope.record_id == target_record) )
1549 var items = $scope.holdingsGridControls.selectedItems();
1550 if (!items.length) {
1554 var vols_to_move = {};
1555 var copies_to_move = {};
1556 angular.forEach(items, function(item) {
1557 var needs_move = false;
1559 && (item.call_number.owning_lib != target_lib)) {
1560 item.call_number.owning_lib = target_lib;
1564 && (item.call_number.record != target_record)) {
1565 item.call_number.record = target_record;
1569 if (item.call_number.id in vols_to_move) {
1570 copies_to_move[item.call_number.id].push(item.id);
1572 vols_to_move[item.call_number.id] = item.call_number;
1573 copies_to_move[item.call_number.id] = new Array;
1574 copies_to_move[item.call_number.id].push(item.id);
1580 angular.forEach(vols_to_move, function(vol) {
1581 promises.push(egCore.net.request(
1583 'open-ils.cat.call_number.find_or_create',
1584 egCore.auth.token(),
1586 vol.record, // may be new
1587 vol.owning_lib, // may be new
1591 ).then(function(resp) {
1592 var evt = egCore.evt.parse(resp);
1594 return egCore.net.request(
1596 'open-ils.cat.transfer_copies_to_volume',
1597 egCore.auth.token(),
1599 copies_to_move[vol.id]
1603 $q.all(promises).then(function() {
1604 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1605 holdingsSvcInst.fetchAgain().then(function() {
1606 $scope.holdingsGridDataProvider.refresh();
1611 $scope.gridCellHandlers = {};
1612 $scope.gridCellHandlers.copyAlertsEdit = function(id) {
1613 egCirc.manage_copy_alerts([id]).then(function() {
1614 // update grid items?
1618 $scope.transferItems = function (){
1619 var xfer_target = egCore.hatch.getLocalItem('eg.cat.transfer_target_vol');
1622 // we have no specific volume, let's try to fill in the
1624 return $scope.transferItemsAutoFill();
1627 var copy_ids = gatherSelectedHoldingsIds();
1628 if (copy_ids.length > 0) {
1631 'open-ils.cat.transfer_copies_to_volume',
1632 egCore.auth.token(),
1636 function(resp) { // oncomplete
1637 var evt = egCore.evt.parse(resp);
1639 egConfirmDialog.open(
1640 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1641 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1642 {'evt_desc': evt.desc}
1643 ).result.then(function() {
1646 'open-ils.cat.transfer_copies_to_volume.override',
1647 egCore.auth.token(),
1650 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1651 ).then(function(resp) {
1652 holdingsSvcInst.fetchAgain().then(function() {
1653 $scope.holdingsGridDataProvider.refresh();
1658 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1659 holdingsSvcInst.fetchAgain().then(function() {
1660 $scope.holdingsGridDataProvider.refresh();
1670 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1672 gatherSelectedHoldingsIds(),
1674 var url = egCore.env.basePath +
1675 'cat/item/' + cid + '/triggered_events';
1676 $timeout(function() { $window.open(url, '_blank') });
1681 $scope.selectedHoldingsItemStatusHolds = function (){
1683 gatherSelectedHoldingsIds(),
1685 var url = egCore.env.basePath +
1686 'cat/item/' + cid + '/holds';
1687 $timeout(function() { $window.open(url, '_blank') });
1692 $scope.selectedHoldingsPrintLabels = function() {
1695 'open-ils.actor.anon_cache.set_value',
1696 null, 'print-labels-these-copies', {
1697 copies : gatherSelectedHoldingsIds()
1699 ).then(function(key) {
1701 var url = egCore.env.basePath + 'cat/printlabels/' + key;
1702 $timeout(function() { $window.open(url, '_blank') });
1704 alert('Could not create anonymous cache key!');
1709 $scope.selectedHoldingsDamaged = function () {
1710 var copy_list = gatherSelectedRawCopies();
1711 if (copy_list.length == 0) return;
1713 angular.forEach(copy_list, function(cp) {
1714 egCirc.mark_damaged({
1716 barcode: cp.barcode(),
1717 circ_lib: cp.circ_lib().id()
1718 }).then(function() {
1719 holdingsSvcInst.fetchAgain().then(function() {
1720 $scope.holdingsGridDataProvider.refresh();
1726 $scope.selectedHoldingsDiscard = function () {
1727 var copy_list = gatherSelectedRawCopies();
1728 if (copy_list.length == 0) return;
1729 egCirc.mark_discard(copy_list.map(function(cp) {
1730 return {id: cp.id(), barcode: cp.barcode()};})).then(function() {
1731 holdingsSvcInst.fetchAgain().then(function() {
1732 $scope.holdingsGridDataProvider.refresh();
1737 $scope.selectedHoldingsMissing = function () {
1738 var copy_list = gatherSelectedRawCopies();
1739 if (copy_list.length == 0) return;
1740 egCirc.mark_missing(copy_list.map(function(cp) {
1741 return {id: cp.id(), barcode: cp.barcode()};})).then(function() {
1742 holdingsSvcInst.fetchAgain().then(function() {
1743 $scope.holdingsGridDataProvider.refresh();
1748 $scope.selectedHoldingsCopyAlertsAdd = function() {
1749 egCirc.add_copy_alerts(gatherSelectedHoldingsIds()).then(function() {
1750 // no need to refresh grid
1753 $scope.selectedHoldingsCopyAlertsManage = function() {
1754 egCirc.manage_copy_alerts(gatherSelectedHoldingsIds()).then(function() {
1755 // no need to refresh grid
1759 $scope.attach_to_peer_bib = function() {
1760 var copy_list = gatherSelectedHoldingsIds();
1761 if (copy_list.length == 0) return;
1763 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1764 if (!target_record) return;
1766 return $uibModal.open({
1767 templateUrl: './cat/catalog/t_conjoined_selector',
1771 ['$scope','$uibModalInstance',
1772 function($scope , $uibModalInstance) {
1773 $scope.update = false;
1775 $scope.peer_type = null;
1776 $scope.peer_type_list = [];
1777 conjoinedSvc.get_peer_types().then(function(list){
1778 $scope.peer_type_list = list;
1781 $scope.ok = function(type) {
1784 angular.forEach(copy_list, function (cp) {
1785 var n = new egCore.idl.bpbcm();
1787 n.peer_record(target_record);
1790 promises.push(egCore.pcrud.create(n));
1793 return $q.all(promises).then(function(){$uibModalInstance.close()});
1796 $scope.cancel = function($event) {
1797 $uibModalInstance.dismiss();
1798 $event.preventDefault();
1806 // ------------------------------------------------------------------
1808 var provider = egGridDataProvider.instance({});
1809 var holds = []; // current list of holds
1812 $scope.hold_grid_data_provider = provider;
1813 $scope.grid_actions = egHoldGridActions;
1814 $scope.grid_actions.refresh = function () { holds = []; hold_count = 0; provider.refresh() };
1815 $scope.hold_grid_controls = {};
1817 provider.get = function(offset, count) {
1818 if ($scope.record_tab != 'holds') return $q.when();
1820 // see if we have the requested range cached
1821 if (holds[offset]) {
1822 return provider.arrayNotifier(holds, offset, count);
1827 var restrictions = {
1828 is_staff_request : 'true',
1829 fulfillment_time : null,
1831 record_id : $scope.record_id,
1832 pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)
1835 var order_by = [{ request_time : null }];
1836 if (provider.sort && provider.sort.length) {
1838 angular.forEach(provider.sort, function (c) {
1839 if (!angular.isObject(c)) {
1840 if (c.match(/^hold\./)) {
1841 var i = c.replace('hold.','');
1847 var i = Object.keys(c)[0];
1848 var direction = c[i];
1849 if (i.match(/^hold\./)) {
1850 i = i.replace('hold.','');
1852 ob[i] = {dir:direction};
1859 egProgressDialog.open({max : 1, value : 0});
1861 return egHolds.fetch_wide_holds(
1864 ).then(function () {
1865 return provider.arrayNotifier(holds, offset, count);
1868 function(hold_data) {
1870 hold_count = hold_data;
1872 egProgressDialog.update({max:hold_count});
1874 egProgressDialog.increment();
1875 var new_item = { id : hold_data.id, hold : hold_data };
1876 new_item.status_string =
1877 egCore.strings['HOLD_STATUS_' + hold_data.hold_status]
1878 || hold_data.hold_status;
1880 holds.push(new_item);
1883 ).finally(egProgressDialog.close);
1887 $scope.detail_view = function(action, user_data, items) {
1889 $scope.detail_hold_id = h.hold.id;
1893 $scope.list_view = function(items) {
1894 $scope.detail_hold_id = null;
1897 // refresh the list of record holds when the pickup lib is changed.
1898 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1899 $scope.pickup_ou_changed = function(org) {
1900 $scope.pickup_ou = org;
1906 function map_prefix_to_subhash (h,pf) {
1908 angular.forEach(Object.keys(h), function (k) {
1909 if (k.startsWith(pf)) {
1910 var nk = k.substr(pf.length);
1917 $scope.print_holds = function() {
1919 angular.forEach(holds, function(item) {
1922 status_string : item.status_string,
1923 patron_first : item.hold.usr_first_given_name,
1924 patron_last : item.hold.usr_family_name,
1925 patron_alias : item.hold.usr_alias,
1926 patron_barcode : item.hold.ucard_barcode,
1927 copy : map_prefix_to_subhash(item.hold,'cp_'),
1928 volume : map_prefix_to_subhash(item.hold,'cn_'),
1929 title : item.hold.title,
1930 author : item.hold.author
1934 egCore.print.print({
1935 context : 'receipt',
1936 template : 'holds_for_bib',
1937 scope : {holds : pholds}
1941 $scope.current_hold_transfer_dest = egCore.hatch.getLocalItem ('eg.circ.hold.title_transfer_target');
1943 $scope.mark_hold_transfer_dest = function() {
1944 $scope.current_hold_transfer_dest = $scope.record_id;
1945 egCore.hatch.setLocalItem(
1946 'eg.circ.hold.title_transfer_target', $scope.record_id);
1947 ngToast.create(egCore.strings.HOLD_TRANSFER_DEST_MARKED);
1950 // UI presents this option as "all holds"
1951 $scope.transfer_holds_to_marked = function() {
1952 var hold_ids = $scope.hold_grid_controls.allItems().map(
1953 function(hold_data) {return hold_data.hold.id});
1954 egHolds.transfer_to_marked_title(hold_ids);
1957 // ------------------------------------------------------------------
1958 // Initialize the selected tab
1960 // we explicitly initialize catalog_url because otherwise Firefox
1961 // ends up setting it to $BASE_URL/{{url}}, which then messes
1962 // things up. See LP#1708951
1963 $scope.catalog_url = '';
1965 function init_cat_url() {
1966 // Set the initial catalog URL. This only happens once.
1967 // The URL is otherwise generated through user navigation.
1968 if ($scope.catalog_url) return;
1970 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1972 // A record ID in the path indicates a request for the record-
1974 if ($routeParams.record_id) {
1975 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1978 // Jumping directly to the results page by passing a search
1979 // query via the URL. Copy all URL params to the iframe url.
1980 if ($location.path().match(/catalog\/results/)) {
1981 url = url.replace(/advanced/, '/results?');
1983 angular.forEach($location.search(), function(val, key) {
1984 if (!first) url += '&';
1986 url += encodeURIComponent(key)
1987 + '=' + encodeURIComponent(val);
1991 // if we're displaying the advanced search form, select
1992 // whatever default pane the user has chosen via workstation
1994 if (url.match(/\/opac\/advanced$/)) {
1995 egCore.hatch.getItem('eg.search.adv_pane').then(function(adv_pane_val){
1997 url += '?pane=' + encodeURIComponent(adv_pane_val);
2000 $scope.catalog_url = url;
2003 $scope.catalog_url = url;
2008 function init_parts_url() {
2009 $scope.parts_url = $location
2013 '/conify/global/biblio/monograph_part?r='+$scope.record_id
2017 $scope.set_record_tab = function(tab) {
2018 $scope.record_tab = tab;
2031 $scope.detail_hold_record_id = $scope.record_id;
2032 // refresh the holds grid
2039 $scope.set_default_record_tab = function() {
2040 egCore.hatch.setLocalItem(
2041 'eg.cat.default_record_tab', $scope.record_tab);
2042 $timeout(function(){$scope.default_tab = $scope.record_tab});
2046 if ($scope.record_id) {
2047 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
2048 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
2051 tab = $routeParams.record_tab || 'catalog';
2053 $scope.set_record_tab(tab);
2057 .controller('AuthorityCtrl',
2058 ['$scope','$routeParams','$location','$window','$q','egCore',
2059 function($scope , $routeParams , $location , $window , $q , egCore) {
2061 // set record ID on page load if available...
2062 $scope.authority_id = $routeParams.authority_id;
2064 if ($routeParams.authority_id) $scope.from_route = true;
2065 else $scope.from_route = false;
2067 $scope.stop_unload = false;
2070 .controller('URLVerifyCtrl',
2071 ['$scope','$location',
2072 function($scope , $location) {
2073 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
2076 .controller('VandelayCtrl',
2077 ['$scope','$location', 'egCore', '$uibModal',
2078 function($scope , $location, egCore, $uibModal) {
2079 $scope.vandelay_url = $location.absUrl().replace(/\/staff\/cat\/catalog\/vandelay/, '/vandelay/vandelay');
2081 $scope.funcs.edit_marc_modal = function(bre, callback){
2082 var marcArgs = { 'marc_xml': bre.marc() };
2083 var vqbibrecId = bre.id();
2085 templateUrl: './cat/catalog/t_edit_marc_modal',
2088 controller: ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
2089 $scope.focusMe = true;
2090 $scope.recordId = vqbibrecId;
2091 $scope.args = marcArgs;
2092 $scope.dirty_flag = false;
2093 $scope.ok = function(marg){
2094 $uibModalInstance.close(marg);
2096 $scope.cancel = function(){ $uibModalInstance.dismiss() }
2098 }).result.then(function(res){
2099 var new_xml = res.marc_xml;
2100 egCore.pcrud.retrieve('vqbr', vqbibrecId).then(function(vqbib){
2101 vqbib.marc(new_xml);
2102 egCore.pcrud.update(vqbib).then( function(){ callback(vqbibrecId); });
2108 .controller('ManageAuthoritiesCtrl',
2109 ['$scope','$location',
2110 function($scope , $location) {
2111 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
2114 .controller('BatchEditCtrl',
2115 ['$scope','$location','$routeParams',
2116 function($scope , $location , $routeParams) {
2117 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
2118 if ($routeParams.container_type) {
2119 switch ($routeParams.container_type) {
2121 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
2124 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
2131 .filter('boolText', function(){
2132 return function (v) {
2137 .factory('conjoinedSvc',
2139 function(egCore , $q) {
2142 items : [], // record search results
2143 index : 0, // search grid index
2150 bpbcm : ['target_copy','peer_type'],
2151 acp : ['call_number'],
2153 bre : ['simple_record']
2155 // avoid fetching the MARC blob by specifying which
2156 // fields on the bre to select. More may be needed.
2157 // note that fleshed fields are explicitly selected.
2158 select : { bre : ['id'] },
2159 order_by : { bpbcm : ['id'] },
2162 // resolved with the last received copy
2163 service.fetch = function(rid) {
2164 if (!rid && !service.rid) return $q.when();
2166 if (rid) service.rid = rid;
2170 return egCore.pcrud.search(
2172 {peer_record : service.rid},
2175 ).then( function(list) { // finished
2176 service.items = list;
2177 return service.items;
2181 // returns a promise resolved with the list of peer bib types
2182 service.get_peer_types = function() {
2184 return $q.when(egCore.env.bpt.list);
2186 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
2187 .then(function(list) {
2188 egCore.env.absorbList(list, 'bpt');