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

[Solved] Q1 release and calendar control

5 Answers 156 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Susan
Top achievements
Rank 1
Susan asked on 01 Apr 2009, 06:53 PM
Hi  - I am using the calendar control and the Q1 2009 version. I have a resource called Status
I have my calendar configured so that if a status of an event is Completed then it is green.
I have defined two possible statuses for an event - Completed and NotCompleted. Below is the markup:

 <telerik:RadScheduler ID="RadScheduler1" runat="server" DataEndField="ENDTIME"
        DataKeyField="ID" DataRecurrenceField="RECURRENCERULE"
        DataRecurrenceParentKeyField="RECURRENCEPARENTID" DataSourceID="SqlDataSource1"
        DataStartField="STARTTIME" DataSubjectField="DESCRIPTION"
        HoursPanelTimeFormat="htt" SelectedView="MonthView" Skin="Office2007"
        style="top: 0px; left: 0px" ValidationGroup="RadScheduler1">
        <ResourceTypes>
            <telerik:ResourceType DataSourceID="SqlDataSource2"
                ForeignKeyField="VQEMSTATUSID" KeyField="ID" Name="Status" TextField="NAME" />

            <telerik:ResourceType DataSourceID="SqlDataSource3"
                ForeignKeyField="LOCATIONID" KeyField="ID" Name="Location" TextField="NAME" />
            <telerik:ResourceType DataSourceID="SqlDataSource4" ForeignKeyField="USERID"
                KeyField="ID" Name="Analyst First Name" TextField="FIRSTNAME" />
            <telerik:ResourceType DataSourceID="SqlDataSource4" ForeignKeyField="USERID"
                KeyField="ID" Name="Analyst Last Name" TextField="LASTNAME" />
        </ResourceTypes>
        <ResourceStyles>
            <telerik:ResourceStyleMapping ApplyCssClass="rsCategoryGreen"  
                 Type="Status" Text="Completed" />
        </ResourceStyles>

    </telerik:RadScheduler>

Is there a way to add a third condition that
if a status is NotCompleted and the date is <  today then make it red?


If u have a code sample or even just a two line snipped that does that it would be great.

Thanks Very much

Susan

5 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 06 Apr 2009, 07:39 AM
Hi Susan,

You can use the AppointmentDataBound to set the appointment's CssClass to one of the predifined styles for the apointments based on your custom condition:

 protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e)  
    {  
        if(e.Appointment.Resources.GetResourceByType("Status") != null)  
        {  
            if (DateTime.Compare(e.Appointment.Start, DateTime.Now) < 0 & e.Appointment.Resources.GetResourceByType("Status").Text == "NotCompleted")  
                e.Appointment.CssClass = "rsCategoryRed";  
 
         }  
     } 

In this case you should not use ResourceMappings inline since they will take precedence to code-behind.

With SP1 of Q1 2009 release, we provide 10 unique styles:

rsCategoryBlue
rsCategoryDarkBlue
rsCategoryDarkGreen
rsCategoryDarkRed
rsCategoryGreen
rsCategoryOrange
rsCategoryPink
rsCategoryRed
rsCategoryViolet
rsCategoryYellow



All the best,
Peter
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Susan
Top achievements
Rank 1
answered on 06 Apr 2009, 01:39 PM
Hello,

Thanks very much for the suggestion but I am using MVC framework so I can't really use the code behind feature.
Is there a way I can achieve the same thing from my client page, just like with the other two properties?

Thanks Very much
Susan
0
T. Tsonev
Telerik team
answered on 08 Apr 2009, 08:24 AM
Hi Susan,

We still haven't implemented the resource style mapping when using web service data binding. We plan to do so soon, but in the mean time you can use the client-side appointmentCreated event to assign a CSS class:

<script type="text/javascript">
    function aptCreated(sender, eventArgs)
    {
        var appt = eventArgs.get_appointment();
       
        var resources = appt.get_resources().getResourcesByType("Status");
        if (resources.get_count() == 0)
            return;
           
        var now = new Date();
        var status = resources.getResource(0);
        if (appt.get_start().getTime() < now.getTime() && status.get_text() == "NotCompleted")
            appt.get_element().className += " rsCategoryRed";
    }
</script>
<telerik:RadScheduler runat="server" ... OnClientAppointmentCreated="aptCreated">
</telerik:RadScheduler>



Best wishes,
Tsvetomir Tsonev
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Susan
Top achievements
Rank 1
answered on 09 Apr 2009, 02:52 PM
Thanks for the reply.

I am almost there. The javascript works great - I just need a new event to bind it to.

I am not adding the events from the UI - my calendar is databound to a table and each row in the table is an item in the calendar - no reoccurance.

So the OnClientAppointmentCreated is not really used.

I know the javascript works because I bound it to the OnClientAppointmentClick and when I click I get the desired effect.
But my question is what event on the calendar gets fired each time I reload the page so I can link the javascript to that event.
I tried a few events but I could not get them to fire up.

Another thing I tried also is to just call the javascript form anywhere on my form after I draw all the elements. For the first parameter I pass the RadScheduler but I am not sure what to pass for the second parameter - EventArgs. So either solution can work for me actually.

Thanks

Susan
0
T. Tsonev
Telerik team
answered on 10 Apr 2009, 11:36 AM
Hi Susan,

The  appointmentCreated event is fired when the visual element of that represents the appointment has been created.  At this point we can be sure that get_element() will return the DOM element of the appointment. So, this is the event that we need in this case.

The event that is fired when an appointment is inserted to the database is appointmentWebServiceInserting.

Best wishes,
Tsvetomir Tsonev
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Susan
Top achievements
Rank 1
Answers by
Peter
Telerik team
Susan
Top achievements
Rank 1
T. Tsonev
Telerik team
Share this question
or