active_scaffold 3.1.20 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/app/assets/javascripts/jquery/active_scaffold.js +4 -1
  2. data/app/assets/javascripts/prototype/active_scaffold.js +4 -1
  3. data/app/assets/stylesheets/{active_scaffold.scss~ → active_scaffold.css.scss} +5 -2
  4. data/app/assets/stylesheets/{active_scaffold_colors.scss → active_scaffold_colors.css.scss} +4 -0
  5. data/app/assets/stylesheets/active_scaffold_extensions.css.erb +2 -0
  6. data/app/assets/stylesheets/active_scaffold_images.css.scss +43 -0
  7. data/lib/active_scaffold/actions/core.rb +1 -0
  8. data/lib/active_scaffold/actions/nested.rb +0 -1
  9. data/lib/active_scaffold/extensions/action_view_rendering.rb +1 -1
  10. data/lib/active_scaffold/helpers/form_column_helpers.rb +1 -0
  11. data/lib/active_scaffold/version.rb +2 -2
  12. data/test/mock_app/.gitignore +2 -0
  13. metadata +86 -164
  14. data/app/assets/javascripts/active_scaffold.js.erb~ +0 -16
  15. data/app/assets/javascripts/jquery/active_scaffold.js~ +0 -1053
  16. data/app/assets/javascripts/jquery/draggable_lists.js~ +0 -27
  17. data/app/assets/javascripts/prototype/active_scaffold.js~ +0 -1037
  18. data/app/assets/stylesheets/active_scaffold.css.erb +0 -11
  19. data/app/assets/stylesheets/active_scaffold.css.erb~ +0 -11
  20. data/app/assets/stylesheets/active_scaffold.css.scss.erb~ +0 -1120
  21. data/app/assets/stylesheets/active_scaffold.css.scss~ +0 -11
  22. data/app/assets/stylesheets/active_scaffold.css~ +0 -11
  23. data/app/assets/stylesheets/active_scaffold_colors.css +0 -244
  24. data/app/assets/stylesheets/active_scaffold_colors.css.scss~ +0 -481
  25. data/app/assets/stylesheets/active_scaffold_default.css.erb +0 -47
  26. data/app/assets/stylesheets/active_scaffold_default.css.erb~ +0 -57
  27. data/app/assets/stylesheets/active_scaffold_default.css.scss~ +0 -1092
  28. data/app/assets/stylesheets/active_scaffold_default.css~ +0 -923
  29. data/app/assets/stylesheets/active_scaffold_layout.css~ +0 -922
  30. data/app/assets/stylesheets/blue-theme.css~ +0 -1150
  31. data/config/locales/es.yml~ +0 -120
  32. data/frontends/default/views/_action_group.html.erb~ +0 -24
  33. data/frontends/default/views/_base_form.html.erb~ +0 -42
  34. data/frontends/default/views/_form.html.erb~ +0 -26
  35. data/frontends/default/views/_form_association.html.erb~ +0 -19
  36. data/frontends/default/views/_form_association_footer.html.erb~ +0 -48
  37. data/frontends/default/views/_horizontal_subform.html.erb~ +0 -32
  38. data/frontends/default/views/_horizontal_subform_header.html.erb~ +0 -11
  39. data/frontends/default/views/_horizontal_subform_record.html.erb~ +0 -38
  40. data/frontends/default/views/_list_actions.html.erb~ +0 -15
  41. data/frontends/default/views/_list_inline_adapter.html.erb~ +0 -10
  42. data/frontends/default/views/_list_messages.html.erb~ +0 -30
  43. data/frontends/default/views/_list_pagination.html.erb~ +0 -11
  44. data/frontends/default/views/_list_pagination_links.html.erb~ +0 -0
  45. data/frontends/default/views/_list_with_header.html.erb~ +0 -36
  46. data/frontends/default/views/_render_field.js.erb~ +0 -23
  47. data/frontends/default/views/_row.html.erb~ +0 -6
  48. data/frontends/default/views/_show.html.erb~ +0 -8
  49. data/frontends/default/views/_update_form.html.erb~ +0 -6
  50. data/frontends/default/views/_vertical_subform.html.erb~ +0 -12
  51. data/frontends/default/views/add_existing.js.erb~ +0 -18
  52. data/frontends/default/views/add_existing_form.html.erb~ +0 -5
  53. data/frontends/default/views/create.html.erb~ +0 -5
  54. data/frontends/default/views/edit_associated.js.erb~ +0 -13
  55. data/frontends/default/views/on_create.js.erb~ +0 -45
  56. data/frontends/default/views/on_update.js.erb~ +0 -31
  57. data/frontends/default/views/render_field.js.erb~ +0 -1
  58. data/frontends/default/views/search.html.erb~ +0 -5
  59. data/frontends/default/views/show.html.erb~ +0 -5
  60. data/frontends/default/views/update.html.erb~ +0 -8
  61. data/frontends/default/views/update_column.js.erb~ +0 -16
  62. data/lib/active_scaffold.rb~ +0 -373
  63. data/lib/active_scaffold/actions/core.rb~ +0 -203
  64. data/lib/active_scaffold/actions/create.rb~ +0 -148
  65. data/lib/active_scaffold/actions/list.rb~ +0 -196
  66. data/lib/active_scaffold/actions/nested.rb~ +0 -247
  67. data/lib/active_scaffold/actions/search.rb~ +0 -49
  68. data/lib/active_scaffold/actions/subform.rb~ +0 -27
  69. data/lib/active_scaffold/actions/update.rb~ +0 -150
  70. data/lib/active_scaffold/attribute_params.rb~ +0 -203
  71. data/lib/active_scaffold/bridges/date_picker/helper.rb~ +0 -180
  72. data/lib/active_scaffold/bridges/record_select/helpers.rb~ +0 -86
  73. data/lib/active_scaffold/bridges/shared/date_bridge.rb~ +0 -209
  74. data/lib/active_scaffold/config/base.rb~ +0 -72
  75. data/lib/active_scaffold/config/list.rb~ +0 -195
  76. data/lib/active_scaffold/config/nested.rb~ +0 -41
  77. data/lib/active_scaffold/config/search.rb~ +0 -74
  78. data/lib/active_scaffold/constraints.rb~ +0 -186
  79. data/lib/active_scaffold/data_structures/action_columns.rb~ +0 -140
  80. data/lib/active_scaffold/data_structures/action_link.rb~ +0 -179
  81. data/lib/active_scaffold/data_structures/nested_info.rb~ +0 -147
  82. data/lib/active_scaffold/extensions/action_controller_rendering.rb~ +0 -22
  83. data/lib/active_scaffold/extensions/action_view_rendering.rb~ +0 -120
  84. data/lib/active_scaffold/extensions/active_association_reflection.rb~ +0 -22
  85. data/lib/active_scaffold/extensions/cache_association.rb~ +0 -12
  86. data/lib/active_scaffold/extensions/reverse_associations.rb~ +0 -64
  87. data/lib/active_scaffold/extensions/routing_mapper.rb~ +0 -48
  88. data/lib/active_scaffold/extensions/unsaved_associated.rb~ +0 -62
  89. data/lib/active_scaffold/finder.rb~ +0 -370
  90. data/lib/active_scaffold/helpers/controller_helpers.rb~ +0 -92
  91. data/lib/active_scaffold/helpers/form_column_helpers.rb~ +0 -320
  92. data/lib/active_scaffold/helpers/id_helpers.rb~ +0 -123
  93. data/lib/active_scaffold/helpers/list_column_helpers.rb~ +0 -370
  94. data/lib/active_scaffold/helpers/search_column_helpers.rb~ +0 -263
  95. data/lib/active_scaffold/helpers/view_helpers.rb~ +0 -350
@@ -1,16 +0,0 @@
1
- <% case ActiveScaffold.js_framework %>
2
- <% when :jquery %>
3
- <% require_asset "jquery-ui" %>
4
- <% require_asset "jquery/active_scaffold" %>
5
- <% require_asset "jquery/jquery.editinplace" %>
6
- <% require_asset "jquery/date_picker_bridge" %>
7
- <% when :prototype %>
8
- <% require_asset "effects" %>
9
- <% require_asset "controls" %>
10
- <% require_asset "prototype/active_scaffold" %>
11
- <% require_asset "prototype/dhtml_history" %>
12
- <% require_asset "prototype/form_enhancements" %>
13
- <% require_asset "prototype/rico_corner" %>
14
- <% end %>
15
- <% ActiveScaffold.javascripts.each {|js| require_asset js} %>
16
- <% ActiveScaffold::Bridges.all_javascripts.each {|js| require_asset js} %>
@@ -1,1053 +0,0 @@
1
- $(document).ready(function() {
2
- $('form.as_form').live('ajax:beforeSend', function(event) {
3
- var as_form = $(this).closest("form");
4
- if (as_form && as_form.attr('data-loading') == 'true') {
5
- ActiveScaffold.disable_form(as_form);
6
- }
7
- return true;
8
- });
9
-
10
- $('form.as_form').live('ajax:complete', function(event) {
11
- var as_form = $(this).closest("form");
12
- if (as_form && as_form.attr('data-loading') == 'true') {
13
- ActiveScaffold.enable_form(as_form);
14
- }
15
- });
16
- $('form.as_form').live('ajax:error', function(event, xhr, status, error) {
17
- var as_div = $(this).closest("div.active-scaffold");
18
- if (as_div) {
19
- ActiveScaffold.report_500_response(as_div)
20
- }
21
- });
22
- $('form.as_form.as_remote_upload').live('submit', function(event) {
23
- var as_form = $(this).closest("form");
24
- if (as_form && as_form.attr('data-loading') == 'true') {
25
- setTimeout("ActiveScaffold.disable_form('" + as_form.attr('id') + "')", 10);
26
- }
27
- return true;
28
- });
29
- $('a.as_action').live('ajax:before', function(event) {
30
- var action_link = ActiveScaffold.ActionLink.get($(this));
31
- if (action_link) {
32
- if (action_link.is_disabled()) {
33
- return false;
34
- } else {
35
- if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','visible');
36
- action_link.disable();
37
- }
38
- }
39
- return true;
40
- });
41
- $('a.as_action').live('ajax:success', function(event, response) {
42
- var action_link = ActiveScaffold.ActionLink.get($(this));
43
- if (action_link) {
44
- if (action_link.position) {
45
- action_link.insert(response);
46
- if (action_link.hide_target) action_link.target.hide();
47
- } else {
48
- action_link.enable();
49
- }
50
- $(this).trigger('as:action_success', action_link);
51
- }
52
- return true;
53
- });
54
- $('a.as_action').live('ajax:complete', function(event) {
55
- var action_link = ActiveScaffold.ActionLink.get($(this));
56
- if (action_link) {
57
- if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden');
58
- }
59
- return true;
60
- });
61
- $('a.as_action').live('ajax:error', function(event, xhr, status, error) {
62
- var action_link = ActiveScaffold.ActionLink.get($(this));
63
- if (action_link) {
64
- ActiveScaffold.report_500_response(action_link.scaffold_id());
65
- action_link.enable();
66
- }
67
- return true;
68
- });
69
- $('a.as_cancel').live('ajax:before', function(event) {
70
- var as_cancel = $(this);
71
- var action_link = ActiveScaffold.find_action_link(as_cancel);
72
-
73
- if (action_link) {
74
- var cancel_url = as_cancel.attr('href');
75
- var refresh_data = as_cancel.attr('data-refresh');
76
- if (refresh_data !== 'true' || !cancel_url) {
77
- action_link.close();
78
- return false;
79
- }
80
- }
81
- return true;
82
- });
83
- $('a.as_cancel').live('ajax:success', function(event, response) {
84
- var action_link = ActiveScaffold.find_action_link($(this));
85
-
86
- if (action_link) {
87
- if (action_link.position) {
88
- action_link.close(response);
89
- } else {
90
- response.evalResponse();
91
- }
92
- }
93
- return true;
94
- });
95
- $('a.as_cancel').live('ajax:error', function(event, xhr, status, error) {
96
- var action_link = ActiveScaffold.find_action_link($(this));
97
- if (action_link) {
98
- ActiveScaffold.report_500_response(action_link.scaffold_id());
99
- }
100
- return true;
101
- });
102
- $('a.as_sort').live('ajax:before', function(event) {
103
- var as_sort = $(this);
104
- var history_controller_id = as_sort.attr('data-page-history');
105
- if (history_controller_id) addActiveScaffoldPageToHistory(as_sort.attr('href'), history_controller_id);
106
- as_sort.closest('th').addClass('loading');
107
- return true;
108
- });
109
- $('a.as_sort').live('ajax:error', function(event, xhr, status, error) {
110
- var as_scaffold = $(this).closest('.active-scaffold');
111
- ActiveScaffold.report_500_response(as_scaffold);
112
- return true;
113
- });
114
- $('span.in_place_editor_field').live('hover', function(event) {
115
- $(this).data(); // jquery 1.4.2 workaround
116
- if (event.type == 'mouseenter') {
117
- if (typeof($(this).data('editInPlace')) === 'undefined') $(this).addClass("hover");
118
- }
119
- if (event.type == 'mouseleave') {
120
- if (typeof($(this).data('editInPlace')) === 'undefined') $(this).removeClass("hover");
121
- }
122
- return true;
123
- });
124
- $('span.in_place_editor_field').live('click', function(event) {
125
- ActiveScaffold.in_place_editor_field_clicked($(this));
126
- });
127
- $('a.as_paginate').live('ajax:before',function(event) {
128
- var as_paginate = $(this);
129
- var history_controller_id = as_paginate.attr('data-page-history');
130
- if (history_controller_id) addActiveScaffoldPageToHistory(as_paginate.attr('href'), history_controller_id);
131
- as_paginate.prevAll('img.loading-indicator').css('visibility','visible');
132
- return true;
133
- });
134
- $('a.as_paginate').live('ajax:error', function(event, xhr, status, error) {
135
- var as_scaffold = $(this).closest('.active-scaffold');
136
- ActiveScaffold.report_500_response(as_scaffold);
137
- return true;
138
- });
139
- $('a.as_paginate').live('ajax:complete', function(event) {
140
- $(this).prevAll('img.loading-indicator').css('visibility','hidden');
141
- return true;
142
- });
143
- $('a.as_add_existing, a.as_replace_existing').live('ajax:before', function(event) {
144
- var id = $(this).prev().val();
145
- if (id) {
146
- if (!$(this).data('href')) $(this).data('href', $(this).attr('href'));
147
- $(this).attr('href', $(this).data('href').replace('--ID--', id));
148
- return true;
149
- } else return false;
150
- });
151
- $('input.update_form, textarea.update_form, select.update_form').live('change', function(event) {
152
- var element = $(this);
153
- var value = element.is("input:checkbox:not(:checked)") ? null : element.val();
154
- ActiveScaffold.update_column(element, element.attr('data-update_url'), element.attr('data-update_send_form'), element.attr('id'), value);
155
- return true;
156
- });
157
- $('input.recordselect.update_form').live('recordselect:change', function(event, id, label) {
158
- var element = $(this);
159
- ActiveScaffold.update_column(element, element.attr('data-update_url'), element.attr('data-update_send_form'), element.attr('id'), id);
160
- return true;
161
- });
162
-
163
- $('select.as_search_range_option').live('change', function(event) {
164
- ActiveScaffold[$(this).val() == 'BETWEEN' ? 'show' : 'hide']($(this).parent().find('.as_search_range_between'));
165
- return true;
166
- });
167
-
168
- $('select.as_search_range_option').live('change', function(event) {
169
- var element = $(this);
170
- ActiveScaffold[!(element.val() == 'PAST' || element.val() == 'FUTURE' || element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_numeric'));
171
- ActiveScaffold[(element.val() == 'PAST' || element.val() == 'FUTURE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_trend'));
172
- ActiveScaffold[(element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_range'));
173
- return true;
174
- });
175
-
176
- $('select.as_update_date_operator').live('change', function(event) {
177
- ActiveScaffold[$(this).val() == 'REPLACE' ? 'show' : 'hide']($(this).next());
178
- ActiveScaffold[$(this).val() == 'REPLACE' ? 'hide' : 'show']($(this).next().next());
179
- return true;
180
- });
181
-
182
- $('a[data-popup]').live('click', function(e) {
183
- window.open($(this).attr('href'));
184
- e.preventDefault();
185
- });
186
-
187
- $('.hover_click').live("click", function(event) {
188
- var element = $(this);
189
- var ul_element = element.children('ul').first();
190
- if (ul_element.is(':visible')) {
191
- element.find('ul').hide();
192
- } else {
193
- ul_element.show();
194
- }
195
- return false;
196
- });
197
- $('.hover_click a.as_action').live('click', function(event) {
198
- var element = $(this).closest('.hover_click');
199
- if (element) {
200
- element.find('ul').hide();
201
- }
202
- return true;
203
- });
204
- });
205
-
206
- /* Simple Inheritance
207
- http://ejohn.org/blog/simple-javascript-inheritance/
208
- */
209
- (function(){
210
- var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
211
-
212
- // The base Class implementation (does nothing)
213
- this.Class = function(){};
214
-
215
- // Create a new Class that inherits from this class
216
- Class.extend = function(prop) {
217
- var _super = this.prototype;
218
-
219
- // Instantiate a base class (but only create the instance,
220
- // don't run the init constructor)
221
- initializing = true;
222
- var prototype = new this();
223
- initializing = false;
224
-
225
- // Copy the properties over onto the new prototype
226
- for (var name in prop) {
227
- // Check if we're overwriting an existing function
228
- prototype[name] = typeof prop[name] == "function" &&
229
- typeof _super[name] == "function" && fnTest.test(prop[name]) ?
230
- (function(name, fn){
231
- return function() {
232
- var tmp = this._super;
233
-
234
- // Add a new ._super() method that is the same method
235
- // but on the super-class
236
- this._super = _super[name];
237
-
238
- // The method only need to be bound temporarily, so we
239
- // remove it when we're done executing
240
- var ret = fn.apply(this, arguments);
241
- this._super = tmp;
242
-
243
- return ret;
244
- };
245
- })(name, prop[name]) :
246
- prop[name];
247
- }
248
-
249
- // The dummy class constructor
250
- function Class() {
251
- // All construction is actually done in the init method
252
- if ( !initializing && this.init )
253
- this.init.apply(this, arguments);
254
- }
255
-
256
- // Populate our constructed prototype object
257
- Class.prototype = prototype;
258
-
259
- // Enforce the constructor to be what we expect
260
- Class.constructor = Class;
261
-
262
- // And make this class extendable
263
- Class.extend = arguments.callee;
264
-
265
- return Class;
266
- };
267
- })();
268
-
269
- /*
270
- jQuery delayed observer
271
- (c) 2007 - Maxime Haineault (max@centdessin.com)
272
-
273
- Special thanks to Stephen Goguen & Tane Piper.
274
-
275
- Slight modifications by Elliot Winkler
276
- */
277
-
278
- if (typeof(jQuery.fn.delayedObserver) === 'undefined') {
279
- (function() {
280
- var delayedObserverStack = [];
281
- var observed;
282
-
283
- function delayedObserverCallback(stackPos) {
284
- observed = delayedObserverStack[stackPos];
285
- if (observed.timer) return;
286
-
287
- observed.timer = setTimeout(function(){
288
- observed.timer = null;
289
- observed.callback(observed.obj.val(), observed.obj);
290
- }, observed.delay * 1000);
291
-
292
- observed.oldVal = observed.obj.val();
293
- }
294
-
295
- // going by
296
- // <http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx>
297
- // I think these codes only work when using keyup or keydown
298
- function isNonPrintableKey(event) {
299
- var code = event.keyCode;
300
- return (
301
- event.metaKey ||
302
- (code >= 9 && code <= 16) || (code >= 27 && code <= 40) || (code >= 91 && code <= 93) || (code >= 112 && code <= 145)
303
- );
304
- }
305
-
306
- jQuery.fn.extend({
307
- delayedObserver:function(delay, callback){
308
- $this = $(this);
309
-
310
- delayedObserverStack.push({
311
- obj: $this, timer: null, delay: delay,
312
- oldVal: $this.val(), callback: callback
313
- });
314
-
315
- stackPos = delayedObserverStack.length-1;
316
-
317
- $this.keyup(function(event) {
318
- if (isNonPrintableKey(event)) return;
319
- observed = delayedObserverStack[stackPos];
320
- if (observed.obj.val() == observed.obj.oldVal) return;
321
- else delayedObserverCallback(stackPos);
322
- });
323
- }
324
- });
325
- })();
326
- };
327
-
328
-
329
- /*
330
- * Simple utility methods
331
- */
332
-
333
- var ActiveScaffold = {
334
- records_for: function(tbody_id) {
335
- if (typeof(tbody_id) == 'string') tbody_id = '#' + tbody_id;
336
- return $(tbody_id).children('.record');
337
- },
338
- stripe: function(tbody_id) {
339
- var even = false;
340
- var rows = this.records_for(tbody_id);
341
-
342
- rows.each(function (index, row_node) {
343
- row = $(row_node);
344
- if (row_node.tagName != 'SCRIPT'
345
- && !row.hasClass("create")
346
- && !row.hasClass("update")
347
- && !row.hasClass("inline-adapter")
348
- && !row.hasClass("active-scaffold-calculations")) {
349
-
350
- if (even) row.addClass("even-record");
351
- else row.removeClass("even-record");
352
-
353
- even = !even;
354
- }
355
- });
356
- },
357
- hide_empty_message: function(tbody) {
358
- if (this.records_for(tbody).length != 0) {
359
- var empty_message_node = $(tbody).parent().find('tbody.messages p.empty-message')
360
- if (empty_message_node) empty_message_node.hide();
361
- }
362
- },
363
- reload_if_empty: function(tbody, url) {
364
- if (this.records_for(tbody).length == 0) {
365
- $.getScript(url);
366
- }
367
- },
368
- removeSortClasses: function(scaffold) {
369
- if (typeof(scaffold) == 'string') scaffold = '#' + scaffold;
370
- scaffold = $(scaffold)
371
- scaffold.find('td.sorted').each(function(element) {
372
- element.removeClass("sorted");
373
- });
374
- scaffold.find('th.sorted').each(function(element) {
375
- element.removeClass("sorted");
376
- element.removeClass("asc");
377
- element.removeClass("desc");
378
- });
379
- },
380
- decrement_record_count: function(scaffold) {
381
- // decrement the last record count, firsts record count are in nested lists
382
- if (typeof(scaffold) == 'string') scaffold = '#' + scaffold;
383
- scaffold = $(scaffold)
384
- count = scaffold.find('span.active-scaffold-records').last();
385
- if (count) count.html(parseInt(count.html(), 10) - 1);
386
- },
387
- increment_record_count: function(scaffold) {
388
- // increment the last record count, firsts record count are in nested lists
389
- if (typeof(scaffold) == 'string') scaffold = '#' + scaffold;
390
- scaffold = $(scaffold)
391
- count = scaffold.find('span.active-scaffold-records').last();
392
- if (count) count.html(parseInt(count.html(), 10) + 1);
393
- },
394
- update_row: function(row, html) {
395
- var even_row = false;
396
- var replaced = null;
397
- if (typeof(row) == 'string') row = '#' + row;
398
- row = $(row);
399
- if (row.hasClass('even-record')) even_row = true;
400
-
401
- replaced = this.replace(row, html);
402
- if (even_row === true) replaced.addClass('even-record');
403
- ActiveScaffold.highlight(replaced);
404
- },
405
-
406
- replace: function(element, html) {
407
- if (typeof(element) == 'string') element = '#' + element;
408
- element = $(element);
409
- element.replaceWith(html);
410
- if (element.attr('id')) {
411
- element = $('#' + element.attr('id'));
412
- }
413
- return element;
414
- },
415
-
416
- replace_html: function(element, html) {
417
- if (typeof(element) == 'string') element = '#' + element;
418
- element = $(element);
419
- element.html(html);
420
- return element;
421
- },
422
-
423
- remove: function(element) {
424
- if (typeof(element) == 'string') element = '#' + element;
425
- $(element).remove();
426
- },
427
-
428
- hide: function(element) {
429
- if (typeof(element) == 'string') element = '#' + element;
430
- $(element).hide();
431
- },
432
-
433
- show: function(element) {
434
- if (typeof(element) == 'string') element = '#' + element;
435
- $(element).show();
436
- },
437
-
438
- reset_form: function(element) {
439
- if (typeof(element) == 'string') element = '#' + element;
440
- $(element).get(0).reset();
441
- },
442
-
443
- disable_form: function(as_form) {
444
- if (typeof(as_form) == 'string') as_form = '#' + as_form;
445
- as_form = $(as_form)
446
- var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator'));
447
- if (loading_indicator) loading_indicator.css('visibility','visible');
448
- $('input[type=submit]', as_form).attr('disabled', 'disabled');
449
- as_form[0].disabled_fields = $("input:enabled,select:enabled,textarea:enabled", as_form).attr('disabled', 'disabled');
450
- },
451
-
452
- enable_form: function(as_form) {
453
- if (typeof(as_form) == 'string') as_form = '#' + as_form;
454
- as_form = $(as_form)
455
- var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator'));
456
- if (loading_indicator) loading_indicator.css('visibility','hidden');
457
- $('input[type=submit]', as_form).removeAttr('disabled');
458
- as_form[0].disabled_fields.removeAttr('disabled');
459
- },
460
-
461
- focus_first_element_of_form: function(form_element) {
462
- if (typeof(form_element) == 'string') form_element = '#' + form_element;
463
- $(form_element + ":first *:input[type!=hidden]:first").focus();
464
- },
465
-
466
- create_record_row: function(active_scaffold_id, html, options) {
467
- if (typeof(active_scaffold_id) == 'string') active_scaffold_id = '#' + active_scaffold_id;
468
- tbody = $(active_scaffold_id).find('tbody.records');
469
-
470
- if (options.insert_at == 'top') {
471
- tbody.prepend(html);
472
- var new_row = tbody.children('tr.record:first-child');
473
- } else if (options.insert_at == 'bottom') {
474
- var rows = tbody.children('tr.record, tr.inline-adapter');
475
- var new_row = null;
476
- if (rows.length > 0) {
477
- new_row = rows.last().after(html).next();
478
- } else {
479
- new_row = tbody.append(html).children().last();
480
- }
481
- }
482
- this.stripe(tbody);
483
- this.hide_empty_message(tbody);
484
- this.increment_record_count(tbody.closest('div.active-scaffold'));
485
- ActiveScaffold.highlight(new_row);
486
- },
487
-
488
- delete_record_row: function(row, page_reload_url) {
489
- if (typeof(row) == 'string') row = '#' + row;
490
- row = $(row);
491
- var tbody = row.closest('tbody.records');
492
-
493
- var current_action_node = row.find('td.actions a.disabled').first();
494
- if (current_action_node) {
495
- var action_link = ActiveScaffold.ActionLink.get(current_action_node);
496
- if (action_link) {
497
- action_link.close_previous_adapter();
498
- }
499
- }
500
-
501
- row.remove();
502
- this.stripe(tbody);
503
- this.decrement_record_count(tbody.closest('div.active-scaffold'));
504
- this.reload_if_empty(tbody, page_reload_url);
505
- },
506
-
507
- delete_subform_record: function(record) {
508
- if (typeof(record) == 'string') record = '#' + record;
509
- record = $(record);
510
- var errors = record.prev();
511
- if (errors.hasClass('association-record-errors')) {
512
- this.remove(errors);
513
- }
514
- var associated = $(record).next();
515
- this.remove(record);
516
- while (associated.hasClass('associated-record')) {
517
- record = associated;
518
- associated = $(record).next();
519
- this.remove(record);
520
- }
521
- },
522
-
523
- report_500_response: function(active_scaffold_id) {
524
- server_error = $(active_scaffold_id).find('td.messages-container p.server-error');
525
- if (!$(server_error).is(':visible')) {
526
- server_error.show();
527
- }
528
- },
529
-
530
- find_action_link: function(element) {
531
- if (typeof(element) == 'string') element = '#' + element;
532
- var as_adapter = $(element).closest('.as_adapter');
533
- return ActiveScaffold.ActionLink.get(as_adapter);
534
- },
535
-
536
- scroll_to: function(element) {
537
- if (typeof(element) == 'string') element = '#' + element;
538
- var form_offset = $(element).offset(),
539
- destination = form_offset.top;
540
- $(document).scrollTop(destination);
541
- },
542
-
543
- process_checkbox_inplace_edit: function(checkbox, options) {
544
- var checked = checkbox.is(':checked');
545
- if (checked === true) options['params'] += '&value=1';
546
- $.ajax({
547
- url: options.url,
548
- type: "POST",
549
- data: options['params'],
550
- dataType: options.ajax_data_type,
551
- after: function(request){
552
- checkbox.attr('disabled', 'disabled');
553
- },
554
- complete: function(request){
555
- checkbox.removeAttr('disabled');
556
- }
557
- });
558
- },
559
-
560
- read_inplace_edit_heading_attributes: function(column_heading, options) {
561
- if (column_heading.attr('data-ie_cancel_text')) options.cancel_button = '<button class="inplace_cancel">' + column_heading.attr('data-ie_cancel_text') + "</button>";
562
- if (column_heading.attr('data-ie_loading_text')) options.loading_text = column_heading.attr('data-ie_loading_text');
563
- if (column_heading.attr('data-ie_saving_text')) options.saving_text = column_heading.attr('data-ie_saving_text');
564
- if (column_heading.attr('data-ie_save_text')) options.save_button = '<button class="inplace_save">' + column_heading.attr('data-ie_save_text') + "</button>";
565
- if (column_heading.attr('data-ie_rows')) options.textarea_rows = column_heading.attr('data-ie_rows');
566
- if (column_heading.attr('data-ie_cols')) options.textarea_cols = column_heading.attr('data-ie_cols');
567
- if (column_heading.attr('data-ie_size')) options.text_size = column_heading.attr('data-ie_size');
568
- },
569
-
570
- create_inplace_editor: function(span, options) {
571
- span.removeClass('hover');
572
- span.editInPlace(options);
573
- span.trigger('click.editInPlace');
574
- },
575
-
576
- highlight: function(element) {
577
- if (typeof(element) == 'string') element = $('#' + element);
578
- if (typeof(element.effect) == 'function') {
579
- element.effect("highlight", {}, 3000);
580
- }
581
- },
582
-
583
- create_visibility_toggle: function(element, options) {
584
- if (typeof(element) == 'string') element = '#' + element;
585
- var toggable = $(element);
586
- var toggler = toggable.prev();
587
- var initial_label = (options.default_visible === true) ? options.hide_label : options.show_label;
588
-
589
- toggler.append(' (<a class="visibility-toggle" href="#">' + initial_label + '</a>)');
590
- toggler.children('a').click(function() {
591
- toggable.toggle();
592
- $(this).html((toggable.is(':hidden')) ? options.show_label : options.hide_label);
593
- return false;
594
- });
595
- },
596
-
597
- create_associated_record_form: function(element, content, options) {
598
- if (typeof(element) == 'string') element = '#' + element;
599
- var element = $(element);
600
- if (options.singular == false) {
601
- if (!(options.id && $('#' + options.id).size() > 0)) {
602
- element.append(content);
603
- }
604
- } else {
605
- var current = $('#' + element.attr('id') + ' .association-record')
606
- if (current[0]) {
607
- this.replace(current[0], content);
608
- } else {
609
- element.prepend(content);
610
- }
611
- }
612
- },
613
-
614
- render_form_field: function(source, content, options) {
615
- if (typeof(source) == 'string') source = '#' + source;
616
- var source = $(source);
617
- var element = source.closest('.association-record');
618
- if (element.length == 0) {
619
- element = source.closest('form > ol.form');
620
- }
621
- element = element.find('.' + options.field_class + ":first");
622
-
623
- if (element) {
624
- if (options.is_subform == false) {
625
- this.replace(element.closest('dl'), content);
626
- } else {
627
- this.replace_html(element, content);
628
- }
629
- }
630
- },
631
-
632
- sortable: function(element, controller, options, url_params) {
633
- if (typeof(element) == 'string') element = '#' + element;
634
- var element = $(element);
635
- var sortable_options = {};
636
- if (options.update === true) {
637
- url_params.authenticity_token = $('meta[name=csrf-param]').attr('content');
638
- sortable_options.update = function(event, ui) {
639
- var url = controller + '/' + options.action + '?'
640
- url += $(this).sortable('serialize',{key: encodeURIComponent($(this).attr('id') + '[]'), expression:/^[^_-](?:[A-Za-z0-9_-]*)-(.*)-row$/});
641
- $.post(url.append_params(url_params));
642
- }
643
- }
644
- element.sortable(sortable_options);
645
- },
646
-
647
- record_select_onselect: function(edit_associated_url, active_scaffold_id, id){
648
- $.ajax({
649
- url: edit_associated_url.split('--ID--').join(id),
650
- error: function(xhr, textStatus, errorThrown){
651
- ActiveScaffold.report_500_response(active_scaffold_id)
652
- }
653
- });
654
- },
655
-
656
- // element is tbody id
657
- mark_records: function(element, options) {
658
- if (typeof(element) == 'string') element = '#' + element;
659
- var element = $(element);
660
- var mark_checkboxes = $('#' + element.attr('id') + ' > tr.record td.marked-column input[type="checkbox"]');
661
- mark_checkboxes.each(function (index) {
662
- var item = $(this);
663
- if(options.checked === true) {
664
- item.attr('checked', 'checked');
665
- } else {
666
- item.removeAttr('checked');
667
- }
668
- item.attr('value', ('' + !options.checked));
669
- });
670
- if(options.include_mark_all === true) {
671
- var mark_all_checkbox = element.prev('thead').find('th.marked-column_heading span input[type="checkbox"]');
672
- if(options.checked === true) {
673
- mark_all_checkbox.attr('checked', 'checked');
674
- } else {
675
- mark_all_checkbox.removeAttr('checked');
676
- }
677
- mark_all_checkbox.attr('value', ('' + !options.checked));
678
- }
679
- },
680
-
681
- in_place_editor_field_clicked: function(span) {
682
- span.data(); // jquery 1.4.2 workaround
683
- if (typeof(span.data('editInPlace')) === 'undefined') {
684
- var options = {show_buttons: true,
685
- hover_class: 'hover',
686
- element_id: 'editor_id',
687
- ajax_data_type: "script",
688
- update_value: 'value'},
689
- csrf_param = $('meta[name=csrf-param]').first(),
690
- csrf_token = $('meta[name=csrf-token]').first(),
691
- my_parent = span.parent(),
692
- column_heading = null;
693
-
694
- if(!(my_parent.is('td') || my_parent.is('th'))){
695
- my_parent = span.parents('td').eq(0);
696
- }
697
-
698
- if (my_parent.is('td')) {
699
- var column_no = my_parent.prevAll('td').length;
700
- column_heading = my_parent.closest('.active-scaffold').find('th:eq(' + column_no + ')');
701
- } else if (my_parent.is('th')) {
702
- column_heading = my_parent;
703
- }
704
-
705
- var render_url = column_heading.attr('data-ie_render_url'),
706
- mode = column_heading.attr('data-ie_mode'),
707
- record_id = span.attr('data-ie_id');
708
-
709
- ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options);
710
-
711
- if (span.attr('data-ie_url')) {
712
- options.url = span.attr('data-ie_url').replace(/__id__/, record_id);
713
- } else {
714
- options.url = column_heading.attr('data-ie_url').replace(/__id__/, record_id);
715
- }
716
-
717
- if (csrf_param) options['params'] = csrf_param.attr('content') + '=' + csrf_token.attr('content');
718
-
719
- if (span.closest('div.active-scaffold').attr('data-eid')) {
720
- if (options['params'].length > 0) {
721
- options['params'] += "&";
722
- }
723
- options['params'] += ("eid=" + span.closest('div.active-scaffold').attr('data-eid'));
724
- }
725
-
726
- if (mode === 'clone') {
727
- options.clone_id_suffix = record_id;
728
- options.clone_selector = '#' + column_heading.attr('id') + ' .as_inplace_pattern';
729
- options.field_type = 'clone';
730
- }
731
-
732
- if (render_url) {
733
- var plural = false;
734
- if (column_heading.attr('data-ie_plural')) plural = true;
735
- options.field_type = 'remote';
736
- options.editor_url = render_url.replace(/__id__/, record_id)
737
- }
738
- if (mode === 'inline_checkbox') {
739
- ActiveScaffold.process_checkbox_inplace_edit(span.find('input:checkbox'), options);
740
- } else {
741
- ActiveScaffold.create_inplace_editor(span, options);
742
- }
743
- }
744
- },
745
-
746
- update_column: function(element, url, send_form, source_id, val) {
747
- if (!element) element = $('#' + source_id);
748
- var as_form = element.closest('form.as_form');
749
- var params = null;
750
-
751
- if (send_form) {
752
- params = as_form.serialize();
753
- params += '&' + $.param({"source_id": source_id});
754
- } else {
755
- params = {value: val};
756
- params.source_id = source_id;
757
- }
758
-
759
- $.ajax({
760
- url: url,
761
- data: params,
762
- beforeSend: function(event) {
763
- element.nextAll('img.loading-indicator').css('visibility','visible');
764
- ActiveScaffold.disable_form(as_form);
765
- },
766
- complete: function(event) {
767
- element.nextAll('img.loading-indicator').css('visibility','hidden');
768
- ActiveScaffold.enable_form(as_form);
769
- },
770
- error: function (xhr, status, error) {
771
- var as_div = element.closest("div.active-scaffold");
772
- if (as_div) {
773
- ActiveScaffold.report_500_response(as_div);
774
- }
775
- }
776
- });
777
- },
778
-
779
- draggable_lists: function(element) {
780
- $('#' + element).draggable_lists();
781
- }
782
- }
783
-
784
- /*
785
- * DHTML history tie-in
786
- */
787
- function addActiveScaffoldPageToHistory(url, active_scaffold_id) {
788
- if (typeof dhtmlHistory == 'undefined') return; // it may not be loaded
789
-
790
- var array = url.split('?');
791
- var qs = new Querystring(array[1]);
792
- var sort = qs.get('sort')
793
- var dir = qs.get('sort_direction')
794
- var page = qs.get('page')
795
- if (sort || dir || page) dhtmlHistory.add(active_scaffold_id+":"+page+":"+sort+":"+dir, url);
796
- }
797
-
798
- /*
799
- * URL modification support. Incomplete functionality.
800
- */
801
- String.prototype.append_params = function(params) {
802
- var url = this;
803
- if (url.indexOf('?') == -1) url += '?';
804
- else if (url.lastIndexOf('&') != url.length) url += '&';
805
-
806
- for(var key in params) {
807
- if (key) url += (key + '=' + params[key] + '&');
808
- }
809
-
810
- // the loop leaves a comma dangling at the end of string, chop it off
811
- url = url.substring(0, url.length-1);
812
- return url;
813
- };
814
-
815
-
816
- /**
817
- * A set of links. As a set, they can be controlled such that only one is "open" at a time, etc.
818
- */
819
- ActiveScaffold.Actions = new Object();
820
- ActiveScaffold.Actions.Abstract = Class.extend({
821
- init: function(links, target, loading_indicator, options) {
822
- this.target = $(target);
823
- this.loading_indicator = $(loading_indicator);
824
- this.options = options;
825
- var _this = this;
826
- this.links = $.map(links, function(link) {
827
- var my_link = _this.instantiate_link(link);
828
- return my_link;
829
- });
830
- },
831
-
832
- instantiate_link: function(link) {
833
- throw 'unimplemented'
834
- }
835
- });
836
-
837
- /**
838
- * A DataStructures::ActionLink, represented in JavaScript.
839
- * Concerned with AJAX-enabling a link and adapting the result for insertion into the table.
840
- */
841
- ActiveScaffold.ActionLink = {
842
- get: function(element) {
843
- if (typeof(element) == 'string') element = '#' + element;
844
- var element = $(element);
845
- if (element.length > 0) {
846
- element.data(); // jquery 1.4.2 workaround
847
- if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) {
848
- var parent = element.closest('.actions');
849
- if (parent.length === 0) {
850
- // maybe an column action_link
851
- parent = element.parent();
852
- }
853
- if (parent && parent.is('td')) {
854
- // record action
855
- parent = parent.closest('tr.record');
856
- var target = parent.find('a.as_action');
857
- var loading_indicator = parent.find('td.actions .loading-indicator');
858
- new ActiveScaffold.Actions.Record(target, parent, loading_indicator);
859
- } else if (parent && parent.is('div')) {
860
- //table action
861
- new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header'), parent.find('.loading-indicator'));
862
- }
863
- element = $(element);
864
- }
865
- return element.data('action_link');
866
- } else {
867
- return null;
868
- }
869
- }
870
- };
871
- ActiveScaffold.ActionLink.Abstract = Class.extend({
872
- init: function(a, target, loading_indicator) {
873
- this.tag = $(a);
874
- this.url = this.tag.attr('href');
875
- this.method = this.tag.attr('data-method') || 'get';
876
- this.target = target;
877
- this.loading_indicator = loading_indicator;
878
- this.hide_target = false;
879
- this.position = this.tag.attr('data-position');
880
- this.action = this.tag.attr('data-action');
881
-
882
- this.tag.data('action_link', this);
883
- return this;
884
- },
885
-
886
- open: function(event) {
887
- },
888
-
889
- insert: function(content) {
890
- throw 'unimplemented'
891
- },
892
-
893
- close: function() {
894
- this.enable();
895
- this.adapter.remove();
896
- if (this.hide_target) this.target.show();
897
- },
898
-
899
- reload: function() {
900
- this.close();
901
- this.open();
902
- },
903
-
904
- get_new_adapter_id: function() {
905
- var id = 'adapter_';
906
- var i = 0;
907
- while ($(id + i)) i++;
908
- return id + i;
909
- },
910
-
911
- enable: function() {
912
- return this.tag.removeClass('disabled');
913
- },
914
-
915
- disable: function() {
916
- return this.tag.addClass('disabled');
917
- },
918
-
919
- is_disabled: function() {
920
- return this.tag.hasClass('disabled');
921
- },
922
-
923
- scaffold_id: function() {
924
- return '#' + this.tag.closest('div.active-scaffold').attr('id');
925
- },
926
-
927
- scaffold: function() {
928
- return this.tag.closest('div.active-scaffold');
929
- },
930
-
931
- update_flash_messages: function(messages) {
932
- message_node = $(this.scaffold_id().replace(/-active-scaffold/, '-messages'));
933
- if (message_node) message_node.html(messages);
934
- },
935
- set_adapter: function(element) {
936
- this.adapter = element;
937
- this.adapter.addClass('as_adapter');
938
- this.adapter.data('action_link', this);
939
- if (this.refresh_url) $('.as_cancel[data-refresh=true]', this.adapter).attr('href', this.refresh_url);
940
- }
941
- });
942
-
943
- /**
944
- * Concrete classes for record actions
945
- */
946
- ActiveScaffold.Actions.Record = ActiveScaffold.Actions.Abstract.extend({
947
- instantiate_link: function(link) {
948
- var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator);
949
- var refresh = this.target.attr('data-refresh');
950
- if (refresh) l.refresh_url = refresh;
951
-
952
- if (l.position) {
953
- l.url = l.url.append_params({adapter: '_list_inline_adapter'});
954
- l.tag.attr('href', l.url);
955
- }
956
- l.set = this;
957
- return l;
958
- }
959
- });
960
-
961
- ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({
962
- close_previous_adapter: function() {
963
- var _this = this;
964
- $.each(this.set.links, function(index, item) {
965
- if (item.url != _this.url && item.is_disabled() && item.adapter) {
966
- item.enable();
967
- item.adapter.remove();
968
- }
969
- });
970
- },
971
-
972
- insert: function(content) {
973
- this.close_previous_adapter();
974
-
975
- if (this.position == 'replace') {
976
- this.position = 'after';
977
- this.hide_target = true;
978
- }
979
-
980
- if (this.position == 'after') {
981
- this.target.after(content);
982
- this.set_adapter(this.target.next());
983
- }
984
- else if (this.position == 'before') {
985
- this.target.before(content);
986
- this.set_adapter(this.target.prev());
987
- }
988
- else {
989
- return false;
990
- }
991
- ActiveScaffold.highlight(this.adapter.find('td'));
992
- },
993
-
994
- close: function(refreshed_content) {
995
- if (refreshed_content) {
996
- ActiveScaffold.update_row(this.target, refreshed_content);
997
- }
998
- this._super();
999
- },
1000
-
1001
- enable: function() {
1002
- var _this = this;
1003
- $.each(this.set.links, function(index, item) {
1004
- if (item.url != _this.url) return;
1005
- item.tag.removeClass('disabled');
1006
- });
1007
- },
1008
-
1009
- disable: function() {
1010
- var _this = this;
1011
- $.each(this.set.links, function(index, item) {
1012
- if (item.url != _this.url) return;
1013
- item.tag.addClass('disabled');
1014
- });
1015
- },
1016
-
1017
- set_opened: function() {
1018
- if (this.position == 'after') {
1019
- this.set_adapter(this.target.next());
1020
- }
1021
- else if (this.position == 'before') {
1022
- this.set_adapter(this.target.prev());
1023
- }
1024
- this.disable();
1025
- }
1026
- });
1027
-
1028
- /**
1029
- * Concrete classes for table actions
1030
- */
1031
- ActiveScaffold.Actions.Table = ActiveScaffold.Actions.Abstract.extend({
1032
- instantiate_link: function(link) {
1033
- var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator);
1034
- if (l.position) {
1035
- l.url = l.url.append_params({adapter: '_list_inline_adapter'});
1036
- l.tag.attr('href', l.url);
1037
- }
1038
- return l;
1039
- }
1040
- });
1041
-
1042
- ActiveScaffold.ActionLink.Table = ActiveScaffold.ActionLink.Abstract.extend({
1043
- insert: function(content) {
1044
- if (this.position == 'top') {
1045
- this.target.prepend(content);
1046
- this.set_adapter(this.target.children().first());
1047
- }
1048
- else {
1049
- throw 'Unknown position "' + this.position + '"'
1050
- }
1051
- ActiveScaffold.highlight(this.adapter.find('td').first().children());
1052
- }
1053
- });