[opencms-dev] xmlcontent, skipping elements, and also disabling icon display

Marcus Popetz marcus at roundpeg.com
Fri Jun 9 19:17:40 CEST 2006


At 05:29 PM 6/8/2006, Marcus Popetz wrote:
>I worked around this by creating my own add/edit/delete buttons based on 
>what they were doing for theirs...cept I don't use javascript to handle 
>the submitting.

I did some cleanup on this to make it a) prettier and b) more resilient.

The file is attached.

Basically, I've found that you need one xmlcontent to create a new one even 
if you can get the button to display. It uses the existing one to set up 
the editing for the one being created.  :P  So, you'll notice that I point 
to a xmlcontent called /internal/news_001.html for the create form and 
store my real xmlcontent in a different directory.  That way a user won't 
see it or accidentally delete it and cause the add button to no longer work.

I changed the submit buttons to links that use javascript to submit and 
threw it in a table format.

I also wrapped a check around the whole thing to not display anything if 
the user is the "Guest" user, ie: viewing the published site.  Without 
this, the edit links appear on the published site.  You could get fancier 
and just disable the links...but I just disabled viewing too.

-mp

-------------- next part --------------
<%@ page import="java.util.Date"%>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<% int count = 0; %>

<c:set var="department"><%=request.getParameter("department") == null ? "Perspective" : request.getParameter("department")%></c:set>


<c:set var="username"><cms:user property="name"/></c:set>

<!-- disable if we have no user..ie accessing published version not thorugh cms. -->
<c:if test="${username eq 'Guest'}">
No logged in user
</c:if>
<c:if test="${username ne 'Guest'}">


<table cellpadding=0 cellspacing=0>
<tr><td align="left" valign="bottom"><b>News 1:</b></td><td  valign="bottom" align="right">
<form name="form_addNewNews" id="form_directedit_-1846939088" method="post" action="/system/workplace/editors/editor.jsp" class="ocms_nomargin" target="_top">
<input type="hidden" name="resource" value="/internal/news_0001.html">
<input type="hidden" name="directedit" value="true">
<input type="hidden" name="elementlanguage" value="en">


<input type="hidden" name="elementname" value="null">
<input type="hidden" name="backlink" value="/news/listBySection.jsp?department=<c:out value="${department}"/>">
<input type="hidden" name="newlink" value="allInFolderDateReleasedDesc%7C%2Fnews%2Fnews_%24%7Bnumber%7D.html%7CAAU_News">
<input type="hidden" name="closelink">
<input type="hidden" name="redirect" value="true">
<input type="hidden" name="editortitle" value="Editing (new resource)">
</form>
<a href="#" onclick="javascript:document.form_addNewNews.submit();">add new news article</a>

</td>
</tr>
<td colspan="2">
<table><tr><td bgcolor="000000">
<table cellspacing=1>
<tr bgcolor="#ffffff"><th>Title</th><th>Teaser</th><th>   Edit   </th><th>   Delete   </th></tr>
<cms:contentload collector="allInFolderPriorityDateDesc" param="/news/news_${number}.html|AAU_News">

    <c:set var="matchesSection" value="false"/>
        <cms:contentloop element="Section">
            <c:set var="section"><cms:contentshow/></c:set>
            <c:if test="${section eq department}">
                <c:set var="matchesSection" value="true"/>
            </c:if>
        </cms:contentloop>
    <c:if test="${matchesSection eq 'true' or department eq ''}">

        <c:set var="strReleased"><cms:contentshow element="ReleaseDate" /></c:set>
        <c:set var="strClosed"><cms:contentshow element="CloseDate" /></c:set>
        <%
        boolean active = false;
        try
        {
            Date releaseDate = new Date(Long.parseLong((String)pageContext.findAttribute("strReleased")));
            Date closeDate = new Date(Long.parseLong((String)pageContext.findAttribute("strClosed")));
            if(releaseDate.before(new Date()) && closeDate.after(new Date()))
            {
                active = true;
            }
        } catch (Exception e) {}
        if(count > 2)
        {//headlines...only 3
        //    active = false;
        }
        if(active)
        {
            count++;
        %>

<tr bgcolor="#ffffff">
<td valign="bottom">
            <div class="newswidget"><cms:contentshow element="Title" /></div>
</td>
<td valign="bottom">
            <cms:contentshow element="Teaser" />
            <a href="<cms:link><cms:contentshow element="${opencms.filename}" /></cms:link>">preview...</a>
</td>
<td align="center" valign="bottom">
<form name="form_directedit_<%=count%>_edit" method="post" action="/system/workplace/editors/editor.jsp" class="ocms_nomargin" target="_top">
<input type="hidden" name="resource" value="<cms:contentshow element="${opencms.filename}" />">
<input type="hidden" name="directedit" value="true">
<input type="hidden" name="elementlanguage" value="en">

<input type="hidden" name="elementname" value="null">
<input type="hidden" name="closelink" value="/news/listBySection.jsp?department=<c:out value="${department}"/>">
<input type="hidden" name="newlink">
<input type="hidden" name="backlink" value="/news/listBySection.jsp?department=<c:out value="${department}"/>">
<input type="hidden" name="redirect" value="true">
<input type="hidden" name="editortitle">
</form>
<a href="#" onclick="javascript:document.form_directedit_<%=count%>_edit.submit();">edit</a>
</td>
<td align="center" valign="bottom">
<form name="form_directedit_<%=count%>_delete" id="form_directedit_-1846939088" method="post" action="/system/workplace/commons/delete.jsp" class="ocms_nomargin" target="_top">
<input type="hidden" name="resource" value="<cms:contentshow element="${opencms.filename}" />">
<input type="hidden" name="directedit" value="true">
<input type="hidden" name="elementlanguage" value="en">
<input type="hidden" name="elementname" value="null">
<input type="hidden" name="backlink" value="/news/listBySection.jsp?department=<c:out value="${department}"/>">
<input type="hidden" name="newlink" value="allInFolderDateReleasedDesc%7C%2Fnews%2Fnews_%24%7Bnumber%7D.html%7CAAU_News">
<input type="hidden" name="closelink" value="/news/listBySection.jsp?department=<c:out value="${department}"/>">
<input type="hidden" name="redirect" value="true">
<input type="hidden" name="editortitle" value="Deleting (resource)">
</form>
<a href="#" onclick="javascript:document.form_directedit_<%=count%>_delete.submit();">delete</a>
</td>
</tr>

        <%}%>

    </c:if>
</cms:contentload>
</table>
</td>
</tr>
</table>
</td></tr>
</table>

</c:if>


More information about the opencms-dev mailing list