active_scaffold 3.7.2 → 3.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +9 -0
- data/app/assets/javascripts/active_scaffold.js.erb +1 -4
- data/app/assets/javascripts/jquery/active_scaffold.js +1421 -1396
- data/app/assets/javascripts/jquery/draggable_lists.js +6 -4
- data/app/assets/javascripts/jquery/tiny_mce_bridge.js +2 -2
- data/app/assets/stylesheets/active_scaffold_jquery_ui.css.erb +7 -8
- data/app/views/active_scaffold_overrides/_field_search.html.erb +10 -1
- data/app/views/active_scaffold_overrides/_search.html.erb +9 -1
- data/lib/active_scaffold/bridges/date_picker.rb +1 -1
- data/lib/active_scaffold/bridges/record_select/helpers.rb +3 -3
- data/lib/active_scaffold/config/field_search.rb +5 -0
- data/lib/active_scaffold/config/search.rb +5 -0
- data/lib/active_scaffold/finder.rb +14 -4
- data/lib/active_scaffold/helpers/id_helpers.rb +1 -1
- data/lib/active_scaffold/version.rb +1 -1
- data/lib/active_scaffold.rb +6 -0
- data/vendor/assets/javascripts/jquery.ba-throttle-debounce.js +10 -3
- metadata +2 -2
@@ -1,1468 +1,1493 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
jQuery(document).ajaxComplete(function(event, xhr, settings){
|
17
|
-
var etag=xhr.getResponseHeader("etag");
|
18
|
-
if (etag && settings.ifModified && xhr.responseText) {
|
19
|
-
var key = etag + xhr.cacheUrl;
|
20
|
-
jQuery(document).data(key, xhr.responseText);
|
21
|
-
var contentType = xhr.getResponseHeader('Content-Type');
|
22
|
-
for(s in settings.contents) {
|
23
|
-
if (settings.contents[s].test(contentType)) {
|
24
|
-
var conv = settings.converters['text '+s];
|
25
|
-
if (typeof conv == 'function') jQuery(document).data('type-'+key, conv);
|
26
|
-
break;
|
1
|
+
(function() {
|
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);
|
27
16
|
}
|
28
|
-
}
|
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);
|
29
38
|
}
|
30
|
-
});
|
31
|
-
*/
|
32
|
-
if (/1\.[2-7]\..*/.test(jQuery().jquery)) {
|
33
|
-
var error = 'ActiveScaffold requires jquery 1.8.0 or greater, please use jquery-rails 2.1.x gem or greater';
|
34
|
-
if (typeof console != 'undefined') console.error(error);
|
35
|
-
else alert(error);
|
36
|
-
}
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
+
jQuery('.action_group.dyn > ul').hide(); // only hide so action links loading still work
|
44
|
+
});
|
45
|
+
jQuery(document).on('ajax:beforeSend', 'form.as_form', function(event) {
|
46
|
+
var as_form = jQuery(this).closest("form");
|
47
|
+
if (as_form.data('loading') == true) {
|
48
|
+
ActiveScaffold.disable_form(as_form);
|
49
|
+
}
|
50
|
+
return true;
|
51
|
+
});
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
53
|
+
jQuery(document).on('ajax:complete', 'form.as_form', function(event) {
|
54
|
+
var as_form = jQuery(this).closest("form");
|
55
|
+
if (as_form.data('loading') == true) {
|
56
|
+
ActiveScaffold.enable_form(as_form);
|
57
|
+
}
|
58
|
+
});
|
59
|
+
jQuery(document).on('ajax:complete', 'form.live', function(event) {
|
60
|
+
ActiveScaffold.focus_first_element_of_form(jQuery(this).closest("form"));
|
61
|
+
});
|
62
|
+
jQuery(document).on('keyup keypress', 'form.search.live input', function(e) {
|
63
|
+
if (e.keyCode == 13) e.preventDefault();
|
64
|
+
});
|
65
|
+
jQuery(document).on('ajax:error', 'form.as_form', function(event, xhr, status, error) {
|
66
|
+
if (event.detail && !xhr) {
|
67
|
+
error = event.detail[0];
|
68
|
+
status = event.detail[1];
|
69
|
+
xhr = event.detail[2];
|
70
|
+
}
|
71
|
+
var as_div = jQuery(this).closest("div.active-scaffold");
|
72
|
+
if (as_div.length) {
|
73
|
+
ActiveScaffold.report_500_response(as_div, xhr);
|
74
|
+
}
|
75
|
+
});
|
76
|
+
jQuery(document).on('submit', 'form.as_form:not([data-remote])', function(event) {
|
77
|
+
var as_form = jQuery(this).closest("form"), form_id = as_form.attr('id'), iframe, interval, doc, cookie;
|
78
|
+
if (as_form.data('loading') == true) {
|
79
|
+
setTimeout(function() { ActiveScaffold.disable_form(form_id); }, 10);
|
80
|
+
if (as_form.attr('target')) {
|
81
|
+
cookie = 'as_dl_' + new Date().getTime();
|
82
|
+
as_form.append($('<input>', {type: 'hidden', name: '_dl_cookie', value: cookie}));
|
83
|
+
iframe = jQuery('iframe[name="' + jQuery(this).attr('target') + '"]')[0];
|
84
|
+
interval = setInterval(function() {
|
85
|
+
doc = iframe.contentDocument || (iframe.contentWindow && iframe.contentWindow.document);
|
86
|
+
if (doc && doc.readyState !== 'loading' && (doc.location.href !== 'about:blank' || document.cookie.split(cookie+'=').length == 2)) {
|
87
|
+
ActiveScaffold.enable_form(form_id);
|
88
|
+
clearInterval(interval);
|
89
|
+
doc.location.replace('about:blank');
|
90
|
+
document.cookie = cookie + '=; path=/; expires=' + new Date().toUTCString();
|
91
|
+
} else if (!doc) {
|
92
|
+
clearInterval(interval);
|
93
|
+
document.cookie = cookie + '=; path=/; expires=' + new Date().toUTCString();
|
94
|
+
}
|
95
|
+
}, 1000);
|
92
96
|
}
|
93
|
-
}, 1000);
|
94
|
-
}
|
95
|
-
}
|
96
|
-
return true;
|
97
|
-
});
|
98
|
-
jQuery(document).on('ajax:before', 'a.as_action', function(event) {
|
99
|
-
var action_link = ActiveScaffold.ActionLink.get(jQuery(this));
|
100
|
-
if (action_link) {
|
101
|
-
if (action_link.is_disabled()) {
|
102
|
-
return false;
|
103
|
-
} else {
|
104
|
-
if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','visible');
|
105
|
-
action_link.disable();
|
106
|
-
}
|
107
|
-
}
|
108
|
-
return true;
|
109
|
-
});
|
110
|
-
jQuery(document).on('ajax:success', 'a.as_action', function(event, response) {
|
111
|
-
if (event.detail && !response) response = event.detail[0];
|
112
|
-
var action_link = ActiveScaffold.ActionLink.get(jQuery(this));
|
113
|
-
if (action_link) {
|
114
|
-
if (action_link.position) {
|
115
|
-
action_link.insert(response);
|
116
|
-
if (action_link.hide_target) action_link.target.hide();
|
117
|
-
if (action_link.hide_content) action_link.content.hide();
|
118
|
-
} else {
|
119
|
-
if (action_link.tag.hasClass('toggle')) {
|
120
|
-
action_link.tag.closest('.action_group,.actions').find('.toggle.active').removeClass('active');
|
121
|
-
action_link.tag.addClass('active');
|
122
97
|
}
|
123
|
-
|
124
|
-
}
|
125
|
-
jQuery(
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
});
|
276
|
-
jQuery(document).on('click', 'a.visibility-toggle', function(e) {
|
277
|
-
var link = jQuery(this), toggable = jQuery('#' + link.data('toggable'));
|
278
|
-
e.preventDefault();
|
279
|
-
toggable.toggle();
|
280
|
-
link.html((toggable.is(':hidden')) ? link.data('show') : link.data('hide'));
|
281
|
-
return false;
|
282
|
-
});
|
283
|
-
jQuery(document).on('recordselect:change', 'input.recordselect.update_form', function(event, id, label) {
|
284
|
-
var element = jQuery(this);
|
285
|
-
ActiveScaffold.update_column(element, element.data('update_url'), element.data('update_send_form'), element.attr('id'), id);
|
286
|
-
return true;
|
287
|
-
});
|
288
|
-
|
289
|
-
jQuery(document).on('change', 'select.as_search_range_option', function(event) {
|
290
|
-
var element = jQuery(this);
|
291
|
-
ActiveScaffold[element.val() == 'BETWEEN' ? 'show' : 'hide'](element.closest('dd').find('.as_search_range_between'));
|
292
|
-
ActiveScaffold[(element.val() == 'null' || element.val() == 'not_null') ? 'hide' : 'show'](element.attr('id').replace(/_opt/, '_numeric'));
|
293
|
-
return true;
|
294
|
-
});
|
295
|
-
|
296
|
-
jQuery(document).on('change', 'select.as_search_date_time_option', function(event) {
|
297
|
-
var element = jQuery(this);
|
298
|
-
ActiveScaffold[!(element.val() == 'PAST' || element.val() == 'FUTURE' || element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_numeric'));
|
299
|
-
ActiveScaffold[(element.val() == 'PAST' || element.val() == 'FUTURE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_trend'));
|
300
|
-
ActiveScaffold[(element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_range'));
|
301
|
-
return true;
|
302
|
-
});
|
303
|
-
|
304
|
-
jQuery(document).on('change', 'select.as_update_date_operator', function(event) {
|
305
|
-
ActiveScaffold[jQuery(this).val() == 'REPLACE' ? 'show' : 'hide'](jQuery(this).next());
|
306
|
-
ActiveScaffold[jQuery(this).val() == 'REPLACE' ? 'hide' : 'show'](jQuery(this).next().next());
|
307
|
-
return true;
|
308
|
-
});
|
309
|
-
|
310
|
-
jQuery(document).on('click', '.active-scaffold .sub-form a.destroy', function(event) {
|
311
|
-
event.preventDefault();
|
312
|
-
ActiveScaffold.delete_subform_record($(this).data('delete-id'));
|
313
|
-
});
|
314
|
-
|
315
|
-
jQuery(document).on("click", '.hover_click', function(event) {
|
316
|
-
var element = jQuery(this);
|
317
|
-
var ul_element = element.children('ul').first();
|
318
|
-
if (ul_element.is(':visible')) {
|
319
|
-
element.find('ul').hide();
|
320
|
-
} else {
|
321
|
-
ul_element.show();
|
322
|
-
}
|
323
|
-
return false;
|
324
|
-
});
|
325
|
-
jQuery(document).on('click', '.hover_click a.as_action', function(event) {
|
326
|
-
var element = jQuery(this).closest('.hover_click');
|
327
|
-
if (element.length) {
|
328
|
-
element.find('ul').hide();
|
329
|
-
}
|
330
|
-
return true;
|
331
|
-
});
|
332
|
-
|
333
|
-
jQuery(document).on('click', '.message a.close', function(e) {
|
334
|
-
ActiveScaffold.hide(jQuery(this).closest('.message'));
|
335
|
-
e.preventDefault();
|
336
|
-
});
|
337
|
-
|
338
|
-
jQuery(document).on('click', 'form.as_form .no-color', function() {
|
339
|
-
var color_field = jQuery(this).parent().next(':input');
|
340
|
-
color_field.attr('type', jQuery(this).prop('checked') ? 'hidden' : 'color');
|
341
|
-
if (jQuery(this).prop('checked')) color_field.val('');
|
342
|
-
});
|
343
|
-
|
344
|
-
jQuery(document).on('click', '.hide-new-subform, .show-new-subform', function(e) {
|
345
|
-
var $this = jQuery(this), line = $this.closest('.form-element'),
|
346
|
-
subform = line.find('#' + $this.data('subform-id')), radio = false, hide, select;
|
347
|
-
if ($this.is('[type=radio]')) {
|
348
|
-
radio = true;
|
349
|
-
hide = $this.is('.hide-new-subform');
|
350
|
-
} else {
|
351
|
-
e.preventDefault();
|
352
|
-
hide = subform.is(':visible');
|
353
|
-
}
|
354
|
-
if ($this.data('select-id')) {
|
355
|
-
select = line.find('#' + $this.data('select-id'));
|
356
|
-
if (select.hasClass('recordselect') || select.is('.no-options')) select = select.next(':hidden').andSelf();
|
357
|
-
}
|
358
|
-
if (hide) {
|
359
|
-
subform.hide().find("input:enabled,select:enabled,textarea:enabled").prop('disabled', true);
|
360
|
-
if (select) select.show().prop('disabled', false);
|
361
|
-
if (radio) {
|
362
|
-
$this.closest('.form-element').find('[name="' + $this.attr('name') + '"].show-new-subform').prop('disabled', false);
|
363
|
-
} else $this.html($this.data('select-text'));
|
364
|
-
} else {
|
365
|
-
if (select) select.hide().prop('disabled', true);
|
366
|
-
subform.show().find("input:disabled,select:disabled,textarea:disabled").prop('disabled', false);
|
367
|
-
if (radio) $this.prop('disabled', true);
|
368
|
-
else {
|
369
|
-
$this.data('select-text', $this.html());
|
370
|
-
$this.html($this.data('subform-text'));
|
371
|
-
}
|
372
|
-
}
|
373
|
-
});
|
98
|
+
return true;
|
99
|
+
});
|
100
|
+
jQuery(document).on('ajax:before', 'a.as_action', function(event) {
|
101
|
+
var action_link = ActiveScaffold.ActionLink.get(jQuery(this));
|
102
|
+
if (action_link) {
|
103
|
+
if (action_link.is_disabled()) {
|
104
|
+
return false;
|
105
|
+
} else {
|
106
|
+
if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','visible');
|
107
|
+
action_link.disable();
|
108
|
+
}
|
109
|
+
}
|
110
|
+
return true;
|
111
|
+
});
|
112
|
+
jQuery(document).on('ajax:success', 'a.as_action', function(event, response) {
|
113
|
+
if (event.detail && !response) response = event.detail[0];
|
114
|
+
var action_link = ActiveScaffold.ActionLink.get(jQuery(this));
|
115
|
+
if (action_link) {
|
116
|
+
if (action_link.position) {
|
117
|
+
action_link.insert(response);
|
118
|
+
if (action_link.hide_target) action_link.target.hide();
|
119
|
+
if (action_link.hide_content) action_link.content.hide();
|
120
|
+
} else {
|
121
|
+
if (action_link.tag.hasClass('toggle')) {
|
122
|
+
action_link.tag.closest('.action_group,.actions').find('.toggle.active').removeClass('active');
|
123
|
+
action_link.tag.addClass('active');
|
124
|
+
}
|
125
|
+
action_link.enable();
|
126
|
+
}
|
127
|
+
jQuery(this).trigger('as:action_success', action_link);
|
128
|
+
if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden');
|
129
|
+
}
|
130
|
+
return true;
|
131
|
+
});
|
132
|
+
jQuery(document).on('ajax:error', 'a.as_action', function(event, xhr, status, error) {
|
133
|
+
if (event.detail && !xhr) {
|
134
|
+
error = event.detail[0];
|
135
|
+
status = event.detail[1];
|
136
|
+
xhr = event.detail[2];
|
137
|
+
}
|
138
|
+
var action_link = ActiveScaffold.ActionLink.get(jQuery(this));
|
139
|
+
if (action_link) {
|
140
|
+
ActiveScaffold.report_500_response(action_link.scaffold_id(), xhr);
|
141
|
+
action_link.enable();
|
142
|
+
}
|
143
|
+
return true;
|
144
|
+
});
|
145
|
+
jQuery(document).on('ajax:before', 'a.as_cancel', function(event) {
|
146
|
+
var as_cancel = jQuery(this);
|
147
|
+
var action_link = ActiveScaffold.find_action_link(as_cancel);
|
148
|
+
|
149
|
+
if (action_link) {
|
150
|
+
var cancel_url = as_cancel.attr('href');
|
151
|
+
var refresh_data = action_link.tag.data('cancel-refresh') || as_cancel.data('refresh');
|
152
|
+
if (!refresh_data || !cancel_url) {
|
153
|
+
action_link.close();
|
154
|
+
return false;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
return true;
|
158
|
+
});
|
159
|
+
jQuery(document).on('ajax:success', 'a.as_cancel', function(event) {
|
160
|
+
var link = jQuery(this), action_link = ActiveScaffold.find_action_link(link);
|
161
|
+
|
162
|
+
if (action_link && action_link.position) {
|
163
|
+
action_link.close();
|
164
|
+
} else if (link.hasClass('reset')) {
|
165
|
+
var form = link.closest('form');
|
166
|
+
if (form.is('.search')) form.find(':input:visible:not([type=submit])').val('');
|
167
|
+
else form.trigger('reset');
|
168
|
+
}
|
169
|
+
return true;
|
170
|
+
});
|
171
|
+
jQuery(document).on('ajax:error', 'a.as_cancel', function(event, xhr, status, error) {
|
172
|
+
if (event.detail && !xhr) {
|
173
|
+
error = event.detail[0];
|
174
|
+
status = event.detail[1];
|
175
|
+
xhr = event.detail[2];
|
176
|
+
}
|
177
|
+
var action_link = ActiveScaffold.find_action_link(jQuery(this));
|
178
|
+
if (action_link) {
|
179
|
+
ActiveScaffold.report_500_response(action_link.scaffold_id(), xhr);
|
180
|
+
}
|
181
|
+
return true;
|
182
|
+
});
|
183
|
+
jQuery(document).on('ajax:before', 'a.as_sort', function(event) {
|
184
|
+
var as_sort = jQuery(this);
|
185
|
+
as_sort.closest('th').addClass('loading');
|
186
|
+
return true;
|
187
|
+
});
|
188
|
+
jQuery(document).on('ajax:error', 'a.as_sort', function(event, xhr, status, error) {
|
189
|
+
if (event.detail && !xhr) {
|
190
|
+
error = event.detail[0];
|
191
|
+
status = event.detail[1];
|
192
|
+
xhr = event.detail[2];
|
193
|
+
}
|
194
|
+
var as_scaffold = jQuery(this).closest('.active-scaffold');
|
195
|
+
ActiveScaffold.report_500_response(as_scaffold, xhr);
|
196
|
+
jQuery(this).closest('th').removeClass('loading');
|
197
|
+
return true;
|
198
|
+
});
|
199
|
+
jQuery(document).on('mouseenter mouseleave', 'td.in_place_editor_field', function(event) {
|
200
|
+
var td = jQuery(this), span = td.find('span.in_place_editor_field');
|
201
|
+
if (event.type == 'mouseenter') {
|
202
|
+
if (td.hasClass('empty') || typeof(span.data('editInPlace')) === 'undefined') td.find('span').addClass("hover");
|
203
|
+
}
|
204
|
+
if (event.type == 'mouseleave') {
|
205
|
+
if (td.hasClass('empty') || typeof(span.data('editInPlace')) === 'undefined') td.find('span').removeClass("hover");
|
206
|
+
}
|
207
|
+
return true;
|
208
|
+
});
|
209
|
+
jQuery(document).on('click', 'td.in_place_editor_field, th.as_marked-column_heading', function(event) {
|
210
|
+
var span = jQuery(this).find('span.in_place_editor_field');
|
211
|
+
span.data('addEmptyOnCancel', jQuery(this).hasClass('empty'));
|
212
|
+
jQuery(this).removeClass('empty');
|
213
|
+
if (span.data('editInPlace')) span.trigger('click.editInPlace');
|
214
|
+
else ActiveScaffold.in_place_editor_field_clicked(span);
|
215
|
+
});
|
216
|
+
jQuery(document).on('ajax:before', 'a.as_paginate',function(event) {
|
217
|
+
var as_paginate = jQuery(this);
|
218
|
+
as_paginate.prevAll('img.loading-indicator').css('visibility','visible');
|
219
|
+
return true;
|
220
|
+
});
|
221
|
+
jQuery(document).on('ajax:error', 'a.as_paginate', function(event, xhr, status, error) {
|
222
|
+
if (event.detail && !xhr) {
|
223
|
+
error = event.detail[0];
|
224
|
+
status = event.detail[1];
|
225
|
+
xhr = event.detail[2];
|
226
|
+
}
|
227
|
+
var as_scaffold = jQuery(this).closest('.active-scaffold');
|
228
|
+
ActiveScaffold.report_500_response(as_scaffold, xhr);
|
229
|
+
return true;
|
230
|
+
});
|
231
|
+
jQuery(document).on('ajax:complete', 'a.as_paginate', function(event) {
|
232
|
+
jQuery(this).prevAll('img.loading-indicator').css('visibility','hidden');
|
233
|
+
return true;
|
234
|
+
});
|
235
|
+
jQuery(document).on('ajax:before', 'a.as_add_existing, a.as_replace_existing', function(event) {
|
236
|
+
var prev = jQuery(this).prev();
|
237
|
+
if (!prev.is(':input')) prev = prev.find(':input');
|
238
|
+
var id = prev.val();
|
239
|
+
if (id) {
|
240
|
+
if (!jQuery(this).data('href')) jQuery(this).data('href', jQuery(this).attr('href'));
|
241
|
+
jQuery(this).attr('href', jQuery(this).data('href').replace('--ID--', id));
|
242
|
+
return true;
|
243
|
+
} else return false;
|
244
|
+
});
|
245
|
+
jQuery(document).on('ajax:complete', '.action_group.dyn > ul a', function(event) {
|
246
|
+
var action_link = ActiveScaffold.find_action_link(event.target);
|
247
|
+
if (action_link && action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden');
|
248
|
+
jQuery(event.target).closest('.action_group.dyn > ul').remove();
|
249
|
+
});
|
374
250
|
|
375
|
-
|
376
|
-
|
377
|
-
|
251
|
+
jQuery(document).on('change', 'input.update_form:not(.recordselect), textarea.update_form, select.update_form, .checkbox-list.update_form input:checkbox', function(event) {
|
252
|
+
var element = jQuery(this);
|
253
|
+
var form_element;
|
254
|
+
var value, additional_params;
|
255
|
+
if (element.is(".checkbox-list input:checkbox")) {
|
256
|
+
form_element = element.closest('.checkbox-list')
|
257
|
+
value = form_element.find(':checked').map(function(item){return $(this).val();}).toArray();
|
258
|
+
additional_params = (element.is(':checked') ? '_added=' : '_removed=') + element.val();
|
259
|
+
} else {
|
260
|
+
value = element.is("input:checkbox:not(:checked)") ? null : element.val();
|
261
|
+
form_element = element;
|
262
|
+
}
|
263
|
+
ActiveScaffold.update_column(form_element, form_element.data('update_url'), form_element.data('update_send_form'), element.attr('id'), value, additional_params);
|
264
|
+
return true;
|
265
|
+
});
|
266
|
+
jQuery(document).on('click', 'a.refresh-link', function(event) {
|
267
|
+
event.preventDefault();
|
268
|
+
var element = jQuery(this);
|
269
|
+
var form_element = element.prev();
|
270
|
+
var value;
|
271
|
+
if (form_element.is(".field_with_errors")) form_element = form_element.children().last();
|
272
|
+
if (form_element.is(".checkbox-list")) {
|
273
|
+
value = form_element.find(':checked').map(function(item){return $(this).val();}).toArray();
|
274
|
+
form_element = form_element.parent().find("input:checkbox"); // parent is needed for draggable-list, checked list may be empty
|
275
|
+
} else value = form_element.is("input:checkbox:not(:checked)") ? null : form_element.val();
|
276
|
+
ActiveScaffold.update_column(form_element, element.attr('href'), element.data('update_send_form'), form_element.attr('id'), value);
|
277
|
+
});
|
278
|
+
jQuery(document).on('click', 'a.visibility-toggle', function(e) {
|
279
|
+
var link = jQuery(this), toggable = jQuery('#' + link.data('toggable'));
|
280
|
+
e.preventDefault();
|
281
|
+
toggable.toggle();
|
282
|
+
link.html((toggable.is(':hidden')) ? link.data('show') : link.data('hide'));
|
283
|
+
return false;
|
284
|
+
});
|
285
|
+
jQuery(document).on('recordselect:change', 'input.recordselect.update_form', function(event, id, label) {
|
286
|
+
var element = jQuery(this);
|
287
|
+
ActiveScaffold.update_column(element, element.data('update_url'), element.data('update_send_form'), element.attr('id'), id);
|
288
|
+
return true;
|
289
|
+
});
|
378
290
|
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
jQuery(window).on('popstate', function(e) {
|
386
|
-
var state = e.originalEvent.state;
|
387
|
-
if (!state || !state.active_scaffold) return;
|
388
|
-
jQuery.ajax({
|
389
|
-
url: document.location.href,
|
390
|
-
data: jQuery.extend({'_popstate': true}, state.active_scaffold),
|
391
|
-
dataType: 'script',
|
392
|
-
cache: true
|
393
|
-
});
|
394
|
-
jQuery('.active-scaffold:first th .as_sort:first').closest('th').addClass('loading');
|
395
|
-
});
|
291
|
+
jQuery(document).on('change', 'select.as_search_range_option', function(event) {
|
292
|
+
var element = jQuery(this);
|
293
|
+
ActiveScaffold[element.val() == 'BETWEEN' ? 'show' : 'hide'](element.closest('dd').find('.as_search_range_between'));
|
294
|
+
ActiveScaffold[(element.val() == 'null' || element.val() == 'not_null') ? 'hide' : 'show'](element.attr('id').replace(/_opt/, '_numeric'));
|
295
|
+
return true;
|
296
|
+
});
|
396
297
|
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
ActiveScaffold.setup(e.target);
|
405
|
-
});
|
406
|
-
jQuery(document).on('as:element_removed', function(e, action_link) {
|
407
|
-
setTimeout(ActiveScaffold.update_floating_form_footer); // delay so form is already removed
|
408
|
-
});
|
409
|
-
jQuery(document).on('as:action_success', 'a.as_action', function(e, action_link) {
|
410
|
-
ActiveScaffold.setup(action_link.adapter);
|
411
|
-
});
|
412
|
-
jQuery(document).on('as:element_updated', '.active-scaffold', function(e) {
|
413
|
-
if (e.target != this) return;
|
414
|
-
var search = $(this).find('form.search');
|
415
|
-
if (search.length) ActiveScaffold.focus_first_element_of_form(search);
|
416
|
-
});
|
417
|
-
});
|
418
|
-
|
419
|
-
jQuery(document).on('turbolinks:load turbo:load', function($) {
|
420
|
-
ActiveScaffold.setup(document);
|
421
|
-
});
|
422
|
-
|
423
|
-
|
424
|
-
/* Simple Inheritance
|
425
|
-
http://ejohn.org/blog/simple-javascript-inheritance/
|
426
|
-
*/
|
427
|
-
(function(){
|
428
|
-
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
|
429
|
-
|
430
|
-
// The base Class implementation (does nothing)
|
431
|
-
this.Class = function(){};
|
432
|
-
|
433
|
-
// Create a new Class that inherits from this class
|
434
|
-
Class.extend = function(prop) {
|
435
|
-
var _super = this.prototype;
|
436
|
-
|
437
|
-
// Instantiate a base class (but only create the instance,
|
438
|
-
// don't run the init constructor)
|
439
|
-
initializing = true;
|
440
|
-
var prototype = new this();
|
441
|
-
initializing = false;
|
442
|
-
|
443
|
-
// Copy the properties over onto the new prototype
|
444
|
-
for (var name in prop) {
|
445
|
-
// Check if we're overwriting an existing function
|
446
|
-
prototype[name] = typeof prop[name] == "function" &&
|
447
|
-
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
|
448
|
-
(function(name, fn){
|
449
|
-
return function() {
|
450
|
-
var tmp = this._super;
|
451
|
-
|
452
|
-
// Add a new ._super() method that is the same method
|
453
|
-
// but on the super-class
|
454
|
-
this._super = _super[name];
|
455
|
-
|
456
|
-
// The method only need to be bound temporarily, so we
|
457
|
-
// remove it when we're done executing
|
458
|
-
var ret = fn.apply(this, arguments);
|
459
|
-
this._super = tmp;
|
460
|
-
|
461
|
-
return ret;
|
462
|
-
};
|
463
|
-
})(name, prop[name]) :
|
464
|
-
prop[name];
|
465
|
-
}
|
298
|
+
jQuery(document).on('change', 'select.as_search_date_time_option', function(event) {
|
299
|
+
var element = jQuery(this);
|
300
|
+
ActiveScaffold[!(element.val() == 'PAST' || element.val() == 'FUTURE' || element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_numeric'));
|
301
|
+
ActiveScaffold[(element.val() == 'PAST' || element.val() == 'FUTURE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_trend'));
|
302
|
+
ActiveScaffold[(element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_range'));
|
303
|
+
return true;
|
304
|
+
});
|
466
305
|
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
}
|
306
|
+
jQuery(document).on('change', 'select.as_update_date_operator', function(event) {
|
307
|
+
ActiveScaffold[jQuery(this).val() == 'REPLACE' ? 'show' : 'hide'](jQuery(this).next());
|
308
|
+
ActiveScaffold[jQuery(this).val() == 'REPLACE' ? 'hide' : 'show'](jQuery(this).next().next());
|
309
|
+
return true;
|
310
|
+
});
|
473
311
|
|
474
|
-
|
475
|
-
|
312
|
+
jQuery(document).on('click', '.active-scaffold .sub-form a.destroy', function(event) {
|
313
|
+
event.preventDefault();
|
314
|
+
ActiveScaffold.delete_subform_record($(this).data('delete-id'));
|
315
|
+
});
|
476
316
|
|
477
|
-
|
478
|
-
|
317
|
+
jQuery(document).on("click", '.hover_click', function(event) {
|
318
|
+
var element = jQuery(this);
|
319
|
+
var ul_element = element.children('ul').first();
|
320
|
+
if (ul_element.is(':visible')) {
|
321
|
+
element.find('ul').hide();
|
322
|
+
} else {
|
323
|
+
ul_element.show();
|
324
|
+
}
|
325
|
+
return false;
|
326
|
+
});
|
327
|
+
jQuery(document).on('click', '.hover_click a.as_action', function(event) {
|
328
|
+
var element = jQuery(this).closest('.hover_click');
|
329
|
+
if (element.length) {
|
330
|
+
element.find('ul').hide();
|
331
|
+
}
|
332
|
+
return true;
|
333
|
+
});
|
479
334
|
|
480
|
-
|
481
|
-
|
335
|
+
jQuery(document).on('click', '.message a.close', function(e) {
|
336
|
+
ActiveScaffold.hide(jQuery(this).closest('.message'));
|
337
|
+
e.preventDefault();
|
338
|
+
});
|
482
339
|
|
483
|
-
|
484
|
-
|
485
|
-
|
340
|
+
jQuery(document).on('click', 'form.as_form .no-color', function() {
|
341
|
+
var color_field = jQuery(this).parent().next(':input');
|
342
|
+
color_field.attr('type', jQuery(this).prop('checked') ? 'hidden' : 'color');
|
343
|
+
if (jQuery(this).prop('checked')) color_field.val('');
|
344
|
+
});
|
486
345
|
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
ActiveScaffold.sliders(container);
|
500
|
-
ActiveScaffold.disable_optional_subforms(container);
|
501
|
-
ActiveScaffold.update_floating_form_footer(); // check other forms too, state may change
|
502
|
-
},
|
503
|
-
setup_history_state: function() {
|
504
|
-
if (!jQuery('.active-scaffold').length) return;
|
505
|
-
var data = {}, current_search_item = jQuery('.active-scaffold .filtered-message[data-search]');
|
506
|
-
if (current_search_item.length) {
|
507
|
-
// store user settings enabled, update state with current page, search and sorting
|
508
|
-
var sorted_columns = jQuery('th.sorted');
|
509
|
-
data.page = jQuery('.active-scaffold-pagination .current').text();
|
510
|
-
data.search = current_search_item.data('search');
|
511
|
-
if (sorted_columns.length == 1) {
|
512
|
-
data.sort = sorted_columns.attr('class').match(/(.+)-column/)[1];
|
513
|
-
data.sort_direction = sorted_columns.hasClass('asc') ? 'asc' : 'desc';
|
514
|
-
} else { // default search
|
515
|
-
jQuery.extend(data, {sort: '', sort_direction: ''});
|
516
|
-
}
|
517
|
-
}
|
518
|
-
ActiveScaffold.add_to_history(document.location.href, data, true);
|
519
|
-
},
|
520
|
-
auto_paginate: function(element) {
|
521
|
-
var paginate_link = jQuery('.active-scaffold-pagination.auto-paginate a:first', element);
|
522
|
-
if (paginate_link.length) {
|
523
|
-
var pagination = paginate_link.closest('.auto-paginate');
|
524
|
-
pagination.find('.as_paginate').hide();
|
525
|
-
pagination.find('.loading-indicator').css({visibility: 'visible'});
|
526
|
-
ActiveScaffold.auto_load_page(paginate_link.attr('href'), {auto_pagination: true});
|
527
|
-
}
|
528
|
-
},
|
529
|
-
auto_load_page: function(href, params) {
|
530
|
-
jQuery.get(href, params, null, 'script');
|
531
|
-
},
|
532
|
-
enable_js_form_buttons: function(element) {
|
533
|
-
jQuery('.as-js-button', element).show();
|
534
|
-
},
|
535
|
-
disable_optional_subforms: function(element) {
|
536
|
-
jQuery('.sub-form.optional', element).each(function () {
|
537
|
-
var $this = jQuery(this), toggle = $this.find('>.visibility-toggle');
|
538
|
-
if (toggle.length) {
|
539
|
-
var hide = toggle.text() == toggle.data('show');
|
540
|
-
$this.find('> [id] > .sub-form-record > .associated-record dl:first').each(function (i) {
|
541
|
-
var parent = jQuery(this).parent(), div_id = toggle.data('toggable') + i;
|
542
|
-
parent.children().wrapAll('<div id="' + div_id + '">');
|
543
|
-
if (hide) parent.find('> div').hide();
|
544
|
-
parent.prepend(toggle.clone().data('toggable', div_id));
|
545
|
-
});
|
546
|
-
toggle.remove();
|
547
|
-
}
|
548
|
-
if ($this.is(':visible')) {
|
549
|
-
var line = $this.closest('.form-element'), toggle = line.find('.show-new-subform[data-subform-id="' + $this.attr('id') + '"]').first();
|
550
|
-
if (toggle.is('[type=radio]')) toggle.prop('disabled', true);
|
551
|
-
else if (toggle.data('select-id')) {
|
552
|
-
select = line.find('#' + toggle.data('select-id'));
|
346
|
+
jQuery(document).on('click', '.hide-new-subform, .show-new-subform', function(e) {
|
347
|
+
var $this = jQuery(this), line = $this.closest('.form-element'),
|
348
|
+
subform = line.find('#' + $this.data('subform-id')), radio = false, hide, select;
|
349
|
+
if ($this.is('[type=radio]')) {
|
350
|
+
radio = true;
|
351
|
+
hide = $this.is('.hide-new-subform');
|
352
|
+
} else {
|
353
|
+
e.preventDefault();
|
354
|
+
hide = subform.is(':visible');
|
355
|
+
}
|
356
|
+
if ($this.data('select-id')) {
|
357
|
+
select = line.find('#' + $this.data('select-id'));
|
553
358
|
if (select.hasClass('recordselect') || select.is('.no-options')) select = select.next(':hidden').andSelf();
|
554
|
-
select.hide().prop('disabled', true);
|
555
359
|
}
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
item.closest('.active-scaffold-component').load(item.attr('href'), function(response, status, xhr) {
|
572
|
-
if (status == 'error') {
|
573
|
-
indicator.css({visibility: 'hidden'});
|
574
|
-
indicator.after($('<p>').html(item.data('error-msg')).addClass("error-message message server-error"));
|
575
|
-
} else jQuery(this).trigger('as:element_updated');
|
360
|
+
if (hide) {
|
361
|
+
subform.hide().find("input:enabled,select:enabled,textarea:enabled").prop('disabled', true);
|
362
|
+
if (select) select.show().prop('disabled', false);
|
363
|
+
if (radio) {
|
364
|
+
$this.closest('.form-element').find('[name="' + $this.attr('name') + '"].show-new-subform').prop('disabled', false);
|
365
|
+
} else $this.html($this.data('select-text'));
|
366
|
+
} else {
|
367
|
+
if (select) select.hide().prop('disabled', true);
|
368
|
+
subform.show().find("input:disabled,select:disabled,textarea:disabled").prop('disabled', false);
|
369
|
+
if (radio) $this.prop('disabled', true);
|
370
|
+
else {
|
371
|
+
$this.data('select-text', $this.html());
|
372
|
+
$this.html($this.data('subform-text'));
|
373
|
+
}
|
374
|
+
}
|
576
375
|
});
|
577
|
-
});
|
578
|
-
},
|
579
|
-
reload_embedded: function(element_or_selector) {
|
580
|
-
var item = jQuery(element_or_selector);
|
581
|
-
item.load(item.data('refresh'), function() {
|
582
|
-
jQuery(this).trigger('as:element_updated');
|
583
|
-
});
|
584
|
-
},
|
585
|
-
|
586
|
-
records_for: function(tbody_id) {
|
587
|
-
if (typeof(tbody_id) == 'string') tbody_id = '#' + tbody_id;
|
588
|
-
return jQuery(tbody_id).children('.record');
|
589
|
-
},
|
590
|
-
stripe: function(tbody_id) {
|
591
|
-
var even = false;
|
592
|
-
var rows = this.records_for(tbody_id);
|
593
|
-
|
594
|
-
rows.each(function (index, row_node) {
|
595
|
-
row = jQuery(row_node);
|
596
|
-
if (row_node.tagName != 'SCRIPT'
|
597
|
-
&& !row.hasClass("create")
|
598
|
-
&& !row.hasClass("update")
|
599
|
-
&& !row.hasClass("inline-adapter")
|
600
|
-
&& !row.hasClass("active-scaffold-calculations")) {
|
601
|
-
|
602
|
-
if (even) row.addClass("even-record");
|
603
|
-
else row.removeClass("even-record");
|
604
|
-
|
605
|
-
even = !even;
|
606
|
-
}
|
607
|
-
});
|
608
|
-
},
|
609
|
-
hide_empty_message: function(tbody) {
|
610
|
-
if (this.records_for(tbody).length != 0) {
|
611
|
-
jQuery(tbody).parent().find('tbody.messages p.empty-message').hide();
|
612
|
-
}
|
613
|
-
},
|
614
|
-
reload_if_empty: function(tbody, url) {
|
615
|
-
if (this.records_for(tbody).length == 0) {
|
616
|
-
this.reload(url);
|
617
|
-
}
|
618
|
-
},
|
619
|
-
reload: function(url) {
|
620
|
-
jQuery.getScript(url);
|
621
|
-
},
|
622
|
-
removeSortClasses: function(scaffold) {
|
623
|
-
if (typeof(scaffold) == 'string') scaffold = '#' + scaffold;
|
624
|
-
scaffold = jQuery(scaffold)
|
625
|
-
scaffold.find('td.sorted').each(function(index, element) {
|
626
|
-
jQuery(element).removeClass("sorted");
|
627
|
-
});
|
628
|
-
scaffold.find('th.sorted').each(function(index, element) {
|
629
|
-
element = jQuery(element);
|
630
|
-
element.removeClass("sorted");
|
631
|
-
element.removeClass("asc");
|
632
|
-
element.removeClass("desc");
|
633
|
-
});
|
634
|
-
},
|
635
|
-
add_to_history: function(url, data, replace) {
|
636
|
-
if (!history || !history.pushState) return;
|
637
|
-
data = {active_scaffold: data};
|
638
|
-
if (replace) history.replaceState(data, null, url);
|
639
|
-
else history.pushState(data, null, url);
|
640
|
-
},
|
641
|
-
decrement_record_count: function(scaffold) {
|
642
|
-
// decrement the last record count, firsts record count are in nested lists
|
643
|
-
if (typeof(scaffold) == 'string') scaffold = '#' + scaffold;
|
644
|
-
scaffold = jQuery(scaffold);
|
645
|
-
count = scaffold.find('span.active-scaffold-records').last();
|
646
|
-
if (count) count.html(parseInt(count.html(), 10) - 1);
|
647
|
-
},
|
648
|
-
increment_record_count: function(scaffold) {
|
649
|
-
// increment the last record count, firsts record count are in nested lists
|
650
|
-
if (typeof(scaffold) == 'string') scaffold = '#' + scaffold;
|
651
|
-
scaffold = jQuery(scaffold);
|
652
|
-
count = scaffold.find('span.active-scaffold-records').last();
|
653
|
-
if (count) count.html(parseInt(count.html(), 10) + 1);
|
654
|
-
},
|
655
|
-
update_row: function(row, html) {
|
656
|
-
var even_row = false;
|
657
|
-
var replaced = null;
|
658
|
-
if (typeof(row) == 'string') row = '#' + row;
|
659
|
-
row = jQuery(row);
|
660
|
-
if (row.hasClass('even-record')) even_row = true;
|
661
|
-
|
662
|
-
replaced = this.replace(row, html);
|
663
|
-
if (replaced) {
|
664
|
-
if (even_row === true) replaced.addClass('even-record');
|
665
|
-
ActiveScaffold.highlight(replaced);
|
666
|
-
}
|
667
|
-
},
|
668
|
-
|
669
|
-
replace: function(element, html) {
|
670
|
-
if (typeof(element) == 'string') element = '#' + element;
|
671
|
-
element = jQuery(element);
|
672
|
-
var new_element = typeof(html) == 'string' ? jQuery.parseHTML(jQuery.trim(html), true) : html;
|
673
|
-
new_element = jQuery(new_element);
|
674
|
-
if (element.length) {
|
675
|
-
element.replaceWith(new_element);
|
676
|
-
new_element.trigger('as:element_updated');
|
677
|
-
return new_element;
|
678
|
-
} else return null;
|
679
|
-
},
|
680
|
-
|
681
|
-
replace_html: function(element, html) {
|
682
|
-
if (typeof(element) == 'string') element = '#' + element;
|
683
|
-
element = jQuery(element);
|
684
|
-
if (element.length) {
|
685
|
-
element.html(html);
|
686
|
-
element.trigger('as:element_updated');
|
687
|
-
}
|
688
|
-
return element;
|
689
|
-
},
|
690
|
-
|
691
|
-
append: function(element, html) {
|
692
|
-
if (typeof(element) == 'string') element = '#' + element;
|
693
|
-
element = jQuery(element);
|
694
|
-
element.append(html);
|
695
|
-
element.trigger('as:element_updated');
|
696
|
-
return element;
|
697
|
-
},
|
698
|
-
|
699
|
-
remove: function(element, callback) {
|
700
|
-
if (typeof(element) == 'string') element = '#' + element;
|
701
|
-
jQuery(element).trigger('as:element_removed').remove();
|
702
|
-
if (callback) callback();
|
703
|
-
},
|
704
|
-
|
705
|
-
update_inplace_edit: function(element, value, empty) {
|
706
|
-
if (typeof(element) == 'string') element = '#' + element;
|
707
|
-
this.replace_html(jQuery(element), value);
|
708
|
-
jQuery(element).closest('td')[empty ? 'addClass' : 'removeClass']('empty');
|
709
|
-
},
|
710
|
-
|
711
|
-
hide: function(element) {
|
712
|
-
if (typeof(element) == 'string') element = '#' + element;
|
713
|
-
jQuery(element).hide();
|
714
|
-
},
|
715
|
-
|
716
|
-
show: function(element) {
|
717
|
-
if (typeof(element) == 'string') element = '#' + element;
|
718
|
-
jQuery(element).show();
|
719
|
-
},
|
720
|
-
|
721
|
-
reset_form: function(element) {
|
722
|
-
if (typeof(element) == 'string') element = '#' + element;
|
723
|
-
jQuery(element).get(0).reset();
|
724
|
-
},
|
725
|
-
|
726
|
-
disable_form: function(as_form, skip_loading_indicator) {
|
727
|
-
if (typeof(as_form) == 'string') as_form = '#' + as_form;
|
728
|
-
as_form = jQuery(as_form);
|
729
|
-
var loading_indicator = jQuery('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator'));
|
730
|
-
if (!skip_loading_indicator && loading_indicator) loading_indicator.css('visibility','visible');
|
731
|
-
jQuery('input[type=submit]', as_form).attr('disabled', 'disabled');
|
732
|
-
jQuery('.sub-form a.destroy', as_form).addClass('disabled');
|
733
|
-
if (jQuery.fn.droppable) jQuery('.draggable-list', as_form).sortable('disable');
|
734
|
-
// data-remote-disabled attr instead of set data because is used to in selector later
|
735
|
-
jQuery("input:enabled,select:enabled,textarea:enabled", as_form).attr('disabled', 'disabled').attr('data-remove-disabled', true);
|
736
|
-
},
|
737
|
-
|
738
|
-
enable_form: function(as_form, skip_loading_indicator) {
|
739
|
-
if (typeof(as_form) == 'string') as_form = '#' + as_form;
|
740
|
-
as_form = jQuery(as_form)
|
741
|
-
var loading_indicator = jQuery('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator'));
|
742
|
-
if (!skip_loading_indicator && loading_indicator) loading_indicator.css('visibility','hidden');
|
743
|
-
jQuery('input[type=submit]', as_form).removeAttr('disabled');
|
744
|
-
jQuery('.sub-form a.destroy.disabled', as_form).removeClass('disabled');
|
745
|
-
if (jQuery.fn.droppable) jQuery('.draggable-list', as_form).sortable('enable');
|
746
|
-
jQuery("input[data-remove-disabled],select[data-remove-disabled],textarea[data-remove-disabled]", as_form).removeAttr('disabled data-remove-disabled');
|
747
|
-
},
|
748
|
-
|
749
|
-
focus_first_element_of_form: function(form_element, form_selector) {
|
750
|
-
if (typeof(form_element) == 'string') form_element = '#' + form_element;
|
751
|
-
if (typeof(form_selector) == 'undefined') form_selector = jQuery(form_element).is('form') ? '' : 'form ';
|
752
|
-
var input = jQuery(form_selector + ":input:visible:first", jQuery(form_element));
|
753
|
-
if (input.is('.no-autofocus :input')) return;
|
754
|
-
input.focus();
|
755
|
-
try { if (input[0] && input[0].value) input[0].selectionStart = input[0].selectionEnd = input[0].value.length; } catch(e) {}
|
756
|
-
},
|
757
|
-
|
758
|
-
create_record_row: function(active_scaffold_id, html, options) {
|
759
|
-
if (typeof(active_scaffold_id) == 'string') active_scaffold_id = '#' + active_scaffold_id;
|
760
|
-
tbody = jQuery(active_scaffold_id).find('tbody.records').first();
|
761
|
-
var new_row;
|
762
|
-
|
763
|
-
if (options.insert_at == 'top') {
|
764
|
-
tbody.prepend(html);
|
765
|
-
new_row = tbody.children('tr.record:first-child');
|
766
|
-
} else if (options.insert_at == 'bottom') {
|
767
|
-
var rows = tbody.children('tr.record, tr.inline-adapter');
|
768
|
-
if (rows.length > 0) {
|
769
|
-
new_row = rows.last().after(html).next();
|
770
|
-
} else {
|
771
|
-
new_row = tbody.append(html).children().last();
|
772
|
-
}
|
773
|
-
} else if (typeof options.insert_at == 'object') {
|
774
|
-
var insert_method, get_method, row, id;
|
775
|
-
if (options.insert_at.after) {
|
776
|
-
insert_method = 'after';
|
777
|
-
get_method = 'next';
|
778
|
-
} else {
|
779
|
-
insert_method = 'before';
|
780
|
-
get_method = 'prev';
|
781
|
-
}
|
782
|
-
if (id = options.insert_at[insert_method]) row = tbody.children('#' + id);
|
783
|
-
if (row && row.length) {
|
784
|
-
new_row = row[insert_method](html)[get_method]();
|
785
|
-
}
|
786
|
-
}
|
787
|
-
this.stripe(tbody);
|
788
|
-
this.hide_empty_message(tbody);
|
789
|
-
this.increment_record_count(tbody.closest('div.active-scaffold'));
|
790
|
-
this.highlight(new_row);
|
791
|
-
new_row.trigger('as:element_created');
|
792
|
-
},
|
793
|
-
|
794
|
-
create_record_row_from_url: function(action_link, url, options) {
|
795
|
-
jQuery.get(url, function(row) {
|
796
|
-
ActiveScaffold.create_record_row(action_link.scaffold(), row, options);
|
797
|
-
action_link.close();
|
798
|
-
});
|
799
|
-
},
|
800
376
|
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
377
|
+
jQuery(document).on('input paste', 'form.search.live input[type=search]', $.debounce((ActiveScaffold.config.live_search_delay || 0.5) * 1000, function() {
|
378
|
+
jQuery(this).parent().find('[type=submit]').click();
|
379
|
+
}));
|
380
|
+
|
381
|
+
jQuery(document).on('click', 'form.search .reset[data-reset]', function(e){
|
382
|
+
e.preventDefault();
|
383
|
+
var form = jQuery(this).closest('form.search');
|
384
|
+
form.find(
|
385
|
+
'input:not([type=button]):not([type=submit]):not([type=reset]):not([type=hidden]),' +
|
386
|
+
'textarea, select:has(option[value=""])'
|
387
|
+
).val('');
|
388
|
+
form.find('select.as_search_range_option').each(function() { $(this).val($(this).find('option:first').val()) });
|
389
|
+
form.find('select.as_search_date_time_option').val('BETWEEN');
|
390
|
+
});
|
805
391
|
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
392
|
+
jQuery(document).on('turbolinks:before-visit turbo:before-visit', function() {
|
393
|
+
if (history.state.active_scaffold) {
|
394
|
+
history.replaceState({turbolinks: true, url: document.location.href}, '', document.location.href);
|
395
|
+
}
|
396
|
+
});
|
810
397
|
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
ActiveScaffold.highlight(server_error);
|
828
|
-
} else {
|
829
|
-
server_error.show();
|
830
|
-
}
|
831
|
-
if (xhr) server_error.find('.error-500')[xhr.status < 500 ? 'hide' : 'show']();
|
832
|
-
ActiveScaffold.scroll_to(server_error, ActiveScaffold.config.scroll_on_close == 'checkInViewport');
|
833
|
-
},
|
834
|
-
|
835
|
-
find_action_link: function(element) {
|
836
|
-
if (typeof(element) == 'string') element = '#' + element;
|
837
|
-
element = jQuery(element);
|
838
|
-
return ActiveScaffold.ActionLink.get(element.is('.actions a') ? element : element.closest('.as_adapter'));
|
839
|
-
},
|
840
|
-
|
841
|
-
display_dynamic_action_group: function(link, html) {
|
842
|
-
var container;
|
843
|
-
if (typeof(link) == 'string') link = jQuery('#' + link);
|
844
|
-
if (link.closest('td.actions').length) {
|
845
|
-
container = link.closest('td').addClass('action_group dyn');
|
846
|
-
} else {
|
847
|
-
if (link.parent('div.actions').length) link.wrap(jQuery('<div>'));
|
848
|
-
container = link.parent().addClass('action_group dyn');
|
849
|
-
}
|
850
|
-
container.find('> ul').remove();
|
851
|
-
container.append(html);
|
852
|
-
},
|
853
|
-
|
854
|
-
scroll_to: function(element, checkInViewport) {
|
855
|
-
if (typeof checkInViewport == 'undefined') checkInViewport = true;
|
856
|
-
if (typeof(element) == 'string') element = '#' + element;
|
857
|
-
element = jQuery(element);
|
858
|
-
if (!element.length) return;
|
859
|
-
if (checkInViewport && element.visible()) return;
|
860
|
-
jQuery(document).scrollTop(element.offset().top);
|
861
|
-
},
|
862
|
-
|
863
|
-
process_checkbox_inplace_edit: function(checkbox, options) {
|
864
|
-
var checked = checkbox.is(':checked'), td = checkbox.closest('td');
|
865
|
-
if (checked === true) options['params'] += '&value=1';
|
866
|
-
jQuery.ajax({
|
867
|
-
url: options.url,
|
868
|
-
type: "POST",
|
869
|
-
data: options['params'],
|
870
|
-
dataType: options.ajax_data_type,
|
871
|
-
beforeSend: function(request, settings) {
|
872
|
-
if (options.beforeSend) options.beforeSend.call(checkbox, request, settings);
|
873
|
-
checkbox.attr('disabled', 'disabled');
|
874
|
-
td.closest('tr').find('td.actions .loading-indicator').css('visibility','visible');
|
875
|
-
},
|
876
|
-
complete: function(request){
|
877
|
-
checkbox.removeAttr('disabled');
|
878
|
-
},
|
879
|
-
success: function(request){
|
880
|
-
td.closest('tr').find('td.actions .loading-indicator').css('visibility','hidden');
|
398
|
+
jQuery(window).on('popstate', function(e) {
|
399
|
+
var state = e.originalEvent.state;
|
400
|
+
if (!state || !state.active_scaffold) return;
|
401
|
+
jQuery.ajax({
|
402
|
+
url: document.location.href,
|
403
|
+
data: jQuery.extend({'_popstate': true}, state.active_scaffold),
|
404
|
+
dataType: 'script',
|
405
|
+
cache: true
|
406
|
+
});
|
407
|
+
jQuery('.active-scaffold:first th .as_sort:first').closest('th').addClass('loading');
|
408
|
+
});
|
409
|
+
|
410
|
+
// call setup on document.ready if Turbolinks not enabled
|
411
|
+
if ((typeof(Turbolinks) == 'undefined' || !Turbolinks.supported) && typeof(Turbo) == 'undefined') {
|
412
|
+
ActiveScaffold.setup_history_state();
|
413
|
+
ActiveScaffold.setup(document);
|
881
414
|
}
|
415
|
+
if (ActiveScaffold.config.warn_changes) ActiveScaffold.setup_warn_changes();
|
416
|
+
jQuery(document).on('as:element_updated as:element_created', function(e, action_link) {
|
417
|
+
ActiveScaffold.setup(e.target);
|
418
|
+
});
|
419
|
+
jQuery(document).on('as:element_removed', function(e, action_link) {
|
420
|
+
setTimeout(ActiveScaffold.update_floating_form_footer); // delay so form is already removed
|
421
|
+
});
|
422
|
+
jQuery(document).on('as:action_success', 'a.as_action', function(e, action_link) {
|
423
|
+
ActiveScaffold.setup(action_link.adapter);
|
424
|
+
});
|
425
|
+
jQuery(document).on('as:element_updated', '.active-scaffold', function(e) {
|
426
|
+
if (e.target != this) return;
|
427
|
+
var search = $(this).find('form.search');
|
428
|
+
if (search.length) ActiveScaffold.focus_first_element_of_form(search);
|
429
|
+
});
|
882
430
|
});
|
883
|
-
},
|
884
|
-
|
885
|
-
read_inplace_edit_heading_attributes: function(column_heading, options) {
|
886
|
-
if (column_heading.data('ie-cancel-text')) options.cancel_button = '<button class="inplace_cancel">' + column_heading.data('ie-cancel-text') + "</button>";
|
887
|
-
if (column_heading.data('ie-loading-text')) options.loading_text = column_heading.data('ie-loading-text');
|
888
|
-
if (column_heading.data('ie-saving-text')) options.saving_text = column_heading.data('ie-saving-text');
|
889
|
-
if (column_heading.data('ie-save-text')) options.save_button = '<button class="inplace_save">' + column_heading.data('ie-save-text') + "</button>";
|
890
|
-
if (column_heading.data('ie-rows')) options.textarea_rows = column_heading.data('ie-rows');
|
891
|
-
if (column_heading.data('ie-cols')) options.textarea_cols = column_heading.data('ie-cols');
|
892
|
-
if (column_heading.data('ie-size')) options.text_size = column_heading.data('ie-size');
|
893
|
-
if (column_heading.data('ie-use-html')) options.use_html = column_heading.data('ie-use-html');
|
894
|
-
},
|
895
|
-
|
896
|
-
create_inplace_editor: function(span, options) {
|
897
|
-
span.removeClass('hover');
|
898
|
-
span.editInPlace(options);
|
899
|
-
span.trigger('click.editInPlace');
|
900
|
-
},
|
901
|
-
|
902
|
-
highlight: function(element) {
|
903
|
-
if (typeof(element) == 'string') element = jQuery('#' + element);
|
904
|
-
if (typeof(element.effect) == 'function') {
|
905
|
-
element.effect("highlight", jQuery.extend({}, ActiveScaffold.config.highlight), 3000);
|
906
|
-
}
|
907
|
-
},
|
908
|
-
|
909
|
-
create_associated_record_form: function(element, content, options) {
|
910
|
-
if (typeof(element) == 'string') element = '#' + element;
|
911
|
-
var element = jQuery(element);
|
912
|
-
content = jQuery(content);
|
913
|
-
if (options.singular == false) {
|
914
|
-
if (!(options.id && jQuery('#' + options.id).size() > 0)) {
|
915
|
-
var tfoot = element.children('tfoot');
|
916
|
-
if (tfoot.length) tfoot.before(content);
|
917
|
-
else element.append(content);
|
918
|
-
}
|
919
|
-
} else {
|
920
|
-
var current = jQuery('#' + element.attr('id') + ' .sub-form-record')
|
921
|
-
if (current[0]) {
|
922
|
-
this.replace(current[0], content);
|
923
|
-
} else {
|
924
|
-
element.prepend(content);
|
925
|
-
}
|
926
|
-
}
|
927
|
-
content.trigger('as:element_created');
|
928
|
-
ActiveScaffold.focus_first_element_of_form(content, '');
|
929
|
-
},
|
930
|
-
|
931
|
-
render_form_field: function(source, content, options) {
|
932
|
-
if (typeof(source) == 'string') source = '#' + source;
|
933
|
-
var source = jQuery(source);
|
934
|
-
var element, container = source.closest('.sub-form-record'), selector = '';
|
935
|
-
if (container.length == 0) {
|
936
|
-
container = source.closest('form > ol.form');
|
937
|
-
selector = 'li';
|
938
|
-
}
|
939
|
-
// find without entering new subforms
|
940
|
-
element = container.find(selector + ':not(.sub-form) .' + options.field_class).first();
|
941
|
-
if (element.length)
|
942
|
-
element = element.closest('dl');
|
943
|
-
else if (options.subform_class)
|
944
|
-
element = container.find(selector + '.' + options.subform_class).first();
|
945
|
-
|
946
|
-
if (element.length) {
|
947
|
-
var parent = element.is('li, td') ? element : element.parent('li, td');
|
948
|
-
if (element.is('li'))
|
949
|
-
this.replace_html(element, content);
|
950
|
-
else
|
951
|
-
this.replace(element, content);
|
952
|
-
if (parent.is('li')) {
|
953
|
-
for (var attr in options.attrs)
|
954
|
-
parent.attr(attr, options.attrs[attr]);
|
955
|
-
}
|
956
|
-
if (typeof(options.hidden) != 'undefined')
|
957
|
-
parent[options.hidden ? 'addClass' : 'removeClass'].call(parent, 'hidden')
|
958
|
-
}
|
959
|
-
},
|
960
431
|
|
961
|
-
|
962
|
-
|
963
|
-
url: edit_associated_url.replace('--ID--', id),
|
964
|
-
error: function(xhr, textStatus, errorThrown){
|
965
|
-
ActiveScaffold.report_500_response(active_scaffold_id, xhr)
|
966
|
-
}
|
432
|
+
jQuery(document).on('turbolinks:load turbo:load', function($) {
|
433
|
+
ActiveScaffold.setup(document);
|
967
434
|
});
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
435
|
+
|
436
|
+
|
437
|
+
/* Simple JavaScript Inheritance for ES 5.1
|
438
|
+
* based on http://ejohn.org/blog/simple-javascript-inheritance/
|
439
|
+
* (inspired by base2 and Prototype)
|
440
|
+
* MIT Licensed.
|
441
|
+
*/
|
442
|
+
(function(global) {
|
443
|
+
"use strict";
|
444
|
+
var fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
|
445
|
+
|
446
|
+
// The base Class implementation (does nothing)
|
447
|
+
function BaseClass(){}
|
448
|
+
|
449
|
+
// Create a new Class that inherits from this class
|
450
|
+
BaseClass.extend = function(props) {
|
451
|
+
var _super = this.prototype;
|
452
|
+
|
453
|
+
// Set up the prototype to inherit from the base class
|
454
|
+
// (but without running the init constructor)
|
455
|
+
var proto = Object.create(_super);
|
456
|
+
|
457
|
+
// Copy the properties over onto the new prototype
|
458
|
+
for (var name in props) {
|
459
|
+
// Check if we're overwriting an existing function
|
460
|
+
proto[name] = typeof props[name] === "function" &&
|
461
|
+
typeof _super[name] == "function" && fnTest.test(props[name])
|
462
|
+
? (function(name, fn){
|
463
|
+
return function() {
|
464
|
+
var tmp = this._super;
|
465
|
+
|
466
|
+
// Add a new ._super() method that is the same method
|
467
|
+
// but on the super-class
|
468
|
+
this._super = _super[name];
|
469
|
+
|
470
|
+
// The method only need to be bound temporarily, so we
|
471
|
+
// remove it when we're done executing
|
472
|
+
var ret = fn.apply(this, arguments);
|
473
|
+
this._super = tmp;
|
474
|
+
|
475
|
+
return ret;
|
476
|
+
};
|
477
|
+
})(name, props[name])
|
478
|
+
: props[name];
|
479
|
+
}
|
480
|
+
|
481
|
+
// The new constructor
|
482
|
+
var newClass = typeof proto.init === "function"
|
483
|
+
? proto.hasOwnProperty("init")
|
484
|
+
? proto.init // All construction is actually done in the init method
|
485
|
+
: function SubClass(){ _super.init.apply(this, arguments); }
|
486
|
+
: function EmptyClass(){};
|
487
|
+
|
488
|
+
// Populate our constructed prototype object
|
489
|
+
newClass.prototype = proto;
|
490
|
+
|
491
|
+
// Enforce the constructor to be what we expect
|
492
|
+
proto.constructor = newClass;
|
493
|
+
|
494
|
+
// And make this class extendable
|
495
|
+
newClass.extend = BaseClass.extend;
|
496
|
+
|
497
|
+
return newClass;
|
498
|
+
};
|
499
|
+
|
500
|
+
// export
|
501
|
+
global.Class = BaseClass;
|
502
|
+
})(window);
|
503
|
+
|
504
|
+
/*
|
505
|
+
* Simple utility methods
|
506
|
+
*/
|
507
|
+
|
508
|
+
window.ActiveScaffold = {
|
509
|
+
last_focus: null,
|
510
|
+
setup: function(container) {
|
511
|
+
/* setup some elements on page/form load */
|
512
|
+
ActiveScaffold.load_embedded(container);
|
513
|
+
ActiveScaffold.enable_js_form_buttons(container);
|
514
|
+
ActiveScaffold.auto_paginate(container);
|
515
|
+
ActiveScaffold.draggable_lists('.draggable-lists', container);
|
516
|
+
ActiveScaffold.sliders(container);
|
517
|
+
ActiveScaffold.disable_optional_subforms(container);
|
518
|
+
ActiveScaffold.update_floating_form_footer(); // check other forms too, state may change
|
519
|
+
},
|
520
|
+
setup_history_state: function() {
|
521
|
+
if (!jQuery('.active-scaffold').length) return;
|
522
|
+
var data = {}, current_search_item = jQuery('.active-scaffold .filtered-message[data-search]');
|
523
|
+
if (current_search_item.length) {
|
524
|
+
// store user settings enabled, update state with current page, search and sorting
|
525
|
+
var sorted_columns = jQuery('th.sorted');
|
526
|
+
data.page = jQuery('.active-scaffold-pagination .current').text();
|
527
|
+
data.search = current_search_item.data('search');
|
528
|
+
if (sorted_columns.length == 1) {
|
529
|
+
data.sort = sorted_columns.attr('class').match(/(.+)-column/)[1];
|
530
|
+
data.sort_direction = sorted_columns.hasClass('asc') ? 'asc' : 'desc';
|
531
|
+
} else { // default search
|
532
|
+
jQuery.extend(data, {sort: '', sort_direction: ''});
|
533
|
+
}
|
534
|
+
}
|
535
|
+
ActiveScaffold.add_to_history(document.location.href, data, true);
|
536
|
+
},
|
537
|
+
auto_paginate: function(element) {
|
538
|
+
var paginate_link = jQuery('.active-scaffold-pagination.auto-paginate a:first', element);
|
539
|
+
if (paginate_link.length) {
|
540
|
+
var pagination = paginate_link.closest('.auto-paginate');
|
541
|
+
pagination.find('.as_paginate').hide();
|
542
|
+
pagination.find('.loading-indicator').css({visibility: 'visible'});
|
543
|
+
ActiveScaffold.auto_load_page(paginate_link.attr('href'), {auto_pagination: true});
|
544
|
+
}
|
545
|
+
},
|
546
|
+
auto_load_page: function(href, params) {
|
547
|
+
jQuery.get(href, params, null, 'script');
|
548
|
+
},
|
549
|
+
enable_js_form_buttons: function(element) {
|
550
|
+
jQuery('.as-js-button', element).show();
|
551
|
+
},
|
552
|
+
disable_optional_subforms: function(element) {
|
553
|
+
jQuery('.sub-form.optional', element).each(function () {
|
554
|
+
var $this = jQuery(this), toggle = $this.find('>.visibility-toggle');
|
555
|
+
if (toggle.length) {
|
556
|
+
var hide = toggle.text() == toggle.data('show');
|
557
|
+
$this.find('> [id] > .sub-form-record > .associated-record dl:first').each(function (i) {
|
558
|
+
var parent = jQuery(this).parent(), div_id = toggle.data('toggable') + i;
|
559
|
+
parent.children().wrapAll('<div id="' + div_id + '">');
|
560
|
+
if (hide) parent.find('> div').hide();
|
561
|
+
parent.prepend(toggle.clone().data('toggable', div_id));
|
562
|
+
});
|
563
|
+
toggle.remove();
|
564
|
+
}
|
565
|
+
if ($this.is(':visible')) {
|
566
|
+
var line = $this.closest('.form-element'), toggle = line.find('.show-new-subform[data-subform-id="' + $this.attr('id') + '"]').first();
|
567
|
+
if (toggle.is('[type=radio]')) toggle.prop('disabled', true);
|
568
|
+
else if (toggle.data('select-id')) {
|
569
|
+
var select = line.find('#' + toggle.data('select-id'));
|
570
|
+
if (select.hasClass('recordselect') || select.is('.no-options')) select = select.next(':hidden').andSelf();
|
571
|
+
select.hide().prop('disabled', true);
|
1000
572
|
}
|
1001
|
-
},
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
}
|
573
|
+
} else $this.find("input:enabled,select:enabled,textarea:enabled").prop('disabled', true);
|
574
|
+
});
|
575
|
+
},
|
576
|
+
sliders: function(element) {
|
577
|
+
jQuery('.as-slider', element).each(function() {
|
578
|
+
var opts = $(this).data('slider');
|
579
|
+
jQuery(this).slider(opts);
|
580
|
+
if (opts.disabled) jQuery(this).find('.ui-slider-handle').hide();
|
581
|
+
});
|
582
|
+
},
|
583
|
+
load_embedded: function(element) {
|
584
|
+
jQuery('.active-scaffold-component .load-embedded', element).each(function(index, item) {
|
585
|
+
item = jQuery(item);
|
586
|
+
var indicator = item.closest('.active-scaffold-component').find('.loading-indicator');
|
587
|
+
indicator.css({visibility: 'visible'});
|
588
|
+
item.closest('.active-scaffold-component').load(item.attr('href'), function(response, status, xhr) {
|
589
|
+
if (status == 'error') {
|
590
|
+
indicator.css({visibility: 'hidden'});
|
591
|
+
indicator.after($('<p>').html(item.data('error-msg')).addClass("error-message message server-error"));
|
592
|
+
} else jQuery(this).trigger('as:element_updated');
|
593
|
+
});
|
594
|
+
});
|
595
|
+
},
|
596
|
+
reload_embedded: function(element_or_selector) {
|
597
|
+
var item = jQuery(element_or_selector);
|
598
|
+
item.load(item.data('refresh'), function() {
|
599
|
+
jQuery(this).trigger('as:element_updated');
|
600
|
+
});
|
601
|
+
},
|
1011
602
|
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
}
|
1016
|
-
|
1017
|
-
|
603
|
+
records_for: function(tbody_id) {
|
604
|
+
if (typeof(tbody_id) == 'string') tbody_id = '#' + tbody_id;
|
605
|
+
return jQuery(tbody_id).children('.record');
|
606
|
+
},
|
607
|
+
stripe: function(tbody_id) {
|
608
|
+
var even = false;
|
609
|
+
var rows = this.records_for(tbody_id);
|
610
|
+
|
611
|
+
rows.each(function (index, row_node) {
|
612
|
+
var row = jQuery(row_node);
|
613
|
+
if (row_node.tagName != 'SCRIPT'
|
614
|
+
&& !row.hasClass("create")
|
615
|
+
&& !row.hasClass("update")
|
616
|
+
&& !row.hasClass("inline-adapter")
|
617
|
+
&& !row.hasClass("active-scaffold-calculations")) {
|
618
|
+
|
619
|
+
if (even) row.addClass("even-record");
|
620
|
+
else row.removeClass("even-record");
|
621
|
+
|
622
|
+
even = !even;
|
623
|
+
}
|
624
|
+
});
|
625
|
+
},
|
626
|
+
hide_empty_message: function(tbody) {
|
627
|
+
if (this.records_for(tbody).length != 0) {
|
628
|
+
jQuery(tbody).parent().find('tbody.messages p.empty-message').hide();
|
629
|
+
}
|
630
|
+
},
|
631
|
+
reload_if_empty: function(tbody, url) {
|
632
|
+
if (this.records_for(tbody).length == 0) {
|
633
|
+
this.reload(url);
|
634
|
+
}
|
635
|
+
},
|
636
|
+
reload: function(url) {
|
637
|
+
jQuery.getScript(url);
|
638
|
+
},
|
639
|
+
removeSortClasses: function(scaffold) {
|
640
|
+
if (typeof(scaffold) == 'string') scaffold = '#' + scaffold;
|
641
|
+
scaffold = jQuery(scaffold)
|
642
|
+
scaffold.find('td.sorted').each(function(index, element) {
|
643
|
+
jQuery(element).removeClass("sorted");
|
644
|
+
});
|
645
|
+
scaffold.find('th.sorted').each(function(index, element) {
|
646
|
+
element = jQuery(element);
|
647
|
+
element.removeClass("sorted");
|
648
|
+
element.removeClass("asc");
|
649
|
+
element.removeClass("desc");
|
650
|
+
});
|
651
|
+
},
|
652
|
+
add_to_history: function(url, data, replace) {
|
653
|
+
if (!history || !history.pushState) return;
|
654
|
+
data = {active_scaffold: data};
|
655
|
+
if (replace) history.replaceState(data, null, url);
|
656
|
+
else history.pushState(data, null, url);
|
657
|
+
},
|
658
|
+
decrement_record_count: function(scaffold) {
|
659
|
+
// decrement the last record count, firsts record count are in nested lists
|
660
|
+
if (typeof(scaffold) == 'string') scaffold = '#' + scaffold;
|
661
|
+
scaffold = jQuery(scaffold);
|
662
|
+
var count = scaffold.find('span.active-scaffold-records').last();
|
663
|
+
if (count) count.html(parseInt(count.html(), 10) - 1);
|
664
|
+
},
|
665
|
+
increment_record_count: function(scaffold) {
|
666
|
+
// increment the last record count, firsts record count are in nested lists
|
667
|
+
if (typeof(scaffold) == 'string') scaffold = '#' + scaffold;
|
668
|
+
scaffold = jQuery(scaffold);
|
669
|
+
var count = scaffold.find('span.active-scaffold-records').last();
|
670
|
+
if (count) count.html(parseInt(count.html(), 10) + 1);
|
671
|
+
},
|
672
|
+
update_row: function(row, html) {
|
673
|
+
var even_row = false;
|
674
|
+
var replaced = null;
|
675
|
+
if (typeof(row) == 'string') row = '#' + row;
|
676
|
+
row = jQuery(row);
|
677
|
+
if (row.hasClass('even-record')) even_row = true;
|
678
|
+
|
679
|
+
replaced = this.replace(row, html);
|
680
|
+
if (replaced) {
|
681
|
+
if (even_row === true) replaced.addClass('even-record');
|
682
|
+
ActiveScaffold.highlight(replaced);
|
683
|
+
}
|
684
|
+
},
|
1018
685
|
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
686
|
+
replace: function(element, html) {
|
687
|
+
if (typeof(element) == 'string') element = '#' + element;
|
688
|
+
element = jQuery(element);
|
689
|
+
var new_element = typeof(html) == 'string' ? jQuery.parseHTML(jQuery.trim(html), true) : html;
|
690
|
+
new_element = jQuery(new_element);
|
691
|
+
if (element.length) {
|
692
|
+
element.replaceWith(new_element);
|
693
|
+
new_element.trigger('as:element_updated');
|
694
|
+
return new_element;
|
695
|
+
} else return null;
|
696
|
+
},
|
1022
697
|
|
1023
|
-
|
698
|
+
replace_html: function(element, html) {
|
699
|
+
if (typeof(element) == 'string') element = '#' + element;
|
700
|
+
element = jQuery(element);
|
701
|
+
if (element.length) {
|
702
|
+
element.html(html);
|
703
|
+
element.trigger('as:element_updated');
|
704
|
+
}
|
705
|
+
return element;
|
706
|
+
},
|
1024
707
|
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
708
|
+
append: function(element, html) {
|
709
|
+
if (typeof(element) == 'string') element = '#' + element;
|
710
|
+
element = jQuery(element);
|
711
|
+
element.append(html);
|
712
|
+
element.trigger('as:element_updated');
|
713
|
+
return element;
|
714
|
+
},
|
715
|
+
|
716
|
+
remove: function(element, callback) {
|
717
|
+
if (typeof(element) == 'string') element = '#' + element;
|
718
|
+
jQuery(element).trigger('as:element_removed').remove();
|
719
|
+
if (callback) callback();
|
720
|
+
},
|
721
|
+
|
722
|
+
update_inplace_edit: function(element, value, empty) {
|
723
|
+
if (typeof(element) == 'string') element = '#' + element;
|
724
|
+
this.replace_html(jQuery(element), value);
|
725
|
+
jQuery(element).closest('td')[empty ? 'addClass' : 'removeClass']('empty');
|
726
|
+
},
|
727
|
+
|
728
|
+
hide: function(element) {
|
729
|
+
if (typeof(element) == 'string') element = '#' + element;
|
730
|
+
jQuery(element).hide();
|
731
|
+
},
|
732
|
+
|
733
|
+
show: function(element) {
|
734
|
+
if (typeof(element) == 'string') element = '#' + element;
|
735
|
+
jQuery(element).show();
|
736
|
+
},
|
1030
737
|
|
1031
|
-
|
738
|
+
reset_form: function(element) {
|
739
|
+
if (typeof(element) == 'string') element = '#' + element;
|
740
|
+
jQuery(element).get(0).reset();
|
741
|
+
},
|
742
|
+
|
743
|
+
disable_form: function(as_form, skip_loading_indicator) {
|
744
|
+
if (typeof(as_form) == 'string') as_form = '#' + as_form;
|
745
|
+
as_form = jQuery(as_form);
|
746
|
+
var loading_indicator = jQuery('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator'));
|
747
|
+
if (!skip_loading_indicator && loading_indicator) loading_indicator.css('visibility','visible');
|
748
|
+
jQuery('input[type=submit]', as_form).attr('disabled', 'disabled');
|
749
|
+
jQuery('.sub-form a.destroy', as_form).addClass('disabled');
|
750
|
+
if (jQuery.fn.droppable) jQuery('.draggable-list', as_form).sortable('disable');
|
751
|
+
// data-remote-disabled attr instead of set data because is used to in selector later
|
752
|
+
jQuery("input:enabled,select:enabled,textarea:enabled", as_form).attr('disabled', 'disabled').attr('data-remove-disabled', true);
|
753
|
+
},
|
754
|
+
|
755
|
+
enable_form: function(as_form, skip_loading_indicator) {
|
756
|
+
if (typeof(as_form) == 'string') as_form = '#' + as_form;
|
757
|
+
as_form = jQuery(as_form)
|
758
|
+
var loading_indicator = jQuery('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator'));
|
759
|
+
if (!skip_loading_indicator && loading_indicator) loading_indicator.css('visibility','hidden');
|
760
|
+
jQuery('input[type=submit]', as_form).removeAttr('disabled');
|
761
|
+
jQuery('.sub-form a.destroy.disabled', as_form).removeClass('disabled');
|
762
|
+
if (jQuery.fn.droppable) jQuery('.draggable-list', as_form).sortable('enable');
|
763
|
+
jQuery("input[data-remove-disabled],select[data-remove-disabled],textarea[data-remove-disabled]", as_form).removeAttr('disabled data-remove-disabled');
|
764
|
+
},
|
765
|
+
|
766
|
+
focus_first_element_of_form: function(form_element, form_selector) {
|
767
|
+
if (typeof(form_element) == 'string') form_element = '#' + form_element;
|
768
|
+
if (typeof(form_selector) == 'undefined') form_selector = jQuery(form_element).is('form') ? '' : 'form ';
|
769
|
+
var input = jQuery(form_selector + ":input:visible:first", jQuery(form_element));
|
770
|
+
if (input.is('.no-autofocus :input')) return;
|
771
|
+
input.focus();
|
772
|
+
try {
|
773
|
+
if (input[0] && input[0].value) input[0].selectionStart = input[0].selectionEnd = input[0].value.length;
|
774
|
+
} catch(e) {}
|
775
|
+
},
|
1032
776
|
|
1033
|
-
|
1034
|
-
if (
|
1035
|
-
|
777
|
+
create_record_row: function(active_scaffold_id, html, options) {
|
778
|
+
if (typeof(active_scaffold_id) == 'string') active_scaffold_id = '#' + active_scaffold_id;
|
779
|
+
var tbody = jQuery(active_scaffold_id).find('tbody.records').first(), new_row;
|
780
|
+
|
781
|
+
if (options.insert_at == 'top') {
|
782
|
+
tbody.prepend(html);
|
783
|
+
new_row = tbody.children('tr.record:first-child');
|
784
|
+
} else if (options.insert_at == 'bottom') {
|
785
|
+
var rows = tbody.children('tr.record, tr.inline-adapter');
|
786
|
+
if (rows.length > 0) {
|
787
|
+
new_row = rows.last().after(html).next();
|
788
|
+
} else {
|
789
|
+
new_row = tbody.append(html).children().last();
|
790
|
+
}
|
791
|
+
} else if (typeof options.insert_at == 'object') {
|
792
|
+
var insert_method, get_method, row, id;
|
793
|
+
if (options.insert_at.after) {
|
794
|
+
insert_method = 'after';
|
795
|
+
get_method = 'next';
|
796
|
+
} else {
|
797
|
+
insert_method = 'before';
|
798
|
+
get_method = 'prev';
|
799
|
+
}
|
800
|
+
if (id = options.insert_at[insert_method]) row = tbody.children('#' + id);
|
801
|
+
if (row && row.length) {
|
802
|
+
new_row = row[insert_method](html)[get_method]();
|
803
|
+
}
|
1036
804
|
}
|
1037
|
-
|
1038
|
-
|
805
|
+
this.stripe(tbody);
|
806
|
+
this.hide_empty_message(tbody);
|
807
|
+
this.increment_record_count(tbody.closest('div.active-scaffold'));
|
808
|
+
this.highlight(new_row);
|
809
|
+
new_row.trigger('as:element_created');
|
810
|
+
},
|
1039
811
|
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
812
|
+
create_record_row_from_url: function(action_link, url, options) {
|
813
|
+
jQuery.get(url, function(row) {
|
814
|
+
ActiveScaffold.create_record_row(action_link.scaffold(), row, options);
|
815
|
+
action_link.close();
|
816
|
+
});
|
817
|
+
},
|
1045
818
|
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
819
|
+
delete_record_row: function(row, page_reload_url) {
|
820
|
+
if (typeof(row) == 'string') row = '#' + row;
|
821
|
+
row = jQuery(row);
|
822
|
+
var tbody = row.closest('tbody.records');
|
823
|
+
|
824
|
+
row.find('a.disabled').each(function() {;
|
825
|
+
var action_link = ActiveScaffold.ActionLink.get(this);
|
826
|
+
if (action_link) action_link.close();
|
827
|
+
});
|
828
|
+
|
829
|
+
ActiveScaffold.remove(row, function() {
|
830
|
+
ActiveScaffold.stripe(tbody);
|
831
|
+
ActiveScaffold.decrement_record_count(tbody.closest('div.active-scaffold'));
|
832
|
+
if (page_reload_url) ActiveScaffold.reload_if_empty(tbody, page_reload_url);
|
833
|
+
});
|
834
|
+
},
|
835
|
+
|
836
|
+
delete_subform_record: function(record) {
|
837
|
+
if (typeof(record) == 'string') record = '#' + record;
|
838
|
+
record = jQuery(record).closest('.sub-form-record');
|
839
|
+
this.remove(record);
|
840
|
+
},
|
841
|
+
|
842
|
+
report_500_response: function(active_scaffold_id, xhr) {
|
843
|
+
var server_error = jQuery(active_scaffold_id).find('.messages-container p.server-error').first();
|
844
|
+
if (server_error.is(':visible')) {
|
845
|
+
ActiveScaffold.highlight(server_error);
|
846
|
+
} else {
|
847
|
+
server_error.show();
|
1066
848
|
}
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
if (forms) ActiveScaffold.enable_form(forms);
|
1071
|
-
}
|
1072
|
-
if (mode === 'inline_checkbox') {
|
1073
|
-
ActiveScaffold.process_checkbox_inplace_edit(span.find('input:checkbox'), options);
|
1074
|
-
} else {
|
1075
|
-
ActiveScaffold.create_inplace_editor(span, options);
|
1076
|
-
}
|
1077
|
-
}
|
1078
|
-
},
|
1079
|
-
|
1080
|
-
update_column: function(element, url, send_form, source_id, val, additional_params) {
|
1081
|
-
if (!element) element = jQuery('#' + source_id);
|
1082
|
-
var as_form = element.closest('form.as_form');
|
1083
|
-
var params = null;
|
1084
|
-
|
1085
|
-
if (send_form) {
|
1086
|
-
var selector, base = as_form;
|
1087
|
-
if (send_form == 'row') base = element.closest('.association-record, form');
|
1088
|
-
if (selector = element.data('update_send_form_selector'))
|
1089
|
-
params = base.find(selector).serialize();
|
1090
|
-
else if (base != as_form) params = base.find(':input').serialize();
|
1091
|
-
else params = base.serialize();
|
1092
|
-
params += '&_method=&' + jQuery.param({"source_id": source_id});
|
1093
|
-
if (additional_params) params += '&' + additional_params;
|
1094
|
-
} else {
|
1095
|
-
params = {value: val};
|
1096
|
-
params.source_id = source_id;
|
1097
|
-
}
|
849
|
+
if (xhr) server_error.find('.error-500')[xhr.status < 500 ? 'hide' : 'show']();
|
850
|
+
ActiveScaffold.scroll_to(server_error, ActiveScaffold.config.scroll_on_close == 'checkInViewport');
|
851
|
+
},
|
1098
852
|
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
853
|
+
find_action_link: function(element) {
|
854
|
+
if (typeof(element) == 'string') element = '#' + element;
|
855
|
+
element = jQuery(element);
|
856
|
+
return ActiveScaffold.ActionLink.get(element.is('.actions a') ? element : element.closest('.as_adapter'));
|
857
|
+
},
|
858
|
+
|
859
|
+
display_dynamic_action_group: function(link, html) {
|
860
|
+
var container;
|
861
|
+
if (typeof(link) == 'string') link = jQuery('#' + link);
|
862
|
+
if (link.closest('td.actions').length) {
|
863
|
+
container = link.closest('td').addClass('action_group dyn');
|
864
|
+
} else {
|
865
|
+
if (link.parent('div.actions').length) link.wrap(jQuery('<div>'));
|
866
|
+
container = link.parent().addClass('action_group dyn');
|
1113
867
|
}
|
1114
|
-
|
868
|
+
container.find('> ul').remove();
|
869
|
+
container.append(html);
|
870
|
+
},
|
871
|
+
|
872
|
+
scroll_to: function(element, checkInViewport) {
|
873
|
+
if (typeof checkInViewport == 'undefined') checkInViewport = true;
|
874
|
+
if (typeof(element) == 'string') element = '#' + element;
|
875
|
+
element = jQuery(element);
|
876
|
+
if (!element.length) return;
|
877
|
+
if (checkInViewport && element.visible()) return;
|
878
|
+
jQuery(document).scrollTop(element.offset().top);
|
879
|
+
},
|
1115
880
|
|
1116
|
-
|
1117
|
-
|
881
|
+
process_checkbox_inplace_edit: function(checkbox, options) {
|
882
|
+
var checked = checkbox.is(':checked'), td = checkbox.closest('td');
|
883
|
+
if (checked === true) options['params'] += '&value=1';
|
884
|
+
jQuery.ajax({
|
885
|
+
url: options.url,
|
886
|
+
type: "POST",
|
887
|
+
data: options['params'],
|
888
|
+
dataType: options.ajax_data_type,
|
889
|
+
beforeSend: function(request, settings) {
|
890
|
+
if (options.beforeSend) options.beforeSend.call(checkbox, request, settings);
|
891
|
+
checkbox.attr('disabled', 'disabled');
|
892
|
+
td.closest('tr').find('td.actions .loading-indicator').css('visibility','visible');
|
893
|
+
},
|
894
|
+
complete: function(request){
|
895
|
+
checkbox.removeAttr('disabled');
|
896
|
+
},
|
897
|
+
success: function(request){
|
898
|
+
td.closest('tr').find('td.actions .loading-indicator').css('visibility','hidden');
|
899
|
+
}
|
900
|
+
});
|
901
|
+
},
|
902
|
+
|
903
|
+
read_inplace_edit_heading_attributes: function(column_heading, options) {
|
904
|
+
if (column_heading.data('ie-cancel-text')) options.cancel_button = '<button class="inplace_cancel">' + column_heading.data('ie-cancel-text') + "</button>";
|
905
|
+
if (column_heading.data('ie-loading-text')) options.loading_text = column_heading.data('ie-loading-text');
|
906
|
+
if (column_heading.data('ie-saving-text')) options.saving_text = column_heading.data('ie-saving-text');
|
907
|
+
if (column_heading.data('ie-save-text')) options.save_button = '<button class="inplace_save">' + column_heading.data('ie-save-text') + "</button>";
|
908
|
+
if (column_heading.data('ie-rows')) options.textarea_rows = column_heading.data('ie-rows');
|
909
|
+
if (column_heading.data('ie-cols')) options.textarea_cols = column_heading.data('ie-cols');
|
910
|
+
if (column_heading.data('ie-size')) options.text_size = column_heading.data('ie-size');
|
911
|
+
if (column_heading.data('ie-use-html')) options.use_html = column_heading.data('ie-use-html');
|
912
|
+
},
|
913
|
+
|
914
|
+
create_inplace_editor: function(span, options) {
|
915
|
+
span.removeClass('hover');
|
916
|
+
span.editInPlace(options);
|
917
|
+
span.trigger('click.editInPlace');
|
918
|
+
},
|
919
|
+
|
920
|
+
highlight: function(element) {
|
921
|
+
if (typeof(element) == 'string') element = jQuery('#' + element);
|
922
|
+
if (typeof(element.effect) == 'function') {
|
923
|
+
element.effect("highlight", jQuery.extend({}, ActiveScaffold.config.highlight), 3000);
|
924
|
+
}
|
925
|
+
},
|
926
|
+
|
927
|
+
create_associated_record_form: function(element, content, options) {
|
928
|
+
if (typeof(element) == 'string') element = '#' + element;
|
929
|
+
var element = jQuery(element);
|
930
|
+
content = jQuery(content);
|
931
|
+
if (options.singular == false) {
|
932
|
+
if (!(options.id && jQuery('#' + options.id).size() > 0)) {
|
933
|
+
var tfoot = element.children('tfoot');
|
934
|
+
if (tfoot.length) tfoot.before(content);
|
935
|
+
else element.append(content);
|
936
|
+
}
|
1118
937
|
} else {
|
1119
|
-
jQuery(
|
1120
|
-
|
938
|
+
var current = jQuery('#' + element.attr('id') + ' .sub-form-record')
|
939
|
+
if (current[0]) {
|
940
|
+
this.replace(current[0], content);
|
941
|
+
} else {
|
942
|
+
element.prepend(content);
|
943
|
+
}
|
1121
944
|
}
|
945
|
+
content.trigger('as:element_created');
|
946
|
+
ActiveScaffold.focus_first_element_of_form(content, '');
|
1122
947
|
},
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
element =
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
948
|
+
|
949
|
+
render_form_field: function(source, content, options) {
|
950
|
+
if (typeof(source) == 'string') source = '#' + source;
|
951
|
+
var source = jQuery(source);
|
952
|
+
var element, container = source.closest('.sub-form-record'), selector = '';
|
953
|
+
if (container.length == 0) {
|
954
|
+
container = source.closest('form > ol.form');
|
955
|
+
selector = 'li';
|
956
|
+
}
|
957
|
+
// find without entering new subforms
|
958
|
+
element = container.find(selector + ':not(.sub-form) .' + options.field_class).first();
|
959
|
+
if (element.length)
|
960
|
+
element = element.closest('dl');
|
961
|
+
else if (options.subform_class)
|
962
|
+
element = container.find(selector + '.' + options.subform_class).first();
|
963
|
+
|
964
|
+
if (element.length) {
|
965
|
+
var parent = element.is('li, td') ? element : element.parent('li, td');
|
966
|
+
if (element.is('li'))
|
967
|
+
this.replace_html(element, content);
|
968
|
+
else
|
969
|
+
this.replace(element, content);
|
970
|
+
if (parent.is('li')) {
|
971
|
+
for (var attr in options.attrs)
|
972
|
+
parent.attr(attr, options.attrs[attr]);
|
973
|
+
}
|
974
|
+
if (typeof(options.hidden) != 'undefined')
|
975
|
+
parent[options.hidden ? 'addClass' : 'removeClass'].call(parent, 'hidden')
|
976
|
+
}
|
977
|
+
},
|
978
|
+
|
979
|
+
record_select_onselect: function(edit_associated_url, active_scaffold_id, id){
|
980
|
+
jQuery.ajax({
|
981
|
+
url: edit_associated_url.replace('--ID--', id),
|
982
|
+
error: function(xhr, textStatus, errorThrown){
|
983
|
+
ActiveScaffold.report_500_response(active_scaffold_id, xhr)
|
984
|
+
}
|
985
|
+
});
|
986
|
+
},
|
987
|
+
|
988
|
+
// element is tbody id
|
989
|
+
mark_records: function(element, options) {
|
990
|
+
if (typeof(element) == 'string') element = '#' + element;
|
991
|
+
var element = jQuery(element);
|
992
|
+
if (options.include_checkboxes) {
|
993
|
+
var mark_checkboxes = jQuery('#' + element.attr('id') + ' > tr.record td.as_marked-column input[type="checkbox"]');
|
994
|
+
mark_checkboxes.prop('checked', !!options.checked);
|
995
|
+
mark_checkboxes.val('' + !options.checked);
|
996
|
+
}
|
997
|
+
if(options.include_mark_all) {
|
998
|
+
var mark_all_checkbox = element.prevAll('thead').find('th.as_marked-column_heading span input[type="checkbox"]');
|
999
|
+
mark_all_checkbox.prop('checked', !!options.checked);
|
1000
|
+
mark_all_checkbox.val('' + !options.checked);
|
1001
|
+
}
|
1002
|
+
},
|
1003
|
+
|
1004
|
+
in_place_editor_field_clicked: function(span) {
|
1005
|
+
// test editor is open
|
1006
|
+
if (typeof(span.data('editInPlace')) === 'undefined') {
|
1007
|
+
var options = {show_buttons: true,
|
1008
|
+
hover_class: 'hover',
|
1009
|
+
element_id: 'editor_id',
|
1010
|
+
ajax_data_type: "script",
|
1011
|
+
delegate: {
|
1012
|
+
willCloseEditInPlace: function(span, options) {
|
1013
|
+
if (span.data('addEmptyOnCancel')) span.closest('td').addClass('empty');
|
1014
|
+
span.closest('tr').find('td.actions .loading-indicator').css('visibility','visible');
|
1015
|
+
},
|
1016
|
+
didCloseEditInPlace: function(span, options) {
|
1017
|
+
span.closest('tr').find('td.actions .loading-indicator').css('visibility','hidden');
|
1018
|
+
}
|
1019
|
+
},
|
1020
|
+
update_value: 'value'},
|
1021
|
+
csrf_param = jQuery('meta[name=csrf-param]').first(),
|
1022
|
+
csrf_token = jQuery('meta[name=csrf-token]').first(),
|
1023
|
+
my_parent = span.parent(),
|
1024
|
+
column_heading = null;
|
1025
|
+
|
1026
|
+
if(!(my_parent.is('td') || my_parent.is('th'))){
|
1027
|
+
my_parent = span.parents('td').eq(0);
|
1028
|
+
}
|
1029
|
+
|
1030
|
+
if (my_parent.is('td')) {
|
1031
|
+
var column_no = my_parent.prevAll('td').length;
|
1032
|
+
column_heading = my_parent.closest('table').find('th:eq(' + column_no + ')');
|
1033
|
+
} else if (my_parent.is('th')) {
|
1034
|
+
column_heading = my_parent;
|
1035
|
+
}
|
1036
|
+
|
1037
|
+
var render_url = column_heading.data('ie-render-url'),
|
1038
|
+
mode = column_heading.data('ie-mode'),
|
1039
|
+
record_id = span.data('ie-id') || '';
|
1040
|
+
|
1041
|
+
ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options);
|
1042
|
+
|
1043
|
+
if (span.data('ie-url')) {
|
1044
|
+
options.url = span.data('ie-url').replace(/__id__/, record_id);
|
1045
|
+
} else {
|
1046
|
+
options.url = column_heading.data('ie-url').replace(/__id__/, record_id);
|
1047
|
+
}
|
1048
|
+
|
1049
|
+
if (csrf_param) options['params'] = csrf_param.attr('content') + '=' + csrf_token.attr('content');
|
1050
|
+
|
1051
|
+
if (span.closest('div.active-scaffold').data('eid')) {
|
1052
|
+
if (options['params'].length > 0) {
|
1053
|
+
options['params'] += "&";
|
1054
|
+
}
|
1055
|
+
options['params'] += ("eid=" + span.closest('div.active-scaffold').data('eid'));
|
1056
|
+
}
|
1057
|
+
|
1058
|
+
if (mode === 'clone') {
|
1059
|
+
options.clone_id_suffix = record_id;
|
1060
|
+
options.clone_selector = '#' + column_heading.attr('id') + ' .as_inplace_pattern';
|
1061
|
+
options.field_type = 'clone';
|
1062
|
+
}
|
1063
|
+
|
1064
|
+
if (render_url) {
|
1065
|
+
var plural = false;
|
1066
|
+
if (column_heading.data('ie-plural')) plural = true;
|
1067
|
+
options.field_type = 'remote';
|
1068
|
+
options.editor_url = render_url.replace(/__id__/, record_id)
|
1069
|
+
if (!options.delegate) options.delegate = {}
|
1070
|
+
options.delegate.didOpenEditInPlace = function(dom) { dom.trigger('as:element_updated'); }
|
1071
|
+
}
|
1072
|
+
var actions, forms;
|
1073
|
+
options.beforeSend = function(xhr, settings) {
|
1074
|
+
switch (span.data('ie-update')) {
|
1075
|
+
case 'update_row':
|
1076
|
+
actions = span.closest('tr').find('.actions a:not(.disabled)').addClass('disabled');
|
1077
|
+
break;
|
1078
|
+
case 'update_table':
|
1079
|
+
var table = span.closest('.as_content');
|
1080
|
+
actions = table.find('.actions a:not(.disabled)').addClass('disabled');
|
1081
|
+
forms = table.find('.as_form');
|
1082
|
+
ActiveScaffold.disable_form(forms);
|
1083
|
+
break;
|
1084
|
+
}
|
1085
|
+
}
|
1086
|
+
options.error = options.success = function() {
|
1087
|
+
if (actions) actions.removeClass('disabled');
|
1088
|
+
if (forms) ActiveScaffold.enable_form(forms);
|
1089
|
+
}
|
1090
|
+
if (mode === 'inline_checkbox') {
|
1091
|
+
ActiveScaffold.process_checkbox_inplace_edit(span.find('input:checkbox'), options);
|
1092
|
+
} else {
|
1093
|
+
ActiveScaffold.create_inplace_editor(span, options);
|
1094
|
+
}
|
1135
1095
|
}
|
1136
1096
|
},
|
1137
|
-
|
1138
|
-
|
1139
|
-
element
|
1097
|
+
|
1098
|
+
update_column: function(element, url, send_form, source_id, val, additional_params) {
|
1099
|
+
if (!element) element = jQuery('#' + source_id);
|
1100
|
+
var as_form = element.closest('form.as_form');
|
1101
|
+
var params = null;
|
1102
|
+
|
1103
|
+
if (send_form) {
|
1104
|
+
var selector, base = as_form;
|
1105
|
+
if (send_form == 'row') base = element.closest('.association-record, form');
|
1106
|
+
if (selector = element.data('update_send_form_selector'))
|
1107
|
+
params = base.find(selector).serialize();
|
1108
|
+
else if (base != as_form) params = base.find(':input').serialize();
|
1109
|
+
else params = base.serialize();
|
1110
|
+
params += '&_method=&' + jQuery.param({"source_id": source_id});
|
1111
|
+
if (additional_params) params += '&' + additional_params;
|
1112
|
+
} else {
|
1113
|
+
params = {value: val};
|
1114
|
+
params.source_id = source_id;
|
1115
|
+
}
|
1116
|
+
|
1117
|
+
jQuery.ajax({
|
1118
|
+
url: url,
|
1119
|
+
data: params,
|
1120
|
+
type: 'post',
|
1121
|
+
dataType: 'script',
|
1122
|
+
beforeSend: function(xhr, settings) {
|
1123
|
+
element.nextAll('img.loading-indicator').css('visibility','visible');
|
1124
|
+
/* force to blur and save previous last_focus, because disable_form will trigger
|
1125
|
+
* blur on focused element and we will not be able to restore focus later
|
1126
|
+
*/
|
1127
|
+
var last_focus = ActiveScaffold.last_focus;
|
1128
|
+
if (last_focus) {
|
1129
|
+
jQuery(last_focus).blur();
|
1130
|
+
ActiveScaffold.last_focus = last_focus;
|
1131
|
+
}
|
1132
|
+
//ActiveScaffold.disable_form(as_form); // not needed: called from on('ajax:beforeSend', 'form.as_form')
|
1133
|
+
|
1134
|
+
if (jQuery.rails.fire(element, 'ajax:beforeSend', [xhr, settings])) {
|
1135
|
+
element.trigger('ajax:send', xhr);
|
1136
|
+
} else {
|
1137
|
+
jQuery(ActiveScaffold.last_focus).focus();
|
1138
|
+
return false;
|
1139
|
+
}
|
1140
|
+
},
|
1141
|
+
success: function(data, status, xhr) {
|
1142
|
+
as_form.find('#'+element.attr('id')).trigger('ajax:success', [data, status, xhr]);
|
1143
|
+
},
|
1144
|
+
complete: function(xhr, status) {
|
1145
|
+
element = as_form.find('#'+element.attr('id'));
|
1146
|
+
element.nextAll('img.loading-indicator').css('visibility','hidden');
|
1147
|
+
var complete_element = element.length ? element : as_form;
|
1148
|
+
complete_element.trigger('ajax:complete', [xhr, status]);
|
1149
|
+
if (ActiveScaffold.last_focus) {
|
1150
|
+
var item = jQuery(ActiveScaffold.last_focus);
|
1151
|
+
if (item.closest('body').length == 0 && item.attr('id')) item = jQuery('#' + item.attr('id'));
|
1152
|
+
if (status != 'error') item.focus().select();
|
1153
|
+
}
|
1154
|
+
},
|
1155
|
+
error: function (xhr, status, error) {
|
1156
|
+
element = as_form.find('#'+element.attr('id'));
|
1157
|
+
element.trigger('ajax:error', [xhr, status, error]);
|
1158
|
+
}
|
1159
|
+
});
|
1160
|
+
},
|
1161
|
+
|
1162
|
+
draggable_lists: function(selector_or_elements, parent) {
|
1163
|
+
var elements;
|
1164
|
+
if (!jQuery.fn.draggableLists) return;
|
1165
|
+
if (typeof(selector_or_elements) == 'string') elements = jQuery(selector_or_elements, parent);
|
1166
|
+
else elements = jQuery(selector_or_elements);
|
1167
|
+
elements.draggableLists();
|
1168
|
+
},
|
1169
|
+
|
1170
|
+
setup_warn_changes: function() {
|
1171
|
+
var need_confirm = false;
|
1172
|
+
var unload_message = jQuery('meta[name=unload-message]').attr('content') || ActiveScaffold.config.unload_message || "This page contains unsaved data that will be lost if you leave this page.";
|
1173
|
+
jQuery(document).on('change input', '.active-scaffold form:not(.search) input, .active-scaffold form:not(.search) textarea, .active-scaffold form:not(.search) select', function() {
|
1174
|
+
jQuery(this).closest('form').addClass('need-confirm');
|
1175
|
+
});
|
1176
|
+
jQuery(document).on('click', '.active-scaffold .as_cancel:not([data-remote]), .active-scaffold input[type=submit]', function() {
|
1177
|
+
jQuery(this).closest('form').removeClass('need-confirm');
|
1178
|
+
});
|
1179
|
+
window.onbeforeunload = function() {
|
1180
|
+
if (jQuery('form.need-confirm').length) return unload_message;
|
1181
|
+
};
|
1182
|
+
jQuery(document).on('turbolinks:before-visit turbolinks:before-visit', function(e) {
|
1183
|
+
if (jQuery('form.need-confirm').length) {
|
1184
|
+
if (!window.confirm(unload_message)) e.preventDefault();
|
1185
|
+
}
|
1186
|
+
});
|
1187
|
+
},
|
1188
|
+
|
1189
|
+
update_floating_form_footer: function() {
|
1190
|
+
jQuery('.active-scaffold form.floating-footer .form-footer').each(function () {
|
1191
|
+
var $footer = jQuery(this), $form = $footer.closest('form.floating-footer');
|
1192
|
+
$footer.removeClass('floating');
|
1193
|
+
if ($form.visible(true) && !$footer.visible(true)) $footer.addClass('floating');
|
1194
|
+
});
|
1140
1195
|
}
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
if (jQuery('form.need-confirm').length) return unload_message;
|
1196
|
+
|
1197
|
+
}
|
1198
|
+
|
1199
|
+
|
1200
|
+
jQuery(window).on('scroll resize', ActiveScaffold.update_floating_form_footer);
|
1201
|
+
|
1202
|
+
/*
|
1203
|
+
* URL modification support. Incomplete functionality.
|
1204
|
+
*/
|
1205
|
+
String.prototype.append_params = function(params) {
|
1206
|
+
var url = this;
|
1207
|
+
if (url.indexOf('?') == -1) url += '?';
|
1208
|
+
else if (url.lastIndexOf('&') != url.length) url += '&';
|
1209
|
+
|
1210
|
+
for(var key in params) {
|
1211
|
+
if (key) url += (key + '=' + params[key] + '&');
|
1212
|
+
}
|
1213
|
+
|
1214
|
+
// the loop leaves a comma dangling at the end of string, chop it off
|
1215
|
+
url = url.substring(0, url.length-1);
|
1216
|
+
return url;
|
1163
1217
|
};
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1218
|
+
|
1219
|
+
|
1220
|
+
/**
|
1221
|
+
* A set of links. As a set, they can be controlled such that only one is "open" at a time, etc.
|
1222
|
+
*/
|
1223
|
+
ActiveScaffold.Actions = new Object();
|
1224
|
+
ActiveScaffold.Actions.Abstract = Class.extend({
|
1225
|
+
init: function(links, target, loading_indicator, options) {
|
1226
|
+
this.target = jQuery(target);
|
1227
|
+
this.loading_indicator = jQuery(loading_indicator);
|
1228
|
+
this.options = options;
|
1229
|
+
var _this = this;
|
1230
|
+
this.links = jQuery.map(links, function(link) {
|
1231
|
+
return _this.instantiate_link(link);
|
1232
|
+
});
|
1233
|
+
},
|
1234
|
+
|
1235
|
+
instantiate_link: function(link) {
|
1236
|
+
throw 'unimplemented'
|
1167
1237
|
}
|
1168
1238
|
});
|
1169
|
-
},
|
1170
1239
|
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1240
|
+
/**
|
1241
|
+
* A DataStructures::ActionLink, represented in JavaScript.
|
1242
|
+
* Concerned with AJAX-enabling a link and adapting the result for insertion into the table.
|
1243
|
+
*/
|
1244
|
+
ActiveScaffold.ActionLink = {
|
1245
|
+
get: function(element) {
|
1246
|
+
if (typeof(element) == 'string') element = '#' + element;
|
1247
|
+
element = jQuery(element);
|
1248
|
+
if (element.length > 0) {
|
1249
|
+
element.data(); // $ 1.4.2 workaround
|
1250
|
+
if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) {
|
1251
|
+
var parent = element.closest('.actions');
|
1252
|
+
if (parent.length === 0 || parent.is('td')) {
|
1253
|
+
// maybe an column action_link
|
1254
|
+
parent = element.closest('tr.record');
|
1255
|
+
}
|
1256
|
+
if (parent.is('tr')) {
|
1257
|
+
// record action
|
1258
|
+
var target = parent.find('a.as_action');
|
1259
|
+
var loading_indicator = parent.find('td.actions .loading-indicator');
|
1260
|
+
if (!loading_indicator.length) loading_indicator = element.parent().find('.loading-indicator');
|
1261
|
+
new ActiveScaffold.Actions.Record(target, parent, loading_indicator);
|
1262
|
+
} else if (parent && parent.is('div')) {
|
1263
|
+
//table action
|
1264
|
+
new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header').first(), parent.find('.loading-indicator').first());
|
1265
|
+
}
|
1266
|
+
element = jQuery(element);
|
1267
|
+
}
|
1268
|
+
return element.data('action_link');
|
1269
|
+
} else {
|
1270
|
+
return null;
|
1271
|
+
}
|
1272
|
+
}
|
1273
|
+
};
|
1274
|
+
ActiveScaffold.ActionLink.Abstract = Class.extend({
|
1275
|
+
init: function(a, target, loading_indicator) {
|
1276
|
+
this.tag = jQuery(a);
|
1277
|
+
this.url = this.tag.attr('href');
|
1278
|
+
this.method = this.tag.data('method') || 'get';
|
1279
|
+
this.target = target;
|
1280
|
+
this.content = target.closest('.active-scaffold').find('.as_content:first');
|
1281
|
+
this.loading_indicator = loading_indicator;
|
1282
|
+
this.hide_target = false;
|
1283
|
+
this.position = this.tag.data('position');
|
1284
|
+
this.action = this.tag.data('action');
|
1285
|
+
|
1286
|
+
this.tag.data('action_link', this);
|
1287
|
+
return this;
|
1288
|
+
},
|
1289
|
+
|
1290
|
+
open: function(event) {
|
1291
|
+
this.tag.click();
|
1292
|
+
},
|
1293
|
+
|
1294
|
+
insert: function(content) {
|
1295
|
+
throw 'unimplemented'
|
1296
|
+
},
|
1178
1297
|
|
1179
|
-
|
1298
|
+
close: function() {
|
1299
|
+
if (this.adapter) {
|
1300
|
+
var link = this;
|
1301
|
+
ActiveScaffold.remove(this.adapter, function() {
|
1302
|
+
link.enable();
|
1303
|
+
if (link.hide_target) link.target.show();
|
1304
|
+
if (link.hide_content) link.content.show();
|
1305
|
+
if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(link.target.attr('id'), ActiveScaffold.config.scroll_on_close == 'checkInViewport');
|
1306
|
+
});
|
1307
|
+
}
|
1308
|
+
},
|
1180
1309
|
|
1310
|
+
reload: function() {
|
1311
|
+
this.close();
|
1312
|
+
this.open();
|
1313
|
+
},
|
1181
1314
|
|
1182
|
-
|
1315
|
+
get_new_adapter_id: function() {
|
1316
|
+
var id = 'adapter_';
|
1317
|
+
var i = 0;
|
1318
|
+
while (jQuery(id + i)) i++;
|
1319
|
+
return id + i;
|
1320
|
+
},
|
1183
1321
|
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
String.prototype.append_params = function(params) {
|
1188
|
-
var url = this;
|
1189
|
-
if (url.indexOf('?') == -1) url += '?';
|
1190
|
-
else if (url.lastIndexOf('&') != url.length) url += '&';
|
1322
|
+
enable: function() {
|
1323
|
+
return this.tag.removeClass('disabled');
|
1324
|
+
},
|
1191
1325
|
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1326
|
+
disable: function() {
|
1327
|
+
return this.tag.addClass('disabled');
|
1328
|
+
},
|
1195
1329
|
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1330
|
+
is_disabled: function() {
|
1331
|
+
return this.tag.hasClass('disabled');
|
1332
|
+
},
|
1333
|
+
|
1334
|
+
scaffold_id: function() {
|
1335
|
+
return '#' + this.tag.closest('div.active-scaffold').attr('id');
|
1336
|
+
},
|
1337
|
+
|
1338
|
+
scaffold: function() {
|
1339
|
+
return this.tag.closest('div.active-scaffold');
|
1340
|
+
},
|
1341
|
+
|
1342
|
+
update_flash_messages: function(messages) {
|
1343
|
+
var message_node = jQuery(this.scaffold_id().replace(/-active-scaffold/, '-messages'));
|
1344
|
+
if (message_node) message_node.html(messages);
|
1345
|
+
},
|
1346
|
+
set_adapter: function(element) {
|
1347
|
+
this.adapter = element;
|
1348
|
+
this.adapter.addClass('as_adapter');
|
1349
|
+
this.adapter.data('action_link', this);
|
1350
|
+
if (this.refresh_url) jQuery('.as_cancel', this.adapter).attr('href', this.refresh_url);
|
1351
|
+
},
|
1352
|
+
keep_open: function() {
|
1353
|
+
return this.tag.data('keep-open');
|
1354
|
+
}
|
1215
1355
|
});
|
1216
|
-
},
|
1217
1356
|
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
var element = jQuery(element);
|
1231
|
-
if (element.length > 0) {
|
1232
|
-
element.data(); // $ 1.4.2 workaround
|
1233
|
-
if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) {
|
1234
|
-
var parent = element.closest('.actions');
|
1235
|
-
if (parent.length === 0 || parent.is('td')) {
|
1236
|
-
// maybe an column action_link
|
1237
|
-
parent = element.closest('tr.record');
|
1357
|
+
/**
|
1358
|
+
* Concrete classes for record actions
|
1359
|
+
*/
|
1360
|
+
ActiveScaffold.Actions.Record = ActiveScaffold.Actions.Abstract.extend({
|
1361
|
+
instantiate_link: function(link) {
|
1362
|
+
var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator);
|
1363
|
+
var refresh = this.target.data('refresh');
|
1364
|
+
if (refresh) l.refresh_url = this.target.closest('.records').data('refresh-record').replace('--ID--', refresh);
|
1365
|
+
|
1366
|
+
if (l.position) {
|
1367
|
+
l.url = l.url.append_params({adapter: '_list_inline_adapter'});
|
1368
|
+
l.tag.attr('href', l.url);
|
1238
1369
|
}
|
1239
|
-
|
1240
|
-
|
1241
|
-
var target = parent.find('a.as_action');
|
1242
|
-
var loading_indicator = parent.find('td.actions .loading-indicator');
|
1243
|
-
if (!loading_indicator.length) loading_indicator = element.parent().find('.loading-indicator');
|
1244
|
-
new ActiveScaffold.Actions.Record(target, parent, loading_indicator);
|
1245
|
-
} else if (parent && parent.is('div')) {
|
1246
|
-
//table action
|
1247
|
-
new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header').first(), parent.find('.loading-indicator').first());
|
1248
|
-
}
|
1249
|
-
element = jQuery(element);
|
1250
|
-
}
|
1251
|
-
return element.data('action_link');
|
1252
|
-
} else {
|
1253
|
-
return null;
|
1254
|
-
}
|
1255
|
-
}
|
1256
|
-
};
|
1257
|
-
ActiveScaffold.ActionLink.Abstract = Class.extend({
|
1258
|
-
init: function(a, target, loading_indicator) {
|
1259
|
-
this.tag = jQuery(a);
|
1260
|
-
this.url = this.tag.attr('href');
|
1261
|
-
this.method = this.tag.data('method') || 'get';
|
1262
|
-
this.target = target;
|
1263
|
-
this.content = target.closest('.active-scaffold').find('.as_content:first');
|
1264
|
-
this.loading_indicator = loading_indicator;
|
1265
|
-
this.hide_target = false;
|
1266
|
-
this.position = this.tag.data('position');
|
1267
|
-
this.action = this.tag.data('action');
|
1268
|
-
|
1269
|
-
this.tag.data('action_link', this);
|
1270
|
-
return this;
|
1271
|
-
},
|
1272
|
-
|
1273
|
-
open: function(event) {
|
1274
|
-
this.tag.click();
|
1275
|
-
},
|
1276
|
-
|
1277
|
-
insert: function(content) {
|
1278
|
-
throw 'unimplemented'
|
1279
|
-
},
|
1280
|
-
|
1281
|
-
close: function() {
|
1282
|
-
if (this.adapter) {
|
1283
|
-
var link = this;
|
1284
|
-
ActiveScaffold.remove(this.adapter, function() {
|
1285
|
-
link.enable();
|
1286
|
-
if (link.hide_target) link.target.show();
|
1287
|
-
if (link.hide_content) link.content.show();
|
1288
|
-
if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(link.target.attr('id'), ActiveScaffold.config.scroll_on_close == 'checkInViewport');
|
1289
|
-
});
|
1290
|
-
}
|
1291
|
-
},
|
1292
|
-
|
1293
|
-
reload: function() {
|
1294
|
-
this.close();
|
1295
|
-
this.open();
|
1296
|
-
},
|
1297
|
-
|
1298
|
-
get_new_adapter_id: function() {
|
1299
|
-
var id = 'adapter_';
|
1300
|
-
var i = 0;
|
1301
|
-
while (jQuery(id + i)) i++;
|
1302
|
-
return id + i;
|
1303
|
-
},
|
1304
|
-
|
1305
|
-
enable: function() {
|
1306
|
-
return this.tag.removeClass('disabled');
|
1307
|
-
},
|
1308
|
-
|
1309
|
-
disable: function() {
|
1310
|
-
return this.tag.addClass('disabled');
|
1311
|
-
},
|
1312
|
-
|
1313
|
-
is_disabled: function() {
|
1314
|
-
return this.tag.hasClass('disabled');
|
1315
|
-
},
|
1316
|
-
|
1317
|
-
scaffold_id: function() {
|
1318
|
-
return '#' + this.tag.closest('div.active-scaffold').attr('id');
|
1319
|
-
},
|
1320
|
-
|
1321
|
-
scaffold: function() {
|
1322
|
-
return this.tag.closest('div.active-scaffold');
|
1323
|
-
},
|
1324
|
-
|
1325
|
-
update_flash_messages: function(messages) {
|
1326
|
-
message_node = jQuery(this.scaffold_id().replace(/-active-scaffold/, '-messages'));
|
1327
|
-
if (message_node) message_node.html(messages);
|
1328
|
-
},
|
1329
|
-
set_adapter: function(element) {
|
1330
|
-
this.adapter = element;
|
1331
|
-
this.adapter.addClass('as_adapter');
|
1332
|
-
this.adapter.data('action_link', this);
|
1333
|
-
if (this.refresh_url) jQuery('.as_cancel', this.adapter).attr('href', this.refresh_url);
|
1334
|
-
},
|
1335
|
-
keep_open: function() {
|
1336
|
-
return this.tag.data('keep-open');
|
1337
|
-
}
|
1338
|
-
});
|
1339
|
-
|
1340
|
-
/**
|
1341
|
-
* Concrete classes for record actions
|
1342
|
-
*/
|
1343
|
-
ActiveScaffold.Actions.Record = ActiveScaffold.Actions.Abstract.extend({
|
1344
|
-
instantiate_link: function(link) {
|
1345
|
-
var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator);
|
1346
|
-
var refresh = this.target.data('refresh');
|
1347
|
-
if (refresh) l.refresh_url = this.target.closest('.records').data('refresh-record').replace('--ID--', refresh);
|
1348
|
-
|
1349
|
-
if (l.position) {
|
1350
|
-
l.url = l.url.append_params({adapter: '_list_inline_adapter'});
|
1351
|
-
l.tag.attr('href', l.url);
|
1352
|
-
}
|
1353
|
-
l.set = this;
|
1354
|
-
return l;
|
1355
|
-
}
|
1356
|
-
});
|
1357
|
-
|
1358
|
-
ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({
|
1359
|
-
close_previous_adapter: function() {
|
1360
|
-
var _this = this;
|
1361
|
-
jQuery.each(this.set.links, function(index, item) {
|
1362
|
-
if (item.url != _this.url && item.is_disabled() && !item.keep_open() && item.adapter) {
|
1363
|
-
ActiveScaffold.remove(item.adapter, function () { item.enable(); });
|
1370
|
+
l.set = this;
|
1371
|
+
return l;
|
1364
1372
|
}
|
1365
1373
|
});
|
1366
|
-
},
|
1367
1374
|
|
1368
|
-
|
1369
|
-
|
1375
|
+
ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({
|
1376
|
+
close_previous_adapter: function() {
|
1377
|
+
var _this = this;
|
1378
|
+
jQuery.each(this.set.links, function(index, item) {
|
1379
|
+
if (item.url != _this.url && item.is_disabled() && !item.keep_open() && item.adapter) {
|
1380
|
+
ActiveScaffold.remove(item.adapter, function () { item.enable(); });
|
1381
|
+
}
|
1382
|
+
});
|
1383
|
+
},
|
1370
1384
|
|
1371
|
-
|
1372
|
-
|
1373
|
-
this.hide_target = true;
|
1374
|
-
}
|
1385
|
+
insert: function(content) {
|
1386
|
+
this.close_previous_adapter();
|
1375
1387
|
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1388
|
+
if (this.position == 'replace') {
|
1389
|
+
this.position = 'after';
|
1390
|
+
this.hide_target = true;
|
1391
|
+
}
|
1392
|
+
|
1393
|
+
var colspan = this.target.children().length;
|
1394
|
+
if (content && this.position) {
|
1395
|
+
content = jQuery(content);
|
1396
|
+
content.find('.inline-adapter-cell:first').attr('colspan', colspan);
|
1397
|
+
}
|
1398
|
+
if (this.position == 'after') {
|
1399
|
+
this.target.after(content);
|
1400
|
+
this.set_adapter(this.target.next());
|
1401
|
+
}
|
1402
|
+
else if (this.position == 'before') {
|
1403
|
+
this.target.before(content);
|
1404
|
+
this.set_adapter(this.target.prev());
|
1405
|
+
}
|
1406
|
+
else {
|
1407
|
+
return false;
|
1408
|
+
}
|
1409
|
+
ActiveScaffold.highlight(this.adapter.find('td'));
|
1410
|
+
ActiveScaffold.focus_first_element_of_form(this.adapter);
|
1411
|
+
},
|
1412
|
+
|
1413
|
+
close: function(refreshed_content_or_reload) {
|
1414
|
+
this._super();
|
1415
|
+
if (refreshed_content_or_reload) {
|
1416
|
+
if (typeof refreshed_content_or_reload == 'string') {
|
1417
|
+
ActiveScaffold.update_row(this.target, refreshed_content_or_reload);
|
1418
|
+
} else if (this.refresh_url) {
|
1419
|
+
var target = this.target;
|
1420
|
+
jQuery.get(this.refresh_url, function(e, status, xhr) {
|
1421
|
+
ActiveScaffold.update_row(target, xhr.responseText);
|
1422
|
+
});
|
1423
|
+
}
|
1424
|
+
}
|
1425
|
+
},
|
1426
|
+
|
1427
|
+
enable: function() {
|
1428
|
+
var _this = this;
|
1429
|
+
jQuery.each(this.set.links, function(index, item) {
|
1430
|
+
if (item.url != _this.url) return;
|
1431
|
+
item.tag.removeClass('disabled');
|
1405
1432
|
});
|
1406
|
-
}
|
1407
|
-
|
1408
|
-
|
1433
|
+
},
|
1434
|
+
|
1435
|
+
disable: function() {
|
1436
|
+
var _this = this;
|
1437
|
+
jQuery.each(this.set.links, function(index, item) {
|
1438
|
+
if (item.url != _this.url) return;
|
1439
|
+
item.tag.addClass('disabled');
|
1440
|
+
});
|
1441
|
+
},
|
1409
1442
|
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1443
|
+
set_opened: function() {
|
1444
|
+
if (this.position == 'after') {
|
1445
|
+
this.set_adapter(this.target.next());
|
1446
|
+
}
|
1447
|
+
else if (this.position == 'before') {
|
1448
|
+
this.set_adapter(this.target.prev());
|
1449
|
+
}
|
1450
|
+
this.disable();
|
1451
|
+
}
|
1415
1452
|
});
|
1416
|
-
},
|
1417
1453
|
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1454
|
+
/**
|
1455
|
+
* Concrete classes for table actions
|
1456
|
+
*/
|
1457
|
+
ActiveScaffold.Actions.Table = ActiveScaffold.Actions.Abstract.extend({
|
1458
|
+
instantiate_link: function(link) {
|
1459
|
+
var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator);
|
1460
|
+
if (l.position) {
|
1461
|
+
l.url = l.url.append_params({adapter: '_list_inline_adapter'});
|
1462
|
+
l.tag.attr('href', l.url);
|
1463
|
+
}
|
1464
|
+
return l;
|
1465
|
+
}
|
1423
1466
|
});
|
1424
|
-
},
|
1425
1467
|
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
}
|
1433
|
-
this.disable();
|
1434
|
-
}
|
1435
|
-
});
|
1436
|
-
|
1437
|
-
/**
|
1438
|
-
* Concrete classes for table actions
|
1439
|
-
*/
|
1440
|
-
ActiveScaffold.Actions.Table = ActiveScaffold.Actions.Abstract.extend({
|
1441
|
-
instantiate_link: function(link) {
|
1442
|
-
var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator);
|
1443
|
-
if (l.position) {
|
1444
|
-
l.url = l.url.append_params({adapter: '_list_inline_adapter'});
|
1445
|
-
l.tag.attr('href', l.url);
|
1446
|
-
}
|
1447
|
-
return l;
|
1448
|
-
}
|
1449
|
-
});
|
1468
|
+
ActiveScaffold.ActionLink.Table = ActiveScaffold.ActionLink.Abstract.extend({
|
1469
|
+
insert: function(content) {
|
1470
|
+
if (this.position == 'replace') {
|
1471
|
+
this.position = 'top';
|
1472
|
+
this.hide_content = true;
|
1473
|
+
}
|
1450
1474
|
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1475
|
+
if (this.position == 'top') {
|
1476
|
+
this.target.prepend(content);
|
1477
|
+
this.set_adapter(this.target.children().first());
|
1478
|
+
}
|
1479
|
+
else {
|
1480
|
+
throw 'Unknown position "' + this.position + '"'
|
1481
|
+
}
|
1482
|
+
ActiveScaffold.highlight(this.adapter.find('td').first().children().not('script'));
|
1483
|
+
ActiveScaffold.focus_first_element_of_form(this.adapter);
|
1484
|
+
}
|
1485
|
+
});
|
1486
|
+
};
|
1457
1487
|
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
else {
|
1463
|
-
throw 'Unknown position "' + this.position + '"'
|
1464
|
-
}
|
1465
|
-
ActiveScaffold.highlight(this.adapter.find('td').first().children().not('script'));
|
1466
|
-
ActiveScaffold.focus_first_element_of_form(this.adapter);
|
1488
|
+
if (window.jQuery) {
|
1489
|
+
activeScaffoldInit(jQuery);
|
1490
|
+
} else if (typeof exports === 'object' && typeof module === 'object') {
|
1491
|
+
module.exports = activeScaffoldInit;
|
1467
1492
|
}
|
1468
|
-
});
|
1493
|
+
})();
|