#parse ( "/template/includes/actionerrors.vm" )

#if( $req.remoteUser )
    #if ($permissionCheckDispatcher.isPermitted("/pages/templates/createpagetemplate.action?key=$!key"))
    <ul class="static-menu">
        <li><a href="$req.contextPath/pages/templates/createpagetemplate.action?key=$!key">
            #if ($space)
                $action.getText("action.add.space.template")
            #else
                $action.getText("action.add.global.template")
            #end
        </a></li>
    </ul>
    #end
#end

#if ($actionErrors.size() == 0)
    <table width="100%" cellspacing="1" class="tableview">
        <tr>
            <th width="50%">$action.getText("heading.name")</th>
            <th width="1%" align="center" nowrap>$action.getText("heading.modifier")</th>
            <th width="1%" align="center" nowrap>$action.getText("heading.mod.date")</th>
            <th>$action.getText("heading.operations")</th>
        </tr>
        #if( !$action.pageTemplates || $action.pageTemplates.size()==0 )
            <td colspan="4">
                $action.getText("there.are.no.page.templates")
            </td>
        #else
            #foreach( $pageTemplate in $action.pageTemplates )
            #if( $previousLoginDate && $pageTemplate.lastModificationDate.after($previousLoginDate) )
                #if( $pageTemplate.isNew() )
                    #set ($colorHtml = 'style="color: #008800"')
                #elseif( $space.lastModificationDate )
                    #set ($colorHtml = 'style="color: #008800"')
                #end
            #else
                #set ($colorHtml = "")
            #end
            <tr href="viewpagetemplate.action?pageTemplateId=$pageTemplate.id" #alternateRowColors()>
                <td>
                    <a $colorHtml href="viewpagetemplate.action?pageTemplateId=$pageTemplate.id&key=$!key">$pageTemplate.name</a>
                </td>
                <td width="1%" align="center" nowrap>
                    #usernameLink ($pageTemplate.lastModifierName)
                </td>
                <td width="1%" align="center" nowrap>
                    $dateFormatter.format( $pageTemplate.lastModificationDate )
                </td>
                <td width="1%" align="center" nowrap>

                    #if ($pageTemplate.space)
                        #if( $permissionCheckDispatcher.isPermitted("/pages/templates/removepagetemplate.action?pageTemplateId=$pageTemplate.id&key=$!key"))
                            <a href="$req.contextPath/pages/templates/editpagetemplate.action?pageTemplateId=$pageTemplate.id&key=$!key">$action.getText("edit.name")</a>  |
                            <a href="$req.contextPath/pages/templates/removepagetemplate.action?pageTemplateId=$pageTemplate.id&key=$!key">$action.getText("remove.name")</a> |
                            <a href="$req.contextPath/pages/createpage-entervariables.action?spaceKey=$generalUtil.urlEncode($key)&templateId=$pageTemplate.id"> $action.getText("action.create.page.from.template") </a>
                        #else
                            #if( $permissionCheckDispatcher.isPermitted("/pages/createpage-entervariables.action?spaceKey=$generalUtil.urlEncode($key)&templateId=$pageTemplate.id") )
                                <a href="$req.contextPath/pages/createpage-entervariables.action?spaceKey=$generalUtil.urlEncode($key)&templateId=$pageTemplate.id"> $action.getText("action.create.page.from.template") </a>
                            #end
                        #end
                    #else
                        #if ($permissionHelper.isConfluenceAdministrator($remoteUser))
                            #if ($permissionCheckDispatcher.isPermitted("/pages/templates/editpagetemplate.action?pageTemplateId=$pageTemplate.id"))
                                <a href="$req.contextPath/pages/templates/editpagetemplate.action?pageTemplateId=$pageTemplate.id">$action.getText("edit.name")</a>
                            #end

                            #if ($permissionCheckDispatcher.isPermitted("/pages/templates/removepagetemplate.action?pageTemplateId=$pageTemplate.id"))
                                | <a href="$req.contextPath/pages/templates/removepagetemplate.action?pageTemplateId=$pageTemplate.id">$action.getText("remove.name")</a>
                            #end
                        #end
                    #end
                </td>
            </tr>
            #end
        #end
    </table>
#end
