event from one day to multi-day

Hello everyone, I have yet another question :wink:,

        On the scheduler, let's suppose I have an event that have the current parameters:

Start: 2010-12-17 10:00:00
End: 2010-12-17 14:00:00

Then, I go around and update the data as follow:

Start: 2010-12-17 10:00:00
End: 2010-12-24 14:00:00

So basically, the event changes from single day to multi-day. The problem is that I have to actually refresh my browser for the event to be rendered correctly, otherwise the scheduler still shows it as a single-day event. Is there a way to successfully update the scheduler when the state of an event changes from single-day to multi-day?

Thanks in advance

Osu

Instead of

scheduler.getEvent(id).start_date = ā€¦
scheduler.getEvent(id).end_date = ā€¦

Try to use

scheduler.setStartDate(id, ā€¦);
scheduler.setEndDate(id, ā€¦);

Thanks a lot, itā€™s working now :slight_smile:, though I had to use setEventStartDate and setEventEndDate. Anyway, you guys rock, great work and merry christmas :smiley:

Hi, I am using the set event date functions, but getting the following error:
ev.start_date.getDate is not a function
on line 5616 in dhtmlxscheduler_debug.js
"var delta = ev.end_date.getDate()-ev.start_date.getDate(); "

Actually, end_date is a field so it canā€™t technically have a function :wink:. What you want is probably something like:

var delta = scheduler.getEventEndDate(ev.id) - scheduler.getEventStartDate(ev.id);

Good luck :wink:

Osu

Well, I assumed that since it was part of the base code, getDate() existsā€¦have you made this change in your debug.js file?

Actually, start_date and end_date are both Javascript timestamps and this particular object does have methods (my bad sorry) but it doesnā€™t really matter since getDate doesnā€™t exists anyway. You can check out Date objectā€™s complete API here if you want:

w3schools.com/jsref/jsref_obj_date.asp

As for me modifying the degug.js, I havenā€™t touched it, getEventEndDate and getEventStartDate are both part of the schedulerā€™s base API, you can check it here:

docs.dhtmlx.com/doku.php?id=dhtm ā€¦ _reference

I hope that answers your question.

Osu

Be sure that you have used date objects, not strings for setStartDate and setEndDate methods ( setters doesnā€™t convert strings to dates automatically )

That was part of my problem - it resolved the issue I had in my simple individual event test case, but Iā€™m back to events updated in this if statement (else if (temp.action == ā€˜recurring_updateā€™)) disappearing after the updateEvent callā€¦

scheduler.attachEvent("onEventChanged", function(event_id,event_object) { $("#working_message").show(); var start_dt = convert(event_object.start_date); var end_dt = convert(event_object.end_date); for (var i = 0; i < sections.length; i++) { if (event_object.instrument_id == sections[i].key) { instr = sections[i].label; } } $.wiengine.request({ handle_only : 1, panel_id : '<{insert name="get_panel_id"}>', parameters : '&update=1&event_id=' + event_id + '&start_dt=' + start_dt + '&end_dt=' + end_dt + '&text=' + event_object.text + '&instr=' + event_object.instrument_id + '&discount=' + event_object.discount + '&is_assisted=' + event_object.is_assisted + '&update_recurring=' + update_recurring + '&event_length=' + length + '&event_pid=' + event_object.event_pid + '&rec_type=' + event_object.rec_type, onSuccess: function(response) { temp = jQuery.parseJSON(response); if (temp.action == 'update') { var ev = scheduler.getEvent(event_id); ev.cost = temp.cost; ev.instrument_name = instr; scheduler.updateEvent(event_id); } else if (temp.action == 'recurring_update') { for (var i = 0; i < temp.ids.length; i++) { var ev = scheduler.getEvent(temp.ids[i]); var start = revert(temp.start[i]); var end = revert(temp.end[i]); if (temp.ids[i] == event_id && temp.orig_instr_id != null) { ev.discount = temp.orig_discount; ev.cost = temp.costs[i]; ev.instrument_id = temp.orig_instr_id; ev.instrument_name = temp.orig_instr_name; scheduler.setEventStartDate(temp.ids[i], start); scheduler.setEventEndDate(temp.ids[i], end); ev.text = temp.orig_text; ev.is_assisted = temp.orig_assisted; } else { ev.cost = temp.costs[i]; ev.instrument_id = event_object.instrument_id; ev.instrument_name = instr; scheduler.setEventStartDate(temp.ids[i], start); scheduler.setEventEndDate(temp.ids[i], end); ev.discount = temp.discount; ev.text = event_object.text; ev.is_assisted = event_object.is_assisted; } scheduler.updateEvent(temp.ids[i]); } } } }); update_recurring = false; $("#working_message").hide(); } );

Have you checked whether your events are still in your database and if so, what happened to their data? And also, if your events are multi days, you have to include this line in the init() function somewhere:

scheduler.config.multi_day = true;

Also, have you tried your code with these lines instead:

var start = scheduler.getEventStartDate(temp.ids[i]);
var end = scheduler.getEventEndDate(temp.ids[i]);

Anyway, I hope this helps

Osu

So my problem has to do with the date object. I have the following:
var revert = scheduler.date.str_to_date("%Y-%m-%d %H:%i");

And then I use it in the following manner:
var start = revert(temp.start[i]);

Where temp.start[i] can have values such as: ā€˜20110125 1330ā€™ (Ymd Hi)

The resulting start variable is being alerted as an invalid date. What am I doing wrong?

Thanks.

The string you give to scheduler.date.str_to_date has to accurately match the format itā€™s written in. So if your date is in format ā€œYmd Hiā€, your string should reflect that. So in essence, if you want things to work accurately, you should change

var revert = scheduler.date.str_to_date("%Y-%m-%d %H:%i");

and put this instead:

var revert = scheduler.date.str_to_date("%Y%m%d %H%i");

Otherwise, just use the getEventStartDate and getEventEndDate functions, they already return a Date object so you wouldnā€™t have to use the revert variable anymore.

Best of luck

Osu

I noticed the issue with my date format and changed it to match the date string Iā€™m passing, but Iā€™m still getting an invalid date.

I canā€™t use getEventStartDate because the Iā€™m trying to update the date of events based on data I am pulling from my database, not based on what the calendar already knows.

Have you tried creating a function that reformats your date string by inserting the ā€œ-ā€ and ā€œ:ā€ at the right places and subsequently passing this string to the revert variable? This might work a little better.

20110125 1330
You will need to create a custom function or change format of data
The date conversion methods expects that group of digits will be separated by any chars and canā€™t split the numeric group in few separate values

Great, thank you.