4 * currently, this app doesn't use routes for each sub-ui, because
5 * reloading the catalog each time is sloooow. better so far to
6 * swap out divs w/ ng-if / ng-show / ng-hide as needed.
10 angular.module('egCatalogApp', ['ui.bootstrap','ngRoute','ngLocationUpdate','egCoreMod','egGridMod', 'egMarcMod', 'egUserMod', 'egHoldingsMod'])
12 .config(function($routeProvider, $locationProvider, $compileProvider) {
13 $locationProvider.html5Mode(true);
14 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
16 var resolver = {delay : ['egCore','egStartup','egUser', function(egCore, egStartup, egUser) {
17 egCore.env.classLoaders.aous = function() {
18 return egCore.org.settings([
19 'cat.marc_control_number_identifier'
20 ]).then(function(settings) {
21 // local settings are cached within egOrg. Caching them
22 // again in egEnv just simplifies the syntax for access.
23 egCore.env.aous = settings;
26 egCore.env.loadClasses.push('aous');
30 $routeProvider.when('/cat/catalog/index', {
31 templateUrl: './cat/catalog/t_catalog',
32 controller: 'CatalogCtrl',
36 $routeProvider.when('/cat/catalog/retrieve_by_id', {
37 templateUrl: './cat/catalog/t_retrieve_by_id',
38 controller: 'CatalogRecordRetrieve',
42 $routeProvider.when('/cat/catalog/retrieve_by_tcn', {
43 templateUrl: './cat/catalog/t_retrieve_by_tcn',
44 controller: 'CatalogRecordRetrieve',
48 $routeProvider.when('/cat/catalog/new_bib', {
49 templateUrl: './cat/catalog/t_new_bib',
50 controller: 'NewBibCtrl',
54 // create some catalog page-specific mappings
55 $routeProvider.when('/cat/catalog/record/:record_id', {
56 templateUrl: './cat/catalog/t_catalog',
57 controller: 'CatalogCtrl',
61 // create some catalog page-specific mappings
62 $routeProvider.when('/cat/catalog/record/:record_id/:record_tab', {
63 templateUrl: './cat/catalog/t_catalog',
64 controller: 'CatalogCtrl',
68 $routeProvider.when('/cat/catalog/batchEdit', {
69 templateUrl: './cat/catalog/t_batchedit',
70 controller: 'BatchEditCtrl',
74 $routeProvider.when('/cat/catalog/batchEdit/:container_type/:container_id', {
75 templateUrl: './cat/catalog/t_batchedit',
76 controller: 'BatchEditCtrl',
80 $routeProvider.when('/cat/catalog/vandelay', {
81 templateUrl: './cat/catalog/t_vandelay',
82 controller: 'VandelayCtrl',
86 $routeProvider.when('/cat/catalog/verifyURLs', {
87 templateUrl: './cat/catalog/t_verifyurls',
88 controller: 'URLVerifyCtrl',
92 $routeProvider.when('/cat/catalog/manageAuthorities', {
93 templateUrl: './cat/catalog/t_manageauthorities',
94 controller: 'ManageAuthoritiesCtrl',
98 $routeProvider.when('/cat/catalog/authority/:authority_id/marc_edit', {
99 templateUrl: './cat/catalog/t_authority',
100 controller: 'AuthorityCtrl',
104 $routeProvider.otherwise({redirectTo : '/cat/catalog/index'});
110 .controller('CatalogRecordRetrieve',
111 ['$scope','$routeParams','$location','$q','egCore',
112 function($scope , $routeParams , $location , $q , egCore ) {
114 $scope.focusMe = true;
116 // jump to the patron checkout UI
117 function loadRecord(record_id) {
119 .path('/cat/catalog/record/' + record_id);
122 $scope.submitId = function(args) {
123 $scope.recordNotFound = null;
124 if (!args.record_id) return;
126 // blur so next time it's set to true it will re-apply select()
127 $scope.selectMe = false;
129 return loadRecord(args.record_id);
132 $scope.submitTCN = function(args) {
133 $scope.recordNotFound = null;
134 $scope.moreRecordsFound = null;
135 if (!args.record_tcn) return;
137 // blur so next time it's set to true it will re-apply select()
138 $scope.selectMe = false;
143 'open-ils.search.biblio.tcn',
146 .then(function(resp) { // get_barcodes
148 if (evt = egCore.evt.parse(resp)) {
154 $scope.recordNotFound = args.record_tcn;
155 $scope.selectMe = true;
159 if (resp.count > 1) {
160 $scope.moreRecordsFound = args.record_tcn;
161 $scope.selectMe = true;
165 var record_id = resp.ids[0];
166 return loadRecord(record_id);
172 .controller('NewBibCtrl',
173 ['$scope','$routeParams','$location','$window','$q','egCore',
174 'egGridDataProvider','egHoldGridActions','$timeout','holdingsSvc',
175 function($scope , $routeParams , $location , $window , $q , egCore) {
177 $scope.have_template = false;
178 $scope.marc_template = '';
179 $scope.stop_unload = false;
180 $scope.template_list = [];
181 $scope.template_name = '';
182 $scope.new_bib_id = 0;
186 'open-ils.cat.marc_template.types.retrieve'
187 ).then(function(resp) {
188 angular.forEach(resp, function(name) {
189 $scope.template_list.push(name);
191 $scope.template_list.sort();
193 $scope.template_name = egCore.hatch.getSessionItem('eg.cat.last_bib_marc_template');
194 if (!$scope.template_name) {
195 egCore.hatch.getItem('cat.default_bib_marc_template').then(function(template) {
196 $scope.template_name = template;
200 $scope.loadTemplate = function() {
201 if ($scope.template_name) {
204 'open-ils.cat.biblio.marc_template.retrieve',
206 ).then(function(template) {
207 $scope.marc_template = template;
208 $scope.have_template = true;
209 egCore.hatch.setSessionItem('eg.cat.last_bib_marc_template', $scope.template_name);
214 $scope.setDefaultTemplate = function() {
215 var hatch_key = "cat.default_bib_marc_template";
216 if ($scope.template_name) {
217 egCore.hatch.setItem(hatch_key, $scope.template_name);
219 egCore.hatch.removeItem(hatch_key);
223 $scope.$watch('new_bib_id', function(newVal, oldVal) {
225 $location.path('/cat/catalog/record/' + $scope.new_bib_id);
232 .controller('CatalogCtrl',
233 ['$scope','$routeParams','$location','$window','$q','egCore','egHolds','egCirc','egConfirmDialog',
234 'egGridDataProvider','egHoldGridActions','$timeout','$modal','holdingsSvc','egUser','conjoinedSvc',
235 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc, egConfirmDialog,
236 egGridDataProvider , egHoldGridActions , $timeout , $modal , holdingsSvc , egUser , conjoinedSvc) {
238 var holdingsSvcInst = new holdingsSvc();
240 // set record ID on page load if available...
241 $scope.record_id = $routeParams.record_id;
242 $scope.summary_pane_record;
244 if ($routeParams.record_id) $scope.from_route = true;
245 else $scope.from_route = false;
247 // will hold a ref to the opac iframe
248 $scope.opac_iframe = null;
249 $scope.parts_iframe = null;
251 $scope.search_result_index = 1;
252 $scope.search_result_hit_count = 1;
255 'opac_iframe.dom.contentWindow.search_result_index',
257 if (!isNaN(parseInt(n)))
258 $scope.search_result_index = n + 1;
263 'opac_iframe.dom.contentWindow.search_result_hit_count',
265 if (!isNaN(parseInt(n)))
266 $scope.search_result_hit_count = n;
270 $scope.in_opac_call = false;
271 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
272 if ($scope.opac_iframe) {
273 if (force_opac_tab) $scope.record_tab = 'catalog';
274 $scope.in_opac_call = true;
275 $scope.opac_iframe.dom.contentWindow[opac_frame_function]();
276 if (opac_frame_function == 'rdetailBackToResults') {
277 $location.update_path('/cat/catalog/index');
282 $scope.add_to_record_bucket = function() {
283 var recId = $scope.record_id;
285 templateUrl: './cat/catalog/t_add_to_bucket',
289 ['$scope','$modalInstance',
290 function($scope , $modalInstance) {
292 $scope.bucket_id = 0;
293 $scope.newBucketName = '';
294 $scope.allBuckets = [];
297 'open-ils.actor.container.retrieve_by_class.authoritative',
298 egCore.auth.token(), egCore.auth.user().id(),
299 'biblio', 'staff_client'
300 ).then(function(buckets) { $scope.allBuckets = buckets; });
302 $scope.add_to_bucket = function() {
303 var item = new egCore.idl.cbrebi();
304 item.bucket($scope.bucket_id);
305 item.target_biblio_record_entry(recId);
308 'open-ils.actor.container.item.create',
309 egCore.auth.token(), 'biblio', item
310 ).then(function(resp) {
311 $modalInstance.close();
315 $scope.add_to_new_bucket = function() {
316 var bucket = new egCore.idl.cbreb();
317 bucket.owner(egCore.auth.user().id());
318 bucket.name($scope.newBucketName);
319 bucket.description('');
320 bucket.btype('staff_client');
324 'open-ils.actor.container.create',
325 egCore.auth.token(), 'biblio', bucket
326 ).then(function(bucket) {
327 $scope.bucket_id = bucket;
328 $scope.add_to_bucket();
332 $scope.cancel = function() {
333 $modalInstance.dismiss();
339 $scope.current_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record');
340 $scope.current_voltransfer_target = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
341 $scope.current_conjoined_target = egCore.hatch.getLocalItem('eg.cat.marked_conjoined_record');
343 $scope.markConjoined = function () {
344 $scope.current_conjoined_target = $scope.record_id;
345 egCore.hatch.setLocalItem('eg.cat.marked_conjoined_record',$scope.record_id);
348 $scope.markVolTransfer = function () {
349 $scope.current_voltransfer_target = $scope.record_id;
350 egCore.hatch.setLocalItem('eg.cat.marked_volume_transfer_record',$scope.record_id);
353 $scope.markOverlay = function () {
354 $scope.current_overlay_target = $scope.record_id;
355 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.record_id);
358 $scope.clearRecordMarks = function () {
359 $scope.current_overlay_target = null;
360 $scope.current_voltransfer_target = null;
361 $scope.current_conjoined_target = null;
362 egCore.hatch.removeLocalItem('eg.cat.marked_volume_transfer_record');
363 egCore.hatch.removeLocalItem('eg.cat.marked_conjoined_record');
364 egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record');
367 $scope.stop_unload = false;
368 $scope.$watch('stop_unload',
369 function(newVal, oldVal) {
370 if (newVal && newVal != oldVal && $scope.opac_iframe) {
371 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
372 return 'There is unsaved data in this record.'
375 if ($scope.opac_iframe)
376 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
381 // Set the "last bib" cookie, if we have that
382 if ($scope.record_id)
383 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
385 $scope.refresh_record_callback = function (record_id) {
386 egCore.pcrud.retrieve('bre', record_id, {
389 bre : ['simple_record','creator','editor']
391 }).then(function(rec) {
392 rec.owner(egCore.org.get(rec.owner()));
393 $scope.summary_pane_record = rec;
399 // also set it when the iframe changes to a new record
400 $scope.handle_page = function(url) {
402 if (!url || url == 'about:blank') {
403 // nothing loaded. If we already have a record ID, leave it.
407 var match = url.match(/\/+opac\/+record\/+(\d+)/);
409 $scope.record_id = match[1];
410 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
411 $scope.holdings_record_id_changed($scope.record_id);
412 conjoinedSvc.fetch($scope.record_id).then(function(){
413 $scope.conjoinedGridDataProvider.refresh();
416 $location.update_path('/cat/catalog/record/' + $scope.record_id);
418 delete $scope.record_id;
419 $scope.from_route = false;
422 // child scope is executing this function, so our digest doesn't fire ... thus,
425 if (!$scope.in_opac_call) {
426 if ($scope.record_id) {
427 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
428 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
430 tab = $routeParams.record_tab || 'catalog';
432 $scope.set_record_tab(tab);
434 $scope.in_opac_call = false;
438 // xulG catalog handlers
439 $scope.handlers = { }
441 // ------------------------------------------------------------------
444 $scope.conjoinedGridControls = {};
445 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
446 get : function(offset, count) {
447 return this.arrayNotifier(conjoinedSvc.items, offset, count);
451 $scope.changeConjoinedType = function () {
452 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
453 angular.forEach(peers, function (p) {
454 p.target_copy(p.target_copy().id());
455 p.peer_type(p.peer_type().id());
458 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
461 templateUrl: './cat/catalog/t_conjoined_selector',
464 ['$scope','$modalInstance',
465 function($scope , $modalInstance) {
466 $scope.update = true;
468 $scope.peer_type = null;
469 $scope.peer_type_list = [];
470 conjoinedSvc.get_peer_types().then(function(list){
471 $scope.peer_type_list = list;
474 $scope.ok = function(type) {
477 angular.forEach(peers, function (p) {
480 promises.push(egCore.pcrud.update(p));
483 return $q.all(promises)
484 .then(function(){$modalInstance.close()})
485 .then(function(){return conjoinedSvc.fetch()})
486 .then(function(){conjoinedGridDataProviderRef.refresh()});
489 $scope.cancel = function($event) {
490 $modalInstance.dismiss();
491 $event.preventDefault();
498 $scope.refreshConjoined = function () {
499 conjoinedSvc.fetch($scope.record_id)
500 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
503 $scope.deleteSelectedConjoined = function () {
504 var peers = $scope.conjoinedGridControls.selectedItems();
506 if (peers.length > 0) {
507 egConfirmDialog.open(
508 egCore.strings.CONFIRM_DELETE_PEERS,
509 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
510 {peers : peers.length}
511 ).result.then(function() {
512 angular.forEach(peers, function (p) {
516 egCore.pcrud.remove(peers).then(function() {
517 return conjoinedSvc.fetch();
519 $scope.conjoinedGridDataProvider.refresh();
524 if ($scope.record_id)
525 conjoinedSvc.fetch($scope.record_id);
527 // ------------------------------------------------------------------
530 $scope.holdingsGridControls = {
531 activateItem : function (item) {
532 $scope.selectedHoldingsVolCopyEdit();
535 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
536 get : function(offset, count) {
537 return this.arrayNotifier(holdingsSvcInst.copies, offset, count);
541 $scope.add_copies_to_bucket = function() {
542 var copy_list = gatherSelectedHoldingsIds();
543 if (copy_list.length == 0) return;
546 templateUrl: './cat/catalog/t_add_to_bucket',
550 ['$scope','$modalInstance',
551 function($scope , $modalInstance) {
553 $scope.bucket_id = 0;
554 $scope.newBucketName = '';
555 $scope.allBuckets = [];
559 'open-ils.actor.container.retrieve_by_class.authoritative',
560 egCore.auth.token(), egCore.auth.user().id(),
561 'copy', 'staff_client'
562 ).then(function(buckets) { $scope.allBuckets = buckets; });
564 $scope.add_to_bucket = function() {
566 angular.forEach(copy_list, function (cp) {
567 var item = new egCore.idl.ccbi()
568 item.bucket($scope.bucket_id);
569 item.target_copy(cp);
573 'open-ils.actor.container.item.create',
574 egCore.auth.token(), 'copy', item
578 return $q.all(promises).then(function() {
579 $modalInstance.close();
584 $scope.add_to_new_bucket = function() {
585 var bucket = new egCore.idl.ccb();
586 bucket.owner(egCore.auth.user().id());
587 bucket.name($scope.newBucketName);
588 bucket.description('');
589 bucket.btype('staff_client');
591 return egCore.net.request(
593 'open-ils.actor.container.create',
594 egCore.auth.token(), 'copy', bucket
595 ).then(function(bucket) {
596 $scope.bucket_id = bucket;
597 $scope.add_to_bucket();
601 $scope.cancel = function() {
602 $modalInstance.dismiss();
608 $scope.requestItems = function() {
609 var copy_list = gatherSelectedHoldingsIds();
610 if (copy_list.length == 0) return;
613 templateUrl: './cat/catalog/t_request_items',
616 ['$scope','$modalInstance',
617 function($scope , $modalInstance) {
619 $scope.first_user_fetch = true;
623 copy_list : copy_list,
624 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
625 user : egCore.auth.user().id()
628 egUser.get( $scope.hold_data.user ).then(function(u) {
630 $scope.barcode = u.card().barcode();
631 $scope.user_name = egUser.format_name(u);
632 $scope.hold_data.user = u.id();
635 $scope.user_name = '';
637 $scope.$watch('barcode', function (n) {
638 if (!$scope.first_user_fetch) {
639 egUser.getByBarcode(n).then(function(u) {
641 $scope.user_name = egUser.format_name(u);
642 $scope.hold_data.user = u.id();
645 $scope.user_name = '';
646 delete $scope.hold_data.user;
649 $scope.first_user_fetch = false;
652 $scope.ok = function(h) {
655 hold_type : h.hold_type,
656 pickup_lib: h.pickup_lib.id(),
662 'open-ils.circ.holds.test_and_create.batch.override',
663 egCore.auth.token(), args, h.copy_list
666 $modalInstance.close();
669 $scope.cancel = function($event) {
670 $modalInstance.dismiss();
671 $event.preventDefault();
677 $scope.replaceBarcodes = function() {
678 var copy_list = gatherSelectedRawCopies();
679 if (copy_list.length == 0) return;
681 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
683 angular.forEach(copy_list, function (cp) {
685 templateUrl: './cat/share/t_replace_barcode',
688 ['$scope','$modalInstance',
689 function($scope , $modalInstance) {
690 $scope.isModal = true;
691 $scope.focusBarcode = false;
692 $scope.focusBarcode2 = true;
693 $scope.barcode1 = cp.barcode();
695 $scope.updateBarcode = function() {
696 $scope.copyNotFound = false;
697 $scope.updateOK = false;
699 egCore.pcrud.search('acp',
700 {deleted : 'f', barcode : $scope.barcode1})
701 .then(function(copy) {
704 $scope.focusBarcode = true;
705 $scope.copyNotFound = true;
709 $scope.copyId = copy.id();
710 copy.barcode($scope.barcode2);
712 egCore.pcrud.update(copy).then(function(stat) {
713 $scope.updateOK = stat;
714 $scope.focusBarcode = true;
715 holdingsSvc.fetchAgain().then(function (){
716 holdingsGridDataProviderRef.refresh();
721 $modalInstance.close();
724 $scope.cancel = function($event) {
725 $modalInstance.dismiss();
726 $event.preventDefault();
734 // refresh the list of holdings when the record_id is changed.
735 $scope.holdings_record_id_changed = function(id) {
736 if ($scope.record_id != id) $scope.record_id = id;
737 console.log('record id changed to ' + id + ', loading new holdings');
738 holdingsSvcInst.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 // refresh the list of holdings when the filter lib is changed.
750 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
751 $scope.holdings_ou_changed = function(org) {
752 $scope.holdings_ou = org;
753 holdingsSvcInst.fetch({
754 rid : $scope.record_id,
755 org : $scope.holdings_ou,
756 copy: $scope.holdings_show_copies,
757 vol : $scope.holdings_show_vols,
758 empty: $scope.holdings_show_empty
760 $scope.holdingsGridDataProvider.refresh();
764 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
766 egCore.hatch.setItem('cat.' + cb, newVal);
767 if (!norefresh) holdingsSvcInst.fetch({
768 rid : $scope.record_id,
769 org : $scope.holdings_ou,
770 copy: $scope.holdings_show_copies,
771 vol : $scope.holdings_show_vols,
772 empty: $scope.holdings_show_empty
774 $scope.holdingsGridDataProvider.refresh();
778 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
779 if (typeof x == 'undefined') x = true;
780 $scope.holdings_cb_changed('holdings_show_vols',x,true);
781 $('#holdings_show_vols').prop('checked', x);
783 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
784 if (typeof x == 'undefined') x = true;
785 $scope.holdings_cb_changed('holdings_show_copies',x,true);
786 $('#holdings_show_copies').prop('checked', x);
788 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
789 if (typeof x == 'undefined') x = true;
790 $scope.holdings_cb_changed('holdings_show_empty',x);
791 $('#holdings_show_empty').prop('checked', x);
796 $scope.vols_not_shown = function () {
797 return !$scope.holdings_show_vols;
800 $scope.copies_not_shown = function () {
801 return !$scope.holdings_show_copies;
804 $scope.holdings_checkbox_handler = function (item) {
805 $scope.holdings_cb_changed(item.checkbox,item.checked);
808 function gatherSelectedHoldingsIds () {
811 $scope.holdingsGridControls.selectedItems(),
812 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
817 function gatherSelectedRawCopies () {
820 $scope.holdingsGridControls.selectedItems(),
821 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
826 function gatherSelectedEmptyVolumeIds () {
829 $scope.holdingsGridControls.selectedItems(),
831 if (item.copy_count == 0)
832 cn_id_list.push(item.call_number.id)
838 function gatherSelectedVolumeIds () {
841 $scope.holdingsGridControls.selectedItems(),
843 if (cn_id_list.indexOf(item.call_number.id) == -1)
844 cn_id_list.push(item.call_number.id)
850 $scope.selectedHoldingsDelete = function (vols, copies) {
853 var perCnCopies = {};
859 $scope.holdingsGridControls.selectedItems(),
861 if (vols && item.raw_call_number) {
862 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
863 cnHash[item.call_number.id].isdeleted(1);
866 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
869 var cn_id = cp.call_number().id();
870 if (!cnHash[cn_id]) {
871 cnHash[cn_id] = cp.call_number();
872 perCnCopies[cn_id] = [cp];
874 perCnCopies[cn_id].push(cp);
876 cp.call_number(cn_id); // prevent loops in JSON-ification
883 angular.forEach(perCnCopies, function (v, k) {
885 cnHash[k].isdeleted(1);
892 angular.forEach(cnHash, function (v, k) {
896 if (cnList.length == 0) return;
899 if (vols && copies) flags.force_delete_copies = 1;
901 egConfirmDialog.open(
902 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
903 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
904 {copies : cp_count, volumes : cn_count}
905 ).result.then(function() {
908 'open-ils.cat.asset.volume.fleshed.batch.update.override',
909 egCore.auth.token(), cnList, 1, flags
910 ).then(function(update_count) {
911 holdingsSvcInst.fetchAgain().then(function() {
912 $scope.holdingsGridDataProvider.refresh();
917 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
918 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
919 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
921 spawnHoldingsAdd = function (vols,copies){
923 if (copies) { // just a copy on existing volumes
924 angular.forEach(gatherSelectedVolumeIds(), function (v) {
925 raw.push( {callnumber : v} );
929 $scope.holdingsGridControls.selectedItems(),
931 raw.push({owner : item.owner_id});
936 if (raw.length == 0) raw.push({});
940 'open-ils.actor.anon_cache.set_value',
941 null, 'edit-these-copies', {
942 record_id: $scope.record_id,
947 ).then(function(key) {
949 var url = egCore.env.basePath + 'cat/volcopy/' + key;
950 $timeout(function() { $window.open(url, '_blank') });
952 alert('Could not create anonymous cache key!');
956 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
957 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
959 spawnHoldingsEdit = function (hide_vols,hide_copies){
962 'open-ils.actor.anon_cache.set_value',
963 null, 'edit-these-copies', {
964 record_id: $scope.record_id,
965 copies: gatherSelectedHoldingsIds(),
966 raw: gatherSelectedEmptyVolumeIds().map(
967 function(v){ return { callnumber : v } }
969 hide_vols : hide_vols,
970 hide_copies : hide_copies
972 ).then(function(key) {
974 var url = egCore.env.basePath + 'cat/volcopy/' + key;
975 $timeout(function() { $window.open(url, '_blank') });
977 alert('Could not create anonymous cache key!');
981 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
982 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
983 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
985 $scope.selectedHoldingsItemStatus = function (){
986 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
987 $timeout(function() { $window.open(url, '_blank') });
990 $scope.markVolAsItemTarget = function() {
991 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
992 egCore.hatch.setLocalItem(
993 'eg.cat.item_transfer_target',
994 $scope.holdingsGridControls.selectedItems()[0].call_number.id
999 $scope.markLibAsVolTarget = function() {
1000 return $modal.open({
1001 templateUrl: './cat/catalog/t_choose_vol_target_lib',
1004 ['$scope','$modalInstance',
1005 function($scope , $modalInstance) {
1007 var orgId = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target') || 1;
1008 $scope.org = egCore.org.get(orgId);
1009 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
1010 $scope.ok = function(org) {
1011 egCore.hatch.setLocalItem(
1012 'eg.cat.volume_transfer_target',
1015 $modalInstance.close();
1017 $scope.cancel = function($event) {
1018 $modalInstance.dismiss();
1019 $event.preventDefault();
1024 $scope.markLibFromSelectedAsVolTarget = function() {
1025 egCore.hatch.setLocalItem(
1026 'eg.cat.volume_transfer_target',
1027 $scope.holdingsGridControls.selectedItems()[0].owner_id
1031 $scope.selectedHoldingsItemStatusDetail = function (){
1033 gatherSelectedHoldingsIds(),
1035 var url = egCore.env.basePath +
1037 $timeout(function() { $window.open(url, '_blank') });
1042 $scope.transferVolumesToRecord = function (){
1043 var target_record = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
1044 if (!target_record) return;
1045 if ($scope.record_id == target_record) return;
1046 var items = $scope.holdingsGridControls.selectedItems();
1047 if (!items.length) return;
1049 var vols_to_move = {};
1050 angular.forEach(items, function(item) {
1051 if (!(item.call_number.owning_lib in vols_to_move)) {
1052 vols_to_move[item.call_number.owning_lib] = new Array;
1054 vols_to_move[item.call_number.owning_lib].push(item.call_number.id);
1058 angular.forEach(vols_to_move, function(vols, owning_lib) {
1059 promises.push(egCore.net.request(
1061 'open-ils.cat.asset.volume.batch.transfer.override',
1062 egCore.auth.token(), {
1063 docid : target_record,
1069 $q.all(promises).then(function(success) {
1071 holdingsSvcInst.fetchAgain().then(function() {
1072 $scope.holdingsGridDataProvider.refresh();
1075 alert('Could not transfer volumes!');
1080 $scope.transferVolumes = function (new_record){
1081 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
1086 'open-ils.cat.asset.volume.batch.transfer.override',
1087 egCore.auth.token(), {
1088 docid : (new_record ? new_record : $scope.record_id),
1090 volumes : gatherSelectedVolumeIds()
1092 ).then(function(success) {
1094 holdingsSvcInst.fetchAgain().then(function() {
1095 $scope.holdingsGridDataProvider.refresh();
1098 alert('Could not transfer volumes!');
1105 $scope.transferVolumesToRecordAndLibrary = function() {
1106 var target_record = egCore.hatch.getLocalItem('eg.cat.marked_volume_transfer_record');
1107 if (!target_record) return;
1108 $scope.transferVolumes(target_record);
1111 // this "transfers" selected copies to a new owning library,
1112 // auto-creating volumes and deleting unused volumes as required.
1113 $scope.changeItemOwningLib = function() {
1114 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
1115 var items = $scope.holdingsGridControls.selectedItems();
1116 if (!xfer_target || !items.length) {
1119 var vols_to_move = {};
1120 var copies_to_move = {};
1121 angular.forEach(items, function(item) {
1122 if (item.call_number.owning_lib != xfer_target) {
1123 if (item.call_number.id in vols_to_move) {
1124 copies_to_move[item.call_number.id].push(item.id);
1126 vols_to_move[item.call_number.id] = item.call_number;
1127 copies_to_move[item.call_number.id] = new Array;
1128 copies_to_move[item.call_number.id].push(item.id);
1134 angular.forEach(vols_to_move, function(vol) {
1135 promises.push(egCore.net.request(
1137 'open-ils.cat.call_number.find_or_create',
1138 egCore.auth.token(),
1145 ).then(function(resp) {
1146 var evt = egCore.evt.parse(resp);
1148 return egCore.net.request(
1150 'open-ils.cat.transfer_copies_to_volume',
1151 egCore.auth.token(),
1153 copies_to_move[vol.id]
1157 $q.all(promises).then(function() {
1158 holdingsSvcInst.fetchAgain().then(function() {
1159 $scope.holdingsGridDataProvider.refresh();
1164 $scope.transferItems = function (){
1165 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
1166 var copy_ids = gatherSelectedHoldingsIds();
1167 if (xfer_target && copy_ids.length > 0) {
1170 'open-ils.cat.transfer_copies_to_volume',
1171 egCore.auth.token(),
1175 function(resp) { // oncomplete
1176 var evt = egCore.evt.parse(resp);
1178 egConfirmDialog.open(
1179 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
1180 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
1181 {'evt_desc': evt.desc}
1182 ).result.then(function() {
1185 'open-ils.cat.transfer_copies_to_volume.override',
1186 egCore.auth.token(),
1189 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
1190 ).then(function(resp) {
1191 holdingsSvcInst.fetchAgain().then(function() {
1192 $scope.holdingsGridDataProvider.refresh();
1197 holdingsSvcInst.fetchAgain().then(function() {
1198 $scope.holdingsGridDataProvider.refresh();
1208 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1210 gatherSelectedHoldingsIds(),
1212 var url = egCore.env.basePath +
1213 'cat/item/' + cid + '/triggered_events';
1214 $timeout(function() { $window.open(url, '_blank') });
1219 $scope.selectedHoldingsItemStatusHolds = function (){
1221 gatherSelectedHoldingsIds(),
1223 var url = egCore.env.basePath +
1224 'cat/item/' + cid + '/holds';
1225 $timeout(function() { $window.open(url, '_blank') });
1230 $scope.selectedHoldingsDamaged = function () {
1231 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
1232 holdingsSvcInst.fetchAgain().then(function() {
1233 $scope.holdingsGridDataProvider.refresh();
1238 $scope.selectedHoldingsMissing = function () {
1239 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1240 holdingsSvcInst.fetchAgain().then(function() {
1241 $scope.holdingsGridDataProvider.refresh();
1246 $scope.attach_to_peer_bib = function() {
1247 var copy_list = gatherSelectedHoldingsIds();
1248 if (copy_list.length == 0) return;
1250 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1251 if (!target_record) return;
1253 return $modal.open({
1254 templateUrl: './cat/catalog/t_conjoined_selector',
1257 ['$scope','$modalInstance',
1258 function($scope , $modalInstance) {
1259 $scope.update = false;
1261 $scope.peer_type = null;
1262 $scope.peer_type_list = [];
1263 conjoinedSvc.get_peer_types().then(function(list){
1264 $scope.peer_type_list = list;
1267 $scope.ok = function(type) {
1270 angular.forEach(copy_list, function (cp) {
1271 var n = new egCore.idl.bpbcm();
1273 n.peer_record(target_record);
1276 promises.push(egCore.pcrud.create(n));
1279 return $q.all(promises).then(function(){$modalInstance.close()});
1282 $scope.cancel = function($event) {
1283 $modalInstance.dismiss();
1284 $event.preventDefault();
1292 // ------------------------------------------------------------------
1294 var provider = egGridDataProvider.instance({});
1295 $scope.hold_grid_data_provider = provider;
1296 $scope.grid_actions = egHoldGridActions;
1297 $scope.grid_actions.refresh = function () { provider.refresh() };
1298 $scope.hold_grid_controls = {};
1300 var hold_ids = []; // current list of holds
1301 function fetchHolds(offset, count) {
1302 var ids = hold_ids.slice(offset, offset + count);
1303 return egHolds.fetch_holds(ids).then(null, null,
1304 function(hold_data) {
1310 provider.get = function(offset, count) {
1311 if ($scope.record_tab != 'holds') return $q.when();
1312 var deferred = $q.defer();
1313 hold_ids = []; // no caching ATM
1318 'open-ils.circ.holds.retrieve_all_from_title',
1319 egCore.auth.token(), $scope.record_id,
1320 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
1322 function(hold_data) {
1323 angular.forEach(hold_data, function(list, type) {
1324 hold_ids = hold_ids.concat(list);
1326 fetchHolds(offset, count).then(
1327 deferred.resolve, null, deferred.notify);
1331 return deferred.promise;
1334 $scope.detail_view = function(action, user_data, items) {
1336 $scope.detail_hold_id = h.hold.id();
1340 $scope.list_view = function(items) {
1341 $scope.detail_hold_id = null;
1344 // refresh the list of record holds when the pickup lib is changed.
1345 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1346 $scope.pickup_ou_changed = function(org) {
1347 $scope.pickup_ou = org;
1351 $scope.print_holds = function() {
1353 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1355 hold : egCore.idl.toHash(item.hold),
1356 patron_last : item.patron_last,
1357 patron_alias : item.patron_alias,
1358 patron_barcode : item.patron_barcode,
1359 copy : egCore.idl.toHash(item.copy),
1360 volume : egCore.idl.toHash(item.volume),
1361 title : item.mvr.title(),
1362 author : item.mvr.author()
1366 egCore.print.print({
1367 context : 'receipt',
1368 template : 'holds_for_bib',
1369 scope : {holds : holds}
1373 $scope.mark_hold_transfer_dest = function() {
1374 egCore.hatch.setLocalItem(
1375 'eg.circ.hold.title_transfer_target', $scope.record_id);
1378 // UI presents this option as "all holds"
1379 $scope.transfer_holds_to_marked = function() {
1380 var hold_ids = $scope.hold_grid_controls.allItems().map(
1381 function(hold_data) {return hold_data.hold.id()});
1382 egHolds.transfer_to_marked_title(hold_ids);
1385 // ------------------------------------------------------------------
1386 // Initialize the selected tab
1388 function init_cat_url() {
1389 // Set the initial catalog URL. This only happens once.
1390 // The URL is otherwise generated through user navigation.
1391 if ($scope.catalog_url) return;
1393 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1395 // A record ID in the path indicates a request for the record-
1397 if ($routeParams.record_id) {
1398 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1401 $scope.catalog_url = url;
1404 function init_parts_url() {
1405 $scope.parts_url = $location
1409 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1413 $scope.set_record_tab = function(tab) {
1414 $scope.record_tab = tab;
1427 $scope.detail_hold_record_id = $scope.record_id;
1428 // refresh the holds grid
1434 $scope.set_default_record_tab = function() {
1435 egCore.hatch.setLocalItem(
1436 'eg.cat.default_record_tab', $scope.record_tab);
1437 $timeout(function(){$scope.default_tab = $scope.record_tab});
1441 if ($scope.record_id) {
1442 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1443 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1446 tab = $routeParams.record_tab || 'catalog';
1448 $scope.set_record_tab(tab);
1452 .controller('AuthorityCtrl',
1453 ['$scope','$routeParams','$location','$window','$q','egCore',
1454 function($scope , $routeParams , $location , $window , $q , egCore) {
1456 // set record ID on page load if available...
1457 $scope.authority_id = $routeParams.authority_id;
1459 if ($routeParams.authority_id) $scope.from_route = true;
1460 else $scope.from_route = false;
1462 $scope.stop_unload = false;
1465 .controller('URLVerifyCtrl',
1466 ['$scope','$location',
1467 function($scope , $location) {
1468 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1471 .controller('VandelayCtrl',
1472 ['$scope','$location',
1473 function($scope , $location) {
1474 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
1477 .controller('ManageAuthoritiesCtrl',
1478 ['$scope','$location',
1479 function($scope , $location) {
1480 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1483 .controller('BatchEditCtrl',
1484 ['$scope','$location','$routeParams',
1485 function($scope , $location , $routeParams) {
1486 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1487 if ($routeParams.container_type) {
1488 switch ($routeParams.container_type) {
1490 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1493 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1500 .filter('boolText', function(){
1501 return function (v) {
1506 .factory('conjoinedSvc',
1508 function(egCore , $q) {
1511 items : [], // record search results
1512 index : 0, // search grid index
1519 bpbcm : ['target_copy','peer_type'],
1520 acp : ['call_number'],
1522 bre : ['simple_record']
1524 // avoid fetching the MARC blob by specifying which
1525 // fields on the bre to select. More may be needed.
1526 // note that fleshed fields are explicitly selected.
1527 select : { bre : ['id'] },
1528 order_by : { bpbcm : ['id'] },
1531 // resolved with the last received copy
1532 service.fetch = function(rid) {
1533 if (!rid && !service.rid) return $q.when();
1535 if (rid) service.rid = rid;
1539 return egCore.pcrud.search(
1541 {peer_record : service.rid},
1544 ).then( function(list) { // finished
1545 service.items = list;
1546 return service.items;
1550 // returns a promise resolved with the list of peer bib types
1551 service.get_peer_types = function() {
1553 return $q.when(egCore.env.bpt.list);
1555 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
1556 .then(function(list) {
1557 egCore.env.absorbList(list, 'bpt');