active_scaffold 3.7.12 → 4.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +9 -23
- data/README.md +3 -2
- data/app/assets/config/active_scaffold_manifest.js +3 -0
- data/app/assets/javascripts/active_scaffold.js.erb +24 -34
- data/app/assets/javascripts/jquery/active_scaffold.js +41 -58
- data/app/assets/javascripts/jquery/date_picker_bridge.js.erb +1 -1
- data/app/assets/stylesheets/active_scaffold_colors.scss +0 -7
- data/app/assets/stylesheets/active_scaffold_extensions.css.erb +2 -2
- data/app/assets/stylesheets/active_scaffold_jquery_ui.css.erb +7 -7
- data/app/assets/stylesheets/active_scaffold_layout.css +57 -30
- data/app/views/active_scaffold_overrides/_add_existing_form.html.erb +10 -10
- data/app/views/active_scaffold_overrides/_base_form.html.erb +21 -21
- data/app/views/active_scaffold_overrides/_create_form.html.erb +10 -7
- data/app/views/active_scaffold_overrides/_create_form_on_list.html.erb +5 -5
- data/app/views/active_scaffold_overrides/_field_search.html.erb +6 -6
- data/app/views/active_scaffold_overrides/_form.html.erb +11 -14
- data/app/views/active_scaffold_overrides/_form_association.html.erb +21 -12
- data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +19 -10
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +15 -21
- data/app/views/active_scaffold_overrides/_form_messages.html.erb +2 -2
- data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +7 -6
- data/app/views/active_scaffold_overrides/_human_conditions.html.erb +2 -2
- data/app/views/active_scaffold_overrides/_list.html.erb +15 -8
- data/app/views/active_scaffold_overrides/_list_calculations.html.erb +2 -3
- data/app/views/active_scaffold_overrides/_list_header.html.erb +2 -2
- data/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb +5 -5
- data/app/views/active_scaffold_overrides/_list_messages.html.erb +12 -3
- data/app/views/active_scaffold_overrides/_list_pagination.html.erb +3 -3
- data/app/views/active_scaffold_overrides/_list_pagination_links.html.erb +4 -4
- data/app/views/active_scaffold_overrides/_list_record.html.erb +6 -6
- data/app/views/active_scaffold_overrides/_list_with_header.html.erb +4 -4
- data/app/views/active_scaffold_overrides/_messages.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_refresh_list.js.erb +2 -2
- data/app/views/active_scaffold_overrides/_render_field.js.erb +4 -4
- data/app/views/active_scaffold_overrides/_row.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_search.html.erb +6 -5
- data/app/views/active_scaffold_overrides/_show.html.erb +3 -3
- data/app/views/active_scaffold_overrides/_show_actions.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_show_association.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_show_association_horizontal.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_show_association_vertical.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_show_columns.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_show_horizontal_record.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_update_actions.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_update_calculations.js.erb +2 -2
- data/app/views/active_scaffold_overrides/_update_column.js.erb +8 -7
- data/app/views/active_scaffold_overrides/_update_form.html.erb +5 -5
- data/app/views/active_scaffold_overrides/_update_messages.js.erb +1 -1
- data/app/views/active_scaffold_overrides/_vertical_subform.html.erb +4 -3
- data/app/views/active_scaffold_overrides/action_confirmation.html.erb +3 -3
- data/app/views/active_scaffold_overrides/add_existing.js.erb +6 -6
- data/app/views/active_scaffold_overrides/add_existing_form.html.erb +1 -1
- data/app/views/active_scaffold_overrides/add_tab.js.erb +15 -0
- data/app/views/active_scaffold_overrides/create.html.erb +1 -1
- data/app/views/active_scaffold_overrides/delete.html.erb +4 -4
- data/app/views/active_scaffold_overrides/destroy.js.erb +15 -13
- data/app/views/active_scaffold_overrides/edit_associated.js.erb +3 -3
- data/app/views/active_scaffold_overrides/field_search.html.erb +1 -1
- data/app/views/active_scaffold_overrides/form_messages.js.erb +1 -1
- data/app/views/active_scaffold_overrides/list.html.erb +1 -1
- data/app/views/active_scaffold_overrides/on_action_update.js.erb +13 -8
- data/app/views/active_scaffold_overrides/on_create.js.erb +34 -6
- data/app/views/active_scaffold_overrides/on_mark.js.erb +3 -3
- data/app/views/active_scaffold_overrides/on_update.js.erb +9 -9
- data/app/views/active_scaffold_overrides/render_field.js.erb +1 -1
- data/app/views/active_scaffold_overrides/render_field_inplace.html.erb +1 -1
- data/app/views/active_scaffold_overrides/row.js.erb +2 -2
- data/app/views/active_scaffold_overrides/search.html.erb +1 -1
- data/app/views/active_scaffold_overrides/show.html.erb +3 -3
- data/app/views/active_scaffold_overrides/update.html.erb +2 -2
- data/app/views/active_scaffold_overrides/update_column.js.erb +4 -4
- data/app/views/active_scaffold_overrides/update_row.js.erb +1 -1
- data/lib/active_scaffold/actions/common_search.rb +5 -3
- data/lib/active_scaffold/actions/core.rb +57 -32
- data/lib/active_scaffold/actions/create.rb +19 -17
- data/lib/active_scaffold/actions/delete.rb +10 -12
- data/lib/active_scaffold/actions/field_search.rb +28 -13
- data/lib/active_scaffold/actions/list.rb +34 -34
- data/lib/active_scaffold/actions/mark.rb +5 -5
- data/lib/active_scaffold/actions/nested.rb +64 -56
- data/lib/active_scaffold/actions/search.rb +2 -2
- data/lib/active_scaffold/actions/show.rb +5 -5
- data/lib/active_scaffold/actions/subform.rb +15 -4
- data/lib/active_scaffold/actions/update.rb +20 -20
- data/lib/active_scaffold/active_record_permissions.rb +4 -3
- data/lib/active_scaffold/attribute_params.rb +51 -50
- data/lib/active_scaffold/bridges/active_storage/active_storage_bridge.rb +4 -4
- data/lib/active_scaffold/bridges/active_storage/active_storage_helpers.rb +6 -2
- data/lib/active_scaffold/bridges/active_storage.rb +1 -1
- data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +3 -3
- data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +4 -1
- data/lib/active_scaffold/bridges/bitfields.rb +1 -1
- data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +9 -8
- data/lib/active_scaffold/bridges/cancan.rb +8 -8
- data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +1 -1
- data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +4 -3
- data/lib/active_scaffold/bridges/carrierwave.rb +2 -2
- data/lib/active_scaffold/bridges/chosen.rb +1 -5
- data/lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb +4 -2
- data/lib/active_scaffold/bridges/date_picker/ext.rb +20 -12
- data/lib/active_scaffold/bridges/date_picker/helper.rb +37 -33
- data/lib/active_scaffold/bridges/date_picker.rb +1 -4
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +3 -2
- data/lib/active_scaffold/bridges/dragonfly.rb +1 -1
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +3 -2
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +2 -1
- data/lib/active_scaffold/bridges/file_column/form_ui.rb +4 -9
- data/lib/active_scaffold/bridges/file_column/list_ui.rb +6 -3
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +3 -3
- data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +1 -4
- data/lib/active_scaffold/bridges/file_column.rb +1 -0
- data/lib/active_scaffold/bridges/paper_trail/actions.rb +4 -2
- data/lib/active_scaffold/bridges/paper_trail/config.rb +1 -1
- data/lib/active_scaffold/bridges/paper_trail/helper.rb +1 -1
- data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +2 -1
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +3 -2
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +10 -9
- data/lib/active_scaffold/bridges/paperclip.rb +2 -1
- data/lib/active_scaffold/bridges/record_select/helpers.rb +10 -11
- data/lib/active_scaffold/bridges/semantic_attributes/column.rb +3 -1
- data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -7
- data/lib/active_scaffold/bridges/tiny_mce.rb +2 -7
- data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +7 -7
- data/lib/active_scaffold/bridges.rb +7 -5
- data/lib/active_scaffold/config/base.rb +20 -24
- data/lib/active_scaffold/config/core.rb +27 -39
- data/lib/active_scaffold/config/create.rb +1 -1
- data/lib/active_scaffold/config/delete.rb +9 -9
- data/lib/active_scaffold/config/field_search.rb +4 -9
- data/lib/active_scaffold/config/form.rb +3 -1
- data/lib/active_scaffold/config/list.rb +19 -15
- data/lib/active_scaffold/config/nested.rb +2 -2
- data/lib/active_scaffold/config/search.rb +5 -5
- data/lib/active_scaffold/config/show.rb +1 -1
- data/lib/active_scaffold/config/subform.rb +1 -1
- data/lib/active_scaffold/config/update.rb +4 -5
- data/lib/active_scaffold/configurable.rb +2 -1
- data/lib/active_scaffold/constraints.rb +16 -11
- data/lib/active_scaffold/core.rb +25 -27
- data/lib/active_scaffold/data_structures/action_columns.rb +10 -3
- data/lib/active_scaffold/data_structures/action_link.rb +19 -9
- data/lib/active_scaffold/data_structures/action_links.rb +20 -26
- data/lib/active_scaffold/data_structures/actions.rb +3 -3
- data/lib/active_scaffold/data_structures/association/abstract.rb +8 -4
- data/lib/active_scaffold/data_structures/association/active_mongoid.rb +1 -0
- data/lib/active_scaffold/data_structures/association/active_record.rb +1 -4
- data/lib/active_scaffold/data_structures/column.rb +368 -327
- data/lib/active_scaffold/data_structures/columns.rb +3 -2
- data/lib/active_scaffold/data_structures/nested_info.rb +6 -5
- data/lib/active_scaffold/data_structures/proxy_column.rb +68 -0
- data/lib/active_scaffold/data_structures/set.rb +7 -4
- data/lib/active_scaffold/data_structures/sorting.rb +21 -12
- data/lib/active_scaffold/engine.rb +12 -12
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +5 -5
- data/lib/active_scaffold/extensions/action_controller_rescueing.rb +1 -1
- data/lib/active_scaffold/extensions/action_view_rendering.rb +29 -31
- data/lib/active_scaffold/extensions/ice_nine.rb +2 -1
- data/lib/active_scaffold/extensions/localize.rb +2 -2
- data/lib/active_scaffold/extensions/name_option_for_datetime.rb +1 -1
- data/lib/active_scaffold/extensions/routing_mapper.rb +5 -4
- data/lib/active_scaffold/extensions/unsaved_associated.rb +3 -2
- data/lib/active_scaffold/finder.rb +71 -78
- data/lib/active_scaffold/helpers/action_link_helpers.rb +37 -49
- data/lib/active_scaffold/helpers/association_helpers.rb +3 -2
- data/lib/active_scaffold/helpers/controller_helpers.rb +18 -16
- data/lib/active_scaffold/helpers/form_column_helpers.rb +69 -53
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +17 -15
- data/lib/active_scaffold/helpers/id_helpers.rb +5 -5
- data/lib/active_scaffold/helpers/list_column_helpers.rb +35 -38
- data/lib/active_scaffold/helpers/pagination_helpers.rb +4 -4
- data/lib/active_scaffold/helpers/search_column_helpers.rb +25 -34
- data/lib/active_scaffold/helpers/show_column_helpers.rb +7 -4
- data/lib/active_scaffold/helpers/tabs_helpers.rb +88 -0
- data/lib/active_scaffold/helpers/view_helpers.rb +15 -13
- data/lib/active_scaffold/marked_model.rb +1 -2
- data/lib/active_scaffold/orm_checks.rb +6 -4
- data/lib/active_scaffold/paginator.rb +3 -2
- data/lib/active_scaffold/registry.rb +5 -0
- data/lib/active_scaffold/tableless.rb +24 -14
- data/lib/active_scaffold/version.rb +4 -4
- data/lib/active_scaffold.rb +8 -34
- data/lib/generators/active_scaffold/controller_generator.rb +20 -20
- data/lib/generators/active_scaffold/install_generator.rb +4 -8
- data/lib/generators/active_scaffold/resource_generator.rb +31 -31
- data/lib/tasks/brakeman.rake +1 -1
- data/shoulda_macros/macros.rb +14 -14
- metadata +11 -232
- data/app/assets/javascripts/prototype/active_scaffold.js +0 -1249
- data/app/assets/javascripts/prototype/active_scaffold_chosen.js +0 -0
- data/app/assets/javascripts/prototype/dhtml_history.js +0 -870
- data/app/assets/javascripts/prototype/form_enhancements.js +0 -117
- data/app/assets/javascripts/prototype/tiny_mce_bridge.js +0 -17
- data/app/views/active_scaffold_overrides/_list_messages_content.html.erb +0 -8
- data/app/views/active_scaffold_overrides/_new_record.js.erb +0 -15
- data/app/views/active_scaffold_overrides/_popup_adapter.html.erb +0 -20
- data/app/views/active_scaffold_overrides/_refresh_create_form.js.erb +0 -12
- data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +0 -58
- data/lib/active_scaffold/bridges/calendar_date_select.rb +0 -17
- data/lib/active_scaffold/data_structures/action_link_separator.rb +0 -13
- data/lib/active_scaffold/extensions/cow_proxy.rb +0 -102
- data/test/active_scaffold_config_mock.rb +0 -33
- data/test/bridges/bridge_test.rb +0 -88
- data/test/bridges/date_picker_test.rb +0 -31
- data/test/bridges/paper_trail_test.rb +0 -16
- data/test/bridges/paperclip_test.rb +0 -85
- data/test/bridges/tiny_mce_test.rb +0 -61
- data/test/class_with_finder.rb +0 -42
- data/test/company.rb +0 -97
- data/test/config/base_test.rb +0 -17
- data/test/config/core_test.rb +0 -66
- data/test/config/create_test.rb +0 -72
- data/test/config/delete_test.rb +0 -35
- data/test/config/field_search_test.rb +0 -49
- data/test/config/list_test.rb +0 -134
- data/test/config/nested_test.rb +0 -55
- data/test/config/search_test.rb +0 -62
- data/test/config/show_test.rb +0 -45
- data/test/config/subform_test.rb +0 -19
- data/test/config/update_test.rb +0 -52
- data/test/const_mocker.rb +0 -32
- data/test/data_structures/action_columns_test.rb +0 -112
- data/test/data_structures/action_link_test.rb +0 -79
- data/test/data_structures/action_links_test.rb +0 -78
- data/test/data_structures/actions_test.rb +0 -25
- data/test/data_structures/association_column_test.rb +0 -41
- data/test/data_structures/column_test.rb +0 -186
- data/test/data_structures/columns_test.rb +0 -68
- data/test/data_structures/set_test.rb +0 -84
- data/test/data_structures/sorting_test.rb +0 -148
- data/test/data_structures/standard_column_test.rb +0 -23
- data/test/data_structures/validation_reflection_test.rb +0 -69
- data/test/data_structures/virtual_column_test.rb +0 -23
- data/test/extensions/action_view_rendering_test.rb +0 -20
- data/test/extensions/active_record_test.rb +0 -44
- data/test/extensions/routing_mapper_test.rb +0 -73
- data/test/helpers/form_column_helpers_test.rb +0 -34
- data/test/helpers/list_column_helpers_test.rb +0 -53
- data/test/helpers/pagination_helpers_test.rb +0 -65
- data/test/helpers/search_column_helpers_test.rb +0 -15
- data/test/misc/active_record_permissions_test.rb +0 -193
- data/test/misc/attribute_params_test.rb +0 -460
- data/test/misc/calculation_test.rb +0 -39
- data/test/misc/configurable_test.rb +0 -97
- data/test/misc/constraints_test.rb +0 -209
- data/test/misc/convert_numbers_format_test.rb +0 -171
- data/test/misc/finder_test.rb +0 -124
- data/test/misc/lang_test.rb +0 -10
- data/test/misc/parse_datetime_test.rb +0 -159
- data/test/misc/render_test.rb +0 -9
- data/test/misc/tableless_test.rb +0 -56
- data/test/mock_app/.gitignore +0 -2
- data/test/mock_app/Rakefile +0 -7
- data/test/mock_app/app/assets/config/manifest.js +0 -0
- data/test/mock_app/app/controllers/addresses_controller.rb +0 -4
- data/test/mock_app/app/controllers/application_controller.rb +0 -10
- data/test/mock_app/app/controllers/buildings_controller.rb +0 -4
- data/test/mock_app/app/controllers/cars_controller.rb +0 -5
- data/test/mock_app/app/controllers/contacts_controller.rb +0 -4
- data/test/mock_app/app/controllers/floors_controller.rb +0 -6
- data/test/mock_app/app/controllers/people_controller.rb +0 -8
- data/test/mock_app/app/controllers/roles_controller.rb +0 -4
- data/test/mock_app/app/helpers/application_helper.rb +0 -3
- data/test/mock_app/app/models/address.rb +0 -3
- data/test/mock_app/app/models/building.rb +0 -9
- data/test/mock_app/app/models/car.rb +0 -3
- data/test/mock_app/app/models/contact.rb +0 -3
- data/test/mock_app/app/models/file_model.rb +0 -31
- data/test/mock_app/app/models/floor.rb +0 -8
- data/test/mock_app/app/models/person.rb +0 -12
- data/test/mock_app/app/models/role.rb +0 -3
- data/test/mock_app/app/views/active_scaffold_overrides/_form.html.erb +0 -2
- data/test/mock_app/app/views/active_scaffold_overrides/list.html.erb +0 -2
- data/test/mock_app/app/views/people/_first_name_form_column.html.erb +0 -2
- data/test/mock_app/app/views/people/_form.html.erb +0 -2
- data/test/mock_app/app/views/people/list.html.erb +0 -2
- data/test/mock_app/config/application.rb +0 -14
- data/test/mock_app/config/boot.rb +0 -7
- data/test/mock_app/config/database.yml +0 -16
- data/test/mock_app/config/environment.rb +0 -6
- data/test/mock_app/config/environments/development.rb +0 -24
- data/test/mock_app/config/environments/production.rb +0 -49
- data/test/mock_app/config/environments/test.rb +0 -34
- data/test/mock_app/config/initializers/backtrace_silencers.rb +0 -7
- data/test/mock_app/config/initializers/inflections.rb +0 -10
- data/test/mock_app/config/initializers/mime_types.rb +0 -5
- data/test/mock_app/config/initializers/secret_token.rb +0 -11
- data/test/mock_app/config/initializers/session_store.rb +0 -8
- data/test/mock_app/config/initializers/wrap_parameters.rb +0 -14
- data/test/mock_app/config/locales/en.yml +0 -5
- data/test/mock_app/config/routes.rb +0 -17
- data/test/mock_app/config.ru +0 -4
- data/test/mock_app/db/schema.rb +0 -68
- data/test/mock_app/db/test.sqlite3 +0 -1
- data/test/model_stub.rb +0 -64
- data/test/performance/list_cars_performance_test.rb +0 -34
- data/test/performance/list_people_performance_test.rb +0 -31
- data/test/performance_test_help.rb +0 -3
- data/test/run_all.rb +0 -6
- data/test/test_helper.rb +0 -71
- data/vendor/assets/javascripts/getprototypeof.js +0 -12
@@ -1,1249 +0,0 @@
|
|
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('click', function(event) {
|
16
|
-
$$('.action_group.dyn > ul').invoke('hide');
|
17
|
-
});
|
18
|
-
document.on('ajax:complete', '.action_group.dyn > ul a', function() {
|
19
|
-
var source = event.findElement();
|
20
|
-
var action_link = ActiveScaffold.find_action_link(source);
|
21
|
-
if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden');
|
22
|
-
$(source).up('.action_group.dyn > ul').remove();
|
23
|
-
});
|
24
|
-
document.on('ajax:create', 'form.as_form', function(event) {
|
25
|
-
var source = event.findElement();
|
26
|
-
var as_form = event.findElement('form');
|
27
|
-
if (source.nodeName.toUpperCase() == 'INPUT' && source.readAttribute('type') == 'button') {
|
28
|
-
// Hack: Prototype or rails.js somehow screw up event handling if someone clicks
|
29
|
-
// a button of type button such as Create Another <Association>
|
30
|
-
// as a result form is disabled but never reenabled..
|
31
|
-
} else {
|
32
|
-
if (as_form && as_form.readAttribute('data-loading') == 'true') {
|
33
|
-
ActiveScaffold.disable_form(as_form);
|
34
|
-
}
|
35
|
-
}
|
36
|
-
return true;
|
37
|
-
});
|
38
|
-
document.on('ajax:complete', 'form.as_form', function(event) {
|
39
|
-
var as_form = event.findElement('form');
|
40
|
-
if (as_form && as_form.readAttribute('data-loading') == 'true') {
|
41
|
-
ActiveScaffold.enable_form(as_form);
|
42
|
-
event.stop();
|
43
|
-
return false;
|
44
|
-
}
|
45
|
-
});
|
46
|
-
document.on('ajax:complete', 'form.live', function(event) {
|
47
|
-
ActiveScaffold.focus_first_element_of_form(event.findElement('form'));
|
48
|
-
});
|
49
|
-
document.on('ajax:failure', 'form.as_form', function(event) {
|
50
|
-
var as_div = event.findElement('div.active-scaffold');
|
51
|
-
if (as_div) {
|
52
|
-
ActiveScaffold.report_500_response(as_div)
|
53
|
-
event.stop();
|
54
|
-
return false;
|
55
|
-
}
|
56
|
-
});
|
57
|
-
document.on('submit', 'form.as_form:not([data-remote])', function(event) {
|
58
|
-
var as_form = event.findElement('form');
|
59
|
-
if (as_form && as_form.readAttribute('data-loading') == 'true') {
|
60
|
-
setTimeout("ActiveScaffold.disable_form('" + as_form.readAttribute('id') + "')", 10);
|
61
|
-
}
|
62
|
-
return true;
|
63
|
-
});
|
64
|
-
document.on('ajax:before', 'a.as_action', function(event) {
|
65
|
-
var action_link = ActiveScaffold.ActionLink.get(event.findElement());
|
66
|
-
if (action_link) {
|
67
|
-
if (action_link.is_disabled()) {
|
68
|
-
event.stop();
|
69
|
-
} else {
|
70
|
-
if (action_link.loading_indicator) action_link.loading_indicator.style.visibility = 'visible';
|
71
|
-
action_link.disable();
|
72
|
-
}
|
73
|
-
}
|
74
|
-
return true;
|
75
|
-
});
|
76
|
-
document.on('ajax:success', 'a.as_action', function(event) {
|
77
|
-
var action_link = ActiveScaffold.ActionLink.get(event.findElement());
|
78
|
-
if (action_link && event.memo && event.memo.request) {
|
79
|
-
if (action_link.position) {
|
80
|
-
action_link.insert(event.memo.request.transport.responseText);
|
81
|
-
if (action_link.hide_target) action_link.target.hide();
|
82
|
-
} else {
|
83
|
-
if (action_link.tag.hasClassName('toggle')) {
|
84
|
-
action_link.tag.up('.action_group,.actions').select('.toggle.active').invoke('removeClassName', 'active');
|
85
|
-
action_link.tag.addClassName('active');
|
86
|
-
}
|
87
|
-
action_link.enable();
|
88
|
-
}
|
89
|
-
event.stop();
|
90
|
-
}
|
91
|
-
return true;
|
92
|
-
});
|
93
|
-
document.on('ajax:complete', 'a.as_action', function(event) {
|
94
|
-
var action_link = ActiveScaffold.ActionLink.get(event.findElement());
|
95
|
-
if (action_link && action_link.loading_indicator) {
|
96
|
-
action_link.loading_indicator.style.visibility = 'hidden';
|
97
|
-
}
|
98
|
-
return true;
|
99
|
-
});
|
100
|
-
document.on('ajax:failure', 'a.as_action', function(event) {
|
101
|
-
var action_link = ActiveScaffold.ActionLink.get(event.findElement());
|
102
|
-
if (action_link) {
|
103
|
-
ActiveScaffold.report_500_response(action_link.scaffold_id());
|
104
|
-
action_link.enable();
|
105
|
-
}
|
106
|
-
return true;
|
107
|
-
});
|
108
|
-
document.on('ajax:before', 'a.as_cancel', function(event) {
|
109
|
-
var as_cancel = event.findElement();
|
110
|
-
var action_link = ActiveScaffold.find_action_link(as_cancel);
|
111
|
-
|
112
|
-
if (action_link) {
|
113
|
-
var refresh_data = action_link.tag.readAttribute('data-cancel-refresh') || as_cancel.readAttribute('data-refresh');
|
114
|
-
if (refresh_data && action_link.refresh_url) {
|
115
|
-
event.memo.url = action_link.refresh_url;
|
116
|
-
} else if (!refresh_data || as_cancel.readAttribute('href').blank()) {
|
117
|
-
action_link.close();
|
118
|
-
event.stop();
|
119
|
-
}
|
120
|
-
}
|
121
|
-
return true;
|
122
|
-
});
|
123
|
-
document.on('ajax:success', 'a.as_cancel', function(event) {
|
124
|
-
var link = event.findElement(), action_link = ActiveScaffold.find_action_link(link);
|
125
|
-
if (action_link) {
|
126
|
-
if (action_link.position) {
|
127
|
-
action_link.close();
|
128
|
-
} else {
|
129
|
-
event.memo.request.evalResponse();
|
130
|
-
}
|
131
|
-
}
|
132
|
-
if (link.hasClassName('reset')) link.up('form').reset();
|
133
|
-
return true;
|
134
|
-
});
|
135
|
-
document.on('ajax:failure', 'a.as_cancel', function(event) {
|
136
|
-
var action_link = ActiveScaffold.find_action_link(event.findElement());
|
137
|
-
if (action_link) {
|
138
|
-
ActiveScaffold.report_500_response(action_link.scaffold_id());
|
139
|
-
}
|
140
|
-
return true;
|
141
|
-
});
|
142
|
-
document.on('ajax:before', 'a.as_sort', function(event) {
|
143
|
-
var as_sort = event.findElement();
|
144
|
-
var history_controller_id = as_sort.readAttribute('data-page-history');
|
145
|
-
if (history_controller_id) addActiveScaffoldPageToHistory(as_sort.readAttribute('href'), history_controller_id);
|
146
|
-
as_sort.up('th').addClassName('loading');
|
147
|
-
return true;
|
148
|
-
});
|
149
|
-
document.on('ajax:failure', 'a.as_sort', function(event) {
|
150
|
-
var as_scaffold = event.findElement('.active-scaffold');
|
151
|
-
ActiveScaffold.report_500_response(as_scaffold);
|
152
|
-
return true;
|
153
|
-
});
|
154
|
-
document.on('mouseover', 'td.in_place_editor_field', function(event) {
|
155
|
-
event.findElement('td.in_place_editor_field').select('span').invoke('addClassName', 'hover');
|
156
|
-
});
|
157
|
-
document.on('mouseout', 'td.in_place_editor_field', function(event) {
|
158
|
-
event.findElement('td.in_place_editor_field').select('span').invoke('removeClassName', 'hover');
|
159
|
-
});
|
160
|
-
document.on('click', 'td.in_place_editor_field', function(event) {
|
161
|
-
var td = event.findElement('td.in_place_editor_field'),
|
162
|
-
span = td.down('span.in_place_editor_field');
|
163
|
-
td.removeClassName('empty');
|
164
|
-
|
165
|
-
if (typeof(span.inplace_edit) === 'undefined') {
|
166
|
-
var options = {htmlResponse: false,
|
167
|
-
onEnterHover: null,
|
168
|
-
onLeaveHover: null,
|
169
|
-
onComplete: null,
|
170
|
-
params: '',
|
171
|
-
externalControl: td.down('.handle'),
|
172
|
-
ajaxOptions: {method: 'post'}},
|
173
|
-
csrf_param = $$('meta[name=csrf-param]')[0],
|
174
|
-
csrf_token = $$('meta[name=csrf-token]')[0],
|
175
|
-
my_parent = span.up(),
|
176
|
-
column_heading = null;
|
177
|
-
|
178
|
-
if(!(my_parent.nodeName.toLowerCase() === 'td' || my_parent.nodeName.toLowerCase() === 'th')){
|
179
|
-
my_parent = span.up('td');
|
180
|
-
}
|
181
|
-
|
182
|
-
if (my_parent.nodeName.toLowerCase() === 'td') {
|
183
|
-
var heading_selector = '.' + span.up().readAttribute('class').split(' ')[0] + '_heading';
|
184
|
-
column_heading = span.up('.active-scaffold').down(heading_selector);
|
185
|
-
} else if (my_parent.nodeName.toLowerCase() === 'th') {
|
186
|
-
column_heading = my_parent;
|
187
|
-
}
|
188
|
-
|
189
|
-
var render_url = column_heading.readAttribute('data-ie-render-url'),
|
190
|
-
mode = column_heading.readAttribute('data-ie-mode'),
|
191
|
-
record_id = span.readAttribute('data-ie-id') || '';
|
192
|
-
|
193
|
-
ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options);
|
194
|
-
|
195
|
-
if (span.readAttribute('data-ie-url')) {
|
196
|
-
options.url = span.readAttribute('data-ie-url');
|
197
|
-
} else {
|
198
|
-
options.url = column_heading.readAttribute('data-ie-url');
|
199
|
-
}
|
200
|
-
options.url = options.url.sub('__id__', record_id);
|
201
|
-
|
202
|
-
if (csrf_param) options['params'] = csrf_param.readAttribute('content') + '=' + csrf_token.readAttribute('content');
|
203
|
-
|
204
|
-
if (span.up('div.active-scaffold').readAttribute('data-eid')) {
|
205
|
-
if (options['params'].length > 0) {
|
206
|
-
options['params'] += "&";
|
207
|
-
}
|
208
|
-
options['params'] += ("eid=" + span.up('div.active-scaffold').readAttribute('data-eid'));
|
209
|
-
}
|
210
|
-
|
211
|
-
if (mode === 'clone') {
|
212
|
-
options.nodeIdSuffix = record_id;
|
213
|
-
options.inplacePatternSelector = '#' + column_heading.readAttribute('id') + ' .as_inplace_pattern';
|
214
|
-
options['onFormCustomization'] = new Function('element', 'form', 'element.clonePatternField();');
|
215
|
-
}
|
216
|
-
|
217
|
-
if (render_url) {
|
218
|
-
var plural = false;
|
219
|
-
if (column_heading.readAttribute('data-ie-plural')) plural = true;
|
220
|
-
options['onFormCustomization'] = new Function('element', 'form', 'element.setFieldFromAjax(' + "'" + render_url.sub('__id__', record_id) + "', {plural: " + plural + '});');
|
221
|
-
}
|
222
|
-
|
223
|
-
if (mode === 'inline_checkbox') {
|
224
|
-
ActiveScaffold.process_checkbox_inplace_edit(span.down('input[type="checkbox"]'), options);
|
225
|
-
} else {
|
226
|
-
ActiveScaffold.create_inplace_editor(span, options);
|
227
|
-
}
|
228
|
-
}
|
229
|
-
return true;
|
230
|
-
});
|
231
|
-
document.on('ajax:before', 'a.as_paginate', function(event) {
|
232
|
-
var as_paginate = event.findElement();
|
233
|
-
var loading_indicator = as_paginate.up().down('img.loading-indicator');
|
234
|
-
var history_controller_id = as_paginate.readAttribute('data-page-history');
|
235
|
-
|
236
|
-
if (history_controller_id) addActiveScaffoldPageToHistory(as_paginate.readAttribute('href'), history_controller_id);
|
237
|
-
if (loading_indicator) loading_indicator.style.visibility = 'visible';
|
238
|
-
return true;
|
239
|
-
});
|
240
|
-
document.on('ajax:failure', 'a.as_paginate', function(event) {
|
241
|
-
var as_scaffold = event.findElement('.active-scaffold');
|
242
|
-
ActiveScaffold.report_500_response(as_scaffold);
|
243
|
-
return true;
|
244
|
-
});
|
245
|
-
document.on('ajax:complete', 'a.as_paginate', function(event) {
|
246
|
-
var as_paginate = event.findElement();
|
247
|
-
var loading_indicator = as_paginate.up().down('img.loading-indicator');
|
248
|
-
|
249
|
-
if(loading_indicator) loading_indicator.style.visibility = 'hidden';
|
250
|
-
return true;
|
251
|
-
});
|
252
|
-
document.on('ajax:before', 'a.as_add_existing, a.as_replace_existing', function(event) {
|
253
|
-
var button = event.findElement();
|
254
|
-
var prev = button.previous();
|
255
|
-
if (!prev.match('input,select')) prev = prev.down('input,select');
|
256
|
-
var id = prev.getValue();
|
257
|
-
if (id) {
|
258
|
-
event.memo.url = button.readAttribute('href').sub('--ID--', id);
|
259
|
-
return true;
|
260
|
-
} else return false;
|
261
|
-
});
|
262
|
-
document.on('change', 'input.update_form, textarea.update_form, select.update_form, .checkbox-list.update_form input:checkbox', function(event) {
|
263
|
-
var element = event.findElement();
|
264
|
-
var form_element = element.up('.checkbox-list');
|
265
|
-
var value, additional_params;
|
266
|
-
if (form_element.match(".checkbox-list")) {
|
267
|
-
value = Form.Element.getValue(form_element.up());
|
268
|
-
additional_params = element.readAttribute('checked') ? {'_added': element.readAttribute('value')} : {'_removed': element.readAttribute('value')};
|
269
|
-
} else {
|
270
|
-
value = element.getValue();
|
271
|
-
form_element = element;
|
272
|
-
}
|
273
|
-
ActiveScaffold.update_column(element, form_element.readAttribute('data-update_url'), form_element.hasAttribute('data-update_send_form'), element.readAttribute('id'), value);
|
274
|
-
return true;
|
275
|
-
});
|
276
|
-
document.on('click', 'a.refresh-link', function(event) {
|
277
|
-
event.stop();
|
278
|
-
var element = event.findElement();
|
279
|
-
var form_element = element.previous();
|
280
|
-
var value;
|
281
|
-
if (form_element.match(".checkbox-list")) {
|
282
|
-
value = Form.Element.getValue(form_element);
|
283
|
-
form_element = form_element.up().select("input:checkbox"); // parent is needed for draggable-list, checked list may be empty
|
284
|
-
} else value = form_element.getValue();
|
285
|
-
ActiveScaffold.update_column(form_element, element.readAttribute('href'), element.hasAttribute('data-update_send_form'), form_element.readAttribute('id'), value);
|
286
|
-
});
|
287
|
-
document.on('click', 'a.visibility-toggle', function(event) {
|
288
|
-
event.stop();
|
289
|
-
var link = event.findElement();
|
290
|
-
var toggable = $(link.readAttribute('data-toggable'));
|
291
|
-
toggable.toggle();
|
292
|
-
link.innerHTML = (toggable.style.display == 'none') ? link.readAttribute('data-show') : link.readAttribute('data-hide');
|
293
|
-
});
|
294
|
-
document.on('recordselect:change', 'input.recordselect.update_form', function(event) {
|
295
|
-
var element = event.findElement();
|
296
|
-
ActiveScaffold.update_column(element, element.readAttribute('data-update_url'), element.hasAttribute('data-update_send_form'), element.readAttribute('id'), element.memo.id);
|
297
|
-
return true;
|
298
|
-
});
|
299
|
-
document.on('change', 'select.as_search_range_option', function(event) {
|
300
|
-
var element = event.findElement();
|
301
|
-
Element[element.value == 'BETWEEN' ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_between'));
|
302
|
-
Element[(element.value == 'null' || element.value == 'not_null') ? 'hide' : 'show'](element.readAttribute('id').sub('_opt', '_numeric'));
|
303
|
-
return true;
|
304
|
-
});
|
305
|
-
document.on('change', 'select.as_search_date_time_option', function(event) {
|
306
|
-
var element = event.findElement();
|
307
|
-
Element[!(element.value == 'PAST' || element.value == 'FUTURE' || element.value == 'RANGE') ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_numeric'));
|
308
|
-
Element[(element.value == 'PAST' || element.value == 'FUTURE') ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_trend'));
|
309
|
-
Element[element.value == 'RANGE' ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_range'));
|
310
|
-
return true;
|
311
|
-
});
|
312
|
-
document.on('change', 'select.as_update_date_operator', function(event) {
|
313
|
-
var element = event.findElement();
|
314
|
-
Element[element.value == 'REPLACE' ? 'show' : 'hide'](element.next());
|
315
|
-
Element[element.value == 'REPLACE' ? 'show' : 'hide'](element.next().next());
|
316
|
-
Element[element.value == 'REPLACE' ? 'hide' : 'show'](element.next('span'));
|
317
|
-
return true;
|
318
|
-
});
|
319
|
-
document.on("click", ".hover_click", function(event, element) {
|
320
|
-
var ul_element = element.down('ul');
|
321
|
-
if (ul_element.getStyle('display') === 'none') {
|
322
|
-
ul_element.style.display = 'block';
|
323
|
-
} else {
|
324
|
-
ul_element.style.display = 'none';
|
325
|
-
}
|
326
|
-
|
327
|
-
return true;
|
328
|
-
});
|
329
|
-
document.on("click", ".hover_click a.as_action", function(event, element) {
|
330
|
-
var element = element.up('.hover_click').down('ul');
|
331
|
-
if (element) {
|
332
|
-
element.style.display = 'none';
|
333
|
-
}
|
334
|
-
return true;
|
335
|
-
});
|
336
|
-
document.on('click', '.messages a.close', function(event, element) {
|
337
|
-
ActiveScaffold.hide(element.up('.message'));
|
338
|
-
event.stop();
|
339
|
-
});
|
340
|
-
|
341
|
-
/* setup some elements on page/form load */
|
342
|
-
ActiveScaffold.load_embedded(document);
|
343
|
-
ActiveScaffold.enable_js_form_buttons(document);
|
344
|
-
ActiveScaffold.live_search(document);
|
345
|
-
ActiveScaffold.auto_paginate(document);
|
346
|
-
ActiveScaffold.draggable_lists('.draggable-lists', document);
|
347
|
-
document.on('as:element_updated', function(e) {
|
348
|
-
var target = event.findElement();
|
349
|
-
ActiveScaffold.load_embedded(target);
|
350
|
-
ActiveScaffold.enable_js_form_buttons(target);
|
351
|
-
ActiveScaffold.live_search(target);
|
352
|
-
ActiveScaffold.draggable_lists('.draggable-lists', target);
|
353
|
-
});
|
354
|
-
document.on('as:action_success', 'a.as_action', function(e, action_link) {
|
355
|
-
ActiveScaffold.load_embedded(action_link.adapter);
|
356
|
-
ActiveScaffold.enable_js_form_buttons(action_link.adapter);
|
357
|
-
ActiveScaffold.live_search(action_link.adapter);
|
358
|
-
ActiveScaffold.auto_paginate(action_link.adapter);
|
359
|
-
ActiveScaffold.draggable_lists('.draggable-lists', action_link.adapter);
|
360
|
-
});
|
361
|
-
});
|
362
|
-
|
363
|
-
|
364
|
-
/*
|
365
|
-
* Simple utility methods
|
366
|
-
*/
|
367
|
-
|
368
|
-
var ActiveScaffold = {
|
369
|
-
live_search: function(element) {
|
370
|
-
$$('form.search.live input[type=search]', element).each(function(item) {
|
371
|
-
new Form.Element.DelayedObserver(item, 0.5, function(element, value) {
|
372
|
-
if (!$(element.id)) return false; // because the element may have been destroyed
|
373
|
-
$(element).next().click();
|
374
|
-
});
|
375
|
-
});
|
376
|
-
},
|
377
|
-
auto_paginate: function(element) {
|
378
|
-
var paginate_link = $(element).select('.active-scaffold-pagination.auto-paginate a:first');
|
379
|
-
if (paginate_link.length) {
|
380
|
-
$(element).select('.active-scaffold-pagination.auto-paginate').invoke('hide');
|
381
|
-
ActiveScaffold.auto_load_page(paginate_link.readAttribute('href'), {auto_pagination: true});
|
382
|
-
}
|
383
|
-
},
|
384
|
-
auto_load_page: function(href, params) {
|
385
|
-
new Ajax.Request(href, {
|
386
|
-
method: 'get',
|
387
|
-
parameters: params,
|
388
|
-
asynchronous: true,
|
389
|
-
evalScripts: true
|
390
|
-
});
|
391
|
-
},
|
392
|
-
enable_js_form_buttons: function(element) {
|
393
|
-
$(element).select('.as-js-button').invoke('show');
|
394
|
-
},
|
395
|
-
load_embedded: function(element) {
|
396
|
-
$(element).select('.active-scaffold-component .load-embedded').each(function(item) {
|
397
|
-
new Ajax.Updater(item.up('.active-scaffold-component'), item.readAttribute('href'), {method: 'get', evalScripts: true});
|
398
|
-
});
|
399
|
-
},
|
400
|
-
reload_embedded: function(element) {
|
401
|
-
var item = $(element)
|
402
|
-
new Ajax.Updater(item, item.readAttribute('data-refresh'), {method: 'get', evalScripts: true});
|
403
|
-
},
|
404
|
-
|
405
|
-
records_for: function(tbody_id) {
|
406
|
-
var rows = [];
|
407
|
-
var child = $(tbody_id).down('.record');
|
408
|
-
while (child) {
|
409
|
-
rows.push(child);
|
410
|
-
child = child.next('.record');
|
411
|
-
}
|
412
|
-
return rows;
|
413
|
-
},
|
414
|
-
stripe: function(tbody_id) {
|
415
|
-
var even = false;
|
416
|
-
var rows = this.records_for(tbody_id);
|
417
|
-
for (var i = 0; i < rows.length; i++) {
|
418
|
-
var child = rows[i];
|
419
|
-
//Make sure to skip rows that are create or edit rows or messages
|
420
|
-
if (child.tagName != 'SCRIPT'
|
421
|
-
&& !child.hasClassName("create")
|
422
|
-
&& !child.hasClassName("update")
|
423
|
-
&& !child.hasClassName("inline-adapter")
|
424
|
-
&& !child.hasClassName("active-scaffold-calculations")) {
|
425
|
-
|
426
|
-
if (even) child.addClassName("even-record");
|
427
|
-
else child.removeClassName("even-record");
|
428
|
-
|
429
|
-
even = !even;
|
430
|
-
}
|
431
|
-
}
|
432
|
-
},
|
433
|
-
hide_empty_message: function(tbody) {
|
434
|
-
if (this.records_for(tbody).length != 0) {
|
435
|
-
var empty_message_nodes = $(tbody).up().select('tbody.messages p.empty-message')
|
436
|
-
empty_message_nodes.invoke('hide');
|
437
|
-
}
|
438
|
-
},
|
439
|
-
reload_if_empty: function(tbody, url) {
|
440
|
-
if (this.records_for(tbody).length == 0) {
|
441
|
-
this.reload(url);
|
442
|
-
}
|
443
|
-
},
|
444
|
-
reload: function(url) {
|
445
|
-
new Ajax.Request(url, {
|
446
|
-
method: 'get',
|
447
|
-
asynchronous: true,
|
448
|
-
evalScripts: true
|
449
|
-
});
|
450
|
-
},
|
451
|
-
removeSortClasses: function(scaffold) {
|
452
|
-
scaffold = $(scaffold)
|
453
|
-
scaffold.select('td.sorted').each(function(element) {
|
454
|
-
element.removeClassName("sorted");
|
455
|
-
});
|
456
|
-
scaffold.select('th.sorted').each(function(element) {
|
457
|
-
element.removeClassName("sorted");
|
458
|
-
element.removeClassName("asc");
|
459
|
-
element.removeClassName("desc");
|
460
|
-
});
|
461
|
-
},
|
462
|
-
decrement_record_count: function(scaffold) {
|
463
|
-
// decrement the last record count, firsts record count are in nested lists
|
464
|
-
scaffold = $(scaffold)
|
465
|
-
count = scaffold.select('span.active-scaffold-records').last();
|
466
|
-
if (count) count.update(parseInt(count.innerHTML, 10) - 1);
|
467
|
-
},
|
468
|
-
increment_record_count: function(scaffold) {
|
469
|
-
// increment the last record count, firsts record count are in nested lists
|
470
|
-
scaffold = $(scaffold)
|
471
|
-
count = scaffold.select('span.active-scaffold-records').last();
|
472
|
-
if (count) count.update(parseInt(count.innerHTML, 10) + 1);
|
473
|
-
},
|
474
|
-
update_row: function(row, html) {
|
475
|
-
row = $(row);
|
476
|
-
var new_row = this.replace(row, html)
|
477
|
-
if (new_row) {
|
478
|
-
if (row.hasClassName('even-record')) new_row.addClassName('even-record');
|
479
|
-
ActiveScaffold.highlight(new_row);
|
480
|
-
}
|
481
|
-
},
|
482
|
-
|
483
|
-
replace: function(element, html) {
|
484
|
-
element = $(element)
|
485
|
-
if (element) {
|
486
|
-
Element.replace(element, html);
|
487
|
-
element = $(element.readAttribute('id'));
|
488
|
-
}
|
489
|
-
return element;
|
490
|
-
},
|
491
|
-
|
492
|
-
replace_html: function(element, html) {
|
493
|
-
element = $(element);
|
494
|
-
if (element) element.update(html);
|
495
|
-
return element;
|
496
|
-
},
|
497
|
-
|
498
|
-
remove: function(element, callback) {
|
499
|
-
$(element).remove();
|
500
|
-
if (callback) callback();
|
501
|
-
},
|
502
|
-
|
503
|
-
update_inplace_edit: function(element, value, empty) {
|
504
|
-
this.replace_html(element, value);
|
505
|
-
if (empty) $(element).up('td').addClassName('empty');
|
506
|
-
},
|
507
|
-
|
508
|
-
hide: function(element) {
|
509
|
-
$(element).hide();
|
510
|
-
},
|
511
|
-
|
512
|
-
show: function(element) {
|
513
|
-
$(element).show();
|
514
|
-
},
|
515
|
-
|
516
|
-
reset_form: function(element) {
|
517
|
-
$(element).reset();
|
518
|
-
},
|
519
|
-
|
520
|
-
disable_form: function(as_form) {
|
521
|
-
as_form = $(as_form)
|
522
|
-
var loading_indicator = $(as_form.readAttribute('id').sub('-form', '-loading-indicator'));
|
523
|
-
if (loading_indicator) loading_indicator.style.visibility = 'visible';
|
524
|
-
as_form.disable();
|
525
|
-
},
|
526
|
-
|
527
|
-
enable_form: function(as_form) {
|
528
|
-
as_form = $(as_form)
|
529
|
-
var loading_indicator = $(as_form.readAttribute('id').sub('-form', '-loading-indicator'));
|
530
|
-
if (loading_indicator) loading_indicator.style.visibility = 'hidden';
|
531
|
-
as_form.enable();
|
532
|
-
},
|
533
|
-
|
534
|
-
focus_first_element_of_form: function(form_element) {
|
535
|
-
Form.focusFirstElement(form_element);
|
536
|
-
},
|
537
|
-
|
538
|
-
create_record_row: function(active_scaffold_id, html, options) {
|
539
|
-
tbody = $(active_scaffold_id).down('tbody.records');
|
540
|
-
|
541
|
-
var new_row = null;
|
542
|
-
|
543
|
-
if (options.insert_at == 'top') {
|
544
|
-
tbody.insert({top: html});
|
545
|
-
new_row = tbody.firstDescendant();
|
546
|
-
} else if (options.insert_at == 'bottom') {
|
547
|
-
var last_row = tbody.childElements().reverse().detect(function(node) { return node.hasClassName('record') || node.hasClassName('inline-adapter')});
|
548
|
-
if (last_row) {
|
549
|
-
last_row.insert({after: html});
|
550
|
-
} else {
|
551
|
-
tbody.insert({bottom: html});
|
552
|
-
}
|
553
|
-
new_row = Selector.findChildElements(tbody, ['tr.record']).last();
|
554
|
-
} else if (typeof options.insert_at == 'object') {
|
555
|
-
var insert_method, get_method, row, id;
|
556
|
-
if (options.insert_at.after) {
|
557
|
-
insert_method = 'after';
|
558
|
-
get_method = 'next';
|
559
|
-
} else {
|
560
|
-
insert_method = 'before';
|
561
|
-
get_method = 'previous';
|
562
|
-
}
|
563
|
-
if (id = options.insert_at[insert_method]) row = $(id);
|
564
|
-
if (row) {
|
565
|
-
row.insert({insert_method: html});
|
566
|
-
new_row = row[get_method]();
|
567
|
-
}
|
568
|
-
}
|
569
|
-
|
570
|
-
this.stripe(tbody);
|
571
|
-
this.hide_empty_message(tbody);
|
572
|
-
this.increment_record_count(tbody.up('div.active-scaffold'));
|
573
|
-
ActiveScaffold.highlight(new_row);
|
574
|
-
},
|
575
|
-
|
576
|
-
create_record_row_from_url: function(action_link, url, options) {
|
577
|
-
new Ajax.Request(url, {
|
578
|
-
method: 'get',
|
579
|
-
onComplete: function(response) {
|
580
|
-
ActiveScaffold.create_record_row(action_link.scaffold(), row, options);
|
581
|
-
action_link.close();
|
582
|
-
}
|
583
|
-
});
|
584
|
-
},
|
585
|
-
|
586
|
-
delete_record_row: function(row, page_reload_url) {
|
587
|
-
row = $(row);
|
588
|
-
var tbody = row.up('tbody.records');
|
589
|
-
|
590
|
-
var current_action_node = row.down('td.actions a.disabled');
|
591
|
-
|
592
|
-
if (current_action_node) {
|
593
|
-
var action_link = ActiveScaffold.ActionLink.get(current_action_node);
|
594
|
-
if (action_link) {
|
595
|
-
action_link.close_previous_adapter();
|
596
|
-
}
|
597
|
-
}
|
598
|
-
ActiveScaffold.remove(row, function() {
|
599
|
-
tbody = $(tbody);
|
600
|
-
ActiveScaffold.stripe(tbody);
|
601
|
-
ActiveScaffold.decrement_record_count(tbody.up('div.active-scaffold'));
|
602
|
-
ActiveScaffold.reload_if_empty(tbody, page_reload_url);
|
603
|
-
});
|
604
|
-
},
|
605
|
-
|
606
|
-
delete_subform_record: function(record) {
|
607
|
-
var errors = $(record).previous();
|
608
|
-
if (errors.hasClassName('association-record-errors')) {
|
609
|
-
this.remove(errors);
|
610
|
-
}
|
611
|
-
var associated = $(record).next();
|
612
|
-
this.remove(record);
|
613
|
-
while (associated && associated.hasClassName('associated-record')) {
|
614
|
-
record = associated;
|
615
|
-
associated = $(record).next();
|
616
|
-
this.remove(record);
|
617
|
-
}
|
618
|
-
},
|
619
|
-
|
620
|
-
report_500_response: function(active_scaffold_id) {
|
621
|
-
var server_error = $(active_scaffold_id).down('td.messages-container p.server-error');
|
622
|
-
if (server_error.visible()) {
|
623
|
-
ActiveScaffold.highlight(server_error);
|
624
|
-
} else {
|
625
|
-
server_error.show();
|
626
|
-
}
|
627
|
-
},
|
628
|
-
|
629
|
-
find_action_link: function(element) {
|
630
|
-
element = $(element);
|
631
|
-
return ActiveScaffold.ActionLink.get(element.match('.actions a') ? element : element.up('.as_adapter'));
|
632
|
-
},
|
633
|
-
|
634
|
-
display_dynamic_action_group: function(link, html) {
|
635
|
-
var container;
|
636
|
-
link = $(link);
|
637
|
-
if (link.up('td.actions')) {
|
638
|
-
container = link.up('td').addClassName('action_group dyn');
|
639
|
-
} else {
|
640
|
-
if (link.up().hasClassName('actions')) link.wrap('div');
|
641
|
-
container = link.up().addClassName('action_group dyn');
|
642
|
-
}
|
643
|
-
container.down('> ul').remove();
|
644
|
-
container.insert({bottom: html});
|
645
|
-
},
|
646
|
-
|
647
|
-
scroll_to: function(element, checkInViewport) {
|
648
|
-
if (typeof checkInViewport == 'undefined') checkInViewport = true;
|
649
|
-
var form_offset = $(element).viewportOffset().top;
|
650
|
-
if (checkInViewport) {
|
651
|
-
var docViewTop = document.viewport.getScrollOffsets().top,
|
652
|
-
docViewBottom = docViewTop + document.viewport.getHeight();
|
653
|
-
// If it's in viewport , don't scroll;
|
654
|
-
if (form_offset + $(element).getHeight() <= docViewBottom && form_offset >= docViewTop) return;
|
655
|
-
}
|
656
|
-
$(element).scrollTo();
|
657
|
-
},
|
658
|
-
|
659
|
-
process_checkbox_inplace_edit: function(checkbox, options) {
|
660
|
-
var checked = checkbox.readAttribute('checked');
|
661
|
-
// checked attribute is nt updated
|
662
|
-
if (checked !== 'checked') options['params'] += '&value=1';
|
663
|
-
new Ajax.Request(options.url, {
|
664
|
-
method: 'post',
|
665
|
-
parameters: options['params'],
|
666
|
-
onCreate: function(response) {
|
667
|
-
checkbox.disable();
|
668
|
-
},
|
669
|
-
onComplete: function(response) {
|
670
|
-
checkbox.enable();
|
671
|
-
}
|
672
|
-
});
|
673
|
-
},
|
674
|
-
|
675
|
-
read_inplace_edit_heading_attributes: function(column_heading, options) {
|
676
|
-
if (column_heading.readAttribute('data-ie-cancel-text')) options.cancelText = column_heading.readAttribute('data-ie-cancel-text');
|
677
|
-
if (column_heading.readAttribute('data-ie-loading-text')) options.loadingText = column_heading.readAttribute('data-ie-loading-text');
|
678
|
-
if (column_heading.readAttribute('data-ie-saving-text')) options.savingText = column_heading.readAttribute('data-ie-saving-text');
|
679
|
-
if (column_heading.readAttribute('data-ie-save-text')) options.okText = column_heading.readAttribute('data-ie-save-text');
|
680
|
-
if (column_heading.readAttribute('data-ie-rows')) options.rows = column-heading.readAttribute('data-ie-rows');
|
681
|
-
if (column_heading.readAttribute('data-ie-cols')) options.cols = column-heading.readAttribute('data-ie-cols');
|
682
|
-
if (column_heading.readAttribute('data-ie-size')) options.size = column-heading.readAttribute('data-ie-size');
|
683
|
-
},
|
684
|
-
|
685
|
-
create_inplace_editor: function(span, options) {
|
686
|
-
if (options['params'].length > 0) {
|
687
|
-
options['callback'] = new Function('form', 'return Form.serialize(form) + ' + "'&" + options['params'] + "';");
|
688
|
-
}
|
689
|
-
span.removeClassName('hover');
|
690
|
-
span.inplace_edit = new ActiveScaffold.InPlaceEditor(span.readAttribute('id'), options.url, options)
|
691
|
-
span.inplace_edit.enterEditMode();
|
692
|
-
},
|
693
|
-
|
694
|
-
create_associated_record_form: function(element, content, options) {
|
695
|
-
var element = $(element);
|
696
|
-
if (options.singular == false) {
|
697
|
-
if (!(options.id && $(options.id))) {
|
698
|
-
element.insert(content);
|
699
|
-
}
|
700
|
-
} else {
|
701
|
-
var current = $$('#' + element.readAttribute('id') + ' .association-record');
|
702
|
-
if (current[0]) {
|
703
|
-
this.replace(current[0], content);
|
704
|
-
} else {
|
705
|
-
element.insert({top: content});
|
706
|
-
}
|
707
|
-
}
|
708
|
-
},
|
709
|
-
|
710
|
-
render_form_field: function(source, content, options) {
|
711
|
-
var source = $(source);
|
712
|
-
var element = source.up('.association-record'), selector = '';
|
713
|
-
if (typeof(element) === 'undefined') {
|
714
|
-
element = source.up('ol.form');
|
715
|
-
selector = 'li';
|
716
|
-
}
|
717
|
-
// find without entering new subforms
|
718
|
-
selector = options.is_subform ? '' : selector + ':not(.sub-form) ';
|
719
|
-
element = element.down(selector + '.' + options.field_class);
|
720
|
-
|
721
|
-
if (element) {
|
722
|
-
if (options.is_subform == false) {
|
723
|
-
this.replace(element.up('dl'), content);
|
724
|
-
} else {
|
725
|
-
this.replace_html(element, content);
|
726
|
-
}
|
727
|
-
}
|
728
|
-
},
|
729
|
-
|
730
|
-
record_select_onselect: function(edit_associated_url, active_scaffold_id, id){
|
731
|
-
new Ajax.Request(
|
732
|
-
edit_associated_url.sub('--ID--', id), {
|
733
|
-
asynchronous: true,
|
734
|
-
evalScripts: true,
|
735
|
-
onFailure: function(){
|
736
|
-
ActiveScaffold.report_500_response(active_scaffold_id.to_json)
|
737
|
-
}
|
738
|
-
}
|
739
|
-
);
|
740
|
-
},
|
741
|
-
|
742
|
-
// element is tbody id
|
743
|
-
mark_records: function(element, options) {
|
744
|
-
var element = $(element);
|
745
|
-
if (options.include_checkboxes) {
|
746
|
-
var mark_checkboxes = $$('#' + element.readAttribute('id') + ' > tr.record td.marked-column input[type="checkbox"]');
|
747
|
-
mark_checkboxes.each(function(item) {
|
748
|
-
if(options.checked) {
|
749
|
-
item.writeAttribute({ checked: 'checked' });
|
750
|
-
} else {
|
751
|
-
item.removeAttribute('checked');
|
752
|
-
}
|
753
|
-
item.writeAttribute('value', ('' + !options.checked));
|
754
|
-
});
|
755
|
-
}
|
756
|
-
if(options.include_mark_all) {
|
757
|
-
var mark_all_checkbox = element.previous('thead').down('th.marked-column_heading span input[type="checkbox"]');
|
758
|
-
if(options.checked) {
|
759
|
-
mark_all_checkbox.writeAttribute({ checked: 'checked' });
|
760
|
-
} else {
|
761
|
-
mark_all_checkbox.removeAttribute('checked');
|
762
|
-
}
|
763
|
-
mark_all_checkbox.writeAttribute('value', ('' + !options.checked));
|
764
|
-
}
|
765
|
-
},
|
766
|
-
|
767
|
-
update_column: function(element, url, send_form, source_id, val, additional_params) {
|
768
|
-
if (!element) element = $(source_id);
|
769
|
-
|
770
|
-
var as_form = element.up('form.as_form');
|
771
|
-
var params = null;
|
772
|
-
|
773
|
-
if (send_form) {
|
774
|
-
var selector, base = as_form;
|
775
|
-
if (send_form == 'row') base = element.up('.association-record, form');
|
776
|
-
if (selector = element.readAttribute('data-update_send_form_selector'))
|
777
|
-
params = Form.serializeElements(base.getElementsBySelector(selector), true);
|
778
|
-
else if (base != as_form)
|
779
|
-
params = Form.serializeElements(base.getElementsBySelector('input, textarea, select'), true);
|
780
|
-
else params = as_form.serialize(true);
|
781
|
-
params['_method'] = '';
|
782
|
-
if (additional_params) params = Object.extend(params, additional_params);
|
783
|
-
} else {
|
784
|
-
params = {value: val};
|
785
|
-
}
|
786
|
-
params.source_id = source_id;
|
787
|
-
|
788
|
-
new Ajax.Request(url, {
|
789
|
-
method: 'post',
|
790
|
-
parameters: params,
|
791
|
-
onLoading: function(response) {
|
792
|
-
element.next('img.loading-indicator').style.visibility = 'visible';
|
793
|
-
as_form.disable();
|
794
|
-
},
|
795
|
-
onComplete: function(response) {
|
796
|
-
element.next('img.loading-indicator').style.visibility = 'hidden';
|
797
|
-
as_form.enable();
|
798
|
-
},
|
799
|
-
onFailure: function(request) {
|
800
|
-
var as_div = event.findElement('div.active-scaffold');
|
801
|
-
if (as_div) {
|
802
|
-
ActiveScaffold.report_500_response(as_div)
|
803
|
-
}
|
804
|
-
}
|
805
|
-
});
|
806
|
-
},
|
807
|
-
|
808
|
-
draggable_lists: function(selector_or_elements, parent) {
|
809
|
-
var elements;
|
810
|
-
if (typeof(selector_or_elements) == 'string') elements = $(parent).select(selector_or_elements);
|
811
|
-
else elements = $A($(selector_or_elements));
|
812
|
-
elements.each(function(item) {
|
813
|
-
new DraggableLists(item);
|
814
|
-
});
|
815
|
-
},
|
816
|
-
|
817
|
-
highlight: function(element) {
|
818
|
-
element = $(element);
|
819
|
-
if (typeof(element.highlight) == 'function') {
|
820
|
-
element.highlight(Object.extend({duration: 3}, ActiveScaffold.config.highlight));
|
821
|
-
}
|
822
|
-
}
|
823
|
-
}
|
824
|
-
|
825
|
-
/*
|
826
|
-
* DHTML history tie-in
|
827
|
-
*/
|
828
|
-
function addActiveScaffoldPageToHistory(url, active_scaffold_id) {
|
829
|
-
if (typeof dhtmlHistory == 'undefined') return; // it may not be loaded
|
830
|
-
|
831
|
-
var array = url.split('?');
|
832
|
-
var qs = new Querystring(array[1]);
|
833
|
-
var sort = qs.get('sort')
|
834
|
-
var dir = qs.get('sort_direction')
|
835
|
-
var page = qs.get('page')
|
836
|
-
if (sort || dir || page) dhtmlHistory.add(active_scaffold_id+":"+page+":"+sort+":"+dir, url);
|
837
|
-
}
|
838
|
-
|
839
|
-
/*
|
840
|
-
* Add-ons/Patches to Prototype
|
841
|
-
*/
|
842
|
-
|
843
|
-
/* patch to support replacing TR/TD/TBODY in Internet Explorer, courtesy of http://dev.rubyonrails.org/ticket/4273 */
|
844
|
-
Element.replace = function(element, html) {
|
845
|
-
element = $(element);
|
846
|
-
if (element.outerHTML) {
|
847
|
-
try {
|
848
|
-
element.outerHTML = html.stripScripts();
|
849
|
-
} catch (e) {
|
850
|
-
var tn = element.tagName;
|
851
|
-
if(tn=='TBODY' || tn=='TR' || tn=='TD')
|
852
|
-
{
|
853
|
-
var tempDiv = document.createElement("div");
|
854
|
-
tempDiv.innerHTML = '<table id="tempTable" style="display: none">' + html.stripScripts() + '</table>';
|
855
|
-
element.parentNode.replaceChild(tempDiv.getElementsByTagName(tn).item(0), element);
|
856
|
-
}
|
857
|
-
else throw e;
|
858
|
-
}
|
859
|
-
} else {
|
860
|
-
var range = element.ownerDocument.createRange();
|
861
|
-
/* patch to fix <form> replaces in Firefox. see http://dev.rubyonrails.org/ticket/8010 */
|
862
|
-
range.selectNodeContents(element.parentNode);
|
863
|
-
element.parentNode.replaceChild(range.createContextualFragment(html.stripScripts()), element);
|
864
|
-
}
|
865
|
-
setTimeout(function() {html.evalScripts()}, 10);
|
866
|
-
return element;
|
867
|
-
};
|
868
|
-
|
869
|
-
/*
|
870
|
-
* URL modification support. Incomplete functionality.
|
871
|
-
*/
|
872
|
-
Object.extend(String.prototype, {
|
873
|
-
append_params: function(params) {
|
874
|
-
url = this;
|
875
|
-
if (url.indexOf('?') == -1) url += '?';
|
876
|
-
else if (url.lastIndexOf('&') != url.length) url += '&';
|
877
|
-
|
878
|
-
url += $H(params).collect(function(item) {
|
879
|
-
return item.key + '=' + item.value;
|
880
|
-
}).join('&');
|
881
|
-
|
882
|
-
return url;
|
883
|
-
}
|
884
|
-
});
|
885
|
-
|
886
|
-
/*
|
887
|
-
* Prototype's implementation was throwing an error instead of false
|
888
|
-
*/
|
889
|
-
Element.Methods.Simulated = {
|
890
|
-
hasAttribute: function(element, attribute) {
|
891
|
-
var t = Element._attributeTranslations;
|
892
|
-
attribute = (t.names && t.names[attribute]) || attribute;
|
893
|
-
// Return false if we get an error here
|
894
|
-
try {
|
895
|
-
return $(element).getAttributeNode(attribute).specified;
|
896
|
-
} catch (e) {
|
897
|
-
return false;
|
898
|
-
}
|
899
|
-
}
|
900
|
-
};
|
901
|
-
|
902
|
-
/**
|
903
|
-
* A set of links. As a set, they can be controlled such that only one is "open" at a time, etc.
|
904
|
-
*/
|
905
|
-
ActiveScaffold.Actions = new Object();
|
906
|
-
ActiveScaffold.Actions.Abstract = Class.create({
|
907
|
-
initialize: function(links, target, loading_indicator, options) {
|
908
|
-
this.target = $(target);
|
909
|
-
this.loading_indicator = $(loading_indicator);
|
910
|
-
this.options = options;
|
911
|
-
this.links = links.collect(function(link) {
|
912
|
-
return this.instantiate_link(link);
|
913
|
-
}.bind(this));
|
914
|
-
},
|
915
|
-
|
916
|
-
instantiate_link: function(link) {
|
917
|
-
throw 'unimplemented'
|
918
|
-
}
|
919
|
-
});
|
920
|
-
|
921
|
-
/**
|
922
|
-
* A DataStructures::ActionLink, represented in JavaScript.
|
923
|
-
* Concerned with AJAX-enabling a link and adapting the result for insertion into the table.
|
924
|
-
*/
|
925
|
-
ActiveScaffold.ActionLink = {
|
926
|
-
get: function(element) {
|
927
|
-
var element = $(element);
|
928
|
-
if (typeof(element.retrieve('action_link')) === 'undefined' && !element.hasClassName('as_adapter')) {
|
929
|
-
var parent = element.up('.actions');
|
930
|
-
if (typeof(parent) === 'undefined') {
|
931
|
-
// maybe an column action_link
|
932
|
-
parent = element.up();
|
933
|
-
}
|
934
|
-
if (parent && parent.nodeName.toUpperCase() == 'TD') {
|
935
|
-
// record action
|
936
|
-
parent = parent.up('tr.record')
|
937
|
-
var loading_indicator = parent.down('td.actions .loading-indicator');
|
938
|
-
if (!loading_indicator) loading_indicator = element.parent().find('.loading-indicator');
|
939
|
-
new ActiveScaffold.Actions.Record(parent.select('a.as_action'), parent, loading_indicator);
|
940
|
-
} else if (parent && parent.nodeName.toUpperCase() == 'DIV') {
|
941
|
-
//table action
|
942
|
-
new ActiveScaffold.Actions.Table(parent.select('a.as_action'), parent.up('div.active-scaffold').down('tbody.before-header'), parent.down('.loading-indicator'));
|
943
|
-
}
|
944
|
-
element = $(element);
|
945
|
-
}
|
946
|
-
return element.retrieve('action_link');
|
947
|
-
}
|
948
|
-
};
|
949
|
-
|
950
|
-
ActiveScaffold.ActionLink.Abstract = Class.create({
|
951
|
-
initialize: function(a, target, loading_indicator) {
|
952
|
-
this.tag = $(a);
|
953
|
-
this.url = this.tag.href;
|
954
|
-
this.method = this.tag.readAttribute('data-method') || 'get';
|
955
|
-
this.target = target;
|
956
|
-
this.loading_indicator = loading_indicator;
|
957
|
-
this.hide_target = false;
|
958
|
-
this.position = this.tag.readAttribute('data-position');
|
959
|
-
|
960
|
-
this.tag.store('action_link', this);
|
961
|
-
},
|
962
|
-
|
963
|
-
open: function(event) {
|
964
|
-
this.tag.click();
|
965
|
-
},
|
966
|
-
|
967
|
-
insert: function(content) {
|
968
|
-
throw 'unimplemented'
|
969
|
-
},
|
970
|
-
|
971
|
-
close: function() {
|
972
|
-
var link = this;
|
973
|
-
ActiveScaffold.remove(this.adapter, function() {
|
974
|
-
link.enable();
|
975
|
-
if (link.hide_target) link.target.show();
|
976
|
-
if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(link.target.id, ActiveScaffold.config.scroll_on_close == 'checkInViewport');
|
977
|
-
});
|
978
|
-
},
|
979
|
-
|
980
|
-
reload: function() {
|
981
|
-
this.close();
|
982
|
-
this.open();
|
983
|
-
},
|
984
|
-
|
985
|
-
get_new_adapter_id: function() {
|
986
|
-
var id = 'adapter_';
|
987
|
-
var i = 0;
|
988
|
-
while ($(id + i)) i++;
|
989
|
-
return id + i;
|
990
|
-
},
|
991
|
-
|
992
|
-
enable: function() {
|
993
|
-
return this.tag.removeClassName('disabled');
|
994
|
-
},
|
995
|
-
|
996
|
-
disable: function() {
|
997
|
-
return this.tag.addClassName('disabled');
|
998
|
-
},
|
999
|
-
|
1000
|
-
is_disabled: function() {
|
1001
|
-
return this.tag.hasClassName('disabled');
|
1002
|
-
},
|
1003
|
-
|
1004
|
-
scaffold_id: function() {
|
1005
|
-
return this.tag.up('div.active-scaffold').readAttribute('id');
|
1006
|
-
},
|
1007
|
-
|
1008
|
-
scaffold: function() {
|
1009
|
-
return this.tag.up('div.active-scaffold');
|
1010
|
-
},
|
1011
|
-
|
1012
|
-
update_flash_messages: function(messages) {
|
1013
|
-
message_node = $(this.scaffold_id().sub('-active-scaffold', '-messages'));
|
1014
|
-
if (message_node) message_node.update(messages);
|
1015
|
-
},
|
1016
|
-
|
1017
|
-
set_adapter: function(element) {
|
1018
|
-
this.adapter = element;
|
1019
|
-
this.adapter.addClassName('as_adapter');
|
1020
|
-
this.adapter.store('action_link', this);
|
1021
|
-
},
|
1022
|
-
|
1023
|
-
keep_open: function() {
|
1024
|
-
return !this.tag.readAttribute('data-keep-open').blank();
|
1025
|
-
}
|
1026
|
-
});
|
1027
|
-
|
1028
|
-
/**
|
1029
|
-
* Concrete classes for record actions
|
1030
|
-
*/
|
1031
|
-
ActiveScaffold.Actions.Record = Class.create(ActiveScaffold.Actions.Abstract, {
|
1032
|
-
instantiate_link: function(link) {
|
1033
|
-
var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator);
|
1034
|
-
if (this.target.hasAttribute('data-refresh') && !this.target.readAttribute('data-refresh').blank()) l.refresh_url = this.target.up('.records').readAttribute('data-refresh-record').replace('--ID--', this.target.readAttribute('data-refresh'));
|
1035
|
-
|
1036
|
-
if (l.position) {
|
1037
|
-
l.url = l.url.append_params({adapter: '_list_inline_adapter'});
|
1038
|
-
l.tag.href = l.url;
|
1039
|
-
}
|
1040
|
-
l.set = this;
|
1041
|
-
return l;
|
1042
|
-
}
|
1043
|
-
});
|
1044
|
-
|
1045
|
-
ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstract, {
|
1046
|
-
close_previous_adapter: function() {
|
1047
|
-
this.set.links.each(function(item) {
|
1048
|
-
if (item.url != this.url && item.is_disabled() && !item.keep_open() && item.adapter) {
|
1049
|
-
ActiveScaffold.remove(item.adapter, function () { item.enable(); });
|
1050
|
-
}
|
1051
|
-
}.bind(this));
|
1052
|
-
},
|
1053
|
-
|
1054
|
-
insert: function(content) {
|
1055
|
-
this.close_previous_adapter();
|
1056
|
-
|
1057
|
-
if (this.position == 'replace') {
|
1058
|
-
this.position = 'after';
|
1059
|
-
this.hide_target = true;
|
1060
|
-
}
|
1061
|
-
|
1062
|
-
var colspan = this.target.childElements().length;
|
1063
|
-
if (this.position == 'after') {
|
1064
|
-
this.target.insert({after:content});
|
1065
|
-
this.set_adapter(this.target.next());
|
1066
|
-
}
|
1067
|
-
else if (this.position == 'before') {
|
1068
|
-
this.target.insert({before:content});
|
1069
|
-
this.set_adapter(this.target.previous());
|
1070
|
-
}
|
1071
|
-
else {
|
1072
|
-
return false;
|
1073
|
-
}
|
1074
|
-
this.adapter.down('.inline-adapter-cell').writeAttribute('colspan', colspan);
|
1075
|
-
ActiveScaffold.focus_first_element_of_form(this.adapter);
|
1076
|
-
ActiveScaffold.highlight(this.adapter.down('td').down());
|
1077
|
-
},
|
1078
|
-
|
1079
|
-
close: function($super, refreshed_content_or_reload) {
|
1080
|
-
$super();
|
1081
|
-
if (refreshed_content_or_reload) {
|
1082
|
-
if (typeof refreshed_content_or_reload == 'string') {
|
1083
|
-
ActiveScaffold.update_row(this.target, refreshed_content_or_reload);
|
1084
|
-
} else if (this.refresh_url) {
|
1085
|
-
var target = this.target;
|
1086
|
-
new Ajax.Request(this.refresh_url, {
|
1087
|
-
method: 'get',
|
1088
|
-
onComplete: function(response) {
|
1089
|
-
ActiveScaffold.update_row(target, response.responseText);
|
1090
|
-
}
|
1091
|
-
});
|
1092
|
-
}
|
1093
|
-
}
|
1094
|
-
},
|
1095
|
-
|
1096
|
-
enable: function() {
|
1097
|
-
this.set.links.each(function(item) {
|
1098
|
-
if (item.url != this.url) return;
|
1099
|
-
item.tag.removeClassName('disabled');
|
1100
|
-
}.bind(this));
|
1101
|
-
},
|
1102
|
-
|
1103
|
-
disable: function() {
|
1104
|
-
this.set.links.each(function(item) {
|
1105
|
-
if (item.url != this.url) return;
|
1106
|
-
item.tag.addClassName('disabled');
|
1107
|
-
}.bind(this));
|
1108
|
-
},
|
1109
|
-
|
1110
|
-
set_opened: function() {
|
1111
|
-
if (this.position == 'after') {
|
1112
|
-
this.set_adapter(this.target.next());
|
1113
|
-
}
|
1114
|
-
else if (this.position == 'before') {
|
1115
|
-
this.set_adapter(this.target.previous());
|
1116
|
-
}
|
1117
|
-
this.disable();
|
1118
|
-
}
|
1119
|
-
});
|
1120
|
-
|
1121
|
-
/**
|
1122
|
-
* Concrete classes for table actions
|
1123
|
-
*/
|
1124
|
-
ActiveScaffold.Actions.Table = Class.create(ActiveScaffold.Actions.Abstract, {
|
1125
|
-
instantiate_link: function(link) {
|
1126
|
-
var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator);
|
1127
|
-
if (l.position) {
|
1128
|
-
l.url = l.url.append_params({adapter: '_list_inline_adapter'});
|
1129
|
-
l.tag.href = l.url;
|
1130
|
-
}
|
1131
|
-
return l;
|
1132
|
-
}
|
1133
|
-
});
|
1134
|
-
|
1135
|
-
ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstract, {
|
1136
|
-
insert: function(content) {
|
1137
|
-
if (this.position == 'top') {
|
1138
|
-
this.target.insert({top:content});
|
1139
|
-
this.set_adapter(this.target.immediateDescendants().first());
|
1140
|
-
}
|
1141
|
-
else {
|
1142
|
-
throw 'Unknown position "' + this.position + '"'
|
1143
|
-
}
|
1144
|
-
ActiveScaffold.focus_first_element_of_form(this.adapter);
|
1145
|
-
ActiveScaffold.highlight(this.adapter.down('td').down());
|
1146
|
-
}
|
1147
|
-
});
|
1148
|
-
|
1149
|
-
if (Ajax.InPlaceEditor) {
|
1150
|
-
ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, {
|
1151
|
-
initialize: function($super, element, url, options) {
|
1152
|
-
$super(element, url, options);
|
1153
|
-
if (this._originalBackground == 'transparent') {
|
1154
|
-
this._originalBackground = null;
|
1155
|
-
}
|
1156
|
-
},
|
1157
|
-
|
1158
|
-
setFieldFromAjax: function(url, options) {
|
1159
|
-
var ipe = this;
|
1160
|
-
$(ipe._controls.editor).remove();
|
1161
|
-
new Ajax.Request(url, {
|
1162
|
-
method: 'get',
|
1163
|
-
onComplete: function(response) {
|
1164
|
-
ipe._form.insert({top: response.responseText});
|
1165
|
-
if (options.plural) {
|
1166
|
-
ipe._form.getElements().each(function(el) {
|
1167
|
-
if (el.type != "submit" && el.type != "image") {
|
1168
|
-
el.name = ipe.options.paramName + '[]';
|
1169
|
-
el.className = 'editor_field';
|
1170
|
-
}
|
1171
|
-
});
|
1172
|
-
} else {
|
1173
|
-
var fld = ipe._form.findFirstElement();
|
1174
|
-
fld.name = ipe.options.paramName;
|
1175
|
-
fld.className = 'editor_field';
|
1176
|
-
if (ipe.options.submitOnBlur)
|
1177
|
-
fld.onblur = ipe._boundSubmitHandler;
|
1178
|
-
ipe._controls.editor = fld;
|
1179
|
-
}
|
1180
|
-
}
|
1181
|
-
});
|
1182
|
-
},
|
1183
|
-
|
1184
|
-
clonePatternField: function() {
|
1185
|
-
var patternNodes = this.getPatternNodes(this.options.inplacePatternSelector);
|
1186
|
-
if (patternNodes.editNode == null) {
|
1187
|
-
alert('did not find any matching node for ' + this.options.editFieldSelector);
|
1188
|
-
return;
|
1189
|
-
}
|
1190
|
-
|
1191
|
-
var fld = $(patternNodes.editNode.cloneNode(true));
|
1192
|
-
if (fld.readAttribute("data-id").length > 0) fld.id = fld.readAttribute("data-id") + this.options.nodeIdSuffix;
|
1193
|
-
fld.name = this.options.paramName;
|
1194
|
-
fld.className = 'editor_field';
|
1195
|
-
this.setValue(fld, this._controls.editor.value);
|
1196
|
-
if (this.options.submitOnBlur)
|
1197
|
-
fld.onblur = this._boundSubmitHandler;
|
1198
|
-
$(this._controls.editor).remove();
|
1199
|
-
this._controls.editor = fld;
|
1200
|
-
this._form.appendChild(this._controls.editor);
|
1201
|
-
|
1202
|
-
$A(patternNodes.additionalNodes).each(function(node) {
|
1203
|
-
var patternNode = $(node.cloneNode(true));
|
1204
|
-
if (patternNode.id.length > 0) {
|
1205
|
-
patternNode.id = patternNode.readAttribute("data-id") + this.options.nodeIdSuffix;
|
1206
|
-
}
|
1207
|
-
this._form.appendChild(patternNode);
|
1208
|
-
}.bind(this));
|
1209
|
-
},
|
1210
|
-
|
1211
|
-
getPatternNodes: function(inplacePatternSelector) {
|
1212
|
-
var nodes = {editNode: null, additionalNodes: []};
|
1213
|
-
var selectedNodes = $$(inplacePatternSelector);
|
1214
|
-
var firstNode = selectedNodes.first();
|
1215
|
-
|
1216
|
-
if (typeof(firstNode) !== 'undefined') {
|
1217
|
-
// AS inplace_edit_control_container -> we have to select all child nodes
|
1218
|
-
// Workaround for ie which does not support css > selector
|
1219
|
-
if (firstNode.className.indexOf('as_inplace_pattern') !== -1) {
|
1220
|
-
selectedNodes = firstNode.childElements();
|
1221
|
-
}
|
1222
|
-
nodes.editNode = selectedNodes.first();
|
1223
|
-
selectedNodes.shift();
|
1224
|
-
nodes.additionalNodes = selectedNodes;
|
1225
|
-
}
|
1226
|
-
return nodes;
|
1227
|
-
},
|
1228
|
-
|
1229
|
-
setValue: function(editField, textValue) {
|
1230
|
-
var function_name = 'setValueFor' + editField.nodeName.toLowerCase();
|
1231
|
-
if (typeof(this[function_name]) == 'function') {
|
1232
|
-
this[function_name](editField, textValue);
|
1233
|
-
} else {
|
1234
|
-
editField.value = textValue;
|
1235
|
-
}
|
1236
|
-
},
|
1237
|
-
|
1238
|
-
setValueForselect: function(editField, textValue) {
|
1239
|
-
var len = editField.options.length;
|
1240
|
-
var i = 0;
|
1241
|
-
while (i < len && editField.options[i].text != textValue) {
|
1242
|
-
i++;
|
1243
|
-
}
|
1244
|
-
if (i < len) {
|
1245
|
-
editField.value = editField.options[i].value
|
1246
|
-
}
|
1247
|
-
}
|
1248
|
-
});
|
1249
|
-
}
|