puffer 0.0.23 → 0.0.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/.rspec +1 -0
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +55 -53
  4. data/VERSION +1 -1
  5. data/app/assets/javascripts/puffer/application.js +6 -3
  6. data/app/assets/javascripts/puffer/paginator.js +223 -0
  7. data/app/assets/javascripts/puffer/puffer.js +12 -0
  8. data/app/assets/javascripts/puffer/rails.js +1 -0
  9. data/app/assets/javascripts/puffer/{right-autocompleter.js → right-autocompleter-src.js} +45 -41
  10. data/app/assets/javascripts/puffer/{right-calendar.js → right-calendar-src.js} +53 -50
  11. data/app/assets/javascripts/puffer/right-dialog-src.js +768 -0
  12. data/app/assets/javascripts/puffer/right-slider-src.js +507 -0
  13. data/app/assets/javascripts/puffer/{right.js → right-src.js} +1000 -230
  14. data/app/assets/stylesheets/puffer/application.css +2 -0
  15. data/app/assets/stylesheets/puffer/paginator.css +33 -0
  16. data/app/assets/stylesheets/puffer/right.css +4 -0
  17. data/app/components/base/form.html.erb +15 -0
  18. data/app/components/base_component.rb +15 -0
  19. data/app/components/boolean/form.html.erb +3 -0
  20. data/app/components/boolean/index.html.erb +3 -0
  21. data/app/components/boolean_component.rb +13 -0
  22. data/app/components/date_time/form.html.erb +5 -0
  23. data/app/components/date_time_component.rb +12 -0
  24. data/app/components/file/form.html.erb +5 -0
  25. data/app/components/file_component.rb +3 -0
  26. data/app/components/hidden/form.html.erb +1 -0
  27. data/app/components/hidden_component.rb +3 -0
  28. data/app/components/password/form.html.erb +5 -0
  29. data/app/components/password_component.rb +7 -0
  30. data/app/components/references_many/form.html.erb +1 -0
  31. data/app/components/references_many_component.rb +7 -0
  32. data/app/components/references_one/choose.html.erb +9 -0
  33. data/app/components/references_one/form.html.erb +28 -0
  34. data/app/components/references_one_component.rb +12 -0
  35. data/app/components/select/form.html.erb +5 -0
  36. data/app/components/select_component.rb +15 -0
  37. data/app/components/string/form.html.erb +5 -0
  38. data/app/components/string_component.rb +3 -0
  39. data/app/components/text/form.html.erb +5 -0
  40. data/app/components/text_component.rb +3 -0
  41. data/app/controllers/puffer/base.rb +4 -0
  42. data/app/views/puffer/base/_form.html.erb +0 -1
  43. data/app/views/puffer/base/_table.html.erb +25 -0
  44. data/app/views/puffer/base/index.html.erb +14 -28
  45. data/app/views/puffer/tree_base/_record.html.erb +1 -1
  46. data/lib/generators/puffer/component/USAGE +12 -0
  47. data/lib/generators/puffer/component/component_generator.rb +19 -0
  48. data/lib/generators/puffer/component/templates/component.rb +15 -0
  49. data/lib/generators/puffer/component/templates/component_spec.rb +19 -0
  50. data/lib/puffer/component.rb +141 -0
  51. data/lib/puffer/controller/dsl.rb +25 -12
  52. data/lib/puffer/engine.rb +5 -0
  53. data/lib/puffer/extensions/controller.rb +11 -9
  54. data/lib/puffer/extensions/form.rb +2 -1
  55. data/lib/puffer/extensions/mapper.rb +2 -0
  56. data/lib/puffer/field.rb +30 -19
  57. data/lib/puffer/field_set.rb +17 -2
  58. data/lib/puffer.rb +25 -8
  59. data/puffer.gemspec +59 -28
  60. data/spec/app/components/base_component_spec.rb +19 -0
  61. data/spec/app/components/boolean_component_spec.rb +36 -0
  62. data/spec/app/components/date_time_component_spec.rb +26 -0
  63. data/spec/app/components/file_component_spec.rb +25 -0
  64. data/spec/app/components/hidden_component_spec.rb +24 -0
  65. data/spec/app/components/password_component_spec.rb +37 -0
  66. data/spec/app/components/references_many_component_spec.rb +19 -0
  67. data/spec/app/components/references_one_component_spec.rb +19 -0
  68. data/spec/app/components/select_component_spec.rb +30 -0
  69. data/spec/app/components/string_component_spec.rb +25 -0
  70. data/spec/app/components/text_component_spec.rb +25 -0
  71. data/spec/dummy/app/controllers/admin/categories_controller.rb +3 -3
  72. data/spec/dummy/app/controllers/admin/posts_controller.rb +3 -0
  73. data/spec/dummy/app/controllers/{puffer → admin}/sessions_controller.rb +1 -1
  74. data/spec/dummy/app/controllers/admin/users_controller.rb +2 -2
  75. data/spec/dummy/app/models/post.rb +4 -0
  76. data/spec/dummy/db/migrate/20100930132656_create_posts.rb +2 -0
  77. data/spec/dummy/db/migrate/20100930132726_create_categories.rb +1 -0
  78. data/spec/dummy/db/schema.rb +3 -0
  79. data/spec/dummy/db/seeds.rb +6 -1
  80. data/spec/fabricators/categories_fabricator.rb +1 -0
  81. data/spec/fabricators/posts_fabricator.rb +1 -0
  82. data/spec/lib/component_spec.rb +7 -0
  83. data/spec/lib/fields_spec.rb +0 -4
  84. metadata +85 -56
  85. data/app/views/puffer/base/associated/_many.html.erb +0 -56
  86. data/app/views/puffer/base/associated/many.rjs +0 -1
  87. data/app/views/puffer/base/associated/one.js.erb +0 -13
  88. data/app/views/puffer/base/association/_many.html.erb +0 -7
  89. data/lib/puffer/controller/generated.rb +0 -65
  90. data/lib/puffer/customs.rb +0 -64
  91. data/lib/puffer/inputs/association.rb +0 -38
  92. data/lib/puffer/inputs/base.rb +0 -51
  93. data/lib/puffer/inputs/boolean.rb +0 -19
  94. data/lib/puffer/inputs/collection_association.rb +0 -11
  95. data/lib/puffer/inputs/date_time.rb +0 -16
  96. data/lib/puffer/inputs/file.rb +0 -11
  97. data/lib/puffer/inputs/hidden.rb +0 -15
  98. data/lib/puffer/inputs/password.rb +0 -11
  99. data/lib/puffer/inputs/select.rb +0 -19
  100. data/lib/puffer/inputs/text.rb +0 -11
@@ -0,0 +1,768 @@
1
+ /**
2
+ * RightJS-UI Dialog v2.2.0
3
+ * http://rightjs.org/ui/dialog
4
+ *
5
+ * Copyright (C) 2010-2011 Nikolay Nemshilov
6
+ */
7
+ var Dialog = RightJS.Dialog = (function(RightJS) {
8
+ /**
9
+ * This module defines the basic widgets constructor
10
+ * it creates an abstract proxy with the common functionality
11
+ * which then we reuse and override in the actual widgets
12
+ *
13
+ * Copyright (C) 2010-2011 Nikolay Nemshilov
14
+ */
15
+
16
+ /**
17
+ * The widget units constructor
18
+ *
19
+ * @param String tag-name or Object methods
20
+ * @param Object methods
21
+ * @return Widget wrapper
22
+ */
23
+ function Widget(tag_name, methods) {
24
+ if (!methods) {
25
+ methods = tag_name;
26
+ tag_name = 'DIV';
27
+ }
28
+
29
+ /**
30
+ * An Abstract Widget Unit
31
+ *
32
+ * Copyright (C) 2010 Nikolay Nemshilov
33
+ */
34
+ var AbstractWidget = new RightJS.Class(RightJS.Element.Wrappers[tag_name] || RightJS.Element, {
35
+ /**
36
+ * The common constructor
37
+ *
38
+ * @param Object options
39
+ * @param String optional tag name
40
+ * @return void
41
+ */
42
+ initialize: function(key, options) {
43
+ this.key = key;
44
+ var args = [{'class': 'rui-' + key}];
45
+
46
+ // those two have different constructors
47
+ if (!(this instanceof RightJS.Input || this instanceof RightJS.Form)) {
48
+ args.unshift(tag_name);
49
+ }
50
+ this.$super.apply(this, args);
51
+
52
+ if (RightJS.isString(options)) {
53
+ options = RightJS.$(options);
54
+ }
55
+
56
+ // if the options is another element then
57
+ // try to dynamically rewrap it with our widget
58
+ if (options instanceof RightJS.Element) {
59
+ this._ = options._;
60
+ if ('$listeners' in options) {
61
+ options.$listeners = options.$listeners;
62
+ }
63
+ options = {};
64
+ }
65
+ this.setOptions(options, this);
66
+
67
+ return (RightJS.Wrapper.Cache[RightJS.$uid(this._)] = this);
68
+ },
69
+
70
+ // protected
71
+
72
+ /**
73
+ * Catches the options
74
+ *
75
+ * @param Object user-options
76
+ * @param Element element with contextual options
77
+ * @return void
78
+ */
79
+ setOptions: function(options, element) {
80
+ if (element) {
81
+ options = RightJS.Object.merge(options, new Function("return "+(
82
+ element.get('data-'+ this.key) || '{}'
83
+ ))());
84
+ }
85
+
86
+ if (options) {
87
+ RightJS.Options.setOptions.call(this, RightJS.Object.merge(this.options, options));
88
+ }
89
+
90
+ return this;
91
+ }
92
+ });
93
+
94
+ /**
95
+ * Creating the actual widget class
96
+ *
97
+ */
98
+ var Klass = new RightJS.Class(AbstractWidget, methods);
99
+
100
+ // creating the widget related shortcuts
101
+ RightJS.Observer.createShortcuts(Klass.prototype, Klass.EVENTS || RightJS([]));
102
+
103
+ return Klass;
104
+ }
105
+
106
+
107
+ /**
108
+ * A shared button unit.
109
+ * NOTE: we use the DIV units instead of INPUTS
110
+ * so those buttons didn't interfere with
111
+ * the user's tab-index on his page
112
+ *
113
+ * Copyright (C) 2010-2011 Nikolay Nemshilov
114
+ */
115
+ var Button = new RightJS.Class(RightJS.Element, {
116
+ /**
117
+ * Constructor
118
+ *
119
+ * @param String caption
120
+ * @param Object options
121
+ * @return void
122
+ */
123
+ initialize: function(caption, options) {
124
+ this.$super('div', options);
125
+ this._.innerHTML = caption;
126
+ this.addClass('rui-button');
127
+ this.on('selectstart', 'stopEvent');
128
+ },
129
+
130
+ /**
131
+ * Disasbles the button
132
+ *
133
+ * @return Button this
134
+ */
135
+ disable: function() {
136
+ return this.addClass('rui-button-disabled');
137
+ },
138
+
139
+ /**
140
+ * Enables the button
141
+ *
142
+ * @return Button this
143
+ */
144
+ enable: function() {
145
+ return this.removeClass('rui-button-disabled');
146
+ },
147
+
148
+ /**
149
+ * Checks if the button is disabled
150
+ *
151
+ * @return Button this
152
+ */
153
+ disabled: function() {
154
+ return this.hasClass('rui-button-disabled');
155
+ },
156
+
157
+ /**
158
+ * Checks if the button is enabled
159
+ *
160
+ * @return Button this
161
+ */
162
+ enabled: function() {
163
+ return !this.disabled();
164
+ },
165
+
166
+ /**
167
+ * Overloading the method, so it fired the events
168
+ * only when the button is active
169
+ *
170
+ * @return Button this
171
+ */
172
+ fire: function() {
173
+ if (this.enabled()) {
174
+ this.$super.apply(this, arguments);
175
+ }
176
+ return this;
177
+ }
178
+ });
179
+
180
+
181
+ /**
182
+ * A shared module to create textual spinners
183
+ *
184
+ * Copyright (C) 2010-2011 Nikolay Nemshilov
185
+ */
186
+ var Spinner = new RightJS.Class(RightJS.Element, {
187
+ /**
188
+ * Constructor
189
+ *
190
+ * @param Number optional spinner size (4 by default)
191
+ * @return void
192
+ */
193
+ initialize: function(size) {
194
+ this.$super('div', {'class': 'rui-spinner'});
195
+ this.dots = [];
196
+
197
+ for (var i=0; i < (size || 4); i++) {
198
+ this.dots.push(new RightJS.Element('div'));
199
+ }
200
+
201
+ this.dots[0].addClass('glowing');
202
+ this.insert(this.dots);
203
+ RightJS(this.shift).bind(this).periodical(300);
204
+ },
205
+
206
+ /**
207
+ * Shifts the spinner elements
208
+ *
209
+ * @return void
210
+ */
211
+ shift: function() {
212
+ if (this.visible()) {
213
+ var dot = this.dots.pop();
214
+ this.dots.unshift(dot);
215
+ this.insert(dot, 'top');
216
+ }
217
+ }
218
+ });
219
+
220
+
221
+ /**
222
+ * Dialog widget initialization script
223
+ *
224
+ * Copyright (C) 2010 Nikolay Nemshilov
225
+ */
226
+ var R = RightJS,
227
+ $ = RightJS.$,
228
+ $w = RightJS.$w,
229
+ $E = RightJS.$E,
230
+ Class = RightJS.Class,
231
+ Object = RightJS.Object,
232
+ Element = RightJS.Element;
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+ /**
241
+ * Basic dialog class
242
+ *
243
+ * Copyright (C) 2010-2011 Nikolay Nemshilov
244
+ */
245
+ var Dialog = new Widget({
246
+ extend: {
247
+ version: '2.2.0',
248
+
249
+ EVENTS: $w('ok cancel help expand collapse resize load'),
250
+
251
+ Options: {
252
+ lockScreen: true, // if you need to lock the scrreen
253
+ fxDuration: 'short', // dialog appearance duration
254
+
255
+ draggable: true, // sets if the user should be able to drag the dialog around
256
+ closeable: true, // allow the user to close the dialog
257
+ expandable: false, // show the user to expand/collapse the dialog window width
258
+
259
+ showHelp: false, // show the 'Help' button
260
+ showIcon: null, // null or some text to be show in the dialog body icon
261
+
262
+ title: null, // default title to preset
263
+ html: null, // html content to set on instance
264
+ url: null // url address that should be loaded on instance
265
+ },
266
+
267
+ i18n: {
268
+ Ok: 'Ok',
269
+ Close: 'Close',
270
+ Cancel: 'Cancel',
271
+ Help: 'Help',
272
+ Expand: 'Expand',
273
+ Collapse: 'Collapse',
274
+
275
+ Alert: 'Warning!',
276
+ Confirm: 'Confirm',
277
+ Prompt: 'Enter'
278
+ },
279
+
280
+ current: false, // the current dialog reference
281
+ dragged: false // currently dragged dialog reference
282
+ },
283
+
284
+ /**
285
+ * Basic constructor
286
+ *
287
+ * @param Object options
288
+ * @return void
289
+ */
290
+ initialize: function(options) {
291
+ this
292
+ .$super('dialog', options)
293
+ .append(
294
+ this.head = new Dialog.Head(this),
295
+ this.body = new Dialog.Body(this),
296
+ this.foot = new Dialog.Foot(this)
297
+ )
298
+ .onCancel(this.hide);
299
+
300
+ this.locker = $E('div', {'class': 'rui-screen-locker'});
301
+
302
+ if (this.options.title) {
303
+ this.title(this.options.title);
304
+ }
305
+
306
+ if (this.options.html) {
307
+ this.html(this.options.html);
308
+ }
309
+
310
+ if (this.options.url) {
311
+ this.load(this.options.url);
312
+ }
313
+ },
314
+
315
+ /**
316
+ * Shows the dialog
317
+ *
318
+ * @return Dialog this
319
+ */
320
+ show: function() {
321
+ if (this.options.lockScreen) {
322
+ this.locker.insertTo(document.body);
323
+ }
324
+
325
+ this
326
+ .setStyle('visibility:hidden')
327
+ .insertTo(document.body)
328
+ .resize()
329
+ .setStyle('visibility:visible;opacity:0');
330
+
331
+ if (this.options.fxDuration) {
332
+ this.morph({opacity: 1}, {
333
+ duration: this.options.fxDuration
334
+ });
335
+ } else {
336
+ this.setStyle('opacity:1');
337
+ }
338
+
339
+ return (Dialog.current = this);
340
+ },
341
+
342
+ /**
343
+ * Hides the dialog
344
+ *
345
+ * @return Dialog this
346
+ */
347
+ hide: function() {
348
+ this.locker.remove();
349
+ this.remove();
350
+
351
+ Dialog.current = false;
352
+
353
+ return this;
354
+ },
355
+
356
+ /**
357
+ * Repositions the dialog to the middle of the screen
358
+ *
359
+ * @param normal arguments
360
+ * @return Dialog this
361
+ */
362
+ resize: function() {
363
+ if (arguments.length) {
364
+ this.$super.apply(this, arguments);
365
+ }
366
+
367
+ var size = this.size(), win_size = $(window).size();
368
+
369
+ if (this.expanded) {
370
+ size.x = win_size.x - 20;
371
+ size.y = win_size.y - 10;
372
+ this.$super.call(this, size);
373
+ }
374
+
375
+ this.setStyle({
376
+ top: (win_size.y - size.y)/2 + $(window).scrolls().y + 'px',
377
+ left: (win_size.x - size.x - 16)/2 + 'px'
378
+ });
379
+
380
+ return this.fire('resize');
381
+ },
382
+
383
+ /**
384
+ * Bidirectional method to work with titles
385
+ *
386
+ * @param String title to set
387
+ * @return String title or Dialog this
388
+ */
389
+ title: function(text) {
390
+ if (arguments.length) {
391
+ this.head.title.html(text);
392
+ return this;
393
+ } else {
394
+ return this.head.title.html();
395
+ }
396
+ },
397
+
398
+ /**
399
+ * Overloading the standard method, so that
400
+ * all the content updates were going into the body element
401
+ *
402
+ * @param mixed content
403
+ * @return Dialog this
404
+ */
405
+ update: function(content) {
406
+ this.body.update(content);
407
+ return this.resize();
408
+ },
409
+
410
+ /**
411
+ * Redirecting the `html` method to work wiht the body html
412
+ *
413
+ * @param mixed content
414
+ * @return Dialog this or html content of the body
415
+ */
416
+ html: function() {
417
+ return arguments.length ?
418
+ this.$super.apply(this, arguments) :
419
+ this.body.html();
420
+ },
421
+
422
+ /**
423
+ * Overloading the original method to bypass things into the body object
424
+ *
425
+ * @param String url
426
+ * @param Object options
427
+ * @return Dialog this
428
+ */
429
+ load: function(url, options) {
430
+ this.show();
431
+ this.body.load(url, options);
432
+ return this;
433
+ },
434
+
435
+ /**
436
+ * Expands a dialog screen-wide
437
+ *
438
+ * @return Dialog this
439
+ */
440
+ expand: function() {
441
+ if (!this.expanded) {
442
+ this._prevSize = this.size();
443
+ this.resize({
444
+ x: $(window).size().x - 20,
445
+ y: $(window).size().y - 10
446
+ });
447
+
448
+ this.expanded = true;
449
+ this.fire('expand');
450
+ }
451
+
452
+ return this;
453
+ },
454
+
455
+ /**
456
+ * Collapses an expanded dialog to it's previous size
457
+ *
458
+ * @return Dialog this
459
+ */
460
+ collapse: function() {
461
+ if (this.expanded) {
462
+ this.expanded = false;
463
+ this.resize(this._prevSize);
464
+ this.fire('collapse');
465
+ }
466
+
467
+ return this;
468
+ }
469
+ });
470
+
471
+ /**
472
+ * Dialog header line element
473
+ *
474
+ * Copyright (C) 2010 Nikolay Nemshilov
475
+ */
476
+ Dialog.Head = new Class(Element, {
477
+
478
+ initialize: function(dialog) {
479
+ this.dialog = dialog;
480
+ this.options = dialog.options;
481
+
482
+ this.$super('div', {'class': 'rui-dialog-head'});
483
+
484
+ this.append(
485
+ this.icon = $E('div', {'class': 'icon'}),
486
+ this.title = $E('div', {'class': 'title', 'html': '&nbsp;'}),
487
+ this.tools = $E('div', {'class': 'tools'})
488
+ );
489
+
490
+ this.fsButton = $E('div', {
491
+ 'class': 'expand', 'html': '&equiv;', 'title': Dialog.i18n.Expand
492
+ }).onClick(function() {
493
+ if (dialog.expanded) {
494
+ dialog.collapse();
495
+ this.html('&equiv;').set('title', Dialog.i18n.Expand);
496
+ } else {
497
+ dialog.expand();
498
+ this.html('_').set('title', Dialog.i18n.Collapse);
499
+ }
500
+ });
501
+
502
+ this.closeButton = $E('div', {
503
+ 'class': 'close', 'html': '&times;', 'title': Dialog.i18n.Close
504
+ }).onClick(function() { dialog.fire('cancel'); });
505
+
506
+ if (this.options.expandable) {
507
+ this.tools.insert(this.fsButton);
508
+ }
509
+
510
+ if (this.options.closeable) {
511
+ this.tools.insert(this.closeButton);
512
+ }
513
+
514
+ this.on({
515
+ selectstart: function(e) { e.stop(); },
516
+ mousedown: this.dragStart
517
+ });
518
+
519
+ if (!this.options.draggable) {
520
+ this.dialog.addClass('rui-dialog-nodrag');
521
+ }
522
+ },
523
+
524
+ // protected
525
+
526
+ dragStart: function(event) {
527
+ if (this.options.draggable && !event.find('div.tools div')) {
528
+ var dim = this.dialog.dimensions(),
529
+ ev_pos = event.position();
530
+
531
+ this.xDiff = dim.left - ev_pos.x;
532
+ this.yDiff = dim.top - ev_pos.y;
533
+ this.maxX = $(window).size().x - dim.width - 20;
534
+ this.dlgStyle = this.dialog.get('style');
535
+
536
+ Dialog.dragged = this.dialog;
537
+
538
+ event.stop();
539
+ }
540
+ },
541
+
542
+ dragMove: function(event) {
543
+ var event_pos = event.position(),
544
+ pos_x = event_pos.x + this.xDiff,
545
+ pos_y = event_pos.y + this.yDiff;
546
+
547
+ if (pos_x < 0) { pos_x = 0; }
548
+ else if (pos_x > this.maxX) { pos_x = this.maxX; }
549
+ if (pos_y < 0) { pos_y = 0; }
550
+
551
+ this.dlgStyle.top = pos_y + 'px';
552
+ this.dlgStyle.left = pos_x + 'px';
553
+ },
554
+
555
+ dragStop: function(event) {
556
+ Dialog.dragged = false;
557
+ }
558
+ });
559
+
560
+ /**
561
+ * Dialog body element
562
+ *
563
+ * Copyright (C) 2010 Nikolay Nemshilov
564
+ */
565
+ Dialog.Body = new Class(Element, {
566
+
567
+ initialize: function(dialog) {
568
+ this.dialog = dialog;
569
+ this.options = dialog.options;
570
+
571
+ this.$super('div', {'class': 'rui-dialog-body'});
572
+ this.locker = $E('div', {'class': 'rui-dialog-body-locker'})
573
+ .insert(new Spinner());
574
+ },
575
+
576
+ load: function(url, options) {
577
+ this.insert(this.locker, 'top');
578
+
579
+ this.xhr = new Xhr(url, Object.merge({method:'get'}, options))
580
+ .onComplete(R(function(r) {
581
+ this.update(r.text);
582
+ this.dialog.resize().fire('load');
583
+ }).bind(this))
584
+ .send();
585
+
586
+ return this;
587
+ },
588
+
589
+ update: function(content) {
590
+ this.$super(content);
591
+
592
+ if (this.options.showIcon) {
593
+ this.insert('<div class="rui-dialog-body-icon">'+ this.options.showIcon + '</div>', 'top');
594
+ }
595
+
596
+ return this;
597
+ }
598
+
599
+ });
600
+
601
+ /**
602
+ * Dialog footer line element
603
+ *
604
+ * Copyright (C) 2010 Nikolay Nemshilov
605
+ */
606
+ Dialog.Foot = new Class(Element, {
607
+
608
+ initialize: function(dialog) {
609
+ this.$super('div', {'class': 'rui-dialog-foot'});
610
+
611
+ this.dialog = dialog;
612
+
613
+ dialog.okButton = new Button(Dialog.i18n.Ok, {'class': 'ok'}).onClick(function() { dialog.fire('ok'); });
614
+ dialog.helpButton = new Button(Dialog.i18n.Help, {'class': 'help'}).onClick(function() { dialog.fire('help'); });
615
+ dialog.cancelButton = new Button(Dialog.i18n.Cancel, {'class': 'cancel'}).onClick(function() { dialog.fire('cancel'); });
616
+
617
+ if (dialog.options.showHelp) {
618
+ this.insert(dialog.helpButton);
619
+ }
620
+
621
+ if (dialog.options.closeable) {
622
+ this.insert(dialog.cancelButton);
623
+ }
624
+
625
+ this.insert(dialog.okButton);
626
+ }
627
+
628
+ });
629
+
630
+ /**
631
+ * Alert specific dialog
632
+ *
633
+ * Copyright (C) 2010 Nikolay Nemshilov
634
+ */
635
+ Dialog.Alert = new Class(Dialog, {
636
+
637
+ initialize: function(options) {
638
+ options = Object.merge({
639
+ showIcon: '!',
640
+ title: Dialog.i18n.Alert
641
+ }, options);
642
+
643
+ this.$super(options);
644
+ this.addClass('rui-dialog-alert');
645
+ this.on('ok', 'hide');
646
+ }
647
+ });
648
+
649
+ /**
650
+ * Confirm specific dialog
651
+ *
652
+ * Copyright (C) 2010 Nikolay Nemshilov
653
+ */
654
+ Dialog.Confirm = new Class(Dialog, {
655
+
656
+ initialize: function(options) {
657
+ options = Object.merge({
658
+ showIcon: '?',
659
+ title: Dialog.i18n.Confirm
660
+ }, options);
661
+
662
+ this.$super(options);
663
+ this.addClass('rui-dialog-confirm');
664
+ this.on('ok', 'hide');
665
+ }
666
+
667
+ });
668
+
669
+ /**
670
+ * The prompt dialog class
671
+ *
672
+ * Copyright (C) 2010 Nikolay Nemshilov
673
+ */
674
+ Dialog.Prompt = new Class(Dialog, {
675
+ /**
676
+ * prompts constructor, you can use additional options with this one
677
+ *
678
+ * * `label` - the text for the input field label
679
+ * * `input` - the input field options (standard for Input unit)
680
+ *
681
+ * @param Object options
682
+ * @return void
683
+ */
684
+ initialize: function(options) {
685
+ options = Object.merge({
686
+ showIcon: '&#x27A5;',
687
+ title: Dialog.i18n.Prompt,
688
+ label: Dialog.i18n.Prompt
689
+ }, options);
690
+
691
+ this.$super(options);
692
+ this.addClass('rui-dialog-prompt');
693
+
694
+ this.html([
695
+ $E('label', {html: this.options.label}),
696
+ this.input = new RightJS.Input(this.options.input || {})
697
+ ]);
698
+
699
+ if (this.input.get('type') !== 'textarea') {
700
+ this.input.onKeydown(R(function(event) {
701
+ if (event.keyCode === 13) {
702
+ this.fire('ok');
703
+ }
704
+ }).bind(this));
705
+ }
706
+ },
707
+
708
+ show: function() {
709
+ this.$super.apply(this, arguments);
710
+ this.input.select();
711
+ return this;
712
+ }
713
+
714
+ });
715
+
716
+ /**
717
+ * Document level hooks for the dialogs
718
+ *
719
+ * Copyright (C) 2010 Nikolay Nemshilov
720
+ */
721
+ $(document).on({
722
+ keydown: function(event) {
723
+ if (event.keyCode === 27 && Dialog.current) {
724
+ if (Dialog.current.options.closeable) {
725
+ Dialog.current.fire('cancel');
726
+ }
727
+ } else if (event.keyCode === 13 && Dialog.current) {
728
+ if (!(Dialog.current instanceof Dialog.Prompt)) {
729
+ event.stop();
730
+ Dialog.current.fire('ok');
731
+ }
732
+ }
733
+ },
734
+
735
+ mousemove: function(event) {
736
+ if (Dialog.dragged) {
737
+ Dialog.dragged.head.dragMove(event);
738
+ }
739
+ },
740
+
741
+ mouseup: function(event) {
742
+ if (Dialog.dragged) {
743
+ Dialog.dragged.head.dragStop(event);
744
+ }
745
+ }
746
+ });
747
+
748
+ $(window).onResize(function() {
749
+ if (Dialog.current) {
750
+ Dialog.current.resize();
751
+ }
752
+ });
753
+
754
+ var embed_style = document.createElement('style'),
755
+ embed_rules = document.createTextNode("*.rui-button{display:inline-block; *display:inline; *zoom:1;height:1em;line-height:1em;margin:0;padding:.2em .5em;text-align:center;border:1px solid #CCC;border-radius:.2em;-moz-border-radius:.2em;-webkit-border-radius:.2em;cursor:pointer;color:#333;background-color:#FFF;user-select:none;-moz-user-select:none;-webkit-user-select:none} *.rui-button:hover{color:#111;border-color:#999;background-color:#DDD;box-shadow:#888 0 0 .1em;-moz-box-shadow:#888 0 0 .1em;-webkit-box-shadow:#888 0 0 .1em} *.rui-button:active{color:#000;border-color:#777;text-indent:1px;box-shadow:none;-moz-box-shadow:none;-webkit-box-shadow:none} *.rui-button-disabled, *.rui-button-disabled:hover, *.rui-button-disabled:active{color:#888;background:#DDD;border-color:#CCC;cursor:default;text-indent:0;box-shadow:none;-moz-box-shadow:none;-webkit-box-shadow:none}div.rui-spinner,div.rui-spinner div{margin:0;padding:0;border:none;background:none;list-style:none;font-weight:normal;float:none;display:inline-block; *display:inline; *zoom:1;border-radius:.12em;-moz-border-radius:.12em;-webkit-border-radius:.12em}div.rui-spinner{text-align:center;white-space:nowrap;background:#EEE;border:1px solid #DDD;height:1.2em;padding:0 .2em}div.rui-spinner div{width:.4em;height:70%;background:#BBB;margin-left:1px}div.rui-spinner div:first-child{margin-left:0}div.rui-spinner div.glowing{background:#777}div.rui-screen-locker{position:fixed;top:0;left:0;width:100%;height:100%;margin:0;padding:0;background:#000;opacity:.5;filter:alpha(opacity=50);z-index:99999;cursor:default}div.rui-dialog{position:absolute;z-index:99999;background:white;margin:0;padding:0;padding-top:2.5em;padding-bottom:2.8em;border-radius:.35em;-moz-border-radius:.35em;-webkit-border-radius:.35em;border:1px solid #ccc}div.rui-dialog-body{min-width:20em;min-height:4.5em;margin:0;padding:0 1em;height:100%;overflow:auto;position:relative}div.rui-dialog-body-locker{position:absolute;z-index:9999;left:0;top:0;width:100%;height:100%;text-align:center;opacity:.6;filter:alpha(opacity=60)}div.rui-dialog-body-locker div.rui-spinner{border:none;background:none;font-size:150%;margin-top:8%}div.rui-dialog-body-icon{float:left;background:#eee;font-size:360%;font-family:Arial;border:2px solid gray;border-radius:.1em;-moz-border-radius:.1em;-webkit-border-radius:.1em;width:1em;line-height:1em;text-align:center;margin-right:.2em;margin-top:.05em;cursor:default;user-select:none;-moz-user-select:none;-webkit-user-select:none}div.rui-dialog-head{position:absolute;top:0;left:0;margin:0;padding:0;width:100%;line-height:2em;background:#ccc;border-radius:.35em;-moz-border-radius:.35em;-webkit-border-radius:.35em;border-bottom-left-radius:0;border-bottom-right-radius:0;-moz-border-radius-bottomleft:0;-moz-border-radius-bottomright:0;-webkit-border-bottom-left-radius:0;-webkit-border-bottom-right-radius:0;cursor:move;user-select:none;-moz-user-select:none;-webkit-user-select:none}div.rui-dialog-head div.icon{float:left;height:1.4em;width:1.4em;margin-left:1em;margin-top:.3em;margin-right:.3em;display:none}div.rui-dialog-head div.title{margin-left:1em;color:#444}div.rui-dialog-head div.tools{position:absolute;right:.3em;top:.3em}div.rui-dialog-head div.tools div{float:left;width:1.4em;line-height:1.4em;text-align:center;margin-left:.15em;cursor:pointer;background:#aaa;border-radius:.2em;-moz-border-radius:.2em;-webkit-border-radius:.2em;font-family:Verdana;opacity:.6;filter:alpha(opacity=60)}div.rui-dialog-head div.tools div:hover{opacity:1;filter:alpha(opacity=100);box-shadow:#444 0 0 .1em;-moz-box-shadow:#444 0 0 .1em;-webkit-box-shadow:#444 0 0 .1em}div.rui-dialog-head div.tools div.close:hover{background:#daa}div.rui-dialog-nodrag div.rui-dialog-head{cursor:default}div.rui-dialog-foot{position:absolute;bottom:0;left:0;width:100%;text-align:right}div.rui-dialog-foot div.rui-button{margin:.6em 1em;background:#eee;width:4em}div.rui-dialog-foot div.help{float:left}div.rui-dialog-foot div.cancel{margin-right:-.5em}div.rui-dialog-foot div.ok:hover{background-color:#ded}div.rui-dialog-foot div.cancel:hover{background-color:#ecc}div.rui-dialog-alert div.rui-dialog-foot{text-align:center}div.rui-dialog-alert div.rui-dialog-foot div.cancel{display:none}div.rui-dialog-alert div.rui-dialog-body-icon{color:brown;background:#FEE;border-color:brown}div.rui-dialog-confirm div.rui-dialog-body-icon{color:#44A;background:#EEF;border-color:#44a}div.rui-dialog-prompt div.rui-dialog-body-icon{color:#333}div.rui-dialog-prompt div.rui-dialog-body label{display:block;font-weight:bold;font-size:120%;color:#444;margin-bottom:.5em}div.rui-dialog-prompt div.rui-dialog-body input,div.rui-dialog-prompt div.rui-dialog-body textarea{border:1px solid #aaa;font-size:1em;display:block;width:16em;margin:0;padding:.2em;margin-left:4.7em;border-radius:.2em;-moz-border-radius:.2em;-webkit-border-radius:.2em;outline:none}div.rui-dialog-prompt div.rui-dialog-body textarea{width:24em;height:8em}");
756
+
757
+ embed_style.type = 'text/css';
758
+ document.getElementsByTagName('head')[0].appendChild(embed_style);
759
+
760
+ if(embed_style.styleSheet) {
761
+ embed_style.styleSheet.cssText = embed_rules.nodeValue;
762
+ } else {
763
+ embed_style.appendChild(embed_rules);
764
+ }
765
+
766
+
767
+ return Dialog;
768
+ })(RightJS);