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'])
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.stop_unload = false;
315 $scope.$watch('stop_unload',
316 function(newVal, oldVal) {
317 if (newVal && newVal != oldVal && $scope.opac_iframe) {
318 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
319 return 'There is unsaved data in this record.'
322 if ($scope.opac_iframe)
323 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
328 // Set the "last bib" cookie, if we have that
329 if ($scope.record_id)
330 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
332 $scope.refresh_record_callback = function (record_id) {
333 egCore.pcrud.retrieve('bre', record_id, {
336 bre : ['simple_record','creator','editor']
338 }).then(function(rec) {
339 rec.owner(egCore.org.get(rec.owner()));
340 $scope.summary_pane_record = rec;
346 // also set it when the iframe changes to a new record
347 $scope.handle_page = function(url) {
349 if (!url || url == 'about:blank') {
350 // nothing loaded. If we already have a record ID, leave it.
354 var match = url.match(/\/+opac\/+record\/+(\d+)/);
356 $scope.record_id = match[1];
357 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
358 $scope.holdings_record_id_changed($scope.record_id);
359 conjoinedSvc.fetch($scope.record_id).then(function(){
360 $scope.conjoinedGridDataProvider.refresh();
363 $location.update_path('/cat/catalog/record/' + $scope.record_id);
365 delete $scope.record_id;
366 $scope.from_route = false;
369 // child scope is executing this function, so our digest doesn't fire ... thus,
372 if (!$scope.in_opac_call) {
373 if ($scope.record_id) {
374 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
375 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
377 tab = $routeParams.record_tab || 'catalog';
379 $scope.set_record_tab(tab);
381 $scope.in_opac_call = false;
385 // xulG catalog handlers
386 $scope.handlers = { }
388 // ------------------------------------------------------------------
391 $scope.conjoinedGridControls = {};
392 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
393 get : function(offset, count) {
394 return this.arrayNotifier(conjoinedSvc.items, offset, count);
398 $scope.changeConjoinedType = function () {
399 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
400 angular.forEach(peers, function (p) {
401 p.target_copy(p.target_copy().id());
402 p.peer_type(p.peer_type().id());
405 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
408 templateUrl: './cat/catalog/t_conjoined_selector',
411 ['$scope','$modalInstance',
412 function($scope , $modalInstance) {
413 $scope.update = true;
415 $scope.peer_type = null;
416 $scope.peer_type_list = [];
417 conjoinedSvc.get_peer_types().then(function(list){
418 $scope.peer_type_list = list;
421 $scope.ok = function(type) {
424 angular.forEach(peers, function (p) {
427 promises.push(egCore.pcrud.update(p));
430 return $q.all(promises)
431 .then(function(){$modalInstance.close()})
432 .then(function(){return conjoinedSvc.fetch()})
433 .then(function(){conjoinedGridDataProviderRef.refresh()});
436 $scope.cancel = function($event) {
437 $modalInstance.dismiss();
438 $event.preventDefault();
445 $scope.refreshConjoined = function () {
446 conjoinedSvc.fetch($scope.record_id)
447 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
450 $scope.deleteSelectedConjoined = function () {
451 var peers = $scope.conjoinedGridControls.selectedItems();
453 if (peers.length > 0) {
454 egConfirmDialog.open(
455 egCore.strings.CONFIRM_DELETE_PEERS,
456 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
457 {peers : peers.length}
458 ).result.then(function() {
459 angular.forEach(peers, function (p) {
463 egCore.pcrud.remove(peers).then(function() {
464 return conjoinedSvc.fetch();
466 $scope.conjoinedGridDataProvider.refresh();
471 if ($scope.record_id)
472 conjoinedSvc.fetch($scope.record_id);
474 // ------------------------------------------------------------------
477 $scope.holdingsGridControls = {};
478 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
479 get : function(offset, count) {
480 return this.arrayNotifier(holdingsSvc.copies, offset, count);
484 $scope.add_copies_to_bucket = function() {
485 var copy_list = gatherSelectedHoldingsIds();
486 if (copy_list.length == 0) return;
489 templateUrl: './cat/catalog/t_add_to_bucket',
493 ['$scope','$modalInstance',
494 function($scope , $modalInstance) {
496 $scope.bucket_id = 0;
497 $scope.newBucketName = '';
498 $scope.allBuckets = [];
502 'open-ils.actor.container.retrieve_by_class.authoritative',
503 egCore.auth.token(), egCore.auth.user().id(),
504 'copy', 'staff_client'
505 ).then(function(buckets) { $scope.allBuckets = buckets; });
507 $scope.add_to_bucket = function() {
509 angular.forEach(copy_list, function (cp) {
510 var item = new egCore.idl.ccbi()
511 item.bucket($scope.bucket_id);
512 item.target_copy(cp);
516 'open-ils.actor.container.item.create',
517 egCore.auth.token(), 'copy', item
521 return $q.all(promises).then(function() {
522 $modalInstance.close();
527 $scope.add_to_new_bucket = function() {
528 var bucket = new egCore.idl.ccb();
529 bucket.owner(egCore.auth.user().id());
530 bucket.name($scope.newBucketName);
531 bucket.description('');
532 bucket.btype('staff_client');
534 return egCore.net.request(
536 'open-ils.actor.container.create',
537 egCore.auth.token(), 'copy', bucket
538 ).then(function(bucket) {
539 $scope.bucket_id = bucket;
540 $scope.add_to_bucket();
544 $scope.cancel = function() {
545 $modalInstance.dismiss();
551 $scope.requestItems = function() {
552 var copy_list = gatherSelectedHoldingsIds();
553 if (copy_list.length == 0) return;
556 templateUrl: './cat/catalog/t_request_items',
559 ['$scope','$modalInstance',
560 function($scope , $modalInstance) {
562 $scope.first_user_fetch = true;
566 copy_list : copy_list,
567 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
568 user : egCore.auth.user().id()
571 egUser.get( $scope.hold_data.user ).then(function(u) {
573 $scope.barcode = u.card().barcode();
574 $scope.user_name = egUser.format_name(u);
575 $scope.hold_data.user = u.id();
578 $scope.user_name = '';
580 $scope.$watch('barcode', function (n) {
581 if (!$scope.first_user_fetch) {
582 egUser.getByBarcode(n).then(function(u) {
584 $scope.user_name = egUser.format_name(u);
585 $scope.hold_data.user = u.id();
588 $scope.user_name = '';
589 delete $scope.hold_data.user;
592 $scope.first_user_fetch = false;
595 $scope.ok = function(h) {
598 hold_type : h.hold_type,
599 pickup_lib: h.pickup_lib.id(),
605 'open-ils.circ.holds.test_and_create.batch.override',
606 egCore.auth.token(), args, h.copy_list
609 $modalInstance.close();
612 $scope.cancel = function($event) {
613 $modalInstance.dismiss();
614 $event.preventDefault();
620 $scope.replaceBarcodes = function() {
621 var copy_list = gatherSelectedRawCopies();
622 if (copy_list.length == 0) return;
624 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
626 angular.forEach(copy_list, function (cp) {
628 templateUrl: './cat/share/t_replace_barcode',
631 ['$scope','$modalInstance',
632 function($scope , $modalInstance) {
633 $scope.isModal = true;
634 $scope.focusBarcode = false;
635 $scope.focusBarcode2 = true;
636 $scope.barcode1 = cp.barcode();
638 $scope.updateBarcode = function() {
639 $scope.copyNotFound = false;
640 $scope.updateOK = false;
642 egCore.pcrud.search('acp',
643 {deleted : 'f', barcode : $scope.barcode1})
644 .then(function(copy) {
647 $scope.focusBarcode = true;
648 $scope.copyNotFound = true;
652 $scope.copyId = copy.id();
653 copy.barcode($scope.barcode2);
655 egCore.pcrud.update(copy).then(function(stat) {
656 $scope.updateOK = stat;
657 $scope.focusBarcode = true;
658 holdingsSvc.fetchAgain().then(function (){
659 holdingsGridDataProviderRef.refresh();
664 $modalInstance.close();
667 $scope.cancel = function($event) {
668 $modalInstance.dismiss();
669 $event.preventDefault();
677 // refresh the list of holdings when the record_id is changed.
678 $scope.holdings_record_id_changed = function(id) {
679 if ($scope.record_id != id) $scope.record_id = id;
680 console.log('record id changed to ' + id + ', loading new holdings');
682 rid : $scope.record_id,
683 org : $scope.holdings_ou,
684 copy: $scope.holdings_show_copies,
685 vol : $scope.holdings_show_vols,
686 empty: $scope.holdings_show_empty
688 $scope.holdingsGridDataProvider.refresh();
692 // refresh the list of holdings when the filter lib is changed.
693 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
694 $scope.holdings_ou_changed = function(org) {
695 $scope.holdings_ou = org;
697 rid : $scope.record_id,
698 org : $scope.holdings_ou,
699 copy: $scope.holdings_show_copies,
700 vol : $scope.holdings_show_vols,
701 empty: $scope.holdings_show_empty
703 $scope.holdingsGridDataProvider.refresh();
707 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
709 egCore.hatch.setItem('cat.' + cb, newVal);
710 if (!norefresh) holdingsSvc.fetch({
711 rid : $scope.record_id,
712 org : $scope.holdings_ou,
713 copy: $scope.holdings_show_copies,
714 vol : $scope.holdings_show_vols,
715 empty: $scope.holdings_show_empty
717 $scope.holdingsGridDataProvider.refresh();
721 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
722 if (typeof x == 'undefined') x = true;
723 $scope.holdings_cb_changed('holdings_show_vols',x,true);
724 $('#holdings_show_vols').prop('checked', x);
726 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
727 if (typeof x == 'undefined') x = true;
728 $scope.holdings_cb_changed('holdings_show_copies',x,true);
729 $('#holdings_show_copies').prop('checked', x);
731 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
732 if (typeof x == 'undefined') x = true;
733 $scope.holdings_cb_changed('holdings_show_empty',x);
734 $('#holdings_show_empty').prop('checked', x);
739 $scope.vols_not_shown = function () {
740 return !$scope.holdings_show_vols;
743 $scope.copies_not_shown = function () {
744 return !$scope.holdings_show_copies;
747 $scope.holdings_checkbox_handler = function (item) {
748 $scope.holdings_cb_changed(item.checkbox,item.checked);
751 function gatherSelectedHoldingsIds () {
754 $scope.holdingsGridControls.selectedItems(),
755 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
760 function gatherSelectedRawCopies () {
763 $scope.holdingsGridControls.selectedItems(),
764 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
769 function gatherSelectedVolumeIds () {
772 $scope.holdingsGridControls.selectedItems(),
774 if (cn_id_list.indexOf(item.call_number.id) == -1)
775 cn_id_list.push(item.call_number.id)
781 $scope.selectedHoldingsDelete = function (vols, copies) {
784 var perCnCopies = {};
790 $scope.holdingsGridControls.selectedItems(),
792 if (vols && item.raw_call_number) {
793 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
794 cnHash[item.call_number.id].isdeleted(1);
797 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
800 var cn_id = cp.call_number().id();
801 if (!cnHash[cn_id]) {
802 cnHash[cn_id] = cp.call_number();
803 perCnCopies[cn_id] = [cp];
805 perCnCopies[cn_id].push(cp);
807 cp.call_number(cn_id); // prevent loops in JSON-ification
814 angular.forEach(perCnCopies, function (v, k) {
816 cnHash[k].isdeleted(1);
823 angular.forEach(cnHash, function (v, k) {
827 if (cnList.length == 0) return;
829 egConfirmDialog.open(
830 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
831 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
832 {copies : cp_count, volumes : cn_count}
833 ).result.then(function() {
836 'open-ils.cat.asset.volume.fleshed.batch.update.override',
837 egCore.auth.token(), cnList, 1, {}
838 ).then(function(update_count) {
839 $scope.holdingsGridDataProvider.refresh();
843 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
844 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
845 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
847 spawnHoldingsAdd = function (vols,copies){
849 if (copies) { // just a copy on existing volumes
850 angular.forEach(gatherSelectedVolumeIds(), function (v) {
851 raw.push( {callnumber : v} );
855 $scope.holdingsGridControls.selectedItems(),
857 raw.push({owner : item.owner_id});
862 if (raw.length == 0) raw.push({});
866 'open-ils.actor.anon_cache.set_value',
867 null, 'edit-these-copies', {
868 record_id: $scope.record_id,
873 ).then(function(key) {
875 var url = egCore.env.basePath + 'cat/volcopy/' + key;
876 $timeout(function() { $window.open(url, '_blank') });
878 alert('Could not create anonymous cache key!');
882 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
883 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
885 spawnHoldingsEdit = function (hide_vols,hide_copies){
888 'open-ils.actor.anon_cache.set_value',
889 null, 'edit-these-copies', {
890 record_id: $scope.record_id,
891 copies: gatherSelectedHoldingsIds(),
892 hide_vols : hide_vols,
893 hide_copies : hide_copies
895 ).then(function(key) {
897 var url = egCore.env.basePath + 'cat/volcopy/' + key;
898 $timeout(function() { $window.open(url, '_blank') });
900 alert('Could not create anonymous cache key!');
904 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
905 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
906 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
908 $scope.selectedHoldingsItemStatus = function (){
909 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
910 $timeout(function() { $window.open(url, '_blank') });
913 $scope.markVolAsItemTarget = function() {
914 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
915 egCore.hatch.setLocalItem(
916 'eg.cat.item_transfer_target',
917 $scope.holdingsGridControls.selectedItems()[0].call_number.id
922 $scope.markLibAsVolTarget = function() {
923 egCore.hatch.setLocalItem(
924 'eg.cat.volume_transfer_target',
925 $scope.holdingsGridControls.selectedItems()[0].owner_id
929 $scope.selectedHoldingsItemStatusDetail = function (){
931 gatherSelectedHoldingsIds(),
933 var url = egCore.env.basePath +
935 $timeout(function() { $window.open(url, '_blank') });
940 $scope.transferVolumes = function (){
941 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
946 'open-ils.open-ils.cat.asset.volume.batch.transfer.override',
947 egCore.auth.token(), {
948 docid : $scope.record_id,
950 volumes : gatherSelectedVolumeIds()
952 ).then(function(success) {
954 holdingsSvc.fetchAgain().then(function() {
955 $scope.holdingsGridDataProvider.refresh();
958 alert('Could not transfer volumes!');
965 $scope.transferItems = function (){
966 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
967 var copy_ids = gatherSelectedHoldingsIds();
968 if (xfer_target && copy_ids.length > 0) {
971 'open-ils.cat.transfer_copies_to_volume',
976 function(resp) { // oncomplete
977 var evt = egCore.evt.parse(resp);
979 egConfirmDialog.open(
980 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
981 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
982 {'evt_desc': evt.desc}
983 ).result.then(function() {
986 'open-ils.cat.transfer_copies_to_volume.override',
990 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
991 ).then(function(resp) {
992 holdingsSvc.fetchAgain().then(function() {
993 $scope.holdingsGridDataProvider.refresh();
998 holdingsSvc.fetchAgain().then(function() {
999 $scope.holdingsGridDataProvider.refresh();
1009 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1011 gatherSelectedHoldingsIds(),
1013 var url = egCore.env.basePath +
1014 'cat/item/' + cid + '/triggered_events';
1015 $timeout(function() { $window.open(url, '_blank') });
1020 $scope.selectedHoldingsItemStatusHolds = function (){
1022 gatherSelectedHoldingsIds(),
1024 var url = egCore.env.basePath +
1025 'cat/item/' + cid + '/holds';
1026 $timeout(function() { $window.open(url, '_blank') });
1031 $scope.selectedHoldingsDamaged = function () {
1032 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
1033 holdingsSvc.fetchAgain().then(function() {
1034 $scope.holdingsGridDataProvider.refresh();
1039 $scope.selectedHoldingsMissing = function () {
1040 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1041 holdingsSvc.fetchAgain().then(function() {
1042 $scope.holdingsGridDataProvider.refresh();
1047 $scope.attach_to_peer_bib = function() {
1048 var copy_list = gatherSelectedHoldingsIds();
1049 if (copy_list.length == 0) return;
1051 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1052 if (!target_record) return;
1054 return $modal.open({
1055 templateUrl: './cat/catalog/t_conjoined_selector',
1058 ['$scope','$modalInstance',
1059 function($scope , $modalInstance) {
1060 $scope.update = false;
1062 $scope.peer_type = null;
1063 $scope.peer_type_list = [];
1064 conjoinedSvc.get_peer_types().then(function(list){
1065 $scope.peer_type_list = list;
1068 $scope.ok = function(type) {
1071 angular.forEach(copy_list, function (cp) {
1072 var n = new egCore.idl.bpbcm();
1074 n.peer_record(target_record);
1077 promises.push(egCore.pcrud.create(n));
1080 return $q.all(promises).then(function(){$modalInstance.close()});
1083 $scope.cancel = function($event) {
1084 $modalInstance.dismiss();
1085 $event.preventDefault();
1093 // ------------------------------------------------------------------
1095 var provider = egGridDataProvider.instance({});
1096 $scope.hold_grid_data_provider = provider;
1097 $scope.grid_actions = egHoldGridActions;
1098 $scope.grid_actions.refresh = function () { provider.refresh() };
1099 $scope.hold_grid_controls = {};
1101 var hold_ids = []; // current list of holds
1102 function fetchHolds(offset, count) {
1103 var ids = hold_ids.slice(offset, offset + count);
1104 return egHolds.fetch_holds(ids).then(null, null,
1105 function(hold_data) {
1111 provider.get = function(offset, count) {
1112 if ($scope.record_tab != 'holds') return $q.when();
1113 var deferred = $q.defer();
1114 hold_ids = []; // no caching ATM
1119 'open-ils.circ.holds.retrieve_all_from_title',
1120 egCore.auth.token(), $scope.record_id,
1121 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
1123 function(hold_data) {
1124 angular.forEach(hold_data, function(list, type) {
1125 hold_ids = hold_ids.concat(list);
1127 fetchHolds(offset, count).then(
1128 deferred.resolve, null, deferred.notify);
1132 return deferred.promise;
1135 $scope.detail_view = function(action, user_data, items) {
1137 $scope.detail_hold_id = h.hold.id();
1141 $scope.list_view = function(items) {
1142 $scope.detail_hold_id = null;
1145 // refresh the list of record holds when the pickup lib is changed.
1146 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1147 $scope.pickup_ou_changed = function(org) {
1148 $scope.pickup_ou = org;
1152 $scope.print_holds = function() {
1154 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1156 hold : egCore.idl.toHash(item.hold),
1157 patron_last : item.patron_last,
1158 patron_alias : item.patron_alias,
1159 patron_barcode : item.patron_barcode,
1160 copy : egCore.idl.toHash(item.copy),
1161 volume : egCore.idl.toHash(item.volume),
1162 title : item.mvr.title(),
1163 author : item.mvr.author()
1167 egCore.print.print({
1168 context : 'receipt',
1169 template : 'holds_for_bib',
1170 scope : {holds : holds}
1174 $scope.mark_hold_transfer_dest = function() {
1175 egCore.hatch.setLocalItem(
1176 'eg.circ.hold.title_transfer_target', $scope.record_id);
1179 // UI presents this option as "all holds"
1180 $scope.transfer_holds_to_marked = function() {
1181 var hold_ids = $scope.hold_grid_controls.allItems().map(
1182 function(hold_data) {return hold_data.hold.id()});
1183 egHolds.transfer_to_marked_title(hold_ids);
1186 // ------------------------------------------------------------------
1187 // Initialize the selected tab
1189 function init_cat_url() {
1190 // Set the initial catalog URL. This only happens once.
1191 // The URL is otherwise generated through user navigation.
1192 if ($scope.catalog_url) return;
1194 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1196 // A record ID in the path indicates a request for the record-
1198 if ($routeParams.record_id) {
1199 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1202 $scope.catalog_url = url;
1205 function init_parts_url() {
1206 $scope.parts_url = $location
1210 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1214 $scope.set_record_tab = function(tab) {
1215 $scope.record_tab = tab;
1228 $scope.detail_hold_record_id = $scope.record_id;
1229 // refresh the holds grid
1235 $scope.set_default_record_tab = function() {
1236 egCore.hatch.setLocalItem(
1237 'eg.cat.default_record_tab', $scope.record_tab);
1238 $timeout(function(){$scope.default_tab = $scope.record_tab});
1242 if ($scope.record_id) {
1243 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1244 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1247 tab = $routeParams.record_tab || 'catalog';
1249 $scope.set_record_tab(tab);
1253 .controller('AuthorityCtrl',
1254 ['$scope','$routeParams','$location','$window','$q','egCore',
1255 function($scope , $routeParams , $location , $window , $q , egCore) {
1257 // set record ID on page load if available...
1258 $scope.authority_id = $routeParams.authority_id;
1260 if ($routeParams.authority_id) $scope.from_route = true;
1261 else $scope.from_route = false;
1263 $scope.stop_unload = false;
1266 .controller('URLVerifyCtrl',
1267 ['$scope','$location',
1268 function($scope , $location) {
1269 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1272 .controller('VandelayCtrl',
1273 ['$scope','$location',
1274 function($scope , $location) {
1275 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
1278 .controller('ManageAuthoritiesCtrl',
1279 ['$scope','$location',
1280 function($scope , $location) {
1281 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1284 .controller('BatchEditCtrl',
1285 ['$scope','$location','$routeParams',
1286 function($scope , $location , $routeParams) {
1287 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1288 if ($routeParams.container_type) {
1289 switch ($routeParams.container_type) {
1291 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1294 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1301 .filter('boolText', function(){
1302 return function (v) {
1307 .factory('holdingsSvc',
1309 function(egCore , $q) {
1313 copies : [], // record search results
1314 index : 0, // search grid index
1322 acp : ['status','location'],
1323 acn : ['prefix','suffix','copies']
1327 service.fetchAgain = function() {
1328 return service.fetch({
1333 empty: service.empty
1337 // resolved with the last received copy
1338 service.fetch = function(opts) {
1339 if (service.ongoing) {
1340 console.log('Skipping fetch, ongoing = true');
1346 var copy = opts.copy;
1348 var empty = opts.empty;
1350 if (!rid) return $q.when();
1351 if (!org) return $q.when();
1353 service.ongoing = true;
1357 service.copy = opts.copy;
1358 service.vol = opts.vol;
1359 service.empty = opts.empty;
1361 service.copies = [];
1364 var org_list = egCore.org.descendants(org.id(), true);
1365 console.log('Holdings fetch with: rid='+rid+' org='+org_list+' copy='+copy+' vol='+vol+' empty='+empty);
1367 return egCore.pcrud.search(
1369 {record : rid, owning_lib : org_list, deleted : 'f'},
1372 function() { // finished
1373 service.copies = service.copies.sort(
1375 function compare_array (x, y, i) {
1376 if (x[i] && y[i]) { // both have values
1377 if (x[i] == y[i]) { // need to look deeper
1378 return compare_array(x, y, ++i);
1381 if (x[i] < y[i]) { // x is first
1383 } else if (x[i] > y[i]) { // y is first
1387 } else { // no orgs to compare ...
1388 if (x[i]) return -1;
1394 var owner_order = compare_array(a.owner_list, b.owner_list, 0);
1396 // now compare on CN label
1397 if (a.call_number.label < b.call_number.label) return -1;
1398 if (a.call_number.label > b.call_number.label) return 1;
1401 if (a.copy_number < b.copy_number) return -1;
1402 if (a.copy_number > b.copy_number) return 1;
1405 if (a.barcode < b.barcode) return -1;
1406 if (a.barcode > b.barcode) return 1;
1412 // create a label using just the unique part of the owner list
1414 var prev_owner_list;
1415 angular.forEach(service.copies, function (cp) {
1416 if (!prev_owner_list) {
1417 cp.owner_label = cp.owner_list.join(' ... ');
1419 var current_owner_list = cp.owner_list.slice();
1420 while (current_owner_list[1] && prev_owner_list[1] && current_owner_list[0] == prev_owner_list[0]) {
1421 current_owner_list.shift();
1422 prev_owner_list.shift();
1424 cp.owner_label = current_owner_list.join(' ... ');
1428 prev_owner_list = cp.owner_list.slice();
1431 var new_list = service.copies;
1432 if (!copy || !vol) { // collapse copy rows, supply a count instead
1437 var current_blob = { copy_count : 0 };
1438 angular.forEach(new_list, function (cp) {
1440 prev_key = cp.owner_list.join('') + cp.call_number.label;
1441 if (cp.barcode) current_blob.copy_count = 1;
1442 current_blob.index = index++;
1443 current_blob.id_list = cp.id_list;
1444 if (cp.raw) current_blob.raw = cp.raw;
1445 current_blob.call_number = cp.call_number;
1446 current_blob.owner_list = cp.owner_list;
1447 current_blob.owner_label = cp.owner_label;
1448 current_blob.owner_id = cp.owner_id;
1450 var current_key = cp.owner_list.join('') + cp.call_number.label;
1451 if (prev_key == current_key) { // collapse into current_blob
1452 current_blob.copy_count++;
1453 current_blob.id_list = current_blob.id_list.concat(cp.id_list);
1454 current_blob.raw = current_blob.raw.concat(cp.raw);
1456 current_blob.barcode = current_blob.copy_count;
1457 cp_list.push(current_blob);
1458 prev_key = current_key;
1459 current_blob = { copy_count : 0 };
1460 if (cp.barcode) current_blob.copy_count = 1;
1461 current_blob.index = index++;
1462 current_blob.id_list = cp.id_list;
1463 if (cp.raw) current_blob.raw = cp.raw;
1464 current_blob.owner_label = cp.owner_label;
1465 current_blob.owner_id = cp.owner_id;
1466 current_blob.call_number = cp.call_number;
1467 current_blob.owner_list = cp.owner_list;
1472 current_blob.barcode = current_blob.copy_count;
1473 cp_list.push(current_blob);
1476 if (!vol) { // do the same for vol rows
1481 current_blob = { copy_count : 0 };
1482 angular.forEach(cp_list, function (cp) {
1484 prev_key = cp.owner_list.join('');
1485 current_blob.index = index++;
1486 current_blob.id_list = cp.id_list;
1487 if (cp.raw) current_blob.raw = cp.raw;
1488 current_blob.cn_count = 1;
1489 current_blob.copy_count = cp.copy_count;
1490 current_blob.owner_list = cp.owner_list;
1491 current_blob.owner_label = cp.owner_label;
1492 current_blob.owner_id = cp.owner_id;
1494 var current_key = cp.owner_list.join('');
1495 if (prev_key == current_key) { // collapse into current_blob
1496 current_blob.cn_count++;
1497 current_blob.copy_count += cp.copy_count;
1498 current_blob.id_list = current_blob.id_list.concat(cp.id_list);
1499 if (cp.raw) current_blob.raw = current_blob.raw.concat(cp.raw);
1501 current_blob.barcode = current_blob.copy_count;
1502 current_blob.call_number = { label : current_blob.cn_count };
1503 cn_list.push(current_blob);
1504 prev_key = current_key;
1505 current_blob = { copy_count : 0 };
1506 current_blob.index = index++;
1507 current_blob.id_list = cp.id_list;
1508 if (cp.raw) current_blob.raw = cp.raw;
1509 current_blob.owner_label = cp.owner_label;
1510 current_blob.owner_id = cp.owner_id;
1511 current_blob.cn_count = 1;
1512 current_blob.copy_count = cp.copy_count;
1513 current_blob.owner_list = cp.owner_list;
1518 current_blob.barcode = current_blob.copy_count;
1519 current_blob.call_number = { label : current_blob.cn_count };
1520 cn_list.push(current_blob);
1526 service.copies = new_list;
1527 service.ongoing = false;
1532 // notify reads the stream of copies, one at a time.
1535 var copies = cn.copies().filter(function(cp){ return cp.deleted() == 'f' });
1538 angular.forEach(copies, function (cp) {
1542 var owner_id = cn.owning_lib();
1543 var owner = egCore.org.get(owner_id);
1545 var owner_name_list = [];
1546 while (owner.parent_ou()) { // we're going to skip the top of the tree...
1547 owner_name_list.unshift(owner.name());
1548 owner = egCore.org.get(owner.parent_ou());
1553 angular.forEach(copies, function (cp) {
1554 var flat_cp = egCore.idl.toHash(cp);
1555 flat_cp.owner_id = owner_id;
1556 flat_cp.owner_list = owner_name_list;
1557 flat_cp.id_list = [flat_cp.id];
1562 service.copies = service.copies.concat(flat);
1564 service.copies.push({
1565 owner_id : owner_id,
1566 owner_list : owner_name_list,
1567 call_number: egCore.idl.toHash(cn),
1580 .factory('conjoinedSvc',
1582 function(egCore , $q) {
1585 items : [], // record search results
1586 index : 0, // search grid index
1593 bpbcm : ['target_copy','peer_type'],
1594 acp : ['call_number'],
1596 bre : ['simple_record']
1598 // avoid fetching the MARC blob by specifying which
1599 // fields on the bre to select. More may be needed.
1600 // note that fleshed fields are explicitly selected.
1601 select : { bre : ['id'] },
1602 order_by : { bpbcm : ['id'] },
1605 // resolved with the last received copy
1606 service.fetch = function(rid) {
1607 if (!rid && !service.rid) return $q.when();
1609 if (rid) service.rid = rid;
1613 return egCore.pcrud.search(
1615 {peer_record : service.rid},
1618 ).then( function(list) { // finished
1619 service.items = list;
1620 return service.items;
1624 // returns a promise resolved with the list of peer bib types
1625 service.get_peer_types = function() {
1627 return $q.when(egCore.env.bpt.list);
1629 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
1630 .then(function(list) {
1631 egCore.env.absorbList(list, 'bpt');