<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改学校设施')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-facilities-edit" th:object="${tbSchoolFacilities}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">学校名称：</label>
                <div class="col-sm-8">
                    <input name="schoolId" th:field="*{schoolCnName}" class="form-control" type="text" disabled="true">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">设施类型：</label>
                <div class="col-sm-8">
                    <input name="facilitiesType" th:field="*{facilitiesType}" class="form-control" type="text" disabled="true">
                </div>
            </div>
            <input id="facilities" th:field="*{facilities}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">设施：</label>
                <div class="col-sm-8">
                    <label class="check-box" id="ff" name="ff">

                    </label>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/facilities";
        $("#form-facilities-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var values = document.getElementsByName("facilities1");
                var str = [];
                for(i=0;i<values.length;i++){
                    if(values[i].checked){
                        str.push(values[i].value);
                    }
                }
                if(str.length==0){
                    alert("设施不能为空");
                    return ;
                }
                $("#facilities").val(str);
                $.operate.save(prefix + "/edit", $('#form-facilities-edit').serialize()
                // +"&facilities="+str;
                );
            }
        }

        $(document).ready(function() {
            var type1=$("#facilitiesType").val();
            var fff=$("#facilities").val();
            $.ajax({
                url: ctx+"system/icon/getFacilitiesList?type="+type1,
                type: "get",
                dataType: "json",
                success: function(data){
                    for(var i=0; i<data.length; i++){
                        if(fff.indexOf(data[i].id) != -1){
                            $("#ff").append("<input id=\"facilities1\" checked=\"true\" name=\"facilities1\" type=\"checkbox\" value=\"" + data[i].id +"\">"+data[i].facilitiesName+"</input>");
                        }else{
                            $("#ff").append("<input id=\"facilities1\" name=\"facilities1\" type=\"checkbox\" value=\"" + data[i].id +"\">"+data[i].facilitiesName+"</input>");
                        }
                    }
                }
            });
        });
    </script>
</body>
</html>