<%@  page pageEncoding="utf-8" contentType="text/html;charset=utf-8" import="com.novell.webaccess.common.JSPConduit2, com.novell.emframe.dev.eMFrameUtils,
                                                                             com.novell.emframe.dev.eMFrameFactory,
                                                                             com.novell.nps.utils.Utils,
                                                                             java.util.Locale,
                                                                             com.novell.emframe.fw.FwUtils,
                                                                             java.util.ResourceBundle" %>
<%@ taglib uri="/WEB-INF/iman.tld" prefix="iman" %>

<%--
   Consumer Paramaters:
     TC.controlName                          this key in HttpRequest will contain the target; (default=eDir$target)
     TC.title                                prompt to show to user
     TC.initialValues                        a packed array representing the initial contents of


   Consumer must call c.setupTargetChooser(context, resultStrings, String[] objectTypeNames)
   Consumer should call MContext.addToHistory() from the Java code after a valid object is chosen
   Consumer template must call validateTargetChooser() in javascript onExit

   Implementation Notes
     Parameters from setupTargetChooser:
       -TC.defaultPrompt
       -TC.packedObjectTypeNames
       -TC.osTypeFilter
--%>
<!-- Begin TC_inc.jsp (Default) -->
<%
   JSPConduit2 c = JSPConduit2.getJSPConduit(request);
   c.stringTable("DevResources");
   
   //------------------- Handle Deprecations ------------------------------
   //TC.objectTypeName and TC.objectTypeNames deprecated... replaced with TC.osTypeFilter
   if (c.var("TC.osTypeFilter").equals(""))
   {
      if (!c.var("TC.objectTypeNames").equals(""))
      {
         //use value from deprecated parameter TC.objectTypeNames
         c.set("TC.osTypeFilter",c.var("TC.objectTypeNames"));
      }
      else if (!c.var("TC.objectTypeName").equals(""))
      {
         //use value from deprecated parameter TC.objectTypeNames
         c.set("TC.osTypeFilter",c.var("TC.objectTypeName"));
      }
   }
   
   //TC.initialValue deprecated.... replaced with TC.initialValues
   if (c.var("TC.initialValues").equals(""))
   {
      c.set("TC.initialValues", c.var("TC.initialValue"));   
   }
   
   //TC.prompt deprecated.... replaced with TC.title
   if (c.var("TC.title").equals(""))
   {
      c.set("TC.title", c.var("TC.prompt"));
   }
      
      
   //-------------------- Validate Parameters -----------------------------
   if (c.var("TC.title").equals(""))
   {
      c.set("TC.title", c.var("TC.defaultPrompt"));
   }

   String target = eMFrameUtils.getSingleTarget(request);
   if (target!=null)
   {
      target = Utils.toTag(target);
   }
   else
   {
      String[] initialValues =  eMFrameUtils.unpack(c.var("TC.initialValues"), eMFrameFactory.getMContext(request));
      if (initialValues!=null && initialValues.length>0) target = Utils.toTag(initialValues[0]);
      else target="";
   }
   
   String pack = c.var("TC.packedObjectTypeNames");
   if (pack==null)
   {
      pack = "";
   }
%>

<SCRIPT>
   window.controlName = "<%= c.var("TC.controlName") %>";
   window.packedObjectTypeNames = "<%= pack %>";
   
   <% 
   Locale locale = FwUtils.getCurrentLocale(pageContext.getSession());
   ResourceBundle devRes = ResourceBundle.getBundle("DevResources", locale);
   
   String types = (String)pageContext.findAttribute("TC.packedObjectTypeNames");
   if (types==null)
   {
      types="";
   }
   out.println();
   out.println("   function showList()");
   out.println("   {");
   
   // output list of types
   out.println("      if(typeof targetTypes!=\"string\")");
   out.println("      {");
   out.println("         targetTypes = unpack(\"" + types + "\");");

   out.println("         var strTypes = \"\";");
   out.println("         for(var i=0; targetTypes.length>i; i++)");
   out.println("         {");
   out.println("            strTypes += \"-\" + targetTypes[i];");
   out.println("            if(targetTypes.length>i+1)");
   out.println("            {");
   out.println("               strTypes+=\"\\n\";");
   out.println("            }");
   out.println("         }");
   out.println("      }");

   out.println("      alert(\""+devRes.getString("General.validObjectTypes")+"\\n\" + strTypes);");
   out.println("   }");
   out.println();
   out.println("   function validateTargetChooser()");
   out.println("   {");
   out.println("      var f = document.forms[0];");
   out.println("      var list = new Array();");
   out.println("     list[0] = f.single.value;");

   out.println("    var packedValue = pack(list);");
   out.println("   if (packedValue==null || packedValue==\"\")");
   out.println("    {");
   out.println("      alert(\""+devRes.getString("General.NeedsObjectName")+"\");");
   out.println("       return false;");
   out.println("    }");
   out.println("    else");
   out.println("    {");
   out.println("       eval(\"f.\" + window.controlName).value = packedValue;");
   out.println("    }");

   out.println("    return true;");
   out.println("  }");
%>
</SCRIPT>

<INPUT type="hidden" name="<%= c.var("TC.controlName") %>" value="<%=c.var("TC.initialValues")%>" size="40">
<NOBR><%= c.toHTML(c.var("TC.title")) %><% if (!c.var("TC.packedObjectTypeNames").equals("")) { %> (<A href="Javascript: showList();"><%= c.string("TC.seeList") %></A>)<% } %>:</NOBR><BR>
<INPUT type="text" name="single" value="<%= target %>" size="<%= c.string("PocketUI.textboxSizeOneButton") %>" style="width:<%= c.string("UI.textboxPixel") %>">
<iman:os typeFilter="${requestScope['TC.osTypeFilter']}" control="single" history="true"/><BR>

<!-- End TC_inc.jsp (Default) -->