<% /*
    $Revision$
    $Id$

    File:           model_cnt_kenmerk.inc

    Description:    Model voor cnt_kenmerk

    Context:

    Notes:
*/
%>
<!-- #include file="model_cnt_srtkenmerk.inc"-->
<%

function model_cnt_kenmerk(params)
{
    params = params || {};
    this.records_name = "contractproperties";
    this.record_name = "contractproperty";
    this.table = "cnt_kenmerk";
    this.primary = "cnt_kenmerk_key";
    this.soft_delete = "cnt_kenmerk_verwijder";
    this.autfunction = params.internal?false:"WEB_CNTMGT";
    this.record_title = L("cnt_kenmerk");
    this.records_title = L("cnt_kenmerk_m");
    this.module = "CNT";

    this.fields = {
        "id": {
            "dbs": "cnt_kenmerk_key",
            "label": L("lcl_key"),
            "typ": "key",
            "required": true,
            "seq": "cnt_s_cnt_kenmerk_key",
            "readonly": true
        },
        "contractpropertytype": {
            "dbs": "cnt_srtkenmerk_key",
            "label": L("mgt_srtkenmerk_key"),
            "typ": "key",
            "required": true,
            "insertonly": true,
            "foreign": {
                "tbl": "(select cnt_srtkenmerk_key"
                     + "      , cnt_srtkenmerk_omschrijving"
                     + (mode != "list"
                       ? " || ' (' || cnt_srtkenmerk_kenmerktype || ')'"
                       : "")
                     + " oms"
                     + "      , cnt_srtkenmerk_kenmerktype"
                     + "   from cnt_srtkenmerk"
                     + "  where cnt_srtkenmerk_verwijder is null"
                     + "  order by cnt_srtkenmerk_upper asc)",
                "key": "cnt_srtkenmerk_key",
                "desc": "oms",
                "extravalue": "cnt_srtkenmerk_kenmerktype"
            },
            "defaultvalue": null,
            "LOVinit": "",
            "friendlyname": true,
            "showtransit": true
        },
        "contractpropertydesc": {
            "dbs": "cnt_kenmerk_omschrijving",
            "label": L("mgt_kenmerk_omschrijving"),
            "typ": "varchar",
            "translate": true,
            "filter": "like"
        },
        "attributetypehide": {
            "dbs": "cnt_srtkenmerk.cnt_srtkenmerk_kenmerktype",
            "label": L("mgt_srtkenmerk_kenmerktype"),
            "typ": "varchar",
            //"hidden_fld": true,
            "readonly" : true,
            "LOV": buildKenmerktypeLOV(),
            "showtransit": true
        },
        "contractdiscipline": {
            "dbs": "cnt_srtcontract_key",
            "label": L("cnt_srtcontract_key"),
            "typ": "key",
            "foreign": {
                "tbl": "(select ins_discipline_key"
                     + "      , ins_discipline_omschrijving"
                     + "   from cnt_discipline"
                     + "  where ins_discipline_verwijder is null"
                     + "  order by ins_discipline_omschrijving asc)",
                "key": "ins_discipline_key",
                "desc": "ins_discipline_omschrijving"
            },
            "LOVinit": "",
            "insertonly" : true,
            "showtransit": true
        },
        "level": {
            "dbs": "cnt_kenmerk_niveau",
            "label": L("mgt_kenmerk_niveau"),
            "typ": "varchar",
            "hidden_fld": true,
            "LOV": fill_cnt_niveau_LOV(),
            "defaultvalue": "S"
        },
        "sequence": {
            "dbs": "cnt_kenmerk_volgnummer",
            "label": L("mgt_kenmerk_volgnummer"),
            "typ": "number",
            "len": 3,
            "required": true
        },
        "rolecode": {
            "dbs": "cnt_kenmerk_rolcode",
            "label": L("mgt_kenmerk_rolcode"),
            "typ": "number",
            "LOV": buildKenmerkRoleCodeLOV({ module: "CNT" }),
            "required": true
        },
        "required": {
            "dbs": "cnt_kenmerk_verplicht",
            "label": L("mgt_kenmerk_verplicht"),
            "typ": "key",
            "LOV": buildVerplichtingList(),
            "emptyisrealvalue": true,
            "emptyoption": null
        },
        "group": {
            "dbs": "cnt_kenmerk_groep",
            "label": L("mgt_kenmerk_groep"),
            "typ": "key",
            "required": true,
            "LOV": buildGroepsverplichtingList(),
            "defaultvalue": "0"
        },
        "readonly": {
            "dbs": "cnt_kenmerk_toonbaar",
            "label": L("mgt_kenmerk_toonbaar"),
            "typ": "check"
        },
        // "inlist": {  // Dit werkt nog niet voor [CNT]
        //     "dbs": "cnt_kenmerk_inlijst",
        //     "label": L("mgt_kenmerk_systeem_overview"),
        //     "typ": "check0",
        //     "multiedit": true
        // },
        "propertydefault": {
            "dbs": "cnt_kenmerk_default",
            "label": L("mgt_kenmerk_default"),
            "typ": "memo",
            "translate": true
        },
        "showexpression": {
            "dbs": "cnt_kenmerk_show_expr",
            "label": L("mgt_kenmerk_show_expr"),
            "typ": "memo"
        },
        "hint": {
            "dbs": "cnt_kenmerk_hint",
            "label": L("mgt_kenmerk_hint"),
            "typ": "memo",
            "translate": true
        },
        "regexp": {
            "dbs": "cnt_kenmerk_regexp",
            "label": L("mgt_kenmerk_regexp"),
            "typ": "varchar"
        },
        "code": {
            "dbs": "cnt_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.getPropertyType = function (kenmerkdata)
    {
        var typedata = api2.GET(new model_cnt_srtkenmerk({internal: params.internal}), kenmerkdata.contractpropertytype.id);
        return typedata;
    }

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

    this.hook_pre_edit = function (obj, fld)
    {
        fld.propertydefault.label = ( (obj.id == -1 && obj.attributetypehide == "l") || (obj.attributetypehide && obj.attributetypehide.id == "l") ? L("mgt_kenmerk_icon"): L("mgt_kenmerk_default") );
        fld.readonly.label        = ( (obj.id == -1 && obj.attributetypehide == "l") || (obj.attributetypehide && obj.attributetypehide.id == "l") ? L("mgt_kenmerk_collapsed"): L("mgt_kenmerk_toonbaar"));
    %>
    <script type="text/javascript">
      var module = "CNT";
    </script>
    <%
    }


    this.REST_GET    = generic_REST_GET(this, {
        "GET": {
            "tables": [ "cnt_srtkenmerk"],
            "wheres": [ "cnt_srtkenmerk.cnt_srtkenmerk_key = cnt_kenmerk.cnt_srtkenmerk_key",
                        "cnt_srtkenmerk.cnt_srtkenmerk_verwijder IS NULL" ]
        }
    });

    this.REST_POST   = generic_REST_POST(this);
    this.REST_PUT    = generic_REST_PUT(this);
    this.REST_DELETE = generic_REST_DELETE(this);


    function fill_cnt_niveau_LOV()
    {
        return  "D;"+L("cnt_niveau_discipline")
             + ";S;"+L("cnt_niveau_herkenning");
    }
}
%>