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.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.copies_not_shown = function () {
455 return !$scope.holdings_show_copies;
458 $scope.holdings_checkbox_handler = function (item) {
459 $scope.holdings_cb_changed(item.checkbox,item.checked);
462 function gatherSelectedHoldingsIds () {
465 $scope.holdingsGridControls.selectedItems(),
466 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
471 function gatherSelectedRawCopies () {
474 $scope.holdingsGridControls.selectedItems(),
475 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
480 function gatherSelectedVolumeIds () {
483 $scope.holdingsGridControls.selectedItems(),
485 if (cn_id_list.indexOf(item.call_number.id) == -1)
486 cn_id_list.push(item.call_number.id)
492 $scope.selectedHoldingsDelete = function (vols, copies) {
495 var perCnCopies = {};
501 $scope.holdingsGridControls.selectedItems(),
503 if (vols && item.raw_call_number) {
504 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
505 cnHash[item.call_number.id].isdeleted(1);
508 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
511 var cn_id = cp.call_number().id();
512 if (!cnHash[cn_id]) {
513 cnHash[cn_id] = cp.call_number();
514 perCnCopies[cn_id] = [cp];
516 perCnCopies[cn_id].push(cp);
518 cp.call_number(cn_id); // prevent loops in JSON-ification
525 angular.forEach(perCnCopies, function (v, k) {
527 cnHash[k].isdeleted(1);
534 angular.forEach(cnHash, function (v, k) {
538 if (cnList.length == 0) return;
540 egConfirmDialog.open(
541 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
542 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
543 {copies : cp_count, volumes : cn_count}
544 ).result.then(function() {
547 'open-ils.cat.asset.volume.fleshed.batch.update.override',
548 egCore.auth.token(), cnList, 1, {}
549 ).then(function(update_count) {
550 $scope.holdingsGridDataProvider.refresh();
554 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
555 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
556 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
558 spawnHoldingsAdd = function (vols,copies){
560 if (copies) { // just a copy on existing volumes
561 angular.forEach(gatherSelectedVolumeIds(), function (v) {
562 raw.push( {callnumber : v} );
566 $scope.holdingsGridControls.selectedItems(),
568 raw.push({owner : item.owner_id});
575 'open-ils.actor.anon_cache.set_value',
576 null, 'edit-these-copies', {
577 record_id: $scope.record_id,
582 ).then(function(key) {
584 var url = egCore.env.basePath + 'cat/volcopy/' + key;
585 $timeout(function() { $window.open(url, '_blank') });
587 alert('Could not create anonymous cache key!');
591 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
592 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
594 spawnHoldingsEdit = function (hide_vols,hide_copies){
597 'open-ils.actor.anon_cache.set_value',
598 null, 'edit-these-copies', {
599 record_id: $scope.record_id,
600 copies: gatherSelectedHoldingsIds(),
601 hide_vols : hide_vols,
602 hide_copies : hide_copies
604 ).then(function(key) {
606 var url = egCore.env.basePath + 'cat/volcopy/' + key;
607 $timeout(function() { $window.open(url, '_blank') });
609 alert('Could not create anonymous cache key!');
613 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
614 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
615 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
617 $scope.selectedHoldingsItemStatus = function (){
618 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
619 $timeout(function() { $window.open(url, '_blank') });
622 $scope.markVolAsItemTarget = function() {
623 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
624 egCore.hatch.setLocalItem(
625 'eg.cat.item_transfer_target',
626 $scope.holdingsGridControls.selectedItems()[0].call_number.id
631 $scope.markLibAsVolTarget = function() {
632 egCore.hatch.setLocalItem(
633 'eg.cat.volume_transfer_target',
634 $scope.holdingsGridControls.selectedItems()[0].owner_id
638 $scope.selectedHoldingsItemStatusDetail = function (){
640 gatherSelectedHoldingsIds(),
642 var url = egCore.env.basePath +
644 $timeout(function() { $window.open(url, '_blank') });
649 $scope.transferVolumes = function (){
650 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
655 'open-ils.open-ils.cat.asset.volume.batch.transfer.override',
656 egCore.auth.token(), {
657 docid : $scope.record_id,
659 volumes : gatherSelectedVolumeIds()
661 ).then(function(success) {
664 rid : $scope.record_id,
665 org : $scope.holdings_ou,
666 copy: $scope.holdings_show_copies,
667 vol : $scope.holdings_show_vols,
668 empty: $scope.holdings_show_empty
670 $scope.holdingsGridDataProvider.refresh();
673 alert('Could not transfer volumes!');
680 $scope.transferItems = function (){
681 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
683 var copy_list = gatherSelectedRawCopies();
685 angular.forEach(copy_list, function (cp) {
686 cp.call_number(xfer_target);
691 ).then(function(success) {
694 rid : $scope.record_id,
695 org : $scope.holdings_ou,
696 copy: $scope.holdings_show_copies,
697 vol : $scope.holdings_show_vols,
698 empty: $scope.holdings_show_empty
700 $scope.holdingsGridDataProvider.refresh();
703 alert('Could not transfer items!');
710 $scope.selectedHoldingsItemStatusTgrEvt = function (){
712 gatherSelectedHoldingsIds(),
714 var url = egCore.env.basePath +
715 'cat/item/' + cid + '/triggered_events';
716 $timeout(function() { $window.open(url, '_blank') });
721 $scope.selectedHoldingsItemStatusHolds = function (){
723 gatherSelectedHoldingsIds(),
725 var url = egCore.env.basePath +
726 'cat/item/' + cid + '/holds';
727 $timeout(function() { $window.open(url, '_blank') });
732 $scope.selectedHoldingsDamaged = function () {
733 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
735 rid : $scope.record_id,
736 org : $scope.holdings_ou,
737 copy: $scope.holdings_show_copies,
738 vol : $scope.holdings_show_vols,
739 empty: $scope.holdings_show_empty
741 $scope.holdingsGridDataProvider.refresh();
746 $scope.selectedHoldingsMissing = function () {
747 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
749 rid : $scope.record_id,
750 org : $scope.holdings_ou,
751 copy: $scope.holdings_show_copies,
752 vol : $scope.holdings_show_vols,
753 empty: $scope.holdings_show_empty
755 $scope.holdingsGridDataProvider.refresh();
761 // ------------------------------------------------------------------
763 var provider = egGridDataProvider.instance({});
764 $scope.hold_grid_data_provider = provider;
765 $scope.grid_actions = egHoldGridActions;
766 $scope.grid_actions.refresh = function () { provider.refresh() };
767 $scope.hold_grid_controls = {};
769 var hold_ids = []; // current list of holds
770 function fetchHolds(offset, count) {
771 var ids = hold_ids.slice(offset, offset + count);
772 return egHolds.fetch_holds(ids).then(null, null,
773 function(hold_data) {
779 provider.get = function(offset, count) {
780 if ($scope.record_tab != 'holds') return $q.when();
781 var deferred = $q.defer();
782 hold_ids = []; // no caching ATM
787 'open-ils.circ.holds.retrieve_all_from_title',
788 egCore.auth.token(), $scope.record_id,
789 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
791 function(hold_data) {
792 angular.forEach(hold_data, function(list, type) {
793 hold_ids = hold_ids.concat(list);
795 fetchHolds(offset, count).then(
796 deferred.resolve, null, deferred.notify);
800 return deferred.promise;
803 $scope.detail_view = function(action, user_data, items) {
805 $scope.detail_hold_id = h.hold.id();
809 $scope.list_view = function(items) {
810 $scope.detail_hold_id = null;
813 // refresh the list of record holds when the pickup lib is changed.
814 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
815 $scope.pickup_ou_changed = function(org) {
816 $scope.pickup_ou = org;
820 $scope.print_holds = function() {
822 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
824 hold : egCore.idl.toHash(item.hold),
825 patron_last : item.patron_last,
826 patron_alias : item.patron_alias,
827 patron_barcode : item.patron_barcode,
828 copy : egCore.idl.toHash(item.copy),
829 volume : egCore.idl.toHash(item.volume),
830 title : item.mvr.title(),
831 author : item.mvr.author()
837 template : 'holds_for_bib',
838 scope : {holds : holds}
842 $scope.mark_hold_transfer_dest = function() {
843 egCore.hatch.setLocalItem(
844 'eg.circ.hold.title_transfer_target', $scope.record_id);
847 // UI presents this option as "all holds"
848 $scope.transfer_holds_to_marked = function() {
849 var hold_ids = $scope.hold_grid_controls.allItems().map(
850 function(hold_data) {return hold_data.hold.id()});
851 egHolds.transfer_to_marked_title(hold_ids);
854 // ------------------------------------------------------------------
855 // Initialize the selected tab
857 function init_cat_url() {
858 // Set the initial catalog URL. This only happens once.
859 // The URL is otherwise generated through user navigation.
860 if ($scope.catalog_url) return;
862 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
864 // A record ID in the path indicates a request for the record-
866 if ($routeParams.record_id) {
867 url = url.replace(/advanced/, '/record/' + $scope.record_id);
870 $scope.catalog_url = url;
873 function init_parts_url() {
874 $scope.parts_url = $location
878 '/conify/global/biblio/monograph_part?r='+$scope.record_id
882 $scope.set_record_tab = function(tab) {
883 $scope.record_tab = tab;
896 $scope.detail_hold_record_id = $scope.record_id;
897 // refresh the holds grid
903 $scope.set_default_record_tab = function() {
904 egCore.hatch.setLocalItem(
905 'eg.cat.default_record_tab', $scope.record_tab);
906 $timeout(function(){$scope.default_tab = $scope.record_tab});
910 if ($scope.record_id) {
911 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
912 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
915 tab = $routeParams.record_tab || 'catalog';
917 $scope.set_record_tab(tab);
921 .controller('AuthorityCtrl',
922 ['$scope','$routeParams','$location','$window','$q','egCore',
923 function($scope , $routeParams , $location , $window , $q , egCore) {
925 // set record ID on page load if available...
926 $scope.authority_id = $routeParams.authority_id;
928 if ($routeParams.authority_id) $scope.from_route = true;
929 else $scope.from_route = false;
931 $scope.stop_unload = false;
934 .controller('URLVerifyCtrl',
935 ['$scope','$location',
936 function($scope , $location) {
937 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
940 .controller('VandelayCtrl',
941 ['$scope','$location',
942 function($scope , $location) {
943 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
946 .controller('ManageAuthoritiesCtrl',
947 ['$scope','$location',
948 function($scope , $location) {
949 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
952 .controller('BatchEditCtrl',
953 ['$scope','$location','$routeParams',
954 function($scope , $location , $routeParams) {
955 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
956 if ($routeParams.container_type) {
957 switch ($routeParams.container_type) {
959 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
962 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
969 .filter('boolText', function(){
970 return function (v) {
975 .factory('holdingsSvc',
977 function(egCore , $q) {
981 copies : [], // record search results
982 index : 0, // search grid index
990 acp : ['status','location'],
991 acn : ['prefix','suffix','copies']
995 // resolved with the last received copy
996 service.fetch = function(opts) {
997 if (service.ongoing) {
998 console.log('Skipping fetch, ongoing = true');
1004 var copy = opts.copy;
1006 var empty = opts.empty;
1008 if (!rid) return $q.when();
1009 if (!org) return $q.when();
1011 service.ongoing = true;
1015 service.copies = [];
1018 var org_list = egCore.org.descendants(org.id(), true);
1019 console.log('Holdings fetch with: rid='+rid+' org='+org_list+' copy='+copy+' vol='+vol+' empty='+empty);
1021 return egCore.pcrud.search(
1023 {record : rid, owning_lib : org_list, deleted : 'f'},
1026 function() { // finished
1027 service.copies = service.copies.sort(
1029 function compare_array (x, y, i) {
1030 if (x[i] && y[i]) { // both have values
1031 if (x[i] == y[i]) { // need to look deeper
1032 return compare_array(x, y, ++i);
1035 if (x[i] < y[i]) { // x is first
1037 } else if (x[i] > y[i]) { // y is first
1041 } else { // no orgs to compare ...
1042 if (x[i]) return -1;
1048 var owner_order = compare_array(a.owner_list, b.owner_list, 0);
1050 // now compare on CN label
1051 if (a.call_number.label < b.call_number.label) return -1;
1052 if (a.call_number.label > b.call_number.label) return 1;
1055 if (a.copy_number < b.copy_number) return -1;
1056 if (a.copy_number > b.copy_number) return 1;
1059 if (a.barcode < b.barcode) return -1;
1060 if (a.barcode > b.barcode) return 1;
1066 // create a label using just the unique part of the owner list
1068 var prev_owner_list;
1069 angular.forEach(service.copies, function (cp) {
1070 if (!prev_owner_list) {
1071 cp.owner_label = cp.owner_list.join(' ... ');
1073 var current_owner_list = cp.owner_list.slice();
1074 while (current_owner_list[1] && prev_owner_list[1] && current_owner_list[0] == prev_owner_list[0]) {
1075 current_owner_list.shift();
1076 prev_owner_list.shift();
1078 cp.owner_label = current_owner_list.join(' ... ');
1082 prev_owner_list = cp.owner_list.slice();
1085 var new_list = service.copies;
1086 if (!copy || !vol) { // collapse copy rows, supply a count instead
1091 var current_blob = { copy_count : 0 };
1092 angular.forEach(new_list, function (cp) {
1094 prev_key = cp.owner_list.join('') + cp.call_number.label;
1095 if (cp.barcode) current_blob.copy_count = 1;
1096 current_blob.index = index++;
1097 current_blob.id_list = cp.id_list;
1098 if (cp.raw) current_blob.raw = cp.raw;
1099 current_blob.call_number = cp.call_number;
1100 current_blob.owner_list = cp.owner_list;
1101 current_blob.owner_label = cp.owner_label;
1102 current_blob.owner_id = cp.owner_id;
1104 var current_key = cp.owner_list.join('') + cp.call_number.label;
1105 if (prev_key == current_key) { // collapse into current_blob
1106 current_blob.copy_count++;
1107 current_blob.id_list = current_blob.id_list.concat(cp.id_list);
1108 current_blob.raw = current_blob.raw.concat(cp.raw);
1110 current_blob.barcode = current_blob.copy_count;
1111 cp_list.push(current_blob);
1112 prev_key = current_key;
1113 current_blob = { copy_count : 0 };
1114 if (cp.barcode) current_blob.copy_count = 1;
1115 current_blob.index = index++;
1116 current_blob.id_list = cp.id_list;
1117 if (cp.raw) current_blob.raw = cp.raw;
1118 current_blob.owner_label = cp.owner_label;
1119 current_blob.owner_id = cp.owner_id;
1120 current_blob.call_number = cp.call_number;
1121 current_blob.owner_list = cp.owner_list;
1126 current_blob.barcode = current_blob.copy_count;
1127 cp_list.push(current_blob);
1130 if (!vol) { // do the same for vol rows
1135 current_blob = { copy_count : 0 };
1136 angular.forEach(cp_list, function (cp) {
1138 prev_key = cp.owner_list.join('');
1139 current_blob.index = index++;
1140 current_blob.id_list = cp.id_list;
1141 if (cp.raw) current_blob.raw = cp.raw;
1142 current_blob.cn_count = 1;
1143 current_blob.copy_count = cp.copy_count;
1144 current_blob.owner_list = cp.owner_list;
1145 current_blob.owner_label = cp.owner_label;
1146 current_blob.owner_id = cp.owner_id;
1148 var current_key = cp.owner_list.join('');
1149 if (prev_key == current_key) { // collapse into current_blob
1150 current_blob.cn_count++;
1151 current_blob.copy_count += cp.copy_count;
1152 current_blob.id_list = current_blob.id_list.concat(cp.id_list);
1153 if (cp.raw) current_blob.raw = current_blob.raw.concat(cp.raw);
1155 current_blob.barcode = current_blob.copy_count;
1156 current_blob.call_number = { label : current_blob.cn_count };
1157 cn_list.push(current_blob);
1158 prev_key = current_key;
1159 current_blob = { copy_count : 0 };
1160 current_blob.index = index++;
1161 current_blob.id_list = cp.id_list;
1162 if (cp.raw) current_blob.raw = cp.raw;
1163 current_blob.owner_label = cp.owner_label;
1164 current_blob.owner_id = cp.owner_id;
1165 current_blob.cn_count = 1;
1166 current_blob.copy_count = cp.copy_count;
1167 current_blob.owner_list = cp.owner_list;
1172 current_blob.barcode = current_blob.copy_count;
1173 current_blob.call_number = { label : current_blob.cn_count };
1174 cn_list.push(current_blob);
1180 service.copies = new_list;
1181 service.ongoing = false;
1186 // notify reads the stream of copies, one at a time.
1189 var copies = cn.copies().filter(function(cp){ return cp.deleted() == 'f' });
1192 angular.forEach(copies, function (cp) {
1196 var owner_id = cn.owning_lib();
1197 var owner = egCore.org.get(owner_id);
1199 var owner_name_list = [];
1200 while (owner.parent_ou()) { // we're going to skip the top of the tree...
1201 owner_name_list.unshift(owner.name());
1202 owner = egCore.org.get(owner.parent_ou());
1207 angular.forEach(copies, function (cp) {
1208 var flat_cp = egCore.idl.toHash(cp);
1209 flat_cp.owner_id = owner_id;
1210 flat_cp.owner_list = owner_name_list;
1211 flat_cp.id_list = [flat_cp.id];
1216 service.copies = service.copies.concat(flat);
1218 service.copies.push({
1219 owner_id : owner_id,
1220 owner_list : owner_name_list,
1221 call_number: egCore.idl.toHash(cn),