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
184 if (evt = egCore.evt.parse(resp)) {
190 $scope.recordNotFound = args.record_tcn;
191 $scope.selectMe = true;
195 if (resp.count > 1) {
196 $scope.moreRecordsFound = args.record_tcn;
197 $scope.selectMe = true;
201 var record_id = resp.ids[0];
202 return loadRecord(record_id);
208 .controller('NewBibCtrl',
209 ['$scope','$routeParams','$location','$window','$q','egCore',
210 'egGridDataProvider','egHoldGridActions','$timeout','holdingsSvc',
211 function($scope , $routeParams , $location , $window , $q , egCore) {
213 $scope.have_template = false;
214 $scope.marc_template = '';
215 $scope.stop_unload = false;
216 $scope.template_list = [];
217 $scope.template_name = '';
218 $scope.new_bib_id = 0;
222 'open-ils.cat.marc_template.types.retrieve'
223 ).then(function(resp) {
224 angular.forEach(resp, function(name) {
225 $scope.template_list.push(name);
227 $scope.template_list.sort();
229 $scope.template_name = egCore.hatch.getSessionItem('eg.cat.last_bib_marc_template');
230 if (!$scope.template_name) {
231 egCore.hatch.getItem('cat.default_bib_marc_template').then(function(template) {
232 $scope.template_name = template;
236 $scope.loadTemplate = function() {
237 if ($scope.template_name) {
240 'open-ils.cat.biblio.marc_template.retrieve',
242 ).then(function(template) {
243 $scope.marc_template = template;
244 $scope.have_template = true;
245 egCore.hatch.setSessionItem('eg.cat.last_bib_marc_template', $scope.template_name);
250 $scope.setDefaultTemplate = function() {
251 var hatch_key = "cat.default_bib_marc_template";
252 if ($scope.template_name) {
253 egCore.hatch.setItem(hatch_key, $scope.template_name);
255 egCore.hatch.removeItem(hatch_key);
259 $scope.$watch('new_bib_id', function(newVal, oldVal) {
261 $location.path('/cat/catalog/record/' + $scope.new_bib_id);
267 .controller('CatalogCtrl',
268 ['$scope','$routeParams','$location','$window','$q','egCore','egHolds','egCirc','egConfirmDialog','ngToast',
269 'egGridDataProvider','egHoldGridActions','egProgressDialog','$timeout','$uibModal','holdingsSvc','egUser','conjoinedSvc',
270 '$cookies','egSerialsCoreSvc',
271 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc , egConfirmDialog , ngToast ,
272 egGridDataProvider , egHoldGridActions , egProgressDialog , $timeout , $uibModal , holdingsSvc , egUser , conjoinedSvc,
273 $cookies , egSerialsCoreSvc
276 var holdingsSvcInst = new holdingsSvc();
278 // set record ID on page load if available...
279 $scope.record_id = $routeParams.record_id;
280 $scope.summary_pane_record;
282 if ($scope.record_id) {
283 // TODO: Apply tab-specific title contexts
284 egCore.strings.setPageTitle(
285 egCore.strings.PAGE_TITLE_BIB_DETAIL,
286 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT,
287 {record_id : $scope.record_id}
290 // Default to title = Catalog
291 egCore.strings.setPageTitle(
292 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT);
295 if ($routeParams.record_id) $scope.from_route = true;
296 else $scope.from_route = false;
298 // set search and preferred library cookies
299 egCore.hatch.getItem('eg.search.search_lib').then(function(val) {
300 $cookies.put('eg_search_lib', val, { path : '/' });
302 egCore.hatch.getItem('eg.search.pref_lib').then(function(val) {
303 $cookies.put('eg_pref_lib', val, { path : '/' });
306 // will hold a ref to the opac iframe
307 $scope.opac_iframe = null;
308 $scope.parts_iframe = null;
310 $scope.search_result_index = 1;
311 $scope.search_result_hit_count = 1;
314 'opac_iframe.dom.contentWindow.search_result_index',
316 if (!isNaN(parseInt(n)))
317 $scope.search_result_index = n + 1;
322 'opac_iframe.dom.contentWindow.search_result_hit_count',
324 if (!isNaN(parseInt(n)))
325 $scope.search_result_hit_count = n;
329 $scope.in_opac_call = false;
330 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
331 if ($scope.opac_iframe) {
332 if (force_opac_tab) $scope.record_tab = 'catalog';
333 $scope.in_opac_call = true;
334 $scope.opac_iframe.dom.contentWindow[opac_frame_function]();
335 if (opac_frame_function == 'rdetailBackToResults') {
336 $location.update_path('/cat/catalog/index');
341 $scope.add_cart_to_record_bucket = function() {
342 var cartkey = $cookies.get('cartcache');
343 if (!cartkey) return;
346 'open-ils.actor.anon_cache.get_value',
349 ).then(function(list) {
350 list = list.map(function(x) {
353 $scope.add_to_record_bucket(list);
357 $scope.add_to_record_bucket = function(recs) {
358 if (!angular.isArray(recs)) {
359 recs = [ $scope.record_id ];
361 return $uibModal.open({
362 templateUrl: './cat/catalog/t_add_to_bucket',
367 ['$scope','$uibModalInstance',
368 function($scope , $uibModalInstance) {
370 $scope.bucket_id = 0;
371 $scope.newBucketName = '';
372 $scope.allBuckets = [];
375 'open-ils.actor.container.retrieve_by_class.authoritative',
376 egCore.auth.token(), egCore.auth.user().id(),
377 'biblio', 'staff_client'
378 ).then(function(buckets) { $scope.allBuckets = buckets; });
380 $scope.add_to_bucket = function() {
382 angular.forEach(recs, function(recId) {
383 var item = new egCore.idl.cbrebi();
384 item.bucket($scope.bucket_id);
385 item.target_biblio_record_entry(recId);
386 promises.push(egCore.net.request(
388 'open-ils.actor.container.item.create',
389 egCore.auth.token(), 'biblio', item
392 $q.all(promises).then(function(resp) {
393 $uibModalInstance.close();
397 $scope.add_to_new_bucket = function() {
398 var bucket = new egCore.idl.cbreb();
399 bucket.owner(egCore.auth.user().id());
400 bucket.name($scope.newBucketName);
401 bucket.description('');
402 bucket.btype('staff_client');
406 'open-ils.actor.container.create',
407 egCore.auth.token(), 'biblio', bucket
408 ).then(function(bucket) {
409 $scope.bucket_id = bucket;
410 $scope.add_to_bucket();
414 $scope.cancel = function() {
415 $uibModalInstance.dismiss();
421 $scope.current_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record');
422 $scope.current_transfer_target = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
423 $scope.current_conjoined_target = egCore.hatch.getLocalItem('eg.cat.marked_conjoined_record');
425 $scope.quickReceive = function () {
427 var next_per_stream = {};
429 var recId = $scope.record_id;
430 return $uibModal.open({
431 templateUrl: './share/t_subscription_select_dialog',
433 controller: ['$scope', '$uibModalInstance',
434 function($scope, $uibModalInstance) {
437 $scope.rememberMe = 'eg.serials.quickreceive.last_org';
438 $scope.record_id = recId;
439 $scope.ssubId = null;
441 $scope.ok = function() { $uibModalInstance.close($scope.ssubId) }
442 $scope.cancel = function() { $uibModalInstance.dismiss(); }
445 }).result.then(function(ssubId) {
448 promises.push(egSerialsCoreSvc.fetchItemsForSub(ssubId,{status:'Expected'}).then(function(){
449 angular.forEach(egSerialsCoreSvc.itemTree, function (item) {
450 if (next_per_stream[item.stream().id()]) return;
451 if (item.status() == 'Expected') {
452 next_per_stream[item.stream().id()] = item;
453 list.push(egCore.idl.Clone(item));
458 return $q.all(promises).then(function() {
461 ngToast.warning(egCore.strings.SERIALS_NO_ITEMS);
465 return egSerialsCoreSvc.process_items(
471 false, // print by default
472 function() { $scope.holdings_record_id_changed($scope.record_id) }
476 ngToast.warning(egCore.strings.SERIALS_NO_SUBS);
482 $scope.markConjoined = function () {
483 $scope.current_conjoined_target = $scope.record_id;
484 egCore.hatch.setLocalItem('eg.cat.marked_conjoined_record',$scope.record_id);
485 ngToast.create(egCore.strings.MARK_CONJ_TARGET);
488 $scope.markHoldingsTransfer = function () {
489 $scope.current_transfer_target = $scope.record_id;
490 egCore.hatch.setLocalItem('eg.cat.transfer_target_record',$scope.record_id);
491 egCore.hatch.removeLocalItem('eg.cat.transfer_target_lib');
492 egCore.hatch.removeLocalItem('eg.cat.transfer_target_vol');
493 ngToast.create(egCore.strings.MARK_HOLDINGS_TARGET);
496 $scope.markOverlay = function () {
497 $scope.current_overlay_target = $scope.record_id;
498 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.record_id);
499 ngToast.create(egCore.strings.MARK_OVERLAY_TARGET);
502 $scope.clearRecordMarks = function () {
503 $scope.current_overlay_target = null;
504 $scope.current_transfer_target = null;
505 $scope.current_conjoined_target = null;
506 $scope.current_hold_transfer_dest = null;
507 egCore.hatch.removeLocalItem('eg.cat.transfer_target_record');
508 egCore.hatch.removeLocalItem('eg.cat.marked_conjoined_record');
509 egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');
510 egCore.hatch.removeLocalItem('eg.circ.hold.title_transfer_target');
513 $scope.stop_unload = false;
514 $scope.$watch('stop_unload',
515 function(newVal, oldVal) {
516 if (newVal && newVal != oldVal && $scope.opac_iframe) {
517 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
518 return 'There is unsaved data in this record.'
521 if ($scope.opac_iframe)
522 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
527 // Set the "last bib" cookie, if we have that
528 if ($scope.record_id)
529 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
531 $scope.refresh_record_callback = function (record_id) {
532 egCore.pcrud.retrieve('bre', record_id, {
535 bre : ['simple_record','creator','editor']
537 }).then(function(rec) {
538 rec.owner(egCore.org.get(rec.owner()));
539 $scope.summary_pane_record = rec;
545 patron_search_dialog = function() {
546 return $uibModal.open({
547 templateUrl: './share/t_patron_selector',
552 ['$scope','$uibModalInstance','$controller',
553 function($scope , $uibModalInstance , $controller) {
554 angular.extend(this, $controller('BasePatronSearchCtrl', {$scope : $scope}));
556 $scope.need_one_selected = function() {
557 var items = $scope.gridControls.selectedItems();
558 return (items.length == 1) ? false : true
560 $scope.ok = function() {
561 var items = $scope.gridControls.selectedItems();
562 if (items.length == 1) {
563 $uibModalInstance.close(items[0].card().barcode());
565 $uibModalInstance.close()
568 $scope.cancel = function($event) {
569 $uibModalInstance.dismiss();
570 $event.preventDefault();
576 // also set it when the iframe changes to a new record
577 $scope.handle_page = function(url) {
579 if (!url || url == 'about:blank') {
580 // nothing loaded. If we already have a record ID, leave it.
584 var prev_record_id = $scope.record_id;
585 var match = url.match(/\/+opac\/+record\/+(\d+)/);
587 $scope.record_id = match[1];
588 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
589 $scope.holdings_record_id_changed($scope.record_id);
590 conjoinedSvc.fetch($scope.record_id).then(function(){
591 $scope.conjoinedGridDataProvider.refresh();
594 $location.update_path('/cat/catalog/record/' + $scope.record_id);
595 // update_path() bypasses the controller for path
596 // /cat/catalog/record/:record_id. Manually set title here too.
597 egCore.strings.setPageTitle(
598 egCore.strings.PAGE_TITLE_BIB_DETAIL,
599 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT,
600 {record_id : $scope.record_id}
603 delete $scope.record_id;
604 $scope.from_route = false;
607 // child scope is executing this function, so our digest doesn't fire ... thus,
610 // don't change tabs if we are using the OPAC nav buttons,
611 // or we didn't change records on the OPAC load
612 if (!$scope.in_opac_call && ($scope.record_id != prev_record_id)) {
613 if ($scope.record_id) {
614 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
615 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
617 tab = $routeParams.record_tab || 'catalog';
619 $scope.set_record_tab(tab);
621 $scope.in_opac_call = false;
624 if ($scope.opac_iframe && $location.path().match(/cat\/catalog/)) {
625 var doc = $scope.opac_iframe.dom.contentWindow.document;
626 $(doc).find('#hold_usr_search').show();
627 $(doc).find('#hold_usr_search').on('click', function() {
628 patron_search_dialog().result.then(function(barc) {
629 $(doc).find('#hold_usr_input').val(barc);
630 $(doc).find('#hold_usr_input').change();
633 $(doc).find('#select_basket_action').on('change', function() {
634 if (this.options[this.selectedIndex].value && this.options[this.selectedIndex].value == "add_cart_to_bucket") {
635 $scope.add_cart_to_record_bucket();
642 // xulG catalog handlers
643 $scope.handlers = { }
645 // ------------------------------------------------------------------
648 $scope.conjoinedGridControls = {};
649 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
650 get : function(offset, count) {
651 return this.arrayNotifier(conjoinedSvc.items, offset, count);
655 $scope.changeConjoinedType = function () {
656 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
657 angular.forEach(peers, function (p) {
658 p.target_copy(p.target_copy().id());
659 p.peer_type(p.peer_type().id());
662 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
664 return $uibModal.open({
665 templateUrl: './cat/catalog/t_conjoined_selector',
669 ['$scope','$uibModalInstance',
670 function($scope , $uibModalInstance) {
671 $scope.update = true;
673 $scope.peer_type = null;
674 $scope.peer_type_list = [];
675 conjoinedSvc.get_peer_types().then(function(list){
676 $scope.peer_type_list = list;
679 $scope.ok = function(type) {
682 angular.forEach(peers, function (p) {
685 promises.push(egCore.pcrud.update(p));
688 return $q.all(promises)
689 .then(function(){$uibModalInstance.close()})
690 .then(function(){return conjoinedSvc.fetch()})
691 .then(function(){conjoinedGridDataProviderRef.refresh()});
694 $scope.cancel = function($event) {
695 $uibModalInstance.dismiss();
696 $event.preventDefault();
703 $scope.refreshConjoined = function () {
704 conjoinedSvc.fetch($scope.record_id)
705 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
708 $scope.deleteSelectedConjoined = function () {
709 var peers = $scope.conjoinedGridControls.selectedItems();
711 if (peers.length > 0) {
712 egConfirmDialog.open(
713 egCore.strings.CONFIRM_DELETE_PEERS,
714 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
715 {peers : peers.length}
716 ).result.then(function() {
717 angular.forEach(peers, function (p) {
721 egCore.pcrud.remove(peers).then(function() {
722 return conjoinedSvc.fetch();
724 $scope.conjoinedGridDataProvider.refresh();
729 if ($scope.record_id)
730 conjoinedSvc.fetch($scope.record_id);
732 // ------------------------------------------------------------------
735 $scope.holdingsGridControls = {
736 activateItem : function (item) {
737 $scope.selectedHoldingsVolCopyEdit();
740 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
741 get : function(offset, count) {
742 return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
746 $scope.add_copies_to_bucket = function() {
747 var copy_list = gatherSelectedHoldingsIds();
748 if (copy_list.length == 0) return;
750 return $uibModal.open({
751 templateUrl: './cat/catalog/t_add_to_bucket',
756 ['$scope','$uibModalInstance',
757 function($scope , $uibModalInstance) {
759 $scope.bucket_id = 0;
760 $scope.newBucketName = '';
761 $scope.allBuckets = [];
765 'open-ils.actor.container.retrieve_by_class.authoritative',
766 egCore.auth.token(), egCore.auth.user().id(),
767 'copy', 'staff_client'
768 ).then(function(buckets) { $scope.allBuckets = buckets; });
770 $scope.add_to_bucket = function() {
772 angular.forEach(copy_list, function (cp) {
773 var item = new egCore.idl.ccbi()
774 item.bucket($scope.bucket_id);
775 item.target_copy(cp);
779 'open-ils.actor.container.item.create',
780 egCore.auth.token(), 'copy', item
784 return $q.all(promises).then(function() {
785 $uibModalInstance.close();
790 $scope.add_to_new_bucket = function() {
791 var bucket = new egCore.idl.ccb();
792 bucket.owner(egCore.auth.user().id());
793 bucket.name($scope.newBucketName);
794 bucket.description('');
795 bucket.btype('staff_client');
797 return egCore.net.request(
799 'open-ils.actor.container.create',
800 egCore.auth.token(), 'copy', bucket
801 ).then(function(bucket) {
802 $scope.bucket_id = bucket;
803 $scope.add_to_bucket();
807 $scope.cancel = function() {
808 $uibModalInstance.dismiss();
814 // TODO: refactor common code between cat/catalog/app.js and cat/item/app.js
816 $scope.need_one_selected = function() {
817 var items = $scope.holdingsGridControls.selectedItems();
818 if (items.length == 1) return false;
822 $scope.make_copies_bookable = function() {
824 var copies_by_record = {};
825 var record_list = [];
827 $scope.holdingsGridControls.selectedItems(),
829 var record_id = item['call_number.record.id'];
830 if (typeof copies_by_record[ record_id ] == 'undefined') {
831 copies_by_record[ record_id ] = [];
832 record_list.push( record_id );
834 copies_by_record[ record_id ].push(item.id);
839 var combined_results = [];
840 angular.forEach(record_list, function(record_id) {
844 'open-ils.booking.resources.create_from_copies',
846 copies_by_record[record_id]
847 ).then(function(results) {
848 if (results && results['brsrc']) {
849 combined_results = combined_results.concat(results['brsrc']);
855 $q.all(promises).then(function() {
856 if (combined_results.length > 0) {
858 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
863 ['$scope','$location','egCore','$uibModalInstance',
864 function($scope , $location , egCore , $uibModalInstance) {
867 ses : egCore.auth.token(),
868 resultant_brsrc : combined_results.map(function(o) { return o[0]; })
871 var booking_path = '/eg/conify/global/booking/resource';
873 $scope.booking_admin_url =
874 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
881 $scope.book_copies_now = 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_brt = [];
898 var combined_brsrc = [];
899 angular.forEach(record_list, function(record_id) {
903 'open-ils.booking.resources.create_from_copies',
905 copies_by_record[record_id]
906 ).then(function(results) {
907 if (results && results['brt']) {
908 combined_brt = combined_brt.concat(results['brt']);
910 if (results && results['brsrc']) {
911 combined_brsrc = combined_brsrc.concat(results['brsrc']);
917 $q.all(promises).then(function() {
918 if (combined_brt.length > 0 || combined_brsrc.length > 0) {
920 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
925 ['$scope','$location','egCore','$uibModalInstance',
926 function($scope , $location , egCore , $uibModalInstance) {
929 ses : egCore.auth.token(),
930 bresv_interface_opts : {
933 ,brsrc : combined_brsrc
938 var booking_path = '/eg/booking/reservation';
940 $scope.booking_admin_url =
941 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
950 $scope.requestItems = function() {
951 var copy_list = gatherSelectedHoldingsIds();
952 if (copy_list.length == 0) return;
954 return $uibModal.open({
955 templateUrl: './cat/catalog/t_request_items',
958 ['$scope','$uibModalInstance',
959 function($scope , $uibModalInstance) {
961 $scope.first_user_fetch = true;
965 copy_list : copy_list,
966 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
967 user : egCore.auth.user().id()
970 egUser.get( $scope.hold_data.user ).then(function(u) {
972 $scope.barcode = u.card().barcode();
973 $scope.user_name = egUser.format_name(u);
974 $scope.hold_data.user = u.id();
977 $scope.user_name = '';
979 $scope.$watch('barcode', function (n) {
980 if (!$scope.first_user_fetch) {
981 egUser.getByBarcode(n).then(function(u) {
983 $scope.user_name = egUser.format_name(u);
984 $scope.hold_data.user = u.id();
987 $scope.user_name = '';
988 delete $scope.hold_data.user;
991 $scope.first_user_fetch = false;
994 $scope.ok = function(h) {
997 hold_type : h.hold_type,
998 pickup_lib: h.pickup_lib.id(),
1004 'open-ils.circ.holds.test_and_create.batch.override',
1005 egCore.auth.token(), args, h.copy_list
1008 $uibModalInstance.close();
1011 $scope.cancel = function($event) {
1012 $uibModalInstance.dismiss();
1013 $event.preventDefault();
1019 $scope.view_place_orders = function() {
1020 if (!$scope.record_id) return;
1021 var url = egCore.env.basePath + 'acq/legacy/lineitem/related/' + $scope.record_id + '?target=bib';
1022 $timeout(function() { $window.open(url, '_blank') });
1025 $scope.replaceBarcodes = function() {
1026 var copy_list = gatherSelectedRawCopies();
1027 if (copy_list.length == 0) return;
1029 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
1031 angular.forEach(copy_list, function (cp) {
1033 templateUrl: './cat/share/t_replace_barcode',
1037 ['$scope','$uibModalInstance',
1038 function($scope , $uibModalInstance) {
1039 $scope.isModal = true;
1040 $scope.focusBarcode = false;
1041 $scope.focusBarcode2 = true;
1042 $scope.barcode1 = cp.barcode();
1044 $scope.updateBarcode = function() {
1045 $scope.copyNotFound = false;
1046 $scope.updateOK = false;
1048 egCore.pcrud.search('acp',
1049 {deleted : 'f', barcode : $scope.barcode1})
1050 .then(function(copy) {
1053 $scope.focusBarcode = true;
1054 $scope.copyNotFound = true;
1058 $scope.copyId = copy.id();
1059 copy.barcode($scope.barcode2);
1061 egCore.pcrud.update(copy).then(function(stat) {
1062 $scope.updateOK = stat;
1063 $scope.focusBarcode = true;
1064 holdingsSvc.fetchAgain().then(function (){
1065 holdingsGridDataProviderRef.refresh();
1070 $uibModalInstance.close();
1073 $scope.cancel = function($event) {
1074 $uibModalInstance.dismiss();
1075 $event.preventDefault();
1083 var holdings_bChannel = null;
1084 // subscribe to BroadcastChannel for any child VolCopy tabs
1085 // refresh grid if needed to show new updates
1086 // if ($scope.record_tab === 'holdings'){
1087 $scope.$watch('record_tab', function(n){
1089 if (n === 'holdings'){
1090 if (typeof BroadcastChannel != 'undefined') {
1091 // we're in holdings tab, connect 2 bChannel
1092 holdings_bChannel = new BroadcastChannel('eg.holdings.update');
1093 holdings_bChannel.onmessage = function(e){
1096 && e.data.records.length
1097 && e.data.records.includes($scope.record_id)
1098 ){ // it's for us, refresh grid!
1099 console.log("Got broadcast from channel eg.holdings.update for records " + e.data.records);
1100 $scope.holdings_record_id_changed($scope.record_id);
1105 } else if (holdings_bChannel){ // we're leaving holding tab, close bChannel
1106 holdings_bChannel.close();
1111 // refresh the list of holdings when the record_id is changed.
1112 $scope.holdings_record_id_changed = function(id) {
1113 if ($scope.record_id != id) $scope.record_id = id;
1114 console.log('record id changed to ' + id + ', loading new holdings');
1115 holdingsSvcInst.fetch({
1116 rid : $scope.record_id,
1117 org : $scope.holdings_ou,
1118 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1119 vol : $scope.holdings_show_vols,
1120 empty: $scope.holdings_show_empty,
1121 empty_org: $scope.holdings_show_empty_org
1122 }).then(function() {
1123 $scope.holdingsGridDataProvider.refresh();
1127 // refresh the list of holdings when the filter lib is changed.
1128 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
1129 $scope.holdings_ou_changed = function(org) {
1130 $scope.holdings_ou = org;
1131 holdingsSvcInst.fetch({
1132 rid : $scope.record_id,
1133 org : $scope.holdings_ou,
1134 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1135 vol : $scope.holdings_show_vols,
1136 empty: $scope.holdings_show_empty,
1137 empty_org: $scope.holdings_show_empty_org
1138 }).then(function() {
1139 $scope.holdingsGridDataProvider.refresh();
1143 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
1144 $scope[cb] = newVal;
1145 var x = $scope.holdings_show_vols ? $scope.holdings_show_copies : false;
1146 $('#holdings_show_copies').prop('checked', x);
1147 egCore.hatch.setItem('cat.' + cb, newVal);
1148 if (!norefresh) holdingsSvcInst.fetch({
1149 rid : $scope.record_id,
1150 org : $scope.holdings_ou,
1151 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1152 vol : $scope.holdings_show_vols,
1153 empty: $scope.holdings_show_empty,
1154 empty_org: $scope.holdings_show_empty_org
1155 }).then(function() {
1156 $scope.holdingsGridDataProvider.refresh();
1160 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
1161 if (typeof x == 'undefined') x = true;
1162 $scope.holdings_cb_changed('holdings_show_vols',x,true);
1163 $('#holdings_show_vols').prop('checked', x);
1165 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
1166 if (typeof x == 'undefined') x = true;
1167 $scope.holdings_cb_changed('holdings_show_copies',x,true);
1168 x = $scope.holdings_show_vols ? x : false;
1169 $('#holdings_show_copies').prop('checked', x);
1171 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
1172 if (typeof x == 'undefined') x = true;
1173 $scope.holdings_cb_changed('holdings_show_empty',x);
1174 $('#holdings_show_empty').prop('checked', x);
1176 egCore.hatch.getItem('cat.holdings_show_empty_org').then(function(x){
1177 if (typeof x == 'undefined') x = true;
1178 $scope.holdings_cb_changed('holdings_show_empty_org',x);
1179 $('#holdings_show_empty_org').prop('checked', x);
1185 $scope.vols_not_shown = function () {
1186 return !$scope.holdings_show_vols;
1189 $scope.copies_not_shown = function () {
1190 return !$scope.holdings_show_copies;
1193 $scope.empty_org_not_shown = function () {
1194 return !$scope.holdings_show_empty_org;
1197 $scope.holdings_checkbox_handler = function (item) {
1198 $scope.holdings_cb_changed(item.checkbox,item.checked);
1201 function gatherSelectedHoldingsIds () {
1202 var cp_id_list = [];
1204 $scope.holdingsGridControls.selectedItems(),
1205 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
1210 function gatherSelectedRawCopies () {
1213 $scope.holdingsGridControls.selectedItems(),
1214 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
1219 function gatherSelectedEmptyVolumeIds () {
1220 var cn_id_list = [];
1222 $scope.holdingsGridControls.selectedItems(),
1224 if (item.copy_count == 0 || (!item.id && item.call_number))
1225 // we are in a compressed row with no copies, or we are in a single
1226 // call number row with no copy (testing for presence of 'id')
1227 // In either case, the call number is 'empty'
1228 cn_id_list.push(item.call_number.id)
1234 function gatherSelectedVolumeIds () {
1235 var cn_id_list = [];
1237 $scope.holdingsGridControls.selectedItems(),
1239 if (cn_id_list.indexOf(item.call_number.id) == -1)
1240 cn_id_list.push(item.call_number.id)
1246 $scope.selectedHoldingsDelete = function (vols, copies) {
1249 var perCnCopies = {};
1255 $scope.holdingsGridControls.selectedItems(),
1257 if (vols && item.raw_call_number) {
1258 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
1259 cnHash[item.call_number.id].isdeleted(1);
1261 } else if (copies) {
1262 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
1265 var cn_id = cp.call_number().id();
1266 if (!cnHash[cn_id]) {
1267 cnHash[cn_id] = cp.call_number();
1268 perCnCopies[cn_id] = [cp];
1270 perCnCopies[cn_id].push(cp);
1272 cp.call_number(cn_id); // prevent loops in JSON-ification
1279 angular.forEach(perCnCopies, function (v, k) {
1281 cnHash[k].isdeleted(1);
1284 cnHash[k].copies(v);
1288 angular.forEach(cnHash, function (v, k) {
1292 if (cnList.length == 0) return;
1295 if (vols && copies) flags.force_delete_copies = 1;
1297 egConfirmDialog.open(
1298 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
1299 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
1300 {copies : cp_count, volumes : cn_count}
1301 ).result.then(function() {
1304 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1305 egCore.auth.token(), cnList, 1, flags
1306 ).then(function(update_count) {
1307 holdingsSvcInst.fetchAgain().then(function() {
1308 $scope.holdingsGridDataProvider.refresh();
1313 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
1314 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
1315 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
1317 spawnHoldingsAdd = function (add_vols,add_copies){
1319 if (!add_vols && add_copies) { // just a copy on existing volumes
1320 angular.forEach(gatherSelectedVolumeIds(), function (v) {
1321 raw.push( {callnumber : v} );
1323 } else if (add_vols) {
1324 if (typeof $scope.holdingsGridControls.selectedItems == "function" &&
1325 $scope.holdingsGridControls.selectedItems().length > 0) {
1326 angular.forEach($scope.holdingsGridControls.selectedItems(),
1329 owner : item.owner_id,
1330 label : ((item.call_number) ? item.call_number.label : null)
1335 owner : egCore.auth.user().ws_ou()
1340 if (raw.length == 0) raw.push({});
1344 'open-ils.actor.anon_cache.set_value',
1345 null, 'edit-these-copies', {
1346 record_id: $scope.record_id,
1349 hide_copies : !add_copies
1351 ).then(function(key) {
1353 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1354 $timeout(function() { $window.open(url, '_blank') });
1356 alert('Could not create anonymous cache key!');
1360 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,true) }
1361 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
1362 $scope.selectedHoldingsVolAdd = function () { spawnHoldingsAdd(true,false) }
1364 spawnHoldingsEdit = function (hide_vols,hide_copies){
1367 'open-ils.actor.anon_cache.set_value',
1368 null, 'edit-these-copies', {
1369 record_id: $scope.record_id,
1370 copies: gatherSelectedHoldingsIds(),
1371 raw: gatherSelectedEmptyVolumeIds().map(
1372 function(v){ return { callnumber : v } }
1374 hide_vols : hide_vols,
1375 hide_copies : hide_copies
1377 ).then(function(key) {
1379 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1380 $timeout(function() { $window.open(url, '_blank') });
1382 alert('Could not create anonymous cache key!');
1386 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
1387 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
1388 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
1390 $scope.selectedHoldingsItemStatus = function (){
1391 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
1392 $timeout(function() { $window.open(url, '_blank') });
1395 $scope.markFromSelectedAsHoldingsTarget = function() {
1396 egCore.hatch.setLocalItem(
1397 'eg.cat.transfer_target_lib',
1398 $scope.holdingsGridControls.selectedItems()[0].owner_id
1400 egCore.hatch.setLocalItem(
1401 'eg.cat.transfer_target_record',
1404 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed, or we are on an empty lib
1405 egCore.hatch.setLocalItem(
1406 'eg.cat.transfer_target_vol',
1407 $scope.holdingsGridControls.selectedItems()[0].call_number.id
1410 // clear out the stale value if we're on a lib-only
1411 // or vol-collapsed row
1412 egCore.hatch.removeLocalItem('eg.cat.transfer_target_vol');
1414 ngToast.create(egCore.strings.MARK_HOLDINGS_TARGET);
1417 $scope.selectedHoldingsItemStatusDetail = function (){
1419 gatherSelectedHoldingsIds(),
1421 var url = egCore.env.basePath +
1423 $timeout(function() { $window.open(url, '_blank') });
1428 $scope.transferVolumes = function (){
1429 var target_record = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
1430 var target_lib = egCore.hatch.getLocalItem('eg.cat.transfer_target_lib');
1432 && (!target_record || ($scope.record_id == target_record) )
1435 var vols_to_move = {};
1437 // we're moving volumes to a different library
1438 var vol_ids = gatherSelectedVolumeIds();
1439 if (vol_ids.length) {
1440 vols_to_move[target_lib] = vol_ids;
1442 // if we're *only* switching libs,
1443 // grab the current record as the target
1444 target_record = target_record || $scope.record_id;
1447 // we're moving volumes to the same library they exist in
1448 // currently, but on a different record
1449 var items = $scope.holdingsGridControls.selectedItems();
1450 angular.forEach(items, function(item) {
1451 if (!(item.call_number.owning_lib in vols_to_move)) {
1452 vols_to_move[item.call_number.owning_lib] = new Array;
1454 vols_to_move[item.call_number.owning_lib].push(item.call_number.id);
1459 angular.forEach(vols_to_move, function(vols, owning_lib) {
1460 promises.push(egCore.net.request(
1462 'open-ils.cat.asset.volume.batch.transfer.override',
1463 egCore.auth.token(), {
1464 docid : target_record,
1470 $q.all(promises).then(function(success) {
1472 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1473 holdingsSvcInst.fetchAgain().then(function() {
1474 $scope.holdingsGridDataProvider.refresh();
1477 alert('Could not transfer volumes!');
1482 // this "transfers" selected copies to a new owning library,
1483 // auto-creating volumes as required
1484 $scope.transferItemsAutoFill = function() {
1485 var target_record = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
1486 var target_lib = egCore.hatch.getLocalItem('eg.cat.transfer_target_lib');
1488 && (!target_record || ($scope.record_id == target_record) )
1491 var items = $scope.holdingsGridControls.selectedItems();
1492 if (!items.length) {
1496 var vols_to_move = {};
1497 var copies_to_move = {};
1498 angular.forEach(items, function(item) {
1499 var needs_move = false;
1501 && (item.call_number.owning_lib != target_lib)) {
1502 item.call_number.owning_lib = target_lib;
1506 && (item.call_number.record != target_record)) {
1507 item.call_number.record = target_record;
1511 if (item.call_number.id in vols_to_move) {
1512 copies_to_move[item.call_number.id].push(item.id);
1514 vols_to_move[item.call_number.id] = item.call_number;
1515 copies_to_move[item.call_number.id] = new Array;
1516 copies_to_move[item.call_number.id].push(item.id);
1522 angular.forEach(vols_to_move, function(vol) {
1523 promises.push(egCore.net.request(
1525 'open-ils.cat.call_number.find_or_create',
1526 egCore.auth.token(),
1528 vol.record, // may be new
1529 vol.owning_lib, // may be new
1533 ).then(function(resp) {
1534 var evt = egCore.evt.parse(resp);
1536 return egCore.net.request(
1538 'open-ils.cat.transfer_copies_to_volume',
1539 egCore.auth.token(),
1541 copies_to_move[vol.id]
1545 $q.all(promises).then(function() {
1546 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1547 holdingsSvcInst.fetchAgain().then(function() {
1548 $scope.holdingsGridDataProvider.refresh();
1553 $scope.gridCellHandlers = {};
1554 $scope.gridCellHandlers.copyAlertsEdit = function(id) {
1555 egCirc.manage_copy_alerts([id]).then(function() {
1556 // update grid items?
1560 $scope.transferItems = function (){
1561 var xfer_target = egCore.hatch.getLocalItem('eg.cat.transfer_target_vol');
1564 // we have no specific volume, let's try to fill in the
1566 return $scope.transferItemsAutoFill();
1569 var copy_ids = gatherSelectedHoldingsIds();
1570 if (copy_ids.length > 0) {
1573 'open-ils.cat.transfer_copies_to_volume',
1574 egCore.auth.token(),
1578 function(resp) { // oncomplete
1579 var evt = egCore.evt.parse(resp);
1581 egConfirmDialog.open(
1582 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1583 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1584 {'evt_desc': evt.desc}
1585 ).result.then(function() {
1588 'open-ils.cat.transfer_copies_to_volume.override',
1589 egCore.auth.token(),
1592 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1593 ).then(function(resp) {
1594 holdingsSvcInst.fetchAgain().then(function() {
1595 $scope.holdingsGridDataProvider.refresh();
1600 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1601 holdingsSvcInst.fetchAgain().then(function() {
1602 $scope.holdingsGridDataProvider.refresh();
1612 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1614 gatherSelectedHoldingsIds(),
1616 var url = egCore.env.basePath +
1617 'cat/item/' + cid + '/triggered_events';
1618 $timeout(function() { $window.open(url, '_blank') });
1623 $scope.selectedHoldingsItemStatusHolds = function (){
1625 gatherSelectedHoldingsIds(),
1627 var url = egCore.env.basePath +
1628 'cat/item/' + cid + '/holds';
1629 $timeout(function() { $window.open(url, '_blank') });
1634 $scope.selectedHoldingsPrintLabels = function() {
1637 'open-ils.actor.anon_cache.set_value',
1638 null, 'print-labels-these-copies', {
1639 copies : gatherSelectedHoldingsIds()
1641 ).then(function(key) {
1643 var url = egCore.env.basePath + 'cat/printlabels/' + key;
1644 $timeout(function() { $window.open(url, '_blank') });
1646 alert('Could not create anonymous cache key!');
1651 $scope.selectedHoldingsDamaged = function () {
1652 var copy_list = gatherSelectedRawCopies();
1653 if (copy_list.length == 0) return;
1655 angular.forEach(copy_list, function(cp) {
1656 egCirc.mark_damaged({
1658 barcode: cp.barcode(),
1659 circ_lib: cp.circ_lib().id()
1660 }).then(function() {
1661 holdingsSvcInst.fetchAgain().then(function() {
1662 $scope.holdingsGridDataProvider.refresh();
1668 $scope.selectedHoldingsMissing = function () {
1669 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1670 holdingsSvcInst.fetchAgain().then(function() {
1671 $scope.holdingsGridDataProvider.refresh();
1676 $scope.selectedHoldingsCopyAlertsAdd = function() {
1677 egCirc.add_copy_alerts(gatherSelectedHoldingsIds()).then(function() {
1678 // no need to refresh grid
1681 $scope.selectedHoldingsCopyAlertsManage = function() {
1682 egCirc.manage_copy_alerts(gatherSelectedHoldingsIds()).then(function() {
1683 // no need to refresh grid
1687 $scope.attach_to_peer_bib = function() {
1688 var copy_list = gatherSelectedHoldingsIds();
1689 if (copy_list.length == 0) return;
1691 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1692 if (!target_record) return;
1694 return $uibModal.open({
1695 templateUrl: './cat/catalog/t_conjoined_selector',
1699 ['$scope','$uibModalInstance',
1700 function($scope , $uibModalInstance) {
1701 $scope.update = false;
1703 $scope.peer_type = null;
1704 $scope.peer_type_list = [];
1705 conjoinedSvc.get_peer_types().then(function(list){
1706 $scope.peer_type_list = list;
1709 $scope.ok = function(type) {
1712 angular.forEach(copy_list, function (cp) {
1713 var n = new egCore.idl.bpbcm();
1715 n.peer_record(target_record);
1718 promises.push(egCore.pcrud.create(n));
1721 return $q.all(promises).then(function(){$uibModalInstance.close()});
1724 $scope.cancel = function($event) {
1725 $uibModalInstance.dismiss();
1726 $event.preventDefault();
1734 // ------------------------------------------------------------------
1736 var provider = egGridDataProvider.instance({});
1737 $scope.hold_grid_data_provider = provider;
1738 $scope.grid_actions = egHoldGridActions;
1739 $scope.grid_actions.refresh = function () { holds = []; hold_count = 0; provider.refresh() };
1740 $scope.hold_grid_controls = {};
1742 var holds = []; // current list of holds
1744 provider.get = function(offset, count) {
1745 if ($scope.record_tab != 'holds') return $q.when();
1747 // see if we have the requested range cached
1748 if (holds[offset]) {
1749 return provider.arrayNotifier(holds, offset, count);
1754 var restrictions = {
1755 is_staff_request : 'true',
1756 fulfillment_time : null,
1758 record_id : $scope.record_id,
1759 pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)
1762 var order_by = [{ request_time : null }];
1763 if (provider.sort && provider.sort.length) {
1765 angular.forEach(provider.sort, function (c) {
1766 if (!angular.isObject(c)) {
1767 if (c.match(/^hold\./)) {
1768 var i = c.replace('hold.','');
1774 var i = Object.keys(c)[0];
1775 var direction = c[i];
1776 if (i.match(/^hold\./)) {
1777 i = i.replace('hold.','');
1779 ob[i] = {dir:direction};
1786 egProgressDialog.open({max : 1, value : 0});
1788 return egHolds.fetch_wide_holds(
1791 ).then(function () {
1792 return provider.arrayNotifier(holds, offset, count);
1795 function(hold_data) {
1797 hold_count = hold_data;
1799 egProgressDialog.update({max:hold_count});
1801 egProgressDialog.increment();
1802 var new_item = { id : hold_data.id, hold : hold_data };
1803 new_item.status_string =
1804 egCore.strings['HOLD_STATUS_' + hold_data.hold_status]
1805 || hold_data.hold_status;
1807 holds.push(new_item);
1810 ).finally(egProgressDialog.close);
1814 $scope.detail_view = function(action, user_data, items) {
1816 $scope.detail_hold_id = h.hold.id;
1820 $scope.list_view = function(items) {
1821 $scope.detail_hold_id = null;
1824 // refresh the list of record holds when the pickup lib is changed.
1825 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1826 $scope.pickup_ou_changed = function(org) {
1827 $scope.pickup_ou = org;
1833 function map_prefix_to_subhash (h,pf) {
1835 angular.forEach(Object.keys(h), function (k) {
1836 if (k.startsWith(pf)) {
1837 var nk = k.substr(pf.length);
1844 $scope.print_holds = function() {
1846 angular.forEach(holds, function(item) {
1849 status_string : item.status_string,
1850 patron_first : item.hold.usr_first_given_name,
1851 patron_last : item.hold.usr_family_name,
1852 patron_alias : item.hold.usr_alias,
1853 patron_barcode : item.hold.ucard_barcode,
1854 copy : map_prefix_to_subhash(item.hold,'cp_'),
1855 volume : map_prefix_to_subhash(item.hold,'cn_'),
1856 title : item.hold.title,
1857 author : item.hold.author
1861 egCore.print.print({
1862 context : 'receipt',
1863 template : 'holds_for_bib',
1864 scope : {holds : pholds}
1868 $scope.current_hold_transfer_dest = egCore.hatch.getLocalItem ('eg.circ.hold.title_transfer_target');
1870 $scope.mark_hold_transfer_dest = function() {
1871 $scope.current_hold_transfer_dest = $scope.record_id;
1872 egCore.hatch.setLocalItem(
1873 'eg.circ.hold.title_transfer_target', $scope.record_id);
1874 ngToast.create(egCore.strings.HOLD_TRANSFER_DEST_MARKED);
1877 // UI presents this option as "all holds"
1878 $scope.transfer_holds_to_marked = function() {
1879 var hold_ids = $scope.hold_grid_controls.allItems().map(
1880 function(hold_data) {return hold_data.hold.id});
1881 egHolds.transfer_to_marked_title(hold_ids);
1884 // ------------------------------------------------------------------
1885 // Initialize the selected tab
1887 // we explicitly initialize catalog_url because otherwise Firefox
1888 // ends up setting it to $BASE_URL/{{url}}, which then messes
1889 // things up. See LP#1708951
1890 $scope.catalog_url = '';
1892 function init_cat_url() {
1893 // Set the initial catalog URL. This only happens once.
1894 // The URL is otherwise generated through user navigation.
1895 if ($scope.catalog_url) return;
1897 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1899 // A record ID in the path indicates a request for the record-
1901 if ($routeParams.record_id) {
1902 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1905 // Jumping directly to the results page by passing a search
1906 // query via the URL. Copy all URL params to the iframe url.
1907 if ($location.path().match(/catalog\/results/)) {
1908 url = url.replace(/advanced/, '/results?');
1910 angular.forEach($location.search(), function(val, key) {
1911 if (!first) url += '&';
1913 url += encodeURIComponent(key)
1914 + '=' + encodeURIComponent(val);
1918 // if we're displaying the advanced search form, select
1919 // whatever default pane the user has chosen via workstation
1921 if (url.match(/\/opac\/advanced$/)) {
1922 var adv_pane = egCore.hatch.getLocalItem('eg.search.adv_pane');
1924 url += '?pane=' + encodeURIComponent(adv_pane);
1928 $scope.catalog_url = url;
1931 function init_parts_url() {
1932 $scope.parts_url = $location
1936 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1940 $scope.set_record_tab = function(tab) {
1941 $scope.record_tab = tab;
1954 $scope.detail_hold_record_id = $scope.record_id;
1955 // refresh the holds grid
1962 $scope.set_default_record_tab = function() {
1963 egCore.hatch.setLocalItem(
1964 'eg.cat.default_record_tab', $scope.record_tab);
1965 $timeout(function(){$scope.default_tab = $scope.record_tab});
1969 if ($scope.record_id) {
1970 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1971 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1974 tab = $routeParams.record_tab || 'catalog';
1976 $scope.set_record_tab(tab);
1980 .controller('AuthorityCtrl',
1981 ['$scope','$routeParams','$location','$window','$q','egCore',
1982 function($scope , $routeParams , $location , $window , $q , egCore) {
1984 // set record ID on page load if available...
1985 $scope.authority_id = $routeParams.authority_id;
1987 if ($routeParams.authority_id) $scope.from_route = true;
1988 else $scope.from_route = false;
1990 $scope.stop_unload = false;
1993 .controller('URLVerifyCtrl',
1994 ['$scope','$location',
1995 function($scope , $location) {
1996 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1999 .controller('VandelayCtrl',
2000 ['$scope','$location', 'egCore', '$uibModal',
2001 function($scope , $location, egCore, $uibModal) {
2002 $scope.vandelay_url = $location.absUrl().replace(/\/staff\/cat\/catalog\/vandelay/, '/vandelay/vandelay');
2004 $scope.funcs.edit_marc_modal = function(bre, callback){
2005 var marcArgs = { 'marc_xml': bre.marc() };
2006 var vqbibrecId = bre.id();
2008 templateUrl: './cat/catalog/t_edit_marc_modal',
2011 controller: ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
2012 $scope.focusMe = true;
2013 $scope.recordId = vqbibrecId;
2014 $scope.args = marcArgs;
2015 $scope.dirty_flag = false;
2016 $scope.ok = function(marg){
2017 $uibModalInstance.close(marg);
2019 $scope.cancel = function(){ $uibModalInstance.dismiss() }
2021 }).result.then(function(res){
2022 var new_xml = res.marc_xml;
2023 egCore.pcrud.retrieve('vqbr', vqbibrecId).then(function(vqbib){
2024 vqbib.marc(new_xml);
2025 egCore.pcrud.update(vqbib).then( function(){ callback(vqbibrecId); });
2031 .controller('ManageAuthoritiesCtrl',
2032 ['$scope','$location',
2033 function($scope , $location) {
2034 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
2037 .controller('BatchEditCtrl',
2038 ['$scope','$location','$routeParams',
2039 function($scope , $location , $routeParams) {
2040 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
2041 if ($routeParams.container_type) {
2042 switch ($routeParams.container_type) {
2044 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
2047 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
2054 .filter('boolText', function(){
2055 return function (v) {
2060 .factory('conjoinedSvc',
2062 function(egCore , $q) {
2065 items : [], // record search results
2066 index : 0, // search grid index
2073 bpbcm : ['target_copy','peer_type'],
2074 acp : ['call_number'],
2076 bre : ['simple_record']
2078 // avoid fetching the MARC blob by specifying which
2079 // fields on the bre to select. More may be needed.
2080 // note that fleshed fields are explicitly selected.
2081 select : { bre : ['id'] },
2082 order_by : { bpbcm : ['id'] },
2085 // resolved with the last received copy
2086 service.fetch = function(rid) {
2087 if (!rid && !service.rid) return $q.when();
2089 if (rid) service.rid = rid;
2093 return egCore.pcrud.search(
2095 {peer_record : service.rid},
2098 ).then( function(list) { // finished
2099 service.items = list;
2100 return service.items;
2104 // returns a promise resolved with the list of peer bib types
2105 service.get_peer_types = function() {
2107 return $q.when(egCore.env.bpt.list);
2109 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
2110 .then(function(list) {
2111 egCore.env.absorbList(list, 'bpt');