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,180 @@
|
|
1
|
+
module ActiveScaffold::Actions
|
2
|
+
module Core
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval do
|
5
|
+
after_filter :clear_flashes
|
6
|
+
end
|
7
|
+
base.helper_method :nested?
|
8
|
+
base.helper_method :beginning_of_chain
|
9
|
+
base.helper_method :new_model
|
10
|
+
end
|
11
|
+
def render_field
|
12
|
+
if params[:in_place_editing]
|
13
|
+
render_field_for_inplace_editing
|
14
|
+
else
|
15
|
+
render_field_for_update_columns
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def nested?
|
22
|
+
false
|
23
|
+
end
|
24
|
+
|
25
|
+
def render_field_for_inplace_editing
|
26
|
+
register_constraints_with_action_columns(nested.constrained_fields, active_scaffold_config.update.hide_nested_column ? [] : [:update]) if nested?
|
27
|
+
@record = find_if_allowed(params[:id], :update)
|
28
|
+
render :inline => "<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %>"
|
29
|
+
end
|
30
|
+
|
31
|
+
def render_field_for_update_columns
|
32
|
+
@record = new_model
|
33
|
+
column = active_scaffold_config.columns[params[:column]]
|
34
|
+
unless column.nil?
|
35
|
+
value = column_value_from_param_value(@record, column, params[:value])
|
36
|
+
@record.send "#{column.name}=", value
|
37
|
+
after_render_field(@record, column)
|
38
|
+
source_id = params.delete(:source_id)
|
39
|
+
render :partial => "render_field", :collection => Array(params[:update_columns]), :content_type => 'text/javascript', :locals => {:source_id => source_id}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# override this method if you want to do something after render_field
|
44
|
+
def after_render_field(record, column); end
|
45
|
+
|
46
|
+
def authorized_for?(options = {})
|
47
|
+
active_scaffold_config.model.authorized_for?(options)
|
48
|
+
end
|
49
|
+
|
50
|
+
def clear_flashes
|
51
|
+
if request.xhr?
|
52
|
+
flash.keys.each do |flash_key|
|
53
|
+
flash[flash_key] = nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def default_formats
|
59
|
+
[:html, :js, :json, :xml, :yaml]
|
60
|
+
end
|
61
|
+
# Returns true if the client accepts one of the MIME types passed to it
|
62
|
+
# ex: accepts? :html, :xml
|
63
|
+
def accepts?(*types)
|
64
|
+
for priority in request.accepts.compact
|
65
|
+
if priority == Mime::ALL
|
66
|
+
# Because IE always sends */* in the accepts header and we assume
|
67
|
+
# that if you really wanted XML or something else you would say so
|
68
|
+
# explicitly, we will assume */* to only ask for :html
|
69
|
+
return types.include?(:html)
|
70
|
+
elsif types.include?(priority.to_sym)
|
71
|
+
return true
|
72
|
+
end
|
73
|
+
end
|
74
|
+
false
|
75
|
+
end
|
76
|
+
|
77
|
+
def response_status
|
78
|
+
if successful?
|
79
|
+
action_name == 'create' ? 201 : 200
|
80
|
+
else
|
81
|
+
422
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# API response object that will be converted to XML/YAML/JSON using to_xxx
|
86
|
+
def response_object
|
87
|
+
@response_object = successful? ? (@record || @records) : @record.errors
|
88
|
+
end
|
89
|
+
|
90
|
+
# Success is the existence of certain variables and the absence of errors (when applicable).
|
91
|
+
# Success can also be defined.
|
92
|
+
def successful?
|
93
|
+
if @successful.nil?
|
94
|
+
@records or (@record and @record.errors.count == 0 and @record.no_errors_in_associated?)
|
95
|
+
else
|
96
|
+
@successful
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def successful=(val)
|
101
|
+
@successful = (val) ? true : false
|
102
|
+
end
|
103
|
+
|
104
|
+
# Redirect to the main page (override if the ActiveScaffold is used as a component on another controllers page) for Javascript degradation
|
105
|
+
def return_to_main
|
106
|
+
redirect_to main_path_to_return
|
107
|
+
end
|
108
|
+
|
109
|
+
# Override this method on your controller to define conditions to be used when querying a recordset (e.g. for List). The return of this method should be any format compatible with the :conditions clause of ActiveRecord::Base's find.
|
110
|
+
def conditions_for_collection
|
111
|
+
end
|
112
|
+
|
113
|
+
# Override this method on your controller to define joins to be used when querying a recordset (e.g. for List). The return of this method should be any format compatible with the :joins clause of ActiveRecord::Base's find.
|
114
|
+
def joins_for_collection
|
115
|
+
end
|
116
|
+
|
117
|
+
# Override this method on your controller to provide custom finder options to the find() call. The return of this method should be a hash.
|
118
|
+
def custom_finder_options
|
119
|
+
{}
|
120
|
+
end
|
121
|
+
|
122
|
+
#Overide this method on your controller to provide model with named scopes
|
123
|
+
def beginning_of_chain
|
124
|
+
active_scaffold_config.model
|
125
|
+
end
|
126
|
+
|
127
|
+
# Builds search conditions by search params for column names. This allows urls like "contacts/list?company_id=5".
|
128
|
+
def conditions_from_params
|
129
|
+
conditions = nil
|
130
|
+
params.reject {|key, value| [:controller, :action, :id, :page, :sort, :sort_direction].include?(key.to_sym)}.each do |key, value|
|
131
|
+
next unless active_scaffold_config.model.column_names.include?(key)
|
132
|
+
if value.is_a?(Array)
|
133
|
+
conditions = merge_conditions(conditions, ["#{active_scaffold_config.model.table_name}.#{key.to_s} in (?)", value])
|
134
|
+
else
|
135
|
+
conditions = merge_conditions(conditions, ["#{active_scaffold_config.model.table_name}.#{key.to_s} = ?", value])
|
136
|
+
end
|
137
|
+
end
|
138
|
+
conditions
|
139
|
+
end
|
140
|
+
|
141
|
+
def new_model
|
142
|
+
model = beginning_of_chain
|
143
|
+
if model.columns_hash[model.inheritance_column]
|
144
|
+
build_options = {model.inheritance_column.to_sym => active_scaffold_config.model_id} if nested? && nested.association && nested.association.collection?
|
145
|
+
params = self.params # in new action inheritance_column must be in params
|
146
|
+
params = params[:record] || {} unless params[model.inheritance_column] # in create action must be inside record key
|
147
|
+
model = params.delete(model.inheritance_column).camelize.constantize if params[model.inheritance_column]
|
148
|
+
end
|
149
|
+
model.respond_to?(:build) ? model.build(build_options || {}) : model.new
|
150
|
+
end
|
151
|
+
|
152
|
+
private
|
153
|
+
def respond_to_action(action)
|
154
|
+
respond_to do |type|
|
155
|
+
action_formats.each do |format|
|
156
|
+
type.send(format){ send("#{action}_respond_to_#{format}") }
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def action_formats
|
162
|
+
@action_formats ||= if respond_to? "#{action_name}_formats"
|
163
|
+
send("#{action_name}_formats")
|
164
|
+
else
|
165
|
+
(default_formats + active_scaffold_config.formats).uniq
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def response_code_for_rescue(exception)
|
170
|
+
case exception
|
171
|
+
when ActiveScaffold::RecordNotAllowed
|
172
|
+
"403 Record Not Allowed"
|
173
|
+
when ActiveScaffold::ActionNotAllowed
|
174
|
+
"403 Action Not Allowed"
|
175
|
+
else
|
176
|
+
super
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
module ActiveScaffold::Actions
|
2
|
+
module Create
|
3
|
+
def self.included(base)
|
4
|
+
base.before_filter :create_authorized_filter, :only => [:new, :create]
|
5
|
+
base.verify :method => :post,
|
6
|
+
:only => :create,
|
7
|
+
:redirect_to => { :action => :index }
|
8
|
+
end
|
9
|
+
|
10
|
+
def new
|
11
|
+
do_new
|
12
|
+
respond_to_action(:new)
|
13
|
+
end
|
14
|
+
|
15
|
+
def create
|
16
|
+
do_create
|
17
|
+
respond_to_action(:create)
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
def response_location
|
22
|
+
url_for(params_for(:action => "show", :id => @record.id)) if successful?
|
23
|
+
end
|
24
|
+
|
25
|
+
def new_respond_to_html
|
26
|
+
if successful?
|
27
|
+
render(:action => 'create')
|
28
|
+
else
|
29
|
+
return_to_main
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def new_respond_to_js
|
34
|
+
render(:partial => 'create_form')
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_respond_to_html
|
38
|
+
if params[:iframe]=='true' # was this an iframe post ?
|
39
|
+
responds_to_parent do
|
40
|
+
render :action => 'on_create.js', :layout => false
|
41
|
+
end
|
42
|
+
else
|
43
|
+
if successful?
|
44
|
+
flash[:info] = as_(:created_model, :model => @record.to_label)
|
45
|
+
if active_scaffold_config.create.edit_after_create
|
46
|
+
redirect_to params_for(:action => "edit", :id => @record.id)
|
47
|
+
elsif active_scaffold_config.create.persistent
|
48
|
+
redirect_to params_for(:action => "new")
|
49
|
+
else
|
50
|
+
return_to_main
|
51
|
+
end
|
52
|
+
else
|
53
|
+
if !nested? && active_scaffold_config.actions.include?(:list) && active_scaffold_config.list.always_show_create
|
54
|
+
do_list
|
55
|
+
render(:action => 'list')
|
56
|
+
else
|
57
|
+
render(:action => 'create')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_respond_to_js
|
64
|
+
if successful? && active_scaffold_config.create.refresh_list && !render_parent?
|
65
|
+
do_search if respond_to? :do_search
|
66
|
+
do_list
|
67
|
+
end
|
68
|
+
render :action => 'on_create'
|
69
|
+
end
|
70
|
+
|
71
|
+
def create_respond_to_xml
|
72
|
+
render :xml => response_object.to_xml(:only => active_scaffold_config.create.columns.names), :content_type => Mime::XML, :status => response_status, :location => response_location
|
73
|
+
end
|
74
|
+
|
75
|
+
def create_respond_to_json
|
76
|
+
render :text => response_object.to_json(:only => active_scaffold_config.create.columns.names), :content_type => Mime::JSON, :status => response_status, :location => response_location
|
77
|
+
end
|
78
|
+
|
79
|
+
def create_respond_to_yaml
|
80
|
+
render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.create.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status, :location => response_location
|
81
|
+
end
|
82
|
+
|
83
|
+
# A simple method to find and prepare an example new record for the form
|
84
|
+
# May be overridden to customize the behavior (add default values, for instance)
|
85
|
+
def do_new
|
86
|
+
@record = new_model
|
87
|
+
apply_constraints_to_record(@record)
|
88
|
+
if nested?
|
89
|
+
create_association_with_parent(@record)
|
90
|
+
register_constraints_with_action_columns(nested.constrained_fields)
|
91
|
+
end
|
92
|
+
@record
|
93
|
+
end
|
94
|
+
|
95
|
+
# A somewhat complex method to actually create a new record. The complexity is from support for subforms and associated records.
|
96
|
+
# If you want to customize this behavior, consider using the +before_create_save+ and +after_create_save+ callbacks.
|
97
|
+
def do_create
|
98
|
+
begin
|
99
|
+
active_scaffold_config.model.transaction do
|
100
|
+
@record = update_record_from_params(new_model, active_scaffold_config.create.columns, params[:record])
|
101
|
+
apply_constraints_to_record(@record, :allow_autosave => true)
|
102
|
+
if nested?
|
103
|
+
create_association_with_parent(@record)
|
104
|
+
register_constraints_with_action_columns(nested.constrained_fields)
|
105
|
+
end
|
106
|
+
create_save
|
107
|
+
end
|
108
|
+
rescue ActiveRecord::RecordInvalid
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def create_save
|
113
|
+
before_create_save(@record)
|
114
|
+
self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit
|
115
|
+
if successful?
|
116
|
+
@record.save! and @record.save_associated!
|
117
|
+
after_create_save(@record)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# override this method if you want to inject data in the record (or its associated objects) before the save
|
122
|
+
def before_create_save(record); end
|
123
|
+
|
124
|
+
# override this method if you want to do something after the save
|
125
|
+
def after_create_save(record); end
|
126
|
+
|
127
|
+
# The default security delegates to ActiveRecordPermissions.
|
128
|
+
# You may override the method to customize.
|
129
|
+
|
130
|
+
def create_ignore?
|
131
|
+
nested? && active_scaffold_config.list.always_show_create
|
132
|
+
end
|
133
|
+
|
134
|
+
def create_authorized?
|
135
|
+
(!nested? || !nested.readonly?) && authorized_for?(:crud_type => :create)
|
136
|
+
end
|
137
|
+
private
|
138
|
+
def create_authorized_filter
|
139
|
+
link = active_scaffold_config.create.link || active_scaffold_config.create.class.link
|
140
|
+
raise ActiveScaffold::ActionNotAllowed unless self.send(link.security_method)
|
141
|
+
end
|
142
|
+
def new_formats
|
143
|
+
(default_formats + active_scaffold_config.formats).uniq
|
144
|
+
end
|
145
|
+
def create_formats
|
146
|
+
(default_formats + active_scaffold_config.formats + active_scaffold_config.create.formats).uniq
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module ActiveScaffold::Actions
|
2
|
+
module Delete
|
3
|
+
def self.included(base)
|
4
|
+
base.before_filter :delete_authorized_filter, :only => [:destroy]
|
5
|
+
end
|
6
|
+
|
7
|
+
def destroy
|
8
|
+
params.delete :destroy_action
|
9
|
+
process_action_link_action(:destroy) do |record|
|
10
|
+
do_destroy
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
def destroy_respond_to_html
|
16
|
+
if self.successful?
|
17
|
+
flash[:info] = as_(:deleted_model, :model => @record.to_label)
|
18
|
+
else
|
19
|
+
#error_message_for not available in controller...
|
20
|
+
#flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br)
|
21
|
+
end
|
22
|
+
return_to_main
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy_respond_to_js
|
26
|
+
if successful? && active_scaffold_config.delete.refresh_list && !render_parent?
|
27
|
+
do_search if respond_to? :do_search
|
28
|
+
do_list
|
29
|
+
end
|
30
|
+
render(:action => 'destroy')
|
31
|
+
end
|
32
|
+
|
33
|
+
def destroy_respond_to_xml
|
34
|
+
render :xml => successful? ? "" : response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy_respond_to_json
|
38
|
+
render :text => successful? ? "" : response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status
|
39
|
+
end
|
40
|
+
|
41
|
+
def destroy_respond_to_yaml
|
42
|
+
render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status
|
43
|
+
end
|
44
|
+
|
45
|
+
def destroy_find_record
|
46
|
+
@record = find_if_allowed(params[:id], :delete)
|
47
|
+
end
|
48
|
+
|
49
|
+
# A simple method to handle the actual destroying of a record
|
50
|
+
# May be overridden to customize the behavior
|
51
|
+
def do_destroy
|
52
|
+
@record ||= destroy_find_record
|
53
|
+
begin
|
54
|
+
self.successful = @record.destroy
|
55
|
+
rescue
|
56
|
+
flash[:warning] = as_(:cant_destroy_record, :record => @record.to_label)
|
57
|
+
self.successful = false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# The default security delegates to ActiveRecordPermissions.
|
62
|
+
# You may override the method to customize.
|
63
|
+
def delete_authorized?(record = nil)
|
64
|
+
(!nested? || !nested.readonly?) && authorized_for?(:crud_type => :delete)
|
65
|
+
end
|
66
|
+
private
|
67
|
+
def delete_authorized_filter
|
68
|
+
link = active_scaffold_config.delete.link || active_scaffold_config.delete.class.link
|
69
|
+
raise ActiveScaffold::ActionNotAllowed unless self.send(link.security_method)
|
70
|
+
end
|
71
|
+
def destroy_formats
|
72
|
+
(default_formats + active_scaffold_config.formats + active_scaffold_config.delete.formats).uniq
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module ActiveScaffold::Actions
|
2
|
+
module FieldSearch
|
3
|
+
include ActiveScaffold::Actions::CommonSearch
|
4
|
+
def self.included(base)
|
5
|
+
base.before_filter :search_authorized_filter, :only => :show_search
|
6
|
+
base.before_filter :store_search_params_into_session, :only => [:index]
|
7
|
+
base.before_filter :do_search, :only => [:index]
|
8
|
+
base.helper_method :field_search_params
|
9
|
+
end
|
10
|
+
|
11
|
+
# FieldSearch uses params[:search] and not @record because search conditions do not always pass the Model's validations.
|
12
|
+
# This facilitates for example, textual searches against associations via .search_sql
|
13
|
+
def show_search
|
14
|
+
@record = new_model
|
15
|
+
respond_to_action(:field_search)
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def store_search_params_into_session
|
21
|
+
set_field_search_default_params(active_scaffold_config.field_search.default_params) unless active_scaffold_config.field_search.default_params.nil?
|
22
|
+
super
|
23
|
+
active_scaffold_session_storage[:search] = nil if search_params.is_a?(String)
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_field_search_default_params(default_params)
|
27
|
+
if (params[:search].nil? && search_params.nil?) || (params[:search].is_a?(String) && params[:search].blank?)
|
28
|
+
params[:search] = default_params.is_a?(Proc) ? self.instance_eval(&default_params) : default_params
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def field_search_params
|
33
|
+
search_params || {}
|
34
|
+
end
|
35
|
+
|
36
|
+
def field_search_respond_to_html
|
37
|
+
render(:action => "field_search")
|
38
|
+
end
|
39
|
+
|
40
|
+
def field_search_respond_to_js
|
41
|
+
render(:partial => "field_search")
|
42
|
+
end
|
43
|
+
|
44
|
+
def do_search
|
45
|
+
unless search_params.nil?
|
46
|
+
text_search = active_scaffold_config.field_search.text_search
|
47
|
+
search_conditions = []
|
48
|
+
human_condition_columns = [] if active_scaffold_config.field_search.human_conditions
|
49
|
+
columns = active_scaffold_config.field_search.columns
|
50
|
+
search_params.each do |key, value|
|
51
|
+
next unless columns.include? key
|
52
|
+
search_condition = self.class.condition_for_column(active_scaffold_config.columns[key], value, text_search)
|
53
|
+
unless search_condition.blank?
|
54
|
+
search_conditions << search_condition
|
55
|
+
human_condition_columns << active_scaffold_config.columns[key] unless human_condition_columns.nil?
|
56
|
+
end
|
57
|
+
end
|
58
|
+
self.active_scaffold_conditions = merge_conditions(self.active_scaffold_conditions, *search_conditions)
|
59
|
+
if search_conditions.blank?
|
60
|
+
@filtered = false
|
61
|
+
else
|
62
|
+
@filtered = human_condition_columns.nil? ? true : human_condition_columns
|
63
|
+
end
|
64
|
+
|
65
|
+
includes_for_search_columns = columns.collect{ |column| column.includes}.flatten.uniq.compact
|
66
|
+
self.active_scaffold_includes.concat includes_for_search_columns
|
67
|
+
|
68
|
+
active_scaffold_config.list.user.page = nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def search_authorized_filter
|
75
|
+
link = active_scaffold_config.field_search.link || active_scaffold_config.field_search.class.link
|
76
|
+
raise ActiveScaffold::ActionNotAllowed unless self.send(link.security_method)
|
77
|
+
end
|
78
|
+
def field_search_formats
|
79
|
+
(default_formats + active_scaffold_config.formats + active_scaffold_config.field_search.formats).uniq
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|