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

<%@ page import="vkc.procoba.project.CreateProjectForm" %>

<vkc:init/>
<html:html locale="true">
<head>
    <meta http-equiv="content-type"  content="text/html; charset=iso-8859-1" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="pragma"        content="no-cache" />
    <meta http-equiv="expires"       content="0" />

    <vkc:cssinclude />

    <script type="text/javascript" src="<vkc:rewrite page='/common/utils.js'/>"></script>
    <script type="text/javascript" src="<vkc:rewrite page='/common/calendar.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;

    function init(){
        setAnchor();
    }

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

    function previewSourceAcl() {
      var form = document.forms[0];
      if (form.templateIdSelect.value == 0) alert('<vkc:message javascript="true" filter="false" key="error.projectmgmt.noTemplateSelected"/>');
      else wnd = openCentered(400, 500, '<%=ctxPath%>/displayAcl.do?ownWindow=true&categoryId=' + form.templateIdSelect.value + '&init=true',"ACLVIEW");
    }

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

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

    function toggleTinyMCEToolbar() {
        var form = document.forms[0];
    	<logic:equal name="createProjectForm" property="showTinyMCEToolbar" value="true">
    	form.showTinyMCEToolbar.value = 'false';
    	</logic:equal>
    	<logic:equal name="createProjectForm" 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();
        }
    }

    </script>
</head>

<body onload="init();" onUnload="unloadPage();">
<table cellspacing="0" cellpadding="0" width="100%" border="0">
  <html:form action="/createProject" method="post">

  <bean:define id="form" toScope="page" name="createProjectForm" type="vkc.procoba.project.CreateProjectForm"/>

  <html:hidden property="parentCategoryId"/>
  <html:hidden property="sourcePageId"/>
  <logic:notEmpty name="form" property="targetId">
    <html:hidden property="targetId"/>
  </logic:notEmpty>
  <logic:notEmpty name="form" property="subTargetId">
    <html:hidden property="subTargetId"/>
  </logic:notEmpty>
  <html:hidden property="ctrlAction" value="-1"/>
  <html:hidden property="validate"   value="true"/>

  <vkc:hidden property="showTinyMCEToolbar"/>

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

    <tr>
      <td width="100%" valign="top">
        <table cellspacing="1" cellpadding="2" width="100%" height="100%" border="0">

          <tr><td align=left><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt=""  height="1" width="150"/></td><td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt=""  height="1" width="10"/></td></tr>

          <tr>
            <td colspan="2">
            <table width="100%">
              <tr>
                <td nowrap="nowrap" align="left"><b><vkc:message key="vkc.projectmgmt.newProject"/>:</b></td>
                <td nowrap="nowrap" align="right">&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>

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

          <tr><td></td><td><b><font color="#ff0000"><vkc:errors property="name"/></font></b></td></tr>

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

          <tr>
            <td align="left" width="1%" nowrap><b><vkc:message key="vkc.projectmgmt.templatecategory"/>:</b></td>
            <td align="left" width="100%">
              <bean:define property="templateInfos" name="createProjectForm" id="templateInfos"/>
              <html:select property="templateIdSelect" size="1" style="width:100%">
                <vkc:options collection="templateInfos" property="templateId" labelProperty="description"/>
              </html:select>
            </td>
          </tr>

          <tr><td></td><td><b><font color="#ff0000"><vkc:errors property="keywords"/></font></b></td></tr>

          <tr>
            <td align="left"><b><vkc:message key="vkc.keywords"/>:</b></td>
            <td align="left" width="100%"><vkc:text property="keywords" style="width:100%;"/></td>
          </tr>

          <tr>
            <td align="left" valign="top"><b><vkc:message key="vkc.projectmgmt.description"/>:</b></td>
            <td align="left" valign="top" width="100%">
	    	  <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>

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

          <tr><td colspan=2><b><font color="#ff0000"><vkc:errors property="steps"/></font></b></td></tr>

          <tr><td colspan=2><b><vkc:message key="vkc.projectmgmt.defineProjectSteps"/>:</b></td>

          </tr>

          <logic:notEmpty name="createProjectForm" property="projectSteps">
          <tr>
              <td colspan=2>
                <table cellspacing="1" cellpadding="3" width="100%" border="0" class="tableLineColor">
                    <tr>
                      <td class="headerUnselected" nowrap="nowrap" align="center">&nbsp;</td>
                      <td class="headerUnselected" nowrap="nowrap" align="center"><b><vkc:message key="vkc.projectmgmt.step.number"/></b></td>
                      <td class="headerUnselected" nowrap="nowrap" align="left" width="100%"><b><vkc:message key="vkc.projectmgmt.create.activity"/>&nbsp;<vkc:img page="/templates/${template.name}/gfx/mandatoryField.gif" alt="*" border="0"/></b></td>
                      <td class="headerUnselected" nowrap="nowrap" align="left"><b><vkc:message key="vkc.projectmgmt.create.startdate"/>&nbsp;<vkc:img page="/templates/${template.name}/gfx/mandatoryField.gif" alt="*" border="0"/></b></td>
                      <td class="headerUnselected" nowrap="nowrap" align="left"><b><vkc:message key="vkc.projectmgmt.create.enddate"/>&nbsp;<vkc:img page="/templates/${template.name}/gfx/mandatoryField.gif" alt="*" border="0"/></b></td>
                    </tr>
                      <logic:iterate id="projectStep" name="form" property="projectSteps" indexId="index" type="vkc.view.bean.NewProjectStepInfo">
                        <tr>
                          <td class="columnSelected" align="center"><html:checkbox name="projectStep" property="selected" indexed="true" /></td>
                          <td class="columnSelected" align="center">&nbsp;<%=index.intValue()+1%>&nbsp;</td>
                          <td class="columnSelected" align="left" width="100%"><vkc:text name="projectStep" property="activity" indexed="true" style="width:100%;"/></td>
                          <td class="columnSelected" align="center" nowrap="nowrap">
                            <table border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td><html:text styleClass="dateField" name="projectStep" property="startDate" indexed="true" size="10"/></td>
                                <td align="left"><vkc:calendarbutton buttonName='<%="btn_projectStep[" + index + "].startDate"%>' /></td>
                              </tr>
                            </table>
                          </td>
                          <td class="columnSelected" align="center" nowrap="nowrap">
                            <table border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td><html:text styleClass="dateField" name="projectStep" property="endDate" indexed="true" size="10"/></td>
                                <td align="left"><vkc:calendarbutton buttonName='<%="btn_projectStep[" + index + "].endDate"%>' /></td>
                              </tr>
                            </table>
                          </td>
                        </tr>
                      </logic:iterate>
                 </table>
               </td>
          </tr>
          </logic:notEmpty>

          <logic:empty name="createProjectForm" property="projectSteps">
          <tr>
            <td colspan="2"><vkc:message key="vkc.projectmgmt.nostepsdefined"/></td>
          </tr>
          </logic:empty>

          <tr>
            <td colspan="2">
              <vkc:button property="action.new.step" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="vkc.projectmgmt.create.button.newStep"/></vkc:button>
              <logic:notEmpty name="createProjectForm" property="projectSteps">
              <vkc:button property="action.delete.steps" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="vkc.projectmgmt.create.button.deleteSelectedSteps"/></vkc:button>
              </logic:notEmpty>
            </td>
          </tr>

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

          <tr><td></td><td><b><font color="#ff0000"><vkc:errors property="permissionsSettings"/></font></b></td></tr>

          <tr>
            <td align="left" width="1%" valign="top"><b><vkc:message key="vkc.projectmgmt.permissions"/>:</b></td>
            <td align="left" width="100%">
                <table border="0">

                  <logic:notEmpty name="form" property="templateInfos">
                  <tr>
                    <td><html:radio name="createProjectForm" property="permissionsSettings" value="<%=CreateProjectForm.PERMISSIONS_COPY_FROM_TEMPLATE%>"/></td>
                    <td><vkc:message key="vkc.projectmgmt.permissions.copy_source"/></td>
                    <td>&nbsp;</td>
                    <td><vkc:link href="javascript:previewSourceAcl();" titleKey="vkc.projectmgmt.preview_acl"><vkc:img page="/templates/${template.name}/gfx/button-acl-view.gif" border="0" alt=""/></vkc:link></td>
                  </tr>
                  </logic:notEmpty>

                  <tr>
                    <td><html:radio name="createProjectForm" property="permissionsSettings" value="<%=CreateProjectForm.PERMISSIONS_COPY_FROM_TARGET%>"/></td>
                    <td><vkc:message key="vkc.projectmgmt.permissions.copy_target"/></td>
                    <td>&nbsp;</td>
                    <td><vkc:link href="javascript:previewTargetAcl();" titleKey="vkc.projectmgmt.preview_acl"><vkc:img page="/templates/${template.name}/gfx/button-acl-view.gif" border="0" alt=""/></vkc:link></td>
                  </tr>
                  <tr>
                    <td><html:radio name="createProjectForm" property="permissionsSettings" value="<%=CreateProjectForm.PERMISSIONS_COPY_FROM_DEFAULT%>"/></td>
                    <td><vkc:message key="vkc.projectmgmt.permissions.default_target"/></td>
                    <td>&nbsp;</td>
                    <td><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 colspan="2" lineClass="hline" lineHeight="1" topSpace="5" bottomSpace="5"/>

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

        </table>
      </td>
    </tr>

</html:form>
</table>
</body>
</html:html>