4 * currently, this app doesn't use routes for each sub-ui, because
5 * reloading the catalog each time is sloooow. better so far to
6 * swap out divs w/ ng-if / ng-show / ng-hide as needed.
10 angular.module('egCatalogApp', ['ui.bootstrap','ngRoute','ngLocationUpdate','egCoreMod','egGridMod', 'egMarcMod', 'egUserMod', 'egHoldingsMod', 'ngToast','egPatronSearchMod',
11 'egSerialsMod','egSerialsAppDep'])
13 .config(['ngToastProvider', function(ngToastProvider) {
14 ngToastProvider.configure({
15 verticalPosition: 'bottom',
20 .config(function($routeProvider, $locationProvider, $compileProvider) {
21 $locationProvider.html5Mode(true);
22 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|mailto|blob):/); // grid export
24 var resolver = {delay : ['egCore','egStartup','egUser', function(egCore, egStartup, egUser) {
25 egCore.env.classLoaders.aous = function() {
26 return egCore.org.settings([
27 'cat.marc_control_number_identifier'
28 ]).then(function(settings) {
29 // local settings are cached within egOrg. Caching them
30 // again in egEnv just simplifies the syntax for access.
31 egCore.env.aous = settings;
34 egCore.env.loadClasses.push('aous');
38 $routeProvider.when('/cat/catalog/index', {
39 templateUrl: './cat/catalog/t_catalog',
40 controller: 'CatalogCtrl',
44 // Jump directly to the results page. Any URL parameter
45 // supported by the embedded catalog is supported here.
46 $routeProvider.when('/cat/catalog/results', {
47 templateUrl: './cat/catalog/t_catalog',
48 controller: 'CatalogCtrl',
52 $routeProvider.when('/cat/catalog/retrieve_by_id', {
53 templateUrl: './cat/catalog/t_retrieve_by_id',
54 controller: 'CatalogRecordRetrieve',
58 $routeProvider.when('/cat/catalog/retrieve_by_tcn', {
59 templateUrl: './cat/catalog/t_retrieve_by_tcn',
60 controller: 'CatalogRecordRetrieve',
64 $routeProvider.when('/cat/catalog/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 ($scope.record_id) {
263 // TODO: Apply tab-specific title contexts
264 egCore.strings.setPageTitle(
265 egCore.strings.PAGE_TITLE_BIB_DETAIL,
266 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT,
267 {record_id : $scope.record_id}
270 // Default to title = Catalog
271 egCore.strings.setPageTitle(
272 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT);
275 if ($routeParams.record_id) $scope.from_route = true;
276 else $scope.from_route = false;
278 // set search and preferred library cookies
279 egCore.hatch.getItem('eg.search.search_lib').then(function(val) {
280 $cookies.put('eg_search_lib', val, { path : '/' });
282 egCore.hatch.getItem('eg.search.pref_lib').then(function(val) {
283 $cookies.put('eg_pref_lib', val, { path : '/' });
286 // will hold a ref to the opac iframe
287 $scope.opac_iframe = null;
288 $scope.parts_iframe = null;
290 $scope.search_result_index = 1;
291 $scope.search_result_hit_count = 1;
294 'opac_iframe.dom.contentWindow.search_result_index',
296 if (!isNaN(parseInt(n)))
297 $scope.search_result_index = n + 1;
302 'opac_iframe.dom.contentWindow.search_result_hit_count',
304 if (!isNaN(parseInt(n)))
305 $scope.search_result_hit_count = n;
309 $scope.in_opac_call = false;
310 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
311 if ($scope.opac_iframe) {
312 if (force_opac_tab) $scope.record_tab = 'catalog';
313 $scope.in_opac_call = true;
314 $scope.opac_iframe.dom.contentWindow[opac_frame_function]();
315 if (opac_frame_function == 'rdetailBackToResults') {
316 $location.update_path('/cat/catalog/index');
321 $scope.add_to_record_bucket = function() {
322 var recId = $scope.record_id;
323 return $uibModal.open({
324 templateUrl: './cat/catalog/t_add_to_bucket',
329 ['$scope','$uibModalInstance',
330 function($scope , $uibModalInstance) {
332 $scope.bucket_id = 0;
333 $scope.newBucketName = '';
334 $scope.allBuckets = [];
337 'open-ils.actor.container.retrieve_by_class.authoritative',
338 egCore.auth.token(), egCore.auth.user().id(),
339 'biblio', 'staff_client'
340 ).then(function(buckets) { $scope.allBuckets = buckets; });
342 $scope.add_to_bucket = function() {
343 var item = new egCore.idl.cbrebi();
344 item.bucket($scope.bucket_id);
345 item.target_biblio_record_entry(recId);
348 'open-ils.actor.container.item.create',
349 egCore.auth.token(), 'biblio', item
350 ).then(function(resp) {
351 $uibModalInstance.close();
355 $scope.add_to_new_bucket = function() {
356 var bucket = new egCore.idl.cbreb();
357 bucket.owner(egCore.auth.user().id());
358 bucket.name($scope.newBucketName);
359 bucket.description('');
360 bucket.btype('staff_client');
364 'open-ils.actor.container.create',
365 egCore.auth.token(), 'biblio', bucket
366 ).then(function(bucket) {
367 $scope.bucket_id = bucket;
368 $scope.add_to_bucket();
372 $scope.cancel = function() {
373 $uibModalInstance.dismiss();
379 $scope.current_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record');
380 $scope.current_transfer_target = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
381 $scope.current_conjoined_target = egCore.hatch.getLocalItem('eg.cat.marked_conjoined_record');
383 $scope.quickReceive = function () {
385 var next_per_stream = {};
387 var recId = $scope.record_id;
388 return $uibModal.open({
389 templateUrl: './share/t_subscription_select_dialog',
391 controller: ['$scope', '$uibModalInstance',
392 function($scope, $uibModalInstance) {
395 $scope.rememberMe = 'eg.serials.quickreceive.last_org';
396 $scope.record_id = recId;
397 $scope.ssubId = null;
399 $scope.ok = function() { $uibModalInstance.close($scope.ssubId) }
400 $scope.cancel = function() { $uibModalInstance.dismiss(); }
403 }).result.then(function(ssubId) {
406 promises.push(egSerialsCoreSvc.fetchItemsForSub(ssubId,{status:'Expected'}).then(function(){
407 angular.forEach(egSerialsCoreSvc.itemTree, function (item) {
408 if (next_per_stream[item.stream().id()]) return;
409 if (item.status() == 'Expected') {
410 next_per_stream[item.stream().id()] = item;
411 list.push(egCore.idl.Clone(item));
416 return $q.all(promises).then(function() {
419 ngToast.warning(egCore.strings.SERIALS_NO_ITEMS);
423 return egSerialsCoreSvc.process_items(
429 false, // print by default
430 function() { $scope.holdings_record_id_changed($scope.record_id) }
434 ngToast.warning(egCore.strings.SERIALS_NO_SUBS);
440 $scope.markConjoined = function () {
441 $scope.current_conjoined_target = $scope.record_id;
442 egCore.hatch.setLocalItem('eg.cat.marked_conjoined_record',$scope.record_id);
443 ngToast.create(egCore.strings.MARK_CONJ_TARGET);
446 $scope.markHoldingsTransfer = function () {
447 $scope.current_transfer_target = $scope.record_id;
448 egCore.hatch.setLocalItem('eg.cat.transfer_target_record',$scope.record_id);
449 egCore.hatch.removeLocalItem('eg.cat.transfer_target_lib');
450 egCore.hatch.removeLocalItem('eg.cat.transfer_target_vol');
451 ngToast.create(egCore.strings.MARK_HOLDINGS_TARGET);
454 $scope.markOverlay = function () {
455 $scope.current_overlay_target = $scope.record_id;
456 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.record_id);
457 ngToast.create(egCore.strings.MARK_OVERLAY_TARGET);
460 $scope.clearRecordMarks = function () {
461 $scope.current_overlay_target = null;
462 $scope.current_transfer_target = null;
463 $scope.current_conjoined_target = null;
464 $scope.current_hold_transfer_dest = null;
465 egCore.hatch.removeLocalItem('eg.cat.transfer_target_record');
466 egCore.hatch.removeLocalItem('eg.cat.marked_conjoined_record');
467 egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');
468 egCore.hatch.removeLocalItem('eg.circ.hold.title_transfer_target');
471 $scope.stop_unload = false;
472 $scope.$watch('stop_unload',
473 function(newVal, oldVal) {
474 if (newVal && newVal != oldVal && $scope.opac_iframe) {
475 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
476 return 'There is unsaved data in this record.'
479 if ($scope.opac_iframe)
480 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
485 // Set the "last bib" cookie, if we have that
486 if ($scope.record_id)
487 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
489 $scope.refresh_record_callback = function (record_id) {
490 egCore.pcrud.retrieve('bre', record_id, {
493 bre : ['simple_record','creator','editor']
495 }).then(function(rec) {
496 rec.owner(egCore.org.get(rec.owner()));
497 $scope.summary_pane_record = rec;
503 patron_search_dialog = function() {
504 return $uibModal.open({
505 templateUrl: './share/t_patron_selector',
510 ['$scope','$uibModalInstance','$controller',
511 function($scope , $uibModalInstance , $controller) {
512 angular.extend(this, $controller('BasePatronSearchCtrl', {$scope : $scope}));
514 $scope.need_one_selected = function() {
515 var items = $scope.gridControls.selectedItems();
516 return (items.length == 1) ? false : true
518 $scope.ok = function() {
519 var items = $scope.gridControls.selectedItems();
520 if (items.length == 1) {
521 $uibModalInstance.close(items[0].card().barcode());
523 $uibModalInstance.close()
526 $scope.cancel = function($event) {
527 $uibModalInstance.dismiss();
528 $event.preventDefault();
534 // also set it when the iframe changes to a new record
535 $scope.handle_page = function(url) {
537 if (!url || url == 'about:blank') {
538 // nothing loaded. If we already have a record ID, leave it.
542 var match = url.match(/\/+opac\/+record\/+(\d+)/);
544 $scope.record_id = match[1];
545 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
546 $scope.holdings_record_id_changed($scope.record_id);
547 conjoinedSvc.fetch($scope.record_id).then(function(){
548 $scope.conjoinedGridDataProvider.refresh();
550 egHolds.fetch_holds(hold_ids).then($scope.hold_grid_data_provider.refresh);
552 $location.update_path('/cat/catalog/record/' + $scope.record_id);
553 // update_path() bypasses the controller for path
554 // /cat/catalog/record/:record_id. Manually set title here too.
555 egCore.strings.setPageTitle(
556 egCore.strings.PAGE_TITLE_BIB_DETAIL,
557 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT,
558 {record_id : $scope.record_id}
561 delete $scope.record_id;
562 $scope.from_route = false;
565 // child scope is executing this function, so our digest doesn't fire ... thus,
568 if (!$scope.in_opac_call) {
569 if ($scope.record_id && !$scope.record_tab) {
570 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
571 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
573 tab = $routeParams.record_tab || 'catalog';
575 $scope.set_record_tab(tab);
577 $scope.in_opac_call = false;
580 if ($scope.opac_iframe && $location.path().match(/cat\/catalog/)) {
581 var doc = $scope.opac_iframe.dom.contentWindow.document;
582 $(doc).find('#hold_usr_search').show();
583 $(doc).find('#hold_usr_search').on('click', function() {
584 patron_search_dialog().result.then(function(barc) {
585 $(doc).find('#hold_usr_input').val(barc);
586 $(doc).find('#hold_usr_input').change();
593 // xulG catalog handlers
594 $scope.handlers = { }
596 // ------------------------------------------------------------------
599 $scope.conjoinedGridControls = {};
600 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
601 get : function(offset, count) {
602 return this.arrayNotifier(conjoinedSvc.items, offset, count);
606 $scope.changeConjoinedType = function () {
607 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
608 angular.forEach(peers, function (p) {
609 p.target_copy(p.target_copy().id());
610 p.peer_type(p.peer_type().id());
613 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
615 return $uibModal.open({
616 templateUrl: './cat/catalog/t_conjoined_selector',
620 ['$scope','$uibModalInstance',
621 function($scope , $uibModalInstance) {
622 $scope.update = true;
624 $scope.peer_type = null;
625 $scope.peer_type_list = [];
626 conjoinedSvc.get_peer_types().then(function(list){
627 $scope.peer_type_list = list;
630 $scope.ok = function(type) {
633 angular.forEach(peers, function (p) {
636 promises.push(egCore.pcrud.update(p));
639 return $q.all(promises)
640 .then(function(){$uibModalInstance.close()})
641 .then(function(){return conjoinedSvc.fetch()})
642 .then(function(){conjoinedGridDataProviderRef.refresh()});
645 $scope.cancel = function($event) {
646 $uibModalInstance.dismiss();
647 $event.preventDefault();
654 $scope.refreshConjoined = function () {
655 conjoinedSvc.fetch($scope.record_id)
656 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
659 $scope.deleteSelectedConjoined = function () {
660 var peers = $scope.conjoinedGridControls.selectedItems();
662 if (peers.length > 0) {
663 egConfirmDialog.open(
664 egCore.strings.CONFIRM_DELETE_PEERS,
665 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
666 {peers : peers.length}
667 ).result.then(function() {
668 angular.forEach(peers, function (p) {
672 egCore.pcrud.remove(peers).then(function() {
673 return conjoinedSvc.fetch();
675 $scope.conjoinedGridDataProvider.refresh();
680 if ($scope.record_id)
681 conjoinedSvc.fetch($scope.record_id);
683 // ------------------------------------------------------------------
686 $scope.holdingsGridControls = {
687 activateItem : function (item) {
688 $scope.selectedHoldingsVolCopyEdit();
691 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
692 get : function(offset, count) {
693 return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
697 $scope.add_copies_to_bucket = function() {
698 var copy_list = gatherSelectedHoldingsIds();
699 if (copy_list.length == 0) return;
701 return $uibModal.open({
702 templateUrl: './cat/catalog/t_add_to_bucket',
707 ['$scope','$uibModalInstance',
708 function($scope , $uibModalInstance) {
710 $scope.bucket_id = 0;
711 $scope.newBucketName = '';
712 $scope.allBuckets = [];
716 'open-ils.actor.container.retrieve_by_class.authoritative',
717 egCore.auth.token(), egCore.auth.user().id(),
718 'copy', 'staff_client'
719 ).then(function(buckets) { $scope.allBuckets = buckets; });
721 $scope.add_to_bucket = function() {
723 angular.forEach(copy_list, function (cp) {
724 var item = new egCore.idl.ccbi()
725 item.bucket($scope.bucket_id);
726 item.target_copy(cp);
730 'open-ils.actor.container.item.create',
731 egCore.auth.token(), 'copy', item
735 return $q.all(promises).then(function() {
736 $uibModalInstance.close();
741 $scope.add_to_new_bucket = function() {
742 var bucket = new egCore.idl.ccb();
743 bucket.owner(egCore.auth.user().id());
744 bucket.name($scope.newBucketName);
745 bucket.description('');
746 bucket.btype('staff_client');
748 return egCore.net.request(
750 'open-ils.actor.container.create',
751 egCore.auth.token(), 'copy', bucket
752 ).then(function(bucket) {
753 $scope.bucket_id = bucket;
754 $scope.add_to_bucket();
758 $scope.cancel = function() {
759 $uibModalInstance.dismiss();
765 // TODO: refactor common code between cat/catalog/app.js and cat/item/app.js
767 $scope.need_one_selected = function() {
768 var items = $scope.holdingsGridControls.selectedItems();
769 if (items.length == 1) return false;
773 $scope.make_copies_bookable = function() {
775 var copies_by_record = {};
776 var record_list = [];
778 $scope.holdingsGridControls.selectedItems(),
780 var record_id = item['call_number.record.id'];
781 if (typeof copies_by_record[ record_id ] == 'undefined') {
782 copies_by_record[ record_id ] = [];
783 record_list.push( record_id );
785 copies_by_record[ record_id ].push(item.id);
790 var combined_results = [];
791 angular.forEach(record_list, function(record_id) {
795 'open-ils.booking.resources.create_from_copies',
797 copies_by_record[record_id]
798 ).then(function(results) {
799 if (results && results['brsrc']) {
800 combined_results = combined_results.concat(results['brsrc']);
806 $q.all(promises).then(function() {
807 if (combined_results.length > 0) {
809 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
814 ['$scope','$location','egCore','$uibModalInstance',
815 function($scope , $location , egCore , $uibModalInstance) {
818 ses : egCore.auth.token(),
819 resultant_brsrc : combined_results.map(function(o) { return o[0]; })
822 var booking_path = '/eg/conify/global/booking/resource';
824 $scope.booking_admin_url =
825 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
832 $scope.book_copies_now = function() {
833 var copies_by_record = {};
834 var record_list = [];
836 $scope.holdingsGridControls.selectedItems(),
838 var record_id = item['call_number.record.id'];
839 if (typeof copies_by_record[ record_id ] == 'undefined') {
840 copies_by_record[ record_id ] = [];
841 record_list.push( record_id );
843 copies_by_record[ record_id ].push(item.id);
848 var combined_brt = [];
849 var combined_brsrc = [];
850 angular.forEach(record_list, function(record_id) {
854 'open-ils.booking.resources.create_from_copies',
856 copies_by_record[record_id]
857 ).then(function(results) {
858 if (results && results['brt']) {
859 combined_brt = combined_brt.concat(results['brt']);
861 if (results && results['brsrc']) {
862 combined_brsrc = combined_brsrc.concat(results['brsrc']);
868 $q.all(promises).then(function() {
869 if (combined_brt.length > 0 || combined_brsrc.length > 0) {
871 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
876 ['$scope','$location','egCore','$uibModalInstance',
877 function($scope , $location , egCore , $uibModalInstance) {
880 ses : egCore.auth.token(),
881 bresv_interface_opts : {
884 ,brsrc : combined_brsrc
889 var booking_path = '/eg/booking/reservation';
891 $scope.booking_admin_url =
892 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
901 $scope.requestItems = function() {
902 var copy_list = gatherSelectedHoldingsIds();
903 if (copy_list.length == 0) return;
905 return $uibModal.open({
906 templateUrl: './cat/catalog/t_request_items',
909 ['$scope','$uibModalInstance',
910 function($scope , $uibModalInstance) {
912 $scope.first_user_fetch = true;
916 copy_list : copy_list,
917 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
918 user : egCore.auth.user().id()
921 egUser.get( $scope.hold_data.user ).then(function(u) {
923 $scope.barcode = u.card().barcode();
924 $scope.user_name = egUser.format_name(u);
925 $scope.hold_data.user = u.id();
928 $scope.user_name = '';
930 $scope.$watch('barcode', function (n) {
931 if (!$scope.first_user_fetch) {
932 egUser.getByBarcode(n).then(function(u) {
934 $scope.user_name = egUser.format_name(u);
935 $scope.hold_data.user = u.id();
938 $scope.user_name = '';
939 delete $scope.hold_data.user;
942 $scope.first_user_fetch = false;
945 $scope.ok = function(h) {
948 hold_type : h.hold_type,
949 pickup_lib: h.pickup_lib.id(),
955 'open-ils.circ.holds.test_and_create.batch.override',
956 egCore.auth.token(), args, h.copy_list
959 $uibModalInstance.close();
962 $scope.cancel = function($event) {
963 $uibModalInstance.dismiss();
964 $event.preventDefault();
970 $scope.view_place_orders = function() {
971 if (!$scope.record_id) return;
972 var url = egCore.env.basePath + 'acq/legacy/lineitem/related/' + $scope.record_id + '?target=bib';
973 $timeout(function() { $window.open(url, '_blank') });
976 $scope.replaceBarcodes = function() {
977 var copy_list = gatherSelectedRawCopies();
978 if (copy_list.length == 0) return;
980 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
982 angular.forEach(copy_list, function (cp) {
984 templateUrl: './cat/share/t_replace_barcode',
988 ['$scope','$uibModalInstance',
989 function($scope , $uibModalInstance) {
990 $scope.isModal = true;
991 $scope.focusBarcode = false;
992 $scope.focusBarcode2 = true;
993 $scope.barcode1 = cp.barcode();
995 $scope.updateBarcode = function() {
996 $scope.copyNotFound = false;
997 $scope.updateOK = false;
999 egCore.pcrud.search('acp',
1000 {deleted : 'f', barcode : $scope.barcode1})
1001 .then(function(copy) {
1004 $scope.focusBarcode = true;
1005 $scope.copyNotFound = true;
1009 $scope.copyId = copy.id();
1010 copy.barcode($scope.barcode2);
1012 egCore.pcrud.update(copy).then(function(stat) {
1013 $scope.updateOK = stat;
1014 $scope.focusBarcode = true;
1015 holdingsSvc.fetchAgain().then(function (){
1016 holdingsGridDataProviderRef.refresh();
1021 $uibModalInstance.close();
1024 $scope.cancel = function($event) {
1025 $uibModalInstance.dismiss();
1026 $event.preventDefault();
1034 // refresh the list of holdings when the record_id is changed.
1035 $scope.holdings_record_id_changed = function(id) {
1036 if ($scope.record_id != id) $scope.record_id = id;
1037 console.log('record id changed to ' + id + ', loading new holdings');
1038 holdingsSvcInst.fetch({
1039 rid : $scope.record_id,
1040 org : $scope.holdings_ou,
1041 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1042 vol : $scope.holdings_show_vols,
1043 empty: $scope.holdings_show_empty,
1044 empty_org: $scope.holdings_show_empty_org
1045 }).then(function() {
1046 $scope.holdingsGridDataProvider.refresh();
1050 // refresh the list of holdings when the filter lib is changed.
1051 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
1052 $scope.holdings_ou_changed = function(org) {
1053 $scope.holdings_ou = org;
1054 holdingsSvcInst.fetch({
1055 rid : $scope.record_id,
1056 org : $scope.holdings_ou,
1057 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1058 vol : $scope.holdings_show_vols,
1059 empty: $scope.holdings_show_empty,
1060 empty_org: $scope.holdings_show_empty_org
1061 }).then(function() {
1062 $scope.holdingsGridDataProvider.refresh();
1066 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
1067 $scope[cb] = newVal;
1068 var x = $scope.holdings_show_vols ? $scope.holdings_show_copies : false;
1069 $('#holdings_show_copies').prop('checked', x);
1070 egCore.hatch.setItem('cat.' + cb, newVal);
1071 if (!norefresh) holdingsSvcInst.fetch({
1072 rid : $scope.record_id,
1073 org : $scope.holdings_ou,
1074 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1075 vol : $scope.holdings_show_vols,
1076 empty: $scope.holdings_show_empty,
1077 empty_org: $scope.holdings_show_empty_org
1078 }).then(function() {
1079 $scope.holdingsGridDataProvider.refresh();
1083 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
1084 if (typeof x == 'undefined') x = true;
1085 $scope.holdings_cb_changed('holdings_show_vols',x,true);
1086 $('#holdings_show_vols').prop('checked', x);
1088 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
1089 if (typeof x == 'undefined') x = true;
1090 $scope.holdings_cb_changed('holdings_show_copies',x,true);
1091 x = $scope.holdings_show_vols ? x : false;
1092 $('#holdings_show_copies').prop('checked', x);
1094 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
1095 if (typeof x == 'undefined') x = true;
1096 $scope.holdings_cb_changed('holdings_show_empty',x);
1097 $('#holdings_show_empty').prop('checked', x);
1099 egCore.hatch.getItem('cat.holdings_show_empty_org').then(function(x){
1100 if (typeof x == 'undefined') x = true;
1101 $scope.holdings_cb_changed('holdings_show_empty_org',x);
1102 $('#holdings_show_empty_org').prop('checked', x);
1108 $scope.vols_not_shown = function () {
1109 return !$scope.holdings_show_vols;
1112 $scope.copies_not_shown = function () {
1113 return !$scope.holdings_show_copies;
1116 $scope.empty_org_not_shown = function () {
1117 return !$scope.holdings_show_empty_org;
1120 $scope.holdings_checkbox_handler = function (item) {
1121 $scope.holdings_cb_changed(item.checkbox,item.checked);
1124 function gatherSelectedHoldingsIds () {
1125 var cp_id_list = [];
1127 $scope.holdingsGridControls.selectedItems(),
1128 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
1133 function gatherSelectedRawCopies () {
1136 $scope.holdingsGridControls.selectedItems(),
1137 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
1142 function gatherSelectedEmptyVolumeIds () {
1143 var cn_id_list = [];
1145 $scope.holdingsGridControls.selectedItems(),
1147 if (item.copy_count == 0 || (!item.id && item.call_number))
1148 // we are in a compressed row with no copies, or we are in a single
1149 // call number row with no copy (testing for presence of 'id')
1150 // In either case, the call number is 'empty'
1151 cn_id_list.push(item.call_number.id)
1157 function gatherSelectedVolumeIds () {
1158 var cn_id_list = [];
1160 $scope.holdingsGridControls.selectedItems(),
1162 if (cn_id_list.indexOf(item.call_number.id) == -1)
1163 cn_id_list.push(item.call_number.id)
1169 $scope.selectedHoldingsDelete = function (vols, copies) {
1172 var perCnCopies = {};
1178 $scope.holdingsGridControls.selectedItems(),
1180 if (vols && item.raw_call_number) {
1181 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
1182 cnHash[item.call_number.id].isdeleted(1);
1184 } else if (copies) {
1185 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
1188 var cn_id = cp.call_number().id();
1189 if (!cnHash[cn_id]) {
1190 cnHash[cn_id] = cp.call_number();
1191 perCnCopies[cn_id] = [cp];
1193 perCnCopies[cn_id].push(cp);
1195 cp.call_number(cn_id); // prevent loops in JSON-ification
1202 angular.forEach(perCnCopies, function (v, k) {
1204 cnHash[k].isdeleted(1);
1207 cnHash[k].copies(v);
1211 angular.forEach(cnHash, function (v, k) {
1215 if (cnList.length == 0) return;
1218 if (vols && copies) flags.force_delete_copies = 1;
1220 egConfirmDialog.open(
1221 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
1222 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
1223 {copies : cp_count, volumes : cn_count}
1224 ).result.then(function() {
1227 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1228 egCore.auth.token(), cnList, 1, flags
1229 ).then(function(update_count) {
1230 holdingsSvcInst.fetchAgain().then(function() {
1231 $scope.holdingsGridDataProvider.refresh();
1236 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
1237 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
1238 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
1240 spawnHoldingsAdd = function (add_vols,add_copies){
1242 if (!add_vols && add_copies) { // just a copy on existing volumes
1243 angular.forEach(gatherSelectedVolumeIds(), function (v) {
1244 raw.push( {callnumber : v} );
1246 } else if (add_vols) {
1247 if (typeof $scope.holdingsGridControls.selectedItems == "function" &&
1248 $scope.holdingsGridControls.selectedItems().length > 0) {
1249 angular.forEach($scope.holdingsGridControls.selectedItems(),
1252 owner : item.owner_id,
1253 label : ((item.call_number) ? item.call_number.label : null)
1258 owner : egCore.auth.user().ws_ou()
1263 if (raw.length == 0) raw.push({});
1267 'open-ils.actor.anon_cache.set_value',
1268 null, 'edit-these-copies', {
1269 record_id: $scope.record_id,
1272 hide_copies : !add_copies
1274 ).then(function(key) {
1276 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1277 $timeout(function() { $window.open(url, '_blank') });
1279 alert('Could not create anonymous cache key!');
1283 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,true) }
1284 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
1285 $scope.selectedHoldingsVolAdd = function () { spawnHoldingsAdd(true,false) }
1287 spawnHoldingsEdit = function (hide_vols,hide_copies){
1290 'open-ils.actor.anon_cache.set_value',
1291 null, 'edit-these-copies', {
1292 record_id: $scope.record_id,
1293 copies: gatherSelectedHoldingsIds(),
1294 raw: gatherSelectedEmptyVolumeIds().map(
1295 function(v){ return { callnumber : v } }
1297 hide_vols : hide_vols,
1298 hide_copies : hide_copies
1300 ).then(function(key) {
1302 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1303 $timeout(function() { $window.open(url, '_blank') });
1305 alert('Could not create anonymous cache key!');
1309 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
1310 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
1311 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
1313 $scope.selectedHoldingsItemStatus = function (){
1314 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
1315 $timeout(function() { $window.open(url, '_blank') });
1318 $scope.markFromSelectedAsHoldingsTarget = function() {
1319 egCore.hatch.setLocalItem(
1320 'eg.cat.transfer_target_lib',
1321 $scope.holdingsGridControls.selectedItems()[0].owner_id
1323 egCore.hatch.setLocalItem(
1324 'eg.cat.transfer_target_record',
1327 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed, or we are on an empty lib
1328 egCore.hatch.setLocalItem(
1329 'eg.cat.transfer_target_vol',
1330 $scope.holdingsGridControls.selectedItems()[0].call_number.id
1333 // clear out the stale value if we're on a lib-only
1334 // or vol-collapsed row
1335 egCore.hatch.removeLocalItem('eg.cat.transfer_target_vol');
1337 ngToast.create(egCore.strings.MARK_HOLDINGS_TARGET);
1340 $scope.selectedHoldingsItemStatusDetail = function (){
1342 gatherSelectedHoldingsIds(),
1344 var url = egCore.env.basePath +
1346 $timeout(function() { $window.open(url, '_blank') });
1351 $scope.transferVolumes = function (){
1352 var target_record = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
1353 var target_lib = egCore.hatch.getLocalItem('eg.cat.transfer_target_lib');
1355 && (!target_record || ($scope.record_id == target_record) )
1358 var vols_to_move = {};
1360 // we're moving volumes to a different library
1361 var vol_ids = gatherSelectedVolumeIds();
1362 if (vol_ids.length) {
1363 vols_to_move[target_lib] = vol_ids;
1365 // if we're *only* switching libs,
1366 // grab the current record as the target
1367 target_record = target_record || $scope.record_id;
1370 // we're moving volumes to the same library they exist in
1371 // currently, but on a different record
1372 var items = $scope.holdingsGridControls.selectedItems();
1373 angular.forEach(items, function(item) {
1374 if (!(item.call_number.owning_lib in vols_to_move)) {
1375 vols_to_move[item.call_number.owning_lib] = new Array;
1377 vols_to_move[item.call_number.owning_lib].push(item.call_number.id);
1382 angular.forEach(vols_to_move, function(vols, owning_lib) {
1383 promises.push(egCore.net.request(
1385 'open-ils.cat.asset.volume.batch.transfer.override',
1386 egCore.auth.token(), {
1387 docid : target_record,
1393 $q.all(promises).then(function(success) {
1395 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1396 holdingsSvcInst.fetchAgain().then(function() {
1397 $scope.holdingsGridDataProvider.refresh();
1400 alert('Could not transfer volumes!');
1405 // this "transfers" selected copies to a new owning library,
1406 // auto-creating volumes as required
1407 $scope.transferItemsAutoFill = function() {
1408 var target_record = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
1409 var target_lib = egCore.hatch.getLocalItem('eg.cat.transfer_target_lib');
1411 && (!target_record || ($scope.record_id == target_record) )
1414 var items = $scope.holdingsGridControls.selectedItems();
1415 if (!items.length) {
1419 var vols_to_move = {};
1420 var copies_to_move = {};
1421 angular.forEach(items, function(item) {
1422 var needs_move = false;
1424 && (item.call_number.owning_lib != target_lib)) {
1425 item.call_number.owning_lib = target_lib;
1429 && (item.call_number.record != target_record)) {
1430 item.call_number.record = target_record;
1434 if (item.call_number.id in vols_to_move) {
1435 copies_to_move[item.call_number.id].push(item.id);
1437 vols_to_move[item.call_number.id] = item.call_number;
1438 copies_to_move[item.call_number.id] = new Array;
1439 copies_to_move[item.call_number.id].push(item.id);
1445 angular.forEach(vols_to_move, function(vol) {
1446 promises.push(egCore.net.request(
1448 'open-ils.cat.call_number.find_or_create',
1449 egCore.auth.token(),
1451 vol.record, // may be new
1452 vol.owning_lib, // may be new
1456 ).then(function(resp) {
1457 var evt = egCore.evt.parse(resp);
1459 return egCore.net.request(
1461 'open-ils.cat.transfer_copies_to_volume',
1462 egCore.auth.token(),
1464 copies_to_move[vol.id]
1468 $q.all(promises).then(function() {
1469 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1470 holdingsSvcInst.fetchAgain().then(function() {
1471 $scope.holdingsGridDataProvider.refresh();
1476 $scope.gridCellHandlers = {};
1477 $scope.gridCellHandlers.copyAlertsEdit = function(id) {
1478 egCirc.manage_copy_alerts([id]).then(function() {
1479 // update grid items?
1483 $scope.transferItems = function (){
1484 var xfer_target = egCore.hatch.getLocalItem('eg.cat.transfer_target_vol');
1487 // we have no specific volume, let's try to fill in the
1489 return $scope.transferItemsAutoFill();
1492 var copy_ids = gatherSelectedHoldingsIds();
1493 if (copy_ids.length > 0) {
1496 'open-ils.cat.transfer_copies_to_volume',
1497 egCore.auth.token(),
1501 function(resp) { // oncomplete
1502 var evt = egCore.evt.parse(resp);
1504 egConfirmDialog.open(
1505 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1506 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1507 {'evt_desc': evt.desc}
1508 ).result.then(function() {
1511 'open-ils.cat.transfer_copies_to_volume.override',
1512 egCore.auth.token(),
1515 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1516 ).then(function(resp) {
1517 holdingsSvcInst.fetchAgain().then(function() {
1518 $scope.holdingsGridDataProvider.refresh();
1523 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1524 holdingsSvcInst.fetchAgain().then(function() {
1525 $scope.holdingsGridDataProvider.refresh();
1535 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1537 gatherSelectedHoldingsIds(),
1539 var url = egCore.env.basePath +
1540 'cat/item/' + cid + '/triggered_events';
1541 $timeout(function() { $window.open(url, '_blank') });
1546 $scope.selectedHoldingsItemStatusHolds = function (){
1548 gatherSelectedHoldingsIds(),
1550 var url = egCore.env.basePath +
1551 'cat/item/' + cid + '/holds';
1552 $timeout(function() { $window.open(url, '_blank') });
1557 $scope.selectedHoldingsPrintLabels = function() {
1560 'open-ils.actor.anon_cache.set_value',
1561 null, 'print-labels-these-copies', {
1562 copies : gatherSelectedHoldingsIds()
1564 ).then(function(key) {
1566 var url = egCore.env.basePath + 'cat/printlabels/' + key;
1567 $timeout(function() { $window.open(url, '_blank') });
1569 alert('Could not create anonymous cache key!');
1574 $scope.selectedHoldingsDamaged = function () {
1575 var copy_list = gatherSelectedRawCopies();
1576 if (copy_list.length == 0) return;
1578 angular.forEach(copy_list, function(cp) {
1579 egCirc.mark_damaged({
1581 barcode: cp.barcode(),
1582 circ_lib: cp.circ_lib().id()
1583 }).then(function() {
1584 holdingsSvcInst.fetchAgain().then(function() {
1585 $scope.holdingsGridDataProvider.refresh();
1591 $scope.selectedHoldingsMissing = function () {
1592 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1593 holdingsSvcInst.fetchAgain().then(function() {
1594 $scope.holdingsGridDataProvider.refresh();
1599 $scope.selectedHoldingsCopyAlertsAdd = function() {
1600 egCirc.add_copy_alerts(gatherSelectedHoldingsIds()).then(function() {
1601 // no need to refresh grid
1604 $scope.selectedHoldingsCopyAlertsManage = function() {
1605 egCirc.manage_copy_alerts(gatherSelectedHoldingsIds()).then(function() {
1606 // no need to refresh grid
1610 $scope.attach_to_peer_bib = function() {
1611 var copy_list = gatherSelectedHoldingsIds();
1612 if (copy_list.length == 0) return;
1614 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1615 if (!target_record) return;
1617 return $uibModal.open({
1618 templateUrl: './cat/catalog/t_conjoined_selector',
1622 ['$scope','$uibModalInstance',
1623 function($scope , $uibModalInstance) {
1624 $scope.update = false;
1626 $scope.peer_type = null;
1627 $scope.peer_type_list = [];
1628 conjoinedSvc.get_peer_types().then(function(list){
1629 $scope.peer_type_list = list;
1632 $scope.ok = function(type) {
1635 angular.forEach(copy_list, function (cp) {
1636 var n = new egCore.idl.bpbcm();
1638 n.peer_record(target_record);
1641 promises.push(egCore.pcrud.create(n));
1644 return $q.all(promises).then(function(){$uibModalInstance.close()});
1647 $scope.cancel = function($event) {
1648 $uibModalInstance.dismiss();
1649 $event.preventDefault();
1657 // ------------------------------------------------------------------
1659 var provider = egGridDataProvider.instance({});
1660 $scope.hold_grid_data_provider = provider;
1661 $scope.grid_actions = egHoldGridActions;
1662 $scope.grid_actions.refresh = function () { provider.refresh() };
1663 $scope.hold_grid_controls = {};
1665 var hold_ids = []; // current list of holds
1666 function fetchHolds(offset, count) {
1667 var ids = hold_ids.slice(offset, offset + count);
1669 return egHolds.fetch_holds(ids).then(null, null,
1670 function(hold_data) {
1676 provider.get = function(offset, count) {
1677 if ($scope.record_tab != 'holds') return $q.when();
1678 var deferred = $q.defer();
1679 hold_ids = []; // no caching ATM
1681 // open a determinate progress dialog, max value set below.
1682 egProgressDialog.open({max : 1, value : 0});
1687 'open-ils.circ.holds.retrieve_all_from_title',
1688 egCore.auth.token(), $scope.record_id,
1689 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
1691 function(hold_data) {
1692 hold_ids = []; // clear the list of ids, hack to avoid dups
1693 // TODO: fix the underlying problem, which is that
1694 // this gets called twice when switching to the holds
1695 // tab; once explicitly, and once via the change handler
1696 // on the OU selector
1697 angular.forEach(hold_data, function(list, type) {
1698 hold_ids = hold_ids.concat(list);
1701 // Set the max value of the progress bar to the lesser of
1702 // the total number of holds to fetch or the page size
1704 egProgressDialog.update(
1705 {max : Math.min(hold_ids.length, count)});
1707 var holds_fetched = 0;
1708 fetchHolds(offset, count)
1709 .then(deferred.resolve, null,
1710 function(hold_data) {
1712 deferred.notify(hold_data);
1713 egProgressDialog.increment();
1715 )['finally'](egProgressDialog.close);
1719 return deferred.promise;
1722 $scope.detail_view = function(action, user_data, items) {
1724 $scope.detail_hold_id = h.hold.id();
1728 $scope.list_view = function(items) {
1729 $scope.detail_hold_id = null;
1732 // refresh the list of record holds when the pickup lib is changed.
1733 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1734 $scope.pickup_ou_changed = function(org) {
1735 $scope.pickup_ou = org;
1739 $scope.print_holds = function() {
1741 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1743 hold : egCore.idl.toHash(item.hold),
1744 patron_last : item.patron_last,
1745 patron_alias : item.patron_alias,
1746 patron_barcode : item.patron_barcode,
1747 copy : egCore.idl.toHash(item.copy),
1748 volume : egCore.idl.toHash(item.volume),
1749 title : item.mvr.title(),
1750 author : item.mvr.author()
1754 egCore.print.print({
1755 context : 'receipt',
1756 template : 'holds_for_bib',
1757 scope : {holds : holds}
1761 $scope.current_hold_transfer_dest = egCore.hatch.getLocalItem ('eg.circ.hold.title_transfer_target');
1763 $scope.mark_hold_transfer_dest = function() {
1764 $scope.current_hold_transfer_dest = $scope.record_id;
1765 egCore.hatch.setLocalItem(
1766 'eg.circ.hold.title_transfer_target', $scope.record_id);
1767 ngToast.create(egCore.strings.HOLD_TRANSFER_DEST_MARKED);
1770 // UI presents this option as "all holds"
1771 $scope.transfer_holds_to_marked = function() {
1772 var hold_ids = $scope.hold_grid_controls.allItems().map(
1773 function(hold_data) {return hold_data.hold.id()});
1774 egHolds.transfer_to_marked_title(hold_ids);
1777 // ------------------------------------------------------------------
1778 // Initialize the selected tab
1780 // we explicitly initialize catalog_url because otherwise Firefox
1781 // ends up setting it to $BASE_URL/{{url}}, which then messes
1782 // things up. See LP#1708951
1783 $scope.catalog_url = '';
1785 function init_cat_url() {
1786 // Set the initial catalog URL. This only happens once.
1787 // The URL is otherwise generated through user navigation.
1788 if ($scope.catalog_url) return;
1790 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1792 // A record ID in the path indicates a request for the record-
1794 if ($routeParams.record_id) {
1795 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1798 // Jumping directly to the results page by passing a search
1799 // query via the URL. Copy all URL params to the iframe url.
1800 if ($location.path().match(/catalog\/results/)) {
1801 url = url.replace(/advanced/, '/results?');
1803 angular.forEach($location.search(), function(val, key) {
1804 if (!first) url += '&';
1806 url += encodeURIComponent(key)
1807 + '=' + encodeURIComponent(val);
1811 // if we're displaying the advanced search form, select
1812 // whatever default pane the user has chosen via workstation
1814 if (url.match(/\/opac\/advanced$/)) {
1815 var adv_pane = egCore.hatch.getLocalItem('eg.search.adv_pane');
1817 url += '?pane=' + encodeURIComponent(adv_pane);
1821 $scope.catalog_url = url;
1824 function init_parts_url() {
1825 $scope.parts_url = $location
1829 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1833 $scope.set_record_tab = function(tab) {
1834 $scope.record_tab = tab;
1847 $scope.detail_hold_record_id = $scope.record_id;
1848 // refresh the holds grid
1855 $scope.set_default_record_tab = function() {
1856 egCore.hatch.setLocalItem(
1857 'eg.cat.default_record_tab', $scope.record_tab);
1858 $timeout(function(){$scope.default_tab = $scope.record_tab});
1862 if ($scope.record_id) {
1863 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1864 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1867 tab = $routeParams.record_tab || 'catalog';
1869 $scope.set_record_tab(tab);
1873 .controller('AuthorityCtrl',
1874 ['$scope','$routeParams','$location','$window','$q','egCore',
1875 function($scope , $routeParams , $location , $window , $q , egCore) {
1877 // set record ID on page load if available...
1878 $scope.authority_id = $routeParams.authority_id;
1880 if ($routeParams.authority_id) $scope.from_route = true;
1881 else $scope.from_route = false;
1883 $scope.stop_unload = false;
1886 .controller('URLVerifyCtrl',
1887 ['$scope','$location',
1888 function($scope , $location) {
1889 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1892 .controller('VandelayCtrl',
1893 ['$scope','$location', 'egCore', '$uibModal',
1894 function($scope , $location, egCore, $uibModal) {
1895 $scope.vandelay_url = $location.absUrl().replace(/\/staff\/cat\/catalog\/vandelay/, '/vandelay/vandelay');
1897 $scope.funcs.edit_marc_modal = function(bre, callback){
1898 var marcArgs = { 'marc_xml': bre.marc() };
1899 var vqbibrecId = bre.id();
1901 templateUrl: './cat/catalog/t_edit_marc_modal',
1904 controller: ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
1905 $scope.focusMe = true;
1906 $scope.recordId = vqbibrecId;
1907 $scope.args = marcArgs;
1908 $scope.dirty_flag = false;
1909 $scope.ok = function(marg){
1910 $uibModalInstance.close(marg);
1912 $scope.cancel = function(){ $uibModalInstance.dismiss() }
1914 }).result.then(function(res){
1915 var new_xml = res.marc_xml;
1916 egCore.pcrud.retrieve('vqbr', vqbibrecId).then(function(vqbib){
1917 vqbib.marc(new_xml);
1918 egCore.pcrud.update(vqbib).then( function(){ callback(vqbibrecId); });
1924 .controller('ManageAuthoritiesCtrl',
1925 ['$scope','$location',
1926 function($scope , $location) {
1927 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1930 .controller('BatchEditCtrl',
1931 ['$scope','$location','$routeParams',
1932 function($scope , $location , $routeParams) {
1933 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1934 if ($routeParams.container_type) {
1935 switch ($routeParams.container_type) {
1937 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1940 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1947 .filter('boolText', function(){
1948 return function (v) {
1953 .factory('conjoinedSvc',
1955 function(egCore , $q) {
1958 items : [], // record search results
1959 index : 0, // search grid index
1966 bpbcm : ['target_copy','peer_type'],
1967 acp : ['call_number'],
1969 bre : ['simple_record']
1971 // avoid fetching the MARC blob by specifying which
1972 // fields on the bre to select. More may be needed.
1973 // note that fleshed fields are explicitly selected.
1974 select : { bre : ['id'] },
1975 order_by : { bpbcm : ['id'] },
1978 // resolved with the last received copy
1979 service.fetch = function(rid) {
1980 if (!rid && !service.rid) return $q.when();
1982 if (rid) service.rid = rid;
1986 return egCore.pcrud.search(
1988 {peer_record : service.rid},
1991 ).then( function(list) { // finished
1992 service.items = list;
1993 return service.items;
1997 // returns a promise resolved with the list of peer bib types
1998 service.get_peer_types = function() {
2000 return $q.when(egCore.env.bpt.list);
2002 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
2003 .then(function(list) {
2004 egCore.env.absorbList(list, 'bpt');