Module: Zena::Use::Dates::FormTags
- Included in:
- ViewMethods
- Defined in:
- lib/zena/use/dates.rb
Instance Method Summary collapse
-
#date_box(obj, name, opts = {}) ⇒ Object
Date selection tool.
Instance Method Details
#date_box(obj, name, opts = {}) ⇒ Object
Date selection tool. TODO: make it work with form_helper: <%= f.date_box(:event_at) %>
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/zena/use/dates.rb', line 122 def date_box(obj, name, opts = {}) rnd_id = rand(100000000000) defaults = { :id=>"datef#{rnd_id}", :button=>"dateb#{rnd_id}", :display=>"dated#{rnd_id}" } opts = defaults.merge(opts) date = opts[:value] || obj.safe_send(name) showsTime = opts[:time] || 'true' # TODO: could we pass the format from the view so that it is # translated with the view's dictionary during compilation ? dateFormat = showsTime == 'true' ? _('datetime') : _('long_date') value = format_date(date, :format => dateFormat) # TODO: migrate code to Zafu::Markup (needs Zafu 0.7.7) # fld = Zafu::Markup.new('input') # fld.params = (opts[:html] || {}).merge(:name => "node[#{name}]", :id => opts[:id], :type => 'text', :value => value) if opts[:size] fld = "<input id='#{opts[:id]}' name='#{name}' type='text' size='#{opts[:size]}' value='#{value}' class='#{opts[:class]}'/>" else fld = "<input id='#{opts[:id]}' name='#{name}' type='text' value='#{value}' class='#{opts[:class]}'/>" end if onUpdate = opts[:onUpdate] onUpdate = "onUpdate : #{onUpdate}," end js_data << %Q{Calendar.setup({ inputField : "#{opts[:id]}", // id of the input field button : "#{opts[:button]}", // trigger for the calendar (button ID) singleClick : true,#{onUpdate} showsTime : #{showsTime}, ifFormat : '#{dateFormat}' });} <<-EOL <span class="date_box"><img src="/calendar/iconCalendar.gif" id="#{opts[:]}" alt='#{_('date selection')}'/> #{fld}</span> EOL end |