<%@ control language="VB" autoeventwireup="false" inherits="PCC_Exchange_CC_MailboxSize, MachSol.MachPanel.Web" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="EM" %>
<%@ Register Assembly="MachSol.MachPanel.Utility" Namespace="MachSol.MachPanel.Utility"
    TagPrefix="EM" %>
<%@ Register Src="~/Template/GVPager.ascx" TagName="Pager" TagPrefix="EM" %>

<script type="text/javascript">
    function GetMailboxUsageHistory(event, mailboxId) {
        var params = "{'MailboxId': '" + mailboxId + "'}";
        $.ajax({
            type: "POST",
            url: "ExHome.aspx/GetAsyncMailboxUsageData",
            async: true,
            data: params,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                if (msg.d.indexOf('Error') < 0) {
                    var receivedArray = msg.d.split("↝");
                    var legendXLabelText = receivedArray[0];
                    var headerLabelText = receivedArray[1];
                    var graphData = receivedArray[3];

                    $find('<%= MPE_MailboxUsageHistory.ClientID %>').show();
                    SetLabelText(legendXLabelText + "↝" + headerLabelText);
                    LoadMailboxUsageGraph(graphData);
                }
                else {
                    alert(msg.d);
                }
            },
            error: function (errorMessage) {
                alert(errorMessage);
            }
        });
    }
    function SetLabelText(response) {
        var receivedArray = response.split("↝");
        var legendXLabelText = receivedArray[0];
        var headerLabelText = receivedArray[1];
        $("#Lbl_GraphXaxis").text(legendXLabelText);
        $("#Lbl_UsagePopupHeader").text(headerLabelText);

    }

    function LoadMailboxUsageGraph(dataParam) {
        $("#graph").empty();
        var body_color = getCookie('body_color');
        var lblColor = 'black'
        if (body_color == 'night-mode') {
            lblColor = 'white';
        }
        var line = Morris.Area({
            element: 'graph',
            data: $.parseJSON(dataParam),
            xkey: 'x',
            ykeys: ['y'],
            labels: ['<%=Resources.Content.L0019%>'],
            fillOpacity: 0.6,
            hideHover: 'auto',
            behaveLikeLine: true,
            resize: true,
            pointFillColors: ['#ffffff'],
            pointStrokeColors: ['black'],
            lineColors: ['gray', 'red'],
            parseTime: false,
            backgroundColor: '#FFFFFF',
            labelColor: lblColor,

            hoverCallback: function (index, options, content, row) {
                //console.log("index" + index + "- options" + options + " - content: " + content + " row: " + row)
                return "<div class='morris-hover-row-label'>" + row.w + "</div><div class='morris-hover-point' style='color: b'>" +
                "<%=Resources.Content.L0019%>: " + row.y + "</div>";
            }
            //xLabelFormat: function (x) {
            //    console.log(x);
            //    return x.src.z;
            //}
        });
        var parentDivWidth = $("#graph").parent("div").width();
        $("#graph").css("min-width", parentDivWidth);
        $("#graph > svg:nth-child(1)").css("min-width", parentDivWidth);
        line.redraw();
    }
</script>
<asp:Panel ID="Pnl_Listing_Mailboxes" runat="server" DefaultButton="Btn_ApplyFilter_Mailboxes">


    <asp:Panel ID="Pnl_Btn_ApplyFilter" runat="server" CssClass="row" DefaultButton="Btn_ApplyFilter_Mailboxes">
        <div class="panel-group search-panel" id="AS_Mailboxes" role="tablist" aria-multiselectable="true">
            <div class="col-xs-12" role="tab" id="SH_Mailboxes">
                <div class="card">
                    <div class="header" role="button" data-toggle="collapse" data-parent="#AS_Mailboxes" href="#<%= CSB_Mailboxes.ClientID%>" aria-expanded="true" aria-controls="SH_Mailboxes">
                        <h3>
                            <%= Resources.Content.GN0000395%>
                        </h3>
                    </div>
                    <div id="CSB_Mailboxes" runat="server" class="body panel-collapse collapse" role="tabpanel" aria-labelledby="SH_Mailboxes" aria-expanded="false">
                        <div class="row">

                            <div class="col-md-3 col-sm-6 col-xs-12">
                                <div class="form-group form-float">
                                    <div class="form-line">
                                        <asp:TextBox ID="TxBx_SrchOrganization" runat="server"></asp:TextBox>
                                        <asp:Label ID="Label1" runat="server" class="form-label" EnableViewState="false"
                                            Text="<%$ Resources:Content,DGN1110357%>"></asp:Label>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3 col-sm-6 col-xs-12">
                                <div class="form-group form-float">
                                    <div class="form-line">
                                        <asp:TextBox ID="TxBx_SrchMailbox" runat="server" />
                                        <asp:Label ID="Label3" runat="server" class="form-label" EnableViewState="false"
                                            Text="<%$ Resources:Content,strMailbox%>"></asp:Label>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3 col-sm-6 col-xs-12">
                                <div class="form-group form-float">
                                    <asp:DropDownList ID="DDL_Databases" runat="server">
                                    </asp:DropDownList>
                                </div>
                            </div>

                            <div class="col-md-3 col-sm-6 col-xs-12">
                                <div class="form-group form-float">
                                    <asp:DropDownList ID="DDL_Alert" runat="server">
                                        <asp:ListItem Text="<%$ Resources:Content,SMI53106 %>" Value="-1"></asp:ListItem>
                                        <asp:ListItem Text="<%$ Resources:Content,strMonthlylimitusedless70 %>" Value="1"></asp:ListItem>
                                        <asp:ListItem Text="<%$ Resources:Content,strMonthlylimitused70 %>" Value="2"></asp:ListItem>
                                        <asp:ListItem Text="<%$ Resources:Content,strMonthlylimitused80 %>" Value="3"></asp:ListItem>
                                        <asp:ListItem Text="<%$ Resources:Content,strMonthlylimitused90 %>" Value="4"></asp:ListItem>
                                    </asp:DropDownList>
                                </div>
                            </div>
                            <div class="col-md-3 col-sm-6 col-xs-12">
                                <div class="form-group form-float">
                                    <asp:ValidationSummary ID="VS_SearchMailboxes" runat="server" ShowMessageBox="true"
                                        ShowSummary="false" ValidationGroup="SearchMailboxes" />
                                    <asp:Button ID="Btn_ApplyFilter_Mailboxes" ValidationGroup="SearchMailboxes" class="btn btn-primary waves-effect" runat="server" Text="<%$ Resources:Content,GN0000391%>" />
                                    <asp:Button ID="Btn_ClearFilter_Mailboxes" Visible="false" class="btn btn-primary waves-effect" runat="server" Text="<%$ Resources:Content,String289 %>" />

                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </asp:Panel>

    <div class="row notofication-icons">
        <div class="col-xs-12">
            <div style="width: 241px;" class="pull-left">
                <div id="Div_Red" runat="server" class="glyphicon glyphicon-remove-sign pull-left color-remove p-t-2"></div>
                <div class="pull-left p-t-5">
                    &nbsp;
                <asp:Literal ID="lbl_red" runat="server" Text="<%$ Resources:Content, AlertText1 %>" />&nbsp;&nbsp;
                </div>
            </div>
            <div style="width: 241px;" class="pull-left">
                <div id="Div1" runat="server" class="glyphicon glyphicon-exclamation-sign pull-left color-exclamation p-t-2"></div>
                <div class="pull-left p-t-5">
                    &nbsp;
                <asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:Content, AlertText2 %>" />&nbsp;&nbsp;
                </div>
            </div>
            <div style="width: 241px;" class="pull-left">
                <div id="Div2" runat="server" class="glyphicon glyphicon-info-sign pull-left color-info p-t-2"></div>
                <div class="pull-left p-t-5">
                    &nbsp;
                <asp:Literal ID="Literal2" runat="server" Text="<%$ Resources:Content, AlertText3 %>" />&nbsp;&nbsp;
                </div>
            </div>
            <div style="width: 235px;" class="pull-left">

                <div id="Div3" runat="server" class="glyphicon glyphicon-ok-sign pull-left color-success p-t-2"></div>
                <div class="pull-left p-t-5">
                    &nbsp;
                <asp:Literal ID="Literal3" runat="server" Text="<%$ Resources:Content, AlertText4 %>" />
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <%--<div class="double-scroll-wrapper1">
                <div>
                </div>
            </div>
            <div class="double-scroll-wrapper2">--%>
                <asp:GridView ID="GV_MailboxesListing" CssClass="table table-bordered table-striped table-hover" AllowSorting="true" AllowPaging="true"
                    EmptyDataText='<%$ Resources:Content, GN00001375 %>' runat="server" AutoGenerateColumns="False">
                    <Columns>
                        <asp:TemplateField SortExpression="Mailbox" HeaderStyle-CssClass="col-xs-3"
                            HeaderText='<%$ Resources:Content, strMailbox %>'>
                            <ItemTemplate>
                                <asp:HyperLink ID="LB_MailboxDisplayName" runat="server" Target="_blank" />
                            </ItemTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField SortExpression="OrganizationName" HeaderText="<%$ Resources:Content,DGN1110357%>"
                            HeaderStyle-CssClass="col-xs-2">
                            <ItemTemplate>
                                <asp:HyperLink ID="LB_OrganizationName" runat="server" Target="_blank" />
                            </ItemTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField SortExpression="CurrentSize" HeaderText='<%$ Resources:Content, CurrentSizeInMB %>'
                            HeaderStyle-CssClass="col-xs-2">
                            <ItemTemplate>
                                <div>
                                    <asp:Label ID="LB_CurrentSize" runat="server" />
                                </div>
                                <div>
                                    <asp:Label ID="LB_Time" runat="server" />
                                </div>
                            </ItemTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField SortExpression="AllocatedSize" HeaderText='<%$ Resources:Content, AllocatedSizeInMB %>'
                            HeaderStyle-CssClass="col-xs-1">
                            <ItemTemplate>
                                <asp:Label ID="LB_AllocatedSize" runat="server" />
                            </ItemTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField SortExpression="Database" HeaderText='<%$ Resources:Content, String18 %>'
                            HeaderStyle-CssClass="col-xs-2">
                            <ItemTemplate>
                                <asp:Label ID="LB_Database" runat="server" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField SortExpression="Alert" HeaderText='<%$ Resources:Content, GN0000320 %>'
                            HeaderStyle-CssClass="col-xs-1">
                            <ItemTemplate>
                                <div id="Div_Alert" runat="server" style="height: 30px;" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText='<%$ Resources:Content, History %>' HeaderStyle-CssClass="col-xs-1">
                            <ItemTemplate>
                                <button id="Btn_ViewHistory"
                                    class="btn btn-primary"
                                    onclick="GetMailboxUsageHistory($(this),<%# DataBinder.Eval(Container.DataItem, "MailboxID")%> );return false;">
                                    <%= Resources.Content.View%></button>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <PagerTemplate>
                        <EM:Pager ID="Pager1" runat="server" />
                    </PagerTemplate>
                </asp:GridView>
            <%--</div>--%>
        </div>
    </div>
</asp:Panel>

<!-- Mailbox Usage History -->
<asp:Button ID="Button2" runat="server" CssClass="btn-dummy" />
<asp:Button ID="Button1" runat="server" CssClass="btn-dummy" />
<EM:ModalPopupExtender runat="server" ID="MPE_MailboxUsageHistory" BackgroundCssClass="modalBackground"
    DropShadow="false" CancelControlID="Btn_Close" PopupControlID="Pnl_MailboxUsageHistory" TargetControlID="Button1"
    OkControlID="Button2">
</EM:ModalPopupExtender>

<asp:Panel ID="Pnl_MailboxUsageHistory" runat="server" CssClass="width-modal-popup-auto" Style="display: none; position: fixed;">
    <div class="col-xs-12">
        <div class="card">
            <div class="header container-fluid">
                <h3 class="pull-left">
                    <label id="Lbl_UsagePopupHeader"></label>
                </h3>
                <span>
                    <button type="button" class="close" onclick="$find('<%=MPE_MailboxUsageHistory.ClientID%>').hide();">&times;</button>
                </span>
            </div>
            <div class="body">
                <div class="row">
                    <div class="col-xs-2" style="margin-top: 12%; width: 12%;">
                        <label class="verticalLabel"><%= Resources.Content.SizeinMB%></label>
                    </div>
                    <div class="col-xs-10">
                        <div id="graph"></div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <label style="margin-left: 43%;">
                            <label id="Lbl_GraphXaxis"></label>
                        </label>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <asp:Button ID="Btn_Close" CausesValidation="false" runat="server" Text='<%$ Resources:Content,GN000150 %>'
                            CssClass="btn btn-primary waves-effect" />
                    </div>
                </div>
            </div>
        </div>
    </div>
</asp:Panel>
