<%@language = "javascript" %>

<!-- #include file="../scf/scaffolding.inc" -->
<!-- #include file="../fac/fac_widget.inc" -->
<!-- #include file="../api2/model_fac_widget_page.inc" -->

<%
var widget_page_key = getQParamInt("id", -1);

var this_model = new model_fac_widget_page();

function fnrowData(oRs)
{
    var data = { title: oRs.Fields("name").Value };
    return JSON.stringify(data);
}

var scf_params = {
    "search": {
        "autosearch": true,
        "filters" : [
            "name",
            "person",
            "authorization_group"
        ]
    },
    "list": {
        "columns": [
            "id",
            "name",
            "person",
            "isStartPage",
            "authorization_group",
            "created"
        ],
        "orderby": [
            "id"
        ],
        "requires": {
            "js": ["./fac_widget_page.js"]
        },
        "actions": [
            { action: "fac_show_widget_page", caption: L("fac_widget_page_show"), multi: false }
        ],
        "fnRowData": fnrowData
    },
    "show": {
        "requires": {
            "js": ["./fac_widget_page.js"]
        }
    },
    "wrap": {
        "frames": []
    },
    "layout": {
        "miscellaneous": {
            "label": L("fac_widget_page"),
            "icon" : "fa-chalkboard"
        }
    }
};

var exists = wgt.exists_widget_page(widget_page_key);
if (exists && wgt.func_enabled_wgt_page(widget_page_key).canRead) {
    scf_params.wrap.frames.push({
        id: "widget_page_frame",
        url: "../fac/fac_show_widget_page.asp?mode=wrap&wgt_page_key={0}",
        title: L("fac_widget_page_layout"),
        icon: "fa-th-large"
    });
}

if (mode == "list" || mode == "search")
{
    this_model.fields.isStartPage = {
        "dbs": "isStartPage",
        "sql": "DECODE (fac_widget_page.fac_widget_page_key, " + S("widgetportal") + ", 1, 0)",
        "listfunction": function(oRs)
        {
            var result = "";
            if (oRs.Fields("isStartPage").Value == 1)
                result = I("fa-home-alt");
            return result;
        },
        "label": I("fa-home-alt"),
        "title": L("fac_widget_homepage"),
        "typ": "number",
        "tdClass": "fa-fw",
        "nosearch": true
    }
}

this_model.REST_POST = function (params, jsondata, key) {
    var result = generic_REST_POST(this)(params, jsondata);
    var cloning = getQParamInt("scf_clone", 0);
    if (cloning && !result.warning) // Dan nu ook de indeling
    {
        var clone_key = getQParamInt("id", -1);
        var layout_result = wgt.clone_widgets_onpage(clone_key, result.key);
        result.warning = layout_result.warning;
    }
    return result;
};

scaffolding(this_model, scf_params);

%>
<% ASPPAGE_END(); %>
