AgileApps Support Wiki Pre Release

DirectoryPopup.jsp

From AgileApps Support Wiki
<%-- Directory Search Demo --%>
<%

 String object_id = request.getParameter("object_id");
 String keyword = request.getParameter("keyword");
 if (keyword == null)
     keyword = "";
 String target_field = request.getParameter("target_field");
 String target_name_field = request.getParameter("target_name_field");

    java.util.HashMap params = new java.util.HashMap();
    String searchType = null;
        String searchString = null;
    String message = null;
    String offset_current = "0";

    if(controllerResponse != null){
        params = (java.util.HashMap)controllerResponse.getData();
        message = controllerResponse == null? "" : controllerResponse.getMessage();
    }
    else
    {
    %>
    <script>
        window.location.href= "/networking/controller/com/platform/demo/samples/DirectoryPopupController?action=search&object_id=<%= object_id %>&keyword=<%=keyword%>&target_field=<%=target_field%>&target_name_field=<%=target_name_field%>";
    </script>
    <%
    }

    if(params != null)
    {
        searchType = params.get("searchType") == null ? "" : (String) params.get("searchType");
        searchString = params.get("keyword") == null ? "" : (String) params.get("keyword");
        offset_current = params.get("offset") == null ? "0" : (String) params.get("offset");
    }

    int offset_previous = Integer.parseInt(offset_current) - 1;
    if(offset_previous < 0)
       offset_previous = 0;
    int offset_next = Integer.parseInt(offset_current) + 1;


%>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Directory Search Demo</title>
 <style type="text/css">

.body1 {
    background-color: #DCDEEE;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    line-height: 24px;
    color: #336699;
}

.td1 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    color: #333333;
}

.a1 {
    color: #3366CC;
    text-decoration: none;
}

.form1 {
    background-color: #CCCC99;
    padding: 6px;
}

.title1 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 24px;
    background-color: #006666;
    color: #DCDCDC;
    padding: 10px;
}

.header1 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    background-color: #006666;
    color: #DCDCDC;
    font-weight: bold;
}

 </style>


</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="33%" class="title1">Employee Directory</td>
    <td width="33%" class="title1"> </td>
    <td width="33%" align="right" valign="middle" class="title1">
     <table width="30%" border="0" cellpadding="0" cellspacing="0">

    <tr>

    <td class="td1">
      <form name="mainForm" action="/networking/controller/com/platform/demo/samples/DirectoryPopupController" method="POST" class="form1">
          <input type="hidden" name="action" value="search" />
            <table>
                <tr>
                    <td> </td>
                    <td>  </td>
                    <td>Search</td>
                    <td>
                        <select name="searchType">
                            <option value="first_name">First Name</option>
                            <option value="name1">Last Name</option>
                            <option value="address">Address</option>
                            <option value="city">City</option>
                            <option value="state">State</option>
                            <option value="zip">Zip</option>
                            <option value="direct_phone">Direct Phone</option>
                            <option value="email">Email</option>
                        </select>
                    </td>
                    <td> for </td>
                    <td><input type="text" name="keyword" value="<%=keyword%>" />
                        <input type="hidden" name="offset" value="<%=offset_current%>" />
                        <input type="hidden" name="target_field" value="<%=target_field%>" />
                        <input type="hidden" name="object_id" value="<%=object_id%>" />
                        <input type="hidden" name="target_name_field" value="<%=target_name_field%>" />
                    </td>
                    <td><input type="Submit" name="Go" value="Go"></td>
                </tr>
            </table>
      </form>
      </td>

    </tr>
   </table></td>
  </tr>
  <tr>
        <td class="td1"> </td>
        <td class="td1"> </td>
  </tr>
  <tr>
        <td class="td1"></td>
        <td align="right" class="td1"> </td>
  </tr>
  <tr>
        <td class="td1"> </td>
        <td class="td1"> </td>
  </tr>
 
  <%
      Result result = null;
      if(params != null)
         result = (Result)params.get("opResult");

      if(result != null)
      {
  %>

<tr>
    <td colspan="3" class="td1"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><font color="red"><%=message%></font></td>
        <td align="right"><a href="/networking/controller/com/platform/demo/samples/DirectoryPopupController?action=search&object_id=<%= object_id %>&offset=<%=offset_previous%>&keyword=<%=keyword%>&target_field=<%=target_field%>&target_name_field=<%=target_name_field%>">Previous</a>   <a href="/networking/controller/com/platform/demo/samples/DirectoryPopupController?action=search&object_id=<%= object_id %>&offset=<%=offset_next%>&keyword=<%=keyword%>&target_field=<%=target_field%>&target_name_field=<%=target_name_field%>">Next</a></td>
      </tr>
      <tr>
         <td> </td>
         <td> </td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td colspan="3" class="td1"><table width="100%" border="0" cellspacing="1" cellpadding="5">
      <tr>
        <td align="left" nowrap="nowrap" class="header1"> </td>
        <td align="left" nowrap="nowrap" class="header1">First Name</td>
        <td align="left" nowrap="nowrap" class="header1">Last Name</td>
        <td align="left" nowrap="nowrap" class="header1">Email</td>
        <td align="left" nowrap="nowrap" class="header1">Direct Phone </td>
        <td align="left" nowrap="nowrap" class="header1">Address</td>
        <td align="left" nowrap="nowrap" class="header1">City</td>
        <td align="left" nowrap="nowrap" class="header1">State</td>
        <td align="left" nowrap="nowrap" class="header1">Zip</td>
      </tr>
  <%
    int searchCode = result.getCode();

    if(searchCode == 0)
    {
 %>
     <tr>
      <td colspan="8">No records found</td>
    </tr>
 <%
    }
    else if(searchCode > 0)
    {
        ParametersIterator iter = result.getIterator();

        while(iter.hasNext())
        {
            Parameters row = iter.next();
            String first_name = row.get("first_name");
            String last_name = row.get("name1");

                       if(first_name == null)
                          first_name= "";

                       if(last_name == null)
                          last_name= "";

            String name_value = first_name + " - " + last_name;
  %>
      <tr>
        <td align="left" bgcolor="#FFFFFF"><a href="javascript:select('<%=name_value%>','<%=row.get("record_id")%>');">
        Select </a>
    </td>
        <td align="left" nowrap="nowrap" bgcolor="#FFFFFF"><%=row.get("first_name")%></td>
        <td align="left" nowrap="nowrap" bgcolor="#FFFFFF"><%=row.get("name1")%></td>
        <td align="left" bgcolor="#FFFFFF"><a href="mailto:<%=row.get("email")%>"><%=row.get("email")%></a></td>
        <td align="left" nowrap="nowrap" bgcolor="#FFFFFF"><%=row.get("direct_phone")%></td>
        <td align="left" nowrap="nowrap" bgcolor="#FFFFFF"><%=row.get("address")%></td>
        <td align="left" nowrap="nowrap" bgcolor="#FFFFFF"><%=row.get("city")%></td>
        <td align="left" bgcolor="#FFFFFF"><%=row.get("state")%></td>
        <td align="left" bgcolor="#FFFFFF"><%=row.get("zip")%></td>
      </tr>
 <%
        }

    }
 %>

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

 <%
  }
 %>


</table>
</body>
</html>

<script>
// Use <tt>target_field</tt> and <tt>target_name_field</tt> 
// paramters value to populate the Lookup Window, 
// based on lookup fields:

function select(name,id)
{
   if (window.opener.document.mainForm.<%=target_field%>)
   window.opener.document.mainForm.<%=target_field%>.value = id;
   if (window.opener.document.mainForm.<%=target_name_field%>)
    window.opener.document.mainForm.<%=target_name_field%>.value = name;
   
    //Here we close the popup window
    window.close();
}
</script>