getAppointmentsInRange() not detecting appointments

2 posts, 0 answers
  1. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 16 Jan 2013 Link to this post

    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;
    }
  2. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 17 Jan 2013 Link to this post

    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.
Back to Top