<% /*
    $Revision$
    $Id$

    File:           model_prs_kenmerk.inc

    Description:    Vanuit CodeCharge gegenereerd model voor prs_kenmerk

    Context:

    Notes:
*/
%>
<%
function model_prs_kenmerk(niveau, params)
{
    params = params || {};
    this.records_name = "basisproperties";
    this.record_name = "basisproperty";
    this.table = "prs_kenmerk";
    this.primary = "prs_kenmerk_key";
    this.soft_delete = "prs_kenmerk_verwijder";
    this.autfunction = params.internal ? false : "WEB_PRSMGT";
    this.record_title = L("mgt_kenmerk_of") + " " + get_prs_naam(niveau);
    this.records_title = L("mgt_kenmerk_m_of") + " " + get_prs_naam(niveau);
    this.module = "PRS";

    this.fields = {
        "id": {
            "dbs": "prs_kenmerk_key",
            "label": L("lcl_key"),
            "typ": "key",
            "required": true,
            "seq": "prs_s_prs_kenmerk_key"
        },
        "level": {
            "dbs": "prs_kenmerk_niveau",
            "label": L("mgt_kenmerk_niveau"),
            "typ": "varchar",
            "hidden_fld": true,
            "LOV": fill_prs_niveau_LOV(),
            "defaultvalue": "P"
        },
        "sequence": {
            "dbs": "prs_kenmerk_volgnr",
            "label": L("mgt_kenmerk_volgnummer"),
            "typ": "number",
            "len": 3,
            "required": true
        },
        "rolecode": {
            "dbs": "prs_kenmerk_rolcode",
            "label": L("mgt_kenmerk_rolcode"),
            "typ": "number",
            "LOV": buildKenmerkRoleCodeLOV({ module: ( niveau == "C" ? "REL" : "PRS") }),
            "required": true,
            "multiedit": true
        },
        "name": {
            "dbs": "prs_kenmerk_omschrijving",
            "label": L("mgt_kenmerk_omschrijving"),
            "typ": "varchar",
            "translate": true,
            "required": true
        },
        "hint": {
            "dbs": "prs_kenmerk_hint",
            "label": L("mgt_kenmerk_hint"),
            "typ": "memo",
            "translate": true
        },
        "unit": {
            "dbs": "prs_kenmerk_dimensie",
            "label": L("mgt_srtkenmerk_dimensie"),
            "typ": "varchar",
            "translate": true
        },
        "attributetype": {
            "dbs": "prs_kenmerk_kenmerktype",
            "label": L("mgt_srtkenmerk_kenmerktype"),
            "typ": "varchar",
            "required": true,
            "LOV": buildKenmerktypeLOV(),
            "showtransit": true
        },
        "required": {
            "dbs": "prs_kenmerk_verplicht",
            "label": L("mgt_kenmerk_verplicht"),
            "typ": "key",
            "LOV": buildVerplichtingList(),
            "emptyisrealvalue": true,
            "emptyoption": null
        },
        "group": {
            "dbs": "prs_kenmerk_groep",
            "label": L("mgt_kenmerk_groep"),
            "typ": "key",
            "required": true,
            "LOV": buildGroepsverplichtingList(),
            "emptyoption": null
        },
//        "readonly": {
//            "dbs": "prs_kenmerk_toonbaar",
//            "label": L("mgt_kenmerk_toonbaar"),
//            "typ": "check",
//            "multiedit": true
//        },
        "readonly": {
            "dbs": "prs_kenmerk_toonbaar",
            "label": L("mgt_kenmerk_toonbaar"),
            "typ": "number",
            "multiedit": true,
            "bits": [
                {
                    "name": "ktoon",
                    "label": "",
                    "showasgroup": false,
                    "typ": "check",
                    "mask": 3,
                    "radios": [
                        {
                            "name": "ktoon1",
                            "label": L("mgt_kenmerk_toonbaar"),
                            "mask": 1,
                            "defaultvalue": 0
                        },
                        {
                            "name": "ktoon2",
                            "label": L("lcl_prs_in_profile"),
                            "mask": 2,
                            "defaultvalue": 0
                        }
                    ]
                }]
        },
        "system": {
            "dbs": "prs_kenmerk_systeem",
            "label": L("mgt_srtkenmerk_systeem_adv"),
            "typ": "number",
            "bits": [
                {
                    "name": "",
                    "label": "",
                    "showasgroup": false,
                    "typ": "check",
                    "mask": 15,
                    "radios": [
                        {
                            "name": "ksystem",
                            "label": L("mgt_kenmerk_systeem"),
                            "mask": 1,
                            "defaultvalue": 0
                        },
/*
                        {
                            "name": "conf",
                            "label": L("mgt_kenmerk_systeem_conf"),
                            "mask": 4,
                            "defaultvalue": 0
                        },
*/
                        {
                            "name": "ano",
                            "label": L("mgt_kenmerk_systeem_ano"),
                            "mask": 8,
                            "defaultvalue": 0
                        }
                    ]
                }
            ]
        },
        "inlist": {
            "dbs": "prs_kenmerk_inlijst",
            "label": L("mgt_kenmerk_systeem_overview"),
            "typ": "check0",
            "multiedit": true
        },
        "length": {
            "dbs": "prs_kenmerk_lengte",
            "label": L("mgt_srtkenmerk_lengte"),
            "typ": "number"
        },
        "decimals": {
            "dbs": "prs_kenmerk_dec",
            "label": L("mgt_srtkenmerk_dec"),
           "typ": "number"
        },
        "minimum": {
            "dbs": "prs_kenmerk_nmin",
            "label": L("mgt_srtkenmerk_nmin"),
            "typ": "number"
        },
        "maximum": {
            "dbs": "prs_kenmerk_nmax",
            "label": L("mgt_srtkenmerk_nmax"),
            "typ": "number"
        },
        "position": {  // rare tag, position, dit is de functie
            "dbs": "prs_srtperslid_key",
            "label": L("prs_srtperslid_key"),
            "typ": "key",
            "foreign": {
                "tbl": "prs_srtperslid",
                "key": "prs_srtperslid_key",
                "desc": "prs_srtperslid_omschrijving"
            }
        },
        "domain": {
            "dbs": "fac_kenmerkdomein_key",
            "label": L("mgt_kenmerkdomein_key"),
            "typ": "key",
            "foreign": fac_kenmerkdomein_foreign("PRS"),
            "LOVinit": ""
        },
        "propertydefault": {
            "dbs": "prs_kenmerk_default",
            "label": L("mgt_kenmerk_default"),
            "typ": "memo",
            "translate": true
        },
        "showexpression": {
            "dbs": "prs_kenmerk_show_expr",
            "label": L("mgt_kenmerk_show_expr"),
            "typ": "memo"
        },
        "regexp": {
            "dbs": "prs_kenmerk_regexp",
            "label": L("mgt_kenmerk_regexp"),
            "typ": "varchar"
        },
        "code": {
            "dbs": "prs_kenmerk_code",
            "label": L("mgt_kenmerk_code"),
            "typ": "varchar",
            "readonly": !user.has("WEB_PRSSYS")
        },
        "authorization": {
            "dbs": "fac_functie_key",
            "label": L("mgt_kenmerk_autorisatie"),
            "typ": "key",
            "foreign": "fac_functie"
        }
    };


    function fill_prs_niveau_LOV()
    {
        return  "B;"+L("lcl_company")
             + ";A;"+L("lcl_department")
             + ";P;"+L("lcl_person")
             + ";C;"+L("lcl_contact");
    }


    this.hook_pre_show = function (obj, fld)
    {
        fld.propertydefault.label = (obj.attributetype.id == "l" ? L("mgt_kenmerk_icon"): L("mgt_kenmerk_default"));
        fld.readonly.label = (obj.attributetype.id == "l" ? L("mgt_kenmerk_collapsed"): L("mgt_kenmerk_toonbaar"));
    }

    this.hook_pre_edit = function (obj, fld)
    {
        var kenmerktype = (obj.attributetype ? obj.attributetype.id : "");
        fld.attributetype.LOV = buildKenmerktypeLOV(kenmerktype);

        if (obj.id != -1)
            fld.position.foreign.readonly = true;

        var srttype = (obj.id == -1 ? obj.attributetype : obj.attributetype.id);
        fld.propertydefault.label = (srttype == "l" ? L("mgt_kenmerk_icon"): L("mgt_kenmerk_default"));
        fld.readonly.label = (srttype == "l" ? L("mgt_kenmerk_collapsed"): L("mgt_kenmerk_toonbaar"));
    %>
    <script type="text/javascript">
      var module = "PRS";
      var property_type = "<%=safe.jsstring(kenmerktype)%>";
    </script>
    <%
    }


    var gparams = {"GET": {}};
    if (niveau)
    {
        gparams.GET = { wheres: [ "prs_kenmerk.prs_kenmerk_niveau = " + safe.quoted_sql(niveau) ] };
    }


    this.REST_GET    = generic_REST_GET(this, gparams);
    this.REST_POST   = generic_REST_POST(this);
    this.REST_PUT    = generic_REST_PUT(this);
    this.REST_DELETE = generic_REST_DELETE(this);


    function get_prs_naam(niveau)
    {
        var naam = "";
        switch (niveau)
        {
            case "B": naam = L("lcl_company");    break;
            case "A": naam = L("lcl_department"); break;
            case "P": naam = L("lcl_person");     break;
            case "C": naam = L("lcl_contact");    break;
        }
        return naam;
    }
}
%>