hope 0.1.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. data/Gemfile +11 -0
  2. data/LICENSE.txt +20 -0
  3. data/README.rdoc +19 -0
  4. data/bin/hope-web +16 -0
  5. data/hope.gemspec +34 -0
  6. data/lib/hope.rb +103 -0
  7. data/lib/hope/core_ext/object.rb +78 -0
  8. data/lib/hope/engine.rb +189 -0
  9. data/lib/hope/event_type.rb +22 -0
  10. data/lib/hope/jars/antlr-runtime-3.2.jar +0 -0
  11. data/lib/hope/jars/cglib-nodep-2.2.jar +0 -0
  12. data/lib/hope/jars/commons-logging-1.1.1.jar +0 -0
  13. data/lib/hope/jars/esper-4.3.0.jar +0 -0
  14. data/lib/hope/jars/log4j-1.2.16.jar +0 -0
  15. data/lib/hope/jars/msgpack-0.6.0-devel.jar +0 -0
  16. data/lib/hope/listener/base.rb +40 -0
  17. data/lib/hope/server.rb +43 -0
  18. data/lib/hope/server/app.rb +40 -0
  19. data/lib/hope/server/public/css/Aristo/images/bg_fallback.png +0 -0
  20. data/lib/hope/server/public/css/Aristo/images/icon_sprite.png +0 -0
  21. data/lib/hope/server/public/css/Aristo/images/progress_bar.gif +0 -0
  22. data/lib/hope/server/public/css/Aristo/images/slider_handles.png +0 -0
  23. data/lib/hope/server/public/css/Aristo/images/ui-icons_222222_256x240.png +0 -0
  24. data/lib/hope/server/public/css/Aristo/images/ui-icons_454545_256x240.png +0 -0
  25. data/lib/hope/server/public/css/Aristo/jquery-ui-1.8.7.custom.css +703 -0
  26. data/lib/hope/server/public/css/hope.css +235 -0
  27. data/lib/hope/server/public/favicon.ico +0 -0
  28. data/lib/hope/server/public/hope.js +995 -0
  29. data/lib/hope/server/public/js/backbone-0.3.3.js +1011 -0
  30. data/lib/hope/server/public/js/backbone-0.5.1.js +1149 -0
  31. data/lib/hope/server/public/js/hope.js +993 -0
  32. data/lib/hope/server/public/js/inflection.js +656 -0
  33. data/lib/hope/server/public/js/jquery-1.6.1.js +8936 -0
  34. data/lib/hope/server/public/js/jquery-ui-1.8.14.custom.min.js +789 -0
  35. data/lib/hope/server/public/js/underscore-1.1.6.js +807 -0
  36. data/lib/hope/server/resources/engine.rb +60 -0
  37. data/lib/hope/server/resources/source.rb +22 -0
  38. data/lib/hope/server/resources/statement.rb +62 -0
  39. data/lib/hope/server/views/app.erb +24 -0
  40. data/lib/hope/source.rb +20 -0
  41. data/lib/hope/source/base.rb +30 -0
  42. data/lib/hope/source/sub.rb +24 -0
  43. data/lib/hope/source/twitter.rb +123 -0
  44. data/lib/hope/statement.rb +73 -0
  45. data/lib/hope/version.rb +3 -0
  46. metadata +241 -0
@@ -0,0 +1,993 @@
1
+ var Hope; window.Hope = Hope = {};Hope.Templates = {};
2
+ Hope.Templates['hope'] = function(__obj) {
3
+ if (!__obj) __obj = {};
4
+ var __out = [], __capture = function(callback) {
5
+ var out = __out, result;
6
+ __out = [];
7
+ callback.call(this);
8
+ result = __out.join('');
9
+ __out = out;
10
+ return __safe(result);
11
+ }, __sanitize = function(value) {
12
+ if (value && value.ecoSafe) {
13
+ return value;
14
+ } else if (typeof value !== 'undefined' && value != null) {
15
+ return __escape(value);
16
+ } else {
17
+ return '';
18
+ }
19
+ }, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
20
+ __safe = __obj.safe = function(value) {
21
+ if (value && value.ecoSafe) {
22
+ return value;
23
+ } else {
24
+ if (!(typeof value !== 'undefined' && value != null)) value = '';
25
+ var result = new String(value);
26
+ result.ecoSafe = true;
27
+ return result;
28
+ }
29
+ };
30
+ if (!__escape) {
31
+ __escape = __obj.escape = function(value) {
32
+ return ('' + value)
33
+ .replace(/&/g, '&')
34
+ .replace(/</g, '&lt;')
35
+ .replace(/>/g, '&gt;')
36
+ .replace(/"/g, '&quot;');
37
+ };
38
+ }
39
+ (function() {
40
+ (function() {
41
+ __out.push('<div id="dialog" style="display:none"></div>\n\n<div id="layout">\n <div id="header" class="header">\n <span class="logo">Hope !</span>\n </div>\n\n <div id="main" class="main">\n <div class="side">\n <h2>Engines</h2>\n <div id="engines_list" class="side_content"></div>\n \n <h2>Sources</h2>\n <div id="sources_list" class="side_content"></div>\n </div>\n <div class="current current_engine"></div>\n </div>\n</div>\n\n<div id="footer" class="footer">\n ...\n</div>');
42
+ }).call(this);
43
+
44
+ }).call(__obj);
45
+ __obj.safe = __objSafe, __obj.escape = __escape;
46
+ return __out.join('');
47
+ };
48
+
49
+
50
+ Hope.Templates['engines/list'] = function(__obj) {
51
+ if (!__obj) __obj = {};
52
+ var __out = [], __capture = function(callback) {
53
+ var out = __out, result;
54
+ __out = [];
55
+ callback.call(this);
56
+ result = __out.join('');
57
+ __out = out;
58
+ return __safe(result);
59
+ }, __sanitize = function(value) {
60
+ if (value && value.ecoSafe) {
61
+ return value;
62
+ } else if (typeof value !== 'undefined' && value != null) {
63
+ return __escape(value);
64
+ } else {
65
+ return '';
66
+ }
67
+ }, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
68
+ __safe = __obj.safe = function(value) {
69
+ if (value && value.ecoSafe) {
70
+ return value;
71
+ } else {
72
+ if (!(typeof value !== 'undefined' && value != null)) value = '';
73
+ var result = new String(value);
74
+ result.ecoSafe = true;
75
+ return result;
76
+ }
77
+ };
78
+ if (!__escape) {
79
+ __escape = __obj.escape = function(value) {
80
+ return ('' + value)
81
+ .replace(/&/g, '&amp;')
82
+ .replace(/</g, '&lt;')
83
+ .replace(/>/g, '&gt;')
84
+ .replace(/"/g, '&quot;');
85
+ };
86
+ }
87
+ (function() {
88
+ (function() {
89
+ __out.push(__sanitize(this.engine.id));
90
+ __out.push('\n');
91
+ }).call(this);
92
+
93
+ }).call(__obj);
94
+ __obj.safe = __objSafe, __obj.escape = __escape;
95
+ return __out.join('');
96
+ };
97
+
98
+
99
+ Hope.Templates['engines/show'] = function(__obj) {
100
+ if (!__obj) __obj = {};
101
+ var __out = [], __capture = function(callback) {
102
+ var out = __out, result;
103
+ __out = [];
104
+ callback.call(this);
105
+ result = __out.join('');
106
+ __out = out;
107
+ return __safe(result);
108
+ }, __sanitize = function(value) {
109
+ if (value && value.ecoSafe) {
110
+ return value;
111
+ } else if (typeof value !== 'undefined' && value != null) {
112
+ return __escape(value);
113
+ } else {
114
+ return '';
115
+ }
116
+ }, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
117
+ __safe = __obj.safe = function(value) {
118
+ if (value && value.ecoSafe) {
119
+ return value;
120
+ } else {
121
+ if (!(typeof value !== 'undefined' && value != null)) value = '';
122
+ var result = new String(value);
123
+ result.ecoSafe = true;
124
+ return result;
125
+ }
126
+ };
127
+ if (!__escape) {
128
+ __escape = __obj.escape = function(value) {
129
+ return ('' + value)
130
+ .replace(/&/g, '&amp;')
131
+ .replace(/</g, '&lt;')
132
+ .replace(/>/g, '&gt;')
133
+ .replace(/"/g, '&quot;');
134
+ };
135
+ }
136
+ (function() {
137
+ (function() {
138
+ __out.push('<h1>Engine: ');
139
+ __out.push(__sanitize(this.engine.id));
140
+ __out.push('</h1>\n\n<button class="newStatement">Add Statement</button>\n\n\n<h2>Statements</h2>\n<table>\n <thead>\n <tr>\n <th>Id</th>\n <th>State</th>\n <th>Text</th>\n <th>Listeners</th>\n </tr>\n </thead>\n <tbody class="statements_list"></tbody>\n</table>\n\n');
141
+ }).call(this);
142
+
143
+ }).call(__obj);
144
+ __obj.safe = __objSafe, __obj.escape = __escape;
145
+ return __out.join('');
146
+ };
147
+
148
+
149
+ Hope.Templates['sources/list'] = function(__obj) {
150
+ if (!__obj) __obj = {};
151
+ var __out = [], __capture = function(callback) {
152
+ var out = __out, result;
153
+ __out = [];
154
+ callback.call(this);
155
+ result = __out.join('');
156
+ __out = out;
157
+ return __safe(result);
158
+ }, __sanitize = function(value) {
159
+ if (value && value.ecoSafe) {
160
+ return value;
161
+ } else if (typeof value !== 'undefined' && value != null) {
162
+ return __escape(value);
163
+ } else {
164
+ return '';
165
+ }
166
+ }, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
167
+ __safe = __obj.safe = function(value) {
168
+ if (value && value.ecoSafe) {
169
+ return value;
170
+ } else {
171
+ if (!(typeof value !== 'undefined' && value != null)) value = '';
172
+ var result = new String(value);
173
+ result.ecoSafe = true;
174
+ return result;
175
+ }
176
+ };
177
+ if (!__escape) {
178
+ __escape = __obj.escape = function(value) {
179
+ return ('' + value)
180
+ .replace(/&/g, '&amp;')
181
+ .replace(/</g, '&lt;')
182
+ .replace(/>/g, '&gt;')
183
+ .replace(/"/g, '&quot;');
184
+ };
185
+ }
186
+ (function() {
187
+ (function() {
188
+ __out.push(__sanitize(this.source.id));
189
+ __out.push('\n');
190
+ }).call(this);
191
+
192
+ }).call(__obj);
193
+ __obj.safe = __objSafe, __obj.escape = __escape;
194
+ return __out.join('');
195
+ };
196
+
197
+
198
+ Hope.Templates['sources/show'] = function(__obj) {
199
+ if (!__obj) __obj = {};
200
+ var __out = [], __capture = function(callback) {
201
+ var out = __out, result;
202
+ __out = [];
203
+ callback.call(this);
204
+ result = __out.join('');
205
+ __out = out;
206
+ return __safe(result);
207
+ }, __sanitize = function(value) {
208
+ if (value && value.ecoSafe) {
209
+ return value;
210
+ } else if (typeof value !== 'undefined' && value != null) {
211
+ return __escape(value);
212
+ } else {
213
+ return '';
214
+ }
215
+ }, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
216
+ __safe = __obj.safe = function(value) {
217
+ if (value && value.ecoSafe) {
218
+ return value;
219
+ } else {
220
+ if (!(typeof value !== 'undefined' && value != null)) value = '';
221
+ var result = new String(value);
222
+ result.ecoSafe = true;
223
+ return result;
224
+ }
225
+ };
226
+ if (!__escape) {
227
+ __escape = __obj.escape = function(value) {
228
+ return ('' + value)
229
+ .replace(/&/g, '&amp;')
230
+ .replace(/</g, '&lt;')
231
+ .replace(/>/g, '&gt;')
232
+ .replace(/"/g, '&quot;');
233
+ };
234
+ }
235
+ (function() {
236
+ (function() {
237
+ __out.push('<h1>Source: ');
238
+ __out.push(__sanitize(this.source.id));
239
+ __out.push('</h1>\n');
240
+ }).call(this);
241
+
242
+ }).call(__obj);
243
+ __obj.safe = __objSafe, __obj.escape = __escape;
244
+ return __out.join('');
245
+ };
246
+
247
+
248
+ Hope.Templates['statements/list'] = function(__obj) {
249
+ if (!__obj) __obj = {};
250
+ var __out = [], __capture = function(callback) {
251
+ var out = __out, result;
252
+ __out = [];
253
+ callback.call(this);
254
+ result = __out.join('');
255
+ __out = out;
256
+ return __safe(result);
257
+ }, __sanitize = function(value) {
258
+ if (value && value.ecoSafe) {
259
+ return value;
260
+ } else if (typeof value !== 'undefined' && value != null) {
261
+ return __escape(value);
262
+ } else {
263
+ return '';
264
+ }
265
+ }, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
266
+ __safe = __obj.safe = function(value) {
267
+ if (value && value.ecoSafe) {
268
+ return value;
269
+ } else {
270
+ if (!(typeof value !== 'undefined' && value != null)) value = '';
271
+ var result = new String(value);
272
+ result.ecoSafe = true;
273
+ return result;
274
+ }
275
+ };
276
+ if (!__escape) {
277
+ __escape = __obj.escape = function(value) {
278
+ return ('' + value)
279
+ .replace(/&/g, '&amp;')
280
+ .replace(/</g, '&lt;')
281
+ .replace(/>/g, '&gt;')
282
+ .replace(/"/g, '&quot;');
283
+ };
284
+ }
285
+ (function() {
286
+ (function() {
287
+ __out.push('<td>');
288
+ __out.push(__sanitize(this.statement.id));
289
+ __out.push('</td>\n<td>');
290
+ __out.push(__sanitize(this.statement.get('state')));
291
+ __out.push('</td>\n<td>');
292
+ __out.push(__sanitize(this.statement.get('text')));
293
+ __out.push('</td>\n<td>');
294
+ __out.push(__sanitize(_.map(this.statement.listeners.models, function(l) {
295
+ return l.get("name");
296
+ }).join(", ")));
297
+ __out.push('</td>\n<td>\n <button class=\'statement-start\'>START</button>\n <button class=\'statement-stop\'>STOP</button>\n <button class=\'statement-destroy\'>DELETE</button>\n</td>');
298
+ }).call(this);
299
+
300
+ }).call(__obj);
301
+ __obj.safe = __objSafe, __obj.escape = __escape;
302
+ return __out.join('');
303
+ };
304
+
305
+ (function() {
306
+ var DialogView, EditDialogView, Engine, EngineCollection, EngineListView, EngineView, FormHelpers, HopeRouter, HopeView, HopeWeb, Listener, ListenerCollection, Source, SourceCollection, SourceListView, SourceView, Statement, StatementCollection, StatementListView, StatementView;
307
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
308
+ for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
309
+ function ctor() { this.constructor = child; }
310
+ ctor.prototype = parent.prototype;
311
+ child.prototype = new ctor;
312
+ child.__super__ = parent.prototype;
313
+ return child;
314
+ }, __slice = Array.prototype.slice;
315
+ HopeWeb = (function() {
316
+ function HopeWeb(el) {
317
+ this.onReady = __bind(this.onReady, this); this.version = "0.0.1";
318
+ this.view = new HopeView({
319
+ el: $("#" + el),
320
+ app: this
321
+ });
322
+ if (window.location.hash.length === 0) {
323
+ window.location.hash = "/";
324
+ }
325
+ console.log("Calling bootstrap on Hope");
326
+ this.boostrap();
327
+ }
328
+ HopeWeb.prototype.boostrap = function() {
329
+ return $.get("/bootstrap", __bind(function(res) {
330
+ this.engines = new EngineCollection(res.engines);
331
+ this.sources = new SourceCollection(res.sources);
332
+ this.engines.bind("all", __bind(function(e, data) {
333
+ console.log("engines collection event... " + e, data);
334
+ return this.view.renderEnginesList();
335
+ }, this));
336
+ this.sources.bind("all", __bind(function(e, data) {
337
+ console.log("sources collection event... " + e, data);
338
+ return this.view.renderSourcesList();
339
+ }, this));
340
+ return this.onReady();
341
+ }, this));
342
+ };
343
+ HopeWeb.prototype.onReady = function() {
344
+ console.log("Hope ready !");
345
+ $("#loading").hide();
346
+ this.view.render();
347
+ $(this.view.el).show();
348
+ this.router = new HopeRouter({
349
+ app: this
350
+ });
351
+ return Backbone.history.start();
352
+ };
353
+ HopeWeb.prototype.addEngine = function(id) {
354
+ var e;
355
+ if (this.engines.get(id)) {
356
+ return false;
357
+ }
358
+ e = new Engine({
359
+ name: id
360
+ });
361
+ this.engines.create(e);
362
+ return e;
363
+ };
364
+ HopeWeb.prototype.addSource = function(name, type, opts) {
365
+ var s;
366
+ if (opts == null) {
367
+ opts = {};
368
+ }
369
+ if (this.sources.get(name)) {
370
+ return false;
371
+ }
372
+ s = new Source({
373
+ name: name,
374
+ type: type,
375
+ opts: opts
376
+ });
377
+ this.sources.create(s);
378
+ return s;
379
+ };
380
+ return HopeWeb;
381
+ })();
382
+ Hope.init = function(config) {
383
+ return new HopeWeb(config);
384
+ };
385
+ DialogView = (function() {
386
+ __extends(DialogView, Backbone.View);
387
+ function DialogView() {
388
+ this.close = __bind(this.close, this);
389
+ this.open = __bind(this.open, this);
390
+ this.buttons = __bind(this.buttons, this);
391
+ DialogView.__super__.constructor.apply(this, arguments);
392
+ }
393
+ DialogView.prototype.initialize = function() {
394
+ return $(this.el).dialog({
395
+ autoOpen: false,
396
+ minWidth: 1000
397
+ });
398
+ };
399
+ DialogView.prototype.render = function() {
400
+ return this;
401
+ };
402
+ DialogView.prototype.buttons = function() {
403
+ return _.extend({
404
+ "Save": this.saveChanges,
405
+ "Cancel": this.close
406
+ }, this.modelView.formButtons());
407
+ };
408
+ DialogView.prototype.open = function() {
409
+ this.render();
410
+ return $(this.el).dialog("open");
411
+ };
412
+ DialogView.prototype.close = function() {
413
+ return $(this.el).dialog('close');
414
+ };
415
+ return DialogView;
416
+ })();
417
+ EditDialogView = (function() {
418
+ __extends(EditDialogView, DialogView);
419
+ function EditDialogView() {
420
+ this.saveChanges = __bind(this.saveChanges, this);
421
+ this.onError = __bind(this.onError, this);
422
+ this.onSuccess = __bind(this.onSuccess, this);
423
+ this.open = __bind(this.open, this);
424
+ this.buttons = __bind(this.buttons, this);
425
+ this.render = __bind(this.render, this);
426
+ EditDialogView.__super__.constructor.apply(this, arguments);
427
+ }
428
+ EditDialogView.prototype.render = function() {
429
+ if (!(this.modelView && this.modelView.model)) {
430
+ return $(this.el).html("No model provided !");
431
+ }
432
+ this.isNew = this.modelView.model.isNew();
433
+ if (this.modelView) {
434
+ $(this.el).dialog("option", "title", this.modelView.model.id);
435
+ $(this.el).html("<div class='form_errors'></div><div class='form_container'>" + (this.modelView.renderForm()) + "</div>");
436
+ }
437
+ return this;
438
+ };
439
+ EditDialogView.prototype.buttons = function() {
440
+ return _.extend({
441
+ "Save": this.saveChanges,
442
+ "Cancel": this.close
443
+ }, this.modelView.formButtons());
444
+ };
445
+ EditDialogView.prototype.open = function() {
446
+ $(this.el).dialog("option", "buttons", this.buttons());
447
+ return EditDialogView.__super__.open.call(this);
448
+ };
449
+ EditDialogView.prototype.onSuccess = function() {
450
+ return this.close();
451
+ };
452
+ EditDialogView.prototype.onError = function(i, resp) {
453
+ var errorMessage;
454
+ errorMessage = JSON.parse(resp.responseText);
455
+ $(".form_errors").html("Error: " + errorMessage['error']);
456
+ $(".form_errors").show();
457
+ return $(this.el).dialog('widget').find('button').button('enable');
458
+ };
459
+ EditDialogView.prototype.saveChanges = function() {
460
+ var input, properties, _i, _len, _ref;
461
+ $(this.el).dialog('widget').find('button').button('disable');
462
+ properties = {};
463
+ _ref = this.el.find('input,textarea,select');
464
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
465
+ input = _ref[_i];
466
+ properties[input.name] = $(input).val();
467
+ }
468
+ if (this.isNew) {
469
+ this.modelView.model.collection.create(properties, {
470
+ success: this.onSuccess,
471
+ error: this.onError
472
+ });
473
+ } else {
474
+ this.modelView.model.save(properties, {
475
+ success: this.onSuccess,
476
+ error: this.onError
477
+ });
478
+ }
479
+ return false;
480
+ };
481
+ return EditDialogView;
482
+ })();
483
+ FormHelpers = (function() {
484
+ var input_tag, labelled_tag;
485
+ labelled_tag = function(name, label, markup) {
486
+ return "<p><label for=\"" + name + "\">" + (label || name) + "</label>" + markup + "</p>";
487
+ };
488
+ input_tag = function(type, name, value, label, opts) {
489
+ return labelled_tag(name, label, "<input type='" + (type || "text") + "' name='" + name + "' value='" + (value || "") + "' />");
490
+ };
491
+ return {
492
+ text_field: function(name, value, label, opts) {
493
+ return input_tag("text", name, value, label, opts);
494
+ },
495
+ password_field: function(name, value, label, opts) {
496
+ return input_tag("password", name, value, label, opts);
497
+ },
498
+ text_area: function(name, value, label, opts) {
499
+ return labelled_tag(name, label, "<textarea name=\"" + name + "\">" + (value || "") + "</textarea>");
500
+ },
501
+ select: function(name, value, values, label, html_opts) {
502
+ var option, option_values;
503
+ if (html_opts != null) {
504
+ html_opts;
505
+ } else {
506
+ html_opts = "";
507
+ };
508
+ if (_.isFunction(values)) {
509
+ values = values();
510
+ }
511
+ if (values) {
512
+ option_values = _.compact(_(values).map(function(ov) {
513
+ return ov.id || ov;
514
+ }));
515
+ }
516
+ if (option_values != null) {
517
+ option_values;
518
+ } else {
519
+ option_values = [];
520
+ };
521
+ option = function(val) {
522
+ var attrs, d, v;
523
+ attrs = [];
524
+ if (_.isArray(val)) {
525
+ d = val[0], v = val[1];
526
+ } else if (_.isString(val) || _.isNumber(val)) {
527
+ v = d = val;
528
+ } else if (val.id) {
529
+ v = d = val.id;
530
+ }
531
+ if (v && value) {
532
+ if ((_.isArray(value) && _.include(value, v.toString())) || v.toString() === value.toString()) {
533
+ attrs.push("selected='selected'");
534
+ }
535
+ }
536
+ return "<option value=\"" + v + "\" " + (attrs.join(" ")) + ">" + d + "</option>";
537
+ };
538
+ return labelled_tag(name, label, "<select name=\"" + name + "\" " + html_opts + ">" + (_.map(option_values, function(v) {
539
+ return option(v);
540
+ }).join("")) + "</select>");
541
+ }
542
+ };
543
+ })();
544
+ if (typeof TBone !== "undefined" && TBone !== null) {
545
+ TBone;
546
+ } else {
547
+ TBone = {};
548
+ };
549
+ TBone.View = (function() {
550
+ __extends(View, Backbone.View);
551
+ function View() {
552
+ View.__super__.constructor.apply(this, arguments);
553
+ }
554
+ View.prototype.tagName = 'div';
555
+ View.prototype.initialize = function(opts) {
556
+ _.bindAll(this, "render");
557
+ this.parent_el = opts.parent_el;
558
+ return this.model.bind("change", this.render);
559
+ };
560
+ View.prototype.formButtons = function() {
561
+ return {};
562
+ };
563
+ View.prototype.renderForm = function() {
564
+ var fieldsets, out;
565
+ if (_.isFunction(this.form_template)) {
566
+ return this.form_template({
567
+ model: this.model,
568
+ app: App
569
+ });
570
+ } else if (this.form) {
571
+ fieldsets = [];
572
+ if (_.isFunction(this.form)) {
573
+ fieldsets = fieldsets.concat(this.form.apply(this));
574
+ } else {
575
+ fieldsets = fieldsets.concat(this.form);
576
+ }
577
+ out = [];
578
+ _(fieldsets).each(__bind(function(fs) {
579
+ var fields, name;
580
+ name = fs[0], fields = fs[1];
581
+ out.push("<fieldset><legend>" + name + "</legend>");
582
+ _.map(fields, __bind(function(i) {
583
+ var k, v, _ref;
584
+ k = i[0], v = i[1];
585
+ return out.push((_ref = FormHelpers[v[0]]).call.apply(_ref, [this].concat(__slice.call([k, this.model.get(k)].concat(__slice.call(_.rest(v)))))));
586
+ }, this));
587
+ return out.push("</fieldset>");
588
+ }, this));
589
+ return out.join("\n");
590
+ } else {
591
+ return "Not available yet !";
592
+ }
593
+ };
594
+ View.prototype.select = function() {
595
+ return console.log("" + this.model + " Selected !");
596
+ };
597
+ View.prototype.edit = function() {
598
+ window.hope.view.edit_dialog.modelView = this;
599
+ return window.hope.view.edit_dialog.open();
600
+ };
601
+ View.prototype.render = function(tpl_name) {
602
+ var el_id, template, view_data;
603
+ if (tpl_name) {
604
+ template = Hope.Templates[tpl_name];
605
+ }
606
+ if (this.template) {
607
+ if (template != null) {
608
+ template;
609
+ } else {
610
+ template = Hope.Templates["" + (this.className.pluralize()) + "/" + this.template] || Hope.Templates[this.template];
611
+ };
612
+ }
613
+ if (template != null) {
614
+ template;
615
+ } else {
616
+ template = Hope.Templates["" + (this.className.pluralize()) + "/show"] || _.template("Missing template for " + this.className + "(" + this.model.id + ")");
617
+ };
618
+ el_id = "" + ([this.className, (this.template || "show").replace("/", "-")].join("-")) + "-" + this.model.cid;
619
+ if (this.parent_el && $("#" + el_id).length === 0) {
620
+ $(this.parent_el).append($(this.el));
621
+ }
622
+ $(this.el).attr("id", el_id);
623
+ $(this.el).addClass(this.className);
624
+ view_data = {};
625
+ view_data[this.className] = this.model;
626
+ $(this.el).html(template(view_data));
627
+ return this;
628
+ };
629
+ View.prototype.show = function() {
630
+ return $(this.el).show();
631
+ };
632
+ View.prototype.hide = function() {
633
+ return $(this.el).hide();
634
+ };
635
+ return View;
636
+ })();
637
+ Engine = (function() {
638
+ __extends(Engine, Backbone.Model);
639
+ function Engine() {
640
+ Engine.__super__.constructor.apply(this, arguments);
641
+ }
642
+ Engine.prototype.initialize = function() {
643
+ return this.statements = new StatementCollection(this.get("statements") || [], {
644
+ engine: this
645
+ });
646
+ };
647
+ Engine.prototype.addStatement = function(epl, id) {
648
+ return this.statements.create({
649
+ statement_id: id,
650
+ epl: epl
651
+ });
652
+ };
653
+ Engine.prototype.stop = function() {
654
+ return $.post([this.url(), "stop"].join("/"), __bind(function(res) {
655
+ return this.statements.fetch();
656
+ }, this));
657
+ };
658
+ Engine.prototype.start = function() {
659
+ return $.post([this.url(), "start"].join("/"), __bind(function(res) {
660
+ return this.statements.fetch();
661
+ }, this));
662
+ };
663
+ Engine.prototype.subscribe = function(srcName) {
664
+ return $.post([this.url(), "subscribe", srcName].join("/"), __bind(function(res) {
665
+ return this.set(res);
666
+ }, this));
667
+ };
668
+ Engine.prototype.unsubscribe = function(srcName) {
669
+ return $.post([this.url(), "unsubscribe", srcName].join("/"), __bind(function(res) {
670
+ return this.set(res);
671
+ }, this));
672
+ };
673
+ return Engine;
674
+ })();
675
+ Listener = (function() {
676
+ __extends(Listener, Backbone.Model);
677
+ function Listener() {
678
+ Listener.__super__.constructor.apply(this, arguments);
679
+ }
680
+ return Listener;
681
+ })();
682
+ Source = (function() {
683
+ __extends(Source, Backbone.Model);
684
+ function Source() {
685
+ Source.__super__.constructor.apply(this, arguments);
686
+ }
687
+ return Source;
688
+ })();
689
+ Statement = (function() {
690
+ __extends(Statement, Backbone.Model);
691
+ function Statement() {
692
+ Statement.__super__.constructor.apply(this, arguments);
693
+ }
694
+ Statement.prototype.initialize = function() {
695
+ return this.listeners = new ListenerCollection(this.get("listeners") || [], {
696
+ statement: this
697
+ });
698
+ };
699
+ Statement.prototype.stop = function(callback) {
700
+ return $.post([this.url(), "stop"].join("/"), __bind(function(res) {
701
+ this.set(res);
702
+ if (callback) {
703
+ return callback(res);
704
+ }
705
+ }, this));
706
+ };
707
+ Statement.prototype.start = function(callback) {
708
+ return $.post([this.url(), "start"].join("/"), __bind(function(res) {
709
+ this.set(res);
710
+ if (callback) {
711
+ return callback(res);
712
+ }
713
+ }, this));
714
+ };
715
+ Statement.prototype.addListener = function(name) {
716
+ var l;
717
+ l = new Listener({
718
+ name: name
719
+ });
720
+ this.listeners.create(l);
721
+ return l;
722
+ };
723
+ return Statement;
724
+ })();
725
+ EngineCollection = (function() {
726
+ __extends(EngineCollection, Backbone.Collection);
727
+ function EngineCollection() {
728
+ EngineCollection.__super__.constructor.apply(this, arguments);
729
+ }
730
+ EngineCollection.prototype.model = Engine;
731
+ EngineCollection.prototype.url = "/engines";
732
+ return EngineCollection;
733
+ })();
734
+ ListenerCollection = (function() {
735
+ __extends(ListenerCollection, Backbone.Collection);
736
+ function ListenerCollection() {
737
+ ListenerCollection.__super__.constructor.apply(this, arguments);
738
+ }
739
+ ListenerCollection.prototype.model = Listener;
740
+ ListenerCollection.prototype.initialize = function(objs, opts) {
741
+ return this.statement = opts.statement;
742
+ };
743
+ ListenerCollection.prototype.url = function() {
744
+ return [this.statement.url(), "listeners"].join("/");
745
+ };
746
+ return ListenerCollection;
747
+ })();
748
+ SourceCollection = (function() {
749
+ __extends(SourceCollection, Backbone.Collection);
750
+ function SourceCollection() {
751
+ SourceCollection.__super__.constructor.apply(this, arguments);
752
+ }
753
+ SourceCollection.prototype.model = Source;
754
+ SourceCollection.prototype.url = "/sources";
755
+ return SourceCollection;
756
+ })();
757
+ StatementCollection = (function() {
758
+ __extends(StatementCollection, Backbone.Collection);
759
+ function StatementCollection() {
760
+ StatementCollection.__super__.constructor.apply(this, arguments);
761
+ }
762
+ StatementCollection.prototype.model = Statement;
763
+ StatementCollection.prototype.initialize = function(objs, opts) {
764
+ return this.engine = opts.engine;
765
+ };
766
+ StatementCollection.prototype.url = function() {
767
+ return ["engines", this.engine.id, "statements"].join("/");
768
+ };
769
+ return StatementCollection;
770
+ })();
771
+ HopeRouter = (function() {
772
+ __extends(HopeRouter, Backbone.Router);
773
+ function HopeRouter() {
774
+ HopeRouter.__super__.constructor.apply(this, arguments);
775
+ }
776
+ HopeRouter.prototype.initialize = function(opts) {
777
+ return this.app = opts.app;
778
+ };
779
+ HopeRouter.prototype.routes = {
780
+ "/": "root",
781
+ "/engines/:id": "engine",
782
+ "/sources/:id": "source"
783
+ };
784
+ HopeRouter.prototype.root = function() {
785
+ return console.log("Back to the basics...");
786
+ };
787
+ HopeRouter.prototype.engine = function(id) {
788
+ return this.app.view.selectEngine(id);
789
+ };
790
+ HopeRouter.prototype.source = function(id) {
791
+ return this.app.view.selectSource(id);
792
+ };
793
+ return HopeRouter;
794
+ })();
795
+ EngineView = (function() {
796
+ __extends(EngineView, TBone.View);
797
+ function EngineView() {
798
+ this.render = __bind(this.render, this);
799
+ EngineView.__super__.constructor.apply(this, arguments);
800
+ }
801
+ EngineView.prototype.template = "engines/show";
802
+ EngineView.prototype.className = "engine";
803
+ EngineView.prototype.events = {
804
+ "click .newStatement": "newStatement"
805
+ };
806
+ EngineView.prototype.initialize = function(opts) {
807
+ EngineView.__super__.initialize.call(this, opts);
808
+ return this.model.statements.bind("all", this.render);
809
+ };
810
+ EngineView.prototype.render = function() {
811
+ EngineView.__super__.render.call(this);
812
+ return this.model.statements.each(__bind(function(statement) {
813
+ return new StatementListView({
814
+ model: statement,
815
+ parent_el: this.$(".statements_list")
816
+ }).render();
817
+ }, this));
818
+ };
819
+ EngineView.prototype.newStatement = function() {
820
+ var nc;
821
+ nc = new StatementView({
822
+ model: new Statement()
823
+ });
824
+ nc.model.collection = this.model.statements;
825
+ window.hope.view.edit_dialog.modelView = nc;
826
+ return window.hope.view.edit_dialog.open();
827
+ };
828
+ return EngineView;
829
+ })();
830
+ EngineListView = (function() {
831
+ __extends(EngineListView, TBone.View);
832
+ function EngineListView() {
833
+ this.select = __bind(this.select, this);
834
+ EngineListView.__super__.constructor.apply(this, arguments);
835
+ }
836
+ EngineListView.prototype.tagName = "li";
837
+ EngineListView.prototype.className = "engine";
838
+ EngineListView.prototype.template = "engines/list";
839
+ EngineListView.prototype.events = {
840
+ "click": "select"
841
+ };
842
+ EngineListView.prototype.select = function() {
843
+ return window.location.hash = this.model.url();
844
+ };
845
+ return EngineListView;
846
+ })();
847
+ HopeView = (function() {
848
+ __extends(HopeView, Backbone.View);
849
+ function HopeView() {
850
+ this.renderSourcesList = __bind(this.renderSourcesList, this);
851
+ this.renderEnginesList = __bind(this.renderEnginesList, this);
852
+ this.selectSource = __bind(this.selectSource, this);
853
+ this.selectEngine = __bind(this.selectEngine, this);
854
+ this.render = __bind(this.render, this);
855
+ HopeView.__super__.constructor.apply(this, arguments);
856
+ }
857
+ HopeView.prototype.template = Hope.Templates['hope'];
858
+ HopeView.prototype.events = {
859
+ "click .logo": "home"
860
+ };
861
+ HopeView.prototype.initialize = function(opts) {
862
+ return this.app = opts.app;
863
+ };
864
+ HopeView.prototype.home = function() {
865
+ window.location.hash = "/";
866
+ return console.log("Going back home...");
867
+ };
868
+ HopeView.prototype.render = function() {
869
+ $(this.el).html(this.template(this.model));
870
+ console.log("App", this.app.engines);
871
+ this.renderEnginesList();
872
+ this.renderSourcesList();
873
+ return this.edit_dialog = new EditDialogView({
874
+ el: $('#dialog'),
875
+ app: this
876
+ });
877
+ };
878
+ HopeView.prototype.selectEngine = function(id) {
879
+ var e;
880
+ if (!(e = this.app.engines.get(id))) {
881
+ return;
882
+ }
883
+ this.$(".side .selected").removeClass("selected");
884
+ this.current_view = new EngineView({
885
+ model: e,
886
+ el: this.$(".current")
887
+ });
888
+ this.current_view.el = this.$(".current");
889
+ this.current_view.render();
890
+ return $("#engine-engines-list-" + e.cid).addClass("selected");
891
+ };
892
+ HopeView.prototype.selectSource = function(id) {
893
+ var s;
894
+ if (!(s = this.app.sources.get(id))) {
895
+ return;
896
+ }
897
+ this.$(".side .selected").removeClass("selected");
898
+ this.current_view = new SourceView({
899
+ model: s,
900
+ el: this.$(".current")
901
+ });
902
+ this.current_view.el = this.$(".current");
903
+ this.current_view.render();
904
+ return $("#source-sources-list-" + s.cid).addClass("selected");
905
+ };
906
+ HopeView.prototype.renderEnginesList = function() {
907
+ this.$("#engines_list").html('');
908
+ return this.app.engines.each(__bind(function(engine) {
909
+ return (new EngineListView({
910
+ model: engine,
911
+ parent_el: this.$("#engines_list")
912
+ })).render();
913
+ }, this));
914
+ };
915
+ HopeView.prototype.renderSourcesList = function() {
916
+ this.$("#sources_list").html('');
917
+ return this.app.sources.each(__bind(function(source) {
918
+ return (new SourceListView({
919
+ model: source,
920
+ parent_el: this.$("#sources_list")
921
+ })).render();
922
+ }, this));
923
+ };
924
+ return HopeView;
925
+ })();
926
+ SourceView = (function() {
927
+ __extends(SourceView, TBone.View);
928
+ function SourceView() {
929
+ SourceView.__super__.constructor.apply(this, arguments);
930
+ }
931
+ SourceView.prototype.template = "sources/show";
932
+ SourceView.prototype.className = "source";
933
+ return SourceView;
934
+ })();
935
+ SourceListView = (function() {
936
+ __extends(SourceListView, TBone.View);
937
+ function SourceListView() {
938
+ this.select = __bind(this.select, this);
939
+ SourceListView.__super__.constructor.apply(this, arguments);
940
+ }
941
+ SourceListView.prototype.tagName = "li";
942
+ SourceListView.prototype.className = "source";
943
+ SourceListView.prototype.template = "sources/list";
944
+ SourceListView.prototype.events = {
945
+ "click": "select"
946
+ };
947
+ SourceListView.prototype.select = function() {
948
+ return window.location.hash = this.model.url();
949
+ };
950
+ return SourceListView;
951
+ })();
952
+ StatementView = (function() {
953
+ __extends(StatementView, TBone.View);
954
+ function StatementView() {
955
+ StatementView.__super__.constructor.apply(this, arguments);
956
+ }
957
+ StatementView.prototype.className = "statement";
958
+ StatementView.prototype.events = {
959
+ 'click .edit': 'edit',
960
+ 'click .statement-stop': 'stop',
961
+ 'click .statement-start': 'start',
962
+ 'click .statement-destroy': 'destroy'
963
+ };
964
+ StatementView.prototype.form = function() {
965
+ return [["Statement", [["statement_id", ["text_field", "Name"]], ["epl", ["text_area", "Epl"]]]]];
966
+ };
967
+ StatementView.prototype.stop = function() {
968
+ if (confirm("Sure ?")) {
969
+ return this.model.stop();
970
+ }
971
+ };
972
+ StatementView.prototype.start = function() {
973
+ if (confirm("Sure ?")) {
974
+ return this.model.start();
975
+ }
976
+ };
977
+ StatementView.prototype.destroy = function() {
978
+ if (confirm("Sure ?")) {
979
+ return this.model.destroy();
980
+ }
981
+ };
982
+ return StatementView;
983
+ })();
984
+ StatementListView = (function() {
985
+ __extends(StatementListView, StatementView);
986
+ function StatementListView() {
987
+ StatementListView.__super__.constructor.apply(this, arguments);
988
+ }
989
+ StatementListView.prototype.tagName = "tr";
990
+ StatementListView.prototype.template = "statements/list";
991
+ return StatementListView;
992
+ })();
993
+ }).call(this);