<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ page import="com.lightinit.hsdataplatform.dictionary.DicResourceCatelogType" %>
<%@ 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 class="active">
                            <strong>数据目录管理</strong>
                        </li>
                    </ol>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox">
                <div class="ibox-title">
                    <span><strong>添加数据目录</strong></span><%--表单头，目的修改文字--%>
    <form id="formAdd" action="<%=basePath%>/admin/datacatelog_mgr/addDataCatalog.action" method="post" class="form-horizontal">
        <div class="form-group">
            <label for="dataName" class="col-md-2 col-sm-2 control-label" style="text-align:center" ><span style="color: red">*</span>信息资源名称：</label>
            <div class="col-md-7 col-sm-7">
                <input type="text" id="dataName" name="dataName" class="form-control" />
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="dataCode" class="col-md-2 col-sm-2 control-label" style="text-align:center"><span style="color: red">*</span>信息资源代码：</label>
            <div class="col-md-7 col-sm-7">
                <input type="text" id="dataCode" name="dataCode" class="form-control" />
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="supplier" class="col-md-2 col-sm-2 control-label" style="text-align:center"><span style="color: red">*</span>信息资源提供方：</label>
            <div class="col-md-7 col-sm-7">
                <input type="hidden" id="supplier" name="supplier" />
                <button type="button" class="form-control" 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="supplierDept" class="col-md-2 col-sm-2 control-label" style="text-align:center"><span style="color: red">*</span>提供方内部部门：</label>
            <div class="col-md-7 col-sm-7">
                <input type="hidden" id="supplierDept" name="supplierDept" />
                <button type="button" class="form-control" style="min-width: 120px; text-align: right;">
                    <span class="caret" style="margin-left: 10px;"></span>
                </button>
                <div id="divAddSectorTree2"></div>
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="supplierCode" class="col-md-2 col-sm-2 control-label" style="text-align:center"><span style="color: red">*</span>资源提供方代码：</label>
            <div class="col-md-7 col-sm-7">
                <input type="text" id="supplierCode" name="supplierCode" class="form-control" />
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="dataSummary" class="col-md-2 col-sm-2 control-label" style="text-align:center"><span style="color: red">*</span>信息资源摘要：</label>
            <div class="col-md-7 col-sm-7">
                <input type="text" id="dataSummary" name="dataSummary" class="form-control" />
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="dataSourceType" class="col-md-2 col-sm-2 control-label" style="text-align:center"><span style="color: red">*</span>信息资源格式分类:</label>
            <div class="col-md-7 col-sm-7">
                <select id="dataSourceType" name="dataSourceType" class="form-control">
                    <option></option>
                    <c:forEach items="${InfomationResourceIdAndNameModels}" var="item" >
                        <option value="${item.id}">${item.groupName}</option>
                    </c:forEach>
                </select>
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="dataSource" class="col-md-2 col-sm-2 control-label" style="text-align:center"><span style="color: red">*</span>信息资源格式类型:</label>
            <div class="col-md-7 col-sm-7">
                <select id="dataSource" name="dataSource" class="form-control">
                </select>
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="dataSourceOther" class="col-md-2 col-sm-2 control-label" style="text-align:center">其他类型资源格式描述:</label>
            <div class="col-md-7 col-sm-7">
                <input type="text" id="dataSourceOther" name="dataSourceOther" class="form-control" />
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="updateCycle" class="col-md-2 col-sm-2 control-label" style="text-align:center"><span style="color: red">*</span>更新周期：</label>
            <div class="col-md-7 col-sm-7">
                <select id="updateCycle" name="updateCycle" class="form-control">
                    <option></option>
                    <c:forEach items="${dicUpdateCycle}" var="item" >
                        <option value="${item.key}">${item.value}</option>
                    </c:forEach>
                </select>
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="publishTime" class="col-md-2 col-sm-2 control-label" style="text-align:center"><span style="color: red">*</span>发布时间：</label>
            <div class="col-md-7 col-sm-7">
                <div class="input-group date">
                    <input type="text" id="publishTime" name="publishTime" class="form-control" />
                    <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="relation" class="col-md-2 col-sm-2 control-label" style="text-align:center">关联及类目名称：</label>
            <div class="col-md-7 col-sm-7">
                <input type="text" id="relation" name="relation" class="form-control" />
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label  class="col-md-2 col-sm-2 control-label" style="text-align:center"><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: 80px;" /><%=DicResourceCatelogType.SECTOR%>
                <input type="checkbox" name="catelogType" value="<%=DicResourceCatelogType.THEME%>" style="margin-left: 80px;" /><%=DicResourceCatelogType.THEME%>
                <input type="checkbox" name="catelogType" value="<%=DicResourceCatelogType.CUSTOM%>" style="margin-left: 80px;" /><%=DicResourceCatelogType.CUSTOM%>
                <span class="help-block"></span>
            </div>
        </div>
        <%-- /////////////--%>
        <script type="text/javascript">
            $("input[name='catelogType']").change(function(){
                var ches=$('input[type="checkbox"]');
                ches.each(function(index,element){
                    if(index==0){
                        $(element).is(':checked')?$('#catelogBasic').next().attr("disabled",false):($('#catelogBasic').next().html('<span class="caret" style="margin-left: 10px;"></span>'),$('#catelogBasic').next().attr("disabled",true),$('#catelogBasic').val(''));
                    }else if(index==1){
                        $(element).is(':checked')?$('#catelogSector').next().attr("disabled",false):($('#catelogSector').next().html('<span class="caret" style="margin-left: 10px;"></span>'),$('#catelogSector').next().attr("disabled",true),$('#catelogSector').val(''));
                    }else if(index==2){
                        $(element).is(':checked')?$('#catelogTheme').next().attr("disabled",false):($('#catelogTheme').next().html('<span class="caret" style="margin-left: 10px;"></span>'),$('#catelogTheme').next().attr("disabled",true),$('#catelogTheme').val(''));
                    } else if(index==3){
                        $(element).is(':checked')?$('#catelogCustom').next().attr("disabled",false):($('#catelogCustom').next().html('<span class="caret" style="margin-left: 10px;"></span>'),$('#catelogCustom').next().attr("disabled",true),$('#catelogCustom').val(''));
                    }
                })
            });
        </script>
        <%-- /////////////--%>
        <div class="form-group">
            <label for="catelogBasic" class="col-md-2 col-sm-2 control-label" style="text-align:center">基础分类：</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" disabled="disabled"  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-2 col-sm-2 control-label" style="text-align:center">部门分类：</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" disabled="disabled" 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-2 col-sm-2 control-label" style="text-align:center">主题分类：</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" disabled="disabled" 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-2 col-sm-2 control-label" style="text-align:center">自定义分类：</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" disabled="disabled" 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="row">
        <table id="testaaa" class="table table-hover  table-condensed table-bordered " align="center">
            <thead>
            <tr>
                <td>信息项名称<span class="help-block"></span></td>
                <td>数据项类型</td>
                <td>数据长度</td>
                <td>共享类型</td>
                <td>共享条件</td>
                <td>共享方式分类</td>
                <td>共享方式类型</td>
                <td>是否向社会开放</td>
                <td>开放条件</td>
                <td>操作</td>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
        <button type="button"  onclick="submintFormToAddData()"  class="btn btn-sm btn-primary btn-position"/><i class="fa fa-check">确定</i></button>
        <button id="btnAdd" type="button" class="btn btn-sm btn-primary btn-position"><i class="fa fa-plus"></i>新增</button>
        <button id="btnBack" type="button" class="btn btn-sm btn-default btn-position"><i class="fa fa-reply"></i>返回</button>
        </div>
    </form>
    <jsp:include page="../../../common/admin/grid_post.jsp"></jsp:include>
    <jsp:include page="../../../common/admin/body_post.jsp"></jsp:include>
    <script type="text/javascript">
        var count=0;/*用在对dataCateLogItem每次点击加一*/
        $("#btnAdd").click(function () {
            $.popBsPartial({ url: "<%=basePath%>/admin/datacatelog_mgr/addDataCatelogItem.htm"});
        });
        $("#btnBack").click(function () {
            window.location.href="<%=basePath%>/admin/datacatelog_mgr/index.htm"
        });

        //下拉选改变出发ajax请求
        $('#dataSourceType').change(function () {
            //alert($(this).val());
            var dictionaryId = $(this).val();
            $.post("<%=basePath%>/admin/datacatelog_mgr/queryInfoStyle.action",{id:dictionaryId},function (result) {
                var options="";
                $(result).each(function (index, domEle) {
                    options+="<option value='"+domEle.id+"'>"+domEle.groupName+"</option>"
                })
                $('#dataSource').html(options);
            },"json")
        })

        function submintFormToAddData(){
            $.post('<%=basePath%>/admin/datacatelog_mgr/addDataCatalog.action',$("#formAdd").serialize(),function (result) {
                console.info(result);
                if(result.stateCode==200){
                    window.location.href="<%=basePath%>/admin/datacatelog_mgr/index.htm"
                }else{
                    $("#formAdd").showFormValidationResult({resultState: result});//显示表单验证
                }
            });
        };

        function deleteTrRow(tr){
            $(tr).parent().parent().remove();
        }
        function detailTrRow(tr) {
            /*var objInput = document.getElementById("testaaa").getElementsByTagName("input");*/
            var currentHidenFields = $(tr).parent().children('input[type="hidden"]');
            var jsonT={id:currentHidenFields[0].value,itemName:currentHidenFields[1].value,itemType:currentHidenFields[2].value,
                itemLength:currentHidenFields[3].value,shareType:currentHidenFields[4].value,shareCondition:currentHidenFields[5].value,
                shareMethodCategory:currentHidenFields[6].value,shareMethodType:currentHidenFields[7].value,isOpen:currentHidenFields[8].value,
                openCondition:currentHidenFields[9].value};
            $.popBsPartial({ url: "<%=basePath%>/admin/datacatelog_mgr/dataCatelogItemEdit.htm", data:JSON.stringify(jsonT), ajaxOptions:{contentType:"application/json;charset=utf-8"}});
            isDelet=$(tr).parent().parent();    /*获取可能会被删除的document对象*/
            //console.info(isDelet);
        }


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

        $("#divAddSectorTree").selectTree({url: "<%=basePath%>/admin/common/sector_tree_data.action"});
        $("#divAddSectorTree2").selectTree({url: "<%=basePath%>/admin/common/sector_tree_data.action"});
        $("#divCatelogBasic").selectTree({url: "<%=basePath%>/admin/common/resource_catelog_tree_data.action?resourceCatelogType=<%=DicResourceCatelogType.BASIC%>"});
        $("#divCatelogSector").selectTree({url: "<%=basePath%>/admin/common/resource_catelog_tree_data.action?resourceCatelogType=<%=DicResourceCatelogType.SECTOR%>"});
        $("#divCatelogTheme").selectTree({url: "<%=basePath%>/admin/common/resource_catelog_tree_data.action?resourceCatelogType=<%=DicResourceCatelogType.THEME%>"});
        $("#divCatelogCustom").selectTree({url: "<%=basePath%>/admin/common/resource_catelog_tree_data.action?resourceCatelogType=<%=DicResourceCatelogType.CUSTOM%>"});
    </script>
</body>
</html>