<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="Telerik.Web.Examples.Scheduler.RadDock.DefaultCS" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
    <telerik:RadScriptBlock runat="server" ID="RadScriptBlock1">

        <script type="text/javascript">
            function openForm() {
                var dock = $find("<%= RadDock1.ClientID %>");
                // Center the RadDock on the screen
                var viewPort = $telerik.getViewPortSize();
                var xPos = Math.round((viewPort.width - parseInt(dock.get_width())) / 2);
                var yPos = Math.round((viewPort.height - parseInt(dock.get_height())) / 2);
                $telerik.setLocation(dock.get_element(), { x: xPos, y: yPos });

                dock.set_closed(false);

                var descriptionTextBox = $get('<%= DescriptionText.ClientID %>');
                descriptionTextBox.focus();

                Sys.Application.remove_load(openForm);
            }

            function hideForm() {
                var dock = $find("<%= RadDock1.ClientID %>");
                dock.set_closed(true);

                return true;
            }

            function dockMoved(sender, args) {
                //Return RadDock to his original HTML parent so it gets updated via ajax
                $get("<%= DockPanel.ClientID %>").appendChild(sender.get_element());
            }
				
        </script>

    </telerik:RadScriptBlock>
    <asp:UpdatePanel runat="server" ID="UpdatePanel1">
        <ContentTemplate>
            <asp:Panel runat="server" ID="DockPanel">
                <telerik:RadDock runat="server" ID="RadDock1" Width="500px" Height="330px" Closed="true"
                    Style="z-index: 2000;" Title="Edit appointment" OnClientDockPositionChanged="dockMoved">
                    <Commands>
                        <telerik:DockCloseCommand />
                    </Commands>
                    <ContentTemplate>
                        <div class="editForm">
                            <div class="header">
                                <asp:Label runat="server" ID="StatusLabel"></asp:Label>
                            </div>
                            <div class="content">
                                Description:<br />
                                <asp:TextBox runat="server" ID="DescriptionText" Width="240px"></asp:TextBox>
                                <asp:RequiredFieldValidator runat="server" ID="DescriptionTextRequiredFieldValidator"
                                    Display="Dynamic" ControlToValidate="DescriptionText" ErrorMessage="Description is required" />
                                <br />
                                <br />
                                Starts at:
                                <telerik:RadDateTimePicker ID="StartTime" runat="server" SharedCalendarID="SharedCalendar"
                                    SharedTimeViewID="SharedTimeView">
                                </telerik:RadDateTimePicker>
                                <asp:RequiredFieldValidator runat="server" ID="StartTimeRequiredFieldValidator" Display="Dynamic"
                                    ControlToValidate="StartTime" ErrorMessage="Start time is required" />
                                <br />
                                <br />
                                Ends at:
                                <telerik:RadDateTimePicker ID="EndTime" runat="server" SharedCalendarID="SharedCalendar"
                                    SharedTimeViewID="SharedTimeView">
                                </telerik:RadDateTimePicker>
                                <asp:RequiredFieldValidator runat="server" ID="EndTimeRequiredFieldValidator" Display="Dynamic"
                                    ControlToValidate="EndTime" ErrorMessage="End time is required" />
                                <br />
                                <br />
                                Assigned to:<br />
                                <asp:DropDownList runat="server" ID="UserDropDown" DataSourceID="UsersDataSource"
                                    DataTextField="UserName" DataValueField="ID">
                                </asp:DropDownList>
                                <br />
                                <br />
                                <asp:Label runat="server" Text="Reminder" ID="lblReminders"></asp:Label>
                                <telerik:RadComboBox runat="server" ID="ReminderDropDown" Width="120px">
                                    <Items>
                                        <telerik:RadComboBoxItem Text="None" Value="" />
                                        <telerik:RadComboBoxItem Text="0 minutes" Value="0" />
                                        <telerik:RadComboBoxItem Text="1 minute" Value="5" />
                                        <telerik:RadComboBoxItem Text="2 minutes" Value="10" />
                                        <telerik:RadComboBoxItem Text="3 minutes" Value="15" />
                                        <telerik:RadComboBoxItem Text="4 minutes" Value="30" />
                                        <telerik:RadComboBoxItem Text="1 hour" Value="60" />
                                        <telerik:RadComboBoxItem Text="2 hours" Value="120" />
                                        <telerik:RadComboBoxItem Text="3 hours" Value="180" />
                                        <telerik:RadComboBoxItem Text="4 hours" Value="240" />
                                        <telerik:RadComboBoxItem Text="5 hours" Value="300" />
                                        <telerik:RadComboBoxItem Text="6 hours" Value="360" />
                                        <telerik:RadComboBoxItem Text="7 hours" Value="420" />
                                        <telerik:RadComboBoxItem Text="8 hours" Value="480" />
                                        <telerik:RadComboBoxItem Text="9 hours" Value="540" />
                                        <telerik:RadComboBoxItem Text="10 hours" Value="600" />
                                        <telerik:RadComboBoxItem Text="11 hours" Value="660" />
                                        <telerik:RadComboBoxItem Text="12 hours" Value="720" />
                                        <telerik:RadComboBoxItem Text="18 hours" Value="1080" />
                                        <telerik:RadComboBoxItem Text="1 day" Value="1440" />
                                        <telerik:RadComboBoxItem Text="2 days" Value="2880" />
                                        <telerik:RadComboBoxItem Text="3 days" Value="4320" />
                                        <telerik:RadComboBoxItem Text="4 days" Value="5760" />
                                        <telerik:RadComboBoxItem Text="1 week" Value="10080" />
                                        <telerik:RadComboBoxItem Text="2 weeks" Value="20160" />
                                    </Items>
                                </telerik:RadComboBox>
                            </div>
                            <div class="footer">
                                <asp:Button runat="server" ID="SubmitButton" Text="Update" OnClick="SubmitButton_Click"
                                    OnClientClick="return hideForm()" />
                                <button onclick="hideForm();" type="button" style="margin-right: 20px;">
                                    Cancel</button>
                            </div>
                            <telerik:RadTimeView ID="SharedTimeView" runat="server">
                            </telerik:RadTimeView>
                            <telerik:RadCalendar ID="SharedCalendar" runat="server" EnableMonthYearFastNavigation="False"
                                EnableMultiSelect="False" UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False">
                            </telerik:RadCalendar>
                        </div>
                    </ContentTemplate>
                </telerik:RadDock>
            </asp:Panel>
            <telerik:RadScheduler runat="server" ID="RadScheduler1" Width="750px" TimeZoneOffset="03:00:00"
                StartEditingInAdvancedForm="False" DataKeyField="ID" DataSubjectField="Subject"
                DataStartField="Start" DataEndField="End" DataReminderField="Reminder" DataRecurrenceField="RecurrenceRule"
                DataRecurrenceParentKeyField="RecurrenceParentID" DataSourceID="SqlDataSource1"
                OnFormCreating="RadScheduler1_FormCreating" Reminders-Enabled="true" DataDescriptionField="Description"
                EnableDescriptionField="True">
                <Reminders Enabled="True" />
                <AdvancedForm Modal="true" />
                <ResourceTypes>
                    <telerik:ResourceType KeyField="ID" Name="Room" TextField="RoomName" ForeignKeyField="RoomID"
                        DataSourceID="RoomsDataSource" />
                    <telerik:ResourceType KeyField="ID" Name="User" TextField="UserName" ForeignKeyField="UserID"
                        DataSourceID="UsersDataSource" />
                </ResourceTypes>
                <TimeSlotContextMenuSettings EnableDefault="true" />
                <AppointmentContextMenuSettings EnableDefault="true" />
            </telerik:RadScheduler>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
                DeleteCommand="DELETE FROM [Appointments] WHERE [ID] = @ID" InsertCommand="INSERT INTO [Appointments] ([Subject], [Start], [End], [UserID], [RoomID], [RecurrenceRule], [RecurrenceParentID], [Annotations], [Description], [Reminder], [LastModified]) VALUES (@Subject, @Start, @End, @UserID, @RoomID, @RecurrenceRule, @RecurrenceParentID, @Annotations, @Description, @Reminder, @LastModified)"
                SelectCommand="SELECT * FROM [Appointments]" UpdateCommand="UPDATE [Appointments] SET [Subject] = @Subject, [Start] = @Start, [End] = @End, [UserID] = @UserID, [RoomID] = @RoomID, [RecurrenceRule] = @RecurrenceRule, [RecurrenceParentID] = @RecurrenceParentID, [Annotations] = @Annotations, [Description] = @Description, [Reminder] = @Reminder, [LastModified] = @LastModified WHERE [ID] = @ID">
                <DeleteParameters>
                    <asp:Parameter Name="ID" Type="Int32" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Subject" Type="String" />
                    <asp:Parameter Name="Start" Type="DateTime" />
                    <asp:Parameter Name="End" Type="DateTime" />
                    <asp:Parameter Name="UserID" Type="Int32" />
                    <asp:Parameter Name="RoomID" Type="Int32" />
                    <asp:Parameter Name="RecurrenceRule" Type="String" />
                    <asp:Parameter Name="RecurrenceParentID" Type="Int32" />
                    <asp:Parameter Name="Annotations" Type="String" />
                    <asp:Parameter Name="Description" Type="String" />
                    <asp:Parameter Name="Reminder" Type="String" />
                    <asp:Parameter Name="LastModified" Type="String" />
                    <asp:Parameter Name="ID" Type="Int32" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="Subject" Type="String" />
                    <asp:Parameter Name="Start" Type="DateTime" />
                    <asp:Parameter Name="End" Type="DateTime" />
                    <asp:Parameter Name="UserID" Type="Int32" />
                    <asp:Parameter Name="RoomID" Type="Int32" />
                    <asp:Parameter Name="RecurrenceRule" Type="String" />
                    <asp:Parameter Name="RecurrenceParentID" Type="Int32" />
                    <asp:Parameter Name="Annotations" Type="String" />
                    <asp:Parameter Name="Description" Type="String" />
                    <asp:Parameter Name="Reminder" Type="String" />
                    <asp:Parameter Name="LastModified" Type="String" />
                </InsertParameters>
            </asp:SqlDataSource>
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:SqlDataSource ID="RoomsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
        SelectCommand="SELECT * FROM [Rooms]"></asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server"></asp:SqlDataSource>
    <asp:SqlDataSource ID="UsersDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
        SelectCommand="SELECT * FROM [Users]"></asp:SqlDataSource>
    </form>
</body>
</html>
