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',
152 function($scope , $routeParams , $location , $q , egCore , egHolds,
153 egGridDataProvider , egHoldGridActions , $timeout) {
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.in_opac_call = false;
164 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
165 if ($scope.opac_iframe) {
166 if (force_opac_tab) $scope.record_tab = 'catalog';
167 $scope.in_opac_call = true;
168 $scope.opac_iframe.contentWindow[opac_frame_function]();
172 $scope.stop_unload = false;
173 $scope.$watch('stop_unload',
174 function(newVal, oldVal) {
175 if (newVal && newVal != oldVal && $scope.opac_iframe) {
176 $($scope.opac_iframe.contentWindow).on('beforeunload', function(){
177 return 'There is unsaved data in this record.'
180 $($scope.opac_iframe.contentWindow).off('beforeunload');
185 // Set the "last bib" cookie, if we have that
186 if ($scope.record_id)
187 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
189 // also set it when the iframe changes to a new record
190 $scope.handle_page = function(url) {
192 if (!url || url == 'about:blank') {
193 // nothing loaded. If we already have a record ID, leave it.
197 var match = url.match(/\/+opac\/+record\/+(\d+)/);
199 $scope.record_id = match[1];
200 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
202 delete $scope.record_id;
205 // child scope is executing this function, so our digest doesn't fire ... thus,
208 if (!$scope.in_opac_call) {
209 if ($scope.record_id) {
210 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
211 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
213 tab = $routeParams.record_tab || 'catalog';
215 $scope.set_record_tab(tab);
217 $scope.in_opac_call = false;
221 // xulG catalog handlers
222 $scope.handlers = { }
224 // ------------------------------------------------------------------
226 var provider = egGridDataProvider.instance({});
227 $scope.hold_grid_data_provider = provider;
228 $scope.grid_actions = egHoldGridActions;
229 $scope.grid_actions.refresh = function () { provider.refresh() };
230 $scope.hold_grid_controls = {};
232 var hold_ids = []; // current list of holds
233 function fetchHolds(offset, count) {
234 var ids = hold_ids.slice(offset, offset + count);
235 return egHolds.fetch_holds(ids).then(null, null,
236 function(hold_data) {
242 provider.get = function(offset, count) {
243 if ($scope.record_tab != 'holds') return $q.when();
244 var deferred = $q.defer();
245 hold_ids = []; // no caching ATM
250 'open-ils.circ.holds.retrieve_all_from_title',
251 egCore.auth.token(), $scope.record_id,
252 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
254 function(hold_data) {
255 angular.forEach(hold_data, function(list, type) {
256 hold_ids = hold_ids.concat(list);
258 fetchHolds(offset, count).then(
259 deferred.resolve, null, deferred.notify);
263 return deferred.promise;
266 $scope.detail_view = function(action, user_data, items) {
268 $scope.detail_hold_id = h.hold.id();
272 $scope.list_view = function(items) {
273 $scope.detail_hold_id = null;
276 // refresh the list of record holds when the pickup lib is changed.
277 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
278 $scope.pickup_ou_changed = function(org) {
279 $scope.pickup_ou = org;
283 $scope.print_holds = function() {
285 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
287 hold : egCore.idl.toHash(item.hold),
288 patron_last : item.patron_last,
289 patron_alias : item.patron_alias,
290 patron_barcode : item.patron_barcode,
291 copy : egCore.idl.toHash(item.copy),
292 volume : egCore.idl.toHash(item.volume),
293 title : item.mvr.title(),
294 author : item.mvr.author()
300 template : 'holds_for_bib',
301 scope : {holds : holds}
305 $scope.mark_hold_transfer_dest = function() {
306 egCore.hatch.setLocalItem(
307 'eg.circ.hold.title_transfer_target', $scope.record_id);
310 // UI presents this option as "all holds"
311 $scope.transfer_holds_to_marked = function() {
312 var hold_ids = $scope.hold_grid_controls.allItems().map(
313 function(hold_data) {return hold_data.hold.id()});
314 egHolds.transfer_to_marked_title(hold_ids);
317 // ------------------------------------------------------------------
318 // Initialize the selected tab
320 function init_cat_url() {
321 // Set the initial catalog URL. This only happens once.
322 // The URL is otherwise generated through user navigation.
323 if ($scope.catalog_url) return;
325 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
327 // A record ID in the path indicates a request for the record-
329 if ($routeParams.record_id) {
330 url = url.replace(/advanced/, '/record/' + $scope.record_id);
333 $scope.catalog_url = url;
336 $scope.set_record_tab = function(tab) {
337 $scope.record_tab = tab;
346 $scope.detail_hold_record_id = $scope.record_id;
347 // refresh the holds grid
353 $scope.set_default_record_tab = function() {
354 egCore.hatch.setLocalItem(
355 'eg.cat.default_record_tab', $scope.record_tab);
356 $timeout(function(){$scope.default_tab = $scope.record_tab});
360 if ($scope.record_id) {
361 $scope.default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
362 tab = $routeParams.record_tab || $scope.default_tab || 'catalog';
364 tab = $routeParams.record_tab || 'catalog';
366 $scope.set_record_tab(tab);
370 .controller('URLVerifyCtrl',
371 ['$scope','$location',
372 function($scope , $location) {
373 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
376 .controller('VandelayCtrl',
377 ['$scope','$location',
378 function($scope , $location) {
379 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
382 .controller('ManageAuthoritiesCtrl',
383 ['$scope','$location',
384 function($scope , $location) {
385 $scope.manageauthorities_url = $location.absUrl().replace(/\/staff.*/, '/cat/authority/list');
388 .controller('BatchEditCtrl',
389 ['$scope','$location','$routeParams',
390 function($scope , $location , $routeParams) {
391 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
392 if ($routeParams.container_type) {
393 switch ($routeParams.container_type) {
395 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
398 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;