LSformElement_date : Added 'today' button
authorBenjamin Renard <brenard@easter-eggs.com>
Mon, 27 Jun 2011 13:48:54 +0000 (15:48 +0200)
committerBenjamin Renard <brenard@easter-eggs.com>
Mon, 27 Jun 2011 13:48:54 +0000 (15:48 +0200)
public_html/includes/class/class.LSformElement_date.php
public_html/includes/js/LSformElement_date_field.js

index a9c0bb5..cd9c042 100644 (file)
@@ -156,7 +156,8 @@ class LSformElement_date extends LSformElement {
       LSsession :: addHelpInfos(
         'LSformElement_date',
         array(
-          'now' => _('Now.')
+          'now' => _('Now.'),
+          'today' => _('Today.')
         )
       );
       
index fac4bbd..99a5198 100644 (file)
@@ -43,9 +43,35 @@ var LSformElement_date_field = new Class({
       this.nowBtn.addEvent('click',this.onNowBtnClick.bind(this));
       this.nowBtn.injectAfter(this.input);
       varLSdefault.addHelpInfo(this.nowBtn,'LSformElement_date','now');
+
+      this.todayBtn = new Element('img');
+      this.todayBtn.src = varLSdefault.imagePath('calendar.png');
+      this.todayBtn.addClass('btn');
+      this.todayBtn.addEvent('click',this.onTodayBtnClick.bind(this));
+      this.todayBtn.injectAfter(this.nowBtn);
+      varLSdefault.addHelpInfo(this.todayBtn,'LSformElement_date','today');
     },
     
     onNowBtnClick: function() {
       this.input.value = new Date().format(this.params.format);
+    },
+
+    onTodayBtnClick: function() {
+      if (this.input.value) {
+        var cur = Date.parse(this.input.value,this.params.format);
+        if (cur == null) {
+          var cur = Date.parse(this.input.value);
+        }
+        if (cur) {
+          var now = new Date();
+          var today = cur.clone();
+          today.set({
+            year: now.get('year'),
+            mo: now.get('mo'),
+            date: now.get('date')
+          });
+          this.input.value = today.format(this.params.format);
+        }
+      }
     }
 });