<%@ page import="com.lightinit.hsdataplatformresdir.dictionary.DicResourceCatelogType" %>
<%@ page import="com.lightinit.hsdataplatformresdir.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();
%>
<jsp:include page="../../../common/admin/modal_content_pre.jsp"><jsp:param name="modal_title" value="编辑"/></jsp:include>
<form id="formEdit" action="<%=basePath%>/admin/data_register/edit.action" method="post" enctype="multipart/form-data" class="form-horizontal">
    <input type="hidden" name="id" value="${busiModel.id}" />
    <input type="hidden" name="resourceState" />
    <div class="form-group">
        <label for="resourceName" class="col-md-3 col-sm-3 control-label"><span style="color: red;">*</span>数据名称：</label>
        <div class="col-md-7 col-sm-7">
            <input type="text" id="resourceName" name="resourceName" class="form-control" value="${busiModel.resourceName}" />
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="resourceSummary" class="col-md-3 col-sm-3 control-label"><span style="color: red;">*</span>数据摘要：</label>
        <div class="col-md-7 col-sm-7">
            <input type="text" id="resourceSummary" name="resourceSummary" class="form-control" value="${busiModel.resourceSummary}" />
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="dataItem" class="col-md-3 col-sm-3 control-label"><span style="color: red;">*</span>数据项：</label>
        <div class="col-md-7 col-sm-7">
            <input type="text" id="dataItem" name="dataItem" class="form-control" value="${busiModel.dataItem}" />
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="registerDate" class="col-md-3 col-sm-3 control-label">注册日期：</label>
        <div class="col-md-7 col-sm-7">
            <div class="input-group date">
                <input type="text" id="registerDate" name="registerDate" class="form-control" value="<fmt:formatDate value="${busiModel.registerDate}" pattern="yyyy-MM-dd"/>" />
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="belongTo" class="col-md-3 col-sm-3 control-label"><span style="color: red;">*</span>所属单位：</label>
        <div class="col-md-7 col-sm-7">
            <input type="hidden" id="belongTo" name="belongTo" />
            <button type="button" class="btn btn-default dropdown-toggle" style="min-width: 120px; text-align: right;">
                <span class="caret" style="margin-left: 10px;"></span>
            </button>
            <div id="divAddSectorTree"></div>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="resourceSummary" class="col-md-3 col-sm-3 control-label"><span style="color: red;">*</span>目录分类：</label>
        <div class="col-md-7 col-sm-7">
            <input type="checkbox" name="catelogType" value="<%=DicResourceCatelogType.BASIC%>" /><%=DicResourceCatelogType.BASIC%>
            <input type="checkbox" name="catelogType" value="<%=DicResourceCatelogType.SECTOR%>" style="margin-left: 50px;" /><%=DicResourceCatelogType.SECTOR%>
            <br />
            <input type="checkbox" name="catelogType" value="<%=DicResourceCatelogType.THEME%>" /><%=DicResourceCatelogType.THEME%>
            <input type="checkbox" name="catelogType" value="<%=DicResourceCatelogType.CUSTOM%>" style="margin-left: 50px;" /><%=DicResourceCatelogType.CUSTOM%>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="catelogBasic" class="col-md-3 col-sm-3 control-label text-right">基础分类</label>
        <div class="col-md-7 col-sm-7">
            <input type="hidden" id="catelogBasic" name="catelogBasic" />
            <button type="button" class="btn btn-default dropdown-toggle" style="min-width: 120px; text-align: right;">
                <span class="caret" style="margin-left: 10px;"></span>
            </button>
            <div id="divCatelogBasic"></div>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="catelogSector" class="col-md-3 col-sm-3 control-label">部门分类</label>
        <div class="col-md-7 col-sm-7">
            <input type="hidden" id="catelogSector" name="catelogSector" />
            <button type="button" class="btn btn-default dropdown-toggle" style="min-width: 120px; text-align: right;">
                <span class="caret" style="margin-left: 10px;"></span>
            </button>
            <div id="divCatelogSector"></div>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="catelogTheme" class="col-md-3 col-sm-3 control-label">主题分类</label>
        <div class="col-md-7 col-sm-7">
            <input type="hidden" id="catelogTheme" name="catelogTheme" />
            <button type="button" class="btn btn-default dropdown-toggle" style="min-width: 120px; text-align: right;">
                <span class="caret" style="margin-left: 10px;"></span>
            </button>
            <div id="divCatelogTheme"></div>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="catelogCustom" class="col-md-3 col-sm-3 control-label">自定义分类</label>
        <div class="col-md-7 col-sm-7">
            <input type="hidden" id="catelogCustom" name="catelogCustom" />
            <button type="button" class="btn btn-default dropdown-toggle" style="min-width: 120px; text-align: right;">
                <span class="caret" style="margin-left: 10px;"></span>
            </button>
            <div id="divCatelogCustom"></div>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="dataTag" class="col-md-3 col-sm-3 control-label"><span style="color: red;">*</span>数据标签：</label>
        <div class="col-md-7 col-sm-7">
            <input type="text" id="dataTag" name="dataTag" class="form-control" value="${busiModel.dataTag}" />
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="shareType" class="col-md-3 col-sm-3 control-label">共享类型：</label>
        <div class="col-md-7 col-sm-7">
            <select id="shareType" name="shareType" class="form-control" value="${busiModel.shareType}">
                <option></option>
                <c:forEach items="${dicResourceShareType}" var="item" >
                    <option value="${item.key}" ${item.key == busiModel.shareType ? "selected=\"selected\"" : ""}>${item.value}</option>
                </c:forEach>
            </select>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="openType" class="col-md-3 col-sm-3 control-label">开放类型：</label>
        <div class="col-md-7 col-sm-7">
            <select id="openType" name="openType" class="form-control" value="${busiModel.openType}">
                <option></option>
                <c:forEach items="${dicResourceOpenType}" var="item" >
                    <option value="${item.key}" ${item.key == busiModel.openType ? "selected=\"selected\"" : ""}>${item.value}</option>
                </c:forEach>
            </select>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="allowDeal" class="col-md-3 col-sm-3 control-label">是否可交易：</label>
        <div class="col-md-7 col-sm-7">
            <select id="allowDeal" name="allowDeal" class="form-control">
                <option value="0" ${busiModel.allowDeal == 0 ? "selected=\"selected\"" : ""}>否</option>
                <option value="1" ${busiModel.allowDeal == 1 ? "selected=\"selected\"" : ""}>是</option>
            </select>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="dataTag" class="col-md-3 col-sm-3 control-label">数据文件：</label>
        <div class="col-md-7 col-sm-7">
            <p class="form-control-static">${dataFileName == null ? "" : dataFileName}</p>
            <input type="file" name="fileData" />
            <input type="hidden" name="dataFile" value="${busiModel.dataFile}" />
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="dataTag" class="col-md-3 col-sm-3 control-label">示例文件：</label>
        <div class="col-md-7 col-sm-7">
            <p class="form-control-static">${demoFileName == null ? "" : demoFileName}</p>
            <input type="file" name="fileDemo" />
            <input type="hidden" name="demoFile" value="${busiModel.demoFile}" />
            <span class="help-block"></span>
        </div>
    </div>
</form>
<jsp:include page="../../../common/admin/modal_content_post.jsp"></jsp:include>
<jsp:include page="../../../common/admin/modal_footer_pre.jsp"></jsp:include>
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-close"></i>取消</button>
<c:set var="dicResourceStateDraft" value="<%=DicResourceState.DRAFT%>"/>
<c:if test="${dicResourceStateDraft == busiModel.resourceState}">
    <button type="button" id="btnSaveDraft" class="btn btn-warning"><i class="fa fa-exclamation"></i>暂存</button>
</c:if>
<button type="button" id="btnSave" class="btn btn-primary"><i class="fa fa-check"></i>提交</button>
<jsp:include page="../../../common/admin/modal_footer_post.jsp"></jsp:include>
<script type="text/javascript">
    $("#btnSave").click(function() {
        $("input[name=resourceState]").val("<%=DicResourceState.PENDING%>");
        $('#formEdit').ajaxSubmitCloseRefresh();
    });

    $("#btnSaveDraft").click(function() {
        $("input[name=resourceState]").val("${busiModel.resourceState}");
        $('#formEdit').ajaxSubmitCloseRefresh();
    });

    $(".input-group.date").datetimepicker({
        format: "YYYY-MM-DD",
        locale: "zh-cn"
    });

    $("#divAddSectorTree").selectTree({url: "<%=basePath%>/admin/common/sector_tree_data.action${busiModel.belongTo == null ? "" : "?selectedId="}${busiModel.belongTo}"});
    $("#divCatelogBasic").selectTree({url: "<%=basePath%>/admin/common/resource_catelog_tree_data.action?resourceCatelogType=<%=DicResourceCatelogType.BASIC%>${busiModel.catelogBasic == null ? "" : "&selectedId="}${busiModel.catelogBasic}"});
    $("#divCatelogSector").selectTree({url: "<%=basePath%>/admin/common/resource_catelog_tree_data.action?resourceCatelogType=<%=DicResourceCatelogType.SECTOR%>${busiModel.catelogSector == null ? "" : "&selectedId="}${busiModel.catelogSector}"});
    $("#divCatelogTheme").selectTree({url: "<%=basePath%>/admin/common/resource_catelog_tree_data.action?resourceCatelogType=<%=DicResourceCatelogType.THEME%>${busiModel.catelogTheme == null ? "" : "&selectedId="}${busiModel.catelogTheme}"});
    $("#divCatelogCustom").selectTree({url: "<%=basePath%>/admin/common/resource_catelog_tree_data.action?resourceCatelogType=<%=DicResourceCatelogType.CUSTOM%>${busiModel.catelogCustom == null ? "" : "&selectedId="}${busiModel.catelogCustom}"});

    $("#formEdit").validate({
        rules: {
            resourceName: "required",
            resourceSummary: "required",
            dataItem: "required",
            belongTo: "required",
            catelogType: "required",
            dataTag: "required",
        }
    });
</script>