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_to_record_bucket = function() {
342 var recId = $scope.record_id;
343 return $uibModal.open({
344 templateUrl: './cat/catalog/t_add_to_bucket',
349 ['$scope','$uibModalInstance',
350 function($scope , $uibModalInstance) {
352 $scope.bucket_id = 0;
353 $scope.newBucketName = '';
354 $scope.allBuckets = [];
357 'open-ils.actor.container.retrieve_by_class.authoritative',
358 egCore.auth.token(), egCore.auth.user().id(),
359 'biblio', 'staff_client'
360 ).then(function(buckets) { $scope.allBuckets = buckets; });
362 $scope.add_to_bucket = function() {
363 var item = new egCore.idl.cbrebi();
364 item.bucket($scope.bucket_id);
365 item.target_biblio_record_entry(recId);
368 'open-ils.actor.container.item.create',
369 egCore.auth.token(), 'biblio', item
370 ).then(function(resp) {
371 $uibModalInstance.close();
375 $scope.add_to_new_bucket = function() {
376 var bucket = new egCore.idl.cbreb();
377 bucket.owner(egCore.auth.user().id());
378 bucket.name($scope.newBucketName);
379 bucket.description('');
380 bucket.btype('staff_client');
384 'open-ils.actor.container.create',
385 egCore.auth.token(), 'biblio', bucket
386 ).then(function(bucket) {
387 $scope.bucket_id = bucket;
388 $scope.add_to_bucket();
392 $scope.cancel = function() {
393 $uibModalInstance.dismiss();
399 $scope.current_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record');
400 $scope.current_transfer_target = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
401 $scope.current_conjoined_target = egCore.hatch.getLocalItem('eg.cat.marked_conjoined_record');
403 $scope.quickReceive = function () {
405 var next_per_stream = {};
407 var recId = $scope.record_id;
408 return $uibModal.open({
409 templateUrl: './share/t_subscription_select_dialog',
411 controller: ['$scope', '$uibModalInstance',
412 function($scope, $uibModalInstance) {
415 $scope.rememberMe = 'eg.serials.quickreceive.last_org';
416 $scope.record_id = recId;
417 $scope.ssubId = null;
419 $scope.ok = function() { $uibModalInstance.close($scope.ssubId) }
420 $scope.cancel = function() { $uibModalInstance.dismiss(); }
423 }).result.then(function(ssubId) {
426 promises.push(egSerialsCoreSvc.fetchItemsForSub(ssubId,{status:'Expected'}).then(function(){
427 angular.forEach(egSerialsCoreSvc.itemTree, function (item) {
428 if (next_per_stream[item.stream().id()]) return;
429 if (item.status() == 'Expected') {
430 next_per_stream[item.stream().id()] = item;
431 list.push(egCore.idl.Clone(item));
436 return $q.all(promises).then(function() {
439 ngToast.warning(egCore.strings.SERIALS_NO_ITEMS);
443 return egSerialsCoreSvc.process_items(
449 false, // print by default
450 function() { $scope.holdings_record_id_changed($scope.record_id) }
454 ngToast.warning(egCore.strings.SERIALS_NO_SUBS);
460 $scope.markConjoined = function () {
461 $scope.current_conjoined_target = $scope.record_id;
462 egCore.hatch.setLocalItem('eg.cat.marked_conjoined_record',$scope.record_id);
463 ngToast.create(egCore.strings.MARK_CONJ_TARGET);
466 $scope.markHoldingsTransfer = function () {
467 $scope.current_transfer_target = $scope.record_id;
468 egCore.hatch.setLocalItem('eg.cat.transfer_target_record',$scope.record_id);
469 egCore.hatch.removeLocalItem('eg.cat.transfer_target_lib');
470 egCore.hatch.removeLocalItem('eg.cat.transfer_target_vol');
471 ngToast.create(egCore.strings.MARK_HOLDINGS_TARGET);
474 $scope.markOverlay = function () {
475 $scope.current_overlay_target = $scope.record_id;
476 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.record_id);
477 ngToast.create(egCore.strings.MARK_OVERLAY_TARGET);
480 $scope.clearRecordMarks = function () {
481 $scope.current_overlay_target = null;
482 $scope.current_transfer_target = null;
483 $scope.current_conjoined_target = null;
484 $scope.current_hold_transfer_dest = null;
485 egCore.hatch.removeLocalItem('eg.cat.transfer_target_record');
486 egCore.hatch.removeLocalItem('eg.cat.marked_conjoined_record');
487 egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');
488 egCore.hatch.removeLocalItem('eg.circ.hold.title_transfer_target');
491 $scope.stop_unload = false;
492 $scope.$watch('stop_unload',
493 function(newVal, oldVal) {
494 if (newVal && newVal != oldVal && $scope.opac_iframe) {
495 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
496 return 'There is unsaved data in this record.'
499 if ($scope.opac_iframe)
500 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
505 // Set the "last bib" cookie, if we have that
506 if ($scope.record_id)
507 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
509 $scope.refresh_record_callback = function (record_id) {
510 egCore.pcrud.retrieve('bre', record_id, {
513 bre : ['simple_record','creator','editor']
515 }).then(function(rec) {
516 rec.owner(egCore.org.get(rec.owner()));
517 $scope.summary_pane_record = rec;
523 patron_search_dialog = function() {
524 return $uibModal.open({
525 templateUrl: './share/t_patron_selector',
530 ['$scope','$uibModalInstance','$controller',
531 function($scope , $uibModalInstance , $controller) {
532 angular.extend(this, $controller('BasePatronSearchCtrl', {$scope : $scope}));
534 $scope.need_one_selected = function() {
535 var items = $scope.gridControls.selectedItems();
536 return (items.length == 1) ? false : true
538 $scope.ok = function() {
539 var items = $scope.gridControls.selectedItems();
540 if (items.length == 1) {
541 $uibModalInstance.close(items[0].card().barcode());
543 $uibModalInstance.close()
546 $scope.cancel = function($event) {
547 $uibModalInstance.dismiss();
548 $event.preventDefault();
554 // also set it when the iframe changes to a new record
555 $scope.handle_page = function(url) {
557 if (!url || url == 'about:blank') {
558 // nothing loaded. If we already have a record ID, leave it.
562 var match = url.match(/\/+opac\/+record\/+(\d+)/);
564 $scope.record_id = match[1];
565 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
566 $scope.holdings_record_id_changed($scope.record_id);
567 conjoinedSvc.fetch($scope.record_id).then(function(){
568 $scope.conjoinedGridDataProvider.refresh();
570 egHolds.fetch_holds(hold_ids).then($scope.hold_grid_data_provider.refresh);
572 $location.update_path('/cat/catalog/record/' + $scope.record_id);
573 // update_path() bypasses the controller for path
574 // /cat/catalog/record/:record_id. Manually set title here too.
575 egCore.strings.setPageTitle(
576 egCore.strings.PAGE_TITLE_BIB_DETAIL,
577 egCore.strings.PAGE_TITLE_CATALOG_CONTEXT,
578 {record_id : $scope.record_id}
581 delete $scope.record_id;
582 $scope.from_route = false;
585 // child scope is executing this function, so our digest doesn't fire ... thus,
588 if (!$scope.in_opac_call) {
589 if ($scope.record_id && !$scope.record_tab) {
590 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
591 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
593 tab = $routeParams.record_tab || 'catalog';
595 $scope.set_record_tab(tab);
597 $scope.in_opac_call = false;
600 if ($scope.opac_iframe && $location.path().match(/cat\/catalog/)) {
601 var doc = $scope.opac_iframe.dom.contentWindow.document;
602 $(doc).find('#hold_usr_search').show();
603 $(doc).find('#hold_usr_search').on('click', function() {
604 patron_search_dialog().result.then(function(barc) {
605 $(doc).find('#hold_usr_input').val(barc);
606 $(doc).find('#hold_usr_input').change();
613 // xulG catalog handlers
614 $scope.handlers = { }
616 // ------------------------------------------------------------------
619 $scope.conjoinedGridControls = {};
620 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
621 get : function(offset, count) {
622 return this.arrayNotifier(conjoinedSvc.items, offset, count);
626 $scope.changeConjoinedType = function () {
627 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
628 angular.forEach(peers, function (p) {
629 p.target_copy(p.target_copy().id());
630 p.peer_type(p.peer_type().id());
633 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
635 return $uibModal.open({
636 templateUrl: './cat/catalog/t_conjoined_selector',
640 ['$scope','$uibModalInstance',
641 function($scope , $uibModalInstance) {
642 $scope.update = true;
644 $scope.peer_type = null;
645 $scope.peer_type_list = [];
646 conjoinedSvc.get_peer_types().then(function(list){
647 $scope.peer_type_list = list;
650 $scope.ok = function(type) {
653 angular.forEach(peers, function (p) {
656 promises.push(egCore.pcrud.update(p));
659 return $q.all(promises)
660 .then(function(){$uibModalInstance.close()})
661 .then(function(){return conjoinedSvc.fetch()})
662 .then(function(){conjoinedGridDataProviderRef.refresh()});
665 $scope.cancel = function($event) {
666 $uibModalInstance.dismiss();
667 $event.preventDefault();
674 $scope.refreshConjoined = function () {
675 conjoinedSvc.fetch($scope.record_id)
676 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
679 $scope.deleteSelectedConjoined = function () {
680 var peers = $scope.conjoinedGridControls.selectedItems();
682 if (peers.length > 0) {
683 egConfirmDialog.open(
684 egCore.strings.CONFIRM_DELETE_PEERS,
685 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
686 {peers : peers.length}
687 ).result.then(function() {
688 angular.forEach(peers, function (p) {
692 egCore.pcrud.remove(peers).then(function() {
693 return conjoinedSvc.fetch();
695 $scope.conjoinedGridDataProvider.refresh();
700 if ($scope.record_id)
701 conjoinedSvc.fetch($scope.record_id);
703 // ------------------------------------------------------------------
706 $scope.holdingsGridControls = {
707 activateItem : function (item) {
708 $scope.selectedHoldingsVolCopyEdit();
711 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
712 get : function(offset, count) {
713 return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
717 $scope.add_copies_to_bucket = function() {
718 var copy_list = gatherSelectedHoldingsIds();
719 if (copy_list.length == 0) return;
721 return $uibModal.open({
722 templateUrl: './cat/catalog/t_add_to_bucket',
727 ['$scope','$uibModalInstance',
728 function($scope , $uibModalInstance) {
730 $scope.bucket_id = 0;
731 $scope.newBucketName = '';
732 $scope.allBuckets = [];
736 'open-ils.actor.container.retrieve_by_class.authoritative',
737 egCore.auth.token(), egCore.auth.user().id(),
738 'copy', 'staff_client'
739 ).then(function(buckets) { $scope.allBuckets = buckets; });
741 $scope.add_to_bucket = function() {
743 angular.forEach(copy_list, function (cp) {
744 var item = new egCore.idl.ccbi()
745 item.bucket($scope.bucket_id);
746 item.target_copy(cp);
750 'open-ils.actor.container.item.create',
751 egCore.auth.token(), 'copy', item
755 return $q.all(promises).then(function() {
756 $uibModalInstance.close();
761 $scope.add_to_new_bucket = function() {
762 var bucket = new egCore.idl.ccb();
763 bucket.owner(egCore.auth.user().id());
764 bucket.name($scope.newBucketName);
765 bucket.description('');
766 bucket.btype('staff_client');
768 return egCore.net.request(
770 'open-ils.actor.container.create',
771 egCore.auth.token(), 'copy', bucket
772 ).then(function(bucket) {
773 $scope.bucket_id = bucket;
774 $scope.add_to_bucket();
778 $scope.cancel = function() {
779 $uibModalInstance.dismiss();
785 // TODO: refactor common code between cat/catalog/app.js and cat/item/app.js
787 $scope.need_one_selected = function() {
788 var items = $scope.holdingsGridControls.selectedItems();
789 if (items.length == 1) return false;
793 $scope.make_copies_bookable = function() {
795 var copies_by_record = {};
796 var record_list = [];
798 $scope.holdingsGridControls.selectedItems(),
800 var record_id = item['call_number.record.id'];
801 if (typeof copies_by_record[ record_id ] == 'undefined') {
802 copies_by_record[ record_id ] = [];
803 record_list.push( record_id );
805 copies_by_record[ record_id ].push(item.id);
810 var combined_results = [];
811 angular.forEach(record_list, function(record_id) {
815 'open-ils.booking.resources.create_from_copies',
817 copies_by_record[record_id]
818 ).then(function(results) {
819 if (results && results['brsrc']) {
820 combined_results = combined_results.concat(results['brsrc']);
826 $q.all(promises).then(function() {
827 if (combined_results.length > 0) {
829 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
834 ['$scope','$location','egCore','$uibModalInstance',
835 function($scope , $location , egCore , $uibModalInstance) {
838 ses : egCore.auth.token(),
839 resultant_brsrc : combined_results.map(function(o) { return o[0]; })
842 var booking_path = '/eg/conify/global/booking/resource';
844 $scope.booking_admin_url =
845 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
852 $scope.book_copies_now = function() {
853 var copies_by_record = {};
854 var record_list = [];
856 $scope.holdingsGridControls.selectedItems(),
858 var record_id = item['call_number.record.id'];
859 if (typeof copies_by_record[ record_id ] == 'undefined') {
860 copies_by_record[ record_id ] = [];
861 record_list.push( record_id );
863 copies_by_record[ record_id ].push(item.id);
868 var combined_brt = [];
869 var combined_brsrc = [];
870 angular.forEach(record_list, function(record_id) {
874 'open-ils.booking.resources.create_from_copies',
876 copies_by_record[record_id]
877 ).then(function(results) {
878 if (results && results['brt']) {
879 combined_brt = combined_brt.concat(results['brt']);
881 if (results && results['brsrc']) {
882 combined_brsrc = combined_brsrc.concat(results['brsrc']);
888 $q.all(promises).then(function() {
889 if (combined_brt.length > 0 || combined_brsrc.length > 0) {
891 template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
896 ['$scope','$location','egCore','$uibModalInstance',
897 function($scope , $location , egCore , $uibModalInstance) {
900 ses : egCore.auth.token(),
901 bresv_interface_opts : {
904 ,brsrc : combined_brsrc
909 var booking_path = '/eg/booking/reservation';
911 $scope.booking_admin_url =
912 $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
921 $scope.requestItems = function() {
922 var copy_list = gatherSelectedHoldingsIds();
923 if (copy_list.length == 0) return;
925 return $uibModal.open({
926 templateUrl: './cat/catalog/t_request_items',
929 ['$scope','$uibModalInstance',
930 function($scope , $uibModalInstance) {
932 $scope.first_user_fetch = true;
936 copy_list : copy_list,
937 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
938 user : egCore.auth.user().id()
941 egUser.get( $scope.hold_data.user ).then(function(u) {
943 $scope.barcode = u.card().barcode();
944 $scope.user_name = egUser.format_name(u);
945 $scope.hold_data.user = u.id();
948 $scope.user_name = '';
950 $scope.$watch('barcode', function (n) {
951 if (!$scope.first_user_fetch) {
952 egUser.getByBarcode(n).then(function(u) {
954 $scope.user_name = egUser.format_name(u);
955 $scope.hold_data.user = u.id();
958 $scope.user_name = '';
959 delete $scope.hold_data.user;
962 $scope.first_user_fetch = false;
965 $scope.ok = function(h) {
968 hold_type : h.hold_type,
969 pickup_lib: h.pickup_lib.id(),
975 'open-ils.circ.holds.test_and_create.batch.override',
976 egCore.auth.token(), args, h.copy_list
979 $uibModalInstance.close();
982 $scope.cancel = function($event) {
983 $uibModalInstance.dismiss();
984 $event.preventDefault();
990 $scope.view_place_orders = function() {
991 if (!$scope.record_id) return;
992 var url = egCore.env.basePath + 'acq/legacy/lineitem/related/' + $scope.record_id + '?target=bib';
993 $timeout(function() { $window.open(url, '_blank') });
996 $scope.replaceBarcodes = function() {
997 var copy_list = gatherSelectedRawCopies();
998 if (copy_list.length == 0) return;
1000 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
1002 angular.forEach(copy_list, function (cp) {
1004 templateUrl: './cat/share/t_replace_barcode',
1008 ['$scope','$uibModalInstance',
1009 function($scope , $uibModalInstance) {
1010 $scope.isModal = true;
1011 $scope.focusBarcode = false;
1012 $scope.focusBarcode2 = true;
1013 $scope.barcode1 = cp.barcode();
1015 $scope.updateBarcode = function() {
1016 $scope.copyNotFound = false;
1017 $scope.updateOK = false;
1019 egCore.pcrud.search('acp',
1020 {deleted : 'f', barcode : $scope.barcode1})
1021 .then(function(copy) {
1024 $scope.focusBarcode = true;
1025 $scope.copyNotFound = true;
1029 $scope.copyId = copy.id();
1030 copy.barcode($scope.barcode2);
1032 egCore.pcrud.update(copy).then(function(stat) {
1033 $scope.updateOK = stat;
1034 $scope.focusBarcode = true;
1035 holdingsSvc.fetchAgain().then(function (){
1036 holdingsGridDataProviderRef.refresh();
1041 $uibModalInstance.close();
1044 $scope.cancel = function($event) {
1045 $uibModalInstance.dismiss();
1046 $event.preventDefault();
1054 // refresh the list of holdings when the record_id is changed.
1055 $scope.holdings_record_id_changed = function(id) {
1056 if ($scope.record_id != id) $scope.record_id = id;
1057 console.log('record id changed to ' + id + ', loading new holdings');
1058 holdingsSvcInst.fetch({
1059 rid : $scope.record_id,
1060 org : $scope.holdings_ou,
1061 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1062 vol : $scope.holdings_show_vols,
1063 empty: $scope.holdings_show_empty,
1064 empty_org: $scope.holdings_show_empty_org
1065 }).then(function() {
1066 $scope.holdingsGridDataProvider.refresh();
1070 // refresh the list of holdings when the filter lib is changed.
1071 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
1072 $scope.holdings_ou_changed = function(org) {
1073 $scope.holdings_ou = org;
1074 holdingsSvcInst.fetch({
1075 rid : $scope.record_id,
1076 org : $scope.holdings_ou,
1077 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1078 vol : $scope.holdings_show_vols,
1079 empty: $scope.holdings_show_empty,
1080 empty_org: $scope.holdings_show_empty_org
1081 }).then(function() {
1082 $scope.holdingsGridDataProvider.refresh();
1086 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
1087 $scope[cb] = newVal;
1088 var x = $scope.holdings_show_vols ? $scope.holdings_show_copies : false;
1089 $('#holdings_show_copies').prop('checked', x);
1090 egCore.hatch.setItem('cat.' + cb, newVal);
1091 if (!norefresh) holdingsSvcInst.fetch({
1092 rid : $scope.record_id,
1093 org : $scope.holdings_ou,
1094 copy: $scope.holdings_show_vols ? $scope.holdings_show_copies : false,
1095 vol : $scope.holdings_show_vols,
1096 empty: $scope.holdings_show_empty,
1097 empty_org: $scope.holdings_show_empty_org
1098 }).then(function() {
1099 $scope.holdingsGridDataProvider.refresh();
1103 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
1104 if (typeof x == 'undefined') x = true;
1105 $scope.holdings_cb_changed('holdings_show_vols',x,true);
1106 $('#holdings_show_vols').prop('checked', x);
1108 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
1109 if (typeof x == 'undefined') x = true;
1110 $scope.holdings_cb_changed('holdings_show_copies',x,true);
1111 x = $scope.holdings_show_vols ? x : false;
1112 $('#holdings_show_copies').prop('checked', x);
1114 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
1115 if (typeof x == 'undefined') x = true;
1116 $scope.holdings_cb_changed('holdings_show_empty',x);
1117 $('#holdings_show_empty').prop('checked', x);
1119 egCore.hatch.getItem('cat.holdings_show_empty_org').then(function(x){
1120 if (typeof x == 'undefined') x = true;
1121 $scope.holdings_cb_changed('holdings_show_empty_org',x);
1122 $('#holdings_show_empty_org').prop('checked', x);
1128 $scope.vols_not_shown = function () {
1129 return !$scope.holdings_show_vols;
1132 $scope.copies_not_shown = function () {
1133 return !$scope.holdings_show_copies;
1136 $scope.empty_org_not_shown = function () {
1137 return !$scope.holdings_show_empty_org;
1140 $scope.holdings_checkbox_handler = function (item) {
1141 $scope.holdings_cb_changed(item.checkbox,item.checked);
1144 function gatherSelectedHoldingsIds () {
1145 var cp_id_list = [];
1147 $scope.holdingsGridControls.selectedItems(),
1148 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
1153 function gatherSelectedRawCopies () {
1156 $scope.holdingsGridControls.selectedItems(),
1157 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
1162 function gatherSelectedEmptyVolumeIds () {
1163 var cn_id_list = [];
1165 $scope.holdingsGridControls.selectedItems(),
1167 if (item.copy_count == 0 || (!item.id && item.call_number))
1168 // we are in a compressed row with no copies, or we are in a single
1169 // call number row with no copy (testing for presence of 'id')
1170 // In either case, the call number is 'empty'
1171 cn_id_list.push(item.call_number.id)
1177 function gatherSelectedVolumeIds () {
1178 var cn_id_list = [];
1180 $scope.holdingsGridControls.selectedItems(),
1182 if (cn_id_list.indexOf(item.call_number.id) == -1)
1183 cn_id_list.push(item.call_number.id)
1189 $scope.selectedHoldingsDelete = function (vols, copies) {
1192 var perCnCopies = {};
1198 $scope.holdingsGridControls.selectedItems(),
1200 if (vols && item.raw_call_number) {
1201 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
1202 cnHash[item.call_number.id].isdeleted(1);
1204 } else if (copies) {
1205 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
1208 var cn_id = cp.call_number().id();
1209 if (!cnHash[cn_id]) {
1210 cnHash[cn_id] = cp.call_number();
1211 perCnCopies[cn_id] = [cp];
1213 perCnCopies[cn_id].push(cp);
1215 cp.call_number(cn_id); // prevent loops in JSON-ification
1222 angular.forEach(perCnCopies, function (v, k) {
1224 cnHash[k].isdeleted(1);
1227 cnHash[k].copies(v);
1231 angular.forEach(cnHash, function (v, k) {
1235 if (cnList.length == 0) return;
1238 if (vols && copies) flags.force_delete_copies = 1;
1240 egConfirmDialog.open(
1241 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
1242 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
1243 {copies : cp_count, volumes : cn_count}
1244 ).result.then(function() {
1247 'open-ils.cat.asset.volume.fleshed.batch.update.override',
1248 egCore.auth.token(), cnList, 1, flags
1249 ).then(function(update_count) {
1250 holdingsSvcInst.fetchAgain().then(function() {
1251 $scope.holdingsGridDataProvider.refresh();
1256 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
1257 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
1258 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
1260 spawnHoldingsAdd = function (add_vols,add_copies){
1262 if (!add_vols && add_copies) { // just a copy on existing volumes
1263 angular.forEach(gatherSelectedVolumeIds(), function (v) {
1264 raw.push( {callnumber : v} );
1266 } else if (add_vols) {
1267 if (typeof $scope.holdingsGridControls.selectedItems == "function" &&
1268 $scope.holdingsGridControls.selectedItems().length > 0) {
1269 angular.forEach($scope.holdingsGridControls.selectedItems(),
1272 owner : item.owner_id,
1273 label : ((item.call_number) ? item.call_number.label : null)
1278 owner : egCore.auth.user().ws_ou()
1283 if (raw.length == 0) raw.push({});
1287 'open-ils.actor.anon_cache.set_value',
1288 null, 'edit-these-copies', {
1289 record_id: $scope.record_id,
1292 hide_copies : !add_copies
1294 ).then(function(key) {
1296 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1297 $timeout(function() { $window.open(url, '_blank') });
1299 alert('Could not create anonymous cache key!');
1303 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,true) }
1304 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
1305 $scope.selectedHoldingsVolAdd = function () { spawnHoldingsAdd(true,false) }
1307 spawnHoldingsEdit = function (hide_vols,hide_copies){
1310 'open-ils.actor.anon_cache.set_value',
1311 null, 'edit-these-copies', {
1312 record_id: $scope.record_id,
1313 copies: gatherSelectedHoldingsIds(),
1314 raw: gatherSelectedEmptyVolumeIds().map(
1315 function(v){ return { callnumber : v } }
1317 hide_vols : hide_vols,
1318 hide_copies : hide_copies
1320 ).then(function(key) {
1322 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1323 $timeout(function() { $window.open(url, '_blank') });
1325 alert('Could not create anonymous cache key!');
1329 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
1330 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
1331 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
1333 $scope.selectedHoldingsItemStatus = function (){
1334 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
1335 $timeout(function() { $window.open(url, '_blank') });
1338 $scope.markFromSelectedAsHoldingsTarget = function() {
1339 egCore.hatch.setLocalItem(
1340 'eg.cat.transfer_target_lib',
1341 $scope.holdingsGridControls.selectedItems()[0].owner_id
1343 egCore.hatch.setLocalItem(
1344 'eg.cat.transfer_target_record',
1347 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed, or we are on an empty lib
1348 egCore.hatch.setLocalItem(
1349 'eg.cat.transfer_target_vol',
1350 $scope.holdingsGridControls.selectedItems()[0].call_number.id
1353 // clear out the stale value if we're on a lib-only
1354 // or vol-collapsed row
1355 egCore.hatch.removeLocalItem('eg.cat.transfer_target_vol');
1357 ngToast.create(egCore.strings.MARK_HOLDINGS_TARGET);
1360 $scope.selectedHoldingsItemStatusDetail = function (){
1362 gatherSelectedHoldingsIds(),
1364 var url = egCore.env.basePath +
1366 $timeout(function() { $window.open(url, '_blank') });
1371 $scope.transferVolumes = function (){
1372 var target_record = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
1373 var target_lib = egCore.hatch.getLocalItem('eg.cat.transfer_target_lib');
1375 && (!target_record || ($scope.record_id == target_record) )
1378 var vols_to_move = {};
1380 // we're moving volumes to a different library
1381 var vol_ids = gatherSelectedVolumeIds();
1382 if (vol_ids.length) {
1383 vols_to_move[target_lib] = vol_ids;
1385 // if we're *only* switching libs,
1386 // grab the current record as the target
1387 target_record = target_record || $scope.record_id;
1390 // we're moving volumes to the same library they exist in
1391 // currently, but on a different record
1392 var items = $scope.holdingsGridControls.selectedItems();
1393 angular.forEach(items, function(item) {
1394 if (!(item.call_number.owning_lib in vols_to_move)) {
1395 vols_to_move[item.call_number.owning_lib] = new Array;
1397 vols_to_move[item.call_number.owning_lib].push(item.call_number.id);
1402 angular.forEach(vols_to_move, function(vols, owning_lib) {
1403 promises.push(egCore.net.request(
1405 'open-ils.cat.asset.volume.batch.transfer.override',
1406 egCore.auth.token(), {
1407 docid : target_record,
1413 $q.all(promises).then(function(success) {
1415 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1416 holdingsSvcInst.fetchAgain().then(function() {
1417 $scope.holdingsGridDataProvider.refresh();
1420 alert('Could not transfer volumes!');
1425 // this "transfers" selected copies to a new owning library,
1426 // auto-creating volumes as required
1427 $scope.transferItemsAutoFill = function() {
1428 var target_record = egCore.hatch.getLocalItem('eg.cat.transfer_target_record');
1429 var target_lib = egCore.hatch.getLocalItem('eg.cat.transfer_target_lib');
1431 && (!target_record || ($scope.record_id == target_record) )
1434 var items = $scope.holdingsGridControls.selectedItems();
1435 if (!items.length) {
1439 var vols_to_move = {};
1440 var copies_to_move = {};
1441 angular.forEach(items, function(item) {
1442 var needs_move = false;
1444 && (item.call_number.owning_lib != target_lib)) {
1445 item.call_number.owning_lib = target_lib;
1449 && (item.call_number.record != target_record)) {
1450 item.call_number.record = target_record;
1454 if (item.call_number.id in vols_to_move) {
1455 copies_to_move[item.call_number.id].push(item.id);
1457 vols_to_move[item.call_number.id] = item.call_number;
1458 copies_to_move[item.call_number.id] = new Array;
1459 copies_to_move[item.call_number.id].push(item.id);
1465 angular.forEach(vols_to_move, function(vol) {
1466 promises.push(egCore.net.request(
1468 'open-ils.cat.call_number.find_or_create',
1469 egCore.auth.token(),
1471 vol.record, // may be new
1472 vol.owning_lib, // may be new
1476 ).then(function(resp) {
1477 var evt = egCore.evt.parse(resp);
1479 return egCore.net.request(
1481 'open-ils.cat.transfer_copies_to_volume',
1482 egCore.auth.token(),
1484 copies_to_move[vol.id]
1488 $q.all(promises).then(function() {
1489 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1490 holdingsSvcInst.fetchAgain().then(function() {
1491 $scope.holdingsGridDataProvider.refresh();
1496 $scope.gridCellHandlers = {};
1497 $scope.gridCellHandlers.copyAlertsEdit = function(id) {
1498 egCirc.manage_copy_alerts([id]).then(function() {
1499 // update grid items?
1503 $scope.transferItems = function (){
1504 var xfer_target = egCore.hatch.getLocalItem('eg.cat.transfer_target_vol');
1507 // we have no specific volume, let's try to fill in the
1509 return $scope.transferItemsAutoFill();
1512 var copy_ids = gatherSelectedHoldingsIds();
1513 if (copy_ids.length > 0) {
1516 'open-ils.cat.transfer_copies_to_volume',
1517 egCore.auth.token(),
1521 function(resp) { // oncomplete
1522 var evt = egCore.evt.parse(resp);
1524 egConfirmDialog.open(
1525 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1526 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1527 {'evt_desc': evt.desc}
1528 ).result.then(function() {
1531 'open-ils.cat.transfer_copies_to_volume.override',
1532 egCore.auth.token(),
1535 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1536 ).then(function(resp) {
1537 holdingsSvcInst.fetchAgain().then(function() {
1538 $scope.holdingsGridDataProvider.refresh();
1543 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1544 holdingsSvcInst.fetchAgain().then(function() {
1545 $scope.holdingsGridDataProvider.refresh();
1555 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1557 gatherSelectedHoldingsIds(),
1559 var url = egCore.env.basePath +
1560 'cat/item/' + cid + '/triggered_events';
1561 $timeout(function() { $window.open(url, '_blank') });
1566 $scope.selectedHoldingsItemStatusHolds = function (){
1568 gatherSelectedHoldingsIds(),
1570 var url = egCore.env.basePath +
1571 'cat/item/' + cid + '/holds';
1572 $timeout(function() { $window.open(url, '_blank') });
1577 $scope.selectedHoldingsPrintLabels = function() {
1580 'open-ils.actor.anon_cache.set_value',
1581 null, 'print-labels-these-copies', {
1582 copies : gatherSelectedHoldingsIds()
1584 ).then(function(key) {
1586 var url = egCore.env.basePath + 'cat/printlabels/' + key;
1587 $timeout(function() { $window.open(url, '_blank') });
1589 alert('Could not create anonymous cache key!');
1594 $scope.selectedHoldingsDamaged = function () {
1595 var copy_list = gatherSelectedRawCopies();
1596 if (copy_list.length == 0) return;
1598 angular.forEach(copy_list, function(cp) {
1599 egCirc.mark_damaged({
1601 barcode: cp.barcode(),
1602 circ_lib: cp.circ_lib().id()
1603 }).then(function() {
1604 holdingsSvcInst.fetchAgain().then(function() {
1605 $scope.holdingsGridDataProvider.refresh();
1611 $scope.selectedHoldingsMissing = function () {
1612 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1613 holdingsSvcInst.fetchAgain().then(function() {
1614 $scope.holdingsGridDataProvider.refresh();
1619 $scope.selectedHoldingsCopyAlertsAdd = function() {
1620 egCirc.add_copy_alerts(gatherSelectedHoldingsIds()).then(function() {
1621 // no need to refresh grid
1624 $scope.selectedHoldingsCopyAlertsManage = function() {
1625 egCirc.manage_copy_alerts(gatherSelectedHoldingsIds()).then(function() {
1626 // no need to refresh grid
1630 $scope.attach_to_peer_bib = function() {
1631 var copy_list = gatherSelectedHoldingsIds();
1632 if (copy_list.length == 0) return;
1634 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1635 if (!target_record) return;
1637 return $uibModal.open({
1638 templateUrl: './cat/catalog/t_conjoined_selector',
1642 ['$scope','$uibModalInstance',
1643 function($scope , $uibModalInstance) {
1644 $scope.update = false;
1646 $scope.peer_type = null;
1647 $scope.peer_type_list = [];
1648 conjoinedSvc.get_peer_types().then(function(list){
1649 $scope.peer_type_list = list;
1652 $scope.ok = function(type) {
1655 angular.forEach(copy_list, function (cp) {
1656 var n = new egCore.idl.bpbcm();
1658 n.peer_record(target_record);
1661 promises.push(egCore.pcrud.create(n));
1664 return $q.all(promises).then(function(){$uibModalInstance.close()});
1667 $scope.cancel = function($event) {
1668 $uibModalInstance.dismiss();
1669 $event.preventDefault();
1677 // ------------------------------------------------------------------
1679 var provider = egGridDataProvider.instance({});
1680 $scope.hold_grid_data_provider = provider;
1681 $scope.grid_actions = egHoldGridActions;
1682 $scope.grid_actions.refresh = function () { provider.refresh() };
1683 $scope.hold_grid_controls = {};
1685 var hold_ids = []; // current list of holds
1686 function fetchHolds(offset, count) {
1687 var ids = hold_ids.slice(offset, offset + count);
1689 return egHolds.fetch_holds(ids).then(null, null,
1690 function(hold_data) {
1696 provider.get = function(offset, count) {
1697 if ($scope.record_tab != 'holds') return $q.when();
1698 var deferred = $q.defer();
1699 hold_ids = []; // no caching ATM
1701 // open a determinate progress dialog, max value set below.
1702 egProgressDialog.open({max : 1, value : 0});
1707 'open-ils.circ.holds.retrieve_all_from_title',
1708 egCore.auth.token(), $scope.record_id,
1709 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
1711 function(hold_data) {
1712 hold_ids = []; // clear the list of ids, hack to avoid dups
1713 // TODO: fix the underlying problem, which is that
1714 // this gets called twice when switching to the holds
1715 // tab; once explicitly, and once via the change handler
1716 // on the OU selector
1717 angular.forEach(hold_data, function(list, type) {
1718 hold_ids = hold_ids.concat(list);
1721 // Set the max value of the progress bar to the lesser of
1722 // the total number of holds to fetch or the page size
1724 egProgressDialog.update(
1725 {max : Math.min(hold_ids.length, count)});
1727 var holds_fetched = 0;
1728 fetchHolds(offset, count)
1729 .then(deferred.resolve, null,
1730 function(hold_data) {
1732 deferred.notify(hold_data);
1733 egProgressDialog.increment();
1735 )['finally'](egProgressDialog.close);
1739 return deferred.promise;
1742 $scope.detail_view = function(action, user_data, items) {
1744 $scope.detail_hold_id = h.hold.id();
1748 $scope.list_view = function(items) {
1749 $scope.detail_hold_id = null;
1752 // refresh the list of record holds when the pickup lib is changed.
1753 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1754 $scope.pickup_ou_changed = function(org) {
1755 $scope.pickup_ou = org;
1759 $scope.print_holds = function() {
1761 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1763 hold : egCore.idl.toHash(item.hold),
1764 patron_last : item.patron_last,
1765 patron_alias : item.patron_alias,
1766 patron_barcode : item.patron_barcode,
1767 copy : egCore.idl.toHash(item.copy),
1768 volume : egCore.idl.toHash(item.volume),
1769 title : item.mvr.title(),
1770 author : item.mvr.author()
1774 egCore.print.print({
1775 context : 'receipt',
1776 template : 'holds_for_bib',
1777 scope : {holds : holds}
1781 $scope.current_hold_transfer_dest = egCore.hatch.getLocalItem ('eg.circ.hold.title_transfer_target');
1783 $scope.mark_hold_transfer_dest = function() {
1784 $scope.current_hold_transfer_dest = $scope.record_id;
1785 egCore.hatch.setLocalItem(
1786 'eg.circ.hold.title_transfer_target', $scope.record_id);
1787 ngToast.create(egCore.strings.HOLD_TRANSFER_DEST_MARKED);
1790 // UI presents this option as "all holds"
1791 $scope.transfer_holds_to_marked = function() {
1792 var hold_ids = $scope.hold_grid_controls.allItems().map(
1793 function(hold_data) {return hold_data.hold.id()});
1794 egHolds.transfer_to_marked_title(hold_ids);
1797 // ------------------------------------------------------------------
1798 // Initialize the selected tab
1800 // we explicitly initialize catalog_url because otherwise Firefox
1801 // ends up setting it to $BASE_URL/{{url}}, which then messes
1802 // things up. See LP#1708951
1803 $scope.catalog_url = '';
1805 function init_cat_url() {
1806 // Set the initial catalog URL. This only happens once.
1807 // The URL is otherwise generated through user navigation.
1808 if ($scope.catalog_url) return;
1810 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1812 // A record ID in the path indicates a request for the record-
1814 if ($routeParams.record_id) {
1815 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1818 // Jumping directly to the results page by passing a search
1819 // query via the URL. Copy all URL params to the iframe url.
1820 if ($location.path().match(/catalog\/results/)) {
1821 url = url.replace(/advanced/, '/results?');
1823 angular.forEach($location.search(), function(val, key) {
1824 if (!first) url += '&';
1826 url += encodeURIComponent(key)
1827 + '=' + encodeURIComponent(val);
1831 // if we're displaying the advanced search form, select
1832 // whatever default pane the user has chosen via workstation
1834 if (url.match(/\/opac\/advanced$/)) {
1835 var adv_pane = egCore.hatch.getLocalItem('eg.search.adv_pane');
1837 url += '?pane=' + encodeURIComponent(adv_pane);
1841 $scope.catalog_url = url;
1844 function init_parts_url() {
1845 $scope.parts_url = $location
1849 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1853 $scope.set_record_tab = function(tab) {
1854 $scope.record_tab = tab;
1867 $scope.detail_hold_record_id = $scope.record_id;
1868 // refresh the holds grid
1875 $scope.set_default_record_tab = function() {
1876 egCore.hatch.setLocalItem(
1877 'eg.cat.default_record_tab', $scope.record_tab);
1878 $timeout(function(){$scope.default_tab = $scope.record_tab});
1882 if ($scope.record_id) {
1883 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1884 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1887 tab = $routeParams.record_tab || 'catalog';
1889 $scope.set_record_tab(tab);
1893 .controller('AuthorityCtrl',
1894 ['$scope','$routeParams','$location','$window','$q','egCore',
1895 function($scope , $routeParams , $location , $window , $q , egCore) {
1897 // set record ID on page load if available...
1898 $scope.authority_id = $routeParams.authority_id;
1900 if ($routeParams.authority_id) $scope.from_route = true;
1901 else $scope.from_route = false;
1903 $scope.stop_unload = false;
1906 .controller('URLVerifyCtrl',
1907 ['$scope','$location',
1908 function($scope , $location) {
1909 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1912 .controller('VandelayCtrl',
1913 ['$scope','$location', 'egCore', '$uibModal',
1914 function($scope , $location, egCore, $uibModal) {
1915 $scope.vandelay_url = $location.absUrl().replace(/\/staff\/cat\/catalog\/vandelay/, '/vandelay/vandelay');
1917 $scope.funcs.edit_marc_modal = function(bre, callback){
1918 var marcArgs = { 'marc_xml': bre.marc() };
1919 var vqbibrecId = bre.id();
1921 templateUrl: './cat/catalog/t_edit_marc_modal',
1924 controller: ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
1925 $scope.focusMe = true;
1926 $scope.recordId = vqbibrecId;
1927 $scope.args = marcArgs;
1928 $scope.dirty_flag = false;
1929 $scope.ok = function(marg){
1930 $uibModalInstance.close(marg);
1932 $scope.cancel = function(){ $uibModalInstance.dismiss() }
1934 }).result.then(function(res){
1935 var new_xml = res.marc_xml;
1936 egCore.pcrud.retrieve('vqbr', vqbibrecId).then(function(vqbib){
1937 vqbib.marc(new_xml);
1938 egCore.pcrud.update(vqbib).then( function(){ callback(vqbibrecId); });
1944 .controller('ManageAuthoritiesCtrl',
1945 ['$scope','$location',
1946 function($scope , $location) {
1947 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1950 .controller('BatchEditCtrl',
1951 ['$scope','$location','$routeParams',
1952 function($scope , $location , $routeParams) {
1953 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1954 if ($routeParams.container_type) {
1955 switch ($routeParams.container_type) {
1957 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1960 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1967 .filter('boolText', function(){
1968 return function (v) {
1973 .factory('conjoinedSvc',
1975 function(egCore , $q) {
1978 items : [], // record search results
1979 index : 0, // search grid index
1986 bpbcm : ['target_copy','peer_type'],
1987 acp : ['call_number'],
1989 bre : ['simple_record']
1991 // avoid fetching the MARC blob by specifying which
1992 // fields on the bre to select. More may be needed.
1993 // note that fleshed fields are explicitly selected.
1994 select : { bre : ['id'] },
1995 order_by : { bpbcm : ['id'] },
1998 // resolved with the last received copy
1999 service.fetch = function(rid) {
2000 if (!rid && !service.rid) return $q.when();
2002 if (rid) service.rid = rid;
2006 return egCore.pcrud.search(
2008 {peer_record : service.rid},
2011 ).then( function(list) { // finished
2012 service.items = list;
2013 return service.items;
2017 // returns a promise resolved with the list of peer bib types
2018 service.get_peer_types = function() {
2020 return $q.when(egCore.env.bpt.list);
2022 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
2023 .then(function(list) {
2024 egCore.env.absorbList(list, 'bpt');