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.otherwise({redirectTo : '/cat/catalog/index'});
75 .controller('CatalogRecordRetrieve',
76 ['$scope','$routeParams','$location','$q','egCore',
77 function($scope , $routeParams , $location , $q , egCore ) {
79 $scope.focusMe = true;
81 // jump to the patron checkout UI
82 function loadRecord(record_id) {
84 .path('/cat/catalog/record/' + record_id);
87 $scope.submitId = function(args) {
88 $scope.recordNotFound = null;
89 if (!args.record_id) return;
91 // blur so next time it's set to true it will re-apply select()
92 $scope.selectMe = false;
94 return loadRecord(args.record_id);
97 $scope.submitTCN = function(args) {
98 $scope.recordNotFound = null;
99 $scope.moreRecordsFound = null;
100 if (!args.record_tcn) return;
102 // blur so next time it's set to true it will re-apply select()
103 $scope.selectMe = false;
108 'open-ils.search.biblio.tcn',
111 .then(function(resp) { // get_barcodes
113 if (evt = egCore.evt.parse(resp)) {
119 $scope.recordNotFound = args.record_tcn;
120 $scope.selectMe = true;
124 if (resp.count > 1) {
125 $scope.moreRecordsFound = args.record_tcn;
126 $scope.selectMe = true;
130 var record_id = resp.ids[0];
131 return loadRecord(record_id);
137 .controller('CatalogCtrl',
138 ['$scope','$routeParams','$location','$q','egCore','egHolds',
139 'egGridDataProvider','egHoldGridActions',
140 function($scope , $routeParams , $location , $q , egCore , egHolds,
141 egGridDataProvider , egHoldGridActions) {
143 // set record ID on page load if available...
144 $scope.record_id = $routeParams.record_id;
146 if ($routeParams.record_id) $scope.from_route = true;
147 else $scope.from_route = false;
149 // will hold a ref to the opac iframe
150 $scope.opac_iframe = null;
151 $scope.in_opac_call = false;
152 $scope.opac_call = function (opac_frame_function, force_opac_tab) {
153 if ($scope.opac_iframe) {
154 if (force_opac_tab) $scope.record_tab = 'catalog';
155 $scope.in_opac_call = true;
156 $scope.opac_iframe.contentWindow[opac_frame_function]();
160 $scope.stop_unload = false;
161 $scope.$watch('stop_unload',
162 function(newVal, oldVal) {
163 if (newVal && newVal != oldVal && $scope.opac_iframe) {
164 $($scope.opac_iframe.contentWindow).on('beforeunload', function(){
165 return 'There is unsaved data in this record.'
168 $($scope.opac_iframe.contentWindow).off('beforeunload');
173 // Set the "last bib" cookie, if we have that
174 if ($scope.record_id)
175 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
177 // also set it when the iframe changes to a new record
178 $scope.handle_page = function(url) {
180 if (!url || url == 'about:blank') {
181 // nothing loaded. If we already have a record ID, leave it.
185 var match = url.match(/\/+opac\/+record\/+(\d+)/);
187 $scope.record_id = match[1];
188 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
190 delete $scope.record_id;
193 // child scope is executing this function, so our digest doesn't fire ... thus,
196 if (!$scope.in_opac_call) {
197 if ($scope.record_id) {
198 var default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
199 tab = $routeParams.record_tab || default_tab || 'catalog';
201 tab = $routeParams.record_tab || 'catalog';
203 $scope.set_record_tab(tab);
205 $scope.in_opac_call = false;
209 // xulG catalog handlers
210 $scope.handlers = { }
212 // ------------------------------------------------------------------
214 var provider = egGridDataProvider.instance({});
215 $scope.hold_grid_data_provider = provider;
216 $scope.grid_actions = egHoldGridActions;
217 $scope.grid_actions.refresh = function () { provider.refresh() };
218 $scope.hold_grid_controls = {};
220 var hold_ids = []; // current list of holds
221 function fetchHolds(offset, count) {
222 var ids = hold_ids.slice(offset, offset + count);
223 return egHolds.fetch_holds(ids).then(null, null,
224 function(hold_data) {
230 provider.get = function(offset, count) {
231 if ($scope.record_tab != 'holds') return $q.when();
232 var deferred = $q.defer();
233 hold_ids = []; // no caching ATM
238 'open-ils.circ.holds.retrieve_all_from_title',
239 egCore.auth.token(), $scope.record_id,
240 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
242 function(hold_data) {
243 angular.forEach(hold_data, function(list, type) {
244 hold_ids = hold_ids.concat(list);
246 fetchHolds(offset, count).then(
247 deferred.resolve, null, deferred.notify);
251 return deferred.promise;
254 $scope.detail_view = function(action, user_data, items) {
256 $scope.detail_hold_id = h.hold.id();
260 $scope.list_view = function(items) {
261 $scope.detail_hold_id = null;
264 // refresh the list of record holds when the pickup lib is changed.
265 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
266 $scope.pickup_ou_changed = function(org) {
267 $scope.pickup_ou = org;
271 $scope.print_holds = function() {
273 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
275 hold : egCore.idl.toHash(item.hold),
276 patron_last : item.patron_last,
277 patron_alias : item.patron_alias,
278 patron_barcode : item.patron_barcode,
279 copy : egCore.idl.toHash(item.copy),
280 volume : egCore.idl.toHash(item.volume),
281 title : item.mvr.title(),
282 author : item.mvr.author()
288 template : 'holds_for_bib',
289 scope : {holds : holds}
293 $scope.mark_hold_transfer_dest = function() {
294 egCore.hatch.setLocalItem(
295 'eg.circ.hold.title_transfer_target', $scope.record_id);
298 // UI presents this option as "all holds"
299 $scope.transfer_holds_to_marked = function() {
300 var hold_ids = $scope.hold_grid_controls.allItems().map(
301 function(hold_data) {return hold_data.hold.id()});
302 egHolds.transfer_to_marked_title(hold_ids);
305 // ------------------------------------------------------------------
306 // Initialize the selected tab
308 function init_cat_url() {
309 // Set the initial catalog URL. This only happens once.
310 // The URL is otherwise generated through user navigation.
311 if ($scope.catalog_url) return;
313 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
315 // A record ID in the path indicates a request for the record-
317 if ($routeParams.record_id) {
318 url = url.replace(/advanced/, '/record/' + $scope.record_id);
321 $scope.catalog_url = url;
324 $scope.set_record_tab = function(tab) {
325 $scope.record_tab = tab;
334 $scope.detail_hold_record_id = $scope.record_id;
335 // refresh the holds grid
341 $scope.set_default_record_tab = function() {
342 egCore.hatch.setLocalItem(
343 'eg.cat.default_record_tab', $scope.record_tab);
347 if ($scope.record_id) {
348 var default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
349 tab = $routeParams.record_tab || default_tab || 'catalog';
351 tab = $routeParams.record_tab || 'catalog';
353 $scope.set_record_tab(tab);
357 .controller('VandelayCtrl',
358 ['$scope','$location',
359 function($scope , $location) {
360 $scope.vandelay_url = $location.absUrl().replace(/\/staff.*/, '/vandelay/vandelay');
363 .controller('BatchEditCtrl',
364 ['$scope','$location','$routeParams',
365 function($scope , $location , $routeParams) {
366 $scope.batchedit_url = $location.absUrl().replace(/\/eg.*/, '/opac/extras/merge_template');
367 if ($routeParams.container_type) {
368 switch ($routeParams.container_type) {
370 $scope.batchedit_url += '?recordSource=b&containerid=' + $routeParams.container_id;
373 $scope.batchedit_url += '?recordSource=r&recid=' + $routeParams.container_id;