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

<!DOCTYPE html>

<html>
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <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>
    <script type="text/javascript">
        $(document).ready(function () {
        });

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

        function ViewArticle(boardId, page, articleId, searchCategoty, searchKeyword) {
            location.href = "View.aspx?searchAll=true&board=" + boardId + "&page=" + page + "&article=" + articleId + "&searchCategoty=" + searchCategoty + "&searchKeyword=" + encodeURIComponent(searchKeyword);
        }

        function SearchOnEnter(event) {
            if (event.keyCode == 13) {
                __doPostBack("SearchButton", "");
                return false;
            }
            return true;
        }
    </script>

    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </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-folder-open"></span></button>
                    <button type="button" id="searchCollapseButton" class="btn btn-primary" data-toggle="collapse" data-target="#searchPanel"><span class="fa-solid fa-magnifying-glass"></span></button>
                </div>
            </div>
        </div>

        <div class="container-fluid" style="padding-top:40px">
            <div id="searchPanel" runat="server" class="collapse in">
                <div class="row">
                    <div class="col-xs-9">
                        <asp:DropDownList ID="CategoryList" runat="server" CssClass="form-control">
                            <asp:ListItem Text="제목" Value="subject" Selected="True" meta:resourcekey="CL01"></asp:ListItem>
                            <asp:ListItem Text="내용" Value="content" meta:resourcekey="CL03"></asp:ListItem>
                            <asp:ListItem Text="작성자" Value="author" meta:resourcekey="CL02"></asp:ListItem>
                        </asp:DropDownList>
                    </div>
                    <div class="col-xs-3">
                        <button type="button" id="searchButton" class="btn btn-default" onclick="__doPostBack('SearchButton', '')"><span class="fa-solid fa-magnifying-glass"></span></button>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-9">
                        <asp:TextBox ID="KeywordTextBox" runat="server" CssClass="form-control" AutoPostBack="false" onkeydown="return SearchOnEnter(event);" />
                    </div>
                    <div class="col-xs-3">
                        <button type="button" id="searchCancelButton" class="btn btn-default" onclick="__doPostBack('SearchCancelButton', '')"><span class="fa-solid fa-xmark"></span></button>
                    </div>
                </div>
            </div>

            <asp:GridView ID="ArticlesGridView" runat="server" Width="100%" CssClass="table table-hover" AutoGenerateColumns="false" 
                AllowPaging="true" PageSize="20" AllowSorting="true" GridLines="None" ShowHeaderWhenEmpty="true" ShowHeader="true" 
                DataSourceID="SearchAllArticlesDataSource" EnableViewState="true" DataKeyNames="ID"
                OnPreRender="ArticlesGridView_PreRender">
                <EmptyDataTemplate>
                    <div>
                        <asp:Localize ID="Localize1" runat="server" meta:resourcekey="L01">게시글이 없습니다.</asp:Localize>
                    </div>
                </EmptyDataTemplate> 
                <Columns>
                    <asp:TemplateField>
                        <HeaderStyle Font-Size="Larger" />
                        <ItemTemplate>
                            <div class="row" onclick="<%# GetClickEventFunction((Guid)Eval("BoardID"), (int)Eval("ID"))%>">
                                <div class="col-xs-2">
                                    <small><%# Eval("BoardName") %></small>
                                </div>
                                <div class="col-xs-10">
                                    <div class="row">
                                        <div class="col-xs-8">
                                            <%# GetSubject((Article)Container.DataItem)%>
                                        </div>
                                        <div class="col-xs-4 text-right">
                                            <small><%# GetDate((DateTime)Eval("Date"))%></small>
                                        </div> 
                                    </div>
                                    <div class="row">
                                        <div class="col-xs-8">
                                            <span class="text-muted"><small><%#: Eval("AuthorName")%></small></span>
                                        </div> 
                                        <div class="col-xs-4 text-right">
                                            <small>
                                                <asp:Localize ID="Localize2" runat="server" meta:resourcekey="L02">조회</asp:Localize>
                                                <%# Eval("ReadCount")%>
                                            </small>
                                            <small><span class="fa-regular fa-heart" style="color:#EE4D68"></span> <%# Eval("RecommendCount")%></small>
                                        </div> 
                                    </div>
                                </div>
                            </div>                            
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns> 
                <PagerSettings PageButtonCount="5" Mode="NumericFirstLast" />
                <PagerStyle CssClass="mc-gridpager"/>
            </asp:GridView>
        </div>

        <div style="display:none">
            <asp:LinkButton ID="SearchButton" runat="server" OnClick="SearchButton_Click" Text="" />
            <asp:LinkButton ID="SearchCancelButton" runat="server" OnClick="SearchCancelButton_Click" Text="" />
        </div>

        <asp:ObjectDataSource ID="SearchAllArticlesDataSource" runat="server" TypeName="SearchAllArticlesDataSource"
            SelectMethod="GetArticles" SelectCountMethod="GetTotalCount" EnablePaging="true" >
            <SelectParameters>
                <asp:Parameter Name="category" Type="String" />
                <asp:Parameter Name="keyword" Type="String" ConvertEmptyStringToNull="false" />
            </SelectParameters>
        </asp:ObjectDataSource>
    </form>
</body>
</html>
