<%@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">
    <gen:if test='${!param.dialog}'><h2><i>上传文件</i></h2></gen:if>
    <div class="area-content">
      <form id="form" name="form" action="upload!save.gen" method="post" enctype="multipart/form-data">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table">
          <tr>
            <td width="30%" align="right" class="orange">友情提示：</td>
            <td>请保持文件在&nbsp;${upload.size}&nbsp;之内，支持格式有&nbsp;${upload.pattern}</td>
          </tr>
          <tr class="border-top">
            <td align="right">文件名称：</td>
            <td>
            <input id="name" name="name" type="text" class="text small" value="" size="20" />&nbsp;
            <label style="${empty param.pic ? 'display:none;':''}"><input name="face" type="checkbox" /> 按寸照处理</label></td>
          </tr>
          <tr class="border-top">
            <td align="right">文件选择：</td>
            <td>
            <label for="filename" class="text small filename-txt" id="filename-txt"></label>
            <label for="filename" class="button gray small blue-hover">浏览</label>
            <input type="file" class="filename" id="filename" name="filename" /></td>
          </tr>
          <tr class="border-top">
            <td colspan="2" class="push txt-c"><input type="hidden" name="formHash" value="${formHash}"/>
            	<input type="hidden" name="configName" value="${param.configName}" />
                <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: {
			filename: {
				required: true
			}
		},
		messages: {
			filename: {
				required: "请选择文件！"
			}
		},
		submitHandler: function(form) {
			// $('input[name="face"]:checked').val();
			if($('input[name="face"]').is(':checked')) {
				$('input[name="configName"]').attr('value', 'editorFace');
			}
			$(form).ajaxSubmit($.extend({
				success: function(result) {
					// {'status':false,'message':'message', 'store':{'id':'id'}}
					if (result) {
						alert(result.message);
						if (result.status) {
							var store = result.store[0];
							<gen:if test='${empty param.dialog}'>
							$dialog.success(result.message, function() {
								refleshFromTab(); removeTab();
							});
							<gen:else />
							$dialogApi.callback({to:'${param.to}', id:store.id, name:store.name, url:store.url, exte:store.fileExte, length:store.fileLength});
							$dialogApi.close();
							</gen:if>
						}else{
							$dialog.error(result.message);
						}
					}
				}
			}, formOptions));
			
			// 阻止表单默认提交
			return false;
		}
	});
	$reset.bind('click', function () {
		<gen:if test='${empty param.dialog}'>validate.resetForm();<gen:else />
		$dialogApi.close();
		</gen:if>							
	});
	
});
</script>
</body>
</html>