Source

trac-1942 / datetimepicker.patch

Full commit
# HG changeset patch
# Parent c7c6043d8eeb06d7b0161a1b82d67ba5b3815b61
Use jQuery datetime picker for custom time fields.

diff -r c7c6043d8eeb trac/htdocs/js/query.js
--- a/trac/htdocs/js/query.js	Wed Jul 11 13:09:51 2012 +0200
+++ b/trac/htdocs/js/query.js	Wed Jul 11 13:12:37 2012 +0200
@@ -184,11 +184,19 @@
             .append(createRadio(propertyName, "0", propertyName + "_off"))
             .append(" ").append(createLabel(_("no"), propertyName + "_off"));
         } else if (property.type == "time") {
-          focusElement = createText(propertyName, 14).datepicker();
+          var endElement = createText(propertyName + "_end", 14);
+          focusElement = createText(propertyName, 14);
+          if (property.format == "datetime") {
+            focusElement.datetimepicker();
+            endElement.datetimepicker();
+          } else if (property.format == "date") {
+            focusElement.datepicker();
+            endElement.datepicker();
+          }
           td.append(createLabel(_("between"))).append(" ")
             .append(focusElement).append(" ")
             .append(createLabel(_("and"))).append(" ")
-            .append(createText(propertyName + "_end", 14).datepicker());
+            .append(endElement);
         }
         tr.append(td);
       } else {
diff -r c7c6043d8eeb trac/ticket/query.py
--- a/trac/ticket/query.py	Wed Jul 11 13:09:51 2012 +0200
+++ b/trac/ticket/query.py	Wed Jul 11 13:12:37 2012 +0200
@@ -1114,7 +1114,7 @@
 
         properties = dict((name, dict((key, field[key])
                                       for key in ('type', 'label', 'options',
-                                                  'optgroups')
+                                                  'optgroups', 'format')
                                       if key in field))
                           for name, field in data['fields'].iteritems())
         add_script_data(req, properties=properties, modes=data['modes'])
diff -r c7c6043d8eeb trac/ticket/templates/query.html
--- a/trac/ticket/templates/query.html	Wed Jul 11 13:09:51 2012 +0200
+++ b/trac/ticket/templates/query.html	Wed Jul 11 13:12:37 2012 +0200
@@ -26,6 +26,8 @@
       /*]]>*/
         /* Hide the columns by default. */
         $("#columns").toggleClass("collapsed");
+        $(".datepicker").datepicker();
+        $(".datetimepicker").datetimepicker();
       });
     </script>
   </head>
@@ -123,12 +125,13 @@
                         
                         <py:when test="field.type == 'time'"
                                  py:with="(start, end) = '..' in constraint_value and constraint_value.split('..', 1)
-                                                         or (constraint_value, '')">
+                                                         or (constraint_value, '');
+                                          date_or_datetime = field.get('format', 'datetime')">
                           <i18n:msg>
                             <label>between</label>
-                            <input type="text" name="${n_field_name}" value="$start" size="14" />
+                            <input type="text" name="${n_field_name}" value="$start" size="14" class="${date_or_datetime}picker" />
                             <label>and</label>
-                            <input type="text" name="${n_field_name}_end" value="$end" size="14" />
+                            <input type="text" name="${n_field_name}_end" value="$end" size="14" class="${date_or_datetime}picker" />
                           </i18n:msg>
                         </py:when>
                       </td>
diff -r c7c6043d8eeb trac/ticket/templates/ticket.html
--- a/trac/ticket/templates/ticket.html	Wed Jul 11 13:09:51 2012 +0200
+++ b/trac/ticket/templates/ticket.html	Wed Jul 11 13:12:37 2012 +0200
@@ -12,12 +12,14 @@
     <title py:choose="">
       <py:when test="ticket.exists">#${ticket.id} (${ticket.summary})</py:when>
       <py:otherwise>New Ticket</py:otherwise>
-    </title>
+    </title>
     <script py:if="ticket.exists" type="text/javascript" src="${chrome.htdocs_location}js/threaded_comments.js"></script>
     <script type="text/javascript" py:choose="">
       jQuery(document).ready(function($) {
         $("div.description").find("h1,h2,h3,h4,h5,h6").addAnchor(_("Link to this section"));
-        $(".foldable").enableFolding(false, true);
+        $(".foldable").enableFolding(false, true);
+        $(".datepicker").datepicker();
+        $(".datetimepicker").datetimepicker();
       <py:when test="ticket.exists">/*<![CDATA[*/
         $("#modify").parent().toggleClass("collapsed");
         $(".trac-topnav a").click(function() { $("#modify").parent().removeClass("collapsed"); });
@@ -303,7 +305,7 @@
                           ${option}
                         </label>
                         <input py:when="'time'" type="text" id="field-${field.name}" title="${field.format_hint}"
-                               name="field_${field.name}" value="${field.edit}" />
+                               name="field_${field.name}" value="${field.edit}" class="${field.format}picker" />
                         <py:otherwise><!--! Text input fields -->
                           <py:choose>
                             <span py:when="field.cc_entry"><!--! Special case for Cc: field -->
diff -r c7c6043d8eeb trac/ticket/web_ui.py
--- a/trac/ticket/web_ui.py	Wed Jul 11 13:09:51 2012 +0200
+++ b/trac/ticket/web_ui.py	Wed Jul 11 13:12:37 2012 +0200
@@ -507,6 +507,7 @@
         add_script(req, 'common/js/folding.js')
         Chrome(self.env).add_wiki_toolbars(req)
         Chrome(self.env).add_auto_preview(req)
+        Chrome(self.env).add_jquery_ui(req)
         return 'ticket.html', data, None
 
     def _process_ticket_request(self, req):
@@ -697,6 +698,7 @@
         add_script(req, 'common/js/folding.js')
         Chrome(self.env).add_wiki_toolbars(req)
         Chrome(self.env).add_auto_preview(req)
+        Chrome(self.env).add_jquery_ui(req)
 
         # Add registered converters
         for conversion in mime.get_supported_conversions('trac.ticket.Ticket'):