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

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

{block name="page-title"}{intl l='Edit a module'}{/block}

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

{block name="main-content"}

<div class="edit-module">

    <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/modules'}">{intl l="Modules"}</a></li>
            <li>{intl l='Editing module'}</li>
        </ul>

        {loop type="module" name="module" id=$module_id backend_context="1" lang=$edit_language_id}

        {hook name="module-edit.top" module_id=$module_id}

        <div class="row">
            <div class="col-md-12 general-block-decorator clearfix">

                <ul class="nav nav-tabs" id="tabbed-menu">
                    <li class="active"><a href="#general" data-toggle="tab">{intl l="General description"}</a></li>
                    <li><a href="#images" data-toggle="tab">{intl l="Images"}</a></li>
                </ul>
                <div class="tab-content">
                    <div class="tab-pane fade active in" id="general">
                        <div class="form-container">

                            {form name="thelia.admin.module.modification"}
                            <form method="POST" action="{url path="/admin/module/save"}" {form_enctype} >

                                {include
                                    file = "includes/inner-form-toolbar.html"
                                    hide_submit_buttons = false

                                    page_url  = {url path="/admin/module/update/$module_id"}
                                    close_url = {url path="/admin/modules"}
                                }

                                {* Be sure to get the module ID, even if the form could not be validated *}
                                <input type="hidden" name="module_id" value="{$ID}" />
                                <input type="hidden" name="current_tab" value="general" />

                                {form_hidden_fields}

                                {render_form_field field="success_url" value={url path="/admin/modules"}}

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

                                {include file="includes/standard-description-form-fields.html"}

                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="control-group">
                                            <label>&nbsp;</label>
                                            <div class="controls">
                                                <p>{intl l='Module created on %date_create. Last modification: %date_change' date_create={format_date date=$CREATE_DATE} date_change={format_date date=$UPDATE_DATE}}</p>
                                            </div>
                                         </div>
                                    </div>
                                </div>

                            </form>
                            {/form}
                        </div>
                    </div>
                    <div class="tab-pane fade" id="images">
                        {include file='includes/image-upload-form.html' imageType='module' parentId=$module_id}
                    </div>
                </div>
            </div>
        </div>

        {hook name="module-edit.bottom" module_id=$module_id}

        {/loop}

    </div>

</div>

{/block}

{block name="javascript-initialization"}
    {javascripts file='assets/js/dropzone.js'}
        <script src="{$asset_url}"></script>
    {/javascripts}
    {javascripts file='assets/js/image-upload.js'}
        <script src="{$asset_url}"></script>
    {/javascripts}

    {javascripts file='assets/js/jquery-ui-1.10.3.custom.min.js'}
        <script src="{$asset_url}"></script>
    {/javascripts}

    <script>
        $(function() {
            // Atomatic ajax tab load, if data-href is defined.
            $('.nav-tabs a[data-href]').on('shown.bs.tab', function(ev) {
                var $this = $(this);
                $($this.attr('href')).load($this.data('href'), function(ev) {
                    if($this.data('callback')) {
                        eval($this.data('callback') + '();');
                    }
                });
            });
            $.imageUploadManager.initImageDropZone();
            $('.use_default_rewriten_url').click(function(ev) {
                alert("Not functionnal");
                ev.preventDefault();
            });
            // Show proper tab, if defined
            {if ! empty($current_tab)}
            $('#tabbed-menu a[href="#{$current_tab}"]').tab('show')
            {/if}
            // Initialize folder select value
            {if $module_id != 0}
            $('#module_id').val("{$module_id}").change();
            {/if}
        });
    </script>
{/block}

{block name="javascript-last-call"}
    {hook name="module.edit-js" location="module-edit-js" module_id={$module_id} }
    {hook name="wysiwyg.js" location="wysiwyg-module-edit-js" }
{/block}