<div class="panel panel-default">
    <div class="panel-body">
        <ul class="nav">
            <h5><strong><i class="glyphicon glyphicon-hand-down"></i> 邮件配置</strong></h5>
            <hr>
        </ul>
        <form class="form-horizontal" method="post" action="/configure/addEmailConfig">
            <div class="form-group">
                <label class="col-sm-2 control-label"><span class="text-danger"> * </span> smtp地址： </label>
                <div class="col-sm-4">
                    <input value="{{.email.email_host}}" type="text" name="email_host" class="form-control" placeholder="请填写smtp地址" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label"><span class="text-danger"> * </span> smtp端口： </label>
                <div class="col-sm-4">
                    <input value="{{.email.email_port}}" type="text" name="email_port" class="form-control" placeholder="请填写smtp端口" required>
                </div>
            </div>
			<div class="form-group">
                <label class="col-sm-2 control-label"><span class="text-danger"> * </span> 用户名： </label>
                <div class="col-sm-4">
                    <input value="{{.email.email_username}}" type="text" name="email_username" class="form-control time" placeholder="请填写邮箱用户名" required>
                </div>
            </div>
			<div class="form-group">
                <label class="col-sm-2 control-label"><span class="text-danger"> * </span> 密码： </label>
                <div class="col-sm-4">
                    <input value="{{.email.email_password}}" type="text" name="email_password" class="form-control" placeholder="请填写邮箱密码" required>
                </div>
            </div>
			<div class="form-group">
                <label class="col-sm-2 control-label"> 发件人： </label>
                <div class="col-sm-4">
                    <input value="{{.email.email_from}}" type="text" name="email_from" class="form-control" placeholder="请填写发件人邮箱" required>
                </div>
                <div class="col-sm-4">
                    <span class="text-danger"> * 默认使用账号</span>
                </div>
            </div>
			<div class="form-group">
                <label class="col-sm-2 control-label"><span class="text-danger"> * </span> 使用SSL： </label>
                <div class="col-sm-4">
                    <label class="radio-inline">
                        <input type="radio" name="email_is_ssl" value="0" checked> 是
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="email_is_ssl" value="1"> 否
                    </label>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="button" onclick="email.sendTestEmail()" class="btn btn-primary">测试发送</button>
                </div>
            </div><br>
            <ul class="nav">
                <h5><strong>发版抄送列表</strong></h5>
                <hr>
            </ul>
            <div class="form-group">
                <label class="col-sm-2 control-label"><span class="text-danger"> * </span> 邮件抄送人列表： </label>
                <div class="col-sm-4">
                    <textarea name="email_cc_list" class="form-control" rows="6">{{.email.email_cc_list}}</textarea>
                </div>
                <div class="col-sm-4">
                    <span class="text-danger"> * 每行一个</span>
                </div>
            </div>
			<div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="button" onclick="Form.ajaxSubmit(this.form, false)" class="btn btn-primary">保存</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
	$(function(){
		{{if(.email.email_is_ssl)}}
        var isSsl = "{{.email.email_is_ssl}}"
		$('input[name=email_is_ssl]').each(function(){
            if($(this).val() == isSsl) {
                $(this).prop('checked', true)
            }
        })
		{{end}}
	})
	
	var sendEmailLock = false
	var email = {
		sendTestEmail: function (){
			if (sendEmailLock) {
				return 
			}
			var index = layer.load(1, {time: 10*1000})
			sendEmailLock = true
			$.ajax({
		        type: "POST",
		        cache: false,
		        url: "/configure/sendTestEmail",
		        data:$("form").serialize(),
		        dataType: 'json',
		        success: function (response) {
		            if(response.code == 0) {
						Common.errorBox("#failedBox", response.message)
					} else {
						Common.successBox("#failedBox", response.message)
					}
					sendEmailLock = false
		        },
				error: function(){
					Common.errorBox("#failedBox", "ajax请求出错")
				},
				complete: function() {
                    layer.close(index);
                },
		    });
		}
	}
</script>
