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

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

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

{block name="main-content"}
    <div class="templates edit-template">

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

            {loop name="template_edit" type="product-template" id="$template_id" backend_context="1" lang="$edit_language_id"}

                <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/templates'}">{intl l="Templates"}</a></li>
                    <li>{intl l='Editing template "%name"' name="{$NAME}"}</li>
                </ul>

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

        					<div class="col-md-12 title title-without-tabs">
        					   {intl l="Edit template $NAME"}
        					</div>

                            <div class="form-container">
                                <div class="col-md-12">

        						    {form name="thelia.admin.template.modification"}
        						    	<form method="POST" action="{url path='/admin/configuration/templates/save'}" {form_enctype form=$form} class="clearfix">

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

                                        	{include file="includes/inner-form-toolbar.html" close_url="{url path='/admin/configuration/templates'}"}

        						        	{form_hidden_fields form=$form}

        						        	{form_field form=$form field='success_url'}
        						        		<input type="hidden" name="{$name}" value="{url path='/admin/configuration/templates'}" />
        						        	{/form_field}

        			                        {form_field form=$form field='locale'}
        			                        	<input type="hidden" name="{$name}" value="{$edit_language_locale}" />
        			                        {/form_field}

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

                                            {form_field form=$form field='name'}
                                                <div class="form-group {if $error}has-error{/if}">
                                                    <label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
                                                    <input type="text" id="{$label_attr.for}" required="required" name="{$name}" value="{$value}" title="{intl l='Template name'}" placeholder="{intl l='Template name'}" class="form-control">
                                                </div>
                                            {/form_field}
                                        </form>
                                    {/form}
                                </div>
                            </div>
                        </div>

                        <div class="row">
                           <div class="form-container">
                                <div class="col-md-6">
                                       <div class="well well-sm">
	                                    <p class="title title-without-tabs">{intl l='Attributes'}</p>
	                                    <p>Manage attributes included in this product templates</p>

	                                    <div id="attribute_list_management">
	                                       <div class="loading"></div>
	                                    </div>
                                       </div>
                                </div>

                                <div class="col-md-6">
                                    <div class="well well-sm">
	                                    <p class="title title-without-tabs">{intl l='Features'}</p>
	                                    <p>Manage features included in this product templates</p>

                                        <div id="feature_list_management">
                                           <div class="loading"></div>
                                        </div>
                                       </div>
        						</div>
       						</div>
        				</div>
        			</div>

        		</div>

    		{/loop}

            {elseloop rel="template_edit"}
                <div class="row">
                    <div class="col-md-12">
                        <div class="alert alert-error">
                            {intl l="Sorry, template ID=$template_id was not found."}
                        </div>
                    </div>
                </div>
            {/elseloop}

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

{block name="javascript-initialization"}

    {javascripts file='assets/js/bootstrap-editable/bootstrap-editable.js'}
        <script src="{$asset_url}"></script>
    {/javascripts}

    <script>
        $(function() {
        	$('#feature_list_management').load("{url noamp='1' path='/admin/configuration/templates/features/list' template_id=$template_id}");
            $('#attribute_list_management').load("{url noamp='1' path='/admin/configuration/templates/attributes/list'  template_id=$template_id}");
       });
    </script>
{/block}