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','conjoinedSvc',
231 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc, egConfirmDialog,
232 egGridDataProvider , egHoldGridActions , $timeout , $modal , holdingsSvc , egUser , conjoinedSvc) {
234 // set record ID on page load if available...
235 $scope.record_id = $routeParams.record_id;
237 if ($routeParams.record_id) $scope.from_route = true;
238 else $scope.from_route = false;
240 // will hold a ref to the opac iframe
241 $scope.opac_iframe = null;
242 $scope.parts_iframe = null;
244 $scope.in_opac_call = false;
245 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
246 if ($scope.opac_iframe) {
247 if (force_opac_tab) $scope.record_tab = 'catalog';
248 $scope.in_opac_call = true;
249 $scope.opac_iframe.dom.contentWindow[opac_frame_function]();
253 $scope.add_to_record_bucket = function() {
254 var recId = $scope.record_id;
256 templateUrl: './cat/catalog/t_add_to_bucket',
260 ['$scope','$modalInstance',
261 function($scope , $modalInstance) {
263 $scope.bucket_id = 0;
264 $scope.newBucketName = '';
265 $scope.allBuckets = [];
268 'open-ils.actor.container.retrieve_by_class.authoritative',
269 egCore.auth.token(), egCore.auth.user().id(),
270 'biblio', 'staff_client'
271 ).then(function(buckets) { $scope.allBuckets = buckets; });
273 $scope.add_to_bucket = function() {
274 var item = new egCore.idl.cbrebi();
275 item.bucket($scope.bucket_id);
276 item.target_biblio_record_entry(recId);
279 'open-ils.actor.container.item.create',
280 egCore.auth.token(), 'biblio', item
281 ).then(function(resp) {
282 $modalInstance.close();
286 $scope.add_to_new_bucket = function() {
287 var bucket = new egCore.idl.cbreb();
288 bucket.owner(egCore.auth.user().id());
289 bucket.name($scope.newBucketName);
290 bucket.description('');
291 bucket.btype('staff_client');
295 'open-ils.actor.container.create',
296 egCore.auth.token(), 'biblio', bucket
297 ).then(function(bucket) {
298 $scope.bucket_id = bucket;
299 $scope.add_to_bucket();
303 $scope.cancel = function() {
304 $modalInstance.dismiss();
310 $scope.stop_unload = false;
311 $scope.$watch('stop_unload',
312 function(newVal, oldVal) {
313 if (newVal && newVal != oldVal && $scope.opac_iframe) {
314 $($scope.opac_iframe.dom.contentWindow).on('beforeunload', function(){
315 return 'There is unsaved data in this record.'
318 if ($scope.opac_iframe)
319 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
324 // Set the "last bib" cookie, if we have that
325 if ($scope.record_id)
326 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
328 // also set it when the iframe changes to a new record
329 $scope.handle_page = function(url) {
331 if (!url || url == 'about:blank') {
332 // nothing loaded. If we already have a record ID, leave it.
336 var match = url.match(/\/+opac\/+record\/+(\d+)/);
338 $scope.record_id = match[1];
339 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
340 $scope.holdings_record_id_changed($scope.record_id);
341 conjoinedSvc.fetch($scope.record_id).then(function(){
342 $scope.conjoinedGridDataProvider.refresh();
346 delete $scope.record_id;
347 $scope.from_route = false;
350 // child scope is executing this function, so our digest doesn't fire ... thus,
353 if (!$scope.in_opac_call) {
354 if ($scope.record_id) {
355 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
356 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
358 tab = $routeParams.record_tab || 'catalog';
360 $scope.set_record_tab(tab);
362 $scope.in_opac_call = false;
366 // xulG catalog handlers
367 $scope.handlers = { }
369 // ------------------------------------------------------------------
372 $scope.conjoinedGridControls = {};
373 $scope.conjoinedGridDataProvider = egGridDataProvider.instance({
374 get : function(offset, count) {
375 return this.arrayNotifier(conjoinedSvc.items, offset, count);
379 $scope.changeConjoinedType = function () {
380 var peers = egCore.idl.Clone($scope.conjoinedGridControls.selectedItems());
381 angular.forEach(peers, function (p) {
382 p.target_copy(p.target_copy().id());
383 p.peer_type(p.peer_type().id());
386 var conjoinedGridDataProviderRef = $scope.conjoinedGridDataProvider;
389 templateUrl: './cat/catalog/t_conjoined_selector',
392 ['$scope','$modalInstance',
393 function($scope , $modalInstance) {
394 $scope.update = true;
396 $scope.peer_type = null;
397 $scope.peer_type_list = [];
398 conjoinedSvc.get_peer_types().then(function(list){
399 $scope.peer_type_list = list;
402 $scope.ok = function(type) {
405 angular.forEach(peers, function (p) {
408 promises.push(egCore.pcrud.update(p));
411 return $q.all(promises)
412 .then(function(){$modalInstance.close()})
413 .then(function(){return conjoinedSvc.fetch()})
414 .then(function(){conjoinedGridDataProviderRef.refresh()});
417 $scope.cancel = function($event) {
418 $modalInstance.dismiss();
419 $event.preventDefault();
426 $scope.refreshConjoined = function () {
427 conjoinedSvc.fetch($scope.record_id)
428 .then(function(){$scope.conjoinedGridDataProvider.refresh();});
431 $scope.deleteSelectedConjoined = function () {
432 var peers = $scope.conjoinedGridControls.selectedItems();
434 if (peers.length > 0) {
435 egConfirmDialog.open(
436 egCore.strings.CONFIRM_DELETE_PEERS,
437 egCore.strings.CONFIRM_DELETE_PEERS_MESSAGE,
438 {peers : peers.length}
439 ).result.then(function() {
440 angular.forEach(peers, function (p) {
444 egCore.pcrud.remove(peers).then(function() {
445 return conjoinedSvc.fetch();
447 $scope.conjoinedGridDataProvider.refresh();
452 if ($scope.record_id)
453 conjoinedSvc.fetch($scope.record_id);
455 // ------------------------------------------------------------------
458 $scope.holdingsGridControls = {};
459 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
460 get : function(offset, count) {
461 return this.arrayNotifier(holdingsSvc.copies, offset, count);
465 $scope.requestItems = function() {
466 var copy_list = gatherSelectedHoldingsIds();
467 if (copy_list.length == 0) return;
470 templateUrl: './cat/catalog/t_request_items',
473 ['$scope','$modalInstance',
474 function($scope , $modalInstance) {
476 $scope.first_user_fetch = true;
480 copy_list : copy_list,
481 pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
482 user : egCore.auth.user().id()
485 egUser.get( $scope.hold_data.user ).then(function(u) {
487 $scope.barcode = u.card().barcode();
488 $scope.user_name = egUser.format_name(u);
489 $scope.hold_data.user = u.id();
492 $scope.user_name = '';
494 $scope.$watch('barcode', function (n) {
495 if (!$scope.first_user_fetch) {
496 egUser.getByBarcode(n).then(function(u) {
498 $scope.user_name = egUser.format_name(u);
499 $scope.hold_data.user = u.id();
502 $scope.user_name = '';
503 delete $scope.hold_data.user;
506 $scope.first_user_fetch = false;
509 $scope.ok = function(h) {
512 hold_type : h.hold_type,
513 pickup_lib: h.pickup_lib.id(),
519 'open-ils.circ.holds.test_and_create.batch.override',
520 egCore.auth.token(), args, h.copy_list
523 $modalInstance.close();
526 $scope.cancel = function($event) {
527 $modalInstance.dismiss();
528 $event.preventDefault();
534 // refresh the list of holdings when the record_id is changed.
535 $scope.holdings_record_id_changed = function(id) {
536 if ($scope.record_id != id) $scope.record_id = id;
537 console.log('record id changed to ' + id + ', loading new holdings');
539 rid : $scope.record_id,
540 org : $scope.holdings_ou,
541 copy: $scope.holdings_show_copies,
542 vol : $scope.holdings_show_vols,
543 empty: $scope.holdings_show_empty
545 $scope.holdingsGridDataProvider.refresh();
549 // refresh the list of holdings when the filter lib is changed.
550 $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
551 $scope.holdings_ou_changed = function(org) {
552 $scope.holdings_ou = org;
554 rid : $scope.record_id,
555 org : $scope.holdings_ou,
556 copy: $scope.holdings_show_copies,
557 vol : $scope.holdings_show_vols,
558 empty: $scope.holdings_show_empty
560 $scope.holdingsGridDataProvider.refresh();
564 $scope.holdings_cb_changed = function(cb,newVal,norefresh) {
566 egCore.hatch.setItem('cat.' + cb, newVal);
567 if (!norefresh) holdingsSvc.fetch({
568 rid : $scope.record_id,
569 org : $scope.holdings_ou,
570 copy: $scope.holdings_show_copies,
571 vol : $scope.holdings_show_vols,
572 empty: $scope.holdings_show_empty
574 $scope.holdingsGridDataProvider.refresh();
578 egCore.hatch.getItem('cat.holdings_show_vols').then(function(x){
579 if (typeof x == 'undefined') x = true;
580 $scope.holdings_cb_changed('holdings_show_vols',x,true);
581 $('#holdings_show_vols').prop('checked', x);
583 egCore.hatch.getItem('cat.holdings_show_copies').then(function(x){
584 if (typeof x == 'undefined') x = true;
585 $scope.holdings_cb_changed('holdings_show_copies',x,true);
586 $('#holdings_show_copies').prop('checked', x);
588 egCore.hatch.getItem('cat.holdings_show_empty').then(function(x){
589 if (typeof x == 'undefined') x = true;
590 $scope.holdings_cb_changed('holdings_show_empty',x);
591 $('#holdings_show_empty').prop('checked', x);
596 $scope.vols_not_shown = function () {
597 return !$scope.holdings_show_vols;
600 $scope.copies_not_shown = function () {
601 return !$scope.holdings_show_copies;
604 $scope.holdings_checkbox_handler = function (item) {
605 $scope.holdings_cb_changed(item.checkbox,item.checked);
608 function gatherSelectedHoldingsIds () {
611 $scope.holdingsGridControls.selectedItems(),
612 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
617 function gatherSelectedRawCopies () {
620 $scope.holdingsGridControls.selectedItems(),
621 function (item) { if (item.raw) cp_list = cp_list.concat(item.raw) }
626 function gatherSelectedVolumeIds () {
629 $scope.holdingsGridControls.selectedItems(),
631 if (cn_id_list.indexOf(item.call_number.id) == -1)
632 cn_id_list.push(item.call_number.id)
638 $scope.selectedHoldingsDelete = function (vols, copies) {
641 var perCnCopies = {};
647 $scope.holdingsGridControls.selectedItems(),
649 if (vols && item.raw_call_number) {
650 cnHash[item.call_number.id] = egCore.idl.Clone(item.raw_call_number);
651 cnHash[item.call_number.id].isdeleted(1);
654 angular.forEach(egCore.idl.Clone(item.raw), function (cp) {
657 var cn_id = cp.call_number().id();
658 if (!cnHash[cn_id]) {
659 cnHash[cn_id] = cp.call_number();
660 perCnCopies[cn_id] = [cp];
662 perCnCopies[cn_id].push(cp);
664 cp.call_number(cn_id); // prevent loops in JSON-ification
671 angular.forEach(perCnCopies, function (v, k) {
673 cnHash[k].isdeleted(1);
680 angular.forEach(cnHash, function (v, k) {
684 if (cnList.length == 0) return;
686 egConfirmDialog.open(
687 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES,
688 egCore.strings.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE,
689 {copies : cp_count, volumes : cn_count}
690 ).result.then(function() {
693 'open-ils.cat.asset.volume.fleshed.batch.update.override',
694 egCore.auth.token(), cnList, 1, {}
695 ).then(function(update_count) {
696 $scope.holdingsGridDataProvider.refresh();
700 $scope.selectedHoldingsCopyDelete = function () { $scope.selectedHoldingsDelete(false,true) }
701 $scope.selectedHoldingsVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,true) }
702 $scope.selectedHoldingsEmptyVolCopyDelete = function () { $scope.selectedHoldingsDelete(true,false) }
704 spawnHoldingsAdd = function (vols,copies){
706 if (copies) { // just a copy on existing volumes
707 angular.forEach(gatherSelectedVolumeIds(), function (v) {
708 raw.push( {callnumber : v} );
712 $scope.holdingsGridControls.selectedItems(),
714 raw.push({owner : item.owner_id});
721 'open-ils.actor.anon_cache.set_value',
722 null, 'edit-these-copies', {
723 record_id: $scope.record_id,
728 ).then(function(key) {
730 var url = egCore.env.basePath + 'cat/volcopy/' + key;
731 $timeout(function() { $window.open(url, '_blank') });
733 alert('Could not create anonymous cache key!');
737 $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
738 $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
740 spawnHoldingsEdit = function (hide_vols,hide_copies){
743 'open-ils.actor.anon_cache.set_value',
744 null, 'edit-these-copies', {
745 record_id: $scope.record_id,
746 copies: gatherSelectedHoldingsIds(),
747 hide_vols : hide_vols,
748 hide_copies : hide_copies
750 ).then(function(key) {
752 var url = egCore.env.basePath + 'cat/volcopy/' + key;
753 $timeout(function() { $window.open(url, '_blank') });
755 alert('Could not create anonymous cache key!');
759 $scope.selectedHoldingsVolCopyEdit = function () { spawnHoldingsEdit(false,false) }
760 $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
761 $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
763 $scope.selectedHoldingsItemStatus = function (){
764 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
765 $timeout(function() { $window.open(url, '_blank') });
768 $scope.markVolAsItemTarget = function() {
769 if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
770 egCore.hatch.setLocalItem(
771 'eg.cat.item_transfer_target',
772 $scope.holdingsGridControls.selectedItems()[0].call_number.id
777 $scope.markLibAsVolTarget = function() {
778 egCore.hatch.setLocalItem(
779 'eg.cat.volume_transfer_target',
780 $scope.holdingsGridControls.selectedItems()[0].owner_id
784 $scope.selectedHoldingsItemStatusDetail = function (){
786 gatherSelectedHoldingsIds(),
788 var url = egCore.env.basePath +
790 $timeout(function() { $window.open(url, '_blank') });
795 $scope.transferVolumes = function (){
796 var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
801 'open-ils.open-ils.cat.asset.volume.batch.transfer.override',
802 egCore.auth.token(), {
803 docid : $scope.record_id,
805 volumes : gatherSelectedVolumeIds()
807 ).then(function(success) {
810 rid : $scope.record_id,
811 org : $scope.holdings_ou,
812 copy: $scope.holdings_show_copies,
813 vol : $scope.holdings_show_vols,
814 empty: $scope.holdings_show_empty
816 $scope.holdingsGridDataProvider.refresh();
819 alert('Could not transfer volumes!');
826 $scope.transferItems = function (){
827 var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
829 var copy_list = gatherSelectedRawCopies();
831 angular.forEach(copy_list, function (cp) {
832 cp.call_number(xfer_target);
837 ).then(function(success) {
840 rid : $scope.record_id,
841 org : $scope.holdings_ou,
842 copy: $scope.holdings_show_copies,
843 vol : $scope.holdings_show_vols,
844 empty: $scope.holdings_show_empty
846 $scope.holdingsGridDataProvider.refresh();
849 alert('Could not transfer items!');
856 $scope.selectedHoldingsItemStatusTgrEvt = function (){
858 gatherSelectedHoldingsIds(),
860 var url = egCore.env.basePath +
861 'cat/item/' + cid + '/triggered_events';
862 $timeout(function() { $window.open(url, '_blank') });
867 $scope.selectedHoldingsItemStatusHolds = function (){
869 gatherSelectedHoldingsIds(),
871 var url = egCore.env.basePath +
872 'cat/item/' + cid + '/holds';
873 $timeout(function() { $window.open(url, '_blank') });
878 $scope.selectedHoldingsDamaged = function () {
879 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
881 rid : $scope.record_id,
882 org : $scope.holdings_ou,
883 copy: $scope.holdings_show_copies,
884 vol : $scope.holdings_show_vols,
885 empty: $scope.holdings_show_empty
887 $scope.holdingsGridDataProvider.refresh();
892 $scope.selectedHoldingsMissing = function () {
893 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
895 rid : $scope.record_id,
896 org : $scope.holdings_ou,
897 copy: $scope.holdings_show_copies,
898 vol : $scope.holdings_show_vols,
899 empty: $scope.holdings_show_empty
901 $scope.holdingsGridDataProvider.refresh();
906 $scope.attach_to_peer_bib = function() {
907 var copy_list = gatherSelectedHoldingsIds();
908 if (copy_list.length == 0) return;
910 egCore.hatch.getItem('eg.cat.marked_conjoined_record').then(function(target_record) {
911 if (!target_record) return;
914 templateUrl: './cat/catalog/t_conjoined_selector',
917 ['$scope','$modalInstance',
918 function($scope , $modalInstance) {
919 $scope.update = false;
921 $scope.peer_type = null;
922 $scope.peer_type_list = [];
923 conjoinedSvc.get_peer_types().then(function(list){
924 $scope.peer_type_list = list;
927 $scope.ok = function(type) {
930 angular.forEach(copy_list, function (cp) {
931 var n = new egCore.idl.bpbcm();
933 n.peer_record(target_record);
936 promises.push(egCore.pcrud.create(n));
939 return $q.all(promises).then(function(){$modalInstance.close()});
942 $scope.cancel = function($event) {
943 $modalInstance.dismiss();
944 $event.preventDefault();
952 // ------------------------------------------------------------------
954 var provider = egGridDataProvider.instance({});
955 $scope.hold_grid_data_provider = provider;
956 $scope.grid_actions = egHoldGridActions;
957 $scope.grid_actions.refresh = function () { provider.refresh() };
958 $scope.hold_grid_controls = {};
960 var hold_ids = []; // current list of holds
961 function fetchHolds(offset, count) {
962 var ids = hold_ids.slice(offset, offset + count);
963 return egHolds.fetch_holds(ids).then(null, null,
964 function(hold_data) {
970 provider.get = function(offset, count) {
971 if ($scope.record_tab != 'holds') return $q.when();
972 var deferred = $q.defer();
973 hold_ids = []; // no caching ATM
978 'open-ils.circ.holds.retrieve_all_from_title',
979 egCore.auth.token(), $scope.record_id,
980 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
982 function(hold_data) {
983 angular.forEach(hold_data, function(list, type) {
984 hold_ids = hold_ids.concat(list);
986 fetchHolds(offset, count).then(
987 deferred.resolve, null, deferred.notify);
991 return deferred.promise;
994 $scope.detail_view = function(action, user_data, items) {
996 $scope.detail_hold_id = h.hold.id();
1000 $scope.list_view = function(items) {
1001 $scope.detail_hold_id = null;
1004 // refresh the list of record holds when the pickup lib is changed.
1005 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
1006 $scope.pickup_ou_changed = function(org) {
1007 $scope.pickup_ou = org;
1011 $scope.print_holds = function() {
1013 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
1015 hold : egCore.idl.toHash(item.hold),
1016 patron_last : item.patron_last,
1017 patron_alias : item.patron_alias,
1018 patron_barcode : item.patron_barcode,
1019 copy : egCore.idl.toHash(item.copy),
1020 volume : egCore.idl.toHash(item.volume),
1021 title : item.mvr.title(),
1022 author : item.mvr.author()
1026 egCore.print.print({
1027 context : 'receipt',
1028 template : 'holds_for_bib',
1029 scope : {holds : holds}
1033 $scope.mark_hold_transfer_dest = function() {
1034 egCore.hatch.setLocalItem(
1035 'eg.circ.hold.title_transfer_target', $scope.record_id);
1038 // UI presents this option as "all holds"
1039 $scope.transfer_holds_to_marked = function() {
1040 var hold_ids = $scope.hold_grid_controls.allItems().map(
1041 function(hold_data) {return hold_data.hold.id()});
1042 egHolds.transfer_to_marked_title(hold_ids);
1045 // ------------------------------------------------------------------
1046 // Initialize the selected tab
1048 function init_cat_url() {
1049 // Set the initial catalog URL. This only happens once.
1050 // The URL is otherwise generated through user navigation.
1051 if ($scope.catalog_url) return;
1053 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
1055 // A record ID in the path indicates a request for the record-
1057 if ($routeParams.record_id) {
1058 url = url.replace(/advanced/, '/record/' + $scope.record_id);
1061 $scope.catalog_url = url;
1064 function init_parts_url() {
1065 $scope.parts_url = $location
1069 '/conify/global/biblio/monograph_part?r='+$scope.record_id
1073 $scope.set_record_tab = function(tab) {
1074 $scope.record_tab = tab;
1087 $scope.detail_hold_record_id = $scope.record_id;
1088 // refresh the holds grid
1094 $scope.set_default_record_tab = function() {
1095 egCore.hatch.setLocalItem(
1096 'eg.cat.default_record_tab', $scope.record_tab);
1097 $timeout(function(){$scope.default_tab = $scope.record_tab});
1101 if ($scope.record_id) {
1102 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
1103 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
1106 tab = $routeParams.record_tab || 'catalog';
1108 $scope.set_record_tab(tab);
1112 .controller('AuthorityCtrl',
1113 ['$scope','$routeParams','$location','$window','$q','egCore',
1114 function($scope , $routeParams , $location , $window , $q , egCore) {
1116 // set record ID on page load if available...
1117 $scope.authority_id = $routeParams.authority_id;
1119 if ($routeParams.authority_id) $scope.from_route = true;
1120 else $scope.from_route = false;
1122 $scope.stop_unload = false;
1125 .controller('URLVerifyCtrl',
1126 ['$scope','$location',
1127 function($scope , $location) {
1128 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
1131 .controller('VandelayCtrl',
1132 ['$scope','$location',
1133 function($scope , $location) {
1134 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
1137 .controller('ManageAuthoritiesCtrl',
1138 ['$scope','$location',
1139 function($scope , $location) {
1140 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
1143 .controller('BatchEditCtrl',
1144 ['$scope','$location','$routeParams',
1145 function($scope , $location , $routeParams) {
1146 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
1147 if ($routeParams.container_type) {
1148 switch ($routeParams.container_type) {
1150 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
1153 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
1160 .filter('boolText', function(){
1161 return function (v) {
1166 .factory('holdingsSvc',
1168 function(egCore , $q) {
1172 copies : [], // record search results
1173 index : 0, // search grid index
1181 acp : ['status','location'],
1182 acn : ['prefix','suffix','copies']
1186 // resolved with the last received copy
1187 service.fetch = function(opts) {
1188 if (service.ongoing) {
1189 console.log('Skipping fetch, ongoing = true');
1195 var copy = opts.copy;
1197 var empty = opts.empty;
1199 if (!rid) return $q.when();
1200 if (!org) return $q.when();
1202 service.ongoing = true;
1206 service.copies = [];
1209 var org_list = egCore.org.descendants(org.id(), true);
1210 console.log('Holdings fetch with: rid='+rid+' org='+org_list+' copy='+copy+' vol='+vol+' empty='+empty);
1212 return egCore.pcrud.search(
1214 {record : rid, owning_lib : org_list, deleted : 'f'},
1217 function() { // finished
1218 service.copies = service.copies.sort(
1220 function compare_array (x, y, i) {
1221 if (x[i] && y[i]) { // both have values
1222 if (x[i] == y[i]) { // need to look deeper
1223 return compare_array(x, y, ++i);
1226 if (x[i] < y[i]) { // x is first
1228 } else if (x[i] > y[i]) { // y is first
1232 } else { // no orgs to compare ...
1233 if (x[i]) return -1;
1239 var owner_order = compare_array(a.owner_list, b.owner_list, 0);
1241 // now compare on CN label
1242 if (a.call_number.label < b.call_number.label) return -1;
1243 if (a.call_number.label > b.call_number.label) return 1;
1246 if (a.copy_number < b.copy_number) return -1;
1247 if (a.copy_number > b.copy_number) return 1;
1250 if (a.barcode < b.barcode) return -1;
1251 if (a.barcode > b.barcode) return 1;
1257 // create a label using just the unique part of the owner list
1259 var prev_owner_list;
1260 angular.forEach(service.copies, function (cp) {
1261 if (!prev_owner_list) {
1262 cp.owner_label = cp.owner_list.join(' ... ');
1264 var current_owner_list = cp.owner_list.slice();
1265 while (current_owner_list[1] && prev_owner_list[1] && current_owner_list[0] == prev_owner_list[0]) {
1266 current_owner_list.shift();
1267 prev_owner_list.shift();
1269 cp.owner_label = current_owner_list.join(' ... ');
1273 prev_owner_list = cp.owner_list.slice();
1276 var new_list = service.copies;
1277 if (!copy || !vol) { // collapse copy rows, supply a count instead
1282 var current_blob = { copy_count : 0 };
1283 angular.forEach(new_list, function (cp) {
1285 prev_key = cp.owner_list.join('') + cp.call_number.label;
1286 if (cp.barcode) current_blob.copy_count = 1;
1287 current_blob.index = index++;
1288 current_blob.id_list = cp.id_list;
1289 if (cp.raw) current_blob.raw = cp.raw;
1290 current_blob.call_number = cp.call_number;
1291 current_blob.owner_list = cp.owner_list;
1292 current_blob.owner_label = cp.owner_label;
1293 current_blob.owner_id = cp.owner_id;
1295 var current_key = cp.owner_list.join('') + cp.call_number.label;
1296 if (prev_key == current_key) { // collapse into current_blob
1297 current_blob.copy_count++;
1298 current_blob.id_list = current_blob.id_list.concat(cp.id_list);
1299 current_blob.raw = current_blob.raw.concat(cp.raw);
1301 current_blob.barcode = current_blob.copy_count;
1302 cp_list.push(current_blob);
1303 prev_key = current_key;
1304 current_blob = { copy_count : 0 };
1305 if (cp.barcode) current_blob.copy_count = 1;
1306 current_blob.index = index++;
1307 current_blob.id_list = cp.id_list;
1308 if (cp.raw) current_blob.raw = cp.raw;
1309 current_blob.owner_label = cp.owner_label;
1310 current_blob.owner_id = cp.owner_id;
1311 current_blob.call_number = cp.call_number;
1312 current_blob.owner_list = cp.owner_list;
1317 current_blob.barcode = current_blob.copy_count;
1318 cp_list.push(current_blob);
1321 if (!vol) { // do the same for vol rows
1326 current_blob = { copy_count : 0 };
1327 angular.forEach(cp_list, function (cp) {
1329 prev_key = cp.owner_list.join('');
1330 current_blob.index = index++;
1331 current_blob.id_list = cp.id_list;
1332 if (cp.raw) current_blob.raw = cp.raw;
1333 current_blob.cn_count = 1;
1334 current_blob.copy_count = cp.copy_count;
1335 current_blob.owner_list = cp.owner_list;
1336 current_blob.owner_label = cp.owner_label;
1337 current_blob.owner_id = cp.owner_id;
1339 var current_key = cp.owner_list.join('');
1340 if (prev_key == current_key) { // collapse into current_blob
1341 current_blob.cn_count++;
1342 current_blob.copy_count += cp.copy_count;
1343 current_blob.id_list = current_blob.id_list.concat(cp.id_list);
1344 if (cp.raw) current_blob.raw = current_blob.raw.concat(cp.raw);
1346 current_blob.barcode = current_blob.copy_count;
1347 current_blob.call_number = { label : current_blob.cn_count };
1348 cn_list.push(current_blob);
1349 prev_key = current_key;
1350 current_blob = { copy_count : 0 };
1351 current_blob.index = index++;
1352 current_blob.id_list = cp.id_list;
1353 if (cp.raw) current_blob.raw = cp.raw;
1354 current_blob.owner_label = cp.owner_label;
1355 current_blob.owner_id = cp.owner_id;
1356 current_blob.cn_count = 1;
1357 current_blob.copy_count = cp.copy_count;
1358 current_blob.owner_list = cp.owner_list;
1363 current_blob.barcode = current_blob.copy_count;
1364 current_blob.call_number = { label : current_blob.cn_count };
1365 cn_list.push(current_blob);
1371 service.copies = new_list;
1372 service.ongoing = false;
1377 // notify reads the stream of copies, one at a time.
1380 var copies = cn.copies().filter(function(cp){ return cp.deleted() == 'f' });
1383 angular.forEach(copies, function (cp) {
1387 var owner_id = cn.owning_lib();
1388 var owner = egCore.org.get(owner_id);
1390 var owner_name_list = [];
1391 while (owner.parent_ou()) { // we're going to skip the top of the tree...
1392 owner_name_list.unshift(owner.name());
1393 owner = egCore.org.get(owner.parent_ou());
1398 angular.forEach(copies, function (cp) {
1399 var flat_cp = egCore.idl.toHash(cp);
1400 flat_cp.owner_id = owner_id;
1401 flat_cp.owner_list = owner_name_list;
1402 flat_cp.id_list = [flat_cp.id];
1407 service.copies = service.copies.concat(flat);
1409 service.copies.push({
1410 owner_id : owner_id,
1411 owner_list : owner_name_list,
1412 call_number: egCore.idl.toHash(cn),
1425 .factory('conjoinedSvc',
1427 function(egCore , $q) {
1430 items : [], // record search results
1431 index : 0, // search grid index
1438 bpbcm : ['target_copy','peer_type'],
1439 acp : ['call_number'],
1441 bre : ['simple_record']
1443 // avoid fetching the MARC blob by specifying which
1444 // fields on the bre to select. More may be needed.
1445 // note that fleshed fields are explicitly selected.
1446 select : { bre : ['id'] },
1447 order_by : { bpbcm : ['id'] },
1450 // resolved with the last received copy
1451 service.fetch = function(rid) {
1452 if (!rid && !service.rid) return $q.when();
1454 if (rid) service.rid = rid;
1458 return egCore.pcrud.search(
1460 {peer_record : service.rid},
1463 ).then( function(list) { // finished
1464 service.items = list;
1465 return service.items;
1469 // returns a promise resolved with the list of peer bib types
1470 service.get_peer_types = function() {
1472 return $q.when(egCore.env.bpt.list);
1474 return egCore.pcrud.retrieveAll('bpt', null, {atomic : true})
1475 .then(function(list) {
1476 egCore.env.absorbList(list, 'bpt');