<%@ page import="com.lightinit.hsdataplatform.dictionary.DicResourceState" %>
<%@ 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>API名称</th>
            <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>${item.catelogType}</td>
                        <td>
                            <a href="#" onclick="resourceAPIView(${item.id})">${item.resourceName}</a>
                        </td>
                        <td>${item.resourceIdentity}</td>
                        <td>${item.resourceSummary}</td>
                        <td>${item.providerName}</td>
                        <td>${item.resourceState}</td>
                        <td><fmt:formatDate value="${item.registerDate}" pattern="yyyy-MM-dd"/></td>
                        <td class="btn-table hidden-print">
                            <input type="hidden" name="id" value="${item.id}" />
                            <c:if test="${item.resourceState eq dicResourceState_DRAFT||item.resourceState eq dicResourceState_AUDITED
                            ||item.resourceState eq dicResourceState_UNPASS}">
                                <button id="editAPI" name="editAPI" class="btn btn-sm btn-primary m-r-sm" onclick="editButton(${item.id})"><i class="fa fa-edit"></i>编辑</button>
                            </c:if>
                            <c:if test="${item.resourceState eq dicResourceState_DRAFT}">
                                <button name="btnDelete" class="btn btn-sm btn-danger"><i class="fa fa-trash-o"></i>删除</button>
                            </c:if>
                            <c:if test="${item.resourceState eq dicResourceState_PENDING}">
                                <button id="auditAPI" name="auditAPI" class="btn btn-sm m-r-sm  btn-warning" onclick="auditButton(${item.id})"><i class="fa fa-edit"></i>审核</button>
                                <c:if test="${not empty item.outId1}">
                                    <button class="btn btn-sm m-r-sm  btn-warning" onclick="auditService(${item.id})"><i class="fa fa-edit"></i>发布微服务</button>
                                </c:if>
                                <c:if test="${empty item.outId1}">
                                    <button id="btnAdd" type="button" onclick="addOutService(${item.id})" class="btn btn-sm m-r-sm  btn-warning"><i class="fa fa-plus"></i>添加三方服务</button>
                                </c:if>
                            </c:if>
                        </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='btnDelete']", function() {
            var id = $(this).parent().children("input[type='hidden'][name='id']").val();
            $.delWithConfirm({ func: $.ajaxGetRefresh, funcArgs: { ajaxGetOptions: { url: "<%=basePath%>/admin/data_register_api/delete.action/" + id } } });
        });

    function editButton(id) {
        window.location.href = "<%=basePath%>/admin/data_register_api/edit.htm/"+id ;
    }

    function auditButton(id) {
        window.location.href = "<%=basePath%>/admin/data_register_api/audit.htm/"+id ;
    }
    function auditService(id) {
        window.location.href = "<%=basePath%>/admin/data_register_api/auditService.htm/"+id ;
    }

    function resourceAPIView(id) {
        window.location.href = "<%=basePath%>/admin/data_register_api/view.htm/"+id ;
    }

   function addOutService(id) {
       window.location.href = "<%=basePath%>/admin/data_register_api/addRouteService.htm/"+id ;
   } ;
</script>