This is a migrated thread and some comments may be shown as answers.
Custom Edit Template With Scheduler Edit Event
2 Answers 135 Views
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 23 May 2014, 05:23 PM
First, love the control, love the MVC wrapper, love the extensibility, love the support and available help.  Now to the issue!

I have created a custom edit template which includes resources.  However, I want some of those resources to not be displayed if the difference between the event start and the time the user double clicks the event is, say, greater than 24 hours. 

I used the Scheduler edit event to set a variable in a javascript function like so...

        .Events(e => { e.Edit("checkValidCancelDate"); }

The function (and global variable):

var showCancelOptions = true;
function checkValidCancelDate(e) {
    var start = e.event.start;
    var now = new Date();

    var startMs = start.getTime();
    var nowMs = now.getTime();

    var hours = (startMs - nowMs) / (1000 * 60 * 60);

    if (hours <= 24) {
        showCancelOptions = false;
    }
}

That all works, but here is the kicker...if I check for that variable with my sweet custom script for the editor template, the variable's value isn't set appropriately, and the resources display.  The script (inside the editor template script) looks like..

 if (resources[resource].title != 'I plan on:' || showCancelOptions) {
       ... 8< ... classic Kendo resource display template code goes here
 }

Because that script actually runs BEFORE the edit event is handled!!!  I have verified this with alert statements.  So the second time the user edits the event, it actually works (the resources don't display), because the editor template script takes the value of the variable from the previous edit click!!!

So, my question is, is there a way to make the edit event fire BEFORE the custom editor template script runs to generate the HTML for the modal dialog that pops up?  Or similarly, is there a way to make the event edit dialog be constructed and shown AFTER the edit event has fired?

Thanks in advance!
Adam

2 Answers, 1 is accepted

Sort by
0
Roderick Prince
Top achievements
Rank 1
answered on 23 May 2014, 08:05 PM
Adam,

Have you tried removing the items you don't want displayed in the Edit event?

Below I am removing the update and delete buttons as an example...

function scheduler_edit(e) {
var scheduler = $("#scheduler").data("kendoScheduler");

if (!userIsEditor) {
$(".k-scheduler-update").remove();
$(".k-scheduler-delete").remove();
$("#editTemplate").remove();
}
else {
$("#viewTemplate").remove();
}
}
0
Vladimir Iliev
Telerik team
answered on 27 May 2014, 10:08 AM
Hi Adam,

Basically it's not possible to trigger the "edit" event before the template is executed. In current case I would suggest to render all resource editors inside the template and use the "edit" event to hide / remove the ones that you doesn't need.

Kind Regards,
Vladimir Iliev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Asked by
Adam
Top achievements
Rank 1
Answers by
Roderick Prince
Top achievements
Rank 1
Vladimir Iliev
Telerik team
Share this question
or