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='pointretrait'}{/block}

{block name="check-resource"}admin.module{/block}
{block name="check-access"}view{/block}
{block name="check-module"}PointRetrait{/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 withdrawal places' d='pointretrait'}
                    </caption>

                    <thead>
                    <tr>
                        <th>{intl l="Place name" d='pointretrait'}</th>
                        <th class="col-md-1">{intl l="Active" d='pointretrait'}</th>
                        <th>{intl l="Address" d='pointretrait'}</th>
                        <th>{intl l="Withdrawal days" d='pointretrait'}</th>
                        <th>{intl l="Withdrawal price" d='pointretrait'}</th>
                        <th>{intl l="Minimum amount" d='pointretrait'}</th>
                        <th class="col-md-1">&nbsp;</th>
                    </tr>
                    </thead>

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

                    <tbody>
                        {loop name="places" type="pdr_places"}
                        <tr>
                            <td><a href="{url path="/admin/module/PointRetrait/edit?place_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>{$ADDRESS1}<br>{$ZIPCODE} {$CITY}{if $LATITUDE eq '' or $LONGITUDE eq ''}<img src="{image file='assets/img/pin.svg' source='PointRetrait'}" title="Pas de coordonnées pour ce point de retrait" alt="Pas de coordonnées" class="pin-pdr" />{/if}</td>
                            <td>{$DELIVERY_DAYS}{if $DELIVERY_DAYS eq ''}<i>{intl l="There is no schedule for this place" d='pointretrait'}</i>{/if}</td>
                            <td>{$PRICE} €</td>
                            <td>{$MINIMUM_AMOUNT} €</td>
                            <td class="actions">
                                <div class="btn-group" role="group">
                                    <a class="btn btn-info btn-responsive" title="{intl l='Edit this place'}"  href="{url path="/admin/module/PointRetrait/edit?place_id=$ID"}">
                                        <i class="glyphicon glyphicon-edit"></i>
                                    </a>
                                    <a class="btn btn-danger btn-responsive place-delete" title="{intl l='Delete this place'}" data-target="#place-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="pdr.place.create"}
        {capture "place_create"}
        {include file="form/place-create.html" form_name="pdr.place.create"}
        {/capture}

        {include file="includes/generic-create-dialog.html"
                dialog_id       = "place-create-modal"
                dialog_title    = {intl l="Create a new place" d="pointretrait"}
                dialog_body     = {$smarty.capture.place_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 "place_delete"}
        {intl l="Do you really want to remove this place ?" d="pointretrait"}
        <input type="hidden" name="attr-place-id" id="attr-place-id" value="999"/>
        <input type="hidden" name="success_url" value="{url path='/admin/module/PointRetrait'}"/>
    {/capture}

    {include file="includes/generic-confirm-dialog.html"
            dialog_id       = "place-delete"
            dialog_title    = {intl l="Delete a place" d="pointretrait"}
            dialog_message  = {$smarty.capture.place_delete nofilter}
            dialog_ok_label     = {intl l="Delete"}
            dialog_cancel_label = {intl l="Cancel"}
            form_action         = {token_url path='/admin/module/PointRetrait/delete'}
    }

{/block}

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

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