<%@  page pageEncoding="utf-8" contentType="text/html;charset=utf-8" import="com.novell.webaccess.common.JSPConduit, com.novell.emframe.dev.eMFrameUtils" %>
<%
   JSPConduit c = JSPConduit.getJSPConduit(request);
   c.stringTable("DevResources");
   c.stringTable("FwResources");
%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>


<HTML>
<HEAD>
   <TITLE><%= c.string("ProductName") %></TITLE>
   <LINK rel='stylesheet' href='<%= c.getModulesUrl() + "/dev/css/hf_style.css" %>'>
   <jsp:include page='<%= c.getPath("dev/eMFrameScripts_inc.jsp") %>' flush="true" />
   <SCRIPT LANGUAGE="JavaScript">
      function showDetails(attrName)
      {
         myWindow = window.open("webacc?taskId=<%= c.var("taskId") %>&merge=fw.TemplateBuilder_attributeDetails&nextState=AttributesDetails&User.context=<%= c.var("User.context") %>&AttributeName="+urlEncode(attrName) ,"","toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,width=450,height=220");
      }

      function showAdvanced(attrName, sel, handlerOptions)
      {
         handlerId = sel.options[sel.selectedIndex].value;
         myWindow = window.open("webacc?taskId=<%= c.var("taskId") %>&merge=fw.TemplateBuilder_advancedControl&nextState=AdvancedControlSelect&client=<%= c.var("client") %>&objectTypeName=<%= c.urlEncode(c.var("objectTypeName")) %>&AttributeName="+urlEncode(attrName)+"&handlerId="+handlerId+"&handlerOptions="+handlerOptions,"","toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,width=750,height=400");
      }

      function init()
      {
         parent.setFooterButtons(parent.nextButton | parent.backButton | parent.cancelButton);
         parent.setHeader("<% if (c.var("mode").equals("developer")) { %><%= c.string("TemplateBuilder.title") %><% } else { %><%= c.string("TaskBuilder.title") %><% } %>", "<%= c.string("TaskBuilder.SelectAttributes") %>");
      }

      // Insure that the user has selected at least one attribute
      function isPageValid()
      {
         var controls = document.form.elements;

         for(var i=0; i<controls.length; i++)
         {
            if(controls[i].type.toLowerCase() == "checkbox" && controls[i].checked)
            {
               return true;
            }
         }

         alert("<%= c.string("TaskBuilder.SelectAnAttribute") %>");
         return false;
      }
   </SCRIPT>
   <STYLE>
      select {width:200px; font-size:10px; font-face:Helvetica,Arial};
   </STYLE>
</HEAD>

<body text="#000000" bgcolor="#ffffff" onLoad="init();">
<FORM name="form" method=post action="webacc" >

<%-- WEBACC VARIABLES --%>
<INPUT type=hidden name="taskId" value="<%= c.var("taskId") %>">
<INPUT type=hidden name="User.context" value="<%= c.var("User.context") %>">
<INPUT type=hidden name="nextState" value="orderAttributes">
<INPUT type=hidden name="objectTypeName" value="<%= c.toHTML(c.var("objectTypeName")) %>">
<INPUT type=hidden name="pluginType" value="<%= c.var("pluginType") %>">
<INPUT type=hidden name="client" value="<%= c.var("client") %>">
<INPUT type=hidden name="mode" value="<%= c.var("mode") %>">
<INPUT type=hidden name="merge" value="fw.TemplateBuilder_reorder">
<INPUT type=hidden name="error" value="dev.GenErr">
<INPUT type=hidden name="Task.outputQueryString" value="false">


<DIV class=instructions><%= c.string("TaskBuilder.AttributesInstructions") %></DIV><BR>

<DIV class=instructions>* = <%= c.string("TaskBuilder.RestrictedControls") %></DIV><BR>


<TABLE border="0" bgcolor="#FFFFFF" cellpadding="3" cellspacing="0">

	<%-- column header --%>
   <TR bgcolor="#FFFFFF">
      <TD></TD>
	  <TD><font face="Trebuchet MS,Helvetica,Arial" size="-1">&nbsp;</font></TD>
	  <TD><font face="Trebuchet MS,Helvetica,Arial" size="-1"><b><%= c.string("TaskBuilder.AttributeName") %></b></font></TD>
	  <TD><font face="Trebuchet MS,Helvetica,Arial" size="-1"><b><%= c.string("TaskBuilder.AvailableControls") %></b></font></td>
   </TR>

   <% int size = Integer.parseInt(c.var("attributes.count"));
      for(int i=0; i<size; i++) { %>
         <TR <% if (i%2 == 0) { %>bgcolor="#efeee9"<% } %>>
         <TD><img src="<%= c.getModulesUrl() + "/dev/images/dir/" + c.var("attributes." + i + ".image") %>" alt="<%= c.toDisplay(c.var("attributes."+i+ ".imageAlt")) %>" title="<%= c.toDisplay(c.var("attributes."+i+ ".imageAlt")) %>"></TD>
            <TD align="center">
               <% if (c.var("attributes." +i+ ".required").equals("true")){ %>
                  <INPUT type="checkbox" name="CB" value="<%= c.toDisplay(c.var("attributes."+i+ ".name")) %>" checked onClick="this.checked=true">
               <% }else{ %>
                  <INPUT type="checkbox" name="CB" value="<%= c.toDisplay(c.var("attributes."+i+ ".name")) %>" <% if (c.var("attributes."+i+ ".uihandler.count").equals("0")) { %>disabled<% } %>>
               <% } %>
            </TD>
            <TD><A href="#" onClick="showDetails('<%= c.toScript(c.var("attributes."+i+ ".name")) %>');return false;"><%= c.toHTML(c.var("attributes."+i+ ".name")) %></A></TD>

            <% int maxj = Integer.parseInt(c.var("attributes."+i+ ".uihandler.count")); %>
            <% if (maxj > 0) { %>
               <TD>

                  <%-- show the different uihandler for the current attribute --%>
                  <SELECT name="<%= c.var("attributes." +i+ ".name") %>_handler">
                  <% for(int j=0; j<maxj; j++) {
                     String key = "attributes."+i+ ".uihandler." +j; %>
                     <option value="<%= c.var(key + ".id") %>"><%= c.toDisplay(c.var(key + ".name")) %><% if(c.var(key+".isRestricted").equals("true")) {%> *<% } %>
                  <% } %>
                  </SELECT>

                  <%-- hidden inputs to post the options (from the advanced button) --%>
                  <% for(int j=0; j<maxj; j++) { %>
                     <INPUT type=hidden name="<%= c.toDisplay(c.var("attributes."+i+ ".name")) %>+<%= c.toHTML(c.var("attributes."+i+ ".uihandler." +j+ ".id")) %>" value="<%= c.toDisplay(c.var("attributes."+i+ ".uihandler." +j+ ".options")) %>"/>
                  <% } %>
                  </TD>
               <TD><A href="#" onClick="showAdvanced('<%= c.toScript(c.var("attributes."+i+ ".name")) %>', document.form.elements['<%= c.toScript(c.var("attributes."+i+ ".name")) %>_handler'] ,'');return false;"><%= c.string("TaskBuilder.Advanced") %></A></TD>
            <% } else { %>
               <TD><%= c.string("None") %></TD>
               <TD></TD>
            <% } %>
	   </TR>
   <% } %>

</TABLE>

</FORM>
</BODY>
</HTML>
