Blocking RadScheduler time slots

7 posts, 0 answers
  1. Paulo
    Paulo avatar
    31 posts
    Member since:
    Oct 2010

    Posted 25 Jan 2012 Link to this post

    Hello.

    I have been developing a web application that accesses the database via web service.
    In order to block time slots of the RadScheduler component, I have implemented the following method, which is associated with event OnTimeSlotCreated:
    protected void RadScheduler1_TimeSlotCreated(object sender, TimeSlotCreatedEventArgs e)
    {     
        // checking if the current time slot is blocked
        if (TimeSlotBlocked(e.TimeSlot.Resource.Key.ToString(), e.TimeSlot.Start, e.TimeSlot.End))
        {
            e.TimeSlot.CssClass = "Disabled";            
        }                                 
    }

    Method TimeSlotBlock checks if the resource is blocked for the start and end times provided:
    protected bool TimeSlotBlocked(String pt, DateTime dt1, DateTime dt2)
    {
        foreach (PTBlockedTime bt in blockedTime)
        {
            if ((pt == bt.PersonalTrainerId) && ((dt1.AddMinutes(+1) >= bt.Start && dt1.AddMinutes(+1) <= bt.End) || (dt2.AddMinutes(-1) >= bt.Start && dt2.AddMinutes(-1) <= bt.End)))
            {
                return true;
            }
        }
        return false;
    }

    blockedTime is a list of blocked times:
    public struct PTBlockedTime
    {
        public String PersonalTrainerId;
        public DateTime Start;
        public DateTime End;
      
        public PTBlockedTime(String pt, DateTime dt1, DateTime dt2)
        {
            PersonalTrainerId = pt;
            Start = dt1;
            End = dt2;
        }
    }
    .
    .
    .
    List<PTBlockedTime> blockedTime = new List<PTBlockedTime>();

    For testing purposes, I have loaded blockedTime on Page_Load:
    DateTime aux1 = new DateTime(2012, 1, 25, 8, 0, 0);
    DateTime aux2 = new DateTime(2012, 1, 25, 10, 0, 0);
    PTBlockedTime aux = new PTBlockedTime("575204", aux1, aux2);
    blockedTime.Add(aux);
    This list item indicates that resource "575204" is blocked from 08:00 AM to 10:00 AM on 01/25/2012.


    This solution works only partially for two reasons:

    1) Method TimeSlotCreated is not called when the calendar date changes. Although in the code above the resource is blocked only on 01/25/2012, all dates will have the time slots blocked from 8 to 10.
    Is there a way to solve this problem?

    2) Instead of Page_Load, the routine that populates the list of blocked times needs to be called every time the calendar date changes. This is required because the time resources are blocked varies on a daily basis. On one day, a resource might be blocked from 8 to 10 AM. On another day, from 5 to 7 AM. And in another day, not blocked at all.
    How can the list of blocked times be populated every time the calendar date changes?

    Thank you in advance.
    Paulo

  2. Paulo
    Paulo avatar
    31 posts
    Member since:
    Oct 2010

    Posted 29 Jan 2012 Link to this post

    Hello, Telerik Team.

    It has been a few days since I posted the question about the RadScheduler time slots.
    It is very important that this issue is clarified so that I can finalize the application I have been working on for quite some time.
    I would appreciate whether an answer could be provided ASAP.

    Thank you in advance.
    Paulo
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Plamen
    Admin
    Plamen avatar
    2734 posts

    Posted 30 Jan 2012 Link to this post

    Hi Paulo,

     
    You can add the desired CSS in the OnClientDataBound  event as it is done in the following code:

    function OnClientDataBound(sender) {
     
              var $ = $telerik.$;
     
              var now = new Date();
     
              $(".rsAllDayTable:visible td", sender.get_element()).each(function (i) {
     
                  var currentTimeSlot = sender.get_activeModel().getTimeSlotFromDomElement($(this).get(0));
     
                  $(this).css("background", " ");
     
                  if (currentTimeSlot.get_startTime() < now)
     
                      $(this).css("background", "silver");
     
              });
     
              $(".rsContentTable:visible td", sender.get_element()).each(function (i) {
     
                  var currentTimeSlot = sender.get_activeModel().getTimeSlotFromDomElement($(this).get(0));
     
                  $(this).css("background", " ");
     
                  if (currentTimeSlot.get_startTime() < now)
     
                      $(this).css("background", "silver");
     
              });
     
          }

    Hope this will be helpful.

     

    All the best,
    Plamen Zdravkov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  5. Paulo
    Paulo avatar
    31 posts
    Member since:
    Oct 2010

    Posted 08 Feb 2012 Link to this post

    Hello, Plamen.

    Thank you for your reply.

    1) After implementing your suggestion, I noticed that the time slots were not blocked when a date with no appointments was selected. So, I have moved the code from OnClientDataBound to OnClientAppointmentsPopulating. Do you agree with this change?

    2) In regard to the code itself, why are the same statements executed twice, once against rsAllDayTable and once against rsContentTable?
    I have commented out section rsAllDayTable and slots were still blocked. Why is that?

    3) In the application I have been developing, the condition to block or not a time slot depends on the resources.
    How can resources be identified in sections rsAllDayTable and rsContentTable?

    Thank you for your assistance.
    Paulo
  6. Plamen
    Admin
    Plamen avatar
    2734 posts

    Posted 13 Feb 2012 Link to this post

    Hello Paulo,

     
    1) It depends on when do you intended to use these changes, but the functionality should be working the same way.

    2)The rsAllDayTable class is for possible all day slots in DayView and WeekView.

    3)You can check the resources from the client object of the TimeSlot  by using the get_startTime() method. You can also refer to this help topic.

    Hope this will be helpful.

    Greetings,
    Plamen Zdravkov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  7. Paulo
    Paulo avatar
    31 posts
    Member since:
    Oct 2010

    Posted 15 Feb 2012 Link to this post

    Hello, Plamen.

    Thank you very much for your reply.

    In AppointmentsPopulating, I have been able to access the resources by referencing sender.get_resources and looping through them:
    function AppointmentsPopulating(sender, args)
    {
        // retrieving the resources
        var resources = sender.get_resources();
      
        if (resources._array.length > 0)
        {
            for (i = 0; i < resources._array.length; i++)
            {

    As I mentioned previously, I need to retrieve the availability of the resources in order to block the time slots or not.
    So, inside the loop, I call a web service method:
    var date = new Date();
    var ret = "";
    ret = Scheduling.SchedulingWebService.AssociateAvailabilityDate(document.getElementById("club_id").value, resources.getResource(i).get_attributes().getAttribute("Resource"),
                                                                      document.getElementById("res_type").value, date);                                                         

    Although there is no compilation error, the value of local variable ret is equal to "undefined" after the web service method is executed.
    In order to debug this issue, I have created a simple HelloWorld method in the web service class:
    namespace Scheduling
    {
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        [System.Web.Script.Services.ScriptService]
      
        public class SchedulingWebService : System.Web.Services.WebService
        {
            [WebMethod]
            public string HelloWorld()
            {
                return "Hello World";
            }
        }
    }

    And I call it from the client side:
    var x = "";
    x = Scheduling.SchedulingWebService.HelloWorld();

    Just like when method AssociateAvailabilityDate is called, local variable x is equal to "undefined" after the web service method is executed.

    As an FYI, inside the RadScriptManager component, a reference to the web service has been added:
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            <asp:ScriptReference Path="AdvancedForm.js" />
        </Scripts>
      
        <Services>
            <asp:ServiceReference Path="SchedulingWebService.asmx" />
        </Services>
    </telerik:RadScriptManager>

    Is there anything I am missing?

    Thank you again for your assistance.
    Paulo
  8. Plamen
    Admin
    Plamen avatar
    2734 posts

    Posted 20 Feb 2012 Link to this post

    Hello Paulo,

     
    My suggestion was to get the resources depending on their name or id as in the yellow code bellow:

    $(".rsContentTable:visible td", sender.get_element()).each(function (i) {
     
                   var currentTimeSlot = sender.get_activeModel().getTimeSlotFromDomElement($(this).get(0));
                   if (currentTimeSlot.get_resource().get_text() == "Mr John Doe") {
                       $(this).css("background", "yellow");
                   }
     
    As for the implementation you suggested- this kind of functionality is not supported so far If you succeed in implementing such scenario, we will be glad if you share your solution. 

    Hope that will be helpful. 

    Regards,
    Plamen Zdravkov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017