<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Open Park</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="<%=path%>/static/css/font.css">
    <link rel="stylesheet" href="<%=path%>/static/css/xadmin.css">
    <script type="text/javascript" src="<%=path%>/static/js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="<%=path%>/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=path%>/static/js/xadmin.js"></script>
    <script>
        var index = parent.layer.getFrameIndex(window.name); //获取当前窗体索引
        $(function () {
            var flag = "${flag }";
            if (flag == 1) {
                parent.layer.alert("修改成功", {icon: 6}, function () {
                    parent.location.reload();
                    parent.layer.close(index); //执行关闭
                });
            }
        });
    </script>
</head>

<body>
<div class="x-body">
    <form class="layui-form" id="editForm" action="<%=path %>/project/update" method="post">
        <input type="hidden" value="${project.id}" name="id">
        <div class="layui-form-item">
            <label for="projectName" class="layui-form-label">
                <span class="x-red">*</span>项目名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="projectName" name="projectName" required="" lay-verify="required"
                       autocomplete="off" value="${project.projectName}" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="projectName" class="layui-form-label">
                <span class="x-red">*</span>项目文件名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="projectFileName" name="projectFileName" required="" lay-verify="required"
                       autocomplete="off" value="${project.projectFileName}" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="projectDesc" class="layui-form-label">
                <span class="x-red"></span>项目描述
            </label>
            <div class="layui-input-inline">
                <input type="text" id="projectDesc" name="projectDesc"
                       autocomplete="off" value="${project.projectDesc}" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="dataSourse" class="layui-form-label">
                <span class="x-red">*</span>数据源
            </label>
            <div class="layui-input-inline">
                <input type="text" id="dataSourse" required="" lay-verify="required"
                       autocomplete="off" value="${project.dataSource.name}" class="layui-input" readonly>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="packName" class="layui-form-label">
                <span class="x-red">*</span>包名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="packName" name="packName" required="" lay-verify="required"
                       autocomplete="off" value="${project.packName}" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="pagePath" class="layui-form-label">
                <span class="x-red"></span>页面路径
            </label>
            <div class="layui-input-inline">
                <input type="text" id="pagePath" name="pagePath"
                       autocomplete="off" value="${project.pagePath}" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">例如：/views 或 /jsp</span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="templateType" class="layui-form-label">
                <span class="x-red">*</span>项目框架
            </label>
            <div class="layui-input-inline">
                <select id="templateType" name="templateType" class="valid" lay-filter="frame">
                    <option value=''>选择项目框架</option>
                    <option value="ssm" <c:if test="${project.templateType == 'ssm'}">selected</c:if>>SSM</option>
                    <option value="ssh" <c:if test="${project.templateType == 'ssh'}">selected</c:if>>SSH</option>
                    <option value="jsp" <c:if test="${project.templateType == 'jsp'}">selected</c:if>>JSP</option>
                    <option value="ssm-custom" <c:if test="${project.templateType == 'ssm-custom'}">selected</c:if>>SSM-Custom</option>
                    <option value="ssm-maven" <c:if test="${project.templateType == 'ssm-maven'}">selected</c:if>>SSM-Maven</option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="pageStyle" class="layui-form-label">
                <span class="x-red">*</span>页面模板
            </label>
            <div class="layui-input-inline">
                <select id="pageStyle" name="pageStyle" class="valid">
                    <option value="">选择页面模板</option>
                    <c:forEach items="${pageTemplateList}" var="page">
                        <option value="${page.id}" <c:if test="${project.pageStyle == page.id}">selected</c:if>>${page.pageName}</option>
                    </c:forEach>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="edit" lay-submit="">
                修改
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form;

        form.on('select(frame)', function (data) {
            $.ajax({
                type: "GET",
                url: "<%=path %>/project/getPage",
                data: {
                    templateType: data.value
                },
                success: function (res) {
                    if(res.state == 0){
                        $("#pageStyle").empty()
                        var options = '';
                        options += "<option value=''>选择页面模板</option>";
                        var pages = res.data;
                        for(var i in pages){
                            options += "<option value='"+pages[i].id+"'>"+pages[i].pageName+"</option>"
                        }
                        $("#pageStyle").append(options)
                        form.render("select");
                    }else{
                        alert(res.message)
                    }
                }
            });
        });
    });
</script>
</body>
</html>