This is a migrated thread and some comments may be shown as answers.

getAppointmentsInRange() not detecting appointments

1 Answer 63 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Marbry
Top achievements
Rank 1
Marbry asked on 16 Jan 2013, 10:31 PM

I am trying to prevent the user from resizing an appointment such that it would overlap with another appointment within the same resource.  The problem seems to be when the end of the appointment being resized is dragged over another that is only 1 day in duration, it's not detecting that appointment as being within the start and end dates.  I'm using the timeline view where each slot is 1 day.

I can set the start time that it passes to the function to one ms less where it spans the day boundary and it works.  If I set it back to 00:00:00 it doesn't.

The code I'm using is below, ResizingTarget() is the handler for the scheduler's OnClientAppointmentResizeEnd event.

function ResizingTarget(sender, args)
{
    if (!isSlotFree(args.get_targetSlot(), args.get_appointment()))
    {
        args.get_appointment().get_element().style.border = "0px none black";
        args.set_cancel(true);
    }
    else
    {
        var apt = args.get_appointment();
        var newTime = args.get_newStartTime();
        var featureId = apt.get_id();
 
 
        // Call web service to update target
    }
}
 
 
 
function isSlotFree(targetSlot, appointment)
{
    //Get start time of target calendar slot
    var startTime = targetSlot.get_startTime();
 
    //Ensure reference to RadScheduler client object
        if (_sched == null)
            _sched = $find( "<%= targets.ClientID %>" );
 
    //Calculate end time (to create span that cannot be overlapped)
    var endTime = new Date(startTime.getTime() + 86400000); //24hr period
    startTime = new Date(startTime.getTime());
 
    //Determine if appt being moved overlaps with another appointment
    return !overlapsWithAnotherAppointment(appointment, startTime, endTime);
}
 
 
function overlapsWithAnotherAppointment(appointment, startTime, endTime)
{
        if (_sched == null)
            _sched = $find( "<%= targets.ClientID %>" );
 
    // Get all appts in range of start and end time
    var appointments = _sched.get_appointments().getAppointmentsInRange(startTime, endTime);
 
    if (appointments.get_count() == 0)
        return false;
 
 
    var strID = "";
    var apptCnt = appointments.get_count();
 
    for (var i = 0; i < apptCnt; i++)
    {
        if (appointments._array[i]._id != appointment._id)
        {
            if (appointments._array[i]._serializedResources[0].key == appointment._resources._array[0]._key)
                return true;
        }
    }
 
    return false;
}

1 Answer, 1 is accepted

Sort by
0
Marbry
Top achievements
Rank 1
answered on 17 Jan 2013, 02:43 PM
I believe I've resolved this.  I just pass the get_newStartTime() and get_newEndTime() from the event arguments as the start and end times.  It seems it won't detect an appointment if the start and end are the same as the appointment's dates.
Tags
Scheduler
Asked by
Marbry
Top achievements
Rank 1
Answers by
Marbry
Top achievements
Rank 1
Share this question
or