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.otherwise({redirectTo : '/cat/catalog/index'});
81 .controller('CatalogRecordRetrieve',
82 ['$scope','$routeParams','$location','$q','egCore',
83 function($scope , $routeParams , $location , $q , egCore ) {
85 $scope.focusMe = true;
87 // jump to the patron checkout UI
88 function loadRecord(record_id) {
90 .path('/cat/catalog/record/' + record_id);
93 $scope.submitId = function(args) {
94 $scope.recordNotFound = null;
95 if (!args.record_id) return;
97 // blur so next time it's set to true it will re-apply select()
98 $scope.selectMe = false;
100 return loadRecord(args.record_id);
103 $scope.submitTCN = function(args) {
104 $scope.recordNotFound = null;
105 $scope.moreRecordsFound = null;
106 if (!args.record_tcn) return;
108 // blur so next time it's set to true it will re-apply select()
109 $scope.selectMe = false;
114 'open-ils.search.biblio.tcn',
117 .then(function(resp) { // get_barcodes
119 if (evt = egCore.evt.parse(resp)) {
125 $scope.recordNotFound = args.record_tcn;
126 $scope.selectMe = true;
130 if (resp.count > 1) {
131 $scope.moreRecordsFound = args.record_tcn;
132 $scope.selectMe = true;
136 var record_id = resp.ids[0];
137 return loadRecord(record_id);
143 .controller('CatalogCtrl',
144 ['$scope','$routeParams','$location','$q','egCore','egHolds',
145 'egGridDataProvider','egHoldGridActions',
146 function($scope , $routeParams , $location , $q , egCore , egHolds,
147 egGridDataProvider , egHoldGridActions) {
149 // set record ID on page load if available...
150 $scope.record_id = $routeParams.record_id;
152 if ($routeParams.record_id) $scope.from_route = true;
153 else $scope.from_route = false;
155 // will hold a ref to the opac iframe
156 $scope.opac_iframe = null;
157 $scope.in_opac_call = false;
158 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
159 if ($scope.opac_iframe) {
160 if (force_opac_tab) $scope.record_tab = 'catalog';
161 $scope.in_opac_call = true;
162 $scope.opac_iframe.contentWindow[opac_frame_function]();
166 $scope.stop_unload = false;
167 $scope.$watch('stop_unload',
168 function(newVal, oldVal) {
169 if (newVal && newVal != oldVal && $scope.opac_iframe) {
170 $($scope.opac_iframe.contentWindow).on('beforeunload', function(){
171 return 'There is unsaved data in this record.'
174 $($scope.opac_iframe.contentWindow).off('beforeunload');
179 // Set the "last bib" cookie, if we have that
180 if ($scope.record_id)
181 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
183 // also set it when the iframe changes to a new record
184 $scope.handle_page = function(url) {
186 if (!url || url == 'about:blank') {
187 // nothing loaded. If we already have a record ID, leave it.
191 var match = url.match(/\/+opac\/+record\/+(\d+)/);
193 $scope.record_id = match[1];
194 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
196 delete $scope.record_id;
199 // child scope is executing this function, so our digest doesn't fire ... thus,
202 if (!$scope.in_opac_call) {
203 if ($scope.record_id) {
204 var default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
205 tab = $routeParams.record_tab || default_tab || 'catalog';
207 tab = $routeParams.record_tab || 'catalog';
209 $scope.set_record_tab(tab);
211 $scope.in_opac_call = false;
215 // xulG catalog handlers
216 $scope.handlers = { }
218 // ------------------------------------------------------------------
220 var provider = egGridDataProvider.instance({});
221 $scope.hold_grid_data_provider = provider;
222 $scope.grid_actions = egHoldGridActions;
223 $scope.grid_actions.refresh = function () { provider.refresh() };
224 $scope.hold_grid_controls = {};
226 var hold_ids = []; // current list of holds
227 function fetchHolds(offset, count) {
228 var ids = hold_ids.slice(offset, offset + count);
229 return egHolds.fetch_holds(ids).then(null, null,
230 function(hold_data) {
236 provider.get = function(offset, count) {
237 if ($scope.record_tab != 'holds') return $q.when();
238 var deferred = $q.defer();
239 hold_ids = []; // no caching ATM
244 'open-ils.circ.holds.retrieve_all_from_title',
245 egCore.auth.token(), $scope.record_id,
246 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
248 function(hold_data) {
249 angular.forEach(hold_data, function(list, type) {
250 hold_ids = hold_ids.concat(list);
252 fetchHolds(offset, count).then(
253 deferred.resolve, null, deferred.notify);
257 return deferred.promise;
260 $scope.detail_view = function(action, user_data, items) {
262 $scope.detail_hold_id = h.hold.id();
266 $scope.list_view = function(items) {
267 $scope.detail_hold_id = null;
270 // refresh the list of record holds when the pickup lib is changed.
271 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
272 $scope.pickup_ou_changed = function(org) {
273 $scope.pickup_ou = org;
277 $scope.print_holds = function() {
279 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
281 hold : egCore.idl.toHash(item.hold),
282 patron_last : item.patron_last,
283 patron_alias : item.patron_alias,
284 patron_barcode : item.patron_barcode,
285 copy : egCore.idl.toHash(item.copy),
286 volume : egCore.idl.toHash(item.volume),
287 title : item.mvr.title(),
288 author : item.mvr.author()
294 template : 'holds_for_bib',
295 scope : {holds : holds}
299 $scope.mark_hold_transfer_dest = function() {
300 egCore.hatch.setLocalItem(
301 'eg.circ.hold.title_transfer_target', $scope.record_id);
304 // UI presents this option as "all holds"
305 $scope.transfer_holds_to_marked = function() {
306 var hold_ids = $scope.hold_grid_controls.allItems().map(
307 function(hold_data) {return hold_data.hold.id()});
308 egHolds.transfer_to_marked_title(hold_ids);
311 // ------------------------------------------------------------------
312 // Initialize the selected tab
314 function init_cat_url() {
315 // Set the initial catalog URL. This only happens once.
316 // The URL is otherwise generated through user navigation.
317 if ($scope.catalog_url) return;
319 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
321 // A record ID in the path indicates a request for the record-
323 if ($routeParams.record_id) {
324 url = url.replace(/advanced/, '/record/' + $scope.record_id);
327 $scope.catalog_url = url;
330 $scope.set_record_tab = function(tab) {
331 $scope.record_tab = tab;
340 $scope.detail_hold_record_id = $scope.record_id;
341 // refresh the holds grid
347 $scope.set_default_record_tab = function() {
348 egCore.hatch.setLocalItem(
349 'eg.cat.default_record_tab', $scope.record_tab);
353 if ($scope.record_id) {
354 var default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
355 tab = $routeParams.record_tab || default_tab || 'catalog';
357 tab = $routeParams.record_tab || 'catalog';
359 $scope.set_record_tab(tab);
363 .controller('URLVerifyCtrl',
364 ['$scope','$location',
365 function($scope , $location) {
366 $scope.verifyurls_url = $location.absUrl().replace(/\/staff.*/, '/url_verify/sessions');
369 .controller('VandelayCtrl',
370 ['$scope','$location',
371 function($scope , $location) {
372 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
375 .controller('BatchEditCtrl',
376 ['$scope','$location','$routeParams',
377 function($scope , $location , $routeParams) {
378 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
379 if ($routeParams.container_type) {
380 switch ($routeParams.container_type) {
382 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
385 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;