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 ($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',
328 ['$scope','$uibModalInstance',
329 function($scope , $uibModalInstance) {
331 $scope.bucket_id = 0;
332 $scope.newBucketName = '';
333 $scope.allBuckets = [];
336 'open-ils.actor.container.retrieve_by_class.authoritative',
337 egCore.auth.token(), egCore.auth.user().id(),
338 'biblio', 'staff_client'
339 ).then(function(buckets) { $scope.allBuckets = buckets; });
341 $scope.add_to_bucket = function() {
342 var item = new egCore.idl.cbrebi();
343 item.bucket($scope.bucket_id);
344 item.target_biblio_record_entry(recId);
347 'open-ils.actor.container.item.create',
348 egCore.auth.token(), 'biblio', item
349 ).then(function(resp) {
350 $uibModalInstance.close();
354 $scope.add_to_new_bucket = function() {
355 var bucket = new egCore.idl.cbreb();
356 bucket.owner(egCore.auth.user().id());
357 bucket.name($scope.newBucketName);
358 bucket.description('');
359 bucket.btype('staff_client');
363 'open-ils.actor.container.create',
364 egCore.auth.token(), 'biblio', bucket
365 ).then(function(bucket) {
366 $scope.bucket_id = bucket;
367 $scope.add_to_bucket();
371 $scope.cancel = function() {
372 $uibModalInstance.dismiss();
378 $scope.current_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record');
379 $scope.current_voltransfer_target = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
380 $scope.current_conjoined_target = egCore.hatch.getLocalItem('eg.cat.marked_conjoined_record');
382 $scope.quickReceive = function () {
384 var next_per_stream = {};
386 var recId = $scope.record_id;
387 return $uibModal.open({
388 templateUrl: './share/t_subscription_select_dialog',
389 controller: ['$scope', '$uibModalInstance',
390 function($scope, $uibModalInstance) {
393 $scope.rememberMe = 'eg.serials.quickreceive.last_org';
394 $scope.record_id = recId;
395 $scope.ssubId = null;
397 $scope.ok = function() { $uibModalInstance.close($scope.ssubId) }
398 $scope.cancel = function() { $uibModalInstance.dismiss(); }
401 }).result.then(function(ssubId) {
404 promises.push(egSerialsCoreSvc.fetchItemsForSub(ssubId,{status:'Expected'}).then(function(){
405 angular.forEach(egSerialsCoreSvc.itemTree, function (item) {
406 if (next_per_stream[item.stream().id()]) return;
407 if (item.status() == 'Expected') {
408 next_per_stream[item.stream().id()] = item;
409 list.push(egCore.idl.Clone(item));
414 return $q.all(promises).then(function() {
417 ngToast.warning(egCore.strings.SERIALS_NO_ITEMS);
421 return egSerialsCoreSvc.process_items(
427 false, // print by default
428 function() { $scope.holdings_record_id_changed($scope.record_id) }
432 ngToast.warning(egCore.strings.SERIALS_NO_SUBS);
438 $scope.markConjoined = function () {
439 $scope.current_conjoined_target = $scope.record_id;
440 egCore.hatch.setLocalItem('eg.cat.marked_conjoined_record',$scope.record_id);
441 ngToast.create(egCore.strings.MARK_CONJ_TARGET);
444 $scope.markVolTransfer = function () {
445 ngToast.create(egCore.strings.MARK_VOL_TARGET);
446 $scope.current_voltransfer_target = $scope.record_id;
447 egCore.hatch.setLocalItem('eg.cat.marked_volume_transfer_record',$scope.record_id);
448 egCore.hatch.removeLocalItem('eg.cat.volume_transfer_target');
451 $scope.markOverlay = function () {
452 $scope.current_overlay_target = $scope.record_id;
453 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.record_id);
454 ngToast.create(egCore.strings.MARK_OVERLAY_TARGET);
457 $scope.clearRecordMarks = function () {
458 $scope.current_overlay_target = null;
459 $scope.current_voltransfer_target = null;
460 $scope.current_conjoined_target = null;
461 $scope.current_hold_transfer_dest = null;
462 egCore.hatch.removeLocalItem('eg.cat.marked_volume_transfer_record');
463 egCore.hatch.removeLocalItem('eg.cat.marked_conjoined_record');
464 egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');
465 egCore.hatch.removeLocalItem('eg.circ.hold.title_transfer_target');
468 $scope.stop_unload = false;
469 $scope.$watch('stop_unload',
470 function(newVal, oldVal) {
471 if (newVal && newVal != oldVal && $scope.opac_iframe) {
472 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
473 return 'There is unsaved data in this record.'
476 if ($scope.opac_iframe)
477 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
482 // Set the "last bib" cookie, if we have that
483 if ($scope.record_id)
484 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
486 $scope.refresh_record_callback = function (record_id) {
487 egCore.pcrud.retrieve('bre', record_id, {
490 bre : ['simple_record','creator','editor']
492 }).then(function(rec) {
493 rec.owner(egCore.org.get(rec.owner()));
494 $scope.summary_pane_record = rec;
500 patron_search_dialog = function() {
501 return $uibModal.open({
502 templateUrl: './share/t_patron_selector',
506 ['$scope','$uibModalInstance','$controller',
507 function($scope , $uibModalInstance , $controller) {
508 angular.extend(this, $controller('BasePatronSearchCtrl', {$scope : $scope}));
510 $scope.need_one_selected = function() {
511 var items = $scope.gridControls.selectedItems();
512 return (items.length == 1) ? false : true
514 $scope.ok = function() {
515 var items = $scope.gridControls.selectedItems();
516 if (items.length == 1) {
517 $uibModalInstance.close(items[0].card().barcode());
519 $uibModalInstance.close()
522 $scope.cancel = function($event) {
523 $uibModalInstance.dismiss();
524 $event.preventDefault();
530 // also set it when the iframe changes to a new record
531 $scope.handle_page = function(url) {
533 if (!url || url == 'about:blank') {
534 // nothing loaded. If we already have a record ID, leave it.
538 var match = url.match(/\/+opac\/+record\/+(\d+)/);
540 $scope.record_id = match[1];
541 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
542 $scope.holdings_record_id_changed($scope.record_id);
543 conjoinedSvc.fetch($scope.record_id).then(function(){
544 $scope.conjoinedGridDataProvider.refresh();
546 egHolds.fetch_holds(hold_ids).then($scope.hold_grid_data_provider.refresh);
548 $location.update_path('/cat/catalog/record/' + $scope.record_id);
549 // update_path() bypasses the controller for path
550 // /cat/catalog/record/:record_id. Manually set title here too.
551 egCore.strings.setPageTitle(
552 egCore.strings.PAGE_TITLE_BIB_DETAIL,
553 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT,
554 {record_id : $scope.record_id}
557 delete $scope.record_id;
558 $scope.from_route = false;
561 // child scope is executing this function, so our digest doesn't fire ... thus,
564 if (!$scope.in_opac_call) {
565 if ($scope.record_id && !$scope.record_tab) {
566 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
567 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
569 tab = $routeParams.record_tab || 'catalog';
571 $scope.set_record_tab(tab);
573 $scope.in_opac_call = false;
576 if ($scope.opac_iframe && $location.path().match(/cat\/catalog/)) {
577 var doc = $scope.opac_iframe.dom.contentWindow.document;
578 $(doc).find('#hold_usr_search').show();
579 $(doc).find('#hold_usr_search').on('click', function() {
580 patron_search_dialog().result.then(function(barc) {
581 $(doc).find('#hold_usr_input').val(barc);
582 $(doc).find('#hold_usr_input').change();
589 // xulG catalog handlers
590 $scope.handlers = { }
592 // ------------------------------------------------------------------
595 $scope.conjoinedGridControls = {};
596 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
597 get : function(offset, count) {
598 return this.arrayNotifier(conjoinedSvc.items, offset, count);
602 $scope.changeConjoinedType = function () {
603 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
604 angular.forEach(peers, function (p) {
605 p.target_copy(p.target_copy().id());
606 p.peer_type(p.peer_type().id());
609 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
611 return $uibModal.open({
612 templateUrl: './cat/catalog/t_conjoined_selector',
615 ['$scope','$uibModalInstance',
616 function($scope , $uibModalInstance) {
617 $scope.update = true;
619 $scope.peer_type = null;
620 $scope.peer_type_list = [];
621 conjoinedSvc.get_peer_types().then(function(list){
622 $scope.peer_type_list = list;
625 $scope.ok = function(type) {
628 angular.forEach(peers, function (p) {
631 promises.push(egCore.pcrud.update(p));
634 return $q.all(promises)
635 .then(function(){$uibModalInstance.close()})
636 .then(function(){return conjoinedSvc.fetch()})
637 .then(function(){conjoinedGridDataProviderRef.refresh()});
640 $scope.cancel = function($event) {
641 $uibModalInstance.dismiss();
642 $event.preventDefault();
649 $scope.refreshConjoined = function () {
650 conjoinedSvc.fetch($scope.record_id)
651 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
654 $scope.deleteSelectedConjoined = function () {
655 var peers = $scope.conjoinedGridControls.selectedItems();
657 if (peers.length > 0) {
658 egConfirmDialog.open(
659 egCore.strings.CONFIRM_DELETE_PEERS,
660 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
661 {peers : peers.length}
662 ).result.then(function() {
663 angular.forEach(peers, function (p) {
667 egCore.pcrud.remove(peers).then(function() {
668 return conjoinedSvc.fetch();
670 $scope.conjoinedGridDataProvider.refresh();
675 if ($scope.record_id)
676 conjoinedSvc.fetch($scope.record_id);
678 // ------------------------------------------------------------------
681 $scope.holdingsGridControls = {
682 activateItem : function (item) {
683 $scope.selectedHoldingsVolCopyEdit();
686 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
687 get : function(offset, count) {
688 return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
692 $scope.add_copies_to_bucket = function() {
693 var copy_list = gatherSelectedHoldingsIds();
694 if (copy_list.length == 0) return;
696 return $uibModal.open({
697 templateUrl: './cat/catalog/t_add_to_bucket',
701 ['$scope','$uibModalInstance',
702 function($scope , $uibModalInstance) {
704 $scope.bucket_id = 0;
705 $scope.newBucketName = '';
706 $scope.allBuckets = [];
710 'open-ils.actor.container.retrieve_by_class.authoritative',
711 egCore.auth.token(), egCore.auth.user().id(),
712 'copy', 'staff_client'
713 ).then(function(buckets) { $scope.allBuckets = buckets; });
715 $scope.add_to_bucket = function() {
717 angular.forEach(copy_list, function (cp) {
718 var item = new egCore.idl.ccbi()
719 item.bucket($scope.bucket_id);
720 item.target_copy(cp);
724 'open-ils.actor.container.item.create',
725 egCore.auth.token(), 'copy', item
729 return $q.all(promises).then(function() {
730 $uibModalInstance.close();
735 $scope.add_to_new_bucket = function() {
736 var bucket = new egCore.idl.ccb();
737 bucket.owner(egCore.auth.user().id());
738 bucket.name($scope.newBucketName);
739 bucket.description('');
740 bucket.btype('staff_client');
742 return egCore.net.request(
744 'open-ils.actor.container.create',
745 egCore.auth.token(), 'copy', bucket
746 ).then(function(bucket) {
747 $scope.bucket_id = bucket;
748 $scope.add_to_bucket();
752 $scope.cancel = function() {
753 $uibModalInstance.dismiss();
759 // TODO: refactor common code between cat/catalog/app.js and cat/item/app.js
761 $scope.need_one_selected = function() {
762 var items = $scope.holdingsGridControls.selectedItems();
763 if (items.length == 1) return false;
767 $scope.make_copies_bookable = function() {
769 var copies_by_record = {};
770 var record_list = [];
772 $scope.holdingsGridControls.selectedItems(),
774 var record_id = item['call_number.record.id'];
775 if (typeof copies_by_record[ record_id ] == 'undefined') {
776 copies_by_record[ record_id ] = [];
777 record_list.push( record_id );
779 copies_by_record[ record_id ].push(item.id);
784 var combined_results = [];
785 angular.forEach(record_list, function(record_id) {
789 'open-ils.booking.resources.create_from_copies',
791 copies_by_record[record_id]
792 ).then(function(results) {
793 if (results && results['brsrc']) {
794 combined_results = combined_results.concat(results['brsrc']);
800 $q.all(promises).then(function() {
801 if (combined_results.length > 0) {
803 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
807 ['$scope','$location','egCore','$uibModalInstance',
808 function($scope , $location , egCore , $uibModalInstance) {
811 ses : egCore.auth.token(),
812 resultant_brsrc : combined_results.map(function(o) { return o[0]; })
815 var booking_path = '/eg/conify/global/booking/resource';
817 $scope.booking_admin_url =
818 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
825 $scope.book_copies_now = function() {
826 var copies_by_record = {};
827 var record_list = [];
829 $scope.holdingsGridControls.selectedItems(),
831 var record_id = item['call_number.record.id'];
832 if (typeof copies_by_record[ record_id ] == 'undefined') {
833 copies_by_record[ record_id ] = [];
834 record_list.push( record_id );
836 copies_by_record[ record_id ].push(item.id);
841 var combined_brt = [];
842 var combined_brsrc = [];
843 angular.forEach(record_list, function(record_id) {
847 'open-ils.booking.resources.create_from_copies',
849 copies_by_record[record_id]
850 ).then(function(results) {
851 if (results && results['brt']) {
852 combined_brt = combined_brt.concat(results['brt']);
854 if (results && results['brsrc']) {
855 combined_brsrc = combined_brsrc.concat(results['brsrc']);
861 $q.all(promises).then(function() {
862 if (combined_brt.length > 0 || combined_brsrc.length > 0) {
864 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
868 ['$scope','$location','egCore','$uibModalInstance',
869 function($scope , $location , egCore , $uibModalInstance) {
872 ses : egCore.auth.token(),
873 bresv_interface_opts : {
876 ,brsrc : combined_brsrc
881 var booking_path = '/eg/booking/reservation';
883 $scope.booking_admin_url =
884 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
893 $scope.requestItems = function() {
894 var copy_list = gatherSelectedHoldingsIds();
895 if (copy_list.length == 0) return;
897 return $uibModal.open({
898 templateUrl: './cat/catalog/t_request_items',
901 ['$scope','$uibModalInstance',
902 function($scope , $uibModalInstance) {
904 $scope.first_user_fetch = true;
908 copy_list : copy_list,
909 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
910 user : egCore.auth.user().id()
913 egUser.get( $scope.hold_data.user ).then(function(u) {
915 $scope.barcode = u.card().barcode();
916 $scope.user_name = egUser.format_name(u);
917 $scope.hold_data.user = u.id();
920 $scope.user_name = '';
922 $scope.$watch('barcode', function (n) {
923 if (!$scope.first_user_fetch) {
924 egUser.getByBarcode(n).then(function(u) {
926 $scope.user_name = egUser.format_name(u);
927 $scope.hold_data.user = u.id();
930 $scope.user_name = '';
931 delete $scope.hold_data.user;
934 $scope.first_user_fetch = false;
937 $scope.ok = function(h) {
940 hold_type : h.hold_type,
941 pickup_lib: h.pickup_lib.id(),
947 'open-ils.circ.holds.test_and_create.batch.override',
948 egCore.auth.token(), args, h.copy_list
951 $uibModalInstance.close();
954 $scope.cancel = function($event) {
955 $uibModalInstance.dismiss();
956 $event.preventDefault();
962 $scope.view_place_orders = function() {
963 if (!$scope.record_id) return;
964 var url = egCore.env.basePath + 'acq/legacy/lineitem/related/' + $scope.record_id + '?target=bib';
965 $timeout(function() { $window.open(url, '_blank') });
968 $scope.replaceBarcodes = function() {
969 var copy_list = gatherSelectedRawCopies();
970 if (copy_list.length == 0) return;
972 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
974 angular.forEach(copy_list, function (cp) {
976 templateUrl: './cat/share/t_replace_barcode',
979 ['$scope','$uibModalInstance',
980 function($scope , $uibModalInstance) {
981 $scope.isModal = true;
982 $scope.focusBarcode = false;
983 $scope.focusBarcode2 = true;
984 $scope.barcode1 = cp.barcode();
986 $scope.updateBarcode = function() {
987 $scope.copyNotFound = false;
988 $scope.updateOK = false;
990 egCore.pcrud.search('acp',
991 {deleted : 'f', barcode : $scope.barcode1})
992 .then(function(copy) {
995 $scope.focusBarcode = true;
996 $scope.copyNotFound = true;
1000 $scope.copyId = copy.id();
1001 copy.barcode($scope.barcode2);
1003 egCore.pcrud.update(copy).then(function(stat) {
1004 $scope.updateOK = stat;
1005 $scope.focusBarcode = true;
1006 holdingsSvc.fetchAgain().then(function (){
1007 holdingsGridDataProviderRef.refresh();
1012 $uibModalInstance.close();
1015 $scope.cancel = function($event) {
1016 $uibModalInstance.dismiss();
1017 $event.preventDefault();
1025 // refresh the list of holdings when the record_id is changed.
1026 $scope.holdings_record_id_changed = function(id) {
1027 if ($scope.record_id != id) $scope.record_id = id;
1028 console.log('record id changed to ' + id + ', loading new holdings');
1029 holdingsSvcInst.fetch({
1030 rid : $scope.record_id,
1031 org : $scope.holdings_ou,
1032 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1033 vol : $scope.holdings_show_vols,
1034 empty: $scope.holdings_show_empty,
1035 empty_org: $scope.holdings_show_empty_org
1036 }).then(function() {
1037 $scope.holdingsGridDataProvider.refresh();
1041 // refresh the list of holdings when the filter lib is changed.
1042 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
1043 $scope.holdings_ou_changed = function(org) {
1044 $scope.holdings_ou = org;
1045 holdingsSvcInst.fetch({
1046 rid : $scope.record_id,
1047 org : $scope.holdings_ou,
1048 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1049 vol : $scope.holdings_show_vols,
1050 empty: $scope.holdings_show_empty,
1051 empty_org: $scope.holdings_show_empty_org
1052 }).then(function() {
1053 $scope.holdingsGridDataProvider.refresh();
1057 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
1058 $scope[cb] = newVal;
1059 var x = $scope.holdings_show_vols ? $scope.holdings_show_copies : false;
1060 $('#holdings_show_copies').prop('checked', x);
1061 egCore.hatch.setItem('cat.' + cb, newVal);
1062 if (!norefresh) holdingsSvcInst.fetch({
1063 rid : $scope.record_id,
1064 org : $scope.holdings_ou,
1065 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1066 vol : $scope.holdings_show_vols,
1067 empty: $scope.holdings_show_empty,
1068 empty_org: $scope.holdings_show_empty_org
1069 }).then(function() {
1070 $scope.holdingsGridDataProvider.refresh();
1074 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
1075 if (typeof x == 'undefined') x = true;
1076 $scope.holdings_cb_changed('holdings_show_vols',x,true);
1077 $('#holdings_show_vols').prop('checked', x);
1079 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
1080 if (typeof x == 'undefined') x = true;
1081 $scope.holdings_cb_changed('holdings_show_copies',x,true);
1082 x = $scope.holdings_show_vols ? x : false;
1083 $('#holdings_show_copies').prop('checked', x);
1085 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
1086 if (typeof x == 'undefined') x = true;
1087 $scope.holdings_cb_changed('holdings_show_empty',x);
1088 $('#holdings_show_empty').prop('checked', x);
1090 egCore.hatch.getItem('cat.holdings_show_empty_org').then(function(x){
1091 if (typeof x == 'undefined') x = true;
1092 $scope.holdings_cb_changed('holdings_show_empty_org',x);
1093 $('#holdings_show_empty_org').prop('checked', x);
1099 $scope.vols_not_shown = function () {
1100 return !$scope.holdings_show_vols;
1103 $scope.copies_not_shown = function () {
1104 return !$scope.holdings_show_copies;
1107 $scope.empty_org_not_shown = function () {
1108 return !$scope.holdings_show_empty_org;
1111 $scope.holdings_checkbox_handler = function (item) {
1112 $scope.holdings_cb_changed(item.checkbox,item.checked);
1115 function gatherSelectedOwners () {
1116 var owner_list = [];
1118 $scope.holdingsGridControls.selectedItems(),
1119 function (item) { owner_list.push(item.owner_id) }
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)
1148 cn_id_list.push(item.call_number.id)
1154 function gatherSelectedVolumeIds () {
1155 var cn_id_list = [];
1157 $scope.holdingsGridControls.selectedItems(),
1159 if (cn_id_list.indexOf(item.call_number.id) == -1)
1160 cn_id_list.push(item.call_number.id)
1166 $scope.selectedHoldingsDelete = function (vols, copies) {
1169 var perCnCopies = {};
1175 $scope.holdingsGridControls.selectedItems(),
1177 if (vols && item.raw_call_number) {
1178 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
1179 cnHash[item.call_number.id].isdeleted(1);
1181 } else if (copies) {
1182 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
1185 var cn_id = cp.call_number().id();
1186 if (!cnHash[cn_id]) {
1187 cnHash[cn_id] = cp.call_number();
1188 perCnCopies[cn_id] = [cp];
1190 perCnCopies[cn_id].push(cp);
1192 cp.call_number(cn_id); // prevent loops in JSON-ification
1199 angular.forEach(perCnCopies, function (v, k) {
1201 cnHash[k].isdeleted(1);
1204 cnHash[k].copies(v);
1208 angular.forEach(cnHash, function (v, k) {
1212 if (cnList.length == 0) return;
1215 if (vols && copies) flags.force_delete_copies = 1;
1217 egConfirmDialog.open(
1218 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
1219 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
1220 {copies : cp_count, volumes : cn_count}
1221 ).result.then(function() {
1224 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1225 egCore.auth.token(), cnList, 1, flags
1226 ).then(function(update_count) {
1227 holdingsSvcInst.fetchAgain().then(function() {
1228 $scope.holdingsGridDataProvider.refresh();
1233 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
1234 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
1235 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
1237 spawnHoldingsAdd = function (vols,copies){
1239 if (copies) { // just a copy on existing volumes
1240 angular.forEach(gatherSelectedVolumeIds(), function (v) {
1241 raw.push( {callnumber : v} );
1244 if (typeof $scope.holdingsGridControls.selectedItems == "function" &&
1245 $scope.holdingsGridControls.selectedItems().length > 0) {
1246 angular.forEach($scope.holdingsGridControls.selectedItems(),
1249 owner : item.owner_id,
1250 label : item.call_number.label
1255 owner : egCore.auth.user().ws_ou()
1260 if (raw.length == 0) raw.push({});
1264 'open-ils.actor.anon_cache.set_value',
1265 null, 'edit-these-copies', {
1266 record_id: $scope.record_id,
1271 ).then(function(key) {
1273 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1274 $timeout(function() { $window.open(url, '_blank') });
1276 alert('Could not create anonymous cache key!');
1280 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
1281 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
1283 spawnHoldingsEdit = function (hide_vols,hide_copies,add_vol){
1287 raw = [{callnumber:null}];
1289 raw = gatherSelectedEmptyVolumeIds().map(
1290 function(v){ return { callnumber : v } }
1296 'open-ils.actor.anon_cache.set_value',
1297 null, 'edit-these-copies', {
1298 record_id: $scope.record_id,
1299 copies: gatherSelectedHoldingsIds(),
1301 hide_vols : hide_vols,
1302 hide_copies : hide_copies,
1303 only_add_vol : ((add_vol) ? true : false),
1304 owners : gatherSelectedOwners()
1306 ).then(function(key) {
1308 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1309 $timeout(function() { $window.open(url, '_blank') });
1311 alert('Could not create anonymous cache key!');
1315 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
1316 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
1317 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
1319 $scope.selectedHoldingsVolAdd = function () { spawnHoldingsEdit(false,true,true) }
1321 $scope.selectedHoldingsItemStatus = function (){
1322 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
1323 $timeout(function() { $window.open(url, '_blank') });
1326 $scope.markVolAsItemTarget = function() {
1327 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
1328 egCore.hatch.setLocalItem(
1329 'eg.cat.item_transfer_target',
1330 $scope.holdingsGridControls.selectedItems()[0].call_number.id
1332 ngToast.create(egCore.strings.MARK_ITEM_TARGET);
1336 $scope.markLibAsVolTarget = function() {
1337 var recId = $scope.record_id;
1338 return $uibModal.open({
1339 templateUrl: './cat/catalog/t_choose_vol_target_lib',
1342 ['$scope','$uibModalInstance',
1343 function($scope , $uibModalInstance) {
1345 var orgId = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target') || 1;
1346 $scope.org = egCore.org.get(orgId);
1347 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1348 $scope.ok = function(org) {
1349 egCore.hatch.setLocalItem(
1350 'eg.cat.volume_transfer_target',
1353 egCore.hatch.setLocalItem(
1354 'eg.cat.marked_volume_transfer_record',
1357 $uibModalInstance.close();
1359 $scope.cancel = function($event) {
1360 $uibModalInstance.dismiss();
1361 $event.preventDefault();
1366 $scope.markLibFromSelectedAsVolTarget = function() {
1367 egCore.hatch.setLocalItem(
1368 'eg.cat.volume_transfer_target',
1369 $scope.holdingsGridControls.selectedItems()[0].owner_id
1371 egCore.hatch.setLocalItem(
1372 'eg.cat.marked_volume_transfer_record',
1375 ngToast.create(egCore.strings.MARK_VOL_TARGET);
1378 $scope.selectedHoldingsItemStatusDetail = function (){
1380 gatherSelectedHoldingsIds(),
1382 var url = egCore.env.basePath +
1384 $timeout(function() { $window.open(url, '_blank') });
1389 $scope.transferVolumesToRecord = function (){
1390 var target_record = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
1391 if (!target_record) return;
1392 if ($scope.record_id == target_record) return;
1393 var items = $scope.holdingsGridControls.selectedItems();
1394 if (!items.length) return;
1396 var vols_to_move = {};
1397 angular.forEach(items, function(item) {
1398 if (!(item.call_number.owning_lib in vols_to_move)) {
1399 vols_to_move[item.call_number.owning_lib] = new Array;
1401 vols_to_move[item.call_number.owning_lib].push(item.call_number.id);
1405 angular.forEach(vols_to_move, function(vols, owning_lib) {
1406 promises.push(egCore.net.request(
1408 'open-ils.cat.asset.volume.batch.transfer.override',
1409 egCore.auth.token(), {
1410 docid : target_record,
1416 $q.all(promises).then(function(success) {
1418 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1419 holdingsSvcInst.fetchAgain().then(function() {
1420 $scope.holdingsGridDataProvider.refresh();
1423 alert('Could not transfer volumes!');
1428 function transferVolumes(new_record){
1429 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
1434 'open-ils.cat.asset.volume.batch.transfer.override',
1435 egCore.auth.token(), {
1436 docid : (new_record ? new_record : $scope.record_id),
1438 volumes : gatherSelectedVolumeIds()
1440 ).then(function(success) {
1442 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1443 holdingsSvcInst.fetchAgain().then(function() {
1444 $scope.holdingsGridDataProvider.refresh();
1447 alert('Could not transfer volumes!');
1454 $scope.transferVolumesToLibrary = function() {
1458 $scope.transferVolumesToRecordAndLibrary = function() {
1459 var target_record = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
1460 if (!target_record) return;
1461 transferVolumes(target_record);
1464 // this "transfers" selected copies to a new owning library,
1465 // auto-creating volumes and deleting unused volumes as required.
1466 $scope.changeItemOwningLib = function() {
1467 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
1468 var items = $scope.holdingsGridControls.selectedItems();
1469 if (!xfer_target || !items.length) {
1472 var vols_to_move = {};
1473 var copies_to_move = {};
1474 angular.forEach(items, function(item) {
1475 if (item.call_number.owning_lib != xfer_target) {
1476 if (item.call_number.id in vols_to_move) {
1477 copies_to_move[item.call_number.id].push(item.id);
1479 vols_to_move[item.call_number.id] = item.call_number;
1480 copies_to_move[item.call_number.id] = new Array;
1481 copies_to_move[item.call_number.id].push(item.id);
1487 angular.forEach(vols_to_move, function(vol) {
1488 promises.push(egCore.net.request(
1490 'open-ils.cat.call_number.find_or_create',
1491 egCore.auth.token(),
1498 ).then(function(resp) {
1499 var evt = egCore.evt.parse(resp);
1501 return egCore.net.request(
1503 'open-ils.cat.transfer_copies_to_volume',
1504 egCore.auth.token(),
1506 copies_to_move[vol.id]
1510 $q.all(promises).then(function() {
1511 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1512 holdingsSvcInst.fetchAgain().then(function() {
1513 $scope.holdingsGridDataProvider.refresh();
1518 $scope.transferItems = function (){
1519 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
1520 var copy_ids = gatherSelectedHoldingsIds();
1521 if (xfer_target && copy_ids.length > 0) {
1524 'open-ils.cat.transfer_copies_to_volume',
1525 egCore.auth.token(),
1529 function(resp) { // oncomplete
1530 var evt = egCore.evt.parse(resp);
1532 egConfirmDialog.open(
1533 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1534 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1535 {'evt_desc': evt.desc}
1536 ).result.then(function() {
1539 'open-ils.cat.transfer_copies_to_volume.override',
1540 egCore.auth.token(),
1543 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1544 ).then(function(resp) {
1545 holdingsSvcInst.fetchAgain().then(function() {
1546 $scope.holdingsGridDataProvider.refresh();
1551 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1552 holdingsSvcInst.fetchAgain().then(function() {
1553 $scope.holdingsGridDataProvider.refresh();
1563 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1565 gatherSelectedHoldingsIds(),
1567 var url = egCore.env.basePath +
1568 'cat/item/' + cid + '/triggered_events';
1569 $timeout(function() { $window.open(url, '_blank') });
1574 $scope.selectedHoldingsItemStatusHolds = function (){
1576 gatherSelectedHoldingsIds(),
1578 var url = egCore.env.basePath +
1579 'cat/item/' + cid + '/holds';
1580 $timeout(function() { $window.open(url, '_blank') });
1585 $scope.selectedHoldingsPrintLabels = function() {
1588 'open-ils.actor.anon_cache.set_value',
1589 null, 'print-labels-these-copies', {
1590 copies : gatherSelectedHoldingsIds()
1592 ).then(function(key) {
1594 var url = egCore.env.basePath + 'cat/printlabels/' + key;
1595 $timeout(function() { $window.open(url, '_blank') });
1597 alert('Could not create anonymous cache key!');
1602 $scope.selectedHoldingsDamaged = function () {
1603 var copy_list = gatherSelectedRawCopies();
1604 if (copy_list.length == 0) return;
1606 angular.forEach(copy_list, function(cp) {
1607 egCirc.mark_damaged({
1609 barcode: cp.barcode(),
1610 circ_lib: cp.circ_lib().id()
1611 }).then(function() {
1612 holdingsSvcInst.fetchAgain().then(function() {
1613 $scope.holdingsGridDataProvider.refresh();
1619 $scope.selectedHoldingsMissing = function () {
1620 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1621 holdingsSvcInst.fetchAgain().then(function() {
1622 $scope.holdingsGridDataProvider.refresh();
1627 $scope.attach_to_peer_bib = function() {
1628 var copy_list = gatherSelectedHoldingsIds();
1629 if (copy_list.length == 0) return;
1631 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1632 if (!target_record) return;
1634 return $uibModal.open({
1635 templateUrl: './cat/catalog/t_conjoined_selector',
1638 ['$scope','$uibModalInstance',
1639 function($scope , $uibModalInstance) {
1640 $scope.update = false;
1642 $scope.peer_type = null;
1643 $scope.peer_type_list = [];
1644 conjoinedSvc.get_peer_types().then(function(list){
1645 $scope.peer_type_list = list;
1648 $scope.ok = function(type) {
1651 angular.forEach(copy_list, function (cp) {
1652 var n = new egCore.idl.bpbcm();
1654 n.peer_record(target_record);
1657 promises.push(egCore.pcrud.create(n));
1660 return $q.all(promises).then(function(){$uibModalInstance.close()});
1663 $scope.cancel = function($event) {
1664 $uibModalInstance.dismiss();
1665 $event.preventDefault();
1673 // ------------------------------------------------------------------
1675 var provider = egGridDataProvider.instance({});
1676 $scope.hold_grid_data_provider = provider;
1677 $scope.grid_actions = egHoldGridActions;
1678 $scope.grid_actions.refresh = function () { provider.refresh() };
1679 $scope.hold_grid_controls = {};
1681 var hold_ids = []; // current list of holds
1682 function fetchHolds(offset, count) {
1683 var ids = hold_ids.slice(offset, offset + count);
1685 return egHolds.fetch_holds(ids).then(null, null,
1686 function(hold_data) {
1692 provider.get = function(offset, count) {
1693 if ($scope.record_tab != 'holds') return $q.when();
1694 var deferred = $q.defer();
1695 hold_ids = []; // no caching ATM
1697 // open a determinate progress dialog, max value set below.
1698 egProgressDialog.open({max : 1, value : 0});
1703 'open-ils.circ.holds.retrieve_all_from_title',
1704 egCore.auth.token(), $scope.record_id,
1705 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
1707 function(hold_data) {
1708 hold_ids = []; // clear the list of ids, hack to avoid dups
1709 // TODO: fix the underlying problem, which is that
1710 // this gets called twice when switching to the holds
1711 // tab; once explicitly, and once via the change handler
1712 // on the OU selector
1713 angular.forEach(hold_data, function(list, type) {
1714 hold_ids = hold_ids.concat(list);
1717 // Set the max value of the progress bar to the lesser of
1718 // the total number of holds to fetch or the page size
1720 egProgressDialog.update(
1721 {max : Math.min(hold_ids.length, count)});
1723 var holds_fetched = 0;
1724 fetchHolds(offset, count)
1725 .then(deferred.resolve, null,
1726 function(hold_data) {
1728 deferred.notify(hold_data);
1729 egProgressDialog.increment();
1731 )['finally'](egProgressDialog.close);
1735 return deferred.promise;
1738 $scope.detail_view = function(action, user_data, items) {
1740 $scope.detail_hold_id = h.hold.id();
1744 $scope.list_view = function(items) {
1745 $scope.detail_hold_id = null;
1748 // refresh the list of record holds when the pickup lib is changed.
1749 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1750 $scope.pickup_ou_changed = function(org) {
1751 $scope.pickup_ou = org;
1755 $scope.print_holds = function() {
1757 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1759 hold : egCore.idl.toHash(item.hold),
1760 patron_last : item.patron_last,
1761 patron_alias : item.patron_alias,
1762 patron_barcode : item.patron_barcode,
1763 copy : egCore.idl.toHash(item.copy),
1764 volume : egCore.idl.toHash(item.volume),
1765 title : item.mvr.title(),
1766 author : item.mvr.author()
1770 egCore.print.print({
1771 context : 'receipt',
1772 template : 'holds_for_bib',
1773 scope : {holds : holds}
1777 $scope.current_hold_transfer_dest = egCore.hatch.getLocalItem ('eg.circ.hold.title_transfer_target');
1779 $scope.mark_hold_transfer_dest = function() {
1780 $scope.current_hold_transfer_dest = $scope.record_id;
1781 egCore.hatch.setLocalItem(
1782 'eg.circ.hold.title_transfer_target', $scope.record_id);
1783 ngToast.create(egCore.strings.HOLD_TRANSFER_DEST_MARKED);
1786 // UI presents this option as "all holds"
1787 $scope.transfer_holds_to_marked = function() {
1788 var hold_ids = $scope.hold_grid_controls.allItems().map(
1789 function(hold_data) {return hold_data.hold.id()});
1790 egHolds.transfer_to_marked_title(hold_ids);
1793 // ------------------------------------------------------------------
1794 // Initialize the selected tab
1796 // we explicitly initialize catalog_url because otherwise Firefox
1797 // ends up setting it to $BASE_URL/{{url}}, which then messes
1798 // things up. See LP#1708951
1799 $scope.catalog_url = '';
1801 function init_cat_url() {
1802 // Set the initial catalog URL. This only happens once.
1803 // The URL is otherwise generated through user navigation.
1804 if ($scope.catalog_url) return;
1806 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1808 // A record ID in the path indicates a request for the record-
1810 if ($routeParams.record_id) {
1811 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1814 // Jumping directly to the results page by passing a search
1815 // query via the URL. Copy all URL params to the iframe url.
1816 if ($location.path().match(/catalog\/results/)) {
1817 url = url.replace(/advanced/, '/results?');
1819 angular.forEach($location.search(), function(val, key) {
1820 if (!first) url += '&';
1822 url += encodeURIComponent(key)
1823 + '=' + encodeURIComponent(val);
1827 // if we're displaying the advanced search form, select
1828 // whatever default pane the user has chosen via workstation
1830 if (url.match(/\/opac\/advanced$/)) {
1831 var adv_pane = egCore.hatch.getLocalItem('eg.search.adv_pane');
1833 url += '?pane=' + encodeURIComponent(adv_pane);
1837 $scope.catalog_url = url;
1840 function init_parts_url() {
1841 $scope.parts_url = $location
1845 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1849 $scope.set_record_tab = function(tab) {
1850 $scope.record_tab = tab;
1863 $scope.detail_hold_record_id = $scope.record_id;
1864 // refresh the holds grid
1871 $scope.set_default_record_tab = function() {
1872 egCore.hatch.setLocalItem(
1873 'eg.cat.default_record_tab', $scope.record_tab);
1874 $timeout(function(){$scope.default_tab = $scope.record_tab});
1878 if ($scope.record_id) {
1879 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1880 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1883 tab = $routeParams.record_tab || 'catalog';
1885 $scope.set_record_tab(tab);
1889 .controller('AuthorityCtrl',
1890 ['$scope','$routeParams','$location','$window','$q','egCore',
1891 function($scope , $routeParams , $location , $window , $q , egCore) {
1893 // set record ID on page load if available...
1894 $scope.authority_id = $routeParams.authority_id;
1896 if ($routeParams.authority_id) $scope.from_route = true;
1897 else $scope.from_route = false;
1899 $scope.stop_unload = false;
1902 .controller('URLVerifyCtrl',
1903 ['$scope','$location',
1904 function($scope , $location) {
1905 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1908 .controller('VandelayCtrl',
1909 ['$scope','$location', 'egCore', '$uibModal',
1910 function($scope , $location, egCore, $uibModal) {
1911 $scope.vandelay_url = $location.absUrl().replace(/\/staff\/cat\/catalog\/vandelay/, '/vandelay/vandelay');
1913 $scope.funcs.edit_marc_modal = function(bre, callback){
1914 var marcArgs = { 'marc_xml': bre.marc() };
1915 var vqbibrecId = bre.id();
1917 templateUrl: './cat/catalog/t_edit_marc_modal',
1919 controller: ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
1920 $scope.focusMe = true;
1921 $scope.recordId = vqbibrecId;
1922 $scope.args = marcArgs;
1923 $scope.dirty_flag = false;
1924 $scope.ok = function(marg){
1925 $uibModalInstance.close(marg);
1927 $scope.cancel = function(){ $uibModalInstance.dismiss() }
1929 }).result.then(function(res){
1930 var new_xml = res.marc_xml;
1931 egCore.pcrud.retrieve('vqbr', vqbibrecId).then(function(vqbib){
1932 vqbib.marc(new_xml);
1933 egCore.pcrud.update(vqbib).then( function(){ callback(vqbibrecId); });
1939 .controller('ManageAuthoritiesCtrl',
1940 ['$scope','$location',
1941 function($scope , $location) {
1942 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1945 .controller('BatchEditCtrl',
1946 ['$scope','$location','$routeParams',
1947 function($scope , $location , $routeParams) {
1948 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1949 if ($routeParams.container_type) {
1950 switch ($routeParams.container_type) {
1952 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1955 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1962 .filter('boolText', function(){
1963 return function (v) {
1968 .factory('conjoinedSvc',
1970 function(egCore , $q) {
1973 items : [], // record search results
1974 index : 0, // search grid index
1981 bpbcm : ['target_copy','peer_type'],
1982 acp : ['call_number'],
1984 bre : ['simple_record']
1986 // avoid fetching the MARC blob by specifying which
1987 // fields on the bre to select. More may be needed.
1988 // note that fleshed fields are explicitly selected.
1989 select : { bre : ['id'] },
1990 order_by : { bpbcm : ['id'] },
1993 // resolved with the last received copy
1994 service.fetch = function(rid) {
1995 if (!rid && !service.rid) return $q.when();
1997 if (rid) service.rid = rid;
2001 return egCore.pcrud.search(
2003 {peer_record : service.rid},
2006 ).then( function(list) { // finished
2007 service.items = list;
2008 return service.items;
2012 // returns a promise resolved with the list of peer bib types
2013 service.get_peer_types = function() {
2015 return $q.when(egCore.env.bpt.list);
2017 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
2018 .then(function(list) {
2019 egCore.env.absorbList(list, 'bpt');