From: Jan Schneider Date: Fri, 20 Feb 2009 23:02:34 +0000 (+0100) Subject: Fix changing dates in the same view. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f7ca49e3827d686098c54165c2b75c3fca52eb93;p=horde.git Fix changing dates in the same view. Catch if view has changed again when events arrive. Send calendar with events. --- diff --git a/kronolith/ajax.php b/kronolith/ajax.php index e309dbe6d..af2b0602b 100644 --- a/kronolith/ajax.php +++ b/kronolith/ajax.php @@ -54,13 +54,15 @@ $result = false; switch ($action) { case 'ListEvents': - $dates = Kronolith::listEvents(Util::getFormData('start'), Util::getFormData('end')); + $start = new Horde_Date(Util::getFormData('start')); + $end = new Horde_Date(Util::getFormData('end')); + $dates = Kronolith::listEvents($start, $end); if (is_a($dates, 'PEAR_Error')) { $notification->push($dates, 'horde.error'); $result = false; } else { $result = new stdClass; - $result->events = array(); + $result->sig = $start->dateString() . $end->dateString(); foreach ($dates as $date => $events) { foreach ($events as $id => $event) { $result->events[$date][$id] = $event->toJSON(); diff --git a/kronolith/js/src/kronolith.js b/kronolith/js/src/kronolith.js index 250eb44d7..02290f7f4 100644 --- a/kronolith/js/src/kronolith.js +++ b/kronolith/js/src/kronolith.js @@ -17,9 +17,12 @@ var frames = { horde_main: true }, KronolithCore = { // Vars used and defaulting to null/false: // DMenu, alertrequest, inAjaxCallback, is_logout, onDoActionComplete, - // eventForm + // eventForm, eventsLoading view: '', + calendars: [], + ecache: {}, + efifo: {}, date: new Date(), doActionOpts: { @@ -273,16 +276,12 @@ KronolithCore = { case 'year': case 'agenda': case 'tasks': - if (this.view == loc) { - break; - } - var locCap = loc.capitalize(); [ 'Day', 'Week', 'Month', 'Year', 'Tasks', 'Agenda' ].each(function(a) { $('kronolithNav' + a).removeClassName('on'); }); $('kronolithNav' + locCap).addClassName('on'); - if (this.view) { + if (this.view && this.view != loc) { $('kronolithView' + this.view.capitalize()).fade(); } @@ -298,6 +297,13 @@ KronolithCore = { date = this.date; } + if (this.view == loc && date.getYear() == this.date.getYear() && + ((loc == 'year') || + (loc == 'month' && date.getMonth() == this.date.getMonth()) || + (loc == 'day' && date.dateString() == this.date.dateString()))) { + return; + } + this.updateView(date, loc); if ($('kronolithView' + locCap)) { $('kronolithView' + locCap).appear(); @@ -343,14 +349,13 @@ KronolithCore = { case 'month': var body = $('kronolithViewMonth').down('.kronolithViewBody'), day = date.clone(), monthEnd = date.clone(), - cell, monday, firstDay, lastDay; + cell, monday, firstDay; // Calculate first and last days being displayed. day.setDate(1); - firstDay = day.clone() day.moveToBeginOfWeek(); + firstDay = day.clone() monthEnd.moveToLastDayOfMonth(); - lastDay = monthEnd.clone(); monthEnd.moveToBeginOfWeek(); // Remove old rows. Maybe we should only rebuild the calendars if @@ -364,7 +369,7 @@ KronolithCore = { } // Load events. - this.doAction('ListEvents', { start: firstDay.toJSON(), end: lastDay.toJSON() }, this._monthCallback.bind(this)); + this._loadEvents(firstDay, monthEnd, this._monthCallback.bind(this)); break; } @@ -463,6 +468,14 @@ KronolithCore = { }, /** + */ + _loadEvents: function(firstDay, lastDay, callback, calendar) + { + this.eventsLoading = firstDay.dateString() + lastDay.dateString(); + this.doAction('ListEvents', { start: firstDay.toJSON(), end: lastDay.toJSON() }, callback); + }, + + /** * Callback method for inserting events in the month view. * * @param object r The returned object. @@ -471,10 +484,15 @@ KronolithCore = { { var div; - if (typeof r.response.events.length == 'undefined') { + // Check if this is the still the result of the most current request. + if (r.response.sig != this.eventsLoading) { + return; + } + + if (r.response.events) { $H(r.response.events).each(function(date) { $H(date.value).each(function(event) { - div = new Element('DIV', { 'class': 'kronolithEvent', 'style': 'background-color:' + event.value.bg + ';color:' + event.value.fg }); + div = new Element('DIV', { 'class': 'kronolithEvent', 'style': 'background-color:' + event.value.bg + ';color:' + event.value.fg, 'calendar': event.value.c }); div.setText(event.value.t) .observe('mouseover', div.addClassName.curry('kronolithSelected')) .observe('mouseout', div.removeClassName.curry('kronolithSelected')); @@ -677,6 +695,7 @@ KronolithCore = { elt = elt.up(); } + Prototype.emptyFunction(); }, mouseHandler: function(e, type) diff --git a/kronolith/lib/Driver.php b/kronolith/lib/Driver.php index 964c65648..e32ff6d2d 100644 --- a/kronolith/lib/Driver.php +++ b/kronolith/lib/Driver.php @@ -1265,6 +1265,7 @@ class Kronolith_Event { { $json = new stdClass; $json->t = $this->getTitle(); + $json->c = $this->getCalendar(); $json->bg = $this->_backgroundColor; $json->fg = $this->_foregroundColor; return $json;