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',
316 ['$scope','$uibModalInstance',
317 function($scope , $uibModalInstance) {
319 $scope.bucket_id = 0;
320 $scope.newBucketName = '';
321 $scope.allBuckets = [];
324 'open-ils.actor.container.retrieve_by_class.authoritative',
325 egCore.auth.token(), egCore.auth.user().id(),
326 'biblio', 'staff_client'
327 ).then(function(buckets) { $scope.allBuckets = buckets; });
329 $scope.add_to_bucket = function() {
330 var item = new egCore.idl.cbrebi();
331 item.bucket($scope.bucket_id);
332 item.target_biblio_record_entry(recId);
335 'open-ils.actor.container.item.create',
336 egCore.auth.token(), 'biblio', item
337 ).then(function(resp) {
338 $uibModalInstance.close();
342 $scope.add_to_new_bucket = function() {
343 var bucket = new egCore.idl.cbreb();
344 bucket.owner(egCore.auth.user().id());
345 bucket.name($scope.newBucketName);
346 bucket.description('');
347 bucket.btype('staff_client');
351 'open-ils.actor.container.create',
352 egCore.auth.token(), 'biblio', bucket
353 ).then(function(bucket) {
354 $scope.bucket_id = bucket;
355 $scope.add_to_bucket();
359 $scope.cancel = function() {
360 $uibModalInstance.dismiss();
366 $scope.current_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record');
367 $scope.current_voltransfer_target = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
368 $scope.current_conjoined_target = egCore.hatch.getLocalItem('eg.cat.marked_conjoined_record');
370 $scope.quickReceive = function () {
372 var next_per_stream = {};
374 var recId = $scope.record_id;
375 return $uibModal.open({
376 templateUrl: './share/t_subscription_select_dialog',
378 controller: ['$scope', '$uibModalInstance',
379 function($scope, $uibModalInstance) {
382 $scope.rememberMe = 'eg.serials.quickreceive.last_org';
383 $scope.record_id = recId;
384 $scope.ssubId = null;
386 $scope.ok = function() { $uibModalInstance.close($scope.ssubId) }
387 $scope.cancel = function() { $uibModalInstance.dismiss(); }
390 }).result.then(function(ssubId) {
393 promises.push(egSerialsCoreSvc.fetchItemsForSub(ssubId,{status:'Expected'}).then(function(){
394 angular.forEach(egSerialsCoreSvc.itemTree, function (item) {
395 if (next_per_stream[item.stream().id()]) return;
396 if (item.status() == 'Expected') {
397 next_per_stream[item.stream().id()] = item;
398 list.push(egCore.idl.Clone(item));
403 return $q.all(promises).then(function() {
406 ngToast.warning(egCore.strings.SERIALS_NO_ITEMS);
410 return egSerialsCoreSvc.process_items(
416 false, // print by default
417 function() { $scope.holdings_record_id_changed($scope.record_id) }
421 ngToast.warning(egCore.strings.SERIALS_NO_SUBS);
427 $scope.markConjoined = function () {
428 $scope.current_conjoined_target = $scope.record_id;
429 egCore.hatch.setLocalItem('eg.cat.marked_conjoined_record',$scope.record_id);
430 ngToast.create(egCore.strings.MARK_CONJ_TARGET);
433 $scope.markVolTransfer = function () {
434 ngToast.create(egCore.strings.MARK_VOL_TARGET);
435 $scope.current_voltransfer_target = $scope.record_id;
436 egCore.hatch.setLocalItem('eg.cat.marked_volume_transfer_record',$scope.record_id);
439 $scope.markOverlay = function () {
440 $scope.current_overlay_target = $scope.record_id;
441 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.record_id);
442 ngToast.create(egCore.strings.MARK_OVERLAY_TARGET);
445 $scope.clearRecordMarks = function () {
446 $scope.current_overlay_target = null;
447 $scope.current_voltransfer_target = null;
448 $scope.current_conjoined_target = null;
449 $scope.current_hold_transfer_dest = null;
450 egCore.hatch.removeLocalItem('eg.cat.marked_volume_transfer_record');
451 egCore.hatch.removeLocalItem('eg.cat.marked_conjoined_record');
452 egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');
453 egCore.hatch.removeLocalItem('eg.circ.hold.title_transfer_target');
456 $scope.stop_unload = false;
457 $scope.$watch('stop_unload',
458 function(newVal, oldVal) {
459 if (newVal && newVal != oldVal && $scope.opac_iframe) {
460 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
461 return 'There is unsaved data in this record.'
464 if ($scope.opac_iframe)
465 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
470 // Set the "last bib" cookie, if we have that
471 if ($scope.record_id)
472 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
474 $scope.refresh_record_callback = function (record_id) {
475 egCore.pcrud.retrieve('bre', record_id, {
478 bre : ['simple_record','creator','editor']
480 }).then(function(rec) {
481 rec.owner(egCore.org.get(rec.owner()));
482 $scope.summary_pane_record = rec;
488 patron_search_dialog = function() {
489 return $uibModal.open({
490 templateUrl: './share/t_patron_selector',
495 ['$scope','$uibModalInstance','$controller',
496 function($scope , $uibModalInstance , $controller) {
497 angular.extend(this, $controller('BasePatronSearchCtrl', {$scope : $scope}));
499 $scope.need_one_selected = function() {
500 var items = $scope.gridControls.selectedItems();
501 return (items.length == 1) ? false : true
503 $scope.ok = function() {
504 var items = $scope.gridControls.selectedItems();
505 if (items.length == 1) {
506 $uibModalInstance.close(items[0].card().barcode());
508 $uibModalInstance.close()
511 $scope.cancel = function($event) {
512 $uibModalInstance.dismiss();
513 $event.preventDefault();
519 // also set it when the iframe changes to a new record
520 $scope.handle_page = function(url) {
522 if (!url || url == 'about:blank') {
523 // nothing loaded. If we already have a record ID, leave it.
527 var match = url.match(/\/+opac\/+record\/+(\d+)/);
529 $scope.record_id = match[1];
530 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
531 $scope.holdings_record_id_changed($scope.record_id);
532 conjoinedSvc.fetch($scope.record_id).then(function(){
533 $scope.conjoinedGridDataProvider.refresh();
535 egHolds.fetch_holds(hold_ids).then($scope.hold_grid_data_provider.refresh);
537 $location.update_path('/cat/catalog/record/' + $scope.record_id);
539 delete $scope.record_id;
540 $scope.from_route = false;
543 // child scope is executing this function, so our digest doesn't fire ... thus,
546 if (!$scope.in_opac_call) {
547 if ($scope.record_id && !$scope.record_tab) {
548 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
549 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
551 tab = $routeParams.record_tab || 'catalog';
553 $scope.set_record_tab(tab);
555 $scope.in_opac_call = false;
558 if ($scope.opac_iframe && $location.path().match(/cat\/catalog/)) {
559 var doc = $scope.opac_iframe.dom.contentWindow.document;
560 $(doc).find('#hold_usr_search').show();
561 $(doc).find('#hold_usr_search').on('click', function() {
562 patron_search_dialog().result.then(function(barc) {
563 $(doc).find('#hold_usr_input').val(barc);
564 $(doc).find('#hold_usr_input').change();
571 // xulG catalog handlers
572 $scope.handlers = { }
574 // ------------------------------------------------------------------
577 $scope.conjoinedGridControls = {};
578 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
579 get : function(offset, count) {
580 return this.arrayNotifier(conjoinedSvc.items, offset, count);
584 $scope.changeConjoinedType = function () {
585 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
586 angular.forEach(peers, function (p) {
587 p.target_copy(p.target_copy().id());
588 p.peer_type(p.peer_type().id());
591 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
593 return $uibModal.open({
594 templateUrl: './cat/catalog/t_conjoined_selector',
598 ['$scope','$uibModalInstance',
599 function($scope , $uibModalInstance) {
600 $scope.update = true;
602 $scope.peer_type = null;
603 $scope.peer_type_list = [];
604 conjoinedSvc.get_peer_types().then(function(list){
605 $scope.peer_type_list = list;
608 $scope.ok = function(type) {
611 angular.forEach(peers, function (p) {
614 promises.push(egCore.pcrud.update(p));
617 return $q.all(promises)
618 .then(function(){$uibModalInstance.close()})
619 .then(function(){return conjoinedSvc.fetch()})
620 .then(function(){conjoinedGridDataProviderRef.refresh()});
623 $scope.cancel = function($event) {
624 $uibModalInstance.dismiss();
625 $event.preventDefault();
632 $scope.refreshConjoined = function () {
633 conjoinedSvc.fetch($scope.record_id)
634 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
637 $scope.deleteSelectedConjoined = function () {
638 var peers = $scope.conjoinedGridControls.selectedItems();
640 if (peers.length > 0) {
641 egConfirmDialog.open(
642 egCore.strings.CONFIRM_DELETE_PEERS,
643 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
644 {peers : peers.length}
645 ).result.then(function() {
646 angular.forEach(peers, function (p) {
650 egCore.pcrud.remove(peers).then(function() {
651 return conjoinedSvc.fetch();
653 $scope.conjoinedGridDataProvider.refresh();
658 if ($scope.record_id)
659 conjoinedSvc.fetch($scope.record_id);
661 // ------------------------------------------------------------------
664 $scope.holdingsGridControls = {
665 activateItem : function (item) {
666 $scope.selectedHoldingsVolCopyEdit();
669 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
670 get : function(offset, count) {
671 return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
675 $scope.add_copies_to_bucket = function() {
676 var copy_list = gatherSelectedHoldingsIds();
677 if (copy_list.length == 0) return;
679 return $uibModal.open({
680 templateUrl: './cat/catalog/t_add_to_bucket',
685 ['$scope','$uibModalInstance',
686 function($scope , $uibModalInstance) {
688 $scope.bucket_id = 0;
689 $scope.newBucketName = '';
690 $scope.allBuckets = [];
694 'open-ils.actor.container.retrieve_by_class.authoritative',
695 egCore.auth.token(), egCore.auth.user().id(),
696 'copy', 'staff_client'
697 ).then(function(buckets) { $scope.allBuckets = buckets; });
699 $scope.add_to_bucket = function() {
701 angular.forEach(copy_list, function (cp) {
702 var item = new egCore.idl.ccbi()
703 item.bucket($scope.bucket_id);
704 item.target_copy(cp);
708 'open-ils.actor.container.item.create',
709 egCore.auth.token(), 'copy', item
713 return $q.all(promises).then(function() {
714 $uibModalInstance.close();
719 $scope.add_to_new_bucket = function() {
720 var bucket = new egCore.idl.ccb();
721 bucket.owner(egCore.auth.user().id());
722 bucket.name($scope.newBucketName);
723 bucket.description('');
724 bucket.btype('staff_client');
726 return egCore.net.request(
728 'open-ils.actor.container.create',
729 egCore.auth.token(), 'copy', bucket
730 ).then(function(bucket) {
731 $scope.bucket_id = bucket;
732 $scope.add_to_bucket();
736 $scope.cancel = function() {
737 $uibModalInstance.dismiss();
743 // TODO: refactor common code between cat/catalog/app.js and cat/item/app.js
745 $scope.need_one_selected = function() {
746 var items = $scope.holdingsGridControls.selectedItems();
747 if (items.length == 1) return false;
751 $scope.make_copies_bookable = function() {
753 var copies_by_record = {};
754 var record_list = [];
756 $scope.holdingsGridControls.selectedItems(),
758 var record_id = item['call_number.record.id'];
759 if (typeof copies_by_record[ record_id ] == 'undefined') {
760 copies_by_record[ record_id ] = [];
761 record_list.push( record_id );
763 copies_by_record[ record_id ].push(item.id);
768 var combined_results = [];
769 angular.forEach(record_list, function(record_id) {
773 'open-ils.booking.resources.create_from_copies',
775 copies_by_record[record_id]
776 ).then(function(results) {
777 if (results && results['brsrc']) {
778 combined_results = combined_results.concat(results['brsrc']);
784 $q.all(promises).then(function() {
785 if (combined_results.length > 0) {
787 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
792 ['$scope','$location','egCore','$uibModalInstance',
793 function($scope , $location , egCore , $uibModalInstance) {
796 ses : egCore.auth.token(),
797 resultant_brsrc : combined_results.map(function(o) { return o[0]; })
800 var booking_path = '/eg/conify/global/booking/resource';
802 $scope.booking_admin_url =
803 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
810 $scope.book_copies_now = function() {
811 var copies_by_record = {};
812 var record_list = [];
814 $scope.holdingsGridControls.selectedItems(),
816 var record_id = item['call_number.record.id'];
817 if (typeof copies_by_record[ record_id ] == 'undefined') {
818 copies_by_record[ record_id ] = [];
819 record_list.push( record_id );
821 copies_by_record[ record_id ].push(item.id);
826 var combined_brt = [];
827 var combined_brsrc = [];
828 angular.forEach(record_list, function(record_id) {
832 'open-ils.booking.resources.create_from_copies',
834 copies_by_record[record_id]
835 ).then(function(results) {
836 if (results && results['brt']) {
837 combined_brt = combined_brt.concat(results['brt']);
839 if (results && results['brsrc']) {
840 combined_brsrc = combined_brsrc.concat(results['brsrc']);
846 $q.all(promises).then(function() {
847 if (combined_brt.length > 0 || combined_brsrc.length > 0) {
849 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
854 ['$scope','$location','egCore','$uibModalInstance',
855 function($scope , $location , egCore , $uibModalInstance) {
858 ses : egCore.auth.token(),
859 bresv_interface_opts : {
862 ,brsrc : combined_brsrc
867 var booking_path = '/eg/booking/reservation';
869 $scope.booking_admin_url =
870 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
879 $scope.requestItems = function() {
880 var copy_list = gatherSelectedHoldingsIds();
881 if (copy_list.length == 0) return;
883 return $uibModal.open({
884 templateUrl: './cat/catalog/t_request_items',
887 ['$scope','$uibModalInstance',
888 function($scope , $uibModalInstance) {
890 $scope.first_user_fetch = true;
894 copy_list : copy_list,
895 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
896 user : egCore.auth.user().id()
899 egUser.get( $scope.hold_data.user ).then(function(u) {
901 $scope.barcode = u.card().barcode();
902 $scope.user_name = egUser.format_name(u);
903 $scope.hold_data.user = u.id();
906 $scope.user_name = '';
908 $scope.$watch('barcode', function (n) {
909 if (!$scope.first_user_fetch) {
910 egUser.getByBarcode(n).then(function(u) {
912 $scope.user_name = egUser.format_name(u);
913 $scope.hold_data.user = u.id();
916 $scope.user_name = '';
917 delete $scope.hold_data.user;
920 $scope.first_user_fetch = false;
923 $scope.ok = function(h) {
926 hold_type : h.hold_type,
927 pickup_lib: h.pickup_lib.id(),
933 'open-ils.circ.holds.test_and_create.batch.override',
934 egCore.auth.token(), args, h.copy_list
937 $uibModalInstance.close();
940 $scope.cancel = function($event) {
941 $uibModalInstance.dismiss();
942 $event.preventDefault();
948 $scope.view_place_orders = function() {
949 if (!$scope.record_id) return;
950 var url = egCore.env.basePath + 'acq/legacy/lineitem/related/' + $scope.record_id + '?target=bib';
951 $timeout(function() { $window.open(url, '_blank') });
954 $scope.replaceBarcodes = function() {
955 var copy_list = gatherSelectedRawCopies();
956 if (copy_list.length == 0) return;
958 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
960 angular.forEach(copy_list, function (cp) {
962 templateUrl: './cat/share/t_replace_barcode',
966 ['$scope','$uibModalInstance',
967 function($scope , $uibModalInstance) {
968 $scope.isModal = true;
969 $scope.focusBarcode = false;
970 $scope.focusBarcode2 = true;
971 $scope.barcode1 = cp.barcode();
973 $scope.updateBarcode = function() {
974 $scope.copyNotFound = false;
975 $scope.updateOK = false;
977 egCore.pcrud.search('acp',
978 {deleted : 'f', barcode : $scope.barcode1})
979 .then(function(copy) {
982 $scope.focusBarcode = true;
983 $scope.copyNotFound = true;
987 $scope.copyId = copy.id();
988 copy.barcode($scope.barcode2);
990 egCore.pcrud.update(copy).then(function(stat) {
991 $scope.updateOK = stat;
992 $scope.focusBarcode = true;
993 holdingsSvc.fetchAgain().then(function (){
994 holdingsGridDataProviderRef.refresh();
999 $uibModalInstance.close();
1002 $scope.cancel = function($event) {
1003 $uibModalInstance.dismiss();
1004 $event.preventDefault();
1012 // refresh the list of holdings when the record_id is changed.
1013 $scope.holdings_record_id_changed = function(id) {
1014 if ($scope.record_id != id) $scope.record_id = id;
1015 console.log('record id changed to ' + id + ', loading new holdings');
1016 holdingsSvcInst.fetch({
1017 rid : $scope.record_id,
1018 org : $scope.holdings_ou,
1019 copy: $scope.holdings_show_copies,
1020 vol : $scope.holdings_show_vols,
1021 empty: $scope.holdings_show_empty
1022 }).then(function() {
1023 $scope.holdingsGridDataProvider.refresh();
1027 // refresh the list of holdings when the filter lib is changed.
1028 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
1029 $scope.holdings_ou_changed = function(org) {
1030 $scope.holdings_ou = org;
1031 holdingsSvcInst.fetch({
1032 rid : $scope.record_id,
1033 org : $scope.holdings_ou,
1034 copy: $scope.holdings_show_copies,
1035 vol : $scope.holdings_show_vols,
1036 empty: $scope.holdings_show_empty
1037 }).then(function() {
1038 $scope.holdingsGridDataProvider.refresh();
1042 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
1043 $scope[cb] = newVal;
1044 egCore.hatch.setItem('cat.' + cb, newVal);
1045 if (!norefresh) holdingsSvcInst.fetch({
1046 rid : $scope.record_id,
1047 org : $scope.holdings_ou,
1048 copy: $scope.holdings_show_copies,
1049 vol : $scope.holdings_show_vols,
1050 empty: $scope.holdings_show_empty
1051 }).then(function() {
1052 $scope.holdingsGridDataProvider.refresh();
1056 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
1057 if (typeof x == 'undefined') x = true;
1058 $scope.holdings_cb_changed('holdings_show_vols',x,true);
1059 $('#holdings_show_vols').prop('checked', x);
1061 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
1062 if (typeof x == 'undefined') x = true;
1063 $scope.holdings_cb_changed('holdings_show_copies',x,true);
1064 $('#holdings_show_copies').prop('checked', x);
1066 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
1067 if (typeof x == 'undefined') x = true;
1068 $scope.holdings_cb_changed('holdings_show_empty',x);
1069 $('#holdings_show_empty').prop('checked', x);
1074 $scope.vols_not_shown = function () {
1075 return !$scope.holdings_show_vols;
1078 $scope.copies_not_shown = function () {
1079 return !$scope.holdings_show_copies;
1082 $scope.holdings_checkbox_handler = function (item) {
1083 $scope.holdings_cb_changed(item.checkbox,item.checked);
1086 function gatherSelectedHoldingsIds () {
1087 var cp_id_list = [];
1089 $scope.holdingsGridControls.selectedItems(),
1090 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
1095 function gatherSelectedRawCopies () {
1098 $scope.holdingsGridControls.selectedItems(),
1099 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
1104 function gatherSelectedEmptyVolumeIds () {
1105 var cn_id_list = [];
1107 $scope.holdingsGridControls.selectedItems(),
1109 if (item.copy_count == 0)
1110 cn_id_list.push(item.call_number.id)
1116 function gatherSelectedVolumeIds () {
1117 var cn_id_list = [];
1119 $scope.holdingsGridControls.selectedItems(),
1121 if (cn_id_list.indexOf(item.call_number.id) == -1)
1122 cn_id_list.push(item.call_number.id)
1128 $scope.selectedHoldingsDelete = function (vols, copies) {
1131 var perCnCopies = {};
1137 $scope.holdingsGridControls.selectedItems(),
1139 if (vols && item.raw_call_number) {
1140 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
1141 cnHash[item.call_number.id].isdeleted(1);
1143 } else if (copies) {
1144 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
1147 var cn_id = cp.call_number().id();
1148 if (!cnHash[cn_id]) {
1149 cnHash[cn_id] = cp.call_number();
1150 perCnCopies[cn_id] = [cp];
1152 perCnCopies[cn_id].push(cp);
1154 cp.call_number(cn_id); // prevent loops in JSON-ification
1161 angular.forEach(perCnCopies, function (v, k) {
1163 cnHash[k].isdeleted(1);
1166 cnHash[k].copies(v);
1170 angular.forEach(cnHash, function (v, k) {
1174 if (cnList.length == 0) return;
1177 if (vols && copies) flags.force_delete_copies = 1;
1179 egConfirmDialog.open(
1180 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
1181 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
1182 {copies : cp_count, volumes : cn_count}
1183 ).result.then(function() {
1186 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1187 egCore.auth.token(), cnList, 1, flags
1188 ).then(function(update_count) {
1189 holdingsSvcInst.fetchAgain().then(function() {
1190 $scope.holdingsGridDataProvider.refresh();
1195 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
1196 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
1197 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
1199 spawnHoldingsAdd = function (vols,copies){
1201 if (copies) { // just a copy on existing volumes
1202 angular.forEach(gatherSelectedVolumeIds(), function (v) {
1203 raw.push( {callnumber : v} );
1206 if (typeof $scope.holdingsGridControls.selectedItems == "function" &&
1207 $scope.holdingsGridControls.selectedItems().length > 0) {
1208 angular.forEach($scope.holdingsGridControls.selectedItems(),
1211 owner : item.owner_id,
1212 label : item.call_number.label
1217 owner : egCore.auth.user().ws_ou()
1222 if (raw.length == 0) raw.push({});
1226 'open-ils.actor.anon_cache.set_value',
1227 null, 'edit-these-copies', {
1228 record_id: $scope.record_id,
1233 ).then(function(key) {
1235 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1236 $timeout(function() { $window.open(url, '_blank') });
1238 alert('Could not create anonymous cache key!');
1242 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
1243 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
1245 spawnHoldingsEdit = function (hide_vols,hide_copies){
1248 'open-ils.actor.anon_cache.set_value',
1249 null, 'edit-these-copies', {
1250 record_id: $scope.record_id,
1251 copies: gatherSelectedHoldingsIds(),
1252 raw: gatherSelectedEmptyVolumeIds().map(
1253 function(v){ return { callnumber : v } }
1255 hide_vols : hide_vols,
1256 hide_copies : hide_copies
1258 ).then(function(key) {
1260 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1261 $timeout(function() { $window.open(url, '_blank') });
1263 alert('Could not create anonymous cache key!');
1267 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
1268 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
1269 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
1271 $scope.selectedHoldingsItemStatus = function (){
1272 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
1273 $timeout(function() { $window.open(url, '_blank') });
1276 $scope.markVolAsItemTarget = function() {
1277 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
1278 egCore.hatch.setLocalItem(
1279 'eg.cat.item_transfer_target',
1280 $scope.holdingsGridControls.selectedItems()[0].call_number.id
1282 ngToast.create(egCore.strings.MARK_ITEM_TARGET);
1286 $scope.markLibAsVolTarget = function() {
1287 return $uibModal.open({
1288 templateUrl: './cat/catalog/t_choose_vol_target_lib',
1292 ['$scope','$uibModalInstance',
1293 function($scope , $uibModalInstance) {
1295 var orgId = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target') || 1;
1296 $scope.org = egCore.org.get(orgId);
1297 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1298 $scope.ok = function(org) {
1299 egCore.hatch.setLocalItem(
1300 'eg.cat.volume_transfer_target',
1303 $uibModalInstance.close();
1305 $scope.cancel = function($event) {
1306 $uibModalInstance.dismiss();
1307 $event.preventDefault();
1312 $scope.markLibFromSelectedAsVolTarget = function() {
1313 egCore.hatch.setLocalItem(
1314 'eg.cat.volume_transfer_target',
1315 $scope.holdingsGridControls.selectedItems()[0].owner_id
1317 ngToast.create(egCore.strings.MARK_VOL_TARGET);
1320 $scope.selectedHoldingsItemStatusDetail = function (){
1322 gatherSelectedHoldingsIds(),
1324 var url = egCore.env.basePath +
1326 $timeout(function() { $window.open(url, '_blank') });
1331 $scope.transferVolumesToRecord = function (){
1332 var target_record = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
1333 if (!target_record) return;
1334 if ($scope.record_id == target_record) return;
1335 var items = $scope.holdingsGridControls.selectedItems();
1336 if (!items.length) return;
1338 var vols_to_move = {};
1339 angular.forEach(items, function(item) {
1340 if (!(item.call_number.owning_lib in vols_to_move)) {
1341 vols_to_move[item.call_number.owning_lib] = new Array;
1343 vols_to_move[item.call_number.owning_lib].push(item.call_number.id);
1347 angular.forEach(vols_to_move, function(vols, owning_lib) {
1348 promises.push(egCore.net.request(
1350 'open-ils.cat.asset.volume.batch.transfer.override',
1351 egCore.auth.token(), {
1352 docid : target_record,
1358 $q.all(promises).then(function(success) {
1360 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1361 holdingsSvcInst.fetchAgain().then(function() {
1362 $scope.holdingsGridDataProvider.refresh();
1365 alert('Could not transfer volumes!');
1370 function transferVolumes(new_record){
1371 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
1376 'open-ils.cat.asset.volume.batch.transfer.override',
1377 egCore.auth.token(), {
1378 docid : (new_record ? new_record : $scope.record_id),
1380 volumes : gatherSelectedVolumeIds()
1382 ).then(function(success) {
1384 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1385 holdingsSvcInst.fetchAgain().then(function() {
1386 $scope.holdingsGridDataProvider.refresh();
1389 alert('Could not transfer volumes!');
1396 $scope.transferVolumesToLibrary = function() {
1400 $scope.transferVolumesToRecordAndLibrary = function() {
1401 var target_record = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
1402 if (!target_record) return;
1403 transferVolumes(target_record);
1406 // this "transfers" selected copies to a new owning library,
1407 // auto-creating volumes and deleting unused volumes as required.
1408 $scope.changeItemOwningLib = function() {
1409 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
1410 var items = $scope.holdingsGridControls.selectedItems();
1411 if (!xfer_target || !items.length) {
1414 var vols_to_move = {};
1415 var copies_to_move = {};
1416 angular.forEach(items, function(item) {
1417 if (item.call_number.owning_lib != xfer_target) {
1418 if (item.call_number.id in vols_to_move) {
1419 copies_to_move[item.call_number.id].push(item.id);
1421 vols_to_move[item.call_number.id] = item.call_number;
1422 copies_to_move[item.call_number.id] = new Array;
1423 copies_to_move[item.call_number.id].push(item.id);
1429 angular.forEach(vols_to_move, function(vol) {
1430 promises.push(egCore.net.request(
1432 'open-ils.cat.call_number.find_or_create',
1433 egCore.auth.token(),
1440 ).then(function(resp) {
1441 var evt = egCore.evt.parse(resp);
1443 return egCore.net.request(
1445 'open-ils.cat.transfer_copies_to_volume',
1446 egCore.auth.token(),
1448 copies_to_move[vol.id]
1452 $q.all(promises).then(function() {
1453 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1454 holdingsSvcInst.fetchAgain().then(function() {
1455 $scope.holdingsGridDataProvider.refresh();
1460 $scope.transferItems = function (){
1461 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
1462 var copy_ids = gatherSelectedHoldingsIds();
1463 if (xfer_target && copy_ids.length > 0) {
1466 'open-ils.cat.transfer_copies_to_volume',
1467 egCore.auth.token(),
1471 function(resp) { // oncomplete
1472 var evt = egCore.evt.parse(resp);
1474 egConfirmDialog.open(
1475 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1476 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1477 {'evt_desc': evt.desc}
1478 ).result.then(function() {
1481 'open-ils.cat.transfer_copies_to_volume.override',
1482 egCore.auth.token(),
1485 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1486 ).then(function(resp) {
1487 holdingsSvcInst.fetchAgain().then(function() {
1488 $scope.holdingsGridDataProvider.refresh();
1493 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1494 holdingsSvcInst.fetchAgain().then(function() {
1495 $scope.holdingsGridDataProvider.refresh();
1505 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1507 gatherSelectedHoldingsIds(),
1509 var url = egCore.env.basePath +
1510 'cat/item/' + cid + '/triggered_events';
1511 $timeout(function() { $window.open(url, '_blank') });
1516 $scope.selectedHoldingsItemStatusHolds = function (){
1518 gatherSelectedHoldingsIds(),
1520 var url = egCore.env.basePath +
1521 'cat/item/' + cid + '/holds';
1522 $timeout(function() { $window.open(url, '_blank') });
1527 $scope.selectedHoldingsPrintLabels = function() {
1530 'open-ils.actor.anon_cache.set_value',
1531 null, 'print-labels-these-copies', {
1532 copies : gatherSelectedHoldingsIds()
1534 ).then(function(key) {
1536 var url = egCore.env.basePath + 'cat/printlabels/' + key;
1537 $timeout(function() { $window.open(url, '_blank') });
1539 alert('Could not create anonymous cache key!');
1544 $scope.selectedHoldingsDamaged = function () {
1545 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
1546 holdingsSvcInst.fetchAgain().then(function() {
1547 $scope.holdingsGridDataProvider.refresh();
1552 $scope.selectedHoldingsMissing = function () {
1553 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1554 holdingsSvcInst.fetchAgain().then(function() {
1555 $scope.holdingsGridDataProvider.refresh();
1560 $scope.attach_to_peer_bib = function() {
1561 var copy_list = gatherSelectedHoldingsIds();
1562 if (copy_list.length == 0) return;
1564 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1565 if (!target_record) return;
1567 return $uibModal.open({
1568 templateUrl: './cat/catalog/t_conjoined_selector',
1572 ['$scope','$uibModalInstance',
1573 function($scope , $uibModalInstance) {
1574 $scope.update = false;
1576 $scope.peer_type = null;
1577 $scope.peer_type_list = [];
1578 conjoinedSvc.get_peer_types().then(function(list){
1579 $scope.peer_type_list = list;
1582 $scope.ok = function(type) {
1585 angular.forEach(copy_list, function (cp) {
1586 var n = new egCore.idl.bpbcm();
1588 n.peer_record(target_record);
1591 promises.push(egCore.pcrud.create(n));
1594 return $q.all(promises).then(function(){$uibModalInstance.close()});
1597 $scope.cancel = function($event) {
1598 $uibModalInstance.dismiss();
1599 $event.preventDefault();
1607 // ------------------------------------------------------------------
1609 var provider = egGridDataProvider.instance({});
1610 $scope.hold_grid_data_provider = provider;
1611 $scope.grid_actions = egHoldGridActions;
1612 $scope.grid_actions.refresh = function () { provider.refresh() };
1613 $scope.hold_grid_controls = {};
1615 var hold_ids = []; // current list of holds
1616 function fetchHolds(offset, count) {
1617 var ids = hold_ids.slice(offset, offset + count);
1619 return egHolds.fetch_holds(ids).then(null, null,
1620 function(hold_data) {
1626 provider.get = function(offset, count) {
1627 if ($scope.record_tab != 'holds') return $q.when();
1628 var deferred = $q.defer();
1629 hold_ids = []; // no caching ATM
1631 // open a determinate progress dialog, max value set below.
1632 egProgressDialog.open({max : 1, value : 0});
1637 'open-ils.circ.holds.retrieve_all_from_title',
1638 egCore.auth.token(), $scope.record_id,
1639 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
1641 function(hold_data) {
1642 hold_ids = []; // clear the list of ids, hack to avoid dups
1643 // TODO: fix the underlying problem, which is that
1644 // this gets called twice when switching to the holds
1645 // tab; once explicitly, and once via the change handler
1646 // on the OU selector
1647 angular.forEach(hold_data, function(list, type) {
1648 hold_ids = hold_ids.concat(list);
1651 // Set the max value of the progress bar to the lesser of
1652 // the total number of holds to fetch or the page size
1654 egProgressDialog.update(
1655 {max : Math.min(hold_ids.length, count)});
1657 var holds_fetched = 0;
1658 fetchHolds(offset, count)
1659 .then(deferred.resolve, null,
1660 function(hold_data) {
1662 deferred.notify(hold_data);
1663 egProgressDialog.increment();
1665 )['finally'](egProgressDialog.close);
1669 return deferred.promise;
1672 $scope.detail_view = function(action, user_data, items) {
1674 $scope.detail_hold_id = h.hold.id();
1678 $scope.list_view = function(items) {
1679 $scope.detail_hold_id = null;
1682 // refresh the list of record holds when the pickup lib is changed.
1683 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1684 $scope.pickup_ou_changed = function(org) {
1685 $scope.pickup_ou = org;
1689 $scope.print_holds = function() {
1691 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1693 hold : egCore.idl.toHash(item.hold),
1694 patron_last : item.patron_last,
1695 patron_alias : item.patron_alias,
1696 patron_barcode : item.patron_barcode,
1697 copy : egCore.idl.toHash(item.copy),
1698 volume : egCore.idl.toHash(item.volume),
1699 title : item.mvr.title(),
1700 author : item.mvr.author()
1704 egCore.print.print({
1705 context : 'receipt',
1706 template : 'holds_for_bib',
1707 scope : {holds : holds}
1711 $scope.current_hold_transfer_dest = egCore.hatch.getLocalItem ('eg.circ.hold.title_transfer_target');
1713 $scope.mark_hold_transfer_dest = function() {
1714 $scope.current_hold_transfer_dest = $scope.record_id;
1715 egCore.hatch.setLocalItem(
1716 'eg.circ.hold.title_transfer_target', $scope.record_id);
1717 ngToast.create(egCore.strings.HOLD_TRANSFER_DEST_MARKED);
1720 // UI presents this option as "all holds"
1721 $scope.transfer_holds_to_marked = function() {
1722 var hold_ids = $scope.hold_grid_controls.allItems().map(
1723 function(hold_data) {return hold_data.hold.id()});
1724 egHolds.transfer_to_marked_title(hold_ids);
1727 // ------------------------------------------------------------------
1728 // Initialize the selected tab
1730 // we explicitly initialize catalog_url because otherwise Firefox
1731 // ends up setting it to $BASE_URL/{{url}}, which then messes
1732 // things up. See LP#1708951
1733 $scope.catalog_url = '';
1735 function init_cat_url() {
1736 // Set the initial catalog URL. This only happens once.
1737 // The URL is otherwise generated through user navigation.
1738 if ($scope.catalog_url) return;
1740 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1742 // A record ID in the path indicates a request for the record-
1744 if ($routeParams.record_id) {
1745 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1748 // Jumping directly to the results page by passing a search
1749 // query via the URL. Copy all URL params to the iframe url.
1750 if ($location.path().match(/catalog\/results/)) {
1751 url = url.replace(/advanced/, '/results?');
1753 angular.forEach($location.search(), function(val, key) {
1754 if (!first) url += '&';
1756 url += encodeURIComponent(key)
1757 + '=' + encodeURIComponent(val);
1761 // if we're displaying the advanced search form, select
1762 // whatever default pane the user has chosen via workstation
1764 if (url.match(/\/opac\/advanced$/)) {
1765 var adv_pane = egCore.hatch.getLocalItem('eg.search.adv_pane');
1767 url += '?pane=' + encodeURIComponent(adv_pane);
1771 $scope.catalog_url = url;
1774 function init_parts_url() {
1775 $scope.parts_url = $location
1779 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1783 $scope.set_record_tab = function(tab) {
1784 $scope.record_tab = tab;
1797 $scope.detail_hold_record_id = $scope.record_id;
1798 // refresh the holds grid
1805 $scope.set_default_record_tab = function() {
1806 egCore.hatch.setLocalItem(
1807 'eg.cat.default_record_tab', $scope.record_tab);
1808 $timeout(function(){$scope.default_tab = $scope.record_tab});
1812 if ($scope.record_id) {
1813 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1814 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1817 tab = $routeParams.record_tab || 'catalog';
1819 $scope.set_record_tab(tab);
1823 .controller('AuthorityCtrl',
1824 ['$scope','$routeParams','$location','$window','$q','egCore',
1825 function($scope , $routeParams , $location , $window , $q , egCore) {
1827 // set record ID on page load if available...
1828 $scope.authority_id = $routeParams.authority_id;
1830 if ($routeParams.authority_id) $scope.from_route = true;
1831 else $scope.from_route = false;
1833 $scope.stop_unload = false;
1836 .controller('URLVerifyCtrl',
1837 ['$scope','$location',
1838 function($scope , $location) {
1839 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1842 .controller('VandelayCtrl',
1843 ['$scope','$location', 'egCore', '$uibModal',
1844 function($scope , $location, egCore, $uibModal) {
1845 $scope.vandelay_url = $location.absUrl().replace(/\/staff\/cat\/catalog\/vandelay/, '/vandelay/vandelay');
1847 $scope.funcs.edit_marc_modal = function(bre, callback){
1848 var marcArgs = { 'marc_xml': bre.marc() };
1849 var vqbibrecId = bre.id();
1851 templateUrl: './cat/catalog/t_edit_marc_modal',
1854 controller: ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
1855 $scope.focusMe = true;
1856 $scope.recordId = vqbibrecId;
1857 $scope.args = marcArgs;
1858 $scope.dirty_flag = false;
1859 $scope.ok = function(marg){
1860 $uibModalInstance.close(marg);
1862 $scope.cancel = function(){ $uibModalInstance.dismiss() }
1864 }).result.then(function(res){
1865 var new_xml = res.marc_xml;
1866 egCore.pcrud.retrieve('vqbr', vqbibrecId).then(function(vqbib){
1867 vqbib.marc(new_xml);
1868 egCore.pcrud.update(vqbib).then( function(){ callback(vqbibrecId); });
1874 .controller('ManageAuthoritiesCtrl',
1875 ['$scope','$location',
1876 function($scope , $location) {
1877 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1880 .controller('BatchEditCtrl',
1881 ['$scope','$location','$routeParams',
1882 function($scope , $location , $routeParams) {
1883 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1884 if ($routeParams.container_type) {
1885 switch ($routeParams.container_type) {
1887 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1890 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1897 .filter('boolText', function(){
1898 return function (v) {
1903 .factory('conjoinedSvc',
1905 function(egCore , $q) {
1908 items : [], // record search results
1909 index : 0, // search grid index
1916 bpbcm : ['target_copy','peer_type'],
1917 acp : ['call_number'],
1919 bre : ['simple_record']
1921 // avoid fetching the MARC blob by specifying which
1922 // fields on the bre to select. More may be needed.
1923 // note that fleshed fields are explicitly selected.
1924 select : { bre : ['id'] },
1925 order_by : { bpbcm : ['id'] },
1928 // resolved with the last received copy
1929 service.fetch = function(rid) {
1930 if (!rid && !service.rid) return $q.when();
1932 if (rid) service.rid = rid;
1936 return egCore.pcrud.search(
1938 {peer_record : service.rid},
1941 ).then( function(list) { // finished
1942 service.items = list;
1943 return service.items;
1947 // returns a promise resolved with the list of peer bib types
1948 service.get_peer_types = function() {
1950 return $q.when(egCore.env.bpt.list);
1952 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
1953 .then(function(list) {
1954 egCore.env.absorbList(list, 'bpt');