Silence websockets install echo
[sitka/sitka-tools.git] / overdrive-eg-opac / build / od_data.js
CommitLineData
7c653aa3
JD
1// Generated by CoffeeScript 1.8.0
2var __hasProp = {}.hasOwnProperty,
3 __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
4
5define(['lodash', 'moment'], function(_, M) {
6 var Availability, Checkouts, Holds, Interests, Metadata, U;
7 U = (function() {
8 function U(x) {
9 var t;
10 if (!x) {
11 return;
12 }
13 t = this;
14 __extends(t, x);
15 return;
16 }
17
18 U.prototype.momentize = function(date, unit) {
19 switch (arguments.length) {
20 case 1:
21 if (date) {
22 return M(date.replace(/Z$/, '-0400'));
23 } else {
24 return M();
25 }
26 break;
27 case 2:
28 if (date) {
29 return M().add(date, unit);
30 } else {
31 return M();
32 }
33 break;
34 default:
35 return M();
36 }
37 };
38
39 U.prototype.proxy = function(x) {
40 var y;
41 if (!x) {
42 return;
43 }
44 y = x;
45 y = y.replace('https://', '//');
46 y = y.replace('http://', '//');
47 y = y.replace('//oauth-patron.overdrive.com', '/od/oauth-patron');
48 y = y.replace('//oauth.overdrive.com', '/od/oauth');
49 y = y.replace('//patron.api.overdrive.com', '/od/api-patron');
50 y = y.replace('//api.overdrive.com', '/od/api');
51 y = y.replace('//images.contentreserve.com', '/od/images');
52 y = y.replace('//fulfill.contentreserve.com', '/od/fulfill');
53 return y;
54 };
55
56 U.prototype.proxies = function(x) {
57 var l, n, v;
58 for (n in x) {
59 v = x[n];
60 if (l = v.href) {
61 v.href = this.proxy(l);
62 }
63 }
64 return x;
65 };
66
67 return U;
68
69 })();
70 Metadata = (function(_super) {
71 __extends(Metadata, _super);
72
73 function Metadata(x) {
74 var v;
75 Metadata.__super__.constructor.call(this, x);
76 this.id = this.id.toUpperCase();
77 this.author = ((function() {
78 var _i, _len, _ref, _results;
79 _ref = this.creators;
80 _results = [];
81 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
82 v = _ref[_i];
83 if (v.role === 'Author') {
84 _results.push(v.name);
85 }
86 }
87 return _results;
88 }).call(this))[0] || '';
89 this.proxies(this.images);
90 return;
91 }
92
93 return Metadata;
94
95 })(U);
96 Availability = (function(_super) {
97 __extends(Availability, _super);
98
99 function Availability(x, email_address) {
100 var _ref;
101 Availability.__super__.constructor.call(this, x);
102 this.zero();
103 if ((_ref = this.actions) != null ? _ref.hold : void 0) {
104 this.hold(email_address);
105 }
106 if (this.actions != null) {
107 this.proxies(this.actions);
108 }
109 this.action_formats();
110 return this;
111 }
112
113 Availability.prototype.zero = function() {
114 if (!this.copiesOwned) {
115 this.copiesOwned = 0;
116 }
117 if (!this.copiesAvailable) {
118 this.copiesAvailable = 0;
119 }
120 if (!this.numberOfHolds) {
121 this.numberOfHolds = 0;
122 }
123 return this;
124 };
125
126 Availability.prototype.hold = function(email_address) {
127 _.where(this.actions.hold.fields, {
128 name: 'reserveId'
129 })[0].value = this.id;
130 if (email_address) {
131 _.where(this.actions.hold.fields, {
132 name: 'emailAddress'
133 })[0].value = email_address;
134 }
135 return this;
136 };
137
138 Availability.prototype.action_formats = function() {
139 var v, x, xs, _i, _len, _ref, _ref1;
140 xs = (_ref = this.actions) != null ? (_ref1 = _ref.checkout) != null ? _ref1.fields : void 0 : void 0;
141 if (!((xs != null ? xs.length : void 0) > 0)) {
142 return this;
143 }
144 for (_i = 0, _len = xs.length; _i < _len; _i++) {
145 x = xs[_i];
146 if (x.name === 'formatType') {
147 break;
148 }
149 }
150 if (!(x.options.length > 0)) {
151 return this;
152 }
153 this.formats = (function() {
154 var _j, _len1, _ref2, _results;
155 _ref2 = x.options;
156 _results = [];
157 for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
158 v = _ref2[_j];
159 _results.push({
160 id: v,
161 name: ''
162 });
163 }
164 return _results;
165 })();
166 return this;
167 };
168
169 return Availability;
170
171 })(U);
172 Holds = (function(_super) {
173 __extends(Holds, _super);
174
175 function Holds(x) {
176 Holds.__super__.constructor.call(this, x);
177 this.add().remove().proxy_urls().moments().count().sort();
178 return;
179 }
180
181 Holds.prototype.add = function() {
182 if (this.holds === void 0) {
183 this.holds = [];
184 }
185 return this;
186 };
187
188 Holds.prototype.remove = function() {
189 var x, _i, _len, _ref;
190 _ref = this.holds;
191 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
192 x = _ref[_i];
193 if (!x.holdSuspension) {
194 delete x.actions.releaseSuspension;
195 }
196 }
197 return this;
198 };
199
200 Holds.prototype.proxy_urls = function() {
201 var n, v, _i, _len, _ref;
202 _ref = this.holds;
203 for (n = _i = 0, _len = _ref.length; _i < _len; n = ++_i) {
204 v = _ref[n];
205 this.proxies(v.actions);
206 }
207 return this;
208 };
209
210 Holds.prototype.moments = function() {
211 var x, _i, _len, _ref;
212 _ref = this.holds;
213 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
214 x = _ref[_i];
215 x.holdPlacedDate = this.momentize(x.holdPlacedDate);
216 x.holdExpires = this.momentize(x.holdExpires);
217 if (x.holdSuspension) {
218 x.holdSuspension.numberOfDays = this.momentize(x.holdSuspension.numberOfDays, 'days');
219 }
220 }
221 return this;
222 };
223
224 Holds.prototype.count = function() {
225 this.ready = _.countBy(this.holds, function(x) {
226 if (x.actions.checkout) {
227 return 'forCheckout';
228 } else {
229 return 'other';
230 }
231 });
232 if (!this.ready.forCheckout) {
233 this.ready.forCheckout = 0;
234 }
235 return this;
236 };
237
238 Holds.prototype.sort = function() {
239 this.holds = _(this.holds).sortBy(['holdListPosition', 'holdPlacedDate']).sortBy(function(x) {
240 return x.actions.checkout;
241 }).value();
242 return this;
243 };
244
245 return Holds;
246
247 })(U);
248 Checkouts = (function(_super) {
249 __extends(Checkouts, _super);
250
251 function Checkouts(x) {
252 Checkouts.__super__.constructor.call(this, x);
253 this.add().proxy_urls().moments().sort();
254 return;
255 }
256
257 Checkouts.prototype.add = function() {
258 if (this.checkouts === void 0) {
259 this.checkouts = [];
260 }
261 return this;
262 };
263
264 Checkouts.prototype.proxy_urls = function() {
265 var x, y, _i, _j, _len, _len1, _ref, _ref1;
266 _ref = this.checkouts;
267 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
268 x = _ref[_i];
269 this.proxies(x.actions);
270 if (x.formats === void 0) {
271 x.formats = [];
272 }
273 _ref1 = x.formats;
274 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
275 y = _ref1[_j];
276 this.proxies(y.linkTemplates);
277 }
278 }
279 return this;
280 };
281
282 Checkouts.prototype.moments = function() {
283 var x, _i, _len, _ref;
284 _ref = this.checkouts;
285 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
286 x = _ref[_i];
287 x.expires = this.momentize(x.expires);
288 }
289 return this;
290 };
291
292 Checkouts.prototype.sort = function() {
293 this.checkouts = _.sortBy(this.checkouts, 'expires');
294 return this;
295 };
296
297 return Checkouts;
298
299 })(U);
300 Interests = (function() {
301 function Interests(h, c) {
302 return {
303 nHolds: h.totalItems,
304 nHoldsReady: h.ready.forCheckout,
305 nCheckouts: c.totalItems,
306 nCheckoutsReady: c.totalCheckouts,
307 ofHolds: h.holds,
308 ofCheckouts: c.checkouts,
309 byID: (function(hs, cs) {
310 var byID, n, v, _i, _j, _len, _len1;
311 byID = {};
312 for (n = _i = 0, _len = hs.length; _i < _len; n = ++_i) {
313 v = hs[n];
314 v.type = 'hold';
315 byID[v.reserveId] = v;
316 }
317 for (n = _j = 0, _len1 = cs.length; _j < _len1; n = ++_j) {
318 v = cs[n];
319 v.type = 'checkout';
320 byID[v.reserveId] = v;
321 }
322 return byID;
323 })(h.holds, c.checkouts)
324 };
325 }
326
327 return Interests;
328
329 })();
330 return {
331 Metadata: Metadata,
332 Availability: Availability,
333 Holds: Holds,
334 Checkouts: Checkouts,
335 Interests: Interests
336 };
337});