{{template "inc"}}
<!-- Main Header -->
{{template "header"}}
<!-- Left side column. 权限菜单 -->
{{template "memu"}}

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
	<section class="content-header">
		<h1>
			<small><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modal-info-addtag">新增标签</button></small>
		</h1>
		<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 class="active"><a href="/admin/site_management/tag?version={{.version}}&vid={{.vid}}&pid={{.pid}}">标签库</a></li>
		</ol>
    </section>
  <!-- Main content -->
  <section class="content">
      <div class="row">
	      <div class="col-xs-12">
	        <div class="box">
		        <div class="box-body">
		            <table id="dataTagTable" class="table table-bordered table-hover">
		              <thead>
		              <tr>
		                <th>名称</th>
						<th>版本</th>
						<th>创建人</th>
						<th>创建时间</th>
						<th>类型</th>
						<th>操作</th>
		              </tr>
		              </thead>
		            </table>
		        </div>
	          <!-- /.box-body -->
	        </div>
        <!-- /.box -->
		</div>
	</div>
  </section>
</div>
<!--新增标签--> 
<div class="modal fade" id="modal-info-addtag">
  	<div class="modal-dialog">
	    <form id="add-dataform" class="form-horizontal" role="form">
		<div class="modal-content">
		    <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
		          <span aria-hidden="true">&times;</span></button>
		        <h4 class="modal-title">标签信息</h4>
		    </div>
		    <div class="modal-body">
		     	<div class="form-group">
				    <label for="code" class="col-sm-2 control-label">名称:</label>
				      <div class="col-sm-10" id="add-name">
				      	<input type="radio" name="name" id="add-str" value="正则类">正则类</input>&nbsp;&nbsp;&nbsp;&nbsp;
					  	<input type="radio" name="name" id="add-reg" value="字符串类">字符串类</input>&nbsp;&nbsp;&nbsp;&nbsp;
					   	<input type="radio" name="name" id="add-simarea" value="城市简称">城市简称</input>&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="radio" name="name" id="add-allarea" value="城市全称">城市全称</input>&nbsp;&nbsp;&nbsp;&nbsp;
				      	<input type="radio" name="name" id="add-province" value="省份">省份
					</div>
					<!--<input id="add-name" type="text" class="form-control" placeholder="请输名称">-->
				</div>
				<div class="form-group">
				    <label for="code" class="col-sm-2 control-label">版本:</label>
				    <div class="col-sm-10">
				      <input id="add-version" type="text" value="{{.version}}" class="form-control" disabled>
				    </div>
				</div>
				<!--<div class="form-group">
				   <label for="code" class="col-sm-2 control-label">类型:</label>
				    <div class="col-sm-10" id="add-checkbox">
				      <input type="radio" name="tp" id="add-str" value="str">字符串</input>&nbsp;&nbsp;&nbsp;&nbsp;
					  <input type="radio" name="tp" id="add-reg" value="reg">正则</input>&nbsp;&nbsp;&nbsp;&nbsp;
					   <input type="radio" name="tp" id="add-area" value="area">地区</input>
				    </div>
				</div>-->
		    </div>
		    <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal" onclick="reset()">取消</button>
		        <button type="button" class="btn btn-primary" onclick="addsave()">保存</button>
	    	</div>
		</div>
	    <!-- /.modal-content -->
	    </form>
  	</div>
  <!-- /.modal-dialog -->
</div>
<!-- /.modal -->


<!-- footer -->
{{template "footer"}}

<script>
menuActive("version")
$(function () {
	ttabletag=$('#dataTagTable').DataTable({
		"lengthChange": false,
		"searching"   : true,
		"ordering"    : false,
		"info"        : true,
		"autoWidth"   : false,
		"paging"	  : true,
		
		"ajax": {
			"url": "/admin/site_management/tag/data",
			"type": "post",
			"data":{"version":{{ .version}},"vid":{{.vid}},"pid":{{.pid}} }
		 },
		"language": {
			"url": "/res/dist/js/dataTables.chinese.lang"
        },
		"columns": [
            { "data": "s_tagname",render:function(val,a,row){
				//return "<a href='#' onclick='searchOneTag(\""+val+"\",\""+row["version"]+"\")'>"+val+"</a>"
				return '<a href="/admin/site_management/onetag?version='+row.s_version+'&tagname='+row.s_tagname+'&tp='+row.s_type+'&parentid='+row._id+'">'+val+'</a>';
			}},
			{ "data": "s_version"},
			{ "data": "s_creater"},
			{ "data": "l_intime"},
			{ "data": "s_type"},
			{ "data": "_id",render:function(val,a,row){
				return  "<a href='#' onclick='del(\""+val+"\")'><i class='fa fa-fw fa-trash text-red'></i></a>"
				//"<a href='#' onclick='edit(\""+val+"\",\""+row["name"]+"\",\""+row["content"]+"\")'><i class='fa fa-fw fa-edit text-yellow'></i></a> &nbsp;"+
			}}
       	]
	});
	//ttabletag.on('init.dt', function () {});
})
//新建保存
function addsave(){
	var name = "";
	$("#add-name input[type=radio]").each(function(){
		if($(this).prop("checked")){
			name = $(this).val();
		}
	});
	version=$("#add-version").val();
	if(name==""){
		alert("表单填写不完整！");
		return false;
	}
	var tp = "";
	if(name == "字符串类"){
		tp = "string";
	}else if(name == "正则类"){
		tp = "reg";
	}else if(name == "城市简称"){
		tp = "citysim";
	}else if(name == "城市全称"){
		tp = "cityall";
	}else if(name == "省份"){
		tp = "province";
	}	
	
	$.ajax({
		url:"/admin/site_management/tag/save",
		type:"post",
		data:{"tagname":name,"tp":tp,"vid":{{.vid}},"pid":{{.pid}},"version":version,"username":{{index (session "user") "name" }}},
		success:function(r){
			if(r.rep){
				$("#add-dataform")[0].reset();
				$("#modal-info-addtag").modal("hide");
				ttabletag.ajax.reload();
			}else{
				$("#add-dataform")[0].reset();
				$("#modal-info-addtag").modal("hide");
				alert("保存失败");
			}
		}
	})
}

//删除
function del(_id){
	showConfirm("确定删除？", function() {
		$.ajax({
			url:"/admin/site_management/tag/del",
			type:"post",
			data:{"_id":_id},
			success:function(r){
				if(r.rep){				
					ttabletag.ajax.reload();
				}else{
					showTip("删除失败", 1000, function() {});
				}
			}
		})
	});
}
</script>
