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

    File:           fac_groep.asp

    Description:    Ingang via groepen om autorisaties te beheren
                    Ook: als je ?editmode=1 meegeeft kun je de groepen toevoegen enz.
    Context:        Vanuit het menu

    Notes:
*/
%>

<!-- #include file="../scf/scaffolding.inc" -->
<!-- #include file="../mgt/mgt_tools.inc" -->
<!-- #include file="../api2/model_fac_groep.inc" -->

<%
    var editmode = getQParamInt("editmode", 0);

    var functie_key = getQParamInt("fac_functie", -1);
    var disc_key = getQParamInt("ins_discipline", -1);

    var model = new model_fac_groep(null, { disc_key: disc_key, functie_key: functie_key });

    function fnrowData(oRs)
    {
      var data = { funcdisc: (functie_key > 0) && model.includes.authorization.model.hasdisc };
      return JSON.stringify(data);
    }

    scf_params =
        {
            "search": {
                "autosearch": true,
                "filters": [
                    "name",
                    "remark"
                ]
            },
            "list": {
                "columns": [
                    "id",
                    "name",
                    "remark"
                    // Leuk maar veel te veel "users.user",
                    ],
                "requires": {
                  js: ["./fac_groep.js"]
                },
                "script": "window.functie_key = " + functie_key + "; window.disc_key = " + disc_key,
                "fnRowData": fnrowData
            },
            "edit":{
                "modal": true
            },
            "transit": {
                "fac_functie": functie_key,
                "ins_discipline" : disc_key,
                "editmode" : editmode
            }
        };
    if (editmode == 1)
    {
        scf_params.search.autosearch = true;
        scf_params.list.columns.push("substitutes");
    }
    else
    {
        model.REST_POST   = false;
        model.REST_PUT    = false;
        model.REST_DELETE = false;
        scf_params.list.default_action = "edit_rechten";
    }

    if (functie_key > 0 && disc_key < 0 && model.includes.authorization.model.hasdisc)
    {
        scf_params.list.columns.push("authorization.ins_discipline");
    }

    if (functie_key > 0)
    {
        var func_desc = Oracle.Get("fac_functie_omschrijving", "fac_functie", functie_key);
        scf_params.search.title = func_desc;
        scf_params.search.labels.push({ "lbl": L("fac_functie"), "txt" : func_desc });
        scf_params.search.labels.push({ "lbl": L("fac_functie_info"), "txt" : Oracle.Get("fac_functie_info", "fac_functie", functie_key)});
        var min_level = model.includes.authorization.model.min_level; // Die is bij functie_key gevuld
        if (min_level & 4 || !(min_level & 8))
        {
            scf_params.list.columns.push("authorization.prs_level_read");
            if (min_level & 2)
                scf_params.list.columns.push("authorization.prs_level_write");
        }
        if (min_level & 8)
        {
            scf_params.list.columns.push("authorization.alg_level_read")
            if (min_level & 2)
                scf_params.list.columns.push("authorization.alg_level_write");
        }
    }
    if (disc_key > 0)
    {
        scf_params.search.labels.push({ "lbl": L("ins_discipline_key"), "txt" : Oracle.Get("ins_discipline_omschrijving", "ins_tab_discipline", "ins_discipline_key", disc_key)});
    }

    scaffolding(model, scf_params);
%>
