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

    File:               MLD/opdr_edit_note.asp
    Description:        Bekijken en/of aanvullen van een notitie behorende bij een opdracht
                        in een apart blokje
    Parameters:         fronto/backo
    Context:            vanuit opdracht-detail/overzicht
    Note:
*/ %>

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

<%
FCLTHeader.Requires({ plugins: [] });

var opdr_key = getQParamInt("opdr_key");
var this_opdr = mld.func_enabled_opdracht(opdr_key); // wat mag ik zoal op deze opdracht
user.auth_required_or_abort(this_opdr.canEditOpdrNote);

mld_opdr = mld.mld_opdr_info(opdr_key);
lcl.set_dialect(mld_opdr.opdr_type, "MLD_TYPEOPDR_KEY");
%>

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

<%
  var note_key = getQParamInt("note_key", -1);
  var submitting = getQParamInt("submit", 0) == 1;

//  if (submitting)
%>

  <script type="text/javascript">
    function checkInput()
    {
      var s = $("#note").val();
      if (s.length > 4000)
      {
        s = s.substring(0, 4000);
        $("#note").val(s);
      }

      return true;
    }

    function opdr_notesubmit()
    {
      if (!checkInput())
        return false;
      if (!validateForm("u2"))
        return false;

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

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




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

  <body id="editbody">
    <div id="edit">
      <form name=u2 method=post action="opdr_edit_note_save.asp?opdr_key=<%=opdr_key%>&note_key=<%=note_key%>">
<%
        var buttons =  [ {title: L("lcl_submit"), icon: "opslaan.png", action:"opdr_notesubmit()" },
                         {title: L("lcl_cancel"), icon: "undo.png",    action:"opdr_notecancel()" }];
        IFRAMER_HEADER(L("lcl_mld_frame_notes"), buttons);
          BLOCK_START("mld_note", L("lcl_mld_note"));
            var note_oms = "";
            if (note_key > -1)
            {
              sql = "SELECT mld_opdr_note_omschrijving"
                  + "  FROM mld_opdr_note"
                  + " WHERE mld_opdr_note_key = " + note_key;
              var oRs = Oracle.Execute(sql);
              note_oms = oRs("mld_opdr_note_omschrijving").value;
            }
            RWTEXTAREATR("note", "fldtxt required", L("lcl_mld_note_new"), note_oms, {html: "rows='4' cols='80'"});
          BLOCK_END();
        IFACE.FORM_END();
%>
      </form>
    </div>

    <div id="result">
<%    var behandeling = "";
      sql = "SELECT n.mld_opdr_note_aanmaak"
          + "     , n.mld_opdr_note_key"
          + "     , pf.prs_perslid_key"
          + "     , pf.prs_perslid_naam_full"
          + "     , n.mld_opdr_note_omschrijving"
          + "  FROM mld_opdr_note n, prs_v_perslid_fullnames_all pf"
          + " WHERE n.prs_perslid_key = pf.prs_perslid_key (+)"
          + "   AND n.mld_opdr_key = " + opdr_key
          + (note_key > -1? " AND n.mld_opdr_note_key <> "+note_key : "")
          + " ORDER BY n.mld_opdr_note_aanmaak "
          + (S("mld_note_sort_ascending") == 0 ? "DESC " : "");

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

      rst.addColumn(new Column({caption: L("lcl_date_time"), content: "mld_opdr_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: "mld_opdr_note_omschrijving"}));

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