]> source.dussan.org Git - redmine.git/commitdiff
set default issue start/due datepicker from due/start date (#14024)
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Sun, 19 May 2013 01:06:25 +0000 (01:06 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Sun, 19 May 2013 01:06:25 +0000 (01:06 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11883 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
public/javascripts/datepicker.js [new file with mode: 0644]
test/ui/issues_test.rb

index 7515501184575d7385cf90d5abde1053b9089a4a..fbf14b3d14dd4e722b14f914c96fea4589455b48 100644 (file)
@@ -1075,6 +1075,7 @@ module ApplicationHelper
 
   def include_calendar_headers_tags
     unless @calendar_headers_tags_included
+      tags = javascript_include_tag("datepicker")
       @calendar_headers_tags_included = true
       content_for :header_tags do
         start_of_week = Setting.start_of_week
@@ -1082,12 +1083,13 @@ module ApplicationHelper
         # Redmine uses 1..7 (monday..sunday) in settings and locales
         # JQuery uses 0..6 (sunday..saturday), 7 needs to be changed to 0
         start_of_week = start_of_week.to_i % 7
-
-        tags = javascript_tag(
+        tags << javascript_tag(
                    "var datepickerOptions={dateFormat: 'yy-mm-dd', firstDay: #{start_of_week}, " +
                      "showOn: 'button', buttonImageOnly: true, buttonImage: '" + 
                      path_to_image('/images/calendar.png') +
-                     "', showButtonPanel: true, showWeek: true, showOtherMonths: true, selectOtherMonths: true, changeMonth: true, changeYear: true};")
+                     "', showButtonPanel: true, showWeek: true, showOtherMonths: true, " +
+                     "selectOtherMonths: true, changeMonth: true, changeYear: true, " +
+                     "beforeShow: beforeShowDatePicker};")
         jquery_locale = l('jquery.locale', :default => current_language.to_s)
         unless jquery_locale == 'en'
           tags << javascript_include_tag("i18n/jquery.ui.datepicker-#{jquery_locale}.js") 
diff --git a/public/javascripts/datepicker.js b/public/javascripts/datepicker.js
new file mode 100644 (file)
index 0000000..9acae0c
--- /dev/null
@@ -0,0 +1,16 @@
+function beforeShowDatePicker(input, inst) {
+  var default_date = null;
+  switch ($(input).attr("id")) {
+    case "issue_start_date" :
+      if ($("#issue_due_date").size() > 0) {
+        default_date = $("#issue_due_date").val();
+      }
+      break;
+    case "issue_due_date" :
+      if ($("#issue_start_date").size() > 0) {
+        default_date = $("#issue_start_date").val();
+      }
+      break;
+  }
+  $(input).datepicker("option", "defaultDate", default_date);
+}
index df25f8b9cfe894310d50eda00d7db3bfd1568182..1f9ba457bf090b8642a4f93719a965a0a91a6c79 100644 (file)
@@ -147,6 +147,22 @@ class Redmine::UiTest::IssuesTest < Redmine::UiTest::Base
     end
   end
 
+  def test_create_issue_start_due_date_default
+    log_user('jsmith', 'jsmith')
+    visit '/projects/ecookbook/issues/new'
+    fill_in 'Start date', :with => '2012-04-01'
+    fill_in 'Due date', :with => ''
+    page.first('p#due_date_area img').click
+    page.first("td.ui-datepicker-days-cell-over a").click
+    assert_equal '2012-04-01', page.find('input#issue_due_date').value
+
+    fill_in 'Start date', :with => ''
+    fill_in 'Due date', :with => '2012-04-01'
+    page.first('p#start_date_area img').click
+    page.first("td.ui-datepicker-days-cell-over a").click
+    assert_equal '2012-04-01', page.find('input#issue_start_date').value
+  end
+
   def test_preview_issue_description
     log_user('jsmith', 'jsmith')
     visit '/projects/ecookbook/issues/new'