{% extends 'flask_docs/base.html' %}

{% block apps_menu %}
    <li class="dropdown">
        <a href="javascript:void(0);" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
           aria-expanded="false">Jump To<span class="caret"></span></a>
        <ul class="dropdown-menu">
            {% for key in endpoints %}
                <li><a href="#{{ key }}-group" style="cursor:pointer;">{{ key }}</a>
                </li>
            {% endfor %}
        </ul>
    </li>

    <li>
        <a href="javascript:void(0);" style="cursor:pointer;" data-toggle="modal" data-target="#tokenModal">Token</a>
    </li>
{% endblock %}

{% block jumbotron %}
    <div class="jumbotron">
        <h1>Flask API Docs</h1>
        <h3><a href="javascript:void(0);">Live API Endpoints</a>.</h3>
    </div>
{% endblock %}


{% block content %}

    <div id="loading"
         style="display:none;position: fixed;top: 0;right: 0;bottom: 0;left: 0;z-index: 1060;background-color:#18BC9C;opacity: 0.5; text-align: center;">
        <div style="margin-top: 20%;">
            <img src="{{ url_for('flask_docs.static', filename='images/loading.gif') }}" alt="正在加载中...">
        </div>
    </div>


    {% for key, endpoint in endpoints.items() %}
        <h1 id="{{ key }}-group"><a
                href="#{{ key }}-group">{{ key }}</a>
        </h1>

        <div class="panel-group" role="tablist">
            {% for k, end in endpoint.items() %}
                <div class="panel panel-default endpoint">
                    <div class="panel-heading" role="tab">
                        <div class="row">
                            <div class="col-md-12" onclick="showPanelBody(this)">
                                <h4 class="panel-title title" id="requestUrl"><i
                                        class="fa fa-link"></i>&nbsp;&nbsp;<span>{{ k }}</span>
                                </h4>
                            </div>
                        </div>
                    </div>
                    <div id="{{ end }}" class="panel-collapse collapse" role="tabpanel"
                         aria-expanded="true"
                         style="">
                        <div class="panel-body">
                            <p class="lead"></p>
                            {% if k == 'description' %}
                                <img src="{{ url_for('flask_docs.static', filename='images/info.png') }}"
                                           alt="" style="width:25px;height:25px;">
                                <p style="word-break: break-all; display: inline-block;">{{ end }}</p>
                            {% elif k == 'methods' %}
                                <div class="col-md-{{ end|length }}">
                                    <ul class="list-inline methods">
                                        {% for method in end %}
                                            <li class="method {{ method|lower }}" data-toggle="modal"
                                                data-target="#requestModal"
                                                data-params="{{ method }}"
                                            >{{ method }}</li>
                                        {% endfor %}
                                    </ul>
                                </div>
                            {% elif k in ['renders', 'parses'] %}
                                <div class="col-md-{{ end|length }}">
                                    <ul class="list-inline methods">
                                        {% for method in end %}
                                            <li class="{{ method|lower }}">{{ method }}</li>
                                        {% endfor %}
                                    </ul>
                                </div>
                            {% elif k == 'params' %}
                                <div class="col-md-{{ end|length }}">
                                    <ul class="list-inline methods">
                                        {% for end_k, method in end.items() %}
                                            <li class="{{ method|lower }}">{{ end_k }}:
                                                <button>{{ method }}</button>
                                            </li>
                                        {% endfor %}
                                    </ul>
                                </div>
                            {% else %}
                                <p style="word-break: break-all">{{ end }}</p>
{#                                <p>No more information.</p>#}
                            {% endif %}
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>
    {% endfor %}

    <!-- 右侧悬浮导航开始 -->
    <div class="right-summary">
        <ul>
            {% for key in endpoints %}
                <li><a href="#{{ key }}-group">{{ key }}</a></li>
            {% endfor %}
        </ul>
    </div>
    <!-- 右侧悬浮导航结束 -->
    {% if endpoints.items() %}

    {% elif not query %}
        <h2 class="text-center">There are currently no api endpoints to document.</h2>
    {% else %}
        <h2 class="text-center">No endpoints found for {{ query }}.</h2>
    {% endif %}

    <!-- getModal -->
    <div class="modal fade api-modal" id="requestModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog modal-lg" role="document" style="width: 80%;">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="titleMethod"></h4>
                </div>
                <div id="liveAPIEndpoints">
                    <form class="form-horizontal" id="requestForm">
                        <div class="modal-body">
                            <div class="row">
                                <div class="col-md-6 request">
                                    <div><h3>Request</h3>
                                        <div><h5 class="section-title">API
                                            Endpoint</h5>
                                            <div class="form-group">
                                                <label
                                                        for="Url Endpoint" class="col-sm-4 control-label">
                                                    <span
                                                    >Url</span></label>
                                                <div class="col-sm-8">
                                                    <input type="text" class="form-control input-sm" id="Endpoint"
                                                           placeholder="Url"
                                                           value="">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="text-center"><h5 class="section-title"
                                        >
                                            Method</h5>
                                            <div class="btn-group methods" id="requestMethod">
                                                <span class="btn btn-sm method get active"
                                                >GET</span>
                                            </div>
                                        </div>
                                        <div id="requestHeaders"><h5 class="section-title"
                                        >Headers</h5>
                                            <div class="form-group"><label
                                                    for="authorization" class="col-sm-4 control-label"
                                            ><span
                                            >authorization</span></label>
                                                <div class="col-sm-8"><input
                                                        class="form-control input-sm" id="authorization"
                                                        placeholder="Token 1234567890" value=""
                                                ></div>
                                            </div>
                                        </div>
                                        <noscript></noscript>
                                        <div id="requestParams">
                                            <h5 class="section-title">Params</h5>
                                            <div class="form-group">
                                                <label class="col-sm-4 control-label">
                                                    Field Name</label>
                                                <div class="col-sm-5">
                                                    <input type="text"
                                                           class="form-control input-sm"
                                                           placeholder="ie. email_address"
                                                           value=""
                                                    >
                                                </div>
                                                <div class="col-sm-3">
                                                    <span class="label label-info">str</span>
                                                    <span class="label label-primary label-required"
                                                          title="Required">R</span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6 response" id="response">
                                    <div><h3>Response</h3>
                                        <p class="lead text-center">Awaiting request...</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">
                                Close
                            </button>
                            <button type="button" class="btn btn-primary" onclick="sendRequest(this)">Send</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <!-- token modal -->
    <div class="modal fade api-modal in" id="tokenModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog modal-sm" role="document" style="width: 50%;">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">×</span></button>
                    <h4 class="modal-title" id="titleMethod">Authorization</h4>
                </div>
                <div id="liveAPIEndpoints">
                    <div class="text-center">
                        <h5 class="section-title">
                            Authorization <span class="label label-warning">Bearer</span>
                        </h5>
                        <div class="form-group">
                        <textarea id="localToken" cols="10" rows="5" class="form-control"
                                  style="width: 60%;margin: 0 auto;resize:none;"></textarea>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">
                            Close
                        </button>
                        <button type="button" class="btn btn-success" data-dismiss="modal" onclick="saveToken()">Save
                        </button>
                        <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="clearToken()">
                            Clear
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <a class="back-top-button">
        <img src="{{ url_for('flask_docs.static', filename='images/top.png') }}" alt="" style="width:25px;height:25px;">
    </a>
    <script src="{{ url_for('flask_docs.static', filename='js/jquery-3.1.1.min.js') }}"></script>
    <script src="{{ url_for('flask_docs.static', filename='js/bootstrap.min.js') }}"></script>
    <script src="{{ url_for('flask_docs.static', filename='js/main.min.js') }}"></script>
    <script src="{{ url_for('flask_docs.static', filename='js/main.js') }}"></script>
    <script>
        // 锚点
        $("a[href*=\\#]:not([href=\\#])").click(function () {
            if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
                var $target = $(decodeURI(this.hash));
                $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
                if ($target.length) {
                    var targetOffset = $target.offset().top;
                    $('html,body').animate({
                            scrollTop: targetOffset
                        },
                        500);
                    return false;
                }
            }
        });

        $("a.back-top-button").click(function () {
            $("html,body").animate({scrollTop: 0}, 500);
        });

    </script>
{% endblock %}
