{extends file="admin-layout.tpl"}

{block name="no-return-functions"}
    {$admin_current_location = 'module'}
{/block}

{block name="page-title"}{intl l='Title of config view' d='livraisonparsecteurs'}{/block}

{block name="check-resource"}admin.module{/block}
{block name="check-access"}view{/block}
{block name="check-module"}LivraisonParSecteurs{/block}

{block name="main-content"}
    <div id="wrapper" class="container">

        {if $general_error}
        <div class="alert alert-danger">
            {$general_error}
        </div>
        {/if}

        <div class="general-block-decorator">
            <div class="table-responsive">
                <table class="table table-striped table-condensed" id="areas-table">
                    <caption class="clearfix">
                        {intl l='My areas' d='livraisonparsecteurs'}
                    </caption>

                    <thead>
                    <tr>
                        <th>{intl l="Area name" d='livraisonparsecteurs'}</th>
                        <th>{intl l="Active" d='livraisonparsecteurs'}</th>
                        <th>{intl l="Delivery price" d='livraisonparsecteurs'}</th>
                        <th>{intl l="Delivery days" d='livraisonparsecteurs'}</th>
                        <th></th>
                    </tr>
                    </thead>

                    <tbody>
                        {loop name="areas" type="lps_area" backend_context="yes"}
                        <tr>
                            <td><a href="{url path='/admin/module/LivraisonParSecteurs/edit' area_id=$ID}">{$TITLE}</a></td>
                            <td>
                                <div class="make-switch switch-small toggle-visible" data-id="{$ID}" data-on="success"
                                     data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>"
                                     data-off-label="<i class='glyphicon glyphicon-remove'></i>">
                                    <input type="checkbox" class="link" {if $ACTIVE == 1}checked="checked"{/if}>
                                </div>
                            </td>
                            <td>{$PRICE} €</td>
                            <td>{$DELIVERY_DAYS}</td>
                            <td class="actions">
                                <div class="btn-group" role="group">
                                    <a class="btn btn-info btn-responsive" title="{intl l='Edit this area'}"  href="{url path='/admin/module/LivraisonParSecteurs/edit' area_id=$ID}">
                                        <i class="glyphicon glyphicon-edit"></i>
                                    </a>
                                    <a class="btn btn-danger btn-responsive area-delete" title="{intl l='Delete this area'}" data-target="#area-delete" data-toggle="modal" data-id="{$ID}">
                                        <i class="glyphicon glyphicon-trash"></i>
                                    </a>
                                </div>
                            </td>
                        </tr>
                        {/loop}
                    </tbody>

                </table>
            </div>
        </div>
    </div>
{/block}

{block name="javascript-initialization"}
{javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'}
<script src="{$asset_url}"></script>
<script>
    $(function() {
        $('a.area-delete').click(function(ev) {
            $('#area_delete_id').val($(this).data('id'));
        });

        $(".toggle-visible").on('switch-change', function (event, data) {
            $.ajax({
                method: "POST",
                url: "{url path='admin/module/LivraisonParSecteurs/toggle-online/'}" + $(this).data('id')
            });
        });
    });
</script>
{/javascripts}
{/block}
