]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/cat/catalog/app.js
webstaff: Use function calls instead of watches; Collapse columns
[working/Evergreen.git] / Open-ILS / web / js / ui / default / staff / cat / catalog / app.js
1 /**
2  * TPAC Frame App
3  *
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.
7  *
8  */
9
10 angular.module('egCatalogApp', ['ui.bootstrap','ngRoute','egCoreMod','egGridMod', 'egMarcMod'])
11
12 .config(function($routeProvider, $locationProvider, $compileProvider) {
13     $locationProvider.html5Mode(true);
14     $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
15
16     var resolver = {delay : 
17         ['egStartup', function(egStartup) {return egStartup.go()}]}
18
19     $routeProvider.when('/cat/catalog/index', {
20         templateUrl: './cat/catalog/t_catalog',
21         controller: 'CatalogCtrl',
22         resolve : resolver
23     });
24
25     $routeProvider.when('/cat/catalog/retrieve_by_id', {
26         templateUrl: './cat/catalog/t_retrieve_by_id',
27         controller: 'CatalogRecordRetrieve',
28         resolve : resolver
29     });
30
31     $routeProvider.when('/cat/catalog/retrieve_by_tcn', {
32         templateUrl: './cat/catalog/t_retrieve_by_tcn',
33         controller: 'CatalogRecordRetrieve',
34         resolve : resolver
35     });
36
37     // create some catalog page-specific mappings
38     $routeProvider.when('/cat/catalog/record/:record_id', {
39         templateUrl: './cat/catalog/t_catalog',
40         controller: 'CatalogCtrl',
41         resolve : resolver
42     });
43
44     // create some catalog page-specific mappings
45     $routeProvider.when('/cat/catalog/record/:record_id/:record_tab', {
46         templateUrl: './cat/catalog/t_catalog',
47         controller: 'CatalogCtrl',
48         resolve : resolver
49     });
50
51     $routeProvider.when('/cat/catalog/batchEdit', {
52         templateUrl: './cat/catalog/t_batchedit',
53         controller: 'BatchEditCtrl',
54         resolve : resolver
55     });
56
57     $routeProvider.when('/cat/catalog/batchEdit/:container_type/:container_id', {
58         templateUrl: './cat/catalog/t_batchedit',
59         controller: 'BatchEditCtrl',
60         resolve : resolver
61     });
62
63     $routeProvider.when('/cat/catalog/vandelay', {
64         templateUrl: './cat/catalog/t_vandelay',
65         controller: 'VandelayCtrl',
66         resolve : resolver
67     });
68
69     $routeProvider.when('/cat/catalog/verifyURLs', {
70         templateUrl: './cat/catalog/t_verifyurls',
71         controller: 'URLVerifyCtrl',
72         resolve : resolver
73     });
74
75     $routeProvider.when('/cat/catalog/manageAuthorities', {
76         templateUrl: './cat/catalog/t_manageauthorities',
77         controller: 'ManageAuthoritiesCtrl',
78         resolve : resolver
79     });
80
81     $routeProvider.otherwise({redirectTo : '/cat/catalog/index'});
82 })
83
84
85 /**
86  * */
87 .controller('CatalogRecordRetrieve',
88        ['$scope','$routeParams','$location','$q','egCore',
89 function($scope , $routeParams , $location , $q , egCore ) {
90
91     $scope.focusMe = true;
92
93     // jump to the patron checkout UI
94     function loadRecord(record_id) {
95         $location
96         .path('/cat/catalog/record/' + record_id);
97     }
98
99     $scope.submitId = function(args) {
100         $scope.recordNotFound = null;
101         if (!args.record_id) return;
102
103         // blur so next time it's set to true it will re-apply select()
104         $scope.selectMe = false;
105
106         return loadRecord(args.record_id);
107     }
108
109     $scope.submitTCN = function(args) {
110         $scope.recordNotFound = null;
111         $scope.moreRecordsFound = null;
112         if (!args.record_tcn) return;
113
114         // blur so next time it's set to true it will re-apply select()
115         $scope.selectMe = false;
116
117         // lookup TCN
118         egCore.net.request(
119             'open-ils.search',
120             'open-ils.search.biblio.tcn',
121             args.record_tcn)
122
123         .then(function(resp) { // get_barcodes
124
125             if (evt = egCore.evt.parse(resp)) {
126                 alert(evt); // FIXME
127                 return;
128             }
129
130             if (!resp.count) {
131                 $scope.recordNotFound = args.record_tcn;
132                 $scope.selectMe = true;
133                 return;
134             }
135
136             if (resp.count > 1) {
137                 $scope.moreRecordsFound = args.record_tcn;
138                 $scope.selectMe = true;
139                 return;
140             }
141
142             var record_id = resp.ids[0];
143             return loadRecord(record_id);
144         });
145     }
146
147 }])
148
149 .controller('CatalogCtrl',
150        ['$scope','$routeParams','$location','$q','egCore','egHolds',
151         'egGridDataProvider','egHoldGridActions','$timeout','holdingsSvc',
152 function($scope , $routeParams , $location , $q , egCore , egHolds, 
153          egGridDataProvider , egHoldGridActions , $timeout , holdingsSvc) {
154
155     // set record ID on page load if available...
156     $scope.record_id = $routeParams.record_id;
157
158     if ($routeParams.record_id) $scope.from_route = true;
159     else $scope.from_route = false;
160
161     // will hold a ref to the opac iframe
162     $scope.opac_iframe = null;
163     $scope.parts_iframe = null;
164
165     $scope.in_opac_call = false;
166     $scope.opac_call = function (opac_frame_function, force_opac_tab) {
167         if ($scope.opac_iframe) {
168             if (force_opac_tab) $scope.record_tab = 'catalog';
169             $scope.in_opac_call = true;
170             $scope.opac_iframe.dom.contentWindow[opac_frame_function]();
171         }
172     }
173
174     $scope.stop_unload = false;
175     $scope.$watch('stop_unload',
176         function(newVal, oldVal) {
177             if (newVal && newVal != oldVal && $scope.opac_iframe) {
178                 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
179                     return 'There is unsaved data in this record.'
180                 });
181             } else {
182                 if ($scope.opac_iframe)
183                     $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
184             }
185         }
186     );
187
188     // Set the "last bib" cookie, if we have that
189     if ($scope.record_id)
190         egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
191
192     // also set it when the iframe changes to a new record
193     $scope.handle_page = function(url) {
194
195         if (!url || url == 'about:blank') {
196             // nothing loaded.  If we already have a record ID, leave it.
197             return;
198         }
199
200         var match = url.match(/\/+opac\/+record\/+(\d+)/);
201         if (match) {
202             $scope.record_id = match[1];
203             egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
204             init_parts_url();
205         } else {
206             delete $scope.record_id;
207             $scope.from_route = false;
208         }
209
210         // child scope is executing this function, so our digest doesn't fire ... thus,
211         $scope.$apply();
212
213         if (!$scope.in_opac_call) {
214             if ($scope.record_id) {
215                 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
216                 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
217             } else {
218                 tab = $routeParams.record_tab || 'catalog';
219             }
220             $scope.set_record_tab(tab);
221         } else {
222             $scope.in_opac_call = false;
223         }
224     }
225
226     // xulG catalog handlers
227     $scope.handlers = { }
228
229     // ------------------------------------------------------------------
230     // Holdings
231
232     $scope.holdingsGridControls = {};
233     $scope.holdingsGridDataProvider = egGridDataProvider.instance({
234         get : function(offset, count) {
235             return this.arrayNotifier(holdingsSvc.copies, offset, count);
236         }
237     });
238
239     // refresh the list of holdings when the filter lib is changed.
240     $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
241     $scope.holdings_ou_changed = function(org) {
242         $scope.holdings_ou = org;
243         holdingsSvc.fetch({
244             rid : $scope.record_id,
245             org : $scope.holdings_ou,
246             copy: $scope.holdings_show_copies,
247             vol : $scope.holdings_show_vols,
248             empty: $scope.holdings_show_empty
249         }).then(function() {
250             $scope.holdingsGridDataProvider.refresh();
251         });
252     }
253
254     $scope.holdings_show_copies_changed = function(newVal) {
255         $scope.holdings_show_copies = newVal;
256         egCore.hatch.setItem('cat.holdings.show_copies', newVal);
257         holdingsSvc.fetch({
258             rid : $scope.record_id,
259             org : $scope.holdings_ou,
260             copy: $scope.holdings_show_copies,
261             vol : $scope.holdings_show_vols,
262             empty: $scope.holdings_show_empty
263         }).then(function() {
264             $scope.holdingsGridDataProvider.refresh();
265         });
266     }
267
268     $scope.holdings_show_vols_changed = function(newVal) {
269         $scope.holdings_show_vols = newVal;
270         egCore.hatch.setItem('cat.holdings.show_vols', newVal);
271         holdingsSvc.fetch({
272             rid : $scope.record_id,
273             org : $scope.holdings_ou,
274             copy: $scope.holdings_show_copies,
275             vol : $scope.holdings_show_vols,
276             empty: $scope.holdings_show_empty
277         }).then(function() {
278             $scope.holdingsGridDataProvider.refresh();
279         });
280     }
281
282     $scope.holdings_show_empty_changed = function(newVal) {
283         $scope.holdings_show_empty = newVal;
284         egCore.hatch.setItem('cat.holdings.show_empty', newVal);
285         holdingsSvc.fetch({
286             rid : $scope.record_id,
287             org : $scope.holdings_ou,
288             copy: $scope.holdings_show_copies,
289             vol : $scope.holdings_show_vols,
290             empty: $scope.holdings_show_empty
291         }).then(function() {
292             $scope.holdingsGridDataProvider.refresh();
293         });
294     }
295
296     egCore.hatch.getItem('cat.holdings.show_copies').then(function(x){
297         if (typeof x ==  'undefined') x = true;
298         $scope.holdings_show_copies = x;
299     });
300
301     egCore.hatch.getItem('cat.holdings.show_vols').then(function(x){
302         if (typeof x ==  'undefined') x = true;
303         $scope.holdings_show_vols = x;
304     });
305
306     egCore.hatch.getItem('cat.holdings.show_emtpy').then(function(x){
307         if (typeof x ==  'undefined') x = false;
308         $scope.holdings_show_empty = x;
309     });
310
311     $scope.holdings_checkbox_handler = function (item) {
312         $scope[item.checkbox] = item.checked;
313         $scope[item.checkbox + '_changed'](item.checked);
314     }
315
316
317     // ------------------------------------------------------------------
318     // Holds 
319     var provider = egGridDataProvider.instance({});
320     $scope.hold_grid_data_provider = provider;
321     $scope.grid_actions = egHoldGridActions;
322     $scope.grid_actions.refresh = function () { provider.refresh() };
323     $scope.hold_grid_controls = {};
324
325     var hold_ids = []; // current list of holds
326     function fetchHolds(offset, count) {
327         var ids = hold_ids.slice(offset, offset + count);
328         return egHolds.fetch_holds(ids).then(null, null,
329             function(hold_data) { 
330                 return hold_data;
331             }
332         );
333     }
334
335     provider.get = function(offset, count) {
336         if ($scope.record_tab != 'holds') return $q.when();
337         var deferred = $q.defer();
338         hold_ids = []; // no caching ATM
339
340         // fetch the IDs
341         egCore.net.request(
342             'open-ils.circ',
343             'open-ils.circ.holds.retrieve_all_from_title',
344             egCore.auth.token(), $scope.record_id, 
345             {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
346         ).then(
347             function(hold_data) {
348                 angular.forEach(hold_data, function(list, type) {
349                     hold_ids = hold_ids.concat(list);
350                 });
351                 fetchHolds(offset, count).then(
352                     deferred.resolve, null, deferred.notify);
353             }
354         );
355
356         return deferred.promise;
357     }
358
359     $scope.detail_view = function(action, user_data, items) {
360         if (h = items[0]) {
361             $scope.detail_hold_id = h.hold.id();
362         }
363     }
364
365     $scope.list_view = function(items) {
366          $scope.detail_hold_id = null;
367     }
368
369     // refresh the list of record holds when the pickup lib is changed.
370     $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
371     $scope.pickup_ou_changed = function(org) {
372         $scope.pickup_ou = org;
373         provider.refresh();
374     }
375
376     $scope.print_holds = function() {
377         var holds = [];
378         angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
379             holds.push({
380                 hold : egCore.idl.toHash(item.hold),
381                 patron_last : item.patron_last,
382                 patron_alias : item.patron_alias,
383                 patron_barcode : item.patron_barcode,
384                 copy : egCore.idl.toHash(item.copy),
385                 volume : egCore.idl.toHash(item.volume),
386                 title : item.mvr.title(),
387                 author : item.mvr.author()
388             });
389         });
390
391         egCore.print.print({
392             context : 'receipt', 
393             template : 'holds_for_bib', 
394             scope : {holds : holds}
395         });
396     }
397
398     $scope.mark_hold_transfer_dest = function() {
399         egCore.hatch.setLocalItem(
400             'eg.circ.hold.title_transfer_target', $scope.record_id);
401     }
402
403     // UI presents this option as "all holds"
404     $scope.transfer_holds_to_marked = function() {
405         var hold_ids = $scope.hold_grid_controls.allItems().map(
406             function(hold_data) {return hold_data.hold.id()});
407         egHolds.transfer_to_marked_title(hold_ids);
408     }
409
410     // ------------------------------------------------------------------
411     // Initialize the selected tab
412
413     function init_cat_url() {
414         // Set the initial catalog URL.  This only happens once.
415         // The URL is otherwise generated through user navigation.
416         if ($scope.catalog_url) return; 
417
418         var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
419
420         // A record ID in the path indicates a request for the record-
421         // specific page.
422         if ($routeParams.record_id) {
423             url = url.replace(/advanced/, '/record/' + $scope.record_id);
424         }
425
426         $scope.catalog_url = url;
427     }
428
429     function init_parts_url() {
430         $scope.parts_url = $location
431             .absUrl()
432             .replace(
433                 /\/staff.*/,
434                 '/conify/global/biblio/monograph_part?r='+$scope.record_id
435             );
436     }
437
438     $scope.set_record_tab = function(tab) {
439         $scope.record_tab = tab;
440
441         switch(tab) {
442
443             case 'monoparts':
444                 init_parts_url();
445                 break;
446
447             case 'catalog':
448                 init_cat_url();
449                 break;
450
451             case 'holds':
452                 $scope.detail_hold_record_id = $scope.record_id; 
453                 // refresh the holds grid
454                 provider.refresh();
455                 break;
456         }
457     }
458
459     $scope.set_default_record_tab = function() {
460         egCore.hatch.setLocalItem(
461             'eg.cat.default_record_tab', $scope.record_tab);
462         $timeout(function(){$scope.default_tab = $scope.record_tab});
463     }
464
465     var tab;
466     if ($scope.record_id) {
467         $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
468         tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
469
470
471         $timeout(function(){
472             holdingsSvc.fetch({
473                 rid : $scope.record_id,
474                 org : $scope.holdings_ou,
475                 copy: $scope.holdings_show_copies,
476                 vol : $scope.holdings_show_vols,
477                 empty: $scope.holdings_show_empty
478             }).then(function() {
479                 $scope.holdingsGridDataProvider.refresh();
480             });
481         });
482
483     } else {
484         tab = $routeParams.record_tab || 'catalog';
485     }
486     $scope.set_record_tab(tab);
487
488 }])
489
490 .controller('URLVerifyCtrl',
491        ['$scope','$location',
492 function($scope , $location) {
493     $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
494 }])
495
496 .controller('VandelayCtrl',
497        ['$scope','$location',
498 function($scope , $location) {
499     $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
500 }])
501
502 .controller('ManageAuthoritiesCtrl',
503        ['$scope','$location',
504 function($scope , $location) {
505     $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
506 }])
507
508 .controller('BatchEditCtrl',
509        ['$scope','$location','$routeParams',
510 function($scope , $location , $routeParams) {
511     $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
512     if ($routeParams.container_type) {
513         switch ($routeParams.container_type) {
514             case 'bucket':
515                 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
516                 break;
517             case 'record':
518                 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
519                 break;
520         };
521     }
522 }])
523
524  
525 .filter('boolText', function(){
526     return function (v) {
527         return v == 't';
528     }
529 })
530
531 .factory('holdingsSvc', 
532        ['egCore','$q',
533 function(egCore , $q) {
534
535     var service = {
536         ongoing : false,
537         copies : [], // record search results
538         index : 0, // search grid index
539         org : null,
540         rid : null
541     };
542
543     service.flesh = {   
544         flesh : 2, 
545         flesh_fields : {
546             acp : ['status','location'],
547             acn : ['prefix','suffix','copies']
548         }
549     }
550
551     // resolved with the last received copy
552     service.fetch = function(opts) {
553         if (service.ongoing) return $q.when();
554
555         var rid = opts.rid;
556         var org = opts.org;
557         var copy = opts.copy;
558         var vol = opts.vol;
559         var empty = opts.empty;
560
561         if (!rid) return $q.when();
562         if (!org) return $q.when();
563
564         service.ongoing = true;
565
566         service.rid = rid;
567         service.org = org;
568         service.copies = [];
569         service.index = 0;
570
571         var org_list = egCore.org.descendants(org.id(), true);
572
573         return egCore.pcrud.search(
574             'acn',
575             {record : rid, owning_lib : org_list, deleted : 'f'},
576             service.flesh
577         ).then(
578             function() { // finished
579                 service.copies = service.copies.sort(
580                     function (a, b) {
581                         function compare_array (x, y, i) {
582                             if (x[i] && y[i]) { // both have values
583                                 if (x[i] == y[i]) { // need to look deeper
584                                     return compare_array(x, y, ++i);
585                                 }
586
587                                 if (x[i] < y[i]) { // x is first
588                                     return -1;
589                                 } else if (x[i] > y[i]) { // y is first
590                                     return 1;
591                                 }
592
593                             } else { // no orgs to compare ...
594                                 if (x[i]) return -1;
595                                 if (y[i]) return 1;
596                             }
597                             return 0;
598                         }
599
600                         var owner_order = compare_array(a.owner_list, b.owner_list, 0);
601                         if (!owner_order) {
602                             // now compare on CN label
603                             if (a.call_number.label < b.call_number.label) return -1;
604                             if (a.call_number.label > b.call_number.label) return 1;
605
606                             // try copy number
607                             if (a.copy_number < b.copy_number) return -1;
608                             if (a.copy_number > b.copy_number) return 1;
609
610                             // finally, barcode
611                             if (a.barcode < b.barcode) return -1;
612                             if (a.barcode > b.barcode) return 1;
613                         }
614                         return owner_order;
615                     }
616                 );
617
618                 // create a label using just the unique part of the owner list
619                 var index = 0;
620                 var prev_owner_list;
621                 angular.forEach(service.copies, function (cp) {
622                     if (!prev_owner_list) {
623                         cp.owner_label = cp.owner_list.join(' ... ');
624                     } else {
625                         var current_owner_list = cp.owner_list.slice();
626                         while (current_owner_list[1] && prev_owner_list[1] && current_owner_list[0] == prev_owner_list[0]) {
627                             current_owner_list.shift();
628                             prev_owner_list.shift();
629                         }
630                         cp.owner_label = current_owner_list.join(' ... ');
631                     }
632
633                     cp.index = index++;
634                     prev_owner_list = cp.owner_list.slice();
635                 });
636
637                 var new_list = service.copies;
638                 if (!copy || !vol) { // collapse copy rows, supply a count instead
639
640                     index = 0;
641                     var cp_list = [];
642                     var prev_key;
643                     var current_blob = {};
644                     angular.forEach(new_list, function (cp) {
645                         if (!prev_key) {
646                             prev_key = cp.owner_list.join('') + cp.call_number.label;
647                             if (cp.barcode) current_blob.copy_count = 1;
648                             current_blob.index = ++index;
649                             current_blob.call_number = cp.call_number;
650                             current_blob.owner_list = cp.owner_list;
651                             current_blob.owner_label = cp.owner_label;
652                         } else {
653                             var current_key = cp.owner_list.join('') + cp.call_number.label;
654                             if (prev_key == current_key) { // collapse into current_blob
655                                 current_blob.copy_count++;
656                             } else {
657                                 current_blob.barcode = current_blob.copy_count;
658                                 cp_list.push(current_blob);
659                                 prev_key = current_key;
660                                 current_blob = {};
661                                 if (cp.barcode) current_blob.copy_count = 1;
662                                 current_blob.index = ++index;
663                                 current_blob.owner_label = cp.owner_label;
664                                 current_blob.call_number = cp.call_number;
665                                 current_blob.owner_list = cp.owner_list;
666                             }
667                         }
668                     });
669
670                     current_blob.barcode = current_blob.copy_count;
671                     cp_list.push(current_blob);
672                     new_list = cp_list;
673
674                     if (!vol) { // do the same for vol rows
675
676                         index = 0;
677                         var cn_list = [];
678                         prev_key = '';
679                         var current_blob = {};
680                         angular.forEach(cp_list, function (cp) {
681                             if (!prev_key) {
682                                 prev_key = cp.owner_list.join('');
683                                 current_blob.index = ++index;
684                                 current_blob.cn_count = 1;
685                                 current_blob.copy_count = cp.copy_count;
686                                 current_blob.owner_list = cp.owner_list;
687                                 current_blob.owner_label = cp.owner_label;
688                             } else {
689                                 var current_key = cp.owner_list.join('');
690                                 if (prev_key == current_key) { // collapse into current_blob
691                                     current_blob.cn_count++;
692                                     current_blob.copy_count += cp.copy_count;
693                                 } else {
694                                     current_blob.barcode = current_blob.copy_count;
695                                     current_blob.call_number = { label : current_blob.cn_count };
696                                     cn_list.push(current_blob);
697                                     prev_key = current_key;
698                                     current_blob = {};
699                                     current_blob.index = ++index;
700                                     current_blob.owner_label = cp.owner_label;
701                                     current_blob.cn_count = 1;
702                                     current_blob.copy_count = cp.copy_count;
703                                     current_blob.owner_list = cp.owner_list;
704                                 }
705                             }
706                         });
707     
708                         current_blob.barcode = current_blob.copy_count;
709                         current_blob.call_number = { label : current_blob.cn_count };
710                         cn_list.push(current_blob);
711                         new_list = cn_list;
712     
713                     }
714                 }
715
716                 service.copies = new_list;
717                 service.ongoing = false;
718             },
719
720             null, // error
721
722             // notify reads the stream of copies, one at a time.
723             function(cn) {
724
725                 var copies = cn.copies();
726                 cn.copies([]);
727
728                 angular.forEach(copies, function (cp) {
729                     cp.call_number(cn);
730                 });
731
732                 var flat = egCore.idl.toHash(copies);
733                 var owner = egCore.org.get(flat[0].call_number.owning_lib);
734
735                 var owner_name_list = [];
736                 while (owner.parent_ou()) { // we're going to skip the top of the tree...
737                     owner_name_list.unshift(owner.name());
738                     owner = egCore.org.get(owner.parent_ou());
739                 }
740
741                 angular.forEach(flat, function (cp) {
742                     cp.owner_list = owner_name_list;
743                 });
744
745                 service.copies = service.copies.concat(flat);
746
747                 if (empty && flat.length == 0) {
748                     service.copies.push({
749                         owner_list : owner_name_list,
750                         call_number: egCore.idl.toHash(cn)
751                     });
752                 }
753
754                 return cn;
755             }
756         );
757     }
758
759     return service;
760 }])
761
762