<%@ page import="com.lightinit.hsdataplatformresdir.dictionary.DicResourceCatelogType" %>
<%@ 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" %>
<%
    String basePath = request.getContextPath();
%>
<jsp:include page="../../../common/admin/modal_content_pre.jsp"><jsp:param name="modal_title" value="新增"/></jsp:include>
<form id="formAddInfo" action="<%=basePath%>/admin/datacatelog_mgr/add.action" method="post" class="form-horizontal">
    <input  id="id" name="id" value="${busiModel.id}" type="hidden"/>
    <div class="form-group">
    <label for="itemName" 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="itemName" name="itemName" class="form-control" value="${busiModel.itemName}"/>
        <span class="help-block"></span>
    </div>
</div>
    <div class="form-group">
        <label for="itemType" class="col-md-3 col-sm-3 control-label"><span style="color: red;">*</span>数据项类型</label>
        <div class="col-md-7 col-sm-7">
            <select id="itemType" name="itemType" class="form-control">
                <option></option>
                <c:forEach items="${dicDataCatelogItemType}" var="item" >
                    <c:choose>
                        <c:when test="${busiModel.itemType == 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="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="itemLength" 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="itemLength" name="itemLength" class="form-control" value="${busiModel.itemLength}"/>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="shareType" class="col-md-3 col-sm-3 control-label"><span style="color: red;">*</span>共享类型：</label>
        <div class="col-md-7 col-sm-7">
            <select id="shareType" name="shareType" class="form-control">
                <option></option>
                <c:forEach items="${dicResourceShareType}" var="item" >
                    <c:choose>
                        <c:when test="${busiModel.shareType == 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="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="shareCondition" class="col-md-3 col-sm-3 control-label text-right"><span style="color: red;">*</span>共享条件：</label>
        <div class="col-md-7 col-sm-7">
            <input type="text" id="shareCondition" name="shareCondition" class="form-control" value="${busiModel.shareCondition}"/>
             <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="shareMethodCategory" class="col-md-3 col-sm-3 control-label"><span style="color: red;">*</span>共享方式分类：</label>
        <div class="col-md-7 col-sm-7">
            <select id="shareMethodCategory" name="shareMethodCategory" class="form-control">
                <c:forEach items="${dicDataSharePatternType}" var="item" >
                    <c:choose>
                        <c:when test="${busiModel.shareMethodCategory == 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>
                <option></option>
                <option value="平台共享方式"  >平台共享方式</option>
                <option value="介质交换">介质交换</option>
            </select>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="shareMethodType" class="col-md-3 col-sm-3 control-label"><span style="color: red;">*</span>共享方式类型：</label>
        <div class="col-md-7 col-sm-7">
            <select id="shareMethodType" name="shareMethodType" class="form-control">
                    <c:forEach items="${dicDataSharePatternType}" var="item" >
                        <c:choose>
                            <c:when test="${busiModel.shareMethodType == 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="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="isOpen" class="col-md-3 col-sm-3 control-label">是否向社会开放：</label>
        <div class="col-md-7 col-sm-7">
            <select id="isOpen" name="isOpen" class="form-control">
                <option value="0"  selected="selected">否</option>
                <option value="1" ${busiModel.isOpen =="1"?'selected':''}>是</option>
            </select>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="openCondition" class="col-md-3 col-sm-3 control-label">开放条件：</label>
        <div class="col-md-7 col-sm-7">
            <input type="text" id="openCondition" name="openCondition" class="form-control" value="${busiModel.openCondition}"/>
            <span class="help-block"></span>
        </div>
    </div>
<button type="button" id="btnSave" class="btn btn-primary"><i class="fa fa-check"></i>保存</button>
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-close"></i>取消</button>
</form>
<jsp:include page="../../../common/admin/modal_content_post.jsp"></jsp:include>
<jsp:include page="../../../common/admin/modal_footer_pre.jsp"></jsp:include>
<jsp:include page="../../../common/admin/modal_footer_post.jsp"></jsp:include>
<script type="text/javascript">
    $("#btnSave").click(function() {
        var isValid = $.getJqObj("#formAddInfo").valid();
        if (!isValid) {
            return;
        }
        count++;/*将计算器定义在了addDataCatelog.jsp中，造成报错原因*/
        var tables=$('#testaaa');
        var addtr=$("<tr>"+
            "<td>"+$('#itemName').val()+"</td>"+
            "<td>"+$('#itemType option:selected').text()+"</td>"+
            "<td>"+$('#itemLength').val()+"</td>"+
            "<td>"+$('#shareType option:selected').text()+"</td>"+
            "<td>"+$('#shareCondition').val()+"</td>"+
            "<td>"+$('#shareMethodCategory option:selected').text()+"</td>"+
            "<td>"+$('#shareMethodType option:selected').text()+"</td>"+
            "<td>"+$('#isOpen option:selected').text()+"</td>"+
            "<td>"+$('#openCondition').val()+"</td>"+
            "<td>"+
            "<input name='dataCatelogItemList["+count+"].id' value='"+$('#id').val()+"' type='hidden'/>"+
            "<input name='dataCatelogItemList["+count+"].itemName' value='"+$('#itemName').val()+"' type='hidden'/>"+
            "<input name='dataCatelogItemList["+count+"].itemType' value='"+$('#itemType').val()+"' type='hidden'/>"+
            "<input name='dataCatelogItemList["+count+"].itemLength' value='"+$('#itemLength').val()+"'type='hidden'/>"+
            "<input name='dataCatelogItemList["+count+"].shareType' value='"+$('#shareType').val()+"'type='hidden'/>"+
            "<input name='dataCatelogItemList["+count+"].shareCondition' value='"+$('#shareCondition').val()+"'type='hidden'/>"+
            "<input name='dataCatelogItemList["+count+"].shareMethodCategory' value='"+$('#shareMethodCategory').val()+"'type='hidden'/>"+
            "<input name='dataCatelogItemList["+count+"].shareMethodType' value='"+$('#shareMethodType').val()+"'type='hidden'/>"+
            "<input name='dataCatelogItemList["+count+"].isOpen' value='"+$('#isOpen').val()+"'type='hidden'/>"+
            "<input name='dataCatelogItemList["+count+"].openCondition' value='"+$('#openCondition').val()+"'type='hidden'/>"+
            "<a onclick='detailTrRow(this);'>编辑</a>|<a onclick='deleteTrRow(this);'>删除</a>" +
            "<td>"+
            "</tr>");
        addtr.appendTo(tables);
        var modal = $.getJqObj(wysharpDefaultModalContainerSelector);
        modal.modal('hide');
        if(isDelet !=null){/*当不是null是，说明是修改的，需要将原来的删除*/
            isDelet.remove();
        }
    });

    $('#shareMethodCategory').change(function(){
       //console.info( $("#shareMethodCategory option:selected").val());
        $('#shareMethodType option').remove();
       if($("#shareMethodCategory option:selected").val()=="平台共享方式"){
           $("#shareMethodType").append('<option value="接口">接口</option><option value="数据库">数据库</option><option value="文件">文件</option>')
       }else if($("#shareMethodCategory option:selected").val()=="介质交换"){
           $("#shareMethodType").append('<option>无</option>')
       }else{
           $("#shareMethodType").append('<option></option>')
       }
    });

    /*表单验证*/
    $("#formAddInfo").validate({
        rules: {
            itemName:"required",
            itemType: "required",
            itemLength: "required",
            shareType: "required",
            shareCondition: "required",
            shareMethodCategory: "required",
            shareMethodType: "required",
            isOpen: "required",
        }
    });
</script>