{{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>SMTP服务器地址</label>
							<input type="text" class="form-control" name="smtp_host" value="" maxlength="50" />
						</div>
						<div class="form-group">
							<label>服务端口</label>
							<input type="text" class="form-control" name="smtp_port" value="" maxlength="5" />
						</div>
						<div class="form-group">
							<label>用户</label>
							<input type="text" class="form-control" name="smtp_user" value="" maxlength="40" />
						</div>
						<div class="form-group">
							<label>密码</label>
							<input type="text" class="form-control" name="smtp_pwd" value="" maxlength="20" />
						</div>
						<div class="form-group">
							<label>署名</label>
							<input type="text" class="form-control" name="smtp_sender" value="" maxlength="20" />
						</div>
						<button type="submit" class="btn btn-sm btn-primary">保存</button>
						<a class="btn btn-sm btn-default" href="/debug/sendmail">测试邮件发送</a>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>

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

$(function(){
	var form = $('#mainform').get(0);
	function load_config() {
		$.get('/syscfg/warn_get', {}, function(resp){
			if (resp && resp.errno == 0) {
				if (resp.data.smtp_host) {
					form.smtp_host.value = resp.data.smtp_host;
				}
				if (resp.data.smtp_port) {
					form.smtp_port.value = resp.data.smtp_port;
				}
				if (resp.data.smtp_user) {
					form.smtp_user.value = resp.data.smtp_user;
				}
				if (resp.data.smtp_pwd) {
					form.smtp_pwd.value = resp.data.smtp_pwd;
				}
				if (resp.data.smtp_sender) {
					form.smtp_sender.value = resp.data.smtp_sender;
				}
			}
		}, 'json');
	}
	$(form).submit(function(){
		if (this.smtp_host.value == '') {
			$.alert('请填写服务地址！');
		} else if (this.smtp_port.value == '') {
			$.alert('请填写服务端口！');
		} else if (this.smtp_user.value == '') {
			$.alert('请填写账号！');
		} else if (this.smtp_pwd.value == '') {
			$.alert('请填写密码！');
		} else if (this.smtp_sender.value == '') {
			$.alert('请填写署名！');
		} else {
			$.post('/syscfg/warn_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>