Provide feedback on resource availability as soon as it's added to the attendees...
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 17 Sep 2009 00:32:21 +0000 (20:32 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 29 Sep 2009 20:53:55 +0000 (16:53 -0400)
If response type is Kronolith_Resource::RESPONSETYPE_AUTO then use the start and end datetime
values that are now passed from the event form to determine if the resource is free.

Still need to figure out how to (efficiently) pass the datetime values to take into account
AM/PM. Probably break out the javascript from the onClick handler into it's function and
provide logic to check the am/pm fields? Is there an easier/prettier way?

kronolith/attendees.php
kronolith/lib/Resource/Single.php
kronolith/templates/attendees/attendees.inc
kronolith/templates/edit/edit.inc

index d12ff3e..0e2fd1e 100644 (file)
@@ -109,6 +109,15 @@ case 'add':
             $response = Kronolith::RESPONSE_ACCEPTED;
         } elseif ($type == Kronolith_Resource::RESPONSETYPE_ALWAYS_DECLINE) {
             $response = Kronolith::RESPONSE_DECLINED;
+        } elseif ($type == Kronolith_Resource::RESPONSETYPE_AUTO) {
+            // Try to figure out the expected response
+            $date = new Horde_Date(Horde_Util::getFormData('date'));
+            $end = new Horde_Date(Horde_Util::getFormData('enddate'));
+            if ($resource->isFree(array('start' => $date, 'end' => $end))) {
+                $response = Kronolith::RESPONSE_ACCEPTED;
+            } else {
+                $response = Kronolith::RESPONSE_DECLINED;
+            }
         } else {
             $response = Kronolith::RESPONSE_NONE;
         }
index 55f2304..241e55a 100644 (file)
@@ -16,14 +16,24 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base
      * Determine if the resource is free during the time period for the
      * supplied event.
      *
-     * @param Kronolith_Event $event
+     * @param mixed $event  Either a Kronolith_Event object or an array
+     *                      containing start and end times.
+     *
      *
      * @return boolean
      */
     public function isFree($event)
     {
+        if (is_array($event)) {
+            $start = $event['start'];
+            $end = $event['end'];
+        } else {
+            $start = $event->start;
+            $end = $event->end;
+        }
+
         /* Fetch events. */
-        $busy = Kronolith::listEvents($event->start, $event->end, array($this->get('calendar')));
+        $busy = Kronolith::listEvents($start, $end, array($this->get('calendar')));
         if ($busy instanceof PEAR_Error) {
             throw new Horde_Exception($busy->getMessage());
         }
@@ -35,7 +45,11 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base
 
         /* Check for conflicts, ignoring the conflict if it's for the
          * same event that is passed. */
-        $uid = $event->getUID();
+        if (!is_array($event)) {
+            $uid = $event->getUID();
+        } else {
+            $uid = 0;
+        }
         $conflicts = 0;
         foreach ($busy as $events) {
             foreach ($events as $e) {
@@ -43,8 +57,8 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base
                       $e->hasStatus(Kronolith::STATUS_FREE)) &&
                      $e->getUID() !== $uid) {
 
-                     if (!($e->start->compareDateTime($event->end) >= 1 ||
-                         $e->end->compareDateTime($event->start) <= -1)) {
+                     if (!($e->start->compareDateTime($end) >= 1 ||
+                         $e->end->compareDateTime($start) <= -1)) {
 
                          $conflicts++;
                      }
index e8754f3..77105fe 100644 (file)
@@ -35,7 +35,8 @@ function switchDateView(view, date)
 <input type="hidden" name="actionID" value="add" />
 <input type="hidden" name="actionValue" value="" />
 <input type="hidden" name="view" value="<?php echo htmlspecialchars($view) ?>" />
-<input type="hidden" name="date" value="<?php echo $date->dateString() ?>" />
+<input type="hidden" name="date" value="<?php echo $date->dateString() . sprintf("%02d%02d00", $date->hour, $date->min) ?>" />
+<input type="hidden" name="enddate" value=<?php echo $end->dateString() . sprintf("%02d%02d00", $end->hour, $end->min) ?>" />
 
 <h1 class="header"><?php echo htmlspecialchars($title) ?></h1>
 
index 1e1eba9..135a1b0 100644 (file)
@@ -244,7 +244,7 @@ if ($event->alarm) {
 <tr>
  <td></td>
  <td colspan="4">
-  <?php echo Horde::link(Horde::applicationUrl('attendees.php'), '', 'button', '_blank', 'var date = (\'000\' + $F(\'start_year\')).slice(-4) + (\'0\' + $F(\'start_month\')).slice(-2) + (\'0\' + $F(\'start_day\')).slice(-2); this.href += (this.href.indexOf(\'?\') == -1 ? \'?\' : \'&\') + \'date=\' + date;Horde.popup({ url: this.href });return false;') . _("Edit Attendees and Resources") . '</a>' ?>
+  <?php echo Horde::link(Horde::applicationUrl('attendees.php'), '', 'button', '_blank', 'var date = (\'000\' + $F(\'start_year\')).slice(-4) + (\'0\' + $F(\'start_month\')).slice(-2) + (\'0\' + $F(\'start_day\')).slice(-2) + (\'0\' + $(\'start_hour\').value).slice(-2) + (\'0\' + $(\'start_min\').value).slice(-2) + \'00\';var enddate = (\'000\' + $F(\'end_year\')).slice(-4) + (\'0\' + $F(\'end_month\')).slice(-2) + (\'0\' + $F(\'end_day\')).slice(-2) + (\'0\' + $(\'end_hour\').value).slice(-2) + (\'0\' + $(\'end_min\').value).slice(-2) + \'00\'; this.href += (this.href.indexOf(\'?\') == -1 ? \'?\' : \'&\') + \'date=\' + date + \'&enddate=\' + enddate;Horde.popup({ url: this.href });return false;') . _("Edit Attendees and Resources") . '</a>' ?>
  </td>
 </tr>
 </tbody>