4 * currently, this app doesn't use routes for each sub-ui, because
5 * reloading the catalog each time is sloooow. better so far to
6 * swap out divs w/ ng-if / ng-show / ng-hide as needed.
10 angular.module('egCatalogApp', ['ui.bootstrap','ngRoute','ngLocationUpdate','egCoreMod','egGridMod', 'egMarcMod', 'egUserMod', 'egHoldingsMod', 'ngToast','egPatronSearchMod',
11 'egSerialsMod','egSerialsAppDep'])
13 .config(['ngToastProvider', function(ngToastProvider) {
14 ngToastProvider.configure({
15 verticalPosition: 'bottom',
20 .config(function($routeProvider, $locationProvider, $compileProvider) {
21 $locationProvider.html5Mode(true);
22 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|mailto|blob):/); // grid export
24 var resolver = {delay : ['egCore','egStartup','egUser', function(egCore, egStartup, egUser) {
25 egCore.env.classLoaders.aous = function() {
26 return egCore.org.settings([
27 'cat.marc_control_number_identifier'
28 ]).then(function(settings) {
29 // local settings are cached within egOrg. Caching them
30 // again in egEnv just simplifies the syntax for access.
31 egCore.env.aous = settings;
34 egCore.env.loadClasses.push('aous');
38 $routeProvider.when('/cat/catalog/index', {
39 templateUrl: './cat/catalog/t_catalog',
40 controller: 'CatalogCtrl',
44 // Jump directly to the results page. Any URL parameter
45 // supported by the embedded catalog is supported here.
46 $routeProvider.when('/cat/catalog/results', {
47 templateUrl: './cat/catalog/t_catalog',
48 controller: 'CatalogCtrl',
52 $routeProvider.when('/cat/catalog/retrieve_by_id', {
53 templateUrl: './cat/catalog/t_retrieve_by_id',
54 controller: 'CatalogRecordRetrieve',
58 $routeProvider.when('/cat/catalog/retrieve_by_tcn', {
59 templateUrl: './cat/catalog/t_retrieve_by_tcn',
60 controller: 'CatalogRecordRetrieve',
64 $routeProvider.when('/cat/catalog/new_bib', {
65 templateUrl: './cat/catalog/t_new_bib',
66 controller: 'NewBibCtrl',
70 // create some catalog page-specific mappings
71 $routeProvider.when('/cat/catalog/record/:record_id', {
72 templateUrl: './cat/catalog/t_catalog',
73 controller: 'CatalogCtrl',
77 // create some catalog page-specific mappings
78 $routeProvider.when('/cat/catalog/record/:record_id/:record_tab', {
79 templateUrl: './cat/catalog/t_catalog',
80 controller: 'CatalogCtrl',
84 $routeProvider.when('/cat/catalog/batchEdit', {
85 templateUrl: './cat/catalog/t_batchedit',
86 controller: 'BatchEditCtrl',
90 $routeProvider.when('/cat/catalog/batchEdit/:container_type/:container_id', {
91 templateUrl: './cat/catalog/t_batchedit',
92 controller: 'BatchEditCtrl',
96 $routeProvider.when('/cat/catalog/vandelay', {
97 templateUrl: './cat/catalog/t_vandelay',
98 controller: 'VandelayCtrl',
102 $routeProvider.when('/cat/catalog/verifyURLs', {
103 templateUrl: './cat/catalog/t_verifyurls',
104 controller: 'URLVerifyCtrl',
108 $routeProvider.when('/cat/catalog/manageAuthorities', {
109 templateUrl: './cat/catalog/t_manageauthorities',
110 controller: 'ManageAuthoritiesCtrl',
114 $routeProvider.when('/cat/catalog/authority/:authority_id/marc_edit', {
115 templateUrl: './cat/catalog/t_authority',
116 controller: 'AuthorityCtrl',
120 $routeProvider.otherwise({redirectTo : '/cat/catalog/index'});
126 .controller('CatalogRecordRetrieve',
127 ['$scope','$routeParams','$location','$q','egCore',
128 function($scope , $routeParams , $location , $q , egCore ) {
130 $scope.focusMe = true;
132 // jump to the patron checkout UI
133 function loadRecord(record_id) {
135 .path('/cat/catalog/record/' + record_id);
138 $scope.submitId = function(args) {
139 $scope.recordNotFound = null;
140 if (!args.record_id) return;
142 // blur so next time it's set to true it will re-apply select()
143 $scope.selectMe = false;
145 return loadRecord(args.record_id);
148 $scope.submitTCN = function(args) {
149 $scope.recordNotFound = null;
150 $scope.moreRecordsFound = null;
151 if (!args.record_tcn) return;
153 // blur so next time it's set to true it will re-apply select()
154 $scope.selectMe = false;
159 'open-ils.search.biblio.tcn',
162 .then(function(resp) { // get_barcodes
164 if (evt = egCore.evt.parse(resp)) {
170 $scope.recordNotFound = args.record_tcn;
171 $scope.selectMe = true;
175 if (resp.count > 1) {
176 $scope.moreRecordsFound = args.record_tcn;
177 $scope.selectMe = true;
181 var record_id = resp.ids[0];
182 return loadRecord(record_id);
188 .controller('NewBibCtrl',
189 ['$scope','$routeParams','$location','$window','$q','egCore',
190 'egGridDataProvider','egHoldGridActions','$timeout','holdingsSvc',
191 function($scope , $routeParams , $location , $window , $q , egCore) {
193 $scope.have_template = false;
194 $scope.marc_template = '';
195 $scope.stop_unload = false;
196 $scope.template_list = [];
197 $scope.template_name = '';
198 $scope.new_bib_id = 0;
202 'open-ils.cat.marc_template.types.retrieve'
203 ).then(function(resp) {
204 angular.forEach(resp, function(name) {
205 $scope.template_list.push(name);
207 $scope.template_list.sort();
209 $scope.template_name = egCore.hatch.getSessionItem('eg.cat.last_bib_marc_template');
210 if (!$scope.template_name) {
211 egCore.hatch.getItem('cat.default_bib_marc_template').then(function(template) {
212 $scope.template_name = template;
216 $scope.loadTemplate = function() {
217 if ($scope.template_name) {
220 'open-ils.cat.biblio.marc_template.retrieve',
222 ).then(function(template) {
223 $scope.marc_template = template;
224 $scope.have_template = true;
225 egCore.hatch.setSessionItem('eg.cat.last_bib_marc_template', $scope.template_name);
230 $scope.setDefaultTemplate = function() {
231 var hatch_key = "cat.default_bib_marc_template";
232 if ($scope.template_name) {
233 egCore.hatch.setItem(hatch_key, $scope.template_name);
235 egCore.hatch.removeItem(hatch_key);
239 $scope.$watch('new_bib_id', function(newVal, oldVal) {
241 $location.path('/cat/catalog/record/' + $scope.new_bib_id);
247 .controller('CatalogCtrl',
248 ['$scope','$routeParams','$location','$window','$q','egCore','egHolds','egCirc','egConfirmDialog','ngToast',
249 'egGridDataProvider','egHoldGridActions','egProgressDialog','$timeout','$uibModal','holdingsSvc','egUser','conjoinedSvc',
250 '$cookies','egSerialsCoreSvc',
251 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc , egConfirmDialog , ngToast ,
252 egGridDataProvider , egHoldGridActions , egProgressDialog , $timeout , $uibModal , holdingsSvc , egUser , conjoinedSvc,
253 $cookies , egSerialsCoreSvc
256 var holdingsSvcInst = new holdingsSvc();
258 // set record ID on page load if available...
259 $scope.record_id = $routeParams.record_id;
260 $scope.summary_pane_record;
262 if ($scope.record_id) {
263 // TODO: Apply tab-specific title contexts
264 egCore.strings.setPageTitle(
265 egCore.strings.PAGE_TITLE_BIB_DETAIL,
266 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT,
267 {record_id : $scope.record_id}
270 // Default to title = Catalog
271 egCore.strings.setPageTitle(
272 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT);
275 if ($routeParams.record_id) $scope.from_route = true;
276 else $scope.from_route = false;
278 // set search and preferred library cookies
279 egCore.hatch.getItem('eg.search.search_lib').then(function(val) {
280 $cookies.put('eg_search_lib', val, { path : '/' });
282 egCore.hatch.getItem('eg.search.pref_lib').then(function(val) {
283 $cookies.put('eg_pref_lib', val, { path : '/' });
286 // will hold a ref to the opac iframe
287 $scope.opac_iframe = null;
288 $scope.parts_iframe = null;
290 $scope.search_result_index = 1;
291 $scope.search_result_hit_count = 1;
294 'opac_iframe.dom.contentWindow.search_result_index',
296 if (!isNaN(parseInt(n)))
297 $scope.search_result_index = n + 1;
302 'opac_iframe.dom.contentWindow.search_result_hit_count',
304 if (!isNaN(parseInt(n)))
305 $scope.search_result_hit_count = n;
309 $scope.in_opac_call = false;
310 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
311 if ($scope.opac_iframe) {
312 if (force_opac_tab) $scope.record_tab = 'catalog';
313 $scope.in_opac_call = true;
314 $scope.opac_iframe.dom.contentWindow[opac_frame_function]();
315 if (opac_frame_function == 'rdetailBackToResults') {
316 $location.update_path('/cat/catalog/index');
321 $scope.add_to_record_bucket = function() {
322 var recId = $scope.record_id;
323 return $uibModal.open({
324 templateUrl: './cat/catalog/t_add_to_bucket',
329 ['$scope','$uibModalInstance',
330 function($scope , $uibModalInstance) {
332 $scope.bucket_id = 0;
333 $scope.newBucketName = '';
334 $scope.allBuckets = [];
337 'open-ils.actor.container.retrieve_by_class.authoritative',
338 egCore.auth.token(), egCore.auth.user().id(),
339 'biblio', 'staff_client'
340 ).then(function(buckets) { $scope.allBuckets = buckets; });
342 $scope.add_to_bucket = function() {
343 var item = new egCore.idl.cbrebi();
344 item.bucket($scope.bucket_id);
345 item.target_biblio_record_entry(recId);
348 'open-ils.actor.container.item.create',
349 egCore.auth.token(), 'biblio', item
350 ).then(function(resp) {
351 $uibModalInstance.close();
355 $scope.add_to_new_bucket = function() {
356 var bucket = new egCore.idl.cbreb();
357 bucket.owner(egCore.auth.user().id());
358 bucket.name($scope.newBucketName);
359 bucket.description('');
360 bucket.btype('staff_client');
364 'open-ils.actor.container.create',
365 egCore.auth.token(), 'biblio', bucket
366 ).then(function(bucket) {
367 $scope.bucket_id = bucket;
368 $scope.add_to_bucket();
372 $scope.cancel = function() {
373 $uibModalInstance.dismiss();
379 $scope.current_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record');
380 $scope.current_voltransfer_target = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
381 $scope.current_conjoined_target = egCore.hatch.getLocalItem('eg.cat.marked_conjoined_record');
383 $scope.quickReceive = function () {
385 var next_per_stream = {};
387 var recId = $scope.record_id;
388 return $uibModal.open({
389 templateUrl: './share/t_subscription_select_dialog',
391 controller: ['$scope', '$uibModalInstance',
392 function($scope, $uibModalInstance) {
395 $scope.rememberMe = 'eg.serials.quickreceive.last_org';
396 $scope.record_id = recId;
397 $scope.ssubId = null;
399 $scope.ok = function() { $uibModalInstance.close($scope.ssubId) }
400 $scope.cancel = function() { $uibModalInstance.dismiss(); }
403 }).result.then(function(ssubId) {
406 promises.push(egSerialsCoreSvc.fetchItemsForSub(ssubId,{status:'Expected'}).then(function(){
407 angular.forEach(egSerialsCoreSvc.itemTree, function (item) {
408 if (next_per_stream[item.stream().id()]) return;
409 if (item.status() == 'Expected') {
410 next_per_stream[item.stream().id()] = item;
411 list.push(egCore.idl.Clone(item));
416 return $q.all(promises).then(function() {
419 ngToast.warning(egCore.strings.SERIALS_NO_ITEMS);
423 return egSerialsCoreSvc.process_items(
429 false, // print by default
430 function() { $scope.holdings_record_id_changed($scope.record_id) }
434 ngToast.warning(egCore.strings.SERIALS_NO_SUBS);
440 $scope.markConjoined = function () {
441 $scope.current_conjoined_target = $scope.record_id;
442 egCore.hatch.setLocalItem('eg.cat.marked_conjoined_record',$scope.record_id);
443 ngToast.create(egCore.strings.MARK_CONJ_TARGET);
446 $scope.markVolTransfer = function () {
447 ngToast.create(egCore.strings.MARK_VOL_TARGET);
448 $scope.current_voltransfer_target = $scope.record_id;
449 egCore.hatch.setLocalItem('eg.cat.marked_volume_transfer_record',$scope.record_id);
450 egCore.hatch.removeLocalItem('eg.cat.volume_transfer_target');
453 $scope.markOverlay = function () {
454 $scope.current_overlay_target = $scope.record_id;
455 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.record_id);
456 ngToast.create(egCore.strings.MARK_OVERLAY_TARGET);
459 $scope.clearRecordMarks = function () {
460 $scope.current_overlay_target = null;
461 $scope.current_voltransfer_target = null;
462 $scope.current_conjoined_target = null;
463 $scope.current_hold_transfer_dest = null;
464 egCore.hatch.removeLocalItem('eg.cat.marked_volume_transfer_record');
465 egCore.hatch.removeLocalItem('eg.cat.marked_conjoined_record');
466 egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');
467 egCore.hatch.removeLocalItem('eg.circ.hold.title_transfer_target');
470 $scope.stop_unload = false;
471 $scope.$watch('stop_unload',
472 function(newVal, oldVal) {
473 if (newVal && newVal != oldVal && $scope.opac_iframe) {
474 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
475 return 'There is unsaved data in this record.'
478 if ($scope.opac_iframe)
479 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
484 // Set the "last bib" cookie, if we have that
485 if ($scope.record_id)
486 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
488 $scope.refresh_record_callback = function (record_id) {
489 egCore.pcrud.retrieve('bre', record_id, {
492 bre : ['simple_record','creator','editor']
494 }).then(function(rec) {
495 rec.owner(egCore.org.get(rec.owner()));
496 $scope.summary_pane_record = rec;
502 patron_search_dialog = function() {
503 return $uibModal.open({
504 templateUrl: './share/t_patron_selector',
509 ['$scope','$uibModalInstance','$controller',
510 function($scope , $uibModalInstance , $controller) {
511 angular.extend(this, $controller('BasePatronSearchCtrl', {$scope : $scope}));
513 $scope.need_one_selected = function() {
514 var items = $scope.gridControls.selectedItems();
515 return (items.length == 1) ? false : true
517 $scope.ok = function() {
518 var items = $scope.gridControls.selectedItems();
519 if (items.length == 1) {
520 $uibModalInstance.close(items[0].card().barcode());
522 $uibModalInstance.close()
525 $scope.cancel = function($event) {
526 $uibModalInstance.dismiss();
527 $event.preventDefault();
533 // also set it when the iframe changes to a new record
534 $scope.handle_page = function(url) {
536 if (!url || url == 'about:blank') {
537 // nothing loaded. If we already have a record ID, leave it.
541 var match = url.match(/\/+opac\/+record\/+(\d+)/);
543 $scope.record_id = match[1];
544 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
545 $scope.holdings_record_id_changed($scope.record_id);
546 conjoinedSvc.fetch($scope.record_id).then(function(){
547 $scope.conjoinedGridDataProvider.refresh();
549 egHolds.fetch_holds(hold_ids).then($scope.hold_grid_data_provider.refresh);
551 $location.update_path('/cat/catalog/record/' + $scope.record_id);
552 // update_path() bypasses the controller for path
553 // /cat/catalog/record/:record_id. Manually set title here too.
554 egCore.strings.setPageTitle(
555 egCore.strings.PAGE_TITLE_BIB_DETAIL,
556 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT,
557 {record_id : $scope.record_id}
560 delete $scope.record_id;
561 $scope.from_route = false;
564 // child scope is executing this function, so our digest doesn't fire ... thus,
567 if (!$scope.in_opac_call) {
568 if ($scope.record_id && !$scope.record_tab) {
569 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
570 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
572 tab = $routeParams.record_tab || 'catalog';
574 $scope.set_record_tab(tab);
576 $scope.in_opac_call = false;
579 if ($scope.opac_iframe && $location.path().match(/cat\/catalog/)) {
580 var doc = $scope.opac_iframe.dom.contentWindow.document;
581 $(doc).find('#hold_usr_search').show();
582 $(doc).find('#hold_usr_search').on('click', function() {
583 patron_search_dialog().result.then(function(barc) {
584 $(doc).find('#hold_usr_input').val(barc);
585 $(doc).find('#hold_usr_input').change();
592 // xulG catalog handlers
593 $scope.handlers = { }
595 // ------------------------------------------------------------------
598 $scope.conjoinedGridControls = {};
599 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
600 get : function(offset, count) {
601 return this.arrayNotifier(conjoinedSvc.items, offset, count);
605 $scope.changeConjoinedType = function () {
606 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
607 angular.forEach(peers, function (p) {
608 p.target_copy(p.target_copy().id());
609 p.peer_type(p.peer_type().id());
612 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
614 return $uibModal.open({
615 templateUrl: './cat/catalog/t_conjoined_selector',
619 ['$scope','$uibModalInstance',
620 function($scope , $uibModalInstance) {
621 $scope.update = true;
623 $scope.peer_type = null;
624 $scope.peer_type_list = [];
625 conjoinedSvc.get_peer_types().then(function(list){
626 $scope.peer_type_list = list;
629 $scope.ok = function(type) {
632 angular.forEach(peers, function (p) {
635 promises.push(egCore.pcrud.update(p));
638 return $q.all(promises)
639 .then(function(){$uibModalInstance.close()})
640 .then(function(){return conjoinedSvc.fetch()})
641 .then(function(){conjoinedGridDataProviderRef.refresh()});
644 $scope.cancel = function($event) {
645 $uibModalInstance.dismiss();
646 $event.preventDefault();
653 $scope.refreshConjoined = function () {
654 conjoinedSvc.fetch($scope.record_id)
655 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
658 $scope.deleteSelectedConjoined = function () {
659 var peers = $scope.conjoinedGridControls.selectedItems();
661 if (peers.length > 0) {
662 egConfirmDialog.open(
663 egCore.strings.CONFIRM_DELETE_PEERS,
664 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
665 {peers : peers.length}
666 ).result.then(function() {
667 angular.forEach(peers, function (p) {
671 egCore.pcrud.remove(peers).then(function() {
672 return conjoinedSvc.fetch();
674 $scope.conjoinedGridDataProvider.refresh();
679 if ($scope.record_id)
680 conjoinedSvc.fetch($scope.record_id);
682 // ------------------------------------------------------------------
685 $scope.holdingsGridControls = {
686 activateItem : function (item) {
687 $scope.selectedHoldingsVolCopyEdit();
690 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
691 get : function(offset, count) {
692 return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
696 $scope.add_copies_to_bucket = function() {
697 var copy_list = gatherSelectedHoldingsIds();
698 if (copy_list.length == 0) return;
700 return $uibModal.open({
701 templateUrl: './cat/catalog/t_add_to_bucket',
706 ['$scope','$uibModalInstance',
707 function($scope , $uibModalInstance) {
709 $scope.bucket_id = 0;
710 $scope.newBucketName = '';
711 $scope.allBuckets = [];
715 'open-ils.actor.container.retrieve_by_class.authoritative',
716 egCore.auth.token(), egCore.auth.user().id(),
717 'copy', 'staff_client'
718 ).then(function(buckets) { $scope.allBuckets = buckets; });
720 $scope.add_to_bucket = function() {
722 angular.forEach(copy_list, function (cp) {
723 var item = new egCore.idl.ccbi()
724 item.bucket($scope.bucket_id);
725 item.target_copy(cp);
729 'open-ils.actor.container.item.create',
730 egCore.auth.token(), 'copy', item
734 return $q.all(promises).then(function() {
735 $uibModalInstance.close();
740 $scope.add_to_new_bucket = function() {
741 var bucket = new egCore.idl.ccb();
742 bucket.owner(egCore.auth.user().id());
743 bucket.name($scope.newBucketName);
744 bucket.description('');
745 bucket.btype('staff_client');
747 return egCore.net.request(
749 'open-ils.actor.container.create',
750 egCore.auth.token(), 'copy', bucket
751 ).then(function(bucket) {
752 $scope.bucket_id = bucket;
753 $scope.add_to_bucket();
757 $scope.cancel = function() {
758 $uibModalInstance.dismiss();
764 // TODO: refactor common code between cat/catalog/app.js and cat/item/app.js
766 $scope.need_one_selected = function() {
767 var items = $scope.holdingsGridControls.selectedItems();
768 if (items.length == 1) return false;
772 $scope.make_copies_bookable = function() {
774 var copies_by_record = {};
775 var record_list = [];
777 $scope.holdingsGridControls.selectedItems(),
779 var record_id = item['call_number.record.id'];
780 if (typeof copies_by_record[ record_id ] == 'undefined') {
781 copies_by_record[ record_id ] = [];
782 record_list.push( record_id );
784 copies_by_record[ record_id ].push(item.id);
789 var combined_results = [];
790 angular.forEach(record_list, function(record_id) {
794 'open-ils.booking.resources.create_from_copies',
796 copies_by_record[record_id]
797 ).then(function(results) {
798 if (results && results['brsrc']) {
799 combined_results = combined_results.concat(results['brsrc']);
805 $q.all(promises).then(function() {
806 if (combined_results.length > 0) {
808 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
813 ['$scope','$location','egCore','$uibModalInstance',
814 function($scope , $location , egCore , $uibModalInstance) {
817 ses : egCore.auth.token(),
818 resultant_brsrc : combined_results.map(function(o) { return o[0]; })
821 var booking_path = '/eg/conify/global/booking/resource';
823 $scope.booking_admin_url =
824 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
831 $scope.book_copies_now = function() {
832 var copies_by_record = {};
833 var record_list = [];
835 $scope.holdingsGridControls.selectedItems(),
837 var record_id = item['call_number.record.id'];
838 if (typeof copies_by_record[ record_id ] == 'undefined') {
839 copies_by_record[ record_id ] = [];
840 record_list.push( record_id );
842 copies_by_record[ record_id ].push(item.id);
847 var combined_brt = [];
848 var combined_brsrc = [];
849 angular.forEach(record_list, function(record_id) {
853 'open-ils.booking.resources.create_from_copies',
855 copies_by_record[record_id]
856 ).then(function(results) {
857 if (results && results['brt']) {
858 combined_brt = combined_brt.concat(results['brt']);
860 if (results && results['brsrc']) {
861 combined_brsrc = combined_brsrc.concat(results['brsrc']);
867 $q.all(promises).then(function() {
868 if (combined_brt.length > 0 || combined_brsrc.length > 0) {
870 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
875 ['$scope','$location','egCore','$uibModalInstance',
876 function($scope , $location , egCore , $uibModalInstance) {
879 ses : egCore.auth.token(),
880 bresv_interface_opts : {
883 ,brsrc : combined_brsrc
888 var booking_path = '/eg/booking/reservation';
890 $scope.booking_admin_url =
891 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
900 $scope.requestItems = function() {
901 var copy_list = gatherSelectedHoldingsIds();
902 if (copy_list.length == 0) return;
904 return $uibModal.open({
905 templateUrl: './cat/catalog/t_request_items',
908 ['$scope','$uibModalInstance',
909 function($scope , $uibModalInstance) {
911 $scope.first_user_fetch = true;
915 copy_list : copy_list,
916 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
917 user : egCore.auth.user().id()
920 egUser.get( $scope.hold_data.user ).then(function(u) {
922 $scope.barcode = u.card().barcode();
923 $scope.user_name = egUser.format_name(u);
924 $scope.hold_data.user = u.id();
927 $scope.user_name = '';
929 $scope.$watch('barcode', function (n) {
930 if (!$scope.first_user_fetch) {
931 egUser.getByBarcode(n).then(function(u) {
933 $scope.user_name = egUser.format_name(u);
934 $scope.hold_data.user = u.id();
937 $scope.user_name = '';
938 delete $scope.hold_data.user;
941 $scope.first_user_fetch = false;
944 $scope.ok = function(h) {
947 hold_type : h.hold_type,
948 pickup_lib: h.pickup_lib.id(),
954 'open-ils.circ.holds.test_and_create.batch.override',
955 egCore.auth.token(), args, h.copy_list
958 $uibModalInstance.close();
961 $scope.cancel = function($event) {
962 $uibModalInstance.dismiss();
963 $event.preventDefault();
969 $scope.view_place_orders = function() {
970 if (!$scope.record_id) return;
971 var url = egCore.env.basePath + 'acq/legacy/lineitem/related/' + $scope.record_id + '?target=bib';
972 $timeout(function() { $window.open(url, '_blank') });
975 $scope.replaceBarcodes = function() {
976 var copy_list = gatherSelectedRawCopies();
977 if (copy_list.length == 0) return;
979 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
981 angular.forEach(copy_list, function (cp) {
983 templateUrl: './cat/share/t_replace_barcode',
987 ['$scope','$uibModalInstance',
988 function($scope , $uibModalInstance) {
989 $scope.isModal = true;
990 $scope.focusBarcode = false;
991 $scope.focusBarcode2 = true;
992 $scope.barcode1 = cp.barcode();
994 $scope.updateBarcode = function() {
995 $scope.copyNotFound = false;
996 $scope.updateOK = false;
998 egCore.pcrud.search('acp',
999 {deleted : 'f', barcode : $scope.barcode1})
1000 .then(function(copy) {
1003 $scope.focusBarcode = true;
1004 $scope.copyNotFound = true;
1008 $scope.copyId = copy.id();
1009 copy.barcode($scope.barcode2);
1011 egCore.pcrud.update(copy).then(function(stat) {
1012 $scope.updateOK = stat;
1013 $scope.focusBarcode = true;
1014 holdingsSvc.fetchAgain().then(function (){
1015 holdingsGridDataProviderRef.refresh();
1020 $uibModalInstance.close();
1023 $scope.cancel = function($event) {
1024 $uibModalInstance.dismiss();
1025 $event.preventDefault();
1033 // refresh the list of holdings when the record_id is changed.
1034 $scope.holdings_record_id_changed = function(id) {
1035 if ($scope.record_id != id) $scope.record_id = id;
1036 console.log('record id changed to ' + id + ', loading new holdings');
1037 holdingsSvcInst.fetch({
1038 rid : $scope.record_id,
1039 org : $scope.holdings_ou,
1040 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1041 vol : $scope.holdings_show_vols,
1042 empty: $scope.holdings_show_empty,
1043 empty_org: $scope.holdings_show_empty_org
1044 }).then(function() {
1045 $scope.holdingsGridDataProvider.refresh();
1049 // refresh the list of holdings when the filter lib is changed.
1050 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
1051 $scope.holdings_ou_changed = function(org) {
1052 $scope.holdings_ou = org;
1053 holdingsSvcInst.fetch({
1054 rid : $scope.record_id,
1055 org : $scope.holdings_ou,
1056 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1057 vol : $scope.holdings_show_vols,
1058 empty: $scope.holdings_show_empty,
1059 empty_org: $scope.holdings_show_empty_org
1060 }).then(function() {
1061 $scope.holdingsGridDataProvider.refresh();
1065 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
1066 $scope[cb] = newVal;
1067 var x = $scope.holdings_show_vols ? $scope.holdings_show_copies : false;
1068 $('#holdings_show_copies').prop('checked', x);
1069 egCore.hatch.setItem('cat.' + cb, newVal);
1070 if (!norefresh) holdingsSvcInst.fetch({
1071 rid : $scope.record_id,
1072 org : $scope.holdings_ou,
1073 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1074 vol : $scope.holdings_show_vols,
1075 empty: $scope.holdings_show_empty,
1076 empty_org: $scope.holdings_show_empty_org
1077 }).then(function() {
1078 $scope.holdingsGridDataProvider.refresh();
1082 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
1083 if (typeof x == 'undefined') x = true;
1084 $scope.holdings_cb_changed('holdings_show_vols',x,true);
1085 $('#holdings_show_vols').prop('checked', x);
1087 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
1088 if (typeof x == 'undefined') x = true;
1089 $scope.holdings_cb_changed('holdings_show_copies',x,true);
1090 x = $scope.holdings_show_vols ? x : false;
1091 $('#holdings_show_copies').prop('checked', x);
1093 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
1094 if (typeof x == 'undefined') x = true;
1095 $scope.holdings_cb_changed('holdings_show_empty',x);
1096 $('#holdings_show_empty').prop('checked', x);
1098 egCore.hatch.getItem('cat.holdings_show_empty_org').then(function(x){
1099 if (typeof x == 'undefined') x = true;
1100 $scope.holdings_cb_changed('holdings_show_empty_org',x);
1101 $('#holdings_show_empty_org').prop('checked', x);
1107 $scope.vols_not_shown = function () {
1108 return !$scope.holdings_show_vols;
1111 $scope.copies_not_shown = function () {
1112 return !$scope.holdings_show_copies;
1115 $scope.empty_org_not_shown = function () {
1116 return !$scope.holdings_show_empty_org;
1119 $scope.holdings_checkbox_handler = function (item) {
1120 $scope.holdings_cb_changed(item.checkbox,item.checked);
1123 function gatherSelectedHoldingsIds () {
1124 var cp_id_list = [];
1126 $scope.holdingsGridControls.selectedItems(),
1127 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
1132 function gatherSelectedRawCopies () {
1135 $scope.holdingsGridControls.selectedItems(),
1136 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
1141 function gatherSelectedEmptyVolumeIds () {
1142 var cn_id_list = [];
1144 $scope.holdingsGridControls.selectedItems(),
1146 if (item.copy_count == 0 || (!item.id && item.call_number))
1147 // we are in a compressed row with no copies, or we are in a single
1148 // call number row with no copy (testing for presence of 'id')
1149 // In either case, the call number is 'empty'
1150 cn_id_list.push(item.call_number.id)
1156 function gatherSelectedVolumeIds () {
1157 var cn_id_list = [];
1159 $scope.holdingsGridControls.selectedItems(),
1161 if (cn_id_list.indexOf(item.call_number.id) == -1)
1162 cn_id_list.push(item.call_number.id)
1168 $scope.selectedHoldingsDelete = function (vols, copies) {
1171 var perCnCopies = {};
1177 $scope.holdingsGridControls.selectedItems(),
1179 if (vols && item.raw_call_number) {
1180 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
1181 cnHash[item.call_number.id].isdeleted(1);
1183 } else if (copies) {
1184 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
1187 var cn_id = cp.call_number().id();
1188 if (!cnHash[cn_id]) {
1189 cnHash[cn_id] = cp.call_number();
1190 perCnCopies[cn_id] = [cp];
1192 perCnCopies[cn_id].push(cp);
1194 cp.call_number(cn_id); // prevent loops in JSON-ification
1201 angular.forEach(perCnCopies, function (v, k) {
1203 cnHash[k].isdeleted(1);
1206 cnHash[k].copies(v);
1210 angular.forEach(cnHash, function (v, k) {
1214 if (cnList.length == 0) return;
1217 if (vols && copies) flags.force_delete_copies = 1;
1219 egConfirmDialog.open(
1220 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
1221 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
1222 {copies : cp_count, volumes : cn_count}
1223 ).result.then(function() {
1226 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1227 egCore.auth.token(), cnList, 1, flags
1228 ).then(function(update_count) {
1229 holdingsSvcInst.fetchAgain().then(function() {
1230 $scope.holdingsGridDataProvider.refresh();
1235 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
1236 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
1237 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
1239 spawnHoldingsAdd = function (add_vols,add_copies){
1241 if (!add_vols && add_copies) { // just a copy on existing volumes
1242 angular.forEach(gatherSelectedVolumeIds(), function (v) {
1243 raw.push( {callnumber : v} );
1245 } else if (add_vols) {
1246 if (typeof $scope.holdingsGridControls.selectedItems == "function" &&
1247 $scope.holdingsGridControls.selectedItems().length > 0) {
1248 angular.forEach($scope.holdingsGridControls.selectedItems(),
1251 owner : item.owner_id,
1252 label : ((item.call_number) ? item.call_number.label : null)
1257 owner : egCore.auth.user().ws_ou()
1262 if (raw.length == 0) raw.push({});
1266 'open-ils.actor.anon_cache.set_value',
1267 null, 'edit-these-copies', {
1268 record_id: $scope.record_id,
1271 hide_copies : !add_copies
1273 ).then(function(key) {
1275 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1276 $timeout(function() { $window.open(url, '_blank') });
1278 alert('Could not create anonymous cache key!');
1282 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,true) }
1283 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
1284 $scope.selectedHoldingsVolAdd = function () { spawnHoldingsAdd(true,false) }
1286 spawnHoldingsEdit = function (hide_vols,hide_copies){
1289 'open-ils.actor.anon_cache.set_value',
1290 null, 'edit-these-copies', {
1291 record_id: $scope.record_id,
1292 copies: gatherSelectedHoldingsIds(),
1293 raw: gatherSelectedEmptyVolumeIds().map(
1294 function(v){ return { callnumber : v } }
1296 hide_vols : hide_vols,
1297 hide_copies : hide_copies
1299 ).then(function(key) {
1301 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1302 $timeout(function() { $window.open(url, '_blank') });
1304 alert('Could not create anonymous cache key!');
1308 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
1309 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
1310 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
1312 $scope.selectedHoldingsItemStatus = function (){
1313 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
1314 $timeout(function() { $window.open(url, '_blank') });
1317 $scope.markVolAsItemTarget = function() {
1318 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
1319 egCore.hatch.setLocalItem(
1320 'eg.cat.item_transfer_target',
1321 $scope.holdingsGridControls.selectedItems()[0].call_number.id
1323 ngToast.create(egCore.strings.MARK_ITEM_TARGET);
1327 $scope.markLibAsVolTarget = function() {
1328 var recId = $scope.record_id;
1329 return $uibModal.open({
1330 templateUrl: './cat/catalog/t_choose_vol_target_lib',
1334 ['$scope','$uibModalInstance',
1335 function($scope , $uibModalInstance) {
1337 var orgId = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target') || 1;
1338 $scope.org = egCore.org.get(orgId);
1339 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1340 $scope.ok = function(org) {
1341 egCore.hatch.setLocalItem(
1342 'eg.cat.volume_transfer_target',
1345 egCore.hatch.setLocalItem(
1346 'eg.cat.marked_volume_transfer_record',
1349 $uibModalInstance.close();
1351 $scope.cancel = function($event) {
1352 $uibModalInstance.dismiss();
1353 $event.preventDefault();
1358 $scope.markLibFromSelectedAsVolTarget = function() {
1359 egCore.hatch.setLocalItem(
1360 'eg.cat.volume_transfer_target',
1361 $scope.holdingsGridControls.selectedItems()[0].owner_id
1363 egCore.hatch.setLocalItem(
1364 'eg.cat.marked_volume_transfer_record',
1367 ngToast.create(egCore.strings.MARK_VOL_TARGET);
1370 $scope.selectedHoldingsItemStatusDetail = function (){
1372 gatherSelectedHoldingsIds(),
1374 var url = egCore.env.basePath +
1376 $timeout(function() { $window.open(url, '_blank') });
1381 $scope.transferVolumesToRecord = function (){
1382 var target_record = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
1383 if (!target_record) return;
1384 if ($scope.record_id == target_record) return;
1385 var items = $scope.holdingsGridControls.selectedItems();
1386 if (!items.length) return;
1388 var vols_to_move = {};
1389 angular.forEach(items, function(item) {
1390 if (!(item.call_number.owning_lib in vols_to_move)) {
1391 vols_to_move[item.call_number.owning_lib] = new Array;
1393 vols_to_move[item.call_number.owning_lib].push(item.call_number.id);
1397 angular.forEach(vols_to_move, function(vols, owning_lib) {
1398 promises.push(egCore.net.request(
1400 'open-ils.cat.asset.volume.batch.transfer.override',
1401 egCore.auth.token(), {
1402 docid : target_record,
1408 $q.all(promises).then(function(success) {
1410 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1411 holdingsSvcInst.fetchAgain().then(function() {
1412 $scope.holdingsGridDataProvider.refresh();
1415 alert('Could not transfer volumes!');
1420 function transferVolumes(new_record){
1421 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
1426 'open-ils.cat.asset.volume.batch.transfer.override',
1427 egCore.auth.token(), {
1428 docid : (new_record ? new_record : $scope.record_id),
1430 volumes : gatherSelectedVolumeIds()
1432 ).then(function(success) {
1434 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1435 holdingsSvcInst.fetchAgain().then(function() {
1436 $scope.holdingsGridDataProvider.refresh();
1439 alert('Could not transfer volumes!');
1446 $scope.transferVolumesToLibrary = function() {
1450 $scope.transferVolumesToRecordAndLibrary = function() {
1451 var target_record = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
1452 if (!target_record) return;
1453 transferVolumes(target_record);
1456 // this "transfers" selected copies to a new owning library,
1457 // auto-creating volumes and deleting unused volumes as required.
1458 $scope.changeItemOwningLib = function() {
1459 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
1460 var items = $scope.holdingsGridControls.selectedItems();
1461 if (!xfer_target || !items.length) {
1464 var vols_to_move = {};
1465 var copies_to_move = {};
1466 angular.forEach(items, function(item) {
1467 if (item.call_number.owning_lib != xfer_target) {
1468 if (item.call_number.id in vols_to_move) {
1469 copies_to_move[item.call_number.id].push(item.id);
1471 vols_to_move[item.call_number.id] = item.call_number;
1472 copies_to_move[item.call_number.id] = new Array;
1473 copies_to_move[item.call_number.id].push(item.id);
1479 angular.forEach(vols_to_move, function(vol) {
1480 promises.push(egCore.net.request(
1482 'open-ils.cat.call_number.find_or_create',
1483 egCore.auth.token(),
1490 ).then(function(resp) {
1491 var evt = egCore.evt.parse(resp);
1493 return egCore.net.request(
1495 'open-ils.cat.transfer_copies_to_volume',
1496 egCore.auth.token(),
1498 copies_to_move[vol.id]
1502 $q.all(promises).then(function() {
1503 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1504 holdingsSvcInst.fetchAgain().then(function() {
1505 $scope.holdingsGridDataProvider.refresh();
1510 $scope.gridCellHandlers = {};
1511 $scope.gridCellHandlers.copyAlertsEdit = function(id) {
1512 egCirc.manage_copy_alerts([id]).then(function() {
1513 // update grid items?
1517 $scope.transferItems = function (){
1518 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
1519 var copy_ids = gatherSelectedHoldingsIds();
1520 if (xfer_target && copy_ids.length > 0) {
1523 'open-ils.cat.transfer_copies_to_volume',
1524 egCore.auth.token(),
1528 function(resp) { // oncomplete
1529 var evt = egCore.evt.parse(resp);
1531 egConfirmDialog.open(
1532 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1533 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1534 {'evt_desc': evt.desc}
1535 ).result.then(function() {
1538 'open-ils.cat.transfer_copies_to_volume.override',
1539 egCore.auth.token(),
1542 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1543 ).then(function(resp) {
1544 holdingsSvcInst.fetchAgain().then(function() {
1545 $scope.holdingsGridDataProvider.refresh();
1550 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1551 holdingsSvcInst.fetchAgain().then(function() {
1552 $scope.holdingsGridDataProvider.refresh();
1562 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1564 gatherSelectedHoldingsIds(),
1566 var url = egCore.env.basePath +
1567 'cat/item/' + cid + '/triggered_events';
1568 $timeout(function() { $window.open(url, '_blank') });
1573 $scope.selectedHoldingsItemStatusHolds = function (){
1575 gatherSelectedHoldingsIds(),
1577 var url = egCore.env.basePath +
1578 'cat/item/' + cid + '/holds';
1579 $timeout(function() { $window.open(url, '_blank') });
1584 $scope.selectedHoldingsPrintLabels = function() {
1587 'open-ils.actor.anon_cache.set_value',
1588 null, 'print-labels-these-copies', {
1589 copies : gatherSelectedHoldingsIds()
1591 ).then(function(key) {
1593 var url = egCore.env.basePath + 'cat/printlabels/' + key;
1594 $timeout(function() { $window.open(url, '_blank') });
1596 alert('Could not create anonymous cache key!');
1601 $scope.selectedHoldingsDamaged = function () {
1602 var copy_list = gatherSelectedRawCopies();
1603 if (copy_list.length == 0) return;
1605 angular.forEach(copy_list, function(cp) {
1606 egCirc.mark_damaged({
1608 barcode: cp.barcode(),
1609 circ_lib: cp.circ_lib().id()
1610 }).then(function() {
1611 holdingsSvcInst.fetchAgain().then(function() {
1612 $scope.holdingsGridDataProvider.refresh();
1618 $scope.selectedHoldingsMissing = function () {
1619 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1620 holdingsSvcInst.fetchAgain().then(function() {
1621 $scope.holdingsGridDataProvider.refresh();
1626 $scope.selectedHoldingsCopyAlertsAdd = function() {
1627 egCirc.add_copy_alerts(gatherSelectedHoldingsIds()).then(function() {
1628 // no need to refresh grid
1631 $scope.selectedHoldingsCopyAlertsManage = function() {
1632 egCirc.manage_copy_alerts(gatherSelectedHoldingsIds()).then(function() {
1633 // no need to refresh grid
1637 $scope.attach_to_peer_bib = function() {
1638 var copy_list = gatherSelectedHoldingsIds();
1639 if (copy_list.length == 0) return;
1641 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1642 if (!target_record) return;
1644 return $uibModal.open({
1645 templateUrl: './cat/catalog/t_conjoined_selector',
1649 ['$scope','$uibModalInstance',
1650 function($scope , $uibModalInstance) {
1651 $scope.update = false;
1653 $scope.peer_type = null;
1654 $scope.peer_type_list = [];
1655 conjoinedSvc.get_peer_types().then(function(list){
1656 $scope.peer_type_list = list;
1659 $scope.ok = function(type) {
1662 angular.forEach(copy_list, function (cp) {
1663 var n = new egCore.idl.bpbcm();
1665 n.peer_record(target_record);
1668 promises.push(egCore.pcrud.create(n));
1671 return $q.all(promises).then(function(){$uibModalInstance.close()});
1674 $scope.cancel = function($event) {
1675 $uibModalInstance.dismiss();
1676 $event.preventDefault();
1684 // ------------------------------------------------------------------
1686 var provider = egGridDataProvider.instance({});
1687 $scope.hold_grid_data_provider = provider;
1688 $scope.grid_actions = egHoldGridActions;
1689 $scope.grid_actions.refresh = function () { provider.refresh() };
1690 $scope.hold_grid_controls = {};
1692 var hold_ids = []; // current list of holds
1693 function fetchHolds(offset, count) {
1694 var ids = hold_ids.slice(offset, offset + count);
1696 return egHolds.fetch_holds(ids).then(null, null,
1697 function(hold_data) {
1703 provider.get = function(offset, count) {
1704 if ($scope.record_tab != 'holds') return $q.when();
1705 var deferred = $q.defer();
1706 hold_ids = []; // no caching ATM
1708 // open a determinate progress dialog, max value set below.
1709 egProgressDialog.open({max : 1, value : 0});
1714 'open-ils.circ.holds.retrieve_all_from_title',
1715 egCore.auth.token(), $scope.record_id,
1716 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
1718 function(hold_data) {
1719 hold_ids = []; // clear the list of ids, hack to avoid dups
1720 // TODO: fix the underlying problem, which is that
1721 // this gets called twice when switching to the holds
1722 // tab; once explicitly, and once via the change handler
1723 // on the OU selector
1724 angular.forEach(hold_data, function(list, type) {
1725 hold_ids = hold_ids.concat(list);
1728 // Set the max value of the progress bar to the lesser of
1729 // the total number of holds to fetch or the page size
1731 egProgressDialog.update(
1732 {max : Math.min(hold_ids.length, count)});
1734 var holds_fetched = 0;
1735 fetchHolds(offset, count)
1736 .then(deferred.resolve, null,
1737 function(hold_data) {
1739 deferred.notify(hold_data);
1740 egProgressDialog.increment();
1742 )['finally'](egProgressDialog.close);
1746 return deferred.promise;
1749 $scope.detail_view = function(action, user_data, items) {
1751 $scope.detail_hold_id = h.hold.id();
1755 $scope.list_view = function(items) {
1756 $scope.detail_hold_id = null;
1759 // refresh the list of record holds when the pickup lib is changed.
1760 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1761 $scope.pickup_ou_changed = function(org) {
1762 $scope.pickup_ou = org;
1766 $scope.print_holds = function() {
1768 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1770 hold : egCore.idl.toHash(item.hold),
1771 patron_last : item.patron_last,
1772 patron_alias : item.patron_alias,
1773 patron_barcode : item.patron_barcode,
1774 copy : egCore.idl.toHash(item.copy),
1775 volume : egCore.idl.toHash(item.volume),
1776 title : item.mvr.title(),
1777 author : item.mvr.author()
1781 egCore.print.print({
1782 context : 'receipt',
1783 template : 'holds_for_bib',
1784 scope : {holds : holds}
1788 $scope.current_hold_transfer_dest = egCore.hatch.getLocalItem ('eg.circ.hold.title_transfer_target');
1790 $scope.mark_hold_transfer_dest = function() {
1791 $scope.current_hold_transfer_dest = $scope.record_id;
1792 egCore.hatch.setLocalItem(
1793 'eg.circ.hold.title_transfer_target', $scope.record_id);
1794 ngToast.create(egCore.strings.HOLD_TRANSFER_DEST_MARKED);
1797 // UI presents this option as "all holds"
1798 $scope.transfer_holds_to_marked = function() {
1799 var hold_ids = $scope.hold_grid_controls.allItems().map(
1800 function(hold_data) {return hold_data.hold.id()});
1801 egHolds.transfer_to_marked_title(hold_ids);
1804 // ------------------------------------------------------------------
1805 // Initialize the selected tab
1807 // we explicitly initialize catalog_url because otherwise Firefox
1808 // ends up setting it to $BASE_URL/{{url}}, which then messes
1809 // things up. See LP#1708951
1810 $scope.catalog_url = '';
1812 function init_cat_url() {
1813 // Set the initial catalog URL. This only happens once.
1814 // The URL is otherwise generated through user navigation.
1815 if ($scope.catalog_url) return;
1817 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1819 // A record ID in the path indicates a request for the record-
1821 if ($routeParams.record_id) {
1822 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1825 // Jumping directly to the results page by passing a search
1826 // query via the URL. Copy all URL params to the iframe url.
1827 if ($location.path().match(/catalog\/results/)) {
1828 url = url.replace(/advanced/, '/results?');
1830 angular.forEach($location.search(), function(val, key) {
1831 if (!first) url += '&';
1833 url += encodeURIComponent(key)
1834 + '=' + encodeURIComponent(val);
1838 // if we're displaying the advanced search form, select
1839 // whatever default pane the user has chosen via workstation
1841 if (url.match(/\/opac\/advanced$/)) {
1842 var adv_pane = egCore.hatch.getLocalItem('eg.search.adv_pane');
1844 url += '?pane=' + encodeURIComponent(adv_pane);
1848 $scope.catalog_url = url;
1851 function init_parts_url() {
1852 $scope.parts_url = $location
1856 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1860 $scope.set_record_tab = function(tab) {
1861 $scope.record_tab = tab;
1874 $scope.detail_hold_record_id = $scope.record_id;
1875 // refresh the holds grid
1882 $scope.set_default_record_tab = function() {
1883 egCore.hatch.setLocalItem(
1884 'eg.cat.default_record_tab', $scope.record_tab);
1885 $timeout(function(){$scope.default_tab = $scope.record_tab});
1889 if ($scope.record_id) {
1890 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1891 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1894 tab = $routeParams.record_tab || 'catalog';
1896 $scope.set_record_tab(tab);
1900 .controller('AuthorityCtrl',
1901 ['$scope','$routeParams','$location','$window','$q','egCore',
1902 function($scope , $routeParams , $location , $window , $q , egCore) {
1904 // set record ID on page load if available...
1905 $scope.authority_id = $routeParams.authority_id;
1907 if ($routeParams.authority_id) $scope.from_route = true;
1908 else $scope.from_route = false;
1910 $scope.stop_unload = false;
1913 .controller('URLVerifyCtrl',
1914 ['$scope','$location',
1915 function($scope , $location) {
1916 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1919 .controller('VandelayCtrl',
1920 ['$scope','$location', 'egCore', '$uibModal',
1921 function($scope , $location, egCore, $uibModal) {
1922 $scope.vandelay_url = $location.absUrl().replace(/\/staff\/cat\/catalog\/vandelay/, '/vandelay/vandelay');
1924 $scope.funcs.edit_marc_modal = function(bre, callback){
1925 var marcArgs = { 'marc_xml': bre.marc() };
1926 var vqbibrecId = bre.id();
1928 templateUrl: './cat/catalog/t_edit_marc_modal',
1931 controller: ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
1932 $scope.focusMe = true;
1933 $scope.recordId = vqbibrecId;
1934 $scope.args = marcArgs;
1935 $scope.dirty_flag = false;
1936 $scope.ok = function(marg){
1937 $uibModalInstance.close(marg);
1939 $scope.cancel = function(){ $uibModalInstance.dismiss() }
1941 }).result.then(function(res){
1942 var new_xml = res.marc_xml;
1943 egCore.pcrud.retrieve('vqbr', vqbibrecId).then(function(vqbib){
1944 vqbib.marc(new_xml);
1945 egCore.pcrud.update(vqbib).then( function(){ callback(vqbibrecId); });
1951 .controller('ManageAuthoritiesCtrl',
1952 ['$scope','$location',
1953 function($scope , $location) {
1954 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1957 .controller('BatchEditCtrl',
1958 ['$scope','$location','$routeParams',
1959 function($scope , $location , $routeParams) {
1960 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1961 if ($routeParams.container_type) {
1962 switch ($routeParams.container_type) {
1964 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1967 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1974 .filter('boolText', function(){
1975 return function (v) {
1980 .factory('conjoinedSvc',
1982 function(egCore , $q) {
1985 items : [], // record search results
1986 index : 0, // search grid index
1993 bpbcm : ['target_copy','peer_type'],
1994 acp : ['call_number'],
1996 bre : ['simple_record']
1998 // avoid fetching the MARC blob by specifying which
1999 // fields on the bre to select. More may be needed.
2000 // note that fleshed fields are explicitly selected.
2001 select : { bre : ['id'] },
2002 order_by : { bpbcm : ['id'] },
2005 // resolved with the last received copy
2006 service.fetch = function(rid) {
2007 if (!rid && !service.rid) return $q.when();
2009 if (rid) service.rid = rid;
2013 return egCore.pcrud.search(
2015 {peer_record : service.rid},
2018 ).then( function(list) { // finished
2019 service.items = list;
2020 return service.items;
2024 // returns a promise resolved with the list of peer bib types
2025 service.get_peer_types = function() {
2027 return $q.when(egCore.env.bpt.list);
2029 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
2030 .then(function(list) {
2031 egCore.env.absorbList(list, 'bpt');