Class: AdminAssistant::ActiveRecordColumn::FormView

Inherits:
Column::View
  • Object
show all
Includes:
Column::FormViewMethods
Defined in:
lib/admin_assistant/active_record_column.rb

Instance Attribute Summary

Attributes inherited from Column::View

#sort_order

Instance Method Summary collapse

Methods included from Column::FormViewMethods

#after_html, #description, #errors, #field_id, #html, #html_from_helper_method, #render_from_custom_template, #set_instance_variables_from_options

Methods inherited from Column::View

#check_box_and_hidden_tags, #controller, #custom_template_file_path, #file_option_for_custom_template_render, #initialize, #label, #name, #paperclip?, #sort_possible?, #string, #value

Constructor Details

This class inherits a constructor from AdminAssistant::Column::View

Instance Method Details

#check_box_html(form) ⇒ Object



152
153
154
# File 'lib/admin_assistant/active_record_column.rb', line 152

def check_box_html(form)
  form.check_box name
end

#date_select_html(form) ⇒ Object



156
157
158
159
160
# File 'lib/admin_assistant/active_record_column.rb', line 156

def date_select_html(form)
  form.date_select(
    name, {:include_blank => true}.merge(@date_select_options)
  )
end

#datetime_select_html(form) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/admin_assistant/active_record_column.rb', line 162

def datetime_select_html(form)
  opts = {:include_blank => true}.merge @datetime_select_options
  h = form.datetime_select name, opts
  if opts[:include_blank]
    js_name = "#{form.object.class.name.underscore}_#{name}"
    name = @clear_link || "Clear"
    h << @action_view.send(
      :link_to, name, '#',
      'data-prefix' => js_name, :class => 'clear_datetime_select'
    )
  end
  h
end

#default_html(form) ⇒ Object



176
177
178
179
# File 'lib/admin_assistant/active_record_column.rb', line 176

def default_html(form)
  input = @input || default_input
  self.send("#{input}_html", form)
end

#default_inputObject



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/admin_assistant/active_record_column.rb', line 181

def default_input
  if AdminAssistant.default_inputs[@column.field_type]
    AdminAssistant.default_inputs[@column.field_type]
  else
    case @column.field_type
      when :boolean
        :check_box
      when :date
        :date_select
      when :datetime
        :datetime_select
      when :text
        :text_area
      else
        :text_field
      end
  end
end

#ordered_us_state_names_and_codesObject



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/admin_assistant/active_record_column.rb', line 200

def ordered_us_state_names_and_codes
  {
    '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', 'Puerto Rico' => 'PR',
    'Rhode Island' => 'RI', 'South Carolina' => 'SC',
    'South Dakota' => 'SD', 'Tennessee' => 'TN', 'Texas' => 'TX',
    'Utah' => 'UT', 'Vermont' => 'VT', 'Virginia' => 'VA',
    'Washington' => 'WA', 'West Virginia' => 'WV', 'Wisconsin' => 'WI', 
    'Wyoming' => 'WY'
  }.sort_by { |name, code| name }
end

#select_html(form) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/admin_assistant/active_record_column.rb', line 224

def select_html(form)
  if @select_choices
    form.select name, @select_choices, @select_options
  else
    value = form.object.send name
    selected = if value
      '1'
    elsif value == false
      '0'
    end
    form.select(
      name, [[true, '1'], [false, '0']],
      @select_options.merge(:selected => selected)
    )
  end
end

#text_area_html(form) ⇒ Object



241
242
243
# File 'lib/admin_assistant/active_record_column.rb', line 241

def text_area_html(form)
  form.text_area name, @text_area_options
end

#text_field_html(form) ⇒ Object



245
246
247
# File 'lib/admin_assistant/active_record_column.rb', line 245

def text_field_html(form)
  form.text_field name
end

#us_state_html(form) ⇒ Object



249
250
251
252
253
# File 'lib/admin_assistant/active_record_column.rb', line 249

def us_state_html(form)
  form.select(
    name, ordered_us_state_names_and_codes, :include_blank => true
  )
end