Set default due date/time.
authorJan Schneider <jan@horde.org>
Fri, 12 Feb 2010 19:32:34 +0000 (20:32 +0100)
committerJan Schneider <jan@horde.org>
Fri, 12 Feb 2010 19:32:34 +0000 (20:32 +0100)
kronolith/js/kronolith.js
nag/lib/Api.php

index 353a09d..b1d0b48 100644 (file)
@@ -1842,6 +1842,9 @@ KronolithCore = {
             $('kronolithTaskList').setValue(Kronolith.conf.tasks.default_tasklist);
             //$('kronolithTaskLocation').setValue('http://');
             $('kronolithTaskPriority').setValue(3);
+            if (Kronolith.conf.tasks.default_due) {
+                this.setDefaultDue();
+            }
             $('kronolithTaskDelete').hide();
             RedBox.showHtml($('kronolithTaskDialog').show());
         }
@@ -1925,6 +1928,25 @@ KronolithCore = {
     },
 
     /**
+     * Sets the default due date and time for tasks.
+     */
+    setDefaultDue: function()
+    {
+        if ($F('kronolithTaskDueDate') || $F('kronolithTaskDueTime')) {
+            return;
+        }
+        $('kronolithTaskDueDate').setValue(new Date().add(Kronolith.conf.tasks.default_due_days).days().toString(Kronolith.conf.date_format));
+        if (Kronolith.conf.tasks.default_due_time == 'now') {
+            $('kronolithTaskDueTime').setValue(new Date().toString(Kronolith.conf.time_format));
+        } else {
+            var date = new Date();
+            date.setHours(Kronolith.conf.tasks.default_due_time.replace(/:.*$/, ''));
+            date.setMinutes(0);
+            $('kronolithTaskDueTime').setValue(date.toString(Kronolith.conf.time_format));
+        }
+    },
+
+    /**
      * Finally removes a task from the DOM and the cache.
      *
      * @param string task  A task id.
@@ -3810,6 +3832,8 @@ KronolithCore = {
         $('kronolithEventStartDate', 'kronolithEventEndDate', 'kronolithTaskDueDate').compact().invoke('observe', 'blur', this.checkDate.bind(this));
         $('kronolithEventStartTime', 'kronolithEventEndTime', 'kronolithTaskDueTime').compact().invoke('observe', 'blur', this.checkTime.bind(this));
 
+        $('kronolithTaskDueDate', 'kronolithEventDueTime').compact().invoke('observe', 'focus', this.setDefaultDue.bind(this));
+
         // Mouse wheel handler.
         [ 'kronolithEventStartDate', 'kronolithEventEndDate' ].each(function(field) {
             $(field).observe(Prototype.Browser.Gecko ? 'DOMMouseScroll' : 'mousewheel', function(e) {
index ada54af..2c2774e 100644 (file)
@@ -27,6 +27,9 @@ class Nag_Api extends Horde_Registry_Api
     {
         return array(
             'default_tasklist' => Nag::getDefaultTasklist(Horde_Perms::EDIT),
+            'default_due' => (bool)$GLOBALS['prefs']->getValue('default_due'),
+            'default_due_days' => (int)$GLOBALS['prefs']->getValue('default_due_days'),
+            'default_due_time' => $GLOBALS['prefs']->getValue('default_due_time'),
         );
     }