<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ page import="com.lightinit.hsdataplatformresdir.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" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%
    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>数据目录编辑</span><%--表单头，目的修改文字--%>
    <form id="formAdd" action="<%=basePath%>/admin/datacatelog_mgr/addDataCatalog.action" method="post" class="form-horizontal">
        <div class="row">
        <input type="hidden" name="id" value="${busiModel.id}"/>
        <div class="form-group">
            <label for="dataName" class="col-md-2 col-sm-2 control-label"><span style="color: red">*</span>信息资源名称：</label>
            <div class="col-md-7 col-sm-7">
                <input type="text" id="dataName" name="dataName" value="${busiModel.dataName}"class="form-control" />
                <span class="field-validation-valid help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="dataCode" class="col-md-2 col-sm-2 control-label"><span style="color: red">*</span>信息资源代码：</label>
            <div class="col-md-7 col-sm-7">
                <input type="text" id="dataCode" name="dataCode" value="${busiModel.dataCode}" class="form-control" />
                <span class="field-validation-valid help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="supplier" class="col-md-2 col-sm-2 control-label"><span style="color: red">*</span>信息资源提供方：</label>
            <div class="col-md-7 col-sm-7">
                <input type="hidden" id="supplier" name="supplier"  value="${sector.id}" />${sector.sectorName}
               <%-- <button type="button" class="form-control" style="min-width: 120px; text-align: left;">
                    <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"><span style="color: red">*</span>提供方内部部门：</label>
            <div class="col-md-7 col-sm-7">
                <input type="hidden" id="supplierDept" name="supplierDept"  value="${sector.id}" />${sector.sectorName}
                <%--<button type="button" class="form-control" style="min-width: 120px; text-align: left;">
                    <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"><span style="color: red">*</span>资源提供方代码：</label>
            <div class="col-md-7 col-sm-7">
                <input type="text" id="supplierCode" name="supplierCode" class="form-control" value="${busiModel.supplierCode}"/>
            </div>
            <span class="field-validation-valid help-block"></span>
        </div>
        <div class="form-group">
            <label for="dataSummary" class="col-md-2 col-sm-2 control-label">信息资源摘要：</label>
            <div class="col-md-7 col-sm-7">
                <input type="text" id="dataSummary" name="dataSummary" class="form-control" value="${busiModel.dataSummary}"/>
            </div>
            <span class="field-validation-valid help-block"></span>
        </div>
        <div class="form-group">
            <label for="dataSourceType" class="col-md-2 col-sm-2 control-label"><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" >
                        <c:choose>
                            <c:when test="${busiModel.dataSourceType == item.id}">
                                <option value="${item.id}"  selected="selected" >${item.groupName}</option>
                            </c:when>
                            <c:otherwise>
                                <option value="${item.id}">${item.groupName}</option>
                            </c:otherwise>
                        </c:choose>
                    </c:forEach>
                </select>
                <span class="field-validation-valid help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="dataSource" class="col-md-2 col-sm-2 control-label"><span style="color: red">*</span>信息资源格式类型:</label>
            <div class="col-md-7 col-sm-7">
                <select id="dataSource" name="dataSource" class="form-control">
                    <c:forEach items="${list}" var="item" >
                        <c:choose>
                            <c:when test="${busiModel.dataSource == item.id}">
                                <option value="${item.id}"  selected="selected" >${item.groupName}</option>
                            </c:when>
                            <c:otherwise>
                                <option value="${item.id}">${item.groupName}</option>
                            </c:otherwise>
                        </c:choose>
                    </c:forEach>
                </select>
            </div>
            <span class="field-validation-valid help-block"></span>
        </div>
        <div class="form-group">
            <label for="dataSourceOther" class="col-md-2 col-sm-2 control-label">其他类型资源格式描述:</label>
            <div class="col-md-7 col-sm-7">
                <input type="text" id="dataSourceOther" name="dataSourceOther" class="form-control" value="${busiModel.dataSourceOther}"/>
                <span class="field-validation-valid help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="updateCycle" class="col-md-2 col-sm-2 control-label">更新周期：</label>
            <div class="col-md-7 col-sm-7">
                <select id="updateCycle" name="updateCycle" class="form-control">
                    <c:forEach items="${dicUpdateCycle}" var="item" >
                        <c:choose>
                            <c:when test="${busiModel.updateCycle == item.value}">
                                <option value="${item.key}"  selected="selected" >${item.value}</option>
                            </c:when>
                            <c:otherwise>
                                <option value="${item.key}">${item.value}</option>
                            </c:otherwise>
                        </c:choose>
                    </c:forEach>
                </select>
                <span class="field-validation-valid help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="publishTime" class="col-md-2 col-sm-2 control-label">发布时间：</label>
            <div class="col-md-7 col-sm-7">
                <div class="input-group date">
                    <input type="text" id="publishTime" name="publishTime" class="form-control" value='<fmt:formatDate value="${busiModel.publishTime}" type="Date" 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="relation" class="col-md-2 col-sm-2 control-label">关联及类目名称：</label>
            <div class="col-md-7 col-sm-7">
                <input type="text" id="relation" name="relation" class="form-control" value="${busiModel.relation}"/>
                <span class="field-validation-valid help-block"></span>
            </div>
        </div>
         <div class="form-group">
             <label  class="col-md-2 col-sm-2 control-label">目录分类：</label>
             <div class="col-md-7 col-sm-7">
                 <input type="checkbox" name="catelogType" value="<%=DicResourceCatelogType.BASIC%>" <c:if test="${fn:contains(busiModel.catelogType,'基础分类')}">checked="checked"</c:if>/><%=DicResourceCatelogType.BASIC%>
                 <input type="checkbox" name="catelogType" value="<%=DicResourceCatelogType.SECTOR%>" style="margin-left: 80px;" <c:if test="${fn:contains(busiModel.catelogType,'部门分类')}">checked="checked"</c:if> /><%=DicResourceCatelogType.SECTOR%>
                 <input type="checkbox" name="catelogType" value="<%=DicResourceCatelogType.THEME%>" style="margin-left: 80px;" <c:if test="${fn:contains(busiModel.catelogType,'主题分类')}">checked="checked"</c:if>/><%=DicResourceCatelogType.THEME%>
                 <input type="checkbox" name="catelogType" value="<%=DicResourceCatelogType.CUSTOM%>" style="margin-left: 80px;" <c:if test="${fn:contains(busiModel.catelogType,'自定义分类')}">checked="checked"</c:if> /><%=DicResourceCatelogType.CUSTOM%>
                 <span class="field-validation-valid help-block"></span>
             </div>
         </div>
        <div class="form-group">
             <label for="catelogBasic" class="col-md-2 col-sm-2 control-label">基础分类：</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-2 col-sm-2 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-2 col-sm-2 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-2 col-sm-2 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>
    <div class="row">
        <table id="testaaa" class="table table-hover  table-condensed table-bordered " align="center">
            <thead>
            <tr>
                <td>信息项名称</td>
                <td>数据项类型</td>
                <td>数据长度</td>
                <td>共享类型</td>
                <td>共享条件</td>
                <td>共享方式分类</td>
                <td>共享方式类型</td>
                <td>是否向社会开放</td>
                <td>开放条件</td>
                <td>操作</td>
            </tr>
            </thead>
            <tbody>
                <c:forEach items="${busiModel.dataCatelogItemList}" var="item" varStatus="status">
                    <tr>
                        <td>${item.itemName}</td>
                        <td>${item.itemType}</td>
                        <td>${item.itemLength}</td>
                        <td>${item.shareType}</td>
                        <td>${item.shareCondition}</td>
                        <td>${item.shareMethodCategory}</td>
                        <td>${item.shareMethodType}</td>
                        <td>${item.isOpen==1?"是":"否"}</td>
                        <td>${item.openCondition}</td>
                        <td>
                            <input type="hidden" name="dataCatelogItemList[${status.index}].id" value="${item.id}" />
                            <input type="hidden" name="dataCatelogItemList[${status.index}].itemName"  value="${item.itemName}"/>
                            <input type="hidden" name="dataCatelogItemList[${status.index}].itemType"  value="${item.itemType}"/>
                            <input type="hidden" name="dataCatelogItemList[${status.index}].itemLength"  value="${item.itemLength}"/>
                            <input type="hidden" name="dataCatelogItemList[${status.index}].shareType"  value="${item.shareType}"/>
                            <input type="hidden" name="dataCatelogItemList[${status.index}].shareCondition"  value="${item.shareCondition}"/>
                            <input type="hidden" name="dataCatelogItemList[${status.index}].shareMethodCategory"  value="${item.shareMethodCategory}"/>
                            <input type="hidden" name="dataCatelogItemList[${status.index}].shareMethodType"  value="${item.shareMethodType}"/>
                            <input type="hidden" name="dataCatelogItemList[${status.index}].isOpen"  value="${item.isOpen}"/>
                            <input type="hidden" name="dataCatelogItemList[${status.index}].openCondition"  value="${item.openCondition}"/>
                            <a onclick='detailTrRow(this);'>编辑</a>|<a onclick='deleteTrRow(this);'>删除</a>
                        </td>
                    </tr>
                </c:forEach>
            </tbody>
        </table>
        <%--<div class="row">--%>
        <button type="button"  onclick="submintFormToUpdateData()"  class="btn btn-sm btn-primary btn-position"/><i class="fa fa-check">确定</i></button>
        <button id="btnAdd11" type="button" class="btn btn-sm btn-primary btn-position"><i class="fa fa-plus"></i>新增</button>
        <button id="btnBack11" type="button" class="btn btn-sm btn-default btn-position"><i class="fa fa-reply"></i>返回</button>
        <%--</div>--%>
    </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">
    $("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>
<%-- /////////////--%>
<script type="text/javascript">
        var count=${fn:length(busiModel.dataCatelogItemList)};/*用在对dataCateLogItem每次点击加一*/
        $("#btnAdd11").click(function () {
            if( isDelet !=null){    /*在点击“添加”按钮时，需要将之前的isDelet标签设null*/
                isDelet=null;
            }
            $.popBsPartial({ url: "<%=basePath%>/admin/datacatelog_mgr/addDataCatelogItem.htm"});
        });

        $("#btnBack11").click(function () {
            window.location.href="<%=basePath%>/admin/datacatelog_mgr/index.htm"
        });

        //删除
        var delIds=new Array();
        function deleteTrRow(tr){
            delIds.push($(tr).parent().children('input:eq(0)').val());//添加删除的
            $(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);
        }

        var isDelet=null; /*定义标识，用于addDataCatelogItem.jsp中的“保存”按钮在修改后删除原来的数据*/
        function submintFormToUpdateData(){
            $("#formAdd").append("<input type='hidden' name='delIds' value='"+delIds+"'/>");
            $.post('/admin/datacatelog_mgr/updateDataCatalog.action',$("#formAdd").serialize(),function (result) {
                if(result.stateCode==200){
                    alert(result.msg);
                    window.location.href="<%=basePath%>/admin/datacatelog_mgr/index.htm"
                }else{
                    $("#formAdd").showFormValidationResult({resultState: result});//显示表单验证
                }
            });
        };

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

        //下拉选改变出发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")
        })



        $("#divAddSectorTree").selectTree({url: "<%=basePath%>/admin/common/sector_tree_data.action${busiModel.supplier == null ? "" : "?selectedId="}${busiModel.supplier}"});
        $("#divAddSectorTree2").selectTree({url: "<%=basePath%>/admin/common/sector_tree_data.action${busiModel.supplierDept == null ? "" : "?selectedId="}${busiModel.supplierDept}"});
        $("#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}"});
</script>
</body>
</html>