From 537c394302df13e7623a36b28b11caceeaaa75b2 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Wed, 05 Oct 2011 05:36:16 -0400
Subject: [PATCH] Attach jquery UI date pickers to contact fields of type 'date'

---
 program/steps/addressbook/func.inc |   14 ++++++++++++++
 program/js/app.js                  |   18 ++++++++++++++++++
 2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index d2760b4..3ddd558 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -4146,6 +4146,21 @@
       this.selectedIndex = 0;
     });
 
+    // enable date pickers on date fields
+    if ($.datepicker && this.env.date_format) {
+      $.datepicker.setDefaults({
+        dateFormat: this.env.date_format,
+        changeMonth: true,
+        changeYear: true,
+        yearRange: '-100:+10',
+        showOtherMonths: true,
+        selectOtherMonths: true,
+        monthNamesShort: this.env.month_names,
+        onSelect: function(dateText) { $(this).focus().val(dateText) }
+      });
+      $('input.datepicker').datepicker();
+    }
+
     $("input[type='text']:visible").first().focus();
   };
 
@@ -4401,6 +4416,9 @@
             .appendTo(cell);
 
           this.init_edit_field(col, input);
+          
+          if (colprop.type == 'date' && $.datepicker)
+            input.datepicker();
         }
         else if (colprop.type == 'composite') {
           var childcol, cp, first, templ, cols = [], suffices = [];
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc
index dd8856a..fc559e6 100644
--- a/program/steps/addressbook/func.inc
+++ b/program/steps/addressbook/func.inc
@@ -422,6 +422,7 @@
 function rcmail_contact_form($form, $record, $attrib = null)
 {
     global $RCMAIL, $CONFIG;
+    static $jqueryui_loaded = 0;
 
     // Allow plugins to modify contact form content
     $plugin = $RCMAIL->plugins->exec_hook('contact_form', array(
@@ -608,6 +609,19 @@
                         if ($colprop['subtypes'] || $colprop['limit'] != 1)
                             $colprop['array'] = true;
 
+                        // load jquery UI datepickert for date fields
+                        if ($colprop['type'] == 'date') {
+                            if (!$jqueryui_loaded++) {
+                                $RCMAIL->plugins->load_plugin('jqueryui');
+                                $RCMAIL->output->set_env('date_format', strtr($RCMAIL->config->get('date_format', 'Y-m-d'), array('y'=>'y', 'Y'=>'yy', 'm'=>'mm', 'n'=>'m', 'd'=>'dd', 'j'=>'d')));
+                                foreach (array('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec') as $month)
+                                    $month_names[] = rcube_label($month);
+                                $RCMAIL->output->set_env('month_names', $month_names);
+                            }
+                            $colprop['class'] .= ($colprop['class'] ? ' ' : '') . 'datepicker';
+                            $val = format_date($val, $RCMAIL->config->get('date_format', 'Y-m-d'));
+                        }
+
                         $val = rcmail_get_edit_field($col, $val, $colprop, $colprop['type']);
                         $coltypes[$field]['count']++;
                     }

--
Gitblit v1.9.1