{{template "header.tmpl" .}}
</head>
<body>
{{template "navbar.tmpl" .}}

<div class="container-fluid">
	<h4 class="text-center">其它配置</h4>
	<hr />
	<div class="row">
		<div class="col-md-4 col-md-offset-4">
			<div class="pannel">
				<div class="pannel_body">
					<form id="mainform">
						<div class="form-group">
							<label>Redis状态检查间隔时长</label>
							<input type="text" class="form-control" name="monitor_loop_interval" value="60" maxlength="10" />
						</div>
						<div class="form-group">
							<label>报警邮件发送间隔时长</label>
							<input type="text" class="form-control" name="monitor_mail_interval" value="300" maxlength="10" />
						</div>
						<div class="form-group">
							<label>日志保留天数</label>
							<input type="text" class="form-control" name="log_kept_days" value="30" maxlength="10" />
						</div>
						<button type="submit" class="btn btn-sm btn-primary">保存</button>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
var $SESS = {{.Sess}};

$(function(){
	var form = $('#mainform').get(0);
	function load_config() {
		$.get('/syscfg/misc_get', {}, function(resp){
			if (resp && resp.errno == 0) {
				if (resp.data.monitor_loop_interval) {
					form.monitor_loop_interval.value = resp.data.monitor_loop_interval;
				}
				if (resp.data.monitor_mail_interval) {
					form.monitor_mail_interval.value = resp.data.monitor_mail_interval;
				}
				if (resp.data.log_kept_days) {
					form.log_kept_days.value = resp.data.log_kept_days;
				}
			}
		}, 'json');
	}
	$(form).submit(function(){
		if (this.monitor_loop_interval.value == '') {
			$.alert('请填写Redis状态检查间隔时长！');
		} else if (this.monitor_mail_interval.value == '') {
			$.alert('请填写报警邮件发送间隔时长！');
		} else if (this.log_kept_days.value == '') {
			$.alert('请填写日志保留天数！');
		} else {
			$.post('/syscfg/misc_set', $(this).serialize(), function(resp){
				if (resp && resp.errno == 0) {
					$.alert('已更新！');
				} else {
					$.alert(resp.error ? resp.error : '操作失败！');
				}
			}, 'json');
		}
		return false;
	});
	load_config();
});
</script>
</body>
</html>