<%
  String[] hiddenField1 = ["jcrPath=/node/jcr:content", "nodetype=nt:resource", "mixintype=dc:elementSet", "visible=false"] ; 
  String[] hiddenField2 = ["jcrPath=/node/jcr:content/jcr:encoding", "visible=false", "UTF-8"] ;
  String[] hiddenField4 = ["jcrPath=/node/jcr:content/jcr:lastModified", "visible=false"] ;
  String[] hiddenField5 = ["jcrPath=/node/jcr:content/dc:date", "visible=false"] ;
  uicomponent.addHiddenField("hiddenInput1", hiddenField1) ;
  uicomponent.addHiddenField("hiddenInput2", hiddenField2) ;
  uicomponent.addCalendarField("hiddenInput4", hiddenField4) ;
  uicomponent.addCalendarField("hiddenInput5", hiddenField5) ;
%>
<div class="UIForm FormLayout">  
  <% uiform.begin() %>
  <div class="HorizontalLayout">
    <table class="UIFormGrid">
        <tr>
          <td class="FieldLabel"><%=_ctx.appRes("File.dialog.label.name")%></td>
          <td class="FieldComponent">
            <%
              String[] fieldName = ["jcrPath=/node", "mixintype=mix:votable,mix:commentable,mix:i18n,dc:elementSet", "editable=if-null", "validate=empty,name"] ;
              uicomponent.addTextField("name", fieldName) ; 
            %>
          </td>
        </tr>
				<%if(!uicomponent.getId().equals("UILanguageDialogForm")){%>
					<tr>
			      <td class="FieldLabel"><%=_ctx.appRes("File.dialog.label.categories")%></td>
			      <td class="FieldComponent">
				      <% 
				        String[] fieldCategories = ["jcrPath=/node/exo:category", "multiValues=true", "reference=true", "editable=false"];
				        uicomponent.addTextField("categories", fieldCategories);
				      %>
				    </td>
				  </tr>
			  <%}%>
        <%
        if(!uicomponent.isEditing()){%>
            <tr>                        
              <td class="FieldLabel"><%=_ctx.appRes("File.dialog.label.mimeType")%></td>
              <td class="FieldComponent">
                <%
                  String[] mimetype = ["jcrPath=/node/jcr:content/jcr:mimeType", "text/html", "options=text/html,text/plain,application/x-groovy+html", "onchange=true"] ;
                  uicomponent.addSelectBoxField("mimetype", mimetype) ;
                %>
              </td>
            </tr>
        <%}%>
		<tr>
        	<td class="FieldLabel"><%=_ctx.appRes("ElementSet.dialog.label.language")%></td>
			<td class="FieldComponent">
			<%
			  String lang = org.exoplatform.portal.webui.util.Util.getPortalRequestContext().getLocale().getLanguage();
			  String[] fieldLang = ["jcrPath=/node/exo:language", "options=en,fr,es,de", lang] ;
			  uicomponent.addSelectBoxField("lang", fieldLang) ;
			%>
			</td>
		</tr>
        <tr>
          <td class="FieldLabel"><%=_ctx.appRes("File.dialog.label.content")%></td>
          <td class="FieldComponent">
              <%
                if(uicomponent.isEditing()) { 
                  def curNode = uicomponent.getNode() ;
                  if(curNode.hasNode("jcr:content")) {
                    def content = curNode.getNode("jcr:content") ;
                    String mimeType = content.getProperty("jcr:mimeType").getString() ;
                    if(mimeType.startsWith("text") || mimeType.indexOf("groovy") >= 0){
                      if(mimeType.equals("text/html")) {
                        String[] fieldSummary = ["jcrPath=/node/jcr:content/jcr:data", "", "validate=empty"] ;
                              uicomponent.addRichtextField("contentHtml", fieldSummary) ;      
                        //uicomponent.removeComponent("content");
                      } else {
                        String[] fieldSummary = ["jcrPath=/node/jcr:content/jcr:data", "validate=empty"] ;
                              uicomponent.addTextAreaField("content", fieldSummary) ;
                      }
                    } else {
                    if (content.getProperty("jcr:data").getStream().available() > 0) {
                        def actionLink = uicomponent.event("RemoveData", "/jcr:content");
                        def fileName = curNode.getName();
                        %> 
                          <div>
                          <div style="font-size:12px; font-weight: bold; line-height: 17px;">
                       	   <%=_ctx.appRes("File.dialog.label.re-upload")%>
                          </div>
                          <a style="font-size:12px; font-weight: bold; line-height: 17px;">
                             $fileName
                          </a>
                          <a href="$actionLink">
							 <img src="/eXoResources/skin/DefaultSkin/background/Blank.gif" alt="" class="ActionIcon Remove16x16Icon"/>
						  </a>
						  </div>
                       <%
                    }else{
 			        String[] fieldData = ["jcrPath=/node/jcr:content/jcr:data"] ;
 			        uicomponent.addUploadField("data", fieldData) ;
 			        }
			        }			      
                  } else {
                    String[] fieldSummary = ["jcrPath=/node/jcr:content/jcr:data", "", "validate=empty"] ;
                                uicomponent.addRichtextField("contentHtml", fieldSummary) ;            
                  }
                } else {  
                  String selectValue = uicomponent.getSelectBoxFieldValue("mimetype") ;   
                  if(selectValue != null && selectValue.equals("text/html")) {  
                    String[] fieldSummary = ["jcrPath=/node/jcr:content/jcr:data", "", "validate=empty"] ;
                                uicomponent.addRichtextField("contentHtml", fieldSummary) ;
                    uicomponent.removeComponent("contentPlain");
                  } else if(selectValue != null && selectValue.equals("text/plain")){
                    String[] fieldSummary = ["jcrPath=/node/jcr:content/jcr:data", "validate=empty"] ;
                                uicomponent.addTextAreaField("contentPlain", fieldSummary) ;
                    uicomponent.removeComponent("contentHtml");
                  } else {
                    String[] fieldSummary = ["jcrPath=/node/jcr:content/jcr:data", "", "validate=empty"] ;
                                uicomponent.addRichtextField("contentHtml", fieldSummary) ;  
                    uicomponent.removeComponent("contentPlain");                
                  }
                }
              %>
          </td>
        </tr>       
          <tr>
            <td class="FieldLabel"><%=_ctx.appRes("ElementSet.dialog.label.title")%></td>
            <td class="FieldComponent">
              <%
                String[] fieldTitle = ["jcrPath=/node/jcr:content/dc:title", "multiValues=true"] ;
                uicomponent.addTextField("title", fieldTitle) ;
              %>
            </td>
          </tr>
          <tr>
            <td class="FieldLabel"><%=_ctx.appRes("ElementSet.dialog.label.description")%></td>
            <td class="FieldComponent">
              <%
                String[] fieldDescription = ["jcrPath=/node/jcr:content/dc:description", "multiValues=true"] ;
                uicomponent.addTextField("description", fieldDescription) ; ;
              %>
            </td>
          </tr>
          <tr>
            <td class="FieldLabel"><%=_ctx.appRes("ElementSet.dialog.label.creator")%></td>
            <td class="FieldComponent">
              <%
                String[] fieldCreator = ["jcrPath=/node/jcr:content/dc:creator", "multiValues=true"] ;
                uicomponent.addTextField("creator", fieldCreator) ;
              %>
            </td>
          </tr>
          <tr>
            <td class="FieldLabel"><%=_ctx.appRes("ElementSet.dialog.label.source")%></td>
            <td class="FieldComponent">
              <%
                String[] fieldSource = ["jcrPath=/node/jcr:content/dc:source", "multiValues=true"] ;
                uicomponent.addTextField("source", fieldSource) ;
              %>
            </td>
          </tr>
          
    </table>       
    <%/* start render action*/%>
	  <%uiform.processRenderAction()%>
    <%/* end render action*/%>
  </div>
  <%uiform.end()%>
</div>