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'])
12 .config(['ngToastProvider', function(ngToastProvider) {
13 ngToastProvider.configure({
14 verticalPosition: 'bottom',
19 .config(function($routeProvider, $locationProvider, $compileProvider) {
20 $locationProvider.html5Mode(true);
21 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
23 var resolver = {delay : ['egCore','egStartup','egUser', function(egCore, egStartup, egUser) {
24 egCore.env.classLoaders.aous = function() {
25 return egCore.org.settings([
26 'cat.marc_control_number_identifier'
27 ]).then(function(settings) {
28 // local settings are cached within egOrg. Caching them
29 // again in egEnv just simplifies the syntax for access.
30 egCore.env.aous = settings;
33 egCore.env.loadClasses.push('aous');
37 $routeProvider.when('/cat/catalog/index', {
38 templateUrl: './cat/catalog/t_catalog',
39 controller: 'CatalogCtrl',
43 $routeProvider.when('/cat/catalog/retrieve_by_id', {
44 templateUrl: './cat/catalog/t_retrieve_by_id',
45 controller: 'CatalogRecordRetrieve',
49 $routeProvider.when('/cat/catalog/retrieve_by_tcn', {
50 templateUrl: './cat/catalog/t_retrieve_by_tcn',
51 controller: 'CatalogRecordRetrieve',
55 $routeProvider.when('/cat/catalog/new_bib', {
56 templateUrl: './cat/catalog/t_new_bib',
57 controller: 'NewBibCtrl',
61 // create some catalog page-specific mappings
62 $routeProvider.when('/cat/catalog/record/:record_id', {
63 templateUrl: './cat/catalog/t_catalog',
64 controller: 'CatalogCtrl',
68 // create some catalog page-specific mappings
69 $routeProvider.when('/cat/catalog/record/:record_id/:record_tab', {
70 templateUrl: './cat/catalog/t_catalog',
71 controller: 'CatalogCtrl',
75 $routeProvider.when('/cat/catalog/batchEdit', {
76 templateUrl: './cat/catalog/t_batchedit',
77 controller: 'BatchEditCtrl',
81 $routeProvider.when('/cat/catalog/batchEdit/:container_type/:container_id', {
82 templateUrl: './cat/catalog/t_batchedit',
83 controller: 'BatchEditCtrl',
87 $routeProvider.when('/cat/catalog/vandelay', {
88 templateUrl: './cat/catalog/t_vandelay',
89 controller: 'VandelayCtrl',
93 $routeProvider.when('/cat/catalog/verifyURLs', {
94 templateUrl: './cat/catalog/t_verifyurls',
95 controller: 'URLVerifyCtrl',
99 $routeProvider.when('/cat/catalog/manageAuthorities', {
100 templateUrl: './cat/catalog/t_manageauthorities',
101 controller: 'ManageAuthoritiesCtrl',
105 $routeProvider.when('/cat/catalog/authority/:authority_id/marc_edit', {
106 templateUrl: './cat/catalog/t_authority',
107 controller: 'AuthorityCtrl',
111 $routeProvider.otherwise({redirectTo : '/cat/catalog/index'});
117 .controller('CatalogRecordRetrieve',
118 ['$scope','$routeParams','$location','$q','egCore',
119 function($scope , $routeParams , $location , $q , egCore ) {
121 $scope.focusMe = true;
123 // jump to the patron checkout UI
124 function loadRecord(record_id) {
126 .path('/cat/catalog/record/' + record_id);
129 $scope.submitId = function(args) {
130 $scope.recordNotFound = null;
131 if (!args.record_id) return;
133 // blur so next time it's set to true it will re-apply select()
134 $scope.selectMe = false;
136 return loadRecord(args.record_id);
139 $scope.submitTCN = function(args) {
140 $scope.recordNotFound = null;
141 $scope.moreRecordsFound = null;
142 if (!args.record_tcn) return;
144 // blur so next time it's set to true it will re-apply select()
145 $scope.selectMe = false;
150 'open-ils.search.biblio.tcn',
153 .then(function(resp) { // get_barcodes
155 if (evt = egCore.evt.parse(resp)) {
161 $scope.recordNotFound = args.record_tcn;
162 $scope.selectMe = true;
166 if (resp.count > 1) {
167 $scope.moreRecordsFound = args.record_tcn;
168 $scope.selectMe = true;
172 var record_id = resp.ids[0];
173 return loadRecord(record_id);
179 .controller('NewBibCtrl',
180 ['$scope','$routeParams','$location','$window','$q','egCore',
181 'egGridDataProvider','egHoldGridActions','$timeout','holdingsSvc',
182 function($scope , $routeParams , $location , $window , $q , egCore) {
184 $scope.have_template = false;
185 $scope.marc_template = '';
186 $scope.stop_unload = false;
187 $scope.template_list = [];
188 $scope.template_name = '';
189 $scope.new_bib_id = 0;
193 'open-ils.cat.marc_template.types.retrieve'
194 ).then(function(resp) {
195 angular.forEach(resp, function(name) {
196 $scope.template_list.push(name);
198 $scope.template_list.sort();
200 $scope.template_name = egCore.hatch.getSessionItem('eg.cat.last_bib_marc_template');
201 if (!$scope.template_name) {
202 egCore.hatch.getItem('cat.default_bib_marc_template').then(function(template) {
203 $scope.template_name = template;
207 $scope.loadTemplate = function() {
208 if ($scope.template_name) {
211 'open-ils.cat.biblio.marc_template.retrieve',
213 ).then(function(template) {
214 $scope.marc_template = template;
215 $scope.have_template = true;
216 egCore.hatch.setSessionItem('eg.cat.last_bib_marc_template', $scope.template_name);
221 $scope.setDefaultTemplate = function() {
222 var hatch_key = "cat.default_bib_marc_template";
223 if ($scope.template_name) {
224 egCore.hatch.setItem(hatch_key, $scope.template_name);
226 egCore.hatch.removeItem(hatch_key);
230 $scope.$watch('new_bib_id', function(newVal, oldVal) {
232 $location.path('/cat/catalog/record/' + $scope.new_bib_id);
239 .controller('CatalogCtrl',
240 ['$scope','$routeParams','$location','$window','$q','egCore','egHolds','egCirc','egConfirmDialog','ngToast',
241 'egGridDataProvider','egHoldGridActions','$timeout','$uibModal','holdingsSvc','egUser','conjoinedSvc',
242 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc , egConfirmDialog , ngToast ,
243 egGridDataProvider , egHoldGridActions , $timeout , $uibModal , holdingsSvc , egUser , conjoinedSvc) {
245 var holdingsSvcInst = new holdingsSvc();
247 // set record ID on page load if available...
248 $scope.record_id = $routeParams.record_id;
249 $scope.summary_pane_record;
251 if ($routeParams.record_id) $scope.from_route = true;
252 else $scope.from_route = false;
254 // will hold a ref to the opac iframe
255 $scope.opac_iframe = null;
256 $scope.parts_iframe = null;
258 $scope.search_result_index = 1;
259 $scope.search_result_hit_count = 1;
262 'opac_iframe.dom.contentWindow.search_result_index',
264 if (!isNaN(parseInt(n)))
265 $scope.search_result_index = n + 1;
270 'opac_iframe.dom.contentWindow.search_result_hit_count',
272 if (!isNaN(parseInt(n)))
273 $scope.search_result_hit_count = n;
277 $scope.in_opac_call = false;
278 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
279 if ($scope.opac_iframe) {
280 if (force_opac_tab) $scope.record_tab = 'catalog';
281 $scope.in_opac_call = true;
282 $scope.opac_iframe.dom.contentWindow[opac_frame_function]();
283 if (opac_frame_function == 'rdetailBackToResults') {
284 $location.update_path('/cat/catalog/index');
289 $scope.add_to_record_bucket = function() {
290 var recId = $scope.record_id;
291 return $uibModal.open({
292 templateUrl: './cat/catalog/t_add_to_bucket',
296 ['$scope','$uibModalInstance',
297 function($scope , $uibModalInstance) {
299 $scope.bucket_id = 0;
300 $scope.newBucketName = '';
301 $scope.allBuckets = [];
304 'open-ils.actor.container.retrieve_by_class.authoritative',
305 egCore.auth.token(), egCore.auth.user().id(),
306 'biblio', 'staff_client'
307 ).then(function(buckets) { $scope.allBuckets = buckets; });
309 $scope.add_to_bucket = function() {
310 var item = new egCore.idl.cbrebi();
311 item.bucket($scope.bucket_id);
312 item.target_biblio_record_entry(recId);
315 'open-ils.actor.container.item.create',
316 egCore.auth.token(), 'biblio', item
317 ).then(function(resp) {
318 $uibModalInstance.close();
322 $scope.add_to_new_bucket = function() {
323 var bucket = new egCore.idl.cbreb();
324 bucket.owner(egCore.auth.user().id());
325 bucket.name($scope.newBucketName);
326 bucket.description('');
327 bucket.btype('staff_client');
331 'open-ils.actor.container.create',
332 egCore.auth.token(), 'biblio', bucket
333 ).then(function(bucket) {
334 $scope.bucket_id = bucket;
335 $scope.add_to_bucket();
339 $scope.cancel = function() {
340 $uibModalInstance.dismiss();
346 $scope.current_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record');
347 $scope.current_voltransfer_target = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
348 $scope.current_conjoined_target = egCore.hatch.getLocalItem('eg.cat.marked_conjoined_record');
350 $scope.markConjoined = function () {
351 $scope.current_conjoined_target = $scope.record_id;
352 egCore.hatch.setLocalItem('eg.cat.marked_conjoined_record',$scope.record_id);
353 ngToast.create(egCore.strings.MARK_CONJ_TARGET);
356 $scope.markVolTransfer = function () {
357 ngToast.create(egCore.strings.MARK_VOL_TARGET);
358 $scope.current_voltransfer_target = $scope.record_id;
359 egCore.hatch.setLocalItem('eg.cat.marked_volume_transfer_record',$scope.record_id);
362 $scope.markOverlay = function () {
363 $scope.current_overlay_target = $scope.record_id;
364 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.record_id);
365 ngToast.create(egCore.strings.MARK_OVERLAY_TARGET);
368 $scope.clearRecordMarks = function () {
369 $scope.current_overlay_target = null;
370 $scope.current_voltransfer_target = null;
371 $scope.current_conjoined_target = null;
372 egCore.hatch.removeLocalItem('eg.cat.marked_volume_transfer_record');
373 egCore.hatch.removeLocalItem('eg.cat.marked_conjoined_record');
374 egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');
377 $scope.stop_unload = false;
378 $scope.$watch('stop_unload',
379 function(newVal, oldVal) {
380 if (newVal && newVal != oldVal && $scope.opac_iframe) {
381 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
382 return 'There is unsaved data in this record.'
385 if ($scope.opac_iframe)
386 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
391 // Set the "last bib" cookie, if we have that
392 if ($scope.record_id)
393 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
395 $scope.refresh_record_callback = function (record_id) {
396 egCore.pcrud.retrieve('bre', record_id, {
399 bre : ['simple_record','creator','editor']
401 }).then(function(rec) {
402 rec.owner(egCore.org.get(rec.owner()));
403 $scope.summary_pane_record = rec;
409 // also set it when the iframe changes to a new record
410 $scope.handle_page = function(url) {
412 if (!url || url == 'about:blank') {
413 // nothing loaded. If we already have a record ID, leave it.
417 var match = url.match(/\/+opac\/+record\/+(\d+)/);
419 $scope.record_id = match[1];
420 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
421 $scope.holdings_record_id_changed($scope.record_id);
422 conjoinedSvc.fetch($scope.record_id).then(function(){
423 $scope.conjoinedGridDataProvider.refresh();
426 $location.update_path('/cat/catalog/record/' + $scope.record_id);
428 delete $scope.record_id;
429 $scope.from_route = false;
432 // child scope is executing this function, so our digest doesn't fire ... thus,
435 if (!$scope.in_opac_call) {
436 if ($scope.record_id) {
437 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
438 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
440 tab = $routeParams.record_tab || 'catalog';
442 $scope.set_record_tab(tab);
444 $scope.in_opac_call = false;
448 // xulG catalog handlers
449 $scope.handlers = { }
451 // ------------------------------------------------------------------
454 $scope.conjoinedGridControls = {};
455 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
456 get : function(offset, count) {
457 return this.arrayNotifier(conjoinedSvc.items, offset, count);
461 $scope.changeConjoinedType = function () {
462 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
463 angular.forEach(peers, function (p) {
464 p.target_copy(p.target_copy().id());
465 p.peer_type(p.peer_type().id());
468 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
470 return $uibModal.open({
471 templateUrl: './cat/catalog/t_conjoined_selector',
474 ['$scope','$uibModalInstance',
475 function($scope , $uibModalInstance) {
476 $scope.update = true;
478 $scope.peer_type = null;
479 $scope.peer_type_list = [];
480 conjoinedSvc.get_peer_types().then(function(list){
481 $scope.peer_type_list = list;
484 $scope.ok = function(type) {
487 angular.forEach(peers, function (p) {
490 promises.push(egCore.pcrud.update(p));
493 return $q.all(promises)
494 .then(function(){$uibModalInstance.close()})
495 .then(function(){return conjoinedSvc.fetch()})
496 .then(function(){conjoinedGridDataProviderRef.refresh()});
499 $scope.cancel = function($event) {
500 $uibModalInstance.dismiss();
501 $event.preventDefault();
508 $scope.refreshConjoined = function () {
509 conjoinedSvc.fetch($scope.record_id)
510 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
513 $scope.deleteSelectedConjoined = function () {
514 var peers = $scope.conjoinedGridControls.selectedItems();
516 if (peers.length > 0) {
517 egConfirmDialog.open(
518 egCore.strings.CONFIRM_DELETE_PEERS,
519 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
520 {peers : peers.length}
521 ).result.then(function() {
522 angular.forEach(peers, function (p) {
526 egCore.pcrud.remove(peers).then(function() {
527 return conjoinedSvc.fetch();
529 $scope.conjoinedGridDataProvider.refresh();
534 if ($scope.record_id)
535 conjoinedSvc.fetch($scope.record_id);
537 // ------------------------------------------------------------------
540 $scope.holdingsGridControls = {
541 activateItem : function (item) {
542 $scope.selectedHoldingsVolCopyEdit();
545 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
546 get : function(offset, count) {
547 return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
551 $scope.add_copies_to_bucket = function() {
552 var copy_list = gatherSelectedHoldingsIds();
553 if (copy_list.length == 0) return;
555 return $uibModal.open({
556 templateUrl: './cat/catalog/t_add_to_bucket',
560 ['$scope','$uibModalInstance',
561 function($scope , $uibModalInstance) {
563 $scope.bucket_id = 0;
564 $scope.newBucketName = '';
565 $scope.allBuckets = [];
569 'open-ils.actor.container.retrieve_by_class.authoritative',
570 egCore.auth.token(), egCore.auth.user().id(),
571 'copy', 'staff_client'
572 ).then(function(buckets) { $scope.allBuckets = buckets; });
574 $scope.add_to_bucket = function() {
576 angular.forEach(copy_list, function (cp) {
577 var item = new egCore.idl.ccbi()
578 item.bucket($scope.bucket_id);
579 item.target_copy(cp);
583 'open-ils.actor.container.item.create',
584 egCore.auth.token(), 'copy', item
588 return $q.all(promises).then(function() {
589 $uibModalInstance.close();
594 $scope.add_to_new_bucket = function() {
595 var bucket = new egCore.idl.ccb();
596 bucket.owner(egCore.auth.user().id());
597 bucket.name($scope.newBucketName);
598 bucket.description('');
599 bucket.btype('staff_client');
601 return egCore.net.request(
603 'open-ils.actor.container.create',
604 egCore.auth.token(), 'copy', bucket
605 ).then(function(bucket) {
606 $scope.bucket_id = bucket;
607 $scope.add_to_bucket();
611 $scope.cancel = function() {
612 $uibModalInstance.dismiss();
618 $scope.requestItems = function() {
619 var copy_list = gatherSelectedHoldingsIds();
620 if (copy_list.length == 0) return;
622 return $uibModal.open({
623 templateUrl: './cat/catalog/t_request_items',
626 ['$scope','$uibModalInstance',
627 function($scope , $uibModalInstance) {
629 $scope.first_user_fetch = true;
633 copy_list : copy_list,
634 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
635 user : egCore.auth.user().id()
638 egUser.get( $scope.hold_data.user ).then(function(u) {
640 $scope.barcode = u.card().barcode();
641 $scope.user_name = egUser.format_name(u);
642 $scope.hold_data.user = u.id();
645 $scope.user_name = '';
647 $scope.$watch('barcode', function (n) {
648 if (!$scope.first_user_fetch) {
649 egUser.getByBarcode(n).then(function(u) {
651 $scope.user_name = egUser.format_name(u);
652 $scope.hold_data.user = u.id();
655 $scope.user_name = '';
656 delete $scope.hold_data.user;
659 $scope.first_user_fetch = false;
662 $scope.ok = function(h) {
665 hold_type : h.hold_type,
666 pickup_lib: h.pickup_lib.id(),
672 'open-ils.circ.holds.test_and_create.batch.override',
673 egCore.auth.token(), args, h.copy_list
676 $uibModalInstance.close();
679 $scope.cancel = function($event) {
680 $uibModalInstance.dismiss();
681 $event.preventDefault();
687 $scope.replaceBarcodes = function() {
688 var copy_list = gatherSelectedRawCopies();
689 if (copy_list.length == 0) return;
691 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
693 angular.forEach(copy_list, function (cp) {
695 templateUrl: './cat/share/t_replace_barcode',
698 ['$scope','$uibModalInstance',
699 function($scope , $uibModalInstance) {
700 $scope.isModal = true;
701 $scope.focusBarcode = false;
702 $scope.focusBarcode2 = true;
703 $scope.barcode1 = cp.barcode();
705 $scope.updateBarcode = function() {
706 $scope.copyNotFound = false;
707 $scope.updateOK = false;
709 egCore.pcrud.search('acp',
710 {deleted : 'f', barcode : $scope.barcode1})
711 .then(function(copy) {
714 $scope.focusBarcode = true;
715 $scope.copyNotFound = true;
719 $scope.copyId = copy.id();
720 copy.barcode($scope.barcode2);
722 egCore.pcrud.update(copy).then(function(stat) {
723 $scope.updateOK = stat;
724 $scope.focusBarcode = true;
725 holdingsSvc.fetchAgain().then(function (){
726 holdingsGridDataProviderRef.refresh();
731 $uibModalInstance.close();
734 $scope.cancel = function($event) {
735 $uibModalInstance.dismiss();
736 $event.preventDefault();
744 // refresh the list of holdings when the record_id is changed.
745 $scope.holdings_record_id_changed = function(id) {
746 if ($scope.record_id != id) $scope.record_id = id;
747 console.log('record id changed to ' + id + ', loading new holdings');
748 holdingsSvcInst.fetch({
749 rid : $scope.record_id,
750 org : $scope.holdings_ou,
751 copy: $scope.holdings_show_copies,
752 vol : $scope.holdings_show_vols,
753 empty: $scope.holdings_show_empty
755 $scope.holdingsGridDataProvider.refresh();
759 // refresh the list of holdings when the filter lib is changed.
760 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
761 $scope.holdings_ou_changed = function(org) {
762 $scope.holdings_ou = org;
763 holdingsSvcInst.fetch({
764 rid : $scope.record_id,
765 org : $scope.holdings_ou,
766 copy: $scope.holdings_show_copies,
767 vol : $scope.holdings_show_vols,
768 empty: $scope.holdings_show_empty
770 $scope.holdingsGridDataProvider.refresh();
774 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
776 egCore.hatch.setItem('cat.' + cb, newVal);
777 if (!norefresh) holdingsSvcInst.fetch({
778 rid : $scope.record_id,
779 org : $scope.holdings_ou,
780 copy: $scope.holdings_show_copies,
781 vol : $scope.holdings_show_vols,
782 empty: $scope.holdings_show_empty
784 $scope.holdingsGridDataProvider.refresh();
788 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
789 if (typeof x == 'undefined') x = true;
790 $scope.holdings_cb_changed('holdings_show_vols',x,true);
791 $('#holdings_show_vols').prop('checked', x);
793 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
794 if (typeof x == 'undefined') x = true;
795 $scope.holdings_cb_changed('holdings_show_copies',x,true);
796 $('#holdings_show_copies').prop('checked', x);
798 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
799 if (typeof x == 'undefined') x = true;
800 $scope.holdings_cb_changed('holdings_show_empty',x);
801 $('#holdings_show_empty').prop('checked', x);
806 $scope.vols_not_shown = function () {
807 return !$scope.holdings_show_vols;
810 $scope.copies_not_shown = function () {
811 return !$scope.holdings_show_copies;
814 $scope.holdings_checkbox_handler = function (item) {
815 $scope.holdings_cb_changed(item.checkbox,item.checked);
818 function gatherSelectedHoldingsIds () {
821 $scope.holdingsGridControls.selectedItems(),
822 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
827 function gatherSelectedRawCopies () {
830 $scope.holdingsGridControls.selectedItems(),
831 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
836 function gatherSelectedEmptyVolumeIds () {
839 $scope.holdingsGridControls.selectedItems(),
841 if (item.copy_count == 0)
842 cn_id_list.push(item.call_number.id)
848 function gatherSelectedVolumeIds () {
851 $scope.holdingsGridControls.selectedItems(),
853 if (cn_id_list.indexOf(item.call_number.id) == -1)
854 cn_id_list.push(item.call_number.id)
860 $scope.selectedHoldingsDelete = function (vols, copies) {
863 var perCnCopies = {};
869 $scope.holdingsGridControls.selectedItems(),
871 if (vols && item.raw_call_number) {
872 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
873 cnHash[item.call_number.id].isdeleted(1);
876 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
879 var cn_id = cp.call_number().id();
880 if (!cnHash[cn_id]) {
881 cnHash[cn_id] = cp.call_number();
882 perCnCopies[cn_id] = [cp];
884 perCnCopies[cn_id].push(cp);
886 cp.call_number(cn_id); // prevent loops in JSON-ification
893 angular.forEach(perCnCopies, function (v, k) {
895 cnHash[k].isdeleted(1);
902 angular.forEach(cnHash, function (v, k) {
906 if (cnList.length == 0) return;
909 if (vols && copies) flags.force_delete_copies = 1;
911 egConfirmDialog.open(
912 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
913 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
914 {copies : cp_count, volumes : cn_count}
915 ).result.then(function() {
918 'open-ils.cat.asset.volume.fleshed.batch.update.override',
919 egCore.auth.token(), cnList, 1, flags
920 ).then(function(update_count) {
921 holdingsSvcInst.fetchAgain().then(function() {
922 $scope.holdingsGridDataProvider.refresh();
927 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
928 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
929 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
931 spawnHoldingsAdd = function (vols,copies){
933 if (copies) { // just a copy on existing volumes
934 angular.forEach(gatherSelectedVolumeIds(), function (v) {
935 raw.push( {callnumber : v} );
939 $scope.holdingsGridControls.selectedItems(),
941 raw.push({owner : item.owner_id});
946 if (raw.length == 0) raw.push({});
950 'open-ils.actor.anon_cache.set_value',
951 null, 'edit-these-copies', {
952 record_id: $scope.record_id,
957 ).then(function(key) {
959 var url = egCore.env.basePath + 'cat/volcopy/' + key;
960 $timeout(function() { $window.open(url, '_blank') });
962 alert('Could not create anonymous cache key!');
966 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
967 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
969 spawnHoldingsEdit = function (hide_vols,hide_copies){
972 'open-ils.actor.anon_cache.set_value',
973 null, 'edit-these-copies', {
974 record_id: $scope.record_id,
975 copies: gatherSelectedHoldingsIds(),
976 raw: gatherSelectedEmptyVolumeIds().map(
977 function(v){ return { callnumber : v } }
979 hide_vols : hide_vols,
980 hide_copies : hide_copies
982 ).then(function(key) {
984 var url = egCore.env.basePath + 'cat/volcopy/' + key;
985 $timeout(function() { $window.open(url, '_blank') });
987 alert('Could not create anonymous cache key!');
991 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
992 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
993 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
995 $scope.selectedHoldingsItemStatus = function (){
996 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
997 $timeout(function() { $window.open(url, '_blank') });
1000 $scope.markVolAsItemTarget = function() {
1001 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
1002 egCore.hatch.setLocalItem(
1003 'eg.cat.item_transfer_target',
1004 $scope.holdingsGridControls.selectedItems()[0].call_number.id
1006 ngToast.create(egCore.strings.MARK_ITEM_TARGET);
1010 $scope.markLibAsVolTarget = function() {
1011 return $uibModal.open({
1012 templateUrl: './cat/catalog/t_choose_vol_target_lib',
1015 ['$scope','$uibModalInstance',
1016 function($scope , $uibModalInstance) {
1018 var orgId = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target') || 1;
1019 $scope.org = egCore.org.get(orgId);
1020 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1021 $scope.ok = function(org) {
1022 egCore.hatch.setLocalItem(
1023 'eg.cat.volume_transfer_target',
1026 $uibModalInstance.close();
1028 $scope.cancel = function($event) {
1029 $uibModalInstance.dismiss();
1030 $event.preventDefault();
1035 $scope.markLibFromSelectedAsVolTarget = function() {
1036 egCore.hatch.setLocalItem(
1037 'eg.cat.volume_transfer_target',
1038 $scope.holdingsGridControls.selectedItems()[0].owner_id
1040 ngToast.create(egCore.strings.MARK_VOL_TARGET);
1043 $scope.selectedHoldingsItemStatusDetail = function (){
1045 gatherSelectedHoldingsIds(),
1047 var url = egCore.env.basePath +
1049 $timeout(function() { $window.open(url, '_blank') });
1054 $scope.transferVolumesToRecord = function (){
1055 var target_record = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
1056 if (!target_record) return;
1057 if ($scope.record_id == target_record) return;
1058 var items = $scope.holdingsGridControls.selectedItems();
1059 if (!items.length) return;
1061 var vols_to_move = {};
1062 angular.forEach(items, function(item) {
1063 if (!(item.call_number.owning_lib in vols_to_move)) {
1064 vols_to_move[item.call_number.owning_lib] = new Array;
1066 vols_to_move[item.call_number.owning_lib].push(item.call_number.id);
1070 angular.forEach(vols_to_move, function(vols, owning_lib) {
1071 promises.push(egCore.net.request(
1073 'open-ils.cat.asset.volume.batch.transfer.override',
1074 egCore.auth.token(), {
1075 docid : target_record,
1081 $q.all(promises).then(function(success) {
1083 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1084 holdingsSvcInst.fetchAgain().then(function() {
1085 $scope.holdingsGridDataProvider.refresh();
1088 alert('Could not transfer volumes!');
1093 function transferVolumes(new_record){
1094 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
1099 'open-ils.cat.asset.volume.batch.transfer.override',
1100 egCore.auth.token(), {
1101 docid : (new_record ? new_record : $scope.record_id),
1103 volumes : gatherSelectedVolumeIds()
1105 ).then(function(success) {
1107 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1108 holdingsSvcInst.fetchAgain().then(function() {
1109 $scope.holdingsGridDataProvider.refresh();
1112 alert('Could not transfer volumes!');
1119 $scope.transferVolumesToLibrary = function() {
1123 $scope.transferVolumesToRecordAndLibrary = function() {
1124 var target_record = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
1125 if (!target_record) return;
1126 transferVolumes(target_record);
1129 // this "transfers" selected copies to a new owning library,
1130 // auto-creating volumes and deleting unused volumes as required.
1131 $scope.changeItemOwningLib = function() {
1132 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
1133 var items = $scope.holdingsGridControls.selectedItems();
1134 if (!xfer_target || !items.length) {
1137 var vols_to_move = {};
1138 var copies_to_move = {};
1139 angular.forEach(items, function(item) {
1140 if (item.call_number.owning_lib != xfer_target) {
1141 if (item.call_number.id in vols_to_move) {
1142 copies_to_move[item.call_number.id].push(item.id);
1144 vols_to_move[item.call_number.id] = item.call_number;
1145 copies_to_move[item.call_number.id] = new Array;
1146 copies_to_move[item.call_number.id].push(item.id);
1152 angular.forEach(vols_to_move, function(vol) {
1153 promises.push(egCore.net.request(
1155 'open-ils.cat.call_number.find_or_create',
1156 egCore.auth.token(),
1163 ).then(function(resp) {
1164 var evt = egCore.evt.parse(resp);
1166 return egCore.net.request(
1168 'open-ils.cat.transfer_copies_to_volume',
1169 egCore.auth.token(),
1171 copies_to_move[vol.id]
1175 $q.all(promises).then(function() {
1176 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1177 holdingsSvcInst.fetchAgain().then(function() {
1178 $scope.holdingsGridDataProvider.refresh();
1183 $scope.transferItems = function (){
1184 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
1185 var copy_ids = gatherSelectedHoldingsIds();
1186 if (xfer_target && copy_ids.length > 0) {
1189 'open-ils.cat.transfer_copies_to_volume',
1190 egCore.auth.token(),
1194 function(resp) { // oncomplete
1195 var evt = egCore.evt.parse(resp);
1197 egConfirmDialog.open(
1198 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1199 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1200 {'evt_desc': evt.desc}
1201 ).result.then(function() {
1204 'open-ils.cat.transfer_copies_to_volume.override',
1205 egCore.auth.token(),
1208 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1209 ).then(function(resp) {
1210 holdingsSvcInst.fetchAgain().then(function() {
1211 $scope.holdingsGridDataProvider.refresh();
1216 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1217 holdingsSvcInst.fetchAgain().then(function() {
1218 $scope.holdingsGridDataProvider.refresh();
1228 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1230 gatherSelectedHoldingsIds(),
1232 var url = egCore.env.basePath +
1233 'cat/item/' + cid + '/triggered_events';
1234 $timeout(function() { $window.open(url, '_blank') });
1239 $scope.selectedHoldingsItemStatusHolds = function (){
1241 gatherSelectedHoldingsIds(),
1243 var url = egCore.env.basePath +
1244 'cat/item/' + cid + '/holds';
1245 $timeout(function() { $window.open(url, '_blank') });
1250 $scope.selectedHoldingsDamaged = function () {
1251 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
1252 holdingsSvcInst.fetchAgain().then(function() {
1253 $scope.holdingsGridDataProvider.refresh();
1258 $scope.selectedHoldingsMissing = function () {
1259 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1260 holdingsSvcInst.fetchAgain().then(function() {
1261 $scope.holdingsGridDataProvider.refresh();
1266 $scope.attach_to_peer_bib = function() {
1267 var copy_list = gatherSelectedHoldingsIds();
1268 if (copy_list.length == 0) return;
1270 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1271 if (!target_record) return;
1273 return $uibModal.open({
1274 templateUrl: './cat/catalog/t_conjoined_selector',
1277 ['$scope','$uibModalInstance',
1278 function($scope , $uibModalInstance) {
1279 $scope.update = false;
1281 $scope.peer_type = null;
1282 $scope.peer_type_list = [];
1283 conjoinedSvc.get_peer_types().then(function(list){
1284 $scope.peer_type_list = list;
1287 $scope.ok = function(type) {
1290 angular.forEach(copy_list, function (cp) {
1291 var n = new egCore.idl.bpbcm();
1293 n.peer_record(target_record);
1296 promises.push(egCore.pcrud.create(n));
1299 return $q.all(promises).then(function(){$uibModalInstance.close()});
1302 $scope.cancel = function($event) {
1303 $uibModalInstance.dismiss();
1304 $event.preventDefault();
1312 // ------------------------------------------------------------------
1314 var provider = egGridDataProvider.instance({});
1315 $scope.hold_grid_data_provider = provider;
1316 $scope.grid_actions = egHoldGridActions;
1317 $scope.grid_actions.refresh = function () { provider.refresh() };
1318 $scope.hold_grid_controls = {};
1320 var hold_ids = []; // current list of holds
1321 function fetchHolds(offset, count) {
1322 var ids = hold_ids.slice(offset, offset + count);
1323 return egHolds.fetch_holds(ids).then(null, null,
1324 function(hold_data) {
1330 provider.get = function(offset, count) {
1331 if ($scope.record_tab != 'holds') return $q.when();
1332 var deferred = $q.defer();
1333 hold_ids = []; // no caching ATM
1338 'open-ils.circ.holds.retrieve_all_from_title',
1339 egCore.auth.token(), $scope.record_id,
1340 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
1342 function(hold_data) {
1343 angular.forEach(hold_data, function(list, type) {
1344 hold_ids = hold_ids.concat(list);
1346 fetchHolds(offset, count).then(
1347 deferred.resolve, null, deferred.notify);
1351 return deferred.promise;
1354 $scope.detail_view = function(action, user_data, items) {
1356 $scope.detail_hold_id = h.hold.id();
1360 $scope.list_view = function(items) {
1361 $scope.detail_hold_id = null;
1364 // refresh the list of record holds when the pickup lib is changed.
1365 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1366 $scope.pickup_ou_changed = function(org) {
1367 $scope.pickup_ou = org;
1371 $scope.print_holds = function() {
1373 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1375 hold : egCore.idl.toHash(item.hold),
1376 patron_last : item.patron_last,
1377 patron_alias : item.patron_alias,
1378 patron_barcode : item.patron_barcode,
1379 copy : egCore.idl.toHash(item.copy),
1380 volume : egCore.idl.toHash(item.volume),
1381 title : item.mvr.title(),
1382 author : item.mvr.author()
1386 egCore.print.print({
1387 context : 'receipt',
1388 template : 'holds_for_bib',
1389 scope : {holds : holds}
1393 $scope.mark_hold_transfer_dest = function() {
1394 egCore.hatch.setLocalItem(
1395 'eg.circ.hold.title_transfer_target', $scope.record_id);
1396 ngToast.create(egCore.strings.HOLD_TRANSFER_DEST_MARKED);
1399 // UI presents this option as "all holds"
1400 $scope.transfer_holds_to_marked = function() {
1401 var hold_ids = $scope.hold_grid_controls.allItems().map(
1402 function(hold_data) {return hold_data.hold.id()});
1403 egHolds.transfer_to_marked_title(hold_ids);
1406 // ------------------------------------------------------------------
1407 // Initialize the selected tab
1409 function init_cat_url() {
1410 // Set the initial catalog URL. This only happens once.
1411 // The URL is otherwise generated through user navigation.
1412 if ($scope.catalog_url) return;
1414 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1416 // A record ID in the path indicates a request for the record-
1418 if ($routeParams.record_id) {
1419 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1422 $scope.catalog_url = url;
1425 function init_parts_url() {
1426 $scope.parts_url = $location
1430 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1434 $scope.set_record_tab = function(tab) {
1435 $scope.record_tab = tab;
1448 $scope.detail_hold_record_id = $scope.record_id;
1449 // refresh the holds grid
1455 $scope.set_default_record_tab = function() {
1456 egCore.hatch.setLocalItem(
1457 'eg.cat.default_record_tab', $scope.record_tab);
1458 $timeout(function(){$scope.default_tab = $scope.record_tab});
1462 if ($scope.record_id) {
1463 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1464 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1467 tab = $routeParams.record_tab || 'catalog';
1469 $scope.set_record_tab(tab);
1473 .controller('AuthorityCtrl',
1474 ['$scope','$routeParams','$location','$window','$q','egCore',
1475 function($scope , $routeParams , $location , $window , $q , egCore) {
1477 // set record ID on page load if available...
1478 $scope.authority_id = $routeParams.authority_id;
1480 if ($routeParams.authority_id) $scope.from_route = true;
1481 else $scope.from_route = false;
1483 $scope.stop_unload = false;
1486 .controller('URLVerifyCtrl',
1487 ['$scope','$location',
1488 function($scope , $location) {
1489 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1492 .controller('VandelayCtrl',
1493 ['$scope','$location',
1494 function($scope , $location) {
1495 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
1498 .controller('ManageAuthoritiesCtrl',
1499 ['$scope','$location',
1500 function($scope , $location) {
1501 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1504 .controller('BatchEditCtrl',
1505 ['$scope','$location','$routeParams',
1506 function($scope , $location , $routeParams) {
1507 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1508 if ($routeParams.container_type) {
1509 switch ($routeParams.container_type) {
1511 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1514 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1521 .filter('boolText', function(){
1522 return function (v) {
1527 .factory('conjoinedSvc',
1529 function(egCore , $q) {
1532 items : [], // record search results
1533 index : 0, // search grid index
1540 bpbcm : ['target_copy','peer_type'],
1541 acp : ['call_number'],
1543 bre : ['simple_record']
1545 // avoid fetching the MARC blob by specifying which
1546 // fields on the bre to select. More may be needed.
1547 // note that fleshed fields are explicitly selected.
1548 select : { bre : ['id'] },
1549 order_by : { bpbcm : ['id'] },
1552 // resolved with the last received copy
1553 service.fetch = function(rid) {
1554 if (!rid && !service.rid) return $q.when();
1556 if (rid) service.rid = rid;
1560 return egCore.pcrud.search(
1562 {peer_record : service.rid},
1565 ).then( function(list) { // finished
1566 service.items = list;
1567 return service.items;
1571 // returns a promise resolved with the list of peer bib types
1572 service.get_peer_types = function() {
1574 return $q.when(egCore.env.bpt.list);
1576 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
1577 .then(function(list) {
1578 egCore.env.absorbList(list, 'bpt');