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

{block name="page-title"}{intl l='Thelia Shipping configuration'}{/block}

{block name="check-resource"}admin.configuration.shipping-configuration{/block}
{block name="check-access"}view{/block}

{block name="main-content"}
<div class="shipping-configurations">

    <div id="wrapper" class="container">

        <ul class="breadcrumb">
            <li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
            <li><a href="{url path='/admin/configuration'}">{intl l="Configuration"}</a></li>
            <li><a href="{url path='/admin/configuration/shipping-configuration'}">{intl l="Shipping configuration"}</a></li>
        </ul>

        {module_include location='shipping_configuration_top'}

        <div class="row">
            <div class="col-md-12">
                <div class="general-block-decorator">
                    <div class="table-responsive">
                        <table class="table table-striped table-condensed table-left-aligned">
                            <caption class="clearfix">
                                {intl l='Thelia Shipping configuration'}
                                {loop type="auth" name="can_create" role="ADMIN" resource="admin.configuration.shipping-configuration" access="CREATE"}
                                <a class="btn btn-default btn-primary pull-right" title="{intl l='Add a new shipping configuration'}" href="#creation_dialog" data-toggle="modal">
                                    <span class="glyphicon glyphicon-plus-sign"></span>
                                </a>
                                {/loop}                        
                            </caption>
                            <thead>
    	                        <tr>	                           
                                   <th>{intl l="Description"}</th>

                                   {module_include location='shipping_configuration_table_header'}

                                   <th>{intl l="Actions"}</th>
    	                        </tr>
                            </thead>

                            <tbody>
                                {loop name="area-list" type="area" backend_context="1"}
                                <tr>
                                   <td><a href="{url path="/admin/configuration/shipping_configuration/update/$ID"}">{$NAME}</a></td>

                                    {module_include location='shipping_configuration_table_row'}

                                    <td>
                                        <div class="btn-group">
                                            {loop type="auth" name="can_change" role="ADMIN" resource="admin.configuration.shipping-configuration" access="UPDATE"}
                                               <a class="btn btn-default btn-xs area-configuration-change" title="{intl l='Change this shipping configuration'}" href="{url path="/admin/configuration/shipping_configuration/update/$ID"}"><i class="glyphicon glyphicon-edit"></i></a>
                                            {/loop}
                                            {loop type="auth" name="can_delete" role="ADMIN" resource="admin.configuration.shipping-configuration" access="DELETE"}
                                                <a class="btn btn-default btn-xs area-configuration-delete" title="{intl l='Delete this shipping configuration'}"  href="#delete_dialog" data-id="{$ID}" data-toggle="modal"><i class="glyphicon glyphicon-trash"></i></a>
                                            {/loop}
                                        </div>
                                    </td>
                                </tr>
                                {/loop}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        {module_include location='shipping_configuration_bottom'}

    </div>
</div>
    
    {* Adding a new Shipping configuration *}

    {* Capture the dialog body, to pass it to the generic dialog *}
    {capture "creation_dialog"}
        {form name="thelia.admin.area.create"}
        {form_hidden_fields form=$form}

        {form_field form=$form field='success_url'}
        {* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller  *}
            <input type="hidden" name="{$name}" value="{url path='/admin/configuration/shipping_configuration/update/_ID_'}" />
        {/form_field}
        {form_field form=$form field="name"}
        <div class="form-group">
            <label for="{$label_attr.for}" class="control-label">{$label} : </label>
            <input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" title="{intl l="Name"}" placeholder="{intl l='Shipping configuration name'}">
        </div>
        {/form_field}
       

        {module_include location='shipping_configuration_create_form'}
        {/form}
    {/capture}

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

        dialog_id    = "creation_dialog"
        dialog_title = {intl l="Create a new shipping configuration"}
        dialog_body  = {$smarty.capture.creation_dialog nofilter}

        dialog_ok_label     = {intl l="Create this shipping configuration"}
        dialog_cancel_label = {intl l="Cancel"}

        form_action        = {url path='/admin/configuration/shipping_configuration/create'}
        form_enctype       = ''
        form_error_message = $form_error_message
    }

    {* Delete confirmation dialog *}

    {capture "delete_dialog"}
        <input type="hidden" name="area_id" id="shipping_configuration_delete_id" value="" />

        {module_include location='shipping_configuration_delete_form'}

    {/capture}

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

        dialog_id       = "delete_dialog"
        dialog_title    = {intl l="Delete shipping configuration"}
        dialog_message  = {intl l="Do you really want to delete this shipping configuration ?"}

        form_action         = {url path='/admin/configuration/shipping_configuration/delete'}
        form_content        = {$smarty.capture.delete_dialog nofilter}
    }
{/block}

{block name="javascript-initialization"}
    <script>
        $(document).ready(function(){
            $(".area-configuration-delete").click(function(e){
                $("#shipping_configuration_delete_id").val($(this).data("id"));
            });
        });
    </script>
{/block}