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 // set record ID on page load if available...
235 $scope.record_id = $routeParams.record_id;
236 $scope.summary_pane_record;
238 if ($routeParams.record_id) $scope.from_route = true;
239 else $scope.from_route = false;
241 // will hold a ref to the opac iframe
242 $scope.opac_iframe = null;
243 $scope.parts_iframe = null;
245 $scope.in_opac_call = false;
246 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
247 if ($scope.opac_iframe) {
248 if (force_opac_tab) $scope.record_tab = 'catalog';
249 $scope.in_opac_call = true;
250 $scope.opac_iframe.dom.contentWindow[opac_frame_function]();
251 if (opac_frame_function == 'rdetailBackToResults') {
252 $location.update_path('/cat/catalog/index');
257 $scope.add_to_record_bucket = function() {
258 var recId = $scope.record_id;
260 templateUrl: './cat/catalog/t_add_to_bucket',
264 ['$scope','$modalInstance',
265 function($scope , $modalInstance) {
267 $scope.bucket_id = 0;
268 $scope.newBucketName = '';
269 $scope.allBuckets = [];
272 'open-ils.actor.container.retrieve_by_class.authoritative',
273 egCore.auth.token(), egCore.auth.user().id(),
274 'biblio', 'staff_client'
275 ).then(function(buckets) { $scope.allBuckets = buckets; });
277 $scope.add_to_bucket = function() {
278 var item = new egCore.idl.cbrebi();
279 item.bucket($scope.bucket_id);
280 item.target_biblio_record_entry(recId);
283 'open-ils.actor.container.item.create',
284 egCore.auth.token(), 'biblio', item
285 ).then(function(resp) {
286 $modalInstance.close();
290 $scope.add_to_new_bucket = function() {
291 var bucket = new egCore.idl.cbreb();
292 bucket.owner(egCore.auth.user().id());
293 bucket.name($scope.newBucketName);
294 bucket.description('');
295 bucket.btype('staff_client');
299 'open-ils.actor.container.create',
300 egCore.auth.token(), 'biblio', bucket
301 ).then(function(bucket) {
302 $scope.bucket_id = bucket;
303 $scope.add_to_bucket();
307 $scope.cancel = function() {
308 $modalInstance.dismiss();
314 $scope.current_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record');
315 $scope.current_voltransfer_target = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
316 $scope.current_conjoined_target = egCore.hatch.getLocalItem('eg.cat.marked_conjoined_record');
318 $scope.markConjoined = function () {
319 $scope.current_conjoined_target = $scope.record_id;
320 egCore.hatch.setLocalItem('eg.cat.marked_conjoined_record',$scope.record_id);
323 $scope.markVolTransfer = function () {
324 $scope.current_voltransfer_target = $scope.record_id;
325 egCore.hatch.setLocalItem('eg.cat.marked_volume_transfer_record',$scope.record_id);
328 $scope.markOverlay = function () {
329 $scope.current_overlay_target = $scope.record_id;
330 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.record_id);
333 $scope.clearRecordMarks = function () {
334 $scope.current_overlay_target = null;
335 $scope.current_voltransfer_target = null;
336 $scope.current_conjoined_target = null;
337 egCore.hatch.removeLocalItem('eg.cat.marked_volume_transfer_record');
338 egCore.hatch.removeLocalItem('eg.cat.marked_conjoined_record');
339 egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');
342 $scope.stop_unload = false;
343 $scope.$watch('stop_unload',
344 function(newVal, oldVal) {
345 if (newVal && newVal != oldVal && $scope.opac_iframe) {
346 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
347 return 'There is unsaved data in this record.'
350 if ($scope.opac_iframe)
351 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
356 // Set the "last bib" cookie, if we have that
357 if ($scope.record_id)
358 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
360 $scope.refresh_record_callback = function (record_id) {
361 egCore.pcrud.retrieve('bre', record_id, {
364 bre : ['simple_record','creator','editor']
366 }).then(function(rec) {
367 rec.owner(egCore.org.get(rec.owner()));
368 $scope.summary_pane_record = rec;
374 // also set it when the iframe changes to a new record
375 $scope.handle_page = function(url) {
377 if (!url || url == 'about:blank') {
378 // nothing loaded. If we already have a record ID, leave it.
382 var match = url.match(/\/+opac\/+record\/+(\d+)/);
384 $scope.record_id = match[1];
385 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
386 $scope.holdings_record_id_changed($scope.record_id);
387 conjoinedSvc.fetch($scope.record_id).then(function(){
388 $scope.conjoinedGridDataProvider.refresh();
391 $location.update_path('/cat/catalog/record/' + $scope.record_id);
393 delete $scope.record_id;
394 $scope.from_route = false;
397 // child scope is executing this function, so our digest doesn't fire ... thus,
400 if (!$scope.in_opac_call) {
401 if ($scope.record_id) {
402 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
403 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
405 tab = $routeParams.record_tab || 'catalog';
407 $scope.set_record_tab(tab);
409 $scope.in_opac_call = false;
413 // xulG catalog handlers
414 $scope.handlers = { }
416 // ------------------------------------------------------------------
419 $scope.conjoinedGridControls = {};
420 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
421 get : function(offset, count) {
422 return this.arrayNotifier(conjoinedSvc.items, offset, count);
426 $scope.changeConjoinedType = function () {
427 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
428 angular.forEach(peers, function (p) {
429 p.target_copy(p.target_copy().id());
430 p.peer_type(p.peer_type().id());
433 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
436 templateUrl: './cat/catalog/t_conjoined_selector',
439 ['$scope','$modalInstance',
440 function($scope , $modalInstance) {
441 $scope.update = true;
443 $scope.peer_type = null;
444 $scope.peer_type_list = [];
445 conjoinedSvc.get_peer_types().then(function(list){
446 $scope.peer_type_list = list;
449 $scope.ok = function(type) {
452 angular.forEach(peers, function (p) {
455 promises.push(egCore.pcrud.update(p));
458 return $q.all(promises)
459 .then(function(){$modalInstance.close()})
460 .then(function(){return conjoinedSvc.fetch()})
461 .then(function(){conjoinedGridDataProviderRef.refresh()});
464 $scope.cancel = function($event) {
465 $modalInstance.dismiss();
466 $event.preventDefault();
473 $scope.refreshConjoined = function () {
474 conjoinedSvc.fetch($scope.record_id)
475 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
478 $scope.deleteSelectedConjoined = function () {
479 var peers = $scope.conjoinedGridControls.selectedItems();
481 if (peers.length > 0) {
482 egConfirmDialog.open(
483 egCore.strings.CONFIRM_DELETE_PEERS,
484 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
485 {peers : peers.length}
486 ).result.then(function() {
487 angular.forEach(peers, function (p) {
491 egCore.pcrud.remove(peers).then(function() {
492 return conjoinedSvc.fetch();
494 $scope.conjoinedGridDataProvider.refresh();
499 if ($scope.record_id)
500 conjoinedSvc.fetch($scope.record_id);
502 // ------------------------------------------------------------------
505 $scope.holdingsGridControls = {};
506 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
507 get : function(offset, count) {
508 return this.arrayNotifier(holdingsSvc.copies, offset, count);
512 $scope.add_copies_to_bucket = function() {
513 var copy_list = gatherSelectedHoldingsIds();
514 if (copy_list.length == 0) return;
517 templateUrl: './cat/catalog/t_add_to_bucket',
521 ['$scope','$modalInstance',
522 function($scope , $modalInstance) {
524 $scope.bucket_id = 0;
525 $scope.newBucketName = '';
526 $scope.allBuckets = [];
530 'open-ils.actor.container.retrieve_by_class.authoritative',
531 egCore.auth.token(), egCore.auth.user().id(),
532 'copy', 'staff_client'
533 ).then(function(buckets) { $scope.allBuckets = buckets; });
535 $scope.add_to_bucket = function() {
537 angular.forEach(copy_list, function (cp) {
538 var item = new egCore.idl.ccbi()
539 item.bucket($scope.bucket_id);
540 item.target_copy(cp);
544 'open-ils.actor.container.item.create',
545 egCore.auth.token(), 'copy', item
549 return $q.all(promises).then(function() {
550 $modalInstance.close();
555 $scope.add_to_new_bucket = function() {
556 var bucket = new egCore.idl.ccb();
557 bucket.owner(egCore.auth.user().id());
558 bucket.name($scope.newBucketName);
559 bucket.description('');
560 bucket.btype('staff_client');
562 return egCore.net.request(
564 'open-ils.actor.container.create',
565 egCore.auth.token(), 'copy', bucket
566 ).then(function(bucket) {
567 $scope.bucket_id = bucket;
568 $scope.add_to_bucket();
572 $scope.cancel = function() {
573 $modalInstance.dismiss();
579 $scope.requestItems = function() {
580 var copy_list = gatherSelectedHoldingsIds();
581 if (copy_list.length == 0) return;
584 templateUrl: './cat/catalog/t_request_items',
587 ['$scope','$modalInstance',
588 function($scope , $modalInstance) {
590 $scope.first_user_fetch = true;
594 copy_list : copy_list,
595 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
596 user : egCore.auth.user().id()
599 egUser.get( $scope.hold_data.user ).then(function(u) {
601 $scope.barcode = u.card().barcode();
602 $scope.user_name = egUser.format_name(u);
603 $scope.hold_data.user = u.id();
606 $scope.user_name = '';
608 $scope.$watch('barcode', function (n) {
609 if (!$scope.first_user_fetch) {
610 egUser.getByBarcode(n).then(function(u) {
612 $scope.user_name = egUser.format_name(u);
613 $scope.hold_data.user = u.id();
616 $scope.user_name = '';
617 delete $scope.hold_data.user;
620 $scope.first_user_fetch = false;
623 $scope.ok = function(h) {
626 hold_type : h.hold_type,
627 pickup_lib: h.pickup_lib.id(),
633 'open-ils.circ.holds.test_and_create.batch.override',
634 egCore.auth.token(), args, h.copy_list
637 $modalInstance.close();
640 $scope.cancel = function($event) {
641 $modalInstance.dismiss();
642 $event.preventDefault();
648 $scope.replaceBarcodes = function() {
649 var copy_list = gatherSelectedRawCopies();
650 if (copy_list.length == 0) return;
652 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
654 angular.forEach(copy_list, function (cp) {
656 templateUrl: './cat/share/t_replace_barcode',
659 ['$scope','$modalInstance',
660 function($scope , $modalInstance) {
661 $scope.isModal = true;
662 $scope.focusBarcode = false;
663 $scope.focusBarcode2 = true;
664 $scope.barcode1 = cp.barcode();
666 $scope.updateBarcode = function() {
667 $scope.copyNotFound = false;
668 $scope.updateOK = false;
670 egCore.pcrud.search('acp',
671 {deleted : 'f', barcode : $scope.barcode1})
672 .then(function(copy) {
675 $scope.focusBarcode = true;
676 $scope.copyNotFound = true;
680 $scope.copyId = copy.id();
681 copy.barcode($scope.barcode2);
683 egCore.pcrud.update(copy).then(function(stat) {
684 $scope.updateOK = stat;
685 $scope.focusBarcode = true;
686 holdingsSvc.fetchAgain().then(function (){
687 holdingsGridDataProviderRef.refresh();
692 $modalInstance.close();
695 $scope.cancel = function($event) {
696 $modalInstance.dismiss();
697 $event.preventDefault();
705 // refresh the list of holdings when the record_id is changed.
706 $scope.holdings_record_id_changed = function(id) {
707 if ($scope.record_id != id) $scope.record_id = id;
708 console.log('record id changed to ' + id + ', loading new holdings');
710 rid : $scope.record_id,
711 org : $scope.holdings_ou,
712 copy: $scope.holdings_show_copies,
713 vol : $scope.holdings_show_vols,
714 empty: $scope.holdings_show_empty
716 $scope.holdingsGridDataProvider.refresh();
720 // refresh the list of holdings when the filter lib is changed.
721 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
722 $scope.holdings_ou_changed = function(org) {
723 $scope.holdings_ou = org;
725 rid : $scope.record_id,
726 org : $scope.holdings_ou,
727 copy: $scope.holdings_show_copies,
728 vol : $scope.holdings_show_vols,
729 empty: $scope.holdings_show_empty
731 $scope.holdingsGridDataProvider.refresh();
735 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
737 egCore.hatch.setItem('cat.' + cb, newVal);
738 if (!norefresh) holdingsSvc.fetch({
739 rid : $scope.record_id,
740 org : $scope.holdings_ou,
741 copy: $scope.holdings_show_copies,
742 vol : $scope.holdings_show_vols,
743 empty: $scope.holdings_show_empty
745 $scope.holdingsGridDataProvider.refresh();
749 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
750 if (typeof x == 'undefined') x = true;
751 $scope.holdings_cb_changed('holdings_show_vols',x,true);
752 $('#holdings_show_vols').prop('checked', x);
754 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
755 if (typeof x == 'undefined') x = true;
756 $scope.holdings_cb_changed('holdings_show_copies',x,true);
757 $('#holdings_show_copies').prop('checked', x);
759 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
760 if (typeof x == 'undefined') x = true;
761 $scope.holdings_cb_changed('holdings_show_empty',x);
762 $('#holdings_show_empty').prop('checked', x);
767 $scope.vols_not_shown = function () {
768 return !$scope.holdings_show_vols;
771 $scope.copies_not_shown = function () {
772 return !$scope.holdings_show_copies;
775 $scope.holdings_checkbox_handler = function (item) {
776 $scope.holdings_cb_changed(item.checkbox,item.checked);
779 function gatherSelectedHoldingsIds () {
782 $scope.holdingsGridControls.selectedItems(),
783 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
788 function gatherSelectedRawCopies () {
791 $scope.holdingsGridControls.selectedItems(),
792 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
797 function gatherSelectedVolumeIds () {
800 $scope.holdingsGridControls.selectedItems(),
802 if (cn_id_list.indexOf(item.call_number.id) == -1)
803 cn_id_list.push(item.call_number.id)
809 $scope.selectedHoldingsDelete = function (vols, copies) {
812 var perCnCopies = {};
818 $scope.holdingsGridControls.selectedItems(),
820 if (vols && item.raw_call_number) {
821 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
822 cnHash[item.call_number.id].isdeleted(1);
825 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
828 var cn_id = cp.call_number().id();
829 if (!cnHash[cn_id]) {
830 cnHash[cn_id] = cp.call_number();
831 perCnCopies[cn_id] = [cp];
833 perCnCopies[cn_id].push(cp);
835 cp.call_number(cn_id); // prevent loops in JSON-ification
842 angular.forEach(perCnCopies, function (v, k) {
844 cnHash[k].isdeleted(1);
851 angular.forEach(cnHash, function (v, k) {
855 if (cnList.length == 0) return;
857 egConfirmDialog.open(
858 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
859 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
860 {copies : cp_count, volumes : cn_count}
861 ).result.then(function() {
864 'open-ils.cat.asset.volume.fleshed.batch.update.override',
865 egCore.auth.token(), cnList, 1, {}
866 ).then(function(update_count) {
867 $scope.holdingsGridDataProvider.refresh();
871 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
872 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
873 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
875 spawnHoldingsAdd = function (vols,copies){
877 if (copies) { // just a copy on existing volumes
878 angular.forEach(gatherSelectedVolumeIds(), function (v) {
879 raw.push( {callnumber : v} );
883 $scope.holdingsGridControls.selectedItems(),
885 raw.push({owner : item.owner_id});
890 if (raw.length == 0) raw.push({});
894 'open-ils.actor.anon_cache.set_value',
895 null, 'edit-these-copies', {
896 record_id: $scope.record_id,
901 ).then(function(key) {
903 var url = egCore.env.basePath + 'cat/volcopy/' + key;
904 $timeout(function() { $window.open(url, '_blank') });
906 alert('Could not create anonymous cache key!');
910 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
911 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
913 spawnHoldingsEdit = function (hide_vols,hide_copies){
916 'open-ils.actor.anon_cache.set_value',
917 null, 'edit-these-copies', {
918 record_id: $scope.record_id,
919 copies: gatherSelectedHoldingsIds(),
920 hide_vols : hide_vols,
921 hide_copies : hide_copies
923 ).then(function(key) {
925 var url = egCore.env.basePath + 'cat/volcopy/' + key;
926 $timeout(function() { $window.open(url, '_blank') });
928 alert('Could not create anonymous cache key!');
932 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
933 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
934 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
936 $scope.selectedHoldingsItemStatus = function (){
937 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
938 $timeout(function() { $window.open(url, '_blank') });
941 $scope.markVolAsItemTarget = function() {
942 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
943 egCore.hatch.setLocalItem(
944 'eg.cat.item_transfer_target',
945 $scope.holdingsGridControls.selectedItems()[0].call_number.id
950 $scope.markLibAsVolTarget = function() {
951 egCore.hatch.setLocalItem(
952 'eg.cat.volume_transfer_target',
953 $scope.holdingsGridControls.selectedItems()[0].owner_id
957 $scope.selectedHoldingsItemStatusDetail = function (){
959 gatherSelectedHoldingsIds(),
961 var url = egCore.env.basePath +
963 $timeout(function() { $window.open(url, '_blank') });
968 $scope.transferVolumes = function (){
969 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
974 'open-ils.open-ils.cat.asset.volume.batch.transfer.override',
975 egCore.auth.token(), {
976 docid : $scope.record_id,
978 volumes : gatherSelectedVolumeIds()
980 ).then(function(success) {
982 holdingsSvc.fetchAgain().then(function() {
983 $scope.holdingsGridDataProvider.refresh();
986 alert('Could not transfer volumes!');
993 $scope.transferItems = function (){
994 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
995 var copy_ids = gatherSelectedHoldingsIds();
996 if (xfer_target && copy_ids.length > 0) {
999 'open-ils.cat.transfer_copies_to_volume',
1000 egCore.auth.token(),
1004 function(resp) { // oncomplete
1005 var evt = egCore.evt.parse(resp);
1007 egConfirmDialog.open(
1008 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1009 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1010 {'evt_desc': evt.desc}
1011 ).result.then(function() {
1014 'open-ils.cat.transfer_copies_to_volume.override',
1015 egCore.auth.token(),
1018 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1019 ).then(function(resp) {
1020 holdingsSvc.fetchAgain().then(function() {
1021 $scope.holdingsGridDataProvider.refresh();
1026 holdingsSvc.fetchAgain().then(function() {
1027 $scope.holdingsGridDataProvider.refresh();
1037 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1039 gatherSelectedHoldingsIds(),
1041 var url = egCore.env.basePath +
1042 'cat/item/' + cid + '/triggered_events';
1043 $timeout(function() { $window.open(url, '_blank') });
1048 $scope.selectedHoldingsItemStatusHolds = function (){
1050 gatherSelectedHoldingsIds(),
1052 var url = egCore.env.basePath +
1053 'cat/item/' + cid + '/holds';
1054 $timeout(function() { $window.open(url, '_blank') });
1059 $scope.selectedHoldingsDamaged = function () {
1060 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
1061 holdingsSvc.fetchAgain().then(function() {
1062 $scope.holdingsGridDataProvider.refresh();
1067 $scope.selectedHoldingsMissing = function () {
1068 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1069 holdingsSvc.fetchAgain().then(function() {
1070 $scope.holdingsGridDataProvider.refresh();
1075 $scope.attach_to_peer_bib = function() {
1076 var copy_list = gatherSelectedHoldingsIds();
1077 if (copy_list.length == 0) return;
1079 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1080 if (!target_record) return;
1082 return $modal.open({
1083 templateUrl: './cat/catalog/t_conjoined_selector',
1086 ['$scope','$modalInstance',
1087 function($scope , $modalInstance) {
1088 $scope.update = false;
1090 $scope.peer_type = null;
1091 $scope.peer_type_list = [];
1092 conjoinedSvc.get_peer_types().then(function(list){
1093 $scope.peer_type_list = list;
1096 $scope.ok = function(type) {
1099 angular.forEach(copy_list, function (cp) {
1100 var n = new egCore.idl.bpbcm();
1102 n.peer_record(target_record);
1105 promises.push(egCore.pcrud.create(n));
1108 return $q.all(promises).then(function(){$modalInstance.close()});
1111 $scope.cancel = function($event) {
1112 $modalInstance.dismiss();
1113 $event.preventDefault();
1121 // ------------------------------------------------------------------
1123 var provider = egGridDataProvider.instance({});
1124 $scope.hold_grid_data_provider = provider;
1125 $scope.grid_actions = egHoldGridActions;
1126 $scope.grid_actions.refresh = function () { provider.refresh() };
1127 $scope.hold_grid_controls = {};
1129 var hold_ids = []; // current list of holds
1130 function fetchHolds(offset, count) {
1131 var ids = hold_ids.slice(offset, offset + count);
1132 return egHolds.fetch_holds(ids).then(null, null,
1133 function(hold_data) {
1139 provider.get = function(offset, count) {
1140 if ($scope.record_tab != 'holds') return $q.when();
1141 var deferred = $q.defer();
1142 hold_ids = []; // no caching ATM
1147 'open-ils.circ.holds.retrieve_all_from_title',
1148 egCore.auth.token(), $scope.record_id,
1149 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
1151 function(hold_data) {
1152 angular.forEach(hold_data, function(list, type) {
1153 hold_ids = hold_ids.concat(list);
1155 fetchHolds(offset, count).then(
1156 deferred.resolve, null, deferred.notify);
1160 return deferred.promise;
1163 $scope.detail_view = function(action, user_data, items) {
1165 $scope.detail_hold_id = h.hold.id();
1169 $scope.list_view = function(items) {
1170 $scope.detail_hold_id = null;
1173 // refresh the list of record holds when the pickup lib is changed.
1174 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1175 $scope.pickup_ou_changed = function(org) {
1176 $scope.pickup_ou = org;
1180 $scope.print_holds = function() {
1182 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1184 hold : egCore.idl.toHash(item.hold),
1185 patron_last : item.patron_last,
1186 patron_alias : item.patron_alias,
1187 patron_barcode : item.patron_barcode,
1188 copy : egCore.idl.toHash(item.copy),
1189 volume : egCore.idl.toHash(item.volume),
1190 title : item.mvr.title(),
1191 author : item.mvr.author()
1195 egCore.print.print({
1196 context : 'receipt',
1197 template : 'holds_for_bib',
1198 scope : {holds : holds}
1202 $scope.mark_hold_transfer_dest = function() {
1203 egCore.hatch.setLocalItem(
1204 'eg.circ.hold.title_transfer_target', $scope.record_id);
1207 // UI presents this option as "all holds"
1208 $scope.transfer_holds_to_marked = function() {
1209 var hold_ids = $scope.hold_grid_controls.allItems().map(
1210 function(hold_data) {return hold_data.hold.id()});
1211 egHolds.transfer_to_marked_title(hold_ids);
1214 // ------------------------------------------------------------------
1215 // Initialize the selected tab
1217 function init_cat_url() {
1218 // Set the initial catalog URL. This only happens once.
1219 // The URL is otherwise generated through user navigation.
1220 if ($scope.catalog_url) return;
1222 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1224 // A record ID in the path indicates a request for the record-
1226 if ($routeParams.record_id) {
1227 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1230 $scope.catalog_url = url;
1233 function init_parts_url() {
1234 $scope.parts_url = $location
1238 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1242 $scope.set_record_tab = function(tab) {
1243 $scope.record_tab = tab;
1256 $scope.detail_hold_record_id = $scope.record_id;
1257 // refresh the holds grid
1263 $scope.set_default_record_tab = function() {
1264 egCore.hatch.setLocalItem(
1265 'eg.cat.default_record_tab', $scope.record_tab);
1266 $timeout(function(){$scope.default_tab = $scope.record_tab});
1270 if ($scope.record_id) {
1271 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1272 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1275 tab = $routeParams.record_tab || 'catalog';
1277 $scope.set_record_tab(tab);
1281 .controller('AuthorityCtrl',
1282 ['$scope','$routeParams','$location','$window','$q','egCore',
1283 function($scope , $routeParams , $location , $window , $q , egCore) {
1285 // set record ID on page load if available...
1286 $scope.authority_id = $routeParams.authority_id;
1288 if ($routeParams.authority_id) $scope.from_route = true;
1289 else $scope.from_route = false;
1291 $scope.stop_unload = false;
1294 .controller('URLVerifyCtrl',
1295 ['$scope','$location',
1296 function($scope , $location) {
1297 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1300 .controller('VandelayCtrl',
1301 ['$scope','$location',
1302 function($scope , $location) {
1303 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
1306 .controller('ManageAuthoritiesCtrl',
1307 ['$scope','$location',
1308 function($scope , $location) {
1309 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1312 .controller('BatchEditCtrl',
1313 ['$scope','$location','$routeParams',
1314 function($scope , $location , $routeParams) {
1315 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1316 if ($routeParams.container_type) {
1317 switch ($routeParams.container_type) {
1319 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1322 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1329 .filter('boolText', function(){
1330 return function (v) {
1335 .factory('conjoinedSvc',
1337 function(egCore , $q) {
1340 items : [], // record search results
1341 index : 0, // search grid index
1348 bpbcm : ['target_copy','peer_type'],
1349 acp : ['call_number'],
1351 bre : ['simple_record']
1353 // avoid fetching the MARC blob by specifying which
1354 // fields on the bre to select. More may be needed.
1355 // note that fleshed fields are explicitly selected.
1356 select : { bre : ['id'] },
1357 order_by : { bpbcm : ['id'] },
1360 // resolved with the last received copy
1361 service.fetch = function(rid) {
1362 if (!rid && !service.rid) return $q.when();
1364 if (rid) service.rid = rid;
1368 return egCore.pcrud.search(
1370 {peer_record : service.rid},
1373 ).then( function(list) { // finished
1374 service.items = list;
1375 return service.items;
1379 // returns a promise resolved with the list of peer bib types
1380 service.get_peer_types = function() {
1382 return $q.when(egCore.env.bpt.list);
1384 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
1385 .then(function(list) {
1386 egCore.env.absorbList(list, 'bpt');