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

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

{block name="check-access"}update{/block}

{block name="main-content"}
    <div class="documents edit-document">

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

            {loop type="document" name="document_edit" source="{$documentType}" id="{$documentId}" 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="{$redirectUrl}"}">{intl l="Document"}</a></li>
                    <li>{intl l='Editing document "%name"' name="{$TITLE}"}</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 document "%name"' name="{$TITLE}"}
        					</div>

                            <div class="form-container">
                                <div class="col-md-12">
        						    {form name="$formId"}
        						    	<form method="POST" action="{url path="/admin/document/type/{$documentType}/{$ID}/update"}" enctype="multipart/form-data" class="clearfix">

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

                                                page_url  = "{url path="/admin/document/type/{$documentType}/{$ID}/update"}"
                                                close_url = "{url path="{$redirectUrl}"}"
                                            }

        						        	{form_hidden_fields form=$form}

        						        	{form_field form=$form field='success_url'}
        						        		<input type="hidden" name="{$name}" value="{url path="/admin/document/type/{$documentType}/{$ID}/update"}" />
        						        	{/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}

                                            <p class="title title-without-tabs">{intl l="Document informations"}</p>

                                            <div class="row">

                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label class="control-label">{intl l="File"} : </label>
                                                        <p><a href="{$DOCUMENT_PATH}" title="{$TITLE}" target="_blank">{$TITLE}</a>
                                                    </div>
                                                </div>

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

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

                                                    {form_field form=$form field='chapo'}
                                                        <div class="form-group {if $error}has-error{/if}">
                                                            <label for="{$label_attr.for}" class="control-label">{$label} : </label>
                                                            <textarea id="{$label_attr.for}" name="{$name}" class="form-control" title="{$label}" placeholder="{intl l='Chapo'}">{$CHAPO}</textarea>
                                                        </div>
                                                    {/form_field}

                                                    {form_field form=$form field='postscriptum'}
                                                        <div class="form-group {if $error}has-error{/if}">
                                                            <label for="{$label_attr.for}" class="control-label">{$label} : </label>
                                                            <textarea id="{$label_attr.for}" name="{$name}" class="form-control" title="{$label}" placeholder="{intl l='Post Scriptum'}">{$POSTSCRIPTUM}</textarea>
                                                        </div>
                                                    {/form_field}
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-12">
                                                    {form_field form=$form field='description'}
                                                        <div class="form-group {if $error}has-error{/if}">
                                                            <label for="{$label_attr.for}" class="control-label">{$label} : </label>
                                                            <textarea id="{$label_attr.for}" name="{$name}" class="form-control wysiwyg" title="{$label}" placeholder="{intl l='Description'}">{$DESCRIPTION}</textarea>
                                                        </div>
                                                    {/form_field}
                                                </div>
                                            </div>

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

                                                page_url  = "{url path="/admin/document/type/{$documentType}/{$ID}/update"}"
                                                close_url = "{url path="{$redirectUrl}"}"
                                            }
                                        </form>
        							{/form}

        						</div>
        					</div>

        				</div>
        			</div>

        		</div>

    		{/loop}

            {elseloop rel="document_edit"}
                <div class="row">
                    <div class="col-md-12">
                        <div class="row inner-toolbar clearfix">
                            <div class="col-md-6 inner-actions pull-right">
                                <a href="{url path="{$redirectUrl}"}" class="btn btn-default btn-info">{intl l='Back'} <span class="glyphicon glyphicon-remove"></span></a>
                            </div>
                        </div>
                        <div class="alert alert-error">
                            {intl l="Sorry, document ID=%id was not found." id={$documentId}}
                        </div>
                    </div>
                </div>
            {/elseloop}

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

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

{/block}

{block name="javascript-last-call"}
    {module_include location='document-edit-js'}
{/block}