{% if type == 0 %}
    {% set text = '标签' %}
{% else %}
    {% set text = '特色' %}
{% endif %}
<h2>添加{{ text }}</h2>
<label for="feature">{{ text }}：</label>
<input id="feature" type="text">
<input type="submit" id="submit" class="btn btn-info">
<h2>{{ text }}列表</h2>
<table class="table">
    <thead>
    </thead>
    <tbody>
    {% for item in result %}
    {% if loop.index0%4 == 0%}
    <tr>
    {% endif %}
        <td>{{ item.name }}</td>
    {% if loop.index0%4 == 3%}
    </tr>
    {% endif %}
    {% endfor %}
    </tbody>
</table>
<script>
    (function ($) {
        $(document).ready(function () {
            $('#submit').click(function () {
                var name = $('#feature').val();
                if (name.trim() != '') {
                    $.ajax({
                        type: 'POST',
                        url: '{{ url }}/wp-admin/admin-ajax.php/',
                        data: 'action=add_feature&name=' + name + '&type={{ type }}',
                        success: function (data) {
                            switch (data.code) {
                                case 2000:
                                    window.location.href = '{{ request_url }}';
                                    break;
                                case 2001:
                                    alert('不能重复添加{{ text }}');
                                    break;
                                default:
                                    break;
                            }
                        }
                    });
                } else {
                    alert('请输入{{ text }}');
                }
            });
        });
    })(jQuery);
</script>