{% set statusStructure = databox.getStatusStructure() %}
{% set databox_id = databox.get_sbas_id() %}

<h1>
    {{ 'phraseanet::status bit' | trans }}
</h1>

<table class="table table-striped table-condensed">
    <thead>
        <th style="width:30px;">{{ 'status:: numero de bit' | trans }}</th>
        <th style="width:60px;" colspan='2'></th>
        <th>{{ 'status:: nom' | trans }}</th>
        <th>{{ 'status:: cherchable par tous' | trans }}</th>
        <th>{{ 'status:: Affichable pour tous' | trans }}</th>
    </thead>
    <tbody>
        {% for bit in range(4, 31) %}
            <tr>
                <td>
                    {{ bit }}
                </td>
                {% if statusStructure.hasStatus(bit) %}
                    <td>
                        <a target="right" href="{{ path('database_display_statusbit_form', { 'databox_id' : databox_id, 'bit' : bit }) }}" class="ajax">
                            <img class="editer" src="/assets/common/images/icons/edit_0.gif" />
                        </a>
                    </td>
                    <td>
                        <form method="post" action="{{ path('admin_statusbit_delete', { 'databox_id' : databox_id, 'bit' : bit }) }}">
                            <img class="deleter submiter" src="/assets/common/images/icons/delete_0.gif" />
                        </form>
                    </td>
                {% else %}
                    <td colspan="2">
                        <a target="right" href="{{ path('database_display_statusbit_form', { 'databox_id' : databox_id, 'bit' : bit }) }}" class="ajax">
                            <img class="adder" src="/assets/common/images/icons/light_new.gif" />
                        </a>
                    </td>
                {% endif %}

                {% if statusStructure.hasStatus(bit) %}
                    {% set statusbit = statusStructure.getStatus(bit) %}
                    <td>
                        {% if statusbit['img_off'] %}
                            <img class="status-img" title='{{ statusbit['labels_off_i18n'][app['locale']] }}' src='{{ statusbit['img_off'] }}' />
                        {% endif %}
                        {{ statusbit['labels_off_i18n'][app['locale']] }}
                        /
                        {% if statusbit['img_on'] %}
                            <img class="status-img" title='{{ statusbit['labels_on_i18n'][app['locale']] }}' src='{{ statusbit['img_on'] }}' />
                        {% endif %}
                        {{ statusbit['labels_on_i18n'][app['locale']] }}
                    </td>
                    <td>{{ statusbit['searchable'] is defined and statusbit['searchable'] == '1' ? 'oui'| trans : 'non'| trans }}</td>
                    <td>{{ statusbit['printable'] is defined and statusbit['printable'] == '1' ? 'oui'| trans : 'non'| trans }}</td>
                {% else %}
                    <td></td>
                    <td></td>
                    <td></td>
                {% endif %}
            </tr>
        {% endfor %}
    </tbody>
</table>

<script type="text/javascript">
    $(document).ready(function(){
        $(".submiter").click(function(){
            var $this = $(this);
            var form = $this.closest('form');

            $.ajax({
                dataType: 'JSON',
                type: form.attr('method'),
                url: form.attr('action'),
                datas: {},
                success: function(data){
                    if (data.success) {
                        $(".treeview li.selected a").trigger("click");
                    } else {
                        alert('{{ 'An error occurred' | trans }}');
                    }
                }
            });
        });
    });
</script>
