deleted event

When an event is deleted from the calendar, it is still visible on the calendar. How can I trigger for it to be removed without reloading the calendar?

Thanks.

Here is what I am doing now:

scheduler.attachEvent(“onBeforeEventDelete”,
function(event_id,event_object) {
var start_dt = convert(event_object.start_date);
var end_dt = convert(event_object.end_date);
<{if $admin == false}>
var now = new Date();
if ((event_object.start_date-now)/60000 < 60) {
alert(“You cannot cancel an appointment less than an hour before it is scheduled to take place.”);
return false;
}
<{/if}>
$.wiengine.request({
handle_only : 1,
panel_id : ‘<{insert name=“get_panel_id”}>’,
parameters : ‘&delete=1&event_id=’ + event_id,
});
scheduler.deleteEvent(event_id);
}
);

The event is successfully marked as canceled in my database, but deleteEvent doesn’t seem to do anything…

Hello,

scheduler.deleteEvent(event_id);

Itself calls onBeforeEventDelete event so I believe you have an infinite loop there.

You can delete event manually, replace

scheduler.deleteEvent(event_id);

with

delete scheduler._events[event_id]; scheduler.unselect(event_id); scheduler.event_updated(event_id);
Hope this helps.

Best regards,
Ilya

These lines of code work only if I switch to a different date range or view then back…it doesn’t remove the event from the screen immediately…

Hello,

Yes, sorry, I made a typo, it should be:

delete scheduler._events[event_id]; scheduler.unselect(event_id); scheduler.event_updated(event_object);
But there is even simpler way I believe:

return true;

instead those 3 lines above (in case you are not specifically blocking default deletion of the event).

Best regards,
Ilya

Try to change the above code as

var ev = scheduler.getEvent(id); delete scheduler._events[event_id]; scheduler.unselect(event_id); scheduler.event_updated(ev);

Also, you can use the next call

scheduler.deleteEvent(id, true);

setting the second parameter as true - will force silent deleting - no event will be triggered, no info will be sent to the server side.

Hello,

I’m getting different behavior for two deleting instances (single event, recurring - see onBeforeDelete below). Both situations result in a database delete. The data is correctly sent back in the ajax response.

For recurring events, the events are removed from the calendar, but the confirm message is not reached and the following error comes up:
ev is undefined
if (ev.start_date<this._max_date && this._min_date<ev.end_date) return true;
line 5608 dhtmlxscheduler.debug.js (line number may not match as I have commented out the two functions you replaced with code to center the details form on the screen)

For single events, there is no error, but the confirm message is not reached and the event is not removed from the calendar.

Thanks.

            scheduler.attachEvent("onBeforeEventDelete", 
                function(event_id,event_object) {
                    if(event_object.status == 'billed') {
                        alert("You cannot alter an appointment that has already been billed");
                        return false;
                    }
                    <{if $admin == false}>
                        var now = new Date();
                        if ((event_object.start_date-now)/60000 < 60) {
                            alert("You cannot cancel an appointment less than an hour before it is scheduled to take place.");
                            return false;
                        } 
                    <{/if}>
                    $("#working_message").show();
                    var start_dt = convert(event_object.start_date);
                    $.wiengine.request({
                        handle_only : 1,
                        panel_id : '<{insert name="get_panel_id"}>',
                        parameters : '&delete=1&event_id=' + event_id + '&start_dt=' + start_dt +
                                '&update_recurring=' + update_recurring + '&event_pid=' + event_object.event_pid,
                        onSuccess: function(response) {
                            temp = jQuery.parseJSON(response); //for recurring, returns action and deleted_ids
                            update_recurring = false;
                            if (response == 'deleted') {
                                delete scheduler._events[event_id];
                                scheduler.unselect(event_id);
                                scheduler.event_updated(event_object);
                                confirm("Event was deleted and notification sent to customer");
                            } else if (temp.action == 'recurring_deleted') {
                                for (var i in temp.deleted_ids) {
                                    var ev = scheduler.getEvent(temp.deleted_ids[i]);
                                    delete scheduler._events[temp.deleted_ids[i]];
                                    scheduler.unselect(temp.deleted_ids[i]);
                                    scheduler.event_updated(ev);
                                }
                                confirm("Recurring series was deleted and notification sent to customer");
                            }
                        }
                    });
                    $("#working_message").hide();
                }
            );   

I’m sorry, I solved the problem with the recurring events. They are being removed properly now and I reach my alert. However, the single events are still not being removed from the scheduler…

Thanks.

And I resolved the other problem too…sorry to bother you!

hi, if you don’t mind can you share how you solve that problem coz i’m facing that problem now :cry:

really appreciate your reply…