mais{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 class="col-md-1">{intl l="Active" d='livraisonparsecteurs'}</th>
                        <th>{intl l="Delivery price" d='livraisonparsecteurs'}</th>
                        <th>{intl l="Minimum amount" d='livraisonparsecteurs'}</th>
                        <th>{intl l="Delivery days" d='livraisonparsecteurs'}</th>
                        <th>{intl l="Delivered cities count" d='livraisonparsecteurs'}</th>
                        <th class="col-md-1">&nbsp;</th>
                    </tr>
                    </thead>

                    <caption class="clearfix">
                        {loop name="auth-create" type="auth" role="ADMIN" resource="admin.lps.general" access="CREATE" module="LivraisonParSecteurs"}
                        <div class="pull-right">
                            <a class="btn btn-default btn-primary"
                               title="{intl l='Add a new area' d='livraisonparsecteurs'}"
                               data-target="#area-create-modal" data-toggle="modal">
                                <i class="glyphicon glyphicon-plus-sign"></i>
                            </a>
                        </div>
                        {/loop}
                    </caption>

                    <tbody>
                        {loop name="areas" type="lps_area"}
                        <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>{$MINIMUM_AMOUNT} €</td>
                            <td>{$DELIVERY_DAYS}{if $DELIVERY_DAYS eq ''}<i>{intl l="There is no schedule for this area" d="livraisonparsecteurs"}</i>{/if}</td>
                            <td>{$COVERED_CITIES_NUMBER}</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>

    {* CREATE Modal *}
    {form name="lps-area-create"}
        {capture "area_create"}
            {include file="form/area-create.html" form_name="lps-area-create"}
        {/capture}

        {include file="includes/generic-create-dialog.html"

        dialog_id       = "area-create-modal"
        dialog_title    = {intl l="Create a new area" d="livraisonparsecteurs"}
        dialog_body     = {$smarty.capture.area_create nofilter}

        dialog_ok_label     = {intl l="Create"}
        dialog_cancel_label = {intl l="Cancel"}

        form_action        = {$current_url}
        form_enctype       = {form_enctype form=$form}
        }
    {/form}


    {* DELETE modal *}
    {capture "area_delete"}
        {intl l="Do you really want to remove this area ?" d="livraisonparsecteurs"}
        <input type="hidden" name="attr-area-id" id="attr-area-id" value="999"/>
        <input type="hidden" name="success_url" value="{url path='/admin/module/LivraisonParSecteurs'}"/>
    {/capture}

    {include file="includes/generic-confirm-dialog.html"
            dialog_id       = "area-delete"
            dialog_title    = {intl l="Delete an area" d="livraisonparsecteurs"}
            dialog_message  = {$smarty.capture.area_delete nofilter}
            dialog_ok_label     = {intl l="Delete"}
            dialog_cancel_label = {intl l="Cancel"}
            form_action         = {token_url path='/admin/module/LivraisonParSecteurs/delete'}
    }

{/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) {
            $('#attr-area-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}
