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'])
12 .config(function($routeProvider, $locationProvider, $compileProvider) {
13 $locationProvider.html5Mode(true);
14 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
16 var resolver = {delay : ['egCore','egStartup','egUser', function(egCore, egStartup, egUser) {
17 egCore.env.classLoaders.aous = function() {
18 return egCore.org.settings([
19 'cat.marc_control_number_identifier'
20 ]).then(function(settings) {
21 // local settings are cached within egOrg. Caching them
22 // again in egEnv just simplifies the syntax for access.
23 egCore.env.aous = settings;
26 egCore.env.loadClasses.push('aous');
30 $routeProvider.when('/cat/catalog/index', {
31 templateUrl: './cat/catalog/t_catalog',
32 controller: 'CatalogCtrl',
36 $routeProvider.when('/cat/catalog/retrieve_by_id', {
37 templateUrl: './cat/catalog/t_retrieve_by_id',
38 controller: 'CatalogRecordRetrieve',
42 $routeProvider.when('/cat/catalog/retrieve_by_tcn', {
43 templateUrl: './cat/catalog/t_retrieve_by_tcn',
44 controller: 'CatalogRecordRetrieve',
48 $routeProvider.when('/cat/catalog/new_bib', {
49 templateUrl: './cat/catalog/t_new_bib',
50 controller: 'NewBibCtrl',
54 // create some catalog page-specific mappings
55 $routeProvider.when('/cat/catalog/record/:record_id', {
56 templateUrl: './cat/catalog/t_catalog',
57 controller: 'CatalogCtrl',
61 // create some catalog page-specific mappings
62 $routeProvider.when('/cat/catalog/record/:record_id/:record_tab', {
63 templateUrl: './cat/catalog/t_catalog',
64 controller: 'CatalogCtrl',
68 $routeProvider.when('/cat/catalog/batchEdit', {
69 templateUrl: './cat/catalog/t_batchedit',
70 controller: 'BatchEditCtrl',
74 $routeProvider.when('/cat/catalog/batchEdit/:container_type/:container_id', {
75 templateUrl: './cat/catalog/t_batchedit',
76 controller: 'BatchEditCtrl',
80 $routeProvider.when('/cat/catalog/vandelay', {
81 templateUrl: './cat/catalog/t_vandelay',
82 controller: 'VandelayCtrl',
86 $routeProvider.when('/cat/catalog/verifyURLs', {
87 templateUrl: './cat/catalog/t_verifyurls',
88 controller: 'URLVerifyCtrl',
92 $routeProvider.when('/cat/catalog/manageAuthorities', {
93 templateUrl: './cat/catalog/t_manageauthorities',
94 controller: 'ManageAuthoritiesCtrl',
98 $routeProvider.when('/cat/catalog/authority/:authority_id/marc_edit', {
99 templateUrl: './cat/catalog/t_authority',
100 controller: 'AuthorityCtrl',
104 $routeProvider.otherwise({redirectTo : '/cat/catalog/index'});
110 .controller('CatalogRecordRetrieve',
111 ['$scope','$routeParams','$location','$q','egCore',
112 function($scope , $routeParams , $location , $q , egCore ) {
114 $scope.focusMe = true;
116 // jump to the patron checkout UI
117 function loadRecord(record_id) {
119 .path('/cat/catalog/record/' + record_id);
122 $scope.submitId = function(args) {
123 $scope.recordNotFound = null;
124 if (!args.record_id) return;
126 // blur so next time it's set to true it will re-apply select()
127 $scope.selectMe = false;
129 return loadRecord(args.record_id);
132 $scope.submitTCN = function(args) {
133 $scope.recordNotFound = null;
134 $scope.moreRecordsFound = null;
135 if (!args.record_tcn) return;
137 // blur so next time it's set to true it will re-apply select()
138 $scope.selectMe = false;
143 'open-ils.search.biblio.tcn',
146 .then(function(resp) { // get_barcodes
148 if (evt = egCore.evt.parse(resp)) {
154 $scope.recordNotFound = args.record_tcn;
155 $scope.selectMe = true;
159 if (resp.count > 1) {
160 $scope.moreRecordsFound = args.record_tcn;
161 $scope.selectMe = true;
165 var record_id = resp.ids[0];
166 return loadRecord(record_id);
172 .controller('NewBibCtrl',
173 ['$scope','$routeParams','$location','$window','$q','egCore',
174 'egGridDataProvider','egHoldGridActions','$timeout','holdingsSvc',
175 function($scope , $routeParams , $location , $window , $q , egCore) {
177 $scope.have_template = false;
178 $scope.marc_template = '';
179 $scope.stop_unload = false;
180 $scope.template_list = [];
181 $scope.template_name = '';
182 $scope.new_bib_id = 0;
186 'open-ils.cat.marc_template.types.retrieve'
187 ).then(function(resp) {
188 angular.forEach(resp, function(name) {
189 $scope.template_list.push(name);
191 $scope.template_list.sort();
193 $scope.template_name = egCore.hatch.getSessionItem('eg.cat.last_bib_marc_template');
194 if (!$scope.template_name) {
195 egCore.hatch.getItem('cat.default_bib_marc_template').then(function(template) {
196 $scope.template_name = template;
200 $scope.loadTemplate = function() {
201 if ($scope.template_name) {
204 'open-ils.cat.biblio.marc_template.retrieve',
206 ).then(function(template) {
207 $scope.marc_template = template;
208 $scope.have_template = true;
209 egCore.hatch.setSessionItem('eg.cat.last_bib_marc_template', $scope.template_name);
214 $scope.setDefaultTemplate = function() {
215 var hatch_key = "cat.default_bib_marc_template";
216 if ($scope.template_name) {
217 egCore.hatch.setItem(hatch_key, $scope.template_name);
219 egCore.hatch.removeItem(hatch_key);
223 $scope.$watch('new_bib_id', function(newVal, oldVal) {
225 $location.path('/cat/catalog/record/' + $scope.new_bib_id);
232 .controller('CatalogCtrl',
233 ['$scope','$routeParams','$location','$window','$q','egCore','egHolds','egCirc','egConfirmDialog',
234 'egGridDataProvider','egHoldGridActions','$timeout','$modal','holdingsSvc','egUser','conjoinedSvc',
235 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc, egConfirmDialog,
236 egGridDataProvider , egHoldGridActions , $timeout , $modal , holdingsSvc , egUser , conjoinedSvc) {
238 var holdingsSvcInst = new holdingsSvc();
240 // set record ID on page load if available...
241 $scope.record_id = $routeParams.record_id;
242 $scope.summary_pane_record;
244 if ($routeParams.record_id) $scope.from_route = true;
245 else $scope.from_route = false;
247 // will hold a ref to the opac iframe
248 $scope.opac_iframe = null;
249 $scope.parts_iframe = null;
251 $scope.in_opac_call = false;
252 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
253 if ($scope.opac_iframe) {
254 if (force_opac_tab) $scope.record_tab = 'catalog';
255 $scope.in_opac_call = true;
256 $scope.opac_iframe.dom.contentWindow[opac_frame_function]();
257 if (opac_frame_function == 'rdetailBackToResults') {
258 $location.update_path('/cat/catalog/index');
263 $scope.add_to_record_bucket = function() {
264 var recId = $scope.record_id;
266 templateUrl: './cat/catalog/t_add_to_bucket',
270 ['$scope','$modalInstance',
271 function($scope , $modalInstance) {
273 $scope.bucket_id = 0;
274 $scope.newBucketName = '';
275 $scope.allBuckets = [];
278 'open-ils.actor.container.retrieve_by_class.authoritative',
279 egCore.auth.token(), egCore.auth.user().id(),
280 'biblio', 'staff_client'
281 ).then(function(buckets) { $scope.allBuckets = buckets; });
283 $scope.add_to_bucket = function() {
284 var item = new egCore.idl.cbrebi();
285 item.bucket($scope.bucket_id);
286 item.target_biblio_record_entry(recId);
289 'open-ils.actor.container.item.create',
290 egCore.auth.token(), 'biblio', item
291 ).then(function(resp) {
292 $modalInstance.close();
296 $scope.add_to_new_bucket = function() {
297 var bucket = new egCore.idl.cbreb();
298 bucket.owner(egCore.auth.user().id());
299 bucket.name($scope.newBucketName);
300 bucket.description('');
301 bucket.btype('staff_client');
305 'open-ils.actor.container.create',
306 egCore.auth.token(), 'biblio', bucket
307 ).then(function(bucket) {
308 $scope.bucket_id = bucket;
309 $scope.add_to_bucket();
313 $scope.cancel = function() {
314 $modalInstance.dismiss();
320 $scope.current_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record');
321 $scope.current_voltransfer_target = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
322 $scope.current_conjoined_target = egCore.hatch.getLocalItem('eg.cat.marked_conjoined_record');
324 $scope.markConjoined = function () {
325 $scope.current_conjoined_target = $scope.record_id;
326 egCore.hatch.setLocalItem('eg.cat.marked_conjoined_record',$scope.record_id);
329 $scope.markVolTransfer = function () {
330 $scope.current_voltransfer_target = $scope.record_id;
331 egCore.hatch.setLocalItem('eg.cat.marked_volume_transfer_record',$scope.record_id);
334 $scope.markOverlay = function () {
335 $scope.current_overlay_target = $scope.record_id;
336 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.record_id);
339 $scope.clearRecordMarks = function () {
340 $scope.current_overlay_target = null;
341 $scope.current_voltransfer_target = null;
342 $scope.current_conjoined_target = null;
343 egCore.hatch.removeLocalItem('eg.cat.marked_volume_transfer_record');
344 egCore.hatch.removeLocalItem('eg.cat.marked_conjoined_record');
345 egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');
348 $scope.stop_unload = false;
349 $scope.$watch('stop_unload',
350 function(newVal, oldVal) {
351 if (newVal && newVal != oldVal && $scope.opac_iframe) {
352 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
353 return 'There is unsaved data in this record.'
356 if ($scope.opac_iframe)
357 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
362 // Set the "last bib" cookie, if we have that
363 if ($scope.record_id)
364 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
366 $scope.refresh_record_callback = function (record_id) {
367 egCore.pcrud.retrieve('bre', record_id, {
370 bre : ['simple_record','creator','editor']
372 }).then(function(rec) {
373 rec.owner(egCore.org.get(rec.owner()));
374 $scope.summary_pane_record = rec;
380 // also set it when the iframe changes to a new record
381 $scope.handle_page = function(url) {
383 if (!url || url == 'about:blank') {
384 // nothing loaded. If we already have a record ID, leave it.
388 var match = url.match(/\/+opac\/+record\/+(\d+)/);
390 $scope.record_id = match[1];
391 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
392 $scope.holdings_record_id_changed($scope.record_id);
393 conjoinedSvc.fetch($scope.record_id).then(function(){
394 $scope.conjoinedGridDataProvider.refresh();
397 $location.update_path('/cat/catalog/record/' + $scope.record_id);
399 delete $scope.record_id;
400 $scope.from_route = false;
403 // child scope is executing this function, so our digest doesn't fire ... thus,
406 if (!$scope.in_opac_call) {
407 if ($scope.record_id) {
408 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
409 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
411 tab = $routeParams.record_tab || 'catalog';
413 $scope.set_record_tab(tab);
415 $scope.in_opac_call = false;
419 // xulG catalog handlers
420 $scope.handlers = { }
422 // ------------------------------------------------------------------
425 $scope.conjoinedGridControls = {};
426 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
427 get : function(offset, count) {
428 return this.arrayNotifier(conjoinedSvc.items, offset, count);
432 $scope.changeConjoinedType = function () {
433 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
434 angular.forEach(peers, function (p) {
435 p.target_copy(p.target_copy().id());
436 p.peer_type(p.peer_type().id());
439 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
442 templateUrl: './cat/catalog/t_conjoined_selector',
445 ['$scope','$modalInstance',
446 function($scope , $modalInstance) {
447 $scope.update = true;
449 $scope.peer_type = null;
450 $scope.peer_type_list = [];
451 conjoinedSvc.get_peer_types().then(function(list){
452 $scope.peer_type_list = list;
455 $scope.ok = function(type) {
458 angular.forEach(peers, function (p) {
461 promises.push(egCore.pcrud.update(p));
464 return $q.all(promises)
465 .then(function(){$modalInstance.close()})
466 .then(function(){return conjoinedSvc.fetch()})
467 .then(function(){conjoinedGridDataProviderRef.refresh()});
470 $scope.cancel = function($event) {
471 $modalInstance.dismiss();
472 $event.preventDefault();
479 $scope.refreshConjoined = function () {
480 conjoinedSvc.fetch($scope.record_id)
481 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
484 $scope.deleteSelectedConjoined = function () {
485 var peers = $scope.conjoinedGridControls.selectedItems();
487 if (peers.length > 0) {
488 egConfirmDialog.open(
489 egCore.strings.CONFIRM_DELETE_PEERS,
490 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
491 {peers : peers.length}
492 ).result.then(function() {
493 angular.forEach(peers, function (p) {
497 egCore.pcrud.remove(peers).then(function() {
498 return conjoinedSvc.fetch();
500 $scope.conjoinedGridDataProvider.refresh();
505 if ($scope.record_id)
506 conjoinedSvc.fetch($scope.record_id);
508 // ------------------------------------------------------------------
511 $scope.holdingsGridControls = {
512 activateItem : function (item) {
513 $scope.selectedHoldingsVolCopyEdit();
516 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
517 get : function(offset, count) {
518 return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
522 $scope.add_copies_to_bucket = function() {
523 var copy_list = gatherSelectedHoldingsIds();
524 if (copy_list.length == 0) return;
527 templateUrl: './cat/catalog/t_add_to_bucket',
531 ['$scope','$modalInstance',
532 function($scope , $modalInstance) {
534 $scope.bucket_id = 0;
535 $scope.newBucketName = '';
536 $scope.allBuckets = [];
540 'open-ils.actor.container.retrieve_by_class.authoritative',
541 egCore.auth.token(), egCore.auth.user().id(),
542 'copy', 'staff_client'
543 ).then(function(buckets) { $scope.allBuckets = buckets; });
545 $scope.add_to_bucket = function() {
547 angular.forEach(copy_list, function (cp) {
548 var item = new egCore.idl.ccbi()
549 item.bucket($scope.bucket_id);
550 item.target_copy(cp);
554 'open-ils.actor.container.item.create',
555 egCore.auth.token(), 'copy', item
559 return $q.all(promises).then(function() {
560 $modalInstance.close();
565 $scope.add_to_new_bucket = function() {
566 var bucket = new egCore.idl.ccb();
567 bucket.owner(egCore.auth.user().id());
568 bucket.name($scope.newBucketName);
569 bucket.description('');
570 bucket.btype('staff_client');
572 return egCore.net.request(
574 'open-ils.actor.container.create',
575 egCore.auth.token(), 'copy', bucket
576 ).then(function(bucket) {
577 $scope.bucket_id = bucket;
578 $scope.add_to_bucket();
582 $scope.cancel = function() {
583 $modalInstance.dismiss();
589 $scope.requestItems = function() {
590 var copy_list = gatherSelectedHoldingsIds();
591 if (copy_list.length == 0) return;
594 templateUrl: './cat/catalog/t_request_items',
597 ['$scope','$modalInstance',
598 function($scope , $modalInstance) {
600 $scope.first_user_fetch = true;
604 copy_list : copy_list,
605 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
606 user : egCore.auth.user().id()
609 egUser.get( $scope.hold_data.user ).then(function(u) {
611 $scope.barcode = u.card().barcode();
612 $scope.user_name = egUser.format_name(u);
613 $scope.hold_data.user = u.id();
616 $scope.user_name = '';
618 $scope.$watch('barcode', function (n) {
619 if (!$scope.first_user_fetch) {
620 egUser.getByBarcode(n).then(function(u) {
622 $scope.user_name = egUser.format_name(u);
623 $scope.hold_data.user = u.id();
626 $scope.user_name = '';
627 delete $scope.hold_data.user;
630 $scope.first_user_fetch = false;
633 $scope.ok = function(h) {
636 hold_type : h.hold_type,
637 pickup_lib: h.pickup_lib.id(),
643 'open-ils.circ.holds.test_and_create.batch.override',
644 egCore.auth.token(), args, h.copy_list
647 $modalInstance.close();
650 $scope.cancel = function($event) {
651 $modalInstance.dismiss();
652 $event.preventDefault();
658 $scope.replaceBarcodes = function() {
659 var copy_list = gatherSelectedRawCopies();
660 if (copy_list.length == 0) return;
662 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
664 angular.forEach(copy_list, function (cp) {
666 templateUrl: './cat/share/t_replace_barcode',
669 ['$scope','$modalInstance',
670 function($scope , $modalInstance) {
671 $scope.isModal = true;
672 $scope.focusBarcode = false;
673 $scope.focusBarcode2 = true;
674 $scope.barcode1 = cp.barcode();
676 $scope.updateBarcode = function() {
677 $scope.copyNotFound = false;
678 $scope.updateOK = false;
680 egCore.pcrud.search('acp',
681 {deleted : 'f', barcode : $scope.barcode1})
682 .then(function(copy) {
685 $scope.focusBarcode = true;
686 $scope.copyNotFound = true;
690 $scope.copyId = copy.id();
691 copy.barcode($scope.barcode2);
693 egCore.pcrud.update(copy).then(function(stat) {
694 $scope.updateOK = stat;
695 $scope.focusBarcode = true;
696 holdingsSvc.fetchAgain().then(function (){
697 holdingsGridDataProviderRef.refresh();
702 $modalInstance.close();
705 $scope.cancel = function($event) {
706 $modalInstance.dismiss();
707 $event.preventDefault();
715 // refresh the list of holdings when the record_id is changed.
716 $scope.holdings_record_id_changed = function(id) {
717 if ($scope.record_id != id) $scope.record_id = id;
718 console.log('record id changed to ' + id + ', loading new holdings');
719 holdingsSvcInst.fetch({
720 rid : $scope.record_id,
721 org : $scope.holdings_ou,
722 copy: $scope.holdings_show_copies,
723 vol : $scope.holdings_show_vols,
724 empty: $scope.holdings_show_empty
726 $scope.holdingsGridDataProvider.refresh();
730 // refresh the list of holdings when the filter lib is changed.
731 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
732 $scope.holdings_ou_changed = function(org) {
733 $scope.holdings_ou = org;
734 holdingsSvcInst.fetch({
735 rid : $scope.record_id,
736 org : $scope.holdings_ou,
737 copy: $scope.holdings_show_copies,
738 vol : $scope.holdings_show_vols,
739 empty: $scope.holdings_show_empty
741 $scope.holdingsGridDataProvider.refresh();
745 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
747 egCore.hatch.setItem('cat.' + cb, newVal);
748 if (!norefresh) 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 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
760 if (typeof x == 'undefined') x = true;
761 $scope.holdings_cb_changed('holdings_show_vols',x,true);
762 $('#holdings_show_vols').prop('checked', x);
764 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
765 if (typeof x == 'undefined') x = true;
766 $scope.holdings_cb_changed('holdings_show_copies',x,true);
767 $('#holdings_show_copies').prop('checked', x);
769 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
770 if (typeof x == 'undefined') x = true;
771 $scope.holdings_cb_changed('holdings_show_empty',x);
772 $('#holdings_show_empty').prop('checked', x);
777 $scope.vols_not_shown = function () {
778 return !$scope.holdings_show_vols;
781 $scope.copies_not_shown = function () {
782 return !$scope.holdings_show_copies;
785 $scope.holdings_checkbox_handler = function (item) {
786 $scope.holdings_cb_changed(item.checkbox,item.checked);
789 function gatherSelectedHoldingsIds () {
792 $scope.holdingsGridControls.selectedItems(),
793 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
798 function gatherSelectedRawCopies () {
801 $scope.holdingsGridControls.selectedItems(),
802 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
807 function gatherSelectedEmptyVolumeIds () {
810 $scope.holdingsGridControls.selectedItems(),
812 if (item.copy_count == 0)
813 cn_id_list.push(item.call_number.id)
819 function gatherSelectedVolumeIds () {
822 $scope.holdingsGridControls.selectedItems(),
824 if (cn_id_list.indexOf(item.call_number.id) == -1)
825 cn_id_list.push(item.call_number.id)
831 $scope.selectedHoldingsDelete = function (vols, copies) {
834 var perCnCopies = {};
840 $scope.holdingsGridControls.selectedItems(),
842 if (vols && item.raw_call_number) {
843 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
844 cnHash[item.call_number.id].isdeleted(1);
847 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
850 var cn_id = cp.call_number().id();
851 if (!cnHash[cn_id]) {
852 cnHash[cn_id] = cp.call_number();
853 perCnCopies[cn_id] = [cp];
855 perCnCopies[cn_id].push(cp);
857 cp.call_number(cn_id); // prevent loops in JSON-ification
864 angular.forEach(perCnCopies, function (v, k) {
866 cnHash[k].isdeleted(1);
873 angular.forEach(cnHash, function (v, k) {
877 if (cnList.length == 0) return;
880 if (vols && copies) flags.force_delete_copies = 1;
882 egConfirmDialog.open(
883 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
884 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
885 {copies : cp_count, volumes : cn_count}
886 ).result.then(function() {
889 'open-ils.cat.asset.volume.fleshed.batch.update.override',
890 egCore.auth.token(), cnList, 1, flags
891 ).then(function(update_count) {
892 holdingsSvcInst.fetchAgain().then(function() {
893 $scope.holdingsGridDataProvider.refresh();
898 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
899 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
900 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
902 spawnHoldingsAdd = function (vols,copies){
904 if (copies) { // just a copy on existing volumes
905 angular.forEach(gatherSelectedVolumeIds(), function (v) {
906 raw.push( {callnumber : v} );
910 $scope.holdingsGridControls.selectedItems(),
912 raw.push({owner : item.owner_id});
917 if (raw.length == 0) raw.push({});
921 'open-ils.actor.anon_cache.set_value',
922 null, 'edit-these-copies', {
923 record_id: $scope.record_id,
928 ).then(function(key) {
930 var url = egCore.env.basePath + 'cat/volcopy/' + key;
931 $timeout(function() { $window.open(url, '_blank') });
933 alert('Could not create anonymous cache key!');
937 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
938 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
940 spawnHoldingsEdit = function (hide_vols,hide_copies){
943 'open-ils.actor.anon_cache.set_value',
944 null, 'edit-these-copies', {
945 record_id: $scope.record_id,
946 copies: gatherSelectedHoldingsIds(),
947 raw: gatherSelectedEmptyVolumeIds().map(
948 function(v){ return { callnumber : v } }
950 hide_vols : hide_vols,
951 hide_copies : hide_copies
953 ).then(function(key) {
955 var url = egCore.env.basePath + 'cat/volcopy/' + key;
956 $timeout(function() { $window.open(url, '_blank') });
958 alert('Could not create anonymous cache key!');
962 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
963 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
964 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
966 $scope.selectedHoldingsItemStatus = function (){
967 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
968 $timeout(function() { $window.open(url, '_blank') });
971 $scope.markVolAsItemTarget = function() {
972 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
973 egCore.hatch.setLocalItem(
974 'eg.cat.item_transfer_target',
975 $scope.holdingsGridControls.selectedItems()[0].call_number.id
980 $scope.markLibAsVolTarget = function() {
981 egCore.hatch.setLocalItem(
982 'eg.cat.volume_transfer_target',
983 $scope.holdingsGridControls.selectedItems()[0].owner_id
987 $scope.selectedHoldingsItemStatusDetail = function (){
989 gatherSelectedHoldingsIds(),
991 var url = egCore.env.basePath +
993 $timeout(function() { $window.open(url, '_blank') });
998 $scope.transferVolumes = function (){
999 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
1004 'open-ils.cat.asset.volume.batch.transfer.override',
1005 egCore.auth.token(), {
1006 docid : $scope.record_id,
1008 volumes : gatherSelectedVolumeIds()
1010 ).then(function(success) {
1012 holdingsSvcInst.fetchAgain().then(function() {
1013 $scope.holdingsGridDataProvider.refresh();
1016 alert('Could not transfer volumes!');
1023 $scope.transferItems = function (){
1024 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
1025 var copy_ids = gatherSelectedHoldingsIds();
1026 if (xfer_target && copy_ids.length > 0) {
1029 'open-ils.cat.transfer_copies_to_volume',
1030 egCore.auth.token(),
1034 function(resp) { // oncomplete
1035 var evt = egCore.evt.parse(resp);
1037 egConfirmDialog.open(
1038 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1039 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1040 {'evt_desc': evt.desc}
1041 ).result.then(function() {
1044 'open-ils.cat.transfer_copies_to_volume.override',
1045 egCore.auth.token(),
1048 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1049 ).then(function(resp) {
1050 holdingsSvcInst.fetchAgain().then(function() {
1051 $scope.holdingsGridDataProvider.refresh();
1056 holdingsSvcInst.fetchAgain().then(function() {
1057 $scope.holdingsGridDataProvider.refresh();
1067 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1069 gatherSelectedHoldingsIds(),
1071 var url = egCore.env.basePath +
1072 'cat/item/' + cid + '/triggered_events';
1073 $timeout(function() { $window.open(url, '_blank') });
1078 $scope.selectedHoldingsItemStatusHolds = function (){
1080 gatherSelectedHoldingsIds(),
1082 var url = egCore.env.basePath +
1083 'cat/item/' + cid + '/holds';
1084 $timeout(function() { $window.open(url, '_blank') });
1089 $scope.selectedHoldingsDamaged = function () {
1090 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
1091 holdingsSvcInst.fetchAgain().then(function() {
1092 $scope.holdingsGridDataProvider.refresh();
1097 $scope.selectedHoldingsMissing = function () {
1098 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1099 holdingsSvcInst.fetchAgain().then(function() {
1100 $scope.holdingsGridDataProvider.refresh();
1105 $scope.attach_to_peer_bib = function() {
1106 var copy_list = gatherSelectedHoldingsIds();
1107 if (copy_list.length == 0) return;
1109 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1110 if (!target_record) return;
1112 return $modal.open({
1113 templateUrl: './cat/catalog/t_conjoined_selector',
1116 ['$scope','$modalInstance',
1117 function($scope , $modalInstance) {
1118 $scope.update = false;
1120 $scope.peer_type = null;
1121 $scope.peer_type_list = [];
1122 conjoinedSvc.get_peer_types().then(function(list){
1123 $scope.peer_type_list = list;
1126 $scope.ok = function(type) {
1129 angular.forEach(copy_list, function (cp) {
1130 var n = new egCore.idl.bpbcm();
1132 n.peer_record(target_record);
1135 promises.push(egCore.pcrud.create(n));
1138 return $q.all(promises).then(function(){$modalInstance.close()});
1141 $scope.cancel = function($event) {
1142 $modalInstance.dismiss();
1143 $event.preventDefault();
1151 // ------------------------------------------------------------------
1153 var provider = egGridDataProvider.instance({});
1154 $scope.hold_grid_data_provider = provider;
1155 $scope.grid_actions = egHoldGridActions;
1156 $scope.grid_actions.refresh = function () { provider.refresh() };
1157 $scope.hold_grid_controls = {};
1159 var hold_ids = []; // current list of holds
1160 function fetchHolds(offset, count) {
1161 var ids = hold_ids.slice(offset, offset + count);
1162 return egHolds.fetch_holds(ids).then(null, null,
1163 function(hold_data) {
1169 provider.get = function(offset, count) {
1170 if ($scope.record_tab != 'holds') return $q.when();
1171 var deferred = $q.defer();
1172 hold_ids = []; // no caching ATM
1177 'open-ils.circ.holds.retrieve_all_from_title',
1178 egCore.auth.token(), $scope.record_id,
1179 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
1181 function(hold_data) {
1182 angular.forEach(hold_data, function(list, type) {
1183 hold_ids = hold_ids.concat(list);
1185 fetchHolds(offset, count).then(
1186 deferred.resolve, null, deferred.notify);
1190 return deferred.promise;
1193 $scope.detail_view = function(action, user_data, items) {
1195 $scope.detail_hold_id = h.hold.id();
1199 $scope.list_view = function(items) {
1200 $scope.detail_hold_id = null;
1203 // refresh the list of record holds when the pickup lib is changed.
1204 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1205 $scope.pickup_ou_changed = function(org) {
1206 $scope.pickup_ou = org;
1210 $scope.print_holds = function() {
1212 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1214 hold : egCore.idl.toHash(item.hold),
1215 patron_last : item.patron_last,
1216 patron_alias : item.patron_alias,
1217 patron_barcode : item.patron_barcode,
1218 copy : egCore.idl.toHash(item.copy),
1219 volume : egCore.idl.toHash(item.volume),
1220 title : item.mvr.title(),
1221 author : item.mvr.author()
1225 egCore.print.print({
1226 context : 'receipt',
1227 template : 'holds_for_bib',
1228 scope : {holds : holds}
1232 $scope.mark_hold_transfer_dest = function() {
1233 egCore.hatch.setLocalItem(
1234 'eg.circ.hold.title_transfer_target', $scope.record_id);
1237 // UI presents this option as "all holds"
1238 $scope.transfer_holds_to_marked = function() {
1239 var hold_ids = $scope.hold_grid_controls.allItems().map(
1240 function(hold_data) {return hold_data.hold.id()});
1241 egHolds.transfer_to_marked_title(hold_ids);
1244 // ------------------------------------------------------------------
1245 // Initialize the selected tab
1247 function init_cat_url() {
1248 // Set the initial catalog URL. This only happens once.
1249 // The URL is otherwise generated through user navigation.
1250 if ($scope.catalog_url) return;
1252 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1254 // A record ID in the path indicates a request for the record-
1256 if ($routeParams.record_id) {
1257 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1260 $scope.catalog_url = url;
1263 function init_parts_url() {
1264 $scope.parts_url = $location
1268 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1272 $scope.set_record_tab = function(tab) {
1273 $scope.record_tab = tab;
1286 $scope.detail_hold_record_id = $scope.record_id;
1287 // refresh the holds grid
1293 $scope.set_default_record_tab = function() {
1294 egCore.hatch.setLocalItem(
1295 'eg.cat.default_record_tab', $scope.record_tab);
1296 $timeout(function(){$scope.default_tab = $scope.record_tab});
1300 if ($scope.record_id) {
1301 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1302 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1305 tab = $routeParams.record_tab || 'catalog';
1307 $scope.set_record_tab(tab);
1311 .controller('AuthorityCtrl',
1312 ['$scope','$routeParams','$location','$window','$q','egCore',
1313 function($scope , $routeParams , $location , $window , $q , egCore) {
1315 // set record ID on page load if available...
1316 $scope.authority_id = $routeParams.authority_id;
1318 if ($routeParams.authority_id) $scope.from_route = true;
1319 else $scope.from_route = false;
1321 $scope.stop_unload = false;
1324 .controller('URLVerifyCtrl',
1325 ['$scope','$location',
1326 function($scope , $location) {
1327 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1330 .controller('VandelayCtrl',
1331 ['$scope','$location',
1332 function($scope , $location) {
1333 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
1336 .controller('ManageAuthoritiesCtrl',
1337 ['$scope','$location',
1338 function($scope , $location) {
1339 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1342 .controller('BatchEditCtrl',
1343 ['$scope','$location','$routeParams',
1344 function($scope , $location , $routeParams) {
1345 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1346 if ($routeParams.container_type) {
1347 switch ($routeParams.container_type) {
1349 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1352 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1359 .filter('boolText', function(){
1360 return function (v) {
1365 .factory('conjoinedSvc',
1367 function(egCore , $q) {
1370 items : [], // record search results
1371 index : 0, // search grid index
1378 bpbcm : ['target_copy','peer_type'],
1379 acp : ['call_number'],
1381 bre : ['simple_record']
1383 // avoid fetching the MARC blob by specifying which
1384 // fields on the bre to select. More may be needed.
1385 // note that fleshed fields are explicitly selected.
1386 select : { bre : ['id'] },
1387 order_by : { bpbcm : ['id'] },
1390 // resolved with the last received copy
1391 service.fetch = function(rid) {
1392 if (!rid && !service.rid) return $q.when();
1394 if (rid) service.rid = rid;
1398 return egCore.pcrud.search(
1400 {peer_record : service.rid},
1403 ).then( function(list) { // finished
1404 service.items = list;
1405 return service.items;
1409 // returns a promise resolved with the list of peer bib types
1410 service.get_peer_types = function() {
1412 return $q.when(egCore.env.bpt.list);
1414 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
1415 .then(function(list) {
1416 egCore.env.absorbList(list, 'bpt');