Project

General

Profile

Patch #19468 » 0001-Use-HTML5-date-input-fields-instead-of-text-fields-w.patch

Jan from Planio www.plan.io, 2015-03-25 16:28

View differences:

app/helpers/application_helper.rb
1139 1139

  
1140 1140
  def calendar_for(field_id)
1141 1141
    include_calendar_headers_tags
1142
    javascript_tag("$(function() { $('##{field_id}').datepicker(datepickerOptions); });")
1142
    javascript_tag("$(function() { $('##{field_id}').datepickerFallback(datepickerOptions); });")
1143 1143
  end
1144 1144

  
1145 1145
  def include_calendar_headers_tags
app/views/custom_fields/formats/_date.html.erb
1
<p><%= f.text_field(:default_value, :size => 10) %></p>
1
<p><%= f.date_field(:default_value, :value => @custom_field.default_value, :size => 10) %></p>
2 2
<%= calendar_for('custom_field_default_value') %>
3 3
<p><%= f.text_field :url_pattern, :size => 50, :label => :label_link_values_to %></p>
app/views/issues/_attributes.html.erb
48 48

  
49 49
<% if @issue.safe_attribute? 'start_date' %>
50 50
<p id="start_date_area">
51
  <%= f.text_field(:start_date, :size => 10, :disabled => !@issue.leaf?,
51
  <%= f.date_field(:start_date, :size => 10, :disabled => !@issue.leaf?,
52 52
                   :required => @issue.required_attribute?('start_date')) %>
53 53
  <%= calendar_for('issue_start_date') if @issue.leaf? %>
54 54
</p>
......
56 56

  
57 57
<% if @issue.safe_attribute? 'due_date' %>
58 58
<p id="due_date_area">
59
  <%= f.text_field(:due_date, :size => 10, :disabled => !@issue.leaf?,
59
  <%= f.date_field(:due_date, :size => 10, :disabled => !@issue.leaf?,
60 60
                   :required => @issue.required_attribute?('due_date')) %>
61 61
  <%= calendar_for('issue_due_date') if @issue.leaf? %>
62 62
</p>
app/views/issues/bulk_edit.html.erb
147 147
<% if @safe_attributes.include?('start_date') %>
148 148
<p>
149 149
  <label for='issue_start_date'><%= l(:field_start_date) %></label>
150
  <%= text_field_tag 'issue[start_date]', '', :value => @issue_params[:start_date], :size => 10 %><%= calendar_for('issue_start_date') %>
150
  <%= date_field_tag 'issue[start_date]', '', :value => @issue_params[:start_date], :size => 10 %><%= calendar_for('issue_start_date') %>
151 151
  <label class="inline"><%= check_box_tag 'issue[start_date]', 'none', (@issue_params[:start_date] == 'none'), :id => nil, :data => {:disables => '#issue_start_date'} %><%= l(:button_clear) %></label>
152 152
</p>
153 153
<% end %>
......
155 155
<% if @safe_attributes.include?('due_date') %>
156 156
<p>
157 157
  <label for='issue_due_date'><%= l(:field_due_date) %></label>
158
  <%= text_field_tag 'issue[due_date]', '', :value => @issue_params[:due_date], :size => 10 %><%= calendar_for('issue_due_date') %>
158
  <%= date_field_tag 'issue[due_date]', '', :value => @issue_params[:due_date], :size => 10 %><%= calendar_for('issue_due_date') %>
159 159
  <label class="inline"><%= check_box_tag 'issue[due_date]', 'none', (@issue_params[:due_date] == 'none'), :id => nil, :data => {:disables => '#issue_due_date'} %><%= l(:button_clear) %></label>
160 160
</p>
161 161
<% end %>
app/views/timelog/_form.html.erb
15 15
    <%= f.text_field :issue_id, :size => 6 %>
16 16
    <span id="time_entry_issue"><%= "#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}" if @time_entry.issue %></span>
17 17
  </p>
18
  <p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
18
  <p><%= f.date_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
19 19
  <p><%= f.text_field :hours, :size => 6, :required => true %></p>
20 20
  <p><%= f.text_field :comments, :size => 100, :maxlength => 255 %></p>
21 21
  <p><%= f.select :activity_id, activity_collection_for_select_options(@time_entry), :required => true %></p>
app/views/timelog/bulk_edit.html.erb
18 18

  
19 19
    <p>
20 20
      <label><%= l(:field_spent_on) %></label>
21
      <%= text_field :time_entry, :spent_on, :size => 10 %><%= calendar_for('time_entry_spent_on') %>
21
      <%= date_field :time_entry, :spent_on, :size => 10 %><%= calendar_for('time_entry_spent_on') %>
22 22
    </p>
23 23

  
24 24
    <p>
app/views/versions/_form.html.erb
6 6
<p><%= f.text_field :description, :size => 60 %></p>
7 7
<p><%= f.select :status, Version::VERSION_STATUSES.collect {|s| [l("version_status_#{s}"), s]} %></p>
8 8
<p><%= f.text_field :wiki_page_title, :label => :label_wiki_page, :size => 60, :disabled => @project.wiki.nil? %></p>
9
<p><%= f.text_field :effective_date, :size => 10 %><%= calendar_for('version_effective_date') %></p>
9
<p><%= f.date_field :effective_date, :size => 10 %><%= calendar_for('version_effective_date') %></p>
10 10
<p><%= f.select :sharing, @version.allowed_sharings.collect {|v| [format_version_sharing(v), v]} %></p>
11 11

  
12 12
<% @version.custom_field_values.each do |value| %>
lib/redmine/field_format.rb
420 420
      end
421 421

  
422 422
      def edit_tag(view, tag_id, tag_name, custom_value, options={})
423
        view.text_field_tag(tag_name, custom_value.value, options.merge(:id => tag_id, :size => 10)) +
423
        view.date_field_tag(tag_name, custom_value.value, options.merge(:id => tag_id, :size => 10)) +
424 424
          view.calendar_for(tag_id)
425 425
      end
426 426

  
427 427
      def bulk_edit_tag(view, tag_id, tag_name, custom_field, objects, value, options={})
428
        view.text_field_tag(tag_name, value, options.merge(:id => tag_id, :size => 10)) +
428
        view.date_field_tag(tag_name, value, options.merge(:id => tag_id, :size => 10)) +
429 429
          view.calendar_for(tag_id) +
430 430
          bulk_clear_tag(view, tag_id, tag_name, custom_field, value)
431 431
      end
public/javascripts/application.js
185 185
  case "date":
186 186
  case "date_past":
187 187
    tr.find('td.values').append(
188
      '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="10" class="value date_value" /></span>' +
189
      ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="10" class="value date_value" /></span>' +
188
      '<span style="display:none;"><input type="date" name="v['+field+'][]" id="values_'+fieldId+'_1" size="10" class="value date_value" /></span>' +
189
      ' <span style="display:none;"><input type="date" name="v['+field+'][]" id="values_'+fieldId+'_2" size="10" class="value date_value" /></span>' +
190 190
      ' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="3" class="value" /> '+labelDayPlural+'</span>'
191 191
    );
192
    $('#values_'+fieldId+'_1').val(values[0]).datepicker(datepickerOptions);
193
    $('#values_'+fieldId+'_2').val(values[1]).datepicker(datepickerOptions);
192
    $('#values_'+fieldId+'_1').val(values[0]).datepickerFallback(datepickerOptions);
193
    $('#values_'+fieldId+'_2').val(values[1]).datepickerFallback(datepickerOptions);
194 194
    $('#values_'+fieldId).val(values[0]);
195 195
    break;
196 196
  case "string":
......
554 554
      }
555 555
      break;
556 556
  }
557
  $(input).datepicker("option", "defaultDate", default_date);
557
  $(input).datepickerFallback("option", "defaultDate", default_date);
558 558
}
559 559

  
560 560
function initMyPageSortable(list, url) {
......
640 640
function toggleDisabledInit() {
641 641
  $('input[data-disables], input[data-enables]').each(toggleDisabledOnChange);
642 642
}
643

  
644
(function ( $ ) {
645

  
646
  // detect if native date input is supported
647
  var nativeDateInputSupported = true;
648

  
649
  var input = document.createElement('input');
650
  input.setAttribute('type','date');
651
  if (input.type === 'text') {
652
    nativeDateInputSupported = false;
653
  }
654

  
655
  var notADateValue = 'not-a-date';
656
  input.setAttribute('value', notADateValue);
657
  if (input.value === notADateValue) {
658
    nativeDateInputSupported = false;
659
  }
660

  
661
  $.fn.datepickerFallback = function( options ) {
662
    if (nativeDateInputSupported) {
663
      return this;
664
    } else {
665
      return this.datepicker( options );
666
    }
667
  };
668
}( jQuery ));
669

  
643 670
$(document).ready(function(){
644 671
  $('#content').on('change', 'input[data-disables], input[data-enables]', toggleDisabledOnChange);
645 672
  toggleDisabledInit();
(2-2/3)