[% currentPage = 'editDir.html' %]
[% currentPageTitle = 'Edit Directory' %]
[%
    id = modwheel.getParam('id')
    title = modwheel.getParam('title') 
    keywords = modwheel.getParam('keywords')
    summary = modwheel.getParam('summary') 
    active = modwheel.getParam('active')
    detach = modwheel.getParam('detach')
    parent = modwheel.getParam('parent')
    sort = modwheel.getParam('sort')
    template = modwheel.getParam('template')
    username = modwheel.getCurrentUser()
    execute = modwheel.getParam('execute')
    executeDeleteFile = modwheel.getParam('executeDeleteFile')
    deleteFileId = modwheel.getParam('deleteFileId')    
                                                %]

[% # ######### Fetch the article requested. %]

[% this = modwheel.fetchObject(id => id, type ="'directory'") %]
[% UNLESS this %]
    [% error = 'No such directory' %]
[% END %]
[% IF this.id %]
    [% id = this.id %]
[% END %]

[% # ######### Set default values %]


[% UNLESS active %]
    [% active = 'off' %]
[% END %]

[% UNLESS sort %]
    [% sort = 10 %]
[% END %]

[% UNLESS parent %]
    [% parent = 1 %]
[% END %]

[% # ############ Save the object. %]

[% IF execute == 'Yes' %]
    [% UNLESS title %]
        [% error = 'All objects must have a title.' %]
    [% END %]
    [% UNLESS error %]
        [% ret = this.setObjectValues(
            type        => 'directory',
            name        => title,
            keywords    => keywords,
            description    => summary,
            active        => active,
            detach        => detach,
            parent        => parent,
            sort        => sort,
            template    => template
            owner        => username,
            revised_by    => username)
        %]
        [% ret = modwheel.saveObject(this) %]
        [% UNLESS ret %]
            [% error = "Internal Error: Couldn't save object." %]
        [% END %]
    [% END %]
[% END %]

[% IF executeDeleteFile == 'Yes' and deleteFileId %]
    [% ret = modwheel.deleteRepositoryFile(deleteFileId) %]
[% END %]

[% INCLUDE header_start.html %]
<script type="text/javascript">
<!--//
    function updateRepositoryFiles()
    {
        new Ajax.Updater({success: 'repositoryFiles'}, '/ajax/repositoryFilesByObjectId.html?id=[% id %]', {method: 'get'});
    }
    function deleteRepositoryFile(repid)
    {
        new Ajax.Request('/ajax/deleteRepositoryFile.html', {method: 'get', parameters: {id: repid}});
        updateRepositoryFiles();
    }
    function updateTags()
    {
        new Ajax.PeriodicalUpdater({success: 'objectTags'}, '/ajax/tagsByObjectId.html', {frequency: 3, decay: 2, method: 'get', parameters: {objid: '[% id %]'}});
    }
    function disconnectTag(tagid, objid)
    {
        new Ajax.Request('/ajax/tagActions.html', {method: 'get', parameters: {tagid: tagid, objid: objid, action: 'disconnect'}});
        updateTags();
    }
    function connectToTagAndFade(htmldivid, tagid)
    {
        new Effect.Fade(htmldivid);
        new Ajax.Request('/ajax/tagActions.html', {method: 'get', parameters: {tagid: tagid, objid: [% id %], action: 'connect'}});
        updateTags();
        hideLightbox();
    }
    updateRepositoryFiles();
    updateTags();
//-->
</script>
[% INCLUDE header_end.html %]    

<h1>Edit directory: [% this.name %]</h1>
<form name="objectedit" method="post" action="[% currentPage %]">
[% includeChangePathButton = 'Yes' %]
[% INCLUDE currentpath.html %]
<input type="hidden" onChange="refreshEditor()" name="parent" value="[% parent %]" />
    <input type="hidden" name="execute" value="Yes" />
    <input type="hidden" name="executeDeleteFile" value="Yes" />
    <input type="hidden" name="deleteFileId" value="" />
    <input type="hidden" name="id" value="[% id %]" />
    <p><b>Name</b></p>
    <p><input size="83" type="text" name="title" value="[% this.name %]"/></p>
    <p><b>Keywords</b></p>
    <p><input size="83" type="text" name="keywords" value="[% this.keywords %]"/></p>
    <p><b>Summary</b></p>
    <p><textarea rows="5" cols="80" name="summary">[% this.description %]</textarea></p>
    <p>
        <b>Active: </b> <input type="checkbox" name="active" value="on" [% IF this.active %]checked="checked"[% END %] /></b>
        <b>Sort:</b> <input type="text" size="2" name="sort" value="[% this.sort %]" />
        <b>Custom template:</b><input type="text" name="template" size="45" value="[% this.template %]" />
    </p>
    <p><b>Detach from tree: </b> <input type="checkbox" name="detach" value="1"   [% IF this.detach %]checked="checked"[% END %] /></b></p>
    <p><input type="submit" alt="Save object" value="Save" /></p>
    <p><b>Tags for this object:</b></p>
    <div id="objectTags">
    </div>
    <a href="#objectTags" onclick="lightbox(
                    '/taglist.html?id=[% object.id %]',
                    {height:700, width:650, overflow:'top'});">[Add new tags]</a>

    <p><b>Files connected with this object:</b></p>
    <div id="repositoryFiles">
    </div>
    <input type="button" onClick="openUploadWindow('[% id %]')" alt="Upload new files..." value="Upload new files..." />

</form>

[% IF execute == 'Yes' %]
    [% IF error %]
        [% error %]
    [% ELSE %]
        Directory successfully saved. [% ret %]
    [% END %]
[% END %]

<h2>Help</h2>
You can use basic html tags, also if you want to reference a file that is connected with this object
you can type: [file:2] where 2 is the id of the file (the number to the left in parantheses in the list of files above).

[% INCLUDE footer.html %]
