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'])
12 .config(function($routeProvider, $locationProvider, $compileProvider) {
13 $locationProvider.html5Mode(true);
14 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
16 var resolver = {delay : ['egCore','egStartup', function(egCore, egStartup) {
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','holdingsSvc',
231 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc,
232 egGridDataProvider , egHoldGridActions , $timeout , holdingsSvc) {
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 // refresh the list of holdings when the record_id is changed.
320 $scope.holdings_record_id_changed = function(id) {
321 if ($scope.record_id != id) $scope.record_id = id;
322 console.log('record id changed to ' + id + ', loading new holdings');
324 rid : $scope.record_id,
325 org : $scope.holdings_ou,
326 copy: $scope.holdings_show_copies,
327 vol : $scope.holdings_show_vols,
328 empty: $scope.holdings_show_empty
330 $scope.holdingsGridDataProvider.refresh();
334 // refresh the list of holdings when the filter lib is changed.
335 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
336 $scope.holdings_ou_changed = function(org) {
337 $scope.holdings_ou = org;
339 rid : $scope.record_id,
340 org : $scope.holdings_ou,
341 copy: $scope.holdings_show_copies,
342 vol : $scope.holdings_show_vols,
343 empty: $scope.holdings_show_empty
345 $scope.holdingsGridDataProvider.refresh();
349 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
351 egCore.hatch.setItem('cat.' + cb, newVal);
352 if (!norefresh) holdingsSvc.fetch({
353 rid : $scope.record_id,
354 org : $scope.holdings_ou,
355 copy: $scope.holdings_show_copies,
356 vol : $scope.holdings_show_vols,
357 empty: $scope.holdings_show_empty
359 $scope.holdingsGridDataProvider.refresh();
363 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
364 if (typeof x == 'undefined') x = true;
365 $scope.holdings_cb_changed('holdings_show_vols',x,true);
366 $('#holdings_show_vols').prop('checked', x);
368 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
369 if (typeof x == 'undefined') x = true;
370 $scope.holdings_cb_changed('holdings_show_copies',x,true);
371 $('#holdings_show_copies').prop('checked', x);
373 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
374 if (typeof x == 'undefined') x = true;
375 $scope.holdings_cb_changed('holdings_show_empty',x);
376 $('#holdings_show_empty').prop('checked', x);
381 $scope.vols_not_shown = function () {
382 return !$scope.holdings_show_vols;
385 $scope.holdings_checkbox_handler = function (item) {
386 $scope.holdings_cb_changed(item.checkbox,item.checked);
389 function gatherSelectedHoldingsIds () {
392 $scope.holdingsGridControls.selectedItems(),
393 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
398 function gatherSelectedRawCopies () {
401 $scope.holdingsGridControls.selectedItems(),
402 function (item) { cp_list = cp_list.concat(item.raw) }
407 function gatherSelectedVolumeIds () {
410 $scope.holdingsGridControls.selectedItems(),
412 if (cn_id_list.indexOf(item.call_number.id) == -1)
413 cn_id_list.push(item.call_number.id)
419 spawnHoldingsAdd = function (hide_vols,hide_copies){
421 if (hide_vols) { // just a copy on existing volumes
422 angular.forEach(gatherSelectedVolumeIds(), function (v) {
423 raw.push( {callnumber : v} );
427 $scope.holdingsGridControls.selectedItems(),
429 raw.push({owner : item.owner_id});
436 'open-ils.actor.anon_cache.set_value',
437 null, 'edit-these-copies', {
438 record_id: $scope.record_id,
440 hide_vols : hide_vols,
441 hide_copies : hide_copies
443 ).then(function(key) {
445 var url = egCore.env.basePath + 'cat/volcopy/' + key;
446 $timeout(function() { $window.open(url, '_blank') });
448 alert('Could not create anonymous cache key!');
452 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(false,false) }
453 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(true,false) }
455 spawnHoldingsEdit = function (hide_vols,hide_copies){
458 'open-ils.actor.anon_cache.set_value',
459 null, 'edit-these-copies', {
460 record_id: $scope.record_id,
461 copies: gatherSelectedHoldingsIds(),
462 hide_vols : hide_vols,
463 hide_copies : hide_copies
465 ).then(function(key) {
467 var url = egCore.env.basePath + 'cat/volcopy/' + key;
468 $timeout(function() { $window.open(url, '_blank') });
470 alert('Could not create anonymous cache key!');
474 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
475 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
476 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
478 $scope.selectedHoldingsItemStatus = function (){
479 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
480 $timeout(function() { $window.open(url, '_blank') });
483 $scope.markVolAsItemTarget = function() {
484 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
485 egCore.hatch.setLocalItem(
486 'eg.cat.item_transfer_target',
487 $scope.holdingsGridControls.selectedItems()[0].call_number.id
489 console.log('item_transfer_dest: '+$scope.holdingsGridControls.selectedItems()[0].call_number.id);
493 $scope.markLibAsVolTarget = function() {
494 egCore.hatch.setLocalItem(
495 'eg.cat.volume_transfer_target',
496 $scope.holdingsGridControls.selectedItems()[0].owner_id
498 console.log('vol_transfer_dest: '+$scope.holdingsGridControls.selectedItems()[0].owner_id);
501 $scope.selectedHoldingsItemStatusDetail = function (){
503 gatherSelectedHoldingsIds(),
505 var url = egCore.env.basePath +
507 $timeout(function() { $window.open(url, '_blank') });
512 $scope.transferVolumes = function (){
513 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
518 'open-ils.open-ils.cat.asset.volume.batch.transfer.override',
519 egCore.auth.token(), {
520 docid : $scope.record_id,
522 volumes : gatherSelectedVolumeIds()
524 ).then(function(success) {
527 rid : $scope.record_id,
528 org : $scope.holdings_ou,
529 copy: $scope.holdings_show_copies,
530 vol : $scope.holdings_show_vols,
531 empty: $scope.holdings_show_empty
533 $scope.holdingsGridDataProvider.refresh();
536 alert('Could not transfer volumes!');
543 $scope.transferItems = function (){
544 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
546 var copy_list = gatherSelectedRawCopies();
548 angular.forEach(copy_list, function (cp) {
549 cp.call_number(xfer_target);
554 ).then(function(success) {
557 rid : $scope.record_id,
558 org : $scope.holdings_ou,
559 copy: $scope.holdings_show_copies,
560 vol : $scope.holdings_show_vols,
561 empty: $scope.holdings_show_empty
563 $scope.holdingsGridDataProvider.refresh();
566 alert('Could not transfer items!');
573 $scope.selectedHoldingsItemStatusTgrEvt = function (){
575 gatherSelectedHoldingsIds(),
577 var url = egCore.env.basePath +
578 'cat/item/' + cid + '/triggered_events';
579 $timeout(function() { $window.open(url, '_blank') });
584 $scope.selectedHoldingsItemStatusHolds = function (){
586 gatherSelectedHoldingsIds(),
588 var url = egCore.env.basePath +
589 'cat/item/' + cid + '/holds';
590 $timeout(function() { $window.open(url, '_blank') });
595 $scope.selectedHoldingsDamaged = function () {
596 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
598 rid : $scope.record_id,
599 org : $scope.holdings_ou,
600 copy: $scope.holdings_show_copies,
601 vol : $scope.holdings_show_vols,
602 empty: $scope.holdings_show_empty
604 $scope.holdingsGridDataProvider.refresh();
609 $scope.selectedHoldingsMissing = function () {
610 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
612 rid : $scope.record_id,
613 org : $scope.holdings_ou,
614 copy: $scope.holdings_show_copies,
615 vol : $scope.holdings_show_vols,
616 empty: $scope.holdings_show_empty
618 $scope.holdingsGridDataProvider.refresh();
624 // ------------------------------------------------------------------
626 var provider = egGridDataProvider.instance({});
627 $scope.hold_grid_data_provider = provider;
628 $scope.grid_actions = egHoldGridActions;
629 $scope.grid_actions.refresh = function () { provider.refresh() };
630 $scope.hold_grid_controls = {};
632 var hold_ids = []; // current list of holds
633 function fetchHolds(offset, count) {
634 var ids = hold_ids.slice(offset, offset + count);
635 return egHolds.fetch_holds(ids).then(null, null,
636 function(hold_data) {
642 provider.get = function(offset, count) {
643 if ($scope.record_tab != 'holds') return $q.when();
644 var deferred = $q.defer();
645 hold_ids = []; // no caching ATM
650 'open-ils.circ.holds.retrieve_all_from_title',
651 egCore.auth.token(), $scope.record_id,
652 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
654 function(hold_data) {
655 angular.forEach(hold_data, function(list, type) {
656 hold_ids = hold_ids.concat(list);
658 fetchHolds(offset, count).then(
659 deferred.resolve, null, deferred.notify);
663 return deferred.promise;
666 $scope.detail_view = function(action, user_data, items) {
668 $scope.detail_hold_id = h.hold.id();
672 $scope.list_view = function(items) {
673 $scope.detail_hold_id = null;
676 // refresh the list of record holds when the pickup lib is changed.
677 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
678 $scope.pickup_ou_changed = function(org) {
679 $scope.pickup_ou = org;
683 $scope.print_holds = function() {
685 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
687 hold : egCore.idl.toHash(item.hold),
688 patron_last : item.patron_last,
689 patron_alias : item.patron_alias,
690 patron_barcode : item.patron_barcode,
691 copy : egCore.idl.toHash(item.copy),
692 volume : egCore.idl.toHash(item.volume),
693 title : item.mvr.title(),
694 author : item.mvr.author()
700 template : 'holds_for_bib',
701 scope : {holds : holds}
705 $scope.mark_hold_transfer_dest = function() {
706 egCore.hatch.setLocalItem(
707 'eg.circ.hold.title_transfer_target', $scope.record_id);
710 // UI presents this option as "all holds"
711 $scope.transfer_holds_to_marked = function() {
712 var hold_ids = $scope.hold_grid_controls.allItems().map(
713 function(hold_data) {return hold_data.hold.id()});
714 egHolds.transfer_to_marked_title(hold_ids);
717 // ------------------------------------------------------------------
718 // Initialize the selected tab
720 function init_cat_url() {
721 // Set the initial catalog URL. This only happens once.
722 // The URL is otherwise generated through user navigation.
723 if ($scope.catalog_url) return;
725 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
727 // A record ID in the path indicates a request for the record-
729 if ($routeParams.record_id) {
730 url = url.replace(/advanced/, '/record/' + $scope.record_id);
733 $scope.catalog_url = url;
736 function init_parts_url() {
737 $scope.parts_url = $location
741 '/conify/global/biblio/monograph_part?r='+$scope.record_id
745 $scope.set_record_tab = function(tab) {
746 $scope.record_tab = tab;
759 $scope.detail_hold_record_id = $scope.record_id;
760 // refresh the holds grid
766 $scope.set_default_record_tab = function() {
767 egCore.hatch.setLocalItem(
768 'eg.cat.default_record_tab', $scope.record_tab);
769 $timeout(function(){$scope.default_tab = $scope.record_tab});
773 if ($scope.record_id) {
774 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
775 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
778 tab = $routeParams.record_tab || 'catalog';
780 $scope.set_record_tab(tab);
784 .controller('AuthorityCtrl',
785 ['$scope','$routeParams','$location','$window','$q','egCore',
786 function($scope , $routeParams , $location , $window , $q , egCore) {
788 // set record ID on page load if available...
789 $scope.authority_id = $routeParams.authority_id;
791 if ($routeParams.authority_id) $scope.from_route = true;
792 else $scope.from_route = false;
794 $scope.stop_unload = false;
797 .controller('URLVerifyCtrl',
798 ['$scope','$location',
799 function($scope , $location) {
800 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
803 .controller('VandelayCtrl',
804 ['$scope','$location',
805 function($scope , $location) {
806 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
809 .controller('ManageAuthoritiesCtrl',
810 ['$scope','$location',
811 function($scope , $location) {
812 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
815 .controller('BatchEditCtrl',
816 ['$scope','$location','$routeParams',
817 function($scope , $location , $routeParams) {
818 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
819 if ($routeParams.container_type) {
820 switch ($routeParams.container_type) {
822 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
825 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
832 .filter('boolText', function(){
833 return function (v) {
838 .factory('holdingsSvc',
840 function(egCore , $q) {
844 copies : [], // record search results
845 index : 0, // search grid index
853 acp : ['status','location'],
854 acn : ['prefix','suffix','copies']
858 // resolved with the last received copy
859 service.fetch = function(opts) {
860 if (service.ongoing) {
861 console.log('Skipping fetch, ongoing = true');
867 var copy = opts.copy;
869 var empty = opts.empty;
871 if (!rid) return $q.when();
872 if (!org) return $q.when();
874 service.ongoing = true;
881 var org_list = egCore.org.descendants(org.id(), true);
882 console.log('Holdings fetch with: rid='+rid+' org='+org_list+' copy='+copy+' vol='+vol+' empty='+empty);
884 return egCore.pcrud.search(
886 {record : rid, owning_lib : org_list, deleted : 'f'},
889 function() { // finished
890 service.copies = service.copies.sort(
892 function compare_array (x, y, i) {
893 if (x[i] && y[i]) { // both have values
894 if (x[i] == y[i]) { // need to look deeper
895 return compare_array(x, y, ++i);
898 if (x[i] < y[i]) { // x is first
900 } else if (x[i] > y[i]) { // y is first
904 } else { // no orgs to compare ...
911 var owner_order = compare_array(a.owner_list, b.owner_list, 0);
913 // now compare on CN label
914 if (a.call_number.label < b.call_number.label) return -1;
915 if (a.call_number.label > b.call_number.label) return 1;
918 if (a.copy_number < b.copy_number) return -1;
919 if (a.copy_number > b.copy_number) return 1;
922 if (a.barcode < b.barcode) return -1;
923 if (a.barcode > b.barcode) return 1;
929 // create a label using just the unique part of the owner list
932 angular.forEach(service.copies, function (cp) {
933 if (!prev_owner_list) {
934 cp.owner_label = cp.owner_list.join(' ... ');
936 var current_owner_list = cp.owner_list.slice();
937 while (current_owner_list[1] && prev_owner_list[1] && current_owner_list[0] == prev_owner_list[0]) {
938 current_owner_list.shift();
939 prev_owner_list.shift();
941 cp.owner_label = current_owner_list.join(' ... ');
945 prev_owner_list = cp.owner_list.slice();
948 var new_list = service.copies;
949 if (!copy || !vol) { // collapse copy rows, supply a count instead
954 var current_blob = {};
955 angular.forEach(new_list, function (cp) {
957 prev_key = cp.owner_list.join('') + cp.call_number.label;
958 if (cp.barcode) current_blob.copy_count = 1;
959 current_blob.index = index++;
960 current_blob.id_list = cp.id_list;
961 current_blob.raw = cp.raw;
962 current_blob.call_number = cp.call_number;
963 current_blob.owner_list = cp.owner_list;
964 current_blob.owner_label = cp.owner_label;
965 current_blob.owner_id = cp.owner_id;
967 var current_key = cp.owner_list.join('') + cp.call_number.label;
968 if (prev_key == current_key) { // collapse into current_blob
969 current_blob.copy_count++;
970 current_blob.id_list = current_blob.id_list.concat(cp.id_list);
971 current_blob.raw = current_blob.raw.concat(cp.raw);
973 current_blob.barcode = current_blob.copy_count;
974 cp_list.push(current_blob);
975 prev_key = current_key;
977 if (cp.barcode) current_blob.copy_count = 1;
978 current_blob.index = index++;
979 current_blob.id_list = cp.id_list;
980 current_blob.raw = cp.raw;
981 current_blob.owner_label = cp.owner_label;
982 current_blob.owner_id = cp.owner_id;
983 current_blob.call_number = cp.call_number;
984 current_blob.owner_list = cp.owner_list;
989 current_blob.barcode = current_blob.copy_count;
990 cp_list.push(current_blob);
993 if (!vol) { // do the same for vol rows
998 var current_blob = {};
999 angular.forEach(cp_list, function (cp) {
1001 prev_key = cp.owner_list.join('');
1002 current_blob.index = index++;
1003 current_blob.id_list = cp.id_list;
1004 current_blob.raw = cp.raw;
1005 current_blob.cn_count = 1;
1006 current_blob.copy_count = cp.copy_count;
1007 current_blob.owner_list = cp.owner_list;
1008 current_blob.owner_label = cp.owner_label;
1009 current_blob.owner_id = cp.owner_id;
1011 var current_key = cp.owner_list.join('');
1012 if (prev_key == current_key) { // collapse into current_blob
1013 current_blob.cn_count++;
1014 current_blob.copy_count += cp.copy_count;
1015 current_blob.id_list = current_blob.id_list.concat(cp.id_list);
1016 current_blob.raw = current_blob.raw.concat(cp.raw);
1018 current_blob.barcode = current_blob.copy_count;
1019 current_blob.call_number = { label : current_blob.cn_count };
1020 cn_list.push(current_blob);
1021 prev_key = current_key;
1023 current_blob.index = index++;
1024 current_blob.id_list = cp.id_list;
1025 current_blob.raw = cp.raw;
1026 current_blob.owner_label = cp.owner_label;
1027 current_blob.owner_id = cp.owner_id;
1028 current_blob.cn_count = 1;
1029 current_blob.copy_count = cp.copy_count;
1030 current_blob.owner_list = cp.owner_list;
1035 current_blob.barcode = current_blob.copy_count;
1036 current_blob.call_number = { label : current_blob.cn_count };
1037 cn_list.push(current_blob);
1043 service.copies = new_list;
1044 service.ongoing = false;
1049 // notify reads the stream of copies, one at a time.
1052 var copies = cn.copies();
1055 angular.forEach(copies, function (cp) {
1059 var owner_id = cn.owning_lib();
1060 var owner = egCore.org.get(owner_id);
1062 var owner_name_list = [];
1063 while (owner.parent_ou()) { // we're going to skip the top of the tree...
1064 owner_name_list.unshift(owner.name());
1065 owner = egCore.org.get(owner.parent_ou());
1070 angular.forEach(copies, function (cp) {
1071 var flat_cp = egCore.idl.toHash(cp);
1072 flat_cp.owner_id = owner_id;
1073 flat_cp.owner_list = owner_name_list;
1074 flat_cp.id_list = [flat_cp.id];
1079 service.copies = service.copies.concat(flat);
1081 service.copies.push({
1082 owner_id : owner_id,
1083 owner_list : owner_name_list,
1084 call_number: egCore.idl.toHash(cn)