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/vandelay', {
52 templateUrl: './cat/catalog/t_vandelay',
53 controller: 'VandelayCtrl',
57 $routeProvider.otherwise({redirectTo : '/cat/catalog/index'});
63 .controller('CatalogRecordRetrieve',
64 ['$scope','$routeParams','$location','$q','egCore',
65 function($scope , $routeParams , $location , $q , egCore ) {
67 $scope.focusMe = true;
69 // jump to the patron checkout UI
70 function loadRecord(record_id) {
72 .path('/cat/catalog/record/' + record_id);
75 $scope.submitId = function(args) {
76 $scope.recordNotFound = null;
77 if (!args.record_id) return;
79 // blur so next time it's set to true it will re-apply select()
80 $scope.selectMe = false;
82 return loadRecord(args.record_id);
85 $scope.submitTCN = function(args) {
86 $scope.recordNotFound = null;
87 $scope.moreRecordsFound = null;
88 if (!args.record_tcn) return;
90 // blur so next time it's set to true it will re-apply select()
91 $scope.selectMe = false;
96 'open-ils.search.biblio.tcn',
99 .then(function(resp) { // get_barcodes
101 if (evt = egCore.evt.parse(resp)) {
107 $scope.recordNotFound = args.record_tcn;
108 $scope.selectMe = true;
112 if (resp.count > 1) {
113 $scope.moreRecordsFound = args.record_tcn;
114 $scope.selectMe = true;
118 var record_id = resp.ids[0];
119 return loadRecord(record_id);
125 .controller('CatalogCtrl',
126 ['$scope','$routeParams','$location','$q','egCore','egHolds',
127 'egGridDataProvider','egHoldGridActions',
128 function($scope , $routeParams , $location , $q , egCore , egHolds,
129 egGridDataProvider , egHoldGridActions) {
131 // set record ID on page load if available...
132 $scope.record_id = $routeParams.record_id;
134 if ($routeParams.record_id) $scope.from_route = true;
135 else $scope.from_route = false;
137 // will hold a ref to the opac iframe
138 $scope.opac_iframe = null;
139 $scope.in_opac_call = false;
140 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
141 if ($scope.opac_iframe) {
142 if (force_opac_tab) $scope.record_tab = 'catalog';
143 $scope.in_opac_call = true;
144 $scope.opac_iframe.contentWindow[opac_frame_function]();
148 $scope.stop_unload = false;
149 $scope.$watch('stop_unload',
150 function(newVal, oldVal) {
151 if (newVal && newVal != oldVal && $scope.opac_iframe) {
152 $($scope.opac_iframe.contentWindow).on('beforeunload', function(){
153 return 'There is unsaved data in this record.'
156 $($scope.opac_iframe.contentWindow).off('beforeunload');
161 // Set the "last bib" cookie, if we have that
162 if ($scope.record_id)
163 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
165 // also set it when the iframe changes to a new record
166 $scope.handle_page = function(url) {
168 if (!url || url == 'about:blank') {
169 // nothing loaded. If we already have a record ID, leave it.
173 var match = url.match(/\/+opac\/+record\/+(\d+)/);
175 $scope.record_id = match[1];
176 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
178 delete $scope.record_id;
181 // child scope is executing this function, so our digest doesn't fire ... thus,
184 if (!$scope.in_opac_call) {
185 if ($scope.record_id) {
186 var default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
187 tab = $routeParams.record_tab || default_tab || 'catalog';
189 tab = $routeParams.record_tab || 'catalog';
191 $scope.set_record_tab(tab);
193 $scope.in_opac_call = false;
197 // xulG catalog handlers
198 $scope.handlers = { }
200 // ------------------------------------------------------------------
202 var provider = egGridDataProvider.instance({});
203 $scope.hold_grid_data_provider = provider;
204 $scope.grid_actions = egHoldGridActions;
205 $scope.grid_actions.refresh = function () { provider.refresh() };
206 $scope.hold_grid_controls = {};
208 var hold_ids = []; // current list of holds
209 function fetchHolds(offset, count) {
210 var ids = hold_ids.slice(offset, offset + count);
211 return egHolds.fetch_holds(ids).then(null, null,
212 function(hold_data) {
218 provider.get = function(offset, count) {
219 if ($scope.record_tab != 'holds') return $q.when();
220 var deferred = $q.defer();
221 hold_ids = []; // no caching ATM
226 'open-ils.circ.holds.retrieve_all_from_title',
227 egCore.auth.token(), $scope.record_id,
228 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
230 function(hold_data) {
231 angular.forEach(hold_data, function(list, type) {
232 hold_ids = hold_ids.concat(list);
234 fetchHolds(offset, count).then(
235 deferred.resolve, null, deferred.notify);
239 return deferred.promise;
242 $scope.detail_view = function(action, user_data, items) {
244 $scope.detail_hold_id = h.hold.id();
248 $scope.list_view = function(items) {
249 $scope.detail_hold_id = null;
252 // refresh the list of record holds when the pickup lib is changed.
253 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
254 $scope.pickup_ou_changed = function(org) {
255 $scope.pickup_ou = org;
259 $scope.print_holds = function() {
261 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
263 hold : egCore.idl.toHash(item.hold),
264 patron_last : item.patron_last,
265 patron_alias : item.patron_alias,
266 patron_barcode : item.patron_barcode,
267 copy : egCore.idl.toHash(item.copy),
268 volume : egCore.idl.toHash(item.volume),
269 title : item.mvr.title(),
270 author : item.mvr.author()
276 template : 'holds_for_bib',
277 scope : {holds : holds}
281 $scope.mark_hold_transfer_dest = function() {
282 egCore.hatch.setLocalItem(
283 'eg.circ.hold.title_transfer_target', $scope.record_id);
286 // UI presents this option as "all holds"
287 $scope.transfer_holds_to_marked = function() {
288 var hold_ids = $scope.hold_grid_controls.allItems().map(
289 function(hold_data) {return hold_data.hold.id()});
290 egHolds.transfer_to_marked_title(hold_ids);
293 // ------------------------------------------------------------------
294 // Initialize the selected tab
296 function init_cat_url() {
297 // Set the initial catalog URL. This only happens once.
298 // The URL is otherwise generated through user navigation.
299 if ($scope.catalog_url) return;
301 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
303 // A record ID in the path indicates a request for the record-
305 if ($routeParams.record_id) {
306 url = url.replace(/advanced/, '/record/' + $scope.record_id);
309 $scope.catalog_url = url;
312 $scope.set_record_tab = function(tab) {
313 $scope.record_tab = tab;
322 $scope.detail_hold_record_id = $scope.record_id;
323 // refresh the holds grid
329 $scope.set_default_record_tab = function() {
330 egCore.hatch.setLocalItem(
331 'eg.cat.default_record_tab', $scope.record_tab);
335 if ($scope.record_id) {
336 var default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
337 tab = $routeParams.record_tab || default_tab || 'catalog';
339 tab = $routeParams.record_tab || 'catalog';
341 $scope.set_record_tab(tab);
345 .controller('VandelayCtrl',
346 ['$scope','$location',
347 function($scope , $location) {
348 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');