<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String basePath = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>
    <jsp:include page="../../../common/admin/head.jsp"></jsp:include>
</head>
<body>
    <jsp:include page="../../../common/admin/body_pre.jsp"></jsp:include>
    <div class="row hidden-print">
        <div class="col-lg-12">
            <div class="ibox">
                <div class="ibox-title">
                    <h2>数据目录</h2>
                    <ol class="breadcrumb">
                        <li>
                            <a href="javascript:void(0);" >资源活化</a>
                        </li>
                        <li>
                            <a href="javascript:void(0);" >数据目录</a>
                        </li>
                        <li class="active">
                            <strong>目录管理</strong>
                        </li>
                    </ol>
                </div>
            </div>
        </div>
    </div>
    <jsp:include page="../../../common/admin/search_pre.jsp"></jsp:include>
    <input type="hidden" name="formSerialize" />
    <input type="hidden" name="pageNo" value="1" />
    <form id="formSearch" action="<%=basePath%>/admin/datacatelog_mgr/list.action" method="get" class="form-inline">
<%--        <div class="form-group">--%>
<%--            <label for="catelogName">信息资源分类</label>--%>
<%--            <input type="text" id="catelogName" name="catelogName" class="form-control" />--%>
<%--        </div>--%>
        <div class="form-group">
            <label for="sectorName">提供方</label>
            <input type="text" id="sectorName" name="sectorName" class="form-control" />
        </div>
        <div class="form-group">
            <label for="dataName">信息资源名称</label>
            <input type="text" id="dataName" name="dataName" class="form-control" />
        </div>
        <div class="form-group">
            <label for="shareType">共享类型</label>
            <select id="shareType" name="shareType" class="form-control">
                <option></option>
                <c:forEach items="${dicResourceShareType}" var="item" >
                    <option value="${item.key}">${item.value}</option>
                </c:forEach>
            </select>
        </div>
        <%--<div class="form-group">
            <label for="resourceState1">开放类型</label>
            <select id="resourceState1" name="resourceState1" class="form-control">
                <option></option>
                <c:forEach items="${dicResourceOpenType}" var="item" >
                    <option value="${item.key}">${item.value}</option>
                </c:forEach>
            </select>
        </div>--%>
        <div class="form-group">
            <button id="btnSearch" type="button" class="btn btn-sm btn-primary"><i class="fa fa-search"></i>查询</button>
            <button id="btnRest" type="button" class="btn btn-sm btn-default"><i class="fa fa-reply"></i>重置</button>
        </div>
    </form>
    <jsp:include page="../../../common/admin/search_post.jsp"></jsp:include>
    <jsp:include page="../../../common/admin/grid_pre.jsp"></jsp:include>
    <input id="articleImageFile" name="excelFile" type="file" class="btn btn-sm btn-primary btn-position"/>
    <button id="saveZipButton" type="button" class="btn btn-sm btn-primary btn-position">导入</button>
    <a href="<%=basePath%>/admin/datacatelog_mgr/addDataCatelog.htm" class="btn btn-sm btn-primary btn-position">新增</a>
    <button id="btnAdd" onclick="javascript:window.location.href='<%=basePath%>/admin/datacatelog_mgr/imageIndex.htm'" type="button" class="btn btn-sm btn-primary btn-position"><i>进入图谱</i></button>
    <jsp:include page="../../../common/admin/grid_middle.jsp"></jsp:include>
    <div id="divGrid">
    </div>
    <jsp:include page="../../../common/admin/grid_post.jsp"></jsp:include>
    <jsp:include page="../../../common/admin/body_post.jsp"></jsp:include>
    <script type="text/javascript">
        function search() {
            var formSerialize = $("input[type='hidden'][name='formSerialize']").val();
            var pageNo = $("input[type='hidden'][name='pageNo']").val();
            var formData = formSerialize + "&pageNo=" + pageNo;
            $("#divGrid").renderPartial({ url: "<%=basePath%>/admin/datacatelog_mgr/list.action", data: formData });
        }

        $('#btnRest').click(function(){
            $('#formSearch').resetForm();
        })

        $("#btnSearch").click(function () {
            $("input[type='hidden'][name='pageNo']").val(1);
            $("input[type='hidden'][name='formSerialize']").val($("#formSearch").serialize());
            search();
        });

        search();


        $("#saveZipButton").on('click', function(){
            var name = $("#articleImageFile").val();
            if(!name || !(/xls(x)?/gi).test(name)){
                alert('请选择导入的excel文件！')
                return;
            }
            document.getElementById("articleImageFile").disabled=true;
            document.getElementById("saveZipButton").disabled=true;
            var formData = new FormData();
            formData.append("file",$("#articleImageFile")[0].files[0]);
            formData.append("name",name);//这个地方可以传递多个参数
            $.ajax({
                url : "<%=basePath%>/admin/datacatelog_mgr/uploadExcel",
                type : 'POST',
                async : true,
                data : formData,
                // 告诉jQuery不要去处理发送的数据
                processData : false,
                // 告诉jQuery不要去设置Content-Type请求头
                contentType : false,
                beforeSend:function(){
                    alert("正在导入，请勿重复导入");
                },
                success : function(data) {
                    document.getElementById("articleImageFile").disabled=false;
                    document.getElementById("saveZipButton").disabled=false;
                    if(data.stateCode==200){
                        alert(data.msg)
                    }else{
                        alert("导入失败");
                    }
                }
            });
        })
    </script>
</body>
</html>