active_scaffold 3.0.26 → 3.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -1
- data/{frontends/default → app/assets}/images/add.gif +0 -0
- data/{frontends/default → app/assets}/images/arrow_down.gif +0 -0
- data/{frontends/default → app/assets}/images/arrow_up.gif +0 -0
- data/{frontends/default → app/assets}/images/close.gif +0 -0
- data/{frontends/default → app/assets}/images/close_touch.png +0 -0
- data/{frontends/default → app/assets}/images/config.png +0 -0
- data/{frontends/default → app/assets}/images/cross.png +0 -0
- data/{frontends/default → app/assets}/images/gears.png +0 -0
- data/{frontends/default → app/assets}/images/indicator-small.gif +0 -0
- data/{frontends/default → app/assets}/images/indicator.gif +0 -0
- data/{frontends/default → app/assets}/images/magnifier.png +0 -0
- data/app/assets/javascripts/active_scaffold.js.erb +16 -0
- data/{frontends/default → app/assets}/javascripts/jquery/active_scaffold.js +16 -28
- data/app/assets/javascripts/jquery/active_scaffold.js~ +1036 -0
- data/{lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js → app/assets/javascripts/jquery/date_picker_bridge.js.erb} +3 -1
- data/{frontends/default → app/assets}/javascripts/jquery/jquery.editinplace.js +0 -0
- data/app/assets/javascripts/prototype/active_scaffold.js +1033 -0
- data/{frontends/default/javascripts/prototype/active_scaffold.js → app/assets/javascripts/prototype/active_scaffold.js~} +1 -0
- data/{frontends/default → app/assets}/javascripts/prototype/dhtml_history.js +0 -0
- data/{frontends/default → app/assets}/javascripts/prototype/form_enhancements.js +0 -0
- data/{frontends/default → app/assets}/javascripts/prototype/rico_corner.js +0 -0
- data/{frontends/default/stylesheets/stylesheet-ie.css → app/assets/stylesheets/active_scaffold-ie.css} +0 -0
- data/{frontends/default/stylesheets/stylesheet.css → app/assets/stylesheets/active_scaffold.css.erb} +29 -24
- data/{lib/active_scaffold/locale → config/locales}/de.yml +3 -0
- data/{lib/active_scaffold/locale → config/locales}/en.yml +3 -0
- data/{lib/active_scaffold/locale → config/locales}/es.yml +5 -0
- data/{lib/active_scaffold/locale → config/locales}/fr.yml +3 -0
- data/{lib/active_scaffold/locale → config/locales}/hu.yml +13 -2
- data/{lib/active_scaffold/locale → config/locales}/ja.yml +9 -0
- data/{lib/active_scaffold/locale → config/locales}/ru.yml +3 -0
- data/frontends/default/views/_form.html.erb +1 -1
- data/frontends/default/views/_form_association.html.erb +1 -5
- data/frontends/default/views/_horizontal_subform.html.erb +7 -4
- data/frontends/default/views/_horizontal_subform.html.erb~ +2 -5
- data/frontends/default/views/_horizontal_subform_footer.html.erb +0 -0
- data/frontends/default/views/_horizontal_subform_header.html.erb +1 -1
- data/frontends/default/views/_horizontal_subform_header.html.erb~ +1 -1
- data/frontends/default/views/_horizontal_subform_record.html.erb~ +1 -1
- data/frontends/default/views/_list_actions.html.erb +1 -1
- data/frontends/default/views/_list_messages.html.erb +1 -3
- data/frontends/default/views/_render_field.js.erb +20 -0
- data/frontends/default/views/_row.html.erb +3 -9
- data/frontends/default/views/_show.html.erb +2 -2
- data/frontends/default/views/add_existing.js.erb +20 -0
- data/frontends/default/views/destroy.js.erb +24 -0
- data/frontends/default/views/{edit_associated.js.rjs → edit_associated.js.erb} +3 -2
- data/frontends/default/views/form_messages.js.erb +1 -0
- data/frontends/default/views/list.js.erb +1 -0
- data/frontends/default/views/mark.js.rjs +6 -0
- data/frontends/default/views/on_action_update.js.erb +13 -0
- data/frontends/default/views/{on_create.js.erb~ → on_create.js.erb} +0 -0
- data/frontends/default/views/on_mark_all.js.erb +12 -0
- data/frontends/default/views/{on_update.js.erb~ → on_update.js.erb} +0 -0
- data/frontends/default/views/render_field.js.erb +1 -0
- data/frontends/default/views/search.html.erb +1 -1
- data/frontends/default/views/{update_column.js.erb~ → update_column.js.erb} +3 -3
- data/frontends/default/views/update_row.js.erb +1 -0
- data/lib/active_scaffold.rb +22 -46
- data/lib/active_scaffold/actions/core.rb +14 -6
- data/lib/active_scaffold/actions/core.rb~ +3 -3
- data/lib/active_scaffold/actions/create.rb +2 -5
- data/lib/active_scaffold/actions/create.rb~ +3 -2
- data/lib/active_scaffold/actions/delete.rb +1 -0
- data/lib/active_scaffold/actions/field_search.rb +1 -1
- data/lib/active_scaffold/actions/list.rb +10 -6
- data/lib/active_scaffold/actions/list.rb~ +3 -3
- data/lib/active_scaffold/actions/mark.rb +8 -8
- data/lib/active_scaffold/actions/nested.rb +2 -9
- data/lib/active_scaffold/actions/nested.rb~ +5 -7
- data/lib/active_scaffold/actions/search.rb +2 -1
- data/lib/active_scaffold/actions/subform.rb +1 -5
- data/lib/active_scaffold/actions/update.rb +1 -4
- data/lib/active_scaffold/actions/update.rb~ +5 -5
- data/lib/active_scaffold/attribute_params.rb +15 -26
- data/lib/active_scaffold/attribute_params.rb~ +1 -2
- data/lib/active_scaffold/bridges.rb +61 -0
- data/lib/active_scaffold/bridges/ancestry.rb +5 -0
- data/lib/active_scaffold/bridges/ancestry/{lib/ancestry_bridge.rb → ancestry_bridge.rb} +3 -3
- data/lib/active_scaffold/bridges/{calendar_date_select/bridge.rb → calendar_date_select.rb} +13 -5
- data/lib/active_scaffold/bridges/calendar_date_select/{lib/as_cds_bridge.rb → as_cds_bridge.rb} +4 -20
- data/lib/active_scaffold/bridges/cancan.rb +15 -0
- data/lib/active_scaffold/bridges/cancan/{lib/cancan_bridge.rb → cancan_bridge.rb} +2 -2
- data/lib/active_scaffold/bridges/carrierwave.rb +12 -0
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +31 -0
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge_helpers.rb +10 -0
- data/lib/active_scaffold/bridges/carrierwave/{lib/form_ui.rb → form_ui.rb} +0 -0
- data/lib/active_scaffold/bridges/carrierwave/{lib/list_ui.rb → list_ui.rb} +1 -1
- data/lib/active_scaffold/bridges/country_helper.rb +9 -0
- data/lib/active_scaffold/bridges/country_helper/{lib/country_helper_bridge.rb → country_helper_bridge.rb} +5 -5
- data/lib/active_scaffold/bridges/date_picker.rb +23 -0
- data/lib/active_scaffold/bridges/date_picker/ext.rb +54 -0
- data/lib/active_scaffold/bridges/date_picker/helper.rb +188 -0
- data/lib/active_scaffold/bridges/dragonfly.rb +9 -0
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +34 -0
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge_helpers.rb +10 -0
- data/lib/active_scaffold/bridges/dragonfly/{lib/form_ui.rb → form_ui.rb} +0 -0
- data/lib/active_scaffold/bridges/dragonfly/{lib/list_ui.rb → list_ui.rb} +2 -2
- data/lib/active_scaffold/bridges/file_column.rb +11 -0
- data/lib/active_scaffold/bridges/file_column/{lib/as_file_column_bridge.rb → as_file_column_bridge.rb} +2 -2
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +57 -0
- data/lib/active_scaffold/bridges/file_column/{lib/form_ui.rb → form_ui.rb} +2 -2
- data/lib/active_scaffold/bridges/file_column/{lib/list_ui.rb → list_ui.rb} +0 -0
- data/lib/active_scaffold/bridges/paperclip.rb +12 -0
- data/lib/active_scaffold/bridges/paperclip/{lib/form_ui.rb → form_ui.rb} +0 -0
- data/lib/active_scaffold/bridges/paperclip/{lib/list_ui.rb → list_ui.rb} +3 -3
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +36 -0
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +24 -0
- data/lib/active_scaffold/bridges/record_select.rb +11 -0
- data/lib/active_scaffold/bridges/record_select/{lib/record_select_bridge.rb → helpers.rb} +5 -16
- data/lib/active_scaffold/bridges/record_select/helpers.rb~ +9 -14
- data/lib/active_scaffold/bridges/semantic_attributes.rb +5 -0
- data/lib/active_scaffold/bridges/semantic_attributes/{lib/semantic_attributes_bridge.rb → column.rb} +3 -3
- data/lib/active_scaffold/bridges/tiny_mce.rb +5 -0
- data/lib/active_scaffold/bridges/tiny_mce/{lib/tiny_mce_bridge.rb → helpers.rb} +16 -8
- data/lib/active_scaffold/config/base.rb +9 -1
- data/lib/active_scaffold/config/core.rb +1 -1
- data/lib/active_scaffold/config/create.rb +3 -10
- data/lib/active_scaffold/config/delete.rb +1 -2
- data/lib/active_scaffold/config/field_search.rb +1 -2
- data/lib/active_scaffold/config/form.rb +2 -6
- data/lib/active_scaffold/config/list.rb +8 -2
- data/lib/active_scaffold/config/nested.rb +2 -6
- data/lib/active_scaffold/config/search.rb +6 -2
- data/lib/active_scaffold/config/show.rb +1 -4
- data/lib/active_scaffold/config/subform.rb +1 -1
- data/lib/active_scaffold/config/update.rb +1 -6
- data/lib/active_scaffold/data_structures/action_columns.rb +3 -0
- data/lib/active_scaffold/data_structures/action_link.rb +14 -10
- data/lib/active_scaffold/data_structures/bridge.rb +22 -0
- data/lib/active_scaffold/data_structures/column.rb +36 -4
- data/lib/active_scaffold/data_structures/nested_info.rb +4 -4
- data/lib/active_scaffold/data_structures/set.rb +1 -6
- data/lib/active_scaffold/data_structures/sorting.rb +2 -2
- data/lib/active_scaffold/engine.rb +4 -0
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +2 -2
- data/lib/active_scaffold/extensions/action_controller_rendering.rb~ +1 -1
- data/lib/active_scaffold/extensions/action_view_rendering.rb +90 -93
- data/lib/active_scaffold/extensions/action_view_rendering.rb~ +1 -13
- data/lib/active_scaffold/extensions/active_association_reflection.rb +16 -7
- data/lib/active_scaffold/extensions/cache_association.rb +16 -0
- data/lib/active_scaffold/extensions/reverse_associations.rb +15 -13
- data/lib/active_scaffold/extensions/unsaved_associated.rb +1 -1
- data/lib/active_scaffold/finder.rb +40 -23
- data/lib/active_scaffold/finder.rb~ +3 -11
- data/lib/active_scaffold/helpers/association_helpers.rb +1 -1
- data/lib/active_scaffold/helpers/controller_helpers.rb +9 -1
- data/lib/active_scaffold/helpers/controller_helpers.rb~ +12 -5
- data/lib/active_scaffold/helpers/form_column_helpers.rb +20 -21
- data/lib/active_scaffold/helpers/form_column_helpers.rb~ +2 -1
- data/lib/active_scaffold/helpers/id_helpers.rb +5 -5
- data/lib/active_scaffold/helpers/list_column_helpers.rb +14 -24
- data/lib/active_scaffold/helpers/list_column_helpers.rb~ +15 -20
- data/lib/active_scaffold/helpers/search_column_helpers.rb +10 -1
- data/lib/active_scaffold/helpers/search_column_helpers.rb~ +1 -1
- data/lib/active_scaffold/helpers/view_helpers.rb +14 -40
- data/lib/active_scaffold/helpers/view_helpers.rb~ +3 -3
- data/lib/active_scaffold/version.rb +2 -2
- data/lib/active_scaffold_env.rb +0 -2
- data/test/bridges/active_scaffold_dependent_protect_test.rb +34 -0
- data/test/bridges/bridge_test.rb +43 -0
- data/test/bridges/company.rb +81 -0
- data/test/bridges/paperclip_test.rb +68 -0
- data/test/bridges/tiny_mce_test.rb +27 -0
- data/test/bridges/unobtrusive_date_picker_test.rb +49 -0
- data/test/bridges/validation_reflection_test.rb +57 -0
- data/test/config/base_test.rb +1 -1
- data/test/config/core_test.rb +58 -0
- data/test/config/create_test.rb +8 -5
- data/test/config/delete_test.rb +33 -0
- data/test/config/field_search_test.rb +47 -0
- data/test/config/list_test.rb +64 -9
- data/test/config/nested_test.rb +62 -0
- data/test/config/search_test.rb +60 -0
- data/test/config/show_test.rb +5 -5
- data/test/config/subform_test.rb +17 -0
- data/test/config/update_test.rb +27 -4
- data/test/helpers/list_column_helpers_test.rb +16 -5
- data/test/helpers/pagination_helpers_test.rb +4 -0
- data/test/misc/attribute_params_test.rb +37 -1
- data/test/misc/finder_test.rb +0 -1
- data/test/misc/lang_test.rb +2 -3
- data/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +2 -2
- data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +13 -7
- metadata +137 -154
- data/frontends/default/views/_list_with_header.html.erb~ +0 -32
- data/frontends/default/views/_render_field.js.rjs +0 -14
- data/frontends/default/views/_show.html.erb~ +0 -8
- data/frontends/default/views/_update_form.html.erb~ +0 -6
- data/frontends/default/views/add_existing.js.erb~ +0 -18
- data/frontends/default/views/add_existing.js.rjs +0 -17
- data/frontends/default/views/destroy.js.rjs +0 -23
- data/frontends/default/views/form_messages.js.rjs +0 -1
- data/frontends/default/views/list.js.rjs +0 -1
- data/frontends/default/views/on_action_update.js.rjs +0 -10
- data/frontends/default/views/on_create.js.rjs +0 -41
- data/frontends/default/views/on_mark_all.js.rjs +0 -12
- data/frontends/default/views/on_update.js.rjs +0 -28
- data/frontends/default/views/render_field.js.rjs +0 -1
- data/frontends/default/views/update_column.js.rjs +0 -13
- data/frontends/default/views/update_row.js.rjs +0 -1
- data/lib/active_scaffold.rb~ +0 -362
- data/lib/active_scaffold/bridges/ancestry/bridge.rb +0 -5
- data/lib/active_scaffold/bridges/bridge.rb +0 -59
- data/lib/active_scaffold/bridges/cancan/bridge.rb +0 -12
- data/lib/active_scaffold/bridges/carrierwave/bridge.rb +0 -9
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +0 -33
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +0 -12
- data/lib/active_scaffold/bridges/country_helper/bridge.rb +0 -9
- data/lib/active_scaffold/bridges/date_picker/bridge.rb +0 -24
- data/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +0 -234
- data/lib/active_scaffold/bridges/dragonfly/bridge.rb +0 -9
- data/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge.rb +0 -36
- data/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge_helpers.rb +0 -12
- data/lib/active_scaffold/bridges/file_column/bridge.rb +0 -11
- data/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb +0 -59
- data/lib/active_scaffold/bridges/paperclip/bridge.rb +0 -12
- data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb +0 -38
- data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +0 -26
- data/lib/active_scaffold/bridges/record_select/bridge.rb +0 -5
- data/lib/active_scaffold/bridges/semantic_attributes/bridge.rb +0 -5
- data/lib/active_scaffold/bridges/shared/date_bridge.rb~ +0 -209
- data/lib/active_scaffold/bridges/tiny_mce/bridge.rb +0 -5
- data/lib/active_scaffold/bridges/validation_reflection/bridge.rb +0 -8
- data/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb +0 -21
- data/lib/active_scaffold/config/base.rb~ +0 -70
- data/lib/active_scaffold/config/nested.rb~ +0 -41
- data/lib/active_scaffold/constraints.rb~ +0 -186
- data/lib/active_scaffold/data_structures/action_link.rb~ +0 -179
- data/lib/active_scaffold/data_structures/nested_info.rb~ +0 -123
- data/lib/active_scaffold/extensions/action_view_resolver.rb +0 -7
- data/lib/active_scaffold/extensions/active_association_reflection.rb~ +0 -22
- data/lib/active_scaffold/extensions/unsaved_associated.rb~ +0 -62
- data/lib/active_scaffold_assets.rb +0 -45
- data/lib/generators/active_scaffold_setup/USAGE +0 -10
- data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +0 -59
@@ -1,3 +1,5 @@
|
|
1
|
+
<%= ActiveScaffold::Bridges[:date_picker].localization %>
|
2
|
+
|
1
3
|
$(document).ready(function() {
|
2
4
|
$('input.date_picker').live('focus', function(event) {
|
3
5
|
var date_picker = $(this);
|
@@ -19,4 +21,4 @@ $(document).ready(function() {
|
|
19
21
|
}
|
20
22
|
return true;
|
21
23
|
});
|
22
|
-
});
|
24
|
+
});
|
File without changes
|
@@ -0,0 +1,1033 @@
|
|
1
|
+
if (typeof Prototype == 'undefined')
|
2
|
+
{
|
3
|
+
warning = "ActiveScaffold Error: Prototype could not be found. Please make sure that your application's layout includes prototype.js (e.g. <%= javascript_include_tag :defaults %>) *before* it includes active_scaffold.js (e.g. <%= active_scaffold_includes %>).";
|
4
|
+
alert(warning);
|
5
|
+
}
|
6
|
+
if (Prototype.Version.substring(0, 3) < '1.6')
|
7
|
+
{
|
8
|
+
warning = "ActiveScaffold Error: Prototype version 1.6.x or higher is required. Please update prototype.js (rake rails:update:javascripts).";
|
9
|
+
alert(warning);
|
10
|
+
}
|
11
|
+
if (!Element.Methods.highlight) Element.addMethods({highlight: Prototype.emptyFunction});
|
12
|
+
|
13
|
+
|
14
|
+
document.observe("dom:loaded", function() {
|
15
|
+
document.on('ajax:create', 'form.as_form', function(event) {
|
16
|
+
var source = event.findElement();
|
17
|
+
var as_form = event.findElement('form');
|
18
|
+
if (source.nodeName.toUpperCase() == 'INPUT' && source.readAttribute('type') == 'button') {
|
19
|
+
// Hack: Prototype or rails.js somehow screw up event handling if someone clicks
|
20
|
+
// a button of type button such as Create Another <Association>
|
21
|
+
// as a result form is disabled but never reenabled..
|
22
|
+
} else {
|
23
|
+
if (as_form && as_form.readAttribute('data-loading') == 'true') {
|
24
|
+
ActiveScaffold.disable_form(as_form);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
return true;
|
28
|
+
});
|
29
|
+
document.on('ajax:complete', 'form.as_form', function(event) {
|
30
|
+
var as_form = event.findElement('form');
|
31
|
+
if (as_form && as_form.readAttribute('data-loading') == 'true') {
|
32
|
+
ActiveScaffold.enable_form(as_form);
|
33
|
+
event.stop();
|
34
|
+
return false;
|
35
|
+
}
|
36
|
+
});
|
37
|
+
document.on('ajax:failure', 'form.as_form', function(event) {
|
38
|
+
var as_div = event.findElement('div.active-scaffold');
|
39
|
+
if (as_div) {
|
40
|
+
ActiveScaffold.report_500_response(as_div)
|
41
|
+
event.stop();
|
42
|
+
return false;
|
43
|
+
}
|
44
|
+
});
|
45
|
+
document.on('submit', 'form.as_form.as_remote_upload', function(event) {
|
46
|
+
var as_form = event.findElement('form');
|
47
|
+
if (as_form && as_form.readAttribute('data-loading') == 'true') {
|
48
|
+
setTimeout("ActiveScaffold.disable_form('" + as_form.readAttribute('id') + "')", 10);
|
49
|
+
}
|
50
|
+
return true;
|
51
|
+
});
|
52
|
+
document.on('ajax:before', 'a.as_action', function(event) {
|
53
|
+
var action_link = ActiveScaffold.ActionLink.get(event.findElement());
|
54
|
+
if (action_link) {
|
55
|
+
if (action_link.is_disabled()) {
|
56
|
+
event.stop();
|
57
|
+
} else {
|
58
|
+
if (action_link.loading_indicator) action_link.loading_indicator.style.visibility = 'visible';
|
59
|
+
action_link.disable();
|
60
|
+
}
|
61
|
+
}
|
62
|
+
return true;
|
63
|
+
});
|
64
|
+
document.on('ajax:success', 'a.as_action', function(event) {
|
65
|
+
var action_link = ActiveScaffold.ActionLink.get(event.findElement());
|
66
|
+
if (action_link && event.memo && event.memo.request) {
|
67
|
+
if (action_link.position) {
|
68
|
+
action_link.insert(event.memo.request.transport.responseText);
|
69
|
+
if (action_link.hide_target) action_link.target.hide();
|
70
|
+
} else {
|
71
|
+
//event.memo.request.evalResponse(); // (clyfe) prototype evals the response by itself checking headers, this would eval twice
|
72
|
+
action_link.enable();
|
73
|
+
}
|
74
|
+
event.stop();
|
75
|
+
}
|
76
|
+
return true;
|
77
|
+
});
|
78
|
+
document.on('ajax:complete', 'a.as_action', function(event) {
|
79
|
+
var action_link = ActiveScaffold.ActionLink.get(event.findElement());
|
80
|
+
if (action_link && action_link.loading_indicator) {
|
81
|
+
action_link.loading_indicator.style.visibility = 'hidden';
|
82
|
+
}
|
83
|
+
return true;
|
84
|
+
});
|
85
|
+
document.on('ajax:failure', 'a.as_action', function(event) {
|
86
|
+
var action_link = ActiveScaffold.ActionLink.get(event.findElement());
|
87
|
+
if (action_link) {
|
88
|
+
ActiveScaffold.report_500_response(action_link.scaffold_id());
|
89
|
+
action_link.enable();
|
90
|
+
}
|
91
|
+
return true;
|
92
|
+
});
|
93
|
+
document.on('ajax:before', 'a.as_cancel', function(event) {
|
94
|
+
var as_cancel = event.findElement();
|
95
|
+
var action_link = ActiveScaffold.find_action_link(as_cancel);
|
96
|
+
|
97
|
+
if (action_link) {
|
98
|
+
var refresh_data = as_cancel.readAttribute('data-refresh');
|
99
|
+
if (refresh_data === 'true' && action_link.refresh_url) {
|
100
|
+
event.memo.url = action_link.refresh_url;
|
101
|
+
} else if (refresh_data === 'false' || as_cancel.readAttribute('href').blank()) {
|
102
|
+
action_link.close();
|
103
|
+
event.stop();
|
104
|
+
}
|
105
|
+
}
|
106
|
+
return true;
|
107
|
+
});
|
108
|
+
document.on('ajax:success', 'a.as_cancel', function(event) {
|
109
|
+
var action_link = ActiveScaffold.find_action_link(event.findElement());
|
110
|
+
if (action_link) {
|
111
|
+
if (action_link.position) {
|
112
|
+
action_link.close(event.memo.request.responseText);
|
113
|
+
} else {
|
114
|
+
event.memo.request.evalResponse();
|
115
|
+
}
|
116
|
+
}
|
117
|
+
return true;
|
118
|
+
});
|
119
|
+
document.on('ajax:failure', 'a.as_cancel', function(event) {
|
120
|
+
var action_link = ActiveScaffold.find_action_link(event.findElement());
|
121
|
+
if (action_link) {
|
122
|
+
ActiveScaffold.report_500_response(action_link.scaffold_id());
|
123
|
+
}
|
124
|
+
return true;
|
125
|
+
});
|
126
|
+
document.on('ajax:before', 'a.as_sort', function(event) {
|
127
|
+
var as_sort = event.findElement();
|
128
|
+
var history_controller_id = as_sort.readAttribute('data-page-history');
|
129
|
+
if (history_controller_id) addActiveScaffoldPageToHistory(as_sort.readAttribute('href'), history_controller_id);
|
130
|
+
as_sort.up('th').addClassName('loading');
|
131
|
+
return true;
|
132
|
+
});
|
133
|
+
document.on('ajax:failure', 'a.as_sort', function(event) {
|
134
|
+
var as_scaffold = event.findElement('.active-scaffold');
|
135
|
+
ActiveScaffold.report_500_response(as_scaffold);
|
136
|
+
return true;
|
137
|
+
});
|
138
|
+
document.on('mouseover', 'span.in_place_editor_field', function(event) {
|
139
|
+
event.findElement().addClassName('hover');
|
140
|
+
});
|
141
|
+
document.on('mouseout', 'span.in_place_editor_field', function(event) {
|
142
|
+
event.findElement().removeClassName('hover');
|
143
|
+
});
|
144
|
+
document.on('click', 'span.in_place_editor_field', function(event) {
|
145
|
+
var span = event.findElement('span.in_place_editor_field');
|
146
|
+
|
147
|
+
if (typeof(span.inplace_edit) === 'undefined') {
|
148
|
+
var options = {htmlResponse: false,
|
149
|
+
onEnterHover: null,
|
150
|
+
onLeaveHover: null,
|
151
|
+
onComplete: null,
|
152
|
+
params: '',
|
153
|
+
ajaxOptions: {method: 'post'}},
|
154
|
+
csrf_param = $$('meta[name=csrf-param]')[0],
|
155
|
+
csrf_token = $$('meta[name=csrf-token]')[0],
|
156
|
+
my_parent = span.up(),
|
157
|
+
column_heading = null;
|
158
|
+
|
159
|
+
if(!(my_parent.nodeName.toLowerCase() === 'td' || my_parent.nodeName.toLowerCase() === 'th')){
|
160
|
+
my_parent = span.up('td');
|
161
|
+
}
|
162
|
+
|
163
|
+
if (my_parent.nodeName.toLowerCase() === 'td') {
|
164
|
+
var heading_selector = '.' + span.up().readAttribute('class').split(' ')[0] + '_heading';
|
165
|
+
column_heading = span.up('.active-scaffold').down(heading_selector);
|
166
|
+
} else if (my_parent.nodeName.toLowerCase() === 'th') {
|
167
|
+
column_heading = my_parent;
|
168
|
+
}
|
169
|
+
|
170
|
+
var render_url = column_heading.readAttribute('data-ie_render_url'),
|
171
|
+
mode = column_heading.readAttribute('data-ie_mode'),
|
172
|
+
record_id = span.readAttribute('data-ie_id');
|
173
|
+
|
174
|
+
ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options);
|
175
|
+
|
176
|
+
if (span.readAttribute('data-ie_url')) {
|
177
|
+
options.url = span.readAttribute('data-ie_url');
|
178
|
+
} else {
|
179
|
+
options.url = column_heading.readAttribute('data-ie_url');
|
180
|
+
}
|
181
|
+
if (record_id) options.url = options.url.sub('__id__', record_id);
|
182
|
+
|
183
|
+
if (csrf_param) options['params'] = csrf_param.readAttribute('content') + '=' + csrf_token.readAttribute('content');
|
184
|
+
|
185
|
+
if (span.up('div.active-scaffold').readAttribute('data-eid')) {
|
186
|
+
if (options['params'].length > 0) {
|
187
|
+
options['params'] += "&";
|
188
|
+
}
|
189
|
+
options['params'] += ("eid=" + span.up('div.active-scaffold').readAttribute('data-eid'));
|
190
|
+
}
|
191
|
+
|
192
|
+
if (mode === 'clone') {
|
193
|
+
options.nodeIdSuffix = record_id;
|
194
|
+
options.inplacePatternSelector = '#' + column_heading.readAttribute('id') + ' .as_inplace_pattern';
|
195
|
+
options['onFormCustomization'] = new Function('element', 'form', 'element.clonePatternField();');
|
196
|
+
}
|
197
|
+
|
198
|
+
if (render_url) {
|
199
|
+
var plural = false;
|
200
|
+
if (column_heading.readAttribute('data-ie_plural')) plural = true;
|
201
|
+
options['onFormCustomization'] = new Function('element', 'form', 'element.setFieldFromAjax(' + "'" + render_url.sub('__id__', record_id) + "', {plural: " + plural + '});');
|
202
|
+
}
|
203
|
+
|
204
|
+
if (mode === 'inline_checkbox') {
|
205
|
+
ActiveScaffold.process_checkbox_inplace_edit(span.down('input[type="checkbox"]'), options);
|
206
|
+
} else {
|
207
|
+
ActiveScaffold.create_inplace_editor(span, options);
|
208
|
+
}
|
209
|
+
}
|
210
|
+
return true;
|
211
|
+
});
|
212
|
+
document.on('ajax:before', 'a.as_paginate', function(event) {
|
213
|
+
var as_paginate = event.findElement();
|
214
|
+
var loading_indicator = as_paginate.up().down('img.loading-indicator');
|
215
|
+
var history_controller_id = as_paginate.readAttribute('data-page-history');
|
216
|
+
|
217
|
+
if (history_controller_id) addActiveScaffoldPageToHistory(as_paginate.readAttribute('href'), history_controller_id);
|
218
|
+
if (loading_indicator) loading_indicator.style.visibility = 'visible';
|
219
|
+
return true;
|
220
|
+
});
|
221
|
+
document.on('ajax:failure', 'a.as_paginate', function(event) {
|
222
|
+
var as_scaffold = event.findElement('.active-scaffold');
|
223
|
+
ActiveScaffold.report_500_response(as_scaffold);
|
224
|
+
return true;
|
225
|
+
});
|
226
|
+
document.on('ajax:complete', 'a.as_paginate', function(event) {
|
227
|
+
var as_paginate = event.findElement();
|
228
|
+
var loading_indicator = as_paginate.up().down('img.loading-indicator');
|
229
|
+
|
230
|
+
if(loading_indicator) loading_indicator.style.visibility = 'hidden';
|
231
|
+
return true;
|
232
|
+
});
|
233
|
+
document.on('ajax:before', 'a.as_add_existing, a.as_replace_existing', function(event) {
|
234
|
+
var button = event.findElement();
|
235
|
+
var url = button.readAttribute('href').sub('--ID--', button.previous().getValue());
|
236
|
+
event.memo.url = url;
|
237
|
+
return true;
|
238
|
+
});
|
239
|
+
document.on('change', 'input.update_form, select.update_form', function(event) {
|
240
|
+
var element = event.findElement();
|
241
|
+
ActiveScaffold.update_column(element, element.readAttribute('data-update_url'), element.hasAttribute('data-update_send_form'), element.readAttribute('id'), element.getValue());
|
242
|
+
return true;
|
243
|
+
});
|
244
|
+
document.on('change', 'select.as_search_range_option', function(event) {
|
245
|
+
var element = event.findElement();
|
246
|
+
Element[element.value == 'BETWEEN' ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_between'));
|
247
|
+
return true;
|
248
|
+
});
|
249
|
+
document.on('change', 'select.as_search_date_time_option', function(event) {
|
250
|
+
var element = event.findElement();
|
251
|
+
Element[!(element.value == 'PAST' || element.value == 'FUTURE' || element.value == 'RANGE') ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_numeric'));
|
252
|
+
Element[(element.value == 'PAST' || element.value == 'FUTURE') ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_trend'));
|
253
|
+
Element[element.value == 'RANGE' ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_range'));
|
254
|
+
return true;
|
255
|
+
});
|
256
|
+
document.on('change', 'select.as_update_date_operator', function(event) {
|
257
|
+
var element = event.findElement();
|
258
|
+
Element[element.value == 'REPLACE' ? 'show' : 'hide'](element.next());
|
259
|
+
Element[element.value == 'REPLACE' ? 'show' : 'hide'](element.next().next());
|
260
|
+
Element[element.value == 'REPLACE' ? 'hide' : 'show'](element.next('span'));
|
261
|
+
return true;
|
262
|
+
});
|
263
|
+
document.on("click", "a[data-popup]", function(event, element) {
|
264
|
+
if (event.stopped) return;
|
265
|
+
window.open($(element).href);
|
266
|
+
event.stop();
|
267
|
+
});
|
268
|
+
document.on("click", ".hover_click", function(event, element) {
|
269
|
+
var ul_element = element.down('ul');
|
270
|
+
if (ul_element.getStyle('display') === 'none') {
|
271
|
+
ul_element.style.display = 'block';
|
272
|
+
} else {
|
273
|
+
ul_element.style.display = 'none';
|
274
|
+
}
|
275
|
+
|
276
|
+
return true;
|
277
|
+
});
|
278
|
+
document.on("click", ".hover_click a.as_action", function(event, element) {
|
279
|
+
var element = element.up('.hover_click').down('ul');
|
280
|
+
if (element) {
|
281
|
+
element.style.display = 'none';
|
282
|
+
}
|
283
|
+
return true;
|
284
|
+
});
|
285
|
+
});
|
286
|
+
|
287
|
+
|
288
|
+
/*
|
289
|
+
* Simple utility methods
|
290
|
+
*/
|
291
|
+
|
292
|
+
var ActiveScaffold = {
|
293
|
+
records_for: function(tbody_id) {
|
294
|
+
var rows = [];
|
295
|
+
var child = $(tbody_id).down('.record');
|
296
|
+
while (child) {
|
297
|
+
rows.push(child);
|
298
|
+
child = child.next('.record');
|
299
|
+
}
|
300
|
+
return rows;
|
301
|
+
},
|
302
|
+
stripe: function(tbody_id) {
|
303
|
+
var even = false;
|
304
|
+
var rows = this.records_for(tbody_id);
|
305
|
+
for (var i = 0; i < rows.length; i++) {
|
306
|
+
var child = rows[i];
|
307
|
+
//Make sure to skip rows that are create or edit rows or messages
|
308
|
+
if (child.tagName != 'SCRIPT'
|
309
|
+
&& !child.hasClassName("create")
|
310
|
+
&& !child.hasClassName("update")
|
311
|
+
&& !child.hasClassName("inline-adapter")
|
312
|
+
&& !child.hasClassName("active-scaffold-calculations")) {
|
313
|
+
|
314
|
+
if (even) child.addClassName("even-record");
|
315
|
+
else child.removeClassName("even-record");
|
316
|
+
|
317
|
+
even = !even;
|
318
|
+
}
|
319
|
+
}
|
320
|
+
},
|
321
|
+
hide_empty_message: function(tbody) {
|
322
|
+
if (this.records_for(tbody).length != 0) {
|
323
|
+
var empty_message_nodes = $(tbody).up().select('tbody.messages p.empty-message')
|
324
|
+
empty_message_nodes.invoke('hide');
|
325
|
+
}
|
326
|
+
},
|
327
|
+
reload_if_empty: function(tbody, url) {
|
328
|
+
if (this.records_for(tbody).length == 0) {
|
329
|
+
new Ajax.Request(url, {
|
330
|
+
method: 'get',
|
331
|
+
asynchronous: true,
|
332
|
+
evalScripts: true
|
333
|
+
});
|
334
|
+
}
|
335
|
+
},
|
336
|
+
removeSortClasses: function(scaffold) {
|
337
|
+
scaffold = $(scaffold)
|
338
|
+
scaffold.select('td.sorted').each(function(element) {
|
339
|
+
element.removeClassName("sorted");
|
340
|
+
});
|
341
|
+
scaffold.select('th.sorted').each(function(element) {
|
342
|
+
element.removeClassName("sorted");
|
343
|
+
element.removeClassName("asc");
|
344
|
+
element.removeClassName("desc");
|
345
|
+
});
|
346
|
+
},
|
347
|
+
decrement_record_count: function(scaffold) {
|
348
|
+
// decrement the last record count, firsts record count are in nested lists
|
349
|
+
scaffold = $(scaffold)
|
350
|
+
count = scaffold.select('span.active-scaffold-records').last();
|
351
|
+
if (count) count.update(parseInt(count.innerHTML, 10) - 1);
|
352
|
+
},
|
353
|
+
increment_record_count: function(scaffold) {
|
354
|
+
// increment the last record count, firsts record count are in nested lists
|
355
|
+
scaffold = $(scaffold)
|
356
|
+
count = scaffold.select('span.active-scaffold-records').last();
|
357
|
+
if (count) count.update(parseInt(count.innerHTML, 10) + 1);
|
358
|
+
},
|
359
|
+
update_row: function(row, html) {
|
360
|
+
row = $(row);
|
361
|
+
var new_row = this.replace(row, html)
|
362
|
+
if (row.hasClassName('even-record')) new_row.addClassName('even-record');
|
363
|
+
new_row.highlight();
|
364
|
+
},
|
365
|
+
|
366
|
+
replace: function(element, html) {
|
367
|
+
element = $(element)
|
368
|
+
Element.replace(element, html);
|
369
|
+
element = $(element.readAttribute('id'));
|
370
|
+
return element;
|
371
|
+
},
|
372
|
+
|
373
|
+
replace_html: function(element, html) {
|
374
|
+
element = $(element);
|
375
|
+
element.update(html);
|
376
|
+
return element;
|
377
|
+
},
|
378
|
+
|
379
|
+
remove: function(element) {
|
380
|
+
$(element).remove();
|
381
|
+
},
|
382
|
+
|
383
|
+
hide: function(element) {
|
384
|
+
$(element).hide();
|
385
|
+
},
|
386
|
+
|
387
|
+
show: function(element) {
|
388
|
+
$(element).show();
|
389
|
+
},
|
390
|
+
|
391
|
+
reset_form: function(element) {
|
392
|
+
$(element).reset();
|
393
|
+
},
|
394
|
+
|
395
|
+
disable_form: function(as_form) {
|
396
|
+
as_form = $(as_form)
|
397
|
+
var loading_indicator = $(as_form.readAttribute('id').sub('-form', '-loading-indicator'));
|
398
|
+
if (loading_indicator) loading_indicator.style.visibility = 'visible';
|
399
|
+
as_form.disable();
|
400
|
+
},
|
401
|
+
|
402
|
+
enable_form: function(as_form) {
|
403
|
+
as_form = $(as_form)
|
404
|
+
var loading_indicator = $(as_form.readAttribute('id').sub('-form', '-loading-indicator'));
|
405
|
+
if (loading_indicator) loading_indicator.style.visibility = 'hidden';
|
406
|
+
as_form.enable();
|
407
|
+
},
|
408
|
+
|
409
|
+
focus_first_element_of_form: function(form_element) {
|
410
|
+
Form.focusFirstElement(form_element);
|
411
|
+
},
|
412
|
+
|
413
|
+
create_record_row: function(active_scaffold_id, html, options) {
|
414
|
+
tbody = $(active_scaffold_id).down('tbody.records');
|
415
|
+
|
416
|
+
var new_row = null;
|
417
|
+
|
418
|
+
if (options.insert_at == 'top') {
|
419
|
+
tbody.insert({top: html});
|
420
|
+
new_row = tbody.firstDescendant();
|
421
|
+
} else if (options.insert_at == 'bottom') {
|
422
|
+
var last_row = tbody.childElements().reverse().detect(function(node) { return node.hasClassName('record') || node.hasClassName('inline-adapter')});
|
423
|
+
if (last_row) {
|
424
|
+
last_row.insert({after: html});
|
425
|
+
} else {
|
426
|
+
tbody.insert({bottom: html});
|
427
|
+
}
|
428
|
+
new_row = Selector.findChildElements(tbody, ['tr.record']).last();
|
429
|
+
}
|
430
|
+
|
431
|
+
this.stripe(tbody);
|
432
|
+
this.hide_empty_message(tbody);
|
433
|
+
this.increment_record_count(tbody.up('div.active-scaffold'));
|
434
|
+
new_row.highlight();
|
435
|
+
},
|
436
|
+
|
437
|
+
delete_record_row: function(row, page_reload_url) {
|
438
|
+
row = $(row);
|
439
|
+
var tbody = row.up('tbody.records');
|
440
|
+
|
441
|
+
var current_action_node = row.down('td.actions a.disabled');
|
442
|
+
|
443
|
+
if (current_action_node) {
|
444
|
+
var action_link = ActiveScaffold.ActionLink.get(current_action_node);
|
445
|
+
if (action_link) {
|
446
|
+
action_link.close_previous_adapter();
|
447
|
+
}
|
448
|
+
}
|
449
|
+
row.remove();
|
450
|
+
tbody = $(tbody);
|
451
|
+
this.stripe(tbody);
|
452
|
+
this.decrement_record_count(tbody.up('div.active-scaffold'));
|
453
|
+
this.reload_if_empty(tbody, page_reload_url);
|
454
|
+
},
|
455
|
+
|
456
|
+
delete_subform_record: function(record) {
|
457
|
+
var errors = $(record).previous();
|
458
|
+
if (errors.hasClassName('association-record-errors')) {
|
459
|
+
this.replace_html(errors, '');
|
460
|
+
}
|
461
|
+
this.remove(record);
|
462
|
+
},
|
463
|
+
|
464
|
+
report_500_response: function(active_scaffold_id) {
|
465
|
+
server_error = $(active_scaffold_id).down('td.messages-container p.server-error');
|
466
|
+
if (server_error.visible()) {
|
467
|
+
server_error.highlight();
|
468
|
+
} else {
|
469
|
+
server_error.show();
|
470
|
+
}
|
471
|
+
},
|
472
|
+
|
473
|
+
find_action_link: function(element) {
|
474
|
+
return ActiveScaffold.ActionLink.get($(element).up('.as_adapter'));
|
475
|
+
},
|
476
|
+
|
477
|
+
scroll_to: function(element) {
|
478
|
+
$(element).scrollTo();
|
479
|
+
},
|
480
|
+
|
481
|
+
process_checkbox_inplace_edit: function(checkbox, options) {
|
482
|
+
var checked = checkbox.readAttribute('checked');
|
483
|
+
// checked attribute is nt updated
|
484
|
+
if (checked !== 'checked') options['params'] += '&value=1';
|
485
|
+
new Ajax.Request(options.url, {
|
486
|
+
method: 'post',
|
487
|
+
parameters: options['params'],
|
488
|
+
onCreate: function(response) {
|
489
|
+
checkbox.disable();
|
490
|
+
},
|
491
|
+
onComplete: function(response) {
|
492
|
+
checkbox.enable();
|
493
|
+
}
|
494
|
+
});
|
495
|
+
},
|
496
|
+
|
497
|
+
read_inplace_edit_heading_attributes: function(column_heading, options) {
|
498
|
+
if (column_heading.readAttribute('data-ie_cancel_text')) options.cancelText = column_heading.readAttribute('data-ie_cancel_text');
|
499
|
+
if (column_heading.readAttribute('data-ie_loading_text')) options.loadingText = column_heading.readAttribute('data-ie_loading_text');
|
500
|
+
if (column_heading.readAttribute('data-ie_saving_text')) options.savingText = column_heading.readAttribute('data-ie_saving_text');
|
501
|
+
if (column_heading.readAttribute('data-ie_save_text')) options.okText = column_heading.readAttribute('data-ie_save_text');
|
502
|
+
if (column_heading.readAttribute('data-ie_rows')) options.rows = column_heading.readAttribute('data-ie_rows');
|
503
|
+
if (column_heading.readAttribute('data-ie_cols')) options.cols = column_heading.readAttribute('data-ie_cols');
|
504
|
+
if (column_heading.readAttribute('data-ie_size')) options.size = column_heading.readAttribute('data-ie_size');
|
505
|
+
},
|
506
|
+
|
507
|
+
create_inplace_editor: function(span, options) {
|
508
|
+
if (options['params'].length > 0) {
|
509
|
+
options['callback'] = new Function('form', 'return Form.serialize(form) + ' + "'&" + options['params'] + "';");
|
510
|
+
}
|
511
|
+
span.removeClassName('hover');
|
512
|
+
span.inplace_edit = new ActiveScaffold.InPlaceEditor(span.readAttribute('id'), options.url, options)
|
513
|
+
span.inplace_edit.enterEditMode();
|
514
|
+
},
|
515
|
+
|
516
|
+
create_visibility_toggle: function(element, options) {
|
517
|
+
var toggable = $(element);
|
518
|
+
var toggler = toggable.previous();
|
519
|
+
var initial_label = (options.default_visible === true) ? options.hide_label : options.show_label;
|
520
|
+
|
521
|
+
toggler.insert(' (<a class="visibility-toggle" href="#">' + initial_label + '</a>)');
|
522
|
+
toggler.firstDescendant().observe('click', function(event) {
|
523
|
+
var element = event.element();
|
524
|
+
toggable.toggle();
|
525
|
+
element.innerHTML = (toggable.style.display == 'none') ? options.show_label : options.hide_label;
|
526
|
+
return false;
|
527
|
+
});
|
528
|
+
},
|
529
|
+
|
530
|
+
create_associated_record_form: function(element, content, options) {
|
531
|
+
var element = $(element);
|
532
|
+
if (options.singular == false) {
|
533
|
+
if (!(options.id && $(options.id))) {
|
534
|
+
element.insert(content);
|
535
|
+
}
|
536
|
+
} else {
|
537
|
+
var current = $$('#' + element.readAttribute('id') + ' .association-record');
|
538
|
+
if (current[0]) {
|
539
|
+
this.replace(current[0], content);
|
540
|
+
} else {
|
541
|
+
element.insert({top: content});
|
542
|
+
}
|
543
|
+
}
|
544
|
+
},
|
545
|
+
|
546
|
+
render_form_field: function(source, content, options) {
|
547
|
+
var source = $(source);
|
548
|
+
var element = source.up('.association-record');
|
549
|
+
if (typeof(element) === 'undefined') {
|
550
|
+
element = source.up('ol.form');
|
551
|
+
}
|
552
|
+
element = element.down('.' + options.field_class);
|
553
|
+
|
554
|
+
if (element) {
|
555
|
+
if (options.is_subform == false) {
|
556
|
+
this.replace(element.up('dl'), content);
|
557
|
+
} else {
|
558
|
+
this.replace_html(element, content);
|
559
|
+
}
|
560
|
+
}
|
561
|
+
},
|
562
|
+
|
563
|
+
record_select_onselect: function(edit_associated_url, active_scaffold_id, id){
|
564
|
+
new Ajax.Request(
|
565
|
+
edit_associated_url.sub('--ID--', id), {
|
566
|
+
asynchronous: true,
|
567
|
+
evalScripts: true,
|
568
|
+
onFailure: function(){
|
569
|
+
ActiveScaffold.report_500_response(active_scaffold_id.to_json)
|
570
|
+
}
|
571
|
+
}
|
572
|
+
);
|
573
|
+
},
|
574
|
+
|
575
|
+
// element is tbody id
|
576
|
+
mark_records: function(element, options) {
|
577
|
+
var element = $(element);
|
578
|
+
var mark_checkboxes = $$('#' + element.readAttribute('id') + ' > tr.record td.marked-column input[type="checkbox"]');
|
579
|
+
mark_checkboxes.each(function(item) {
|
580
|
+
if(options.checked === true) {
|
581
|
+
item.writeAttribute({ checked: 'checked' });
|
582
|
+
} else {
|
583
|
+
item.removeAttribute('checked');
|
584
|
+
}
|
585
|
+
item.writeAttribute('value', ('' + !options.checked));
|
586
|
+
});
|
587
|
+
if(options.include_mark_all === true) {
|
588
|
+
var mark_all_checkbox = element.previous('thead').down('th.marked-column_heading span input[type="checkbox"]');
|
589
|
+
if(options.checked === true) {
|
590
|
+
mark_all_checkbox.writeAttribute({ checked: 'checked' });
|
591
|
+
} else {
|
592
|
+
mark_all_checkbox.removeAttribute('checked');
|
593
|
+
}
|
594
|
+
mark_all_checkbox.writeAttribute('value', ('' + !options.checked));
|
595
|
+
}
|
596
|
+
},
|
597
|
+
|
598
|
+
update_column: function(element, url, send_form, source_id, val) {
|
599
|
+
if (!element) element = $(source_id);
|
600
|
+
|
601
|
+
var as_form = element.up('form.as_form');
|
602
|
+
var params = null;
|
603
|
+
|
604
|
+
if (send_form) {
|
605
|
+
params = as_form.serialize(true);
|
606
|
+
} else {
|
607
|
+
params = {value: val};
|
608
|
+
}
|
609
|
+
params.source_id = source_id;
|
610
|
+
|
611
|
+
new Ajax.Request(url, {
|
612
|
+
method: 'get',
|
613
|
+
parameters: params,
|
614
|
+
onLoading: function(response) {
|
615
|
+
element.next('img.loading-indicator').style.visibility = 'visible';
|
616
|
+
as_form.disable();
|
617
|
+
},
|
618
|
+
onComplete: function(response) {
|
619
|
+
element.next('img.loading-indicator').style.visibility = 'hidden';
|
620
|
+
as_form.enable();
|
621
|
+
},
|
622
|
+
onFailure: function(request) {
|
623
|
+
var as_div = event.findElement('div.active-scaffold');
|
624
|
+
if (as_div) {
|
625
|
+
ActiveScaffold.report_500_response(as_div)
|
626
|
+
}
|
627
|
+
}
|
628
|
+
});
|
629
|
+
}
|
630
|
+
}
|
631
|
+
|
632
|
+
/*
|
633
|
+
* DHTML history tie-in
|
634
|
+
*/
|
635
|
+
function addActiveScaffoldPageToHistory(url, active_scaffold_id) {
|
636
|
+
if (typeof dhtmlHistory == 'undefined') return; // it may not be loaded
|
637
|
+
|
638
|
+
var array = url.split('?');
|
639
|
+
var qs = new Querystring(array[1]);
|
640
|
+
var sort = qs.get('sort')
|
641
|
+
var dir = qs.get('sort_direction')
|
642
|
+
var page = qs.get('page')
|
643
|
+
if (sort || dir || page) dhtmlHistory.add(active_scaffold_id+":"+page+":"+sort+":"+dir, url);
|
644
|
+
}
|
645
|
+
|
646
|
+
/*
|
647
|
+
* Add-ons/Patches to Prototype
|
648
|
+
*/
|
649
|
+
|
650
|
+
/* patch to support replacing TR/TD/TBODY in Internet Explorer, courtesy of http://dev.rubyonrails.org/ticket/4273 */
|
651
|
+
Element.replace = function(element, html) {
|
652
|
+
element = $(element);
|
653
|
+
if (element.outerHTML) {
|
654
|
+
try {
|
655
|
+
element.outerHTML = html.stripScripts();
|
656
|
+
} catch (e) {
|
657
|
+
var tn = element.tagName;
|
658
|
+
if(tn=='TBODY' || tn=='TR' || tn=='TD')
|
659
|
+
{
|
660
|
+
var tempDiv = document.createElement("div");
|
661
|
+
tempDiv.innerHTML = '<table id="tempTable" style="display: none">' + html.stripScripts() + '</table>';
|
662
|
+
element.parentNode.replaceChild(tempDiv.getElementsByTagName(tn).item(0), element);
|
663
|
+
}
|
664
|
+
else throw e;
|
665
|
+
}
|
666
|
+
} else {
|
667
|
+
var range = element.ownerDocument.createRange();
|
668
|
+
/* patch to fix <form> replaces in Firefox. see http://dev.rubyonrails.org/ticket/8010 */
|
669
|
+
range.selectNodeContents(element.parentNode);
|
670
|
+
element.parentNode.replaceChild(range.createContextualFragment(html.stripScripts()), element);
|
671
|
+
}
|
672
|
+
setTimeout(function() {html.evalScripts()}, 10);
|
673
|
+
return element;
|
674
|
+
};
|
675
|
+
|
676
|
+
/*
|
677
|
+
* URL modification support. Incomplete functionality.
|
678
|
+
*/
|
679
|
+
Object.extend(String.prototype, {
|
680
|
+
append_params: function(params) {
|
681
|
+
url = this;
|
682
|
+
if (url.indexOf('?') == -1) url += '?';
|
683
|
+
else if (url.lastIndexOf('&') != url.length) url += '&';
|
684
|
+
|
685
|
+
url += $H(params).collect(function(item) {
|
686
|
+
return item.key + '=' + item.value;
|
687
|
+
}).join('&');
|
688
|
+
|
689
|
+
return url;
|
690
|
+
}
|
691
|
+
});
|
692
|
+
|
693
|
+
/*
|
694
|
+
* Prototype's implementation was throwing an error instead of false
|
695
|
+
*/
|
696
|
+
Element.Methods.Simulated = {
|
697
|
+
hasAttribute: function(element, attribute) {
|
698
|
+
var t = Element._attributeTranslations;
|
699
|
+
attribute = (t.names && t.names[attribute]) || attribute;
|
700
|
+
// Return false if we get an error here
|
701
|
+
try {
|
702
|
+
return $(element).getAttributeNode(attribute).specified;
|
703
|
+
} catch (e) {
|
704
|
+
return false;
|
705
|
+
}
|
706
|
+
}
|
707
|
+
};
|
708
|
+
|
709
|
+
/**
|
710
|
+
* A set of links. As a set, they can be controlled such that only one is "open" at a time, etc.
|
711
|
+
*/
|
712
|
+
ActiveScaffold.Actions = new Object();
|
713
|
+
ActiveScaffold.Actions.Abstract = Class.create({
|
714
|
+
initialize: function(links, target, loading_indicator, options) {
|
715
|
+
this.target = $(target);
|
716
|
+
this.loading_indicator = $(loading_indicator);
|
717
|
+
this.options = options;
|
718
|
+
this.links = links.collect(function(link) {
|
719
|
+
return this.instantiate_link(link);
|
720
|
+
}.bind(this));
|
721
|
+
},
|
722
|
+
|
723
|
+
instantiate_link: function(link) {
|
724
|
+
throw 'unimplemented'
|
725
|
+
}
|
726
|
+
});
|
727
|
+
|
728
|
+
/**
|
729
|
+
* A DataStructures::ActionLink, represented in JavaScript.
|
730
|
+
* Concerned with AJAX-enabling a link and adapting the result for insertion into the table.
|
731
|
+
*/
|
732
|
+
ActiveScaffold.ActionLink = {
|
733
|
+
get: function(element) {
|
734
|
+
var element = $(element);
|
735
|
+
if (typeof(element.retrieve('action_link')) === 'undefined' && !element.hasClassName('as_adapter')) {
|
736
|
+
var parent = element.up('.actions');
|
737
|
+
if (typeof(parent) === 'undefined') {
|
738
|
+
// maybe an column action_link
|
739
|
+
parent = element.up();
|
740
|
+
}
|
741
|
+
if (parent && parent.nodeName.toUpperCase() == 'TD') {
|
742
|
+
// record action
|
743
|
+
parent = parent.up('tr.record')
|
744
|
+
new ActiveScaffold.Actions.Record(parent.select('a.as_action'), parent, parent.down('td.actions .loading-indicator'));
|
745
|
+
} else if (parent && parent.nodeName.toUpperCase() == 'DIV') {
|
746
|
+
//table action
|
747
|
+
new ActiveScaffold.Actions.Table(parent.select('a.as_action'), parent.up('div.active-scaffold').down('tbody.before-header'), parent.down('.loading-indicator'));
|
748
|
+
}
|
749
|
+
element = $(element);
|
750
|
+
}
|
751
|
+
return element.retrieve('action_link');
|
752
|
+
}
|
753
|
+
};
|
754
|
+
|
755
|
+
ActiveScaffold.ActionLink.Abstract = Class.create({
|
756
|
+
initialize: function(a, target, loading_indicator) {
|
757
|
+
this.tag = $(a);
|
758
|
+
this.url = this.tag.href;
|
759
|
+
this.method = this.tag.readAttribute('data-method') || 'get';
|
760
|
+
this.target = target;
|
761
|
+
this.loading_indicator = loading_indicator;
|
762
|
+
this.hide_target = false;
|
763
|
+
this.position = this.tag.readAttribute('data-position');
|
764
|
+
|
765
|
+
this.tag.store('action_link', this);
|
766
|
+
},
|
767
|
+
|
768
|
+
open: function(event) {
|
769
|
+
},
|
770
|
+
|
771
|
+
insert: function(content) {
|
772
|
+
throw 'unimplemented'
|
773
|
+
},
|
774
|
+
|
775
|
+
close: function() {
|
776
|
+
this.enable();
|
777
|
+
this.adapter.remove();
|
778
|
+
if (this.hide_target) this.target.show();
|
779
|
+
},
|
780
|
+
|
781
|
+
reload: function() {
|
782
|
+
this.close();
|
783
|
+
this.open();
|
784
|
+
},
|
785
|
+
|
786
|
+
get_new_adapter_id: function() {
|
787
|
+
var id = 'adapter_';
|
788
|
+
var i = 0;
|
789
|
+
while ($(id + i)) i++;
|
790
|
+
return id + i;
|
791
|
+
},
|
792
|
+
|
793
|
+
enable: function() {
|
794
|
+
return this.tag.removeClassName('disabled');
|
795
|
+
},
|
796
|
+
|
797
|
+
disable: function() {
|
798
|
+
return this.tag.addClassName('disabled');
|
799
|
+
},
|
800
|
+
|
801
|
+
is_disabled: function() {
|
802
|
+
return this.tag.hasClassName('disabled');
|
803
|
+
},
|
804
|
+
|
805
|
+
scaffold_id: function() {
|
806
|
+
return this.tag.up('div.active-scaffold').readAttribute('id');
|
807
|
+
},
|
808
|
+
|
809
|
+
scaffold: function() {
|
810
|
+
return this.tag.up('div.active-scaffold');
|
811
|
+
},
|
812
|
+
|
813
|
+
update_flash_messages: function(messages) {
|
814
|
+
message_node = $(this.scaffold_id().sub('-active-scaffold', '-messages'));
|
815
|
+
if (message_node) message_node.update(messages);
|
816
|
+
},
|
817
|
+
|
818
|
+
set_adapter: function(element) {
|
819
|
+
this.adapter = element;
|
820
|
+
this.adapter.addClassName('as_adapter');
|
821
|
+
this.adapter.store('action_link', this);
|
822
|
+
}
|
823
|
+
});
|
824
|
+
|
825
|
+
/**
|
826
|
+
* Concrete classes for record actions
|
827
|
+
*/
|
828
|
+
ActiveScaffold.Actions.Record = Class.create(ActiveScaffold.Actions.Abstract, {
|
829
|
+
instantiate_link: function(link) {
|
830
|
+
var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator);
|
831
|
+
if (this.target.hasAttribute('data-refresh') && !this.target.readAttribute('data-refresh').blank()) l.refresh_url = this.target.readAttribute('data-refresh');
|
832
|
+
|
833
|
+
if (l.position) {
|
834
|
+
l.url = l.url.append_params({adapter: '_list_inline_adapter'});
|
835
|
+
l.tag.href = l.url;
|
836
|
+
}
|
837
|
+
l.set = this;
|
838
|
+
return l;
|
839
|
+
}
|
840
|
+
});
|
841
|
+
|
842
|
+
ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstract, {
|
843
|
+
close_previous_adapter: function() {
|
844
|
+
this.set.links.each(function(item) {
|
845
|
+
if (item.url != this.url && item.is_disabled() && item.adapter) {
|
846
|
+
item.enable();
|
847
|
+
item.adapter.remove();
|
848
|
+
}
|
849
|
+
}.bind(this));
|
850
|
+
},
|
851
|
+
|
852
|
+
insert: function(content) {
|
853
|
+
this.close_previous_adapter();
|
854
|
+
|
855
|
+
if (this.position == 'replace') {
|
856
|
+
this.position = 'after';
|
857
|
+
this.hide_target = true;
|
858
|
+
}
|
859
|
+
|
860
|
+
if (this.position == 'after') {
|
861
|
+
this.target.insert({after:content});
|
862
|
+
this.set_adapter(this.target.next());
|
863
|
+
}
|
864
|
+
else if (this.position == 'before') {
|
865
|
+
this.target.insert({before:content});
|
866
|
+
this.set_adapter(this.target.previous());
|
867
|
+
}
|
868
|
+
else {
|
869
|
+
return false;
|
870
|
+
}
|
871
|
+
this.adapter.down('td').down().highlight();
|
872
|
+
},
|
873
|
+
|
874
|
+
close: function($super, refreshed_content) {
|
875
|
+
if (refreshed_content) {
|
876
|
+
ActiveScaffold.update_row(this.target, refreshed_content);
|
877
|
+
}
|
878
|
+
$super();
|
879
|
+
},
|
880
|
+
|
881
|
+
enable: function() {
|
882
|
+
this.set.links.each(function(item) {
|
883
|
+
if (item.url != this.url) return;
|
884
|
+
item.tag.removeClassName('disabled');
|
885
|
+
}.bind(this));
|
886
|
+
},
|
887
|
+
|
888
|
+
disable: function() {
|
889
|
+
this.set.links.each(function(item) {
|
890
|
+
if (item.url != this.url) return;
|
891
|
+
item.tag.addClassName('disabled');
|
892
|
+
}.bind(this));
|
893
|
+
},
|
894
|
+
|
895
|
+
set_opened: function() {
|
896
|
+
if (this.position == 'after') {
|
897
|
+
this.set_adapter(this.target.next());
|
898
|
+
}
|
899
|
+
else if (this.position == 'before') {
|
900
|
+
this.set_adapter(this.target.previous());
|
901
|
+
}
|
902
|
+
this.disable();
|
903
|
+
}
|
904
|
+
});
|
905
|
+
|
906
|
+
/**
|
907
|
+
* Concrete classes for table actions
|
908
|
+
*/
|
909
|
+
ActiveScaffold.Actions.Table = Class.create(ActiveScaffold.Actions.Abstract, {
|
910
|
+
instantiate_link: function(link) {
|
911
|
+
var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator);
|
912
|
+
if (l.position) {
|
913
|
+
l.url = l.url.append_params({adapter: '_list_inline_adapter'});
|
914
|
+
l.tag.href = l.url;
|
915
|
+
}
|
916
|
+
return l;
|
917
|
+
}
|
918
|
+
});
|
919
|
+
|
920
|
+
ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstract, {
|
921
|
+
insert: function(content) {
|
922
|
+
if (this.position == 'top') {
|
923
|
+
this.target.insert({top:content});
|
924
|
+
this.set_adapter(this.target.immediateDescendants().first());
|
925
|
+
}
|
926
|
+
else {
|
927
|
+
throw 'Unknown position "' + this.position + '"'
|
928
|
+
}
|
929
|
+
this.adapter.down('td').down().highlight();
|
930
|
+
}
|
931
|
+
});
|
932
|
+
|
933
|
+
if (Ajax.InPlaceEditor) {
|
934
|
+
ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, {
|
935
|
+
initialize: function($super, element, url, options) {
|
936
|
+
$super(element, url, options);
|
937
|
+
if (this._originalBackground == 'transparent') {
|
938
|
+
this._originalBackground = null;
|
939
|
+
}
|
940
|
+
},
|
941
|
+
|
942
|
+
setFieldFromAjax: function(url, options) {
|
943
|
+
var ipe = this;
|
944
|
+
$(ipe._controls.editor).remove();
|
945
|
+
new Ajax.Request(url, {
|
946
|
+
method: 'get',
|
947
|
+
onComplete: function(response) {
|
948
|
+
ipe._form.insert({top: response.responseText});
|
949
|
+
if (options.plural) {
|
950
|
+
ipe._form.getElements().each(function(el) {
|
951
|
+
if (el.type != "submit" && el.type != "image") {
|
952
|
+
el.name = ipe.options.paramName + '[]';
|
953
|
+
el.className = 'editor_field';
|
954
|
+
}
|
955
|
+
});
|
956
|
+
} else {
|
957
|
+
var fld = ipe._form.findFirstElement();
|
958
|
+
fld.name = ipe.options.paramName;
|
959
|
+
fld.className = 'editor_field';
|
960
|
+
if (ipe.options.submitOnBlur)
|
961
|
+
fld.onblur = ipe._boundSubmitHandler;
|
962
|
+
ipe._controls.editor = fld;
|
963
|
+
}
|
964
|
+
}
|
965
|
+
});
|
966
|
+
},
|
967
|
+
|
968
|
+
clonePatternField: function() {
|
969
|
+
var patternNodes = this.getPatternNodes(this.options.inplacePatternSelector);
|
970
|
+
if (patternNodes.editNode == null) {
|
971
|
+
alert('did not find any matching node for ' + this.options.editFieldSelector);
|
972
|
+
return;
|
973
|
+
}
|
974
|
+
|
975
|
+
var fld = patternNodes.editNode.cloneNode(true);
|
976
|
+
if (fld.id.length > 0) fld.id += this.options.nodeIdSuffix;
|
977
|
+
fld.name = this.options.paramName;
|
978
|
+
fld.className = 'editor_field';
|
979
|
+
this.setValue(fld, this._controls.editor.value);
|
980
|
+
if (this.options.submitOnBlur)
|
981
|
+
fld.onblur = this._boundSubmitHandler;
|
982
|
+
$(this._controls.editor).remove();
|
983
|
+
this._controls.editor = fld;
|
984
|
+
this._form.appendChild(this._controls.editor);
|
985
|
+
|
986
|
+
$A(patternNodes.additionalNodes).each(function(node) {
|
987
|
+
var patternNode = node.cloneNode(true);
|
988
|
+
if (patternNode.id.length > 0) {
|
989
|
+
patternNode.id = patternNode.id + this.options.nodeIdSuffix;
|
990
|
+
}
|
991
|
+
this._form.appendChild(patternNode);
|
992
|
+
}.bind(this));
|
993
|
+
},
|
994
|
+
|
995
|
+
getPatternNodes: function(inplacePatternSelector) {
|
996
|
+
var nodes = {editNode: null, additionalNodes: []};
|
997
|
+
var selectedNodes = $$(inplacePatternSelector);
|
998
|
+
var firstNode = selectedNodes.first();
|
999
|
+
|
1000
|
+
if (typeof(firstNode) !== 'undefined') {
|
1001
|
+
// AS inplace_edit_control_container -> we have to select all child nodes
|
1002
|
+
// Workaround for ie which does not support css > selector
|
1003
|
+
if (firstNode.className.indexOf('as_inplace_pattern') !== -1) {
|
1004
|
+
selectedNodes = firstNode.childElements();
|
1005
|
+
}
|
1006
|
+
nodes.editNode = selectedNodes.first();
|
1007
|
+
selectedNodes.shift();
|
1008
|
+
nodes.additionalNodes = selectedNodes;
|
1009
|
+
}
|
1010
|
+
return nodes;
|
1011
|
+
},
|
1012
|
+
|
1013
|
+
setValue: function(editField, textValue) {
|
1014
|
+
var function_name = 'setValueFor' + editField.nodeName.toLowerCase();
|
1015
|
+
if (typeof(this[function_name]) == 'function') {
|
1016
|
+
this[function_name](editField, textValue);
|
1017
|
+
} else {
|
1018
|
+
editField.value = textValue;
|
1019
|
+
}
|
1020
|
+
},
|
1021
|
+
|
1022
|
+
setValueForselect: function(editField, textValue) {
|
1023
|
+
var len = editField.options.length;
|
1024
|
+
var i = 0;
|
1025
|
+
while (i < len && editField.options[i].text != textValue) {
|
1026
|
+
i++;
|
1027
|
+
}
|
1028
|
+
if (i < len) {
|
1029
|
+
editField.value = editField.options[i].value
|
1030
|
+
}
|
1031
|
+
}
|
1032
|
+
});
|
1033
|
+
}
|