<% /*
    $Revision$
    $Id$

    File:           model_cad_thema.inc

    Description:    Vanuit CodeCharge gegenereerd model voor cad_thema

    Context:

    Notes:      TODO: JGL: Ik ben er nog niet helemaal uit hoe de bitjes netjes op te lossen
*/
%>
<%

function model_cad_thema()
{
    this.records_name = "graphicthemes";
    this.record_name = "graphictheme";
    this.table = "cad_thema";
    this.primary = "cad_thema_key";
    this.autfunction = "WEB_CADMGT";
    this.record_title = L("cad_thema");
    this.records_title = L("cad_thema_m");


    this.fields = {
        "id": {
            "dbs": "cad_thema_key",
            "label": L("lcl_key"),
            "typ": "key",
            "required": true,
            "seq": "cad_s_cad_thema_key"
        },
        "name": {
            "dbs": "cad_thema_omschrijving",
            "label": L("cad_thema_omschrijving"),
            "typ": "varchar",
            "translate": true,
            "required": true,
            "filter": "like"
        },
        "viewname": {
            "dbs": "cad_thema_view",
            "label": L("cad_label_view"),
            "typ": "varchar",
            "required": true,
            "filter": "like"
        },
        "description": {
            "dbs": "cad_thema_opmerking",
            "label": L("cad_thema_opmerking"),
            "typ": "memo",
            "translate": true,
            "filter": "like"
        },
        "graphiclegend": {
            "dbs": "cad_legenda_key",
            "label": L("cad_legenda"),
            "typ": "key",
            "foreign": {
                "tbl": "cad_legenda",
                "key": "cad_legenda_key",
                "desc": "cad_legenda_omschrijving"
            },
            "defaultvalue": null,
            "emptyoption": null,
            "multiedit": true,
            "showtransit": true
        },
        "authorization": {
            "dbs": "fac_functie_key",
            "label": L("fac_functie_key"),
            "typ": "key",
            "foreign": "fac_functie",
            "LOVinit": "",
            "multiedit": true
        },
        "position": {
            "dbs": "plaats.waar",
            "label": L("cad_label_type_waar"),
            "typ": "key",
            "hidden_fld": true,
            "LOV": buildCadPositionLOV()
        },
        "situation": {
            "dbs": "plaats.situatie",
            "label": L("cad_label_type_situatie"),
            "typ": "key",
            "hidden_fld": true,
            "LOV": buildCadSituationLOV()
        },
        "themetype": {
            "dbs": "cad_thema_type",
            "label": L("cad_label_type"),
            "typ": "number",
            "defaultvalue": 1,
            "bits": [
                {
                    "name": "waar",
                    "label": L("cad_label_type_waar"),
                    "typ": "radio",
                    "mask": 27,
                    "radios": [
                        {
                            "mask": 1,
                            "label": L("cad_label_type_bi_rui")
                        },
                        {
                            "mask": 9,
                            "label": L("cad_label_type_bi_wp")
                        },
                        {
                            "mask": 17,
                            "label": L("cad_label_type_bi_obj")
                        },
                        {
                            "mask": 2,
                            "label": L("cad_label_type_bu_ts")
                        },
                        {
                            "mask": 18,
                            "label": L("cad_label_type_bu_obj")
                        }
                    ]
                },
                {
                    "name": "situatie",
                    "label": L("cad_label_type_situatie"),
                    "typ": "radio",
                    "mask": 4,
                    "readonly": false,
                    "radios": [
                        {
                            "mask": 0,
                            "label": L("cad_label_type_si_act")
                        },
                        {
                            "mask": 4,
                            "label": L("cad_label_type_si_sce")
                        }
                    ]
                },
                {
                    "name": "",
                    "label": " ",
                    "typ": "check",
                    "mask": 128,
                    "radios": [
                        {
                            "name": "sleepbaar",
                            "label": L("cad_thema_sleepbaar"),
                            "mask": 128,
                            "readonly": !user.has("WEB_FACTAB")
                        }
                    ]
                }
            ]
        },
        "themeurl": {
            "dbs": "cad_thema_onclick_url",
            "label": L("cad_thema_onclick_url"),
            "typ": "varchar",
            "multiedit": true
        },
        "_generate": {
            "dbs": "dual.dummy",
            "label": L("cad_thema_genereren"),
            "typ": "check",
            "hidden": true
        },
        "_update": {
            "dbs": "dual.dummy",
            "label": L("cad_thema_bijwerken"),
            "typ": "check",
            "hidden": true
        }
    };


    this.hook_pre_show = function(jsondata, fld)
    {   // De checkboxen genereer- en bijwerken-legenda zijn alleen voor het uitvoren van een functie in edit-mode.
        // Dus niet tonen in show-mode.
        delete fld._generate;
        delete fld._update;
    }

    this.hook_pre_put = function(params, jsondata, key)
    {   // update
        refresh_legenda(jsondata);
    }
    this.hook_pre_post = function(params, jsondata)
    {   // insert
        refresh_legenda(jsondata);
    }


    var ext_sql = "(SELECT BITAND(cad_thema_type, 27) waar"
                + "      , BITAND(cad_thema_type,  4) situatie"
                + "      , cad_thema_key"
                + "   FROM cad_thema) plaats ";
    this.REST_GET    = generic_REST_GET(this, {
        "GET": {
            "tables": [ext_sql],
            "wheres": ["cad_thema.cad_thema_key = plaats.cad_thema_key"]
        }
    });
    this.REST_POST   = generic_REST_POST(this);
    this.REST_PUT    = generic_REST_PUT(this);
    this.REST_DELETE = generic_REST_DELETE(this);
}
%>