active_scaffold 3.0.12 → 3.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/README +21 -11
  2. data/frontends/default/images/close_touch.png +0 -0
  3. data/frontends/default/javascripts/jquery/active_scaffold.js +187 -99
  4. data/frontends/default/javascripts/prototype/active_scaffold.js +105 -33
  5. data/frontends/default/javascripts/prototype/dhtml_history.js +80 -77
  6. data/frontends/default/stylesheets/stylesheet.css +121 -2
  7. data/frontends/default/views/_action_group.html.erb +6 -2
  8. data/frontends/default/views/_base_form.html.erb +11 -5
  9. data/frontends/default/views/_base_form.html.erb~ +42 -0
  10. data/frontends/default/views/_field_search.html.erb +1 -1
  11. data/frontends/default/views/_form.html.erb +9 -7
  12. data/frontends/default/views/_form_association.html.erb +8 -3
  13. data/frontends/default/views/_form_association_footer.html.erb +10 -3
  14. data/frontends/default/views/_form_attribute.html.erb +8 -3
  15. data/frontends/default/views/_horizontal_subform.html.erb +12 -2
  16. data/frontends/default/views/_horizontal_subform_header.html.erb +1 -1
  17. data/frontends/default/views/_horizontal_subform_record.html.erb +5 -4
  18. data/frontends/default/views/_list_messages.html.erb +1 -1
  19. data/frontends/default/views/_list_with_header.html.erb +1 -1
  20. data/frontends/default/views/_render_field.js.rjs +4 -6
  21. data/frontends/default/views/_vertical_subform.html.erb +1 -1
  22. data/frontends/default/views/_vertical_subform_record.html.erb +2 -2
  23. data/frontends/default/views/on_action_update.js.rjs +3 -1
  24. data/frontends/default/views/on_mark_all.js.rjs +12 -0
  25. data/frontends/default/views/on_update.js.rjs +1 -1
  26. data/frontends/default/views/render_field.js.rjs +1 -0
  27. data/frontends/default/views/update_column.js.rjs +1 -1
  28. data/lib/active_scaffold.rb +60 -21
  29. data/lib/active_scaffold/actions/common_search.rb +2 -2
  30. data/lib/active_scaffold/actions/core.rb +30 -9
  31. data/lib/active_scaffold/actions/create.rb +14 -10
  32. data/lib/active_scaffold/actions/field_search.rb +6 -6
  33. data/lib/active_scaffold/actions/list.rb +22 -12
  34. data/lib/active_scaffold/actions/mark.rb +34 -9
  35. data/lib/active_scaffold/actions/nested.rb +12 -16
  36. data/lib/active_scaffold/actions/show.rb +2 -2
  37. data/lib/active_scaffold/actions/subform.rb +15 -8
  38. data/lib/active_scaffold/actions/update.rb +14 -4
  39. data/lib/active_scaffold/attribute_params.rb +15 -10
  40. data/lib/active_scaffold/bridges/bridge.rb +21 -12
  41. data/lib/active_scaffold/bridges/calendar_date_select/bridge.rb +3 -3
  42. data/lib/active_scaffold/bridges/cancan/bridge.rb +12 -0
  43. data/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb +107 -0
  44. data/lib/active_scaffold/bridges/carrierwave/bridge.rb +1 -1
  45. data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +3 -8
  46. data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +1 -15
  47. data/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +23 -13
  48. data/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb +1 -1
  49. data/lib/active_scaffold/bridges/country_helper/bridge.rb +9 -0
  50. data/lib/active_scaffold/bridges/country_helper/lib/country_helper_bridge.rb +358 -0
  51. data/lib/active_scaffold/bridges/date_picker/bridge.rb +5 -3
  52. data/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +9 -0
  53. data/lib/active_scaffold/bridges/dragonfly/bridge.rb +9 -0
  54. data/lib/active_scaffold/bridges/dragonfly/bridge.rb~ +12 -0
  55. data/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge.rb +36 -0
  56. data/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge.rb~ +36 -0
  57. data/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge_helpers.rb +12 -0
  58. data/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge_helpers.rb~ +12 -0
  59. data/lib/active_scaffold/bridges/dragonfly/lib/form_ui.rb +27 -0
  60. data/lib/active_scaffold/bridges/dragonfly/lib/form_ui.rb~ +27 -0
  61. data/lib/active_scaffold/bridges/dragonfly/lib/list_ui.rb +16 -0
  62. data/lib/active_scaffold/bridges/dragonfly/lib/list_ui.rb~ +16 -0
  63. data/lib/active_scaffold/bridges/paperclip/bridge.rb +1 -1
  64. data/lib/active_scaffold/bridges/record_select/bridge.rb +5 -0
  65. data/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb +87 -0
  66. data/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb~ +84 -0
  67. data/lib/active_scaffold/bridges/shared/date_bridge.rb +56 -34
  68. data/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb +19 -3
  69. data/lib/active_scaffold/config/base.rb +4 -4
  70. data/lib/active_scaffold/config/core.rb +4 -0
  71. data/lib/active_scaffold/config/create.rb +1 -1
  72. data/lib/active_scaffold/config/field_search.rb +7 -7
  73. data/lib/active_scaffold/config/form.rb +8 -2
  74. data/lib/active_scaffold/config/list.rb +22 -8
  75. data/lib/active_scaffold/config/mark.rb +18 -5
  76. data/lib/active_scaffold/config/nested.rb +3 -3
  77. data/lib/active_scaffold/config/search.rb +1 -1
  78. data/lib/active_scaffold/config/show.rb +1 -1
  79. data/lib/active_scaffold/data_structures/action_columns.rb +10 -6
  80. data/lib/active_scaffold/data_structures/action_link.rb +14 -10
  81. data/lib/active_scaffold/data_structures/action_links.rb +2 -2
  82. data/lib/active_scaffold/data_structures/column.rb +25 -11
  83. data/lib/active_scaffold/data_structures/nested_info.rb +21 -21
  84. data/lib/active_scaffold/data_structures/set.rb +2 -3
  85. data/lib/active_scaffold/data_structures/sorting.rb +8 -8
  86. data/lib/{extensions → active_scaffold/extensions}/action_controller_rendering.rb +3 -1
  87. data/lib/{extensions → active_scaffold/extensions}/action_view_rendering.rb +31 -33
  88. data/lib/{extensions → active_scaffold/extensions}/action_view_resolver.rb +0 -0
  89. data/lib/{extensions → active_scaffold/extensions}/active_association_reflection.rb +0 -0
  90. data/lib/active_scaffold/extensions/active_record_offset.rb +12 -0
  91. data/lib/{extensions → active_scaffold/extensions}/array.rb +0 -0
  92. data/lib/{extensions → active_scaffold/extensions}/localize.rb +1 -1
  93. data/lib/{extensions → active_scaffold/extensions}/name_option_for_datetime.rb +1 -1
  94. data/lib/{extensions → active_scaffold/extensions}/nil_id_in_url_params.rb +0 -0
  95. data/lib/{extensions → active_scaffold/extensions}/paginator_extensions.rb +2 -2
  96. data/lib/{extensions → active_scaffold/extensions}/reverse_associations.rb +1 -1
  97. data/lib/{extensions → active_scaffold/extensions}/routing_mapper.rb +2 -2
  98. data/lib/{extensions → active_scaffold/extensions}/to_label.rb +0 -0
  99. data/lib/{extensions → active_scaffold/extensions}/unsaved_associated.rb +0 -0
  100. data/lib/{extensions → active_scaffold/extensions}/unsaved_record.rb +0 -0
  101. data/lib/active_scaffold/extensions/usa_state.rb +46 -0
  102. data/lib/active_scaffold/finder.rb +30 -19
  103. data/lib/active_scaffold/helpers/controller_helpers.rb +3 -5
  104. data/lib/active_scaffold/helpers/form_column_helpers.rb +19 -45
  105. data/lib/active_scaffold/helpers/human_condition_helpers.rb +1 -1
  106. data/lib/active_scaffold/helpers/id_helpers.rb +2 -2
  107. data/lib/active_scaffold/helpers/list_column_helpers.rb +28 -17
  108. data/lib/active_scaffold/helpers/search_column_helpers.rb +51 -40
  109. data/lib/active_scaffold/helpers/search_column_helpers.rb~ +215 -0
  110. data/lib/active_scaffold/helpers/show_column_helpers.rb +8 -4
  111. data/lib/active_scaffold/helpers/view_helpers.rb +50 -27
  112. data/lib/active_scaffold/locale/de.yml +111 -0
  113. data/lib/active_scaffold/locale/en.yml +115 -0
  114. data/lib/active_scaffold/locale/es.yml +32 -32
  115. data/lib/active_scaffold/locale/fr.yml +118 -0
  116. data/lib/active_scaffold/marked_model.rb +6 -6
  117. data/lib/active_scaffold/version.rb +1 -1
  118. data/lib/active_scaffold_assets.rb +1 -3
  119. data/lib/active_scaffold_env.rb +1 -2
  120. data/lib/generators/active_scaffold/active_scaffold_generator.rb +5 -5
  121. data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +3 -2
  122. data/lib/generators/active_scaffold_controller/templates/helper.rb +2 -0
  123. data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +17 -19
  124. data/shoulda_macros/macros.rb +4 -4
  125. data/test/misc/finder_test.rb +2 -2
  126. data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +4 -1
  127. metadata +144 -126
  128. data/.autotest +0 -27
  129. data/.document +0 -5
  130. data/Gemfile +0 -13
  131. data/Gemfile.lock +0 -20
  132. data/Rakefile +0 -53
  133. data/active_scaffold.gemspec +0 -385
  134. data/init.rb +0 -2
  135. data/lib/active_scaffold/helpers/country_helpers.rb +0 -358
  136. data/lib/active_scaffold/locale/de.rb +0 -120
  137. data/lib/active_scaffold/locale/en.rb +0 -119
  138. data/lib/active_scaffold/locale/fr.rb +0 -116
  139. data/lib/extensions/active_record_offset.rb +0 -12
  140. data/lib/extensions/usa_state.rb +0 -50
  141. data/test/mock_app/.gitignore +0 -2
  142. data/uninstall.rb +0 -13
@@ -5,10 +5,14 @@
5
5
  <% if (options[:node] == :finished_traversing) -%>
6
6
  <%= "</ul>#{(options[:level] == 0 ? "</div>#{end_level_0_tag}": '</li>')}".html_safe %>
7
7
  <% elsif (options[:node] == :start_traversing) -%>
8
+ <% html_classes = []
9
+ html_classes << 'hover_click' if hover_via_click? %>
8
10
  <% if options[:level] == 0 %>
9
- <%= "#{start_level_0_tag}<div class=\"action_group\"> #{content_tag(:div, as_(parent.name), :class => (parent.name.to_s).downcase)}<ul>".html_safe %>
11
+ <% html_classes << 'action_group' %>
12
+ <%= "#{start_level_0_tag}<div class=\"#{html_classes.join(' ')}\" #{"onclick=\"\"" if hover_via_click?}> #{content_tag(:div, as_(parent.name), :class => (parent.name.to_s).downcase)}<ul>".html_safe %>
10
13
  <% else %>
11
- <%= "<li #{"class=\"top\"" if options[:first_action]}>#{content_tag(:div, as_(parent.name), :class => (parent.name.to_s).downcase)}<ul>".html_safe %>
14
+ <% html_classes << 'top' if options[:first_action] %>
15
+ <%= "<li #{"class=\"#{html_classes.join(' ')}\"" unless html_classes.empty?} #{"onclick=\"\"" if hover_via_click?}>#{content_tag(:div, as_(parent.name), :class => (parent.name.to_s).downcase)}<ul>".html_safe %>
12
16
  <% end %>
13
17
  <% else -%>
14
18
  <% if options[:level] == 0 %>
@@ -1,21 +1,27 @@
1
1
  <% url_options ||= params_for(:action => form_action)
2
2
  xhr = request.xhr? if xhr.nil?
3
- as_action_config = active_scaffold_config.send(form_action)
3
+ if active_scaffold_config.actions.include? form_action
4
+ multipart ||= active_scaffold_config.send(form_action).multipart?
5
+ columns ||= active_scaffold_config.send(form_action).columns
6
+ else
7
+ multipart ||= false
8
+ columns ||= nil
9
+ end
4
10
  body_partial ||= 'form' %>
5
11
  <%=
6
12
  options = {:onsubmit => onsubmit,
7
13
  :id => element_form_id(:action => form_action),
8
- :multipart => as_action_config.multipart?,
14
+ :multipart => multipart,
9
15
  :class => "as_form #{form_action.to_s}",
10
16
  :method => method,
11
17
  'data-loading' => true}
12
18
  cancel_options = {:class => 'as_cancel', 'data-refresh' => false}
13
19
 
14
20
  cancel_options[:remote] = true if xhr #cancel link does nt have to care about multipart forms
15
- if xhr && as_action_config.multipart? # file_uploads
21
+ if xhr && multipart # file_uploads
16
22
  form_remote_upload_tag url_options.merge({:iframe => true}), options
17
23
  else
18
- options[:remote] = true if xhr && !as_action_config.multipart?
24
+ options[:remote] = true if xhr && !multipart
19
25
  form_tag url_options, options
20
26
  end
21
27
  -%>
@@ -33,7 +39,7 @@ end
33
39
  <% end -%>
34
40
  </div>
35
41
 
36
- <%= render :partial => body_partial, :locals => { :columns => as_action_config.columns } %>
42
+ <%= render :partial => body_partial, :locals => { :columns => columns, :form_action => form_action } %>
37
43
 
38
44
  <p class="form-footer">
39
45
  <%= submit_tag as_(form_action), :class => "submit" %>
@@ -0,0 +1,42 @@
1
+ <% url_options ||= params_for(:action => :update)
2
+ xhr = request.xhr?
3
+ multipart ||= false
4
+ columns ||= nil
5
+ %>
6
+ <%=
7
+ options = {:id => element_form_id(:action => :update),
8
+ :multipart => multipart,
9
+ :class => "as_form #{form_action.to_s}",
10
+ :method => :put,
11
+ 'data-loading' => true}
12
+
13
+ if xhr && multipart # file_uploads
14
+ form_remote_upload_tag url_options.merge({:iframe => true}), options
15
+ else
16
+ options[:remote] = true if xhr && !multipart
17
+ form_tag url_options, options
18
+ end
19
+ -%>
20
+
21
+ <h4><%= Setting.model_name.human(:count => 2) -%></h4>
22
+
23
+ <div id="<%= element_messages_id(:action => :update) %>" class="messages-container">
24
+ <% if request.xhr? -%>
25
+ <% records = @error_records || Array(@record)
26
+ records.each do |record| %>
27
+ <%= active_scaffold_error_messages_for record, :object_name => "#{record.class.model_name.human.downcase}#{record.new_record? ? '' : ": #{record.to_label}"}" %>
28
+ <% end %>
29
+ <% else -%>
30
+ <%= render :partial => 'form_messages' %>
31
+ <% end -%>
32
+ </div>
33
+
34
+ <%= render :partial => 'form', :locals => { :columns => columns, :form_action => :update } %>
35
+
36
+ <p class="form-footer">
37
+ <%= submit_tag as_(form_action), :class => "submit" %>
38
+ <%= loading_indicator_tag(:action => :update, :id => params[:id]) %>
39
+ </p>
40
+
41
+ </form>
42
+ <%= javascript_tag("ActiveScaffold.focus_first_element_of_form('#{element_form_id(:action => :update)}');") %>
@@ -14,7 +14,7 @@ form_tag url_options, options %>
14
14
  <% unless hiddens.empty? -%>
15
15
  <li class="sub-section">
16
16
  <h5><%= as_(:optional_attributes) %></h5>
17
- <ol id ="<%= sub_section_id(:sub_section => 'further_options') %>" class="form" 'style="display: none;"'>
17
+ <ol id ="<%= sub_section_id(:sub_section => 'further_options') %>" class="form" style="display:none;">
18
18
  <% hiddens.each do |column| -%>
19
19
  <%= render :partial => 'search_attribute', :locals => {:column => column} %>
20
20
  <% end -%>
@@ -1,23 +1,25 @@
1
1
  <% subsection_id ||= nil %>
2
- <ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= 'style="display: none;"' if columns.collapsed -%>>
3
- <% columns.each :for => @record do |column| %>
2
+ <% show_unauthorized_columns = active_scaffold_config.send(form_action).show_unauthorized_columns %>
3
+ <ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= "style=\"display: none;\"" if columns.collapsed %>>
4
+ <% columns.each :for => @record, :crud_type => (:read if show_unauthorized_columns) do |column| %>
5
+ <% authorized = show_unauthorized_columns ? @record.authorized_for?(:crud_type => form_action, :column => column.name) : true %>
4
6
  <% renders_as = column_renders_as(column) %>
5
7
  <% if renders_as == :subsection -%>
6
8
  <% subsection_id = sub_section_id(:sub_section => column.label) %>
7
9
  <li class="sub-section">
8
10
  <h5><%= column.label %></h5>
9
- <%= render :partial => 'form', :locals => { :columns => column, :subsection_id => subsection_id} %>
11
+ <%= render :partial => 'form', :locals => { :columns => column, :subsection_id => subsection_id, :form_action => form_action } %>
10
12
  <%= link_to_visibility_toggle(subsection_id, {:default_visible => !column.collapsed}) -%>
11
13
  </li>
12
14
  <% elsif column.readonly_association?
13
15
  next %>
14
- <% elsif renders_as == :subform and !override_form_field?(column) -%>
15
- <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %>" id="<%= sub_form_id(:association => column.name) %>">
16
- <%= render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column } -%>
16
+ <% elsif renders_as == :subform and !override_form_field?(column) and authorized -%>
17
+ <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %> <%=column.name%>-sub-form" id="<%= sub_form_id(:association => column.name) %>">
18
+ <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column } -%>
17
19
  </li>
18
20
  <% else -%>
19
21
  <li class="form-element <%= 'required' if column.required? %> <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %>">
20
- <%= render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column } -%>
22
+ <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column, :only_value => !authorized } -%>
21
23
  </li>
22
24
  <% end -%>
23
25
  <% end -%>
@@ -2,13 +2,18 @@
2
2
  parent_record = @record
3
3
  associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a
4
4
  associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order)
5
-
6
- associated << column.association.klass.new if column.show_blank_record? associated
5
+ if show_blank_record = column.show_blank_record?(associated)
6
+ associated << if column.singular_association?
7
+ parent_record.send("build_#{column.name}".to_sym)
8
+ else
9
+ parent_record.send(column.name).build
10
+ end
11
+ end
7
12
  subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_record.id || 99999999999})}-div"
8
13
  -%>
9
14
  <h5><%= column.label -%></h5>
10
15
  <div id ="<%= subform_div_id %>" <%= 'style="display: none;"'.html_safe if column.collapsed -%>>
11
- <%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated} %>
16
+ <%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated, :show_blank_record => show_blank_record} %>
12
17
  </div>
13
18
  <%= link_to_visibility_toggle(subform_div_id, {:default_visible => !column.collapsed}) -%>
14
19
  <% @record = parent_record -%>
@@ -4,6 +4,7 @@ begin
4
4
  rescue ActiveScaffold::ControllerNotFound
5
5
  remote_controller = nil
6
6
  end
7
+ @record = parent_record
7
8
 
8
9
  show_add_existing = column_show_add_existing(column)
9
10
  show_add_new = column_show_add_new(column, associated, @record)
@@ -17,9 +18,15 @@ add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :as
17
18
  <div class="footer-wrapper">
18
19
  <div class="footer">
19
20
  <% if show_add_new -%>
20
- <% add_label = column.plural_association? ? as_(:create_another, :model => column.association.klass.model_name.human) : as_(:replace_with_new)
21
+ <% if column.plural_association?
22
+ add_label = as_(:create_another, :model => column.association.klass.model_name.human)
23
+ add_class = 'as_create_another'
24
+ else
25
+ add_label = as_(:replace_with_new)
26
+ add_class = 'as_replace_with_new'
27
+ end
21
28
  create_another_id = "#{sub_form_id(:association => column.name)}-create-another" %>
22
- <%= tag(:input, {:id => create_another_id, :type => 'button', :value => add_label, :href => add_new_url.html_safe, 'data-remote' => true, :style=> "display: none;"}) %>
29
+ <%= tag(:input, {:id => create_another_id, :type => 'button', :value => add_label, :href => add_new_url.html_safe, 'data-remote' => true, :class => add_class, :style=> "display: none;"}) %>
23
30
  <%= javascript_tag("ActiveScaffold.show('#{create_another_id}');") %>
24
31
  <% end -%>
25
32
 
@@ -32,7 +39,7 @@ add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :as
32
39
  <% select_options = options_for_select(options_for_association(column.association))
33
40
  add_existing_id = "#{sub_form_id(:association => column.name)}-add-existing" %>
34
41
  <%= select_tag 'associated_id', '<option value="">'.html_safe + as_(:_select_) + '</option>'.html_safe + select_options %>
35
- <%= tag(:input, {:id => add_existing_id, :type => 'button', :value => as_(:add_existing), :href => edit_associated_url.html_safe, 'data-remote' => true, :class=> 'as_add_existing', :style => "display: none;"}) %>
42
+ <%= tag(:input, {:id => add_existing_id, :type => 'button', :value => as_(:add_existing), :href => edit_associated_url.html_safe, 'data-remote' => true, :class=> column.plural_association? ? 'as_add_existing' : 'as_replace_existing', :style => "display: none;"}) %>
36
43
  <%= javascript_tag("ActiveScaffold.show('#{add_existing_id}');") %>
37
44
  <% end -%>
38
45
  <% end -%>
@@ -4,12 +4,17 @@
4
4
  <label for="<%= active_scaffold_input_options(column, scope)[:id] %>"><%= column.label %></label>
5
5
  </dt>
6
6
  <dd>
7
- <%= active_scaffold_input_for column, scope %>
7
+ <% unless local_assigns[:only_value] %>
8
+ <%=raw active_scaffold_input_for column, scope %>
9
+ <% else %>
10
+ <%= get_column_value(@record, column) %>
11
+ <%= hidden_field :record, column.association ? column.association.primary_key_name : column.name, active_scaffold_input_options(column, scope) -%>
12
+ <% end %>
8
13
  <% if column.update_columns -%>
9
14
  <%= loading_indicator_tag(:action => :render_field, :id => params[:id]) %>
10
15
  <% end -%>
11
- <% if column.description -%>
16
+ <% if column.description.present? -%>
12
17
  <span class="description"><%= column.description %></span>
13
18
  <% end -%>
14
19
  </dd>
15
- </dl>
20
+ </dl>
@@ -1,5 +1,15 @@
1
1
  <table cellpadding="0" cellspacing="0">
2
- <% @record = column.association.klass.new -%>
2
+ <%
3
+ if associated.empty?
4
+ @record = if column.singular_association?
5
+ parent_record.send("build_#{column.name}".to_sym)
6
+ else
7
+ parent_record.send(column.name).build
8
+ end
9
+ else
10
+ @record = associated.last
11
+ end
12
+ -%>
3
13
  <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record} %>
4
14
 
5
15
  <tbody id="<%= sub_form_list_id(:association => column.name) %>">
@@ -12,7 +22,7 @@
12
22
  </td>
13
23
  </tr>
14
24
  <% end %>
15
- <%= render :partial => 'horizontal_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => @record.new_record? && @record == associated.last} %>
25
+ <%= render :partial => 'horizontal_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %>
16
26
  <% end -%>
17
27
  </tbody>
18
28
  </table>
@@ -1,7 +1,7 @@
1
1
  <thead>
2
2
  <tr>
3
3
  <%
4
- active_scaffold_config_for(@record.class).subform.columns.each :for => @record, :flatten => true do |column|
4
+ active_scaffold_config_for(@record.class).subform.columns.each :for => @record.class, :flatten => true do |column|
5
5
  next unless in_subform?(column, parent_record) and column_renders_as(column) != :hidden
6
6
  -%>
7
7
  <th<%= ' class="required"' if column.required? %>><label><%= column.label %></label></th>
@@ -1,6 +1,7 @@
1
- <% record_column = column
1
+ <%
2
+ record_column = column
2
3
  readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update))
3
- crud_type = @record.new_record? ? :create : (readonly ? :read : nil)
4
+ crud_type = @record.new_record? ? :create : (readonly ? :read : :update)
4
5
  show_actions = false
5
6
  config = active_scaffold_config_for(@record.class)
6
7
  options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope)
@@ -15,7 +16,7 @@
15
16
  column.form_ui ||= :select if column.association
16
17
  -%>
17
18
  <td>
18
- <% unless readonly and not @record.new_record? -%>
19
+ <% unless readonly and not @record.new_record? or not @record.authorized_for?(:crud_type => crud_type, :column => column.name) -%>
19
20
  <%= render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope } -%>
20
21
  <% else -%>
21
22
  <p><%= get_column_value(@record, column) -%></p>
@@ -26,7 +27,7 @@
26
27
  <td class="actions">
27
28
  <% if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %>
28
29
  <% destroy_id = "#{options[:id]}-destroy" %>
29
- <%= link_to as_(:remove), '#', :class => 'destroy', :id => destroy_id , :onclick => "ActiveScaffold.remove(\"#{tr_id}\"); return false;", :style=> "display: none;" %>
30
+ <%= link_to as_(:remove), '#', :class => 'destroy', :id => destroy_id , :onclick => "ActiveScaffold.delete_subform_record(\"#{tr_id}\"); return false;", :style=> "display: none;" %>
30
31
  <%= javascript_tag("ActiveScaffold.show('#{destroy_id}');") if !locked %>
31
32
  <% end %>
32
33
  <% unless @record.new_record? %>
@@ -18,7 +18,7 @@
18
18
  <% if active_scaffold_config.list.show_search_reset && @filtered -%>
19
19
  <% search_link = ActiveScaffold::DataStructures::ActionLink.new('index', :label => :click_to_reset, :type => :member, :position => false)
20
20
  action_links = ActiveScaffold::DataStructures::ActionLinks.new
21
- record = active_scaffold_config.model.new
21
+ record = new_model
22
22
  record.id = 0
23
23
  action_links.add(search_link) -%>
24
24
  <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => params_for(:escape => false, :search => ''), :action_links => action_links.member} %>
@@ -1,4 +1,4 @@
1
- <div id="<%= active_scaffold_id -%>" class="active-scaffold active-scaffold-<%= controller_id %> <%= "#{params[:controller]}-view" %> <%= active_scaffold_config.theme %>-theme" <%= "data-eid=#{id_from_controller(params[:eid])}" if params[:eid]%>>
1
+ <div id="<%= active_scaffold_id -%>" class="<%= as_main_div_class %>" <%= "data-eid=#{id_from_controller(params[:eid])}" if params[:eid]%>>
2
2
  <div class="active-scaffold-header">
3
3
  <%= render :partial => 'list_header' %>
4
4
  </div>
@@ -1,13 +1,11 @@
1
1
  column = active_scaffold_config.columns[render_field.to_sym]
2
- options = {:is_subform => false}
3
2
  if column_renders_as(column) == :subform
4
- options[:is_subform] = true
5
- field_id = sub_form_id(:association => column.name)
3
+ options = {:is_subform => true, :field_class => "#{column.name}-sub-form"}
6
4
  else
7
- field_id = active_scaffold_input_options(column, params[:scope])[:id]
5
+ options = {:is_subform => false, :field_class => "#{column.name}-input"}
8
6
  end
9
- page.call 'ActiveScaffold.render_form_field', field_id, render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] }), options
10
- render(:partial => "render_field", :collection => column.update_columns) if column.update_columns && !column.update_columns.empty?
7
+ page.call 'ActiveScaffold.render_form_field', source_id, render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope }), options
8
+ page << render(:partial => "render_field", :collection => column.update_columns, :locals => {:source_id => source_id, :scope => scope}) if column.update_columns && !column.update_columns.empty?
11
9
 
12
10
 
13
11
 
@@ -6,7 +6,7 @@
6
6
  <%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %>
7
7
  </div>
8
8
  <% end %>
9
- <%= render :partial => 'vertical_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => @record.new_record? && @record == associated.last} %>
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
10
  <% end -%>
11
11
  </div>
12
12
  <%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated} -%>
@@ -1,7 +1,7 @@
1
1
  <%
2
2
  record_column = column
3
3
  readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update))
4
- crud_type = @record.new_record? ? :create : (readonly ? :read : nil)
4
+ crud_type = @record.new_record? ? :create : (readonly ? :read : :update)
5
5
  show_actions = false
6
6
  config = active_scaffold_config_for(@record.class)
7
7
  options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope)
@@ -27,7 +27,7 @@
27
27
  <li class="actions">
28
28
  <% if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %>
29
29
  <% destroy_id = "#{options[:id]}-destroy" %>
30
- <%= link_to as_(:remove), '#', :class => 'destroy', :id => destroy_id , :onclick => "ActiveScaffold.remove(\"#{tr_id}\"); return false;", :style=> "display: none;" %>
30
+ <%= link_to as_(:remove), '#', :class => 'destroy', :id => destroy_id , :onclick => "ActiveScaffold.delete_subform_record(\"#{tr_id}\"); return false;", :style=> "display: none;" %>
31
31
  <%= javascript_tag("ActiveScaffold.show('#{destroy_id}');") if !locked %>
32
32
  <% end %>
33
33
  <% unless @record.new_record? %>
@@ -1,8 +1,10 @@
1
- page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, render(:partial => 'messages')
2
1
  if controller.send :successful?
2
+ page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, render(:partial => 'messages')
3
3
  page.call 'ActiveScaffold.update_row', element_row_id(:action => :list, :id => @record.id), render(:partial => 'list_record', :locals => {:record => @record}) if @record
4
4
  page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}
5
5
  else
6
+ 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)
7
+ page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, render(:partial => 'messages')
6
8
  page.call 'ActiveScaffold.scroll_to', active_scaffold_messages_id
7
9
  end
8
10
 
@@ -0,0 +1,12 @@
1
+ options = {:checked => mark_all,
2
+ :include_mark_all => true}
3
+ page << "ActiveScaffold.mark_records('#{active_scaffold_tbody_id}', #{options.to_json});"
4
+ if active_scaffold_config.model.marked.length>0 then
5
+ if active_scaffold_config.model.marked.length < @page.pager.count then
6
+ page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, active_scaffold_config.model.marked.length.to_s + " records marked. Press <a href=\""+url_for(:action=>"mark_all",:mark_target=>"scope")+"\">here</a> to select all #{@page.pager.count} records.".html_safe
7
+ else
8
+ page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, "All #{@page.pager.count} records marked"
9
+ end
10
+ else
11
+ page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, ""
12
+ end
@@ -15,7 +15,7 @@ if controller.send :successful?
15
15
  end
16
16
  end
17
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 (active_scaffold_config.update.refresh_list)
18
+ elsif update_refresh_list?
19
19
  page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false)
20
20
  else
21
21
  updated_row = render :partial => 'list_record', :locals => {:record => @record}
@@ -0,0 +1 @@
1
+ page << render(:partial => "render_field", :collection => columns, :locals => {:source_id => source_id, :scope => scope})
@@ -1,6 +1,6 @@
1
1
  column_span_id ||= element_cell_id(:id => @record.id.to_s, :action => 'update_column', :name => params[:column])
2
2
  unless controller.send :successful?
3
- page.call 'alert', @record.errors.full_messages(active_scaffold_config).join("\n")
3
+ page.call 'alert', @record.errors.full_messages.join("\n")
4
4
  @record.reload
5
5
  end
6
6
  column = active_scaffold_config.columns[params[:column]]
@@ -66,13 +66,17 @@ module ActiveScaffold
66
66
  base.module_eval do
67
67
  # TODO: these should be in actions/core
68
68
  before_filter :handle_user_settings
69
+ before_filter :check_input_device
69
70
  end
71
+
72
+ base.helper_method :touch_device?
73
+ base.helper_method :hover_via_click?
70
74
  end
71
75
 
72
76
  def self.set_defaults(&block)
73
77
  ActiveScaffold::Config::Core.configure &block
74
78
  end
75
-
79
+
76
80
  def active_scaffold_config
77
81
  self.class.active_scaffold_config
78
82
  end
@@ -81,8 +85,7 @@ module ActiveScaffold
81
85
  self.class.active_scaffold_config_for(klass)
82
86
  end
83
87
 
84
- def active_scaffold_session_storage
85
- id = params[:eid] || params[:controller]
88
+ def active_scaffold_session_storage(id = (params[:eid] || params[:controller]))
86
89
  session_index = "as:#{id}"
87
90
  session[session_index] ||= {}
88
91
  session[session_index]
@@ -100,14 +103,46 @@ module ActiveScaffold
100
103
  end
101
104
  end
102
105
 
106
+ def check_input_device
107
+ if request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(iPhone|iPod|iPad)/i]
108
+ session[:input_device_type] = 'TOUCH'
109
+ session[:hover_supported] = false
110
+ else
111
+ session[:input_device_type] = 'MOUSE'
112
+ session[:hover_supported] = true
113
+ end if session[:input_device_type].nil?
114
+ end
115
+
116
+ def touch_device?
117
+ session[:input_device_type] == 'TOUCH'
118
+ end
119
+
120
+ def hover_via_click?
121
+ session[:hover_supported] == false
122
+ end
123
+
103
124
  def self.js_framework=(framework)
104
125
  @@js_framework = framework
105
126
  end
106
-
127
+
107
128
  def self.js_framework
108
129
  @@js_framework ||= :prototype
109
130
  end
110
131
 
132
+ # exclude bridges you do not need
133
+ # name of bridge subdir should be used to exclude it
134
+ # eg
135
+ # ActiveScaffold.exclude_bridges = [:cancan, :ancestry]
136
+ # if you are using Activescaffold as a gem add to initializer
137
+ # if you are using Activescaffold as a plugin add to active_scaffold_env.rb
138
+ def self.exclude_bridges=(bridges)
139
+ @@exclude_bridges = bridges
140
+ end
141
+
142
+ def self.exclude_bridges
143
+ @@exclude_bridges ||= []
144
+ end
145
+
111
146
  def self.root
112
147
  File.dirname(__FILE__) + "/.."
113
148
  end
@@ -201,10 +236,10 @@ module ActiveScaffold
201
236
  column.set_link(Proc.new {|col| link_for_association(col)})
202
237
  end
203
238
  end
204
-
205
- def link_for_association(column, options = {})
239
+
240
+ def active_scaffold_controller_for_column(column, options = {})
206
241
  begin
207
- controller = if column.polymorphic_association?
242
+ if column.polymorphic_association?
208
243
  :polymorph
209
244
  elsif options.include?(:controller)
210
245
  "#{options[:controller].to_s.camelize}Controller".constantize
@@ -212,28 +247,32 @@ module ActiveScaffold
212
247
  active_scaffold_controller_for(column.association.klass)
213
248
  end
214
249
  rescue ActiveScaffold::ControllerNotFound
215
- controller = nil
250
+ nil
216
251
  end
217
-
252
+ end
253
+
254
+ def link_for_association(column, options = {})
255
+ controller = active_scaffold_controller_for_column(column, options)
256
+
218
257
  unless controller.nil?
219
258
  options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => (controller == :polymorph ? controller : controller.controller_path), :column => column
220
259
  options[:parameters] ||= {}
221
260
  options[:parameters].reverse_merge! :parent_scaffold => controller_path, :association => column.association.name
222
261
  if column.plural_association?
223
262
  # note: we can't create nested scaffolds on :through associations because there's no reverse association.
224
-
263
+
225
264
  ActiveScaffold::DataStructures::ActionLink.new('index', options) #unless column.through_association?
226
265
  else
227
- actions = [:create, :update, :show]
266
+ actions = [:create, :update, :show]
228
267
  actions = controller.active_scaffold_config.actions unless controller == :polymorph
229
268
  column.actions_for_association_links.delete :new unless actions.include? :create
230
269
  column.actions_for_association_links.delete :edit unless actions.include? :update
231
270
  column.actions_for_association_links.delete :show unless actions.include? :show
232
271
  ActiveScaffold::DataStructures::ActionLink.new(:none, options.merge({:crud_type => nil, :html_options => {:class => column.name}}))
233
- end
272
+ end
234
273
  end
235
274
  end
236
-
275
+
237
276
  def link_for_association_as_scope(scope, options = {})
238
277
  options.reverse_merge! :label => scope, :position => :after, :type => :member, :controller => controller_path
239
278
  options[:parameters] ||= {}
@@ -297,13 +336,12 @@ module ActiveScaffold
297
336
  end
298
337
 
299
338
  # Tries to find a controller for the given ActiveRecord model.
300
- # Searches in the namespace of the current controller for singular
301
- # and plural versions of the conventional "#{model}Controller"
302
- # syntax. You may override this method to customize the search
303
- # routine.
339
+ # Searches in the namespace of the current controller for singular and plural versions of the conventional "#{model}Controller" syntax.
340
+ # You may override this method to customize the search routine.
304
341
  def active_scaffold_controller_for(klass)
305
342
  controller_namespace = self.to_s.split('::')[0...-1].join('::') + '::'
306
343
  error_message = []
344
+ klass = klass.to_s.singularize.camelize.constantize unless klass.is_a? Class
307
345
  [controller_namespace, ''].each do |namespace|
308
346
  ["#{klass.to_s.underscore.pluralize}", "#{klass.to_s.underscore.pluralize.singularize}"].each do |controller_name|
309
347
  begin
@@ -338,10 +376,11 @@ require 'active_scaffold_env'
338
376
  ## But at least rescue the action in production
339
377
  ##
340
378
 
341
- if defined?(ACTIVE_SCAFFOLD_PLUGIN)
342
- ActiveScaffoldAssets.copy_to_public(ActiveScaffold.root, {:clean_up_destination => true})
343
- else
344
- Rails::Application.initializer("active_scaffold.install_assets") do
379
+ Rails::Application.initializer("active_scaffold.install_assets") do
380
+ begin
345
381
  ActiveScaffoldAssets.copy_to_public(ActiveScaffold.root, {:clean_up_destination => true})
382
+ rescue
383
+ raise $! unless Rails.env == 'production'
346
384
  end
347
385
  end
386
+