<%@language = "javascript" %>
<% /*
     $Revision$
     $Id$

     Status: 100%
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/disciplineselector.inc" -->
<!-- #include file="../Shared/stdmeldingselector.inc" -->
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="mld.inc" -->

<%
FCLTHeader.Requires({ plugins: ["suggest", "jQuery"] });
var urole = getQParamSafe("urole");
var backo  = urole == "bo";
var autfunction = '';
if (backo)
  autfunction = 'WEB_MLDBOF';
else
  autfunction = 'WEB_MLDUSE';

var mld_key = getQParamInt('mld_key');
var this_mld = mld.func_enabled_melding(mld_key);
user.auth_required_or_abort(this_mld.canContinue);
var mld_melding = mld.mld_melding_info(mld_key); // Globale variabele met alle mld_melding informatie
lcl.set_dialect(mld_melding.srtdisc, "MLD_SRTDISCIPLINE_KEY");
%>

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

    <script type="text/javascript">
      var user_kpkey = <%=user.afdeling().prs_kostenplaats_key() || -1%>;
      var user_kpnaam = "<%=safe.jsstring(user.afdeling().kpn_naam())%>";
      var user_kpmodule = "<%=user.afdeling().kpn_module()%>";
      var show_alg = (<%=mld_melding.show_alg? 1 : 0%> == 1);
      function mld_cont()
      {
        document.activeElement.blur(); // trigger laatste onChanges

        // Standaard checks op verplichte velden, datum formaat, numeriek en float formaat, currency formaat.
        if (!validateForm("rejectform"))
          return false;

        document.rejectform.submit();
        return true; // disable button
      }

      function mld_cancel()
      {
          FcltMgr.closeDetail(window, { cancel: true } );
      }

      function onChangeVakgroep(vakgroep_key)
      {
        // Melding leegmaken
        sgStdm.setValue(-1, "", true, false, null, true);
        sgStdm.CheckJustOne();
      }

      function process_stdm_info(data, textStatus)
      {
        // Zet de discipline indien niet ingevuld
        if ($("#disc").val() <= 0)
          sgDisc.setValue(data.ins_discipline_key, (data.ins_srtdiscipline_prefix != null ? data.ins_srtdiscipline_prefix + "-" : "") + data.discipline_omschrijving, false /*doonChange*/, true /*checkExist*/);
      }

      function onChangeStdMelding(stdmelding_key)
      {
        if (stdmelding_key > 0)
        {
          $.getJSON("./get_mld_info_ajax.asp",
                    { req_info: "mld_stdmelding",
                      mld_stdmelding_key: stdmelding_key,
                      mld_key: <%=mld_key%>,
                      caller_key: <%=user_key%> },
                      process_stdm_info);
        }
      }
    </script>
  </head>

  <body class="modal" id="mod_mldcontinue">
    <form id="rejectform" name="rejectform" action="mld_continue_save.asp?mld_key=<%=mld_key%>&urole=<%=urole%>" method="post">
<%
      BLOCK_START("mldContinue", L("lcl_mld_continueblok") + (mld_melding.prefix||"") + mld_key);
      // Vakgroep
      FCLTdisciplineselector("disc",
                             "sgDisc",
                             { label: L("lcl_vakgroup"),
                               disc_key: null, //mld_disc,
                               module: "MLD",
                               perslidKey: mld_melding.melder_key,
                               autfunctionKey: -1, // alles is toegestaan! authparams.autfunctionkey,
                               srtdisc_key: (S("mld_forward_all") == 1 ? null : mld_melding.srtdisc),
                               filtercode: "VD",
                               onChange: "onChangeVakgroep",
                               required: true
                             });
      // Meldingen (Discipline)
      FCLTstdmeldingselector("stdm",
                             "sgStdm",
                             { label: L("lcl_complain"),
                               perslidKey: mld_melding.melder_key,
                               autfunctionKey: -1, // alles is toegestaan! authparams.autfunctionkey,
                               srtdisc_key: (S("mld_forward_all") == 1 ? null : mld_melding.srtdisc),
                               urlAdd: [{urlParam: "disc_key", field: "disc"}],
                               stdmelding_key: null,
                               onChange: "onChangeStdMelding",
                               required: true
                             } );
      // Melder
      if (S("mld_continue_edit_issuer"))
      {
          FCLTpersoonselector("person",
                              "sgPerson",
                              { perslidKey: mld_melding.melder_key,
                                label: L("lcl_mld_name"),
                                fieldNameKey: "person",
                                moreinfo: backo,
                                autlevel: this_mld.authparams(autfunction) && this_mld.authparams(autfunction).PRSwritelevel,
                                required: true
                              });
      }
      // Opmerking die wordt opgeslagen in de oorspronkelijke opmerking

      RWTEXTAREATR("opmerk",  "fldremark", L("lcl_mld_omschr_oorsprong"), mld_melding.remark,     {html: "rows='8'", readonly: (mld_melding.mld_status==5?true:false)});
      RWTEXTAREATR("vervolg", "fldremark", L("lcl_mld_omschr_vervolg"),   mld_melding.mld_omschr, {html: "rows='8'"});
      BLOCK_END();
      var buttons =  [ {title: L("lcl_mld_continuation"), icon: "opslaan.png", action: "mld_cont()", singlepress: true, id: "btn_cont_submit"  },
                       {title: L("lcl_cancel"),           icon: "undo.png",    action: "mld_cancel()" } ];
      CreateButtons(buttons);
IFACE.FORM_END();
%>
    </form>
  </body>
</html>
