<%@page trimDirectiveWhitespaces="true"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="gen" uri="http://help.jspgen.com/taglib/jstl"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1" />
<title>模型</title>
<!-- 当前页面 -->
<link type="text/css" href="${config.statie}ui/admin/images/admin.css" rel="stylesheet">
</head>
<body>
<div id="wrapper">
  <div class="area">
    <h2><i><gen:if test='${empty param.id}'>添加<gen:else />编辑</gen:if>模型</i></h2>
    <div class="area-content">
      <form id="form" name="form" method="post" action="<gen:if test='${empty param.id}'>model!save.gen<gen:else />model!update.gen</gen:if>">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table">
          <tr>
            <td width="30%" align="right"><span class="red">*</span>&nbsp;Id：</td>
            <td><input id="id" name="id" type="text" class="text small" value="${model.id}" size="25" />
              <label for="id" generated="true" class="tip normal" tip="仅限英文字母+数字，保持唯一性"></label></td>
          </tr>
          <tr class="border-top">
            <td width="30%" align="right"><span class="red">*</span>&nbsp;名称：</td>
            <td><input id="name" name="name" type="text" class="text small" value="${model.name}" size="25" />
              <label for="name" generated="true" class="tip normal" tip=""></label></td>
          </tr>
          <tr class="border-top">
            <td align="right" valign="top">描述：</td>
            <td><textarea id="description" name="description" class="text small textarea general ignore">${model.description}</textarea></td>
          </tr>
          <tr class="border-top">
            <td align="right"><span class="red">*</span>&nbsp;发布版本：</td>
            <td><input id="release" name="release" type="text" class="text small" value="${model.release}" size="20" />
              <label for="release" generated="true" class="tip normal" tip="建议采用发布日期式数字，如：20150505"></label></td>
          </tr>
          <tr class="border-top templateTr">
            <td align="right"><span class="red">*</span>&nbsp;默认模板：</td>
            <td><span class="field">
              <input id="template" name="template" type="text" class="text small" value="${model.template}" size="50" readonly="readonly" />
              &nbsp;<a href="javascript:void(0);" title="选择模板" genre="model" to="template" class="choose">选择</a>&nbsp;<a href="javascript:void(0);" title="编辑模板" to="template" class="edit">编辑</a>&nbsp;&nbsp;
              <label><input name="isTemplate" type="checkbox" value="1" <gen:if test='${model.isTemplate == 1}'> checked</gen:if> /> 可更换</label></span></td>
          </tr>
          <tr class="border-top">
            <td align="right">系统模型：</td>
            <td><select name="isSystem">
                <option value="0"<gen:if test='${model.isSystem == 0}'> selected</gen:if>>否</option>
                <option value="1"<gen:if test='${model.isSystem == 1}'> selected</gen:if>>是</option>
              </select></td>
          </tr>
          <tr class="border-top">
            <td align="right">状态：</td>
            <td><label>
                <input name="isDisabled" type="radio" value="0"<gen:if test='${empty model || model.isDisabled == 0}'> checked</gen:if> />
                启用</label>
              &nbsp;&nbsp;
              <label>
                <input name="isDisabled" type="radio" value="1"<gen:if test='${model.isDisabled == 1}'> checked</gen:if> />
              禁用</label></td>
          </tr>
          <tr class="border-top">
            <td colspan="2" class="push txt-c"><input type="hidden" name="formHash" value="${formHash}"/>
              <input type="hidden" name="sort" value="${model.sort}"/>
              <input name="submit" class="button blue small" type="submit" value="确 定" />
              &nbsp;&nbsp;&nbsp;&nbsp;
              <input name="reset" class="button gray small" type="reset" value="取 消" /></td>
          </tr>
        </table>
      </form>
    </div>
  </div>
</div>
<!-- 必备插件 -->
<script type="text/javascript" src="${config.statie}js/jquery.js"></script>
<script type="text/javascript" src="${config.statie}js/jquery.form.js"></script>
<script type="text/javascript" src="${config.statie}js/jquery.grapes.js"></script>
<script type="text/javascript" src="${config.statie}js/jquery.timers.js"></script>
<script type="text/javascript" src="${config.statie}js/jquery.mousewheel.js"></script>
<script type="text/javascript" src="${config.statie}js/jquery.tablecolor.js"></script>
<!-- 弹窗插件 -->
<script type="text/javascript" src="${config.statie}js/dialog/jquery.dialog.js?self=true"></script>
<script type="text/javascript" src="${config.statie}js/dialog/jquery.dialog.plugins.js"></script>
<!-- 表单验证插件 -->
<script type="text/javascript" src="${config.statie}js/validate/jquery.validate.js"></script>
<script type="text/javascript" src="${config.statie}js/validate/validate.expand.js"></script>
<script type="text/javascript" src="${config.statie}js/validate/messages_zh.js"></script>
<!-- UI界面必备 -->
<script type="text/javascript" src="${config.statie}ui/js/jspgen.js"></script>
<script type="text/javascript" src="${config.statie}ui/js/jspgen.ajax.js"></script>
<script type="text/javascript" src="${config.statie}ui/js/jspgen.ready.js"></script>
<!-- 当前页面 -->
<script type="text/javascript">
// document.domain = "baidu.com";

// 调用
$(document).ready(function(){
	var $form = $('#form'), $reset = $('input:reset');
	
	// 表单验证
	var validate = $form.validate({
		rules: {
			id: {
				required: true
			},
			name: {
				required: true
			},
			release: {
				required: true
			},
			template: {
				required: true
			}
		},
		messages: {
			id: {
				required: "Id不允许为空！"
			},
			name: {
				required: "名称不允许为空！"
			},
			release: {
				required: "版本不允许为空！"
			},
			template: {
				required: "模板不允许为空！"
			}
		},
		submitHandler: function(form) {
			$(form).ajaxSubmit($.extend({
				success: function(result) {
					// {'status':false,'message':'message', 'store':{'id':'id'}}
					if (result) {
						if (result.status) {
							$dialog.success(result.message, function() {
								refleshFromTab(); removeTab();
							});
						}else{
							$dialog.error(result.message);
						}
					}
				}
			}, formOptions));
			
			// 阻止表单默认提交
			return false;
		}
	});
	$reset.bind('click', function () {
		validate.resetForm();
	});
});

// 模板选择（传递默认路径、赋值对象不一样）
$('#wrapper').on('click', '.templateTr a.edit', function () {
	var to = $(this).attr('to'), uri = $('#'+to).prop('value'); // 采用prop为即时属性值,可预防手动删除时依旧能获取到表单值
	if(grapes.isEmpty(uri)) {
		$dialog.alert('请先选择模板文件…'); return false;
	}
	var parent = uri.substring(0, uri.lastIndexOf('/')+1);
	var id = uri.substring(uri.lastIndexOf('/')+1), idn = 'template_edit_'+id.replace('.', '-'); // 采用jQuery定位，不能出现定位符号
	return addTab($(this).attr('title'), 'template!edit.gen?parent='+parent+'&filename='+id, idn);
});
$('#wrapper').on('click', '.templateTr a.choose', function () {
	var genre = $(this).attr('genre'), to = $(this).attr('to'), uri = '?to='+to;
	if(grapes.isNotEmpty(genre)) {
		uri += '&parent=/'+genre+'/';
	}
	var dialog = $dialog.iframe('template!choose.gen'+uri, {title: $(this).attr('title'), width:'700px', height:'350px', resize: false});
	dialog.callback = function(obj) {
		if(grapes.isNotEmpty(obj.to)) {
			$('#'+obj.to).attr('value', obj.uri);
		}else{
			$('#template').attr('value', obj.uri);
		}
	}
});
</script>
</body>
</html>