<%@ page language="java" buffer="64kb" %>

<%@ taglib uri="struts-html"     prefix="html"  %>
<%@ taglib uri="struts-bean"     prefix="bean"  %>
<%@ taglib uri="struts-logic"    prefix="logic" %>
<%@ taglib uri="vkc-taglib"      prefix="vkc"   %>

<vkc:init/>

<script type="text/javascript">
    function deleteSelectedMessages(elem) {
        var form = document.forms[ 0 ];
        var numChecked = getNumberOfCheckedEntries();
        	        
        if ( numChecked == 0 ) {
            alert( '<vkc:message javascript="true" filter="false" key="error.noitem_checked"/>' );
            return;
        }

        if ( !confirm( '<vkc:message javascript="true" filter="false" key="vkc.string.confirm.delete.selection"/>' ) ) {
            return;
		}               

        if (form.action.indexOf('?') == -1) {
          form.action = form.action + "?action.delete.messages=true";
        } else {
          form.action = form.action + "&action.delete.messages=true";
        }

        disableAllButtons(elem);
        form.submit();
    }
    
	function checkAll( mForm ) {			
		for( var i=0 ; i<mForm.elements.length ; i++ ) { 
			var elem = mForm.elements[i];
			if( elem.name!='allItems' ) {
			    elem.checked=mForm.allItems.checked;
			}
		}
	}
	
	function getNumberOfCheckedEntries() {
        var form  = document.forms[ 0 ];
        var field = form.selectedIds;

        if ( !field )
        	return 0;

        if ( !field.length ) {

            <%-- nur eine Checkbox auf der Seite --%>
            if ( field.checked ) {
                return 1;
            } else {
                return 0;
            }
        }

        var checked = 0;
        for ( var i=0 ; i<field.length ; i++ ) {
            if ( field[i].checked ) {
                checked++;
            }
        }
        return checked;
	}

</script>  

<table width="100%" cellpadding="0" cellspacing="0" border="0">

  <bean:define id="form" name="form" scope="request" type="vkc.procoba.project.ProjectViewForm"/>

  <html:hidden property="viewMode" name="form"/>

  <logic:notEmpty name="form" property="project">

    <bean:define id="messages" name="form" property="projectMessages"/>
	
	<tr>
	  <td width="100%" align="left" colspan="1" class="color_toolbar">
	    <table width="100%" cellpadding="0" cellspacing="5">
	      <tr><td align="left"><b><vkc:message key="project.label.message.overview"/></b></td></tr>
	    </table>
	  </td>
	</tr>

    <tr><td background="<vkc:rewrite page='/templates/${template.name}/gfx/dotted-line-h.gif'/>"><vkc:img page="/templates/${template.name}/procoba/images/void.gif" alt="" width="1" height="1"/></td></tr>

    <logic:empty name="messages">
      <tr>
        <td width="100%">
          <table width="100%" cellpadding="0" cellspacing="5" border="0">
            <tr><td align="left"><vkc:message key="project.info.no.messages"/></td>
          </table>
        </td>
      </tr>
    </logic:empty>

    <logic:notEmpty name="messages">
      <tr>
        <td width="100%">
          <table width="100%" cellpadding="0" cellspacing="5" border="0">
            <tr>
              <td align="left">
                <table width="100%" class="tableLineColor" cellpadding="2" cellspacing="1" border="0">

                  <tr>
                    <td valign="top" nowrap="nowrap" class="headerSelected">&nbsp;</td>
                    <td valign="top" nowrap="nowrap" class="headerSelected"><b><vkc:message key="project.message.date"  /></b></td>
                    <td valign="top" nowrap="nowrap" class="headerSelected"><b><vkc:message key="project.message.sender"/></b></td>
                    <td valign="top" nowrap="nowrap" class="headerSelected">&nbsp;</td>
                    <td valign="top" nowrap="nowrap" class="headerSelected"><b><vkc:message key="project.message.text"  /></b></td>
                  </tr>
            
                  <logic:iterate name="messages" id="message" indexId="index" type="vkc.procoba.project.entities.VKCProjectMessage">
                  <a id="msg<vkc:write name="message" property="messageId"/>" name='msg<vkc:write name="message" property="messageId"/>'></a>
                  <tr>
      				<td nowrap="nowrap" class="smallFont" bgcolor="#fafafa"><html:multibox name="form" property="selectedIds" onfocus="this.blur();"><vkc:write name="message" property="messageId"/></html:multibox></td>
                    <td nowrap="nowrap" class="smallFont" bgcolor="#fafafa"><vkc:write name="message" property="creationDate" formatKey="date.medium.format"/></td>
                    <td nowrap="nowrap" class="smallFont" bgcolor="#fafafa">
                      <logic:notEmpty name="message" property="creatorInfo">
                      <vkc:write name="message" property="creatorInfo.firstname"/>&nbsp;<vkc:write name="message" property="creatorInfo.lastname"/>
                      </logic:notEmpty>
                      <logic:empty name="message" property="creatorInfo">
                      <vkc:message key="project.message.system"/>
                      </logic:empty>
                    </td>

                    <td align="left" nowrap="nowrap" class="smallFont" bgcolor="#fafafa">
                      <table cellpadding="0" cellspacing="0">
                        <tr>
                          <logic:notEmpty name="message" property="link">
                          <td><vkc:img page="/templates/${template.name}/procoba/images/void.gif" alt="" border="0" width="5" height="5"/></td>
                            <logic:empty name="message" property="linkKey">
                            <td><a href="<%=ctxPath%><%=message.getLink()%>" style="font-weight:normal;"><vkc:img page="/templates/${template.name}/procoba/images/document-link.gif" border="0" alt=""/></a></td>
                            </logic:empty>
                            <logic:notEmpty name="message" property="linkKey">
                            <td><a href="<%=ctxPath%><%=message.getLink()%>" title='<vkc:message key="<%=message.getLinkKey()%>"/>' style="font-weight:normal;"><vkc:img page="/templates/${template.name}/procoba/images/document-link.gif" border="0" alt=""/></a></td>
                            </logic:notEmpty>
                          </logic:notEmpty>
                        </tr>    
                      </table>
                    </td>  

                    <td width="100%" nowrap="nowrap" class="smallFont" bgcolor="#fafafa">
			          <logic:equal name="form" property="tinyMCECompatible" value="true">
			          <vkc:write name="message" property="text" displayAsHTML="true" renderNewLine="true"/>
			          </logic:equal>
			          <logic:equal name="form" property="tinyMCECompatible" value="false">
			          <vkc:write name="message" property="text" stripHTML="true" renderNewLine="true"/>
			          </logic:equal>
                    </td>
                  </tr>
                  </logic:iterate>
                </table>
              </td>
            </tr>
  			<tr><td colspan="5">&nbsp;<input type="checkbox" name="allItems" value="allItems" onclick="javascript:checkAll(this.form);">&nbsp;<vkc:message key="vkc.string.checkAll"/></td></tr>
          </table>    
        </td>
      </tr>
    </logic:notEmpty>

    <vkc:hline colspan="15" lineClass="hline" lineHeight="1" topSpace="0" bottomSpace="5"/>

    <tr>
      <td width="100%">
        <table width="100%" cellpadding="0" cellspacing="0" border="0">
          <tr>
            <logic:notEmpty name="messages">
            <td align="left" nowrap="nowrap"><vkc:button property="deleteButton" onclick="javascript:deleteSelectedMessages(this);"><vkc:message key="button.delete.selection"/></vkc:button></td>
            </logic:notEmpty>
            <td width="100%" align="center" nowrap="nowrap">
              <vkc:button property="action.new.message" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.new.message"/></vkc:button>
              <vkc:button property="action.back.to.subfolder" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.back"/></vkc:button>
            </td>
          </tr>
        </table>
      </td>
    </tr>    
  </logic:notEmpty>
</table>
