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?|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/new_bib', {
65 templateUrl: './cat/catalog/t_new_bib',
66 controller: 'NewBibCtrl',
70 // create some catalog page-specific mappings
71 $routeProvider.when('/cat/catalog/record/:record_id', {
72 templateUrl: './cat/catalog/t_catalog',
73 controller: 'CatalogCtrl',
77 // create some catalog page-specific mappings
78 $routeProvider.when('/cat/catalog/record/:record_id/:record_tab', {
79 templateUrl: './cat/catalog/t_catalog',
80 controller: 'CatalogCtrl',
84 $routeProvider.when('/cat/catalog/batchEdit', {
85 templateUrl: './cat/catalog/t_batchedit',
86 controller: 'BatchEditCtrl',
90 $routeProvider.when('/cat/catalog/batchEdit/:container_type/:container_id', {
91 templateUrl: './cat/catalog/t_batchedit',
92 controller: 'BatchEditCtrl',
96 $routeProvider.when('/cat/catalog/vandelay', {
97 templateUrl: './cat/catalog/t_vandelay',
98 controller: 'VandelayCtrl',
102 $routeProvider.when('/cat/catalog/verifyURLs', {
103 templateUrl: './cat/catalog/t_verifyurls',
104 controller: 'URLVerifyCtrl',
108 $routeProvider.when('/cat/catalog/manageAuthorities', {
109 templateUrl: './cat/catalog/t_manageauthorities',
110 controller: 'ManageAuthoritiesCtrl',
114 $routeProvider.when('/cat/catalog/authority/:authority_id/marc_edit', {
115 templateUrl: './cat/catalog/t_authority',
116 controller: 'AuthorityCtrl',
120 $routeProvider.otherwise({redirectTo : '/cat/catalog/index'});
126 .controller('CatalogRecordRetrieve',
127 ['$scope','$routeParams','$location','$q','egCore',
128 function($scope , $routeParams , $location , $q , egCore ) {
130 $scope.focusMe = true;
132 // jump to the patron checkout UI
133 function loadRecord(record_id) {
135 .path('/cat/catalog/record/' + record_id);
138 $scope.submitId = function(args) {
139 $scope.recordNotFound = null;
140 if (!args.record_id) return;
142 // blur so next time it's set to true it will re-apply select()
143 $scope.selectMe = false;
145 return loadRecord(args.record_id);
148 $scope.submitTCN = function(args) {
149 $scope.recordNotFound = null;
150 $scope.moreRecordsFound = null;
151 if (!args.record_tcn) return;
153 // blur so next time it's set to true it will re-apply select()
154 $scope.selectMe = false;
159 'open-ils.search.biblio.tcn',
162 .then(function(resp) { // get_barcodes
164 if (evt = egCore.evt.parse(resp)) {
170 $scope.recordNotFound = args.record_tcn;
171 $scope.selectMe = true;
175 if (resp.count > 1) {
176 $scope.moreRecordsFound = args.record_tcn;
177 $scope.selectMe = true;
181 var record_id = resp.ids[0];
182 return loadRecord(record_id);
188 .controller('NewBibCtrl',
189 ['$scope','$routeParams','$location','$window','$q','egCore',
190 'egGridDataProvider','egHoldGridActions','$timeout','holdingsSvc',
191 function($scope , $routeParams , $location , $window , $q , egCore) {
193 $scope.have_template = false;
194 $scope.marc_template = '';
195 $scope.stop_unload = false;
196 $scope.template_list = [];
197 $scope.template_name = '';
198 $scope.new_bib_id = 0;
202 'open-ils.cat.marc_template.types.retrieve'
203 ).then(function(resp) {
204 angular.forEach(resp, function(name) {
205 $scope.template_list.push(name);
207 $scope.template_list.sort();
209 $scope.template_name = egCore.hatch.getSessionItem('eg.cat.last_bib_marc_template');
210 if (!$scope.template_name) {
211 egCore.hatch.getItem('cat.default_bib_marc_template').then(function(template) {
212 $scope.template_name = template;
216 $scope.loadTemplate = function() {
217 if ($scope.template_name) {
220 'open-ils.cat.biblio.marc_template.retrieve',
222 ).then(function(template) {
223 $scope.marc_template = template;
224 $scope.have_template = true;
225 egCore.hatch.setSessionItem('eg.cat.last_bib_marc_template', $scope.template_name);
230 $scope.setDefaultTemplate = function() {
231 var hatch_key = "cat.default_bib_marc_template";
232 if ($scope.template_name) {
233 egCore.hatch.setItem(hatch_key, $scope.template_name);
235 egCore.hatch.removeItem(hatch_key);
239 $scope.$watch('new_bib_id', function(newVal, oldVal) {
241 $location.path('/cat/catalog/record/' + $scope.new_bib_id);
247 .controller('CatalogCtrl',
248 ['$scope','$routeParams','$location','$window','$q','egCore','egHolds','egCirc','egConfirmDialog','ngToast',
249 'egGridDataProvider','egHoldGridActions','egProgressDialog','$timeout','$uibModal','holdingsSvc','egUser','conjoinedSvc',
250 '$cookies','egSerialsCoreSvc',
251 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc , egConfirmDialog , ngToast ,
252 egGridDataProvider , egHoldGridActions , egProgressDialog , $timeout , $uibModal , holdingsSvc , egUser , conjoinedSvc,
253 $cookies , egSerialsCoreSvc
256 var holdingsSvcInst = new holdingsSvc();
258 // set record ID on page load if available...
259 $scope.record_id = $routeParams.record_id;
260 $scope.summary_pane_record;
262 if ($routeParams.record_id) $scope.from_route = true;
263 else $scope.from_route = false;
265 // set search and preferred library cookies
266 egCore.hatch.getItem('eg.search.search_lib').then(function(val) {
267 $cookies.put('eg_search_lib', val, { path : '/' });
269 egCore.hatch.getItem('eg.search.pref_lib').then(function(val) {
270 $cookies.put('eg_pref_lib', val, { path : '/' });
273 // will hold a ref to the opac iframe
274 $scope.opac_iframe = null;
275 $scope.parts_iframe = null;
277 $scope.search_result_index = 1;
278 $scope.search_result_hit_count = 1;
281 'opac_iframe.dom.contentWindow.search_result_index',
283 if (!isNaN(parseInt(n)))
284 $scope.search_result_index = n + 1;
289 'opac_iframe.dom.contentWindow.search_result_hit_count',
291 if (!isNaN(parseInt(n)))
292 $scope.search_result_hit_count = n;
296 $scope.in_opac_call = false;
297 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
298 if ($scope.opac_iframe) {
299 if (force_opac_tab) $scope.record_tab = 'catalog';
300 $scope.in_opac_call = true;
301 $scope.opac_iframe.dom.contentWindow[opac_frame_function]();
302 if (opac_frame_function == 'rdetailBackToResults') {
303 $location.update_path('/cat/catalog/index');
308 $scope.add_to_record_bucket = function() {
309 var recId = $scope.record_id;
310 return $uibModal.open({
311 templateUrl: './cat/catalog/t_add_to_bucket',
315 ['$scope','$uibModalInstance',
316 function($scope , $uibModalInstance) {
318 $scope.bucket_id = 0;
319 $scope.newBucketName = '';
320 $scope.allBuckets = [];
323 'open-ils.actor.container.retrieve_by_class.authoritative',
324 egCore.auth.token(), egCore.auth.user().id(),
325 'biblio', 'staff_client'
326 ).then(function(buckets) { $scope.allBuckets = buckets; });
328 $scope.add_to_bucket = function() {
329 var item = new egCore.idl.cbrebi();
330 item.bucket($scope.bucket_id);
331 item.target_biblio_record_entry(recId);
334 'open-ils.actor.container.item.create',
335 egCore.auth.token(), 'biblio', item
336 ).then(function(resp) {
337 $uibModalInstance.close();
341 $scope.add_to_new_bucket = function() {
342 var bucket = new egCore.idl.cbreb();
343 bucket.owner(egCore.auth.user().id());
344 bucket.name($scope.newBucketName);
345 bucket.description('');
346 bucket.btype('staff_client');
350 'open-ils.actor.container.create',
351 egCore.auth.token(), 'biblio', bucket
352 ).then(function(bucket) {
353 $scope.bucket_id = bucket;
354 $scope.add_to_bucket();
358 $scope.cancel = function() {
359 $uibModalInstance.dismiss();
365 $scope.current_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record');
366 $scope.current_voltransfer_target = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
367 $scope.current_conjoined_target = egCore.hatch.getLocalItem('eg.cat.marked_conjoined_record');
369 $scope.quickReceive = function () {
371 var next_per_stream = {};
373 var recId = $scope.record_id;
374 return $uibModal.open({
375 templateUrl: './share/t_subscription_select_dialog',
376 controller: ['$scope', '$uibModalInstance',
377 function($scope, $uibModalInstance) {
380 $scope.rememberMe = 'eg.serials.quickreceive.last_org';
381 $scope.record_id = recId;
382 $scope.ssubId = null;
384 $scope.ok = function() { $uibModalInstance.close($scope.ssubId) }
385 $scope.cancel = function() { $uibModalInstance.dismiss(); }
388 }).result.then(function(ssubId) {
391 promises.push(egSerialsCoreSvc.fetchItemsForSub(ssubId,{status:'Expected'}).then(function(){
392 angular.forEach(egSerialsCoreSvc.itemTree, function (item) {
393 if (next_per_stream[item.stream().id()]) return;
394 if (item.status() == 'Expected') {
395 next_per_stream[item.stream().id()] = item;
396 list.push(egCore.idl.Clone(item));
401 return $q.all(promises).then(function() {
404 ngToast.warning(egCore.strings.SERIALS_NO_ITEMS);
408 return egSerialsCoreSvc.process_items(
414 false, // print by default
415 function() { $scope.holdings_record_id_changed($scope.record_id) }
419 ngToast.warning(egCore.strings.SERIALS_NO_SUBS);
425 $scope.markConjoined = function () {
426 $scope.current_conjoined_target = $scope.record_id;
427 egCore.hatch.setLocalItem('eg.cat.marked_conjoined_record',$scope.record_id);
428 ngToast.create(egCore.strings.MARK_CONJ_TARGET);
431 $scope.markVolTransfer = function () {
432 ngToast.create(egCore.strings.MARK_VOL_TARGET);
433 $scope.current_voltransfer_target = $scope.record_id;
434 egCore.hatch.setLocalItem('eg.cat.marked_volume_transfer_record',$scope.record_id);
437 $scope.markOverlay = function () {
438 $scope.current_overlay_target = $scope.record_id;
439 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.record_id);
440 ngToast.create(egCore.strings.MARK_OVERLAY_TARGET);
443 $scope.clearRecordMarks = function () {
444 $scope.current_overlay_target = null;
445 $scope.current_voltransfer_target = null;
446 $scope.current_conjoined_target = null;
447 $scope.current_hold_transfer_dest = null;
448 egCore.hatch.removeLocalItem('eg.cat.marked_volume_transfer_record');
449 egCore.hatch.removeLocalItem('eg.cat.marked_conjoined_record');
450 egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');
451 egCore.hatch.removeLocalItem('eg.circ.hold.title_transfer_target');
454 $scope.stop_unload = false;
455 $scope.$watch('stop_unload',
456 function(newVal, oldVal) {
457 if (newVal && newVal != oldVal && $scope.opac_iframe) {
458 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
459 return 'There is unsaved data in this record.'
462 if ($scope.opac_iframe)
463 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
468 // Set the "last bib" cookie, if we have that
469 if ($scope.record_id)
470 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
472 $scope.refresh_record_callback = function (record_id) {
473 egCore.pcrud.retrieve('bre', record_id, {
476 bre : ['simple_record','creator','editor']
478 }).then(function(rec) {
479 rec.owner(egCore.org.get(rec.owner()));
480 $scope.summary_pane_record = rec;
486 patron_search_dialog = function() {
487 return $uibModal.open({
488 templateUrl: './share/t_patron_selector',
492 ['$scope','$uibModalInstance','$controller',
493 function($scope , $uibModalInstance , $controller) {
494 angular.extend(this, $controller('BasePatronSearchCtrl', {$scope : $scope}));
496 $scope.need_one_selected = function() {
497 var items = $scope.gridControls.selectedItems();
498 return (items.length == 1) ? false : true
500 $scope.ok = function() {
501 var items = $scope.gridControls.selectedItems();
502 if (items.length == 1) {
503 $uibModalInstance.close(items[0].card().barcode());
505 $uibModalInstance.close()
508 $scope.cancel = function($event) {
509 $uibModalInstance.dismiss();
510 $event.preventDefault();
516 // also set it when the iframe changes to a new record
517 $scope.handle_page = function(url) {
519 if (!url || url == 'about:blank') {
520 // nothing loaded. If we already have a record ID, leave it.
524 var match = url.match(/\/+opac\/+record\/+(\d+)/);
526 $scope.record_id = match[1];
527 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
528 $scope.holdings_record_id_changed($scope.record_id);
529 conjoinedSvc.fetch($scope.record_id).then(function(){
530 $scope.conjoinedGridDataProvider.refresh();
532 egHolds.fetch_holds(hold_ids).then($scope.hold_grid_data_provider.refresh);
534 $location.update_path('/cat/catalog/record/' + $scope.record_id);
536 delete $scope.record_id;
537 $scope.from_route = false;
540 // child scope is executing this function, so our digest doesn't fire ... thus,
543 if (!$scope.in_opac_call) {
544 if ($scope.record_id && !$scope.record_tab) {
545 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
546 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
548 tab = $routeParams.record_tab || 'catalog';
550 $scope.set_record_tab(tab);
552 $scope.in_opac_call = false;
555 if ($scope.opac_iframe && $location.path().match(/cat\/catalog/)) {
556 var doc = $scope.opac_iframe.dom.contentWindow.document;
557 $(doc).find('#hold_usr_search').show();
558 $(doc).find('#hold_usr_search').on('click', function() {
559 patron_search_dialog().result.then(function(barc) {
560 $(doc).find('#hold_usr_input').val(barc);
561 $(doc).find('#hold_usr_input').change();
568 // xulG catalog handlers
569 $scope.handlers = { }
571 // ------------------------------------------------------------------
574 $scope.conjoinedGridControls = {};
575 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
576 get : function(offset, count) {
577 return this.arrayNotifier(conjoinedSvc.items, offset, count);
581 $scope.changeConjoinedType = function () {
582 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
583 angular.forEach(peers, function (p) {
584 p.target_copy(p.target_copy().id());
585 p.peer_type(p.peer_type().id());
588 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
590 return $uibModal.open({
591 templateUrl: './cat/catalog/t_conjoined_selector',
594 ['$scope','$uibModalInstance',
595 function($scope , $uibModalInstance) {
596 $scope.update = true;
598 $scope.peer_type = null;
599 $scope.peer_type_list = [];
600 conjoinedSvc.get_peer_types().then(function(list){
601 $scope.peer_type_list = list;
604 $scope.ok = function(type) {
607 angular.forEach(peers, function (p) {
610 promises.push(egCore.pcrud.update(p));
613 return $q.all(promises)
614 .then(function(){$uibModalInstance.close()})
615 .then(function(){return conjoinedSvc.fetch()})
616 .then(function(){conjoinedGridDataProviderRef.refresh()});
619 $scope.cancel = function($event) {
620 $uibModalInstance.dismiss();
621 $event.preventDefault();
628 $scope.refreshConjoined = function () {
629 conjoinedSvc.fetch($scope.record_id)
630 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
633 $scope.deleteSelectedConjoined = function () {
634 var peers = $scope.conjoinedGridControls.selectedItems();
636 if (peers.length > 0) {
637 egConfirmDialog.open(
638 egCore.strings.CONFIRM_DELETE_PEERS,
639 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
640 {peers : peers.length}
641 ).result.then(function() {
642 angular.forEach(peers, function (p) {
646 egCore.pcrud.remove(peers).then(function() {
647 return conjoinedSvc.fetch();
649 $scope.conjoinedGridDataProvider.refresh();
654 if ($scope.record_id)
655 conjoinedSvc.fetch($scope.record_id);
657 // ------------------------------------------------------------------
660 $scope.holdingsGridControls = {
661 activateItem : function (item) {
662 $scope.selectedHoldingsVolCopyEdit();
665 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
666 get : function(offset, count) {
667 return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
671 $scope.add_copies_to_bucket = function() {
672 var copy_list = gatherSelectedHoldingsIds();
673 if (copy_list.length == 0) return;
675 return $uibModal.open({
676 templateUrl: './cat/catalog/t_add_to_bucket',
680 ['$scope','$uibModalInstance',
681 function($scope , $uibModalInstance) {
683 $scope.bucket_id = 0;
684 $scope.newBucketName = '';
685 $scope.allBuckets = [];
689 'open-ils.actor.container.retrieve_by_class.authoritative',
690 egCore.auth.token(), egCore.auth.user().id(),
691 'copy', 'staff_client'
692 ).then(function(buckets) { $scope.allBuckets = buckets; });
694 $scope.add_to_bucket = function() {
696 angular.forEach(copy_list, function (cp) {
697 var item = new egCore.idl.ccbi()
698 item.bucket($scope.bucket_id);
699 item.target_copy(cp);
703 'open-ils.actor.container.item.create',
704 egCore.auth.token(), 'copy', item
708 return $q.all(promises).then(function() {
709 $uibModalInstance.close();
714 $scope.add_to_new_bucket = function() {
715 var bucket = new egCore.idl.ccb();
716 bucket.owner(egCore.auth.user().id());
717 bucket.name($scope.newBucketName);
718 bucket.description('');
719 bucket.btype('staff_client');
721 return egCore.net.request(
723 'open-ils.actor.container.create',
724 egCore.auth.token(), 'copy', bucket
725 ).then(function(bucket) {
726 $scope.bucket_id = bucket;
727 $scope.add_to_bucket();
731 $scope.cancel = function() {
732 $uibModalInstance.dismiss();
738 // TODO: refactor common code between cat/catalog/app.js and cat/item/app.js
740 $scope.need_one_selected = function() {
741 var items = $scope.holdingsGridControls.selectedItems();
742 if (items.length == 1) return false;
746 $scope.make_copies_bookable = function() {
748 var copies_by_record = {};
749 var record_list = [];
751 $scope.holdingsGridControls.selectedItems(),
753 var record_id = item['call_number.record.id'];
754 if (typeof copies_by_record[ record_id ] == 'undefined') {
755 copies_by_record[ record_id ] = [];
756 record_list.push( record_id );
758 copies_by_record[ record_id ].push(item.id);
763 var combined_results = [];
764 angular.forEach(record_list, function(record_id) {
768 'open-ils.booking.resources.create_from_copies',
770 copies_by_record[record_id]
771 ).then(function(results) {
772 if (results && results['brsrc']) {
773 combined_results = combined_results.concat(results['brsrc']);
779 $q.all(promises).then(function() {
780 if (combined_results.length > 0) {
782 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
786 ['$scope','$location','egCore','$uibModalInstance',
787 function($scope , $location , egCore , $uibModalInstance) {
790 ses : egCore.auth.token(),
791 resultant_brsrc : combined_results.map(function(o) { return o[0]; })
794 var booking_path = '/eg/conify/global/booking/resource';
796 $scope.booking_admin_url =
797 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
804 $scope.book_copies_now = function() {
805 var copies_by_record = {};
806 var record_list = [];
808 $scope.holdingsGridControls.selectedItems(),
810 var record_id = item['call_number.record.id'];
811 if (typeof copies_by_record[ record_id ] == 'undefined') {
812 copies_by_record[ record_id ] = [];
813 record_list.push( record_id );
815 copies_by_record[ record_id ].push(item.id);
820 var combined_brt = [];
821 var combined_brsrc = [];
822 angular.forEach(record_list, function(record_id) {
826 'open-ils.booking.resources.create_from_copies',
828 copies_by_record[record_id]
829 ).then(function(results) {
830 if (results && results['brt']) {
831 combined_brt = combined_brt.concat(results['brt']);
833 if (results && results['brsrc']) {
834 combined_brsrc = combined_brsrc.concat(results['brsrc']);
840 $q.all(promises).then(function() {
841 if (combined_brt.length > 0 || combined_brsrc.length > 0) {
843 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
847 ['$scope','$location','egCore','$uibModalInstance',
848 function($scope , $location , egCore , $uibModalInstance) {
851 ses : egCore.auth.token(),
852 bresv_interface_opts : {
855 ,brsrc : combined_brsrc
860 var booking_path = '/eg/booking/reservation';
862 $scope.booking_admin_url =
863 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
872 $scope.requestItems = function() {
873 var copy_list = gatherSelectedHoldingsIds();
874 if (copy_list.length == 0) return;
876 return $uibModal.open({
877 templateUrl: './cat/catalog/t_request_items',
880 ['$scope','$uibModalInstance',
881 function($scope , $uibModalInstance) {
883 $scope.first_user_fetch = true;
887 copy_list : copy_list,
888 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
889 user : egCore.auth.user().id()
892 egUser.get( $scope.hold_data.user ).then(function(u) {
894 $scope.barcode = u.card().barcode();
895 $scope.user_name = egUser.format_name(u);
896 $scope.hold_data.user = u.id();
899 $scope.user_name = '';
901 $scope.$watch('barcode', function (n) {
902 if (!$scope.first_user_fetch) {
903 egUser.getByBarcode(n).then(function(u) {
905 $scope.user_name = egUser.format_name(u);
906 $scope.hold_data.user = u.id();
909 $scope.user_name = '';
910 delete $scope.hold_data.user;
913 $scope.first_user_fetch = false;
916 $scope.ok = function(h) {
919 hold_type : h.hold_type,
920 pickup_lib: h.pickup_lib.id(),
926 'open-ils.circ.holds.test_and_create.batch.override',
927 egCore.auth.token(), args, h.copy_list
930 $uibModalInstance.close();
933 $scope.cancel = function($event) {
934 $uibModalInstance.dismiss();
935 $event.preventDefault();
941 $scope.view_place_orders = function() {
942 if (!$scope.record_id) return;
943 var url = egCore.env.basePath + 'acq/legacy/lineitem/related/' + $scope.record_id + '?target=bib';
944 $timeout(function() { $window.open(url, '_blank') });
947 $scope.replaceBarcodes = function() {
948 var copy_list = gatherSelectedRawCopies();
949 if (copy_list.length == 0) return;
951 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
953 angular.forEach(copy_list, function (cp) {
955 templateUrl: './cat/share/t_replace_barcode',
958 ['$scope','$uibModalInstance',
959 function($scope , $uibModalInstance) {
960 $scope.isModal = true;
961 $scope.focusBarcode = false;
962 $scope.focusBarcode2 = true;
963 $scope.barcode1 = cp.barcode();
965 $scope.updateBarcode = function() {
966 $scope.copyNotFound = false;
967 $scope.updateOK = false;
969 egCore.pcrud.search('acp',
970 {deleted : 'f', barcode : $scope.barcode1})
971 .then(function(copy) {
974 $scope.focusBarcode = true;
975 $scope.copyNotFound = true;
979 $scope.copyId = copy.id();
980 copy.barcode($scope.barcode2);
982 egCore.pcrud.update(copy).then(function(stat) {
983 $scope.updateOK = stat;
984 $scope.focusBarcode = true;
985 holdingsSvc.fetchAgain().then(function (){
986 holdingsGridDataProviderRef.refresh();
991 $uibModalInstance.close();
994 $scope.cancel = function($event) {
995 $uibModalInstance.dismiss();
996 $event.preventDefault();
1004 // refresh the list of holdings when the record_id is changed.
1005 $scope.holdings_record_id_changed = function(id) {
1006 if ($scope.record_id != id) $scope.record_id = id;
1007 console.log('record id changed to ' + id + ', loading new holdings');
1008 holdingsSvcInst.fetch({
1009 rid : $scope.record_id,
1010 org : $scope.holdings_ou,
1011 copy: $scope.holdings_show_copies,
1012 vol : $scope.holdings_show_vols,
1013 empty: $scope.holdings_show_empty
1014 }).then(function() {
1015 $scope.holdingsGridDataProvider.refresh();
1019 // refresh the list of holdings when the filter lib is changed.
1020 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
1021 $scope.holdings_ou_changed = function(org) {
1022 $scope.holdings_ou = org;
1023 holdingsSvcInst.fetch({
1024 rid : $scope.record_id,
1025 org : $scope.holdings_ou,
1026 copy: $scope.holdings_show_copies,
1027 vol : $scope.holdings_show_vols,
1028 empty: $scope.holdings_show_empty
1029 }).then(function() {
1030 $scope.holdingsGridDataProvider.refresh();
1034 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
1035 $scope[cb] = newVal;
1036 egCore.hatch.setItem('cat.' + cb, newVal);
1037 if (!norefresh) holdingsSvcInst.fetch({
1038 rid : $scope.record_id,
1039 org : $scope.holdings_ou,
1040 copy: $scope.holdings_show_copies,
1041 vol : $scope.holdings_show_vols,
1042 empty: $scope.holdings_show_empty
1043 }).then(function() {
1044 $scope.holdingsGridDataProvider.refresh();
1048 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
1049 if (typeof x == 'undefined') x = true;
1050 $scope.holdings_cb_changed('holdings_show_vols',x,true);
1051 $('#holdings_show_vols').prop('checked', x);
1053 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
1054 if (typeof x == 'undefined') x = true;
1055 $scope.holdings_cb_changed('holdings_show_copies',x,true);
1056 $('#holdings_show_copies').prop('checked', x);
1058 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
1059 if (typeof x == 'undefined') x = true;
1060 $scope.holdings_cb_changed('holdings_show_empty',x);
1061 $('#holdings_show_empty').prop('checked', x);
1066 $scope.vols_not_shown = function () {
1067 return !$scope.holdings_show_vols;
1070 $scope.copies_not_shown = function () {
1071 return !$scope.holdings_show_copies;
1074 $scope.holdings_checkbox_handler = function (item) {
1075 $scope.holdings_cb_changed(item.checkbox,item.checked);
1078 function gatherSelectedHoldingsIds () {
1079 var cp_id_list = [];
1081 $scope.holdingsGridControls.selectedItems(),
1082 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
1087 function gatherSelectedRawCopies () {
1090 $scope.holdingsGridControls.selectedItems(),
1091 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
1096 function gatherSelectedEmptyVolumeIds () {
1097 var cn_id_list = [];
1099 $scope.holdingsGridControls.selectedItems(),
1101 if (item.copy_count == 0)
1102 cn_id_list.push(item.call_number.id)
1108 function gatherSelectedVolumeIds () {
1109 var cn_id_list = [];
1111 $scope.holdingsGridControls.selectedItems(),
1113 if (cn_id_list.indexOf(item.call_number.id) == -1)
1114 cn_id_list.push(item.call_number.id)
1120 $scope.selectedHoldingsDelete = function (vols, copies) {
1123 var perCnCopies = {};
1129 $scope.holdingsGridControls.selectedItems(),
1131 if (vols && item.raw_call_number) {
1132 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
1133 cnHash[item.call_number.id].isdeleted(1);
1135 } else if (copies) {
1136 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
1139 var cn_id = cp.call_number().id();
1140 if (!cnHash[cn_id]) {
1141 cnHash[cn_id] = cp.call_number();
1142 perCnCopies[cn_id] = [cp];
1144 perCnCopies[cn_id].push(cp);
1146 cp.call_number(cn_id); // prevent loops in JSON-ification
1153 angular.forEach(perCnCopies, function (v, k) {
1155 cnHash[k].isdeleted(1);
1158 cnHash[k].copies(v);
1162 angular.forEach(cnHash, function (v, k) {
1166 if (cnList.length == 0) return;
1169 if (vols && copies) flags.force_delete_copies = 1;
1171 egConfirmDialog.open(
1172 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
1173 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
1174 {copies : cp_count, volumes : cn_count}
1175 ).result.then(function() {
1178 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1179 egCore.auth.token(), cnList, 1, flags
1180 ).then(function(update_count) {
1181 holdingsSvcInst.fetchAgain().then(function() {
1182 $scope.holdingsGridDataProvider.refresh();
1187 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
1188 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
1189 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
1191 spawnHoldingsAdd = function (vols,copies){
1193 if (copies) { // just a copy on existing volumes
1194 angular.forEach(gatherSelectedVolumeIds(), function (v) {
1195 raw.push( {callnumber : v} );
1198 if (typeof $scope.holdingsGridControls.selectedItems == "function" &&
1199 $scope.holdingsGridControls.selectedItems().length > 0) {
1200 angular.forEach($scope.holdingsGridControls.selectedItems(),
1203 owner : item.owner_id,
1204 label : item.call_number.label
1209 owner : egCore.auth.user().ws_ou()
1214 if (raw.length == 0) raw.push({});
1218 'open-ils.actor.anon_cache.set_value',
1219 null, 'edit-these-copies', {
1220 record_id: $scope.record_id,
1225 ).then(function(key) {
1227 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1228 $timeout(function() { $window.open(url, '_blank') });
1230 alert('Could not create anonymous cache key!');
1234 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
1235 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
1237 spawnHoldingsEdit = function (hide_vols,hide_copies){
1240 'open-ils.actor.anon_cache.set_value',
1241 null, 'edit-these-copies', {
1242 record_id: $scope.record_id,
1243 copies: gatherSelectedHoldingsIds(),
1244 raw: gatherSelectedEmptyVolumeIds().map(
1245 function(v){ return { callnumber : v } }
1247 hide_vols : hide_vols,
1248 hide_copies : hide_copies
1250 ).then(function(key) {
1252 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1253 $timeout(function() { $window.open(url, '_blank') });
1255 alert('Could not create anonymous cache key!');
1259 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
1260 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
1261 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
1263 $scope.selectedHoldingsItemStatus = function (){
1264 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
1265 $timeout(function() { $window.open(url, '_blank') });
1268 $scope.markVolAsItemTarget = function() {
1269 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
1270 egCore.hatch.setLocalItem(
1271 'eg.cat.item_transfer_target',
1272 $scope.holdingsGridControls.selectedItems()[0].call_number.id
1274 ngToast.create(egCore.strings.MARK_ITEM_TARGET);
1278 $scope.markLibAsVolTarget = function() {
1279 return $uibModal.open({
1280 templateUrl: './cat/catalog/t_choose_vol_target_lib',
1283 ['$scope','$uibModalInstance',
1284 function($scope , $uibModalInstance) {
1286 var orgId = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target') || 1;
1287 $scope.org = egCore.org.get(orgId);
1288 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1289 $scope.ok = function(org) {
1290 egCore.hatch.setLocalItem(
1291 'eg.cat.volume_transfer_target',
1294 $uibModalInstance.close();
1296 $scope.cancel = function($event) {
1297 $uibModalInstance.dismiss();
1298 $event.preventDefault();
1303 $scope.markLibFromSelectedAsVolTarget = function() {
1304 egCore.hatch.setLocalItem(
1305 'eg.cat.volume_transfer_target',
1306 $scope.holdingsGridControls.selectedItems()[0].owner_id
1308 ngToast.create(egCore.strings.MARK_VOL_TARGET);
1311 $scope.selectedHoldingsItemStatusDetail = function (){
1313 gatherSelectedHoldingsIds(),
1315 var url = egCore.env.basePath +
1317 $timeout(function() { $window.open(url, '_blank') });
1322 $scope.transferVolumesToRecord = function (){
1323 var target_record = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
1324 if (!target_record) return;
1325 if ($scope.record_id == target_record) return;
1326 var items = $scope.holdingsGridControls.selectedItems();
1327 if (!items.length) return;
1329 var vols_to_move = {};
1330 angular.forEach(items, function(item) {
1331 if (!(item.call_number.owning_lib in vols_to_move)) {
1332 vols_to_move[item.call_number.owning_lib] = new Array;
1334 vols_to_move[item.call_number.owning_lib].push(item.call_number.id);
1338 angular.forEach(vols_to_move, function(vols, owning_lib) {
1339 promises.push(egCore.net.request(
1341 'open-ils.cat.asset.volume.batch.transfer.override',
1342 egCore.auth.token(), {
1343 docid : target_record,
1349 $q.all(promises).then(function(success) {
1351 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1352 holdingsSvcInst.fetchAgain().then(function() {
1353 $scope.holdingsGridDataProvider.refresh();
1356 alert('Could not transfer volumes!');
1361 function transferVolumes(new_record){
1362 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
1367 'open-ils.cat.asset.volume.batch.transfer.override',
1368 egCore.auth.token(), {
1369 docid : (new_record ? new_record : $scope.record_id),
1371 volumes : gatherSelectedVolumeIds()
1373 ).then(function(success) {
1375 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1376 holdingsSvcInst.fetchAgain().then(function() {
1377 $scope.holdingsGridDataProvider.refresh();
1380 alert('Could not transfer volumes!');
1387 $scope.transferVolumesToLibrary = function() {
1391 $scope.transferVolumesToRecordAndLibrary = function() {
1392 var target_record = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
1393 if (!target_record) return;
1394 transferVolumes(target_record);
1397 // this "transfers" selected copies to a new owning library,
1398 // auto-creating volumes and deleting unused volumes as required.
1399 $scope.changeItemOwningLib = function() {
1400 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
1401 var items = $scope.holdingsGridControls.selectedItems();
1402 if (!xfer_target || !items.length) {
1405 var vols_to_move = {};
1406 var copies_to_move = {};
1407 angular.forEach(items, function(item) {
1408 if (item.call_number.owning_lib != xfer_target) {
1409 if (item.call_number.id in vols_to_move) {
1410 copies_to_move[item.call_number.id].push(item.id);
1412 vols_to_move[item.call_number.id] = item.call_number;
1413 copies_to_move[item.call_number.id] = new Array;
1414 copies_to_move[item.call_number.id].push(item.id);
1420 angular.forEach(vols_to_move, function(vol) {
1421 promises.push(egCore.net.request(
1423 'open-ils.cat.call_number.find_or_create',
1424 egCore.auth.token(),
1431 ).then(function(resp) {
1432 var evt = egCore.evt.parse(resp);
1434 return egCore.net.request(
1436 'open-ils.cat.transfer_copies_to_volume',
1437 egCore.auth.token(),
1439 copies_to_move[vol.id]
1443 $q.all(promises).then(function() {
1444 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1445 holdingsSvcInst.fetchAgain().then(function() {
1446 $scope.holdingsGridDataProvider.refresh();
1451 $scope.transferItems = function (){
1452 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
1453 var copy_ids = gatherSelectedHoldingsIds();
1454 if (xfer_target && copy_ids.length > 0) {
1457 'open-ils.cat.transfer_copies_to_volume',
1458 egCore.auth.token(),
1462 function(resp) { // oncomplete
1463 var evt = egCore.evt.parse(resp);
1465 egConfirmDialog.open(
1466 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1467 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1468 {'evt_desc': evt.desc}
1469 ).result.then(function() {
1472 'open-ils.cat.transfer_copies_to_volume.override',
1473 egCore.auth.token(),
1476 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1477 ).then(function(resp) {
1478 holdingsSvcInst.fetchAgain().then(function() {
1479 $scope.holdingsGridDataProvider.refresh();
1484 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1485 holdingsSvcInst.fetchAgain().then(function() {
1486 $scope.holdingsGridDataProvider.refresh();
1496 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1498 gatherSelectedHoldingsIds(),
1500 var url = egCore.env.basePath +
1501 'cat/item/' + cid + '/triggered_events';
1502 $timeout(function() { $window.open(url, '_blank') });
1507 $scope.selectedHoldingsItemStatusHolds = function (){
1509 gatherSelectedHoldingsIds(),
1511 var url = egCore.env.basePath +
1512 'cat/item/' + cid + '/holds';
1513 $timeout(function() { $window.open(url, '_blank') });
1518 $scope.selectedHoldingsPrintLabels = function() {
1521 'open-ils.actor.anon_cache.set_value',
1522 null, 'print-labels-these-copies', {
1523 copies : gatherSelectedHoldingsIds()
1525 ).then(function(key) {
1527 var url = egCore.env.basePath + 'cat/printlabels/' + key;
1528 $timeout(function() { $window.open(url, '_blank') });
1530 alert('Could not create anonymous cache key!');
1535 $scope.selectedHoldingsDamaged = function () {
1536 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
1537 holdingsSvcInst.fetchAgain().then(function() {
1538 $scope.holdingsGridDataProvider.refresh();
1543 $scope.selectedHoldingsMissing = function () {
1544 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1545 holdingsSvcInst.fetchAgain().then(function() {
1546 $scope.holdingsGridDataProvider.refresh();
1551 $scope.attach_to_peer_bib = function() {
1552 var copy_list = gatherSelectedHoldingsIds();
1553 if (copy_list.length == 0) return;
1555 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1556 if (!target_record) return;
1558 return $uibModal.open({
1559 templateUrl: './cat/catalog/t_conjoined_selector',
1562 ['$scope','$uibModalInstance',
1563 function($scope , $uibModalInstance) {
1564 $scope.update = false;
1566 $scope.peer_type = null;
1567 $scope.peer_type_list = [];
1568 conjoinedSvc.get_peer_types().then(function(list){
1569 $scope.peer_type_list = list;
1572 $scope.ok = function(type) {
1575 angular.forEach(copy_list, function (cp) {
1576 var n = new egCore.idl.bpbcm();
1578 n.peer_record(target_record);
1581 promises.push(egCore.pcrud.create(n));
1584 return $q.all(promises).then(function(){$uibModalInstance.close()});
1587 $scope.cancel = function($event) {
1588 $uibModalInstance.dismiss();
1589 $event.preventDefault();
1597 // ------------------------------------------------------------------
1599 var provider = egGridDataProvider.instance({});
1600 $scope.hold_grid_data_provider = provider;
1601 $scope.grid_actions = egHoldGridActions;
1602 $scope.grid_actions.refresh = function () { provider.refresh() };
1603 $scope.hold_grid_controls = {};
1605 var hold_ids = []; // current list of holds
1606 function fetchHolds(offset, count) {
1607 var ids = hold_ids.slice(offset, offset + count);
1609 return egHolds.fetch_holds(ids).then(null, null,
1610 function(hold_data) {
1616 provider.get = function(offset, count) {
1617 if ($scope.record_tab != 'holds') return $q.when();
1618 var deferred = $q.defer();
1619 hold_ids = []; // no caching ATM
1621 // open a determinate progress dialog, max value set below.
1622 egProgressDialog.open({max : 1, value : 0});
1627 'open-ils.circ.holds.retrieve_all_from_title',
1628 egCore.auth.token(), $scope.record_id,
1629 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
1631 function(hold_data) {
1632 hold_ids = []; // clear the list of ids, hack to avoid dups
1633 // TODO: fix the underlying problem, which is that
1634 // this gets called twice when switching to the holds
1635 // tab; once explicitly, and once via the change handler
1636 // on the OU selector
1637 angular.forEach(hold_data, function(list, type) {
1638 hold_ids = hold_ids.concat(list);
1641 // Set the max value of the progress bar to the lesser of
1642 // the total number of holds to fetch or the page size
1644 egProgressDialog.update(
1645 {max : Math.min(hold_ids.length, count)});
1647 var holds_fetched = 0;
1648 fetchHolds(offset, count)
1649 .then(deferred.resolve, null,
1650 function(hold_data) {
1652 deferred.notify(hold_data);
1653 egProgressDialog.increment();
1655 )['finally'](egProgressDialog.close);
1659 return deferred.promise;
1662 $scope.detail_view = function(action, user_data, items) {
1664 $scope.detail_hold_id = h.hold.id();
1668 $scope.list_view = function(items) {
1669 $scope.detail_hold_id = null;
1672 // refresh the list of record holds when the pickup lib is changed.
1673 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1674 $scope.pickup_ou_changed = function(org) {
1675 $scope.pickup_ou = org;
1679 $scope.print_holds = function() {
1681 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1683 hold : egCore.idl.toHash(item.hold),
1684 patron_last : item.patron_last,
1685 patron_alias : item.patron_alias,
1686 patron_barcode : item.patron_barcode,
1687 copy : egCore.idl.toHash(item.copy),
1688 volume : egCore.idl.toHash(item.volume),
1689 title : item.mvr.title(),
1690 author : item.mvr.author()
1694 egCore.print.print({
1695 context : 'receipt',
1696 template : 'holds_for_bib',
1697 scope : {holds : holds}
1701 $scope.current_hold_transfer_dest = egCore.hatch.getLocalItem ('eg.circ.hold.title_transfer_target');
1703 $scope.mark_hold_transfer_dest = function() {
1704 $scope.current_hold_transfer_dest = $scope.record_id;
1705 egCore.hatch.setLocalItem(
1706 'eg.circ.hold.title_transfer_target', $scope.record_id);
1707 ngToast.create(egCore.strings.HOLD_TRANSFER_DEST_MARKED);
1710 // UI presents this option as "all holds"
1711 $scope.transfer_holds_to_marked = function() {
1712 var hold_ids = $scope.hold_grid_controls.allItems().map(
1713 function(hold_data) {return hold_data.hold.id()});
1714 egHolds.transfer_to_marked_title(hold_ids);
1717 // ------------------------------------------------------------------
1718 // Initialize the selected tab
1720 // we explicitly initialize catalog_url because otherwise Firefox
1721 // ends up setting it to $BASE_URL/{{url}}, which then messes
1722 // things up. See LP#1708951
1723 $scope.catalog_url = '';
1725 function init_cat_url() {
1726 // Set the initial catalog URL. This only happens once.
1727 // The URL is otherwise generated through user navigation.
1728 if ($scope.catalog_url) return;
1730 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1732 // A record ID in the path indicates a request for the record-
1734 if ($routeParams.record_id) {
1735 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1738 // Jumping directly to the results page by passing a search
1739 // query via the URL. Copy all URL params to the iframe url.
1740 if ($location.path().match(/catalog\/results/)) {
1741 url = url.replace(/advanced/, '/results?');
1743 angular.forEach($location.search(), function(val, key) {
1744 if (!first) url += '&';
1746 url += encodeURIComponent(key)
1747 + '=' + encodeURIComponent(val);
1751 // if we're displaying the advanced search form, select
1752 // whatever default pane the user has chosen via workstation
1754 if (url.match(/\/opac\/advanced$/)) {
1755 var adv_pane = egCore.hatch.getLocalItem('eg.search.adv_pane');
1757 url += '?pane=' + encodeURIComponent(adv_pane);
1761 $scope.catalog_url = url;
1764 function init_parts_url() {
1765 $scope.parts_url = $location
1769 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1773 $scope.set_record_tab = function(tab) {
1774 $scope.record_tab = tab;
1787 $scope.detail_hold_record_id = $scope.record_id;
1788 // refresh the holds grid
1795 $scope.set_default_record_tab = function() {
1796 egCore.hatch.setLocalItem(
1797 'eg.cat.default_record_tab', $scope.record_tab);
1798 $timeout(function(){$scope.default_tab = $scope.record_tab});
1802 if ($scope.record_id) {
1803 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1804 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1807 tab = $routeParams.record_tab || 'catalog';
1809 $scope.set_record_tab(tab);
1813 .controller('AuthorityCtrl',
1814 ['$scope','$routeParams','$location','$window','$q','egCore',
1815 function($scope , $routeParams , $location , $window , $q , egCore) {
1817 // set record ID on page load if available...
1818 $scope.authority_id = $routeParams.authority_id;
1820 if ($routeParams.authority_id) $scope.from_route = true;
1821 else $scope.from_route = false;
1823 $scope.stop_unload = false;
1826 .controller('URLVerifyCtrl',
1827 ['$scope','$location',
1828 function($scope , $location) {
1829 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1832 .controller('VandelayCtrl',
1833 ['$scope','$location', 'egCore', '$uibModal',
1834 function($scope , $location, egCore, $uibModal) {
1835 $scope.vandelay_url = $location.absUrl().replace(/\/staff\/cat\/catalog\/vandelay/, '/vandelay/vandelay');
1837 $scope.funcs.edit_marc_modal = function(bre, callback){
1838 var marcArgs = { 'marc_xml': bre.marc() };
1839 var vqbibrecId = bre.id();
1841 templateUrl: './cat/catalog/t_edit_marc_modal',
1843 controller: ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
1844 $scope.focusMe = true;
1845 $scope.recordId = vqbibrecId;
1846 $scope.args = marcArgs;
1847 $scope.dirty_flag = false;
1848 $scope.ok = function(marg){
1849 $uibModalInstance.close(marg);
1851 $scope.cancel = function(){ $uibModalInstance.dismiss() }
1853 }).result.then(function(res){
1854 var new_xml = res.marc_xml;
1855 egCore.pcrud.retrieve('vqbr', vqbibrecId).then(function(vqbib){
1856 vqbib.marc(new_xml);
1857 egCore.pcrud.update(vqbib).then( function(){ callback(vqbibrecId); });
1863 .controller('ManageAuthoritiesCtrl',
1864 ['$scope','$location',
1865 function($scope , $location) {
1866 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1869 .controller('BatchEditCtrl',
1870 ['$scope','$location','$routeParams',
1871 function($scope , $location , $routeParams) {
1872 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1873 if ($routeParams.container_type) {
1874 switch ($routeParams.container_type) {
1876 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1879 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1886 .filter('boolText', function(){
1887 return function (v) {
1892 .factory('conjoinedSvc',
1894 function(egCore , $q) {
1897 items : [], // record search results
1898 index : 0, // search grid index
1905 bpbcm : ['target_copy','peer_type'],
1906 acp : ['call_number'],
1908 bre : ['simple_record']
1910 // avoid fetching the MARC blob by specifying which
1911 // fields on the bre to select. More may be needed.
1912 // note that fleshed fields are explicitly selected.
1913 select : { bre : ['id'] },
1914 order_by : { bpbcm : ['id'] },
1917 // resolved with the last received copy
1918 service.fetch = function(rid) {
1919 if (!rid && !service.rid) return $q.when();
1921 if (rid) service.rid = rid;
1925 return egCore.pcrud.search(
1927 {peer_record : service.rid},
1930 ).then( function(list) { // finished
1931 service.items = list;
1932 return service.items;
1936 // returns a promise resolved with the list of peer bib types
1937 service.get_peer_types = function() {
1939 return $q.when(egCore.env.bpt.list);
1941 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
1942 .then(function(list) {
1943 egCore.env.absorbList(list, 'bpt');