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 // Jump directly to the results page. Any URL parameter
44 // supported by the embedded catalog is supported here.
45 $routeProvider.when('/cat/catalog/results', {
46 templateUrl: './cat/catalog/t_catalog',
47 controller: 'CatalogCtrl',
51 $routeProvider.when('/cat/catalog/retrieve_by_id', {
52 templateUrl: './cat/catalog/t_retrieve_by_id',
53 controller: 'CatalogRecordRetrieve',
57 $routeProvider.when('/cat/catalog/retrieve_by_tcn', {
58 templateUrl: './cat/catalog/t_retrieve_by_tcn',
59 controller: 'CatalogRecordRetrieve',
63 $routeProvider.when('/cat/catalog/new_bib', {
64 templateUrl: './cat/catalog/t_new_bib',
65 controller: 'NewBibCtrl',
69 // create some catalog page-specific mappings
70 $routeProvider.when('/cat/catalog/record/:record_id', {
71 templateUrl: './cat/catalog/t_catalog',
72 controller: 'CatalogCtrl',
76 // create some catalog page-specific mappings
77 $routeProvider.when('/cat/catalog/record/:record_id/:record_tab', {
78 templateUrl: './cat/catalog/t_catalog',
79 controller: 'CatalogCtrl',
83 $routeProvider.when('/cat/catalog/batchEdit', {
84 templateUrl: './cat/catalog/t_batchedit',
85 controller: 'BatchEditCtrl',
89 $routeProvider.when('/cat/catalog/batchEdit/:container_type/:container_id', {
90 templateUrl: './cat/catalog/t_batchedit',
91 controller: 'BatchEditCtrl',
95 $routeProvider.when('/cat/catalog/vandelay', {
96 templateUrl: './cat/catalog/t_vandelay',
97 controller: 'VandelayCtrl',
101 $routeProvider.when('/cat/catalog/verifyURLs', {
102 templateUrl: './cat/catalog/t_verifyurls',
103 controller: 'URLVerifyCtrl',
107 $routeProvider.when('/cat/catalog/manageAuthorities', {
108 templateUrl: './cat/catalog/t_manageauthorities',
109 controller: 'ManageAuthoritiesCtrl',
113 $routeProvider.when('/cat/catalog/authority/:authority_id/marc_edit', {
114 templateUrl: './cat/catalog/t_authority',
115 controller: 'AuthorityCtrl',
119 $routeProvider.otherwise({redirectTo : '/cat/catalog/index'});
125 .controller('CatalogRecordRetrieve',
126 ['$scope','$routeParams','$location','$q','egCore',
127 function($scope , $routeParams , $location , $q , egCore ) {
129 $scope.focusMe = true;
131 // jump to the patron checkout UI
132 function loadRecord(record_id) {
134 .path('/cat/catalog/record/' + record_id);
137 $scope.submitId = function(args) {
138 $scope.recordNotFound = null;
139 if (!args.record_id) return;
141 // blur so next time it's set to true it will re-apply select()
142 $scope.selectMe = false;
144 return loadRecord(args.record_id);
147 $scope.submitTCN = function(args) {
148 $scope.recordNotFound = null;
149 $scope.moreRecordsFound = null;
150 if (!args.record_tcn) return;
152 // blur so next time it's set to true it will re-apply select()
153 $scope.selectMe = false;
158 'open-ils.search.biblio.tcn',
161 .then(function(resp) { // get_barcodes
163 if (evt = egCore.evt.parse(resp)) {
169 $scope.recordNotFound = args.record_tcn;
170 $scope.selectMe = true;
174 if (resp.count > 1) {
175 $scope.moreRecordsFound = args.record_tcn;
176 $scope.selectMe = true;
180 var record_id = resp.ids[0];
181 return loadRecord(record_id);
187 .controller('NewBibCtrl',
188 ['$scope','$routeParams','$location','$window','$q','egCore',
189 'egGridDataProvider','egHoldGridActions','$timeout','holdingsSvc',
190 function($scope , $routeParams , $location , $window , $q , egCore) {
192 $scope.have_template = false;
193 $scope.marc_template = '';
194 $scope.stop_unload = false;
195 $scope.template_list = [];
196 $scope.template_name = '';
197 $scope.new_bib_id = 0;
201 'open-ils.cat.marc_template.types.retrieve'
202 ).then(function(resp) {
203 angular.forEach(resp, function(name) {
204 $scope.template_list.push(name);
206 $scope.template_list.sort();
208 $scope.template_name = egCore.hatch.getSessionItem('eg.cat.last_bib_marc_template');
209 if (!$scope.template_name) {
210 egCore.hatch.getItem('cat.default_bib_marc_template').then(function(template) {
211 $scope.template_name = template;
215 $scope.loadTemplate = function() {
216 if ($scope.template_name) {
219 'open-ils.cat.biblio.marc_template.retrieve',
221 ).then(function(template) {
222 $scope.marc_template = template;
223 $scope.have_template = true;
224 egCore.hatch.setSessionItem('eg.cat.last_bib_marc_template', $scope.template_name);
229 $scope.setDefaultTemplate = function() {
230 var hatch_key = "cat.default_bib_marc_template";
231 if ($scope.template_name) {
232 egCore.hatch.setItem(hatch_key, $scope.template_name);
234 egCore.hatch.removeItem(hatch_key);
238 $scope.$watch('new_bib_id', function(newVal, oldVal) {
240 $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','$timeout','$uibModal','holdingsSvc','egUser','conjoinedSvc',
251 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc , egConfirmDialog , ngToast ,
252 egGridDataProvider , egHoldGridActions , $timeout , $uibModal , holdingsSvc , egUser , conjoinedSvc,
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 ($routeParams.record_id) $scope.from_route = true;
263 else $scope.from_route = false;
265 // set search and preferred library cookies
266 egCore.hatch.getItem('eg.search.search_lib').then(function(val) {
267 $cookies.put('eg_search_lib', val, { path : '/' });
269 egCore.hatch.getItem('eg.search.pref_lib').then(function(val) {
270 $cookies.put('eg_pref_lib', val, { path : '/' });
273 // will hold a ref to the opac iframe
274 $scope.opac_iframe = null;
275 $scope.parts_iframe = null;
277 $scope.search_result_index = 1;
278 $scope.search_result_hit_count = 1;
281 'opac_iframe.dom.contentWindow.search_result_index',
283 if (!isNaN(parseInt(n)))
284 $scope.search_result_index = n + 1;
289 'opac_iframe.dom.contentWindow.search_result_hit_count',
291 if (!isNaN(parseInt(n)))
292 $scope.search_result_hit_count = n;
296 $scope.in_opac_call = false;
297 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
298 if ($scope.opac_iframe) {
299 if (force_opac_tab) $scope.record_tab = 'catalog';
300 $scope.in_opac_call = true;
301 $scope.opac_iframe.dom.contentWindow[opac_frame_function]();
302 if (opac_frame_function == 'rdetailBackToResults') {
303 $location.update_path('/cat/catalog/index');
308 $scope.add_to_record_bucket = function() {
309 var recId = $scope.record_id;
310 return $uibModal.open({
311 templateUrl: './cat/catalog/t_add_to_bucket',
315 ['$scope','$uibModalInstance',
316 function($scope , $uibModalInstance) {
318 $scope.bucket_id = 0;
319 $scope.newBucketName = '';
320 $scope.allBuckets = [];
323 'open-ils.actor.container.retrieve_by_class.authoritative',
324 egCore.auth.token(), egCore.auth.user().id(),
325 'biblio', 'staff_client'
326 ).then(function(buckets) { $scope.allBuckets = buckets; });
328 $scope.add_to_bucket = function() {
329 var item = new egCore.idl.cbrebi();
330 item.bucket($scope.bucket_id);
331 item.target_biblio_record_entry(recId);
334 'open-ils.actor.container.item.create',
335 egCore.auth.token(), 'biblio', item
336 ).then(function(resp) {
337 $uibModalInstance.close();
341 $scope.add_to_new_bucket = function() {
342 var bucket = new egCore.idl.cbreb();
343 bucket.owner(egCore.auth.user().id());
344 bucket.name($scope.newBucketName);
345 bucket.description('');
346 bucket.btype('staff_client');
350 'open-ils.actor.container.create',
351 egCore.auth.token(), 'biblio', bucket
352 ).then(function(bucket) {
353 $scope.bucket_id = bucket;
354 $scope.add_to_bucket();
358 $scope.cancel = function() {
359 $uibModalInstance.dismiss();
365 $scope.current_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record');
366 $scope.current_voltransfer_target = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
367 $scope.current_conjoined_target = egCore.hatch.getLocalItem('eg.cat.marked_conjoined_record');
369 $scope.markConjoined = function () {
370 $scope.current_conjoined_target = $scope.record_id;
371 egCore.hatch.setLocalItem('eg.cat.marked_conjoined_record',$scope.record_id);
372 ngToast.create(egCore.strings.MARK_CONJ_TARGET);
375 $scope.markVolTransfer = function () {
376 ngToast.create(egCore.strings.MARK_VOL_TARGET);
377 $scope.current_voltransfer_target = $scope.record_id;
378 egCore.hatch.setLocalItem('eg.cat.marked_volume_transfer_record',$scope.record_id);
381 $scope.markOverlay = function () {
382 $scope.current_overlay_target = $scope.record_id;
383 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.record_id);
384 ngToast.create(egCore.strings.MARK_OVERLAY_TARGET);
387 $scope.clearRecordMarks = function () {
388 $scope.current_overlay_target = null;
389 $scope.current_voltransfer_target = null;
390 $scope.current_conjoined_target = null;
391 egCore.hatch.removeLocalItem('eg.cat.marked_volume_transfer_record');
392 egCore.hatch.removeLocalItem('eg.cat.marked_conjoined_record');
393 egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');
396 $scope.stop_unload = false;
397 $scope.$watch('stop_unload',
398 function(newVal, oldVal) {
399 if (newVal && newVal != oldVal && $scope.opac_iframe) {
400 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
401 return 'There is unsaved data in this record.'
404 if ($scope.opac_iframe)
405 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
410 // Set the "last bib" cookie, if we have that
411 if ($scope.record_id)
412 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
414 $scope.refresh_record_callback = function (record_id) {
415 egCore.pcrud.retrieve('bre', record_id, {
418 bre : ['simple_record','creator','editor']
420 }).then(function(rec) {
421 rec.owner(egCore.org.get(rec.owner()));
422 $scope.summary_pane_record = rec;
428 // also set it when the iframe changes to a new record
429 $scope.handle_page = function(url) {
431 if (!url || url == 'about:blank') {
432 // nothing loaded. If we already have a record ID, leave it.
436 var match = url.match(/\/+opac\/+record\/+(\d+)/);
438 $scope.record_id = match[1];
439 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
440 $scope.holdings_record_id_changed($scope.record_id);
441 conjoinedSvc.fetch($scope.record_id).then(function(){
442 $scope.conjoinedGridDataProvider.refresh();
445 $location.update_path('/cat/catalog/record/' + $scope.record_id);
447 delete $scope.record_id;
448 $scope.from_route = false;
451 // child scope is executing this function, so our digest doesn't fire ... thus,
454 if (!$scope.in_opac_call) {
455 if ($scope.record_id) {
456 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
457 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
459 tab = $routeParams.record_tab || 'catalog';
461 $scope.set_record_tab(tab);
463 $scope.in_opac_call = false;
467 // xulG catalog handlers
468 $scope.handlers = { }
470 // ------------------------------------------------------------------
473 $scope.conjoinedGridControls = {};
474 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
475 get : function(offset, count) {
476 return this.arrayNotifier(conjoinedSvc.items, offset, count);
480 $scope.changeConjoinedType = function () {
481 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
482 angular.forEach(peers, function (p) {
483 p.target_copy(p.target_copy().id());
484 p.peer_type(p.peer_type().id());
487 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
489 return $uibModal.open({
490 templateUrl: './cat/catalog/t_conjoined_selector',
493 ['$scope','$uibModalInstance',
494 function($scope , $uibModalInstance) {
495 $scope.update = true;
497 $scope.peer_type = null;
498 $scope.peer_type_list = [];
499 conjoinedSvc.get_peer_types().then(function(list){
500 $scope.peer_type_list = list;
503 $scope.ok = function(type) {
506 angular.forEach(peers, function (p) {
509 promises.push(egCore.pcrud.update(p));
512 return $q.all(promises)
513 .then(function(){$uibModalInstance.close()})
514 .then(function(){return conjoinedSvc.fetch()})
515 .then(function(){conjoinedGridDataProviderRef.refresh()});
518 $scope.cancel = function($event) {
519 $uibModalInstance.dismiss();
520 $event.preventDefault();
527 $scope.refreshConjoined = function () {
528 conjoinedSvc.fetch($scope.record_id)
529 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
532 $scope.deleteSelectedConjoined = function () {
533 var peers = $scope.conjoinedGridControls.selectedItems();
535 if (peers.length > 0) {
536 egConfirmDialog.open(
537 egCore.strings.CONFIRM_DELETE_PEERS,
538 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
539 {peers : peers.length}
540 ).result.then(function() {
541 angular.forEach(peers, function (p) {
545 egCore.pcrud.remove(peers).then(function() {
546 return conjoinedSvc.fetch();
548 $scope.conjoinedGridDataProvider.refresh();
553 if ($scope.record_id)
554 conjoinedSvc.fetch($scope.record_id);
556 // ------------------------------------------------------------------
559 $scope.holdingsGridControls = {
560 activateItem : function (item) {
561 $scope.selectedHoldingsVolCopyEdit();
564 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
565 get : function(offset, count) {
566 return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
570 $scope.add_copies_to_bucket = function() {
571 var copy_list = gatherSelectedHoldingsIds();
572 if (copy_list.length == 0) return;
574 return $uibModal.open({
575 templateUrl: './cat/catalog/t_add_to_bucket',
579 ['$scope','$uibModalInstance',
580 function($scope , $uibModalInstance) {
582 $scope.bucket_id = 0;
583 $scope.newBucketName = '';
584 $scope.allBuckets = [];
588 'open-ils.actor.container.retrieve_by_class.authoritative',
589 egCore.auth.token(), egCore.auth.user().id(),
590 'copy', 'staff_client'
591 ).then(function(buckets) { $scope.allBuckets = buckets; });
593 $scope.add_to_bucket = function() {
595 angular.forEach(copy_list, function (cp) {
596 var item = new egCore.idl.ccbi()
597 item.bucket($scope.bucket_id);
598 item.target_copy(cp);
602 'open-ils.actor.container.item.create',
603 egCore.auth.token(), 'copy', item
607 return $q.all(promises).then(function() {
608 $uibModalInstance.close();
613 $scope.add_to_new_bucket = function() {
614 var bucket = new egCore.idl.ccb();
615 bucket.owner(egCore.auth.user().id());
616 bucket.name($scope.newBucketName);
617 bucket.description('');
618 bucket.btype('staff_client');
620 return egCore.net.request(
622 'open-ils.actor.container.create',
623 egCore.auth.token(), 'copy', bucket
624 ).then(function(bucket) {
625 $scope.bucket_id = bucket;
626 $scope.add_to_bucket();
630 $scope.cancel = function() {
631 $uibModalInstance.dismiss();
637 $scope.requestItems = function() {
638 var copy_list = gatherSelectedHoldingsIds();
639 if (copy_list.length == 0) return;
641 return $uibModal.open({
642 templateUrl: './cat/catalog/t_request_items',
645 ['$scope','$uibModalInstance',
646 function($scope , $uibModalInstance) {
648 $scope.first_user_fetch = true;
652 copy_list : copy_list,
653 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
654 user : egCore.auth.user().id()
657 egUser.get( $scope.hold_data.user ).then(function(u) {
659 $scope.barcode = u.card().barcode();
660 $scope.user_name = egUser.format_name(u);
661 $scope.hold_data.user = u.id();
664 $scope.user_name = '';
666 $scope.$watch('barcode', function (n) {
667 if (!$scope.first_user_fetch) {
668 egUser.getByBarcode(n).then(function(u) {
670 $scope.user_name = egUser.format_name(u);
671 $scope.hold_data.user = u.id();
674 $scope.user_name = '';
675 delete $scope.hold_data.user;
678 $scope.first_user_fetch = false;
681 $scope.ok = function(h) {
684 hold_type : h.hold_type,
685 pickup_lib: h.pickup_lib.id(),
691 'open-ils.circ.holds.test_and_create.batch.override',
692 egCore.auth.token(), args, h.copy_list
695 $uibModalInstance.close();
698 $scope.cancel = function($event) {
699 $uibModalInstance.dismiss();
700 $event.preventDefault();
706 $scope.replaceBarcodes = function() {
707 var copy_list = gatherSelectedRawCopies();
708 if (copy_list.length == 0) return;
710 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
712 angular.forEach(copy_list, function (cp) {
714 templateUrl: './cat/share/t_replace_barcode',
717 ['$scope','$uibModalInstance',
718 function($scope , $uibModalInstance) {
719 $scope.isModal = true;
720 $scope.focusBarcode = false;
721 $scope.focusBarcode2 = true;
722 $scope.barcode1 = cp.barcode();
724 $scope.updateBarcode = function() {
725 $scope.copyNotFound = false;
726 $scope.updateOK = false;
728 egCore.pcrud.search('acp',
729 {deleted : 'f', barcode : $scope.barcode1})
730 .then(function(copy) {
733 $scope.focusBarcode = true;
734 $scope.copyNotFound = true;
738 $scope.copyId = copy.id();
739 copy.barcode($scope.barcode2);
741 egCore.pcrud.update(copy).then(function(stat) {
742 $scope.updateOK = stat;
743 $scope.focusBarcode = true;
744 holdingsSvc.fetchAgain().then(function (){
745 holdingsGridDataProviderRef.refresh();
750 $uibModalInstance.close();
753 $scope.cancel = function($event) {
754 $uibModalInstance.dismiss();
755 $event.preventDefault();
763 // refresh the list of holdings when the record_id is changed.
764 $scope.holdings_record_id_changed = function(id) {
765 if ($scope.record_id != id) $scope.record_id = id;
766 console.log('record id changed to ' + id + ', loading new holdings');
767 holdingsSvcInst.fetch({
768 rid : $scope.record_id,
769 org : $scope.holdings_ou,
770 copy: $scope.holdings_show_copies,
771 vol : $scope.holdings_show_vols,
772 empty: $scope.holdings_show_empty
774 $scope.holdingsGridDataProvider.refresh();
778 // refresh the list of holdings when the filter lib is changed.
779 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
780 $scope.holdings_ou_changed = function(org) {
781 $scope.holdings_ou = org;
782 holdingsSvcInst.fetch({
783 rid : $scope.record_id,
784 org : $scope.holdings_ou,
785 copy: $scope.holdings_show_copies,
786 vol : $scope.holdings_show_vols,
787 empty: $scope.holdings_show_empty
789 $scope.holdingsGridDataProvider.refresh();
793 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
795 egCore.hatch.setItem('cat.' + cb, newVal);
796 if (!norefresh) holdingsSvcInst.fetch({
797 rid : $scope.record_id,
798 org : $scope.holdings_ou,
799 copy: $scope.holdings_show_copies,
800 vol : $scope.holdings_show_vols,
801 empty: $scope.holdings_show_empty
803 $scope.holdingsGridDataProvider.refresh();
807 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
808 if (typeof x == 'undefined') x = true;
809 $scope.holdings_cb_changed('holdings_show_vols',x,true);
810 $('#holdings_show_vols').prop('checked', x);
812 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
813 if (typeof x == 'undefined') x = true;
814 $scope.holdings_cb_changed('holdings_show_copies',x,true);
815 $('#holdings_show_copies').prop('checked', x);
817 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
818 if (typeof x == 'undefined') x = true;
819 $scope.holdings_cb_changed('holdings_show_empty',x);
820 $('#holdings_show_empty').prop('checked', x);
825 $scope.vols_not_shown = function () {
826 return !$scope.holdings_show_vols;
829 $scope.copies_not_shown = function () {
830 return !$scope.holdings_show_copies;
833 $scope.holdings_checkbox_handler = function (item) {
834 $scope.holdings_cb_changed(item.checkbox,item.checked);
837 function gatherSelectedHoldingsIds () {
840 $scope.holdingsGridControls.selectedItems(),
841 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
846 function gatherSelectedRawCopies () {
849 $scope.holdingsGridControls.selectedItems(),
850 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
855 function gatherSelectedEmptyVolumeIds () {
858 $scope.holdingsGridControls.selectedItems(),
860 if (item.copy_count == 0)
861 cn_id_list.push(item.call_number.id)
867 function gatherSelectedVolumeIds () {
870 $scope.holdingsGridControls.selectedItems(),
872 if (cn_id_list.indexOf(item.call_number.id) == -1)
873 cn_id_list.push(item.call_number.id)
879 $scope.selectedHoldingsDelete = function (vols, copies) {
882 var perCnCopies = {};
888 $scope.holdingsGridControls.selectedItems(),
890 if (vols && item.raw_call_number) {
891 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
892 cnHash[item.call_number.id].isdeleted(1);
895 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
898 var cn_id = cp.call_number().id();
899 if (!cnHash[cn_id]) {
900 cnHash[cn_id] = cp.call_number();
901 perCnCopies[cn_id] = [cp];
903 perCnCopies[cn_id].push(cp);
905 cp.call_number(cn_id); // prevent loops in JSON-ification
912 angular.forEach(perCnCopies, function (v, k) {
914 cnHash[k].isdeleted(1);
921 angular.forEach(cnHash, function (v, k) {
925 if (cnList.length == 0) return;
928 if (vols && copies) flags.force_delete_copies = 1;
930 egConfirmDialog.open(
931 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
932 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
933 {copies : cp_count, volumes : cn_count}
934 ).result.then(function() {
937 'open-ils.cat.asset.volume.fleshed.batch.update.override',
938 egCore.auth.token(), cnList, 1, flags
939 ).then(function(update_count) {
940 holdingsSvcInst.fetchAgain().then(function() {
941 $scope.holdingsGridDataProvider.refresh();
946 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
947 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
948 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
950 spawnHoldingsAdd = function (vols,copies){
952 if (copies) { // just a copy on existing volumes
953 angular.forEach(gatherSelectedVolumeIds(), function (v) {
954 raw.push( {callnumber : v} );
957 if (typeof $scope.holdingsGridControls.selectedItems == "function" &&
958 $scope.holdingsGridControls.selectedItems().length > 0) {
959 angular.forEach($scope.holdingsGridControls.selectedItems(),
962 owner : item.owner_id,
963 label : item.call_number.label
968 owner : egCore.auth.user().ws_ou()
973 if (raw.length == 0) raw.push({});
977 'open-ils.actor.anon_cache.set_value',
978 null, 'edit-these-copies', {
979 record_id: $scope.record_id,
984 ).then(function(key) {
986 var url = egCore.env.basePath + 'cat/volcopy/' + key;
987 $timeout(function() { $window.open(url, '_blank') });
989 alert('Could not create anonymous cache key!');
993 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
994 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
996 spawnHoldingsEdit = function (hide_vols,hide_copies){
999 'open-ils.actor.anon_cache.set_value',
1000 null, 'edit-these-copies', {
1001 record_id: $scope.record_id,
1002 copies: gatherSelectedHoldingsIds(),
1003 raw: gatherSelectedEmptyVolumeIds().map(
1004 function(v){ return { callnumber : v } }
1006 hide_vols : hide_vols,
1007 hide_copies : hide_copies
1009 ).then(function(key) {
1011 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1012 $timeout(function() { $window.open(url, '_blank') });
1014 alert('Could not create anonymous cache key!');
1018 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
1019 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
1020 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
1022 $scope.selectedHoldingsItemStatus = function (){
1023 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
1024 $timeout(function() { $window.open(url, '_blank') });
1027 $scope.markVolAsItemTarget = function() {
1028 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
1029 egCore.hatch.setLocalItem(
1030 'eg.cat.item_transfer_target',
1031 $scope.holdingsGridControls.selectedItems()[0].call_number.id
1033 ngToast.create(egCore.strings.MARK_ITEM_TARGET);
1037 $scope.markLibAsVolTarget = function() {
1038 return $uibModal.open({
1039 templateUrl: './cat/catalog/t_choose_vol_target_lib',
1042 ['$scope','$uibModalInstance',
1043 function($scope , $uibModalInstance) {
1045 var orgId = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target') || 1;
1046 $scope.org = egCore.org.get(orgId);
1047 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1048 $scope.ok = function(org) {
1049 egCore.hatch.setLocalItem(
1050 'eg.cat.volume_transfer_target',
1053 $uibModalInstance.close();
1055 $scope.cancel = function($event) {
1056 $uibModalInstance.dismiss();
1057 $event.preventDefault();
1062 $scope.markLibFromSelectedAsVolTarget = function() {
1063 egCore.hatch.setLocalItem(
1064 'eg.cat.volume_transfer_target',
1065 $scope.holdingsGridControls.selectedItems()[0].owner_id
1067 ngToast.create(egCore.strings.MARK_VOL_TARGET);
1070 $scope.selectedHoldingsItemStatusDetail = function (){
1072 gatherSelectedHoldingsIds(),
1074 var url = egCore.env.basePath +
1076 $timeout(function() { $window.open(url, '_blank') });
1081 $scope.transferVolumesToRecord = function (){
1082 var target_record = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
1083 if (!target_record) return;
1084 if ($scope.record_id == target_record) return;
1085 var items = $scope.holdingsGridControls.selectedItems();
1086 if (!items.length) return;
1088 var vols_to_move = {};
1089 angular.forEach(items, function(item) {
1090 if (!(item.call_number.owning_lib in vols_to_move)) {
1091 vols_to_move[item.call_number.owning_lib] = new Array;
1093 vols_to_move[item.call_number.owning_lib].push(item.call_number.id);
1097 angular.forEach(vols_to_move, function(vols, owning_lib) {
1098 promises.push(egCore.net.request(
1100 'open-ils.cat.asset.volume.batch.transfer.override',
1101 egCore.auth.token(), {
1102 docid : target_record,
1108 $q.all(promises).then(function(success) {
1110 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1111 holdingsSvcInst.fetchAgain().then(function() {
1112 $scope.holdingsGridDataProvider.refresh();
1115 alert('Could not transfer volumes!');
1120 function transferVolumes(new_record){
1121 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
1126 'open-ils.cat.asset.volume.batch.transfer.override',
1127 egCore.auth.token(), {
1128 docid : (new_record ? new_record : $scope.record_id),
1130 volumes : gatherSelectedVolumeIds()
1132 ).then(function(success) {
1134 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1135 holdingsSvcInst.fetchAgain().then(function() {
1136 $scope.holdingsGridDataProvider.refresh();
1139 alert('Could not transfer volumes!');
1146 $scope.transferVolumesToLibrary = function() {
1150 $scope.transferVolumesToRecordAndLibrary = function() {
1151 var target_record = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
1152 if (!target_record) return;
1153 transferVolumes(target_record);
1156 // this "transfers" selected copies to a new owning library,
1157 // auto-creating volumes and deleting unused volumes as required.
1158 $scope.changeItemOwningLib = function() {
1159 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
1160 var items = $scope.holdingsGridControls.selectedItems();
1161 if (!xfer_target || !items.length) {
1164 var vols_to_move = {};
1165 var copies_to_move = {};
1166 angular.forEach(items, function(item) {
1167 if (item.call_number.owning_lib != xfer_target) {
1168 if (item.call_number.id in vols_to_move) {
1169 copies_to_move[item.call_number.id].push(item.id);
1171 vols_to_move[item.call_number.id] = item.call_number;
1172 copies_to_move[item.call_number.id] = new Array;
1173 copies_to_move[item.call_number.id].push(item.id);
1179 angular.forEach(vols_to_move, function(vol) {
1180 promises.push(egCore.net.request(
1182 'open-ils.cat.call_number.find_or_create',
1183 egCore.auth.token(),
1190 ).then(function(resp) {
1191 var evt = egCore.evt.parse(resp);
1193 return egCore.net.request(
1195 'open-ils.cat.transfer_copies_to_volume',
1196 egCore.auth.token(),
1198 copies_to_move[vol.id]
1202 $q.all(promises).then(function() {
1203 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1204 holdingsSvcInst.fetchAgain().then(function() {
1205 $scope.holdingsGridDataProvider.refresh();
1210 $scope.transferItems = function (){
1211 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
1212 var copy_ids = gatherSelectedHoldingsIds();
1213 if (xfer_target && copy_ids.length > 0) {
1216 'open-ils.cat.transfer_copies_to_volume',
1217 egCore.auth.token(),
1221 function(resp) { // oncomplete
1222 var evt = egCore.evt.parse(resp);
1224 egConfirmDialog.open(
1225 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1226 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1227 {'evt_desc': evt.desc}
1228 ).result.then(function() {
1231 'open-ils.cat.transfer_copies_to_volume.override',
1232 egCore.auth.token(),
1235 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1236 ).then(function(resp) {
1237 holdingsSvcInst.fetchAgain().then(function() {
1238 $scope.holdingsGridDataProvider.refresh();
1243 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1244 holdingsSvcInst.fetchAgain().then(function() {
1245 $scope.holdingsGridDataProvider.refresh();
1255 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1257 gatherSelectedHoldingsIds(),
1259 var url = egCore.env.basePath +
1260 'cat/item/' + cid + '/triggered_events';
1261 $timeout(function() { $window.open(url, '_blank') });
1266 $scope.selectedHoldingsItemStatusHolds = function (){
1268 gatherSelectedHoldingsIds(),
1270 var url = egCore.env.basePath +
1271 'cat/item/' + cid + '/holds';
1272 $timeout(function() { $window.open(url, '_blank') });
1277 $scope.selectedHoldingsDamaged = function () {
1278 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
1279 holdingsSvcInst.fetchAgain().then(function() {
1280 $scope.holdingsGridDataProvider.refresh();
1285 $scope.selectedHoldingsMissing = function () {
1286 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1287 holdingsSvcInst.fetchAgain().then(function() {
1288 $scope.holdingsGridDataProvider.refresh();
1293 $scope.attach_to_peer_bib = function() {
1294 var copy_list = gatherSelectedHoldingsIds();
1295 if (copy_list.length == 0) return;
1297 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1298 if (!target_record) return;
1300 return $uibModal.open({
1301 templateUrl: './cat/catalog/t_conjoined_selector',
1304 ['$scope','$uibModalInstance',
1305 function($scope , $uibModalInstance) {
1306 $scope.update = false;
1308 $scope.peer_type = null;
1309 $scope.peer_type_list = [];
1310 conjoinedSvc.get_peer_types().then(function(list){
1311 $scope.peer_type_list = list;
1314 $scope.ok = function(type) {
1317 angular.forEach(copy_list, function (cp) {
1318 var n = new egCore.idl.bpbcm();
1320 n.peer_record(target_record);
1323 promises.push(egCore.pcrud.create(n));
1326 return $q.all(promises).then(function(){$uibModalInstance.close()});
1329 $scope.cancel = function($event) {
1330 $uibModalInstance.dismiss();
1331 $event.preventDefault();
1339 // ------------------------------------------------------------------
1341 var provider = egGridDataProvider.instance({});
1342 $scope.hold_grid_data_provider = provider;
1343 $scope.grid_actions = egHoldGridActions;
1344 $scope.grid_actions.refresh = function () { provider.refresh() };
1345 $scope.hold_grid_controls = {};
1347 var hold_ids = []; // current list of holds
1348 function fetchHolds(offset, count) {
1349 var ids = hold_ids.slice(offset, offset + count);
1350 return egHolds.fetch_holds(ids).then(null, null,
1351 function(hold_data) {
1357 provider.get = function(offset, count) {
1358 if ($scope.record_tab != 'holds') return $q.when();
1359 var deferred = $q.defer();
1360 hold_ids = []; // no caching ATM
1365 'open-ils.circ.holds.retrieve_all_from_title',
1366 egCore.auth.token(), $scope.record_id,
1367 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
1369 function(hold_data) {
1370 angular.forEach(hold_data, function(list, type) {
1371 hold_ids = hold_ids.concat(list);
1373 fetchHolds(offset, count).then(
1374 deferred.resolve, null, deferred.notify);
1378 return deferred.promise;
1381 $scope.detail_view = function(action, user_data, items) {
1383 $scope.detail_hold_id = h.hold.id();
1387 $scope.list_view = function(items) {
1388 $scope.detail_hold_id = null;
1391 // refresh the list of record holds when the pickup lib is changed.
1392 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1393 $scope.pickup_ou_changed = function(org) {
1394 $scope.pickup_ou = org;
1398 $scope.print_holds = function() {
1400 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1402 hold : egCore.idl.toHash(item.hold),
1403 patron_last : item.patron_last,
1404 patron_alias : item.patron_alias,
1405 patron_barcode : item.patron_barcode,
1406 copy : egCore.idl.toHash(item.copy),
1407 volume : egCore.idl.toHash(item.volume),
1408 title : item.mvr.title(),
1409 author : item.mvr.author()
1413 egCore.print.print({
1414 context : 'receipt',
1415 template : 'holds_for_bib',
1416 scope : {holds : holds}
1420 $scope.mark_hold_transfer_dest = function() {
1421 egCore.hatch.setLocalItem(
1422 'eg.circ.hold.title_transfer_target', $scope.record_id);
1423 ngToast.create(egCore.strings.HOLD_TRANSFER_DEST_MARKED);
1426 // UI presents this option as "all holds"
1427 $scope.transfer_holds_to_marked = function() {
1428 var hold_ids = $scope.hold_grid_controls.allItems().map(
1429 function(hold_data) {return hold_data.hold.id()});
1430 egHolds.transfer_to_marked_title(hold_ids);
1433 // ------------------------------------------------------------------
1434 // Initialize the selected tab
1436 function init_cat_url() {
1437 // Set the initial catalog URL. This only happens once.
1438 // The URL is otherwise generated through user navigation.
1439 if ($scope.catalog_url) return;
1441 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1443 // A record ID in the path indicates a request for the record-
1445 if ($routeParams.record_id) {
1446 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1449 // Jumping directly to the results page by passing a search
1450 // query via the URL. Copy all URL params to the iframe url.
1451 if ($location.path().match(/catalog\/results/)) {
1452 url = url.replace(/advanced/, '/results?');
1454 angular.forEach($location.search(), function(val, key) {
1455 if (!first) url += '&';
1457 url += encodeURIComponent(key)
1458 + '=' + encodeURIComponent(val);
1462 // if we're displaying the advanced search form, select
1463 // whatever default pane the user has chosen via workstation
1465 if (url.match(/\/opac\/advanced$/)) {
1466 var adv_pane = egCore.hatch.getLocalItem('eg.search.adv_pane');
1468 url += '?pane=' + encodeURIComponent(adv_pane);
1472 $scope.catalog_url = url;
1475 function init_parts_url() {
1476 $scope.parts_url = $location
1480 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1484 $scope.set_record_tab = function(tab) {
1485 $scope.record_tab = tab;
1498 $scope.detail_hold_record_id = $scope.record_id;
1499 // refresh the holds grid
1505 $scope.set_default_record_tab = function() {
1506 egCore.hatch.setLocalItem(
1507 'eg.cat.default_record_tab', $scope.record_tab);
1508 $timeout(function(){$scope.default_tab = $scope.record_tab});
1512 if ($scope.record_id) {
1513 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1514 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1517 tab = $routeParams.record_tab || 'catalog';
1519 $scope.set_record_tab(tab);
1523 .controller('AuthorityCtrl',
1524 ['$scope','$routeParams','$location','$window','$q','egCore',
1525 function($scope , $routeParams , $location , $window , $q , egCore) {
1527 // set record ID on page load if available...
1528 $scope.authority_id = $routeParams.authority_id;
1530 if ($routeParams.authority_id) $scope.from_route = true;
1531 else $scope.from_route = false;
1533 $scope.stop_unload = false;
1536 .controller('URLVerifyCtrl',
1537 ['$scope','$location',
1538 function($scope , $location) {
1539 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1542 .controller('VandelayCtrl',
1543 ['$scope','$location',
1544 function($scope , $location) {
1545 $scope.vandelay_url = $location.absUrl().replace(/\/staff\/cat\/catalog\/vandelay/, '/vandelay/vandelay');
1548 .controller('ManageAuthoritiesCtrl',
1549 ['$scope','$location',
1550 function($scope , $location) {
1551 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1554 .controller('BatchEditCtrl',
1555 ['$scope','$location','$routeParams',
1556 function($scope , $location , $routeParams) {
1557 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1558 if ($routeParams.container_type) {
1559 switch ($routeParams.container_type) {
1561 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1564 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1571 .filter('boolText', function(){
1572 return function (v) {
1577 .factory('conjoinedSvc',
1579 function(egCore , $q) {
1582 items : [], // record search results
1583 index : 0, // search grid index
1590 bpbcm : ['target_copy','peer_type'],
1591 acp : ['call_number'],
1593 bre : ['simple_record']
1595 // avoid fetching the MARC blob by specifying which
1596 // fields on the bre to select. More may be needed.
1597 // note that fleshed fields are explicitly selected.
1598 select : { bre : ['id'] },
1599 order_by : { bpbcm : ['id'] },
1602 // resolved with the last received copy
1603 service.fetch = function(rid) {
1604 if (!rid && !service.rid) return $q.when();
1606 if (rid) service.rid = rid;
1610 return egCore.pcrud.search(
1612 {peer_record : service.rid},
1615 ).then( function(list) { // finished
1616 service.items = list;
1617 return service.items;
1621 // returns a promise resolved with the list of peer bib types
1622 service.get_peer_types = function() {
1624 return $q.when(egCore.env.bpt.list);
1626 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
1627 .then(function(list) {
1628 egCore.env.absorbList(list, 'bpt');