<%@language = "javascript" %>
<% /*
     $Revision$
     $Id$
*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/disciplineselector.inc" -->
<!-- #include file="../Shared/srtgroepselector.inc" -->
<!-- #include file="../Shared/srtdeelselector.inc" -->

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

var authparams = user.checkAutorisation("WEB_INSMGT");
var disc_key = getQParamInt("disc_key", -1);
var srtgroep_key = getQParamInt("srtgroep_key", -1);
var srtdeel_key = getQParamInt("srtdeel_key", -1);
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>

    <script type="text/javascript">
      function callback_ins_info(data, textStatus, jqXHR)
      { // Zet de discipline indien niet ingevuld
        // setValue(key, txt, doonChange, checkExist, extraParam, lastTry)
        if ($("#disc_key").val() == -1)
          sgDisc.setValue(data.disc_key, data.disc_omschr, false /*doonChange*/, true /*checkExist*/);
        if ($("#srtgroep_key").val() == -1)
          sgSrtgroep.setValue(data.srtgroep_key, data.srtgroep_omschr, false /*doonChange*/, true /*checkExist*/);
        if ($("#srtdeel_key").val() == -1)
          sgSrtdeel.setValue(data.srtdeel_key, data.srtdeel_omschr, false /*doonChange*/, true /*checkExist*/);
      }

      function onChangeDiscipline()
      {
        sgSrtgroep.setValue(-1, "", true, false, null, true);
        sgSrtgroep.CheckJustOne();
      }

      function onChangeSrtgroep(srtgroep_key)
      {
        if (srtgroep_key > 0 && $("#disc_key").val() <= 0 && typeof sgDisc != "undefined")
        {
          $.getJSON("../Shared/get_ins_info.asp",
                    { srtgroep_key: srtgroep_key },
                      callback_ins_info);
        }
        sgSrtdeel.setValue(-1, "", true, false, null, true);
        sgSrtdeel.CheckJustOne();
      }

      function onChangeSrtdeel(srtdeel_key)
      {
        if (srtdeel_key > 0 && ($("#srtgroep_key").val() <= 0 && typeof sgSrtgroep != "undefined"))
        {
          $.getJSON("../Shared/get_ins_info.asp",
                    { srtdeel_key: srtdeel_key },
                      callback_ins_info);
        }
        sgDeel.setValue(-1, "", true, false, null, true);
        sgDeel.CheckJustOne();
      }

      function doSubmit()
      {
          document.forms.u2.submit();
      }
    </script>
  </head>

  <body id="searchbody">
    <form name="u2" target="workFrame" action="ins_srtdeel_search_list.asp" method="get">
      <% SEARCH_PAGE_START({ header: L("lcl_filterblok") }); %>
<%      SEARCH_BLOCK_START();
        %>
<%
      RWFIELDTR("srtdeel", "fldshort", L("lcl_obj_srtdeel_code"), "", { trclass: "primsearch" });
      FCLTdisciplineselector("disc_key",
                               "sgDisc",
                               { label: L("lcl_discipline"),
                                 disc_key: disc_key,
                                 autfunctionKey: authparams.autfunctionkey,
                                 autRW: "R",
                                 module: "INS",
                                 perslidKey: user_key,
                                 onChange: "onChangeDiscipline",
                                 multitoggle: true,
                                 sgRelType: "srtgroep, srtdeel",  // Wijzigen van discipline heeft effect op de srtgroepselector en de srtdeelselector.
                                 readonly: disc_key>0
                               });

        FCLTsrtgroepselector("srtgroep_key",
                             "sgSrtgroep",
                             { label: L("lcl_obj_group"),
                               srtgroep_key: srtgroep_key,
                               autfunction: "WEB_INSMGT",
                               onChange: "onChangeSrtgroep",
                               urlAdd: [{urlParam: "disc_key", field: "disc_key"}],
                               multitoggle: true,
                               sgRelType: "srtdeel",  // wijzigen van groep heeft effect op de srtdeelselector.
                               readonly: srtgroep_key>0
                             });
        FCLTsrtdeelselector("srtdeel_key",
                            "sgSrtdeel",
                            { label: L("lcl_obj_sort"),
                              srtdeel_key: srtdeel_key,
                              module: "INS",
                              autfunction: "WEB_INSMGT",
                              onChange: "onChangeSrtdeel",
                              urlAdd: [{urlParam: "srtgroep_key", field: "srtgroep_key"},
                                       {urlParam: "disc_key", field: "disc_key"}],
                              multitoggle: true,
                              readonly: srtdeel_key>0
                            });

%>
<%      SEARCH_BLOCK_END();
        var buttons =  [ {title: L("lcl_overview_list"), action: "doSubmit()", icon: "fa-clipboard-list" } ];
        SIMPLE_BLOCK_START();
          CreateButtons(buttons, { entersubmit: true, showIcons: true} );
        SIMPLE_BLOCK_END();
%><% SEARCH_PAGE_END(); %>
      </form>

    <div id="result">
      <iframe width="100%" height="100%"
              src="../Shared/empty.asp"
              name="workFrame" id="workFrame"
              onload='FcltMgr.iframeLoaded(this)'
              frameborder="0" scrolling="no">
      </iframe>
    </div>

  </body>
</html>
<% ASPPAGE_END(); %>
