diff --git a/app/helpers/forms_helper.rb b/app/helpers/forms_helper.rb index c0641cd..4ffd205 100644 --- a/app/helpers/forms_helper.rb +++ b/app/helpers/forms_helper.rb @@ -137,7 +137,7 @@ module FormsHelper content_tag('table',rows.join("\n")) end - def date_field(name, value, format = '%Y-%m-%d', datepicker_options = {}, html_options = {}) + def date_field(name, value, datepicker_options = {}, html_options = {}) datepicker_options[:disabled] ||= false datepicker_options[:alt_field] ||= '' datepicker_options[:alt_format] ||= '' @@ -152,7 +152,7 @@ module FormsHelper datepicker_options[:close_text] ||= _('Done') datepicker_options[:constrain_input] ||= true datepicker_options[:current_text] ||= _('Today') - datepicker_options[:date_format] ||= 'yy/mm/dd' + datepicker_options[:date_format] ||= 'yy-mm-dd' datepicker_options[:day_names] ||= [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')] datepicker_options[:day_names_min] ||= [_('Su'), _('Mo'), _('Tu'), _('We'), _('Th'), _('Fr'), _('Sa')] datepicker_options[:day_names_short] ||= [_('Sun'), _('Mon'), _('Tue'), _('Wed'), _('Thu'), _('Fri'), _('Sat')] @@ -184,10 +184,11 @@ module FormsHelper datepicker_options[:year_range] ||= 'c-10:c+10' datepicker_options[:year_suffix] ||= '' + date_format = datepicker_options[:time] ? "%Y-%m-%d %H:%M" : "%Y-%m-%d" + value = value.strftime(date_format) if value.present? + element_id = html_options[:id] || 'datepicker-date' - value = value.strftime(format) if value.present? method = datepicker_options[:time] ? 'datetimepicker' : 'datepicker' - current_date_or_nil = value.present? ? "new Date('#{value}')" : "null" result = text_field_tag(name, value, html_options) result += " @@ -238,17 +239,17 @@ module FormsHelper weekHeader: #{datepicker_options[:week_header].to_json}, yearRange: #{datepicker_options[:year_range].to_json}, yearSuffix: #{datepicker_options[:year_suffix].to_json} - }).datepicker('setDate', current_date_or_nil) + }).datepicker() ".html_safe result end - def date_range_field(from_name, to_name, from_value, to_value, format = '%Y-%m-%d', datepicker_options = {}, html_options = {}) + def date_range_field(from_name, to_name, from_value, to_value, datepicker_options = {}, html_options = {}) from_id = html_options[:from_id] || 'datepicker-from-date' to_id = html_options[:to_id] || 'datepicker-to-date' - return _('From') +' '+ date_field(from_name, from_value, format, datepicker_options, html_options.merge({:id => from_id})) + - ' ' + _('until') +' '+ date_field(to_name, to_value, format, datepicker_options, html_options.merge({:id => to_id})) + return _('From') +' '+ date_field(from_name, from_value, datepicker_options, html_options.merge({:id => from_id})) + + ' ' + _('until') +' '+ date_field(to_name, to_value, datepicker_options, html_options.merge({:id => to_id})) end def select_folder(label_text, field_id, collection, default_value=nil, html_options = {}, js_options = {}) diff --git a/app/views/cms/_event.html.erb b/app/views/cms/_event.html.erb index 6db070a..1a9db6c 100644 --- a/app/views/cms/_event.html.erb +++ b/app/views/cms/_event.html.erb @@ -8,7 +8,7 @@ <%= render :partial => 'general_fields' %> <%= render :partial => 'translatable' %> -<%= 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'} ) %> +<%= date_range_field('article[start_date]', 'article[end_date]', @article.start_date, @article.end_date, {:time => true}, {:id => 'article_start_date'} ) %> <%= labelled_form_field(_('Event website:'), text_field(:article, :link)) %> diff --git a/app/views/cms/_text_fields.html.erb b/app/views/cms/_text_fields.html.erb index 96bb370..ca62fce 100644 --- a/app/views/cms/_text_fields.html.erb +++ b/app/views/cms/_text_fields.html.erb @@ -1 +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"})) %> +<%= 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"})) %> diff --git a/app/views/custom_fields/_date.html.erb b/app/views/custom_fields/_date.html.erb index 95bd803..907d890 100644 --- a/app/views/custom_fields/_date.html.erb +++ b/app/views/custom_fields/_date.html.erb @@ -1 +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}))%> +<%= 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}))%> diff --git a/app/views/profile_editor/_person_form.html.erb b/app/views/profile_editor/_person_form.html.erb index 19abfb0..ef09ab7 100644 --- a/app/views/profile_editor/_person_form.html.erb +++ b/app/views/profile_editor/_person_form.html.erb @@ -16,7 +16,7 @@ <%= optional_field(@person, 'jabber_id', f.text_field(:jabber_id, :rel => _('Jabber'))) %> <%= optional_field(@person, 'personal_website', f.text_field(:personal_website, :rel => _('Personal website'))) %> <%= optional_field(@person, 'sex', f.radio_group(:profile_data, :sex, [ ['male',_('Male')], ['female',_('Female')] ])) %> -<%= 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'}))) %> +<%= 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'}))) %> <%= optional_field(@person, 'nationality', f.text_field(:nationality, :rel => _('Nationality'))) %> <%= optional_field(@person, 'country', select_country(_('Country'), 'profile_data', 'country', {:class => 'type-select'})) %> <%= optional_field(@person, 'state', f.text_field(:state, :id => 'state_field', :rel => _('State'))) %> diff --git a/plugins/community_track/views/cms/community_track_plugin/_step.html.erb b/plugins/community_track/views/cms/community_track_plugin/_step.html.erb index a807569..d45ada8 100644 --- a/plugins/community_track/views/cms/community_track_plugin/_step.html.erb +++ b/plugins/community_track/views/cms/community_track_plugin/_step.html.erb @@ -6,7 +6,6 @@ <%= required f.text_field('name', :size => '64', :maxlength => 150) %> <%= labelled_form_field(_('Period'), ( date_range_field('article[start_date]', 'article[end_date]', @article.start_date, @article.end_date, - '%Y-%m-%d', { :change_month => true, :change_year => true, :date_format => 'yy-mm-dd' }, { :size => 14 }) diff --git a/plugins/custom_forms/views/custom_forms_plugin_myprofile/_form.html.erb b/plugins/custom_forms/views/custom_forms_plugin_myprofile/_form.html.erb index c2495e8..0273e9e 100644 --- a/plugins/custom_forms/views/custom_forms_plugin_myprofile/_form.html.erb +++ b/plugins/custom_forms/views/custom_forms_plugin_myprofile/_form.html.erb @@ -5,7 +5,6 @@ <%= required labelled_form_field _('Name'), f.text_field(:name) %> <%= labelled_form_field(_('What is the time limit for this form to be filled?'), ( date_range_field('form[begining]', 'form[ending]', @form.begining, @form.ending, - '%Y/%m/%d %H:%M', { :time => true, :change_month => true, :change_year => true, :date_format => 'yy-mm-dd', :time_format => 'hh:mm' }, { :size => 14 }) -- libgit2 0.21.2