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

    File:               cnt/cnt_edit_note.asp
    Description:        Bekijken en/of aanvullen van een notitie behorende bij een melding
                        in een apart blokje
    Parameters:         fronto/backo
    Context:            vanuit melding-detail/overzicht
    Note:               STATUS: functioneel wel ok, moet nog in redesign 5i mee.
TODO: mld-labels ver-cnt-en
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/resultset_table_v2.inc" -->
<!-- #include file="./cnt.inc" -->

<%

var cnt_key = getQParamInt("cnt_key");
var note_key = getQParamInt("note_key", -1);

var this_cnt = cnt.func_enabled_contract(cnt_key); // Wat heb ik zoal aan rechten op dit contract?
user.auth_required_or_abort(this_cnt.canWriteNotes);
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
  <script>
    $(function()
    {
      $('textarea').resize(function () { FcltMgr.resized(window) } );
      $('textarea').autogrow();
    });
  </script>
  </head>

  <script type="text/javascript">

    function checkInput()
    {
      var s = $("#note").val();
      if (s.length > 4000)
      {
        s = s.substring(0, 4000);
        $("#note").val(s);
      }
      return true;
    }

    async function cnt_notesubmit()
    {
      if (!checkInput())
        return false;
      if (!await validateForm("u2"))
        return false;

      $.post($("form[name=u2]")[0].action,
             $("[name=u2]").serialize(),
             FcltCallbackAndThenAlways(cnt_submit_callback),
             "json");
      return true;
    }

    function cnt_submit_callback(json)
    {
      if (json.success)
      {
        FcltMgr.closeDetail(window, json);
      }
    }

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

  <body class="editmode">
  <% SUBFRAME_START(); %>
  <%
  var buttons =  [ {title: L("lcl_submit"), icon: "fa-fclt-save", action: "cnt_notesubmit()", id: "cnt_edit_note", singlepress: true},
                         {title: L("lcl_cancel"), icon: "fa-fclt-cancel", action: "cnt_notecancel()"}];

  %>
  <% IFRAMER_HEADER(L("lcl_cnt_frame_notes"), buttons); %>
      <form name=u2 method=post action="cnt_edit_note_save.asp?cnt_key=<%=cnt_key%>&note_key=<%=note_key%>">
<%

          BLOCK_START("cnt_note", L("lcl_cnt_note"), {icon: "fa-clipboard-list-check"});
            var note_oms = "";
            if (note_key > -1)
            {
              sql = "SELECT cnt_contract_note_omschrijving"
                  + "  FROM cnt_contract_note"
                  + " WHERE cnt_contract_note_key = " + note_key;
              var oRs = Oracle.Execute(sql);
              note_oms = oRs("cnt_contract_note_omschrijving").value;
            }
            RWTEXTAREATR("note", "fldtxt required", L("lcl_cnt_note_new"), note_oms, {html: "rows='4' cols='80'"});
          BLOCK_END();
        IFACE.FORM_END();
%>
      </form>
<% SUBFRAME_END(); %>
    <div id="result">
<%
      sql = "SELECT n.cnt_contract_note_aanmaak"
          + "     , n.cnt_contract_note_key"
          + "     , pf.prs_perslid_naam_full"
          + "     , n.cnt_contract_note_omschrijving"
          + "  FROM cnt_contract_note n, prs_v_perslid_fullnames_all pf"
          + " WHERE n.prs_perslid_key = pf.prs_perslid_key (+)"
          + "   AND n.cnt_contract_key = " + cnt_key
          + (note_key > -1? " AND n.cnt_contract_note_key <> "+note_key : "")
          + " ORDER BY n.cnt_contract_note_aanmaak"
          + (S("mld_note_sort_ascending") == 0
            ? " DESC "
            : "");

      // Toon de overige notes onder het invulveld.
      var rst = new ResultsetTable({ sql: sql,
                                     ID: "notestable",
                                     keyColumn: "cnt_contract_note_key",
                                     noPrint: true,
                                     emptySetString : ""
                                   });

      rst.addColumn(new Column({caption: L("lcl_date_time"), content: "cnt_contract_note_aanmaak", datatype: "datetime"}));
      rst.addColumn(new Column({caption: L("lcl_mld_changedby"), content: "prs_perslid_naam_full"}));
      rst.addColumn(new Column({caption: L("lcl_mld_note"), content: "cnt_contract_note_omschrijving"}));

      var cnt = rst.processResultset();
    %>
    </div>
  </body>
</html>
<% ASPPAGE_END(); %>
