<% /*
    $Revision$
    $Id$

    File:           model_ins_tab_discipline.inc

    Description:    Model voor ins_tab_catalogus

    Context:

    Notes:          Vooralsnog alleen gebruikt voor autorisatie bewerkingen
                    Zou waarschijnlijk als basis kunnen dienen voor de diverse
                    'discipline' van modules
*/
%>
<!-- #include file="model_fac_groeprechten.inc" -->
<%
// Krijgt in params altijd een functie_key en groep_key
function model_ins_tab_discipline(disc_key, params)
{
    this.table = "ins_tab_discipline";
    this.primary = "ins_discipline_key";
    this.records_name = "disciplines";
    this.record_name = "discipline";
    this.fields = {
        "id": {
            "dbs": "ins_discipline_key",
            "label": "Key",
            "typ": "key",
            "required": true,
            "seq": "ins_s_ins_discipline_key"
        },
        "module": {
            "dbs": "ins_discipline_module",
            "label": L("ins_discipline_module"),
            "typ": "varchar",
            "required": true,
            "hidden_fld": true,
            "foreign": {
                    "tbl": "fac_module",
                    "key": "fac_module_name",
                    "desc": "fac_module_name || ' - ' || lcl.l(fac_module_remark)",
                    "where": "fac_module_name IN (SELECT fac_functie_module FROM fac_functie WHERE fac_functie_discipline = 1)"
                }
        },
        "disciplinetype": {
            "dbs": "ins_srtdiscipline_key",
            "label": L("lcl_mld_vakgroeptype"),
            "typ": "key",
            "foreign" : {
              "tbl": "ins_srtdiscipline",
              "key": "ins_srtdiscipline_key",
              "desc": "ins_srtdiscipline_omschrijving"
            }
        },
        "ins_discipline_min_level": {
            "dbs": "ins_discipline_min_level",
            "label": L("ins_discipline_min_level"),
            "typ": "key",
            "required": true,
            "insertonly": true,
            "LOV": L("ins_discipline_min_levelLOV"),
            "LOVinit": ""
        },
        "name": {
            "dbs": "ins_discipline_omschrijving",
            "label": L("ins_discipline_omschrijving"),
            "typ": "varchar",
            "translate": true,
            "required": true
        },
        "sequence": {
            "dbs": "ins_discipline_volgnr",
            "label": L("ins_discipline_volgnr"),
            "typ": "number"
        },
        "costtype": {
            "dbs": "prs_kostensoort_key",
            "label": L("prs_kostensoort_key"),
            "typ": "key",
            "foreign": "prs_kostensoort",
            "LOVinit": ""
        },
        "ins_discipline_kpnverplicht": {
            "dbs": "ins_discipline_kpnverplicht",
            "label": L("ins_discipline_kpnverplicht"),
            "typ": "check"
        },
        "ins_discipline_email": {
            "dbs": "ins_discipline_email",
            "label": L("ins_discipline_email"),
            "typ": "varchar"
        },
        "ins_discipline_ktopercentage": {
            "dbs": "ins_discipline_ktopercentage",
            "label": L("ins_discipline_ktopercentage"),
            "typ": "number"
        },
        "ins_discipline_ktodrempel": {
            "dbs": "ins_discipline_ktodrempel",
            "label": L("ins_discipline_ktodrempel"),
            "typ": "number"
        }
    }
    this.soft_delete = "ins_discipline_verwijder";
    this.list = {
        "columns": [
            "id",
            "ins_discipline_min_level",
            "name",
            "costtype",
            "sequence"
        ]
    };

    if (params.groep_key > 0 && params.functie_key > 0)
    {
        this.includes = {"authorization":
            {   "model": new model_fac_groeprechten(params),
                "joinfield": "ins_discipline",
                "outertoggle": { def: false, lbl: L("fac_gebruiker_outerdisc") }
            }};
    }

    this.autfunction = "WEB_FACMSU";
    this.record_title = L("mgt_discipline"); // TODO: De generieke termen
    this.records_title = L("res_v_res_catalogus_m");

    var xparams = null;
    if (params.functie_key > 0)
    {
        this.module = Oracle.Get("fac_functie_module", "fac_functie", params.functie_key);
        this.autfunction = ["WEB_FACMSU", "WEB_" + this.module + "MSU"];
        this.level = Oracle.Get("fac_functie_min_level", "fac_functie", params.functie_key);
        xparams = { GET: { wheres: ["ins_discipline_module = " + safe.quoted_sql(this.module)] } }
    }

    this.REST_GET    = generic_REST_GET(this, xparams);
    //this.REST_POST   = generic_REST_POST(this);
    //this.REST_PUT    = generic_REST_PUT(this);
    //this.REST_DELETE = generic_REST_DELETE(this);
}
%>