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',
231 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc, egConfirmDialog,
232 egGridDataProvider , egHoldGridActions , $timeout , $modal , holdingsSvc , egUser) {
234 // set record ID on page load if available...
235 $scope.record_id = $routeParams.record_id;
237 if ($routeParams.record_id) $scope.from_route = true;
238 else $scope.from_route = false;
240 // will hold a ref to the opac iframe
241 $scope.opac_iframe = null;
242 $scope.parts_iframe = null;
244 $scope.in_opac_call = false;
245 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
246 if ($scope.opac_iframe) {
247 if (force_opac_tab) $scope.record_tab = 'catalog';
248 $scope.in_opac_call = true;
249 $scope.opac_iframe.dom.contentWindow[opac_frame_function]();
253 $scope.add_to_record_bucket = function() {
254 var recId = $scope.record_id;
256 templateUrl: './cat/catalog/t_add_to_bucket',
260 ['$scope','$modalInstance',
261 function($scope , $modalInstance) {
263 $scope.bucket_id = 0;
264 $scope.newBucketName = '';
265 $scope.allBuckets = [];
268 'open-ils.actor.container.retrieve_by_class.authoritative',
269 egCore.auth.token(), egCore.auth.user().id(),
270 'biblio', 'staff_client'
271 ).then(function(buckets) { $scope.allBuckets = buckets; });
273 $scope.add_to_bucket = function() {
274 var item = new egCore.idl.cbrebi();
275 item.bucket($scope.bucket_id);
276 item.target_biblio_record_entry(recId);
279 'open-ils.actor.container.item.create',
280 egCore.auth.token(), 'biblio', item
281 ).then(function(resp) {
282 $modalInstance.close();
286 $scope.add_to_new_bucket = function() {
287 var bucket = new egCore.idl.cbreb();
288 bucket.owner(egCore.auth.user().id());
289 bucket.name($scope.newBucketName);
290 bucket.description('');
291 bucket.btype('staff_client');
295 'open-ils.actor.container.create',
296 egCore.auth.token(), 'biblio', bucket
297 ).then(function(bucket) {
298 $scope.bucket_id = bucket;
299 $scope.add_to_bucket();
303 $scope.cancel = function() {
304 $modalInstance.dismiss();
310 $scope.stop_unload = false;
311 $scope.$watch('stop_unload',
312 function(newVal, oldVal) {
313 if (newVal && newVal != oldVal && $scope.opac_iframe) {
314 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
315 return 'There is unsaved data in this record.'
318 if ($scope.opac_iframe)
319 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
324 // Set the "last bib" cookie, if we have that
325 if ($scope.record_id)
326 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
328 // also set it when the iframe changes to a new record
329 $scope.handle_page = function(url) {
331 if (!url || url == 'about:blank') {
332 // nothing loaded. If we already have a record ID, leave it.
336 var match = url.match(/\/+opac\/+record\/+(\d+)/);
338 $scope.record_id = match[1];
339 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
340 $scope.holdings_record_id_changed($scope.record_id);
343 delete $scope.record_id;
344 $scope.from_route = false;
347 // child scope is executing this function, so our digest doesn't fire ... thus,
350 if (!$scope.in_opac_call) {
351 if ($scope.record_id) {
352 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
353 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
355 tab = $routeParams.record_tab || 'catalog';
357 $scope.set_record_tab(tab);
359 $scope.in_opac_call = false;
363 // xulG catalog handlers
364 $scope.handlers = { }
366 // ------------------------------------------------------------------
369 $scope.holdingsGridControls = {};
370 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
371 get : function(offset, count) {
372 return this.arrayNotifier(holdingsSvc.copies, offset, count);
376 $scope.requestItems = function() {
377 var copy_list = gatherSelectedHoldingsIds();
378 if (copy_list.length == 0) return;
381 templateUrl: './cat/catalog/t_request_items',
384 ['$scope','$modalInstance',
385 function($scope , $modalInstance) {
387 $scope.first_user_fetch = true;
391 copy_list : copy_list,
392 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
393 user : egCore.auth.user().id()
396 egUser.get( $scope.hold_data.user ).then(function(u) {
398 $scope.barcode = u.card().barcode();
399 $scope.user_name = egUser.format_name(u);
400 $scope.hold_data.user = u.id();
403 $scope.user_name = '';
405 $scope.$watch('barcode', function (n) {
406 if (!$scope.first_user_fetch) {
407 egUser.getByBarcode(n).then(function(u) {
409 $scope.user_name = egUser.format_name(u);
410 $scope.hold_data.user = u.id();
413 $scope.user_name = '';
414 delete $scope.hold_data.user;
417 $scope.first_user_fetch = false;
420 $scope.ok = function(h) {
423 hold_type : h.hold_type,
424 pickup_lib: h.pickup_lib.id(),
430 'open-ils.circ.holds.test_and_create.batch.override',
431 egCore.auth.token(), args, h.copy_list
434 $modalInstance.close();
437 $scope.cancel = function($event) {
438 $modalInstance.dismiss();
439 $event.preventDefault();
445 // refresh the list of holdings when the record_id is changed.
446 $scope.holdings_record_id_changed = function(id) {
447 if ($scope.record_id != id) $scope.record_id = id;
448 console.log('record id changed to ' + id + ', loading new holdings');
450 rid : $scope.record_id,
451 org : $scope.holdings_ou,
452 copy: $scope.holdings_show_copies,
453 vol : $scope.holdings_show_vols,
454 empty: $scope.holdings_show_empty
456 $scope.holdingsGridDataProvider.refresh();
460 // refresh the list of holdings when the filter lib is changed.
461 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
462 $scope.holdings_ou_changed = function(org) {
463 $scope.holdings_ou = org;
465 rid : $scope.record_id,
466 org : $scope.holdings_ou,
467 copy: $scope.holdings_show_copies,
468 vol : $scope.holdings_show_vols,
469 empty: $scope.holdings_show_empty
471 $scope.holdingsGridDataProvider.refresh();
475 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
477 egCore.hatch.setItem('cat.' + cb, newVal);
478 if (!norefresh) holdingsSvc.fetch({
479 rid : $scope.record_id,
480 org : $scope.holdings_ou,
481 copy: $scope.holdings_show_copies,
482 vol : $scope.holdings_show_vols,
483 empty: $scope.holdings_show_empty
485 $scope.holdingsGridDataProvider.refresh();
489 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
490 if (typeof x == 'undefined') x = true;
491 $scope.holdings_cb_changed('holdings_show_vols',x,true);
492 $('#holdings_show_vols').prop('checked', x);
494 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
495 if (typeof x == 'undefined') x = true;
496 $scope.holdings_cb_changed('holdings_show_copies',x,true);
497 $('#holdings_show_copies').prop('checked', x);
499 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
500 if (typeof x == 'undefined') x = true;
501 $scope.holdings_cb_changed('holdings_show_empty',x);
502 $('#holdings_show_empty').prop('checked', x);
507 $scope.vols_not_shown = function () {
508 return !$scope.holdings_show_vols;
511 $scope.copies_not_shown = function () {
512 return !$scope.holdings_show_copies;
515 $scope.holdings_checkbox_handler = function (item) {
516 $scope.holdings_cb_changed(item.checkbox,item.checked);
519 function gatherSelectedHoldingsIds () {
522 $scope.holdingsGridControls.selectedItems(),
523 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
528 function gatherSelectedRawCopies () {
531 $scope.holdingsGridControls.selectedItems(),
532 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
537 function gatherSelectedVolumeIds () {
540 $scope.holdingsGridControls.selectedItems(),
542 if (cn_id_list.indexOf(item.call_number.id) == -1)
543 cn_id_list.push(item.call_number.id)
549 $scope.selectedHoldingsDelete = function (vols, copies) {
552 var perCnCopies = {};
558 $scope.holdingsGridControls.selectedItems(),
560 if (vols && item.raw_call_number) {
561 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
562 cnHash[item.call_number.id].isdeleted(1);
565 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
568 var cn_id = cp.call_number().id();
569 if (!cnHash[cn_id]) {
570 cnHash[cn_id] = cp.call_number();
571 perCnCopies[cn_id] = [cp];
573 perCnCopies[cn_id].push(cp);
575 cp.call_number(cn_id); // prevent loops in JSON-ification
582 angular.forEach(perCnCopies, function (v, k) {
584 cnHash[k].isdeleted(1);
591 angular.forEach(cnHash, function (v, k) {
595 if (cnList.length == 0) return;
597 egConfirmDialog.open(
598 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
599 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
600 {copies : cp_count, volumes : cn_count}
601 ).result.then(function() {
604 'open-ils.cat.asset.volume.fleshed.batch.update.override',
605 egCore.auth.token(), cnList, 1, {}
606 ).then(function(update_count) {
607 $scope.holdingsGridDataProvider.refresh();
611 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
612 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
613 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
615 spawnHoldingsAdd = function (vols,copies){
617 if (copies) { // just a copy on existing volumes
618 angular.forEach(gatherSelectedVolumeIds(), function (v) {
619 raw.push( {callnumber : v} );
623 $scope.holdingsGridControls.selectedItems(),
625 raw.push({owner : item.owner_id});
632 'open-ils.actor.anon_cache.set_value',
633 null, 'edit-these-copies', {
634 record_id: $scope.record_id,
639 ).then(function(key) {
641 var url = egCore.env.basePath + 'cat/volcopy/' + key;
642 $timeout(function() { $window.open(url, '_blank') });
644 alert('Could not create anonymous cache key!');
648 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
649 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
651 spawnHoldingsEdit = function (hide_vols,hide_copies){
654 'open-ils.actor.anon_cache.set_value',
655 null, 'edit-these-copies', {
656 record_id: $scope.record_id,
657 copies: gatherSelectedHoldingsIds(),
658 hide_vols : hide_vols,
659 hide_copies : hide_copies
661 ).then(function(key) {
663 var url = egCore.env.basePath + 'cat/volcopy/' + key;
664 $timeout(function() { $window.open(url, '_blank') });
666 alert('Could not create anonymous cache key!');
670 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
671 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
672 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
674 $scope.selectedHoldingsItemStatus = function (){
675 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
676 $timeout(function() { $window.open(url, '_blank') });
679 $scope.markVolAsItemTarget = function() {
680 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
681 egCore.hatch.setLocalItem(
682 'eg.cat.item_transfer_target',
683 $scope.holdingsGridControls.selectedItems()[0].call_number.id
688 $scope.markLibAsVolTarget = function() {
689 egCore.hatch.setLocalItem(
690 'eg.cat.volume_transfer_target',
691 $scope.holdingsGridControls.selectedItems()[0].owner_id
695 $scope.selectedHoldingsItemStatusDetail = function (){
697 gatherSelectedHoldingsIds(),
699 var url = egCore.env.basePath +
701 $timeout(function() { $window.open(url, '_blank') });
706 $scope.transferVolumes = function (){
707 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
712 'open-ils.open-ils.cat.asset.volume.batch.transfer.override',
713 egCore.auth.token(), {
714 docid : $scope.record_id,
716 volumes : gatherSelectedVolumeIds()
718 ).then(function(success) {
721 rid : $scope.record_id,
722 org : $scope.holdings_ou,
723 copy: $scope.holdings_show_copies,
724 vol : $scope.holdings_show_vols,
725 empty: $scope.holdings_show_empty
727 $scope.holdingsGridDataProvider.refresh();
730 alert('Could not transfer volumes!');
737 $scope.transferItems = function (){
738 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
740 var copy_list = gatherSelectedRawCopies();
742 angular.forEach(copy_list, function (cp) {
743 cp.call_number(xfer_target);
748 ).then(function(success) {
751 rid : $scope.record_id,
752 org : $scope.holdings_ou,
753 copy: $scope.holdings_show_copies,
754 vol : $scope.holdings_show_vols,
755 empty: $scope.holdings_show_empty
757 $scope.holdingsGridDataProvider.refresh();
760 alert('Could not transfer items!');
767 $scope.selectedHoldingsItemStatusTgrEvt = function (){
769 gatherSelectedHoldingsIds(),
771 var url = egCore.env.basePath +
772 'cat/item/' + cid + '/triggered_events';
773 $timeout(function() { $window.open(url, '_blank') });
778 $scope.selectedHoldingsItemStatusHolds = function (){
780 gatherSelectedHoldingsIds(),
782 var url = egCore.env.basePath +
783 'cat/item/' + cid + '/holds';
784 $timeout(function() { $window.open(url, '_blank') });
789 $scope.selectedHoldingsDamaged = function () {
790 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
792 rid : $scope.record_id,
793 org : $scope.holdings_ou,
794 copy: $scope.holdings_show_copies,
795 vol : $scope.holdings_show_vols,
796 empty: $scope.holdings_show_empty
798 $scope.holdingsGridDataProvider.refresh();
803 $scope.selectedHoldingsMissing = function () {
804 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
806 rid : $scope.record_id,
807 org : $scope.holdings_ou,
808 copy: $scope.holdings_show_copies,
809 vol : $scope.holdings_show_vols,
810 empty: $scope.holdings_show_empty
812 $scope.holdingsGridDataProvider.refresh();
817 $scope.attach_to_peer_bib = function() {
818 var copy_list = gatherSelectedHoldingsIds();
819 if (copy_list.length == 0) return;
821 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
822 if (!target_record) return;
825 templateUrl: './cat/catalog/t_conjoined_selector',
828 ['$scope','$modalInstance',
829 function($scope , $modalInstance) {
830 $scope.peer_type = null;
831 $scope.peer_type_list = [];
832 holdingsSvc.get_peer_types().then(function(list){
833 $scope.peer_type_list = list;
836 $scope.ok = function(type) {
839 angular.forEach(copy_list, function (cp) {
840 var n = new egCore.idl.bpbcm();
842 n.peer_record(target_record);
845 promises.push(egCore.pcrud.create(n));
848 return $q.all(promises).then(function(){$modalInstance.close()});
851 $scope.cancel = function($event) {
852 $modalInstance.dismiss();
853 $event.preventDefault();
861 // ------------------------------------------------------------------
863 var provider = egGridDataProvider.instance({});
864 $scope.hold_grid_data_provider = provider;
865 $scope.grid_actions = egHoldGridActions;
866 $scope.grid_actions.refresh = function () { provider.refresh() };
867 $scope.hold_grid_controls = {};
869 var hold_ids = []; // current list of holds
870 function fetchHolds(offset, count) {
871 var ids = hold_ids.slice(offset, offset + count);
872 return egHolds.fetch_holds(ids).then(null, null,
873 function(hold_data) {
879 provider.get = function(offset, count) {
880 if ($scope.record_tab != 'holds') return $q.when();
881 var deferred = $q.defer();
882 hold_ids = []; // no caching ATM
887 'open-ils.circ.holds.retrieve_all_from_title',
888 egCore.auth.token(), $scope.record_id,
889 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
891 function(hold_data) {
892 angular.forEach(hold_data, function(list, type) {
893 hold_ids = hold_ids.concat(list);
895 fetchHolds(offset, count).then(
896 deferred.resolve, null, deferred.notify);
900 return deferred.promise;
903 $scope.detail_view = function(action, user_data, items) {
905 $scope.detail_hold_id = h.hold.id();
909 $scope.list_view = function(items) {
910 $scope.detail_hold_id = null;
913 // refresh the list of record holds when the pickup lib is changed.
914 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
915 $scope.pickup_ou_changed = function(org) {
916 $scope.pickup_ou = org;
920 $scope.print_holds = function() {
922 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
924 hold : egCore.idl.toHash(item.hold),
925 patron_last : item.patron_last,
926 patron_alias : item.patron_alias,
927 patron_barcode : item.patron_barcode,
928 copy : egCore.idl.toHash(item.copy),
929 volume : egCore.idl.toHash(item.volume),
930 title : item.mvr.title(),
931 author : item.mvr.author()
937 template : 'holds_for_bib',
938 scope : {holds : holds}
942 $scope.mark_hold_transfer_dest = function() {
943 egCore.hatch.setLocalItem(
944 'eg.circ.hold.title_transfer_target', $scope.record_id);
947 // UI presents this option as "all holds"
948 $scope.transfer_holds_to_marked = function() {
949 var hold_ids = $scope.hold_grid_controls.allItems().map(
950 function(hold_data) {return hold_data.hold.id()});
951 egHolds.transfer_to_marked_title(hold_ids);
954 // ------------------------------------------------------------------
955 // Initialize the selected tab
957 function init_cat_url() {
958 // Set the initial catalog URL. This only happens once.
959 // The URL is otherwise generated through user navigation.
960 if ($scope.catalog_url) return;
962 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
964 // A record ID in the path indicates a request for the record-
966 if ($routeParams.record_id) {
967 url = url.replace(/advanced/, '/record/' + $scope.record_id);
970 $scope.catalog_url = url;
973 function init_parts_url() {
974 $scope.parts_url = $location
978 '/conify/global/biblio/monograph_part?r='+$scope.record_id
982 $scope.set_record_tab = function(tab) {
983 $scope.record_tab = tab;
996 $scope.detail_hold_record_id = $scope.record_id;
997 // refresh the holds grid
1003 $scope.set_default_record_tab = function() {
1004 egCore.hatch.setLocalItem(
1005 'eg.cat.default_record_tab', $scope.record_tab);
1006 $timeout(function(){$scope.default_tab = $scope.record_tab});
1010 if ($scope.record_id) {
1011 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1012 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1015 tab = $routeParams.record_tab || 'catalog';
1017 $scope.set_record_tab(tab);
1021 .controller('AuthorityCtrl',
1022 ['$scope','$routeParams','$location','$window','$q','egCore',
1023 function($scope , $routeParams , $location , $window , $q , egCore) {
1025 // set record ID on page load if available...
1026 $scope.authority_id = $routeParams.authority_id;
1028 if ($routeParams.authority_id) $scope.from_route = true;
1029 else $scope.from_route = false;
1031 $scope.stop_unload = false;
1034 .controller('URLVerifyCtrl',
1035 ['$scope','$location',
1036 function($scope , $location) {
1037 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1040 .controller('VandelayCtrl',
1041 ['$scope','$location',
1042 function($scope , $location) {
1043 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
1046 .controller('ManageAuthoritiesCtrl',
1047 ['$scope','$location',
1048 function($scope , $location) {
1049 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1052 .controller('BatchEditCtrl',
1053 ['$scope','$location','$routeParams',
1054 function($scope , $location , $routeParams) {
1055 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1056 if ($routeParams.container_type) {
1057 switch ($routeParams.container_type) {
1059 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1062 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1069 .filter('boolText', function(){
1070 return function (v) {
1075 .factory('holdingsSvc',
1077 function(egCore , $q) {
1081 copies : [], // record search results
1082 index : 0, // search grid index
1090 acp : ['status','location'],
1091 acn : ['prefix','suffix','copies']
1095 // resolved with the last received copy
1096 service.fetch = function(opts) {
1097 if (service.ongoing) {
1098 console.log('Skipping fetch, ongoing = true');
1104 var copy = opts.copy;
1106 var empty = opts.empty;
1108 if (!rid) return $q.when();
1109 if (!org) return $q.when();
1111 service.ongoing = true;
1115 service.copies = [];
1118 var org_list = egCore.org.descendants(org.id(), true);
1119 console.log('Holdings fetch with: rid='+rid+' org='+org_list+' copy='+copy+' vol='+vol+' empty='+empty);
1121 return egCore.pcrud.search(
1123 {record : rid, owning_lib : org_list, deleted : 'f'},
1126 function() { // finished
1127 service.copies = service.copies.sort(
1129 function compare_array (x, y, i) {
1130 if (x[i] && y[i]) { // both have values
1131 if (x[i] == y[i]) { // need to look deeper
1132 return compare_array(x, y, ++i);
1135 if (x[i] < y[i]) { // x is first
1137 } else if (x[i] > y[i]) { // y is first
1141 } else { // no orgs to compare ...
1142 if (x[i]) return -1;
1148 var owner_order = compare_array(a.owner_list, b.owner_list, 0);
1150 // now compare on CN label
1151 if (a.call_number.label < b.call_number.label) return -1;
1152 if (a.call_number.label > b.call_number.label) return 1;
1155 if (a.copy_number < b.copy_number) return -1;
1156 if (a.copy_number > b.copy_number) return 1;
1159 if (a.barcode < b.barcode) return -1;
1160 if (a.barcode > b.barcode) return 1;
1166 // create a label using just the unique part of the owner list
1168 var prev_owner_list;
1169 angular.forEach(service.copies, function (cp) {
1170 if (!prev_owner_list) {
1171 cp.owner_label = cp.owner_list.join(' ... ');
1173 var current_owner_list = cp.owner_list.slice();
1174 while (current_owner_list[1] && prev_owner_list[1] && current_owner_list[0] == prev_owner_list[0]) {
1175 current_owner_list.shift();
1176 prev_owner_list.shift();
1178 cp.owner_label = current_owner_list.join(' ... ');
1182 prev_owner_list = cp.owner_list.slice();
1185 var new_list = service.copies;
1186 if (!copy || !vol) { // collapse copy rows, supply a count instead
1191 var current_blob = { copy_count : 0 };
1192 angular.forEach(new_list, function (cp) {
1194 prev_key = cp.owner_list.join('') + cp.call_number.label;
1195 if (cp.barcode) current_blob.copy_count = 1;
1196 current_blob.index = index++;
1197 current_blob.id_list = cp.id_list;
1198 if (cp.raw) current_blob.raw = cp.raw;
1199 current_blob.call_number = cp.call_number;
1200 current_blob.owner_list = cp.owner_list;
1201 current_blob.owner_label = cp.owner_label;
1202 current_blob.owner_id = cp.owner_id;
1204 var current_key = cp.owner_list.join('') + cp.call_number.label;
1205 if (prev_key == current_key) { // collapse into current_blob
1206 current_blob.copy_count++;
1207 current_blob.id_list = current_blob.id_list.concat(cp.id_list);
1208 current_blob.raw = current_blob.raw.concat(cp.raw);
1210 current_blob.barcode = current_blob.copy_count;
1211 cp_list.push(current_blob);
1212 prev_key = current_key;
1213 current_blob = { copy_count : 0 };
1214 if (cp.barcode) current_blob.copy_count = 1;
1215 current_blob.index = index++;
1216 current_blob.id_list = cp.id_list;
1217 if (cp.raw) current_blob.raw = cp.raw;
1218 current_blob.owner_label = cp.owner_label;
1219 current_blob.owner_id = cp.owner_id;
1220 current_blob.call_number = cp.call_number;
1221 current_blob.owner_list = cp.owner_list;
1226 current_blob.barcode = current_blob.copy_count;
1227 cp_list.push(current_blob);
1230 if (!vol) { // do the same for vol rows
1235 current_blob = { copy_count : 0 };
1236 angular.forEach(cp_list, function (cp) {
1238 prev_key = cp.owner_list.join('');
1239 current_blob.index = index++;
1240 current_blob.id_list = cp.id_list;
1241 if (cp.raw) current_blob.raw = cp.raw;
1242 current_blob.cn_count = 1;
1243 current_blob.copy_count = cp.copy_count;
1244 current_blob.owner_list = cp.owner_list;
1245 current_blob.owner_label = cp.owner_label;
1246 current_blob.owner_id = cp.owner_id;
1248 var current_key = cp.owner_list.join('');
1249 if (prev_key == current_key) { // collapse into current_blob
1250 current_blob.cn_count++;
1251 current_blob.copy_count += cp.copy_count;
1252 current_blob.id_list = current_blob.id_list.concat(cp.id_list);
1253 if (cp.raw) current_blob.raw = current_blob.raw.concat(cp.raw);
1255 current_blob.barcode = current_blob.copy_count;
1256 current_blob.call_number = { label : current_blob.cn_count };
1257 cn_list.push(current_blob);
1258 prev_key = current_key;
1259 current_blob = { copy_count : 0 };
1260 current_blob.index = index++;
1261 current_blob.id_list = cp.id_list;
1262 if (cp.raw) current_blob.raw = cp.raw;
1263 current_blob.owner_label = cp.owner_label;
1264 current_blob.owner_id = cp.owner_id;
1265 current_blob.cn_count = 1;
1266 current_blob.copy_count = cp.copy_count;
1267 current_blob.owner_list = cp.owner_list;
1272 current_blob.barcode = current_blob.copy_count;
1273 current_blob.call_number = { label : current_blob.cn_count };
1274 cn_list.push(current_blob);
1280 service.copies = new_list;
1281 service.ongoing = false;
1286 // notify reads the stream of copies, one at a time.
1289 var copies = cn.copies().filter(function(cp){ return cp.deleted() == 'f' });
1292 angular.forEach(copies, function (cp) {
1296 var owner_id = cn.owning_lib();
1297 var owner = egCore.org.get(owner_id);
1299 var owner_name_list = [];
1300 while (owner.parent_ou()) { // we're going to skip the top of the tree...
1301 owner_name_list.unshift(owner.name());
1302 owner = egCore.org.get(owner.parent_ou());
1307 angular.forEach(copies, function (cp) {
1308 var flat_cp = egCore.idl.toHash(cp);
1309 flat_cp.owner_id = owner_id;
1310 flat_cp.owner_list = owner_name_list;
1311 flat_cp.id_list = [flat_cp.id];
1316 service.copies = service.copies.concat(flat);
1318 service.copies.push({
1319 owner_id : owner_id,
1320 owner_list : owner_name_list,
1321 call_number: egCore.idl.toHash(cn),
1331 // returns a promise resolved with the list of peer bib types
1332 service.get_peer_types = function() {
1334 return $q.when(egCore.env.bpt.list);
1336 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
1337 .then(function(list) {
1338 egCore.env.absorbList(list, 'bpt');