<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" isELIgnored="false"%>

<%@ taglib prefix="sitemesh"
	uri="http://www.opensymphony.com/sitemesh/decorator"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="cui" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css"
	href="${ctx}/styles/jquery-ui.css" />
<link rel="stylesheet" type="text/css"
	href="${ctx}/styles/jquery-ui-timepicker-addon.min.css" />
</head>

<div class="header-title-nobg table com-head">
	<div>
		<h1>告警列表</h1>
		<ul>
			<li><span>群组</span> <select autocomplete="off" id="selectGroup">
					<option selected="selected" value="-1">所有群组</option>
			</select> <span>主机</span> <select autocomplete="off" id="selectHostByGroup">
					<option selected="selected" value="-1">所有主机</option>
			</select> <span>触发器</span> <select autocomplete="off" id="selectTriggers">
					<option selected="selected" value="-1">所有触发器</option>
			</select></li>
		</ul>

	</div>
	<div class="borderClass"></div>
</div>
<div class="borderClass"></div>
<div class="filter-btn-container">
	<button type="button" class="filter-trigger filter-active"
		id="filter-mode"
		onclick="javascript:
			jQuery(&quot;#filter-space&quot;).toggle();
			jQuery(&quot;#filter-mode&quot;).toggleClass(&quot;filter-active&quot;);
			jQuery(&quot;#filter-arrow&quot;).toggleClass(&quot;arrow-up arrow-down&quot;);
			updateUserProfile(&quot;web.hostinventories.filter.state&quot;, jQuery(&quot;#filter-arrow&quot;).hasClass(&quot;arrow-up&quot;) ? 1 : 0, []);
			if(jQuery(&quot;#filter-arrow&quot;).hasClass(&quot;arrow-up&quot;)){
					jQuery(&quot;.newMainViewContent&quot;).removeClass(&quot;newMainViewContent&quot;).addClass(&quot;mainViewContent&quot;);
			}else{
					jQuery(&quot;.mainViewContent&quot;).removeClass(&quot;mainViewContent&quot;).addClass(&quot;newMainViewContent&quot;);
			}
			if (jQuery(&quot;.multiselect&quot;).length > 0 &amp;&amp; jQuery(&quot;#filter-arrow&quot;).hasClass(&quot;arrow-up&quot;)) {
				jQuery(&quot;.multiselect&quot;).multiSelect(&quot;resize&quot;);
			}">
		过滤器<span id="filter-arrow" class="arrow-up"></span>
	</button>
	<form method="get" action="hostinventories.php" accept-charset="utf-8"
		name="zbx_filter" id="id">

		<div class="filter-container" id="filter-space">
			<div class="table filter-forms">
				<div class="row">
					<div class="cell">
						<ul class="table-forms">
							<li>
								<div class="table-forms-td-left">
									<label for="alarmStatus">告警状态</label>
								</div>
								<div class="table-forms-td-right">
									<select id="alarmStatus" name="alarmStatus" autocomplete="off">
										<option value="-1" selected="selected">所有</option>

										<option value="1">已恢复</option>
										<option value="2">告警中</option>

									</select>
								</div>
								<div class="table-forms-td-left">
									<label for="alarmLevel">&nbsp;&nbsp;告警严重级别</label>
								</div>
								<div class="table-forms-td-right">
									<select id="alarmLevel" name="alarmLevel" autocomplete="off">
										<option value="-1" selected="selected">所有</option>
										<option value="0">未分类</option>
										<option value="1">信息</option>
										<option value="2">警告</option>
										<option value="3">一般严重</option>
										<option value="4">严重</option>
										<option value="5">灾难</option>
									</select>
								</div>
								<div class="table-forms-td-left">
									<label for="alarmTime">&nbsp;&nbsp;告警时间</label>
								</div>
								<div class="table-forms-td-right countTime">
									<select id="alarmTime" name="alarmTime" autocomplete="off">
										<option value="-1" selected="selected">所有</option>
										<option value="1">1天</option>
										<option value="2">1个月</option>
										<option value="3">6个月</option>
										<option value="10" class="selfConf">自定义</option>
									</select>
									<ul class="radio-segmented">
										<li class="lightenblue-bg datepicker "><input
											id="datepicker_from" name="minDate" class="custom-date1"
											disabled="disabled"
											style="box-sizing: border-box; height: 24px;" /></li>
										<span class="font ">到</span>
										<li class="lightenblue-bg datepicker "><input
											id="datepicker_to" name="maxDate" class="custom-date1"
											disabled="disabled"
											style="box-sizing: border-box; height: 24px;" /></li>
									</ul>
								</div>
					</div>
				</div>
			</div>
			<div class="filter-forms">
				<button type="button" id="confirm" value="过滤">过滤</button>
				<button type="button" id="reset" class="btn-alt btn-border">重设</button>
			</div>
	</form>


</div>
<div class="body">
	<div>
		<table class="list-table">
			<thead id="tabTop">
				<tr id="topTen" class="tabTop">			
					<th style="width:10%">时间</th>
					<th style="width:15%">名称</th>
					<th style="width:5%">类型</th>
					<th style="width:32%">描述</th>
					<th style="width:10%">状态</th>
					<th style="width:12%">严重性</th>
					<th style="width:12%">持续时间</th>
				</tr>

			</thead>
			<tbody id="alarmInfoTab">


			</tbody>
		</table>
	</div>
</div>
<div class="table-paging" id="table-paging">
	<div class="paging-btn-container" id="pageNum"></div>
</div>
<%-- <script src="${ctx}/js/jquery.1.10.1.min.js"></script> --%>
<script src="${ctx}/js/vendors/jquery-ui.js"></script>
<script src="${ctx}/js/vendors/jquery-datepicker-zh.js"></script>
<script src="${ctx}/js/vendors/jquery-ui-timepicker-addon.min.js"></script>
<script>
			    MMenu.def_label = 'cm';
			    var priorityName = ["未分类","信息","警告","一般严重","严重","灾难"];
			    var statusName = ["已恢复","告警中"];
			    var date = new Date(),timeValue=[],maxTime=[];
			    timeValue.push(date.getFullYear()-1);
				timeValue.push(date.getMonth()+1);
				timeValue.push(date.getDate());
				timeValue.push(date.getHours());
				timeValue.push(date.getMinutes());
				var minDate = timeValue.join("-");
				maxTime.push(date.getFullYear());
				maxTime.push(date.getMonth()+1);
				maxTime.push(date.getDate());
				maxTime.push(date.getHours());
				maxTime.push(date.getMinutes());
				var maxDate = maxTime.join("-");
			    jQuery("#datepicker_from").datetimepicker({
			    	timeText: '时间',
                    hourText: '小时',
                    minuteText: '分钟',
                    secondText: '秒',
                    currentText: '现在',
                    closeText: '完成',
                    changeYear:true,
                    changeMonth:true,
                    showSecond: true, //显示秒  
                    timeFormat: 'HH:mm:ss' //格式化时间  
			    }).on( "change", function() {
			    	jQuery("#datepicker_to").datetimepicker( "option", "minDate", this.value );
			    });;
			    jQuery("#datepicker_to").datetimepicker({
			    	timeText: '时间',
                    hourText: '小时',
                    minuteText: '分钟',
                    secondText: '秒',
                    currentText: '现在',
                    closeText: '完成',
                    changeYear:true,
                    changeMonth:true,
                    showSecond: true, //显示秒  
                    timeFormat: 'HH:mm:ss' //格式化时间  
			    }).on( "change", function() {
			    	//jQuery("#datepicker_to").datetimepicker( "option", "maxDate", this.value );
			    });
			    jQuery("#datepicker_to").datetimepicker( "option", "maxDate", maxDate );
			    jQuery("#datepicker_to").datetimepicker( "option", "minDate", minDate );
			    /* timeValue.push(date.getFullYear()-1);
				timeValue.push(date.getMonth()+1);
				timeValue.push(date.getDate());
				var minDate = timeValue.join("-");
				maxTime.push(date.getFullYear());
				maxTime.push(date.getMonth()+1);
				maxTime.push(date.getDate());
				var maxDate = maxTime.join("-");
			    jQuery("#datepicker_from").datepicker({
			    	 defaultDate: new Date() ,
			         changeMonth: true,
			         numberOfMonths:1,
			         changeMonth: true,
			         changeYear: true,
			         dateFormat:"yy-mm-dd"
			    }).on( "change", function() {
			    	jQuery("#datepicker_to").datepicker( "option", "minDate", this.value );
			    });
			    jQuery("#datepicker_from").datepicker( "option", "minDate", minDate );
			    jQuery("#datepicker_from").datepicker( "option", "maxDate", maxDate );
			    jQuery("#datepicker_to").datepicker({
			    	 defaultDate: new Date() ,
			         changeMonth: true,
			         numberOfMonths: 1,
			         changeMonth: true,
			         changeYear: true,
			         dateFormat:"yy-mm-dd"
			    }).on( "change", function() {
			    	jQuery("#datepicker_from").datepicker( "option", "maxDate", this.value );
			    });
			    jQuery("#datepicker_to").datepicker( "option", "maxDate", maxDate );
			    jQuery("#datepicker_to").datepicker( "option", "minDate", minDate ); */
			    
			    var groupId = jQuery("#selectGroup").find("option:selected").attr('value');
		  		var hostId = jQuery("#selectHostByGroup").find("option:selected").attr('value');
		    	var objectId = jQuery("#selectTriggers").find("option:selected").attr('value');
		    	var interval = dealTimeInfo();//警告时间
	    		var alarmStatus = dealStatusInfo();//警告状态 
	    		var alarmLevel = dealPriorityInfo();//警告级别 
	    		if(interval==10){
		    		var startDate = jQuery("input[name='minDate']").val();
		    		var endDate = jQuery("input[name='maxDate']").val();
		    		var startTime = (new Date(startDate).getTime())/1000;
		    		var endTime = (new Date(endDate).getTime())/1000;
	    		}else{
	    			startTime = 0;
	    			endTime = 0;
	    		}
	    		function getUrlParam(name) {
	    		      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	    		      var r = window.location.search.substr(1).match(reg); //匹配目标参数
	    		      if (r != null) return unescape(r[2]); return null; //返回参数值
	    		} 
			    jQuery(document).ready(function() {
			    	jQuery("").html('<tr><td colspan="5"><div class="loading"><img src="${ctx}/img/ajax-loader.gif"><label>正在加载请稍等……</label></div></td></tr>');
			    	var trId = getUrlParam('triggerid');
			    	var hId = getUrlParam('hostid');
			    	var gId = getUrlParam('groupid');
			    	var hostId ="";
			    	var objectId ="";
			    	var groupId = -1;
			    	if(hId!=null){
			    		if(gId==0||gId==null){
			    			groupId =-1;
			    		}else{
			    			groupId =gId;
			    		}
			    		hostId = hId;
			    		objectId = -1;
			    	}else{		    		
			    		if(trId!=null){	    			
				    		objectId = trId;
				    		jQuery.ajax({
						        type: 'POST',
						        async: false,
						        url: '${ctx}/alarmList/getHostByTriggerId.json',
						        data: {triggerId:objectId},
						        success: function (data) {
						        	hostId = data.hostid;
						        	groupId = data.groups[0].groupid;
						        	/* return hostId; */
						        }, 
						        dataType: 'json'
						        });
				    	}else{
				    		objectId = -1;
				    		hostId = -1;
				    	} 
			    	}

			    	getByPage(null,groupId,hostId,objectId);
			    	jQuery.ajax({
				        type: 'POST',
				        async: true,
				        url: '${ctx}/formview/getHostGroups.json',
				        data: {},
				        success: function (data) {
				        	jQuery("#selectGroup").empty();
				        	jQuery("#selectHostByGroup").empty();
					    	jQuery("#selectGroup").append('<option selected="selected" value = "-1">所有群组</option>');
					    	jQuery("#selectHostByGroup").append('<option selected="selected" value = "-1">所有主机</option>');
				        	for (var i=0; i<data.length; i++){
				        		jQuery("#selectGroup").append('<option value="' + data[i].groupid + '">' + data[i].name + '</option>');
				        		for(var j=0;j<data[i].hosts.length;j++){
				        			jQuery("#selectHostByGroup").append('<option value="' + data[i].hosts[j].hostid + '">' + data[i].hosts[j].name + '</option>');
				        		}
				        	}
				        	jQuery("#selectGroup option[value='"+groupId+"']").prop("selected", 'selected');
				        	jQuery("#selectHostByGroup option[value='"+hostId+"']").prop("selected", 'selected');
				        	
				        }, 
				        dataType: 'json'
				        });
				    	jQuery.ajax({
					        type: 'POST',
					        async: true,
					        url: '${ctx}/alarmList/getAllTriggers.json',
					        data: {hostId:hostId},
					        success: function (data) {
					        	jQuery("#selectTriggers").empty();
						    	jQuery("#selectTriggers").append('<option selected="selected" value = "-1">所有触发器</option>');
					        	for (var i=0; i<data.length; i++){
					        		jQuery("#selectTriggers").append('<option value="' + data[i].triggerid + '">' + data[i].description + '</option>');
					        	}
					        	jQuery("#selectTriggers option[value='"+objectId+"']").prop("selected", 'selected');
 
					        }, 
					        dataType: 'json'
					     });
				    	  
				    	
			    });

			    function getLocalTime(nS) {     
			        return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");      
			     }
			    function datetimeFormat(longTypeDate){ 
			    	  var datetimeType = ""; 
			    	  var date = new Date(); 
			    	  date.setTime(longTypeDate); 
			    	  datetimeType+= date.getFullYear();  //年 
			    	  datetimeType+= "-" + getMonth(date); //月  
			    	  datetimeType += "-" + getDay(date);  //日 
			    	  datetimeType+= "  " + getHours(date);  //时 
			    	  datetimeType+= ":" + getMinutes(date);   //分
			    	  datetimeType+= ":" + getSeconds(date);   //分
			    	  return datetimeType;
			    }
			    function getMonth(date){ 
			    	  var month = ""; 
			    	  month = date.getMonth() + 1; //getMonth()得到的月份是0-11 
			    	  if(month<10){ 
			    	    month = "0" + month; 
			    	  } 
			    	  return month; 
			    	} 
			    	//返回01-30的日期 
		    	function getDay(date){ 
		    	  var day = ""; 
		    	  day = date.getDate(); 
		    	  if(day<10){ 
		    	    day = "0" + day; 
		    	  } 
		    	  return day; 
		    	}
		    	//返回小时
		    	function getHours(date){
		    	  var hours = "";
		    	  hours = date.getHours();
		    	  if(hours<10){ 
		    	    hours = "0" + hours; 
		    	  } 
		    	  return hours; 
		    	}
		    	//返回分
		    	function getMinutes(date){
		    	  var minute = "";
		    	  minute = date.getMinutes();
		    	  if(minute<10){ 
		    	    minute = "0" + minute; 
		    	  } 
		    	  return minute; 
		    	}
		    	//返回秒
		    	function getSeconds(date){
		    	  var second = "";
		    	  second = date.getSeconds();
		    	  if(second<10){ 
		    	    second = "0" + second; 
		    	  } 
		    	  return second; 
		    	}
				//获取当前页的事件告警信息
	    		function getByPage(obj,groupId,hostId,objectId){
	    			var page = 1;
	    			if(obj!=null){
	    				var page = obj.getAttribute('value');
	    				var groupId = jQuery("#selectGroup").find("option:selected").attr('value');
		   		  		var hostId = jQuery("#selectHostByGroup").find("option:selected").attr('value');
		   		    	var objectId = jQuery("#selectTriggers").find("option:selected").attr('value'); 
	    			}
	   		    	var interval = dealTimeInfo();//警告时间
	   	    		var alarmStatus = dealStatusInfo();//警告状态 
	   	    		var alarmLevel = dealPriorityInfo();//警告级别 
	   	    		if(interval==10){
	   		    		var startDate = jQuery("input[name='minDate']").val();
	   		    		var endDate = jQuery("input[name='maxDate']").val();
	   		    		if(startDate!=""&&endDate!=""){
				    		var startTime = (new Date(startDate).getTime())/1000;
				    		var endTime = (new Date(endDate).getTime())/1000;
			    		}else{
			    			alert("请输入自定义时间！");
			    		}
	   	    		}else{
	   	    			startTime = 0;
	   	    			endTime = 0;
	   	    		}
	   	    	/* 	if(page==1){
	   	    			getAlarmInfo(groupId,hostId,objectId);
	   	    		}else{ */
	   	    			
	   	    	//需要添加字段的地方
		   	     jQuery("#alarmInfoTab").html('<tr><td colspan="5"><div class="loading"><img src="${ctx}/img/ajax-loader.gif"><label>正在加载请稍等……</label></div></td></tr>');
    			 jQuery.ajax({
					type:'post',
					
				    url:"${ctx}/alarmList/filterAlarmInfo.json", //请求数据的地址
				    data : {	
				    	groupId :groupId,
				    	hostId : hostId,
				    	objectId : objectId,
				    	status : alarmStatus,
				    	warningLevel : alarmLevel,
				    	startTime: startTime,
				    	endTime: endTime,
				    	interval:interval,
				    	page:page
				    },
				    success:function(data){
				    	jQuery('.loadingindex').hide();
				    	var length = data.length;
				    	jQuery("tbody tr").remove();
				    	var tr = "";
				    	if(data.length==null){
				    		 tr +="<td colspan='5'>未发现数据</td>";  
				    	}else{
					    	for(var i = 0;i < length;i++) {			    		
					    		tr += "<tr>"
					    	    tr += "<td>" + datetimeFormat(data[i].startClock*1000) + "</td>";
					    	    tr +="<td>"+data[i].hostName+"</td>";     //名称
					    	    if(data[i].hostType==1){				 //类型
					    			tr += "<td>"+"交换机"+"</td>";
					    		}else if(data[i].hostType==2){
					    			tr += "<td>"+"服务器"+"</td>";
					    		}else if(data[i].hostType==3){
					    			tr += "<td>"+"路由器"+"</td>";
					    		}else if(data[i].hostType==4){
					    			tr += "<td>"+"中间件"+"</td>";
					    		}else if(data[i].hostType==5){
					    			tr += "<td>"+"防火墙"+"</td>";
					    		}else if(data[i].hostType==6){
					    			tr += "<td>"+"PC机"+"</td>";
					    		}else{
					    			tr += "<td>"+""+"</td>";
					    		}
					    		
					    		tr += "<td>" + data[i].description + "</td>";
					    		if(data[i].status==1){
					    			tr += '<td><span style="color: #DC0000">告警中</span></td>';
					    		}else{
					    			tr += '<td><span style="color: #429e47">已恢复</span></td>';
					    		}
					    		tr += "<td>" + priorityName[data[i].warningLevel] + "</td>";
					    		tr += "<td>" + data[i].subClock + "</td>";
					    		tr += "</tr>"
						    }
				    	}
				    	jQuery("tbody").append(tr);
				    	var a = "";
				    	var totalPage = 0;
				    	var length = 0;
				    	if(data.length!=null){
				    		length = data[0].totalRecord;
				    	}
				    	jQuery("#pageNum").children().remove(); 
				    	if (length % 50 == 0&& length!=0) {
				            totalPage = length / 50;
				    	}else if (length == 0){
				    		totalPage = 1;
				    	}else {
				        	totalPage = Math.floor(length / 50) + 1;
				        }
				    	if(totalPage>1){
					    	a += "<a href='#' value='"+1+"' onclick='getByPage(this)'>首</a>";
					    	if(page!=1){
					    	a += "<a href='#' value="+"'"+(parseInt(page)-1)+"'"+" onclick='getByPage(this)'>"+"<span class="+"'arrow-left'></span>"+"</a>";
					    	}
					    	if(totalPage<=10){
					    		for(var j=1 ; j<=totalPage ; j++){
						    		a += "<a href='#' id="+"'"+j+"'"+ "value="+"'"+j+"'"+" onclick='getByPage(this)'>"+j+"</a>";
						    	}
								if(page<totalPage){
									a += "<a href='#' value="+"'"+(parseInt(page)+1)+"'"+" onclick='getByPage(this)'>"+"<span class="+"'arrow-right'></span>"+"</a>";
					    		}
					    	}else if(totalPage>10){
					    		if(page>5&&page<=(parseInt(totalPage)-5)){
						    		for(var j=(parseInt(page)-5) ; j<(parseInt(page)+5) ; j++){
						    			a += "<a href='#' id="+"'"+j+"'"+ "value="+"'"+j+"'"+" onclick='getByPage(this)'>"+j+"</a>";
							    	}
						    		a += "<a href='#' value="+"'"+(parseInt(page)+1)+"'"+" onclick='getByPage(this)'>"+"<span class="+"'arrow-right'></span>"+"</a>";
					    		}else if(page>(parseInt(totalPage)-5)){
					    			for(var j=(parseInt(totalPage)-9); j<=totalPage ; j++){
					    				a += "<a href='#' id="+"'"+j+"'"+ "value="+"'"+j+"'"+" onclick='getByPage(this)'>"+j+"</a>";
							    	}
					    			if(page<totalPage){
					    				a += "<a href='#' value="+"'"+(parseInt(page)+1)+"'"+" onclick='getByPage(this)'>"+"<span class="+"'arrow-right'></span>"+"</a>"; 	   
						    		}	
					    		}else{
					    			for(var j=1 ; j<=10 ; j++){
					    				a += "<a href='#' id="+"'"+j+"'"+ "value="+"'"+j+"'"+" onclick='getByPage(this)'>"+j+"</a>";
							    	}
					    			a += "<a href='#' value='"+(parseInt(page)+1)+"' onclick='getByPage(this)'>"+"<span class="+"'arrow-right'></span>"+"</a>"; 	   
					    		}
					    	}
					    	a += "<a href='#' value='"+totalPage+"' onclick='getByPage(this)'>末</a>";
				    	}
				    	if(length<=1000&&length>=50&&page!=totalPage){
				    		a += "<div class='table-stats'>在 "+length+" 中打印"+ (50*(parseInt(page)-1)+1)+"到"+ 50*parseInt(page)+"</div>";
				    	}else if(length<=1000&&length>=50&&page==totalPage){
				    		a += "<div class='table-stats'>在 "+length+" 中打印"+ (50*(parseInt(page)-1)+1)+"到"+ length+"</div>";
				    	}else if(length>1000&&page!=totalPage){
				    		a += "<div class='table-stats'>在 1000+ 中打印"+ (50*(parseInt(page)-1)+1)+"到"+ 50*parseInt(page)+"</div>";
				    	}else if(length>1000&&page==totalPage){
				    		a += "<div class='table-stats'>在 1000+ 中打印"+ (50*(parseInt(page)-1)+1)+"到"+ length+"</div>";
				    	}else if(length<50&&length>0){
				    		a += "<div class='table-stats'>显示 已自动发现的 "+length+" 中的"+ length+"</div>";
				    	}
				    	
				    	jQuery("#pageNum").append(a);
				    	jQuery("#"+page).css("background-color","#768d99");
				    	
			        },	
			      
			        dataType: 'json'
				});
	   	    		
	    		}

			  	jQuery("#selectTriggers").change(function(){
			  		var objectId = jQuery("#selectTriggers").find("option:selected").attr('value');
			  		var groupId = jQuery("#selectGroup").find("option:selected").attr('value');
			  		var hostId = jQuery("#selectHostByGroup").find("option:selected").attr('value');
			  		if(objectId!=-1){
			  			getByPage(null,-1,-1,objectId);
			  		}else{
			  			getByPage(null,groupId,hostId,objectId);
			  		}
					});
			  	jQuery("#selectHostByGroup").change(function(){	
				  var hostId = jQuery(this).find("option:selected").attr('value');
				  var objectId = jQuery("#selectTriggers").find("option:selected").attr('value');
				  var groupId = jQuery("#selectGroup").find("option:selected").attr('value');
				 
				  if(hostId!=-1){
					  getByPage(null,-1,hostId,-1); 
					  jQuery.ajax({
								type: 'POST',
							 	url: '${ctx}/formview/getHostTriggers.json',
							 	data: {
							 		hostId : hostId,
							    },
							    success: function (data) {
							    	jQuery("#selectTriggers").empty();
							    	jQuery("#selectTriggers").append('<option selected="selected" value = "-1">所有触发器</option>');
							    	for (var i=0; i<data.length; i++){
						        		jQuery("#selectTriggers").append('<option value="' + data[i].triggerid + '">' + data[i].description + '</option>');
						        	}
						 		},
							 	error: function () {
							  		alert("请求失败！重新操作");
							 	},
							 	dataType: 'json'
								});	
						
				  }else{
					  getByPage(null,groupId,-1,-1);
					  if(groupId!=-1){
						  jQuery.ajax({
						        type: 'POST',
						        url: '${ctx}/alarmList/getTriggersByGroupId.json',
						        data: {groupId:groupId},
						        success: function (data) {
						        	jQuery("#selectTriggers").empty();
							    	jQuery("#selectTriggers").append('<option selected="selected" value = "-1">所有触发器</option>');
						        	for (var i=0; i<data.length; i++){
						        		jQuery("#selectTriggers").append('<option value="' + data[i].triggerid + '">' + data[i].description + '</option>');
						        	}
						        }, 
						        dataType: 'json'
						  });
					  }else{
						  jQuery.ajax({
						        type: 'POST',
						        url: '${ctx}/alarmList/getAllTriggers.json',
						        data: {hostId:hostId},
						        success: function (data) {
						        	jQuery("#selectTriggers").empty();
							    	jQuery("#selectTriggers").append('<option selected="selected" value = "-1">所有触发器</option>');
						        	for (var i=0; i<data.length; i++){
						        		jQuery("#selectTriggers").append('<option value="' + data[i].triggerid + '">' + data[i].description + '</option>');
						        	}
						        }, 
						        dataType: 'json'
						  });
					  }
				  }
			    });
			  	
			  	//选择群组按钮后显示告警列表以及主机、触发器选择框 
			    jQuery("#selectGroup").change(function(){
			    	var groupId = jQuery("#selectGroup").find("option:selected").attr('value');
			    	getByPage(null,groupId,-1,-1);
			    	var groupName = jQuery(this).find("option:selected").text();
			    	var groupId = jQuery(this).find("option:selected").attr('value');
					if (groupId != -1){
						jQuery.ajax({
							 type: 'POST',
							 url: '${ctx}/formview/hostByGroup.json',
							 data: {
							 	groupName : groupName,
							 	hostIp : ''
							 },
							 success: function (data) {
							    jQuery("#selectHostByGroup").empty();
							    jQuery("#selectHostByGroup").append('<option selected="selected" value = "-1">所有主机</option>');
							    for (var i=0; i<data.length; i++){
						        	jQuery("#selectHostByGroup").append('<option value="' + data[i].hostid + '">' + data[i].hostName + '</option>');
						        }
							    jQuery("#selectTriggers").empty();
						    	jQuery("#selectTriggers").append('<option selected="selected" value = "-1">所有触发器</option>');
						 	 },
							 error: function () {
							  	alert("请求失败！重新操作");
							 },
							 dataType: 'json'
							 });
						jQuery.ajax({
					        type: 'POST',
					        url: '${ctx}/alarmList/getTriggersByGroupId.json',
					        data: {
					        	groupId:groupId
					        },
					        success: function (data) {
					        	jQuery("#selectTriggers").empty();
						    	jQuery("#selectTriggers").append('<option selected="selected" value = "-1">所有触发器</option>');
					        	for (var i=0; i<data.length; i++){
					        		jQuery("#selectTriggers").append('<option value="' + data[i].triggerid + '">' + data[i].description + '</option>');
					        	}
					        }, 
					        dataType: 'json'
					        });
					}else{
						jQuery.ajax({
					        type: 'POST',
					        url: '${ctx}/formview/getHostGroups.json',
					        data: {},
					        success: function (data) {		        	
					        	jQuery("#selectHostByGroup").empty();
						    	jQuery("#selectHostByGroup").append('<option selected="selected" value = "-1">所有主机</option>');
					        	for (var i=0; i<data.length; i++){
					        		for(var j=0;j<data[i].hosts.length;j++){
					        			jQuery("#selectHostByGroup").append('<option value="' + data[i].hosts[j].hostid + '">' + data[i].hosts[j].name + '</option>');
					        		}
					        	}
					        }, 
					        dataType: 'json'
					     });
					     jQuery.ajax({
						        type: 'POST',
						        url: '${ctx}/alarmList/getAllTriggers.json',
						        data: {},
						        success: function (data) {
						        	jQuery("#selectTriggers").empty();
							    	jQuery("#selectTriggers").append('<option selected="selected" value = "-1">所有触发器</option>');
						        	for (var i=0; i<data.length; i++){
						        		jQuery("#selectTriggers").append('<option value="' + data[i].triggerid + '">' + data[i].description + '</option>');
						        	}
						        }, 
						        dataType: 'json'
						        });
					}
					
						
			    });
					//过滤告警信息
			    	jQuery("#confirm").click(function(e) {
			    		var groupId = jQuery("#selectGroup").find("option:selected").attr('value');
				  		var hostId = jQuery("#selectHostByGroup").find("option:selected").attr('value');
				    	var objectId = jQuery("#selectTriggers").find("option:selected").attr('value'); 
			    		getByPage(null,groupId,hostId,objectId);	
			    	});
					
					//重设过滤器参数
			    	jQuery("#reset").click(function(e) {
			    		jQuery("#alarmStatus option:first").prop("selected", 'selected');
			    		jQuery("#alarmLevel option:first").prop("selected", 'selected');
			    		jQuery("#alarmTime option:first").prop("selected", 'selected');
			    		var startInput=jQuery("input[name='minDate']");
		    			var endInput=jQuery("input[name='maxDate']");
		    			
		    			var inputTime=jQuery(".radio-segmented li.datepicker").find('input');
		    			var inputAttr=inputTime.attr('disabled');
		    			if(!inputAttr){
		    				inputTime.attr("disabled","disabled");
		    				startInput.val(" ");
		            		endInput.val(" ");
		    			}
			    	});
					
			    	//点击时间自定义
			    	jQuery("#alarmTime").change(function(){
			    		var inputTime=jQuery(".radio-segmented li.datepicker").find('input');
			    		var val=jQuery("#alarmTime").val();
			    		 if(val=='10'){
			    			 inputTime.removeAttr("disabled");
			    			/* if(jQuery(".radio-segmented li.datepicker").hasClass("isShow")){
				        		jQuery(".radio-segmented li.datepicker").removeClass("isShow");
				        		jQuery(".radio-segmented span.font").removeClass("isShow"); */
				        	/* }else{ */
				        		/* jQuery(".radio-segmented li.datepicker").addClass("isShow");
				        		jQuery(".radio-segmented span.font").addClass("isShow"); */
				        	/* } */
			    		  }else{
			    			var startInput=jQuery("input[name='minDate']");
			    			var endInput=jQuery("input[name='maxDate']");
			    			var inputAttr=inputTime.attr('disabled');
			    			if(!inputAttr){
			    				inputTime.attr("disabled","disabled");
			    				startInput.val(" ");
			            		endInput.val(" ");
			    			}
			    				
			    		}
			    		
			    	})

			    	//处理告警时间下拉框信息  
			        function dealTimeInfo() {
			        	//var group = jQuery("#alarmTime").val();
						var interval = jQuery("#alarmTime").find("option:selected").attr('value');
						if(parseInt(interval) == 1) {
							interval = 24;
						} else if(parseInt(interval) == 2) {
							interval = 30;
						} else if(parseInt(interval) == 3) {
							interval = 6;
						} else if(parseInt(interval) == -1){
							interval = -1;
						}
						return interval;
			        }
			        
			        //处理告警状态下拉框信息 
			        function dealStatusInfo() {
			        	var status= jQuery("#alarmStatus").find("option:selected").attr('value');
			        	if(parseInt(status) == -1) {
			        		status = '-1';
			    		} else {
			    			status =  parseInt(status) - 1;
			    		}
			        	return status;
			        }
			        
			        //处理告警严重级别下拉框信息 
			        function dealPriorityInfo() {
			        	//var priority = jQuery("#alarmLevel :selected").val();
			        	var priority= jQuery("#alarmLevel").find("option:selected").attr('value');
			        	if(parseInt(priority) == -1) {
			    			priority = '-1';
			    		} else {
			    			priority = parseInt(priority);
			    		}
			        	return priority;
			        }
			    </script>