<%@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}'>ad!save.gen<gen:else />ad!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;名称：</td>
            <td><input id="name" name="name" type="text" class="text small" value="${ad.name}" size="25" />
              <label for="name" generated="true" class="tip normal" tip=""></label></td>
          </tr>
          <tr class="border-top">
            <td align="right"><span class="red">*</span>&nbsp;类型：</td>
            <td><span class="field"><label><input name="genre" type="radio" value="file" <gen:if test='${ad.genre == "file"}'>checked</gen:if>/>
            文件</label>&nbsp;&nbsp;
            <label><input type="radio" name="genre" value="code" <gen:if test='${ad.genre == "code"}'>checked</gen:if>/>
            代码</label></span></td>
          </tr>
          <tr class="border-top tr_file <gen:if test='${ad.genre == "file"}'>show<gen:else />hide</gen:if>">
            <td align="right">文件：</td>
            <td><span class="field"><input id="file" name="file" type="text" class="text small" config="ad" value="${ad.file}" size="62" />
            <input type="button" name="browse" to="file" class="button gray small blue-hover" value="浏览" /><input type="button" name="upload" to="file" class="button gray small blue-hover" value="选择" /></span>
            <label for="file" generated="true" class="tip normal" tip=""></label></td>
          </tr>
          <tr class="border-top tr_file <gen:if test='${ad.genre == "file"}'>show<gen:else />hide</gen:if>">
            <td align="right">链接：</td>
            <td><input name="url" type="text" class="text small" id="url" value="${ad.url}" size="62" /></td>
          </tr>
          <tr class="border-top tr_code <gen:if test='${ad.genre == "code"}'>show<gen:else />hide</gen:if>">
            <td align="right" valign="top">代码：</td>
            <td><textarea id="code" name="code" class="text small textarea general ignore">${ad.code}</textarea></td>
          </tr>
          <tr class="border-top">
            <td align="right" valign="top">属性：</td>
            <td><table border="0" cellspacing="0" cellpadding="0">
                <tr class="ignore">
                  <td>开始时间
                  	<input name="startTime" type="text" class="text small ignore" id="startTime" value="${gen:dateTime(ad.startTime, 'yyyy-MM-dd HH:mm:ss', config.timezoneid)}" size="20" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{$dp.$D(\'endTime\')||\'2080-12-12 00:00:00\'}'});" /><label for="startTime" generated="true" class="ico-tips date-picker"></label>
                    &nbsp;结束时间
                  <input name="endTime" type="text" class="text small ignore" id="endTime" value="${gen:dateTime(ad.endTime, 'yyyy-MM-dd HH:mm:ss', config.timezoneid)}" size="20" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'startTime\')}'});" /><label for="endTime" generated="true" class="ico-tips date-picker"></label></td>
                </tr>
                <tr class="ignore">
                  <td>展示次数
                    <input name="pv" type="text" class="text small" id="pv" value="${ad.pv}" size="20" />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;点击次数
                  <input name="clicks" type="text" class="text small" id="clicks" value="${ad.clicks}" size="20" /></td>
                </tr>
              </table></td>
          </tr>
          <tr class="border-top">
            <td align="right">状态：</td>
            <td><select name="status" id="status">
                  <option value="0" <gen:if test='${ad.status == 0}'>selected="selected"</gen:if>>正常</option>
                  <option value="1" <gen:if test='${ad.status == 1}'>selected="selected"</gen:if>>关闭</option>
                </select></td>
          </tr>
          <tr class="border-top">
            <td align="right"> 排序：</td>
            <td>
            <input name="sort" type="text" class="text small" value="${ad.sort}" size="5" /></td>
          </tr>
          <tr class="border-top">
            <td colspan="2" class="push txt-c"><input type="hidden" name="formHash" value="${formHash}"/>
              <input type="hidden" name="id" value="${ad.id}" />
              <input type="hidden" name="adareaId" value="${adarea.id}" />
              <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/datePicker/WdatePicker.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" src="${config.statie}ui/admin/js/tree.js"></script>
<!-- 当前页面 -->
<script type="text/javascript">
// document.domain = "jspgen.com";// 调用
$(document).ready(function(){	
	var $form = $('#form'), $reset = $('input:reset');
	
	// 表单验证
	var validate = $form.validate({
		rules: {
			name: {
				required: true
			},
			genre: {
				required: true
			}
		},
		messages: {
			name: {
				required: "名称不允许为空！"
			},
			genre: {
				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();
	});
	
	// 类型切换
	var $genre=$(':radio[name="genre"]'), $tr_file=$('.tr_file'), $tr_code=$('.tr_code');
	$genre.bind('click',function() {
		switch($(':radio[name="genre"]:checked').prop('value')){
			case'file': fileShow(); break;
			case'code': fileHide(); break;
			default:break;
		}
	});
	function fileShow(){
		$tr_file.show(); $tr_code.hide();
		$("#file").rules("remove");	$("#code").rules("remove");
		$("#file").rules("add", {required: true, messages: {required: "请输入文件地址"}});
	}
	function fileHide(){
		$tr_file.hide(); $tr_code.show();
		$("#file").rules("remove");	//$("#code").rules("remove");
		//$("#code").rules("add", {required: true, messages: {required: "请输入代码"}});
	}
});
</script>
</body>
</html>