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

     File:          mjb_dragdropyear.asp
     Description:   Invoer aantal jaren voor het verschuiven van taken in het MJOB overzicht.
     Parameters:    Geen.
     Context:       Vanuit mjb_search_list.asp.

*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<%
var ctrdisc_key = getQParamInt("ctrdisc_key", -1); // Ctrdiscipline
var ins_key_arr = getQParamIntArray("ins_keys", []);
var jaar = getQParamInt("jaar", -1);
var plan_opm = getQParam("plan_opm", "");
user.anything_todo_or_abort(ins_key_arr.length > 0); // We klagen niet over enkele wel en enkele niet

if (ctrdisc_key > 0)
    lcl.set_dialect(ctrdisc_key, "INS_TAB_DISCIPLINE_KEY");

%>
<html>
  <head>
<%  FCLTHeader.Generate(); %>
      <script type="text/javascript">

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

        async function mjb_submit()
        {
          if (!await validateForm("u2"))
            return false;
<%        if (jaar == -1)  %>
            var year = $("#dragdropyear").val();
<%        else             %>
            var year = <%=jaar%>;
          var minyear = <%=Math.max(S("mjb_freeze_year"), new Date().getFullYear())%>;
          var toyear = new Date().getFullYear() + <%=S("mjb_show_years")%>;
          var movemaxyears = toyear - minyear;

          // minyear = inclusive
          // toyear  = exclusive -> consistent with mjb_search.asp ('toyear')

          if ( year <= -movemaxyears                   ||
              (year >= movemaxyears && year < minyear) ||
               year >= toyear
             )
          {
            FcltMgr.alert(L("lcl_mjb_between_years").format(minyear, toyear-1, movemaxyears-1));
            return false;
          }

          FcltMgr.closeDetail(window, { year: year, plan_opm: $("#remark").val() } );
        }

        $(function()
        {
          $("#dragdropyear").focus();
        });

      </script>
  </head>

  <body class="fclt-modal" id="mod_mjbdragdropyears">
  <% MODAL_START(); %>
    <form id="dragdropyearsform" name="dragdropyearsform" action="javascript:mjb_submit()" method="post">
<%
      MODAL_BLOCK_START("mldDragDropYears", L("lcl_shared_needed_info"), { "icon": "fa-memo-circle-info" });

      if (jaar != -1) {
        ROFIELDTR("fld", L("lcl_mjb_years"), jaar, { datatype: "number" })
      }
      else
      {
        RWFIELDTR("dragdropyear", "fld", L("lcl_mjb_years"), "", { required: true, datatype: "number" })
      }
      RWTEXTAREATR("remark", "fldtxt", L("lcl_mjb_plan_opmerking"), plan_opm, { maxlength: 4000 });

      MODAL_BLOCK_END();

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