{% extends "portal/layout.html" %}
{% block content %}

    <div class="form-inline" role="form">
        <div class="form-group">
            <input type="text" value="{{ data.query }}" class="form-control" id="query"
                   placeholder="search name" onkeydown="if(event.keyCode==13)query_template()">
        </div>
        <button type="button" onclick="query_template();" class="btn btn-default">
            <span class="glyphicon glyphicon-search"></span>
        </button>
        <input type="checkbox" name="mine" id="mine" {% if data.mine == '1' %}checked="checked"{% endif %}>
        <span>mine</span>

        <div class="pull-right">
            <input type="text" placeholder="input name to create" class="form-control" id="tpl_name"
                   onkeydown="if(event.keyCode==13)create_template()">
            <button onclick="create_template()" class="btn btn-default">
                <span class="glyphicon glyphicon-plus"></span>
            </button>
        </div>
    </div>

    <table class="table table-hover table-bordered table-striped" style="margin-bottom: 0px; margin-top: 10px;">
        <thead>
        <tr>
            <th>name</th>
            <th>parent</th>
            <th>creator</th>
            <th>operation</th>
        </tr>
        </thead>
        <tbody>
        {% for v in data.vs %}
            <tr>
                <td><a href="{{ url_for('template_view_get', tpl_id=v.id) }}">{{ v.tpl_name }}</a></td>
                <td>{% if v.parent %}<a href="{{ url_for('template_view_get', tpl_id=v.parent.id) }}">{{ v.parent.tpl_name }}</a>{% endif %}</td>
                <td>
                    <a href="/user/about/{{ v.create_user }}">{{ v.create_user }}</a>
                </td>
                <td>
                    <a data-toggle="tooltip" data-placement="top" title="克隆一份该模板" href="javascript:fork_template('{{ v.id }}');" style="text-decoration: none;">
                        <span class="glyphicon glyphicon-duplicate orange"></span>
                    </a>
                    {% if v.writable(g.user) %}
                        <span class="cut-line">¦</span>
                        <a data-toggle="tooltip" data-placement="top" title="查看绑定了哪些HostGroup" href="{{ url_for('template_binds_get', tpl_id=v.id) }}"
                           style="text-decoration: none;">
                            <span class="glyphicon glyphicon-list-alt orange"></span>
                        </a>
                        <span class="cut-line">¦</span>
                        <a data-toggle="tooltip" data-placement="top" title="修改" href="{{ url_for('template_update_get', tpl_id=v.id) }}"
                           style="text-decoration: none;">
                            <span class="glyphicon glyphicon-edit orange"></span>
                        </a>
                        <span class="cut-line">¦</span>
                        <a data-toggle="tooltip" data-placement="top" title="删除" href="javascript:delete_template('{{ v.id }}');"
                           style="text-decoration: none;">
                            <span class="glyphicon glyphicon-trash orange"></span>
                        </a>
                    {% endif %}
                </td>
            </tr>
        {% else %}
            <tr>
                <td colspan="4">no records</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
    <div class="pull-right" style="margin-top: 20px;">
        <a href="{{ url_for('template_help_get') }}" class="btn btn-default">
            <span class="glyphicon glyphicon-question-sign"></span>
        </a>
    </div>
    {% import "portal/blocks.html" as blocks %}
    {{ blocks.pager('/portal/template?q='+data.query+'&mine='+data.mine, data.total, data.limit, data.page) }}

    <script>
        $(function () {
            $("#query").focus();
            $("#mine").click(query_template);
            $('[data-toggle="tooltip"]').tooltip();
        });
    </script>

{% endblock %}
