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

<div class="content-wrapper" id="showbtn">
	<section class="content-header">
		<h1>
			<small><a class="btn btn-primary opr" opr="new">新增清理任务</a></small>
		</h1>
		<ol class="breadcrumb">
		  <li><a href="/admin/task/list"><i class="fa fa-dashboard"></i> 任务管理</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="dataTable" class="table table-bordered table-hover">
		              <thead>
		              <tr>
		                <th>任务名称</th> <th>创建时间</th> <th>创建人</th> <th>描述</th><th>操作</th>
		              </tr>
		              </thead>
		            </table>
		        </div>
	          <!-- /.box-body -->
	        </div>
        <!-- /.box -->
		</div>
	</div>
  </section>
</div>
{{template "dialog"}}
{{template "footer"}}
<script>
menuActive("taskclear")
$(function () {
	ttable=$('#dataTable').DataTable({
		"paging"      : false,
		"lengthChange": false,
		"searching"   : false,
		"ordering"    : false,
		"info"        : true,
		"autoWidth"   : false,
		"ajax": {
			"url": "/admin/cleartask/list",
			"type": "post",
			"data":{}
		 },
		"language": {
            "url": "/res/dist/js/dataTables.chinese.lang"
        },
		"columns": [
            { "data": "s_taskname"},
			{ "data": "l_createtime",render:function(val){
				var dt=new Date()
				dt.setTime(parseInt(val)*1000)
				return dt.format("yyyy-MM-dd hh:mm:ss")
			}},
			{ "data": "s_username"},
			{ "data": "s_descript","width":"25%"},
			{ "data":"_id","width":"25%",render:function(val,a,row,pos){
				tmp = '<div>'+
					'<a class="btn btn-sm btn-primary opr" opr="edit" row="'+pos.row+'" >编辑</a>　'+
					'</div>';
				return  tmp
			}}
       	]
	});
	ttable.on('init.dt', function () {
		$("#showbtn").on('click','a.opr',function(){
			var n=$(this).attr("opr");
			var taskid=$(this).attr("taskid");
			var htmlObj={},obj,tag=[],bts=[];
			var _tit="";
			switch(n){
			case "edit":			
				obj=ttable.row($(this).closest("tr")).data();	
			case "test":
				obj=ttable.row($(this).closest("tr")).data();
			case "new":
				/*表单*/
				addtask=[
					{label:"任务名称",s_label:"s_taskname",placeholder:"结果清理",must:true},
					{label:"源库连接",s_label:"s_mgoaddr",must:true},
					{label:"源数据库",s_label:"s_mgodb",must:true},
					{label:"结果表",s_label:"s_mgocoll",must:true},
					{label:"描述",s_label:"s_descript",type:"tpl_text"},
					{label:"使用版本",s_label:"s_version",type:"tpl_list_local",must:true,url:"/admin/task/getclearversions"},
					{label:"并发数量",s_label:"i_process",placeholder:"5",must:true},
					{s_label:"_id",type:"tpl_hidden"},
				];
				/*按钮*/
				//新增保存按钮
				addtaskbtn=[
					{label:"保存",class:"btn-primary",
						fun:function(){
							var obj={}
							var bcon=true
							$("#_con").find("input[id!=s_show],textarea").each(function(i,el){
								var val=$(el).val();
								if(el.id!="_id"&&$(el).attr("must")&&!val){
									bcon=false
									return false
								}
								obj[el.id]=$(el).val()
							})
							if (bcon){								
								$.post("/admin/cleartask/save",obj,function(data){
									if(data&&data.rep){
										window.location.href="/admin/taskclear"								
									}else{
										alert(data.msg)
									}
								},'json')
							}else{
								alert("红色标签的表单不能为空！")
							}
						}
					}
				];
				if(n == "new"){
					_tit="新增清理任务";
					tag = com.pushArry(tag,addtask);
					bts = com.pushArry(bts,addtaskbtn);
				}else if(n == "edit"){
					_tit="编辑-"+obj.s_taskname;
					tag = com.pushArry(tag,addtask);
					bts = com.pushArry(bts,addtaskbtn);
				}
				htmlObj={
					title:_tit,
					tag:tag,
					bts:bts
				}
			OpenDialog(htmlObj,obj)
			break;
			}
		});
	})
	
})

</script>
