<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Monthly.aspx.cs" Inherits="Calendar_Monthly" meta:resourcekey="Page" %>
<%@ Register src="../Common/TopNavbar.ascx" tagname="TopNavbar" tagprefix="tabs" %>
<%@ Import Namespace="TABS.MailCarrier.WebSDK.Calendar" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <title></title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../libs/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../libs/fontawesome/css/all.min.css" >
    <script type="text/javascript" src="../libs/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="../libs/bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
    <style>    
    #Calendar th
    {
        text-align: center;
    }    
    .noCssClass
    {
    }
    </style>
    <script type="text/javascript">
        $(document).ready(function () {
            Dialog.setMessage('<asp:Literal runat="server" Text="<%$ Resources:Dialog, Title%>" />', '<asp:Literal runat="server" Text="<%$ Resources:Dialog, OK%>" />', '<asp:Literal runat="server" Text="<%$ Resources:Dialog, Cancel%>" />');
            Dialog.setUseBrowserConfirm(<%=AppSetting.UseBrowserConfirm%>);
        });

        function OpenFolders() {
            location.href = "Calendars.aspx";
        }

        function NewAppointment() {
            var url = "Edit.aspx?new=true&cid=<%=_calendarId%>&sdate=" + $get("SelectedDate").value;
            location.href = url;
        }

        function ShowAppointments(day) {
            $get("SelectedDate").value = day;
            __doPostBack("ShowAppButton", "");
        }

        function OpenAppointment(appid, recur, recurid, begin) {
            var url = "View.aspx?cid=<%=_calendarId%>&sdate=" + $get("SelectedDate").value;
            if (recur) {
                Dialog.confirm({
                    content: '<asp:Literal runat="server" Text="<%$ Resources:Calendar, RecurAppViewQuery%>" />',
                    ok: function () {
                        url += "&recurid=" + recurid;
                        location.href = url;
                    },
                    cancel: function () {
                        url += "&appid=" + appid + "&recurid=" + recurid + "&begin=" + begin;
                        location.href = url;
                    }
                });
            } else {
                url += "&appid=" + appid;
                location.href = url;
            }
        }
    </script>

    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <CompositeScript>
                <Scripts>
                    <asp:ScriptReference Path="~/libs/tabs/common.js" />
                    <asp:ScriptReference Path="~/libs/tabs/dialog.js" />
                </Scripts>
            </CompositeScript>
        </asp:ScriptManager>

        <tabs:TopNavbar ID="TopMenu1" runat="server" />

        <div class="container-fluid topNavbarRegion">
            <div class="row" id="toolBar" data-spy="affix">
                <div class="col-xs-12" style="padding-top:2px;padding-bottom:2px;">
                    <button type="button" id="folderToolButton" class="btn btn-primary" onclick="OpenFolders()"><span class="fa-solid fa-calendar-days"></span></button>
                    <button type="button" id="newToolButton" runat="server" class="btn btn-primary" onclick="NewAppointment()"><span class="fa-solid fa-pen"></span></button>
                </div>
            </div>
        </div>

        <div class="container-fluid" style="padding-top:40px">
            <h4><asp:Label ID="CalendarName" runat="server" Text=""></asp:Label></h4>

            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Calendar CssClass="table table-bordered mc7_calendar" ID="Calendar" runat="server" Width="100%" Height="100%" ShowGridLines="true" ShowNextPrevMonth="true"
                        OnDayRender="Calendar_DayRender" 
                        NextMonthText='<i class="fa-solid fa-caret-right"></i>' 
                        PrevMonthText='<i class="fa-solid fa-caret-left"></i>' 
                        OnVisibleMonthChanged="Calendar_VisibleMonthChanged">
                        <TitleStyle CssClass="title" BackColor="Transparent" HorizontalAlign="Center"/>
                        <NextPrevStyle CssClass="nextprev" />
                        <DayHeaderStyle CssClass="dayheader" Height="15" HorizontalAlign="Center"></DayHeaderStyle>
                        <DayStyle Height="30" VerticalAlign="Top" HorizontalAlign="Center"></DayStyle>
                    </asp:Calendar>
                    <asp:Repeater ID="AppListView" runat="server">
                        <HeaderTemplate>
                            <table class="table table-striped">
                        </HeaderTemplate>
                        <ItemTemplate>
                            <tr onclick='<%# GetClickEventFunction((Appointment)Container.DataItem)%>'>
                                <td>
                                    <%# GetAppTimeStr((int)Eval("Type"), (DateTime)Eval("BeginTime"), (DateTime)Eval("EndTime"), (bool)Eval("IsRecurrent"))%></div>
                                </td>
                                <td>
                                    <%# GetSubject((string)Eval("Subject"), (string)Eval("Place"))%>
                                </td>
                            </tr>
                        </ItemTemplate>
                        <FooterTemplate>
                            </table>
                        </FooterTemplate>
                    </asp:Repeater>
                    <asp:HiddenField ID="SelectedDate" runat="server" />
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="ShowAppButton" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>
        </div>

        <div style="display:none">
            <asp:LinkButton ID="ShowAppButton" runat="server" Text="" onclick="ShowAppButton_Click" />
        </div>
    </form>
</body>
</html>
