I see a issue here, recurring events are treated as a single event, with rec_type pattern, unless explicitly edited a event from the series of events.
what i want is to save recurring events as individual events.
i am on PHP. please help.
I see a issue here, recurring events are treated as a single event, with rec_type pattern, unless explicitly edited a event from the series of events.
what i want is to save recurring events as individual events.
i am on PHP. please help.
There is no built in solution for such scenario.
Technically it possible to use getRecDates method to get all occurrences of recurring events and use addEvent to add separate event objects to each date, after which original recurring event can be deleted.
( getRecDates is not available in official 2.2 package, you need to use viewtopic.php?f=6&t=13634&p=40136&hilit=getrecdates#p40136)
does scheduler.getRecDates(event_id) works for saved events only? how to use this method
when saving a new recurring event? i mean what i want is depending on the rec_type pattern user selected, i would like to save all the events as individual. is there any sample regarding this? it’s getting all my days and still couldn’t get out of this issue. please help.
It doesn’t depends on server side and works for any recurring event on client side
how to use this method
when saving a new recurring event?
You can attach your custom handler to onEventAdded, from which delete recurring event and create new non-recurring events, for each occurrence.
Such functionality is not a part of scheduler, but mostly “hack”
@Stanislav thanks,
i’ve added following code:
scheduler.attachEvent("onEventAdded", function(event_id,event_object){
//any custom logic here
if(event_id!=''){
var xyz = scheduler.getRecDates(event_id);//
alert(xyz.toSource());
}
});
this works fine in the case i enable repeat & displays array of start_date & end_date as you’ve mentioned,
[{start_date:(new Date(1277881200000)), end_date:(new Date(1277882100000))}, {start_date:(new Date(1277967600000)), end_date:(new Date(1277968500000))}, {start_date:(new Date(1278054000000)), end_date:(new Date(1278054900000))}, {start_date:(new Date(1278140400000)), end_date:(new Date(1278141300000))}, {start_date:(new Date(1278226800000)), end_date:(new Date(1278227700000))}]
but for the case repeat is disabled, when i try to save new events from lightbox i am receiving following error:
scheduler.date[“transpose_” + ev.rec_pattern] is not a function
—>scheduler.date[“transpose_”+ev.rec_pattern](td, from);
what’s wrong here?
Method will fail for non-recurring events, you can use
if(event_id!='' && scheduler.getEvent(event_id).rec_type){
so logic will be triggered for recurring events only.
thanks so far, i added the line, the error is gone now, my code looks like this, what am i missing here? events is still saved as recurring.
[code]scheduler.attachEvent(“onEventAdded”, function(event_id,event_object){
//alert(event_object.toSource());
//return false;
if(event_id!=’’ && scheduler.getEvent(event_id).rec_type){
var eventText = event_object.text;
var repeatArray = new Array();
var repeatArray = scheduler.getRecDates(event_id);
var repeatCount = repeatArray.length;
for (var i = 0; i < repeatCount; i++){
var start_date = repeatArray[i]['start_date'];
var end_date = repeatArray[i]['end_date'];
scheduler.addEvent({
start_date: start_date,
end_date: end_date,
text:eventText
});
}
scheduler.deleteEvent(event_id);
}
else return true;
//rec_type:event_object.rec_type,
//rec_pattern:event_object.rec_pattern,
//event_length:event_object.event_length
});[/code]
to be true, i am still not actually getting the idea of onEventAdded. please help.
a) be sure that attachEvent is called BEFORE init of dataprocessor
b) change your code as
[code] //alert(event_object.toSource());
//return false;
if(event_id!=’’ && scheduler.getEvent(event_id).rec_type){
var eventText = event_object.text;
var repeatArray = new Array();
var repeatArray = scheduler.getRecDates(event_id);
var repeatCount = repeatArray.length;
var new_id = event_id; //added
scheduler.deleteEvent(event_id);
for (var i = 0; i < repeatCount; i++){
var start_date = repeatArray[i]['start_date'];
var end_date = repeatArray[i]['end_date'];
scheduler.addEvent({
id:new_id, //added
start_date: start_date,
end_date: end_date,
text:eventText
});
if (new_id!=event_id) //added
dp.setUpdated(id, true, "inserted"); //added
new_id = scheduler.uid(); //added
}
}
else return true;[/code]
In updated code - “dp” - name of var , which used for dataprocessor object.
@Stanislav
thanks a lot,
i see events are being added to database as individual events, but i see an error:
id is not defined
in line -> dp.setUpdated(id, true, “inserted”); //added
i tried using “new_id” and it works with no error. is that correct?
really, grateful to your support. cheers!
i tried using “new_id” and it works with no error. is that correct?
Yep, was a my typo
Your fix is correct.
@Stanislav, this works like a charm, thank a lot.
i got a situation here, we saved the event as individual deleting the original recurring event, but i think it would be better if we could preserve the recurring property of the original events (the event with rec_type=PATTERN ) & create all the recurring events individually in the series at save time. What i want is:
Create Individual Events from the rec_type pattern. each events in the recurring series would be in their own row in database table, i think they have rec_type=none & event_pid = id of the root event.
Hope i am clear on this. Please suggest how would we do this?
code similar to previous one can be used with next modifications
a) you need not delete original event
b) var new_id = event_id; need to be replaced with var new_id = scheduler.uid();
c) addEvent command will look as
scheduler.addEvent({
id:new_id, //added
start_date: start_date,
end_date: end_date,
text:eventText,
event_pid:event_id,
event_length:start_date.valueOf()/1000,
rec_type:""
});
As result you will have separate records for each event, and in same time, they will be recognized of instances of the same event, and can be deleted|modified all at once.
after each addEvent call you need to add the next call
scheduler._add_rec_marker(scheduler.getEvent(new_id),start_date);
@Stanislav
i am getting events in table but pid is not correctly being set, i see random value like 2147483647, also scheduler is rendering same event twice in the same time slot??
here’s my code:
[code]scheduler.attachEvent(“onEventAdded”, function(event_id,event_object){
if(event_id!='' && scheduler.getEvent(event_id).rec_type){
var eventText = event_object.text;
var repeatArray = new Array();
var repeatArray = scheduler.getRecDates(event_id);
var repeatCount = repeatArray.length;
var new_id = scheduler.uid();
for (var i = 0; i < repeatCount; i++){
var start_date = repeatArray[i]['start_date'];
var end_date = repeatArray[i]['end_date'];
scheduler.addEvent({
start_date: start_date,
end_date: end_date,
text:eventText,
event_pid:event_id,
event_length:start_date.valueOf()/1000,
rec_type:""
});
}
scheduler._add_rec_marker(scheduler.getEvent(new_id),start_date);
if (new_id!=event_id); //added
dp.setUpdated(new_id, true, "inserted"); //added
new_id = scheduler.uid(); //added
}
else return true;
});[/code]
a) move scheduler._add_rec_marker in for loop, it need to be called for each newly added event , it must resolve event duplication.
b) as for event pid - problem can be caused by Id changing on server side , in moment of onEvenAdded call , we don’t know final ID of event, but newly created child-events need to have that final ID as pid value.
You can try to move logic from onEventAdded to the onEventIdChange event - it will be called after id change, so you can executed the same logic against final id.
@Stanislav i noticed the duplication was due to missing pid value, and your point (b) explains it well. Since we are creating individual events & also now the main events with rec_type too gets inserted, this resulted in duplicate rendering.
i need to do this and could you please suggest me something to start with on:
thanks a lot for your quick responses.
Hello,
Do you an example how to solve this problem at the server side?
Regards,
Michiel Klaver
probably you can add server side handler to afterInsert and update all records in DB with old pid value to the new pid value.
Something like
function myupdates($action){
$oldid = $action->get_id();
$newid = $action->get_new_id();
mysql_query("UPDATE events SET event_pid=$oldid WHERE event_pid=$new_id");
}
$grid->event->attach("afterInsert", "myupdates")
Hello,
Can you tell me what’s wrong with the code below? I get this error: this.getEvent(B) is undefined [Break on this error] loadUpdate:function(){var B=this;var A…e(A.end_date);scheduler.addEvent(A)};
Regards,
Michiel Klaver
[code] scheduler.attachEvent(“onEventAdded”, function(event_id,event_object){
if(event_id!="" && scheduler.getEvent(event_id).rec_type){
var eventText = event_object.text;
var eventReminder = event_object.event_reminder;
var eventCustom_1 = event_object.event_custom_1;
var eventCustom_2 = event_object.event_custom_2;
var eventLocation = event_object.event_location;
var eventProject_id = event_object.project_id;
var eventDebtor_id = event_object.debtor_id;
var eventEmployee_id = event_object.employee_id;
var eventAct_id = event_object.act_id;
var eventRoom_id = event_object.room_id;
var eventEquip_id = event_object.equip_id;
var eventRec_type = "";
var eventRec_pattern = "";
var eventShared_employees = event_object.event_shared_employees;
var eventSendmail = event_object.sendmail;
var eventKm_start = event_object.event_km_start;
var eventKm_end = event_object.event_km_end;
var repeatArray = new Array();
var repeatArray = scheduler.getRecDates(event_id);
var repeatCount = repeatArray.length;
var new_id = scheduler.uid();
for (var i = 0; i < repeatCount; i++){
var start_date = repeatArray[i]["start_date"];
var end_date = repeatArray[i]["end_date"];
scheduler.addEvent({
id: new_id,
start_date: start_date,
end_date: end_date,
text: eventText,
event_reminder: eventReminder,
event_custom_1: eventCustom_1,
event_custom_2: eventCustom_2,
event_location: eventLocation,
project_id: eventProject_id,
debtor_id: eventDebtor_id,
employee_id: eventEmployee_id,
act_id: eventAct_id,
room_id: eventRoom_id,
equip_id: eventEquip_id,
event_pid: event_id,
event_length: start_date.valueOf()/1000,
rec_type: "",
event_shared_employees: eventShared_employees,
event_km_start: eventKm_start,
event_km_end: eventKm_end,
sendmail: eventSendmail
});
scheduler._add_rec_marker(scheduler.getEvent(new_id),start_date);
}
if (new_id!=event_id){
dp.setUpdated(new_id, true, "inserted");
new_id = scheduler.uid();
}
}
else return true;
});
[/code]
Its hard to say, based on current info
Can you provide some kind of sample, or error details in case of not-minified code?