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

    File:        prs_inzetbaar_list.asp
    Description: Geeft inzetbaarheidslijst van persoon
    Parameters:
       prs_key   Key van persoon

    Context:     Vanuit prs_perslid.asp of prs_contactpersoon.asp
    Note:
*/ %>

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

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

var prs_perslid_key = getQParamInt("prs_key");
var showall = getQParamInt("showall", 0) == 1;

var prsauthparams = prs.checkAutorisation(prs_perslid_key);

if (prsauthparams.readcontact)
{
  var canAdd = prsauthparams.writecontact;
}
else
{
    var autfunction = "WEB_PRSMAN";
    var authparams = user.checkAutorisation(autfunction);

    var canAdd = (authparams && authparams.ALGwritelevel < 9 && authparams.PRSwritelevel < 9);
}
%>

<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 prsInzetbaarEdit(row)
      {
        var prsData = JSON.parse(row.getAttribute("ROWDATA"));
        FcltMgr.openModalDetail("../prs/prs_edit_inzetbaar.asp?prs_inzetbaar_key=" + prsData.key, L("lcl_prs_inzetbaar"), { callback: refreshall });
      }

      function prsInzetbaarDelete(row)
      {
        FcltMgr.confirm(L("lcl_prs_del_txt_inzetbaar"), function() {
            var prsData = JSON.parse(row.getAttribute("ROWDATA"));
            var data = {
                prs_inzetbaar_key: prsData.key
            };
            <% protectRequest.dataToken("data"); %>
            $.post("prs_inzetbaar_delete.asp",
                data,
                FcltCallbackRefresh,
                "json");
        });
      }
    </script>
  </head>

  <body id="listbody">
<%  var sql = "SELECT pi.prs_perslid_inzetbaar_key"
            + "     , pi.prs_perslid_key"
            + "     , pi.prs_perslid_inzetbaar_van"
            + "     , pi.prs_perslid_inzetbaar_tot"
            + "     , pi.prs_perslid_inzetbaar_dag"
            + "     , pi.prs_perslid_inzetbaar_plaats"
            + "  FROM prs_perslid_inzetbaar pi"
            + "     , prs_perslid p"
            + " WHERE pi.prs_perslid_key = p.prs_perslid_key"
            + "   AND pi.prs_perslid_key = " + prs_perslid_key
            + " ORDER BY pi.prs_perslid_inzetbaar_dag";

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

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

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

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

    var addButton = [];
    var addurl = "../prs/prs_edit_inzetbaar.asp?prs_key=" + prs_perslid_key;
    if (canAdd)
      addButton = [{ icon: "fa-plus", title: L("lcl_add"), action: "FcltMgr.openModalDetail('" + addurl + "', '" + safe.jsstring(L("lcl_add")) + "', { callback: refreshall })" }]

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

    //rst.addColumn(new Column({caption: L("lcl_location"), content: "prs_naam"}));
    rst.addColumn(new Column({caption: L("lcl_prs_inzetbaar_dag"), content: fncolDag}));
    rst.addColumn(new Column({caption: L("lcl_from"), content: fncolVan}));
    rst.addColumn(new Column({caption: L("lcl_to"), content: fncolTot}));
    rst.addColumn(new Column({caption: L("lcl_prs_inzetbaar_plaats"), content: "prs_perslid_inzetbaar_plaats"}));

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

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