4 * currently, this app doesn't use routes for each sub-ui, because
5 * reloading the catalog each time is sloooow. better so far to
6 * swap out divs w/ ng-if / ng-show / ng-hide as needed.
10 angular.module('egCatalogApp', ['ui.bootstrap','ngRoute','egCoreMod','egGridMod', 'egMarcMod'])
12 .config(function($routeProvider, $locationProvider, $compileProvider) {
13 $locationProvider.html5Mode(true);
14 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
16 var resolver = {delay :
17 ['egStartup', function(egStartup) {return egStartup.go()}]}
19 $routeProvider.when('/cat/catalog/index', {
20 templateUrl: './cat/catalog/t_catalog',
21 controller: 'CatalogCtrl',
25 $routeProvider.when('/cat/catalog/retrieve_by_id', {
26 templateUrl: './cat/catalog/t_retrieve_by_id',
27 controller: 'CatalogRecordRetrieve',
31 $routeProvider.when('/cat/catalog/retrieve_by_tcn', {
32 templateUrl: './cat/catalog/t_retrieve_by_tcn',
33 controller: 'CatalogRecordRetrieve',
37 // create some catalog page-specific mappings
38 $routeProvider.when('/cat/catalog/record/:record_id', {
39 templateUrl: './cat/catalog/t_catalog',
40 controller: 'CatalogCtrl',
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',
51 $routeProvider.when('/cat/catalog/batchEdit', {
52 templateUrl: './cat/catalog/t_batchedit',
53 controller: 'BatchEditCtrl',
57 $routeProvider.when('/cat/catalog/batchEdit/:container_type/:container_id', {
58 templateUrl: './cat/catalog/t_batchedit',
59 controller: 'BatchEditCtrl',
63 $routeProvider.when('/cat/catalog/vandelay', {
64 templateUrl: './cat/catalog/t_vandelay',
65 controller: 'VandelayCtrl',
69 $routeProvider.when('/cat/catalog/verifyURLs', {
70 templateUrl: './cat/catalog/t_verifyurls',
71 controller: 'URLVerifyCtrl',
75 $routeProvider.when('/cat/catalog/manageAuthorities', {
76 templateUrl: './cat/catalog/t_manageauthorities',
77 controller: 'ManageAuthoritiesCtrl',
81 $routeProvider.otherwise({redirectTo : '/cat/catalog/index'});
87 .controller('CatalogRecordRetrieve',
88 ['$scope','$routeParams','$location','$q','egCore',
89 function($scope , $routeParams , $location , $q , egCore ) {
91 $scope.focusMe = true;
93 // jump to the patron checkout UI
94 function loadRecord(record_id) {
96 .path('/cat/catalog/record/' + record_id);
99 $scope.submitId = function(args) {
100 $scope.recordNotFound = null;
101 if (!args.record_id) return;
103 // blur so next time it's set to true it will re-apply select()
104 $scope.selectMe = false;
106 return loadRecord(args.record_id);
109 $scope.submitTCN = function(args) {
110 $scope.recordNotFound = null;
111 $scope.moreRecordsFound = null;
112 if (!args.record_tcn) return;
114 // blur so next time it's set to true it will re-apply select()
115 $scope.selectMe = false;
120 'open-ils.search.biblio.tcn',
123 .then(function(resp) { // get_barcodes
125 if (evt = egCore.evt.parse(resp)) {
131 $scope.recordNotFound = args.record_tcn;
132 $scope.selectMe = true;
136 if (resp.count > 1) {
137 $scope.moreRecordsFound = args.record_tcn;
138 $scope.selectMe = true;
142 var record_id = resp.ids[0];
143 return loadRecord(record_id);
149 .controller('CatalogCtrl',
150 ['$scope','$routeParams','$location','$window','$q','egCore','egHolds','egCirc',
151 'egGridDataProvider','egHoldGridActions','$timeout','holdingsSvc',
152 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc,
153 egGridDataProvider , egHoldGridActions , $timeout , holdingsSvc) {
155 // set record ID on page load if available...
156 $scope.record_id = $routeParams.record_id;
158 if ($routeParams.record_id) $scope.from_route = true;
159 else $scope.from_route = false;
161 // will hold a ref to the opac iframe
162 $scope.opac_iframe = null;
163 $scope.parts_iframe = null;
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]();
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.'
182 if ($scope.opac_iframe)
183 $($scope.opac_iframe.dom.contentWindow).off('beforeunload');
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);
192 // also set it when the iframe changes to a new record
193 $scope.handle_page = function(url) {
195 if (!url || url == 'about:blank') {
196 // nothing loaded. If we already have a record ID, leave it.
200 var match = url.match(/\/+opac\/+record\/+(\d+)/);
202 $scope.record_id = match[1];
203 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
206 delete $scope.record_id;
207 $scope.from_route = false;
210 // child scope is executing this function, so our digest doesn't fire ... thus,
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';
218 tab = $routeParams.record_tab || 'catalog';
220 $scope.set_record_tab(tab);
222 $scope.in_opac_call = false;
226 // xulG catalog handlers
227 $scope.handlers = { }
229 // ------------------------------------------------------------------
232 $scope.holdingsGridControls = {};
233 $scope.holdingsGridDataProvider = egGridDataProvider.instance({
234 get : function(offset, count) {
235 return this.arrayNotifier(holdingsSvc.copies, offset, count);
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;
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
250 $scope.holdingsGridDataProvider.refresh();
254 $scope.holdings_show_copies_changed = function(newVal) {
255 $scope.holdings_show_copies = newVal;
256 egCore.hatch.setItem('cat.holdings.show_copies', newVal);
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
264 $scope.holdingsGridDataProvider.refresh();
268 $scope.holdings_show_vols_changed = function(newVal) {
269 $scope.holdings_show_vols = newVal;
270 egCore.hatch.setItem('cat.holdings.show_vols', newVal);
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
278 $scope.holdingsGridDataProvider.refresh();
282 $scope.holdings_show_empty_changed = function(newVal) {
283 $scope.holdings_show_empty = newVal;
284 egCore.hatch.setItem('cat.holdings.show_empty', newVal);
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
292 $scope.holdingsGridDataProvider.refresh();
296 egCore.hatch.getItem('cat.holdings.show_copies').then(function(x){
297 if (typeof x == 'undefined') x = true;
298 $scope.holdings_show_copies = x;
301 egCore.hatch.getItem('cat.holdings.show_vols').then(function(x){
302 if (typeof x == 'undefined') x = true;
303 $scope.holdings_show_vols = x;
306 egCore.hatch.getItem('cat.holdings.show_emtpy').then(function(x){
307 if (typeof x == 'undefined') x = false;
308 $scope.holdings_show_empty = x;
311 $scope.holdings_checkbox_handler = function (item) {
312 $scope[item.checkbox] = item.checked;
313 $scope[item.checkbox + '_changed'](item.checked);
316 function gatherSelectedHoldingsIds () {
319 $scope.holdingsGridControls.selectedItems(),
320 function (item) { cp_id_list = cp_id_list.concat(item.id_list) }
325 $scope.selectedHoldingsItemStatus = function (){
326 var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
327 $timeout(function() { $window.open(url, '_blank') });
330 $scope.selectedHoldingsItemStatusDetail = function (){
332 gatherSelectedHoldingsIds(),
334 var url = egCore.env.basePath +
336 $timeout(function() { $window.open(url, '_blank') });
341 $scope.selectedHoldingsItemStatusTgrEvt = function (){
343 gatherSelectedHoldingsIds(),
345 var url = egCore.env.basePath +
346 'cat/item/' + cid + '/triggered_events';
347 $timeout(function() { $window.open(url, '_blank') });
352 $scope.selectedHoldingsItemStatusHolds = function (){
354 gatherSelectedHoldingsIds(),
356 var url = egCore.env.basePath +
357 'cat/item/' + cid + '/holds';
358 $timeout(function() { $window.open(url, '_blank') });
363 $scope.selectedHoldingsDamaged = function () {
364 egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
366 rid : $scope.record_id,
367 org : $scope.holdings_ou,
368 copy: $scope.holdings_show_copies,
369 vol : $scope.holdings_show_vols,
370 empty: $scope.holdings_show_empty
372 $scope.holdingsGridDataProvider.refresh();
377 $scope.selectedHoldingsMissing = function () {
378 egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
380 rid : $scope.record_id,
381 org : $scope.holdings_ou,
382 copy: $scope.holdings_show_copies,
383 vol : $scope.holdings_show_vols,
384 empty: $scope.holdings_show_empty
386 $scope.holdingsGridDataProvider.refresh();
392 // ------------------------------------------------------------------
394 var provider = egGridDataProvider.instance({});
395 $scope.hold_grid_data_provider = provider;
396 $scope.grid_actions = egHoldGridActions;
397 $scope.grid_actions.refresh = function () { provider.refresh() };
398 $scope.hold_grid_controls = {};
400 var hold_ids = []; // current list of holds
401 function fetchHolds(offset, count) {
402 var ids = hold_ids.slice(offset, offset + count);
403 return egHolds.fetch_holds(ids).then(null, null,
404 function(hold_data) {
410 provider.get = function(offset, count) {
411 if ($scope.record_tab != 'holds') return $q.when();
412 var deferred = $q.defer();
413 hold_ids = []; // no caching ATM
418 'open-ils.circ.holds.retrieve_all_from_title',
419 egCore.auth.token(), $scope.record_id,
420 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
422 function(hold_data) {
423 angular.forEach(hold_data, function(list, type) {
424 hold_ids = hold_ids.concat(list);
426 fetchHolds(offset, count).then(
427 deferred.resolve, null, deferred.notify);
431 return deferred.promise;
434 $scope.detail_view = function(action, user_data, items) {
436 $scope.detail_hold_id = h.hold.id();
440 $scope.list_view = function(items) {
441 $scope.detail_hold_id = null;
444 // refresh the list of record holds when the pickup lib is changed.
445 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
446 $scope.pickup_ou_changed = function(org) {
447 $scope.pickup_ou = org;
451 $scope.print_holds = function() {
453 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
455 hold : egCore.idl.toHash(item.hold),
456 patron_last : item.patron_last,
457 patron_alias : item.patron_alias,
458 patron_barcode : item.patron_barcode,
459 copy : egCore.idl.toHash(item.copy),
460 volume : egCore.idl.toHash(item.volume),
461 title : item.mvr.title(),
462 author : item.mvr.author()
468 template : 'holds_for_bib',
469 scope : {holds : holds}
473 $scope.mark_hold_transfer_dest = function() {
474 egCore.hatch.setLocalItem(
475 'eg.circ.hold.title_transfer_target', $scope.record_id);
478 // UI presents this option as "all holds"
479 $scope.transfer_holds_to_marked = function() {
480 var hold_ids = $scope.hold_grid_controls.allItems().map(
481 function(hold_data) {return hold_data.hold.id()});
482 egHolds.transfer_to_marked_title(hold_ids);
485 // ------------------------------------------------------------------
486 // Initialize the selected tab
488 function init_cat_url() {
489 // Set the initial catalog URL. This only happens once.
490 // The URL is otherwise generated through user navigation.
491 if ($scope.catalog_url) return;
493 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
495 // A record ID in the path indicates a request for the record-
497 if ($routeParams.record_id) {
498 url = url.replace(/advanced/, '/record/' + $scope.record_id);
501 $scope.catalog_url = url;
504 function init_parts_url() {
505 $scope.parts_url = $location
509 '/conify/global/biblio/monograph_part?r='+$scope.record_id
513 $scope.set_record_tab = function(tab) {
514 $scope.record_tab = tab;
527 $scope.detail_hold_record_id = $scope.record_id;
528 // refresh the holds grid
534 $scope.set_default_record_tab = function() {
535 egCore.hatch.setLocalItem(
536 'eg.cat.default_record_tab', $scope.record_tab);
537 $timeout(function(){$scope.default_tab = $scope.record_tab});
541 if ($scope.record_id) {
542 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
543 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
548 rid : $scope.record_id,
549 org : $scope.holdings_ou,
550 copy: $scope.holdings_show_copies,
551 vol : $scope.holdings_show_vols,
552 empty: $scope.holdings_show_empty
554 $scope.holdingsGridDataProvider.refresh();
559 tab = $routeParams.record_tab || 'catalog';
561 $scope.set_record_tab(tab);
565 .controller('URLVerifyCtrl',
566 ['$scope','$location',
567 function($scope , $location) {
568 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
571 .controller('VandelayCtrl',
572 ['$scope','$location',
573 function($scope , $location) {
574 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
577 .controller('ManageAuthoritiesCtrl',
578 ['$scope','$location',
579 function($scope , $location) {
580 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
583 .controller('BatchEditCtrl',
584 ['$scope','$location','$routeParams',
585 function($scope , $location , $routeParams) {
586 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
587 if ($routeParams.container_type) {
588 switch ($routeParams.container_type) {
590 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
593 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
600 .filter('boolText', function(){
601 return function (v) {
606 .factory('holdingsSvc',
608 function(egCore , $q) {
612 copies : [], // record search results
613 index : 0, // search grid index
621 acp : ['status','location'],
622 acn : ['prefix','suffix','copies']
626 // resolved with the last received copy
627 service.fetch = function(opts) {
628 if (service.ongoing) return $q.when();
632 var copy = opts.copy;
634 var empty = opts.empty;
636 if (!rid) return $q.when();
637 if (!org) return $q.when();
639 service.ongoing = true;
646 var org_list = egCore.org.descendants(org.id(), true);
648 return egCore.pcrud.search(
650 {record : rid, owning_lib : org_list, deleted : 'f'},
653 function() { // finished
654 service.copies = service.copies.sort(
656 function compare_array (x, y, i) {
657 if (x[i] && y[i]) { // both have values
658 if (x[i] == y[i]) { // need to look deeper
659 return compare_array(x, y, ++i);
662 if (x[i] < y[i]) { // x is first
664 } else if (x[i] > y[i]) { // y is first
668 } else { // no orgs to compare ...
675 var owner_order = compare_array(a.owner_list, b.owner_list, 0);
677 // now compare on CN label
678 if (a.call_number.label < b.call_number.label) return -1;
679 if (a.call_number.label > b.call_number.label) return 1;
682 if (a.copy_number < b.copy_number) return -1;
683 if (a.copy_number > b.copy_number) return 1;
686 if (a.barcode < b.barcode) return -1;
687 if (a.barcode > b.barcode) return 1;
693 // create a label using just the unique part of the owner list
696 angular.forEach(service.copies, function (cp) {
697 if (!prev_owner_list) {
698 cp.owner_label = cp.owner_list.join(' ... ');
700 var current_owner_list = cp.owner_list.slice();
701 while (current_owner_list[1] && prev_owner_list[1] && current_owner_list[0] == prev_owner_list[0]) {
702 current_owner_list.shift();
703 prev_owner_list.shift();
705 cp.owner_label = current_owner_list.join(' ... ');
709 prev_owner_list = cp.owner_list.slice();
712 var new_list = service.copies;
713 if (!copy || !vol) { // collapse copy rows, supply a count instead
718 var current_blob = {};
719 angular.forEach(new_list, function (cp) {
721 prev_key = cp.owner_list.join('') + cp.call_number.label;
722 if (cp.barcode) current_blob.copy_count = 1;
723 current_blob.index = index++;
724 current_blob.id_list = cp.id_list;
725 current_blob.call_number = cp.call_number;
726 current_blob.owner_list = cp.owner_list;
727 current_blob.owner_label = cp.owner_label;
729 var current_key = cp.owner_list.join('') + cp.call_number.label;
730 if (prev_key == current_key) { // collapse into current_blob
731 current_blob.copy_count++;
732 current_blob.id_list = current_blob.id_list.concat(cp.id_list);
734 current_blob.barcode = current_blob.copy_count;
735 cp_list.push(current_blob);
736 prev_key = current_key;
738 if (cp.barcode) current_blob.copy_count = 1;
739 current_blob.index = index++;
740 current_blob.id_list = cp.id_list;
741 current_blob.owner_label = cp.owner_label;
742 current_blob.call_number = cp.call_number;
743 current_blob.owner_list = cp.owner_list;
748 current_blob.barcode = current_blob.copy_count;
749 cp_list.push(current_blob);
752 if (!vol) { // do the same for vol rows
757 var current_blob = {};
758 angular.forEach(cp_list, function (cp) {
760 prev_key = cp.owner_list.join('');
761 current_blob.index = index++;
762 current_blob.id_list = cp.id_list;
763 current_blob.cn_count = 1;
764 current_blob.copy_count = cp.copy_count;
765 current_blob.owner_list = cp.owner_list;
766 current_blob.owner_label = cp.owner_label;
768 var current_key = cp.owner_list.join('');
769 if (prev_key == current_key) { // collapse into current_blob
770 current_blob.cn_count++;
771 current_blob.copy_count += cp.copy_count;
772 current_blob.id_list = current_blob.id_list.concat(cp.id_list);
774 current_blob.barcode = current_blob.copy_count;
775 current_blob.call_number = { label : current_blob.cn_count };
776 cn_list.push(current_blob);
777 prev_key = current_key;
779 current_blob.index = index++;
780 current_blob.id_list = cp.id_list;
781 current_blob.owner_label = cp.owner_label;
782 current_blob.cn_count = 1;
783 current_blob.copy_count = cp.copy_count;
784 current_blob.owner_list = cp.owner_list;
789 current_blob.barcode = current_blob.copy_count;
790 current_blob.call_number = { label : current_blob.cn_count };
791 cn_list.push(current_blob);
797 service.copies = new_list;
798 service.ongoing = false;
803 // notify reads the stream of copies, one at a time.
806 var copies = cn.copies();
809 angular.forEach(copies, function (cp) {
813 var flat = egCore.idl.toHash(copies);
814 var owner = egCore.org.get(flat[0].call_number.owning_lib);
816 var owner_name_list = [];
817 while (owner.parent_ou()) { // we're going to skip the top of the tree...
818 owner_name_list.unshift(owner.name());
819 owner = egCore.org.get(owner.parent_ou());
822 angular.forEach(flat, function (cp) {
823 cp.owner_list = owner_name_list;
824 cp.id_list = [cp.id];
827 service.copies = service.copies.concat(flat);
829 if (empty && flat.length == 0) {
830 service.copies.push({
831 owner_list : owner_name_list,
832 call_number: egCore.idl.toHash(cn)