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 gatherSelectedVolumeIds () {
802 $scope.holdingsGridControls.selectedItems(),
804 if (cn_id_list.indexOf(item.call_number.id) == -1)
805 cn_id_list.push(item.call_number.id)
811 $scope.selectedHoldingsDelete = function (vols, copies) {
814 var perCnCopies = {};
820 $scope.holdingsGridControls.selectedItems(),
822 if (vols && item.raw_call_number) {
823 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
824 cnHash[item.call_number.id].isdeleted(1);
827 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
830 var cn_id = cp.call_number().id();
831 if (!cnHash[cn_id]) {
832 cnHash[cn_id] = cp.call_number();
833 perCnCopies[cn_id] = [cp];
835 perCnCopies[cn_id].push(cp);
837 cp.call_number(cn_id); // prevent loops in JSON-ification
844 angular.forEach(perCnCopies, function (v, k) {
846 cnHash[k].isdeleted(1);
853 angular.forEach(cnHash, function (v, k) {
857 if (cnList.length == 0) return;
859 egConfirmDialog.open(
860 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
861 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
862 {copies : cp_count, volumes : cn_count}
863 ).result.then(function() {
866 'open-ils.cat.asset.volume.fleshed.batch.update.override',
867 egCore.auth.token(), cnList, 1, {}
868 ).then(function(update_count) {
869 $scope.holdingsGridDataProvider.refresh();
873 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
874 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
875 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
877 spawnHoldingsAdd = function (vols,copies){
879 if (copies) { // just a copy on existing volumes
880 angular.forEach(gatherSelectedVolumeIds(), function (v) {
881 raw.push( {callnumber : v} );
885 $scope.holdingsGridControls.selectedItems(),
887 raw.push({owner : item.owner_id});
892 if (raw.length == 0) raw.push({});
896 'open-ils.actor.anon_cache.set_value',
897 null, 'edit-these-copies', {
898 record_id: $scope.record_id,
903 ).then(function(key) {
905 var url = egCore.env.basePath + 'cat/volcopy/' + key;
906 $timeout(function() { $window.open(url, '_blank') });
908 alert('Could not create anonymous cache key!');
912 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
913 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
915 spawnHoldingsEdit = function (hide_vols,hide_copies){
918 'open-ils.actor.anon_cache.set_value',
919 null, 'edit-these-copies', {
920 record_id: $scope.record_id,
921 copies: gatherSelectedHoldingsIds(),
922 hide_vols : hide_vols,
923 hide_copies : hide_copies
925 ).then(function(key) {
927 var url = egCore.env.basePath + 'cat/volcopy/' + key;
928 $timeout(function() { $window.open(url, '_blank') });
930 alert('Could not create anonymous cache key!');
934 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
935 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
936 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
938 $scope.selectedHoldingsItemStatus = function (){
939 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
940 $timeout(function() { $window.open(url, '_blank') });
943 $scope.markVolAsItemTarget = function() {
944 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
945 egCore.hatch.setLocalItem(
946 'eg.cat.item_transfer_target',
947 $scope.holdingsGridControls.selectedItems()[0].call_number.id
952 $scope.markLibAsVolTarget = function() {
953 egCore.hatch.setLocalItem(
954 'eg.cat.volume_transfer_target',
955 $scope.holdingsGridControls.selectedItems()[0].owner_id
959 $scope.selectedHoldingsItemStatusDetail = function (){
961 gatherSelectedHoldingsIds(),
963 var url = egCore.env.basePath +
965 $timeout(function() { $window.open(url, '_blank') });
970 $scope.transferVolumes = function (){
971 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
976 'open-ils.open-ils.cat.asset.volume.batch.transfer.override',
977 egCore.auth.token(), {
978 docid : $scope.record_id,
980 volumes : gatherSelectedVolumeIds()
982 ).then(function(success) {
984 holdingsSvcInst.fetchAgain().then(function() {
985 $scope.holdingsGridDataProvider.refresh();
988 alert('Could not transfer volumes!');
995 $scope.transferItems = function (){
996 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
997 var copy_ids = gatherSelectedHoldingsIds();
998 if (xfer_target && copy_ids.length > 0) {
1001 'open-ils.cat.transfer_copies_to_volume',
1002 egCore.auth.token(),
1006 function(resp) { // oncomplete
1007 var evt = egCore.evt.parse(resp);
1009 egConfirmDialog.open(
1010 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1011 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1012 {'evt_desc': evt.desc}
1013 ).result.then(function() {
1016 'open-ils.cat.transfer_copies_to_volume.override',
1017 egCore.auth.token(),
1020 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1021 ).then(function(resp) {
1022 holdingsSvcInst.fetchAgain().then(function() {
1023 $scope.holdingsGridDataProvider.refresh();
1028 holdingsSvcInst.fetchAgain().then(function() {
1029 $scope.holdingsGridDataProvider.refresh();
1039 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1041 gatherSelectedHoldingsIds(),
1043 var url = egCore.env.basePath +
1044 'cat/item/' + cid + '/triggered_events';
1045 $timeout(function() { $window.open(url, '_blank') });
1050 $scope.selectedHoldingsItemStatusHolds = function (){
1052 gatherSelectedHoldingsIds(),
1054 var url = egCore.env.basePath +
1055 'cat/item/' + cid + '/holds';
1056 $timeout(function() { $window.open(url, '_blank') });
1061 $scope.selectedHoldingsDamaged = function () {
1062 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
1063 holdingsSvcInst.fetchAgain().then(function() {
1064 $scope.holdingsGridDataProvider.refresh();
1069 $scope.selectedHoldingsMissing = function () {
1070 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1071 holdingsSvcInst.fetchAgain().then(function() {
1072 $scope.holdingsGridDataProvider.refresh();
1077 $scope.attach_to_peer_bib = function() {
1078 var copy_list = gatherSelectedHoldingsIds();
1079 if (copy_list.length == 0) return;
1081 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1082 if (!target_record) return;
1084 return $modal.open({
1085 templateUrl: './cat/catalog/t_conjoined_selector',
1088 ['$scope','$modalInstance',
1089 function($scope , $modalInstance) {
1090 $scope.update = false;
1092 $scope.peer_type = null;
1093 $scope.peer_type_list = [];
1094 conjoinedSvc.get_peer_types().then(function(list){
1095 $scope.peer_type_list = list;
1098 $scope.ok = function(type) {
1101 angular.forEach(copy_list, function (cp) {
1102 var n = new egCore.idl.bpbcm();
1104 n.peer_record(target_record);
1107 promises.push(egCore.pcrud.create(n));
1110 return $q.all(promises).then(function(){$modalInstance.close()});
1113 $scope.cancel = function($event) {
1114 $modalInstance.dismiss();
1115 $event.preventDefault();
1123 // ------------------------------------------------------------------
1125 var provider = egGridDataProvider.instance({});
1126 $scope.hold_grid_data_provider = provider;
1127 $scope.grid_actions = egHoldGridActions;
1128 $scope.grid_actions.refresh = function () { provider.refresh() };
1129 $scope.hold_grid_controls = {};
1131 var hold_ids = []; // current list of holds
1132 function fetchHolds(offset, count) {
1133 var ids = hold_ids.slice(offset, offset + count);
1134 return egHolds.fetch_holds(ids).then(null, null,
1135 function(hold_data) {
1141 provider.get = function(offset, count) {
1142 if ($scope.record_tab != 'holds') return $q.when();
1143 var deferred = $q.defer();
1144 hold_ids = []; // no caching ATM
1149 'open-ils.circ.holds.retrieve_all_from_title',
1150 egCore.auth.token(), $scope.record_id,
1151 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
1153 function(hold_data) {
1154 angular.forEach(hold_data, function(list, type) {
1155 hold_ids = hold_ids.concat(list);
1157 fetchHolds(offset, count).then(
1158 deferred.resolve, null, deferred.notify);
1162 return deferred.promise;
1165 $scope.detail_view = function(action, user_data, items) {
1167 $scope.detail_hold_id = h.hold.id();
1171 $scope.list_view = function(items) {
1172 $scope.detail_hold_id = null;
1175 // refresh the list of record holds when the pickup lib is changed.
1176 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1177 $scope.pickup_ou_changed = function(org) {
1178 $scope.pickup_ou = org;
1182 $scope.print_holds = function() {
1184 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1186 hold : egCore.idl.toHash(item.hold),
1187 patron_last : item.patron_last,
1188 patron_alias : item.patron_alias,
1189 patron_barcode : item.patron_barcode,
1190 copy : egCore.idl.toHash(item.copy),
1191 volume : egCore.idl.toHash(item.volume),
1192 title : item.mvr.title(),
1193 author : item.mvr.author()
1197 egCore.print.print({
1198 context : 'receipt',
1199 template : 'holds_for_bib',
1200 scope : {holds : holds}
1204 $scope.mark_hold_transfer_dest = function() {
1205 egCore.hatch.setLocalItem(
1206 'eg.circ.hold.title_transfer_target', $scope.record_id);
1209 // UI presents this option as "all holds"
1210 $scope.transfer_holds_to_marked = function() {
1211 var hold_ids = $scope.hold_grid_controls.allItems().map(
1212 function(hold_data) {return hold_data.hold.id()});
1213 egHolds.transfer_to_marked_title(hold_ids);
1216 // ------------------------------------------------------------------
1217 // Initialize the selected tab
1219 function init_cat_url() {
1220 // Set the initial catalog URL. This only happens once.
1221 // The URL is otherwise generated through user navigation.
1222 if ($scope.catalog_url) return;
1224 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1226 // A record ID in the path indicates a request for the record-
1228 if ($routeParams.record_id) {
1229 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1232 $scope.catalog_url = url;
1235 function init_parts_url() {
1236 $scope.parts_url = $location
1240 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1244 $scope.set_record_tab = function(tab) {
1245 $scope.record_tab = tab;
1258 $scope.detail_hold_record_id = $scope.record_id;
1259 // refresh the holds grid
1265 $scope.set_default_record_tab = function() {
1266 egCore.hatch.setLocalItem(
1267 'eg.cat.default_record_tab', $scope.record_tab);
1268 $timeout(function(){$scope.default_tab = $scope.record_tab});
1272 if ($scope.record_id) {
1273 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1274 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1277 tab = $routeParams.record_tab || 'catalog';
1279 $scope.set_record_tab(tab);
1283 .controller('AuthorityCtrl',
1284 ['$scope','$routeParams','$location','$window','$q','egCore',
1285 function($scope , $routeParams , $location , $window , $q , egCore) {
1287 // set record ID on page load if available...
1288 $scope.authority_id = $routeParams.authority_id;
1290 if ($routeParams.authority_id) $scope.from_route = true;
1291 else $scope.from_route = false;
1293 $scope.stop_unload = false;
1296 .controller('URLVerifyCtrl',
1297 ['$scope','$location',
1298 function($scope , $location) {
1299 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1302 .controller('VandelayCtrl',
1303 ['$scope','$location',
1304 function($scope , $location) {
1305 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
1308 .controller('ManageAuthoritiesCtrl',
1309 ['$scope','$location',
1310 function($scope , $location) {
1311 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1314 .controller('BatchEditCtrl',
1315 ['$scope','$location','$routeParams',
1316 function($scope , $location , $routeParams) {
1317 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1318 if ($routeParams.container_type) {
1319 switch ($routeParams.container_type) {
1321 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1324 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1331 .filter('boolText', function(){
1332 return function (v) {
1337 .factory('conjoinedSvc',
1339 function(egCore , $q) {
1342 items : [], // record search results
1343 index : 0, // search grid index
1350 bpbcm : ['target_copy','peer_type'],
1351 acp : ['call_number'],
1353 bre : ['simple_record']
1355 // avoid fetching the MARC blob by specifying which
1356 // fields on the bre to select. More may be needed.
1357 // note that fleshed fields are explicitly selected.
1358 select : { bre : ['id'] },
1359 order_by : { bpbcm : ['id'] },
1362 // resolved with the last received copy
1363 service.fetch = function(rid) {
1364 if (!rid && !service.rid) return $q.when();
1366 if (rid) service.rid = rid;
1370 return egCore.pcrud.search(
1372 {peer_record : service.rid},
1375 ).then( function(list) { // finished
1376 service.items = list;
1377 return service.items;
1381 // returns a promise resolved with the list of peer bib types
1382 service.get_peer_types = function() {
1384 return $q.when(egCore.env.bpt.list);
1386 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
1387 .then(function(list) {
1388 egCore.env.absorbList(list, 'bpt');