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