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','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]();
254 $scope.add_to_record_bucket = function() {
255 var recId = $scope.record_id;
257 templateUrl: './cat/catalog/t_add_to_bucket',
261 ['$scope','$modalInstance',
262 function($scope , $modalInstance) {
264 $scope.bucket_id = 0;
265 $scope.newBucketName = '';
266 $scope.allBuckets = [];
269 'open-ils.actor.container.retrieve_by_class.authoritative',
270 egCore.auth.token(), egCore.auth.user().id(),
271 'biblio', 'staff_client'
272 ).then(function(buckets) { $scope.allBuckets = buckets; });
274 $scope.add_to_bucket = function() {
275 var item = new egCore.idl.cbrebi();
276 item.bucket($scope.bucket_id);
277 item.target_biblio_record_entry(recId);
280 'open-ils.actor.container.item.create',
281 egCore.auth.token(), 'biblio', item
282 ).then(function(resp) {
283 $modalInstance.close();
287 $scope.add_to_new_bucket = function() {
288 var bucket = new egCore.idl.cbreb();
289 bucket.owner(egCore.auth.user().id());
290 bucket.name($scope.newBucketName);
291 bucket.description('');
292 bucket.btype('staff_client');
296 'open-ils.actor.container.create',
297 egCore.auth.token(), 'biblio', bucket
298 ).then(function(bucket) {
299 $scope.bucket_id = bucket;
300 $scope.add_to_bucket();
304 $scope.cancel = function() {
305 $modalInstance.dismiss();
311 $scope.stop_unload = false;
312 $scope.$watch('stop_unload',
313 function(newVal, oldVal) {
314 if (newVal && newVal != oldVal && $scope.opac_iframe) {
315 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
316 return 'There is unsaved data in this record.'
319 if ($scope.opac_iframe)
320 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
325 // Set the "last bib" cookie, if we have that
326 if ($scope.record_id)
327 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
329 $scope.refresh_record_callback = function (record_id) {
330 egCore.pcrud.retrieve('bre', record_id, {
333 bre : ['simple_record','creator','editor']
335 }).then(function(rec) {
336 rec.owner(egCore.org.get(rec.owner()));
337 $scope.summary_pane_record = rec;
343 // also set it when the iframe changes to a new record
344 $scope.handle_page = function(url) {
346 if (!url || url == 'about:blank') {
347 // nothing loaded. If we already have a record ID, leave it.
351 var match = url.match(/\/+opac\/+record\/+(\d+)/);
353 $scope.record_id = match[1];
354 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
355 $scope.holdings_record_id_changed($scope.record_id);
356 conjoinedSvc.fetch($scope.record_id).then(function(){
357 $scope.conjoinedGridDataProvider.refresh();
361 delete $scope.record_id;
362 $scope.from_route = false;
365 // child scope is executing this function, so our digest doesn't fire ... thus,
368 if (!$scope.in_opac_call) {
369 if ($scope.record_id) {
370 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
371 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
373 tab = $routeParams.record_tab || 'catalog';
375 $scope.set_record_tab(tab);
377 $scope.in_opac_call = false;
381 // xulG catalog handlers
382 $scope.handlers = { }
384 // ------------------------------------------------------------------
387 $scope.conjoinedGridControls = {};
388 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
389 get : function(offset, count) {
390 return this.arrayNotifier(conjoinedSvc.items, offset, count);
394 $scope.changeConjoinedType = function () {
395 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
396 angular.forEach(peers, function (p) {
397 p.target_copy(p.target_copy().id());
398 p.peer_type(p.peer_type().id());
401 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
404 templateUrl: './cat/catalog/t_conjoined_selector',
407 ['$scope','$modalInstance',
408 function($scope , $modalInstance) {
409 $scope.update = true;
411 $scope.peer_type = null;
412 $scope.peer_type_list = [];
413 conjoinedSvc.get_peer_types().then(function(list){
414 $scope.peer_type_list = list;
417 $scope.ok = function(type) {
420 angular.forEach(peers, function (p) {
423 promises.push(egCore.pcrud.update(p));
426 return $q.all(promises)
427 .then(function(){$modalInstance.close()})
428 .then(function(){return conjoinedSvc.fetch()})
429 .then(function(){conjoinedGridDataProviderRef.refresh()});
432 $scope.cancel = function($event) {
433 $modalInstance.dismiss();
434 $event.preventDefault();
441 $scope.refreshConjoined = function () {
442 conjoinedSvc.fetch($scope.record_id)
443 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
446 $scope.deleteSelectedConjoined = function () {
447 var peers = $scope.conjoinedGridControls.selectedItems();
449 if (peers.length > 0) {
450 egConfirmDialog.open(
451 egCore.strings.CONFIRM_DELETE_PEERS,
452 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
453 {peers : peers.length}
454 ).result.then(function() {
455 angular.forEach(peers, function (p) {
459 egCore.pcrud.remove(peers).then(function() {
460 return conjoinedSvc.fetch();
462 $scope.conjoinedGridDataProvider.refresh();
467 if ($scope.record_id)
468 conjoinedSvc.fetch($scope.record_id);
470 // ------------------------------------------------------------------
473 $scope.holdingsGridControls = {};
474 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
475 get : function(offset, count) {
476 return this.arrayNotifier(holdingsSvc.copies, offset, count);
480 $scope.add_copies_to_bucket = function() {
481 var copy_list = gatherSelectedHoldingsIds();
482 if (copy_list.length == 0) return;
485 templateUrl: './cat/catalog/t_add_to_bucket',
489 ['$scope','$modalInstance',
490 function($scope , $modalInstance) {
492 $scope.bucket_id = 0;
493 $scope.newBucketName = '';
494 $scope.allBuckets = [];
498 'open-ils.actor.container.retrieve_by_class.authoritative',
499 egCore.auth.token(), egCore.auth.user().id(),
500 'copy', 'staff_client'
501 ).then(function(buckets) { $scope.allBuckets = buckets; });
503 $scope.add_to_bucket = function() {
505 angular.forEach(copy_list, function (cp) {
506 var item = new egCore.idl.ccbi()
507 item.bucket($scope.bucket_id);
508 item.target_copy(cp);
512 'open-ils.actor.container.item.create',
513 egCore.auth.token(), 'copy', item
517 return $q.all(promises).then(function() {
518 $modalInstance.close();
523 $scope.add_to_new_bucket = function() {
524 var bucket = new egCore.idl.ccb();
525 bucket.owner(egCore.auth.user().id());
526 bucket.name($scope.newBucketName);
527 bucket.description('');
528 bucket.btype('staff_client');
530 return egCore.net.request(
532 'open-ils.actor.container.create',
533 egCore.auth.token(), 'copy', bucket
534 ).then(function(bucket) {
535 $scope.bucket_id = bucket;
536 $scope.add_to_bucket();
540 $scope.cancel = function() {
541 $modalInstance.dismiss();
547 $scope.requestItems = function() {
548 var copy_list = gatherSelectedHoldingsIds();
549 if (copy_list.length == 0) return;
552 templateUrl: './cat/catalog/t_request_items',
555 ['$scope','$modalInstance',
556 function($scope , $modalInstance) {
558 $scope.first_user_fetch = true;
562 copy_list : copy_list,
563 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
564 user : egCore.auth.user().id()
567 egUser.get( $scope.hold_data.user ).then(function(u) {
569 $scope.barcode = u.card().barcode();
570 $scope.user_name = egUser.format_name(u);
571 $scope.hold_data.user = u.id();
574 $scope.user_name = '';
576 $scope.$watch('barcode', function (n) {
577 if (!$scope.first_user_fetch) {
578 egUser.getByBarcode(n).then(function(u) {
580 $scope.user_name = egUser.format_name(u);
581 $scope.hold_data.user = u.id();
584 $scope.user_name = '';
585 delete $scope.hold_data.user;
588 $scope.first_user_fetch = false;
591 $scope.ok = function(h) {
594 hold_type : h.hold_type,
595 pickup_lib: h.pickup_lib.id(),
601 'open-ils.circ.holds.test_and_create.batch.override',
602 egCore.auth.token(), args, h.copy_list
605 $modalInstance.close();
608 $scope.cancel = function($event) {
609 $modalInstance.dismiss();
610 $event.preventDefault();
616 $scope.replaceBarcodes = function() {
617 var copy_list = gatherSelectedRawCopies();
618 if (copy_list.length == 0) return;
620 var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
622 angular.forEach(copy_list, function (cp) {
624 templateUrl: './cat/share/t_replace_barcode',
627 ['$scope','$modalInstance',
628 function($scope , $modalInstance) {
629 $scope.isModal = true;
630 $scope.focusBarcode = false;
631 $scope.focusBarcode2 = true;
632 $scope.barcode1 = cp.barcode();
634 $scope.updateBarcode = function() {
635 $scope.copyNotFound = false;
636 $scope.updateOK = false;
638 egCore.pcrud.search('acp',
639 {deleted : 'f', barcode : $scope.barcode1})
640 .then(function(copy) {
643 $scope.focusBarcode = true;
644 $scope.copyNotFound = true;
648 $scope.copyId = copy.id();
649 copy.barcode($scope.barcode2);
651 egCore.pcrud.update(copy).then(function(stat) {
652 $scope.updateOK = stat;
653 $scope.focusBarcode = true;
654 holdingsSvc.fetchAgain().then(function (){
655 holdingsGridDataProviderRef.refresh();
660 $modalInstance.close();
663 $scope.cancel = function($event) {
664 $modalInstance.dismiss();
665 $event.preventDefault();
673 // refresh the list of holdings when the record_id is changed.
674 $scope.holdings_record_id_changed = function(id) {
675 if ($scope.record_id != id) $scope.record_id = id;
676 console.log('record id changed to ' + id + ', loading new holdings');
678 rid : $scope.record_id,
679 org : $scope.holdings_ou,
680 copy: $scope.holdings_show_copies,
681 vol : $scope.holdings_show_vols,
682 empty: $scope.holdings_show_empty
684 $scope.holdingsGridDataProvider.refresh();
688 // refresh the list of holdings when the filter lib is changed.
689 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
690 $scope.holdings_ou_changed = function(org) {
691 $scope.holdings_ou = org;
693 rid : $scope.record_id,
694 org : $scope.holdings_ou,
695 copy: $scope.holdings_show_copies,
696 vol : $scope.holdings_show_vols,
697 empty: $scope.holdings_show_empty
699 $scope.holdingsGridDataProvider.refresh();
703 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
705 egCore.hatch.setItem('cat.' + cb, newVal);
706 if (!norefresh) holdingsSvc.fetch({
707 rid : $scope.record_id,
708 org : $scope.holdings_ou,
709 copy: $scope.holdings_show_copies,
710 vol : $scope.holdings_show_vols,
711 empty: $scope.holdings_show_empty
713 $scope.holdingsGridDataProvider.refresh();
717 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
718 if (typeof x == 'undefined') x = true;
719 $scope.holdings_cb_changed('holdings_show_vols',x,true);
720 $('#holdings_show_vols').prop('checked', x);
722 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
723 if (typeof x == 'undefined') x = true;
724 $scope.holdings_cb_changed('holdings_show_copies',x,true);
725 $('#holdings_show_copies').prop('checked', x);
727 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
728 if (typeof x == 'undefined') x = true;
729 $scope.holdings_cb_changed('holdings_show_empty',x);
730 $('#holdings_show_empty').prop('checked', x);
735 $scope.vols_not_shown = function () {
736 return !$scope.holdings_show_vols;
739 $scope.copies_not_shown = function () {
740 return !$scope.holdings_show_copies;
743 $scope.holdings_checkbox_handler = function (item) {
744 $scope.holdings_cb_changed(item.checkbox,item.checked);
747 function gatherSelectedHoldingsIds () {
750 $scope.holdingsGridControls.selectedItems(),
751 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
756 function gatherSelectedRawCopies () {
759 $scope.holdingsGridControls.selectedItems(),
760 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
765 function gatherSelectedVolumeIds () {
768 $scope.holdingsGridControls.selectedItems(),
770 if (cn_id_list.indexOf(item.call_number.id) == -1)
771 cn_id_list.push(item.call_number.id)
777 $scope.selectedHoldingsDelete = function (vols, copies) {
780 var perCnCopies = {};
786 $scope.holdingsGridControls.selectedItems(),
788 if (vols && item.raw_call_number) {
789 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
790 cnHash[item.call_number.id].isdeleted(1);
793 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
796 var cn_id = cp.call_number().id();
797 if (!cnHash[cn_id]) {
798 cnHash[cn_id] = cp.call_number();
799 perCnCopies[cn_id] = [cp];
801 perCnCopies[cn_id].push(cp);
803 cp.call_number(cn_id); // prevent loops in JSON-ification
810 angular.forEach(perCnCopies, function (v, k) {
812 cnHash[k].isdeleted(1);
819 angular.forEach(cnHash, function (v, k) {
823 if (cnList.length == 0) return;
825 egConfirmDialog.open(
826 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
827 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
828 {copies : cp_count, volumes : cn_count}
829 ).result.then(function() {
832 'open-ils.cat.asset.volume.fleshed.batch.update.override',
833 egCore.auth.token(), cnList, 1, {}
834 ).then(function(update_count) {
835 $scope.holdingsGridDataProvider.refresh();
839 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
840 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
841 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
843 spawnHoldingsAdd = function (vols,copies){
845 if (copies) { // just a copy on existing volumes
846 angular.forEach(gatherSelectedVolumeIds(), function (v) {
847 raw.push( {callnumber : v} );
851 $scope.holdingsGridControls.selectedItems(),
853 raw.push({owner : item.owner_id});
858 if (raw.length == 0) raw.push({});
862 'open-ils.actor.anon_cache.set_value',
863 null, 'edit-these-copies', {
864 record_id: $scope.record_id,
869 ).then(function(key) {
871 var url = egCore.env.basePath + 'cat/volcopy/' + key;
872 $timeout(function() { $window.open(url, '_blank') });
874 alert('Could not create anonymous cache key!');
878 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
879 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
881 spawnHoldingsEdit = function (hide_vols,hide_copies){
884 'open-ils.actor.anon_cache.set_value',
885 null, 'edit-these-copies', {
886 record_id: $scope.record_id,
887 copies: gatherSelectedHoldingsIds(),
888 hide_vols : hide_vols,
889 hide_copies : hide_copies
891 ).then(function(key) {
893 var url = egCore.env.basePath + 'cat/volcopy/' + key;
894 $timeout(function() { $window.open(url, '_blank') });
896 alert('Could not create anonymous cache key!');
900 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
901 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
902 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
904 $scope.selectedHoldingsItemStatus = function (){
905 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
906 $timeout(function() { $window.open(url, '_blank') });
909 $scope.markVolAsItemTarget = function() {
910 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
911 egCore.hatch.setLocalItem(
912 'eg.cat.item_transfer_target',
913 $scope.holdingsGridControls.selectedItems()[0].call_number.id
918 $scope.markLibAsVolTarget = function() {
919 egCore.hatch.setLocalItem(
920 'eg.cat.volume_transfer_target',
921 $scope.holdingsGridControls.selectedItems()[0].owner_id
925 $scope.selectedHoldingsItemStatusDetail = function (){
927 gatherSelectedHoldingsIds(),
929 var url = egCore.env.basePath +
931 $timeout(function() { $window.open(url, '_blank') });
936 $scope.transferVolumes = function (){
937 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
942 'open-ils.open-ils.cat.asset.volume.batch.transfer.override',
943 egCore.auth.token(), {
944 docid : $scope.record_id,
946 volumes : gatherSelectedVolumeIds()
948 ).then(function(success) {
950 holdingsSvc.fetchAgain().then(function() {
951 $scope.holdingsGridDataProvider.refresh();
954 alert('Could not transfer volumes!');
961 $scope.transferItems = function (){
962 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
963 var copy_ids = gatherSelectedHoldingsIds();
964 if (xfer_target && copy_ids.length > 0) {
967 'open-ils.cat.transfer_copies_to_volume',
972 function(resp) { // oncomplete
973 var evt = egCore.evt.parse(resp);
975 egConfirmDialog.open(
976 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_TITLE,
977 egCore.strings.OVERRIDE_TRANSFER_COPIES_TO_MARKED_VOLUME_BODY,
978 {'evt_desc': evt.desc}
979 ).result.then(function() {
982 'open-ils.cat.transfer_copies_to_volume.override',
986 { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
987 ).then(function(resp) {
988 holdingsSvc.fetchAgain().then(function() {
989 $scope.holdingsGridDataProvider.refresh();
994 holdingsSvc.fetchAgain().then(function() {
995 $scope.holdingsGridDataProvider.refresh();
1005 $scope.selectedHoldingsItemStatusTgrEvt = function (){
1007 gatherSelectedHoldingsIds(),
1009 var url = egCore.env.basePath +
1010 'cat/item/' + cid + '/triggered_events';
1011 $timeout(function() { $window.open(url, '_blank') });
1016 $scope.selectedHoldingsItemStatusHolds = function (){
1018 gatherSelectedHoldingsIds(),
1020 var url = egCore.env.basePath +
1021 'cat/item/' + cid + '/holds';
1022 $timeout(function() { $window.open(url, '_blank') });
1027 $scope.selectedHoldingsDamaged = function () {
1028 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
1029 holdingsSvc.fetchAgain().then(function() {
1030 $scope.holdingsGridDataProvider.refresh();
1035 $scope.selectedHoldingsMissing = function () {
1036 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
1037 holdingsSvc.fetchAgain().then(function() {
1038 $scope.holdingsGridDataProvider.refresh();
1043 $scope.attach_to_peer_bib = function() {
1044 var copy_list = gatherSelectedHoldingsIds();
1045 if (copy_list.length == 0) return;
1047 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
1048 if (!target_record) return;
1050 return $modal.open({
1051 templateUrl: './cat/catalog/t_conjoined_selector',
1054 ['$scope','$modalInstance',
1055 function($scope , $modalInstance) {
1056 $scope.update = false;
1058 $scope.peer_type = null;
1059 $scope.peer_type_list = [];
1060 conjoinedSvc.get_peer_types().then(function(list){
1061 $scope.peer_type_list = list;
1064 $scope.ok = function(type) {
1067 angular.forEach(copy_list, function (cp) {
1068 var n = new egCore.idl.bpbcm();
1070 n.peer_record(target_record);
1073 promises.push(egCore.pcrud.create(n));
1076 return $q.all(promises).then(function(){$modalInstance.close()});
1079 $scope.cancel = function($event) {
1080 $modalInstance.dismiss();
1081 $event.preventDefault();
1089 // ------------------------------------------------------------------
1091 var provider = egGridDataProvider.instance({});
1092 $scope.hold_grid_data_provider = provider;
1093 $scope.grid_actions = egHoldGridActions;
1094 $scope.grid_actions.refresh = function () { provider.refresh() };
1095 $scope.hold_grid_controls = {};
1097 var hold_ids = []; // current list of holds
1098 function fetchHolds(offset, count) {
1099 var ids = hold_ids.slice(offset, offset + count);
1100 return egHolds.fetch_holds(ids).then(null, null,
1101 function(hold_data) {
1107 provider.get = function(offset, count) {
1108 if ($scope.record_tab != 'holds') return $q.when();
1109 var deferred = $q.defer();
1110 hold_ids = []; // no caching ATM
1115 'open-ils.circ.holds.retrieve_all_from_title',
1116 egCore.auth.token(), $scope.record_id,
1117 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
1119 function(hold_data) {
1120 angular.forEach(hold_data, function(list, type) {
1121 hold_ids = hold_ids.concat(list);
1123 fetchHolds(offset, count).then(
1124 deferred.resolve, null, deferred.notify);
1128 return deferred.promise;
1131 $scope.detail_view = function(action, user_data, items) {
1133 $scope.detail_hold_id = h.hold.id();
1137 $scope.list_view = function(items) {
1138 $scope.detail_hold_id = null;
1141 // refresh the list of record holds when the pickup lib is changed.
1142 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1143 $scope.pickup_ou_changed = function(org) {
1144 $scope.pickup_ou = org;
1148 $scope.print_holds = function() {
1150 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1152 hold : egCore.idl.toHash(item.hold),
1153 patron_last : item.patron_last,
1154 patron_alias : item.patron_alias,
1155 patron_barcode : item.patron_barcode,
1156 copy : egCore.idl.toHash(item.copy),
1157 volume : egCore.idl.toHash(item.volume),
1158 title : item.mvr.title(),
1159 author : item.mvr.author()
1163 egCore.print.print({
1164 context : 'receipt',
1165 template : 'holds_for_bib',
1166 scope : {holds : holds}
1170 $scope.mark_hold_transfer_dest = function() {
1171 egCore.hatch.setLocalItem(
1172 'eg.circ.hold.title_transfer_target', $scope.record_id);
1175 // UI presents this option as "all holds"
1176 $scope.transfer_holds_to_marked = function() {
1177 var hold_ids = $scope.hold_grid_controls.allItems().map(
1178 function(hold_data) {return hold_data.hold.id()});
1179 egHolds.transfer_to_marked_title(hold_ids);
1182 // ------------------------------------------------------------------
1183 // Initialize the selected tab
1185 function init_cat_url() {
1186 // Set the initial catalog URL. This only happens once.
1187 // The URL is otherwise generated through user navigation.
1188 if ($scope.catalog_url) return;
1190 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1192 // A record ID in the path indicates a request for the record-
1194 if ($routeParams.record_id) {
1195 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1198 $scope.catalog_url = url;
1201 function init_parts_url() {
1202 $scope.parts_url = $location
1206 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1210 $scope.set_record_tab = function(tab) {
1211 $scope.record_tab = tab;
1224 $scope.detail_hold_record_id = $scope.record_id;
1225 // refresh the holds grid
1231 $scope.set_default_record_tab = function() {
1232 egCore.hatch.setLocalItem(
1233 'eg.cat.default_record_tab', $scope.record_tab);
1234 $timeout(function(){$scope.default_tab = $scope.record_tab});
1238 if ($scope.record_id) {
1239 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1240 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1243 tab = $routeParams.record_tab || 'catalog';
1245 $scope.set_record_tab(tab);
1249 .controller('AuthorityCtrl',
1250 ['$scope','$routeParams','$location','$window','$q','egCore',
1251 function($scope , $routeParams , $location , $window , $q , egCore) {
1253 // set record ID on page load if available...
1254 $scope.authority_id = $routeParams.authority_id;
1256 if ($routeParams.authority_id) $scope.from_route = true;
1257 else $scope.from_route = false;
1259 $scope.stop_unload = false;
1262 .controller('URLVerifyCtrl',
1263 ['$scope','$location',
1264 function($scope , $location) {
1265 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1268 .controller('VandelayCtrl',
1269 ['$scope','$location',
1270 function($scope , $location) {
1271 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
1274 .controller('ManageAuthoritiesCtrl',
1275 ['$scope','$location',
1276 function($scope , $location) {
1277 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1280 .controller('BatchEditCtrl',
1281 ['$scope','$location','$routeParams',
1282 function($scope , $location , $routeParams) {
1283 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1284 if ($routeParams.container_type) {
1285 switch ($routeParams.container_type) {
1287 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1290 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1297 .filter('boolText', function(){
1298 return function (v) {
1303 .factory('holdingsSvc',
1305 function(egCore , $q) {
1309 copies : [], // record search results
1310 index : 0, // search grid index
1318 acp : ['status','location'],
1319 acn : ['prefix','suffix','copies']
1323 service.fetchAgain = function() {
1324 return service.fetch({
1329 empty: service.empty
1333 // resolved with the last received copy
1334 service.fetch = function(opts) {
1335 if (service.ongoing) {
1336 console.log('Skipping fetch, ongoing = true');
1342 var copy = opts.copy;
1344 var empty = opts.empty;
1346 if (!rid) return $q.when();
1347 if (!org) return $q.when();
1349 service.ongoing = true;
1353 service.copy = opts.copy;
1354 service.vol = opts.vol;
1355 service.empty = opts.empty;
1357 service.copies = [];
1360 var org_list = egCore.org.descendants(org.id(), true);
1361 console.log('Holdings fetch with: rid='+rid+' org='+org_list+' copy='+copy+' vol='+vol+' empty='+empty);
1363 return egCore.pcrud.search(
1365 {record : rid, owning_lib : org_list, deleted : 'f'},
1368 function() { // finished
1369 service.copies = service.copies.sort(
1371 function compare_array (x, y, i) {
1372 if (x[i] && y[i]) { // both have values
1373 if (x[i] == y[i]) { // need to look deeper
1374 return compare_array(x, y, ++i);
1377 if (x[i] < y[i]) { // x is first
1379 } else if (x[i] > y[i]) { // y is first
1383 } else { // no orgs to compare ...
1384 if (x[i]) return -1;
1390 var owner_order = compare_array(a.owner_list, b.owner_list, 0);
1392 // now compare on CN label
1393 if (a.call_number.label < b.call_number.label) return -1;
1394 if (a.call_number.label > b.call_number.label) return 1;
1397 if (a.copy_number < b.copy_number) return -1;
1398 if (a.copy_number > b.copy_number) return 1;
1401 if (a.barcode < b.barcode) return -1;
1402 if (a.barcode > b.barcode) return 1;
1408 // create a label using just the unique part of the owner list
1410 var prev_owner_list;
1411 angular.forEach(service.copies, function (cp) {
1412 if (!prev_owner_list) {
1413 cp.owner_label = cp.owner_list.join(' ... ');
1415 var current_owner_list = cp.owner_list.slice();
1416 while (current_owner_list[1] && prev_owner_list[1] && current_owner_list[0] == prev_owner_list[0]) {
1417 current_owner_list.shift();
1418 prev_owner_list.shift();
1420 cp.owner_label = current_owner_list.join(' ... ');
1424 prev_owner_list = cp.owner_list.slice();
1427 var new_list = service.copies;
1428 if (!copy || !vol) { // collapse copy rows, supply a count instead
1433 var current_blob = { copy_count : 0 };
1434 angular.forEach(new_list, function (cp) {
1436 prev_key = cp.owner_list.join('') + cp.call_number.label;
1437 if (cp.barcode) current_blob.copy_count = 1;
1438 current_blob.index = index++;
1439 current_blob.id_list = cp.id_list;
1440 if (cp.raw) current_blob.raw = cp.raw;
1441 current_blob.call_number = cp.call_number;
1442 current_blob.owner_list = cp.owner_list;
1443 current_blob.owner_label = cp.owner_label;
1444 current_blob.owner_id = cp.owner_id;
1446 var current_key = cp.owner_list.join('') + cp.call_number.label;
1447 if (prev_key == current_key) { // collapse into current_blob
1448 current_blob.copy_count++;
1449 current_blob.id_list = current_blob.id_list.concat(cp.id_list);
1450 current_blob.raw = current_blob.raw.concat(cp.raw);
1452 current_blob.barcode = current_blob.copy_count;
1453 cp_list.push(current_blob);
1454 prev_key = current_key;
1455 current_blob = { copy_count : 0 };
1456 if (cp.barcode) current_blob.copy_count = 1;
1457 current_blob.index = index++;
1458 current_blob.id_list = cp.id_list;
1459 if (cp.raw) current_blob.raw = cp.raw;
1460 current_blob.owner_label = cp.owner_label;
1461 current_blob.owner_id = cp.owner_id;
1462 current_blob.call_number = cp.call_number;
1463 current_blob.owner_list = cp.owner_list;
1468 current_blob.barcode = current_blob.copy_count;
1469 cp_list.push(current_blob);
1472 if (!vol) { // do the same for vol rows
1477 current_blob = { copy_count : 0 };
1478 angular.forEach(cp_list, function (cp) {
1480 prev_key = cp.owner_list.join('');
1481 current_blob.index = index++;
1482 current_blob.id_list = cp.id_list;
1483 if (cp.raw) current_blob.raw = cp.raw;
1484 current_blob.cn_count = 1;
1485 current_blob.copy_count = cp.copy_count;
1486 current_blob.owner_list = cp.owner_list;
1487 current_blob.owner_label = cp.owner_label;
1488 current_blob.owner_id = cp.owner_id;
1490 var current_key = cp.owner_list.join('');
1491 if (prev_key == current_key) { // collapse into current_blob
1492 current_blob.cn_count++;
1493 current_blob.copy_count += cp.copy_count;
1494 current_blob.id_list = current_blob.id_list.concat(cp.id_list);
1495 if (cp.raw) current_blob.raw = current_blob.raw.concat(cp.raw);
1497 current_blob.barcode = current_blob.copy_count;
1498 current_blob.call_number = { label : current_blob.cn_count };
1499 cn_list.push(current_blob);
1500 prev_key = current_key;
1501 current_blob = { copy_count : 0 };
1502 current_blob.index = index++;
1503 current_blob.id_list = cp.id_list;
1504 if (cp.raw) current_blob.raw = cp.raw;
1505 current_blob.owner_label = cp.owner_label;
1506 current_blob.owner_id = cp.owner_id;
1507 current_blob.cn_count = 1;
1508 current_blob.copy_count = cp.copy_count;
1509 current_blob.owner_list = cp.owner_list;
1514 current_blob.barcode = current_blob.copy_count;
1515 current_blob.call_number = { label : current_blob.cn_count };
1516 cn_list.push(current_blob);
1522 service.copies = new_list;
1523 service.ongoing = false;
1528 // notify reads the stream of copies, one at a time.
1531 var copies = cn.copies().filter(function(cp){ return cp.deleted() == 'f' });
1534 angular.forEach(copies, function (cp) {
1538 var owner_id = cn.owning_lib();
1539 var owner = egCore.org.get(owner_id);
1541 var owner_name_list = [];
1542 while (owner.parent_ou()) { // we're going to skip the top of the tree...
1543 owner_name_list.unshift(owner.name());
1544 owner = egCore.org.get(owner.parent_ou());
1549 angular.forEach(copies, function (cp) {
1550 var flat_cp = egCore.idl.toHash(cp);
1551 flat_cp.owner_id = owner_id;
1552 flat_cp.owner_list = owner_name_list;
1553 flat_cp.id_list = [flat_cp.id];
1558 service.copies = service.copies.concat(flat);
1560 service.copies.push({
1561 owner_id : owner_id,
1562 owner_list : owner_name_list,
1563 call_number: egCore.idl.toHash(cn),
1576 .factory('conjoinedSvc',
1578 function(egCore , $q) {
1581 items : [], // record search results
1582 index : 0, // search grid index
1589 bpbcm : ['target_copy','peer_type'],
1590 acp : ['call_number'],
1592 bre : ['simple_record']
1594 // avoid fetching the MARC blob by specifying which
1595 // fields on the bre to select. More may be needed.
1596 // note that fleshed fields are explicitly selected.
1597 select : { bre : ['id'] },
1598 order_by : { bpbcm : ['id'] },
1601 // resolved with the last received copy
1602 service.fetch = function(rid) {
1603 if (!rid && !service.rid) return $q.when();
1605 if (rid) service.rid = rid;
1609 return egCore.pcrud.search(
1611 {peer_record : service.rid},
1614 ).then( function(list) { // finished
1615 service.items = list;
1616 return service.items;
1620 // returns a promise resolved with the list of peer bib types
1621 service.get_peer_types = function() {
1623 return $q.when(egCore.env.bpt.list);
1625 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
1626 .then(function(list) {
1627 egCore.env.absorbList(list, 'bpt');