<% /*
     $Revision$
     $Id$

     File:          mldtagelector.inc
     Description:   Algemene interface functie om een mld-mijlpaal (mld_melding_tag) suggestbox te maken
                    Deze moet je kunnen includen en aanroepen.
     parameters     fieldName:    veldnaam van het srtperslidKey veld. Dit veld wordt gesubmit.
                    objectName:   naam van het suggest object dat wordt aangemaakt.
                    params:       object met meegegeven parameters.
*/ %>

<%
FCLTHeader.Requires({ plugins: ["suggest", "jQuery"], js: [] });

function FCLTmldtagselector(fieldName, objectName, params)
{
  if (typeof params == "undefined") params = {};
  var isMobile = ("mobile" in params) ? params.mobile : (typeof mobile != "undefined");

  var lwhenEmpty = (params.whenEmpty != null ? params.whenEmpty :  (params.readonly ? L("lcl_select_readonly") : L("lcl_select_mldtag")));
  var lvalueText = "";
  var lextraInit = "";
  if (params.initKeyArr && params.initKeyArr.length > 0)
  {
      var sql = "SELECT mld_melding_tag_key"
              + "     , mld_melding_tag_naam"
              + "  FROM mld_melding_tag"
              + " WHERE mld_melding_tag_key = " + (params.initKeyArr).join(",");

      var oRs = Oracle.Execute(sql);
      lvalueText = oRs("mld_melding_tag_naam").value;
      oRs.Close(); // close the recordset
  }

    // Bouw de url voor de query op
  var functieQueryUrl = rooturl + "/appl/shared/suggest/SuggestMldTag.asp?x=x"
                  + (params.filtercode? "&filtcode=" + params.filtercode : "")
                  + (params.srtdisc_key? "&srtdisc_key=" + params.srtdisc_key : "");
  if (params.label)
  { %><tr <%=params.trclass?"class='"+params.trclass+"'":""%>>
    <td class="label">
      <label for="<%=fieldName%>_show"><%=params.label%></label>
    </td>
    <td>
<%
  }
  if (params.readonly)
  {
%>
    <span id="<%=fieldName%>_show" class="readonly fld<%=params.moreinfo ? ' details' : '' %>"><%=safe.html(lvalueText)%></span>
    <input type="hidden" id="<%=fieldName%>" name="<%=fieldName%>" value="<%=params.initKeyArr[0]%>">
<%
  } else {
%>
  <div<%=isMobile ? ' class="input-icon-wrapper"' : ''%>>
    <input id="<%=fieldName%>_show" class="fld<%=params.required ? ' required' : ''%><%=isMobile ? MOBILE_UI_CLASSES.input : ""%>"
           value="<%=safe.htmlattr(lvalueText)%>" placeholder="<%=safe.htmlattr(lwhenEmpty)%>"
           <%=params.onChange ? " sgonChange='" + params.onChange + "'" : ""%>>
    <input type="hidden" id="<%=fieldName%>" name="<%=fieldName%>" value="<%=params.initKeyArr[0]%>">
<%
    if (params.extraParamField)
    { /* het extra parameter veld wordt door suggest object gevuld */
%>
      <input type="hidden" id="<%=params.extraParamField%>" name="<%=params.extraParamField%>" value="<%=safe.htmlattr(lextraInit)%>">
<%
    }
%>
  </div>
<%
  }
  if (params.label)
  {
%>
    </td></tr>
<%
  }
  if (!params.readonly)
  {
    if (params.urlAdd)
    {
      var urlAddTxt = "[";
      for (var i = 0; i < params.urlAdd.length; i++)
      {
        urlAddTxt += (i > 0? ", " : "") + "{ urlParam: \"" + params.urlAdd[i].urlParam + "\", field: \"" + params.urlAdd[i].field + "\" }";
      }
      urlAddTxt += "]"
    }
%>
    <script type="text/javascript">
      $(function()
      {
        <%=objectName%> = new Suggest({ objectName: "<%=objectName%>",
                                        queryField: $("#<%=fieldName%>_show")[0],
                                        queryUrl: "<%=functieQueryUrl%>",
                                        initKey: <%=params.initKeyArr[0] ? params.initKeyArr[0] : -1%>,
                                        icon: "fa-bullseye-arrow",
                                        keyField: $("#<%=fieldName%>")[0]
                                        <%=params.urlAdd? ", urlAdd: " + urlAddTxt : ""%>
                                        <%=params.extraParamField? ", extraParamField: $(\"" + "#" + params.extraParamField + "\")[0]" : ""%>
                                        <%=params.extraParamField? ", initExtraParam: \"" + safe.jsstring("" + lextraInit) + "\"": ""%>
                                        <%=params.isBad? ", isBad: true": ""%>
                                        <%=params.readonly? ", fieldReadonly: true": ""%>
                                        <%=params.multitoggle? ", multitoggle: true" : ""%>
                                        <%=params.addfixedoption? ", addfixedoption: JSON.parse(\"" + safe.jsstring(JSON.stringify(params.addfixedoption)) + "\")": ""%>
                                      });
      });
    </script>
<%
  }
}
%>