[% currentPage = 'newDir.html' %]
[% currentPageTitle = 'New Directory' %]
[%    title = modwheel.getParam('title') 
    keywords = modwheel.getParam('keywords')
    description = modwheel.getParam('description') 
    active = modwheel.getParam('active')
    parent = modwheel.getParam('parent')
    sort = modwheel.getParam('sort')
    template = modwheel.getParam('template')
    detach = modwheel.getParam('detach')
    username = modwheel.currentUserName()
    execute = modwheel.getParam('execute')
                                                %]

[% UNLESS title %]
    [% error = 'All directories must have a name.' %]
[% END %]
[% DEFAULT active = 'on' %]
[% DEFAULT sort = 10 %]

[% IF execute == 'Yes' and !error %]
    [% obj = modwheel.createObject(
        type        => 'directory',
        name        => title,
        keywords    => keywords,
        description    => description,
        data        => text,
        active        => active,
        parent        => parent,
        sort        => sort,
        template    => template
        detach        => detach,
        owner        => username,
        revised_by    => username)
    %]
    [% ret = modwheel.saveObject(obj) %]
    [% UNLESS ret %]
        [% error = "Internal Error: Couldn't save object." %]
    [% END %]
[% END %]

[% INCLUDE header_start.html %]
[% IF ret %]
<script type="text/javascript">
window.location = "editDir.html?id=[% ret %]&parent=[% parent %]";
</script>
[% END %]
[% INCLUDE header_end.html %]
    
<h1>New directory</h1>
<form name="objectedit" method="post" action="[% currentPage %]">
<b> Create in: </b>
[% includeChangePathButton = 'Yes' %]                                                                   
[% INCLUDE currentpath.html %]                                                                          
<input type="hidden" onChange="refreshEditor()" name="parent" value="[% parent %]" />
<input type="hidden" name="execute" value="Yes" />
    <p><b>Name</b></p>
    <p><input size="83" type="text" name="title" value="[% title %]"/></p>
    <p><b>Keywords</b></p>
    <p><input size="83" type="text" name="keywords" value="[% keywords %]"/></p>
    <p><b>Description</b></p>
    <p><textarea rows="5" cols="80" name="description">[% description %]</textarea></p>
    <p>
        <b>Active: </b> <input type="checkbox" name="active" value="on" [% IF active %]checked="checked"[% END %] /></b>
        <b>Sort:</b> <input type="text" size="2" name="sort" value="[% sort %]" />
        <b>Custom template:</b><input type="text" name="template" size="45" value="[% template %]" />
    </p>
    <p><b>Detach from tree:</b><input type="checkbox" name="detach" value="1" [%IF detach %]checked="checked"[% END %] /></b></p>
    <p><input type="submit" value="Save" /></p>
</form>

[% IF execute == 'Yes' %]
    [% IF error %]
        <p class="error">[% error %]</p>
    [% ELSE %]
        <p class="success">Directory saved with new id: [% ret %]</p>
    [% END %]
[% END %]

[% INCLUDE footer.html %]
