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 egCore.hatch.getItem('cat.default_bib_marc_template').then(function(template) {
194 $scope.template_name = template;
197 $scope.loadTemplate = function() {
198 if ($scope.template_name) {
201 'open-ils.cat.biblio.marc_template.retrieve',
203 ).then(function(template) {
204 $scope.marc_template = template;
205 $scope.have_template = true;
210 $scope.setDefaultTemplate = function() {
211 var hatch_key = "cat.default_bib_marc_template";
212 if ($scope.template_name) {
213 egCore.hatch.setItem(hatch_key, $scope.template_name);
215 egCore.hatch.removeItem(hatch_key);
219 $scope.$watch('new_bib_id', function(newVal, oldVal) {
221 $location.path('/cat/catalog/record/' + $scope.new_bib_id);
228 .controller('CatalogCtrl',
229 ['$scope','$routeParams','$location','$window','$q','egCore','egHolds','egCirc','egConfirmDialog',
230 'egGridDataProvider','egHoldGridActions','$timeout','$modal','holdingsSvc','egUser','conjoinedSvc',
231 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc, egConfirmDialog,
232 egGridDataProvider , egHoldGridActions , $timeout , $modal , holdingsSvc , egUser , conjoinedSvc) {
234 var holdingsSvcInst = new holdingsSvc();
236 // set record ID on page load if available...
237 $scope.record_id = $routeParams.record_id;
238 $scope.summary_pane_record;
240 if ($routeParams.record_id) $scope.from_route = true;
241 else $scope.from_route = false;
243 // will hold a ref to the opac iframe
244 $scope.opac_iframe = null;
245 $scope.parts_iframe = null;
247 $scope.in_opac_call = false;
248 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
249 if ($scope.opac_iframe) {
250 if (force_opac_tab) $scope.record_tab = 'catalog';
251 $scope.in_opac_call = true;
252 $scope.opac_iframe.dom.contentWindow[opac_frame_function]();
253 if (opac_frame_function == 'rdetailBackToResults') {
254 $location.update_path('/cat/catalog/index');
259 $scope.add_to_record_bucket = function() {
260 var recId = $scope.record_id;
262 templateUrl: './cat/catalog/t_add_to_bucket',
266 ['$scope','$modalInstance',
267 function($scope , $modalInstance) {
269 $scope.bucket_id = 0;
270 $scope.newBucketName = '';
271 $scope.allBuckets = [];
274 'open-ils.actor.container.retrieve_by_class.authoritative',
275 egCore.auth.token(), egCore.auth.user().id(),
276 'biblio', 'staff_client'
277 ).then(function(buckets) { $scope.allBuckets = buckets; });
279 $scope.add_to_bucket = function() {
280 var item = new egCore.idl.cbrebi();
281 item.bucket($scope.bucket_id);
282 item.target_biblio_record_entry(recId);
285 'open-ils.actor.container.item.create',
286 egCore.auth.token(), 'biblio', item
287 ).then(function(resp) {
288 $modalInstance.close();
292 $scope.add_to_new_bucket = function() {
293 var bucket = new egCore.idl.cbreb();
294 bucket.owner(egCore.auth.user().id());
295 bucket.name($scope.newBucketName);
296 bucket.description('');
297 bucket.btype('staff_client');
301 'open-ils.actor.container.create',
302 egCore.auth.token(), 'biblio', bucket
303 ).then(function(bucket) {
304 $scope.bucket_id = bucket;
305 $scope.add_to_bucket();
309 $scope.cancel = function() {
310 $modalInstance.dismiss();
316 $scope.current_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record');
317 $scope.current_voltransfer_target = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
318 $scope.current_conjoined_target = egCore.hatch.getLocalItem('eg.cat.marked_conjoined_record');
320 $scope.markConjoined = function () {
321 $scope.current_conjoined_target = $scope.record_id;
322 egCore.hatch.setLocalItem('eg.cat.marked_conjoined_record',$scope.record_id);
325 $scope.markVolTransfer = function () {
326 $scope.current_voltransfer_target = $scope.record_id;
327 egCore.hatch.setLocalItem('eg.cat.marked_volume_transfer_record',$scope.record_id);
330 $scope.markOverlay = function () {
331 $scope.current_overlay_target = $scope.record_id;
332 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.record_id);
335 $scope.clearRecordMarks = function () {
336 $scope.current_overlay_target = null;
337 $scope.current_voltransfer_target = null;
338 $scope.current_conjoined_target = null;
339 egCore.hatch.removeLocalItem('eg.cat.marked_volume_transfer_record');
340 egCore.hatch.removeLocalItem('eg.cat.marked_conjoined_record');
341 egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');
344 $scope.stop_unload = false;
345 $scope.$watch('stop_unload',
346 function(newVal, oldVal) {
347 if (newVal && newVal != oldVal && $scope.opac_iframe) {
348 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
349 return 'There is unsaved data in this record.'
352 if ($scope.opac_iframe)
353 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
358 // Set the "last bib" cookie, if we have that
359 if ($scope.record_id)
360 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
362 $scope.refresh_record_callback = function (record_id) {
363 egCore.pcrud.retrieve('bre', record_id, {
366 bre : ['simple_record','creator','editor']
368 }).then(function(rec) {
369 rec.owner(egCore.org.get(rec.owner()));
370 $scope.summary_pane_record = rec;
376 // also set it when the iframe changes to a new record
377 $scope.handle_page = function(url) {
379 if (!url || url == 'about:blank') {
380 // nothing loaded. If we already have a record ID, leave it.
384 var match = url.match(/\/+opac\/+record\/+(\d+)/);
386 $scope.record_id = match[1];
387 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
388 $scope.holdings_record_id_changed($scope.record_id);
389 conjoinedSvc.fetch($scope.record_id).then(function(){
390 $scope.conjoinedGridDataProvider.refresh();
393 $location.update_path('/cat/catalog/record/' + $scope.record_id);
395 delete $scope.record_id;
396 $scope.from_route = false;
399 // child scope is executing this function, so our digest doesn't fire ... thus,
402 if (!$scope.in_opac_call) {
403 if ($scope.record_id) {
404 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
405 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
407 tab = $routeParams.record_tab || 'catalog';
409 $scope.set_record_tab(tab);
411 $scope.in_opac_call = false;
415 // xulG catalog handlers
416 $scope.handlers = { }
418 // ------------------------------------------------------------------
421 $scope.conjoinedGridControls = {};
422 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
423 get : function(offset, count) {
424 return this.arrayNotifier(conjoinedSvc.items, offset, count);
428 $scope.changeConjoinedType = function () {
429 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
430 angular.forEach(peers, function (p) {
431 p.target_copy(p.target_copy().id());
432 p.peer_type(p.peer_type().id());
435 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
438 templateUrl: './cat/catalog/t_conjoined_selector',
441 ['$scope','$modalInstance',
442 function($scope , $modalInstance) {
443 $scope.update = true;
445 $scope.peer_type = null;
446 $scope.peer_type_list = [];
447 conjoinedSvc.get_peer_types().then(function(list){
448 $scope.peer_type_list = list;
451 $scope.ok = function(type) {
454 angular.forEach(peers, function (p) {
457 promises.push(egCore.pcrud.update(p));
460 return $q.all(promises)
461 .then(function(){$modalInstance.close()})
462 .then(function(){return conjoinedSvc.fetch()})
463 .then(function(){conjoinedGridDataProviderRef.refresh()});
466 $scope.cancel = function($event) {
467 $modalInstance.dismiss();
468 $event.preventDefault();
475 $scope.refreshConjoined = function () {
476 conjoinedSvc.fetch($scope.record_id)
477 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
480 $scope.deleteSelectedConjoined = function () {
481 var peers = $scope.conjoinedGridControls.selectedItems();
483 if (peers.length > 0) {
484 egConfirmDialog.open(
485 egCore.strings.CONFIRM_DELETE_PEERS,
486 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
487 {peers : peers.length}
488 ).result.then(function() {
489 angular.forEach(peers, function (p) {
493 egCore.pcrud.remove(peers).then(function() {
494 return conjoinedSvc.fetch();
496 $scope.conjoinedGridDataProvider.refresh();
501 if ($scope.record_id)
502 conjoinedSvc.fetch($scope.record_id);
504 // ------------------------------------------------------------------
507 $scope.holdingsGridControls = {};
508 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
509 get : function(offset, count) {
510 return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
514 $scope.add_copies_to_bucket = function() {
515 var copy_list = gatherSelectedHoldingsIds();
516 if (copy_list.length == 0) return;
519 templateUrl: './cat/catalog/t_add_to_bucket',
523 ['$scope','$modalInstance',
524 function($scope , $modalInstance) {
526 $scope.bucket_id = 0;
527 $scope.newBucketName = '';
528 $scope.allBuckets = [];
532 'open-ils.actor.container.retrieve_by_class.authoritative',
533 egCore.auth.token(), egCore.auth.user().id(),
534 'copy', 'staff_client'
535 ).then(function(buckets) { $scope.allBuckets = buckets; });
537 $scope.add_to_bucket = function() {
539 angular.forEach(copy_list, function (cp) {
540 var item = new egCore.idl.ccbi()
541 item.bucket($scope.bucket_id);
542 item.target_copy(cp);
546 'open-ils.actor.container.item.create',
547 egCore.auth.token(), 'copy', item
551 return $q.all(promises).then(function() {
552 $modalInstance.close();
557 $scope.add_to_new_bucket = function() {
558 var bucket = new egCore.idl.ccb();
559 bucket.owner(egCore.auth.user().id());
560 bucket.name($scope.newBucketName);
561 bucket.description('');
562 bucket.btype('staff_client');
564 return egCore.net.request(
566 'open-ils.actor.container.create',
567 egCore.auth.token(), 'copy', bucket
568 ).then(function(bucket) {
569 $scope.bucket_id = bucket;
570 $scope.add_to_bucket();
574 $scope.cancel = function() {
575 $modalInstance.dismiss();
581 $scope.requestItems = function() {
582 var copy_list = gatherSelectedHoldingsIds();
583 if (copy_list.length == 0) return;
586 templateUrl: './cat/catalog/t_request_items',
589 ['$scope','$modalInstance',
590 function($scope , $modalInstance) {
592 $scope.first_user_fetch = true;
596 copy_list : copy_list,
597 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
598 user : egCore.auth.user().id()
601 egUser.get( $scope.hold_data.user ).then(function(u) {
603 $scope.barcode = u.card().barcode();
604 $scope.user_name = egUser.format_name(u);
605 $scope.hold_data.user = u.id();
608 $scope.user_name = '';
610 $scope.$watch('barcode', function (n) {
611 if (!$scope.first_user_fetch) {
612 egUser.getByBarcode(n).then(function(u) {
614 $scope.user_name = egUser.format_name(u);
615 $scope.hold_data.user = u.id();
618 $scope.user_name = '';
619 delete $scope.hold_data.user;
622 $scope.first_user_fetch = false;
625 $scope.ok = function(h) {
628 hold_type : h.hold_type,
629 pickup_lib: h.pickup_lib.id(),
635 'open-ils.circ.holds.test_and_create.batch.override',
636 egCore.auth.token(), args, h.copy_list
639 $modalInstance.close();
642 $scope.cancel = function($event) {
643 $modalInstance.dismiss();
644 $event.preventDefault();
650 $scope.replaceBarcodes = function() {
651 var copy_list = gatherSelectedRawCopies();
652 if (copy_list.length == 0) return;
654 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
656 angular.forEach(copy_list, function (cp) {
658 templateUrl: './cat/share/t_replace_barcode',
661 ['$scope','$modalInstance',
662 function($scope , $modalInstance) {
663 $scope.isModal = true;
664 $scope.focusBarcode = false;
665 $scope.focusBarcode2 = true;
666 $scope.barcode1 = cp.barcode();
668 $scope.updateBarcode = function() {
669 $scope.copyNotFound = false;
670 $scope.updateOK = false;
672 egCore.pcrud.search('acp',
673 {deleted : 'f', barcode : $scope.barcode1})
674 .then(function(copy) {
677 $scope.focusBarcode = true;
678 $scope.copyNotFound = true;
682 $scope.copyId = copy.id();
683 copy.barcode($scope.barcode2);
685 egCore.pcrud.update(copy).then(function(stat) {
686 $scope.updateOK = stat;
687 $scope.focusBarcode = true;
688 holdingsSvc.fetchAgain().then(function (){
689 holdingsGridDataProviderRef.refresh();
694 $modalInstance.close();
697 $scope.cancel = function($event) {
698 $modalInstance.dismiss();
699 $event.preventDefault();
707 // refresh the list of holdings when the record_id is changed.
708 $scope.holdings_record_id_changed = function(id) {
709 if ($scope.record_id != id) $scope.record_id = id;
710 console.log('record id changed to ' + id + ', loading new holdings');
711 holdingsSvcInst.fetch({
712 rid : $scope.record_id,
713 org : $scope.holdings_ou,
714 copy: $scope.holdings_show_copies,
715 vol : $scope.holdings_show_vols,
716 empty: $scope.holdings_show_empty
718 $scope.holdingsGridDataProvider.refresh();
722 // refresh the list of holdings when the filter lib is changed.
723 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
724 $scope.holdings_ou_changed = function(org) {
725 $scope.holdings_ou = org;
726 holdingsSvcInst.fetch({
727 rid : $scope.record_id,
728 org : $scope.holdings_ou,
729 copy: $scope.holdings_show_copies,
730 vol : $scope.holdings_show_vols,
731 empty: $scope.holdings_show_empty
733 $scope.holdingsGridDataProvider.refresh();
737 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
739 egCore.hatch.setItem('cat.' + cb, newVal);
740 if (!norefresh) holdingsSvcInst.fetch({
741 rid : $scope.record_id,
742 org : $scope.holdings_ou,
743 copy: $scope.holdings_show_copies,
744 vol : $scope.holdings_show_vols,
745 empty: $scope.holdings_show_empty
747 $scope.holdingsGridDataProvider.refresh();
751 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
752 if (typeof x == 'undefined') x = true;
753 $scope.holdings_cb_changed('holdings_show_vols',x,true);
754 $('#holdings_show_vols').prop('checked', x);
756 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
757 if (typeof x == 'undefined') x = true;
758 $scope.holdings_cb_changed('holdings_show_copies',x,true);
759 $('#holdings_show_copies').prop('checked', x);
761 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
762 if (typeof x == 'undefined') x = true;
763 $scope.holdings_cb_changed('holdings_show_empty',x);
764 $('#holdings_show_empty').prop('checked', x);
769 $scope.vols_not_shown = function () {
770 return !$scope.holdings_show_vols;
773 $scope.copies_not_shown = function () {
774 return !$scope.holdings_show_copies;
777 $scope.holdings_checkbox_handler = function (item) {
778 $scope.holdings_cb_changed(item.checkbox,item.checked);
781 function gatherSelectedHoldingsIds () {
784 $scope.holdingsGridControls.selectedItems(),
785 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
790 function gatherSelectedRawCopies () {
793 $scope.holdingsGridControls.selectedItems(),
794 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
799 function gatherSelectedEmptyVolumeIds () {
802 $scope.holdingsGridControls.selectedItems(),
804 if (item.copy_count == 0)
805 cn_id_list.push(item.call_number.id)
811 function gatherSelectedVolumeIds () {
814 $scope.holdingsGridControls.selectedItems(),
816 if (cn_id_list.indexOf(item.call_number.id) == -1)
817 cn_id_list.push(item.call_number.id)
823 $scope.selectedHoldingsDelete = function (vols, copies) {
826 var perCnCopies = {};
832 $scope.holdingsGridControls.selectedItems(),
834 if (vols && item.raw_call_number) {
835 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
836 cnHash[item.call_number.id].isdeleted(1);
839 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
842 var cn_id = cp.call_number().id();
843 if (!cnHash[cn_id]) {
844 cnHash[cn_id] = cp.call_number();
845 perCnCopies[cn_id] = [cp];
847 perCnCopies[cn_id].push(cp);
849 cp.call_number(cn_id); // prevent loops in JSON-ification
856 angular.forEach(perCnCopies, function (v, k) {
858 cnHash[k].isdeleted(1);
865 angular.forEach(cnHash, function (v, k) {
869 if (cnList.length == 0) return;
871 egConfirmDialog.open(
872 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
873 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
874 {copies : cp_count, volumes : cn_count}
875 ).result.then(function() {
878 'open-ils.cat.asset.volume.fleshed.batch.update.override',
879 egCore.auth.token(), cnList, 1, {}
880 ).then(function(update_count) {
881 $scope.holdingsGridDataProvider.refresh();
885 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
886 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
887 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
889 spawnHoldingsAdd = function (vols,copies){
891 if (copies) { // just a copy on existing volumes
892 angular.forEach(gatherSelectedVolumeIds(), function (v) {
893 raw.push( {callnumber : v} );
897 $scope.holdingsGridControls.selectedItems(),
899 raw.push({owner : item.owner_id});
904 if (raw.length == 0) raw.push({});
908 'open-ils.actor.anon_cache.set_value',
909 null, 'edit-these-copies', {
910 record_id: $scope.record_id,
915 ).then(function(key) {
917 var url = egCore.env.basePath + 'cat/volcopy/' + key;
918 $timeout(function() { $window.open(url, '_blank') });
920 alert('Could not create anonymous cache key!');
924 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
925 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
927 spawnHoldingsEdit = function (hide_vols,hide_copies){
930 'open-ils.actor.anon_cache.set_value',
931 null, 'edit-these-copies', {
932 record_id: $scope.record_id,
933 copies: gatherSelectedHoldingsIds(),
934 raw: gatherSelectedEmptyVolumeIds().map(
935 function(v){ return { callnumber : v } }
937 hide_vols : hide_vols,
938 hide_copies : hide_copies
940 ).then(function(key) {
942 var url = egCore.env.basePath + 'cat/volcopy/' + key;
943 $timeout(function() { $window.open(url, '_blank') });
945 alert('Could not create anonymous cache key!');
949 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
950 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
951 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
953 $scope.selectedHoldingsItemStatus = function (){
954 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
955 $timeout(function() { $window.open(url, '_blank') });
958 $scope.markVolAsItemTarget = function() {
959 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
960 egCore.hatch.setLocalItem(
961 'eg.cat.item_transfer_target',
962 $scope.holdingsGridControls.selectedItems()[0].call_number.id
967 $scope.markLibAsVolTarget = function() {
968 egCore.hatch.setLocalItem(
969 'eg.cat.volume_transfer_target',
970 $scope.holdingsGridControls.selectedItems()[0].owner_id
974 $scope.selectedHoldingsItemStatusDetail = function (){
976 gatherSelectedHoldingsIds(),
978 var url = egCore.env.basePath +
980 $timeout(function() { $window.open(url, '_blank') });
985 $scope.transferVolumes = function (){
986 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
991 'open-ils.open-ils.cat.asset.volume.batch.transfer.override',
992 egCore.auth.token(), {
993 docid : $scope.record_id,
995 volumes : gatherSelectedVolumeIds()
997 ).then(function(success) {
999 holdingsSvcInst.fetchAgain().then(function() {
1000 $scope.holdingsGridDataProvider.refresh();
1003 alert('Could not transfer volumes!');
1010 $scope.transferItems = function (){
1011 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
1012 var copy_ids = gatherSelectedHoldingsIds();
1013 if (xfer_target && copy_ids.length > 0) {
1016 'open-ils.cat.transfer_copies_to_volume',
1017 egCore.auth.token(),
1021 function(resp) { // oncomplete
1022 var evt = egCore.evt.parse(resp);
1024 egConfirmDialog.open(
1025 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1026 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1027 {'evt_desc': evt.desc}
1028 ).result.then(function() {
1031 'open-ils.cat.transfer_copies_to_volume.override',
1032 egCore.auth.token(),
1035 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1036 ).then(function(resp) {
1037 holdingsSvcInst.fetchAgain().then(function() {
1038 $scope.holdingsGridDataProvider.refresh();
1043 holdingsSvcInst.fetchAgain().then(function() {
1044 $scope.holdingsGridDataProvider.refresh();
1054 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1056 gatherSelectedHoldingsIds(),
1058 var url = egCore.env.basePath +
1059 'cat/item/' + cid + '/triggered_events';
1060 $timeout(function() { $window.open(url, '_blank') });
1065 $scope.selectedHoldingsItemStatusHolds = function (){
1067 gatherSelectedHoldingsIds(),
1069 var url = egCore.env.basePath +
1070 'cat/item/' + cid + '/holds';
1071 $timeout(function() { $window.open(url, '_blank') });
1076 $scope.selectedHoldingsDamaged = function () {
1077 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
1078 holdingsSvcInst.fetchAgain().then(function() {
1079 $scope.holdingsGridDataProvider.refresh();
1084 $scope.selectedHoldingsMissing = function () {
1085 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1086 holdingsSvcInst.fetchAgain().then(function() {
1087 $scope.holdingsGridDataProvider.refresh();
1092 $scope.attach_to_peer_bib = function() {
1093 var copy_list = gatherSelectedHoldingsIds();
1094 if (copy_list.length == 0) return;
1096 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1097 if (!target_record) return;
1099 return $modal.open({
1100 templateUrl: './cat/catalog/t_conjoined_selector',
1103 ['$scope','$modalInstance',
1104 function($scope , $modalInstance) {
1105 $scope.update = false;
1107 $scope.peer_type = null;
1108 $scope.peer_type_list = [];
1109 conjoinedSvc.get_peer_types().then(function(list){
1110 $scope.peer_type_list = list;
1113 $scope.ok = function(type) {
1116 angular.forEach(copy_list, function (cp) {
1117 var n = new egCore.idl.bpbcm();
1119 n.peer_record(target_record);
1122 promises.push(egCore.pcrud.create(n));
1125 return $q.all(promises).then(function(){$modalInstance.close()});
1128 $scope.cancel = function($event) {
1129 $modalInstance.dismiss();
1130 $event.preventDefault();
1138 // ------------------------------------------------------------------
1140 var provider = egGridDataProvider.instance({});
1141 $scope.hold_grid_data_provider = provider;
1142 $scope.grid_actions = egHoldGridActions;
1143 $scope.grid_actions.refresh = function () { provider.refresh() };
1144 $scope.hold_grid_controls = {};
1146 var hold_ids = []; // current list of holds
1147 function fetchHolds(offset, count) {
1148 var ids = hold_ids.slice(offset, offset + count);
1149 return egHolds.fetch_holds(ids).then(null, null,
1150 function(hold_data) {
1156 provider.get = function(offset, count) {
1157 if ($scope.record_tab != 'holds') return $q.when();
1158 var deferred = $q.defer();
1159 hold_ids = []; // no caching ATM
1164 'open-ils.circ.holds.retrieve_all_from_title',
1165 egCore.auth.token(), $scope.record_id,
1166 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
1168 function(hold_data) {
1169 angular.forEach(hold_data, function(list, type) {
1170 hold_ids = hold_ids.concat(list);
1172 fetchHolds(offset, count).then(
1173 deferred.resolve, null, deferred.notify);
1177 return deferred.promise;
1180 $scope.detail_view = function(action, user_data, items) {
1182 $scope.detail_hold_id = h.hold.id();
1186 $scope.list_view = function(items) {
1187 $scope.detail_hold_id = null;
1190 // refresh the list of record holds when the pickup lib is changed.
1191 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1192 $scope.pickup_ou_changed = function(org) {
1193 $scope.pickup_ou = org;
1197 $scope.print_holds = function() {
1199 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1201 hold : egCore.idl.toHash(item.hold),
1202 patron_last : item.patron_last,
1203 patron_alias : item.patron_alias,
1204 patron_barcode : item.patron_barcode,
1205 copy : egCore.idl.toHash(item.copy),
1206 volume : egCore.idl.toHash(item.volume),
1207 title : item.mvr.title(),
1208 author : item.mvr.author()
1212 egCore.print.print({
1213 context : 'receipt',
1214 template : 'holds_for_bib',
1215 scope : {holds : holds}
1219 $scope.mark_hold_transfer_dest = function() {
1220 egCore.hatch.setLocalItem(
1221 'eg.circ.hold.title_transfer_target', $scope.record_id);
1224 // UI presents this option as "all holds"
1225 $scope.transfer_holds_to_marked = function() {
1226 var hold_ids = $scope.hold_grid_controls.allItems().map(
1227 function(hold_data) {return hold_data.hold.id()});
1228 egHolds.transfer_to_marked_title(hold_ids);
1231 // ------------------------------------------------------------------
1232 // Initialize the selected tab
1234 function init_cat_url() {
1235 // Set the initial catalog URL. This only happens once.
1236 // The URL is otherwise generated through user navigation.
1237 if ($scope.catalog_url) return;
1239 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1241 // A record ID in the path indicates a request for the record-
1243 if ($routeParams.record_id) {
1244 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1247 $scope.catalog_url = url;
1250 function init_parts_url() {
1251 $scope.parts_url = $location
1255 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1259 $scope.set_record_tab = function(tab) {
1260 $scope.record_tab = tab;
1273 $scope.detail_hold_record_id = $scope.record_id;
1274 // refresh the holds grid
1280 $scope.set_default_record_tab = function() {
1281 egCore.hatch.setLocalItem(
1282 'eg.cat.default_record_tab', $scope.record_tab);
1283 $timeout(function(){$scope.default_tab = $scope.record_tab});
1287 if ($scope.record_id) {
1288 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1289 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1292 tab = $routeParams.record_tab || 'catalog';
1294 $scope.set_record_tab(tab);
1298 .controller('AuthorityCtrl',
1299 ['$scope','$routeParams','$location','$window','$q','egCore',
1300 function($scope , $routeParams , $location , $window , $q , egCore) {
1302 // set record ID on page load if available...
1303 $scope.authority_id = $routeParams.authority_id;
1305 if ($routeParams.authority_id) $scope.from_route = true;
1306 else $scope.from_route = false;
1308 $scope.stop_unload = false;
1311 .controller('URLVerifyCtrl',
1312 ['$scope','$location',
1313 function($scope , $location) {
1314 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1317 .controller('VandelayCtrl',
1318 ['$scope','$location',
1319 function($scope , $location) {
1320 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
1323 .controller('ManageAuthoritiesCtrl',
1324 ['$scope','$location',
1325 function($scope , $location) {
1326 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1329 .controller('BatchEditCtrl',
1330 ['$scope','$location','$routeParams',
1331 function($scope , $location , $routeParams) {
1332 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1333 if ($routeParams.container_type) {
1334 switch ($routeParams.container_type) {
1336 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1339 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1346 .filter('boolText', function(){
1347 return function (v) {
1352 .factory('conjoinedSvc',
1354 function(egCore , $q) {
1357 items : [], // record search results
1358 index : 0, // search grid index
1365 bpbcm : ['target_copy','peer_type'],
1366 acp : ['call_number'],
1368 bre : ['simple_record']
1370 // avoid fetching the MARC blob by specifying which
1371 // fields on the bre to select. More may be needed.
1372 // note that fleshed fields are explicitly selected.
1373 select : { bre : ['id'] },
1374 order_by : { bpbcm : ['id'] },
1377 // resolved with the last received copy
1378 service.fetch = function(rid) {
1379 if (!rid && !service.rid) return $q.when();
1381 if (rid) service.rid = rid;
1385 return egCore.pcrud.search(
1387 {peer_record : service.rid},
1390 ).then( function(list) { // finished
1391 service.items = list;
1392 return service.items;
1396 // returns a promise resolved with the list of peer bib types
1397 service.get_peer_types = function() {
1399 return $q.when(egCore.env.bpt.list);
1401 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
1402 .then(function(list) {
1403 egCore.env.absorbList(list, 'bpt');