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

    {% include 'twig/common/header/include.twig' %}
    <script src="/dev/js/admin/webhook.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/lib/bootstrap-select/js/bootstrap-select.js" type="text/javascript" charset="utf-8"></script>
    <link href="/dev/lib/bootstrap-select/css/bootstrap-select.css" rel="stylesheet">


</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">
                <div class="row  ">
                    <div class="col-lg-12">
                        <div class="top-area">

                            <ul class="nav-links">
                                <li id="state-list"  class="state_li active" data-value="list">
                                    <a  title="Webhook列表" href="/admin/plugin/webhook/" ><span> Url列表 </span>
                                    </a>
                                </li>
                                <li id="state-log"  class="state_li" data-value="log">
                                    <a  title="执行日志" href="/admin/plugin/webhook/log" ><span> 执行日志 </span>
                                    </a>
                                </li>
                            </ul>
                            <div class="nav-controls">
                                <div class="btn-group" role="group">
                                    <a class="btn btn-new js-key-create"  id="btn-create_plugin">
                                        <i class="fa fa-plus"></i>
                                        创建Webhook
                                    </a>
                                </div>
                            </div>
                        </div>
                        <div class="content-list">
                            <div class="table-holder">
                                <table class="table">
                                    <thead>
                                    <tr>
                                        <th class="js-pipeline-info pipeline-info">名称</th>
                                        <th class="js-pipeline-stages pipeline-info">url</th>
                                        <th class="js-pipeline-stages pipeline-info">秘钥</th>
                                        <th class="js-pipeline-stages pipeline-info">描述</th>
                                        <th class="js-pipeline-stages pipeline-info">超时时间</th>
                                        <th class="js-pipeline-stages pipeline-info">状态</th>
                                        <th class="pipeline-info" >操作</th>
                                    </tr>
                                    </thead>
                                    <tbody id="list_render_id">


                                    </tbody>
                                </table>
                            </div>
                            <div class="gl-pagination" id="pagination">
                            </div>
                        </div>
                    </div>
                </div>

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

<div class="modal" id="modal-plugin">
    <form class="js-quick-submit js-upload-blob-form form-horizontal"
          id="form-plugin"
          action="/admin/plugin_manager/add"
          accept-charset="UTF-8"
          method="post">
        <input type="hidden" name="format" id="id_format" value="json">
        <input type="hidden" name="action" id="id_action" value="add">
        <input type="hidden" name="id" id="edit_id" value="">

        <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" id="modal-header-title">创建Webhook</h3>
                </div>
                <div class="modal-body min-height400" id="modal-body">

                    <div class="form-group">
                        <label class="control-label" for="id_name">名称:<span class="required"> *</span></label>
                        <div class="col-sm-2">
                            <div class="form-group">
                                <input type="text" class="form-control" name="name" id="id_name"  value="" />
                            </div>
                        </div>
                        <div class="col-sm-4">
                                <span id="tip_name"></span>
                        </div>

                    </div>
                    <div class="form-group">
                        <label class="control-label" for="id_url">URL:<span class="required"> *</span></label>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <input type="text" class="form-control" name="url" id="id_url"  value="" />
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label" for="id_description">触发事件:</label>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <select name="hook_events[]" id="id_hook_events" class="selectpicker" multiple data-actions-box="true">
                                    {% for key, events in hook_event_arr %}
                                        <optgroup label="<?=key?>">
                                            {% for event_key,event_name in events %}
                                                {% set selected = '' %}
                                                {% if event_key  in default_hook_event_arr %}
                                                    {% set selected = 'selected' %}
                                                {% endif %}
                                                <option  value="<?=event_key?>" <?=selected?> data-subtext="<?=event_key?>"><?=event_name?></option>
                                            {% endfor %}
                                        </optgroup>
                                    {% endfor %}
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label" for="id_secret_token">验证Token:<span class="required"> </span></label>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <input type="text" class="form-control" name="secret_token" id="id_secret_token"  value="" />
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label" for="id_timeout">超时时间:<span class="required"> </span></label>
                        <div class="col-sm-2">
                            <div class="form-group">
                                <input type="text" class="form-control" name="timeout" id="id_timeout"  value="" />
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label" for="id_description">描述:</label>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <textarea  class="form-control" name="description" id="id_description" ></textarea>
                            </div>
                        </div>
                    </div>

                </div>
                <div class="modal-footer footer-block row-content-block">
                    <button name="submit"
                            type="button"
                            class="btn btn-create js-key-modal-enter1"
                            id="btn-plugin_save"
                            title="">提 交</button>
                    <a class="btn btn-cancel" data-dismiss="modal" href="#">取消</a>
                </div>
            </div>
        </div>
    </form>
</div>


    </div>
</section>


<style>
    .qq-gallery.qq-uploader {
        position: relative;
        min-height: 140px;
        max-height: 320px;
        overflow-y: hidden;
        width: inherit;
        border-radius: 6px;
        border: 1px dashed #CCCCCC;
        background-color: #FAFAFA;
        padding: 20px;
    }
</style>

{% verbatim %}
<script type="text/html"  id="list_tpl">
    {{#webhooks}}
        <tr class="commit">
            <td>
                {{name}}
            </td>
            <td>
                {{url}}
            </td>
            <td>
                {{secret_token}}
            </td>
            <td>
                {{description}}
            </td>
            <td>
                {{timeout}}
            </td>
            <td>
            {{#if_eq enable '1'}}
                <span class="label  label-success">启用中</span>
             {{/if_eq}}
             {{#if_eq enable '0'}}
                <span class="label  label-danger">已停用</span>
             {{/if_eq}}
            </td>
            <td  >
                    <a class="list_for_edit btn btn-transparent  " href="#" data-value="{{id}}" style="padding: 6px 2px;">编辑 </a>

                    {{#if_eq enable '1'}}
                        <a class="list_for_disable btn btn-transparent  " href="#" data-value="{{id}}" style="padding: 6px 2px;color:blue">停用 </a>
                    {{/if_eq}}
                     {{#if_eq enable '0'}}
                        <a class="list_for_enable btn  btn-transparent " href="#" data-value="{{id}}" style="padding: 6px 2px;color: orange">启用</a>
                    {{/if_eq}}

                    <a class="list_for_delete btn btn-transparent  " href="#" data-value="{{id}}" style="padding: 6px 2px;color:red">删除 </a>


            </td>
        </tr>
    {{/webhooks}}

</script>{% endverbatim %}


<script src="/dev/js/handlebars.helper.js?v=<?=_version?>"></script>
<script type="text/javascript">

    var $plugin = null;
    var uploader = null;

    $(function() {
        $('.selectpicker').selectpicker('refresh');
        var options = {
            list_render_id:"list_render_id",
            list_tpl_id:"list_tpl",
            filter_form_id:"filter_form",
            filter_url:"/admin/plugin/<?=plugin_name?>/fetchAll",
            get_url:"/admin/plugin/<?=plugin_name?>/get",
            update_url:"/admin/plugin/<?=plugin_name?>/update",
            add_url:"/admin/plugin/<?=plugin_name?>/add",
            enable_url:"/admin/plugin/<?=plugin_name?>/enable",
            disable_url:"/admin/plugin/<?=plugin_name?>/disable",
            delete_url:"/admin/plugin/<?=plugin_name?>/delete",
            pagination_id:"pagination"

        }
        window.$plugin = new Webhook( options );
        window.$plugin.fetchWebhooks( );

        $("#modal-plugin").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'
                }
            ])
        });
    });

</script>
</body>
</html>