Skip to content

Commit

Permalink
Fix/Implement updating resource events when host event chagnes.
Browse files Browse the repository at this point in the history
Bug: 13465
  • Loading branch information
mrubinsk committed Aug 31, 2014
1 parent ca437de commit 2aa3e89
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 9 deletions.
71 changes: 69 additions & 2 deletions kronolith/js/kronolith.js
Expand Up @@ -4049,8 +4049,9 @@ KronolithCore = {
*
* @param string calendar A calendar string or array.
* @param string event An event ID or empty if deleting the calendar.
* @param string day A specific day to delete in yyyyMMdd form.
*/
deleteCache: function(calendar, event)
deleteCache: function(calendar, event, day)
{
if (Object.isString(calendar)) {
calendar = calendar.split('|');
Expand All @@ -4063,6 +4064,8 @@ KronolithCore = {
this.ecache.get(calendar[0]).get(calendar[1]).each(function(day) {
day.value.unset(event);
});
} else if (day) {
this.ecache.get(calendar[0]).get(calendar[1]).unset(day);
} else {
this.ecache.get(calendar[0]).unset(calendar[1]);
}
Expand Down Expand Up @@ -4107,6 +4110,7 @@ KronolithCore = {
!this.ecache.get(cals[0]).get(cals[1])) {
return $H();
}
var x = this.ecache.get(cals[0]).get(cals[1]).get(date);
return this.ecache.get(cals[0]).get(cals[1]).get(date);
}

Expand Down Expand Up @@ -5288,6 +5292,7 @@ KronolithCore = {
}, this);
}
this.loadEventsCallback(r, false);
this.refreshResources(newDate.toString('yyyyMMdd'), cal, eventid, lastDate.toString('yyyyMMdd'));
}.bind(this);

if (event.value.mt) {
Expand Down Expand Up @@ -5450,6 +5455,10 @@ KronolithCore = {
// request.
if (r.events &&
r.sig == this.eventsLoading[r.cal]) {
if (event.value.rs) {
var d = new Date(event.value.s);
this.refreshResources(d.toString('yyyyMMdd'), event.value.calendar, event.key)
}
this.removeEvent(event.value.calendar, event.key);
}
this.loadEventsCallback(r, false);
Expand All @@ -5473,6 +5482,57 @@ KronolithCore = {
});
},

/**
* Refresh any resource calendars bound to the given just-updated event.
* Clears the old resource event from UI and cache, and clears the cache
* for the days of the new event, in order to allow listEvents to refresh
* the UI.
*
* @param string dt The current/new date for the event (yyyyMMdd).
* @param string cal The calendar the event exists in.
* @param string eventid The eventid that is changing.
* @param string last_dt The previous date for the event, if known. (yyyyMMdd).
*
*/
refreshResources: function(dt, cal, eventid, last_dt)
{
var events = this.getCacheForDate(dt, cal),
event = events.find(function(e) { return e.key == eventid; }),
dates = this.viewDates(this.parseDate(dt), this.view),
update_cals = [], r_dates;

if (event) {
$H(event.value.rs).each(function(r) {
var r_cal = ['resource', r.value.calendar],
r_events = this.getCacheForDate(last_dt, r_cal.join('|')),
r_event, day;

if (r_events) {
r_event = r_events.find(function(e) { return e.value.uid == event.value.uid });
if (r_event) {
this.removeEvent(r_cal, r_event.key);
day = event.value.start.clone();
end = event.value.end.clone().add(1).day();
while (!day.isAfter(end)) {
this.deleteCache(r_cal, null, day.toString('yyyyMMdd'));
day.add(1).day();
}
} else {
// Don't know the previous date/time so just nuke the cache.
this.deleteCache(r_cal);
}
} else {
this.deleteCache(r_cal);
}
update_cals.push(r_cal);
}.bind(this));

if (update_cals.length) {
this.loadEvents(dates[0], dates[1], this.view, update_cals);
}
}
},

editEvent: function(calendar, id, date, title)
{
if (this.redBoxLoading) {
Expand Down Expand Up @@ -5689,7 +5749,9 @@ KronolithCore = {
this.removeEvent(cal, eventid);
}
this.loadEventsCallback(r, false);
var calendar = cal.split('|');

// Refresh bound exceptions
var calendar = cal.split('|'), refreshed = false;
$H(r.events).each(function(d) {
$H(d.value).each(function(evt) {
if (evt.value.bid) {
Expand All @@ -5700,8 +5762,13 @@ KronolithCore = {
}
}.bind(this));
}
if (!refreshed && evt.key == eventid && evt.value.rs) {
this.refreshResources(evt.value.start.toString('yyyyMMdd'), cal, eventid, false);
refreshed = true;
}
}.bind(this))
}.bind(this));

if (r.events) {
this.resetMap();
this.closeRedBox();
Expand Down
15 changes: 8 additions & 7 deletions kronolith/lib/Event.php
Expand Up @@ -164,10 +164,10 @@ abstract class Kronolith_Event
/**
* All resources of this event.
*
* This is an associative array where keys are resource uids values are
* This is an associative array where keys are resource uids, values are
* associative arrays with keys attendance and response.
*
* @var unknown_type
* @var array
*/
protected $_resources = array();

Expand Down Expand Up @@ -2306,6 +2306,7 @@ public function toAlarm($time, $user = null, $prefs = null)
public function toJson($allDay = null, $full = false, $time_format = 'H:i')
{
$json = new stdClass;
$json->uid = $this->uid;
$json->t = $this->getTitle();
$json->c = $this->calendar;
$json->s = $this->start->toJson();
Expand Down Expand Up @@ -2350,7 +2351,9 @@ public function toJson($allDay = null, $full = false, $time_format = 'H:i')
$json->eod = sprintf(_("%s at %s"), $this->exceptionoriginaldate->strftime($GLOBALS['prefs']->getValue('date_format')), $this->exceptionoriginaldate->strftime(($GLOBALS['prefs']->getValue('twentyFour') ? '%H:%M' : '%I:%M %p')));
}
}

if ($this->_resources) {
$json->rs = $this->_resources;
}
if ($full) {
$json->id = $this->id;
$json->ty = $this->calendarType;
Expand Down Expand Up @@ -2388,9 +2391,6 @@ public function toJson($allDay = null, $full = false, $time_format = 'H:i')
}
}
}
if ($this->_resources) {
$json->rs = $this->_resources;
}
if ($this->methods) {
$json->m = $this->methods;
}
Expand Down Expand Up @@ -2711,7 +2711,8 @@ public function addResource($resource, $response)
$this->_resources[$resource->getId()] = array(
'attendance' => Kronolith::PART_REQUIRED,
'response' => $response,
'name' => $resource->get('name')
'name' => $resource->get('name'),
'calendar' => $resource->get('calendar')
);
}

Expand Down

0 comments on commit 2aa3e89

Please sign in to comment.