<%@ LANGUAGE = JavaScript %>
<% /*
     $Revision$
     $Id$

     File:          opdr_schedule_confirm.asp
     Description:   Plannen van een specifieke opdracht.
     Parameters:
         opdr_key   Opdracht key van de opdracht die gepland moet worden.
     Context:
     Note:          A) Rechtstreeks vanuit showmode opdracht

*/
var mode = getQParamInt("mode");
var opdr_key = getQParamInt("opdr_key");
if (opdr_key > 0)
  var LOCKED_USER_OK = { "xmlnode": "opdracht", "key": opdr_key };
%>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/notes.inc" -->
<!-- #include file="../Shared/calendar.inc" -->
<!-- #include file="mld.inc" -->
<%

FCLTHeader.Requires({plugins: ["jQuery"],
                          js: ["jquery.timepicker-table.js", "notes.js"],
                         css: ["timePicker-table.css"]
                    });

var this_opdr = mld.func_enabled_opdracht(opdr_key); // wat mag ik zoal op deze opdracht

user.anything_todo_or_abort(this_opdr.canPlanDatesChange && (S("mld_ord_edit_plandates") & 2) && !(mode == 2 && !(S("mld_use_plandate2") & 2)));

var result = { opdr_key: opdr_key, message: "", success: false, canCloseMld: false };
var mld_opdr = mld.mld_opdr_info(opdr_key);
lcl.set_dialect(mld_opdr.opdr_type, "MLD_TYPEOPDR_KEY");
%>
<html>
  <head>
<%  FCLTHeader.Generate(); %>

      <script type="text/javascript">
        var mode = <%=mode%>;
        var plandate = <%=mld_opdr.mld_opdr_plandatum? mld_opdr.mld_opdr_plandatum.getTime() : 0%>;
        var plandate2 = <%=mld_opdr.mld_opdr_plandatum2? mld_opdr.mld_opdr_plandatum2.getTime() : 0%>;
        var plandate_old = (mode == 1? plandate : plandate2);

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

        function mldScheduleCallback(data)
        {
          if (data.note_key > -1 )
            $("#note_key").val(data.note_key);

          $.post($("form[name=scheduleform]")[0].action, $("[name=scheduleform]").serialize(), FcltCallbackClose, "json");
        }

        async function mld_schedule(close)
        {
          if (!await validateForm("u2"))
            return false;

          // Is de datum wel ingevuld.
          var planddate_new = (mode == 1? $("#date_plan").val() : $("#date_plan2").val())
          if (plandate_old == planddate_new)
          {
            FcltMgr.alert(L("lcl_mld_opdr_no_date_change"));
            return false;
          }

<%        var save_note_url = "../mld/opdr_edit_note_save.asp?opdr_key=" + opdr_key; %>
          if ($(".mail_notes").length > 0 && $(".mail_notes").val().trim() != "")
          {
            var data = $("[type=checkbox], [name^=has_], #note, [name=<%=protectRequest.theVar%>]").serialize();
            var url = "<%=save_note_url%>";
            $.post(url,
                   data,
                   FcltCallbackAndThenAlways(mldScheduleCallback),
                   "json");
            return true; // disable button
          }
          else
          {
            var data = { success: true,
                         note_key: -1
                       };
            mldScheduleCallback(data);
          }

          return true; // disable button
        }

        $(function()
        {
          $("#note").focus();
        });
      </script>
  </head>

  <body class="fclt-modal" id="mod_opdraccept">
    <% MODAL_START(); %>
    <form id="scheduleform" name="scheduleform" action="opdr_schedule_save.asp" method="post">
<%
      var ttl = L("lcl_mld_opdr_number") + " " + (mld_opdr.srtdiscprefix||"") + mld_opdr.mld_key + "/" + mld_opdr.mld_opdr_bedrijfopdr_volgnr;
      MODAL_BLOCK_START("mldAccept", ttl, { icon: "fa-check" });

      if (mode == 1)
        FCLTcalendar("date_plan",
                     { label: L("lcl_opdr_plandate"),
                       datum: mld_opdr.mld_opdr_plandatum,
                       timeField: true,
                       timeStep: 15,
                       startTime: S("fac_t_startofworkday"),
                       endTime  : S("fac_t_endofworkday"),
                       initEmpty: !mld_opdr.mld_opdr_plandatum,     // initieel leeg, maar als plandatum aanwezig deze ook tonen.
                       initTimeEmpty: !mld_opdr.mld_opdr_plandatum, // idem.
                       volgnr: 1
                     } );
      else //(mode == 2)
        FCLTcalendar("date_plan2",
                     { label: L("lcl_opdr_plandate2"),
                       datum: mld_opdr.mld_opdr_plandatum2,
                       timeField: true,
                       timeStep: 15,
                       startTime: S("fac_t_startofworkday"),
                       endTime  : S("fac_t_endofworkday"),
                       initEmpty: !mld_opdr.mld_opdr_plandatum2,     // initieel leeg, maar als plandatum2 aanwezig deze ook tonen.
                       initTimeEmpty: !mld_opdr.mld_opdr_plandatum2, // idem.
                       volgnr: 2
                     } );

      RWTEXTAREATR("note",
                   "fldtxt mail_notes",
                   L("lcl_mld_note"),
                   "",
                   {html: "rows='8' cols='80'"}
                  );
      Response.Write("<tr><td></td><td>");
      notes.note_toggles("OPDR", { pkey: opdr_key });
      Response.Write("</td></tr>");
%>
      <input type="hidden" name="mode" value=<%=mode%>>
      <input type="hidden" name="opdr_key" value="<%=opdr_key%>">
      <input type="hidden" name="note_key" id="note_key" value="-1"><%
      MODAL_BLOCK_END();
      var buttons =  [ {title: L("lcl_schedule"), icon: "fa-fclt-save", action: "mld_schedule()", singlepress: true, id: "btn_schedule_submit", importance: 1},
                       {title: L("lcl_cancel"), icon: "fa-fclt-cancel", action: "mld_cancel()", importance: 3} ];
      SIMPLE_BLOCK_START();
        CreateButtons(buttons);
      SIMPLE_BLOCK_END();
      IFACE.FORM_END();
%>
    </form>
    <% MODAL_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
