<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%
    String basePath = request.getContextPath();
%>
<div class="table-responsive">
    <table class="table table-striped table-bordered table-hover " >
        <thead>
        <tr>
            <th>数据名称</th>
            <th>数据描述</th>
            <th>所属单位</th>
            <th>状态</th>
            <th>提交日期</th>
            <th class="hidden-print">操 作</th>
        </tr>
        </thead>
        <tbody>
        <c:choose>
            <c:when test="${list!=null}">
                <c:forEach items="${list}" var="item" >
                    <tr>
                        <td><input type="hidden"  name="id" value="${item.id}"/><a href="javascript:(0);" onclick="toDetail(this)">${item.resourceName}</a></td>
                        <td>${item.resourceSummary}</td>
                        <td>${item.sectorName}</td>
                        <td>${item.publishState}</td>
                        <td><fmt:formatDate value="${item.createdAt}" pattern="yyyy-MM-dd"></fmt:formatDate></td>
                        <td class="btn-table hidden-print">
                            <input type="hidden" name="id" value="${item.id}" />
                            <c:choose>
                                <c:when test="${item.publishState =='待提交'}">
                                    <button name="btnDelete" class="btn btn-sm btn-danger m-r-sm"><i class="fa fa-trash-o"></i>删除</button>
                                    <button name="btnEdit"class="btn btn-sm btn-primary m-r-sm" ><i class="fa fa-edit"></i>编辑</button>
                                </c:when>
                                <c:when test="${item.publishState =='审核中'}">
                                    ----
                                </c:when>
                                <c:when test="${item.publishState =='审核不通过'}">
                                    <button name="btnEdit"class="btn btn-sm btn-primary m-r-sm" ><i class="fa fa-edit"></i>编辑</button>
                                </c:when>
                                <c:when test="${item.publishState =='已发布'}">
                                    <button name="btnOff" class="btn btn-sm btn-warning m-r-sm"><i class="fa fa-minus"></i>下架</button>
                                    <button name="btnEdit"class="btn btn-sm btn-primary m-r-sm" ><i class="fa fa-edit"></i>编辑</button>
                                </c:when>
                                <c:otherwise>
                                    <button name="btnEdit"class="btn btn-sm btn-primary m-r-sm" ><i class="fa fa-edit"></i>编辑</button>
                                </c:otherwise>
                            </c:choose>
                        </td>
                    </tr>
                </c:forEach>
            </c:when>
            <c:otherwise>
                <tr>
                    <td colspan="4">无数据</td>
                </tr>
            </c:otherwise>
        </c:choose>
        </tbody>
    </table>
</div>
<jsp:include page="../../../common/admin/pager.jsp">
    <jsp:param name="pageNo" value="${pager.pageNo}"/>
    <jsp:param name="pageSize" value="${pager.pageSize}"/>
    <jsp:param name="total" value="${pager.total}"/>
</jsp:include>
<script type="text/javascript">

    $("#divGrid table tbody tr td:last-child")
        .on("click", "button[name='btnEdit']", function () {
            var id = $(this).parent().children("input[type='hidden'][name='id']").val();
            $.popBsPartial({ url: "<%=basePath%>/admin/datapublish_mgr/edit.htm/" + id, size: WySharpSize.Large });
        })
        .on("click", "button[name='btnDelete']", function() {
            var id = $(this).parent().children("input[type='hidden'][name='id']").val();
            $.delWithConfirm({ func: $.ajaxGetRefresh, funcArgs: { ajaxGetOptions: { url: "<%=basePath%>/admin/datapublish_mgr/delete.action/" + id } } });
        });

        $("button[name='btnOff']").click(function () {
            $.ajax({
                url: "<%=basePath%>/admin/datapublish_mgr/offPublishData.action",
                type: "POST",
                data:{id:$(this).parent().children("input[type='hidden'][name='id']").val()},
                success: function(){
                    window.location.href="<%=basePath%>/admin/datapublish_mgr/index.htm"
                }});
        });

        function toDetail(tr){
            var id=$(tr).parent().children("input[name='id']").val();
            $.popBsPartial({ url: "<%=basePath%>/admin/datapublish_mgr/detail.htm/" + id, size: WySharpSize.Large });
        }
</script>