Skip to content

Commit

Permalink
Load free/busy information for user attendees.
Browse files Browse the repository at this point in the history
Still needs to be optimized to:
- load more day at first
- implement a proper cache
- load missing information while navigating
  • Loading branch information
yunosh committed Jul 15, 2016
1 parent ef27bdc commit 788a43c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
49 changes: 23 additions & 26 deletions kronolith/js/kronolith.js
Expand Up @@ -16,7 +16,7 @@ KronolithCore = {
// Vars used and defaulting to null/false:
// weekSizes, daySizes,
// groupLoading, colorPicker, duration, timeMarker, monthDays,
// allDays, eventsWeek, initialized
// allDays, eventsWeek, initialized, fbStart, fbEnd

view: '',
ecache: $H(),
Expand Down Expand Up @@ -918,7 +918,8 @@ KronolithCore = {

// Highlight days currently being displayed.
if (view &&
((view == 'month' && this.date.between(dates[0], dates[1])) ||
((view == 'month' &&
this.date.between(dates[0], dates[1])) ||
(view == 'week' && day.between(week[0], week[1])) ||
(view == 'workweek' && day.between(workweek[0], workweek[1])) ||
(view == 'day' && day.equals(this.date)) ||
Expand Down Expand Up @@ -1318,10 +1319,10 @@ KronolithCore = {
}
switch (tab.identify()) {
case 'kronolithEventTabAttendees':
this.attendeeStartDateHandler(this.getFBDate());
this.attendeeStartDateHandler(this.fbStart);
break;
case 'kronolithEventTabResources':
this.resourceStartDateHandler(this.getFBDate());
this.resourceStartDateHandler(this.fbStart);
break;
}
},
Expand Down Expand Up @@ -6444,15 +6445,18 @@ KronolithCore = {
u: user.user,
l: user.name
};
this.attendees.push(user);
this.fbLoading++;
HordeCore.doAction('getFreeBusy', {
user: user.u
}, {
callback: this.getFBCallback.bind(this, user.i)
});
}

this.attendees.push(user);
this.fbLoading++;
HordeCore.doAction('getFreeBusy', {
user: user.u,
start: this.fbStart.getTime() / 1000,
end: this.fbEnd.getTime() / 1000
}, {
callback: this.getFBCallback.bind(this, user.i)
});

this.insertFBRow(user);
},

Expand Down Expand Up @@ -6487,7 +6491,7 @@ KronolithCore = {
}
if (!Object.isUndefined(r.fb)) {
this.freeBusy.get(attendee)[1] = r.fb;
this.insertFreeBusy(attendee, this.getFBDate());
this.insertFreeBusy(attendee, this.fbStart);
}
},

Expand Down Expand Up @@ -6611,7 +6615,9 @@ KronolithCore = {
case 4: response = 'Tentative'; break;
}
var att = {
'resource': v
'resource': v,
start: this.fbStart.getTime() / 1000,
end: this.fbEnd.getTime() / 1000
},
tr, i;
if (att.resource) {
Expand Down Expand Up @@ -6719,17 +6725,6 @@ KronolithCore = {
}
},

getFBDate: function()
{
var startDate = $('kronolithFBDate').innerHTML.split(' ');
if (startDate.length > 1) {
startDate = startDate[1];
} else {
startDate = startDate[0];
}
return Date.parseExact(startDate, Kronolith.conf.date_format);
},

/**
* Updates rows with free/busy information in the attendees table.
*
Expand Down Expand Up @@ -6840,19 +6835,21 @@ KronolithCore = {

nextFreebusy: function()
{
this.fbStartDateHandler(this.getFBDate().addDays(1));
this.fbStartDateHandler(this.fbStart.addDays(1));
},

prevFreebusy: function()
{
this.fbStartDateHandler(this.getFBDate().addDays(-1));
this.fbStartDateHandler(this.fbStart.addDays(-1));
},

/**
* @start Date object
*/
updateFBDate: function(start)
{
this.fbStart = start.clone();
this.fbEnd = start.clone().addDays(1);
$('kronolithFBDate').update(start.toString('dddd') + ' ' + start.toString(Kronolith.conf.date_format));
$('kronolithResourceFBDate').update(start.toString('dddd') + ' ' + start.toString(Kronolith.conf.date_format));
},
Expand Down
4 changes: 3 additions & 1 deletion kronolith/lib/Ajax/Application/Handler.php
Expand Up @@ -946,7 +946,9 @@ public function getFreeBusy()
$resource = Kronolith::getDriver('Resource')
->getResource($this->vars->resource);
try {
$result->fb = $resource->getFreeBusy(null, null, true, true);
$result->fb = $resource->getFreeBusy(
$this->vars->start, $this->vars->end, true, true
);
} catch (Horde_Exception $e) {
// Resource groups can't provide FB information.
$result->fb = null;
Expand Down

0 comments on commit 788a43c

Please sign in to comment.