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.otherwise({redirectTo : '/cat/catalog/index'});
57 .controller('CatalogRecordRetrieve',
58 ['$scope','$routeParams','$location','$q','egCore',
59 function($scope , $routeParams , $location , $q , egCore ) {
61 $scope.focusMe = true;
63 // jump to the patron checkout UI
64 function loadRecord(record_id) {
66 .path('/cat/catalog/record/' + record_id);
69 $scope.submitId = function(args) {
70 $scope.recordNotFound = null;
71 if (!args.record_id) return;
73 // blur so next time it's set to true it will re-apply select()
74 $scope.selectMe = false;
76 return loadRecord(args.record_id);
79 $scope.submitTCN = function(args) {
80 $scope.recordNotFound = null;
81 $scope.moreRecordsFound = null;
82 if (!args.record_tcn) return;
84 // blur so next time it's set to true it will re-apply select()
85 $scope.selectMe = false;
90 'open-ils.search.biblio.tcn',
93 .then(function(resp) { // get_barcodes
95 if (evt = egCore.evt.parse(resp)) {
101 $scope.recordNotFound = args.record_tcn;
102 $scope.selectMe = true;
106 if (resp.count > 1) {
107 $scope.moreRecordsFound = args.record_tcn;
108 $scope.selectMe = true;
112 var record_id = resp.ids[0];
113 return loadRecord(record_id);
119 .controller('CatalogCtrl',
120 ['$scope','$routeParams','$location','$q','egCore','egHolds',
121 'egGridDataProvider','egHoldGridActions',
122 function($scope , $routeParams , $location , $q , egCore , egHolds,
123 egGridDataProvider , egHoldGridActions) {
125 // set record ID on page load if available...
126 $scope.record_id = $routeParams.record_id;
128 if ($routeParams.record_id) $scope.from_route = true;
129 else $scope.from_route = false;
131 // will hold a ref to the opac iframe
132 $scope.opac_iframe = null;
133 $scope.opac_call = function (thing) {
134 if ($scope.opac_iframe) $scope.opac_iframe.contentWindow[thing]()
137 // Set the "last bib" cookie, if we have that
138 if ($scope.record_id)
139 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
141 // also set it when the iframe changes to a new record
142 $scope.handle_page = function(url) {
144 if (!url || url == 'about:blank') {
145 // nothing loaded. If we already have a record ID, leave it.
149 var match = url.match(/\/+opac\/+record\/+(\d+)/);
151 $scope.record_id = match[1];
152 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
154 // force the record_id to show up in the page.
155 // not sure why a $digest isn't occuring here.
156 try { $scope.$apply() } catch(E) {}
158 delete $scope.record_id;
161 if ($scope.record_id) {
162 var default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
163 tab = $routeParams.record_tab || default_tab || 'catalog';
165 tab = $routeParams.record_tab || 'catalog';
167 $scope.set_record_tab(tab);
170 // xulG catalog handlers
171 $scope.handlers = { }
173 // ------------------------------------------------------------------
175 var provider = egGridDataProvider.instance({});
176 $scope.hold_grid_data_provider = provider;
177 $scope.grid_actions = egHoldGridActions;
178 $scope.grid_actions.refresh = function () { provider.refresh() };
179 $scope.hold_grid_controls = {};
181 var hold_ids = []; // current list of holds
182 function fetchHolds(offset, count) {
183 var ids = hold_ids.slice(offset, offset + count);
184 return egHolds.fetch_holds(ids).then(null, null,
185 function(hold_data) {
191 provider.get = function(offset, count) {
192 if ($scope.record_tab != 'holds') return $q.when();
193 var deferred = $q.defer();
194 hold_ids = []; // no caching ATM
199 'open-ils.circ.holds.retrieve_all_from_title',
200 egCore.auth.token(), $scope.record_id,
201 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
203 function(hold_data) {
204 angular.forEach(hold_data, function(list, type) {
205 hold_ids = hold_ids.concat(list);
207 fetchHolds(offset, count).then(
208 deferred.resolve, null, deferred.notify);
212 return deferred.promise;
215 $scope.detail_view = function(action, user_data, items) {
217 $scope.detail_hold_id = h.hold.id();
221 $scope.list_view = function(items) {
222 $scope.detail_hold_id = null;
225 // refresh the list of record holds when the pickup lib is changed.
226 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
227 $scope.pickup_ou_changed = function(org) {
228 $scope.pickup_ou = org;
232 $scope.print_holds = function() {
234 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
236 hold : egCore.idl.toHash(item.hold),
237 patron_last : item.patron_last,
238 patron_alias : item.patron_alias,
239 patron_barcode : item.patron_barcode,
240 copy : egCore.idl.toHash(item.copy),
241 volume : egCore.idl.toHash(item.volume),
242 title : item.mvr.title(),
243 author : item.mvr.author()
249 template : 'holds_for_bib',
250 scope : {holds : holds}
254 $scope.mark_hold_transfer_dest = function() {
255 egCore.hatch.setLocalItem(
256 'eg.circ.hold.title_transfer_target', $scope.record_id);
259 // UI presents this option as "all holds"
260 $scope.transfer_holds_to_marked = function() {
261 var hold_ids = $scope.hold_grid_controls.allItems().map(
262 function(hold_data) {return hold_data.hold.id()});
263 egHolds.transfer_to_marked_title(hold_ids);
266 // ------------------------------------------------------------------
267 // Initialize the selected tab
269 function init_cat_url() {
270 // Set the initial catalog URL. This only happens once.
271 // The URL is otherwise generated through user navigation.
272 if ($scope.catalog_url) return;
274 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
276 // A record ID in the path indicates a request for the record-
278 if ($routeParams.record_id) {
279 url = url.replace(/advanced/, '/record/' + $scope.record_id);
282 $scope.catalog_url = url;
285 $scope.set_record_tab = function(tab) {
286 $scope.record_tab = tab;
295 $scope.detail_hold_record_id = $scope.record_id;
296 // refresh the holds grid
302 $scope.set_default_record_tab = function() {
303 egCore.hatch.setLocalItem(
304 'eg.cat.default_record_tab', $scope.record_tab);
308 if ($scope.record_id) {
309 var default_tab = egCore.hatch.getLocalItem( 'eg.cat.default_record_tab' );
310 tab = $routeParams.record_tab || default_tab || 'catalog';
312 tab = $routeParams.record_tab || 'catalog';
314 $scope.set_record_tab(tab);