Silence websockets install echo
[sitka/sitka-tools.git] / overdrive-eg-opac / build / overdrive.js
CommitLineData
7c653aa3
JD
1// Generated by CoffeeScript 1.8.0
2var __hasProp = {}.hasOwnProperty;
3
4require(['jquery-noconflict', 'lodash', 'cookies', 'od_api', 'od_config', 'od_pages_opac', 'od_pages_myopac', 'od_action'], function($, _, C, od, config) {
5 var failed, log_page, logged_in, notify, page_name, reload_page, replace_page, routes, search_params;
6 logged_in = false;
7 log_page = function() {
8 return console.log(window.location.pathname);
9 };
10 notify = function(what) {
11 return console.log("" + what + " is in progress");
12 };
13 failed = function(what) {
14 return console.log("" + what + " failed");
15 };
16 reload_page = function() {
17 return window.location.reload(true);
18 };
19 replace_page = function(href) {
20 return window.location.replace(href);
21 };
22 search_params = function(p) {
23 var o, x, xs, _ref, _ref1, _ref2;
24 o = (xs = (_ref = decodeURIComponent(window.location.search)) != null ? (_ref1 = _ref.split('?')) != null ? (_ref2 = _ref1[1]) != null ? _ref2.split(/&|;/) : void 0 : void 0 : void 0) ? _.zipObject((function() {
25 var _i, _len, _results;
26 _results = [];
27 for (_i = 0, _len = xs.length; _i < _len; _i++) {
28 x = xs[_i];
29 _results.push(x.replace(/\+/g, ' ').split('='));
30 }
31 return _results;
32 })()) : {};
33 if (arguments.length === 1) {
34 return o[p] || o.hasOwnProperty(p);
35 } else {
36 return o;
37 }
38 };
39 page_name = function() {
40 var xs;
41 xs = window.location.pathname.match(/eg\/opac\/(.+)/);
42 if (xs) {
43 return xs[1].replace(/\/\d+/, '');
44 } else {
45 return '';
46 }
47 };
48 routes = {
49 handle: function(p) {
50 var n, v, _results;
51 if (p == null) {
52 p = window.location.pathname;
53 }
54 _results = [];
55 for (n in this) {
56 if (!__hasProp.call(this, n)) continue;
57 v = this[n];
58 if (n !== 'handle') {
59 if ((new RegExp(n)).test(p)) {
60 _results.push(v());
61 } else {
62 _results.push(void 0);
63 }
64 }
65 }
66 return _results;
67 },
68 'eg\/opac': function() {
69 var $dash;
70 $dash = $('#dash_wrapper')._dashboard();
71 return od.$.on({
72 'od.interests': function(ev, x) {
73 return $dash._dashboard({
74 ncheckouts: x.nCheckouts,
75 nholds: x.nHolds,
76 nholdsready: x.nHoldsReady
77 });
78 },
79 'od.hold.delete': function() {
80 return $dash._dashboard({
81 nholds: -1
82 });
83 },
84 'od.checkout.delete': function() {
85 return $dash._dashboard({
86 ncheckouts: -1
87 });
88 },
89 'od.logout': function(ev, x) {
90 if (x === 'od') {
91 if (logged_in) {
92 return window.location.replace('/eg/opac/logout');
93 }
94 }
95 }
96 });
97 },
98 'opac\/myopac': function(this_page) {
99 if (this_page == null) {
100 this_page = page_name();
101 }
102 $('#acct_holds_tabs, #acct_checked_tabs')._etabs(this_page, search_params('e_items'));
103 $('#tab_holds_history, #tab_circs_history')._tab_history();
104 },
105 'opac\/home': function() {
106 if (!logged_in) {
107 return od.$.triggerHandler('od.logout', 'eg');
108 }
109 },
110 'opac\/login': function() {
111 return $('form', '#login-form-box').one('submit', function() {
112 return od.login({
113 username: $('[name=username]').val(),
114 password: $('[name=password]').val()
115 });
116 });
117 },
118 'myopac\/main': function($table) {
119 if ($table == null) {
120 $table = $('.acct_sum_table');
121 }
122 if (!$table.length) {
123 return;
124 }
125 $table._account_summary();
126 return od.$.on('od.interests', function(ev, x) {
127 return $table._account_summary({
128 n_checkouts: x.nCheckouts,
129 n_holds: x.nHolds,
130 n_ready: x.nHoldsReady
131 });
132 });
133 },
134 'myopac\/prefs': function() {
135 var $tr, bc, em, hl;
136 $tr = $('#myopac_summary_tbody > tr');
137 em = $tr.eq(6).find('td').eq(1).text();
138 bc = $tr.eq(7).find('td').eq(1).text();
139 hl = $tr.eq(8).find('td').eq(1).text();
140 return od.$.triggerHandler('od.prefs', {
141 email_address: em,
142 barcode: bc,
143 home_library: hl
144 });
145 },
146 'opac\/results': function(interested) {
147 var hrefs, ids, productbaseURL, _i, _len, _ref;
148 if (interested == null) {
149 interested = {};
150 }
151 hrefs = [];
152 _ref = config.productbaseURLs;
153 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
154 productbaseURL = _ref[_i];
155 hrefs.push('a[href*="' + productbaseURL + '"]');
156 }
157 ids = $(hrefs.join(',')).closest('.result_table_row')._results();
158 if ((ids != null ? ids.length : void 0) === 0) {
159 return;
160 }
161 return od.$.on({
162 'od.interests': function(ev, x) {
163 var id, _j, _len1;
164 for (_j = 0, _len1 = ids.length; _j < _len1; _j++) {
165 id = ids[_j];
166 od.apiAvailability({
167 id: id
168 });
169 if (!logged_in) {
170 od.apiMetadata({
171 id: id
172 });
173 }
174 }
175 return interested = x.byID;
176 },
177 'od.metadata': function(ev, x) {
178 return $("#" + x.id)._results_meta(x);
179 },
180 'od.availability': function(ev, x) {
181 var _ref1;
182 $("#" + x.id)._results_avail(x)._replace_place_hold_link(x, (_ref1 = interested[x.id]) != null ? _ref1.type : void 0);
183 if (logged_in) {
184 if (x.available) {
185 return $("#" + x.id)._results_meta(x);
186 } else {
187 return od.apiMetadata({
188 id: x.id
189 });
190 }
191 }
192 }
193 });
194 },
195 'opac\/record': function(interested) {
196 var id;
197 if (interested == null) {
198 interested = {};
199 }
200 if (!(id = $('div.rdetail_uris')._record())) {
201 return;
202 }
203 return od.$.on({
204 'od.interests': function(ev, x) {
205 if (!logged_in) {
206 od.apiMetadata({
207 id: id
208 });
209 }
210 od.apiAvailability({
211 id: id
212 });
213 return interested = x.byID;
214 },
215 'od.metadata': function(ev, x) {
216 return $("#" + x.id)._record_meta(x);
217 },
218 'od.availability': function(ev, x) {
219 var _ref;
220 $("#" + x.id)._record_avail(x);
221 $('#rdetail_actions_div')._replace_place_hold_link(x, (_ref = interested[x.id]) != null ? _ref.type : void 0);
222 if (logged_in) {
223 if (x.available) {
224 return $("#" + x.id)._record_meta(x);
225 } else {
226 return od.apiMetadata({
227 id: x.id
228 });
229 }
230 }
231 }
232 });
233 },
234 'opac\/place_hold': function(id, interested) {
235 var $div;
236 if (interested == null) {
237 interested = {};
238 }
239 if (!id) {
240 return;
241 }
242 $('#myopac_holds_div')._replace_title('Place E-Item on Hold');
243 $('#myopac_checked_div')._replace_title('Check out E-Item');
244 $('#holds_main, #checked_main, .warning_box').remove();
245 $div = $('<div id="#holds_main">')._holds_main()._holdings_row(id).appendTo($('#myopac_holds_div, #myopac_checked_div'));
246 return od.$.on({
247 'od.interests': function(ev, x) {
248 interested = x.byID;
249 return $.when(od.apiMetadata({
250 id: id
251 }), od.apiAvailability({
252 id: id
253 })).then(function(x, y) {
254 var _ref;
255 if ((_ref = interested[y.id]) != null ? _ref.type : void 0) {
256 return window.history.go(-2);
257 } else {
258 $("#" + x.id)._row_meta(x, 'thumbnail', 'title', 'author');
259 $("#" + x.id)._row_meta((y.available ? y : x), 'formats');
260 return $("#" + y.id)._holdings_row_avail(y).find('.opac-button.hold, .opac-button.checkout').focus().end();
261 }
262 });
263 }
264 });
265 },
266 'myopac\/holds': function() {
267 var $div, $holds_div, id;
268 if (id = search_params('interested')) {
269 return routes['opac\/place_hold'](id);
270 }
271 if (!search_params('e_items')) {
272 $('.warning_box').text($('.warning_box').text().replace(' holds', ' physical holds'));
273 return;
274 }
275 if (!($holds_div = $('#myopac_holds_div')).length) {
276 return;
277 }
278 $holds_div._replace_title('Current E-Items on Hold');
279 $('#holds_main, .warning_box').remove();
280 $div = $('<div id="#holds_main">')._holds_main().appendTo($holds_div);
281 return od.$.on({
282 'od.interests': function(ev, x) {
283 var holds, ids, _i, _len, _results;
284 holds = x != null ? x.ofHolds : void 0;
285 if (search_params('available')) {
286 holds = _.filter(holds, function(x) {
287 return x.actions.checkout;
288 });
289 }
290 ids = $div._holds_rows(holds);
291 _results = [];
292 for (_i = 0, _len = ids.length; _i < _len; _i++) {
293 id = ids[_i];
294 od.apiMetadata({
295 id: id
296 });
297 _results.push(od.apiAvailability({
298 id: id
299 }));
300 }
301 return _results;
302 },
303 'od.metadata': function(ev, x) {
304 return $("#" + x.id)._row_meta(x, 'thumbnail', 'title', 'author', 'formats');
305 },
306 'od.availability': function(ev, x) {
307 return $("#" + x.id)._holds_row_avail(x);
308 },
309 'od.hold.update': function(ev, x) {
310 x = x.holds[0];
311 return $("#" + x.reserveId)._holds_row(x);
312 },
313 'od.hold.delete': function(ev, id) {
314 return $("#" + id).remove();
315 }
316 });
317 },
318 'myopac\/circs': function() {
319 var $checked_div, $div, code, id;
320 if (id = search_params('interested')) {
321 return routes['opac\/place_hold'](id);
322 }
323 if (code = search_params('read_error')) {
324 $('<div>')._notify('Error message', "<p>Could not get content</p>\n<div>Error code: " + code + "</div>\n<div>Reserve ID: " + (search_params('reserveid')) + "</div>");
325 } else if (code = search_params('ErrorCode')) {
326 $('<div>')._notify('Error message', "<p>" + (search_params('ErrorDescription')) + "</p>\n<div>Error code: " + code + "</div>\n<div>Details: " + (search_params('ErrorDetails')) + "</div>");
327 }
328 if (!search_params('e_items')) {
329 $('.warning_box').text($('.warning_box').text().replace(' items', ' physical items'));
330 return;
331 }
332 if (!($checked_div = $('#myopac_checked_div')).length) {
333 return;
334 }
335 $checked_div._replace_title('Current E-Items Checked Out');
336 $('#checked_main, .warning_box').remove();
337 $div = $('<div id="#checked_main">')._checkouts_main().appendTo($checked_div);
338 return od.$.on({
339 'od.interests': function(ev, x) {
340 var ids, _i, _len, _results;
341 ids = $div._checkouts_rows(x != null ? x.ofCheckouts : void 0);
342 _results = [];
343 for (_i = 0, _len = ids.length; _i < _len; _i++) {
344 id = ids[_i];
345 _results.push(od.apiMetadata({
346 id: id
347 }));
348 }
349 return _results;
350 },
351 'od.metadata': function(ev, x) {
352 return $("#" + x.id)._row_meta(x, 'thumbnail', 'title', 'author');
353 },
354 'od.checkout.update': function(ev, x) {
355 x = x.checkouts[0];
356 return $("#" + x.reserveId)._row_checkout(x);
357 },
358 'od.checkout.delete': function(ev, id) {
359 return $("#" + id).remove();
360 }
361 });
362 }
363 };
364 $(function() {
365 if (window.IAMXUL) {
366 return;
367 }
368 if (config.blacklisted()) {
369 return;
370 }
371 logged_in = Boolean(C('eg_loggedin') || window.IAMXUL);
372 if (_.every(routes.handle(), function(r) {
373 return r === void 0;
374 })) {
375 return;
376 }
377 od.apiLibraryInfo().then(function() {
378 var interests;
379 if (logged_in) {
380 return od.login().then(od.apiInterestsGet);
381 } else {
382 interests = {
383 byID: {}
384 };
385 od.$.triggerHandler('od.interests', interests);
386 return interests;
387 }
388 });
389 });
390});