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'])
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 // create some catalog page-specific mappings
26 $routeProvider.when('/cat/catalog/record/:record_id', {
27 templateUrl: './cat/catalog/t_catalog',
28 controller: 'CatalogCtrl',
32 // create some catalog page-specific mappings
33 $routeProvider.when('/cat/catalog/record/:record_id/:record_tab', {
34 templateUrl: './cat/catalog/t_catalog',
35 controller: 'CatalogCtrl',
39 $routeProvider.otherwise({redirectTo : '/cat/catalog/index'});
45 .controller('CatalogCtrl',
46 ['$scope','$routeParams','$location','$q','egCore','egHolds',
47 'egGridDataProvider','egHoldGridActions',
48 function($scope , $routeParams , $location , $q , egCore , egHolds,
49 egGridDataProvider , egHoldGridActions) {
51 // set record ID on page load if available...
52 $scope.record_id = $routeParams.record_id;
54 // Set the "last bib" cookie, if we have that
56 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
58 // also set it when the iframe changes to a new record
59 $scope.handle_page = function(url) {
61 if (!url || url == 'about:blank') {
62 // nothing loaded. If we already have a record ID, leave it.
66 var match = url.match(/\/+opac\/+record\/+(\d+)/);
68 $scope.record_id = match[1];
69 egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
71 // force the record_id to show up in the page.
72 // not sure why a $digest isn't occuring here.
73 try { $scope.$apply() } catch(E) {}
75 delete $scope.record_id;
79 // xulG catalog handlers
82 // ------------------------------------------------------------------
84 var provider = egGridDataProvider.instance({});
85 $scope.hold_grid_data_provider = provider;
86 $scope.grid_actions = egHoldGridActions;
87 $scope.hold_grid_controls = {};
89 var hold_ids = []; // current list of holds
90 function fetchHolds(offset, count) {
91 var ids = hold_ids.slice(offset, offset + count);
92 return egHolds.fetch_holds(ids).then(null, null,
99 provider.get = function(offset, count) {
100 if ($scope.record_tab != 'holds') return $q.when();
101 var deferred = $q.defer();
102 hold_ids = []; // no caching ATM
107 'open-ils.circ.holds.retrieve_all_from_title',
108 egCore.auth.token(), $scope.record_id,
109 {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
111 function(hold_data) {
112 angular.forEach(hold_data, function(list, type) {
113 hold_ids = hold_ids.concat(list);
115 fetchHolds(offset, count).then(
116 deferred.resolve, null, deferred.notify);
120 return deferred.promise;
123 $scope.detail_view = function(action, user_data, items) {
125 $scope.detail_hold_id = h.hold.id();
129 $scope.list_view = function(items) {
130 $scope.detail_hold_id = null;
133 // refresh the list of record holds when the pickup lib is changed.
134 $scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
135 $scope.pickup_ou_changed = function(org) {
136 $scope.pickup_ou = org;
140 $scope.print_holds = function() {
142 angular.forEach($scope.hold_grid_controls.allItems(), function(item) {
144 hold : egCore.idl.toHash(item.hold),
145 patron_last : item.patron_last,
146 patron_alias : item.patron_alias,
147 patron_barcode : item.patron_barcode,
148 copy : egCore.idl.toHash(item.copy),
149 volume : egCore.idl.toHash(item.volume),
150 title : item.mvr.title(),
151 author : item.mvr.author()
157 template : 'holds_for_bib',
158 scope : {holds : holds}
162 $scope.mark_hold_transfer_dest = function() {
163 egCore.hatch.setLocalItem(
164 'eg.circ.hold.title_transfer_target', $scope.record_id);
167 // UI presents this option as "all holds"
168 $scope.transfer_holds_to_marked = function() {
169 var hold_ids = $scope.hold_grid_controls.allItems().map(
170 function(hold_data) {return hold_data.hold.id()});
171 egHolds.transfer_to_marked_title(hold_ids);
174 // ------------------------------------------------------------------
175 // Initialize the selected tab
177 function init_cat_url() {
178 // Set the initial catalog URL. This only happens once.
179 // The URL is otherwise generated through user navigation.
180 if ($scope.catalog_url) return;
182 var url = $location.absUrl().replace(/\/staff.*/, '/opac/advanced');
184 // A record ID in the path indicates a request for the record-
186 if ($routeParams.record_id) {
187 url = url.replace(/advanced/, '/record/' + $scope.record_id);
190 $scope.catalog_url = url;
193 $scope.set_record_tab = function(tab) {
194 $scope.record_tab = tab;
203 $scope.detail_hold_record_id = $scope.record_id;
204 // refresh the holds grid
210 var tab = $routeParams.record_tab || 'catalog';
211 $scope.set_record_tab(tab);