Permalink
Browse files

Add support for DateSelectInput. Some other house cleaning comes

in with this.  (I'll try to make the commits tidier from here on
out.)
  • Loading branch information...
1 parent 98b29fb commit 08537411391137adf4fb1641aeef6144778a3d9b @mjbellantoni committed Sep 2, 2012
@@ -1,7 +1,6 @@
require "formtastic"
require "formtastic-bootstrap/engine" if defined?(::Rails) # For tests
require "formtastic-bootstrap/helpers"
-# require "formtastic-bootstrap/inputs"
require "formtastic-bootstrap/form_builder"
require "action_view/helpers/text_field_date_helper"
@@ -1,32 +1,36 @@
-require "formtastic-bootstrap/inputs/base"
-
-require "formtastic-bootstrap/inputs/date_input"
-require "formtastic-bootstrap/inputs/datetime_input"
-require "formtastic-bootstrap/inputs/email_input"
-require "formtastic-bootstrap/inputs/file_input"
-require "formtastic-bootstrap/inputs/hidden_input"
-require "formtastic-bootstrap/inputs/number_input"
-require "formtastic-bootstrap/inputs/password_input"
-require "formtastic-bootstrap/inputs/phone_input"
-require "formtastic-bootstrap/inputs/radio_input"
-require "formtastic-bootstrap/inputs/range_input"
-require "formtastic-bootstrap/inputs/search_input"
-require "formtastic-bootstrap/inputs/select_input"
-require "formtastic-bootstrap/inputs/string_input"
-require "formtastic-bootstrap/inputs/text_input"
-require "formtastic-bootstrap/inputs/time_input"
-require "formtastic-bootstrap/inputs/time_zone_input"
-require "formtastic-bootstrap/inputs/url_input"
-
module FormtasticBootstrap
module Inputs
- include Base # TODO: Understand why I need to do this.
- # autoload :Base, "formtastic-bootstrap/inputs/base"
+ autoload :Base, "formtastic-bootstrap/inputs/base"
+ # autoload :Basic
autoload :BooleanInput, "formtastic-bootstrap/inputs/boolean_input"
autoload :CheckBoxesInput, "formtastic-bootstrap/inputs/check_boxes_input"
- # autoload :DateSelectInput, "formtastic-bootstrap/inputs/date_select_input"
+ # autoload :CountryInput
+ # autoload :DateInput
+ # autoload :DatePickerInput
+ # autoload :DatetimePickerInput
+ autoload :DateSelectInput, "formtastic-bootstrap/inputs/date_select_input"
+ # autoload :DatetimeInput
+ # autoload :DatetimeSelectInput
+ # autoload :EmailInput
+ # autoload :FileInput
+ # autoload :HiddenInput
+ # autoload :NumberInput
+ # autoload :NumericInput
+ # autoload :PasswordInput
+ # autoload :PhoneInput
+ # autoload :RadioInput
+ # autoload :RangeInput
+ # autoload :SearchInput
+ # autoload :SelectInput
+ autoload :StringInput, "formtastic-bootstrap/inputs/string_input"
+ # autoload :TextInput
+ # autoload :TimeInput
+ # autoload :TimePickerInput
+ # autoload :TimeSelectInput
+ # autoload :TimeZoneInput
+ # autoload :Timeish
+ # autoload :UrlInput
end
end
-
@@ -1,22 +1,45 @@
-require "formtastic-bootstrap/inputs/base/choices"
require "formtastic-bootstrap/inputs/base/errors"
require "formtastic-bootstrap/inputs/base/hints"
require "formtastic-bootstrap/inputs/base/html"
require "formtastic-bootstrap/inputs/base/labelling"
-require "formtastic-bootstrap/inputs/base/stringish"
-require "formtastic-bootstrap/inputs/base/timeish"
-require "formtastic-bootstrap/inputs/base/wrapping"
module FormtasticBootstrap
module Inputs
module Base
+ # autoload :DatetimePickerish
+ # autoload :Associations
+ # autoload :Collections
+ # autoload :Choices
+ # autoload :Database
+ # autoload :Errors
+ # autoload :Fileish
+ # autoload :GroupedCollections
+ # autoload :Hints
+ # autoload :Html
+ # autoload :Labelling
+ # autoload :Naming
+ # autoload :Numeric
+ # autoload :Options
+ # autoload :Placeholder
+ autoload :Stringish, "formtastic-bootstrap/inputs/base/stringish"
+ autoload :Timeish, "formtastic-bootstrap/inputs/base/timeish"
+ # autoload :Validations
+ autoload :Wrapping, "formtastic-bootstrap/inputs/base/wrapping"
+
+ include Html
+ # include Options
+ # include Database
+ # include Database
include Errors
include Hints
- include Html
+ # include Naming
+ # include Validations
+ # include Fileish
+ # include Associations
include Labelling
include Wrapping
-
+
end
end
end
@@ -3,177 +3,51 @@ module Inputs
module Base
module Timeish
-
- # ORIGINAL FORMTASTIC BOOTSTRAP
+ def to_html
+ control_group_wrapping do
+ control_label_html <<
+ controls_wrapping do
+ hidden_fragments <<
+ fragments.map do |fragment|
+ fragment_input_html(fragment)
+ end.join.html_safe
+ end
+ end
+ end
- # def label_html
- # # TODO Supress the "for" field?
- # template.content_tag(:label, label_html_options) do
- # render_label? ? label_text : "".html_safe
- # end
- # end
- #
- # def date_input_html
- # fragment_input_html(:date, "small")
- # end
- #
- # def time_input_html
- # fragment_input_html(:time, "mini")
- # end
- #
- # def fragment_id(fragment)
- # # TODO is this right?
- # # "#{input_html_options[:id]}_#{position(fragment)}i"
- # "#{input_html_options[:id]}[#{fragment}]"
- # end
- #
- # def fragment_input_html(fragment, klass)
- # opts = input_options.merge(:prefix => object_name, :field_name => fragment_name(fragment), :default => value, :include_blank => include_blank?)
- # template.send(:"text_field_#{fragment}", value, opts, input_html_options.merge(:id => fragment_id(fragment), :class => klass))
- # end
+ def controls_wrapper_html_options
+ super.tap do |options|
+ options[:class] = (options[:class].split << "controls-row").join(" ")
+ end
+ end
+ def fragment_input_html(fragment)
+ opts = input_options.merge(:prefix => fragment_prefix, :field_name => fragment_name(fragment), :default => value, :include_blank => include_blank?)
+ template.send(:"select_#{fragment}", value, opts, fragment_input_html_options(fragment))
+ end
- # ORIGINAL FORMTASTIC
-
- # def to_html
- # input_wrapping do
- # fragments_wrapping do
- # hidden_fragments <<
- # fragments_label <<
- # template.content_tag(:ol,
- # fragments.map do |fragment|
- # fragment_wrapping do
- # fragment_label_html(fragment) <<
- # fragment_input_html(fragment)
- # end
- # end.join.html_safe, # TODO is this safe?
- # { :class => 'fragments-group' } # TODO refactor to fragments_group_wrapping
- # )
- # end
- # end
- # end
- #
- # def fragments
- # date_fragments + time_fragments
- # end
- #
- # def time_fragments
- # options[:include_seconds] ? [:hour, :minute, :second] : [:hour, :minute]
- # end
- #
- # def date_fragments
- # options[:order] || i18n_date_fragments || default_date_fragments
- # end
- #
- # def default_date_fragments
- # [:year, :month, :day]
- # end
- #
- # def fragment_wrapping(&block)
- # template.content_tag(:li, template.capture(&block), fragment_wrapping_html_options)
- # end
- #
- # def fragment_wrapping_html_options
- # { :class => 'fragment' }
- # end
- #
- # def fragment_label(fragment)
- # labels_from_options = options[:labels] || {}
- # if labels_from_options.key?(fragment)
- # labels_from_options[fragment]
- # else
- # ::I18n.t(fragment.to_s, :default => fragment.to_s.humanize, :scope => [:datetime, :prompts])
- # end
- # end
- #
- # def fragment_id(fragment)
- # "#{input_html_options[:id]}_#{position(fragment)}i"
- # end
- #
- # def fragment_name(fragment)
- # "#{method}(#{position(fragment)}i)"
- # end
- #
- # def fragment_label_html(fragment)
- # text = fragment_label(fragment)
- # text.blank? ? "".html_safe : template.content_tag(:label, text, :for => fragment_id(fragment))
- # end
- #
- # def value
- # object.send(method) if object && object.respond_to?(method)
- # end
- #
- # def fragment_input_html(fragment)
- # opts = input_options.merge(:prefix => fragment_prefix, :field_name => fragment_name(fragment), :default => value, :include_blank => include_blank?)
- # template.send(:"select_#{fragment}", value, opts, input_html_options.merge(:id => fragment_id(fragment)))
- # end
- #
- # def fragment_prefix
- # if builder.options.key?(:index)
- # object_name + "[#{builder.options[:index]}]"
- # else
- # object_name
- # end
- # end
- #
- # # TODO extract to BlankOptions or similar -- Select uses similar code
- # def include_blank?
- # options.key?(:include_blank) ? options[:include_blank] : builder.include_blank_for_select_by_default
- # end
- #
- # def positions
- # { :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :second => 6 }
- # end
- #
- # def position(fragment)
- # positions[fragment]
- # end
- #
- # def i18n_date_fragments
- # order = ::I18n.t(:order, :scope => [:date])
- # order = nil unless order.is_a?(Array)
- # order
- # end
- #
- # def fragments_wrapping(&block)
- # template.content_tag(:fieldset,
- # template.capture(&block).html_safe,
- # fragments_wrapping_html_options
- # )
- # end
- #
- # def fragments_wrapping_html_options
- # { :class => "fragments" }
- # end
- #
- # def fragments_label
- # if render_label?
- # template.content_tag(:legend,
- # builder.label(method, label_text, :for => fragment_id(fragments.first)),
- # :class => "label"
- # )
- # else
- # "".html_safe
- # end
- # end
- #
- # def fragments_inner_wrapping(&block)
- # template.content_tag(:ol,
- # template.capture(&block)
- # )
- # end
- #
- # def hidden_fragments
- # "".html_safe
- # end
- #
- # def hidden_field_name(fragment)
- # if builder.options.key?(:index)
- # "#{object_name}[#{builder.options[:index]}][#{fragment_name(fragment)}]"
- # else
- # "#{object_name}[#{fragment_name(fragment)}]"
- # end
- # end
+ def fragment_input_html_options(fragment)
+ input_html_options.tap do |options|
+ options[:id] = fragment_id(fragment)
+ options[:class] = ((options[:class] || "").split << fragment_class(fragment)).join(" ")
+ options[:placeholder] = fragment_placeholder(fragment)
+ end
+ end
+
+ def fragment_class(fragment)
+ {
+ :year => "span1",
+ :month => "span2",
+ :day => "span1",
+ :hour => "span1",
+ :minute => "span1",
+ :second => "span1"
+ }[fragment]
+ end
+
+ def fragment_placeholder(fragment)
+ "." + fragment_class(fragment)
+ end
end
end
@@ -28,10 +28,16 @@ def control_group_wrapping(&block)
end
def controls_wrapping(&block)
- template.content_tag(:div, template.capture(&block).html_safe, {:class => "controls"})
+ template.content_tag(:div, template.capture(&block).html_safe, controls_wrapper_html_options)
# I think error_html and hint_html will move here.
end
+ def controls_wrapper_html_options
+ {
+ :class => "controls"
+ }
+ end
+
def wrapper_html_options
super.tap do |options|
options[:class] << " control-group"
@@ -0,0 +1,38 @@
+$stderr.puts "THIS A"
+module FormtasticBootstrap
+ $stderr.puts "THIS B"
+ module Inputs
+ $stderr.puts "THIS C"
+
+ class DateSelectInput < Formtastic::Inputs::DateSelectInput
+ $stderr.puts "THIS D"
+ include Base
+ $stderr.puts "THIS E"
+ include Base::Timeish
+ $stderr.puts "THIS F"
+
+ # We don't want hour and minute fragments on a date input
+ # def time_fragments
+ # []
+ # end
+ #
+ # def hidden_date_fragments
+ # default_date_fragments - date_fragments
+ # end
+ #
+ # def hidden_fragments
+ # hidden_date_fragments.map do |fragment|
+ # template.hidden_field_tag(hidden_field_name(fragment), fragment_value(fragment), :id => fragment_id(fragment), :disabled => input_html_options[:disabled] )
+ # end.join.html_safe
+ # end
+ #
+ # def fragment_value(fragment)
+ # if fragment == :year
+ # Time.now.year
+ # else
+ # '1'
+ # end
+ # end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 0853741

Please sign in to comment.