<%@language = "javascript" %>
<%  Server.ScriptTimeout=6000; %>
<% /*
     $Revision$
     $Id$

    File:               ins_xcp_multi.asp
    Description:        Multi editten van de exception (xcp) waarden van de priodieke taken.
    Parameters:         ins_keys

    Context:
    Note:

*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/save2db.inc" -->
<!-- #include file="../Shared/calendar.inc" -->
<!-- #include file="../Shared/kostenplaatsselector.inc" -->
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="../Shared/kenmerk_common.inc" -->
<!-- #include file="./ins_flexkenmerk.inc" -->
<!-- #include file="ins.inc" -->

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

%>
<html>
  <head>
<%  FCLTHeader.Generate(); %>
<%
    var posting = getQParamInt("post", 0) == 1;
    if (!posting)
    { %>
        <script type="text/javascript">
          $(function()
          {
            var insKeyString = FcltMgr.dialogArguments().insKeyString;
            var srtcontrolekeyArray = FcltMgr.dialogArguments().srtcontrolekeyArray;
            var xcpkeyArray = FcltMgr.dialogArguments().xcpkeyArray;
            var scenKeyArray = FcltMgr.dialogArguments().scenKeyArray;
            $("#ins_keys").val(insKeyString);
            $("#srtcontkeys").val(srtcontrolekeyArray);
            $("#xcpkeys").val(xcpkeyArray);
            $("#scenkeys").val(scenKeyArray);
            document.forms.u2.submit();
          });
        </script>
      </head>

      <body class="fclt-modal"
            id="mod_mjbinclscen">
            <% MODAL_START(); %>
        <div class="busyloading" style="width:100%;position: top"><span><%=I("fa-fclt-spinner fa-4x")%></span></div>
          <form name="u2" id="u2" action="ins_xcp_multi.asp?post=1"  method="post">
            <input type="hidden" name="ins_keys" id="ins_keys" value="">
            <input type="hidden" name="srtcontkeys" id="srtcontkeys" value="">
            <input type="hidden" name="xcpkeys" id="xcpkeys" value="">
            <input type="hidden" name="scenkeys" id="scenkeys" value="">
<%
            protectRequest.inputToken();
%>
          </form>
        <% MODAL_END(); %>
      </body>
<%  }
    else
    {
      protectRequest.validateToken();

      var ins_key_arr = getFParamIntArray("ins_keys");
      var srtcont_key_arr = getFParamIntArray("srtcontkeys");
      var xcp_key_arr = getFParamIntArray("xcpkeys", null, true); // Waarden -1 in de array wordt toegestaan en niet gezien als een lege array.
      var scen_key_arr = getFParamIntArray("scenkeys");

      var ins_xcp_active_cost = S("ins_xcp_active_cost");

      var result = {};
      var tobeedited = 0;
      var ingesloten = [];
      var ingeslotensrtc = [];
      var ingeslotenxcp = [];
      var ingeslotenscen = [];
      var showPeriod = true;
      // Bepaal de objecten in de selectie die
      // ook echt gewijzigd kunnen of mogen worden.
      for (var i = 0; i < ins_key_arr.length; i++)
      {
        // Mag ik de exceptions (xcp) waarden van de taak wijzigen?
        var this_ins = ins.func_enabled_deel(ins_key_arr[i],
                                             { srtcont_key: srtcont_key_arr[i],
                                               scen_key: scen_key_arr[i]
                                             });

        if (this_ins.canChangeXcp || this_ins.hasAnyWriteXcp) // Alleen afhankelijk van rechten.
        {
          ingesloten.push(ins_key_arr[i]);
          ingeslotensrtc.push(srtcont_key_arr[i]);
          ingeslotenxcp.push(xcp_key_arr[i]);
          ingeslotenscen.push(scen_key_arr[i]);
          tobeedited++;
          if (!this_ins.canChangeCycle)
            showPeriod = false;
        }
      }

      user.auth_required_or_abort(tobeedited > 0); // Melding geven dat de user geen rechten heeft om de wijzigingen door te voeren.
%>

      <script type="text/javascript">
        var ins_xcp_active_cost = <%=ins_xcp_active_cost%>;

        function ins_submit()
        { // Invoer van velden wordt realtime gevalideerd.
          $.post($("form[name=u2]")[0].action,
                 $("[name=u2]").serialize(),
                 FcltCallbackClose,
                 "json");
          return true; // disable submit.
        }

        function ins_cancel()
        {
          FcltMgr.closeDetail(window, { cancel: true } );
        }
      </script>
    </head>


    <body class="fclt-modal" id="mod_insxcpmultiedit">
      <% MODAL_START(); %>
      <form name="u2" action="ins_xcp_multi_save.asp" method="post">
          <input type="hidden" name="ins_keys" id="ins_keys" value="<%=ingesloten.join(",")%>">
          <input type="hidden" name="srtcontkeys" id="srtcontkeys" value="<%=ingeslotensrtc.join(",")%>">
          <input type="hidden" name="scenkeys" id="scenkeys" value="<%=ingeslotenscen.join(",")%>">
          <input type="hidden" name="xcpkeys" id="xcpkeys" value="<%=ingeslotenxcp.join(",")%>">
          <input type="hidden" name="aantaltaken" id="aantaltaken" value="<%=ins_key_arr.length%>">
<%
        // Ook als de binding bits niet overeeenkomen dan mag je multi wijzigen.
        // De "vaste" kenmerken mag je altijd wijzigen en de flexkenmerken alleen als de objectsoort hetzelfde is.
        MODAL_BLOCK_START("insXcpMulti", L("lcl_ins_meta_data"), { icon: "fa-clipboard" });
        if (showPeriod)
          RWFIELDTR("periode",
                    "fldshort",
                    L("lcl_ins_controle_period"),
                    "",
                    { datatype: "number",
                      initEmpty: true,
                      fronttext: L("lcl_ins_controle_period_fronttext"),
                      reartext: "<span id='periodereartext'>" + L("lcl_ins_controle_period_rearyear") + "</span>", // MJOB is per jaar.
                      trclass: "trperiode",
                      maxlength: 3
                    });
        FCLTkostenplaatsselector("account",
                                 "sgAccount",
                                 user_key,
                                 { kostenplaatsKey: -1,
                                   label: L("lcl_prs_kosten"),
                                   showCustomLabel: true,
                                   filtercode: "A"
                                 });
        if (ins_xcp_active_cost & 1)
          RWFIELDTR("kosten1",
                    "fldshort",
                    L("ins_srtcontrole_kosten") + "&nbsp;(" + (S("currency_pref")).replace(/^\s+|\s+$/gm,'') + ")<span class='stdmjb' id='stdkosten1'></span>",
                    "",
                    { datatype: "currency",
                      initEmpty: true
                    });
        if (ins_xcp_active_cost & 2)
          RWFIELDTR("kosten2",
                    "fldshort",
                    L("ins_srtcontrole_kosten2") + "&nbsp;(" + S("currency_pref").replace(/^\s+|\s+$/gm,'') + ")<span class='stdmjb' id='stdkosten2'></span>",
                    "",
                    { datatype: "currency",
                      initEmpty: true
                    });
        if (ins_xcp_active_cost & 4)
          RWFIELDTR("kosten3",
                    "fldshort",
                    L("ins_srtcontrole_kosten3") + "&nbsp;(" + S("currency_pref").replace(/^\s+|\s+$/gm,'') + ")<span class='stdmjb' id='stdkosten3'></span>",
                    "",
                    { datatype: "currency",
                      initEmpty: true
                    });
        if (ins_xcp_active_cost & 8)
          RWFIELDTR("materiaal",
                    "fldshort",
                    L("ins_srtcontrole_materiaal") + "&nbsp;(" + S("currency_pref").replace(/^\s+|\s+$/gm,'') + ")<span class='stdmjb' id='stdmateriaal'></span>",
                    "",
                    { datatype: "currency",
                      initEmpty: true,
                      html: "onBlur='calcMateriaal()'"
                    });
        RWFIELDTR("uren",
                  "fldshort",
                  L("ins_srtcontrole_uren") + "<span class='stdmjb' id='stduren'></span>",
                  "",
                  { datatype: "currency",
                    initEmpty: true,
                    html: "onBlur='calcUren()'"
                  });
        RWFIELDTR("perc",
                  "fldshort",
                  L("ins_srtcontrole_percentage") + "<span class='stdmjb' id='stdperc'></span>",
                  "",
                  { datatype: "text",
                    initEmpty: true
                  });
        FCLTcalendar("startdatum",
                     { datum: "",
                       label    : L("lcl_ins_startdatum"),
                       volgnr: 1,
                       initEmpty: true,
                       onChange: "DateChangedStart()"
                     });
        FCLTcalendar("vervaldatum",
                     { datum: "",
                       label    : L("lcl_ins_vervaldatum") + "<span class='stdmjb' id='stdvervaldatum'></span>",
                       volgnr: 1,
                       initEmpty: true,
                       onChange: "DateChangedVerval()"
                     });
        RWTEXTAREATR("opmerk",
                     "fldtxt",
                     L("ins_srtcontrole_opmerking"),
                     "");
        MODAL_BLOCK_END();
%>
        <script type="text/javascript">
        $(function()
          {
            init_multi();
          });
        </script>
<%

        var buttons =  [];
        buttons.push({title: L("lcl_submit"), icon: "fa-fclt-save", action:"ins_submit()", singlepress: true, id: "btn_edit_submit"})
        buttons.push({title: L("lcl_cancel"), icon: "fa-fclt-cancel",  action:"ins_cancel()"})
        SIMPLE_BLOCK_START();
          CreateButtons(buttons);
        SIMPLE_BLOCK_END();
        IFACE.FORM_END();
%>
      </form>
      <% MODAL_END(); %>
    </body>
<%  } %>
</html>
<% ASPPAGE_END(); %>
