4 * currently, this app doesn't use routes for each sub-ui, because
5 * reloading the catalog each time is sloooow. better so far to
6 * swap out divs w/ ng-if / ng-show / ng-hide as needed.
10 angular.module('egCatalogApp', ['ui.bootstrap','ngRoute','ngLocationUpdate','egCoreMod','egGridMod', 'egMarcMod', 'egUserMod', 'egHoldingsMod', 'ngToast','egPatronSearchMod',
11 'egSerialsMod','egSerialsAppDep'])
13 .config(['ngToastProvider', function(ngToastProvider) {
14 ngToastProvider.configure({
15 verticalPosition: 'bottom',
20 .config(function($routeProvider, $locationProvider, $compileProvider) {
21 $locationProvider.html5Mode(true);
22 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|mailto|blob):/); // grid export
24 var resolver = {delay : ['egCore','egStartup','egUser', function(egCore, egStartup, egUser) {
25 egCore.env.classLoaders.aous = function() {
26 return egCore.org.settings([
27 'cat.marc_control_number_identifier'
28 ]).then(function(settings) {
29 // local settings are cached within egOrg. Caching them
30 // again in egEnv just simplifies the syntax for access.
31 egCore.env.aous = settings;
34 egCore.env.loadClasses.push('aous');
38 $routeProvider.when('/cat/catalog/index', {
39 templateUrl: './cat/catalog/t_catalog',
40 controller: 'CatalogCtrl',
44 // Jump directly to the results page. Any URL parameter
45 // supported by the embedded catalog is supported here.
46 $routeProvider.when('/cat/catalog/results', {
47 templateUrl: './cat/catalog/t_catalog',
48 controller: 'CatalogCtrl',
52 $routeProvider.when('/cat/catalog/retrieve_by_id', {
53 templateUrl: './cat/catalog/t_retrieve_by_id',
54 controller: 'CatalogRecordRetrieve',
58 $routeProvider.when('/cat/catalog/retrieve_by_tcn', {
59 templateUrl: './cat/catalog/t_retrieve_by_tcn',
60 controller: 'CatalogRecordRetrieve',
64 $routeProvider.when('/cat/catalog/retrieve_by_authority_id', {
65 templateUrl: './cat/catalog/t_retrieve_by_authority_id',
66 controller: 'CatalogRecordRetrieve',
70 $routeProvider.when('/cat/catalog/new_bib', {
71 templateUrl: './cat/catalog/t_new_bib',
72 controller: 'NewBibCtrl',
76 // create some catalog page-specific mappings
77 $routeProvider.when('/cat/catalog/record/:record_id', {
78 templateUrl: './cat/catalog/t_catalog',
79 controller: 'CatalogCtrl',
83 // create some catalog page-specific mappings
84 $routeProvider.when('/cat/catalog/record/:record_id/:record_tab', {
85 templateUrl: './cat/catalog/t_catalog',
86 controller: 'CatalogCtrl',
90 $routeProvider.when('/cat/catalog/batchEdit', {
91 templateUrl: './cat/catalog/t_batchedit',
92 controller: 'BatchEditCtrl',
96 $routeProvider.when('/cat/catalog/batchEdit/:container_type/:container_id', {
97 templateUrl: './cat/catalog/t_batchedit',
98 controller: 'BatchEditCtrl',
102 $routeProvider.when('/cat/catalog/vandelay', {
103 templateUrl: './cat/catalog/t_vandelay',
104 controller: 'VandelayCtrl',
108 $routeProvider.when('/cat/catalog/verifyURLs', {
109 templateUrl: './cat/catalog/t_verifyurls',
110 controller: 'URLVerifyCtrl',
114 $routeProvider.when('/cat/catalog/manageAuthorities', {
115 templateUrl: './cat/catalog/t_manageauthorities',
116 controller: 'ManageAuthoritiesCtrl',
120 $routeProvider.when('/cat/catalog/authority/:authority_id/marc_edit', {
121 templateUrl: './cat/catalog/t_authority',
122 controller: 'AuthorityCtrl',
126 $routeProvider.otherwise({redirectTo : '/cat/catalog/index'});
132 .controller('CatalogRecordRetrieve',
133 ['$scope','$routeParams','$location','$q','egCore',
134 function($scope , $routeParams , $location , $q , egCore ) {
136 $scope.focusMe = true;
138 // jump to the patron checkout UI
139 function loadRecord(record_id) {
141 .path('/cat/catalog/record/' + record_id);
144 function loadAuthorityRecord(record_id) {
146 .path('/cat/catalog/authority/' + record_id + '/marc_edit');
149 $scope.submitId = function(args) {
150 $scope.recordNotFound = null;
151 if (!args.record_id) return;
153 // blur so next time it's set to true it will re-apply select()
154 $scope.selectMe = false;
156 return loadRecord(args.record_id);
159 $scope.submitAuthorityId = function(args) {
160 if (!args.record_id) return;
162 // blur so next time it's set to true it will re-apply select()
163 $scope.selectMe = false;
165 return loadAuthorityRecord(args.record_id);
168 $scope.submitTCN = function(args) {
169 $scope.recordNotFound = null;
170 $scope.moreRecordsFound = null;
171 if (!args.record_tcn) return;
173 // blur so next time it's set to true it will re-apply select()
174 $scope.selectMe = false;
179 'open-ils.search.biblio.tcn',
182 .then(function(resp) { // get_barcodes
184 if (evt = egCore.evt.parse(resp)) {
190 $scope.recordNotFound = args.record_tcn;
191 $scope.selectMe = true;
195 if (resp.count > 1) {
196 $scope.moreRecordsFound = args.record_tcn;
197 $scope.selectMe = true;
201 var record_id = resp.ids[0];
202 return loadRecord(record_id);
208 .controller('NewBibCtrl',
209 ['$scope','$routeParams','$location','$window','$q','egCore',
210 'egGridDataProvider','egHoldGridActions','$timeout','holdingsSvc',
211 function($scope , $routeParams , $location , $window , $q , egCore) {
213 $scope.have_template = false;
214 $scope.marc_template = '';
215 $scope.stop_unload = false;
216 $scope.template_list = [];
217 $scope.template_name = '';
218 $scope.new_bib_id = 0;
222 'open-ils.cat.marc_template.types.retrieve'
223 ).then(function(resp) {
224 angular.forEach(resp, function(name) {
225 $scope.template_list.push(name);
227 $scope.template_list.sort();
229 $scope.template_name = egCore.hatch.getSessionItem('eg.cat.last_bib_marc_template');
230 if (!$scope.template_name) {
231 egCore.hatch.getItem('cat.default_bib_marc_template').then(function(template) {
232 $scope.template_name = template;
236 $scope.loadTemplate = function() {
237 if ($scope.template_name) {
240 'open-ils.cat.biblio.marc_template.retrieve',
242 ).then(function(template) {
243 $scope.marc_template = template;
244 $scope.have_template = true;
245 egCore.hatch.setSessionItem('eg.cat.last_bib_marc_template', $scope.template_name);
250 $scope.setDefaultTemplate = function() {
251 var hatch_key = "cat.default_bib_marc_template";
252 if ($scope.template_name) {
253 egCore.hatch.setItem(hatch_key, $scope.template_name);
255 egCore.hatch.removeItem(hatch_key);
259 $scope.$watch('new_bib_id', function(newVal, oldVal) {
261 $location.path('/cat/catalog/record/' + $scope.new_bib_id);
267 .controller('CatalogCtrl',
268 ['$scope','$routeParams','$location','$window','$q','egCore','egHolds','egCirc','egConfirmDialog','ngToast',
269 'egGridDataProvider','egHoldGridActions','egProgressDialog','$timeout','$uibModal','holdingsSvc','egUser','conjoinedSvc',
270 '$cookies','egSerialsCoreSvc',
271 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc , egConfirmDialog , ngToast ,
272 egGridDataProvider , egHoldGridActions , egProgressDialog , $timeout , $uibModal , holdingsSvc , egUser , conjoinedSvc,
273 $cookies , egSerialsCoreSvc
276 var holdingsSvcInst = new holdingsSvc();
278 // set record ID on page load if available...
279 $scope.record_id = $routeParams.record_id;
280 $scope.summary_pane_record;
282 if ($scope.record_id) {
283 // TODO: Apply tab-specific title contexts
284 egCore.strings.setPageTitle(
285 egCore.strings.PAGE_TITLE_BIB_DETAIL,
286 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT,
287 {record_id : $scope.record_id}
290 // Default to title = Catalog
291 egCore.strings.setPageTitle(
292 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT);
295 if ($routeParams.record_id) $scope.from_route = true;
296 else $scope.from_route = false;
298 // set search and preferred library cookies
299 egCore.hatch.getItem('eg.search.search_lib').then(function(val) {
300 $cookies.put('eg_search_lib', val, { path : '/' });
302 egCore.hatch.getItem('eg.search.pref_lib').then(function(val) {
303 $cookies.put('eg_pref_lib', val, { path : '/' });
306 // will hold a ref to the opac iframe
307 $scope.opac_iframe = null;
308 $scope.parts_iframe = null;
310 $scope.search_result_index = 1;
311 $scope.search_result_hit_count = 1;
314 'opac_iframe.dom.contentWindow.search_result_index',
316 if (!isNaN(parseInt(n)))
317 $scope.search_result_index = n + 1;
322 'opac_iframe.dom.contentWindow.search_result_hit_count',
324 if (!isNaN(parseInt(n)))
325 $scope.search_result_hit_count = n;
329 $scope.in_opac_call = false;
330 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
331 if ($scope.opac_iframe) {
332 if (force_opac_tab) $scope.record_tab = 'catalog';
333 $scope.in_opac_call = true;
334 $scope.opac_iframe.dom.contentWindow[opac_frame_function]();
335 if (opac_frame_function == 'rdetailBackToResults') {
336 $location.update_path('/cat/catalog/index');
341 $scope.add_cart_to_record_bucket = function() {
342 var cartkey = $cookies.get('cartcache');
343 if (!cartkey) return;
346 'open-ils.actor.anon_cache.get_value',
349 ).then(function(list) {
350 list = list.map(function(x) {
353 $scope.add_to_record_bucket(list);
357 $scope.add_to_record_bucket = function(recs) {
358 if (!angular.isArray(recs)) {
359 recs = [ $scope.record_id ];
361 return $uibModal.open({
362 templateUrl: './cat/catalog/t_add_to_bucket',
367 ['$scope','$uibModalInstance',
368 function($scope , $uibModalInstance) {
370 $scope.bucket_id = 0;
371 $scope.newBucketName = '';
372 $scope.allBuckets = [];
375 'open-ils.actor.container.retrieve_by_class.authoritative',
376 egCore.auth.token(), egCore.auth.user().id(),
377 'biblio', 'staff_client'
378 ).then(function(buckets) { $scope.allBuckets = buckets; });
380 $scope.add_to_bucket = function() {
382 angular.forEach(recs, function(recId) {
383 var item = new egCore.idl.cbrebi();
384 item.bucket($scope.bucket_id);
385 item.target_biblio_record_entry(recId);
386 promises.push(egCore.net.request(
388 'open-ils.actor.container.item.create',
389 egCore.auth.token(), 'biblio', item
392 $q.all(promises).then(function(resp) {
393 $uibModalInstance.close();
397 $scope.add_to_new_bucket = function() {
398 var bucket = new egCore.idl.cbreb();
399 bucket.owner(egCore.auth.user().id());
400 bucket.name($scope.newBucketName);
401 bucket.description('');
402 bucket.btype('staff_client');
406 'open-ils.actor.container.create',
407 egCore.auth.token(), 'biblio', bucket
408 ).then(function(bucket) {
409 $scope.bucket_id = bucket;
410 $scope.add_to_bucket();
414 $scope.cancel = function() {
415 $uibModalInstance.dismiss();
421 $scope.current_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record');
422 $scope.current_transfer_target = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
423 $scope.current_conjoined_target = egCore.hatch.getLocalItem('eg.cat.marked_conjoined_record');
425 $scope.quickReceive = function () {
427 var next_per_stream = {};
429 var recId = $scope.record_id;
430 return $uibModal.open({
431 templateUrl: './share/t_subscription_select_dialog',
433 controller: ['$scope', '$uibModalInstance',
434 function($scope, $uibModalInstance) {
437 $scope.rememberMe = 'eg.serials.quickreceive.last_org';
438 $scope.record_id = recId;
439 $scope.ssubId = null;
441 $scope.ok = function() { $uibModalInstance.close($scope.ssubId) }
442 $scope.cancel = function() { $uibModalInstance.dismiss(); }
445 }).result.then(function(ssubId) {
448 promises.push(egSerialsCoreSvc.fetchItemsForSub(ssubId,{status:'Expected'}).then(function(){
449 angular.forEach(egSerialsCoreSvc.itemTree, function (item) {
450 if (next_per_stream[item.stream().id()]) return;
451 if (item.status() == 'Expected') {
452 next_per_stream[item.stream().id()] = item;
453 list.push(egCore.idl.Clone(item));
458 return $q.all(promises).then(function() {
461 ngToast.warning(egCore.strings.SERIALS_NO_ITEMS);
465 return egSerialsCoreSvc.process_items(
471 false, // print by default
472 function() { $scope.holdings_record_id_changed($scope.record_id) }
476 ngToast.warning(egCore.strings.SERIALS_NO_SUBS);
482 $scope.markConjoined = function () {
483 $scope.current_conjoined_target = $scope.record_id;
484 egCore.hatch.setLocalItem('eg.cat.marked_conjoined_record',$scope.record_id);
485 ngToast.create(egCore.strings.MARK_CONJ_TARGET);
488 $scope.markHoldingsTransfer = function () {
489 $scope.current_transfer_target = $scope.record_id;
490 egCore.hatch.setLocalItem('eg.cat.transfer_target_record',$scope.record_id);
491 egCore.hatch.removeLocalItem('eg.cat.transfer_target_lib');
492 egCore.hatch.removeLocalItem('eg.cat.transfer_target_vol');
493 ngToast.create(egCore.strings.MARK_HOLDINGS_TARGET);
496 $scope.markOverlay = function () {
497 $scope.current_overlay_target = $scope.record_id;
498 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.record_id);
499 ngToast.create(egCore.strings.MARK_OVERLAY_TARGET);
502 $scope.clearRecordMarks = function () {
503 $scope.current_overlay_target = null;
504 $scope.current_transfer_target = null;
505 $scope.current_conjoined_target = null;
506 $scope.current_hold_transfer_dest = null;
507 egCore.hatch.removeLocalItem('eg.cat.transfer_target_record');
508 egCore.hatch.removeLocalItem('eg.cat.marked_conjoined_record');
509 egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');
510 egCore.hatch.removeLocalItem('eg.circ.hold.title_transfer_target');
513 $scope.stop_unload = false;
514 $scope.$watch('stop_unload',
515 function(newVal, oldVal) {
516 if (newVal && newVal != oldVal && $scope.opac_iframe) {
517 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
518 return 'There is unsaved data in this record.'
521 if ($scope.opac_iframe)
522 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
527 // Set the "last bib" cookie, if we have that
528 if ($scope.record_id)
529 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
531 $scope.refresh_record_callback = function (record_id) {
532 egCore.pcrud.retrieve('bre', record_id, {
535 bre : ['simple_record','creator','editor']
537 }).then(function(rec) {
538 rec.owner(egCore.org.get(rec.owner()));
539 $scope.summary_pane_record = rec;
545 patron_search_dialog = function() {
546 return $uibModal.open({
547 templateUrl: './share/t_patron_selector',
552 ['$scope','$uibModalInstance','$controller',
553 function($scope , $uibModalInstance , $controller) {
554 angular.extend(this, $controller('BasePatronSearchCtrl', {$scope : $scope}));
556 $scope.need_one_selected = function() {
557 var items = $scope.gridControls.selectedItems();
558 return (items.length == 1) ? false : true
560 $scope.ok = function() {
561 var items = $scope.gridControls.selectedItems();
562 if (items.length == 1) {
563 $uibModalInstance.close(items[0].card().barcode());
565 $uibModalInstance.close()
568 $scope.cancel = function($event) {
569 $uibModalInstance.dismiss();
570 $event.preventDefault();
576 // also set it when the iframe changes to a new record
577 $scope.handle_page = function(url) {
579 if (!url || url == 'about:blank') {
580 // nothing loaded. If we already have a record ID, leave it.
584 var match = url.match(/\/+opac\/+record\/+(\d+)/);
586 $scope.record_id = match[1];
587 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
588 $scope.holdings_record_id_changed($scope.record_id);
589 conjoinedSvc.fetch($scope.record_id).then(function(){
590 $scope.conjoinedGridDataProvider.refresh();
592 egHolds.fetch_holds(hold_ids).then($scope.hold_grid_data_provider.refresh);
594 $location.update_path('/cat/catalog/record/' + $scope.record_id);
595 // update_path() bypasses the controller for path
596 // /cat/catalog/record/:record_id. Manually set title here too.
597 egCore.strings.setPageTitle(
598 egCore.strings.PAGE_TITLE_BIB_DETAIL,
599 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT,
600 {record_id : $scope.record_id}
603 delete $scope.record_id;
604 $scope.from_route = false;
607 // child scope is executing this function, so our digest doesn't fire ... thus,
610 if (!$scope.in_opac_call) {
611 if ($scope.record_id && !$scope.record_tab) {
612 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
613 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
615 tab = $routeParams.record_tab || 'catalog';
617 $scope.set_record_tab(tab);
619 $scope.in_opac_call = false;
622 if ($scope.opac_iframe && $location.path().match(/cat\/catalog/)) {
623 var doc = $scope.opac_iframe.dom.contentWindow.document;
624 $(doc).find('#hold_usr_search').show();
625 $(doc).find('#hold_usr_search').on('click', function() {
626 patron_search_dialog().result.then(function(barc) {
627 $(doc).find('#hold_usr_input').val(barc);
628 $(doc).find('#hold_usr_input').change();
631 $(doc).find('#select_basket_action').on('change', function() {
632 if (this.options[this.selectedIndex].value && this.options[this.selectedIndex].value == "add_cart_to_bucket") {
633 $scope.add_cart_to_record_bucket();
640 // xulG catalog handlers
641 $scope.handlers = { }
643 // ------------------------------------------------------------------
646 $scope.conjoinedGridControls = {};
647 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
648 get : function(offset, count) {
649 return this.arrayNotifier(conjoinedSvc.items, offset, count);
653 $scope.changeConjoinedType = function () {
654 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
655 angular.forEach(peers, function (p) {
656 p.target_copy(p.target_copy().id());
657 p.peer_type(p.peer_type().id());
660 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
662 return $uibModal.open({
663 templateUrl: './cat/catalog/t_conjoined_selector',
667 ['$scope','$uibModalInstance',
668 function($scope , $uibModalInstance) {
669 $scope.update = true;
671 $scope.peer_type = null;
672 $scope.peer_type_list = [];
673 conjoinedSvc.get_peer_types().then(function(list){
674 $scope.peer_type_list = list;
677 $scope.ok = function(type) {
680 angular.forEach(peers, function (p) {
683 promises.push(egCore.pcrud.update(p));
686 return $q.all(promises)
687 .then(function(){$uibModalInstance.close()})
688 .then(function(){return conjoinedSvc.fetch()})
689 .then(function(){conjoinedGridDataProviderRef.refresh()});
692 $scope.cancel = function($event) {
693 $uibModalInstance.dismiss();
694 $event.preventDefault();
701 $scope.refreshConjoined = function () {
702 conjoinedSvc.fetch($scope.record_id)
703 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
706 $scope.deleteSelectedConjoined = function () {
707 var peers = $scope.conjoinedGridControls.selectedItems();
709 if (peers.length > 0) {
710 egConfirmDialog.open(
711 egCore.strings.CONFIRM_DELETE_PEERS,
712 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
713 {peers : peers.length}
714 ).result.then(function() {
715 angular.forEach(peers, function (p) {
719 egCore.pcrud.remove(peers).then(function() {
720 return conjoinedSvc.fetch();
722 $scope.conjoinedGridDataProvider.refresh();
727 if ($scope.record_id)
728 conjoinedSvc.fetch($scope.record_id);
730 // ------------------------------------------------------------------
733 $scope.holdingsGridControls = {
734 activateItem : function (item) {
735 $scope.selectedHoldingsVolCopyEdit();
738 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
739 get : function(offset, count) {
740 return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
744 $scope.add_copies_to_bucket = function() {
745 var copy_list = gatherSelectedHoldingsIds();
746 if (copy_list.length == 0) return;
748 return $uibModal.open({
749 templateUrl: './cat/catalog/t_add_to_bucket',
754 ['$scope','$uibModalInstance',
755 function($scope , $uibModalInstance) {
757 $scope.bucket_id = 0;
758 $scope.newBucketName = '';
759 $scope.allBuckets = [];
763 'open-ils.actor.container.retrieve_by_class.authoritative',
764 egCore.auth.token(), egCore.auth.user().id(),
765 'copy', 'staff_client'
766 ).then(function(buckets) { $scope.allBuckets = buckets; });
768 $scope.add_to_bucket = function() {
770 angular.forEach(copy_list, function (cp) {
771 var item = new egCore.idl.ccbi()
772 item.bucket($scope.bucket_id);
773 item.target_copy(cp);
777 'open-ils.actor.container.item.create',
778 egCore.auth.token(), 'copy', item
782 return $q.all(promises).then(function() {
783 $uibModalInstance.close();
788 $scope.add_to_new_bucket = function() {
789 var bucket = new egCore.idl.ccb();
790 bucket.owner(egCore.auth.user().id());
791 bucket.name($scope.newBucketName);
792 bucket.description('');
793 bucket.btype('staff_client');
795 return egCore.net.request(
797 'open-ils.actor.container.create',
798 egCore.auth.token(), 'copy', bucket
799 ).then(function(bucket) {
800 $scope.bucket_id = bucket;
801 $scope.add_to_bucket();
805 $scope.cancel = function() {
806 $uibModalInstance.dismiss();
812 // TODO: refactor common code between cat/catalog/app.js and cat/item/app.js
814 $scope.need_one_selected = function() {
815 var items = $scope.holdingsGridControls.selectedItems();
816 if (items.length == 1) return false;
820 $scope.make_copies_bookable = function() {
822 var copies_by_record = {};
823 var record_list = [];
825 $scope.holdingsGridControls.selectedItems(),
827 var record_id = item['call_number.record.id'];
828 if (typeof copies_by_record[ record_id ] == 'undefined') {
829 copies_by_record[ record_id ] = [];
830 record_list.push( record_id );
832 copies_by_record[ record_id ].push(item.id);
837 var combined_results = [];
838 angular.forEach(record_list, function(record_id) {
842 'open-ils.booking.resources.create_from_copies',
844 copies_by_record[record_id]
845 ).then(function(results) {
846 if (results && results['brsrc']) {
847 combined_results = combined_results.concat(results['brsrc']);
853 $q.all(promises).then(function() {
854 if (combined_results.length > 0) {
856 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
861 ['$scope','$location','egCore','$uibModalInstance',
862 function($scope , $location , egCore , $uibModalInstance) {
865 ses : egCore.auth.token(),
866 resultant_brsrc : combined_results.map(function(o) { return o[0]; })
869 var booking_path = '/eg/conify/global/booking/resource';
871 $scope.booking_admin_url =
872 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
879 $scope.book_copies_now = function() {
880 var copies_by_record = {};
881 var record_list = [];
883 $scope.holdingsGridControls.selectedItems(),
885 var record_id = item['call_number.record.id'];
886 if (typeof copies_by_record[ record_id ] == 'undefined') {
887 copies_by_record[ record_id ] = [];
888 record_list.push( record_id );
890 copies_by_record[ record_id ].push(item.id);
895 var combined_brt = [];
896 var combined_brsrc = [];
897 angular.forEach(record_list, function(record_id) {
901 'open-ils.booking.resources.create_from_copies',
903 copies_by_record[record_id]
904 ).then(function(results) {
905 if (results && results['brt']) {
906 combined_brt = combined_brt.concat(results['brt']);
908 if (results && results['brsrc']) {
909 combined_brsrc = combined_brsrc.concat(results['brsrc']);
915 $q.all(promises).then(function() {
916 if (combined_brt.length > 0 || combined_brsrc.length > 0) {
918 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
923 ['$scope','$location','egCore','$uibModalInstance',
924 function($scope , $location , egCore , $uibModalInstance) {
927 ses : egCore.auth.token(),
928 bresv_interface_opts : {
931 ,brsrc : combined_brsrc
936 var booking_path = '/eg/booking/reservation';
938 $scope.booking_admin_url =
939 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
948 $scope.requestItems = function() {
949 var copy_list = gatherSelectedHoldingsIds();
950 if (copy_list.length == 0) return;
952 return $uibModal.open({
953 templateUrl: './cat/catalog/t_request_items',
956 ['$scope','$uibModalInstance',
957 function($scope , $uibModalInstance) {
959 $scope.first_user_fetch = true;
963 copy_list : copy_list,
964 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
965 user : egCore.auth.user().id()
968 egUser.get( $scope.hold_data.user ).then(function(u) {
970 $scope.barcode = u.card().barcode();
971 $scope.user_name = egUser.format_name(u);
972 $scope.hold_data.user = u.id();
975 $scope.user_name = '';
977 $scope.$watch('barcode', function (n) {
978 if (!$scope.first_user_fetch) {
979 egUser.getByBarcode(n).then(function(u) {
981 $scope.user_name = egUser.format_name(u);
982 $scope.hold_data.user = u.id();
985 $scope.user_name = '';
986 delete $scope.hold_data.user;
989 $scope.first_user_fetch = false;
992 $scope.ok = function(h) {
995 hold_type : h.hold_type,
996 pickup_lib: h.pickup_lib.id(),
1002 'open-ils.circ.holds.test_and_create.batch.override',
1003 egCore.auth.token(), args, h.copy_list
1006 $uibModalInstance.close();
1009 $scope.cancel = function($event) {
1010 $uibModalInstance.dismiss();
1011 $event.preventDefault();
1017 $scope.view_place_orders = function() {
1018 if (!$scope.record_id) return;
1019 var url = egCore.env.basePath + 'acq/legacy/lineitem/related/' + $scope.record_id + '?target=bib';
1020 $timeout(function() { $window.open(url, '_blank') });
1023 $scope.replaceBarcodes = function() {
1024 var copy_list = gatherSelectedRawCopies();
1025 if (copy_list.length == 0) return;
1027 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
1029 angular.forEach(copy_list, function (cp) {
1031 templateUrl: './cat/share/t_replace_barcode',
1035 ['$scope','$uibModalInstance',
1036 function($scope , $uibModalInstance) {
1037 $scope.isModal = true;
1038 $scope.focusBarcode = false;
1039 $scope.focusBarcode2 = true;
1040 $scope.barcode1 = cp.barcode();
1042 $scope.updateBarcode = function() {
1043 $scope.copyNotFound = false;
1044 $scope.updateOK = false;
1046 egCore.pcrud.search('acp',
1047 {deleted : 'f', barcode : $scope.barcode1})
1048 .then(function(copy) {
1051 $scope.focusBarcode = true;
1052 $scope.copyNotFound = true;
1056 $scope.copyId = copy.id();
1057 copy.barcode($scope.barcode2);
1059 egCore.pcrud.update(copy).then(function(stat) {
1060 $scope.updateOK = stat;
1061 $scope.focusBarcode = true;
1062 holdingsSvc.fetchAgain().then(function (){
1063 holdingsGridDataProviderRef.refresh();
1068 $uibModalInstance.close();
1071 $scope.cancel = function($event) {
1072 $uibModalInstance.dismiss();
1073 $event.preventDefault();
1081 // refresh the list of holdings when the record_id is changed.
1082 $scope.holdings_record_id_changed = function(id) {
1083 if ($scope.record_id != id) $scope.record_id = id;
1084 console.log('record id changed to ' + id + ', loading new holdings');
1085 holdingsSvcInst.fetch({
1086 rid : $scope.record_id,
1087 org : $scope.holdings_ou,
1088 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1089 vol : $scope.holdings_show_vols,
1090 empty: $scope.holdings_show_empty,
1091 empty_org: $scope.holdings_show_empty_org
1092 }).then(function() {
1093 $scope.holdingsGridDataProvider.refresh();
1097 // refresh the list of holdings when the filter lib is changed.
1098 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
1099 $scope.holdings_ou_changed = function(org) {
1100 $scope.holdings_ou = org;
1101 holdingsSvcInst.fetch({
1102 rid : $scope.record_id,
1103 org : $scope.holdings_ou,
1104 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1105 vol : $scope.holdings_show_vols,
1106 empty: $scope.holdings_show_empty,
1107 empty_org: $scope.holdings_show_empty_org
1108 }).then(function() {
1109 $scope.holdingsGridDataProvider.refresh();
1113 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
1114 $scope[cb] = newVal;
1115 var x = $scope.holdings_show_vols ? $scope.holdings_show_copies : false;
1116 $('#holdings_show_copies').prop('checked', x);
1117 egCore.hatch.setItem('cat.' + cb, newVal);
1118 if (!norefresh) holdingsSvcInst.fetch({
1119 rid : $scope.record_id,
1120 org : $scope.holdings_ou,
1121 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1122 vol : $scope.holdings_show_vols,
1123 empty: $scope.holdings_show_empty,
1124 empty_org: $scope.holdings_show_empty_org
1125 }).then(function() {
1126 $scope.holdingsGridDataProvider.refresh();
1130 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
1131 if (typeof x == 'undefined') x = true;
1132 $scope.holdings_cb_changed('holdings_show_vols',x,true);
1133 $('#holdings_show_vols').prop('checked', x);
1135 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
1136 if (typeof x == 'undefined') x = true;
1137 $scope.holdings_cb_changed('holdings_show_copies',x,true);
1138 x = $scope.holdings_show_vols ? x : false;
1139 $('#holdings_show_copies').prop('checked', x);
1141 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
1142 if (typeof x == 'undefined') x = true;
1143 $scope.holdings_cb_changed('holdings_show_empty',x);
1144 $('#holdings_show_empty').prop('checked', x);
1146 egCore.hatch.getItem('cat.holdings_show_empty_org').then(function(x){
1147 if (typeof x == 'undefined') x = true;
1148 $scope.holdings_cb_changed('holdings_show_empty_org',x);
1149 $('#holdings_show_empty_org').prop('checked', x);
1155 $scope.vols_not_shown = function () {
1156 return !$scope.holdings_show_vols;
1159 $scope.copies_not_shown = function () {
1160 return !$scope.holdings_show_copies;
1163 $scope.empty_org_not_shown = function () {
1164 return !$scope.holdings_show_empty_org;
1167 $scope.holdings_checkbox_handler = function (item) {
1168 $scope.holdings_cb_changed(item.checkbox,item.checked);
1171 function gatherSelectedHoldingsIds () {
1172 var cp_id_list = [];
1174 $scope.holdingsGridControls.selectedItems(),
1175 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
1180 function gatherSelectedRawCopies () {
1183 $scope.holdingsGridControls.selectedItems(),
1184 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
1189 function gatherSelectedEmptyVolumeIds () {
1190 var cn_id_list = [];
1192 $scope.holdingsGridControls.selectedItems(),
1194 if (item.copy_count == 0 || (!item.id && item.call_number))
1195 // we are in a compressed row with no copies, or we are in a single
1196 // call number row with no copy (testing for presence of 'id')
1197 // In either case, the call number is 'empty'
1198 cn_id_list.push(item.call_number.id)
1204 function gatherSelectedVolumeIds () {
1205 var cn_id_list = [];
1207 $scope.holdingsGridControls.selectedItems(),
1209 if (cn_id_list.indexOf(item.call_number.id) == -1)
1210 cn_id_list.push(item.call_number.id)
1216 $scope.selectedHoldingsDelete = function (vols, copies) {
1219 var perCnCopies = {};
1225 $scope.holdingsGridControls.selectedItems(),
1227 if (vols && item.raw_call_number) {
1228 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
1229 cnHash[item.call_number.id].isdeleted(1);
1231 } else if (copies) {
1232 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
1235 var cn_id = cp.call_number().id();
1236 if (!cnHash[cn_id]) {
1237 cnHash[cn_id] = cp.call_number();
1238 perCnCopies[cn_id] = [cp];
1240 perCnCopies[cn_id].push(cp);
1242 cp.call_number(cn_id); // prevent loops in JSON-ification
1249 angular.forEach(perCnCopies, function (v, k) {
1251 cnHash[k].isdeleted(1);
1254 cnHash[k].copies(v);
1258 angular.forEach(cnHash, function (v, k) {
1262 if (cnList.length == 0) return;
1265 if (vols && copies) flags.force_delete_copies = 1;
1267 egConfirmDialog.open(
1268 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
1269 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
1270 {copies : cp_count, volumes : cn_count}
1271 ).result.then(function() {
1274 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1275 egCore.auth.token(), cnList, 1, flags
1276 ).then(function(update_count) {
1277 holdingsSvcInst.fetchAgain().then(function() {
1278 $scope.holdingsGridDataProvider.refresh();
1283 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
1284 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
1285 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
1287 spawnHoldingsAdd = function (add_vols,add_copies){
1289 if (!add_vols && add_copies) { // just a copy on existing volumes
1290 angular.forEach(gatherSelectedVolumeIds(), function (v) {
1291 raw.push( {callnumber : v} );
1293 } else if (add_vols) {
1294 if (typeof $scope.holdingsGridControls.selectedItems == "function" &&
1295 $scope.holdingsGridControls.selectedItems().length > 0) {
1296 angular.forEach($scope.holdingsGridControls.selectedItems(),
1299 owner : item.owner_id,
1300 label : ((item.call_number) ? item.call_number.label : null)
1305 owner : egCore.auth.user().ws_ou()
1310 if (raw.length == 0) raw.push({});
1314 'open-ils.actor.anon_cache.set_value',
1315 null, 'edit-these-copies', {
1316 record_id: $scope.record_id,
1319 hide_copies : !add_copies
1321 ).then(function(key) {
1323 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1324 $timeout(function() { $window.open(url, '_blank') });
1326 alert('Could not create anonymous cache key!');
1330 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,true) }
1331 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
1332 $scope.selectedHoldingsVolAdd = function () { spawnHoldingsAdd(true,false) }
1334 spawnHoldingsEdit = function (hide_vols,hide_copies){
1337 'open-ils.actor.anon_cache.set_value',
1338 null, 'edit-these-copies', {
1339 record_id: $scope.record_id,
1340 copies: gatherSelectedHoldingsIds(),
1341 raw: gatherSelectedEmptyVolumeIds().map(
1342 function(v){ return { callnumber : v } }
1344 hide_vols : hide_vols,
1345 hide_copies : hide_copies
1347 ).then(function(key) {
1349 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1350 $timeout(function() { $window.open(url, '_blank') });
1352 alert('Could not create anonymous cache key!');
1356 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
1357 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
1358 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
1360 $scope.selectedHoldingsItemStatus = function (){
1361 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
1362 $timeout(function() { $window.open(url, '_blank') });
1365 $scope.markFromSelectedAsHoldingsTarget = function() {
1366 egCore.hatch.setLocalItem(
1367 'eg.cat.transfer_target_lib',
1368 $scope.holdingsGridControls.selectedItems()[0].owner_id
1370 egCore.hatch.setLocalItem(
1371 'eg.cat.transfer_target_record',
1374 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed, or we are on an empty lib
1375 egCore.hatch.setLocalItem(
1376 'eg.cat.transfer_target_vol',
1377 $scope.holdingsGridControls.selectedItems()[0].call_number.id
1380 // clear out the stale value if we're on a lib-only
1381 // or vol-collapsed row
1382 egCore.hatch.removeLocalItem('eg.cat.transfer_target_vol');
1384 ngToast.create(egCore.strings.MARK_HOLDINGS_TARGET);
1387 $scope.selectedHoldingsItemStatusDetail = function (){
1389 gatherSelectedHoldingsIds(),
1391 var url = egCore.env.basePath +
1393 $timeout(function() { $window.open(url, '_blank') });
1398 $scope.transferVolumes = function (){
1399 var target_record = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
1400 var target_lib = egCore.hatch.getLocalItem('eg.cat.transfer_target_lib');
1402 && (!target_record || ($scope.record_id == target_record) )
1405 var vols_to_move = {};
1407 // we're moving volumes to a different library
1408 var vol_ids = gatherSelectedVolumeIds();
1409 if (vol_ids.length) {
1410 vols_to_move[target_lib] = vol_ids;
1412 // if we're *only* switching libs,
1413 // grab the current record as the target
1414 target_record = target_record || $scope.record_id;
1417 // we're moving volumes to the same library they exist in
1418 // currently, but on a different record
1419 var items = $scope.holdingsGridControls.selectedItems();
1420 angular.forEach(items, function(item) {
1421 if (!(item.call_number.owning_lib in vols_to_move)) {
1422 vols_to_move[item.call_number.owning_lib] = new Array;
1424 vols_to_move[item.call_number.owning_lib].push(item.call_number.id);
1429 angular.forEach(vols_to_move, function(vols, owning_lib) {
1430 promises.push(egCore.net.request(
1432 'open-ils.cat.asset.volume.batch.transfer.override',
1433 egCore.auth.token(), {
1434 docid : target_record,
1440 $q.all(promises).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!');
1452 // this "transfers" selected copies to a new owning library,
1453 // auto-creating volumes as required
1454 $scope.transferItemsAutoFill = function() {
1455 var target_record = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
1456 var target_lib = egCore.hatch.getLocalItem('eg.cat.transfer_target_lib');
1458 && (!target_record || ($scope.record_id == target_record) )
1461 var items = $scope.holdingsGridControls.selectedItems();
1462 if (!items.length) {
1466 var vols_to_move = {};
1467 var copies_to_move = {};
1468 angular.forEach(items, function(item) {
1469 var needs_move = false;
1471 && (item.call_number.owning_lib != target_lib)) {
1472 item.call_number.owning_lib = target_lib;
1476 && (item.call_number.record != target_record)) {
1477 item.call_number.record = target_record;
1481 if (item.call_number.id in vols_to_move) {
1482 copies_to_move[item.call_number.id].push(item.id);
1484 vols_to_move[item.call_number.id] = item.call_number;
1485 copies_to_move[item.call_number.id] = new Array;
1486 copies_to_move[item.call_number.id].push(item.id);
1492 angular.forEach(vols_to_move, function(vol) {
1493 promises.push(egCore.net.request(
1495 'open-ils.cat.call_number.find_or_create',
1496 egCore.auth.token(),
1498 vol.record, // may be new
1499 vol.owning_lib, // may be new
1503 ).then(function(resp) {
1504 var evt = egCore.evt.parse(resp);
1506 return egCore.net.request(
1508 'open-ils.cat.transfer_copies_to_volume',
1509 egCore.auth.token(),
1511 copies_to_move[vol.id]
1515 $q.all(promises).then(function() {
1516 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1517 holdingsSvcInst.fetchAgain().then(function() {
1518 $scope.holdingsGridDataProvider.refresh();
1523 $scope.gridCellHandlers = {};
1524 $scope.gridCellHandlers.copyAlertsEdit = function(id) {
1525 egCirc.manage_copy_alerts([id]).then(function() {
1526 // update grid items?
1530 $scope.transferItems = function (){
1531 var xfer_target = egCore.hatch.getLocalItem('eg.cat.transfer_target_vol');
1534 // we have no specific volume, let's try to fill in the
1536 return $scope.transferItemsAutoFill();
1539 var copy_ids = gatherSelectedHoldingsIds();
1540 if (copy_ids.length > 0) {
1543 'open-ils.cat.transfer_copies_to_volume',
1544 egCore.auth.token(),
1548 function(resp) { // oncomplete
1549 var evt = egCore.evt.parse(resp);
1551 egConfirmDialog.open(
1552 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1553 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1554 {'evt_desc': evt.desc}
1555 ).result.then(function() {
1558 'open-ils.cat.transfer_copies_to_volume.override',
1559 egCore.auth.token(),
1562 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1563 ).then(function(resp) {
1564 holdingsSvcInst.fetchAgain().then(function() {
1565 $scope.holdingsGridDataProvider.refresh();
1570 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1571 holdingsSvcInst.fetchAgain().then(function() {
1572 $scope.holdingsGridDataProvider.refresh();
1582 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1584 gatherSelectedHoldingsIds(),
1586 var url = egCore.env.basePath +
1587 'cat/item/' + cid + '/triggered_events';
1588 $timeout(function() { $window.open(url, '_blank') });
1593 $scope.selectedHoldingsItemStatusHolds = function (){
1595 gatherSelectedHoldingsIds(),
1597 var url = egCore.env.basePath +
1598 'cat/item/' + cid + '/holds';
1599 $timeout(function() { $window.open(url, '_blank') });
1604 $scope.selectedHoldingsPrintLabels = function() {
1607 'open-ils.actor.anon_cache.set_value',
1608 null, 'print-labels-these-copies', {
1609 copies : gatherSelectedHoldingsIds()
1611 ).then(function(key) {
1613 var url = egCore.env.basePath + 'cat/printlabels/' + key;
1614 $timeout(function() { $window.open(url, '_blank') });
1616 alert('Could not create anonymous cache key!');
1621 $scope.selectedHoldingsDamaged = function () {
1622 var copy_list = gatherSelectedRawCopies();
1623 if (copy_list.length == 0) return;
1625 angular.forEach(copy_list, function(cp) {
1626 egCirc.mark_damaged({
1628 barcode: cp.barcode(),
1629 circ_lib: cp.circ_lib().id()
1630 }).then(function() {
1631 holdingsSvcInst.fetchAgain().then(function() {
1632 $scope.holdingsGridDataProvider.refresh();
1638 $scope.selectedHoldingsMissing = function () {
1639 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1640 holdingsSvcInst.fetchAgain().then(function() {
1641 $scope.holdingsGridDataProvider.refresh();
1646 $scope.selectedHoldingsCopyAlertsAdd = function() {
1647 egCirc.add_copy_alerts(gatherSelectedHoldingsIds()).then(function() {
1648 // no need to refresh grid
1651 $scope.selectedHoldingsCopyAlertsManage = function() {
1652 egCirc.manage_copy_alerts(gatherSelectedHoldingsIds()).then(function() {
1653 // no need to refresh grid
1657 $scope.attach_to_peer_bib = function() {
1658 var copy_list = gatherSelectedHoldingsIds();
1659 if (copy_list.length == 0) return;
1661 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1662 if (!target_record) return;
1664 return $uibModal.open({
1665 templateUrl: './cat/catalog/t_conjoined_selector',
1669 ['$scope','$uibModalInstance',
1670 function($scope , $uibModalInstance) {
1671 $scope.update = false;
1673 $scope.peer_type = null;
1674 $scope.peer_type_list = [];
1675 conjoinedSvc.get_peer_types().then(function(list){
1676 $scope.peer_type_list = list;
1679 $scope.ok = function(type) {
1682 angular.forEach(copy_list, function (cp) {
1683 var n = new egCore.idl.bpbcm();
1685 n.peer_record(target_record);
1688 promises.push(egCore.pcrud.create(n));
1691 return $q.all(promises).then(function(){$uibModalInstance.close()});
1694 $scope.cancel = function($event) {
1695 $uibModalInstance.dismiss();
1696 $event.preventDefault();
1704 // ------------------------------------------------------------------
1706 var provider = egGridDataProvider.instance({});
1707 $scope.hold_grid_data_provider = provider;
1708 $scope.grid_actions = egHoldGridActions;
1709 $scope.grid_actions.refresh = function () { provider.refresh() };
1710 $scope.hold_grid_controls = {};
1712 var hold_ids = []; // current list of holds
1713 function fetchHolds(offset, count) {
1714 var ids = hold_ids.slice(offset, offset + count);
1716 return egHolds.fetch_holds(ids).then(null, null,
1717 function(hold_data) {
1723 provider.get = function(offset, count) {
1724 if ($scope.record_tab != 'holds') return $q.when();
1725 var deferred = $q.defer();
1726 hold_ids = []; // no caching ATM
1728 // open a determinate progress dialog, max value set below.
1729 egProgressDialog.open({max : 1, value : 0});
1734 'open-ils.circ.holds.retrieve_all_from_title',
1735 egCore.auth.token(), $scope.record_id,
1736 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
1738 function(hold_data) {
1739 hold_ids = []; // clear the list of ids, hack to avoid dups
1740 // TODO: fix the underlying problem, which is that
1741 // this gets called twice when switching to the holds
1742 // tab; once explicitly, and once via the change handler
1743 // on the OU selector
1744 angular.forEach(hold_data, function(list, type) {
1745 hold_ids = hold_ids.concat(list);
1748 // Set the max value of the progress bar to the lesser of
1749 // the total number of holds to fetch or the page size
1751 egProgressDialog.update(
1752 {max : Math.min(hold_ids.length, count)});
1754 var holds_fetched = 0;
1755 fetchHolds(offset, count)
1756 .then(deferred.resolve, null,
1757 function(hold_data) {
1759 deferred.notify(hold_data);
1760 egProgressDialog.increment();
1762 )['finally'](egProgressDialog.close);
1766 return deferred.promise;
1769 $scope.detail_view = function(action, user_data, items) {
1771 $scope.detail_hold_id = h.hold.id();
1775 $scope.list_view = function(items) {
1776 $scope.detail_hold_id = null;
1779 // refresh the list of record holds when the pickup lib is changed.
1780 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1781 $scope.pickup_ou_changed = function(org) {
1782 $scope.pickup_ou = org;
1786 $scope.print_holds = function() {
1788 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1790 hold : egCore.idl.toHash(item.hold),
1791 patron_last : item.patron_last,
1792 patron_alias : item.patron_alias,
1793 patron_barcode : item.patron_barcode,
1794 copy : egCore.idl.toHash(item.copy),
1795 volume : egCore.idl.toHash(item.volume),
1796 title : item.mvr.title(),
1797 author : item.mvr.author()
1801 egCore.print.print({
1802 context : 'receipt',
1803 template : 'holds_for_bib',
1804 scope : {holds : holds}
1808 $scope.current_hold_transfer_dest = egCore.hatch.getLocalItem ('eg.circ.hold.title_transfer_target');
1810 $scope.mark_hold_transfer_dest = function() {
1811 $scope.current_hold_transfer_dest = $scope.record_id;
1812 egCore.hatch.setLocalItem(
1813 'eg.circ.hold.title_transfer_target', $scope.record_id);
1814 ngToast.create(egCore.strings.HOLD_TRANSFER_DEST_MARKED);
1817 // UI presents this option as "all holds"
1818 $scope.transfer_holds_to_marked = function() {
1819 var hold_ids = $scope.hold_grid_controls.allItems().map(
1820 function(hold_data) {return hold_data.hold.id()});
1821 egHolds.transfer_to_marked_title(hold_ids);
1824 // ------------------------------------------------------------------
1825 // Initialize the selected tab
1827 // we explicitly initialize catalog_url because otherwise Firefox
1828 // ends up setting it to $BASE_URL/{{url}}, which then messes
1829 // things up. See LP#1708951
1830 $scope.catalog_url = '';
1832 function init_cat_url() {
1833 // Set the initial catalog URL. This only happens once.
1834 // The URL is otherwise generated through user navigation.
1835 if ($scope.catalog_url) return;
1837 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1839 // A record ID in the path indicates a request for the record-
1841 if ($routeParams.record_id) {
1842 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1845 // Jumping directly to the results page by passing a search
1846 // query via the URL. Copy all URL params to the iframe url.
1847 if ($location.path().match(/catalog\/results/)) {
1848 url = url.replace(/advanced/, '/results?');
1850 angular.forEach($location.search(), function(val, key) {
1851 if (!first) url += '&';
1853 url += encodeURIComponent(key)
1854 + '=' + encodeURIComponent(val);
1858 // if we're displaying the advanced search form, select
1859 // whatever default pane the user has chosen via workstation
1861 if (url.match(/\/opac\/advanced$/)) {
1862 var adv_pane = egCore.hatch.getLocalItem('eg.search.adv_pane');
1864 url += '?pane=' + encodeURIComponent(adv_pane);
1868 $scope.catalog_url = url;
1871 function init_parts_url() {
1872 $scope.parts_url = $location
1876 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1880 $scope.set_record_tab = function(tab) {
1881 $scope.record_tab = tab;
1894 $scope.detail_hold_record_id = $scope.record_id;
1895 // refresh the holds grid
1902 $scope.set_default_record_tab = function() {
1903 egCore.hatch.setLocalItem(
1904 'eg.cat.default_record_tab', $scope.record_tab);
1905 $timeout(function(){$scope.default_tab = $scope.record_tab});
1909 if ($scope.record_id) {
1910 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1911 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1914 tab = $routeParams.record_tab || 'catalog';
1916 $scope.set_record_tab(tab);
1920 .controller('AuthorityCtrl',
1921 ['$scope','$routeParams','$location','$window','$q','egCore',
1922 function($scope , $routeParams , $location , $window , $q , egCore) {
1924 // set record ID on page load if available...
1925 $scope.authority_id = $routeParams.authority_id;
1927 if ($routeParams.authority_id) $scope.from_route = true;
1928 else $scope.from_route = false;
1930 $scope.stop_unload = false;
1933 .controller('URLVerifyCtrl',
1934 ['$scope','$location',
1935 function($scope , $location) {
1936 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1939 .controller('VandelayCtrl',
1940 ['$scope','$location', 'egCore', '$uibModal',
1941 function($scope , $location, egCore, $uibModal) {
1942 $scope.vandelay_url = $location.absUrl().replace(/\/staff\/cat\/catalog\/vandelay/, '/vandelay/vandelay');
1944 $scope.funcs.edit_marc_modal = function(bre, callback){
1945 var marcArgs = { 'marc_xml': bre.marc() };
1946 var vqbibrecId = bre.id();
1948 templateUrl: './cat/catalog/t_edit_marc_modal',
1951 controller: ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
1952 $scope.focusMe = true;
1953 $scope.recordId = vqbibrecId;
1954 $scope.args = marcArgs;
1955 $scope.dirty_flag = false;
1956 $scope.ok = function(marg){
1957 $uibModalInstance.close(marg);
1959 $scope.cancel = function(){ $uibModalInstance.dismiss() }
1961 }).result.then(function(res){
1962 var new_xml = res.marc_xml;
1963 egCore.pcrud.retrieve('vqbr', vqbibrecId).then(function(vqbib){
1964 vqbib.marc(new_xml);
1965 egCore.pcrud.update(vqbib).then( function(){ callback(vqbibrecId); });
1971 .controller('ManageAuthoritiesCtrl',
1972 ['$scope','$location',
1973 function($scope , $location) {
1974 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1977 .controller('BatchEditCtrl',
1978 ['$scope','$location','$routeParams',
1979 function($scope , $location , $routeParams) {
1980 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1981 if ($routeParams.container_type) {
1982 switch ($routeParams.container_type) {
1984 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1987 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1994 .filter('boolText', function(){
1995 return function (v) {
2000 .factory('conjoinedSvc',
2002 function(egCore , $q) {
2005 items : [], // record search results
2006 index : 0, // search grid index
2013 bpbcm : ['target_copy','peer_type'],
2014 acp : ['call_number'],
2016 bre : ['simple_record']
2018 // avoid fetching the MARC blob by specifying which
2019 // fields on the bre to select. More may be needed.
2020 // note that fleshed fields are explicitly selected.
2021 select : { bre : ['id'] },
2022 order_by : { bpbcm : ['id'] },
2025 // resolved with the last received copy
2026 service.fetch = function(rid) {
2027 if (!rid && !service.rid) return $q.when();
2029 if (rid) service.rid = rid;
2033 return egCore.pcrud.search(
2035 {peer_record : service.rid},
2038 ).then( function(list) { // finished
2039 service.items = list;
2040 return service.items;
2044 // returns a promise resolved with the list of peer bib types
2045 service.get_peer_types = function() {
2047 return $q.when(egCore.env.bpt.list);
2049 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
2050 .then(function(list) {
2051 egCore.env.absorbList(list, 'bpt');