Possible bug fix

I have been trying to debug an issue with the scheduler for a few days now and it has been driving me a bit crazy. I am really pleased now though - because I have managed to debug and fix the issue.

When you use dynamic loading of data (we are playing with scheduler.setLoadMode(“month”);), you can sometimes end up with event double ups in the month view. This occurs if you start in week or day view and then switch into month view. If you start immediately in month view, the issue does not occur.

It appears that the scheduler tries to load a three month period using a single Ajax request (eg April to July) and is unaware that the middle month is already loaded into the scheduler. For this reason the middle month (in our case May) ends up with two of every event. (The existing events plus the new ones from the ajax request)

To fix the code, I added the following two lines to dhtmlxscheduler.js

     if (this._load_mode=="month"){
        this.clearAll();
    }

This is directly before the line

dhtmlxAjax.get(url+"&from="+lf(from)+"&to="+lf(to),function(l){scheduler.on_load(l);});    

This has worked for us but is a bit of a hack. Because will not use use the year, agenda or two month views, I suspect the issue may also occur in these.

I thought I would post this in the forum in case anyone else had experienced the same problem and been unable to replicate the issue.

We will double-check such behavior.

By the way, even if data is loaded twice ( which must not be, but probably is possible in some cases ) it must not cause event dupplication. During data loading, scheduler checks if event with such ID already presents , and when it exists - update existing event instead of previous one. So while events has constant IDs , dupplication must not occur.

Thanks for the hint about it not reloading the id numbers. It turns out the actual issue is specific to using iCal files.

In an iCal file, we use the reference “UID=” to set the id of the event. The dhtmlscheduler.js file does not use this as the event id and creates its own unique id on the fly (hence the double ups)

I solved the issue by including an extra entry in the iCal file stating what the “ID” value is (as well as UID).

    echo "BEGIN:VEVENT\r\n";
    echo "UID:" . $row['id'] . "\r\n";
    echo "ID:" . $row['id'] . "\r\n";
    echo "SUMMARY:" . $row['title'] . "\r\n";
    echo "DESCRIPTION:" . $row['notes'] . "\r\n";

etc…

I could have also resolved it by adding an extra mapping in the javascript file (in the function scheduler.ical) to swap UID to ID.

Once I included the extra line in the iCal file, I didn’t need the clearAll in my previous forum posting. It also means the correct id value comes through when you use the “OnBeforeLightbox” event (and probably several other event handlers)

To prevent similar problems in future we will add logic, which will use UID as event’s ID, when ID property is not defined. Update will be included in the next build.

Thanks for useful info.