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

    File:            mld_uitvoeren_list.asp
    Description:     Geeft lijst van verzorgingsplan van mld opdracht
    Parameters:
      mld_opdr_key   Opdracht key
    Context:         Vanuit mld_opdr.asp
    Note:
*/ %>

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

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

var mld_opdr_key = getQParamInt("opdr_key");
var showall = getQParamInt("showall", 0) == 1;

var this_opdr = mld.func_enabled_opdracht(mld_opdr_key); // wat mag ik zoal op deze opdracht
user.auth_required_or_abort(this_opdr.canReadAny);
var canAdd = this_opdr.canChange;
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script type="text/javascript">
      var autosearch = 1; // automatisch laden van resultaat op search pagina
      function refreshall(data)
      {
        if (data.refresh)
          FcltMgr.reload();
      }

      function mldUitvoerenEdit(row)
      {
        var mldData = eval('(' + row.getAttribute("ROWDATA") + ')');
        FcltMgr.openModalDetail("../mld/mld_edit_uitvoeren.asp?mld_uitvoeren_key=" + mldData.key, L("lcl_prs_werkplan"), { callback: refreshall });
      }

      function mldUitvoerenDelete(row)
      {
        var mldData = eval('(' + row.getAttribute("ROWDATA") + ')');
        if (confirm(L("lcl_mld_del_txt_uitvoeren")))
        {
          var data = { mld_uitvoeren_key: mldData.key
                     };
          <% protectRequest.dataToken("data"); %>
          $.post("mld_uitvoeren_delete.asp",
                 data,
                 FcltCallbackRefresh,
                 "json");
        }
      }
    </script>
  </head>

  <body id="listbody">
<%  var sql = "SELECT ou.mld_opdr_uitvoeren_key"
            + "     , ou.mld_opdr_key"
            + "     , ou.mld_opdr_uitvoeren_van"
            + "     , ou.mld_opdr_uitvoeren_tot"
            + "     , ou.mld_opdr_uitvoeren_dag"
            + "  FROM mld_opdr_uitvoeren ou"
            + "     , mld_opdr o"
            + " WHERE ou.mld_opdr_key = o.mld_opdr_key"
            + "   AND ou.mld_opdr_key = " + mld_opdr_key
            + " ORDER BY ou.mld_opdr_uitvoeren_dag"
            + "     , ou.mld_opdr_uitvoeren_van";

    function fnrowData(oRs)
    {
      var key = oRs("mld_opdr_uitvoeren_key").value;
      var data = {key: key};
      return JSON.stringify(data);
    }

    function fncolDag(oRs)
    {
      var dag = calendar_names.days[oRs("mld_opdr_uitvoeren_dag").value]
      return dag;
    }

    function fncolVan(oRs)
    {
      var dt = new Date(); // Vandaag
      dt = new Date(dt.getFullYear(), dt.getMonth(), dt.getDate(), 0, oRs("mld_opdr_uitvoeren_van").value);
      return toTimeString(dt);
    }

    function fncolTot(oRs)
    {
      var dt = new Date(); // Vandaag
      dt = new Date(dt.getFullYear(), dt.getMonth(), dt.getDate(), 0, oRs("mld_opdr_uitvoeren_tot").value);
      return toTimeString(dt);
    }

    var addButton = [];
    var addurl = "../mld/mld_edit_uitvoeren.asp?mld_opdr_key=" + mld_opdr_key;
    if (canAdd)
      addButton = [{ icon: "plus.png", title: L("lcl_add"), action: "FcltMgr.openModalDetail('" + addurl + "', '" + L("lcl_add") + "', { callback: refreshall })" }]

    var rst = new ResultsetTable({ sql: sql,
                                   keyColumn: "mld_opdr_uitvoeren_key",
                                   noPrint: true,
                                   ID: "inzetbaartable",
                                   rowData: fnrowData,
                                   buttons: addButton,
                                   showAll: showall,
                                   title: L("lcl_mld_uitvoeren_title")
                                 });

    rst.addColumn(new Column({caption: L("lcl_mld_uitvoeren_dag"), content: fncolDag}));
    rst.addColumn(new Column({caption: L("lcl_from"), content: fncolVan}));
    rst.addColumn(new Column({caption: L("lcl_to"), content: fncolTot}));

    if (canAdd)
    {
      rst.addAction({ action: "mldUitvoerenEdit", caption: L("lcl_edit"), isDefault: true});
      rst.addAction({ action: "mldUitvoerenDelete", caption: L("lcl_delete")});
    }

    rst.processResultset();
%>
  </body>
</html>
