Fix free/busy lookups.
authorJan Schneider <jan@horde.org>
Mon, 22 Feb 2010 00:06:22 +0000 (01:06 +0100)
committerJan Schneider <jan@horde.org>
Mon, 22 Feb 2010 00:35:29 +0000 (01:35 +0100)
kronolith/js/kronolith.js
kronolith/lib/Event.php
kronolith/lib/FreeBusy.php

index 7ebd60c..824fe5e 100644 (file)
@@ -3525,21 +3525,23 @@ KronolithCore = {
             table.select('tr').invoke('remove');
             ev.at.each(function(attendee) {
                 var tr = new Element('tr'), i;
-                this.fbLoading++;
-                this.doAction('GetFreeBusy',
-                              { email: attendee.e },
-                              function(r) {
-                                  this.fbLoading--;
-                                  if (!this.fbLoading) {
-                                      $('kronolithFBLoading').hide();
-                                  }
-                                  if (Object.isUndefined(r.response.fb)) {
-                                      return;
-                                  }
-                                  this.freeBusy.set(attendee.e, [ tr, r.response.fb ]);
-                                  this.insertFreeBusy(attendee.e);
-                              }.bind(this));
-                tr.insert(new Element('td').writeAttribute('title', attendee.l).insert(attendee.e.escapeHTML()));
+                if (attendee.e) {
+                    this.fbLoading++;
+                    this.doAction('GetFreeBusy',
+                                  { email: attendee.e },
+                                  function(r) {
+                                      this.fbLoading--;
+                                      if (!this.fbLoading) {
+                                          $('kronolithFBLoading').hide();
+                                      }
+                                      if (Object.isUndefined(r.response.fb)) {
+                                          return;
+                                      }
+                                      this.freeBusy.set(attendee.e, [ tr, r.response.fb ]);
+                                      this.insertFreeBusy(attendee.e);
+                                  }.bind(this));
+                }
+                tr.insert(new Element('td').writeAttribute('title', attendee.l).insert(attendee.e ? attendee.e.escapeHTML() : attendee.l));
                 for (i = 0; i < 24; i++) {
                     tr.insert(new Element('td', { className: 'kronolithFBUnknown' }));
                 }
@@ -3582,6 +3584,9 @@ KronolithCore = {
     /**
      * Inserts rows with free/busy information into the attendee table.
      *
+     * @todo Update when changing dates; only show free time for fb times we
+     *       actually received.
+     *
      * @param string email  An email address as the free/busy identifier.
      */
     insertFreeBusy: function(email)
@@ -3593,15 +3598,17 @@ KronolithCore = {
         var fb = this.freeBusy.get(email)[1],
             tr = this.freeBusy.get(email)[0],
             td = tr.select('td')[1],
-            div = td.down('div');
+            div = td.down('div'),
+            i = 0;
         if (!td.getWidth()) {
             this.insertFreeBusy.bind(this, email).defer();
             return;
         }
         tr.select('td').each(function(td, i) {
             if (i != 0) {
-                td.addClassName('kronolithFBFree');
+                td.className = 'kronolithFBFree';
             }
+            i++;
         });
         if (div) {
             div.remove();
index 8860c1a..1d379ad 100644 (file)
@@ -1263,10 +1263,13 @@ abstract class Kronolith_Event
             if ($this->attendees) {
                 $attendees = array();
                 foreach ($this->attendees as $email => $info) {
-                    $attendees[] = array('e' => $email,
-                                         'l' => empty($info['name']) ? $email : ($info['name'] . ' <' . $email . '>'),
-                                         'a' => $info['attendance'],
-                                         'r' => $info['response']);
+                    $attendee = array('a' => $info['attendance'],
+                                      'r' => $info['response'],
+                                      'l' => empty($info['name']) ? $email : Horde_Mime_Address::trimAddress($info['name'] . (strpos($email, '@') === false ? '' : ' <' . $email . '>')));
+                    if (strpos($email, '@') !== false) {
+                        $attendee['e'] = $email;
+                    }
+                    $attendees[] = $attendee;
                 }
                 $json->at = $attendees;
             }
index 3c80c49..a335c3d 100644 (file)
@@ -263,13 +263,12 @@ class Kronolith_FreeBusy
     function toJson($fb)
     {
         $json = new stdClass;
-        $json->e = $fb->getEmail();
         $start = $fb->getStart();
         if ($start) {
             $start = new Horde_Date($start);
             $json->s = $start->dateString();
         }
-        $end = $fb->getStart();
+        $end = $fb->getEnd();
         if ($end) {
             $end = new Horde_Date($end);
             $json->e = $end->dateString();