[%
    USE JavaScript;
    # figure out the extra title part;
    IF page.content_version;
        SET pre_title = loc("Editing");
    ELSE;
        SET pre_title = loc("Creating");
    END;

    # TODO: Make Edit/Attachment an ajax action, so you can go
    # to attachments while editing and let it retain your content.
    # Now, edits are lost.
%]

[% WRAPPER page/wrapper.tt pre_title=pre_title %]
<div id="content">

<script type="text/javascript">
    var append='[% append | js %]';
    [% IF syntax_formatters %]
        var syntax_formatters = ["[% syntax_formatters.join('","') %]"];
    [% ELSE %]
        syntax_formatters = ["Please install Syntax::Highlight::Engine::Kate"];
    [% END %]    
    [% UNLESS user %]
    $('#editForm').submit(function() { return cleanAuthorName("[%c.pref('anonymous_user')%]")});
    [% END +%]
</script>

<div id="edithelp">[% PROCESS edithelp.tt %]</div>

<div id="preview_and_edit_container">
    <div id="content_preview">
    [% IF page.content.formatted(c) %]
        [% page.content.formatted(c) %]
    [% ELSE %]
        <i>[%loc('To start editing this page, write in the text area below this preview. To find out what kind of codes you can use click the syntax link above.')%]</i>
    [% END %]
    </div>

    <div id="edit_form">
        <form id="editForm" accept-charset="UTF-8" action="" method="POST">

        [% FOREACH column IN ['id','depth','name','name_orig','path'] +%]
            <input type="hidden" name="[% column %]" value="[% page.$column %]" />
        [% END +%]
            <input type="hidden" name="parent" value="[% page.parent.id %]" />
            <input type="hidden" name="version" value="[% page.content.version %]" />
        [% IF message %]
            <p id="message"><small>[% message %]</small></p>
        [% END +%]
            <span id="formatter_toolbar"><!-- This will be replaced with a js generated toolbar --></span>
            <br/>
            <a href="[%c.uri_for('jsrpc','render')%]" id="preview_url"></a>
            <textarea id="body" name="body" cols="70">[% merged_body || page.content.encoded_body-%][% append %]</textarea>

            <div class="spinner">
                <span id="editstatus"></span>
                <img id="editspinner" src="[% c.uri_for_static('spinner.gif') %]" alt="[% loc('busy spinner') %]"/>
            </div>

            <input type="submit" name="submit" value="[% IF page.content && page.content.version >= 1; loc('Save and View'); ELSE; loc('Create and View'); END %]" />
            <input type="submit" name="submit" value="[% loc('Save') %]"/>
            [% loc('as') %]
            [% IF user.id %]
                [% c.wikiword(user.link, base, user.login, 'profile') %]
                (<a href="[% c.uri_for('/.logout')%]">[%loc('forget me')%]</a>)
            [% ELSE %]
            <input type="text" name="login" id="authorName" value="[% c.pref('anonymous_user')%]" />
            <input type="password" name="pass" id="userAuth" value="f**k" size="16" />
            <br/>
            ([% loc('Leave the second field blank if you do not want a password') %])
            [% END %]
            [% captcha +%]
        </form>
    </div>
<!-- between last two divs -->
</div>

</div>
[% END # WRAPPER %]
