active_scaffold 4.2.3 → 4.3.0

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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.rdoc +16 -1
  3. data/README.md +108 -7
  4. data/app/assets/javascripts/{jquery → active_scaffold}/active_scaffold.js +759 -762
  5. data/app/assets/javascripts/{jquery/date_picker_bridge.js.erb → active_scaffold/date_picker_bridge.js} +0 -3
  6. data/app/assets/javascripts/active_scaffold/load.js +102 -0
  7. data/app/assets/javascripts/active_scaffold.js.erb +3 -27
  8. data/app/assets/stylesheets/active_scaffold/_colours.scss +330 -0
  9. data/app/assets/stylesheets/active_scaffold/_images.scss +65 -0
  10. data/app/assets/stylesheets/{active_scaffold_layout.scss → active_scaffold/_layout.scss} +14 -0
  11. data/app/assets/stylesheets/active_scaffold/_variables.scss +194 -0
  12. data/app/assets/stylesheets/active_scaffold/core.scss +15 -0
  13. data/app/assets/stylesheets/active_scaffold.scss.erb +16 -0
  14. data/app/views/active_scaffold_overrides/_field_search_columns.html.erb +8 -0
  15. data/app/views/active_scaffold_overrides/_form.html.erb +8 -0
  16. data/app/views/active_scaffold_overrides/_form_association.html.erb +3 -1
  17. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +4 -2
  18. data/app/views/active_scaffold_overrides/_show_association.html.erb +2 -1
  19. data/app/views/active_scaffold_overrides/_show_association_horizontal.html.erb +2 -2
  20. data/app/views/active_scaffold_overrides/_show_association_vertical.html.erb +1 -1
  21. data/app/views/active_scaffold_overrides/edit_associated.js.erb +10 -8
  22. data/lib/active_scaffold/actions/core.rb +34 -3
  23. data/lib/active_scaffold/assets/css_deps_generator.rb +42 -0
  24. data/lib/active_scaffold/assets/jquery_ui_manifest.rb +77 -0
  25. data/lib/active_scaffold/assets/jquery_ui_theme_generator.rb +102 -0
  26. data/lib/active_scaffold/assets.rb +109 -0
  27. data/lib/active_scaffold/attribute_params.rb +11 -2
  28. data/lib/active_scaffold/bridges/active_storage/form_ui.rb +1 -1
  29. data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +1 -1
  30. data/lib/active_scaffold/bridges/chosen.rb +1 -1
  31. data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +1 -1
  32. data/lib/active_scaffold/bridges/file_column/form_ui.rb +1 -1
  33. data/lib/active_scaffold/bridges/paperclip/form_ui.rb +1 -1
  34. data/lib/active_scaffold/bridges/record_select/helpers.rb +1 -1
  35. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +1 -0
  36. data/lib/active_scaffold/bridges/tiny_mce.rb +6 -1
  37. data/lib/active_scaffold/bridges.rb +7 -0
  38. data/lib/active_scaffold/config/core.rb +7 -3
  39. data/lib/active_scaffold/constraints.rb +1 -1
  40. data/lib/active_scaffold/data_structures/action_columns.rb +66 -0
  41. data/lib/active_scaffold/data_structures/bridge.rb +2 -0
  42. data/lib/active_scaffold/data_structures/column.rb +3 -0
  43. data/lib/active_scaffold/engine.rb +40 -0
  44. data/lib/active_scaffold/finder.rb +1 -1
  45. data/lib/active_scaffold/helpers/assets_helpers.rb +39 -0
  46. data/lib/active_scaffold/helpers/controller_helpers.rb +1 -1
  47. data/lib/active_scaffold/helpers/form_column_helpers.rb +57 -532
  48. data/lib/active_scaffold/helpers/form_ui_helpers.rb +530 -0
  49. data/lib/active_scaffold/helpers/human_condition_helpers.rb +1 -0
  50. data/lib/active_scaffold/helpers/list_column_helpers.rb +31 -11
  51. data/lib/active_scaffold/helpers/search_column_helpers.rb +5 -12
  52. data/lib/active_scaffold/helpers/show_column_helpers.rb +4 -2
  53. data/lib/active_scaffold/helpers/view_helpers.rb +12 -0
  54. data/lib/active_scaffold/railties/tasks.rake +10 -0
  55. data/lib/active_scaffold/testing/assert_embedded_load.rb +33 -0
  56. data/lib/active_scaffold/version.rb +2 -2
  57. data/lib/active_scaffold.rb +7 -2
  58. data/lib/tasks/active_scaffold/assets.rake +42 -0
  59. data/lib/tasks/bundle.rake +25 -0
  60. data/vendor/assets/stylesheets/{jquery-ui-theme.css.erb → jquery-ui-theme.css} +17 -17
  61. metadata +26 -28
  62. data/app/assets/stylesheets/active_scaffold.scss +0 -424
  63. data/app/assets/stylesheets/active_scaffold_extensions.css.erb +0 -2
  64. data/app/assets/stylesheets/active_scaffold_images.scss +0 -65
  65. data/app/assets/stylesheets/active_scaffold_jquery_ui.css.erb +0 -13
  66. /data/app/assets/javascripts/{jquery → active_scaffold}/active_scaffold_chosen.js +0 -0
  67. /data/app/assets/javascripts/{jquery → active_scaffold}/draggable_lists.js +0 -0
  68. /data/app/assets/javascripts/{jquery → active_scaffold}/jquery.editinplace.js +0 -0
  69. /data/app/assets/javascripts/{jquery → active_scaffold}/tiny_mce_bridge.js +0 -0
@@ -1,515 +1,5 @@
1
1
  (function() {
2
2
  var activeScaffoldInit = function($, undefined) {
3
- jQuery(document).ready(function($) {
4
- /* It should not be needed, latest chrome is caching by itself
5
- if (ActiveScaffold.config.conditional_get) jQuery.ajaxSettings.ifModified = true;
6
- jQuery(document).on('ajax:beforeSend', function(event, xhr, settings){
7
- xhr.cacheUrl = settings.url;
8
- });
9
- jQuery(document).on('ajax:success', function(event, data, status, xhr){
10
- var etag=xhr.getResponseHeader("etag");
11
- if (etag && xhr.status==304) {
12
- var key = etag + xhr.cacheUrl;
13
- xhr.responseText=jQuery(document).data(key);
14
- var conv = jQuery(document).data('type-'+key);
15
- if (conv) conv(xhr.responseText);
16
- }
17
- });
18
- jQuery(document).ajaxComplete(function(event, xhr, settings){
19
- var etag=xhr.getResponseHeader("etag");
20
- if (etag && settings.ifModified && xhr.responseText) {
21
- var key = etag + xhr.cacheUrl;
22
- jQuery(document).data(key, xhr.responseText);
23
- var contentType = xhr.getResponseHeader('Content-Type');
24
- for(var s in settings.contents) {
25
- if (settings.contents[s].test(contentType)) {
26
- var conv = settings.converters['text '+s];
27
- if (typeof conv == 'function') jQuery(document).data('type-'+key, conv);
28
- break;
29
- }
30
- }
31
- }
32
- });
33
- */
34
- if (/1\.[2-7]\..*/.test(jQuery().jquery)) {
35
- var error = 'ActiveScaffold requires jquery 1.8.0 or greater, please use jquery-rails 2.1.x gem or greater';
36
- if (typeof console != 'undefined') console.error(error);
37
- else alert(error);
38
- }
39
-
40
- jQuery(document).on('focus', ':input', function() { ActiveScaffold.last_focus = this; });
41
- jQuery(document).on('blur', ':input', function(e) { ActiveScaffold.last_focus = e.relatedTarget; });
42
- jQuery(document).click(function(event) {
43
- if (!jQuery(event.target).closest('.action_group.dyn').length) {
44
- jQuery('.action_group.dyn > .dynamic-menu').each(function() {
45
- ActiveScaffold.remove_dynamic_action_group(this);
46
- });
47
- }
48
- });
49
- jQuery(document).on('ajax:beforeSend', 'form.as_form', function(event) {
50
- var as_form = jQuery(this).closest("form");
51
- if (as_form.data('loading') == true) {
52
- if (!jQuery(event.target).data('skip-disable-form')) ActiveScaffold.disable_form(as_form);
53
- }
54
- return true;
55
- });
56
-
57
- jQuery(document).on('ajax:complete', 'form.as_form', function(event) {
58
- var as_form = jQuery(this).closest("form");
59
- if (as_form.data('loading') == true) {
60
- ActiveScaffold.enable_form(as_form);
61
- }
62
- });
63
- jQuery(document).on('ajax:complete', 'form.live', function(event) {
64
- ActiveScaffold.focus_first_element_of_form(jQuery(this).closest("form"));
65
- });
66
- jQuery(document).on('keyup keypress', 'form.search.live input', function(e) {
67
- if (e.keyCode == 13) e.preventDefault();
68
- });
69
- jQuery(document).on('ajax:error', 'form.as_form', function(event, xhr, status, error) {
70
- if (event.detail && !xhr) {
71
- error = event.detail[0];
72
- status = event.detail[1];
73
- xhr = event.detail[2];
74
- }
75
- var as_div = jQuery(this).closest("div.active-scaffold");
76
- if (as_div.length) {
77
- ActiveScaffold.report_500_response(as_div, xhr);
78
- }
79
- });
80
- jQuery(document).on('submit', 'form.as_form:not([data-remote])', function(event) {
81
- var as_form = jQuery(this).closest("form"), form_id = as_form.attr('id'), iframe, interval, doc, cookie;
82
- if (as_form.data('loading') == true) {
83
- setTimeout(function() { ActiveScaffold.disable_form(form_id); }, 10);
84
- if (as_form.attr('target')) {
85
- cookie = 'as_dl_' + new Date().getTime();
86
- as_form.append(jQuery('<input>', {type: 'hidden', name: '_dl_cookie', value: cookie}));
87
- iframe = jQuery('iframe[name="' + jQuery(this).attr('target') + '"]')[0];
88
- interval = setInterval(function() {
89
- doc = iframe.contentDocument || (iframe.contentWindow && iframe.contentWindow.document);
90
- if (doc && doc.readyState !== 'loading' && (doc.location.href !== 'about:blank' || document.cookie.split(cookie+'=').length == 2)) {
91
- ActiveScaffold.enable_form(form_id);
92
- clearInterval(interval);
93
- doc.location.replace('about:blank');
94
- document.cookie = cookie + '=; path=/; expires=' + new Date().toUTCString();
95
- } else if (!doc) {
96
- clearInterval(interval);
97
- document.cookie = cookie + '=; path=/; expires=' + new Date().toUTCString();
98
- }
99
- }, 1000);
100
- }
101
- }
102
- return true;
103
- });
104
- jQuery(document).on('ajax:before', 'a.as_action[data-prompt]', function(e, xhr, settings){
105
- var link = jQuery(this), value = prompt(link.data('prompt'));
106
- if (value) {
107
- link.data('params', jQuery.param({value: value}));
108
- } else if (jQuery(this).data('prompt-required')) {
109
- e.stopImmediatePropagation();
110
- return false;
111
- } else {
112
- link.removeData('params');
113
- }
114
- return true;
115
- });
116
- jQuery(document).on('ajax:before', 'a.as_action', function(event) {
117
- var action_link = ActiveScaffold.ActionLink.get(jQuery(this));
118
- if (action_link) {
119
- if (action_link.is_disabled()) {
120
- return false;
121
- } else {
122
- if (action_link.position == 'popup') ActiveScaffold.open_popup('<div class="loading"></div>', action_link);
123
- if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','visible');
124
- action_link.disable();
125
- }
126
- }
127
- return true;
128
- });
129
- jQuery(document).on('ajax:success', 'a.as_action', function(event, response) {
130
- if (event.detail && !response) response = event.detail[0];
131
- var action_link = ActiveScaffold.ActionLink.get(jQuery(this));
132
- if (action_link) {
133
- if (action_link.position) {
134
- action_link.insert(response);
135
- if (action_link.hide_target) action_link.target.hide();
136
- if (action_link.hide_content) action_link.content.hide();
137
- } else {
138
- if (action_link.tag.hasClass('toggle')) {
139
- action_link.tag.closest('.action_group,.actions').find('.toggle.active').removeClass('active');
140
- action_link.tag.addClass('active');
141
- }
142
- action_link.enable();
143
- }
144
- jQuery(this).trigger('as:action_success', action_link);
145
- if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden');
146
- }
147
- return true;
148
- });
149
- jQuery(document).on('ajax:error', 'a.as_action', function(event, xhr, status, error) {
150
- if (event.detail && !xhr) {
151
- error = event.detail[0];
152
- status = event.detail[1];
153
- xhr = event.detail[2];
154
- }
155
- var action_link = ActiveScaffold.ActionLink.get(jQuery(this));
156
- if (action_link) {
157
- ActiveScaffold.report_500_response(action_link.scaffold_id(), xhr);
158
- if (action_link.position == 'popup') action_link.close();
159
- if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden');
160
- action_link.enable();
161
- }
162
- return true;
163
- });
164
- jQuery(document).on({
165
- 'ajax:before': function () {
166
- var $this = jQuery(this), indicator_id = $this.data('loading-indicator-id'),
167
- $indicator = indicator_id ? jQuery('#' + indicator_id) : jQuery();
168
- if (!$indicator.length) $indicator = $this.parent().find('.loading-indicator');
169
- if (!$indicator.length) $indicator = $this.closest('.active-scaffold-header').find('.loading-indicator:first');
170
- $indicator.css('visibility', 'visible');
171
- $this.data('url', jQuery('option:selected', this).data('url'));
172
- }, 'ajax:complete': function () {
173
- var $this = jQuery(this), indicator_id = $this.data('loading-indicator-id'),
174
- $indicator = indicator_id ? jQuery('#' + indicator_id) : jQuery();
175
- if (!$indicator.length) $indicator = $this.parent().find('.loading-indicator');
176
- if (!$indicator.length) $indicator = $this.closest('.active-scaffold-header').find('.loading-indicator');
177
- $indicator.css('visibility', 'hidden');
178
- }
179
- }, ':input[data-remote="url"]:not(data-url)');
180
- jQuery(document).on('ajax:before', 'a.as_cancel', function(event) {
181
- var as_cancel = jQuery(this);
182
- var action_link = ActiveScaffold.find_action_link(as_cancel);
183
-
184
- if (action_link) {
185
- var cancel_url = as_cancel.attr('href');
186
- var refresh_data = action_link.tag.data('cancel-refresh') || as_cancel.data('refresh');
187
- if (!refresh_data || !cancel_url) {
188
- action_link.close();
189
- return false;
190
- }
191
- }
192
- return true;
193
- });
194
- jQuery(document).on('ajax:success', 'a.as_cancel', function(event) {
195
- var link = jQuery(this), action_link = ActiveScaffold.find_action_link(link);
196
-
197
- if (action_link && action_link.position) {
198
- action_link.close();
199
- } else if (link.hasClass('reset')) {
200
- var form = link.closest('form');
201
- if (form.is('.search')) form.find(':input:visible:not([type=submit])').val('');
202
- else form.trigger('reset');
203
- }
204
- return true;
205
- });
206
- jQuery(document).on('ajax:error', 'a.as_cancel', function(event, xhr, status, error) {
207
- if (event.detail && !xhr) {
208
- error = event.detail[0];
209
- status = event.detail[1];
210
- xhr = event.detail[2];
211
- }
212
- var action_link = ActiveScaffold.find_action_link(jQuery(this));
213
- if (action_link) {
214
- ActiveScaffold.report_500_response(action_link.scaffold_id(), xhr);
215
- }
216
- return true;
217
- });
218
- jQuery(document).on('ajax:before', 'a.as_sort', function(event) {
219
- var as_sort = jQuery(this);
220
- as_sort.closest('th').addClass('loading');
221
- return true;
222
- });
223
- jQuery(document).on('ajax:error', 'a.as_sort', function(event, xhr, status, error) {
224
- if (event.detail && !xhr) {
225
- error = event.detail[0];
226
- status = event.detail[1];
227
- xhr = event.detail[2];
228
- }
229
- var as_scaffold = jQuery(this).closest('.active-scaffold');
230
- ActiveScaffold.report_500_response(as_scaffold, xhr);
231
- jQuery(this).closest('th').removeClass('loading');
232
- return true;
233
- });
234
- jQuery(document).on('mouseenter mouseleave', 'td.in_place_editor_field', function(event) {
235
- var td = jQuery(this), span = td.find('span.in_place_editor_field');
236
- if (event.type == 'mouseenter') {
237
- if (td.hasClass('empty') || typeof(span.data('editInPlace')) === 'undefined') td.find('span').addClass("hover");
238
- }
239
- if (event.type == 'mouseleave') {
240
- if (td.hasClass('empty') || typeof(span.data('editInPlace')) === 'undefined') td.find('span').removeClass("hover");
241
- }
242
- return true;
243
- });
244
- jQuery(document).on('click', 'td.in_place_editor_field, th.as_marked-column_heading', function(event) {
245
- var span = jQuery(this).find('span.in_place_editor_field');
246
- span.data('addEmptyOnCancel', jQuery(this).hasClass('empty'));
247
- jQuery(this).removeClass('empty');
248
- if (span.data('editInPlace')) span.trigger('click.editInPlace');
249
- else ActiveScaffold.in_place_editor_field_clicked(span);
250
- });
251
- jQuery(document).on('click', '.file-input-controls .remove-file-btn', function(event) {
252
- event.preventDefault();
253
- var btn = jQuery(this), file_line = btn.closest('.file-input-controls');
254
- if (file_line.find('.remove_file').val('true').length) {
255
- btn.parent().hide();
256
- file_line.find('input').show();
257
- if (file_line.attr('required')) file_line.find('input').attr('required', 'required');
258
- } else {
259
- file_line.remove();
260
- }
261
- return false;
262
- });
263
- jQuery(document).on('change', '.file-input-controls input[type=file]', function(event) {
264
- var file_line = jQuery(this).closest('.file-input-controls');
265
- file_line.find('.remove_file').val('false');
266
- });
267
- jQuery(document).on('ajax:before', 'a.as_paginate',function(event) {
268
- var as_paginate = jQuery(this);
269
- as_paginate.prevAll('img.loading-indicator').css('visibility','visible');
270
- return true;
271
- });
272
- jQuery(document).on('ajax:error', 'a.as_paginate', function(event, xhr, status, error) {
273
- if (event.detail && !xhr) {
274
- error = event.detail[0];
275
- status = event.detail[1];
276
- xhr = event.detail[2];
277
- }
278
- var as_scaffold = jQuery(this).closest('.active-scaffold');
279
- ActiveScaffold.report_500_response(as_scaffold, xhr);
280
- return true;
281
- });
282
- jQuery(document).on('ajax:complete', 'a.as_paginate', function(event) {
283
- jQuery(this).prevAll('img.loading-indicator').css('visibility','hidden');
284
- return true;
285
- });
286
- jQuery(document).on('ajax:before', 'a.as_add_existing, a.as_replace_existing', function(event) {
287
- var prev = jQuery(this).prev();
288
- if (!prev.is(':input')) prev = prev.find(':input');
289
- var id = prev.val();
290
- if (id) {
291
- if (!jQuery(this).data('href')) jQuery(this).data('href', jQuery(this).attr('href'));
292
- jQuery(this).attr('href', jQuery(this).data('href').replace('--ID--', id));
293
- return true;
294
- } else return false;
295
- });
296
- jQuery(document).on('ajax:complete', '.action_group.dyn > .dynamic-menu a', function(event) {
297
- var action_link = ActiveScaffold.find_action_link(event.target), link = jQuery(event.target);
298
- if (action_link && action_link.loading_indicator) action_link.loading_indicator.css('visibility', 'hidden');
299
- setTimeout(function() {
300
- if (!link.parent().is('.action_group.dyn')) {
301
- ActiveScaffold.remove_dynamic_action_group(link.closest('.action_group.dyn > .dynamic-menu'));
302
- }
303
- }, 100);
304
- });
305
-
306
- jQuery(document).on('change', 'input.update_form:not(.recordselect), textarea.update_form, select.update_form, .checkbox-list.update_form input:checkbox', function(event, additional_params) {
307
- var element = jQuery(this);
308
- var form_element;
309
- var value;
310
- if (element.is(".checkbox-list input:checkbox")) {
311
- form_element = element.closest('.checkbox-list');
312
- if (form_element.is('.draggable-list')) form_element = form_element.closest('.draggable-lists-container').find('.checkbox-list') // draggable lists will have 2 lists
313
- value = form_element.find(':checked').map(function(item) { return jQuery(this).val(); }).toArray();
314
- if (!additional_params) additional_params = (element.is(':checked') ? '_added=' : '_removed=') + element.val();
315
- } else {
316
- value = element.is("input:checkbox:not(:checked)") ? null : element.val();
317
- form_element = element;
318
- }
319
- ActiveScaffold.update_column(form_element, form_element.data('update_url'), form_element.data('update_send_form'), element.attr('id'), value, additional_params);
320
- return true;
321
- });
322
- jQuery(document).on('click', 'a.refresh-link', function(event) {
323
- event.preventDefault();
324
- var element = jQuery(this), selector = element.data('field-selector'), value, form_element;
325
- form_element = selector.startsWith('#') ? jQuery(selector) : element.closest('.form-element').find(selector);
326
- if (form_element.is('.draggable-list')) form_element = form_element.closest('.draggable-lists-container');
327
- if (form_element.is(".field_with_errors")) form_element = form_element.children().last();
328
- if (form_element.is(".checkbox-list")) {
329
- value = form_element.find(':checked').map(function(item) { return jQuery(this).val(); }).toArray();
330
- form_element = form_element.parent().find("input:checkbox"); // parent is needed for draggable-list, checked list may be empty
331
- } else if (form_element.is(':radio, :checkbox')) value = form_element.filter(':checked').val() || null;
332
- else value = form_element.val();
333
- ActiveScaffold.update_column(form_element, element.attr('href'), element.data('update_send_form'), form_element.attr('id'), value);
334
- });
335
- jQuery(document).on('click', 'a.visibility-toggle', function(e) {
336
- var link = jQuery(this), toggable = jQuery('#' + link.data('toggable'));
337
- e.preventDefault();
338
- toggable.toggle();
339
- link.html((toggable.is(':hidden')) ? link.data('show') : link.data('hide'));
340
- return false;
341
- });
342
- jQuery(document).on('recordselect:change', 'input.recordselect.update_form', function(event, id, label) {
343
- var element = jQuery(this);
344
- ActiveScaffold.update_column(element, element.data('update_url'), element.data('update_send_form'), element.attr('id'), id);
345
- return true;
346
- });
347
-
348
- jQuery(document).on('change', 'select.as_search_range_option', function(event) {
349
- var element = jQuery(this);
350
- ActiveScaffold[element.val() == 'BETWEEN' ? 'show' : 'hide'](element.closest('dd').find('.as_search_range_between'));
351
- ActiveScaffold[(element.val() == 'null' || element.val() == 'not_null') ? 'hide' : 'show'](element.attr('id').replace(/_opt/, '_numeric'));
352
- return true;
353
- });
354
-
355
- jQuery(document).on('change', 'select.as_search_date_time_option', function(event) {
356
- var element = jQuery(this);
357
- ActiveScaffold[!(element.val() == 'PAST' || element.val() == 'FUTURE' || element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_numeric'));
358
- ActiveScaffold[(element.val() == 'PAST' || element.val() == 'FUTURE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_trend'));
359
- ActiveScaffold[(element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_range'));
360
- return true;
361
- });
362
-
363
- jQuery(document).on('click', '.active-scaffold .sub-form a.destroy', function(event) {
364
- event.preventDefault();
365
- ActiveScaffold.remove(jQuery(this).closest('.sub-form-record'));
366
- });
367
-
368
- jQuery(document).on("click", '.hover_click', function(event) {
369
- var element = jQuery(this);
370
- var ul_element = element.children('ul').first();
371
- if (ul_element.is(':visible')) {
372
- element.find('ul').hide();
373
- } else {
374
- ul_element.show();
375
- }
376
- return false;
377
- });
378
- jQuery(document).on('click', '.hover_click a.as_action', function(event) {
379
- var element = jQuery(this).closest('.hover_click');
380
- if (element.length) {
381
- element.find('ul').hide();
382
- }
383
- return true;
384
- });
385
-
386
- jQuery(document).on('click', '.message a.close', function(e) {
387
- ActiveScaffold.hide(jQuery(this).closest('.message'));
388
- e.preventDefault();
389
- });
390
-
391
- jQuery(document).on('click', 'form.as_form .no-color', function() {
392
- var color_field = jQuery(this).parent().next(':input');
393
- color_field.attr('type', jQuery(this).prop('checked') ? 'hidden' : 'color');
394
- if (jQuery(this).prop('checked')) color_field.val('');
395
- });
396
-
397
- jQuery(document).on('click', '.hide-new-subform, .show-new-subform', function(e) {
398
- var $this = jQuery(this), line = $this.closest('.form-element'),
399
- subform = line.find('#' + $this.data('subform-id')), radio = false, hide, field;
400
- if ($this.is('[type=radio]')) {
401
- radio = true;
402
- hide = $this.is('.hide-new-subform');
403
- } else {
404
- e.preventDefault();
405
- hide = subform.is(':visible');
406
- }
407
- if ($this.data('select-id')) {
408
- field = line.find('#' + $this.data('select-id')).closest('.select-field');
409
- }
410
- if (hide) {
411
- subform.hide().find("input:enabled,select:enabled,textarea:enabled").prop('disabled', true);
412
- if (field) field.show().find('input:disabled,select:disabled,textarea:disabled').prop('disabled', false);
413
- if (radio) {
414
- $this.closest('.form-element').find('[name="' + $this.attr('name') + '"].show-new-subform').prop('disabled', false);
415
- } else $this.html($this.data('select-text'));
416
- } else {
417
- if (field) field.hide().find('input:enabled,select:enabled,textarea:enabled').prop('disabled', true);
418
- subform.show().find("input:disabled,select:disabled,textarea:disabled").prop('disabled', false);
419
- if (radio) $this.prop('disabled', true);
420
- else {
421
- $this.data('select-text', $this.html());
422
- $this.html($this.data('subform-text'));
423
- }
424
- }
425
- });
426
-
427
- jQuery(document).on('input paste', 'form.search.live input[type=search]', $.debounce((ActiveScaffold.config.live_search_delay || 0.5) * 1000, function() {
428
- jQuery(this).parent().find('[type=submit]').click();
429
- }));
430
-
431
- jQuery(document).on('click', 'form.search [data-reset]', function(e){
432
- e.preventDefault();
433
- var form = jQuery(this).closest('form.search');
434
- form.find(
435
- 'input:not([type=button]):not([type=submit]):not([type=reset]):not([type=hidden]),' +
436
- 'textarea, select:has(option[value=""])'
437
- ).val('');
438
- form.find('select.as_search_range_option').each(function() { jQuery(this).val(jQuery(this).find('option:first').val()) });
439
- form.find('select.as_search_date_time_option').val('BETWEEN');
440
- });
441
-
442
- jQuery(document).on('click', '.active-scaffold .tabbed .nav-tabs a', function(e) {
443
- if (typeof jQuery().tab == 'function') return; // bootstrap tab plugin is loaded and will handle tabs
444
- e.preventDefault();
445
- var tab_ctrl = jQuery(this), tabbed = tab_ctrl.closest('.tabbed')
446
- tabbed.find('.nav-tabs .active').removeClass('active');
447
- tabbed.find('.tab-content .active').removeClass('in active');
448
- tab_ctrl.closest('li').addClass('active');
449
- jQuery(tab_ctrl.attr('href')).addClass('in active');
450
- });
451
-
452
- jQuery(document).on('turbolinks:before-visit turbo:before-visit', function() {
453
- if (history.state.active_scaffold) {
454
- history.replaceState({turbolinks: true, url: document.location.href}, '', document.location.href);
455
- }
456
- });
457
-
458
- jQuery(window).on('popstate', function(e) {
459
- var state = e.originalEvent.state;
460
- if (!state || !state.active_scaffold) return;
461
- jQuery.ajax({
462
- url: document.location.href,
463
- data: jQuery.extend({'_popstate': true}, state.active_scaffold),
464
- dataType: 'script',
465
- cache: true
466
- });
467
- jQuery('.active-scaffold:first th .as_sort:first').closest('th').addClass('loading');
468
- });
469
-
470
- // call setup on document.ready if Turbolinks not enabled
471
- if ((typeof(Turbolinks) == 'undefined' || !Turbolinks.supported) && typeof(Turbo) == 'undefined') {
472
- ActiveScaffold.setup_history_state();
473
- ActiveScaffold.setup(document);
474
- }
475
- if (ActiveScaffold.config.warn_changes) ActiveScaffold.setup_warn_changes();
476
- jQuery(document).on('as:element_updated as:element_created', function(e, action_link) {
477
- ActiveScaffold.setup(e.target);
478
- });
479
- jQuery(document).on('as:element_removed', function(e, action_link) {
480
- setTimeout(ActiveScaffold.update_floating_form_footer); // delay so form is already removed
481
- });
482
- jQuery(document).on('as:action_success', 'a.as_action', function(e, action_link) {
483
- if (action_link.adapter) ActiveScaffold.setup(action_link.adapter);
484
- });
485
- jQuery(document).on('as:element_updated', '.active-scaffold', function(e) {
486
- if (e.target != this) return;
487
- var search = jQuery(this).find('form.search');
488
- if (search.length) ActiveScaffold.focus_first_element_of_form(search);
489
- });
490
- jQuery(document).on('click', '.active-scaffold form .check-all', function(e) {
491
- e.preventDefault();
492
- ActiveScaffold.update_all_checkboxes(jQuery(this), true);
493
- });
494
- jQuery(document).on('click', '.active-scaffold form .uncheck-all', function(e) {
495
- e.preventDefault();
496
- ActiveScaffold.update_all_checkboxes(jQuery(this), false);
497
- });
498
- jQuery(document).on('click', '.descriptions-click .description:not(.visible)', function(e) {
499
- e.preventDefault();
500
- $(this).addClass('visible');
501
- });
502
- jQuery(document).on('click', '.descriptions-click .description.visible .close', function(e) {
503
- e.preventDefault();
504
- $(this).closest('.description').removeClass('visible');
505
- });
506
- });
507
-
508
- jQuery(document).on('turbolinks:load turbo:load', function($) {
509
- ActiveScaffold.setup(document);
510
- });
511
-
512
-
513
3
  /* Simple JavaScript Inheritance for ES 5.1
514
4
  * based on http://ejohn.org/blog/simple-javascript-inheritance/
515
5
  * (inspired by base2 and Prototype)
@@ -581,7 +71,7 @@
581
71
  * Simple utility methods
582
72
  */
583
73
 
584
- window.ActiveScaffold = {
74
+ window.ActiveScaffold = Object.assign(window.ActiveScaffold || {}, {
585
75
  last_focus: null,
586
76
  setup_callbacks: [],
587
77
  setup: function(container) {
@@ -1319,10 +809,7 @@
1319
809
  ActiveScaffold.remove(link.adapter, callback);
1320
810
  link.set_adapter(null);
1321
811
  }
1322
- }
1323
-
1324
-
1325
- jQuery(window).on('scroll resize', ActiveScaffold.update_floating_form_footer);
812
+ });
1326
813
 
1327
814
  /*
1328
815
  * URL modification support. Incomplete functionality.
@@ -1352,296 +839,806 @@
1352
839
  this.loading_indicator = jQuery(loading_indicator);
1353
840
  this.options = options;
1354
841
  var _this = this;
1355
- this.links = jQuery.map(links, function(link) {
1356
- return _this.instantiate_link(link);
842
+ this.links = jQuery.map(links, function(link) {
843
+ return _this.instantiate_link(link);
844
+ });
845
+ },
846
+
847
+ instantiate_link: function(link) {
848
+ throw 'unimplemented'
849
+ }
850
+ });
851
+
852
+ /**
853
+ * A DataStructures::ActionLink, represented in JavaScript.
854
+ * Concerned with AJAX-enabling a link and adapting the result for insertion into the table.
855
+ */
856
+ ActiveScaffold.ActionLink = {
857
+ get: function(element) {
858
+ if (typeof(element) == 'string') element = '#' + element;
859
+ element = jQuery(element);
860
+ if (element.length > 0) {
861
+ element.data(); // $ 1.4.2 workaround
862
+ if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) {
863
+ var parent = element.parent().closest('.record');
864
+ if (parent.length === 0) parent = element.parent().closest('.actions');
865
+ if (parent.length === 0) parent = element.parent().closest('form.as_form');
866
+ if (parent.is('.record')) {
867
+ // record action
868
+ var target = parent.find('a.as_action');
869
+ var loading_indicator = parent.find('.actions .loading-indicator');
870
+ if (!loading_indicator.length) loading_indicator = element.parent().find('.loading-indicator');
871
+ new ActiveScaffold.Actions.Record(target, parent, loading_indicator);
872
+ } else if (parent.is('.active-scaffold-header .actions')) {
873
+ //table action
874
+ new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header').first(), parent.find('.loading-indicator').first());
875
+ } else if (parent.is('form.as_form')) {
876
+ //table action
877
+ new ActiveScaffold.Actions.Table(parent.find('a.as_action').filter(function() { return !jQuery(this).data('action_link'); }), parent.closest('div.active-scaffold').find('tbody.before-header').first(), parent.find('.form-footer .loading-indicator').first());
878
+ }
879
+ element = jQuery(element);
880
+ }
881
+ return element.data('action_link');
882
+ } else {
883
+ return null;
884
+ }
885
+ }
886
+ };
887
+ ActiveScaffold.ActionLink.Abstract = Class.extend({
888
+ init: function(a, target, loading_indicator) {
889
+ this.tag = jQuery(a);
890
+ this.url = this.tag.attr('href');
891
+ this.method = this.tag.data('method') || 'get';
892
+ this.target = target;
893
+ this.content = target.closest('.active-scaffold').find('.as_content:first');
894
+ this.loading_indicator = loading_indicator;
895
+ this.hide_target = false;
896
+ this.position = this.tag.data('position');
897
+ this.action = this.tag.data('action');
898
+
899
+ this.tag.data('action_link', this);
900
+ return this;
901
+ },
902
+
903
+ open: function(event) {
904
+ this.tag.click();
905
+ },
906
+
907
+ insert: function(content) {
908
+ throw 'unimplemented'
909
+ },
910
+
911
+ close: function() {
912
+ var link = this, callback = function() {
913
+ link.enable();
914
+ if (link.hide_target) link.target.show();
915
+ if (link.hide_content) link.content.show();
916
+ if (ActiveScaffold.config.scroll_on_close) {
917
+ ActiveScaffold.scroll_to(link.target.attr('id'), ActiveScaffold.config.scroll_on_close === 'checkInViewport');
918
+ }
919
+ };
920
+ if (this.position === 'popup') {
921
+ ActiveScaffold.close_popup(this, callback);
922
+ } else if (this.adapter) {
923
+ ActiveScaffold.remove(this.adapter, callback);
924
+ }
925
+ },
926
+
927
+ reload: function() {
928
+ this.close();
929
+ this.open();
930
+ },
931
+
932
+ get_new_adapter_id: function() {
933
+ var id = 'adapter_';
934
+ var i = 0;
935
+ while (jQuery(id + i)) i++;
936
+ return id + i;
937
+ },
938
+
939
+ enable: function() {
940
+ return this.tag.removeClass('disabled');
941
+ },
942
+
943
+ disable: function() {
944
+ return this.tag.addClass('disabled');
945
+ },
946
+
947
+ is_disabled: function() {
948
+ return this.tag.hasClass('disabled');
949
+ },
950
+
951
+ scaffold_id: function() {
952
+ const div_id = this.scaffold().attr('id');
953
+ if (div_id) return '#' + div_id;
954
+ },
955
+
956
+ scaffold: function() {
957
+ return this.tag.closest('div.active-scaffold');
958
+ },
959
+
960
+ messages: function() {
961
+ const re = /-active-scaffold$/, div_id = this.scaffold_id();
962
+
963
+ if (re.test(div_id)) {
964
+ return jQuery(div_id.replace(re, '-messages'));
965
+ } else {
966
+ var messages_container = this.scaffold().find('.messages-container'),
967
+ messages = messages_container.find('.action-messages');
968
+ if (!messages.length) messages = jQuery('<div class="action-messages"></div>').appendTo(messages_container);
969
+ return messages;
970
+ }
971
+ },
972
+
973
+ update_flash_messages: function(messages) {
974
+ this.messages().html(messages);
975
+ },
976
+
977
+ set_adapter: function(element) {
978
+ this.adapter = element;
979
+ if (element) {
980
+ this.adapter.addClass('as_adapter');
981
+ this.adapter.data('action_link', this);
982
+ if (this.refresh_url) jQuery('.as_cancel', this.adapter).attr('href', this.refresh_url);
983
+ }
984
+ },
985
+
986
+ keep_open: function() {
987
+ return this.tag.data('keep-open');
988
+ }
989
+ });
990
+
991
+ /**
992
+ * Concrete classes for record actions
993
+ */
994
+ ActiveScaffold.Actions.Record = ActiveScaffold.Actions.Abstract.extend({
995
+ instantiate_link: function(link) {
996
+ var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator);
997
+ var refresh = this.target.data('refresh');
998
+ if (refresh) l.refresh_url = this.target.closest('.records').data('refresh-record').replace('--ID--', refresh);
999
+
1000
+ if (l.position) {
1001
+ l.url = l.url.append_params({adapter: l.position == 'popup' ? '_popup_adapter' : '_list_inline_adapter'});
1002
+ l.tag.attr('href', l.url);
1003
+ }
1004
+ l.set = this;
1005
+ return l;
1006
+ }
1007
+ });
1008
+
1009
+ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({
1010
+ close_previous_adapter: function() {
1011
+ var _this = this;
1012
+ jQuery.each(this.set.links, function(index, item) {
1013
+ if (item.url != _this.url && item.is_disabled() && !item.keep_open() && item.adapter) {
1014
+ ActiveScaffold.remove(item.adapter, function () { item.enable(); });
1015
+ }
1016
+ });
1017
+ },
1018
+
1019
+ insert: function(content) {
1020
+ this.close_previous_adapter();
1021
+
1022
+ if (this.position === 'replace') {
1023
+ this.position = 'after';
1024
+ this.hide_target = true;
1025
+ } else if (this.position === 'table') {
1026
+ this.hide_content = true;
1027
+ } else if (this.position === 'popup') {
1028
+ return ActiveScaffold.open_popup(content, this);
1029
+ }
1030
+
1031
+ var colspan = this.target.children().length;
1032
+ if (content && this.position) {
1033
+ content = jQuery(content);
1034
+ content.find('.inline-adapter-cell:first').attr('colspan', colspan);
1035
+ }
1036
+ if (this.position === 'after') {
1037
+ this.target.after(content);
1038
+ this.set_adapter(this.target.next());
1039
+ } else if (this.position === 'before') {
1040
+ this.target.before(content);
1041
+ this.set_adapter(this.target.prev());
1042
+ } else if (this.position === 'table') {
1043
+ var content_parent = this.target.closest('div.active-scaffold').find('tbody.before-header').first()
1044
+ content_parent.prepend(content);
1045
+ this.set_adapter(content_parent.children().first())
1046
+ } else {
1047
+ return false;
1048
+ }
1049
+ ActiveScaffold.highlight(this.adapter.find('td'));
1050
+ ActiveScaffold.focus_first_element_of_form(this.adapter);
1051
+ },
1052
+
1053
+ close: function(refreshed_content_or_reload) {
1054
+ this._super();
1055
+ if (refreshed_content_or_reload) {
1056
+ if (typeof refreshed_content_or_reload == 'string') this.refresh(refreshed_content_or_reload);
1057
+ else this.refresh();
1058
+ }
1059
+ },
1060
+
1061
+ refresh: function(content) {
1062
+ if (content) {
1063
+ ActiveScaffold.update_row(this.target, content);
1064
+ } else if (this.refresh_url) {
1065
+ var target = this.target;
1066
+ jQuery.get(this.refresh_url, function(e, status, xhr) {
1067
+ ActiveScaffold.update_row(target, xhr.responseText);
1068
+ });
1069
+ }
1070
+ },
1071
+
1072
+ enable: function() {
1073
+ var _this = this;
1074
+ jQuery.each(this.set.links, function(index, item) {
1075
+ if (item.url != _this.url) return;
1076
+ item.tag.removeClass('disabled');
1077
+ });
1078
+ },
1079
+
1080
+ disable: function() {
1081
+ var _this = this;
1082
+ jQuery.each(this.set.links, function(index, item) {
1083
+ if (item.url != _this.url) return;
1084
+ item.tag.addClass('disabled');
1357
1085
  });
1358
1086
  },
1359
1087
 
1360
- instantiate_link: function(link) {
1361
- throw 'unimplemented'
1088
+ set_opened: function() {
1089
+ if (this.position === 'after') {
1090
+ this.set_adapter(this.target.next());
1091
+ }
1092
+ else if (this.position === 'before') {
1093
+ this.set_adapter(this.target.prev());
1094
+ }
1095
+ this.disable();
1362
1096
  }
1363
1097
  });
1364
1098
 
1365
1099
  /**
1366
- * A DataStructures::ActionLink, represented in JavaScript.
1367
- * Concerned with AJAX-enabling a link and adapting the result for insertion into the table.
1100
+ * Concrete classes for table actions
1368
1101
  */
1369
- ActiveScaffold.ActionLink = {
1370
- get: function(element) {
1371
- if (typeof(element) == 'string') element = '#' + element;
1372
- element = jQuery(element);
1373
- if (element.length > 0) {
1374
- element.data(); // $ 1.4.2 workaround
1375
- if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) {
1376
- var parent = element.parent().closest('.record');
1377
- if (parent.length === 0) parent = element.parent().closest('.actions');
1378
- if (parent.length === 0) parent = element.parent().closest('form.as_form');
1379
- if (parent.is('.record')) {
1380
- // record action
1381
- var target = parent.find('a.as_action');
1382
- var loading_indicator = parent.find('.actions .loading-indicator');
1383
- if (!loading_indicator.length) loading_indicator = element.parent().find('.loading-indicator');
1384
- new ActiveScaffold.Actions.Record(target, parent, loading_indicator);
1385
- } else if (parent.is('.active-scaffold-header .actions')) {
1386
- //table action
1387
- new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header').first(), parent.find('.loading-indicator').first());
1388
- } else if (parent.is('form.as_form')) {
1389
- //table action
1390
- new ActiveScaffold.Actions.Table(parent.find('a.as_action').filter(function() { return !jQuery(this).data('action_link'); }), parent.closest('div.active-scaffold').find('tbody.before-header').first(), parent.find('.form-footer .loading-indicator').first());
1391
- }
1392
- element = jQuery(element);
1393
- }
1394
- return element.data('action_link');
1102
+ ActiveScaffold.Actions.Table = ActiveScaffold.Actions.Abstract.extend({
1103
+ instantiate_link: function(link) {
1104
+ var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator);
1105
+ if (l.position) {
1106
+ l.url = l.url.append_params({adapter: l.position == 'popup' ? '_popup_adapter' : '_list_inline_adapter'});
1107
+ l.tag.attr('href', l.url);
1108
+ }
1109
+ return l;
1110
+ }
1111
+ });
1112
+
1113
+ ActiveScaffold.ActionLink.Table = ActiveScaffold.ActionLink.Abstract.extend({
1114
+ insert: function(content) {
1115
+ if (this.position == 'replace') {
1116
+ this.position = 'top';
1117
+ this.hide_content = true;
1118
+ } else if (this.position == 'popup') {
1119
+ return ActiveScaffold.open_popup(content, this);
1120
+ }
1121
+
1122
+ if (this.position == 'top') {
1123
+ this.target.prepend(content);
1124
+ this.set_adapter(this.target.children().first());
1395
1125
  } else {
1396
- return null;
1126
+ throw 'Unknown position "' + this.position + '"'
1397
1127
  }
1128
+ ActiveScaffold.highlight(this.adapter.find('td').first().children().not('script'));
1129
+ ActiveScaffold.focus_first_element_of_form(this.adapter);
1398
1130
  }
1399
- };
1400
- ActiveScaffold.ActionLink.Abstract = Class.extend({
1401
- init: function(a, target, loading_indicator) {
1402
- this.tag = jQuery(a);
1403
- this.url = this.tag.attr('href');
1404
- this.method = this.tag.data('method') || 'get';
1405
- this.target = target;
1406
- this.content = target.closest('.active-scaffold').find('.as_content:first');
1407
- this.loading_indicator = loading_indicator;
1408
- this.hide_target = false;
1409
- this.position = this.tag.data('position');
1410
- this.action = this.tag.data('action');
1131
+ });
1411
1132
 
1412
- this.tag.data('action_link', this);
1413
- return this;
1414
- },
1133
+ jQuery(document).ready(function($) {
1134
+ /* It should not be needed, latest chrome is caching by itself
1135
+ if (ActiveScaffold.config.conditional_get) jQuery.ajaxSettings.ifModified = true;
1136
+ jQuery(document).on('ajax:beforeSend', function(event, xhr, settings){
1137
+ xhr.cacheUrl = settings.url;
1138
+ });
1139
+ jQuery(document).on('ajax:success', function(event, data, status, xhr){
1140
+ var etag=xhr.getResponseHeader("etag");
1141
+ if (etag && xhr.status==304) {
1142
+ var key = etag + xhr.cacheUrl;
1143
+ xhr.responseText=jQuery(document).data(key);
1144
+ var conv = jQuery(document).data('type-'+key);
1145
+ if (conv) conv(xhr.responseText);
1146
+ }
1147
+ });
1148
+ jQuery(document).ajaxComplete(function(event, xhr, settings){
1149
+ var etag=xhr.getResponseHeader("etag");
1150
+ if (etag && settings.ifModified && xhr.responseText) {
1151
+ var key = etag + xhr.cacheUrl;
1152
+ jQuery(document).data(key, xhr.responseText);
1153
+ var contentType = xhr.getResponseHeader('Content-Type');
1154
+ for(var s in settings.contents) {
1155
+ if (settings.contents[s].test(contentType)) {
1156
+ var conv = settings.converters['text '+s];
1157
+ if (typeof conv == 'function') jQuery(document).data('type-'+key, conv);
1158
+ break;
1159
+ }
1160
+ }
1161
+ }
1162
+ });
1163
+ */
1164
+ if (/1\.[2-7]\..*/.test(jQuery().jquery)) {
1165
+ var error = 'ActiveScaffold requires jquery 1.8.0 or greater, please use jquery-rails 2.1.x gem or greater';
1166
+ if (typeof console != 'undefined') console.error(error);
1167
+ else alert(error);
1168
+ }
1415
1169
 
1416
- open: function(event) {
1417
- this.tag.click();
1418
- },
1170
+ jQuery(document).on('focus', ':input', function() { ActiveScaffold.last_focus = this; });
1171
+ jQuery(document).on('blur', ':input', function(e) { ActiveScaffold.last_focus = e.relatedTarget; });
1172
+ jQuery(document).click(function(event) {
1173
+ if (!jQuery(event.target).closest('.action_group.dyn').length) {
1174
+ jQuery('.action_group.dyn > .dynamic-menu').each(function() {
1175
+ ActiveScaffold.remove_dynamic_action_group(this);
1176
+ });
1177
+ }
1178
+ });
1179
+ jQuery(document).on('ajax:beforeSend', 'form.as_form', function(event) {
1180
+ var as_form = jQuery(this).closest("form");
1181
+ if (as_form.data('loading') == true) {
1182
+ if (!jQuery(event.target).data('skip-disable-form')) ActiveScaffold.disable_form(as_form);
1183
+ }
1184
+ return true;
1185
+ });
1419
1186
 
1420
- insert: function(content) {
1421
- throw 'unimplemented'
1422
- },
1187
+ jQuery(document).on('ajax:complete', 'form.as_form', function(event) {
1188
+ var as_form = jQuery(this).closest("form");
1189
+ if (as_form.data('loading') == true) {
1190
+ ActiveScaffold.enable_form(as_form);
1191
+ }
1192
+ });
1193
+ jQuery(document).on('ajax:complete', 'form.live', function(event) {
1194
+ ActiveScaffold.focus_first_element_of_form(jQuery(this).closest("form"));
1195
+ });
1196
+ jQuery(document).on('keyup keypress', 'form.search.live input', function(e) {
1197
+ if (e.keyCode == 13) e.preventDefault();
1198
+ });
1199
+ jQuery(document).on('ajax:error', 'form.as_form', function(event, xhr, status, error) {
1200
+ if (event.detail && !xhr) {
1201
+ error = event.detail[0];
1202
+ status = event.detail[1];
1203
+ xhr = event.detail[2];
1204
+ }
1205
+ var as_div = jQuery(this).closest("div.active-scaffold");
1206
+ if (as_div.length) {
1207
+ ActiveScaffold.report_500_response(as_div, xhr);
1208
+ }
1209
+ });
1210
+ jQuery(document).on('submit', 'form.as_form:not([data-remote])', function(event) {
1211
+ var as_form = jQuery(this).closest("form"), form_id = as_form.attr('id'), iframe, interval, doc, cookie;
1212
+ if (as_form.data('loading') == true) {
1213
+ setTimeout(function() { ActiveScaffold.disable_form(form_id); }, 10);
1214
+ if (as_form.attr('target')) {
1215
+ cookie = 'as_dl_' + new Date().getTime();
1216
+ as_form.append(jQuery('<input>', {type: 'hidden', name: '_dl_cookie', value: cookie}));
1217
+ iframe = jQuery('iframe[name="' + jQuery(this).attr('target') + '"]')[0];
1218
+ interval = setInterval(function() {
1219
+ doc = iframe.contentDocument || (iframe.contentWindow && iframe.contentWindow.document);
1220
+ if (doc && doc.readyState !== 'loading' && (doc.location.href !== 'about:blank' || document.cookie.split(cookie+'=').length == 2)) {
1221
+ ActiveScaffold.enable_form(form_id);
1222
+ clearInterval(interval);
1223
+ doc.location.replace('about:blank');
1224
+ document.cookie = cookie + '=; path=/; expires=' + new Date().toUTCString();
1225
+ } else if (!doc) {
1226
+ clearInterval(interval);
1227
+ document.cookie = cookie + '=; path=/; expires=' + new Date().toUTCString();
1228
+ }
1229
+ }, 1000);
1230
+ }
1231
+ }
1232
+ return true;
1233
+ });
1234
+ jQuery(document).on('ajax:before', 'a.as_action[data-prompt]', function(e, xhr, settings){
1235
+ var link = jQuery(this), value = prompt(link.data('prompt'));
1236
+ if (value) {
1237
+ link.data('params', jQuery.param({value: value}));
1238
+ } else if (jQuery(this).data('prompt-required')) {
1239
+ e.stopImmediatePropagation();
1240
+ return false;
1241
+ } else {
1242
+ link.removeData('params');
1243
+ }
1244
+ return true;
1245
+ });
1246
+ jQuery(document).on('ajax:before', 'a.as_action', function(event) {
1247
+ var action_link = ActiveScaffold.ActionLink.get(jQuery(this));
1248
+ if (action_link) {
1249
+ if (action_link.is_disabled()) {
1250
+ return false;
1251
+ } else {
1252
+ if (action_link.position == 'popup') ActiveScaffold.open_popup('<div class="loading"></div>', action_link);
1253
+ if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','visible');
1254
+ action_link.disable();
1255
+ }
1256
+ }
1257
+ return true;
1258
+ });
1259
+ jQuery(document).on('ajax:success', 'a.as_action', function(event, response) {
1260
+ if (event.detail && !response) response = event.detail[0];
1261
+ var action_link = ActiveScaffold.ActionLink.get(jQuery(this));
1262
+ if (action_link) {
1263
+ if (action_link.position) {
1264
+ action_link.insert(response);
1265
+ if (action_link.hide_target) action_link.target.hide();
1266
+ if (action_link.hide_content) action_link.content.hide();
1267
+ } else {
1268
+ if (action_link.tag.hasClass('toggle')) {
1269
+ action_link.tag.closest('.action_group,.actions').find('.toggle.active').removeClass('active');
1270
+ action_link.tag.addClass('active');
1271
+ }
1272
+ action_link.enable();
1273
+ }
1274
+ jQuery(this).trigger('as:action_success', action_link);
1275
+ if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden');
1276
+ }
1277
+ return true;
1278
+ });
1279
+ jQuery(document).on('ajax:error', 'a.as_action', function(event, xhr, status, error) {
1280
+ if (event.detail && !xhr) {
1281
+ error = event.detail[0];
1282
+ status = event.detail[1];
1283
+ xhr = event.detail[2];
1284
+ }
1285
+ var action_link = ActiveScaffold.ActionLink.get(jQuery(this));
1286
+ if (action_link) {
1287
+ ActiveScaffold.report_500_response(action_link.scaffold_id(), xhr);
1288
+ if (action_link.position == 'popup') action_link.close();
1289
+ if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden');
1290
+ action_link.enable();
1291
+ }
1292
+ return true;
1293
+ });
1294
+ jQuery(document).on({
1295
+ 'ajax:before': function () {
1296
+ var $this = jQuery(this), indicator_id = $this.data('loading-indicator-id'),
1297
+ $indicator = indicator_id ? jQuery('#' + indicator_id) : jQuery();
1298
+ if (!$indicator.length) $indicator = $this.parent().find('.loading-indicator');
1299
+ if (!$indicator.length) $indicator = $this.closest('.active-scaffold-header').find('.loading-indicator:first');
1300
+ $indicator.css('visibility', 'visible');
1301
+ $this.data('url', jQuery('option:selected', this).data('url'));
1302
+ }, 'ajax:complete': function () {
1303
+ var $this = jQuery(this), indicator_id = $this.data('loading-indicator-id'),
1304
+ $indicator = indicator_id ? jQuery('#' + indicator_id) : jQuery();
1305
+ if (!$indicator.length) $indicator = $this.parent().find('.loading-indicator');
1306
+ if (!$indicator.length) $indicator = $this.closest('.active-scaffold-header').find('.loading-indicator');
1307
+ $indicator.css('visibility', 'hidden');
1308
+ }
1309
+ }, ':input[data-remote="url"]:not(data-url)');
1310
+ jQuery(document).on('ajax:before', 'a.as_cancel', function(event) {
1311
+ var as_cancel = jQuery(this);
1312
+ var action_link = ActiveScaffold.find_action_link(as_cancel);
1423
1313
 
1424
- close: function() {
1425
- var link = this, callback = function() {
1426
- link.enable();
1427
- if (link.hide_target) link.target.show();
1428
- if (link.hide_content) link.content.show();
1429
- if (ActiveScaffold.config.scroll_on_close) {
1430
- ActiveScaffold.scroll_to(link.target.attr('id'), ActiveScaffold.config.scroll_on_close === 'checkInViewport');
1314
+ if (action_link) {
1315
+ var cancel_url = as_cancel.attr('href');
1316
+ var refresh_data = action_link.tag.data('cancel-refresh') || as_cancel.data('refresh');
1317
+ if (!refresh_data || !cancel_url) {
1318
+ action_link.close();
1319
+ return false;
1431
1320
  }
1432
- };
1433
- if (this.position === 'popup') {
1434
- ActiveScaffold.close_popup(this, callback);
1435
- } else if (this.adapter) {
1436
- ActiveScaffold.remove(this.adapter, callback);
1437
1321
  }
1438
- },
1439
-
1440
- reload: function() {
1441
- this.close();
1442
- this.open();
1443
- },
1444
-
1445
- get_new_adapter_id: function() {
1446
- var id = 'adapter_';
1447
- var i = 0;
1448
- while (jQuery(id + i)) i++;
1449
- return id + i;
1450
- },
1451
-
1452
- enable: function() {
1453
- return this.tag.removeClass('disabled');
1454
- },
1455
-
1456
- disable: function() {
1457
- return this.tag.addClass('disabled');
1458
- },
1459
-
1460
- is_disabled: function() {
1461
- return this.tag.hasClass('disabled');
1462
- },
1463
-
1464
- scaffold_id: function() {
1465
- const div_id = this.scaffold().attr('id');
1466
- if (div_id) return '#' + div_id;
1467
- },
1468
-
1469
- scaffold: function() {
1470
- return this.tag.closest('div.active-scaffold');
1471
- },
1472
-
1473
- messages: function() {
1474
- const re = /-active-scaffold$/, div_id = this.scaffold_id();
1322
+ return true;
1323
+ });
1324
+ jQuery(document).on('ajax:success', 'a.as_cancel', function(event) {
1325
+ var link = jQuery(this), action_link = ActiveScaffold.find_action_link(link);
1475
1326
 
1476
- if (re.test(div_id)) {
1477
- return jQuery(div_id.replace(re, '-messages'));
1327
+ if (action_link && action_link.position) {
1328
+ action_link.close();
1329
+ } else if (link.hasClass('reset')) {
1330
+ var form = link.closest('form');
1331
+ if (form.is('.search')) form.find(':input:visible:not([type=submit])').val('');
1332
+ else form.trigger('reset');
1333
+ }
1334
+ return true;
1335
+ });
1336
+ jQuery(document).on('ajax:error', 'a.as_cancel', function(event, xhr, status, error) {
1337
+ if (event.detail && !xhr) {
1338
+ error = event.detail[0];
1339
+ status = event.detail[1];
1340
+ xhr = event.detail[2];
1341
+ }
1342
+ var action_link = ActiveScaffold.find_action_link(jQuery(this));
1343
+ if (action_link) {
1344
+ ActiveScaffold.report_500_response(action_link.scaffold_id(), xhr);
1345
+ }
1346
+ return true;
1347
+ });
1348
+ jQuery(document).on('ajax:before', 'a.as_sort', function(event) {
1349
+ var as_sort = jQuery(this);
1350
+ as_sort.closest('th').addClass('loading');
1351
+ return true;
1352
+ });
1353
+ jQuery(document).on('ajax:error', 'a.as_sort', function(event, xhr, status, error) {
1354
+ if (event.detail && !xhr) {
1355
+ error = event.detail[0];
1356
+ status = event.detail[1];
1357
+ xhr = event.detail[2];
1358
+ }
1359
+ var as_scaffold = jQuery(this).closest('.active-scaffold');
1360
+ ActiveScaffold.report_500_response(as_scaffold, xhr);
1361
+ jQuery(this).closest('th').removeClass('loading');
1362
+ return true;
1363
+ });
1364
+ jQuery(document).on('mouseenter mouseleave', 'td.in_place_editor_field', function(event) {
1365
+ var td = jQuery(this), span = td.find('span.in_place_editor_field');
1366
+ if (event.type == 'mouseenter') {
1367
+ if (td.hasClass('empty') || typeof(span.data('editInPlace')) === 'undefined') td.find('span').addClass("hover");
1368
+ }
1369
+ if (event.type == 'mouseleave') {
1370
+ if (td.hasClass('empty') || typeof(span.data('editInPlace')) === 'undefined') td.find('span').removeClass("hover");
1371
+ }
1372
+ return true;
1373
+ });
1374
+ jQuery(document).on('click', 'td.in_place_editor_field, th.as_marked-column_heading', function(event) {
1375
+ var span = jQuery(this).find('span.in_place_editor_field');
1376
+ span.data('addEmptyOnCancel', jQuery(this).hasClass('empty'));
1377
+ jQuery(this).removeClass('empty');
1378
+ if (span.data('editInPlace')) span.trigger('click.editInPlace');
1379
+ else ActiveScaffold.in_place_editor_field_clicked(span);
1380
+ });
1381
+ jQuery(document).on('click', '.file-input-controls .remove-file-btn', function(event) {
1382
+ event.preventDefault();
1383
+ var btn = jQuery(this), file_line = btn.closest('.file-input-controls');
1384
+ if (file_line.find('.remove_file').val('true').length) {
1385
+ btn.parent().hide();
1386
+ file_line.find('input').show();
1387
+ if (file_line.attr('required')) file_line.find('input').attr('required', 'required');
1478
1388
  } else {
1479
- var messages_container = this.scaffold().find('.messages-container'),
1480
- messages = messages_container.find('.action-messages');
1481
- if (!messages.length) messages = jQuery('<div class="action-messages"></div>').appendTo(messages_container);
1482
- return messages;
1389
+ file_line.remove();
1483
1390
  }
1484
- },
1485
-
1486
- update_flash_messages: function(messages) {
1487
- this.messages().html(messages);
1488
- },
1391
+ return false;
1392
+ });
1393
+ jQuery(document).on('change', '.file-input-controls input[type=file]', function(event) {
1394
+ var file_line = jQuery(this).closest('.file-input-controls');
1395
+ file_line.find('.remove_file').val('false');
1396
+ });
1397
+ jQuery(document).on('ajax:before', 'a.as_paginate',function(event) {
1398
+ var as_paginate = jQuery(this);
1399
+ as_paginate.prevAll('img.loading-indicator').css('visibility','visible');
1400
+ return true;
1401
+ });
1402
+ jQuery(document).on('ajax:error', 'a.as_paginate', function(event, xhr, status, error) {
1403
+ if (event.detail && !xhr) {
1404
+ error = event.detail[0];
1405
+ status = event.detail[1];
1406
+ xhr = event.detail[2];
1407
+ }
1408
+ var as_scaffold = jQuery(this).closest('.active-scaffold');
1409
+ ActiveScaffold.report_500_response(as_scaffold, xhr);
1410
+ return true;
1411
+ });
1412
+ jQuery(document).on('ajax:complete', 'a.as_paginate', function(event) {
1413
+ jQuery(this).prevAll('img.loading-indicator').css('visibility','hidden');
1414
+ return true;
1415
+ });
1416
+ jQuery(document).on('ajax:before', 'a.as_add_existing, a.as_replace_existing', function(event) {
1417
+ var prev = jQuery(this).prev();
1418
+ if (!prev.is(':input')) prev = prev.find(':input');
1419
+ var id = prev.val();
1420
+ if (id) {
1421
+ if (!jQuery(this).data('href')) jQuery(this).data('href', jQuery(this).attr('href'));
1422
+ jQuery(this).attr('href', jQuery(this).data('href').replace('--ID--', id));
1423
+ return true;
1424
+ } else return false;
1425
+ });
1426
+ jQuery(document).on('ajax:complete', '.action_group.dyn > .dynamic-menu a', function(event) {
1427
+ var action_link = ActiveScaffold.find_action_link(event.target), link = jQuery(event.target);
1428
+ if (action_link && action_link.loading_indicator) action_link.loading_indicator.css('visibility', 'hidden');
1429
+ setTimeout(function() {
1430
+ if (!link.parent().is('.action_group.dyn')) {
1431
+ ActiveScaffold.remove_dynamic_action_group(link.closest('.action_group.dyn > .dynamic-menu'));
1432
+ }
1433
+ }, 100);
1434
+ });
1489
1435
 
1490
- set_adapter: function(element) {
1491
- this.adapter = element;
1492
- if (element) {
1493
- this.adapter.addClass('as_adapter');
1494
- this.adapter.data('action_link', this);
1495
- if (this.refresh_url) jQuery('.as_cancel', this.adapter).attr('href', this.refresh_url);
1436
+ jQuery(document).on('change', 'input.update_form:not(.recordselect), textarea.update_form, select.update_form, .checkbox-list.update_form input:checkbox', function(event, additional_params) {
1437
+ var element = jQuery(this);
1438
+ var form_element;
1439
+ var value;
1440
+ if (element.is(".checkbox-list input:checkbox")) {
1441
+ form_element = element.closest('.checkbox-list');
1442
+ if (form_element.is('.draggable-list')) form_element = form_element.closest('.draggable-lists-container').find('.checkbox-list') // draggable lists will have 2 lists
1443
+ value = form_element.find(':checked').map(function(item) { return jQuery(this).val(); }).toArray();
1444
+ if (!additional_params) additional_params = (element.is(':checked') ? '_added=' : '_removed=') + element.val();
1445
+ } else {
1446
+ value = element.is("input:checkbox:not(:checked)") ? null : element.val();
1447
+ form_element = element;
1496
1448
  }
1497
- },
1449
+ ActiveScaffold.update_column(form_element, form_element.data('update_url'), form_element.data('update_send_form'), element.attr('id'), value, additional_params);
1450
+ return true;
1451
+ });
1452
+ jQuery(document).on('click', 'a.refresh-link', function(event) {
1453
+ event.preventDefault();
1454
+ var element = jQuery(this), selector = element.data('field-selector'), value, form_element;
1455
+ form_element = selector.startsWith('#') ? jQuery(selector) : element.closest('.form-element').find(selector);
1456
+ if (form_element.is('.draggable-list')) form_element = form_element.closest('.draggable-lists-container');
1457
+ if (form_element.is(".field_with_errors")) form_element = form_element.children().last();
1458
+ if (form_element.is(".checkbox-list")) {
1459
+ value = form_element.find(':checked').map(function(item) { return jQuery(this).val(); }).toArray();
1460
+ form_element = form_element.parent().find("input:checkbox"); // parent is needed for draggable-list, checked list may be empty
1461
+ } else if (form_element.is(':radio, :checkbox')) value = form_element.filter(':checked').val() || null;
1462
+ else value = form_element.val();
1463
+ ActiveScaffold.update_column(form_element, element.attr('href'), element.data('update_send_form'), form_element.attr('id'), value);
1464
+ });
1465
+ jQuery(document).on('click', 'a.visibility-toggle', function(e) {
1466
+ var link = jQuery(this), toggable = jQuery('#' + link.data('toggable'));
1467
+ e.preventDefault();
1468
+ toggable.toggle();
1469
+ link.html((toggable.is(':hidden')) ? link.data('show') : link.data('hide'));
1470
+ return false;
1471
+ });
1472
+ jQuery(document).on('recordselect:change', 'input.recordselect.update_form', function(event, id, label) {
1473
+ var element = jQuery(this);
1474
+ ActiveScaffold.update_column(element, element.data('update_url'), element.data('update_send_form'), element.attr('id'), id);
1475
+ return true;
1476
+ });
1498
1477
 
1499
- keep_open: function() {
1500
- return this.tag.data('keep-open');
1501
- }
1502
- });
1478
+ jQuery(document).on('change', 'select.as_search_range_option', function(event) {
1479
+ var element = jQuery(this);
1480
+ ActiveScaffold[element.val() == 'BETWEEN' ? 'show' : 'hide'](element.closest('dd').find('.as_search_range_between'));
1481
+ ActiveScaffold[(element.val() == 'null' || element.val() == 'not_null') ? 'hide' : 'show'](element.attr('id').replace(/_opt/, '_numeric'));
1482
+ return true;
1483
+ });
1484
+
1485
+ jQuery(document).on('change', 'select.as_search_date_time_option', function(event) {
1486
+ var element = jQuery(this);
1487
+ ActiveScaffold[!(element.val() == 'PAST' || element.val() == 'FUTURE' || element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_numeric'));
1488
+ ActiveScaffold[(element.val() == 'PAST' || element.val() == 'FUTURE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_trend'));
1489
+ ActiveScaffold[(element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_range'));
1490
+ return true;
1491
+ });
1503
1492
 
1504
- /**
1505
- * Concrete classes for record actions
1506
- */
1507
- ActiveScaffold.Actions.Record = ActiveScaffold.Actions.Abstract.extend({
1508
- instantiate_link: function(link) {
1509
- var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator);
1510
- var refresh = this.target.data('refresh');
1511
- if (refresh) l.refresh_url = this.target.closest('.records').data('refresh-record').replace('--ID--', refresh);
1493
+ jQuery(document).on('click', '.active-scaffold .sub-form a.destroy', function(event) {
1494
+ event.preventDefault();
1495
+ ActiveScaffold.remove(jQuery(this).closest('.sub-form-record'));
1496
+ });
1512
1497
 
1513
- if (l.position) {
1514
- l.url = l.url.append_params({adapter: l.position == 'popup' ? '_popup_adapter' : '_list_inline_adapter'});
1515
- l.tag.attr('href', l.url);
1498
+ jQuery(document).on("click", '.hover_click', function(event) {
1499
+ var element = jQuery(this);
1500
+ var ul_element = element.children('ul').first();
1501
+ if (ul_element.is(':visible')) {
1502
+ element.find('ul').hide();
1503
+ } else {
1504
+ ul_element.show();
1516
1505
  }
1517
- l.set = this;
1518
- return l;
1519
- }
1520
- });
1506
+ return false;
1507
+ });
1508
+ jQuery(document).on('click', '.hover_click a.as_action', function(event) {
1509
+ var element = jQuery(this).closest('.hover_click');
1510
+ if (element.length) {
1511
+ element.find('ul').hide();
1512
+ }
1513
+ return true;
1514
+ });
1521
1515
 
1522
- ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({
1523
- close_previous_adapter: function() {
1524
- var _this = this;
1525
- jQuery.each(this.set.links, function(index, item) {
1526
- if (item.url != _this.url && item.is_disabled() && !item.keep_open() && item.adapter) {
1527
- ActiveScaffold.remove(item.adapter, function () { item.enable(); });
1528
- }
1529
- });
1530
- },
1516
+ jQuery(document).on('click', '.message a.close', function(e) {
1517
+ ActiveScaffold.hide(jQuery(this).closest('.message'));
1518
+ e.preventDefault();
1519
+ });
1531
1520
 
1532
- insert: function(content) {
1533
- this.close_previous_adapter();
1521
+ jQuery(document).on('click', 'form.as_form .no-color', function() {
1522
+ var color_field = jQuery(this).parent().next(':input');
1523
+ color_field.attr('type', jQuery(this).prop('checked') ? 'hidden' : 'color');
1524
+ if (jQuery(this).prop('checked')) color_field.val('');
1525
+ });
1534
1526
 
1535
- if (this.position === 'replace') {
1536
- this.position = 'after';
1537
- this.hide_target = true;
1538
- } else if (this.position === 'table') {
1539
- this.hide_content = true;
1540
- } else if (this.position === 'popup') {
1541
- return ActiveScaffold.open_popup(content, this);
1527
+ jQuery(document).on('click', '.hide-new-subform, .show-new-subform', function(e) {
1528
+ var $this = jQuery(this), line = $this.closest('.form-element'),
1529
+ subform = line.find('#' + $this.data('subform-id')), radio = false, hide, field;
1530
+ if ($this.is('[type=radio]')) {
1531
+ radio = true;
1532
+ hide = $this.is('.hide-new-subform');
1533
+ } else {
1534
+ e.preventDefault();
1535
+ hide = subform.is(':visible');
1542
1536
  }
1543
-
1544
- var colspan = this.target.children().length;
1545
- if (content && this.position) {
1546
- content = jQuery(content);
1547
- content.find('.inline-adapter-cell:first').attr('colspan', colspan);
1537
+ if ($this.data('select-id')) {
1538
+ field = line.find('#' + $this.data('select-id')).closest('.select-field');
1548
1539
  }
1549
- if (this.position === 'after') {
1550
- this.target.after(content);
1551
- this.set_adapter(this.target.next());
1552
- } else if (this.position === 'before') {
1553
- this.target.before(content);
1554
- this.set_adapter(this.target.prev());
1555
- } else if (this.position === 'table') {
1556
- var content_parent = this.target.closest('div.active-scaffold').find('tbody.before-header').first()
1557
- content_parent.prepend(content);
1558
- this.set_adapter(content_parent.children().first())
1540
+ if (hide) {
1541
+ subform.hide().find("input:enabled,select:enabled,textarea:enabled").prop('disabled', true);
1542
+ if (field) field.show().find('input:disabled,select:disabled,textarea:disabled').prop('disabled', false);
1543
+ if (radio) {
1544
+ $this.closest('.form-element').find('[name="' + $this.attr('name') + '"].show-new-subform').prop('disabled', false);
1545
+ } else $this.html($this.data('select-text'));
1559
1546
  } else {
1560
- return false;
1561
- }
1562
- ActiveScaffold.highlight(this.adapter.find('td'));
1563
- ActiveScaffold.focus_first_element_of_form(this.adapter);
1564
- },
1565
-
1566
- close: function(refreshed_content_or_reload) {
1567
- this._super();
1568
- if (refreshed_content_or_reload) {
1569
- if (typeof refreshed_content_or_reload == 'string') this.refresh(refreshed_content_or_reload);
1570
- else this.refresh();
1547
+ if (field) field.hide().find('input:enabled,select:enabled,textarea:enabled').prop('disabled', true);
1548
+ subform.show().find("input:disabled,select:disabled,textarea:disabled").prop('disabled', false);
1549
+ if (radio) $this.prop('disabled', true);
1550
+ else {
1551
+ $this.data('select-text', $this.html());
1552
+ $this.html($this.data('subform-text'));
1553
+ }
1571
1554
  }
1572
- },
1555
+ });
1573
1556
 
1574
- refresh: function(content) {
1575
- if (content) {
1576
- ActiveScaffold.update_row(this.target, content);
1577
- } else if (this.refresh_url) {
1578
- var target = this.target;
1579
- jQuery.get(this.refresh_url, function(e, status, xhr) {
1580
- ActiveScaffold.update_row(target, xhr.responseText);
1581
- });
1582
- }
1583
- },
1557
+ jQuery(document).on('input paste', 'form.search.live input[type=search]', $.debounce((ActiveScaffold.config.live_search_delay || 0.5) * 1000, function() {
1558
+ jQuery(this).parent().find('[type=submit]').click();
1559
+ }));
1584
1560
 
1585
- enable: function() {
1586
- var _this = this;
1587
- jQuery.each(this.set.links, function(index, item) {
1588
- if (item.url != _this.url) return;
1589
- item.tag.removeClass('disabled');
1590
- });
1591
- },
1561
+ jQuery(document).on('click', 'form.search [data-reset]', function(e){
1562
+ e.preventDefault();
1563
+ var form = jQuery(this).closest('form.search');
1564
+ form.find(
1565
+ 'input:not([type=button]):not([type=submit]):not([type=reset]):not([type=hidden]),' +
1566
+ 'textarea, select:has(option[value=""])'
1567
+ ).val('');
1568
+ form.find('select.as_search_range_option').each(function() { jQuery(this).val(jQuery(this).find('option:first').val()) });
1569
+ form.find('select.as_search_date_time_option').val('BETWEEN');
1570
+ });
1592
1571
 
1593
- disable: function() {
1594
- var _this = this;
1595
- jQuery.each(this.set.links, function(index, item) {
1596
- if (item.url != _this.url) return;
1597
- item.tag.addClass('disabled');
1598
- });
1599
- },
1572
+ jQuery(document).on('click', '.active-scaffold .tabbed .nav-tabs a', function(e) {
1573
+ if (typeof jQuery().tab == 'function') return; // bootstrap tab plugin is loaded and will handle tabs
1574
+ e.preventDefault();
1575
+ var tab_ctrl = jQuery(this), tabbed = tab_ctrl.closest('.tabbed')
1576
+ tabbed.find('.nav-tabs .active').removeClass('active');
1577
+ tabbed.find('.tab-content .active').removeClass('in active');
1578
+ tab_ctrl.closest('li').addClass('active');
1579
+ jQuery(tab_ctrl.attr('href')).addClass('in active');
1580
+ });
1600
1581
 
1601
- set_opened: function() {
1602
- if (this.position === 'after') {
1603
- this.set_adapter(this.target.next());
1604
- }
1605
- else if (this.position === 'before') {
1606
- this.set_adapter(this.target.prev());
1582
+ jQuery(document).on('turbolinks:before-visit turbo:before-visit', function() {
1583
+ if (history.state.active_scaffold) {
1584
+ history.replaceState({turbolinks: true, url: document.location.href}, '', document.location.href);
1607
1585
  }
1608
- this.disable();
1609
- }
1610
- });
1586
+ });
1611
1587
 
1612
- /**
1613
- * Concrete classes for table actions
1614
- */
1615
- ActiveScaffold.Actions.Table = ActiveScaffold.Actions.Abstract.extend({
1616
- instantiate_link: function(link) {
1617
- var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator);
1618
- if (l.position) {
1619
- l.url = l.url.append_params({adapter: l.position == 'popup' ? '_popup_adapter' : '_list_inline_adapter'});
1620
- l.tag.attr('href', l.url);
1621
- }
1622
- return l;
1588
+ jQuery(window).on('popstate', function(e) {
1589
+ var state = e.originalEvent.state;
1590
+ if (!state || !state.active_scaffold) return;
1591
+ jQuery.ajax({
1592
+ url: document.location.href,
1593
+ data: jQuery.extend({'_popstate': true}, state.active_scaffold),
1594
+ dataType: 'script',
1595
+ cache: true
1596
+ });
1597
+ jQuery('.active-scaffold:first th .as_sort:first').closest('th').addClass('loading');
1598
+ });
1599
+
1600
+ // call setup on document.ready if Turbolinks not enabled
1601
+ if ((typeof(Turbolinks) == 'undefined' || !Turbolinks.supported) && typeof(Turbo) == 'undefined') {
1602
+ ActiveScaffold.setup_history_state();
1603
+ ActiveScaffold.setup(document);
1623
1604
  }
1605
+ if (ActiveScaffold.config.warn_changes) ActiveScaffold.setup_warn_changes();
1606
+ jQuery(document).on('as:element_updated as:element_created', function(e, action_link) {
1607
+ ActiveScaffold.setup(e.target);
1608
+ });
1609
+ jQuery(document).on('as:element_removed', function(e, action_link) {
1610
+ setTimeout(ActiveScaffold.update_floating_form_footer); // delay so form is already removed
1611
+ });
1612
+ jQuery(document).on('as:action_success', 'a.as_action', function(e, action_link) {
1613
+ if (action_link.adapter) ActiveScaffold.setup(action_link.adapter);
1614
+ });
1615
+ jQuery(document).on('as:element_updated', '.active-scaffold', function(e) {
1616
+ if (e.target != this) return;
1617
+ var search = jQuery(this).find('form.search');
1618
+ if (search.length) ActiveScaffold.focus_first_element_of_form(search);
1619
+ });
1620
+ jQuery(document).on('click', '.active-scaffold form .check-all', function(e) {
1621
+ e.preventDefault();
1622
+ ActiveScaffold.update_all_checkboxes(jQuery(this), true);
1623
+ });
1624
+ jQuery(document).on('click', '.active-scaffold form .uncheck-all', function(e) {
1625
+ e.preventDefault();
1626
+ ActiveScaffold.update_all_checkboxes(jQuery(this), false);
1627
+ });
1628
+ jQuery(document).on('click', '.descriptions-click .description:not(.visible)', function(e) {
1629
+ e.preventDefault();
1630
+ $(this).addClass('visible');
1631
+ });
1632
+ jQuery(document).on('click', '.descriptions-click .description.visible .close', function(e) {
1633
+ e.preventDefault();
1634
+ $(this).closest('.description').removeClass('visible');
1635
+ });
1624
1636
  });
1625
1637
 
1626
- ActiveScaffold.ActionLink.Table = ActiveScaffold.ActionLink.Abstract.extend({
1627
- insert: function(content) {
1628
- if (this.position == 'replace') {
1629
- this.position = 'top';
1630
- this.hide_content = true;
1631
- } else if (this.position == 'popup') {
1632
- return ActiveScaffold.open_popup(content, this);
1633
- }
1634
-
1635
- if (this.position == 'top') {
1636
- this.target.prepend(content);
1637
- this.set_adapter(this.target.children().first());
1638
- } else {
1639
- throw 'Unknown position "' + this.position + '"'
1640
- }
1641
- ActiveScaffold.highlight(this.adapter.find('td').first().children().not('script'));
1642
- ActiveScaffold.focus_first_element_of_form(this.adapter);
1643
- }
1638
+ jQuery(document).on('turbolinks:load turbo:load', function($) {
1639
+ ActiveScaffold.setup(document);
1644
1640
  });
1641
+ jQuery(window).on('scroll resize', ActiveScaffold.update_floating_form_footer);
1645
1642
  };
1646
1643
 
1647
1644
  if (window.jQuery) {