search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

How do you use EventResizeJavaScript and similar with MVC

Asked by Tony
10 years ago.

Hi,

I'm trying to use the MVC control scheduler, and would like the page to redirect to a different action (page) after an event has been created/moved etc. The only way I can see of doing this is to use the Javascript functions, but these don't seem to work with MVC. If I try to use them I can't find __doPostback the web forms handler, so it doesn't look like they'll work.

Is there a way to use these Javascript events with MVC. Or better how can I simply redirect after moving an after - there doesn't seem to be a aftermove event on the scheduler control.

Answer posted by Dan Letecky [DayPilot]
10 years ago.

This is not a typical scenario and that makes the solution a bit complicated. What you need to do in the JavaScript is to call the server-side handler and then make sure the request has been completed before redirecting to the other page.

This is how you fire the server-side OnEventMode handler using your own JavaScript:

        <%= Html.DayPilotScheduler("dps", new DayPilotSchedulerConfig {
                BackendUrl = ResolveUrl("~/Scheduler/Backend"),
                ...
                EventMoveHandling = EventMoveHandlingType.CallBack,
                EventMoveJavaScript = "dps.eventMoveCallBack(e, newStart, newEnd, newResource);",
                ...

Then you need to know that the request has been sent successfully. The right way is to use AfterRenderJavaScript that gets called after the callback response is processed. You need to know that this callback was a result of eventMoveCallBack - you can do that by passing custom object to Update() on the server side:

            protected override void OnTimeRangeSelected(TimeRangeSelectedArgs e)
            {
                new EventManager(Controller).EventCreate(e.Start, e.End, "Default name", e.Resource);
                Update("moved", CallBackUpdateType.EventsOnly);
            }
        <%= Html.DayPilotScheduler("dps", new DayPilotSchedulerConfig {
                BackendUrl = ResolveUrl("~/Scheduler/Backend"),
                ...
                EventMoveHandling = EventMoveHandlingType.CallBack,
                EventMoveJavaScript = "dps.eventMoveCallBack(e, newStart, newEnd, newResource);",
                AfterRenderJavaScript = "if (isCallBack && data == 'moved') { document.location.href = 'NewPage.aspx'; }",
                ...

You can also use this hack and just wait some time to allow the request to complete:

        <%= Html.DayPilotScheduler("dps", new DayPilotSchedulerConfig {
                BackendUrl = ResolveUrl("~/Scheduler/Backend"),
                ...
                EventMoveHandling = EventMoveHandlingType.CallBack,
                EventMoveJavaScript = "dps.eventMoveCallBack(e, newStart, newEnd, newResource); setTimeout(function() { document.location.href = 'NewPage.aspx'; }, 500);",
                ...

Answer posted by Dan Letecky [DayPilot]
10 years ago.

Build 5541 now supports Redirect() method in DayPilotCalendar, DayPilotScheduler and DayPilotMonth classes. You can use it to redirect to another page after the callback event has been processed.

Example:

            protected override void OnEventClick(EventClickArgs e)
            {
                Redirect("http://www.daypilot.org/");
            }

You can download the latest build in the sandbox:

http://mvc.daypilot.org/sandbox/

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.