<% /*
    $Revision$
    $Id$

    File:           model_alg_kenmerk.inc

    Description:    Vanuit CodeCharge gegenereerd model voor alg_kenmerk

    Context:

    Notes:
*/
%>
<%
function model_alg_kenmerk(niveau, params)
{
    params = params || {};
    this.records_name = "realestateproperties";
    this.record_name = "realestateproperty";
    this.table = "alg_kenmerk";
    this.primary = "alg_kenmerk_key";
    this.soft_delete = "alg_kenmerk_verwijder";
    this.autfunction = params.internal?false:"WEB_ALGMGT";
    this.record_title = L("alg_kenmerk");
    this.records_title = L("alg_kenmerk_m");
    this.module = "ALG";

    // overrule titel voor schermen.
    this.record_title = L("mgt_kenmerk_of")    + " " + get_real_estate_name(niveau);
    this.records_title = L("mgt_kenmerk_m_of") + " " + get_real_estate_name(niveau);


    this.fields = {
        "id": {
            "dbs": "alg_kenmerk_key",
            "label": L("lcl_key"),
            "typ": "key",
            "required": true,
            "seq": "alg_s_alg_kenmerk_key"
        },
        "level": {
            "dbs": "alg_kenmerk_niveau",
            "label": L("mgt_kenmerk_niveau"),
            "typ": "varchar",
            "hidden_fld": true,
            "LOV": fill_real_estate_level_LOV(),
            "defaultvalue": "L"
        },
        "sequence": {
            "dbs": "alg_kenmerk_volgnr",
            "label": L("mgt_kenmerk_volgnummer"),
            "typ": "number",
            "len": 3,
            "required": true // deze zou er straks weer af mogen
        },
        "rolecode": {
            "dbs": "alg_kenmerk_rolcode",
            "label": L("mgt_kenmerk_rolcode"),
            "typ": "number",
            "LOV": buildKenmerkRoleCodeLOV({ module: "ALG" }),
            "required": true,
            "multiedit": true
        },
        "name": {
            "dbs": "alg_kenmerk_omschrijving",
            "label": L("mgt_kenmerk_omschrijving"),
            "typ": "varchar",
            "translate": true,
            "required": true,
            "filter": "like"
        },
        "hint": {
           "dbs": "alg_kenmerk_hint",
            "label": L("mgt_kenmerk_hint"),
            "typ": "memo",
            "translate": true
       },
       "unit": {
            "dbs": "alg_kenmerk_dimensie",
            "label": L("mgt_srtkenmerk_dimensie"),
            "typ": "varchar",
            "translate": true
        },
        "attributetype": {
            "dbs": "alg_kenmerk_kenmerktype",
            "label": L("mgt_srtkenmerk_kenmerktype"),
            "typ": "varchar",
            "required": true,
//            "insertonly": true,
            "LOV": buildKenmerktypeLOV(),
            "showtransit": true
        },
        "required": {
            "dbs": "alg_kenmerk_verplicht",
            "label": L("mgt_kenmerk_verplicht"),
            "typ": "key",
            "LOV": buildVerplichtingList(),
            "emptyisrealvalue": true,
            "emptyoption": null
        },
        "group": {
            "dbs": "alg_kenmerk_groep",
            "label": L("mgt_kenmerk_groep"),
            "typ": "key",
            "required": true,
            "LOV": buildGroepsverplichtingList(),
            "emptyoption": null
        },
        "readonly": {
            "dbs": "alg_kenmerk_toonbaar",
            "label": L("mgt_kenmerk_toonbaar"),
            "typ": "check"
        },
        "system": {
            "dbs": "alg_kenmerk_systeem",
            "label": L("mgt_srtkenmerk_systeem"),
            "typ": "check",
            "readonly": !user.has("WEB_PRSSYS")
        },
        "inlist": {
            "dbs": "alg_kenmerk_inlijst",
            "label": L("mgt_kenmerk_systeem_overview"),
            "typ": "number",
            "bits": [
                {
                    "name": "",
                    "label": "",
                    "showasgroup": false,
                    "typ": "check",
                    "mask": 1,
                    "radios": [
                        {
                            "name": "inplan",
                            //"label": (niveau == "G"? L("mgt_kenmerk_systeem_overview_bui") + " " : "") + L("mgt_kenmerk_systeem_overview"),
                            "label":  L("mgt_kenmerk_systeem_overview"),
                            "mask": 1,
                            "defaultvalue": 0
                        }
                    ]
                }
            ],
            "multiedit": true
        },
        "length": {
            "dbs": "alg_kenmerk_lengte",
            "label": L("mgt_srtkenmerk_lengte"),
            "typ": "number"
        },
        "decimals": {
            "dbs": "alg_kenmerk_dec",
            "label": L("mgt_srtkenmerk_dec"),
            "typ": "number"
        },
        "minimum": {
            "dbs": "alg_kenmerk_nmin",
            "label": L("mgt_srtkenmerk_nmin"),
            "typ": "number"
        },
        "maximum": {
            "dbs": "alg_kenmerk_nmax",
            "label": L("mgt_srtkenmerk_nmax"),
            "typ": "number"
        },
        "domain": {
            "dbs": "fac_kenmerkdomein_key",
            "label": L("mgt_kenmerkdomein_key"),
            "typ": "key",
            "foreign": fac_kenmerkdomein_foreign("ALG"),
            "LOVinit": ""
        },
        "propertydefault": {
            "dbs": "alg_kenmerk_default",
            "label": L("mgt_kenmerk_default"),
            "typ": "memo",
            "translate": true
        },
        "showexpression": {
            "dbs": "alg_kenmerk_show_expr",
            "label": L("mgt_kenmerk_show_expr"),
            "typ": "memo"
        },
        "regexp": {
            "dbs": "alg_kenmerk_regexp",
            "label": L("mgt_kenmerk_regexp"),
            "typ": "varchar"
        },
        "code": {
            "dbs": "alg_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"
        }
    };


    this.hook_pre_edit = function (obj, fld)
    {
        var kenmerktype = (obj.attributetype ? obj.attributetype.id : "");
        fld.attributetype.LOV = buildKenmerktypeLOV(kenmerktype);
    %>
    <script type="text/javascript">
      var module = "ALG";
      var property_type = "<%=safe.jsstring(kenmerktype)%>";
    </script>
    <%
    }

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

    if (niveau == "G")  // en dan ook nog alleen als je MJOB hebt/gebruikt lijkt me TODO?
    {
      this.fields.inlist.bits[0].mask = 3;
      this.fields.inlist.bits[0].radios.push({ "name": "start",
                                               "label": L("mgt_kenmerk_systeem_overview_mjob"),
                                               "mask": 2,
                                               "defaultvalue": 0
                                             });
    }
    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_real_estate_name(niveau)
    {
        var naam = "";
        switch (niveau)
        {
            case "E": naam = L("lcl_region"); break;
            case "D": naam = L("lcl_district"); break;
            case "L": naam = L("lcl_location"); break;
            case "T": naam = L("lcl_terra"); break;
            case "G": naam = L("lcl_building"); break;
            case "V": naam = L("lcl_floor"); break;
            case "R": naam = L("lcl_room"); break;
        }
        return naam;
    }

    function fill_real_estate_level_LOV()
    {
        return  "E;"+L("lcl_region")
             + ";D;"+L("lcl_district")
             + ";L;"+L("lcl_location")
             + ";G;"+L("lcl_building")
             + ";R;"+L("lcl_room"); // Moet hier T en V ook nog bij?
    }

}
%>