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);
246 .controller('CatalogCtrl',
247 ['$scope','$routeParams','$location','$window','$q','egCore','egHolds','egCirc','egConfirmDialog','ngToast',
248 'egGridDataProvider','egHoldGridActions','egProgressDialog','$timeout','$uibModal','holdingsSvc','egUser','conjoinedSvc',
250 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc , egConfirmDialog , ngToast ,
251 egGridDataProvider , egHoldGridActions , egProgressDialog , $timeout , $uibModal , holdingsSvc , egUser , conjoinedSvc,
255 var holdingsSvcInst = new holdingsSvc();
257 // set record ID on page load if available...
258 $scope.record_id = $routeParams.record_id;
259 $scope.summary_pane_record;
261 if ($routeParams.record_id) $scope.from_route = true;
262 else $scope.from_route = false;
264 // set search and preferred library cookies
265 egCore.hatch.getItem('eg.search.search_lib').then(function(val) {
266 $cookies.put('eg_search_lib', val, { path : '/' });
268 egCore.hatch.getItem('eg.search.pref_lib').then(function(val) {
269 $cookies.put('eg_pref_lib', val, { path : '/' });
272 // will hold a ref to the opac iframe
273 $scope.opac_iframe = null;
274 $scope.parts_iframe = null;
276 $scope.search_result_index = 1;
277 $scope.search_result_hit_count = 1;
280 'opac_iframe.dom.contentWindow.search_result_index',
282 if (!isNaN(parseInt(n)))
283 $scope.search_result_index = n + 1;
288 'opac_iframe.dom.contentWindow.search_result_hit_count',
290 if (!isNaN(parseInt(n)))
291 $scope.search_result_hit_count = n;
295 $scope.in_opac_call = false;
296 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
297 if ($scope.opac_iframe) {
298 if (force_opac_tab) $scope.record_tab = 'catalog';
299 $scope.in_opac_call = true;
300 $scope.opac_iframe.dom.contentWindow[opac_frame_function]();
301 if (opac_frame_function == 'rdetailBackToResults') {
302 $location.update_path('/cat/catalog/index');
307 $scope.add_to_record_bucket = function() {
308 var recId = $scope.record_id;
309 return $uibModal.open({
310 templateUrl: './cat/catalog/t_add_to_bucket',
314 ['$scope','$uibModalInstance',
315 function($scope , $uibModalInstance) {
317 $scope.bucket_id = 0;
318 $scope.newBucketName = '';
319 $scope.allBuckets = [];
322 'open-ils.actor.container.retrieve_by_class.authoritative',
323 egCore.auth.token(), egCore.auth.user().id(),
324 'biblio', 'staff_client'
325 ).then(function(buckets) { $scope.allBuckets = buckets; });
327 $scope.add_to_bucket = function() {
328 var item = new egCore.idl.cbrebi();
329 item.bucket($scope.bucket_id);
330 item.target_biblio_record_entry(recId);
333 'open-ils.actor.container.item.create',
334 egCore.auth.token(), 'biblio', item
335 ).then(function(resp) {
336 $uibModalInstance.close();
340 $scope.add_to_new_bucket = function() {
341 var bucket = new egCore.idl.cbreb();
342 bucket.owner(egCore.auth.user().id());
343 bucket.name($scope.newBucketName);
344 bucket.description('');
345 bucket.btype('staff_client');
349 'open-ils.actor.container.create',
350 egCore.auth.token(), 'biblio', bucket
351 ).then(function(bucket) {
352 $scope.bucket_id = bucket;
353 $scope.add_to_bucket();
357 $scope.cancel = function() {
358 $uibModalInstance.dismiss();
364 $scope.current_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record');
365 $scope.current_voltransfer_target = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
366 $scope.current_conjoined_target = egCore.hatch.getLocalItem('eg.cat.marked_conjoined_record');
368 $scope.markConjoined = function () {
369 $scope.current_conjoined_target = $scope.record_id;
370 egCore.hatch.setLocalItem('eg.cat.marked_conjoined_record',$scope.record_id);
371 ngToast.create(egCore.strings.MARK_CONJ_TARGET);
374 $scope.markVolTransfer = function () {
375 ngToast.create(egCore.strings.MARK_VOL_TARGET);
376 $scope.current_voltransfer_target = $scope.record_id;
377 egCore.hatch.setLocalItem('eg.cat.marked_volume_transfer_record',$scope.record_id);
380 $scope.markOverlay = function () {
381 $scope.current_overlay_target = $scope.record_id;
382 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.record_id);
383 ngToast.create(egCore.strings.MARK_OVERLAY_TARGET);
386 $scope.clearRecordMarks = function () {
387 $scope.current_overlay_target = null;
388 $scope.current_voltransfer_target = null;
389 $scope.current_conjoined_target = null;
390 egCore.hatch.removeLocalItem('eg.cat.marked_volume_transfer_record');
391 egCore.hatch.removeLocalItem('eg.cat.marked_conjoined_record');
392 egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');
395 $scope.stop_unload = false;
396 $scope.$watch('stop_unload',
397 function(newVal, oldVal) {
398 if (newVal && newVal != oldVal && $scope.opac_iframe) {
399 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
400 return 'There is unsaved data in this record.'
403 if ($scope.opac_iframe)
404 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
409 // Set the "last bib" cookie, if we have that
410 if ($scope.record_id)
411 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
413 $scope.refresh_record_callback = function (record_id) {
414 egCore.pcrud.retrieve('bre', record_id, {
417 bre : ['simple_record','creator','editor']
419 }).then(function(rec) {
420 rec.owner(egCore.org.get(rec.owner()));
421 $scope.summary_pane_record = rec;
427 // also set it when the iframe changes to a new record
428 $scope.handle_page = function(url) {
430 if (!url || url == 'about:blank') {
431 // nothing loaded. If we already have a record ID, leave it.
435 var match = url.match(/\/+opac\/+record\/+(\d+)/);
437 $scope.record_id = match[1];
438 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
439 $scope.holdings_record_id_changed($scope.record_id);
440 conjoinedSvc.fetch($scope.record_id).then(function(){
441 $scope.conjoinedGridDataProvider.refresh();
444 $location.update_path('/cat/catalog/record/' + $scope.record_id);
446 delete $scope.record_id;
447 $scope.from_route = false;
450 // child scope is executing this function, so our digest doesn't fire ... thus,
453 if (!$scope.in_opac_call) {
454 if ($scope.record_id) {
455 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
456 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
458 tab = $routeParams.record_tab || 'catalog';
460 $scope.set_record_tab(tab);
462 $scope.in_opac_call = false;
466 // xulG catalog handlers
467 $scope.handlers = { }
469 // ------------------------------------------------------------------
472 $scope.conjoinedGridControls = {};
473 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
474 get : function(offset, count) {
475 return this.arrayNotifier(conjoinedSvc.items, offset, count);
479 $scope.changeConjoinedType = function () {
480 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
481 angular.forEach(peers, function (p) {
482 p.target_copy(p.target_copy().id());
483 p.peer_type(p.peer_type().id());
486 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
488 return $uibModal.open({
489 templateUrl: './cat/catalog/t_conjoined_selector',
492 ['$scope','$uibModalInstance',
493 function($scope , $uibModalInstance) {
494 $scope.update = true;
496 $scope.peer_type = null;
497 $scope.peer_type_list = [];
498 conjoinedSvc.get_peer_types().then(function(list){
499 $scope.peer_type_list = list;
502 $scope.ok = function(type) {
505 angular.forEach(peers, function (p) {
508 promises.push(egCore.pcrud.update(p));
511 return $q.all(promises)
512 .then(function(){$uibModalInstance.close()})
513 .then(function(){return conjoinedSvc.fetch()})
514 .then(function(){conjoinedGridDataProviderRef.refresh()});
517 $scope.cancel = function($event) {
518 $uibModalInstance.dismiss();
519 $event.preventDefault();
526 $scope.refreshConjoined = function () {
527 conjoinedSvc.fetch($scope.record_id)
528 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
531 $scope.deleteSelectedConjoined = function () {
532 var peers = $scope.conjoinedGridControls.selectedItems();
534 if (peers.length > 0) {
535 egConfirmDialog.open(
536 egCore.strings.CONFIRM_DELETE_PEERS,
537 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
538 {peers : peers.length}
539 ).result.then(function() {
540 angular.forEach(peers, function (p) {
544 egCore.pcrud.remove(peers).then(function() {
545 return conjoinedSvc.fetch();
547 $scope.conjoinedGridDataProvider.refresh();
552 if ($scope.record_id)
553 conjoinedSvc.fetch($scope.record_id);
555 // ------------------------------------------------------------------
558 $scope.holdingsGridControls = {
559 activateItem : function (item) {
560 $scope.selectedHoldingsVolCopyEdit();
563 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
564 get : function(offset, count) {
565 return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
569 $scope.add_copies_to_bucket = function() {
570 var copy_list = gatherSelectedHoldingsIds();
571 if (copy_list.length == 0) return;
573 return $uibModal.open({
574 templateUrl: './cat/catalog/t_add_to_bucket',
578 ['$scope','$uibModalInstance',
579 function($scope , $uibModalInstance) {
581 $scope.bucket_id = 0;
582 $scope.newBucketName = '';
583 $scope.allBuckets = [];
587 'open-ils.actor.container.retrieve_by_class.authoritative',
588 egCore.auth.token(), egCore.auth.user().id(),
589 'copy', 'staff_client'
590 ).then(function(buckets) { $scope.allBuckets = buckets; });
592 $scope.add_to_bucket = function() {
594 angular.forEach(copy_list, function (cp) {
595 var item = new egCore.idl.ccbi()
596 item.bucket($scope.bucket_id);
597 item.target_copy(cp);
601 'open-ils.actor.container.item.create',
602 egCore.auth.token(), 'copy', item
606 return $q.all(promises).then(function() {
607 $uibModalInstance.close();
612 $scope.add_to_new_bucket = function() {
613 var bucket = new egCore.idl.ccb();
614 bucket.owner(egCore.auth.user().id());
615 bucket.name($scope.newBucketName);
616 bucket.description('');
617 bucket.btype('staff_client');
619 return egCore.net.request(
621 'open-ils.actor.container.create',
622 egCore.auth.token(), 'copy', bucket
623 ).then(function(bucket) {
624 $scope.bucket_id = bucket;
625 $scope.add_to_bucket();
629 $scope.cancel = function() {
630 $uibModalInstance.dismiss();
636 $scope.requestItems = function() {
637 var copy_list = gatherSelectedHoldingsIds();
638 if (copy_list.length == 0) return;
640 return $uibModal.open({
641 templateUrl: './cat/catalog/t_request_items',
644 ['$scope','$uibModalInstance',
645 function($scope , $uibModalInstance) {
647 $scope.first_user_fetch = true;
651 copy_list : copy_list,
652 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
653 user : egCore.auth.user().id()
656 egUser.get( $scope.hold_data.user ).then(function(u) {
658 $scope.barcode = u.card().barcode();
659 $scope.user_name = egUser.format_name(u);
660 $scope.hold_data.user = u.id();
663 $scope.user_name = '';
665 $scope.$watch('barcode', function (n) {
666 if (!$scope.first_user_fetch) {
667 egUser.getByBarcode(n).then(function(u) {
669 $scope.user_name = egUser.format_name(u);
670 $scope.hold_data.user = u.id();
673 $scope.user_name = '';
674 delete $scope.hold_data.user;
677 $scope.first_user_fetch = false;
680 $scope.ok = function(h) {
683 hold_type : h.hold_type,
684 pickup_lib: h.pickup_lib.id(),
690 'open-ils.circ.holds.test_and_create.batch.override',
691 egCore.auth.token(), args, h.copy_list
694 $uibModalInstance.close();
697 $scope.cancel = function($event) {
698 $uibModalInstance.dismiss();
699 $event.preventDefault();
705 $scope.view_place_orders = function() {
706 if (!$scope.record_id) return;
707 var url = egCore.env.basePath + 'acq/legacy/lineitem/related/' + $scope.record_id + '?target=bib';
708 $timeout(function() { $window.open(url, '_blank') });
711 $scope.replaceBarcodes = function() {
712 var copy_list = gatherSelectedRawCopies();
713 if (copy_list.length == 0) return;
715 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
717 angular.forEach(copy_list, function (cp) {
719 templateUrl: './cat/share/t_replace_barcode',
722 ['$scope','$uibModalInstance',
723 function($scope , $uibModalInstance) {
724 $scope.isModal = true;
725 $scope.focusBarcode = false;
726 $scope.focusBarcode2 = true;
727 $scope.barcode1 = cp.barcode();
729 $scope.updateBarcode = function() {
730 $scope.copyNotFound = false;
731 $scope.updateOK = false;
733 egCore.pcrud.search('acp',
734 {deleted : 'f', barcode : $scope.barcode1})
735 .then(function(copy) {
738 $scope.focusBarcode = true;
739 $scope.copyNotFound = true;
743 $scope.copyId = copy.id();
744 copy.barcode($scope.barcode2);
746 egCore.pcrud.update(copy).then(function(stat) {
747 $scope.updateOK = stat;
748 $scope.focusBarcode = true;
749 holdingsSvc.fetchAgain().then(function (){
750 holdingsGridDataProviderRef.refresh();
755 $uibModalInstance.close();
758 $scope.cancel = function($event) {
759 $uibModalInstance.dismiss();
760 $event.preventDefault();
768 // refresh the list of holdings when the record_id is changed.
769 $scope.holdings_record_id_changed = function(id) {
770 if ($scope.record_id != id) $scope.record_id = id;
771 console.log('record id changed to ' + id + ', loading new holdings');
772 holdingsSvcInst.fetch({
773 rid : $scope.record_id,
774 org : $scope.holdings_ou,
775 copy: $scope.holdings_show_copies,
776 vol : $scope.holdings_show_vols,
777 empty: $scope.holdings_show_empty
779 $scope.holdingsGridDataProvider.refresh();
783 // refresh the list of holdings when the filter lib is changed.
784 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
785 $scope.holdings_ou_changed = function(org) {
786 $scope.holdings_ou = org;
787 holdingsSvcInst.fetch({
788 rid : $scope.record_id,
789 org : $scope.holdings_ou,
790 copy: $scope.holdings_show_copies,
791 vol : $scope.holdings_show_vols,
792 empty: $scope.holdings_show_empty
794 $scope.holdingsGridDataProvider.refresh();
798 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
800 egCore.hatch.setItem('cat.' + cb, newVal);
801 if (!norefresh) holdingsSvcInst.fetch({
802 rid : $scope.record_id,
803 org : $scope.holdings_ou,
804 copy: $scope.holdings_show_copies,
805 vol : $scope.holdings_show_vols,
806 empty: $scope.holdings_show_empty
808 $scope.holdingsGridDataProvider.refresh();
812 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
813 if (typeof x == 'undefined') x = true;
814 $scope.holdings_cb_changed('holdings_show_vols',x,true);
815 $('#holdings_show_vols').prop('checked', x);
817 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
818 if (typeof x == 'undefined') x = true;
819 $scope.holdings_cb_changed('holdings_show_copies',x,true);
820 $('#holdings_show_copies').prop('checked', x);
822 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
823 if (typeof x == 'undefined') x = true;
824 $scope.holdings_cb_changed('holdings_show_empty',x);
825 $('#holdings_show_empty').prop('checked', x);
830 $scope.vols_not_shown = function () {
831 return !$scope.holdings_show_vols;
834 $scope.copies_not_shown = function () {
835 return !$scope.holdings_show_copies;
838 $scope.holdings_checkbox_handler = function (item) {
839 $scope.holdings_cb_changed(item.checkbox,item.checked);
842 function gatherSelectedHoldingsIds () {
845 $scope.holdingsGridControls.selectedItems(),
846 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
851 function gatherSelectedRawCopies () {
854 $scope.holdingsGridControls.selectedItems(),
855 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
860 function gatherSelectedEmptyVolumeIds () {
863 $scope.holdingsGridControls.selectedItems(),
865 if (item.copy_count == 0)
866 cn_id_list.push(item.call_number.id)
872 function gatherSelectedVolumeIds () {
875 $scope.holdingsGridControls.selectedItems(),
877 if (cn_id_list.indexOf(item.call_number.id) == -1)
878 cn_id_list.push(item.call_number.id)
884 $scope.selectedHoldingsDelete = function (vols, copies) {
887 var perCnCopies = {};
893 $scope.holdingsGridControls.selectedItems(),
895 if (vols && item.raw_call_number) {
896 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
897 cnHash[item.call_number.id].isdeleted(1);
900 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
903 var cn_id = cp.call_number().id();
904 if (!cnHash[cn_id]) {
905 cnHash[cn_id] = cp.call_number();
906 perCnCopies[cn_id] = [cp];
908 perCnCopies[cn_id].push(cp);
910 cp.call_number(cn_id); // prevent loops in JSON-ification
917 angular.forEach(perCnCopies, function (v, k) {
919 cnHash[k].isdeleted(1);
926 angular.forEach(cnHash, function (v, k) {
930 if (cnList.length == 0) return;
933 if (vols && copies) flags.force_delete_copies = 1;
935 egConfirmDialog.open(
936 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
937 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
938 {copies : cp_count, volumes : cn_count}
939 ).result.then(function() {
942 'open-ils.cat.asset.volume.fleshed.batch.update.override',
943 egCore.auth.token(), cnList, 1, flags
944 ).then(function(update_count) {
945 holdingsSvcInst.fetchAgain().then(function() {
946 $scope.holdingsGridDataProvider.refresh();
951 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
952 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
953 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
955 spawnHoldingsAdd = function (vols,copies){
957 if (copies) { // just a copy on existing volumes
958 angular.forEach(gatherSelectedVolumeIds(), function (v) {
959 raw.push( {callnumber : v} );
962 if (typeof $scope.holdingsGridControls.selectedItems == "function" &&
963 $scope.holdingsGridControls.selectedItems().length > 0) {
964 angular.forEach($scope.holdingsGridControls.selectedItems(),
967 owner : item.owner_id,
968 label : item.call_number.label
973 owner : egCore.auth.user().ws_ou()
978 if (raw.length == 0) raw.push({});
982 'open-ils.actor.anon_cache.set_value',
983 null, 'edit-these-copies', {
984 record_id: $scope.record_id,
989 ).then(function(key) {
991 var url = egCore.env.basePath + 'cat/volcopy/' + key;
992 $timeout(function() { $window.open(url, '_blank') });
994 alert('Could not create anonymous cache key!');
998 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
999 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
1001 spawnHoldingsEdit = function (hide_vols,hide_copies){
1004 'open-ils.actor.anon_cache.set_value',
1005 null, 'edit-these-copies', {
1006 record_id: $scope.record_id,
1007 copies: gatherSelectedHoldingsIds(),
1008 raw: gatherSelectedEmptyVolumeIds().map(
1009 function(v){ return { callnumber : v } }
1011 hide_vols : hide_vols,
1012 hide_copies : hide_copies
1014 ).then(function(key) {
1016 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1017 $timeout(function() { $window.open(url, '_blank') });
1019 alert('Could not create anonymous cache key!');
1023 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
1024 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
1025 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
1027 $scope.selectedHoldingsItemStatus = function (){
1028 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
1029 $timeout(function() { $window.open(url, '_blank') });
1032 $scope.markVolAsItemTarget = function() {
1033 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
1034 egCore.hatch.setLocalItem(
1035 'eg.cat.item_transfer_target',
1036 $scope.holdingsGridControls.selectedItems()[0].call_number.id
1038 ngToast.create(egCore.strings.MARK_ITEM_TARGET);
1042 $scope.markLibAsVolTarget = function() {
1043 return $uibModal.open({
1044 templateUrl: './cat/catalog/t_choose_vol_target_lib',
1047 ['$scope','$uibModalInstance',
1048 function($scope , $uibModalInstance) {
1050 var orgId = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target') || 1;
1051 $scope.org = egCore.org.get(orgId);
1052 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1053 $scope.ok = function(org) {
1054 egCore.hatch.setLocalItem(
1055 'eg.cat.volume_transfer_target',
1058 $uibModalInstance.close();
1060 $scope.cancel = function($event) {
1061 $uibModalInstance.dismiss();
1062 $event.preventDefault();
1067 $scope.markLibFromSelectedAsVolTarget = function() {
1068 egCore.hatch.setLocalItem(
1069 'eg.cat.volume_transfer_target',
1070 $scope.holdingsGridControls.selectedItems()[0].owner_id
1072 ngToast.create(egCore.strings.MARK_VOL_TARGET);
1075 $scope.selectedHoldingsItemStatusDetail = function (){
1077 gatherSelectedHoldingsIds(),
1079 var url = egCore.env.basePath +
1081 $timeout(function() { $window.open(url, '_blank') });
1086 $scope.transferVolumesToRecord = function (){
1087 var target_record = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
1088 if (!target_record) return;
1089 if ($scope.record_id == target_record) return;
1090 var items = $scope.holdingsGridControls.selectedItems();
1091 if (!items.length) return;
1093 var vols_to_move = {};
1094 angular.forEach(items, function(item) {
1095 if (!(item.call_number.owning_lib in vols_to_move)) {
1096 vols_to_move[item.call_number.owning_lib] = new Array;
1098 vols_to_move[item.call_number.owning_lib].push(item.call_number.id);
1102 angular.forEach(vols_to_move, function(vols, owning_lib) {
1103 promises.push(egCore.net.request(
1105 'open-ils.cat.asset.volume.batch.transfer.override',
1106 egCore.auth.token(), {
1107 docid : target_record,
1113 $q.all(promises).then(function(success) {
1115 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1116 holdingsSvcInst.fetchAgain().then(function() {
1117 $scope.holdingsGridDataProvider.refresh();
1120 alert('Could not transfer volumes!');
1125 function transferVolumes(new_record){
1126 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
1131 'open-ils.cat.asset.volume.batch.transfer.override',
1132 egCore.auth.token(), {
1133 docid : (new_record ? new_record : $scope.record_id),
1135 volumes : gatherSelectedVolumeIds()
1137 ).then(function(success) {
1139 ngToast.create(egCore.strings.VOLS_TRANSFERED);
1140 holdingsSvcInst.fetchAgain().then(function() {
1141 $scope.holdingsGridDataProvider.refresh();
1144 alert('Could not transfer volumes!');
1151 $scope.transferVolumesToLibrary = function() {
1155 $scope.transferVolumesToRecordAndLibrary = function() {
1156 var target_record = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
1157 if (!target_record) return;
1158 transferVolumes(target_record);
1161 // this "transfers" selected copies to a new owning library,
1162 // auto-creating volumes and deleting unused volumes as required.
1163 $scope.changeItemOwningLib = function() {
1164 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
1165 var items = $scope.holdingsGridControls.selectedItems();
1166 if (!xfer_target || !items.length) {
1169 var vols_to_move = {};
1170 var copies_to_move = {};
1171 angular.forEach(items, function(item) {
1172 if (item.call_number.owning_lib != xfer_target) {
1173 if (item.call_number.id in vols_to_move) {
1174 copies_to_move[item.call_number.id].push(item.id);
1176 vols_to_move[item.call_number.id] = item.call_number;
1177 copies_to_move[item.call_number.id] = new Array;
1178 copies_to_move[item.call_number.id].push(item.id);
1184 angular.forEach(vols_to_move, function(vol) {
1185 promises.push(egCore.net.request(
1187 'open-ils.cat.call_number.find_or_create',
1188 egCore.auth.token(),
1195 ).then(function(resp) {
1196 var evt = egCore.evt.parse(resp);
1198 return egCore.net.request(
1200 'open-ils.cat.transfer_copies_to_volume',
1201 egCore.auth.token(),
1203 copies_to_move[vol.id]
1207 $q.all(promises).then(function() {
1208 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1209 holdingsSvcInst.fetchAgain().then(function() {
1210 $scope.holdingsGridDataProvider.refresh();
1215 $scope.transferItems = function (){
1216 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
1217 var copy_ids = gatherSelectedHoldingsIds();
1218 if (xfer_target && copy_ids.length > 0) {
1221 'open-ils.cat.transfer_copies_to_volume',
1222 egCore.auth.token(),
1226 function(resp) { // oncomplete
1227 var evt = egCore.evt.parse(resp);
1229 egConfirmDialog.open(
1230 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1231 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1232 {'evt_desc': evt.desc}
1233 ).result.then(function() {
1236 'open-ils.cat.transfer_copies_to_volume.override',
1237 egCore.auth.token(),
1240 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1241 ).then(function(resp) {
1242 holdingsSvcInst.fetchAgain().then(function() {
1243 $scope.holdingsGridDataProvider.refresh();
1248 ngToast.create(egCore.strings.ITEMS_TRANSFERED);
1249 holdingsSvcInst.fetchAgain().then(function() {
1250 $scope.holdingsGridDataProvider.refresh();
1260 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1262 gatherSelectedHoldingsIds(),
1264 var url = egCore.env.basePath +
1265 'cat/item/' + cid + '/triggered_events';
1266 $timeout(function() { $window.open(url, '_blank') });
1271 $scope.selectedHoldingsItemStatusHolds = function (){
1273 gatherSelectedHoldingsIds(),
1275 var url = egCore.env.basePath +
1276 'cat/item/' + cid + '/holds';
1277 $timeout(function() { $window.open(url, '_blank') });
1282 $scope.selectedHoldingsDamaged = function () {
1283 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
1284 holdingsSvcInst.fetchAgain().then(function() {
1285 $scope.holdingsGridDataProvider.refresh();
1290 $scope.selectedHoldingsMissing = function () {
1291 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1292 holdingsSvcInst.fetchAgain().then(function() {
1293 $scope.holdingsGridDataProvider.refresh();
1298 $scope.attach_to_peer_bib = function() {
1299 var copy_list = gatherSelectedHoldingsIds();
1300 if (copy_list.length == 0) return;
1302 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1303 if (!target_record) return;
1305 return $uibModal.open({
1306 templateUrl: './cat/catalog/t_conjoined_selector',
1309 ['$scope','$uibModalInstance',
1310 function($scope , $uibModalInstance) {
1311 $scope.update = false;
1313 $scope.peer_type = null;
1314 $scope.peer_type_list = [];
1315 conjoinedSvc.get_peer_types().then(function(list){
1316 $scope.peer_type_list = list;
1319 $scope.ok = function(type) {
1322 angular.forEach(copy_list, function (cp) {
1323 var n = new egCore.idl.bpbcm();
1325 n.peer_record(target_record);
1328 promises.push(egCore.pcrud.create(n));
1331 return $q.all(promises).then(function(){$uibModalInstance.close()});
1334 $scope.cancel = function($event) {
1335 $uibModalInstance.dismiss();
1336 $event.preventDefault();
1344 // ------------------------------------------------------------------
1346 var provider = egGridDataProvider.instance({});
1347 $scope.hold_grid_data_provider = provider;
1348 $scope.grid_actions = egHoldGridActions;
1349 $scope.grid_actions.refresh = function () { provider.refresh() };
1350 $scope.hold_grid_controls = {};
1352 var hold_ids = []; // current list of holds
1353 function fetchHolds(offset, count) {
1354 var ids = hold_ids.slice(offset, offset + count);
1356 return egHolds.fetch_holds(ids).then(null, null,
1357 function(hold_data) {
1363 provider.get = function(offset, count) {
1364 if ($scope.record_tab != 'holds') return $q.when();
1365 var deferred = $q.defer();
1366 hold_ids = []; // no caching ATM
1368 // open a determinate progress dialog, max value set below.
1369 egProgressDialog.open({max : 1, value : 0});
1374 'open-ils.circ.holds.retrieve_all_from_title',
1375 egCore.auth.token(), $scope.record_id,
1376 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
1378 function(hold_data) {
1379 angular.forEach(hold_data, function(list, type) {
1380 hold_ids = hold_ids.concat(list);
1383 // Set the max value of the progress bar to the lesser of
1384 // the total number of holds to fetch or the page size
1386 egProgressDialog.update(
1387 {max : Math.min(hold_ids.length, count)});
1389 var holds_fetched = 0;
1390 fetchHolds(offset, count)
1391 .then(deferred.resolve, null,
1392 function(hold_data) {
1394 deferred.notify(hold_data);
1395 egProgressDialog.increment();
1397 )['finally'](egProgressDialog.close);
1401 return deferred.promise;
1404 $scope.detail_view = function(action, user_data, items) {
1406 $scope.detail_hold_id = h.hold.id();
1410 $scope.list_view = function(items) {
1411 $scope.detail_hold_id = null;
1414 // refresh the list of record holds when the pickup lib is changed.
1415 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1416 $scope.pickup_ou_changed = function(org) {
1417 $scope.pickup_ou = org;
1421 $scope.print_holds = function() {
1423 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1425 hold : egCore.idl.toHash(item.hold),
1426 patron_last : item.patron_last,
1427 patron_alias : item.patron_alias,
1428 patron_barcode : item.patron_barcode,
1429 copy : egCore.idl.toHash(item.copy),
1430 volume : egCore.idl.toHash(item.volume),
1431 title : item.mvr.title(),
1432 author : item.mvr.author()
1436 egCore.print.print({
1437 context : 'receipt',
1438 template : 'holds_for_bib',
1439 scope : {holds : holds}
1443 $scope.mark_hold_transfer_dest = function() {
1444 egCore.hatch.setLocalItem(
1445 'eg.circ.hold.title_transfer_target', $scope.record_id);
1446 ngToast.create(egCore.strings.HOLD_TRANSFER_DEST_MARKED);
1449 // UI presents this option as "all holds"
1450 $scope.transfer_holds_to_marked = function() {
1451 var hold_ids = $scope.hold_grid_controls.allItems().map(
1452 function(hold_data) {return hold_data.hold.id()});
1453 egHolds.transfer_to_marked_title(hold_ids);
1456 // ------------------------------------------------------------------
1457 // Initialize the selected tab
1459 function init_cat_url() {
1460 // Set the initial catalog URL. This only happens once.
1461 // The URL is otherwise generated through user navigation.
1462 if ($scope.catalog_url) return;
1464 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1466 // A record ID in the path indicates a request for the record-
1468 if ($routeParams.record_id) {
1469 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1472 // Jumping directly to the results page by passing a search
1473 // query via the URL. Copy all URL params to the iframe url.
1474 if ($location.path().match(/catalog\/results/)) {
1475 url = url.replace(/advanced/, '/results?');
1477 angular.forEach($location.search(), function(val, key) {
1478 if (!first) url += '&';
1480 url += encodeURIComponent(key)
1481 + '=' + encodeURIComponent(val);
1485 // if we're displaying the advanced search form, select
1486 // whatever default pane the user has chosen via workstation
1488 if (url.match(/\/opac\/advanced$/)) {
1489 var adv_pane = egCore.hatch.getLocalItem('eg.search.adv_pane');
1491 url += '?pane=' + encodeURIComponent(adv_pane);
1495 $scope.catalog_url = url;
1498 function init_parts_url() {
1499 $scope.parts_url = $location
1503 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1507 $scope.set_record_tab = function(tab) {
1508 $scope.record_tab = tab;
1521 $scope.detail_hold_record_id = $scope.record_id;
1522 // refresh the holds grid
1529 $scope.set_default_record_tab = function() {
1530 egCore.hatch.setLocalItem(
1531 'eg.cat.default_record_tab', $scope.record_tab);
1532 $timeout(function(){$scope.default_tab = $scope.record_tab});
1536 if ($scope.record_id) {
1537 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1538 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1541 tab = $routeParams.record_tab || 'catalog';
1543 $scope.set_record_tab(tab);
1547 .controller('AuthorityCtrl',
1548 ['$scope','$routeParams','$location','$window','$q','egCore',
1549 function($scope , $routeParams , $location , $window , $q , egCore) {
1551 // set record ID on page load if available...
1552 $scope.authority_id = $routeParams.authority_id;
1554 if ($routeParams.authority_id) $scope.from_route = true;
1555 else $scope.from_route = false;
1557 $scope.stop_unload = false;
1560 .controller('URLVerifyCtrl',
1561 ['$scope','$location',
1562 function($scope , $location) {
1563 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1566 .controller('VandelayCtrl',
1567 ['$scope','$location',
1568 function($scope , $location) {
1569 $scope.vandelay_url = $location.absUrl().replace(/\/staff\/cat\/catalog\/vandelay/, '/vandelay/vandelay');
1572 .controller('ManageAuthoritiesCtrl',
1573 ['$scope','$location',
1574 function($scope , $location) {
1575 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1578 .controller('BatchEditCtrl',
1579 ['$scope','$location','$routeParams',
1580 function($scope , $location , $routeParams) {
1581 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1582 if ($routeParams.container_type) {
1583 switch ($routeParams.container_type) {
1585 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1588 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1595 .filter('boolText', function(){
1596 return function (v) {
1601 .factory('conjoinedSvc',
1603 function(egCore , $q) {
1606 items : [], // record search results
1607 index : 0, // search grid index
1614 bpbcm : ['target_copy','peer_type'],
1615 acp : ['call_number'],
1617 bre : ['simple_record']
1619 // avoid fetching the MARC blob by specifying which
1620 // fields on the bre to select. More may be needed.
1621 // note that fleshed fields are explicitly selected.
1622 select : { bre : ['id'] },
1623 order_by : { bpbcm : ['id'] },
1626 // resolved with the last received copy
1627 service.fetch = function(rid) {
1628 if (!rid && !service.rid) return $q.when();
1630 if (rid) service.rid = rid;
1634 return egCore.pcrud.search(
1636 {peer_record : service.rid},
1639 ).then( function(list) { // finished
1640 service.items = list;
1641 return service.items;
1645 // returns a promise resolved with the list of peer bib types
1646 service.get_peer_types = function() {
1648 return $q.when(egCore.env.bpt.list);
1650 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
1651 .then(function(list) {
1652 egCore.env.absorbList(list, 'bpt');