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','$q','egCore','egHolds',
151 'egGridDataProvider','egHoldGridActions','$timeout','holdingsSvc',
152 function($scope , $routeParams , $location , $q , egCore , egHolds,
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;
243 holdingsSvc.fetch($scope.record_id, $scope.holdings_ou).then(function() {
244 $scope.holdingsGridDataProvider.refresh();
249 // ------------------------------------------------------------------
251 var provider = egGridDataProvider.instance({});
252 $scope.hold_grid_data_provider = provider;
253 $scope.grid_actions = egHoldGridActions;
254 $scope.grid_actions.refresh = function () { provider.refresh() };
255 $scope.hold_grid_controls = {};
257 var hold_ids = []; // current list of holds
258 function fetchHolds(offset, count) {
259 var ids = hold_ids.slice(offset, offset + count);
260 return egHolds.fetch_holds(ids).then(null, null,
261 function(hold_data) {
267 provider.get = function(offset, count) {
268 if ($scope.record_tab != 'holds') return $q.when();
269 var deferred = $q.defer();
270 hold_ids = []; // no caching ATM
275 'open-ils.circ.holds.retrieve_all_from_title',
276 egCore.auth.token(), $scope.record_id,
277 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
279 function(hold_data) {
280 angular.forEach(hold_data, function(list, type) {
281 hold_ids = hold_ids.concat(list);
283 fetchHolds(offset, count).then(
284 deferred.resolve, null, deferred.notify);
288 return deferred.promise;
291 $scope.detail_view = function(action, user_data, items) {
293 $scope.detail_hold_id = h.hold.id();
297 $scope.list_view = function(items) {
298 $scope.detail_hold_id = null;
301 // refresh the list of record holds when the pickup lib is changed.
302 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
303 $scope.pickup_ou_changed = function(org) {
304 $scope.pickup_ou = org;
308 $scope.print_holds = function() {
310 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
312 hold : egCore.idl.toHash(item.hold),
313 patron_last : item.patron_last,
314 patron_alias : item.patron_alias,
315 patron_barcode : item.patron_barcode,
316 copy : egCore.idl.toHash(item.copy),
317 volume : egCore.idl.toHash(item.volume),
318 title : item.mvr.title(),
319 author : item.mvr.author()
325 template : 'holds_for_bib',
326 scope : {holds : holds}
330 $scope.mark_hold_transfer_dest = function() {
331 egCore.hatch.setLocalItem(
332 'eg.circ.hold.title_transfer_target', $scope.record_id);
335 // UI presents this option as "all holds"
336 $scope.transfer_holds_to_marked = function() {
337 var hold_ids = $scope.hold_grid_controls.allItems().map(
338 function(hold_data) {return hold_data.hold.id()});
339 egHolds.transfer_to_marked_title(hold_ids);
342 // ------------------------------------------------------------------
343 // Initialize the selected tab
345 function init_cat_url() {
346 // Set the initial catalog URL. This only happens once.
347 // The URL is otherwise generated through user navigation.
348 if ($scope.catalog_url) return;
350 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
352 // A record ID in the path indicates a request for the record-
354 if ($routeParams.record_id) {
355 url = url.replace(/advanced/, '/record/' + $scope.record_id);
358 $scope.catalog_url = url;
361 function init_parts_url() {
362 $scope.parts_url = $location
366 '/conify/global/biblio/monograph_part?r='+$scope.record_id
370 $scope.set_record_tab = function(tab) {
371 $scope.record_tab = tab;
384 $scope.detail_hold_record_id = $scope.record_id;
385 // refresh the holds grid
391 $scope.set_default_record_tab = function() {
392 egCore.hatch.setLocalItem(
393 'eg.cat.default_record_tab', $scope.record_tab);
394 $timeout(function(){$scope.default_tab = $scope.record_tab});
398 if ($scope.record_id) {
399 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
400 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
402 holdingsSvc.fetch($scope.record_id, $scope.holdings_ou).then(function() {
403 $scope.holdingsGridDataProvider.refresh();
407 tab = $routeParams.record_tab || 'catalog';
409 $scope.set_record_tab(tab);
413 .controller('URLVerifyCtrl',
414 ['$scope','$location',
415 function($scope , $location) {
416 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
419 .controller('VandelayCtrl',
420 ['$scope','$location',
421 function($scope , $location) {
422 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
425 .controller('ManageAuthoritiesCtrl',
426 ['$scope','$location',
427 function($scope , $location) {
428 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
431 .controller('BatchEditCtrl',
432 ['$scope','$location','$routeParams',
433 function($scope , $location , $routeParams) {
434 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
435 if ($routeParams.container_type) {
436 switch ($routeParams.container_type) {
438 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
441 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;
448 .filter('boolText', function(){
449 return function (v) {
454 .factory('holdingsSvc',
456 function(egCore , $q) {
459 copies : [], // record search results
460 index : 0, // search grid index
468 acp : ['status','location'],
469 acn : ['prefix','suffix','copies']
473 // resolved with the last received copy
474 service.fetch = function(rid, org) {
476 if (!rid) return $q.when();
477 if (!org) return $q.when();
478 if (service.rid && service.org && service.rid == rid && service.org == org) return $q.when();
485 var org_list = egCore.org.descendants(org.id(), true);
487 return egCore.pcrud.search(
489 {record : rid, owning_lib : org_list, deleted : 'f'},
492 function() { // finished
493 service.copies = service.copies.sort(
495 function compare_array (x, y, i) {
496 if (x[i] && y[i]) { // both have values
497 if (x[i] == y[i]) { // need to look deeper
498 return compare_array(x, y, ++i);
501 if (x[i] < y[i]) { // x is first
503 } else if (x[i] > y[i]) { // y is first
507 } else { // no orgs to compare ...
514 var owner_order = compare_array(a.owner_list, b.owner_list, 0);
516 // now compare on CN label
517 if (a.call_number.label < b.call_number.label) return -1;
518 if (a.call_number.label > b.call_number.label) return 1;
521 if (a.copy_number < b.copy_number) return -1;
522 if (a.copy_number > b.copy_number) return 1;
525 if (a.barcode < b.barcode) return -1;
526 if (a.barcode > b.barcode) return 1;
532 // create a label using just the unique part of the owner list
535 angular.forEach(service.copies, function (cp) {
536 if (!prev_owner_list) {
537 cp.owner_label = cp.owner_list.join(' ... ');
539 var current_owner_list = cp.owner_list.slice();
540 while (current_owner_list[1] && prev_owner_list[1] && current_owner_list[0] == prev_owner_list[0]) {
541 current_owner_list.shift();
542 prev_owner_list.shift();
544 cp.owner_label = current_owner_list.join(' ... ');
548 prev_owner_list = cp.owner_list.slice();
554 // notify reads the stream of copies, one at a time.
557 var copies = cn.copies();
560 angular.forEach(copies, function (cp) {
564 var flat = egCore.idl.toHash(copies);
565 var owner = egCore.org.get(flat[0].call_number.owning_lib);
567 var owner_name_list = [];
568 while (owner.parent_ou()) { // we're going to skip the top of the tree...
569 owner_name_list.unshift(owner.name());
570 owner = egCore.org.get(owner.parent_ou());
573 angular.forEach(flat, function (cp) {
574 cp.owner_list = owner_name_list;
577 service.copies = service.copies.concat(flat);