<% /*
     $Revision$
     $Id$
    File:               alg_regio.inc
    Description:        Show an overview of regio items in list-form,
                        which meets with the given requirements
    Parameters:
    Context:            Search action from alg_regio_search_list.asp form
    Note:
*/ %>

<!-- #include file="../Shared/json2.js" -->
<!-- #include file="../shared/data_recordset.inc" -->
<!-- #include file="../Shared/resultset_table_v2.inc" -->
<!-- #include file="../Shared/getkenmerksql.inc" -->
<!-- #include file="../API2/api2.inc" -->
<!-- #include file="../API2/model_regions.inc" -->

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


function fnrowData(oRs)
{
    var detail_key = oRs.Fields("id").Value;
    var key        = oRs.Fields("id").Value;
    var oms        = oRs.Fields("name").Value;

    var data = {detail_key: detail_key, key: key, oms: oms};

    return JSON.stringify(data);
}

%>
<script type="text/javascript">

  var autosearch = 1; // automatisch laden van resultaat op search pagina.

  function gotoDetails(row)
  {
    var algData = eval('(' + row.getAttribute("ROWDATA") + ')');
    var url = "appl/ALG/alg_district_search.asp?regio_key=" + algData.detail_key + "&autosearch=" + autosearch;
    FcltMgr.openDetail(url, "<%=L("lcl_district")%>");
  }

    function districtEdit(row)
  {
    var algData = eval('(' + row.getAttribute("ROWDATA") + ')');
    var url = "appl/ALG/alg_regio.asp?mode=viewUpdate&key=" + algData.key;
    FcltMgr.openDetail(url, "<%=L("lcl_region")%>" + ' ' + algData.oms);
  }

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

function regio_list(pautfunction, params)
{
  // De functie checkAutorisation(autfunction) geeft een Response.End indien er geen autorisatie voor autfunction wordt gevonden
  var addButton = [];
  var authparams = alg.checkAutorisation();
  var canAdd = (authparams.mALGwritelevel < 1);

  // 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 reg_key    = params.reg_key;

  function fnrowActionEnabler(oRs)
  {
      var eDelete = false;
      if (alg.canWriteRegio(oRs.Fields("id").Value, authparams.mALGwritelevel))
          eDelete = true;
      return ({eDelete: eDelete})
  }
%>
  <html>
    <head>
      <% FCLTHeader.Generate({outputmode: outputmode}); %>
    </head>
    <body id="listbody">
<%
    // Ophalen regio`s
    var regio_key = getQParamInt("regiokey");
    var filter = {};
    if (regio_key > -1)
        var filter = {id: regio_key};
    var params = { filter: filter };  // Alle regio`s ophalen, behalve de verwijderde.
    var regio_array = model_regions.REST_GET(params);       // Roep de API2 GET aan
    //

    var addurl = "appl/alg/alg_regio.asp";
    //  addurl += buildTransitParam(["loc_key", "bld_key", "flo_key", "room_key"], params)  // TODO: welke allemaal?

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

    var rst = new ResultsetTable({ dataset: regio_array,
                                   keyColumn: "id",
                                   ID: "algtable",
                                   showAll: showall,
                                   rowData: fnrowData,
                                   rowActionEnabler: fnrowActionEnabler,
                                   outputmode: outputmode,
                                   filterParams: params,
                                   buttons: addButton
                                 });


    rst.addColumn(new Column({caption: L("lcl_estate_regio_descr"), content: "name"}));

    rst.addAction({ action: "districtEdit", caption: L("lcl_edit"), isDefault:  true});
    rst.addAction({ action: "doDelete", caption: L("lcl_delete"), enabler: "eDelete", multi: true, multiOnce: true});
    rst.addAction({ action: "gotoDetails", caption: L("lcl_goto_district_list")});

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

