<!DOCTYPE html>
<html class="" lang="en">
<head  >

    {% include 'twig/common/header/include.twig' %}
    <script src="/dev/js/admin/setting2.js?v=<?=_version?>" type="text/javascript" charset="utf-8"></script>
    <script src="/dev/lib/handlebars-v4.0.10.js" type="text/javascript" charset="utf-8"></script>
    <script src="/dev/js/handlebars.helper.js?v=<?=_version?>" type="text/javascript" charset="utf-8"></script>

</head>
<body class="" data-group="" data-page="projects:issues:index" data-project="xphp">
{% include 'twig/common/body/script.twig' %}

<section class="has-sidebar page-layout max-sidebar">
    {% include 'twig/common/body/page-left.twig' %}

    <div class="page-layout page-content-body system-page">
        {% include 'twig/common/body/header-content.twig' %}

        <script>
            var findFileURL = "";
        </script>
        <div class="page-with-sidebar">
            {% include 'twig/admin/common-page-nav-admin.twig' %}


            <div class="content-wrapper page-with-layout-nav page-with-sub-nav">
                <div class="alert-wrapper">

                    <div class="flash-container flash-container-page">
                    </div>

                </div>
                <div class="container-fluid ">

                    <div class="content" id="content-body">

                        {% include 'twig/admin/common_system_left_nav.twig' %}
                        <div class="row has-side-margin-left">
                            <div class="col-lg-12">
                                <div class="top-area">
                                    <ul class="nav-links">
                                        <li class="active">
                                            <a href="#">SMTP 配置</a>
                                        </li>
                                        <li>
                                            <span class="hint">SMTP 配置用于发送邮件</span>
                                        </li>
                                    </ul>
                                    <div class="nav-controls">
                                        <div class="btn-group" role="group">
                                            <a class="hidden-xs hidden-sm btn btn-grouped  " id="btn-mail_test">
                                                发送测试
                                            </a>
                                            <a class="hidden-xs hidden-sm btn btn-grouped btn-setting_edit"
                                               data-target="#modal-setting"
                                               data-toggle="modal" href="#modal-setting">
                                                <i class="fa fa-edit"></i> 修改
                                            </a>
                                        </div>
                                    </div>
                                </div>
                                <div class="content-list">
                                    <div class="table-holder">
                                        <table class="table ci-table">
                                            <tbody id="tbody_id">
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>


                    <div class="modal" id="modal-mail_test">
                        <form class="js-quick-submit js-upload-blob-form form-horizontal"
                              action="/admin/system/mail_test"
                              accept-charset="UTF-8"
                              method="post">
                            <div class="modal-dialog">
                                <div class="modal-content  modal-middle">
                                    <div class="modal-header">
                                        <a class="close js-key-modal-close1" data-dismiss="modal" href="#">×</a>
                                        <h3 class="modal-header-title">Test</h3>
                                    </div>

                                    <div class="modal-body">
                                        <div  >
                                            <div class="form-group">
                                                <label for="inputEmail3" class="col-sm-2 control-label">收件人:</label>
                                                <div class="col-sm-10">
                                                    <input type="text" class="form-control" name="params[recipients]" id="id_max_project_name" value="">
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label for="inputEmail3" class="col-sm-2 control-label">标题</label>
                                                <div class="col-sm-10">
                                                    <input type="text"  class="form-control" name="params[title]" id="id_title" value="Test Message From Masterlab">
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label for="inputEmail3" class="col-sm-2 control-label">邮件格式:</label>
                                                <div class="col-sm-10">

                                                    <label style=" font-weight: 200;  ">
                                                        <input type="radio" value="text" checked="checked" name="params[content_type]" id="test_type_text">
                                                        text
                                                    </label>
                                                    <label style=" font-weight: 200;  ">
                                                        <input type="radio" value="html"  name="params[content_type]" id="test_type_html">
                                                        html
                                                    </label>

                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label for="inputEmail3" class="col-sm-2 control-label">内容</label>
                                                <div class="col-sm-10">
                                            <textarea name="params[content]" id="test_content" rows="5" class="form-control" rows="3" >This is a test message from Masterlab.
Server: Masterlab邮件
SMTP Port: 25
Description:
From:
Host User Name:  </textarea>
                                                </div>
                                            </div>

                                            <hr>
                                            <div class="form-group">
                                                <label for="inputEmail3" class="col-sm-2 control-label">返回日志：</label>
                                                <div class="col-sm-10">
                                                    <textarea class="form-control"  rows="6" name="resp_log" id="resp_log" style="font-size: 10px"></textarea>

                                                </div>
                                            </div>
                                        </div>

                                        <div class="modal-footer form-actions">
                                            <button name="btn-submit-test" type="button" class="btn btn-create btn-send_test js-key-modal-enter1" id="submit-test">发送测试</button>
                                            <a class="btn btn-cancel" data-dismiss="modal" href="#">取消</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>

                </div>
            </div>
        </div>

    </div>
</section>

{% include 'twig/admin/common-setting-content.twig' %}
{% include 'twig/admin/common-setting-form.twig' %}
<script type="text/javascript">

    var setting_module = 'mail';
    var options = {
        fetch_url:"/admin/system/setting_fetch",
        list_render_id:"tbody_id",
        list_tpl_id:"setting_content_tpl",
        form_tpl:"setting_form_tpl",
        form_render_id:"form_id",
        update_url:"/admin/system/basic_setting_update",
    };
    var $setting = null;
    $(function() {
        $setting = new SettingV2(setting_module,  options);
    });

    function show_mail_test(){
        $('#modal-mail_test').modal();
    }

    $(".btn-send_test").click(function(){

        var method = 'post';
        var url = '';

        method =  $(this).closest('form').attr('method') ;
        url =  $(this).closest('form').attr('action') ;
        var params = $(this).closest('form').serialize();
        $.ajax({
            type: method,
            dataType: "json",
            async: true,
            url: url,
            data: params ,
            success: function (resp) {
                auth_check(resp);
                notify_success( "提交数据成功,后台服务发送中" );
                $('#resp_log').text( resp.data.err+"\n"+resp.data.verbose );
            },
            error: function (resp) {
                notify_error("请求数据错误" + resp);
            }
        });

    });

    $(function() {

        $('#btn-mail_test').on('click',function () {
            show_mail_test();
        })

        $('#modal-mail_test').on('show.bs.modal', function (e) {
            keyMaster.addKeys([
                {
                    key: ['command+enter', 'ctrl+enter'],
                    'trigger-element': '.js-key-modal-enter1',
                    trigger: 'click'
                },
                {
                    key: 'esc',
                    'trigger-element': '.js-key-modal-close1',
                    trigger: 'click'
                }
            ])
        })

        $('#modal-mail_test').on('hidden.bs.modal', function (e) {
            keyMaster.delKeys([['command+enter', 'ctrl+enter'], 'esc'])
        })
        $('#modal-edit_datetime').on('hidden.bs.modal', function (e) {
            keyMaster.delKeys([['command+enter', 'ctrl+enter'], 'esc'])
        })

    });

</script>


</body>
</html>
