active_scaffold 3.0.4 → 3.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/CHANGELOG +5 -0
  2. data/active_scaffold.gemspec +1 -1
  3. data/frontends/default/stylesheets/stylesheet.css +40 -2
  4. data/lib/active_scaffold.rb +111 -21
  5. data/lib/active_scaffold/actions/nested.rb +5 -1
  6. data/lib/active_scaffold/actions/subform.rb +4 -1
  7. data/lib/active_scaffold/attribute_params.rb +4 -4
  8. data/lib/active_scaffold/bridges/bridge.rb +2 -5
  9. data/lib/active_scaffold/config/list.rb +9 -9
  10. data/lib/active_scaffold/config/update.rb +1 -1
  11. data/lib/active_scaffold/data_structures/action_links.rb +4 -3
  12. data/lib/active_scaffold/finder.rb +13 -13
  13. data/lib/active_scaffold/helpers/controller_helpers.rb +5 -3
  14. data/lib/active_scaffold/helpers/country_helpers.rb +263 -257
  15. data/lib/active_scaffold/helpers/form_column_helpers.rb +5 -5
  16. data/lib/active_scaffold/helpers/id_helpers.rb +2 -2
  17. data/lib/active_scaffold/helpers/search_column_helpers.rb +11 -11
  18. data/lib/active_scaffold/helpers/view_helpers.rb +15 -15
  19. data/lib/active_scaffold/marked_model.rb +6 -6
  20. data/lib/extensions/action_view_rendering.rb +5 -5
  21. data/lib/extensions/active_record_offset.rb +7 -7
  22. data/lib/extensions/localize.rb +1 -1
  23. data/lib/extensions/name_option_for_datetime.rb +1 -1
  24. data/lib/extensions/paginator_extensions.rb +2 -2
  25. data/lib/extensions/reverse_associations.rb +1 -1
  26. data/lib/extensions/routing_mapper.rb +2 -2
  27. data/lib/extensions/usa_state.rb +15 -11
  28. data/lib/generators/active_scaffold/active_scaffold_generator.rb +5 -5
  29. data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +2 -2
  30. data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +10 -10
  31. metadata +4 -6
  32. data/environment.rb +0 -24
  33. data/install_assets.rb +0 -44
@@ -117,14 +117,14 @@ module ActiveScaffold
117
117
 
118
118
  active_scaffold_checkbox_list(column, select_options, associated_options.collect {|a| a[1]}, options)
119
119
  end
120
-
120
+
121
121
  def active_scaffold_checkbox_list(column, select_options, associated_ids, options)
122
122
  html = "<ul class=\"checkbox-list\" id=\"#{options[:id]}\">"
123
-
123
+
124
124
  select_options.each_with_index do |option, i|
125
125
  label, id = option
126
126
  this_id = "#{options[:id]}_#{i}_id"
127
- html << content_tag(:li) do
127
+ html << content_tag(:li) do
128
128
  check_box_tag("#{options[:name]}[]", id, associated_ids.include?(id), :id => this_id) <<
129
129
  content_tag(:label, h(label), :for => this_id)
130
130
  end
@@ -184,7 +184,7 @@ module ActiveScaffold
184
184
  if [:has_one, :has_many].include?(column.association.macro)
185
185
  params.merge!({column.association.primary_key_name => ''})
186
186
  end
187
-
187
+
188
188
  record_select_options = {:controller => remote_controller, :id => options[:id]}
189
189
  record_select_options.merge!(active_scaffold_input_text_options)
190
190
  record_select_options.merge!(column.options)
@@ -208,7 +208,7 @@ module ActiveScaffold
208
208
  def active_scaffold_input_textarea(column, options)
209
209
  text_area(:record, column.name, options.merge(:cols => column.options[:cols], :rows => column.options[:rows], :size => column.options[:size]))
210
210
  end
211
-
211
+
212
212
  def active_scaffold_input_virtual(column, options)
213
213
  options = active_scaffold_input_text_options(options)
214
214
  text_field :record, column.name, options.merge(column.options)
@@ -90,7 +90,7 @@ module ActiveScaffold
90
90
  options[:action] ||= params[:action]
91
91
  clean_id "#{controller_id}-#{options[:action]}-#{options[:id]}-loading-indicator"
92
92
  end
93
-
93
+
94
94
  def sub_section_id(options = {})
95
95
  options[:id] ||= params[:id]
96
96
  options[:id] ||= params[:parent_id]
@@ -102,7 +102,7 @@ module ActiveScaffold
102
102
  options[:id] ||= params[:parent_id]
103
103
  clean_id "#{controller_id}-#{options[:id]}-#{options[:association]}-subform"
104
104
  end
105
-
105
+
106
106
  def sub_form_list_id(options = {})
107
107
  options[:id] ||= params[:id]
108
108
  options[:id] ||= params[:parent_id]
@@ -59,7 +59,7 @@ module ActiveScaffold
59
59
  associated = options.delete :value
60
60
  associated = [associated].compact unless associated.is_a? Array
61
61
  associated.collect!(&:to_i)
62
-
62
+
63
63
  if column.association
64
64
  select_options = options_for_association(column.association, false)
65
65
  else
@@ -86,7 +86,7 @@ module ActiveScaffold
86
86
  if html_options[:multiple]
87
87
  html_options[:name] += '[]'
88
88
  else
89
- options[:include_blank] ||= as_(:_select_)
89
+ options[:include_blank] ||= as_(:_select_)
90
90
  end
91
91
  select(:record, method, select_options, options, html_options)
92
92
  end
@@ -107,7 +107,7 @@ module ActiveScaffold
107
107
  end
108
108
  # we can't use checkbox ui because it's not possible to decide whether search for this field or not
109
109
  alias_method :active_scaffold_search_checkbox, :active_scaffold_search_boolean
110
-
110
+
111
111
  def active_scaffold_search_null(column, options)
112
112
  select_options = []
113
113
  select_options << [as_(:_select_), nil]
@@ -148,9 +148,9 @@ module ActiveScaffold
148
148
  value = field_search_record_select_value(column)
149
149
  active_scaffold_record_select(column, options, value, column.options[:multiple])
150
150
  end
151
-
151
+
152
152
  def field_search_record_select_value(column)
153
- begin
153
+ begin
154
154
  value = field_search_params[column.name]
155
155
  unless value.blank?
156
156
  if column.options[:multiple]
@@ -168,13 +168,13 @@ module ActiveScaffold
168
168
  def field_search_datetime_value(value)
169
169
  DateTime.new(value[:year].to_i, value[:month].to_i, value[:day].to_i, value[:hour].to_i, value[:minute].to_i, value[:second].to_i) unless value.nil? || value[:year].blank?
170
170
  end
171
-
171
+
172
172
  def active_scaffold_search_datetime(column, options)
173
173
  opt_value, from_value, to_value = field_search_params_range_values(column)
174
174
  options = column.options.merge(options)
175
175
  helper = "select_#{'date' unless options[:discard_date]}#{'time' unless options[:discard_time]}"
176
-
177
- send(helper, field_search_datetime_value(from_value), {:include_blank => true, :prefix => "#{options[:name]}[from]"}.merge(options)) <<
176
+
177
+ send(helper, field_search_datetime_value(from_value), {:include_blank => true, :prefix => "#{options[:name]}[from]"}.merge(options)) <<
178
178
  ' - '.html_safe << send(helper, field_search_datetime_value(to_value), {:include_blank => true, :prefix => "#{options[:name]}[to]"}.merge(options))
179
179
  end
180
180
 
@@ -207,9 +207,9 @@ module ActiveScaffold
207
207
  def override_search(form_ui)
208
208
  "active_scaffold_search_#{form_ui}"
209
209
  end
210
-
210
+
211
211
  def visibles_and_hiddens(search_config)
212
- visibles = []
212
+ visibles = []
213
213
  hiddens = []
214
214
  search_config.columns.each do |column|
215
215
  next unless column.search_sql
@@ -221,7 +221,7 @@ module ActiveScaffold
221
221
  end
222
222
  return visibles, hiddens
223
223
  end
224
-
224
+
225
225
  def searched_by?(column)
226
226
  value = field_search_params[column.name]
227
227
  case value
@@ -64,7 +64,7 @@ module ActiveScaffold
64
64
  def form_remote_upload_tag(url_for_options = {}, options = {})
65
65
  options[:target] = action_iframe_id(url_for_options)
66
66
  options[:multipart] ||= true
67
- options[:class] = "#{options[:class]} as_remote_upload".strip
67
+ options[:class] = "#{options[:class]} as_remote_upload".strip
68
68
  output=""
69
69
  output << form_tag(url_for_options, options)
70
70
  (output << "<iframe id='#{action_iframe_id(url_for_options)}' name='#{action_iframe_id(url_for_options)}' style='display:none'></iframe>").html_safe
@@ -78,13 +78,13 @@ module ActiveScaffold
78
78
  ActiveScaffold::Config::Core.asset_path(name, frontend)
79
79
  end
80
80
  end
81
-
81
+
82
82
  # Provides stylesheets to include with +stylesheet_link_tag+
83
83
  def active_scaffold_stylesheets(frontend = :default)
84
84
  [ActiveScaffold::Config::Core.asset_path("stylesheet.css", frontend)]
85
85
  end
86
86
 
87
- # Provides stylesheets for IE to include with +stylesheet_link_tag+
87
+ # Provides stylesheets for IE to include with +stylesheet_link_tag+
88
88
  def active_scaffold_ie_stylesheets(frontend = :default)
89
89
  [ActiveScaffold::Config::Core.asset_path("stylesheet-ie.css", frontend)]
90
90
  end
@@ -113,7 +113,7 @@ module ActiveScaffold
113
113
  # You may also flag whether the other element is visible by default or not, and the initial text will adjust accordingly.
114
114
  def link_to_visibility_toggle(id, options = {})
115
115
  options[:default_visible] = true if options[:default_visible].nil?
116
- options[:hide_label] = as_(:hide)
116
+ options[:hide_label] = as_(:hide)
117
117
  options[:show_label] = as_(:show)
118
118
  javascript_tag("ActiveScaffold.create_visibility_toggle('#{id}', #{options.to_json});")
119
119
  end
@@ -127,7 +127,7 @@ module ActiveScaffold
127
127
  html_options = action_link_html_options(link, url_options, record, html_options)
128
128
  action_link_html(link, url_options, html_options)
129
129
  end
130
-
130
+
131
131
  def action_link_url_options(link, url_options, record, options = {})
132
132
  url_options = url_options.clone
133
133
  url_options[:action] = link.action
@@ -138,12 +138,12 @@ module ActiveScaffold
138
138
  url_options[:_method] = link.method if link.inline? && link.method != :get
139
139
  url_options
140
140
  end
141
-
141
+
142
142
  def action_link_html_options(link, url_options, record, html_options)
143
143
  link_id = get_action_link_id(url_options, record, link.column)
144
144
  html_options.reverse_merge! link.html_options.merge(:class => link.action)
145
145
 
146
- # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails
146
+ # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails
147
147
  html_options[:method] = link.method if !link.inline? && link.method != :get
148
148
 
149
149
  html_options['data-confirm'] = link.confirm(record.try(:to_label)) if link.confirm?
@@ -172,10 +172,10 @@ module ActiveScaffold
172
172
  action_id = "#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}#{url_options[:action].to_s}"
173
173
  action_link_id(action_id, id)
174
174
  end
175
-
175
+
176
176
  def action_link_html(link, url, html_options)
177
177
  # issue 260, use url_options[:link] if it exists. This prevents DB data from being localized.
178
- label = url.delete(:link) if url.is_a?(Hash)
178
+ label = url.delete(:link) if url.is_a?(Hash)
179
179
  label ||= link.label
180
180
  if link.image.nil?
181
181
  html = link_to(label, url, html_options)
@@ -183,11 +183,11 @@ module ActiveScaffold
183
183
  html = link_to(image_tag(link.image[:name] , :size => link.image[:size], :alt => label), url, html_options)
184
184
  end
185
185
  # if url is nil we would like to generate an anchor without href attribute
186
- url.nil? ? html.sub(/href=".*?"/, '') : html
186
+ url.nil? ? html.sub(/href=".*?"/, '') : html
187
187
  end
188
-
188
+
189
189
  def url_options_for_nested_link(column, record, link, url_options, options = {})
190
- if column && column.association
190
+ if column && column.association
191
191
  url_options[:assoc_id] = url_options.delete(:id)
192
192
  url_options[:id] = record.send(column.association.name).id if column.singular_association? && record.send(column.association.name).present?
193
193
  link.eid = "#{controller_id.from(3)}_#{record.id}_#{column.association.name}" unless options.has_key?(:reuse_eid)
@@ -208,13 +208,13 @@ module ActiveScaffold
208
208
  else
209
209
  classes << column.css_class
210
210
  end unless column.css_class.nil?
211
-
211
+
212
212
  classes << 'empty' if column_empty? column_value
213
213
  classes << 'sorted' if active_scaffold_config.list.user.sorting.sorts_on?(column)
214
214
  classes << 'numeric' if column.column and [:decimal, :float, :integer].include?(column.column.type)
215
215
  classes.join(' ').rstrip
216
216
  end
217
-
217
+
218
218
  def column_heading_class(column, sorting)
219
219
  classes = []
220
220
  classes << "#{column.name}-column_heading"
@@ -255,7 +255,7 @@ module ActiveScaffold
255
255
  value = false unless record.class.authorized_for?(:crud_type => :create)
256
256
  value
257
257
  end
258
-
258
+
259
259
  def error_messages_for(*params)
260
260
  options = params.extract_options!.symbolize_keys
261
261
 
@@ -1,16 +1,16 @@
1
1
  module ActiveScaffold
2
2
  module MarkedModel
3
3
  # This is a module aimed at making the make session_stored marked_records available to ActiveRecord models
4
-
4
+
5
5
  def self.included(base)
6
6
  base.extend ClassMethods
7
7
  base.scope :marked, lambda {{:conditions => {:id => base.marked_records.to_a}}}
8
8
  end
9
-
9
+
10
10
  def marked
11
11
  marked_records.include?(self.id)
12
12
  end
13
-
13
+
14
14
  def marked=(value)
15
15
  value = [true, 'true', 1, '1', 'T', 't'].include?(value.class == String ? value.downcase : value)
16
16
  if value == true
@@ -19,17 +19,17 @@ module ActiveScaffold
19
19
  marked_records.delete(self.id)
20
20
  end
21
21
  end
22
-
22
+
23
23
  module ClassMethods
24
24
  # The proc to call that retrieves the marked_records from the ApplicationController.
25
25
  attr_accessor :marked_records_proc
26
-
26
+
27
27
  # Class-level access to the marked_records
28
28
  def marked_records
29
29
  (marked_records_proc.call || Set.new) if marked_records_proc
30
30
  end
31
31
  end
32
-
32
+
33
33
  # Instance-level access to the marked_records
34
34
  def marked_records
35
35
  self.class.marked_records
@@ -58,10 +58,10 @@ module ActionView::Rendering #:nodoc:
58
58
  session["as:#{eid}"] = {:constraints => constraints, :conditions => conditions, :list => {:label => args.first[:label]}}
59
59
  options[:params] ||= {}
60
60
  options[:params].merge! :eid => eid, :embedded => true
61
-
61
+
62
62
  id = "as_#{eid}-content"
63
63
  url_options = {:controller => remote_controller.to_s, :action => 'index'}.merge(options[:params])
64
-
64
+
65
65
  if respond_to? :render_component
66
66
  render_component url_options
67
67
  else
@@ -75,7 +75,7 @@ module ActionView::Rendering #:nodoc:
75
75
  end
76
76
  end
77
77
  end
78
-
78
+
79
79
  else
80
80
  options = args.first
81
81
  if options.is_a?(Hash)
@@ -87,7 +87,7 @@ module ActionView::Rendering #:nodoc:
87
87
  end
88
88
  end
89
89
  alias_method_chain :render, :active_scaffold
90
-
90
+
91
91
 
92
92
  def partial_pieces(partial_path)
93
93
  if partial_path.include?('/')
@@ -96,7 +96,7 @@ module ActionView::Rendering #:nodoc:
96
96
  return controller.class.controller_path, partial_path
97
97
  end
98
98
  end
99
-
99
+
100
100
  # This is the template finder logic, keep it updated with however we find stuff in rails
101
101
  # currently this very similar to the logic in ActionBase::Base.render for options file
102
102
  # TODO: Work with rails core team to find a better way to check for this.
@@ -1,12 +1,12 @@
1
1
  # Bugfix: Team.offset(1).limit(1) throws an error
2
2
  ActiveRecord::Base.instance_eval do
3
- def offset(*args, &block)
3
+ def offset(*args, &block)
4
4
  scoped.__send__(:offset, *args, &block)
5
- rescue NoMethodError
6
- if scoped.nil?
5
+ rescue NoMethodError
6
+ if scoped.nil?
7
7
  'depends on :allow_nil'
8
- else
9
- raise
10
- end
11
- end
8
+ else
9
+ raise
10
+ end
11
+ end
12
12
  end
@@ -4,7 +4,7 @@ class Object
4
4
  text = I18n.translate "#{key}", {:scope => [:active_scaffold], :default => key.is_a?(String) ? key : key.to_s.titleize}.merge(options)
5
5
  # text = nil if text.include?('translation missing:')
6
6
  end
7
- text ||= key
7
+ text ||= key
8
8
  text
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module ActionView
4
4
  private
5
5
  def datetime_selector_with_name(options, html_options)
6
6
  options.merge!(:prefix => options[:name].gsub(/\[[^\[]*\]$/,'')) if options[:name]
7
- datetime_selector_without_name(options, html_options)
7
+ datetime_selector_without_name(options, html_options)
8
8
  end
9
9
  alias_method_chain :datetime_selector, :name
10
10
  end
@@ -7,12 +7,12 @@ class Paginator
7
7
  number_of_pages_without_infinite unless infinite?
8
8
  end
9
9
  alias_method_chain :number_of_pages, :infinite
10
-
10
+
11
11
  # Is this an "infinite" paginator
12
12
  def infinite?
13
13
  @count.nil?
14
14
  end
15
-
15
+
16
16
  class Page
17
17
  # Checks to see if there's a page after this one
18
18
  def next_with_infinite?
@@ -2,7 +2,7 @@ module ActiveRecord
2
2
  module Reflection
3
3
  class AssociationReflection #:nodoc:
4
4
  def reverse_for?(klass)
5
- reverse_matches_for(klass).empty? ? false : true
5
+ ! reverse_matches_for(klass).empty?
6
6
  end
7
7
 
8
8
  attr_writer :reverse
@@ -19,9 +19,9 @@ module ActionDispatch
19
19
  end
20
20
  as_association_routes if options[:association]
21
21
  end
22
-
22
+
23
23
  def as_association_routes
24
- collection do
24
+ collection do
25
25
  ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:collection].each {|name, type| send(type, name)}
26
26
  end
27
27
  member do
@@ -2,16 +2,20 @@ module ActionView
2
2
  module Helpers
3
3
  module FormOptionsHelper
4
4
 
5
- # Return a full select and option tags for the given object and method, using usa_state_options_for_select to generate the list of option <tags>.
5
+ # Return a full select and option tags for the given object and
6
+ # method, using usa_state_options_for_select to generate the
7
+ # list of option <tags>.
6
8
  def usa_state_select(object, method, priority_states = nil, options = {}, html_options = {})
7
9
  InstanceTag.new(object, method, self, options.delete(:object)).to_usa_state_select_tag(priority_states, options, html_options)
8
10
  end
9
-
10
11
 
11
- # Returns a string of option tags for the states in the United States. Supply a state name as +selected to
12
- # have it marked as the selected option tag. Included also is the option to set a couple of +priority_states+
13
- # in case you want to highligh a local area
14
- # NOTE: Only the option tags are returned from this method, wrap it in a <select>
12
+
13
+ # Returns a string of option tags for the states in the United
14
+ # States. Supply a state name as +selected to have it marked as
15
+ # the selected option tag. Included also is the option to set a
16
+ # couple of +priority_states+ in case you want to highligh a
17
+ # local area. NOTE: Only the option tags are returned from this
18
+ # method, wrap it in a <select>
15
19
  def usa_state_options_for_select(selected = nil, priority_states = nil)
16
20
  state_options = ""
17
21
  if priority_states
@@ -28,13 +32,13 @@ module ActionView
28
32
  return state_options
29
33
  end
30
34
 
31
- USASTATES = [["Alabama", "AL"], ["Alaska", "AK"], ["Arizona", "AZ"], ["Arkansas", "AR"], ["California", "CA"], ["Colorado", "CO"], ["Connecticut", "CT"], ["Delaware", "DE"], ["District of Columbia", "DC"], ["Florida", "FL"], ["Georgia", "GA"], ["Hawaii", "HI"], ["Idaho", "ID"], ["Illinois", "IL"], ["Indiana", "IN"], ["Iowa", "IA"], ["Kansas", "KS"], ["Kentucky", "KY"], ["Louisiana", "LA"], ["Maine", "ME"], ["Maryland", "MD"], ["Massachusetts", "MA"], ["Michigan", "MI"], ["Minnesota", "MN"], ["Mississippi", "MS"], ["Missouri", "MO"], ["Montana", "MT"], ["Nebraska", "NE"], ["Nevada", "NV"], ["New Hampshire", "NH"], ["New Jersey", "NJ"], ["New Mexico", "NM"], ["New York", "NY"], ["North Carolina", "NC"], ["North Dakota", "ND"], ["Ohio", "OH"], ["Oklahoma", "OK"], ["Oregon", "OR"], ["Pennsylvania", "PA"], ["Rhode Island", "RI"], ["South Carolina", "SC"], ["South Dakota", "SD"], ["Tennessee", "TN"], ["Texas", "TX"], ["Utah", "UT"], ["Vermont", "VT"], ["Virginia", "VA"], ["Washington", "WA"], ["Wisconsin", "WI"], ["West Virginia", "WV"], ["Wyoming", "WY"]] unless const_defined?("USASTATES")
32
-
35
+ USASTATES = [["Alabama", "AL"], ["Alaska", "AK"], ["Arizona", "AZ"], ["Arkansas", "AR"], ["California", "CA"], ["Colorado", "CO"], ["Connecticut", "CT"], ["Delaware", "DE"], ["District of Columbia", "DC"], ["Florida", "FL"], ["Georgia", "GA"], ["Hawaii", "HI"], ["Idaho", "ID"], ["Illinois", "IL"], ["Indiana", "IN"], ["Iowa", "IA"], ["Kansas", "KS"], ["Kentucky", "KY"], ["Louisiana", "LA"], ["Maine", "ME"], ["Maryland", "MD"], ["Massachusetts", "MA"], ["Michigan", "MI"], ["Minnesota", "MN"], ["Mississippi", "MS"], ["Missouri", "MO"], ["Montana", "MT"], ["Nebraska", "NE"], ["Nevada", "NV"], ["New Hampshire", "NH"], ["New Jersey", "NJ"], ["New Mexico", "NM"], ["New York", "NY"], ["North Carolina", "NC"], ["North Dakota", "ND"], ["Ohio", "OH"], ["Oklahoma", "OK"], ["Oregon", "OR"], ["Pennsylvania", "PA"], ["Rhode Island", "RI"], ["South Carolina", "SC"], ["South Dakota", "SD"], ["Tennessee", "TN"], ["Texas", "TX"], ["Utah", "UT"], ["Vermont", "VT"], ["Virginia", "VA"], ["Washington", "WA"], ["Wisconsin", "WI"], ["West Virginia", "WV"], ["Wyoming", "WY"]] unless const_defined?("USASTATES")
36
+
33
37
  end
34
-
38
+
35
39
  class InstanceTag #:nodoc:
36
40
  include FormOptionsHelper
37
-
41
+
38
42
  def to_usa_state_select_tag(priority_states, options, html_options)
39
43
  html_options = html_options.stringify_keys
40
44
  add_default_name_and_id(html_options)
@@ -43,4 +47,4 @@ module ActionView
43
47
  end
44
48
  end
45
49
  end
46
- end
50
+ end