active_scaffold_san 3.0.18
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +27 -0
- data/.document +5 -0
- data/CHANGELOG +179 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +20 -0
- data/MIT-LICENSE +20 -0
- data/README +69 -0
- data/Rakefile +53 -0
- data/active_scaffold_vho.gemspec +388 -0
- data/frontends/default/images/add.gif +0 -0
- data/frontends/default/images/arrow_down.gif +0 -0
- data/frontends/default/images/arrow_up.gif +0 -0
- data/frontends/default/images/close.gif +0 -0
- data/frontends/default/images/config.png +0 -0
- data/frontends/default/images/cross.png +0 -0
- data/frontends/default/images/gears.png +0 -0
- data/frontends/default/images/indicator-small.gif +0 -0
- data/frontends/default/images/indicator.gif +0 -0
- data/frontends/default/images/magnifier.png +0 -0
- data/frontends/default/javascripts/jquery/active_scaffold.js +1004 -0
- data/frontends/default/javascripts/jquery/jquery.editinplace.js +743 -0
- data/frontends/default/javascripts/prototype/active_scaffold.js +1003 -0
- data/frontends/default/javascripts/prototype/dhtml_history.js +867 -0
- data/frontends/default/javascripts/prototype/form_enhancements.js +117 -0
- data/frontends/default/javascripts/prototype/rico_corner.js +370 -0
- data/frontends/default/stylesheets/stylesheet-ie.css +35 -0
- data/frontends/default/stylesheets/stylesheet.css +973 -0
- data/frontends/default/views/_action_group.html.erb +20 -0
- data/frontends/default/views/_add_existing_form.html.erb +30 -0
- data/frontends/default/views/_base_form.html.erb +51 -0
- data/frontends/default/views/_create_form.html.erb +8 -0
- data/frontends/default/views/_create_form_on_list.html.erb +6 -0
- data/frontends/default/views/_field_search.html.erb +32 -0
- data/frontends/default/views/_form.html.erb +24 -0
- data/frontends/default/views/_form_association.html.erb +19 -0
- data/frontends/default/views/_form_association_footer.html.erb +40 -0
- data/frontends/default/views/_form_attribute.html.erb +15 -0
- data/frontends/default/views/_form_hidden_attribute.html.erb +2 -0
- data/frontends/default/views/_form_messages.html.erb +5 -0
- data/frontends/default/views/_horizontal_subform.html.erb +29 -0
- data/frontends/default/views/_horizontal_subform_header.html.erb +10 -0
- data/frontends/default/views/_horizontal_subform_record.html.erb +37 -0
- data/frontends/default/views/_human_conditions.html.erb +1 -0
- data/frontends/default/views/_list.html.erb +18 -0
- data/frontends/default/views/_list_actions.html.erb +15 -0
- data/frontends/default/views/_list_calculations.html.erb +16 -0
- data/frontends/default/views/_list_column_headings.html.erb +12 -0
- data/frontends/default/views/_list_header.html.erb +10 -0
- data/frontends/default/views/_list_inline_adapter.html.erb +10 -0
- data/frontends/default/views/_list_messages.html.erb +32 -0
- data/frontends/default/views/_list_pagination.html.erb +11 -0
- data/frontends/default/views/_list_pagination_links.html.erb +9 -0
- data/frontends/default/views/_list_record.html.erb +14 -0
- data/frontends/default/views/_list_record_columns.html.erb +8 -0
- data/frontends/default/views/_list_with_header.html.erb +32 -0
- data/frontends/default/views/_messages.html.erb +10 -0
- data/frontends/default/views/_render_field.js.rjs +10 -0
- data/frontends/default/views/_row.html.erb +12 -0
- data/frontends/default/views/_search.html.erb +34 -0
- data/frontends/default/views/_search_attribute.html.erb +10 -0
- data/frontends/default/views/_show.html.erb +8 -0
- data/frontends/default/views/_show_columns.html.erb +15 -0
- data/frontends/default/views/_update_actions.html.erb +9 -0
- data/frontends/default/views/_update_form.html.erb +6 -0
- data/frontends/default/views/_vertical_subform.html.erb +12 -0
- data/frontends/default/views/_vertical_subform_record.html.erb +38 -0
- data/frontends/default/views/action_confirmation.html.erb +13 -0
- data/frontends/default/views/add_existing.js.rjs +17 -0
- data/frontends/default/views/add_existing_form.html.erb +5 -0
- data/frontends/default/views/create.html.erb +5 -0
- data/frontends/default/views/delete.html.erb +13 -0
- data/frontends/default/views/destroy.js.rjs +23 -0
- data/frontends/default/views/edit_associated.js.rjs +11 -0
- data/frontends/default/views/field_search.html.erb +5 -0
- data/frontends/default/views/form_messages.js.rjs +1 -0
- data/frontends/default/views/list.html.erb +1 -0
- data/frontends/default/views/list.js.rjs +1 -0
- data/frontends/default/views/on_action_update.js.rjs +8 -0
- data/frontends/default/views/on_create.js.rjs +41 -0
- data/frontends/default/views/on_mark_all.js.rjs +4 -0
- data/frontends/default/views/on_update.js.rjs +28 -0
- data/frontends/default/views/search.html.erb +5 -0
- data/frontends/default/views/show.html.erb +5 -0
- data/frontends/default/views/update.html.erb +8 -0
- data/frontends/default/views/update_column.js.rjs +13 -0
- data/frontends/default/views/update_row.js.rjs +1 -0
- data/init.rb +8 -0
- data/lib/active_scaffold.rb +360 -0
- data/lib/active_scaffold/actions/common_search.rb +22 -0
- data/lib/active_scaffold/actions/core.rb +180 -0
- data/lib/active_scaffold/actions/create.rb +149 -0
- data/lib/active_scaffold/actions/delete.rb +75 -0
- data/lib/active_scaffold/actions/field_search.rb +82 -0
- data/lib/active_scaffold/actions/list.rb +184 -0
- data/lib/active_scaffold/actions/mark.rb +63 -0
- data/lib/active_scaffold/actions/nested.rb +250 -0
- data/lib/active_scaffold/actions/search.rb +47 -0
- data/lib/active_scaffold/actions/show.rb +61 -0
- data/lib/active_scaffold/actions/subform.rb +27 -0
- data/lib/active_scaffold/actions/update.rb +151 -0
- data/lib/active_scaffold/active_record_permissions.rb +134 -0
- data/lib/active_scaffold/attribute_params.rb +211 -0
- data/lib/active_scaffold/bridges/ancestry/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb +39 -0
- data/lib/active_scaffold/bridges/bridge.rb +59 -0
- data/lib/active_scaffold/bridges/calendar_date_select/bridge.rb +16 -0
- data/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +83 -0
- data/lib/active_scaffold/bridges/cancan/bridge.rb +12 -0
- data/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb +107 -0
- data/lib/active_scaffold/bridges/carrierwave/bridge.rb +9 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +33 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +12 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +45 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb +17 -0
- data/lib/active_scaffold/bridges/date_picker/bridge.rb +24 -0
- data/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +225 -0
- data/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js +22 -0
- data/lib/active_scaffold/bridges/file_column/bridge.rb +11 -0
- data/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb +46 -0
- data/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb +59 -0
- data/lib/active_scaffold/bridges/file_column/lib/form_ui.rb +37 -0
- data/lib/active_scaffold/bridges/file_column/lib/list_ui.rb +26 -0
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +43 -0
- data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +9 -0
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +15 -0
- data/lib/active_scaffold/bridges/paperclip/bridge.rb +12 -0
- data/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb +27 -0
- data/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb +16 -0
- data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb +38 -0
- data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +26 -0
- data/lib/active_scaffold/bridges/semantic_attributes/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb +20 -0
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +209 -0
- data/lib/active_scaffold/bridges/tiny_mce/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb +61 -0
- data/lib/active_scaffold/bridges/validation_reflection/bridge.rb +8 -0
- data/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb +21 -0
- data/lib/active_scaffold/config/base.rb +62 -0
- data/lib/active_scaffold/config/core.rb +220 -0
- data/lib/active_scaffold/config/create.rb +51 -0
- data/lib/active_scaffold/config/delete.rb +34 -0
- data/lib/active_scaffold/config/field_search.rb +75 -0
- data/lib/active_scaffold/config/form.rb +47 -0
- data/lib/active_scaffold/config/list.rb +174 -0
- data/lib/active_scaffold/config/mark.rb +22 -0
- data/lib/active_scaffold/config/nested.rb +44 -0
- data/lib/active_scaffold/config/search.rb +69 -0
- data/lib/active_scaffold/config/show.rb +35 -0
- data/lib/active_scaffold/config/subform.rb +35 -0
- data/lib/active_scaffold/config/update.rb +46 -0
- data/lib/active_scaffold/configurable.rb +29 -0
- data/lib/active_scaffold/constraints.rb +184 -0
- data/lib/active_scaffold/data_structures/action_columns.rb +137 -0
- data/lib/active_scaffold/data_structures/action_link.rb +175 -0
- data/lib/active_scaffold/data_structures/action_links.rb +185 -0
- data/lib/active_scaffold/data_structures/actions.rb +45 -0
- data/lib/active_scaffold/data_structures/column.rb +355 -0
- data/lib/active_scaffold/data_structures/columns.rb +75 -0
- data/lib/active_scaffold/data_structures/error_message.rb +24 -0
- data/lib/active_scaffold/data_structures/nested_info.rb +123 -0
- data/lib/active_scaffold/data_structures/set.rb +62 -0
- data/lib/active_scaffold/data_structures/sorting.rb +168 -0
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +20 -0
- data/lib/active_scaffold/extensions/action_view_rendering.rb +123 -0
- data/lib/active_scaffold/extensions/action_view_resolver.rb +7 -0
- data/lib/active_scaffold/extensions/active_association_reflection.rb +13 -0
- data/lib/active_scaffold/extensions/active_record_offset.rb +12 -0
- data/lib/active_scaffold/extensions/array.rb +7 -0
- data/lib/active_scaffold/extensions/localize.rb +10 -0
- data/lib/active_scaffold/extensions/name_option_for_datetime.rb +12 -0
- data/lib/active_scaffold/extensions/nil_id_in_url_params.rb +7 -0
- data/lib/active_scaffold/extensions/paginator_extensions.rb +26 -0
- data/lib/active_scaffold/extensions/reverse_associations.rb +62 -0
- data/lib/active_scaffold/extensions/routing_mapper.rb +34 -0
- data/lib/active_scaffold/extensions/to_label.rb +8 -0
- data/lib/active_scaffold/extensions/unsaved_associated.rb +61 -0
- data/lib/active_scaffold/extensions/unsaved_record.rb +20 -0
- data/lib/active_scaffold/extensions/usa_state.rb +46 -0
- data/lib/active_scaffold/finder.rb +343 -0
- data/lib/active_scaffold/helpers/association_helpers.rb +40 -0
- data/lib/active_scaffold/helpers/controller_helpers.rb +87 -0
- data/lib/active_scaffold/helpers/country_helpers.rb +352 -0
- data/lib/active_scaffold/helpers/form_column_helpers.rb +350 -0
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +59 -0
- data/lib/active_scaffold/helpers/id_helpers.rb +127 -0
- data/lib/active_scaffold/helpers/list_column_helpers.rb +361 -0
- data/lib/active_scaffold/helpers/pagination_helpers.rb +55 -0
- data/lib/active_scaffold/helpers/search_column_helpers.rb +249 -0
- data/lib/active_scaffold/helpers/show_column_helpers.rb +46 -0
- data/lib/active_scaffold/helpers/view_helpers.rb +360 -0
- data/lib/active_scaffold/locale/de.rb +120 -0
- data/lib/active_scaffold/locale/en.rb +119 -0
- data/lib/active_scaffold/locale/es.yml +115 -0
- data/lib/active_scaffold/locale/fr.rb +122 -0
- data/lib/active_scaffold/locale/hu.yml +63 -0
- data/lib/active_scaffold/locale/ja.yml +64 -0
- data/lib/active_scaffold/locale/ru.yml +119 -0
- data/lib/active_scaffold/marked_model.rb +38 -0
- data/lib/active_scaffold/paginator.rb +136 -0
- data/lib/active_scaffold/responds_to_parent.rb +70 -0
- data/lib/active_scaffold/version.rb +9 -0
- data/lib/active_scaffold_assets.rb +45 -0
- data/lib/active_scaffold_env.rb +14 -0
- data/lib/active_scaffold_vho.rb +2 -0
- data/lib/generators/active_scaffold/USAGE +29 -0
- data/lib/generators/active_scaffold/active_scaffold_generator.rb +20 -0
- data/lib/generators/active_scaffold_controller/USAGE +19 -0
- data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +29 -0
- data/lib/generators/active_scaffold_controller/templates/controller.rb +4 -0
- data/lib/generators/active_scaffold_controller/templates/helper.rb +2 -0
- data/lib/generators/active_scaffold_setup/USAGE +10 -0
- data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +61 -0
- data/public/blank.html +33 -0
- data/shoulda_macros/macros.rb +136 -0
- data/test/bridges/bridge_test.rb +47 -0
- data/test/config/base_test.rb +15 -0
- data/test/config/create_test.rb +55 -0
- data/test/config/list_test.rb +74 -0
- data/test/config/show_test.rb +43 -0
- data/test/config/update_test.rb +17 -0
- data/test/const_mocker.rb +36 -0
- data/test/data_structures/action_columns_test.rb +113 -0
- data/test/data_structures/action_link_test.rb +78 -0
- data/test/data_structures/action_links_test.rb +78 -0
- data/test/data_structures/actions_test.rb +25 -0
- data/test/data_structures/association_column_test.rb +42 -0
- data/test/data_structures/column_test.rb +185 -0
- data/test/data_structures/columns_test.rb +69 -0
- data/test/data_structures/error_message_test.rb +28 -0
- data/test/data_structures/set_test.rb +86 -0
- data/test/data_structures/sorting_test.rb +126 -0
- data/test/data_structures/standard_column_test.rb +24 -0
- data/test/data_structures/virtual_column_test.rb +23 -0
- data/test/extensions/active_record_test.rb +45 -0
- data/test/extensions/array_test.rb +12 -0
- data/test/helpers/form_column_helpers_test.rb +31 -0
- data/test/helpers/list_column_helpers_test.rb +31 -0
- data/test/helpers/pagination_helpers_test.rb +55 -0
- data/test/misc/active_record_permissions_test.rb +154 -0
- data/test/misc/attribute_params_test.rb +110 -0
- data/test/misc/configurable_test.rb +96 -0
- data/test/misc/constraints_test.rb +193 -0
- data/test/misc/finder_test.rb +93 -0
- data/test/misc/lang_test.rb +12 -0
- data/test/mock_app/.gitignore +2 -0
- data/test/mock_app/app/controllers/application_controller.rb +10 -0
- data/test/mock_app/app/helpers/application_helper.rb +3 -0
- data/test/mock_app/config/boot.rb +110 -0
- data/test/mock_app/config/database.yml +16 -0
- data/test/mock_app/config/environment.rb +43 -0
- data/test/mock_app/config/environments/development.rb +17 -0
- data/test/mock_app/config/environments/production.rb +28 -0
- data/test/mock_app/config/environments/test.rb +28 -0
- data/test/mock_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/mock_app/config/initializers/inflections.rb +10 -0
- data/test/mock_app/config/initializers/mime_types.rb +5 -0
- data/test/mock_app/config/initializers/new_rails_defaults.rb +19 -0
- data/test/mock_app/config/initializers/session_store.rb +15 -0
- data/test/mock_app/config/locales/en.yml +5 -0
- data/test/mock_app/config/routes.rb +43 -0
- data/test/mock_app/db/test.sqlite3 +1 -0
- data/test/mock_app/public/blank.html +33 -0
- data/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/images/active_scaffold/default/add.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/arrow_down.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/arrow_up.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/close.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/cross.png +0 -0
- data/test/mock_app/public/images/active_scaffold/default/indicator-small.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/indicator.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/magnifier.png +0 -0
- data/test/mock_app/public/javascripts/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +532 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +867 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js +117 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js +370 -0
- data/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css +35 -0
- data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +842 -0
- data/test/model_stub.rb +55 -0
- data/test/run_all.rb +8 -0
- data/test/test_helper.rb +39 -0
- data/uninstall.rb +13 -0
- metadata +497 -0
@@ -0,0 +1,1003 @@
|
|
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', 'input[type=button].as_add_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
|
+
var as_form = element.up('form.as_form');
|
242
|
+
|
243
|
+
new Ajax.Request(element.readAttribute('data-update_url'), {
|
244
|
+
method: 'get',
|
245
|
+
parameters: {value: element.getValue(), source_id: element.readAttribute('id')},
|
246
|
+
onLoading: function(response) {
|
247
|
+
element.next('img.loading-indicator').style.visibility = 'visible';
|
248
|
+
as_form.disable();
|
249
|
+
},
|
250
|
+
onComplete: function(response) {
|
251
|
+
element.next('img.loading-indicator').style.visibility = 'hidden';
|
252
|
+
as_form.enable();
|
253
|
+
},
|
254
|
+
onFailure: function(request) {
|
255
|
+
var as_div = event.findElement('div.active-scaffold');
|
256
|
+
if (as_div) {
|
257
|
+
ActiveScaffold.report_500_response(as_div)
|
258
|
+
}
|
259
|
+
}
|
260
|
+
});
|
261
|
+
return true;
|
262
|
+
});
|
263
|
+
document.on('change', 'select.as_search_range_option', function(event) {
|
264
|
+
var element = event.findElement();
|
265
|
+
Element[element.value == 'BETWEEN' ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_between'));
|
266
|
+
return true;
|
267
|
+
});
|
268
|
+
document.on('change', 'select.as_search_date_time_option', function(event) {
|
269
|
+
var element = event.findElement();
|
270
|
+
Element[!(element.value == 'PAST' || element.value == 'FUTURE' || element.value == 'RANGE') ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_numeric'));
|
271
|
+
Element[(element.value == 'PAST' || element.value == 'FUTURE') ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_trend'));
|
272
|
+
Element[element.value == 'RANGE' ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_range'));
|
273
|
+
return true;
|
274
|
+
});
|
275
|
+
document.on('change', 'select.as_update_date_operator', function(event) {
|
276
|
+
var element = event.findElement();
|
277
|
+
Element[element.value == 'REPLACE' ? 'show' : 'hide'](element.next());
|
278
|
+
Element[element.value == 'REPLACE' ? 'show' : 'hide'](element.next().next());
|
279
|
+
Element[element.value == 'REPLACE' ? 'hide' : 'show'](element.next('span'));
|
280
|
+
return true;
|
281
|
+
});
|
282
|
+
document.on("click", "a[data-popup]", function(event, element) {
|
283
|
+
if (event.stopped) return;
|
284
|
+
window.open($(element).href);
|
285
|
+
event.stop();
|
286
|
+
});
|
287
|
+
});
|
288
|
+
|
289
|
+
|
290
|
+
/*
|
291
|
+
* Simple utility methods
|
292
|
+
*/
|
293
|
+
|
294
|
+
var ActiveScaffold = {
|
295
|
+
records_for: function(tbody_id) {
|
296
|
+
var rows = [];
|
297
|
+
var child = $(tbody_id).down('.record');
|
298
|
+
while (child) {
|
299
|
+
rows.push(child);
|
300
|
+
child = child.next('.record');
|
301
|
+
}
|
302
|
+
return rows;
|
303
|
+
},
|
304
|
+
stripe: function(tbody_id) {
|
305
|
+
var even = false;
|
306
|
+
var rows = this.records_for(tbody_id);
|
307
|
+
for (var i = 0; i < rows.length; i++) {
|
308
|
+
var child = rows[i];
|
309
|
+
//Make sure to skip rows that are create or edit rows or messages
|
310
|
+
if (child.tagName != 'SCRIPT'
|
311
|
+
&& !child.hasClassName("create")
|
312
|
+
&& !child.hasClassName("update")
|
313
|
+
&& !child.hasClassName("inline-adapter")
|
314
|
+
&& !child.hasClassName("active-scaffold-calculations")) {
|
315
|
+
|
316
|
+
if (even) child.addClassName("even-record");
|
317
|
+
else child.removeClassName("even-record");
|
318
|
+
|
319
|
+
even = !even;
|
320
|
+
}
|
321
|
+
}
|
322
|
+
},
|
323
|
+
hide_empty_message: function(tbody) {
|
324
|
+
if (this.records_for(tbody).length != 0) {
|
325
|
+
var empty_message_nodes = $(tbody).up().select('tbody.messages p.empty-message')
|
326
|
+
empty_message_nodes.invoke('hide');
|
327
|
+
}
|
328
|
+
},
|
329
|
+
reload_if_empty: function(tbody, url) {
|
330
|
+
if (this.records_for(tbody).length == 0) {
|
331
|
+
new Ajax.Request(url, {
|
332
|
+
method: 'get',
|
333
|
+
asynchronous: true,
|
334
|
+
evalScripts: true
|
335
|
+
});
|
336
|
+
}
|
337
|
+
},
|
338
|
+
removeSortClasses: function(scaffold) {
|
339
|
+
scaffold = $(scaffold)
|
340
|
+
scaffold.select('td.sorted').each(function(element) {
|
341
|
+
element.removeClassName("sorted");
|
342
|
+
});
|
343
|
+
scaffold.select('th.sorted').each(function(element) {
|
344
|
+
element.removeClassName("sorted");
|
345
|
+
element.removeClassName("asc");
|
346
|
+
element.removeClassName("desc");
|
347
|
+
});
|
348
|
+
},
|
349
|
+
decrement_record_count: function(scaffold) {
|
350
|
+
// decrement the last record count, firsts record count are in nested lists
|
351
|
+
scaffold = $(scaffold)
|
352
|
+
count = scaffold.select('span.active-scaffold-records').last();
|
353
|
+
if (count) count.update(parseInt(count.innerHTML, 10) - 1);
|
354
|
+
},
|
355
|
+
increment_record_count: function(scaffold) {
|
356
|
+
// increment the last record count, firsts record count are in nested lists
|
357
|
+
scaffold = $(scaffold)
|
358
|
+
count = scaffold.select('span.active-scaffold-records').last();
|
359
|
+
if (count) count.update(parseInt(count.innerHTML, 10) + 1);
|
360
|
+
},
|
361
|
+
update_row: function(row, html) {
|
362
|
+
row = $(row);
|
363
|
+
var new_row = this.replace(row, html)
|
364
|
+
if (row.hasClassName('even-record')) new_row.addClassName('even-record');
|
365
|
+
new_row.highlight();
|
366
|
+
},
|
367
|
+
|
368
|
+
replace: function(element, html) {
|
369
|
+
element = $(element)
|
370
|
+
Element.replace(element, html);
|
371
|
+
element = $(element.readAttribute('id'));
|
372
|
+
return element;
|
373
|
+
},
|
374
|
+
|
375
|
+
replace_html: function(element, html) {
|
376
|
+
element = $(element);
|
377
|
+
element.update(html);
|
378
|
+
return element;
|
379
|
+
},
|
380
|
+
|
381
|
+
remove: function(element) {
|
382
|
+
$(element).remove();
|
383
|
+
},
|
384
|
+
|
385
|
+
hide: function(element) {
|
386
|
+
$(element).hide();
|
387
|
+
},
|
388
|
+
|
389
|
+
show: function(element) {
|
390
|
+
$(element).show();
|
391
|
+
},
|
392
|
+
|
393
|
+
reset_form: function(element) {
|
394
|
+
$(element).reset();
|
395
|
+
},
|
396
|
+
|
397
|
+
disable_form: function(as_form) {
|
398
|
+
as_form = $(as_form)
|
399
|
+
var loading_indicator = $(as_form.readAttribute('id').sub('-form', '-loading-indicator'));
|
400
|
+
if (loading_indicator) loading_indicator.style.visibility = 'visible';
|
401
|
+
as_form.disable();
|
402
|
+
},
|
403
|
+
|
404
|
+
enable_form: function(as_form) {
|
405
|
+
as_form = $(as_form)
|
406
|
+
var loading_indicator = $(as_form.readAttribute('id').sub('-form', '-loading-indicator'));
|
407
|
+
if (loading_indicator) loading_indicator.style.visibility = 'hidden';
|
408
|
+
as_form.enable();
|
409
|
+
},
|
410
|
+
|
411
|
+
focus_first_element_of_form: function(form_element) {
|
412
|
+
Form.focusFirstElement(form_element);
|
413
|
+
},
|
414
|
+
|
415
|
+
create_record_row: function(active_scaffold_id, html, options) {
|
416
|
+
tbody = $(active_scaffold_id).down('tbody.records');
|
417
|
+
|
418
|
+
var new_row = null;
|
419
|
+
|
420
|
+
if (options.insert_at == 'top') {
|
421
|
+
tbody.insert({top: html});
|
422
|
+
new_row = tbody.firstDescendant();
|
423
|
+
} else if (options.insert_at == 'bottom') {
|
424
|
+
var last_row = tbody.childElements().reverse().detect(function(node) { return node.hasClassName('record') || node.hasClassName('inline-adapter')});
|
425
|
+
if (last_row) {
|
426
|
+
last_row.insert({after: html});
|
427
|
+
} else {
|
428
|
+
tbody.insert({bottom: html});
|
429
|
+
}
|
430
|
+
new_row = Selector.findChildElements(tbody, ['tr.record']).last();
|
431
|
+
}
|
432
|
+
|
433
|
+
this.stripe(tbody);
|
434
|
+
this.hide_empty_message(tbody);
|
435
|
+
this.increment_record_count(tbody.up('div.active-scaffold'));
|
436
|
+
new_row.highlight();
|
437
|
+
},
|
438
|
+
|
439
|
+
delete_record_row: function(row, page_reload_url) {
|
440
|
+
row = $(row);
|
441
|
+
var tbody = row.up('tbody.records');
|
442
|
+
|
443
|
+
var current_action_node = row.down('td.actions a.disabled');
|
444
|
+
|
445
|
+
if (current_action_node) {
|
446
|
+
var action_link = ActiveScaffold.ActionLink.get(current_action_node);
|
447
|
+
if (action_link) {
|
448
|
+
action_link.close_previous_adapter();
|
449
|
+
}
|
450
|
+
}
|
451
|
+
row.remove();
|
452
|
+
tbody = $(tbody);
|
453
|
+
this.stripe(tbody);
|
454
|
+
this.decrement_record_count(tbody.up('div.active-scaffold'));
|
455
|
+
this.reload_if_empty(tbody, page_reload_url);
|
456
|
+
},
|
457
|
+
|
458
|
+
delete_subform_record: function(record) {
|
459
|
+
var errors = $(record).previous();
|
460
|
+
if (errors.hasClassName('association-record-errors')) {
|
461
|
+
this.replace_html(errors, '');
|
462
|
+
}
|
463
|
+
this.remove(record);
|
464
|
+
},
|
465
|
+
|
466
|
+
report_500_response: function(active_scaffold_id) {
|
467
|
+
server_error = $(active_scaffold_id).down('td.messages-container p.server-error');
|
468
|
+
if (server_error.visible()) {
|
469
|
+
server_error.highlight();
|
470
|
+
} else {
|
471
|
+
server_error.show();
|
472
|
+
}
|
473
|
+
},
|
474
|
+
|
475
|
+
find_action_link: function(element) {
|
476
|
+
return ActiveScaffold.ActionLink.get($(element).up('.as_adapter'));
|
477
|
+
},
|
478
|
+
|
479
|
+
scroll_to: function(element) {
|
480
|
+
$(element).scrollTo();
|
481
|
+
},
|
482
|
+
|
483
|
+
process_checkbox_inplace_edit: function(checkbox, options) {
|
484
|
+
var checked = checkbox.readAttribute('checked');
|
485
|
+
// checked attribute is nt updated
|
486
|
+
if (checked !== 'checked') options['params'] += '&value=1';
|
487
|
+
new Ajax.Request(options.url, {
|
488
|
+
method: 'post',
|
489
|
+
parameters: options['params'],
|
490
|
+
onCreate: function(response) {
|
491
|
+
checkbox.disable();
|
492
|
+
},
|
493
|
+
onComplete: function(response) {
|
494
|
+
checkbox.enable();
|
495
|
+
}
|
496
|
+
});
|
497
|
+
},
|
498
|
+
|
499
|
+
read_inplace_edit_heading_attributes: function(column_heading, options) {
|
500
|
+
if (column_heading.readAttribute('data-ie_cancel_text')) options.cancelText = column_heading.readAttribute('data-ie_cancel_text');
|
501
|
+
if (column_heading.readAttribute('data-ie_loading_text')) options.loadingText = column_heading.readAttribute('data-ie_loading_text');
|
502
|
+
if (column_heading.readAttribute('data-ie_saving_text')) options.savingText = column_heading.readAttribute('data-ie_saving_text');
|
503
|
+
if (column_heading.readAttribute('data-ie_save_text')) options.okText = column_heading.readAttribute('data-ie_save_text');
|
504
|
+
if (column_heading.readAttribute('data-ie_rows')) options.rows = column_heading.readAttribute('data-ie_rows');
|
505
|
+
if (column_heading.readAttribute('data-ie_cols')) options.cols = column_heading.readAttribute('data-ie_cols');
|
506
|
+
if (column_heading.readAttribute('data-ie_size')) options.size = column_heading.readAttribute('data-ie_size');
|
507
|
+
},
|
508
|
+
|
509
|
+
create_inplace_editor: function(span, options) {
|
510
|
+
if (options['params'].length > 0) {
|
511
|
+
options['callback'] = new Function('form', 'return Form.serialize(form) + ' + "'&" + options['params'] + "';");
|
512
|
+
}
|
513
|
+
span.removeClassName('hover');
|
514
|
+
span.inplace_edit = new ActiveScaffold.InPlaceEditor(span.readAttribute('id'), options.url, options)
|
515
|
+
span.inplace_edit.enterEditMode();
|
516
|
+
},
|
517
|
+
|
518
|
+
create_visibility_toggle: function(element, options) {
|
519
|
+
var toggable = $(element);
|
520
|
+
var toggler = toggable.previous();
|
521
|
+
var initial_label = (options.default_visible === true) ? options.hide_label : options.show_label;
|
522
|
+
|
523
|
+
toggler.insert(' (<a class="visibility-toggle" href="#">' + initial_label + '</a>)');
|
524
|
+
toggler.firstDescendant().observe('click', function(event) {
|
525
|
+
var element = event.element();
|
526
|
+
toggable.toggle();
|
527
|
+
element.innerHTML = (toggable.style.display == 'none') ? options.show_label : options.hide_label;
|
528
|
+
return false;
|
529
|
+
});
|
530
|
+
},
|
531
|
+
|
532
|
+
create_associated_record_form: function(element, content, options) {
|
533
|
+
var element = $(element);
|
534
|
+
if (options.singular == false) {
|
535
|
+
if (!(options.id && $(options.id))) {
|
536
|
+
element.insert(content);
|
537
|
+
}
|
538
|
+
} else {
|
539
|
+
var current = $$('#' + element.readAttribute('id') + ' tr.association-record');
|
540
|
+
if (current[0]) {
|
541
|
+
this.replace(current[0], content);
|
542
|
+
} else {
|
543
|
+
element.insert({top: content});
|
544
|
+
}
|
545
|
+
}
|
546
|
+
},
|
547
|
+
|
548
|
+
render_form_field: function(source, content, options) {
|
549
|
+
var source = $(source);
|
550
|
+
var element = source.up('.association-record');
|
551
|
+
if (typeof(element) === 'undefined') {
|
552
|
+
element = source.up('ol.form');
|
553
|
+
}
|
554
|
+
element = element.down('.' + options.field_class);
|
555
|
+
|
556
|
+
if (element) {
|
557
|
+
if (options.is_subform == false) {
|
558
|
+
this.replace(element.up('dl'), content);
|
559
|
+
} else {
|
560
|
+
this.replace_html(element, content);
|
561
|
+
}
|
562
|
+
}
|
563
|
+
},
|
564
|
+
|
565
|
+
record_select_onselect: function(edit_associated_url, active_scaffold_id, id){
|
566
|
+
new Ajax.Request(
|
567
|
+
edit_associated_url.sub('--ID--', id), {
|
568
|
+
asynchronous: true,
|
569
|
+
evalScripts: true,
|
570
|
+
onFailure: function(){
|
571
|
+
ActiveScaffold.report_500_response(active_scaffold_id.to_json)
|
572
|
+
}
|
573
|
+
}
|
574
|
+
);
|
575
|
+
},
|
576
|
+
|
577
|
+
// element is tbody id
|
578
|
+
mark_records: function(element, options) {
|
579
|
+
var element = $(element);
|
580
|
+
var mark_checkboxes = $$('#' + element.readAttribute('id') + ' > tr.record td.marked-column input[type="checkbox"]');
|
581
|
+
mark_checkboxes.each(function(item) {
|
582
|
+
if(options.checked === true) {
|
583
|
+
item.writeAttribute({ checked: 'checked' });
|
584
|
+
} else {
|
585
|
+
item.removeAttribute('checked');
|
586
|
+
}
|
587
|
+
item.writeAttribute('value', ('' + !options.checked));
|
588
|
+
});
|
589
|
+
if(options.include_mark_all === true) {
|
590
|
+
var mark_all_checkbox = element.previous('thead').down('th.marked-column_heading span input[type="checkbox"]');
|
591
|
+
if(options.checked === true) {
|
592
|
+
mark_all_checkbox.writeAttribute({ checked: 'checked' });
|
593
|
+
} else {
|
594
|
+
mark_all_checkbox.removeAttribute('checked');
|
595
|
+
}
|
596
|
+
mark_all_checkbox.writeAttribute('value', ('' + !options.checked));
|
597
|
+
}
|
598
|
+
}
|
599
|
+
|
600
|
+
}
|
601
|
+
|
602
|
+
/*
|
603
|
+
* DHTML history tie-in
|
604
|
+
*/
|
605
|
+
function addActiveScaffoldPageToHistory(url, active_scaffold_id) {
|
606
|
+
if (typeof dhtmlHistory == 'undefined') return; // it may not be loaded
|
607
|
+
|
608
|
+
var array = url.split('?');
|
609
|
+
var qs = new Querystring(array[1]);
|
610
|
+
var sort = qs.get('sort')
|
611
|
+
var dir = qs.get('sort_direction')
|
612
|
+
var page = qs.get('page')
|
613
|
+
if (sort || dir || page) dhtmlHistory.add(active_scaffold_id+":"+page+":"+sort+":"+dir, url);
|
614
|
+
}
|
615
|
+
|
616
|
+
/*
|
617
|
+
* Add-ons/Patches to Prototype
|
618
|
+
*/
|
619
|
+
|
620
|
+
/* patch to support replacing TR/TD/TBODY in Internet Explorer, courtesy of http://dev.rubyonrails.org/ticket/4273 */
|
621
|
+
Element.replace = function(element, html) {
|
622
|
+
element = $(element);
|
623
|
+
if (element.outerHTML) {
|
624
|
+
try {
|
625
|
+
element.outerHTML = html.stripScripts();
|
626
|
+
} catch (e) {
|
627
|
+
var tn = element.tagName;
|
628
|
+
if(tn=='TBODY' || tn=='TR' || tn=='TD')
|
629
|
+
{
|
630
|
+
var tempDiv = document.createElement("div");
|
631
|
+
tempDiv.innerHTML = '<table id="tempTable" style="display: none">' + html.stripScripts() + '</table>';
|
632
|
+
element.parentNode.replaceChild(tempDiv.getElementsByTagName(tn).item(0), element);
|
633
|
+
}
|
634
|
+
else throw e;
|
635
|
+
}
|
636
|
+
} else {
|
637
|
+
var range = element.ownerDocument.createRange();
|
638
|
+
/* patch to fix <form> replaces in Firefox. see http://dev.rubyonrails.org/ticket/8010 */
|
639
|
+
range.selectNodeContents(element.parentNode);
|
640
|
+
element.parentNode.replaceChild(range.createContextualFragment(html.stripScripts()), element);
|
641
|
+
}
|
642
|
+
setTimeout(function() {html.evalScripts()}, 10);
|
643
|
+
return element;
|
644
|
+
};
|
645
|
+
|
646
|
+
/*
|
647
|
+
* URL modification support. Incomplete functionality.
|
648
|
+
*/
|
649
|
+
Object.extend(String.prototype, {
|
650
|
+
append_params: function(params) {
|
651
|
+
url = this;
|
652
|
+
if (url.indexOf('?') == -1) url += '?';
|
653
|
+
else if (url.lastIndexOf('&') != url.length) url += '&';
|
654
|
+
|
655
|
+
url += $H(params).collect(function(item) {
|
656
|
+
return item.key + '=' + item.value;
|
657
|
+
}).join('&');
|
658
|
+
|
659
|
+
return url;
|
660
|
+
}
|
661
|
+
});
|
662
|
+
|
663
|
+
/*
|
664
|
+
* Prototype's implementation was throwing an error instead of false
|
665
|
+
*/
|
666
|
+
Element.Methods.Simulated = {
|
667
|
+
hasAttribute: function(element, attribute) {
|
668
|
+
var t = Element._attributeTranslations;
|
669
|
+
attribute = (t.names && t.names[attribute]) || attribute;
|
670
|
+
// Return false if we get an error here
|
671
|
+
try {
|
672
|
+
return $(element).getAttributeNode(attribute).specified;
|
673
|
+
} catch (e) {
|
674
|
+
return false;
|
675
|
+
}
|
676
|
+
}
|
677
|
+
};
|
678
|
+
|
679
|
+
/**
|
680
|
+
* A set of links. As a set, they can be controlled such that only one is "open" at a time, etc.
|
681
|
+
*/
|
682
|
+
ActiveScaffold.Actions = new Object();
|
683
|
+
ActiveScaffold.Actions.Abstract = Class.create({
|
684
|
+
initialize: function(links, target, loading_indicator, options) {
|
685
|
+
this.target = $(target);
|
686
|
+
this.loading_indicator = $(loading_indicator);
|
687
|
+
this.options = options;
|
688
|
+
this.links = links.collect(function(link) {
|
689
|
+
return this.instantiate_link(link);
|
690
|
+
}.bind(this));
|
691
|
+
},
|
692
|
+
|
693
|
+
instantiate_link: function(link) {
|
694
|
+
throw 'unimplemented'
|
695
|
+
}
|
696
|
+
});
|
697
|
+
|
698
|
+
/**
|
699
|
+
* A DataStructures::ActionLink, represented in JavaScript.
|
700
|
+
* Concerned with AJAX-enabling a link and adapting the result for insertion into the table.
|
701
|
+
*/
|
702
|
+
ActiveScaffold.ActionLink = {
|
703
|
+
get: function(element) {
|
704
|
+
var element = $(element);
|
705
|
+
if (typeof(element.retrieve('action_link')) === 'undefined' && !element.hasClassName('as_adapter')) {
|
706
|
+
var parent = element.up('.actions');
|
707
|
+
if (typeof(parent) === 'undefined') {
|
708
|
+
// maybe an column action_link
|
709
|
+
parent = element.up();
|
710
|
+
}
|
711
|
+
if (parent && parent.nodeName.toUpperCase() == 'TD') {
|
712
|
+
// record action
|
713
|
+
parent = parent.up('tr.record')
|
714
|
+
new ActiveScaffold.Actions.Record(parent.select('a.as_action'), parent, parent.down('td.actions .loading-indicator'));
|
715
|
+
} else if (parent && parent.nodeName.toUpperCase() == 'DIV') {
|
716
|
+
//table action
|
717
|
+
new ActiveScaffold.Actions.Table(parent.select('a.as_action'), parent.up('div.active-scaffold').down('tbody.before-header'), parent.down('.loading-indicator'));
|
718
|
+
}
|
719
|
+
element = $(element);
|
720
|
+
}
|
721
|
+
return element.retrieve('action_link');
|
722
|
+
}
|
723
|
+
};
|
724
|
+
|
725
|
+
ActiveScaffold.ActionLink.Abstract = Class.create({
|
726
|
+
initialize: function(a, target, loading_indicator) {
|
727
|
+
this.tag = $(a);
|
728
|
+
this.url = this.tag.href;
|
729
|
+
this.method = this.tag.readAttribute('data-method') || 'get';
|
730
|
+
this.target = target;
|
731
|
+
this.loading_indicator = loading_indicator;
|
732
|
+
this.hide_target = false;
|
733
|
+
this.position = this.tag.readAttribute('data-position');
|
734
|
+
|
735
|
+
this.tag.store('action_link', this);
|
736
|
+
},
|
737
|
+
|
738
|
+
open: function(event) {
|
739
|
+
},
|
740
|
+
|
741
|
+
insert: function(content) {
|
742
|
+
throw 'unimplemented'
|
743
|
+
},
|
744
|
+
|
745
|
+
close: function() {
|
746
|
+
this.enable();
|
747
|
+
this.adapter.remove();
|
748
|
+
if (this.hide_target) this.target.show();
|
749
|
+
},
|
750
|
+
|
751
|
+
reload: function() {
|
752
|
+
this.close();
|
753
|
+
this.open();
|
754
|
+
},
|
755
|
+
|
756
|
+
get_new_adapter_id: function() {
|
757
|
+
var id = 'adapter_';
|
758
|
+
var i = 0;
|
759
|
+
while ($(id + i)) i++;
|
760
|
+
return id + i;
|
761
|
+
},
|
762
|
+
|
763
|
+
enable: function() {
|
764
|
+
return this.tag.removeClassName('disabled');
|
765
|
+
},
|
766
|
+
|
767
|
+
disable: function() {
|
768
|
+
return this.tag.addClassName('disabled');
|
769
|
+
},
|
770
|
+
|
771
|
+
is_disabled: function() {
|
772
|
+
return this.tag.hasClassName('disabled');
|
773
|
+
},
|
774
|
+
|
775
|
+
scaffold_id: function() {
|
776
|
+
return this.tag.up('div.active-scaffold').readAttribute('id');
|
777
|
+
},
|
778
|
+
|
779
|
+
scaffold: function() {
|
780
|
+
return this.tag.up('div.active-scaffold');
|
781
|
+
},
|
782
|
+
|
783
|
+
update_flash_messages: function(messages) {
|
784
|
+
message_node = $(this.scaffold_id().sub('-active-scaffold', '-messages'));
|
785
|
+
if (message_node) message_node.update(messages);
|
786
|
+
},
|
787
|
+
|
788
|
+
set_adapter: function(element) {
|
789
|
+
this.adapter = element;
|
790
|
+
this.adapter.addClassName('as_adapter');
|
791
|
+
this.adapter.store('action_link', this);
|
792
|
+
}
|
793
|
+
});
|
794
|
+
|
795
|
+
/**
|
796
|
+
* Concrete classes for record actions
|
797
|
+
*/
|
798
|
+
ActiveScaffold.Actions.Record = Class.create(ActiveScaffold.Actions.Abstract, {
|
799
|
+
instantiate_link: function(link) {
|
800
|
+
var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator);
|
801
|
+
if (this.target.hasAttribute('data-refresh') && !this.target.readAttribute('data-refresh').blank()) l.refresh_url = this.target.readAttribute('data-refresh');
|
802
|
+
|
803
|
+
if (l.position) {
|
804
|
+
l.url = l.url.append_params({adapter: '_list_inline_adapter'});
|
805
|
+
l.tag.href = l.url;
|
806
|
+
}
|
807
|
+
l.set = this;
|
808
|
+
return l;
|
809
|
+
}
|
810
|
+
});
|
811
|
+
|
812
|
+
ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstract, {
|
813
|
+
close_previous_adapter: function() {
|
814
|
+
this.set.links.each(function(item) {
|
815
|
+
if (item.url != this.url && item.is_disabled() && item.adapter) {
|
816
|
+
item.enable();
|
817
|
+
item.adapter.remove();
|
818
|
+
}
|
819
|
+
}.bind(this));
|
820
|
+
},
|
821
|
+
|
822
|
+
insert: function(content) {
|
823
|
+
this.close_previous_adapter();
|
824
|
+
|
825
|
+
if (this.position == 'replace') {
|
826
|
+
this.position = 'after';
|
827
|
+
this.hide_target = true;
|
828
|
+
}
|
829
|
+
|
830
|
+
if (this.position == 'after') {
|
831
|
+
this.target.insert({after:content});
|
832
|
+
this.set_adapter(this.target.next());
|
833
|
+
}
|
834
|
+
else if (this.position == 'before') {
|
835
|
+
this.target.insert({before:content});
|
836
|
+
this.set_adapter(this.target.previous());
|
837
|
+
}
|
838
|
+
else {
|
839
|
+
return false;
|
840
|
+
}
|
841
|
+
this.adapter.down('td').down().highlight();
|
842
|
+
},
|
843
|
+
|
844
|
+
close: function($super, refreshed_content) {
|
845
|
+
if (refreshed_content) {
|
846
|
+
ActiveScaffold.update_row(this.target, refreshed_content);
|
847
|
+
}
|
848
|
+
$super();
|
849
|
+
},
|
850
|
+
|
851
|
+
enable: function() {
|
852
|
+
this.set.links.each(function(item) {
|
853
|
+
if (item.url != this.url) return;
|
854
|
+
item.tag.removeClassName('disabled');
|
855
|
+
}.bind(this));
|
856
|
+
},
|
857
|
+
|
858
|
+
disable: function() {
|
859
|
+
this.set.links.each(function(item) {
|
860
|
+
if (item.url != this.url) return;
|
861
|
+
item.tag.addClassName('disabled');
|
862
|
+
}.bind(this));
|
863
|
+
},
|
864
|
+
|
865
|
+
set_opened: function() {
|
866
|
+
if (this.position == 'after') {
|
867
|
+
this.set_adapter(this.target.next());
|
868
|
+
}
|
869
|
+
else if (this.position == 'before') {
|
870
|
+
this.set_adapter(this.target.previous());
|
871
|
+
}
|
872
|
+
this.disable();
|
873
|
+
}
|
874
|
+
});
|
875
|
+
|
876
|
+
/**
|
877
|
+
* Concrete classes for table actions
|
878
|
+
*/
|
879
|
+
ActiveScaffold.Actions.Table = Class.create(ActiveScaffold.Actions.Abstract, {
|
880
|
+
instantiate_link: function(link) {
|
881
|
+
var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator);
|
882
|
+
if (l.position) {
|
883
|
+
l.url = l.url.append_params({adapter: '_list_inline_adapter'});
|
884
|
+
l.tag.href = l.url;
|
885
|
+
}
|
886
|
+
return l;
|
887
|
+
}
|
888
|
+
});
|
889
|
+
|
890
|
+
ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstract, {
|
891
|
+
insert: function(content) {
|
892
|
+
if (this.position == 'top') {
|
893
|
+
this.target.insert({top:content});
|
894
|
+
this.set_adapter(this.target.immediateDescendants().first());
|
895
|
+
}
|
896
|
+
else {
|
897
|
+
throw 'Unknown position "' + this.position + '"'
|
898
|
+
}
|
899
|
+
this.adapter.down('td').down().highlight();
|
900
|
+
}
|
901
|
+
});
|
902
|
+
|
903
|
+
if (Ajax.InPlaceEditor) {
|
904
|
+
ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, {
|
905
|
+
initialize: function($super, element, url, options) {
|
906
|
+
$super(element, url, options);
|
907
|
+
if (this._originalBackground == 'transparent') {
|
908
|
+
this._originalBackground = null;
|
909
|
+
}
|
910
|
+
},
|
911
|
+
|
912
|
+
setFieldFromAjax: function(url, options) {
|
913
|
+
var ipe = this;
|
914
|
+
$(ipe._controls.editor).remove();
|
915
|
+
new Ajax.Request(url, {
|
916
|
+
method: 'get',
|
917
|
+
onComplete: function(response) {
|
918
|
+
ipe._form.insert({top: response.responseText});
|
919
|
+
if (options.plural) {
|
920
|
+
ipe._form.getElements().each(function(el) {
|
921
|
+
if (el.type != "submit" && el.type != "image") {
|
922
|
+
el.name = ipe.options.paramName + '[]';
|
923
|
+
el.className = 'editor_field';
|
924
|
+
}
|
925
|
+
});
|
926
|
+
} else {
|
927
|
+
var fld = ipe._form.findFirstElement();
|
928
|
+
fld.name = ipe.options.paramName;
|
929
|
+
fld.className = 'editor_field';
|
930
|
+
if (ipe.options.submitOnBlur)
|
931
|
+
fld.onblur = ipe._boundSubmitHandler;
|
932
|
+
ipe._controls.editor = fld;
|
933
|
+
}
|
934
|
+
}
|
935
|
+
});
|
936
|
+
},
|
937
|
+
|
938
|
+
clonePatternField: function() {
|
939
|
+
var patternNodes = this.getPatternNodes(this.options.inplacePatternSelector);
|
940
|
+
if (patternNodes.editNode == null) {
|
941
|
+
alert('did not find any matching node for ' + this.options.editFieldSelector);
|
942
|
+
return;
|
943
|
+
}
|
944
|
+
|
945
|
+
var fld = patternNodes.editNode.cloneNode(true);
|
946
|
+
if (fld.id.length > 0) fld.id += this.options.nodeIdSuffix;
|
947
|
+
fld.name = this.options.paramName;
|
948
|
+
fld.className = 'editor_field';
|
949
|
+
this.setValue(fld, this._controls.editor.value);
|
950
|
+
if (this.options.submitOnBlur)
|
951
|
+
fld.onblur = this._boundSubmitHandler;
|
952
|
+
$(this._controls.editor).remove();
|
953
|
+
this._controls.editor = fld;
|
954
|
+
this._form.appendChild(this._controls.editor);
|
955
|
+
|
956
|
+
$A(patternNodes.additionalNodes).each(function(node) {
|
957
|
+
var patternNode = node.cloneNode(true);
|
958
|
+
if (patternNode.id.length > 0) {
|
959
|
+
patternNode.id = patternNode.id + this.options.nodeIdSuffix;
|
960
|
+
}
|
961
|
+
this._form.appendChild(patternNode);
|
962
|
+
}.bind(this));
|
963
|
+
},
|
964
|
+
|
965
|
+
getPatternNodes: function(inplacePatternSelector) {
|
966
|
+
var nodes = {editNode: null, additionalNodes: []};
|
967
|
+
var selectedNodes = $$(inplacePatternSelector);
|
968
|
+
var firstNode = selectedNodes.first();
|
969
|
+
|
970
|
+
if (typeof(firstNode) !== 'undefined') {
|
971
|
+
// AS inplace_edit_control_container -> we have to select all child nodes
|
972
|
+
// Workaround for ie which does not support css > selector
|
973
|
+
if (firstNode.className.indexOf('as_inplace_pattern') !== -1) {
|
974
|
+
selectedNodes = firstNode.childElements();
|
975
|
+
}
|
976
|
+
nodes.editNode = selectedNodes.first();
|
977
|
+
selectedNodes.shift();
|
978
|
+
nodes.additionalNodes = selectedNodes;
|
979
|
+
}
|
980
|
+
return nodes;
|
981
|
+
},
|
982
|
+
|
983
|
+
setValue: function(editField, textValue) {
|
984
|
+
var function_name = 'setValueFor' + editField.nodeName.toLowerCase();
|
985
|
+
if (typeof(this[function_name]) == 'function') {
|
986
|
+
this[function_name](editField, textValue);
|
987
|
+
} else {
|
988
|
+
editField.value = textValue;
|
989
|
+
}
|
990
|
+
},
|
991
|
+
|
992
|
+
setValueForselect: function(editField, textValue) {
|
993
|
+
var len = editField.options.length;
|
994
|
+
var i = 0;
|
995
|
+
while (i < len && editField.options[i].text != textValue) {
|
996
|
+
i++;
|
997
|
+
}
|
998
|
+
if (i < len) {
|
999
|
+
editField.value = editField.options[i].value
|
1000
|
+
}
|
1001
|
+
}
|
1002
|
+
});
|
1003
|
+
}
|