active_scaffold 3.1.20 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/app/assets/javascripts/jquery/active_scaffold.js +4 -1
  2. data/app/assets/javascripts/prototype/active_scaffold.js +4 -1
  3. data/app/assets/stylesheets/{active_scaffold.scss~ → active_scaffold.css.scss} +5 -2
  4. data/app/assets/stylesheets/{active_scaffold_colors.scss → active_scaffold_colors.css.scss} +4 -0
  5. data/app/assets/stylesheets/active_scaffold_extensions.css.erb +2 -0
  6. data/app/assets/stylesheets/active_scaffold_images.css.scss +43 -0
  7. data/lib/active_scaffold/actions/core.rb +1 -0
  8. data/lib/active_scaffold/actions/nested.rb +0 -1
  9. data/lib/active_scaffold/extensions/action_view_rendering.rb +1 -1
  10. data/lib/active_scaffold/helpers/form_column_helpers.rb +1 -0
  11. data/lib/active_scaffold/version.rb +2 -2
  12. data/test/mock_app/.gitignore +2 -0
  13. metadata +86 -164
  14. data/app/assets/javascripts/active_scaffold.js.erb~ +0 -16
  15. data/app/assets/javascripts/jquery/active_scaffold.js~ +0 -1053
  16. data/app/assets/javascripts/jquery/draggable_lists.js~ +0 -27
  17. data/app/assets/javascripts/prototype/active_scaffold.js~ +0 -1037
  18. data/app/assets/stylesheets/active_scaffold.css.erb +0 -11
  19. data/app/assets/stylesheets/active_scaffold.css.erb~ +0 -11
  20. data/app/assets/stylesheets/active_scaffold.css.scss.erb~ +0 -1120
  21. data/app/assets/stylesheets/active_scaffold.css.scss~ +0 -11
  22. data/app/assets/stylesheets/active_scaffold.css~ +0 -11
  23. data/app/assets/stylesheets/active_scaffold_colors.css +0 -244
  24. data/app/assets/stylesheets/active_scaffold_colors.css.scss~ +0 -481
  25. data/app/assets/stylesheets/active_scaffold_default.css.erb +0 -47
  26. data/app/assets/stylesheets/active_scaffold_default.css.erb~ +0 -57
  27. data/app/assets/stylesheets/active_scaffold_default.css.scss~ +0 -1092
  28. data/app/assets/stylesheets/active_scaffold_default.css~ +0 -923
  29. data/app/assets/stylesheets/active_scaffold_layout.css~ +0 -922
  30. data/app/assets/stylesheets/blue-theme.css~ +0 -1150
  31. data/config/locales/es.yml~ +0 -120
  32. data/frontends/default/views/_action_group.html.erb~ +0 -24
  33. data/frontends/default/views/_base_form.html.erb~ +0 -42
  34. data/frontends/default/views/_form.html.erb~ +0 -26
  35. data/frontends/default/views/_form_association.html.erb~ +0 -19
  36. data/frontends/default/views/_form_association_footer.html.erb~ +0 -48
  37. data/frontends/default/views/_horizontal_subform.html.erb~ +0 -32
  38. data/frontends/default/views/_horizontal_subform_header.html.erb~ +0 -11
  39. data/frontends/default/views/_horizontal_subform_record.html.erb~ +0 -38
  40. data/frontends/default/views/_list_actions.html.erb~ +0 -15
  41. data/frontends/default/views/_list_inline_adapter.html.erb~ +0 -10
  42. data/frontends/default/views/_list_messages.html.erb~ +0 -30
  43. data/frontends/default/views/_list_pagination.html.erb~ +0 -11
  44. data/frontends/default/views/_list_pagination_links.html.erb~ +0 -0
  45. data/frontends/default/views/_list_with_header.html.erb~ +0 -36
  46. data/frontends/default/views/_render_field.js.erb~ +0 -23
  47. data/frontends/default/views/_row.html.erb~ +0 -6
  48. data/frontends/default/views/_show.html.erb~ +0 -8
  49. data/frontends/default/views/_update_form.html.erb~ +0 -6
  50. data/frontends/default/views/_vertical_subform.html.erb~ +0 -12
  51. data/frontends/default/views/add_existing.js.erb~ +0 -18
  52. data/frontends/default/views/add_existing_form.html.erb~ +0 -5
  53. data/frontends/default/views/create.html.erb~ +0 -5
  54. data/frontends/default/views/edit_associated.js.erb~ +0 -13
  55. data/frontends/default/views/on_create.js.erb~ +0 -45
  56. data/frontends/default/views/on_update.js.erb~ +0 -31
  57. data/frontends/default/views/render_field.js.erb~ +0 -1
  58. data/frontends/default/views/search.html.erb~ +0 -5
  59. data/frontends/default/views/show.html.erb~ +0 -5
  60. data/frontends/default/views/update.html.erb~ +0 -8
  61. data/frontends/default/views/update_column.js.erb~ +0 -16
  62. data/lib/active_scaffold.rb~ +0 -373
  63. data/lib/active_scaffold/actions/core.rb~ +0 -203
  64. data/lib/active_scaffold/actions/create.rb~ +0 -148
  65. data/lib/active_scaffold/actions/list.rb~ +0 -196
  66. data/lib/active_scaffold/actions/nested.rb~ +0 -247
  67. data/lib/active_scaffold/actions/search.rb~ +0 -49
  68. data/lib/active_scaffold/actions/subform.rb~ +0 -27
  69. data/lib/active_scaffold/actions/update.rb~ +0 -150
  70. data/lib/active_scaffold/attribute_params.rb~ +0 -203
  71. data/lib/active_scaffold/bridges/date_picker/helper.rb~ +0 -180
  72. data/lib/active_scaffold/bridges/record_select/helpers.rb~ +0 -86
  73. data/lib/active_scaffold/bridges/shared/date_bridge.rb~ +0 -209
  74. data/lib/active_scaffold/config/base.rb~ +0 -72
  75. data/lib/active_scaffold/config/list.rb~ +0 -195
  76. data/lib/active_scaffold/config/nested.rb~ +0 -41
  77. data/lib/active_scaffold/config/search.rb~ +0 -74
  78. data/lib/active_scaffold/constraints.rb~ +0 -186
  79. data/lib/active_scaffold/data_structures/action_columns.rb~ +0 -140
  80. data/lib/active_scaffold/data_structures/action_link.rb~ +0 -179
  81. data/lib/active_scaffold/data_structures/nested_info.rb~ +0 -147
  82. data/lib/active_scaffold/extensions/action_controller_rendering.rb~ +0 -22
  83. data/lib/active_scaffold/extensions/action_view_rendering.rb~ +0 -120
  84. data/lib/active_scaffold/extensions/active_association_reflection.rb~ +0 -22
  85. data/lib/active_scaffold/extensions/cache_association.rb~ +0 -12
  86. data/lib/active_scaffold/extensions/reverse_associations.rb~ +0 -64
  87. data/lib/active_scaffold/extensions/routing_mapper.rb~ +0 -48
  88. data/lib/active_scaffold/extensions/unsaved_associated.rb~ +0 -62
  89. data/lib/active_scaffold/finder.rb~ +0 -370
  90. data/lib/active_scaffold/helpers/controller_helpers.rb~ +0 -92
  91. data/lib/active_scaffold/helpers/form_column_helpers.rb~ +0 -320
  92. data/lib/active_scaffold/helpers/id_helpers.rb~ +0 -123
  93. data/lib/active_scaffold/helpers/list_column_helpers.rb~ +0 -370
  94. data/lib/active_scaffold/helpers/search_column_helpers.rb~ +0 -263
  95. data/lib/active_scaffold/helpers/view_helpers.rb~ +0 -350
@@ -1,36 +0,0 @@
1
- <div id="<%= active_scaffold_id -%>" class="<%= as_main_div_class %>" <%= "data-eid=#{id_from_controller(params[:eid])}" if params[:eid]%>>
2
- <div class="active-scaffold-header">
3
- <%= render :partial => 'list_header' %>
4
- </div>
5
- <table cellpadding="0" cellspacing="0">
6
- <tbody class="before-header" id="<%= before_header_id -%>">
7
- <% if active_scaffold_config.list.always_show_search %>
8
- <% old_record, @record = @record, new_model %>
9
- <tr>
10
- <td>
11
- <div class="active-scaffold show_search-view <%= "#{scope_id params[:controller]}-view" %> view">
12
- <%= render :partial => active_scaffold_config.list.search_partial %>
13
- </div>
14
- </td>
15
- </tr>
16
- <% @record = old_record %>
17
- <% else %>
18
- <tr><td></td></tr>
19
- <% end %>
20
- <% if !nested? && active_scaffold_config.list.always_show_create %>
21
- <% old_record, @record = @record, new_model %>
22
- <tr>
23
- <td>
24
- <div class="active-scaffold create-view <%= "#{scope_id params[:controller]}-view" %> view">
25
- <%= render :partial => 'create_form_on_list' %>
26
- </div>
27
- </td>
28
- </tr>
29
- <% @record = old_record %>
30
- <% end %>
31
- </tbody>
32
- </table>
33
- <div id="<%= active_scaffold_content_id-%>" class="as_content">
34
- <%= render :partial => 'list' %>
35
- </div>
36
- </div>
@@ -1,23 +0,0 @@
1
- <%
2
- column = if render_field.is_a? ActiveScaffold::DataStructures::Column
3
- render_field
4
- else
5
- active_scaffold_config.columns[render_field.to_sym] unless render_field.is_a? ActiveScaffold::DataStructures::Column
6
- end
7
- @rendered ||= Set.new
8
- return if @rendered.include? column.name
9
- @rendered << column.name
10
- if column_renders_as(column) == :subform
11
- options = {:is_subform => true, :field_class => "#{column.name}-sub-form"}
12
- else
13
- options = {:is_subform => false, :field_class => "#{column.name}-input"}
14
- end
15
- -%>
16
-
17
- ActiveScaffold.render_form_field('<%= source_id %>','<%= escape_javascript(render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope })) %>', <%= options.to_json.html_safe %>);
18
- <%if column.update_columns && !column.update_columns.empty?%>
19
- <%= render(:partial => "render_field", :collection => column.update_columns, :locals => {:source_id => source_id, :scope => scope})%>
20
- <%end%>
21
-
22
-
23
-
@@ -1,6 +0,0 @@
1
- <%= render :partial => 'list_record', :locals => {:record => record}%>
2
- <%= javascript_tag do %>
3
- ActiveScaffold.replace('<%= active_scaffold_calculations_id %>', '<%= escape_javascript render(:partial => 'list_calculations') %>');
4
- <% end if active_scaffold_config.list.columns.any? {|c| c.calculation?} %>
5
-
6
-
@@ -1,8 +0,0 @@
1
- <h4><%= active_scaffold_config.show.label(@record.to_label.nil? ? nil : clean_column_value(@record.to_label)) %></h4>
2
-
3
- <%= render :partial => 'show_columns', :locals => {:columns => active_scaffold_config.show.columns} -%>
4
-
5
- <p class="form-footer">
6
- <%= link_to as_(:close), main_path_to_return, :class => 'as_cancel', :remote => request.xhr?, 'data-refresh' => false %>
7
- <%= loading_indicator_tag(:action => :create, :id => params[:id]) %>
8
- </p>
@@ -1,6 +0,0 @@
1
- <% cancel_link = true if cancel_link.nil? %>
2
- <%= render :partial => "base_form", :locals => {:xhr => xhr ||= nil,
3
- :form_action => form_action ||= :update,
4
- :method => method ||= :put,
5
- :cancel_link => cancel_link,
6
- :headline => headline ||= @record.to_label.nil? ? active_scaffold_config.update.label : as_(:update_model, :model => clean_column_value(@record.to_label))} %>
@@ -1,12 +0,0 @@
1
- <div id="<%= sub_form_list_id(:association => column.name) %>">
2
- <% associated.each_index do |index| %>
3
- <% @record = associated[index] -%>
4
- <% if @record.errors.count -%>
5
- <div class="association-record-errors" id="<%= element_messages_id :action => @record.class.name.underscore, :id => "#{parent_record.id}-#{index}" %>">
6
- <%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %>
7
- </div>
8
- <% end %>
9
- <%= render :partial => 'vertical_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %>
10
- <% end -%>
11
- </div>
12
- <%#= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated} -%>
@@ -1,18 +0,0 @@
1
- <% new_row = render :partial => 'list_record', :locals => {:record => @record} %>
2
- ActiveScaffold.create_record_row('<%= active_scaffold_id %>', '<%= escape_javascript(new_row) %>', <%= {:insert_at => :top}.to_json.html_safe %>);
3
-
4
- <% if active_scaffold_config.list.columns.any? {|c| c.calculation?} %>
5
- ActiveScaffold.replace('<%= active_scaffold_calculations_id %>', '<%= escape_javascript(render(:partial => 'list_calculations')) %>');
6
- <%end%>
7
-
8
- <% if form_stays_open ||= true %>
9
- <%# why not just re-render the form? that wouldn't utilize a possible do_new override which sets default values.%>
10
- ActiveScaffold.reset_form('<%= element_form_id %>');
11
- ActiveScaffold.replace_html('<%= element_messages_id(:action => :add_existing) %>', '<%= escape_javascript(render(:partial => 'form_messages')) %>');
12
- <%# have to delay the focus, because there's no "firstElement" in prototype until at least one element is not disabled%>
13
- <% if ActiveScaffold.js_framework == :prototype %>
14
- ActiveScaffold.focus_first_element_of_form.defer('<%= element_form_id %>');
15
- <% end %>
16
- <% else %>
17
- ActiveScaffold.find_action_link('<%element_form_id(:action => :new_existing)%>').close();
18
- <% end %>
@@ -1,5 +0,0 @@
1
- <div class="active-scaffold">
2
- <div class="create-view <%= "scope_id #{params[:controller]}-view" %> view">
3
- <%= render :partial => 'add_existing_form' -%>
4
- </div>
5
- </div>
@@ -1,5 +0,0 @@
1
- <div class="active-scaffold">
2
- <div class="create-view <%= "#{scope_id params[:controller]}-view" %> view">
3
- <%= render :partial => 'create_form' -%>
4
- </div>
5
- </div>
@@ -1,13 +0,0 @@
1
- <%
2
- associated_form = render :partial => "#{subform_partial_for_column(@column)}_record", :locals => {:scope => @scope, :parent_record => @parent_record, :column => @column, :locked => @record.new_record? && @column.singular_association?}
3
- options = {:singular => false}
4
- if @column.singular_association?
5
- options[:singular] = true
6
- else
7
- unless @record.new_record?
8
- column = active_scaffold_config_for(@record.class).columns[@record.class.primary_key]
9
- options[:id] = active_scaffold_input_options(column, @scope)[:id]
10
- end
11
- end %>
12
- alert("probando");
13
- ActiveScaffold.create_associated_record_form('<%=sub_form_list_id(:association => @column.name)%>','<%=escape_javascript(associated_form)%>', <%= options.to_json.html_safe %>);
@@ -1,45 +0,0 @@
1
- try {
2
- <% form_selector = "#{element_form_id(:action => :create)}"
3
- insert_at ||= :top %>
4
- var action_link = ActiveScaffold.find_action_link('<%= form_selector%>');
5
- action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'messages').strip)%>');
6
- <% if controller.send :successful? %>
7
- <% if render_parent? && controller.respond_to?(:render_component_into_view) %>
8
- <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %>
9
- <% if nested_singular_association? %>
10
- action_link.close('<%= escape_javascript(parent_rendered)%>');
11
- <% else %>
12
- <% if render_parent_action == :row %>
13
- ActiveScaffold.create_record_row(action_link.scaffold(),'<%= escape_javascript(parent_rendered)%>', <%= {:insert_at => insert_at}.to_json.html_safe %>);
14
- <% elsif render_parent_action == :index %>
15
- <%= escape_javascript(parent_rendered) %>
16
- <% end %>
17
- action_link.close();
18
- <% end %>
19
- <%#page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}%>
20
- <% elsif (active_scaffold_config.create.refresh_list) %>
21
- ActiveScaffold.replace_html(<%= active_scaffold_content_id%>, <%= escape_javascript(render(:partial => 'list', :layout => false)) %>);
22
- <% elsif params[:parent_controller].nil? %>
23
- <% new_row = render :partial => 'list_record', :locals => {:record => @record} %>
24
- ActiveScaffold.create_record_row(action_link.scaffold(),'<%=escape_javascript(new_row)%>', <%={:insert_at => insert_at}.to_json.html_safe%>);
25
- <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%>
26
- ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>');
27
- <% end %>
28
- <% end %>
29
-
30
- <% unless render_parent? %>
31
- <% if (active_scaffold_config.create.persistent) %>
32
- action_link.reload();
33
- <% else %>
34
- action_link.close();
35
- <% end %>
36
- <% if (active_scaffold_config.create.action_after_create) %>
37
- var link = $('<%=action_link_id active_scaffold_config.create.action_after_create, @record.id%>');
38
- if (link) (function() { link.action_link.open() }).defer();
39
- <% end %>
40
- <% end %>
41
- <% else %>
42
- ActiveScaffold.replace('<%=form_selector%>','<%=escape_javascript(render(:partial => 'create_form', :locals => {:xhr => true}))%>');
43
- ActiveScaffold.scroll_to('<%=form_selector%>');
44
- <% end %>
45
- } catch (e) { alert('RJS error:\n\n' + e.toString());}
@@ -1,31 +0,0 @@
1
- try {
2
- <% form_selector = "#{element_form_id(:action => :update)}" %>
3
- var action_link = ActiveScaffold.find_action_link('<%= form_selector%>');
4
- action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'messages').strip)%>');
5
- <% if controller.send :successful? %>
6
- <% if render_parent? && controller.respond_to?(:render_component_into_view) %>
7
- <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %>
8
- <% if nested_singular_association? %>
9
- action_link.close('<%= escape_javascript(parent_rendered)%>');
10
- <% else %>
11
- <% if render_parent_action == :row %>
12
- action_link.close('<%= escape_javascript(parent_rendered)%>');
13
- <% elsif render_parent_action == :index %>
14
- <%= escape_javascript(parent_rendered) %>
15
- <% end %>
16
- <% end %>
17
- <%#page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}%>
18
- <% elsif update_refresh_list? %>
19
- ActiveScaffold.replace_html('<%= active_scaffold_content_id%>', '<%= escape_javascript(render(:partial => 'list', :layout => false))%>');
20
- <% else %>
21
- <% updated_row = render :partial => 'list_record', :locals => {:record => @record}%>
22
- action_link.close('<%= escape_javascript(updated_row)%>');
23
- <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%>
24
- ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>');
25
- <% end %>
26
- <% end %>
27
- <% else %>
28
- ActiveScaffold.replace('<%=form_selector%>','<%=escape_javascript(render(:partial => 'update_form', :locals => {:xhr => true}))%>');
29
- ActiveScaffold.scroll_to('<%=form_selector%>');
30
- <% end %>
31
- } catch (e) { alert('RJS error:\n\n' + e.toString());}
@@ -1 +0,0 @@
1
- <%= render :partial => "render_field", :collection => columns, :locals => {:source_id => source_id, :scope => scope} %>
@@ -1,5 +0,0 @@
1
- <div class="active-scaffold">
2
- <div class="search-view <%= "#{scope_id params[:controller]}-view" %> view">
3
- <%= render :partial => 'search' -%>
4
- </div>
5
- </div>
@@ -1,5 +0,0 @@
1
- <div class="active-scaffold">
2
- <div class="show-view <%= "#{scope_id params[:controller]}-view" %> view">
3
- <%= render :partial => 'show' -%>
4
- </div>
5
- </div>
@@ -1,8 +0,0 @@
1
- <div class="active-scaffold">
2
- <div class="update-view <%= "#{scope_id params[:controller]}-view" %> view">
3
- <% if active_scaffold_config.update.nested_links and active_scaffold_config.action_links.member.empty? -%>
4
- <%= render :partial => 'update_actions', :locals => {:record => @record, :url_options => params_for(:action => :list, :id => @record.id)} %>
5
- <% end -%>
6
- <%= render :partial => 'update_form' -%>
7
- </div>
8
- </div>
@@ -1,16 +0,0 @@
1
- <% @column_span_id ||= element_cell_id(:id => @record.id.to_s, :action => 'update_column', :name => params[:column]) %>
2
- <% unless controller.send :successful?%>
3
- alert('<%= escape_javascript(@record.errors.full_messages.join("\n"))%>');
4
- <% @record.reload%>
5
- <% end%>
6
- <% column = active_scaffold_config.columns[params[:column]]%>
7
- <% if column.inplace_edit%>
8
- ActiveScaffold.replace_html('<%=@column_span_id%>','<%=escape_javascript(format_inplace_edit_column(@record, column))%>');
9
- <% else%>
10
- <% formatted_value = get_column_value(@record, column)%>
11
- ActiveScaffold.replace_html('<%=@column_span_id%>','<%=escape_javascript(formatted_value)%>');
12
- <% end%>
13
- <% if column.calculation?%>
14
- ActiveScaffold.replace_html('<%=active_scaffold_calculations_id(column)%>', '<%=escape_javascript(render_column_calculation(column))%>');
15
- <% end%>
16
-
@@ -1,373 +0,0 @@
1
- unless Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR >= 1
2
- raise "This version of ActiveScaffold requires Rails 3.1 or higher. Please use an earlier version."
3
- end
4
-
5
- begin
6
- require 'render_component'
7
- rescue LoadError
8
- end
9
-
10
- require 'active_scaffold/active_record_permissions'
11
- require 'active_scaffold/paginator'
12
- require 'active_scaffold/responds_to_parent'
13
-
14
- require 'active_scaffold/version'
15
- require 'active_scaffold/engine' unless defined? ACTIVE_SCAFFOLD_PLUGIN
16
- require 'json' # for js_config
17
-
18
- module ActiveScaffold
19
- autoload :AttributeParams, 'active_scaffold/attribute_params'
20
- autoload :Configurable, 'active_scaffold/configurable'
21
- autoload :Constraints, 'active_scaffold/constraints'
22
- autoload :Finder, 'active_scaffold/finder'
23
- autoload :MarkedModel, 'active_scaffold/marked_model'
24
- autoload :Bridges, 'active_scaffold/bridges'
25
-
26
- mattr_accessor :stylesheets
27
- self.stylesheets = []
28
- mattr_accessor :javascripts
29
- self.javascripts = []
30
-
31
- def self.autoload_subdir(dir, mod=self, root = File.dirname(__FILE__))
32
- Dir["#{root}/active_scaffold/#{dir}/*.rb"].each { |file|
33
- basename = File.basename(file, ".rb")
34
- mod.module_eval {
35
- autoload basename.camelcase.to_sym, "active_scaffold/#{dir}/#{basename}"
36
- }
37
- }
38
- end
39
-
40
- module Actions
41
- ActiveScaffold.autoload_subdir('actions', self)
42
- end
43
-
44
- module Config
45
- ActiveScaffold.autoload_subdir('config', self)
46
- end
47
-
48
- module DataStructures
49
- ActiveScaffold.autoload_subdir('data_structures', self)
50
- end
51
-
52
- module Helpers
53
- ActiveScaffold.autoload_subdir('helpers', self)
54
- end
55
-
56
- class ControllerNotFound < RuntimeError; end
57
- class DependencyFailure < RuntimeError; end
58
- class MalformedConstraint < RuntimeError; end
59
- class RecordNotAllowed < SecurityError; end
60
- class ActionNotAllowed < SecurityError; end
61
- class ReverseAssociationRequired < RuntimeError; end
62
-
63
- def self.included(base)
64
- base.extend(ClassMethods)
65
- base.module_eval do
66
- # TODO: these should be in actions/core
67
- before_filter :handle_user_settings
68
- before_filter :check_input_device
69
- end
70
-
71
- base.helper_method :touch_device?
72
- base.helper_method :hover_via_click?
73
- end
74
-
75
- def self.set_defaults(&block)
76
- ActiveScaffold::Config::Core.configure &block
77
- end
78
-
79
- def active_scaffold_config
80
- self.class.active_scaffold_config
81
- end
82
-
83
- def active_scaffold_config_for(klass)
84
- self.class.active_scaffold_config_for(klass)
85
- end
86
-
87
- def active_scaffold_session_storage(id = nil)
88
- debugger
89
- id ||= params[:eid] || "#{params[:controller]}#{"_#{nested.parent_id}" if nested?}"
90
- session_index = "as:#{id}"
91
- session[session_index] ||= {}
92
- session[session_index]
93
- end
94
-
95
- # at some point we need to pass the session and params into config. we'll just take care of that before any particular action occurs by passing those hashes off to the UserSettings class of each action.
96
- def handle_user_settings
97
- if self.class.uses_active_scaffold?
98
- active_scaffold_config.actions.each do |action_name|
99
- conf_instance = active_scaffold_config.send(action_name) rescue next
100
- next if conf_instance.class::UserSettings == ActiveScaffold::Config::Base::UserSettings # if it hasn't been extended, skip it
101
- active_scaffold_session_storage[action_name] ||= {}
102
- conf_instance.user = conf_instance.class::UserSettings.new(conf_instance, active_scaffold_session_storage[action_name], params)
103
- end
104
- end
105
- end
106
-
107
- def check_input_device
108
- if request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(iPhone|iPod|iPad)/i]
109
- session[:input_device_type] = 'TOUCH'
110
- session[:hover_supported] = false
111
- else
112
- session[:input_device_type] = 'MOUSE'
113
- session[:hover_supported] = true
114
- end if session[:input_device_type].nil?
115
- end
116
-
117
- def touch_device?
118
- session[:input_device_type] == 'TOUCH'
119
- end
120
-
121
- def hover_via_click?
122
- session[:hover_supported] == false
123
- end
124
-
125
- def self.js_framework=(framework)
126
- @@js_framework = framework
127
- end
128
-
129
- def self.js_framework
130
- @@js_framework ||= if defined? Jquery
131
- :jquery
132
- elsif defined? PrototypeRails
133
- :prototype
134
- end
135
- end
136
-
137
- def self.js_config=(config)
138
- @@js_config = config
139
- end
140
-
141
- def self.js_config
142
- @@js_config ||= {:scroll_on_close => true}
143
- end
144
-
145
- # exclude bridges you do not need
146
- # name of bridge subdir should be used to exclude it
147
- # eg
148
- # ActiveScaffold.exclude_bridges = [:cancan, :ancestry]
149
- # if you are using Activescaffold as a gem add to initializer
150
- # if you are using Activescaffold as a plugin add to active_scaffold_env.rb
151
- def self.exclude_bridges=(bridges)
152
- @@exclude_bridges = bridges
153
- end
154
-
155
- def self.exclude_bridges
156
- @@exclude_bridges ||= []
157
- end
158
-
159
- def self.root
160
- File.dirname(__FILE__) + "/.."
161
- end
162
-
163
- module ClassMethods
164
- def active_scaffold(model_id = nil, &block)
165
- # initialize bridges here
166
- ActiveScaffold::Bridges.run_all
167
-
168
- # converts Foo::BarController to 'bar' and FooBarsController to 'foo_bar' and AddressController to 'address'
169
- model_id = self.to_s.split('::').last.sub(/Controller$/, '').pluralize.singularize.underscore unless model_id
170
-
171
- # run the configuration
172
- @active_scaffold_config = ActiveScaffold::Config::Core.new(model_id)
173
- @active_scaffold_config_block = block
174
- self.links_for_associations
175
-
176
- @active_scaffold_frontends = []
177
- if active_scaffold_config.frontend.to_sym != :default
178
- active_scaffold_custom_frontend_path = File.join(ActiveScaffold::Config::Core.plugin_directory, 'frontends', active_scaffold_config.frontend.to_s , 'views')
179
- @active_scaffold_frontends << active_scaffold_custom_frontend_path
180
- end
181
- active_scaffold_default_frontend_path = File.join(ActiveScaffold::Config::Core.plugin_directory, 'frontends', 'default' , 'views')
182
- @active_scaffold_frontends << active_scaffold_default_frontend_path
183
- @active_scaffold_custom_paths = []
184
-
185
- self.active_scaffold_superclasses_blocks.each {|superblock| self.active_scaffold_config.configure &superblock}
186
- self.active_scaffold_config.sti_children = nil # reset sti_children if set in parent block
187
- self.active_scaffold_config.configure &block if block_given?
188
- self.active_scaffold_config._configure_sti unless self.active_scaffold_config.sti_children.nil?
189
- self.active_scaffold_config._load_action_columns
190
-
191
- # defines the attribute read methods on the model, so record.send() doesn't find protected/private methods instead
192
- klass = self.active_scaffold_config.model
193
- klass.define_attribute_methods unless klass.attribute_methods_generated?
194
- # include the rest of the code into the controller: the action core and the included actions
195
- module_eval do
196
- include ActiveScaffold::Finder
197
- include ActiveScaffold::Constraints
198
- include ActiveScaffold::AttributeParams
199
- include ActiveScaffold::Actions::Core
200
- active_scaffold_config.actions.each do |mod|
201
- name = mod.to_s.camelize
202
- include "ActiveScaffold::Actions::#{name}".constantize
203
-
204
- # sneak the action links from the actions into the main set
205
- if link = active_scaffold_config.send(mod).link rescue nil
206
- if link.is_a? Array
207
- link.each {|current| active_scaffold_config.action_links.add_to_group(current, active_scaffold_config.send(mod).action_group)}
208
- elsif link.is_a? ActiveScaffold::DataStructures::ActionLink
209
- active_scaffold_config.action_links.add_to_group(link, active_scaffold_config.send(mod).action_group)
210
- end
211
- end
212
- end
213
- end
214
- self.append_view_path active_scaffold_paths
215
- self._add_sti_create_links if self.active_scaffold_config.add_sti_create_links?
216
- end
217
-
218
- def parent_prefixes
219
- @parent_prefixes ||= super << 'active_scaffold_overrides' << ''
220
- end
221
-
222
- # To be called after include action modules
223
- def _add_sti_create_links
224
- new_action_link = active_scaffold_config.action_links.collection['new']
225
- unless new_action_link.nil? || active_scaffold_config.sti_children.empty?
226
- active_scaffold_config.action_links.collection.delete('new')
227
- active_scaffold_config.sti_children.each do |child|
228
- new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone
229
- new_sti_link.label = child.to_s.camelize.constantize.model_name.human
230
- new_sti_link.parameters = {:parent_sti => controller_path}
231
- new_sti_link.controller = Proc.new { active_scaffold_controller_for(child.to_s.camelize.constantize).controller_path }
232
- active_scaffold_config.action_links.collection.create.add(new_sti_link)
233
- end
234
- end
235
- end
236
-
237
- # Create the automatic column links. Note that this has to happen when configuration is *done*, because otherwise the Nested module could be disabled. Actually, it could still be disabled later, couldn't it?
238
- def links_for_associations
239
- return unless active_scaffold_config.actions.include? :list and active_scaffold_config.actions.include? :nested
240
- active_scaffold_config.columns.each do |column|
241
- next unless column.link.nil? and column.autolink?
242
- #lazy load of action_link, cause it was really slowing down app in dev mode
243
- #and might lead to trouble cause of cyclic constantization of controllers
244
- #and might be unnecessary cause it is done before columns are configured
245
- column.set_link(Proc.new {|col| link_for_association(col)})
246
- end
247
- end
248
-
249
- def active_scaffold_controller_for_column(column, options = {})
250
- begin
251
- if column.polymorphic_association?
252
- :polymorph
253
- elsif options.include?(:controller)
254
- "#{options[:controller].to_s.camelize}Controller".constantize
255
- else
256
- active_scaffold_controller_for(column.association.klass)
257
- end
258
- rescue ActiveScaffold::ControllerNotFound
259
- nil
260
- end
261
- end
262
-
263
- def link_for_association(column, options = {})
264
- controller = active_scaffold_controller_for_column(column, options)
265
-
266
- unless controller.nil?
267
- options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => (controller == :polymorph ? controller : controller.controller_path), :column => column
268
- options[:parameters] ||= {}
269
- options[:parameters].reverse_merge! :parent_scaffold => controller_path, :association => column.association.name
270
- if column.plural_association?
271
- # note: we can't create nested scaffolds on :through associations because there's no reverse association.
272
-
273
- ActiveScaffold::DataStructures::ActionLink.new('index', options) #unless column.through_association?
274
- else
275
- actions = [:create, :update, :show]
276
- actions = controller.active_scaffold_config.actions unless controller == :polymorph
277
- column.actions_for_association_links.delete :new unless actions.include? :create
278
- column.actions_for_association_links.delete :edit unless actions.include? :update
279
- column.actions_for_association_links.delete :show unless actions.include? :show
280
- ActiveScaffold::DataStructures::ActionLink.new(nil, options.merge(:html_options => {:class => column.name}))
281
- end
282
- end
283
- end
284
-
285
- def link_for_association_as_scope(scope, options = {})
286
- options.reverse_merge! :label => scope, :position => :after, :type => :member, :controller => controller_path
287
- options[:parameters] ||= {}
288
- options[:parameters].reverse_merge! :parent_scaffold => controller_path, :named_scope => scope
289
- ActiveScaffold::DataStructures::ActionLink.new('index', options)
290
- end
291
-
292
- def add_active_scaffold_path(path)
293
- @active_scaffold_paths = nil # Force active_scaffold_paths to rebuild
294
- @active_scaffold_custom_paths << path
295
- end
296
-
297
- def active_scaffold_paths
298
- return @active_scaffold_paths unless @active_scaffold_paths.nil?
299
-
300
- @active_scaffold_paths = []
301
- @active_scaffold_paths.concat @active_scaffold_custom_paths unless @active_scaffold_custom_paths.nil?
302
- @active_scaffold_paths.concat @active_scaffold_frontends unless @active_scaffold_frontends.nil?
303
- @active_scaffold_paths
304
- end
305
-
306
- def active_scaffold_config
307
- if @active_scaffold_config.nil?
308
- self.superclass.active_scaffold_config if self.superclass.respond_to? :active_scaffold_config
309
- else
310
- @active_scaffold_config
311
- end
312
- end
313
-
314
- def active_scaffold_config_block
315
- @active_scaffold_config_block
316
- end
317
-
318
- def active_scaffold_superclasses_blocks
319
- blocks = []
320
- klass = self.superclass
321
- while klass.respond_to? :active_scaffold_superclasses_blocks
322
- blocks << klass.active_scaffold_config_block
323
- klass = klass.superclass
324
- end
325
- blocks.compact.reverse
326
- end
327
-
328
- def active_scaffold_config_for(klass)
329
- begin
330
- controller = active_scaffold_controller_for(klass)
331
- rescue ActiveScaffold::ControllerNotFound
332
- config = ActiveScaffold::Config::Core.new(klass)
333
- config._load_action_columns
334
- config
335
- else
336
- controller.active_scaffold_config
337
- end
338
- end
339
-
340
- # Tries to find a controller for the given ActiveRecord model.
341
- # Searches in the namespace of the current controller for singular and plural versions of the conventional "#{model}Controller" syntax.
342
- # You may override this method to customize the search routine.
343
- def active_scaffold_controller_for(klass)
344
- controller_namespace = self.to_s.split('::')[0...-1].join('::') + '::'
345
- error_message = []
346
- [controller_namespace, ''].each do |namespace|
347
- ["#{klass.to_s.underscore.pluralize}", "#{klass.to_s.underscore.pluralize.singularize}"].each do |controller_name|
348
- begin
349
- controller = "#{namespace}#{controller_name.camelize}Controller".constantize
350
- rescue NameError => error
351
- # Only rescue NameError associated with the controller constant not existing - not other compile errors
352
- if error.message["uninitialized constant #{controller}"]
353
- error_message << "#{namespace}#{controller_name.camelize}Controller"
354
- next
355
- else
356
- raise
357
- end
358
- end
359
- raise ActiveScaffold::ControllerNotFound, "#{controller} missing ActiveScaffold", caller unless controller.uses_active_scaffold?
360
- raise ActiveScaffold::ControllerNotFound, "ActiveScaffold on #{controller} is not for #{klass} model.", caller unless controller.active_scaffold_config.model.to_s == klass.to_s
361
- return controller
362
- end
363
- end
364
- raise ActiveScaffold::ControllerNotFound, "Could not find " + error_message.join(" or "), caller
365
- end
366
-
367
- def uses_active_scaffold?
368
- !active_scaffold_config.nil?
369
- end
370
- end
371
- end
372
-
373
- require 'active_scaffold_env'