<%@language = "javascript" %>

<!-- #include file="../scf/scaffolding.inc" -->
<!-- #include file="../api2/model_res_kenmerk.inc" -->

<%

var kenmerk_key = getQParamInt("id", -1);
var niveau = getQParam("niveau", "");
//if (!niveau)
//    niveau = getQParam("level", "");

var this_model = new model_res_kenmerk(niveau);

if (mode == "edit")
{
    if (kenmerk_key > 0)
    {
        if ("bookingactivity" in this_model.fields)
           this_model.fields.bookingactivity.readonly = true ;
        if ("article" in this_model.fields)
           this_model.fields.article.readonly = true;
        if ("bookingdiscipline" in this_model.fields)
           this_model.fields.bookingdiscipline.readonly = true;
    }
    else
    {
      	delete this_model.fields.article;
      	delete this_model.fields.bookingdiscipline;
    }
}
else if (mode == "save")
{
    if (kenmerk_key == -1)
    {
        this_model.fields.article.required = false;
    }
}

var model_params = {
        "search": {
            "autosearch": true,
            "filters": [
                "level",
                "objectpropertydesc",
                "bookingpropertytype",
                "bookingactivity",
                "article",
                "bookingdiscipline"
            ],
            "transit": [
                "bookingpropertytype",
                "bookingactivity"
            ]
        },
        "list": {
            "columns": [
                "sequence",
                "bookingpropertytype",
                "objectpropertydesc",
                        "rolecode",
                "level",
//                "required",
                //"group",
                "authorization",
                "code",
                "id"
            ],
            "orderby": [
                "bookingactivity",
                "sequence",
                "objectpropertydesc",
                "sequence"
            ]
        },
        "edit": {
            "requires": {
                "js": ["./res_kenmerk.js"]
            }
        },
        "layout": {
            "block": [
                {
                    "blockid": "prsKenmerkAlgemeen",
                    "label": L("mgt_kenmerk"),
                    "icon": "fa-table-tree",
                    "ishtmlsafe": true,
                    "hidden": false,
                    "buttons": [],
                    "fields": [
                        "id",
                        "bookingpropertytype",
                        "objectpropertydesc",
                        "level",
                        "bookingactivity",
                        "article",
                        "bookingdiscipline",
                        "rolecode",
                        "group",
                        "sequence",
                        "propertydefault",
                        "hint",
                        "regexp",
                        "code"
                    ]
                },
                {
                    "blockid": "resKenmerkFormat",
                    "label": L("mgt_kenmerk_displayprops"),
                    "icon": "fa-face-viewfinder",
                    "ishtmlsafe": true,
                    "hidden": false,
                    "buttons": [],
                    "fields": [
                        "required",
                        "authorization",
                        "showexpression",
                        "readonly",
                        "inlist"
                    ]
                }
            ]
        },
        "transit": {
            "niveau": niveau
        }
    };
//TODO kolomvolgorde wellicht anders
if (niveau == "D")
{   // Kenmerk niveau: "D"=Discipline/Catalogus .
    // Toevoegen extra kolom voor discipline kenmerken.
    model_params.list.columns.splice(4, 0, "bookingdiscipline");
}
else if (niveau == "C")
{   // Kenmerk niveau: "C"= Catering artikel.
    // Toevoegen extra kolom voor artikel kenmerken.
    model_params.list.columns.splice(4, 0, "article");
}
else if (niveau == "A")
{   // Kenmerk_niveau: "A"=Activiteit.
    // Toevoegen extra kolom voor activiteit kenmerken.
    model_params.list.columns.splice(4, 0, "bookingactivity");
}
else
{   // overzicht, alles in beeld
    model_params.list.columns.splice(4, 0, "bookingactivity");
    model_params.list.columns.splice(5, 0, "bookingdiscipline");
    model_params.list.columns.splice(6, 0, "article");
}

scaffolding(this_model, model_params);
%><% ASPPAGE_END(); %>
