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

    File:        kpn_kpncat_list.asp
    Description:
    Parameters:  -
    Context:
    Note:
*/
%>

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

<%
FCLTHeader.Requires({ plugins:["jQuery"],
                      js: []
                    })
var kpn_key = getQParamInt("kpn_key");
var addurl = "appl/prs/kpn_edit_kpncat.asp?kpn_key=" + kpn_key;

%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script type="text/javascript">
      function refreshall(data)
      {
        if (data.refresh)
            window.location.reload();
      }

      function kpncatAdd()
      {
        var toUrl = "<%=addurl%>&kpndisc_key=-1";
        FcltMgr.openDetail(toUrl, "<%=L("lcl_add")%>");
      }

      function kpncatEdit(row)
      {
        var kpndisc_key = row.getAttribute("ROWKEY");
        var toUrl = "<%=addurl%>&kpndisc_key="+kpndisc_key+"&mode=viewUpdate";
        FcltMgr.openDetail(toUrl, "<%=L("lcl_prs_budget")%>");
      }

      function kpncatDelete(row)
      {
        var kpndisc_key = row.getAttribute("ROWKEY");
        if (confirm(L("lcl_kpn_del_txt_kpncat")))
        {
          var data = { kpndisc_key: kpndisc_key
                     };
          <% protectRequest.dataToken("data"); %>
          $.post("kpn_kpncat_delete.asp",
                 data,
                 FcltCallbackRefresh,
                 "json");
        }
      }

    </script>
  </head>

  <body id="listbody">
<%
    var autfunction = 'WEB_FINMSU';
    var authparams = user.checkAutorisation(autfunction);
    var canAdd = (authparams.ALGwritelevel < 9);

    var buttons = [];

    if (canAdd)
    {
      buttons = [{ icon: "page_refresh.png", title: L("lcl_refresh"), action: "FcltMgr.reload()" },
                 { icon: "plus.png", title: L("lcl_add"), action: "kpncatAdd()" }];
    }

    var sql = "SELECT p.prs_kostenplaatsdisc_key"
            + "     , p.ins_discipline_key"
            + "     , (SELECT CASE"
            + "               WHEN sd.ins_srtdiscipline_prefix IS NULL"
            + "               THEN ''"
            + "               ELSE sd.ins_srtdiscipline_prefix || '-'"
            + "               END || "
            +                 lcl.xsqla('md.ins_discipline_omschrijving', 'md.ins_discipline_key')
            + "          FROM ins_tab_discipline md"
            + "             , ins_srtdiscipline sd"
            + "         WHERE md.ins_srtdiscipline_key = sd.ins_srtdiscipline_key(+)"
            + "           AND md.ins_discipline_key = p.ins_discipline_key) categorie"
            + "     , p.prs_kostenplaatsdisc_limiet"
            + "  FROM prs_kostenplaatsdisc p"
            + " WHERE p.prs_kostenplaats_key = " + kpn_key
            + " ORDER BY categorie";
    var rst = new ResultsetTable({ sql: sql,
                                   keyColumn: "prs_kostenplaatsdisc_key",
                                   noPrint:true,
                                   ID: "kpncattable",
                                   buttons: buttons,
                                   title: L("lcl_kpn_kpncat_frame")
                                 });


    rst.addColumn(new Column({caption: L("lcl_bes_discipline"), content: "categorie"}));
    rst.addColumn(new Column({caption: L("lcl_prs_budget"),     content: "prs_kostenplaatsdisc_limiet", datatype: "currency"}));

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

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