<% /*
     $Revision$
     $Id$

    File:               kpngroep_list.inc
    Description:        Show an overview of kostenplaats groepen items in list-form,
                        which meets with the given requirements
    Parameters:
    Context:            Search action from kpngroep_search_list.asp form
    Note:
*/ %>

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

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

 function fnrowData(oRs)
        {
          var key        = oRs("prs_kostenplaatsgrp_key").value;

          var data = {key:key};

          return JSON.stringify(data);
        }
%>
<script type="text/javascript">
  var autosearch = 1; // automatisch laden van resultaat op search pagina
  function refreshall(data)
    {
      if (data.refresh)
          window.location.reload();
    }


 function kpngroepEdit(row)
  {
    var kpnData = eval('(' + row.getAttribute("ROWDATA") + ')');
    var url = "appl/prs/kpn_kpngroep.asp?mode=viewUpdate&key="+kpnData.key;
    FcltMgr.openDetail(url, "<%=L("lcl_prs_kostenpl_group")%>" + ' ' + kpnData.key, {callback: refreshall});
  }

  function doDelete(rowArray, isMulti)
  {
    FcltMgr.confirm(L("lcl_kpn_del_txt_kostenplaatsgrp"), {
        autoconfirm: isMulti
    }, function() {
        var kpngroepKeyString = getKeyString(rowArray);
        var data = {
            key: kpngroepKeyString,
            level: "G"
        };
        <% protectRequest.dataToken("data"); %>
        $.post("prs_delete.asp",
            data,
            FcltCallbackRefresh,
            "json");
    });
  }
</script>
<%

function kpngroep_list(pautfunction, params)
{
  // De functie checkAutorisation(autfunction) geeft een Response.End indien er geen autorisatie voor autfunction wordt gevonden
  var addButton = [];

  var authparams = user.checkAutorisation("WEB_FINMSU", true);
  var canAdd = (authparams && authparams.ALGwritelevel < 9);

  // Voor resulttable de globalen zetten; zou ng anders moeten.
  var outputmode = params.outputmode; // print to 0 = screen, 1 = printer, 2 = excel, etc.
  var showall = params.showall;

  var descr = params.descr;
  var budgeth_key = params.budgeth_key;

  function fnrowActionEnabler(oRs)
    {
      /*  var eDelete = false;
        if (alg.canWriteRuimte(oRs("alg_ruimte_key").value, authparams.mALGwritelevel)) */ //Moet hier nog iets mee?
        eDelete = true;
        return ({eDelete: eDelete})
    }
%>

  <html>
    <head>
      <% FCLTHeader.Generate({outputmode:outputmode}) %>
    </head>
    <body id="listbody">
<%
  var sqln = "SELECT   kpg.prs_kostenplaatsgrp_key, "
           + "         kpg.prs_kostenplaatsgrp_oms, "
           +           S("prs_pers_string") + " naam,"
           + "         p.prs_perslid_verwijder "
           + "    FROM prs_kostenplaatsgrp kpg, "
           + "         prs_perslid p "
           + "   WHERE p.prs_perslid_key(+) = kpg.prs_perslid_key "


    if (!(authparams && authparams.ALGreadlevel < 9 && authparams.ALGwritelevel < 9)) // Geen WEB_FINMSU. Dan ben ik budgedhouder en mag ik alleen mijn kostenplaatsen zien.
      sqln += "AND kpg.prs_perslid_key = " + user_key;

    if (descr)
      {
      sqln += " AND UPPER(kpg.prs_kostenplaatsgrp_oms) LIKE " + safe.quoted_sql_wild("%" + descr + "%");
      }

    if (budgeth_key)
      {
      sqln += " AND p.prs_perslid_key = " + budgeth_key;
      }

      sqln += "ORDER BY naam "

    var addurl = "appl/prs/kpn_kpngroep.asp";

    if (canAdd)
      {
      addButton = [{ icon: "plus.png", title: L("lcl_add"), action: "FcltMgr.openDetail('" + addurl + "', '" + L("lcl_add") + "')" }]
      }

   function formatBudgethouder (oRs) {
        var prefix = ''+oRs("prs_perslid_verwijder").value != 'null' ? '<span class="deleted">' : '';
        var suffix = ''+oRs("prs_perslid_verwijder").value != 'null' ? '</span>' : '';
        if (''+oRs("naam").value != 'null')
            return prefix+safe.html(oRs("naam").value)+suffix;
    }

    var rst = new ResultsetTable({sql:sqln,
                                   keyColumn: "prs_kostenplaatsgrp_key",
                                   ID: "prstable",
                                   showAll: showall,
                                   rowData: fnrowData,
                                   rowActionEnabler: fnrowActionEnabler,
                                   outputmode: outputmode,
                                   filterParams: params,
                                   buttons: addButton
                                  });

    rst.addColumn(new Column({caption: L("lcl_prs_kostenpl_group"), content: "prs_kostenplaatsgrp_oms", hasActions: true}));
    rst.addColumn(new Column({caption: L("lcl_prs_budgethouder"), content: formatBudgethouder}));

    rst.addAction({ action: "kpngroepEdit", caption: L("lcl_edit"), isDefault:  true});
    rst.addAction({ action: "doDelete", caption: L("lcl_delete"), enabler: "eDelete", single: false, multi: true, multiOnce: true});

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