<%@language = "javascript" %>

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

<%

var this_model = new model_fac_widget(true);

this_model.hook_pre_put = pre_save;
this_model.hook_pre_post = pre_save;

function pre_save(params, jsondata)
{
    if ((jsondata.type || "WGT") == "WGT")
    {
        this_model.REST_PUT = function (params, jsondata, key) { return { key: jsondata.widgets } };
        this_model.REST_POST = function (params, jsondata, key) { return { key: jsondata.widgets } };
    }
    else
    {
        /* Met readonly wordt het overbodige veld niet opgeslagen,
        anders wordt in de SQL 2x hetzelfde veld ge-insert */
        this_model.fields.widgets.readonly = true;

        this_model.fields.ref_key_MK.readonly = true;
        this_model.fields.ref_key_MI.readonly = true;
        this_model.fields.ref_key_NWS.readonly = true;
        this_model.fields.ref_key_RAP.readonly = true;
        this_model.fields.ref_key_FAQ.readonly = true;

        switch (jsondata.type) {
            case "MK":
                this_model.fields.ref_key_MK.readonly = false;
                break;
            case "MI":
                this_model.fields.ref_key_MI.readonly = false;
                break;
            case "NWS":
                this_model.fields.ref_key_NWS.readonly = false;
                break;
            case "RAP":
                this_model.fields.ref_key_RAP.readonly = false;
                break;
            case "FAQ":
                this_model.fields.ref_key_FAQ.readonly = false;
                break;
        }
    }
}

var model_params = {
    "edit": {
        "modal": true,
        "requires": {
            "js": [
                "./fac_widget.js",
                "./fac_widget_onpage.js"
            ]
        }
    },
    "layout": {
        "miscellaneous": {
            "label": L("fac_widget"),
            "icon" : "fa-expand-wide"
        }
    }
}

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