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

{block name="page-title"}{intl l='Edit an image'}{/block}

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

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

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

            {loop type="image" name="image_edit" source="{$imageType}" id="{$imageId}" width="580" 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="Image"}</a></li>
                    <li>{intl l='Editing image "%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 image $TITLE"}
        					</div>

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

        						    {form name="$formId"}
        						    	<form method="POST" action="{url path="/admin/image/type/{$imageType}/{$ID}/update"}" {form_enctype form=$form} class="clearfix">

                                            <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>
                                                    <button type="submit" name="save_mode" value="stay" class="btn btn-default btn-primary" title="{intl l='Save'}">{intl l='Save'} <span class="glyphicon glyphicon-ok"></span></button>
                                                </div>
                                            </div>

        						        	{form_hidden_fields form=$form}

        						        	{form_field form=$form field='success_url'}
        						        		<input type="hidden" name="{$name}" value="{url path="/admin/image/type/{$imageType}/{$ID}/update"}" />
        						        	{/form_field}

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

                                            <p class="title title-without-tabs">{intl l="Image informations"}</p>
                                            
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label class="control-label">{intl l="Preview"} : </label>
                                                        <p>
                                                            <a href="{$ORIGINAL_IMAGE_URL}" alt="{$TITLE}" target="_blank">
                                                                <img src="{$IMAGE_URL}" alt="{$TITLE}" class="img-thumbnail">
                                                            </a>
                                                        </p>
                                                    </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">{intl l="{$label}"} : </label>
                                                            <input type="file" id="{$label_attr.for}" name="{$name}" class="form-control" value="" title="{intl l="{$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">{intl l="{$label}"} : </label>
                                                            <input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$TITLE}" title="{intl l="{$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">{intl l="{$label}"} : </label>
                                                            <textarea id="{$label_attr.for}" name="{$name}" class="form-control" title="{intl l="{$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">{intl l="{$label}"} : </label>
                                                            <textarea id="{$label_attr.for}" name="{$name}" class="form-control" title="{intl l="{$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">{intl l="{$label}"} : </label>
                                                            <textarea id="{$label_attr.for}" name="{$name}" class="form-control wysiwyg" title="{intl l="{$label}"}" placeholder="{intl l='Description'}">{$DESCRIPTION}</textarea>
                                                        </div>
                                                    {/form_field}
                                                </div>
                                            </div>

                                            <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>
                                                    <button type="submit" name="save_mode" value="stay" class="btn btn-default btn-primary" title="{intl l='Save'}">{intl l='Save'} <span class="glyphicon glyphicon-ok"></span></button>
                                                </div>
                                            </div>

                                        </form>
        							{/form}

        						</div>
        					</div>

        				</div>
        			</div>

        		</div>

    		{/loop}

            {elseloop rel="image_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, image ID=$imageId was not found."}
                        </div>
                    </div>
                </div>
            {/elseloop}

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

{block name="javascript-initialization"}
    {javascripts file='assets/js/main.js'}
        <script src="{$asset_url}"></script>
    {/javascripts}
    
    <script src="{url file='/tinymce/tinymce.min.js'}"></script>
    <script>
        tinymce.init({
            selector: ".wysiwyg",
            theme: "modern",
            menubar : false,
            language: "",
            plugins: [
                 "advlist autolink link image lists charmap print preview hr anchor pagebreak",
                 "searchreplace wordcount visualblocks visualchars insertdatetime media nonbreaking",
                 "table contextmenu directionality emoticons paste textcolor filemanager"
            ],
            toolbar1: "undo redo | bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | styleselect | filemanager | link unlink anchor | image media | forecolor backcolor  | print preview code ",
            image_advtab: true ,
            external_filemanager_path:"{url file='/tinymce/plugins/filemanager/'}'",
            filemanager_title:"{intl l='Files manager'}" ,
            external_plugins: { "filemanager" : "{url file='/tinymce/plugins/filemanager/plugin.min.js'}"}
         });
    </script>

{/block}