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',
230 'egGridDataProvider','egHoldGridActions','$timeout','$modal','holdingsSvc','egUser',
231 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc,
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.stop_unload = false;
254 $scope.$watch('stop_unload',
255 function(newVal, oldVal) {
256 if (newVal && newVal != oldVal && $scope.opac_iframe) {
257 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
258 return 'There is unsaved data in this record.'
261 if ($scope.opac_iframe)
262 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
267 // Set the "last bib" cookie, if we have that
268 if ($scope.record_id)
269 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
271 // also set it when the iframe changes to a new record
272 $scope.handle_page = function(url) {
274 if (!url || url == 'about:blank') {
275 // nothing loaded. If we already have a record ID, leave it.
279 var match = url.match(/\/+opac\/+record\/+(\d+)/);
281 $scope.record_id = match[1];
282 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
283 $scope.holdings_record_id_changed($scope.record_id);
286 delete $scope.record_id;
287 $scope.from_route = false;
290 // child scope is executing this function, so our digest doesn't fire ... thus,
293 if (!$scope.in_opac_call) {
294 if ($scope.record_id) {
295 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
296 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
298 tab = $routeParams.record_tab || 'catalog';
300 $scope.set_record_tab(tab);
302 $scope.in_opac_call = false;
306 // xulG catalog handlers
307 $scope.handlers = { }
309 // ------------------------------------------------------------------
312 $scope.holdingsGridControls = {};
313 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
314 get : function(offset, count) {
315 return this.arrayNotifier(holdingsSvc.copies, offset, count);
319 $scope.requestItems = function() {
320 var copy_list = gatherSelectedHoldingsIds();
321 if (copy_list.length == 0) return;
324 templateUrl: './cat/catalog/t_request_items',
327 ['$scope','$modalInstance',
328 function($scope , $modalInstance) {
330 $scope.first_user_fetch = true;
334 copy_list : copy_list,
335 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
336 user : egCore.auth.user().id()
339 egUser.get( $scope.hold_data.user ).then(function(u) {
341 $scope.barcode = u.card().barcode();
342 $scope.user_name = egUser.format_name(u);
343 $scope.hold_data.user = u.id();
346 $scope.user_name = '';
348 $scope.$watch('barcode', function (n) {
349 if (!$scope.first_user_fetch) {
350 egUser.getByBarcode(n).then(function(u) {
352 $scope.user_name = egUser.format_name(u);
353 $scope.hold_data.user = u.id();
356 $scope.user_name = '';
357 delete $scope.hold_data.user;
360 $scope.first_user_fetch = false;
363 $scope.ok = function(h) {
366 hold_type : h.hold_type,
367 pickup_lib: h.pickup_lib.id(),
373 'open-ils.circ.holds.test_and_create.batch.override',
374 egCore.auth.token(), args, h.copy_list
377 $modalInstance.close();
380 $scope.cancel = function($event) {
381 $modalInstance.dismiss();
382 $event.preventDefault();
388 // refresh the list of holdings when the record_id is changed.
389 $scope.holdings_record_id_changed = function(id) {
390 if ($scope.record_id != id) $scope.record_id = id;
391 console.log('record id changed to ' + id + ', loading new holdings');
393 rid : $scope.record_id,
394 org : $scope.holdings_ou,
395 copy: $scope.holdings_show_copies,
396 vol : $scope.holdings_show_vols,
397 empty: $scope.holdings_show_empty
399 $scope.holdingsGridDataProvider.refresh();
403 // refresh the list of holdings when the filter lib is changed.
404 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
405 $scope.holdings_ou_changed = function(org) {
406 $scope.holdings_ou = org;
408 rid : $scope.record_id,
409 org : $scope.holdings_ou,
410 copy: $scope.holdings_show_copies,
411 vol : $scope.holdings_show_vols,
412 empty: $scope.holdings_show_empty
414 $scope.holdingsGridDataProvider.refresh();
418 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
420 egCore.hatch.setItem('cat.' + cb, newVal);
421 if (!norefresh) holdingsSvc.fetch({
422 rid : $scope.record_id,
423 org : $scope.holdings_ou,
424 copy: $scope.holdings_show_copies,
425 vol : $scope.holdings_show_vols,
426 empty: $scope.holdings_show_empty
428 $scope.holdingsGridDataProvider.refresh();
432 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
433 if (typeof x == 'undefined') x = true;
434 $scope.holdings_cb_changed('holdings_show_vols',x,true);
435 $('#holdings_show_vols').prop('checked', x);
437 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
438 if (typeof x == 'undefined') x = true;
439 $scope.holdings_cb_changed('holdings_show_copies',x,true);
440 $('#holdings_show_copies').prop('checked', x);
442 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
443 if (typeof x == 'undefined') x = true;
444 $scope.holdings_cb_changed('holdings_show_empty',x);
445 $('#holdings_show_empty').prop('checked', x);
450 $scope.vols_not_shown = function () {
451 return !$scope.holdings_show_vols;
454 $scope.holdings_checkbox_handler = function (item) {
455 $scope.holdings_cb_changed(item.checkbox,item.checked);
458 function gatherSelectedHoldingsIds () {
461 $scope.holdingsGridControls.selectedItems(),
462 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
467 function gatherSelectedRawCopies () {
470 $scope.holdingsGridControls.selectedItems(),
471 function (item) { cp_list = cp_list.concat(item.raw) }
476 function gatherSelectedVolumeIds () {
479 $scope.holdingsGridControls.selectedItems(),
481 if (cn_id_list.indexOf(item.call_number.id) == -1)
482 cn_id_list.push(item.call_number.id)
488 spawnHoldingsAdd = function (hide_vols,hide_copies){
490 if (hide_vols) { // just a copy on existing volumes
491 angular.forEach(gatherSelectedVolumeIds(), function (v) {
492 raw.push( {callnumber : v} );
496 $scope.holdingsGridControls.selectedItems(),
498 raw.push({owner : item.owner_id});
505 'open-ils.actor.anon_cache.set_value',
506 null, 'edit-these-copies', {
507 record_id: $scope.record_id,
509 hide_vols : hide_vols,
510 hide_copies : hide_copies
512 ).then(function(key) {
514 var url = egCore.env.basePath + 'cat/volcopy/' + key;
515 $timeout(function() { $window.open(url, '_blank') });
517 alert('Could not create anonymous cache key!');
521 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(false,false) }
522 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(true,false) }
524 spawnHoldingsEdit = function (hide_vols,hide_copies){
527 'open-ils.actor.anon_cache.set_value',
528 null, 'edit-these-copies', {
529 record_id: $scope.record_id,
530 copies: gatherSelectedHoldingsIds(),
531 hide_vols : hide_vols,
532 hide_copies : hide_copies
534 ).then(function(key) {
536 var url = egCore.env.basePath + 'cat/volcopy/' + key;
537 $timeout(function() { $window.open(url, '_blank') });
539 alert('Could not create anonymous cache key!');
543 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
544 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
545 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
547 $scope.selectedHoldingsItemStatus = function (){
548 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
549 $timeout(function() { $window.open(url, '_blank') });
552 $scope.markVolAsItemTarget = function() {
553 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
554 egCore.hatch.setLocalItem(
555 'eg.cat.item_transfer_target',
556 $scope.holdingsGridControls.selectedItems()[0].call_number.id
561 $scope.markLibAsVolTarget = function() {
562 egCore.hatch.setLocalItem(
563 'eg.cat.volume_transfer_target',
564 $scope.holdingsGridControls.selectedItems()[0].owner_id
568 $scope.selectedHoldingsItemStatusDetail = function (){
570 gatherSelectedHoldingsIds(),
572 var url = egCore.env.basePath +
574 $timeout(function() { $window.open(url, '_blank') });
579 $scope.transferVolumes = function (){
580 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
585 'open-ils.open-ils.cat.asset.volume.batch.transfer.override',
586 egCore.auth.token(), {
587 docid : $scope.record_id,
589 volumes : gatherSelectedVolumeIds()
591 ).then(function(success) {
594 rid : $scope.record_id,
595 org : $scope.holdings_ou,
596 copy: $scope.holdings_show_copies,
597 vol : $scope.holdings_show_vols,
598 empty: $scope.holdings_show_empty
600 $scope.holdingsGridDataProvider.refresh();
603 alert('Could not transfer volumes!');
610 $scope.transferItems = function (){
611 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
613 var copy_list = gatherSelectedRawCopies();
615 angular.forEach(copy_list, function (cp) {
616 cp.call_number(xfer_target);
621 ).then(function(success) {
624 rid : $scope.record_id,
625 org : $scope.holdings_ou,
626 copy: $scope.holdings_show_copies,
627 vol : $scope.holdings_show_vols,
628 empty: $scope.holdings_show_empty
630 $scope.holdingsGridDataProvider.refresh();
633 alert('Could not transfer items!');
640 $scope.selectedHoldingsItemStatusTgrEvt = function (){
642 gatherSelectedHoldingsIds(),
644 var url = egCore.env.basePath +
645 'cat/item/' + cid + '/triggered_events';
646 $timeout(function() { $window.open(url, '_blank') });
651 $scope.selectedHoldingsItemStatusHolds = function (){
653 gatherSelectedHoldingsIds(),
655 var url = egCore.env.basePath +
656 'cat/item/' + cid + '/holds';
657 $timeout(function() { $window.open(url, '_blank') });
662 $scope.selectedHoldingsDamaged = function () {
663 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
665 rid : $scope.record_id,
666 org : $scope.holdings_ou,
667 copy: $scope.holdings_show_copies,
668 vol : $scope.holdings_show_vols,
669 empty: $scope.holdings_show_empty
671 $scope.holdingsGridDataProvider.refresh();
676 $scope.selectedHoldingsMissing = function () {
677 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
679 rid : $scope.record_id,
680 org : $scope.holdings_ou,
681 copy: $scope.holdings_show_copies,
682 vol : $scope.holdings_show_vols,
683 empty: $scope.holdings_show_empty
685 $scope.holdingsGridDataProvider.refresh();
691 // ------------------------------------------------------------------
693 var provider = egGridDataProvider.instance({});
694 $scope.hold_grid_data_provider = provider;
695 $scope.grid_actions = egHoldGridActions;
696 $scope.grid_actions.refresh = function () { provider.refresh() };
697 $scope.hold_grid_controls = {};
699 var hold_ids = []; // current list of holds
700 function fetchHolds(offset, count) {
701 var ids = hold_ids.slice(offset, offset + count);
702 return egHolds.fetch_holds(ids).then(null, null,
703 function(hold_data) {
709 provider.get = function(offset, count) {
710 if ($scope.record_tab != 'holds') return $q.when();
711 var deferred = $q.defer();
712 hold_ids = []; // no caching ATM
717 'open-ils.circ.holds.retrieve_all_from_title',
718 egCore.auth.token(), $scope.record_id,
719 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
721 function(hold_data) {
722 angular.forEach(hold_data, function(list, type) {
723 hold_ids = hold_ids.concat(list);
725 fetchHolds(offset, count).then(
726 deferred.resolve, null, deferred.notify);
730 return deferred.promise;
733 $scope.detail_view = function(action, user_data, items) {
735 $scope.detail_hold_id = h.hold.id();
739 $scope.list_view = function(items) {
740 $scope.detail_hold_id = null;
743 // refresh the list of record holds when the pickup lib is changed.
744 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
745 $scope.pickup_ou_changed = function(org) {
746 $scope.pickup_ou = org;
750 $scope.print_holds = function() {
752 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
754 hold : egCore.idl.toHash(item.hold),
755 patron_last : item.patron_last,
756 patron_alias : item.patron_alias,
757 patron_barcode : item.patron_barcode,
758 copy : egCore.idl.toHash(item.copy),
759 volume : egCore.idl.toHash(item.volume),
760 title : item.mvr.title(),
761 author : item.mvr.author()
767 template : 'holds_for_bib',
768 scope : {holds : holds}
772 $scope.mark_hold_transfer_dest = function() {
773 egCore.hatch.setLocalItem(
774 'eg.circ.hold.title_transfer_target', $scope.record_id);
777 // UI presents this option as "all holds"
778 $scope.transfer_holds_to_marked = function() {
779 var hold_ids = $scope.hold_grid_controls.allItems().map(
780 function(hold_data) {return hold_data.hold.id()});
781 egHolds.transfer_to_marked_title(hold_ids);
784 // ------------------------------------------------------------------
785 // Initialize the selected tab
787 function init_cat_url() {
788 // Set the initial catalog URL. This only happens once.
789 // The URL is otherwise generated through user navigation.
790 if ($scope.catalog_url) return;
792 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
794 // A record ID in the path indicates a request for the record-
796 if ($routeParams.record_id) {
797 url = url.replace(/advanced/, '/record/' + $scope.record_id);
800 $scope.catalog_url = url;
803 function init_parts_url() {
804 $scope.parts_url = $location
808 '/conify/global/biblio/monograph_part?r='+$scope.record_id
812 $scope.set_record_tab = function(tab) {
813 $scope.record_tab = tab;
826 $scope.detail_hold_record_id = $scope.record_id;
827 // refresh the holds grid
833 $scope.set_default_record_tab = function() {
834 egCore.hatch.setLocalItem(
835 'eg.cat.default_record_tab', $scope.record_tab);
836 $timeout(function(){$scope.default_tab = $scope.record_tab});
840 if ($scope.record_id) {
841 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
842 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
845 tab = $routeParams.record_tab || 'catalog';
847 $scope.set_record_tab(tab);
851 .controller('AuthorityCtrl',
852 ['$scope','$routeParams','$location','$window','$q','egCore',
853 function($scope , $routeParams , $location , $window , $q , egCore) {
855 // set record ID on page load if available...
856 $scope.authority_id = $routeParams.authority_id;
858 if ($routeParams.authority_id) $scope.from_route = true;
859 else $scope.from_route = false;
861 $scope.stop_unload = false;
864 .controller('URLVerifyCtrl',
865 ['$scope','$location',
866 function($scope , $location) {
867 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
870 .controller('VandelayCtrl',
871 ['$scope','$location',
872 function($scope , $location) {
873 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
876 .controller('ManageAuthoritiesCtrl',
877 ['$scope','$location',
878 function($scope , $location) {
879 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
882 .controller('BatchEditCtrl',
883 ['$scope','$location','$routeParams',
884 function($scope , $location , $routeParams) {
885 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
886 if ($routeParams.container_type) {
887 switch ($routeParams.container_type) {
889 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
892 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
899 .filter('boolText', function(){
900 return function (v) {
905 .factory('holdingsSvc',
907 function(egCore , $q) {
911 copies : [], // record search results
912 index : 0, // search grid index
920 acp : ['status','location'],
921 acn : ['prefix','suffix','copies']
925 // resolved with the last received copy
926 service.fetch = function(opts) {
927 if (service.ongoing) {
928 console.log('Skipping fetch, ongoing = true');
934 var copy = opts.copy;
936 var empty = opts.empty;
938 if (!rid) return $q.when();
939 if (!org) return $q.when();
941 service.ongoing = true;
948 var org_list = egCore.org.descendants(org.id(), true);
949 console.log('Holdings fetch with: rid='+rid+' org='+org_list+' copy='+copy+' vol='+vol+' empty='+empty);
951 return egCore.pcrud.search(
953 {record : rid, owning_lib : org_list, deleted : 'f'},
956 function() { // finished
957 service.copies = service.copies.sort(
959 function compare_array (x, y, i) {
960 if (x[i] && y[i]) { // both have values
961 if (x[i] == y[i]) { // need to look deeper
962 return compare_array(x, y, ++i);
965 if (x[i] < y[i]) { // x is first
967 } else if (x[i] > y[i]) { // y is first
971 } else { // no orgs to compare ...
978 var owner_order = compare_array(a.owner_list, b.owner_list, 0);
980 // now compare on CN label
981 if (a.call_number.label < b.call_number.label) return -1;
982 if (a.call_number.label > b.call_number.label) return 1;
985 if (a.copy_number < b.copy_number) return -1;
986 if (a.copy_number > b.copy_number) return 1;
989 if (a.barcode < b.barcode) return -1;
990 if (a.barcode > b.barcode) return 1;
996 // create a label using just the unique part of the owner list
999 angular.forEach(service.copies, function (cp) {
1000 if (!prev_owner_list) {
1001 cp.owner_label = cp.owner_list.join(' ... ');
1003 var current_owner_list = cp.owner_list.slice();
1004 while (current_owner_list[1] && prev_owner_list[1] && current_owner_list[0] == prev_owner_list[0]) {
1005 current_owner_list.shift();
1006 prev_owner_list.shift();
1008 cp.owner_label = current_owner_list.join(' ... ');
1012 prev_owner_list = cp.owner_list.slice();
1015 var new_list = service.copies;
1016 if (!copy || !vol) { // collapse copy rows, supply a count instead
1021 var current_blob = {};
1022 angular.forEach(new_list, function (cp) {
1024 prev_key = cp.owner_list.join('') + cp.call_number.label;
1025 if (cp.barcode) current_blob.copy_count = 1;
1026 current_blob.index = index++;
1027 current_blob.id_list = cp.id_list;
1028 current_blob.raw = cp.raw;
1029 current_blob.call_number = cp.call_number;
1030 current_blob.owner_list = cp.owner_list;
1031 current_blob.owner_label = cp.owner_label;
1032 current_blob.owner_id = cp.owner_id;
1034 var current_key = cp.owner_list.join('') + cp.call_number.label;
1035 if (prev_key == current_key) { // collapse into current_blob
1036 current_blob.copy_count++;
1037 current_blob.id_list = current_blob.id_list.concat(cp.id_list);
1038 current_blob.raw = current_blob.raw.concat(cp.raw);
1040 current_blob.barcode = current_blob.copy_count;
1041 cp_list.push(current_blob);
1042 prev_key = current_key;
1044 if (cp.barcode) current_blob.copy_count = 1;
1045 current_blob.index = index++;
1046 current_blob.id_list = cp.id_list;
1047 current_blob.raw = cp.raw;
1048 current_blob.owner_label = cp.owner_label;
1049 current_blob.owner_id = cp.owner_id;
1050 current_blob.call_number = cp.call_number;
1051 current_blob.owner_list = cp.owner_list;
1056 current_blob.barcode = current_blob.copy_count;
1057 cp_list.push(current_blob);
1060 if (!vol) { // do the same for vol rows
1065 var current_blob = {};
1066 angular.forEach(cp_list, function (cp) {
1068 prev_key = cp.owner_list.join('');
1069 current_blob.index = index++;
1070 current_blob.id_list = cp.id_list;
1071 current_blob.raw = cp.raw;
1072 current_blob.cn_count = 1;
1073 current_blob.copy_count = cp.copy_count;
1074 current_blob.owner_list = cp.owner_list;
1075 current_blob.owner_label = cp.owner_label;
1076 current_blob.owner_id = cp.owner_id;
1078 var current_key = cp.owner_list.join('');
1079 if (prev_key == current_key) { // collapse into current_blob
1080 current_blob.cn_count++;
1081 current_blob.copy_count += cp.copy_count;
1082 current_blob.id_list = current_blob.id_list.concat(cp.id_list);
1083 current_blob.raw = current_blob.raw.concat(cp.raw);
1085 current_blob.barcode = current_blob.copy_count;
1086 current_blob.call_number = { label : current_blob.cn_count };
1087 cn_list.push(current_blob);
1088 prev_key = current_key;
1090 current_blob.index = index++;
1091 current_blob.id_list = cp.id_list;
1092 current_blob.raw = cp.raw;
1093 current_blob.owner_label = cp.owner_label;
1094 current_blob.owner_id = cp.owner_id;
1095 current_blob.cn_count = 1;
1096 current_blob.copy_count = cp.copy_count;
1097 current_blob.owner_list = cp.owner_list;
1102 current_blob.barcode = current_blob.copy_count;
1103 current_blob.call_number = { label : current_blob.cn_count };
1104 cn_list.push(current_blob);
1110 service.copies = new_list;
1111 service.ongoing = false;
1116 // notify reads the stream of copies, one at a time.
1119 var copies = cn.copies();
1122 angular.forEach(copies, function (cp) {
1126 var owner_id = cn.owning_lib();
1127 var owner = egCore.org.get(owner_id);
1129 var owner_name_list = [];
1130 while (owner.parent_ou()) { // we're going to skip the top of the tree...
1131 owner_name_list.unshift(owner.name());
1132 owner = egCore.org.get(owner.parent_ou());
1137 angular.forEach(copies, function (cp) {
1138 var flat_cp = egCore.idl.toHash(cp);
1139 flat_cp.owner_id = owner_id;
1140 flat_cp.owner_list = owner_name_list;
1141 flat_cp.id_list = [flat_cp.id];
1146 service.copies = service.copies.concat(flat);
1148 service.copies.push({
1149 owner_id : owner_id,
1150 owner_list : owner_name_list,
1151 call_number: egCore.idl.toHash(cn)