<%@ page import="vkc.view.form.CreateCategoryForm" %>

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

<vkc:init/>
<html:html locale="true">
<head>

    <meta http-equiv="content-type"  content="text/html; charset=iso-8859-1" />

  	<vkc:cssinclude />

    <script type="text/javascript" src="<vkc:rewrite page='/common/calendar.js'/>"></script>
    <script type="text/javascript" src="<vkc:rewrite page='/common/utils.js'   />"></script>
    <script type="text/javascript" src="<vkc:rewrite page='/common/overlib/overlib.js'/>"><!-- overLIB (c) Erik Bosrup --></script>
    <script type="text/javascript" src="<vkc:rewrite page='/common/overlib/overlib_positioncap.js'/>"></script>
	<script type="text/javascript" src="<vkc:rewrite page='/common/tiny_mce/tiny_mce.js'/>"></script>
    <script type="text/javascript">
    window.name = "MAINVIEW";
	initTinyMCE("<vkc:write name='user' property='language.shortName'/>", "<vkc:rewrite page='/templates/${template.name}/tiny_mce.css'/>");
    var currentCalendar = null;
    var windowOpen = null;
	
	
    function init(){
        setAnchor();
    }

    function setAnchor() {
        <logic:present parameter="anchor">
            <bean:parameter id="anchor2" name="anchor"/>
            this.location.hash = '<%=anchor2%>';
        </logic:present>
    }

    function deleteAttribute( index ) {
        var form = document.forms[0];
        form.selectedIndex.value = index;
        return true;
    }

    function previewParentAcl() {
      var wnd = openCentered(400, 500, '<%=ctxPath%>/displayAcl.do?ownWindow=true&categoryId=<vkc:write name="createCategoryForm" property="parentCategoryId"/>&init=true',"ACLVIEW");
    }

    function previewDefaultTargetAcl() {
      var wnd = openCentered(400, 500, '<%=ctxPath%>/displayAcl.do?ownWindow=true&categoryId=<vkc:write name="createCategoryForm" property="parentCategoryId"/>&init=true&defaultAcl=true',"ACLVIEW");
    }

    function gotoCreateProjectCategory() {
      window.location.replace( '<%=ctxPath%>/createProject.do?parentCategoryId=<vkc:write name="createCategoryForm" property="parentCategoryId"/>&validate=false' );
    }

    function showExplorer() {
        var w = 200;
        var h = 600;
        var leftPosition = screen.width/2  - w/2;
        var topPosition  = screen.height/2 - h/2;
        var settings ='height=' + h + ', width=' + w + ', top=' + topPosition + ', left=' + leftPosition;
        settings += ',scrollbars=yes,resizable';
        settings += ',toolbar=no, location=no, directories=no, status=true, menubar=no';
        windowOpen = window.open( '<vkc:rewrite page="/explorerTreeView.do"/>', 'EXPLORER_MAINVIEW', settings );
        windowOpen.focus();
        return false;
    }

    function setCategoryId(id) {
        var form = document.forms[0];
        
        if (form.action.indexOf('?') == -1) {
          form.action = form.action + "?action.change.category=true" + "&selectedCategoryId=" + id;
        } else {
          form.action = form.action + "&action.change.category=true" + "&selectedCategoryId=" + id;
        }
        
        windowOpen = null;
        form.submit();
    }

    function toggleTinyMCEToolbar() {
        var form = document.forms[0];
    	<logic:equal name="createCategoryForm" property="showTinyMCEToolbar" value="true">
    	form.showTinyMCEToolbar.value = 'false';
    	</logic:equal>
    	<logic:equal name="createCategoryForm" property="showTinyMCEToolbar" value="false">
    	form.showTinyMCEToolbar.value = 'true';
    	</logic:equal>
        
        if (form.action.indexOf('?') == -1) {
          form.action = form.action + "?action.toggle.tinymcetoolbar=true";
        } else {
          form.action = form.action + "&action.toggle.tinymcetoolbar=true";
        }

        form.submit();
    }

    function unloadPage() {
        if ( currentCalendar!=null ) {
              hideCalendar();
        }

        if ( windowOpen != null ) {
            windowOpen.close();
        }
    }


    function showHelpText() {
    	var text = '<vkc:message javascript="true" filter="false" key="vkc.keywords.help"/>';
        
        return overlib( text, STICKY, MOUSEOFF, WIDTH, 200, OFFSETX, 30, OFFSETY, -10, RIGHT );
    }

    </script>

</head>

<body onload="init();" onUnload="unloadPage();">
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<html:form action="/createCategory" method="post">
<bean:define id="form"  name="createCategoryForm" scope="request" type="vkc.view.form.CreateCategoryForm" toScope="request"/>

<vkc:hidden property="parentCategoryId"/>
<vkc:hidden property="sourcePageId"/>
<logic:notEmpty name="form" property="targetId">
  <vkc:hidden property="targetId"/>
</logic:notEmpty>
<logic:notEmpty name="form" property="subTargetId">
  <vkc:hidden property="subTargetId"/>
</logic:notEmpty>
<vkc:hidden property="searchQuery"/>
<vkc:hidden property="selectedIndex"/>

<vkc:hidden property="showTinyMCEToolbar"/>

<logic:equal name="form" property="editMode" value='<%=CreateCategoryForm.EDITMODE_SEARCHQUERY%>'>
  <vkc:hidden property="name"/>
  <vkc:hidden property="keywords"/>
  <vkc:hidden property="description"/>

  <logic:present name="form" property="permissionsSettings">
    <vkc:hidden property="permissionsSettings"/>
  </logic:present>

  <logic:notEmpty name="form" property="addCatAttributes">
    <logic:iterate id="fieldName" indexId="fieldCtr" name="form" property="addCatAttributeKeys" type="java.lang.String">
    <vkc:hidden property='<%= String.valueOf( "addCatAttributeValue(" + fieldName + ")" ) %>'  name="form"/>
    </logic:iterate>
  </logic:notEmpty>

  <logic:notEmpty name="form" property="dynaAttributes">
    <logic:iterate id="dynaAttribute" name="form" property="dynaAttributes" indexId="index" type="org.apache.struts.util.LabelValueBean">
    <vkc:hidden property='<%= "dynaAttributeLabel_" + index %>' value='<%= dynaAttribute.getLabel() %>' />
    <vkc:hidden property='<%= "dynaAttributeValue_" + index %>' value='<%= dynaAttribute.getValue() %>' />
    </logic:iterate>
  </logic:notEmpty>

  <jsp:include page="EditSearchQueryView.jsp" flush="true" />
</logic:equal>

<logic:equal name="form" property="editMode" value='<%=CreateCategoryForm.EDITMODE_CATEGORY%>'>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <logic:present name="<%=org.apache.struts.Globals.ERROR_KEY%>">
  <html:messages id="error" message="false">
  <tr><td align="left" nowrap="nowrap" colspan="2"><span class="error"><b><vkc:write name="error"/></b></span></td></tr>
  </html:messages>
  <tr><td colspan="2"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" height="5" border="0"/></td></tr>
  </logic:present>

  <tr>
    <td width="100%" valign="top">
      <table cellspacing="1" cellpadding="2" width="100%" height="100%" border="0">
        <logic:equal name="form" property="parentCategory.documentCategory" value="true">
        <tr>
          <td colspan="2">
            <table width="100%">
              <tr>
                <td align="left" nowrap="nowrap"><b><vkc:message key="category.create"/></b></td>
                <td align="right" nowrap="nowrap">&nbsp;<vkc:message key="mandatory.field1"/>&nbsp;<vkc:img page="/templates/${template.name}/gfx/mandatoryField.gif" alt="*" border="0"/>&nbsp;<vkc:message key="mandatory.field2"/></td>
              </tr>
            </table>
          </td>
        </tr>
        </logic:equal>

        <logic:equal name="form" property="parentCategory.documentCategory" value="false">
        <tr>
          <td colspan="2">
            <table width="100%">
              <tr>
                <td align="left" nowrap="nowrap"><b><vkc:message key="category.create.project.subfolder"/>:</b></td>
                <td align="right" nowrap="nowrap">&nbsp;<vkc:message key="mandatory.field1"/>&nbsp;<vkc:img page="/templates/${template.name}/gfx/mandatoryField.gif" alt="*" border="0"/>&nbsp;<vkc:message key="mandatory.field2"/></td>
              </tr>
            </table>
          </td>
        </tr>
        </logic:equal>

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

		<tr>
          <td align="left" nowrap="nowrap"><b><vkc:message key="category.parentCategory"/>:&nbsp;</b></td>
		    <td colspan="1">
		      <table cellpadding="0" cellspacing="0">
		        <tr>
		          <td>
		            <logic:iterate id="pathdescr" name="form" property="parentCategory.absPathDescr.pathNodes" indexId="index">
		            <logic:greaterThan name="index" value="0">
		            <span dir="ltr">
		            <vkc:img page="/templates/${template.name}/gfx/dot.gif" border="0" alt=""/>
		            </span>
		            </logic:greaterThan>
		
		            <logic:equal value="true" name="pathdescr" property="lastNode">
		            <span dir="ltr">
		            <b><vkc:write name="pathdescr" property="pathName"/></b>
		            </span>
		            </logic:equal>
		
		            <logic:equal value="false" name="pathdescr" property="lastNode">
		            <span dir="ltr">
		            <vkc:write name="pathdescr" property="pathName"/>
		            </span>
		            </logic:equal>
		            </logic:iterate>
		          </td>
		        </tr>
		      </table>
		    </td>
		  </tr>

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

    	<logic:equal name="form" property="tinyMCECompatible" value="true">
	    	<logic:equal name="form" property="showTinyMCEToolbar" value="false">
				<style type="text/css">
				.mceToolbar {
				    display:none;
				}
				</style>
	    	</logic:equal>
    	</logic:equal>

        <tr>
          <td align="left" nowrap="nowrap"><b><vkc:message key="vkc.name"/>:&nbsp;<vkc:img page="/templates/${template.name}/gfx/mandatoryField.gif" alt="*" border="0"/></b></td>
          <td width="100%" align="left"><vkc:text property="name" style="width:100%;"/></td>
        </tr>

        <tr>
          <td align="left" nowrap="nowrap"><b><vkc:message key="vkc.keywords"/>:</b></td>
          <td width="100%" align="left"><vkc:text property="keywords" style="width:100%;" onfocus="return showHelpText();" onblur="return nd();"/></td>
        </tr>
		
      <tr>		
        <td align="left" valign="top" nowrap="nowrap"><b><vkc:message key="vkc.description"/>:</b></td>
        <td width="100%" align="left" valign="top">
	    <logic:equal name="form" property="tinyMCECompatible" value="true">  
	      <logic:equal name="form" property="showTinyMCEToolbar" value="true">
		  <vkc:link href="javascript:toggleTinyMCEToolbar();"><vkc:img page="/templates/${template.name}/gfx/minus-big.gif" border="0" titleKey="vkc.string.htmleditor"/></vkc:link>
	      </logic:equal>
	      <logic:equal name="form" property="showTinyMCEToolbar" value="false">
		  <vkc:link href="javascript:toggleTinyMCEToolbar();"><vkc:img page="/templates/${template.name}/gfx/plus-big.gif" border="0" titleKey="vkc.string.htmleditor"/></vkc:link>
	      </logic:equal>
	    </logic:equal> 
		  
          <vkc:textarea property="description" cols="57" rows="7" style="width:100%;"/>
        </td>
      </tr>

      <logic:equal name="form" property="hasPermissionForSearchQueries" value="true">
      <vkc:hline bottomSpace="0" topSpace="0" colspan="2" lineClass="hline" lineHeight="1"/>

      <tr>
        <td align="left" valign="top"><b><vkc:message key="vkc.searchquery"/>:</b></td>
        <td width="100%" align="left">
          <table>
            <logic:equal name="form" property="emptyQuery" value="false">
            <tr>
              <td width="100%" align="left"><vkc:write name="form" property="localizedSearchQuery" filter="false"/></td>
              <td width="1%" align="left" valign="bottom"><vkc:button property="action.edit.searchquery" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.edit"/></vkc:button></td>
              <td width="1%" align="left" valign="bottom"><vkc:button property="action.delete.searchquery" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.delete"/></vkc:button></td>
            </tr>
            </logic:equal>

            <logic:equal name="form" property="emptyQuery" value="true">
            <tr>
              <td width="100%" align="left"><vkc:message key="vkc.searchquery.empty"/></td>
              <td width="1%" align="left" valign="bottom"><vkc:button property="action.edit.searchquery" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.create"/></vkc:button></td>
            </tr>
            </logic:equal>
          </table>
        </td>
      </tr>
      </logic:equal>

      <logic:notEmpty name="form" property="addCatAttributes">
      <%-- Beginn Verwaltung globaler Attribute --%>
      <vkc:hline bottomSpace="0" topSpace="0" colspan="2" lineClass="hline" lineHeight="1"/>

      <logic:iterate id="fieldName" indexId="fieldCtr" name="form" property="addCatAttributeKeys" type="java.lang.String">
      <tr>
        <td align="left"><b><vkc:write name="form" property='<%= String.valueOf( "addCatAttributeName(" + fieldName + ")" ) %>'/>:</b><logic:equal name="form" property='<%= String.valueOf( "addCatAttributeAllowNull(" + fieldName + ")" ) %>' value="false">&nbsp;<vkc:img page="/templates/${template.name}/gfx/mandatoryField.gif" alt="*" border="0"/></logic:equal></td>
        <td align="left"><vkc:text name="form" property='<%= String.valueOf( "addCatAttributeValue(" + fieldName + ")" ) %>' style="width:100%;"/></td>
      </tr>
      </logic:iterate>
      </logic:notEmpty>

      <!-- Beginn - Verwaltung dynamischer Attribute -->
      <vkc:hline bottomSpace="0" topSpace="0" colspan="2" lineClass="hline" lineHeight="1"/>

      <tr>
        <td align="left" valign="top" nowrap="nowrap"><b><vkc:message key="vkc.string.dynaAttributes"/>:</b></td>

        <logic:empty name="form" property="dynaAttributes">
        <td width="100%" align="left"><vkc:button property="action.add.dynaattribute" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.addDynaAttribute"/></vkc:button></td>
        </logic:empty>

        <logic:notEmpty name="form" property="dynaAttributes">
        <td width="100%" align="left">
          <a name="dynaattributes"></a>
          <table width="100%" cellspacing="3" cellpadding="0" border="0">
            <tr>
              <td>&nbsp;</td>
              <td width="200" ><b><vkc:message key="vkc.string.name"/>:</b>&nbsp;<vkc:img page="/templates/${template.name}/gfx/mandatoryField.gif" alt="*" border="0"/></td>
              <td width="100%"><b><vkc:message key="vkc.string.value"/>:</b></td>
              <td>&nbsp;</td>
            </tr>

            <logic:iterate id="dynaAttribute" name="form" property="dynaAttributes" indexId="index">
            <tr>
              <td align="right"><b><%=String.valueOf( ( (Integer)index ).intValue() + 1 ) + "."%></b></td>
              <td align="left" nowrap="nowrap"><input type="text" name="dynaAttributeLabel_<%=index%>" value="<vkc:write name='dynaAttribute' property='label'/>" style="width:200px;"></td>
              <td width="100%" align="left"><input type="text" name="dynaAttributeValue_<%=index%>" value="<vkc:write name='dynaAttribute' property='value'/>" style="width:100%;"></td>
              <td align="left" ><vkc:image page="/templates/${template.name}/gfx/button-deletecategory.gif" property="action.delete.dynaattribute" onclick='<%= String.valueOf( "return deleteAttribute(" + index + ")" )%>' titleKey="category.remove.attribute"/></td>
            </tr>
            </logic:iterate>

            <tr>
              <td align="left" colspan="2"><vkc:button property="action.add.dynaattribute" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.addDynaAttribute"/></vkc:button></td>
            </tr>
          </table>
        </td>
        </logic:notEmpty>
      </tr>
      <!-- Ende - Verwaltung dynamischer Attribute -->

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

      <tr>
        <td>&nbsp;</td>
        <td align="left">
          <table width="1%" cellpadding="0" cellspacing="0" border="0">
            <tr>
              <td nowrap="nowrap"><html:radio name="form" property="permissionsSettings" value="<%=CreateCategoryForm.PERMISSIONS_COPY_FROM_PARENT.toString()%>"/></td>
              <td nowrap="nowrap"><vkc:message key="category.copy_parent_acl"/></td>
              <td nowrap="nowrap">&nbsp;</td>
              <td nowrap="nowrap"><vkc:link href="javascript:previewParentAcl();" titleKey="vkc.preview.parent.acl"><vkc:img page="/templates/${template.name}/gfx/button-acl-view.gif" border="0" alt=""/></vkc:link></td>
            </tr>
            <tr>
              <td nowrap="nowrap"><html:radio name="form" property="permissionsSettings" value="<%=CreateCategoryForm.PERMISSIONS_COPY_FROM_DEFAULT.toString()%>"/></td>
              <td nowrap="nowrap"><vkc:message key="category.copy_default_acl"/></td>
              <td nowrap="nowrap">&nbsp;</td>
              <td nowrap="nowrap"><vkc:link href="javascript:previewDefaultTargetAcl();" titleKey="vkc.projectmgmt.preview_acl"><vkc:img page="/templates/${template.name}/gfx/button-acl-view.gif" border="0" alt=""/></vkc:link></td>
            </tr>
          </table>
        </td>
      </tr>

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

      <tr>
        <td align="center" nowrap="nowrap" colspan="2">
          <vkc:button property="action.create" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.create"/></vkc:button>
          <vkc:button property="action.cancel" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.cancel"/></vkc:button>
        </td>
      </tr>
    </table>
    </td>
  </tr>
</table>
</logic:equal>
</html:form>
</body>
</html:html>