{{template "inc"}}
<!-- Main Header -->
{{template "header"}}
<!-- Left side column. 权限菜单 -->
{{template "memu"}}
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
	<section class="content-header">
		<ol class="breadcrumb">
		  <li><a href="/admin/version"><i class="fa fa-dashboard"></i>版本管理</a></li>
			<li class="active"><a href="/admin/site_management?vid={{.vid}}">站点列表</a></li>
			<li>属性配置</li>
		  <li>抽取逻辑</li>
		  <li>前置规则</li>
		  <li class="active"><a href="/admin/site_management/check/lua/corepre?vid={{.vid}}&pid={{.pid}}&sid={{.sid}}&s_code={{.code}}">{{.code}}</a></li>
		</ol>
    </section>
  <!-- Main content -->
  <section class="content"><br/>
    	<form id="dataform" class="form-horizontal">
			<div class="form-group">
				<div class="col-sm-12">
					<select name="infoid" class="form-control">
	                	<option value="">请选择测试信息</option>
						{{if .rule.infoid}}
							{{$ruleid := .rule.infoid}}
							{{range .infos}}
								<option value="{{._id}}" {{if eq ._id $ruleid}} selected {{end}}>{{.title}}</option>
							{{end}}
						{{else}}
							{{range .infos}}
								<option value="{{._id}}">{{.title}}</option>
							{{end}}
						{{end}}
	              	</select>
				</div>
				<label for="code" class="col-sm-1 control-label">代码: {{.rule.s_code}}</label>
			    <label for="code" class="col-sm-3 control-label">名称: {{.rule.s_name}}</label>
			</div>
			<fieldset class="col-sm-6" data-mode="expert">
				<textarea id="s_luascript" name="s_luascript">{{.rule.s_luascript}}</textarea>
			</fieldset>
			<fieldset class="col-sm-6" data-mode="expert">
				<textarea id="result" style="height:400px;width:100%"></textarea>
			</fieldset>
			<input type="hidden" name="_id" value="{{.rule._id}}">
			<input type="hidden" name="s_code" value="{{.rule.s_code}}">
			<input type="hidden" name="s_name" value="{{.rule.s_name}}">
		</form>
		
		<h1><div class="btn-center">
			<button type="button" class="btn btn-success" onclick="check()">测试</button>
			<button type="button" class="btn btn-primary" onclick="save()">保存</button>
		</div></h1>
</section>

</div>
{{template "luares"}}
{{template "footer"}}
<script>
com.initMirror(400)
menuActive("version")
function check(){
	$.post("/admin/site_management/check/lua/coreprerule",
		com.serializeArray("dataform"), 
		function(r) {
			if(r.rep){				
				$("#result").html(JSON.stringify(r.rep, null, 2)) 
			}
		}
	);
}
function save(){
	$.post("/admin/site_management/logicpre/save",
		com.serializeArray("dataform"),
		function(r){
			if(r){
				showTip("保存成功",1000)
			}
		}
	);
}
</script>

