<% /*
    $Revision$
    $Id$

    File:           model_bes_kenmerkbestel.inc

    Description:    Model voor bes_kenmerkbestel = Kenmerken van bestelling

*/
%>
<%

function model_bes_kenmerkbestel()
{
    this.records_name = "orderproperties";
    this.record_name = "orderproperty";
    this.table = "bes_kenmerk";
    this.primary = "bes_kenmerk_key";
    this.soft_delete = "bes_kenmerk_verwijder";
    this.autfunction = "WEB_BESMGT";
    this.record_title = L("bes_kenmerkbestel");
    this.records_title = L("bes_kenmerkbestel_m");


    this.fields = {
        "id": {
            "dbs": "bes_kenmerk_key",
            "label": L("lcl_key"),
            "typ": "key",
            "required": true,
            "seq": "bes_s_bes_kenmerk_key",
            "defaultvalue": null
        },
        "orderdiscipline": {
            "dbs": "bes_srtinstallatie_key",
            "label": L("bes_ins_discipline_key"),
            "typ": "key",
            "required": true,
            "insertonly": true,
            "foreign": {
                "tbl": "bes_v_aanwezigdiscipline",
                "key": "ins_discipline_key",
                "desc": "ins_discipline_omschrijving"
            },
            "LOVinit": "",
            "defaultvalue": null,
            "showtransit": true
        },
        "orderpropertytype": {
            "dbs": "bes_srtkenmerk_key",
            "label": L("mgt_srtkenmerk_key"),
            "typ": "key",
            "required": true,
            "insertonly": true,
            "foreign": {
                "tbl": "(select bes_srtkenmerk_key"
                     + "      , bes_srtkenmerk_omschrijving"
                     + (mode != "list"
                       ? " || ' (' || bes_srtkenmerk_kenmerktype || ')'"
                       : "")
                     + " oms"
                     + "      , bes_srtkenmerk_kenmerktype"
                     + "   from bes_srtkenmerk"
                     + "  where bes_srtkenmerk_verwijder is null"
                     + "  order by bes_srtkenmerk_omschrijving asc)",
                "key": "bes_srtkenmerk_key",
                "desc": "oms",
                "extravalue": "bes_srtkenmerk_kenmerktype"
            },
            "defaultvalue": null,
            "emptyoption": null,
            "friendlyname": true,
            "showtransit": true
        },
        "orderpropertydesc": {
            "dbs": "bes_kenmerk_omschrijving",
            "label": L("mgt_kenmerk_omschrijving"),
            "typ": "varchar",
            "translate": true,
            "filter": "like"
        },
        "level": {
            "dbs": "bes_kenmerk_niveau",
            "label": L("mgt_kenmerk_niveau"),
            "typ": "varchar",
            "hidden_fld": true,
            "defaultvalue": "D"
        },
        "attributetype": {
            "dbs": "bes_kenmerk_type",
            "label": L("bes_kenmerk_type"),
            "typ": "varchar",
            "hidden_fld": true,
            "defaultvalue": "B"
        },
        "sequence": {
            "dbs": "bes_kenmerk_volgnummer",
            "label": L("mgt_kenmerk_volgnummer"),
            "typ": "number",
            "len": 3,
            "required": true
        },
        "rolecode": {
            "dbs": "bes_kenmerk_rolcode",
            "label": L("mgt_kenmerk_rolcode"),
            "typ": "number",
            "LOV": buildKenmerkRoleCodeLOV({ module: "BES" }),
            "required": true
        },
        "required": {
            "dbs": "bes_kenmerk_verplicht",
            "label": L("mgt_kenmerk_verplicht"),
            "typ": "key",
            "LOV": buildVerplichtingList(),
            "emptyoption": null
        },
        "group": {
            "dbs": "bes_kenmerk_groep",
            "label": L("mgt_kenmerk_groep"),
            "typ": "key",
            "required": true,
            "LOV": buildGroepsverplichtingList(),
            "emptyoption": null
        },
        "readonly": {
            "dbs": "bes_kenmerk_toonbaar",
            "label": L("mgt_kenmerk_toonbaar"),
            "typ": "check"
        },
        "system": {
            "dbs": "bes_kenmerk_inlijst",
            "label": L("mgt_srtkenmerk_systeem_adv"),
            "typ": "number",
            "bits": [
                {
                    "name": "",
                    "label": "",
                    "showasgroup": false,
                    "typ": "check",
                    "mask": 7,
                    "radios": [
                        {
                            "name": "overview_req",
                            "label": L("mgt_kenmerk_systeem_overview_req"),
                            "mask": 1,
                            "defaultvalue": 0
                        },
                        {
                            "name": "overview_pur",
                            "label": L("mgt_kenmerk_systeem_overview_pur"),
                            "mask": 2,
                            "defaultvalue": 0
                        },
                        {
                            "name": "visible_bes_opdr",
                            "label": L("lcl_bes_opdr_kenmerk_visible"),
                            "mask": 4,
                            "defaultvalue": 0
                        }
                    ]
                }
            ],
            "defaultvalue": 0,
            "required": true
        },
        "propertydefault": {
            "dbs": "bes_kenmerk_default",
            "label": L("mgt_kenmerk_default"),
            "typ": "memo",
            "translate": true
        },
        "showexpression": {
            "dbs": "bes_kenmerk_show_expr",
            "label": L("mgt_kenmerk_show_expr"),
            "typ": "memo"
        },
        "hint": {
            "dbs": "bes_kenmerk_hint",
            "label": L("mgt_kenmerk_hint"),
            "typ": "memo",
            "translate": true
        },
        "code": {
            "dbs": "bes_kenmerk_code",
            "label": L("mgt_kenmerk_code"),
            "typ": "varchar",
            "readonly": !user.has("WEB_PRSSYS")
        },
       "authorization": {  // wordt nog niet ondersteund in deze module
            "dbs": "fac_functie_key",
            "label": L("mgt_kenmerk_autorisatie"),
            "typ": "key",
            "foreign": "fac_functie"
        },
       "regexp": {
            "dbs": "bes_kenmerk_regexp",
            "label": L("mgt_kenmerk_regexp"),
            "typ": "varchar"
        }
    };


    function get_orderpropertytype_srttype(obj)
    {
        var orderpropertytype = getQParamInt("orderpropertytype", ( (obj.orderpropertytype && obj.orderpropertytype.id) ? obj.orderpropertytype.id : -1));
        var result = { lbl_default:  L("mgt_kenmerk_default")
                     , lbl_readonly: L("mgt_kenmerk_toonbaar")
                     };
        if (orderpropertytype > 0)
        {
            var sql = "SELECT bes_srtkenmerk_kenmerktype"
                    + "  FROM bes_srtkenmerk"
                    + " WHERE bes_srtkenmerk_key = " + obj.orderpropertytype.id;
            var oRs = Oracle.Execute(sql);
            if (!oRs.eof)
                result.lbl_default  = (oRs("bes_srtkenmerk_kenmerktype").Value == "l" ? L("mgt_kenmerk_icon"): L("mgt_kenmerk_default"));
                result.lbl_readonly = (oRs("bes_srtkenmerk_kenmerktype").Value == "l" ? L("mgt_kenmerk_collapsed"): L("mgt_kenmerk_toonbaar"));
            oRs.Close();
        }
        return result;
    }

    this.hook_pre_show = function (obj, fld)
    {
        var srttype = get_orderpropertytype_srttype(obj);
        fld.propertydefault.label = srttype.lbl_default;
        fld.readonly.label = srttype.lbl_readonly;
    }

    this.hook_pre_edit = function (obj, fld)
    {
        var srttype = get_orderpropertytype_srttype(obj);
        fld.propertydefault.label = srttype.lbl_default;
        fld.readonly.label = srttype.lbl_readonly;
    %>
    <script type="text/javascript">
      var module = "BES";
    </script>
    <%
    }

    this.hook_pre_post = function (params, jsondata)
    {
        var checkdata = { module: "bes",
                          srtkenmerk: true,
                          key: (jsondata.orderpropertytype.id ? jsondata.orderpropertytype.id : jsondata.orderpropertytype),
                          value: jsondata.propertydefault
                        };
        checkSrtkenmerkValue(checkdata);
        if (checkdata.err != "")
            abort_with_warning(checkdata.err);

        jsondata.propertydefault = checkdata.value;
    }


    this.REST_GET    = generic_REST_GET(this, {
        "GET": {
            "tables": [
                "bes_srtkenmerk",
                "bes_v_aanwezigdiscipline"
            ],
            "wheres": [
                "bes_kenmerk.bes_kenmerk_type = 'B'",
                "bes_kenmerk.bes_srtkenmerk_key = bes_srtkenmerk.bes_srtkenmerk_key",
                "bes_kenmerk.bes_srtinstallatie_key = bes_v_aanwezigdiscipline.ins_discipline_key"
            ]
        }
    });
    this.REST_POST   = generic_REST_POST(this);
    this.REST_PUT    = generic_REST_PUT(this);
    this.REST_DELETE = generic_REST_DELETE(this, {});
}
%>