Commit dd7e39a5dc2541c35f0477d89cab76961f1d8efc

Authored by Rodrigo Souto
2 parents adb0fcbf 80b720d8

Merge branch 'removes_date_field_formats' into 'master'

Removes date fields format customization

Aims to fix a bug where the _datepicker_ component was not able to correctly retrieve the date displayed in the text field due format compatibility. Since there is no reliable way to convert the formats (used by `strftime` and the _datepicker_), the option to customize the date format was removed from the `date_field` and `date_range_field` helpers.

See merge request !811
app/helpers/forms_helper.rb
... ... @@ -137,7 +137,7 @@ module FormsHelper
137 137 content_tag('table',rows.join("\n"))
138 138 end
139 139  
140   - def date_field(name, value, format = '%Y-%m-%d', datepicker_options = {}, html_options = {})
  140 + def date_field(name, value, datepicker_options = {}, html_options = {})
141 141 datepicker_options[:disabled] ||= false
142 142 datepicker_options[:alt_field] ||= ''
143 143 datepicker_options[:alt_format] ||= ''
... ... @@ -152,7 +152,7 @@ module FormsHelper
152 152 datepicker_options[:close_text] ||= _('Done')
153 153 datepicker_options[:constrain_input] ||= true
154 154 datepicker_options[:current_text] ||= _('Today')
155   - datepicker_options[:date_format] ||= 'yy/mm/dd'
  155 + datepicker_options[:date_format] ||= 'yy-mm-dd'
156 156 datepicker_options[:day_names] ||= [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')]
157 157 datepicker_options[:day_names_min] ||= [_('Su'), _('Mo'), _('Tu'), _('We'), _('Th'), _('Fr'), _('Sa')]
158 158 datepicker_options[:day_names_short] ||= [_('Sun'), _('Mon'), _('Tue'), _('Wed'), _('Thu'), _('Fri'), _('Sat')]
... ... @@ -184,10 +184,11 @@ module FormsHelper
184 184 datepicker_options[:year_range] ||= 'c-10:c+10'
185 185 datepicker_options[:year_suffix] ||= ''
186 186  
  187 + date_format = datepicker_options[:time] ? "%Y-%m-%d %H:%M" : "%Y-%m-%d"
  188 + value = value.strftime(date_format) if value.present?
  189 +
187 190 element_id = html_options[:id] || 'datepicker-date'
188   - value = value.strftime(format) if value.present?
189 191 method = datepicker_options[:time] ? 'datetimepicker' : 'datepicker'
190   - current_date_or_nil = value.present? ? "new Date('#{value}')" : "null"
191 192 result = text_field_tag(name, value, html_options)
192 193 result +=
193 194 "
... ... @@ -238,17 +239,17 @@ module FormsHelper
238 239 weekHeader: #{datepicker_options[:week_header].to_json},
239 240 yearRange: #{datepicker_options[:year_range].to_json},
240 241 yearSuffix: #{datepicker_options[:year_suffix].to_json}
241   - }).datepicker('setDate', current_date_or_nil)
  242 + }).datepicker()
242 243 </script>
243 244 ".html_safe
244 245 result
245 246 end
246 247  
247   - def date_range_field(from_name, to_name, from_value, to_value, format = '%Y-%m-%d', datepicker_options = {}, html_options = {})
  248 + def date_range_field(from_name, to_name, from_value, to_value, datepicker_options = {}, html_options = {})
248 249 from_id = html_options[:from_id] || 'datepicker-from-date'
249 250 to_id = html_options[:to_id] || 'datepicker-to-date'
250   - return _('From') +' '+ date_field(from_name, from_value, format, datepicker_options, html_options.merge({:id => from_id})) +
251   - ' ' + _('until') +' '+ date_field(to_name, to_value, format, datepicker_options, html_options.merge({:id => to_id}))
  251 + return _('From') +' '+ date_field(from_name, from_value, datepicker_options, html_options.merge({:id => from_id})) +
  252 + ' ' + _('until') +' '+ date_field(to_name, to_value, datepicker_options, html_options.merge({:id => to_id}))
252 253 end
253 254  
254 255 def select_folder(label_text, field_id, collection, default_value=nil, html_options = {}, js_options = {})
... ...
app/views/cms/_event.html.erb
... ... @@ -8,7 +8,7 @@
8 8 <%= render :partial => 'general_fields' %>
9 9 <%= render :partial => 'translatable' %>
10 10  
11   -<%= date_range_field('article[start_date]', 'article[end_date]', @article.start_date, @article.end_date, _('%Y-%m-%d %H:%M'), {:time => true}, {:id => 'article_start_date'} ) %>
  11 +<%= date_range_field('article[start_date]', 'article[end_date]', @article.start_date, @article.end_date, {:time => true}, {:id => 'article_start_date'} ) %>
12 12  
13 13  
14 14 <%= labelled_form_field(_('Event website:'), text_field(:article, :link)) %>
... ...
app/views/cms/_text_fields.html.erb
1   -<%= labelled_form_field(_('Publish date'), date_field('article[published_at]', @article.published_at || DateTime.current, '%Y-%m-%d', {:max_date => '+0d', :date_format => 'yy-mm-dd'}, {:id => "article_published_at"})) %>
  1 +<%= labelled_form_field(_('Publish date'), date_field('article[published_at]', @article.published_at || DateTime.current, {:max_date => '+0d', :date_format => 'yy-mm-dd'}, {:id => "article_published_at"})) %>
... ...
app/views/custom_fields/_date.html.erb
1   -<%= labelled_form_field(field.name, date_field(name, profile.custom_value(field.name).to_date, '%Y-%m-%d', {:change_month => true, :change_year => true, :year_range => '-100:-5', :date_format => 'yy-mm-dd'}, {:id => field.name.parameterize.underscore}))%>
  1 +<%= labelled_form_field(field.name, date_field(name, profile.custom_value(field.name).to_date, {:change_month => true, :change_year => true, :year_range => '-100:-5', :date_format => 'yy-mm-dd'}, {:id => field.name.parameterize.underscore}))%>
... ...
app/views/profile_editor/_person_form.html.erb
... ... @@ -16,7 +16,7 @@
16 16 <%= optional_field(@person, 'jabber_id', f.text_field(:jabber_id, :rel => _('Jabber'))) %>
17 17 <%= optional_field(@person, 'personal_website', f.text_field(:personal_website, :rel => _('Personal website'))) %>
18 18 <%= optional_field(@person, 'sex', f.radio_group(:profile_data, :sex, [ ['male',_('Male')], ['female',_('Female')] ])) %>
19   -<%= optional_field(@person, 'birth_date', labelled_form_field(_('Birth date'), date_field('profile_data[birth_date]', @profile_data. birth_date, '%Y-%m-%d', {:change_month => true, :change_year => true, :year_range => '-100:-5', :date_format => 'yy-mm-dd'}, {:id => 'profile_data_birth_date'}))) %>
  19 +<%= optional_field(@person, 'birth_date', labelled_form_field(_('Birth date'), date_field('profile_data[birth_date]', @profile_data. birth_date, {:change_month => true, :change_year => true, :year_range => '-100:-5', :date_format => 'yy-mm-dd'}, {:id => 'profile_data_birth_date'}))) %>
20 20 <%= optional_field(@person, 'nationality', f.text_field(:nationality, :rel => _('Nationality'))) %>
21 21 <%= optional_field(@person, 'country', select_country(_('Country'), 'profile_data', 'country', {:class => 'type-select'})) %>
22 22 <%= optional_field(@person, 'state', f.text_field(:state, :id => 'state_field', :rel => _('State'))) %>
... ...
plugins/community_track/views/cms/community_track_plugin/_step.html.erb
... ... @@ -6,7 +6,6 @@
6 6 <%= required f.text_field('name', :size => '64', :maxlength => 150) %>
7 7 <%= labelled_form_field(_('Period'), (
8 8 date_range_field('article[start_date]', 'article[end_date]', @article.start_date, @article.end_date,
9   - '%Y-%m-%d',
10 9 { :change_month => true, :change_year => true,
11 10 :date_format => 'yy-mm-dd' },
12 11 { :size => 14 })
... ...
plugins/custom_forms/views/custom_forms_plugin_myprofile/_form.html.erb
... ... @@ -5,7 +5,6 @@
5 5 <%= required labelled_form_field _('Name'), f.text_field(:name) %>
6 6 <%= labelled_form_field(_('What is the time limit for this form to be filled?'), (
7 7 date_range_field('form[begining]', 'form[ending]', @form.begining, @form.ending,
8   - '%Y/%m/%d %H:%M',
9 8 { :time => true, :change_month => true, :change_year => true,
10 9 :date_format => 'yy-mm-dd', :time_format => 'hh:mm' },
11 10 { :size => 14 })
... ...