<% /*
    $Revision$
    $Id$

    File:           model_fac_widget_page.inc

    Description:

    Context:

    Notes:
*/
%>
<%
function model_fac_widget_page()
{
    this.records_name = "widget_pages";
    this.record_name = "widget_page";
    this.table = "fac_widget_page";
    this.primary = "fac_widget_page_key";
    this.autfunction = ["WEB_PRSSYS", "WEB_WGTMAN"];
    this.record_title = L("fac_widget_page");
    this.records_title = L("fac_widget_page_m");

    var hasPRSSYS = user.has("WEB_PRSSYS");
    this.fields = {
        "id": {
            "dbs": "fac_widget_page_key",
            "label": L("lcl_key"),
            "typ": "key",
            "required": true,
            "seq": "fac_s_fac_widget_page_key",
            "defaultvalue": null
        },
        "name" : {
            "dbs": "fac_widget_page_name",
            "label": L("fac_widget_page_name"),
            "typ": "varchar",
            "required": true,
            "filter": "like"
        },
        "person": {
            "dbs": "prs_perslid_key",
            "label": L("fac_widget_page_pers"),
            "typ": "key",
            "foreign": "prs_perslid",
            "preferredKeys": [user_key]
        },
        "authorization_group": {
            "dbs": "fac_groep_key",
            "label": L("fac_groep"),
            "typ": "key",
            "foreign": "fac_groep",
            "foreignfiltercode": hasPRSSYS ? "" : "SELF",
            "multiedit": true
        },
        "created": {
            "dbs": "fac_widget_page_aanmaak",
            "label": L("fac_widget_page_aanmaak"),
            "typ": "date",
            "hidden_fld": true,
            "readonly": true
        }
    }

    if (mode == "list")
    {
        this.fields.name.sql = " CASE"
                             + "     WHEN     fac_widget_page.fac_widget_page_name IS NULL"
                             + "          AND fac_widget_page.prs_perslid_key IS NOT NULL"
                             + "     THEN"
                             +           safe.qL("fac_widget_page_personal")
                             + "     ELSE"
                             + "         fac_widget_page.fac_widget_page_name"
                             + " END";
    }

    var gparams;
    if (!hasPRSSYS || S("fac_usrrap_mode") == 0)
    {
        // Dan alleen; openbaar of van jezelf en waar je rechten op hebt
        gparams = {
            "GET": {
                "wheres": [ "(fac_widget_page.prs_perslid_key IS NULL"
                                + (S("fac_usrrap_mode") == 1 ? " OR fac_widget_page.prs_perslid_key = " + user_key : "")
                                + ")",
                            "(fac_widget_page.fac_groep_key IS NULL"
                                + (S("fac_usrrap_mode") == 1
                                    ?   " OR fac_widget_page.fac_groep_key IN (SELECT fgg.fac_groep_key"
                                        + "                                      FROM fac_gebruikersgroep fgg"
                                        + "                                     WHERE fgg.prs_perslid_key = " + user_key + ")"
                                    : "")
                                + ")" ]
            }
        };

        if (S("fac_usrrap_mode") == 0)
        {
            delete this.fields.person;
            delete this.fields.authorization_group;
        }
        else
            this.fields.person.foreignfiltercode = "ONLY_SELF";
    }

    this.REST_GET    = generic_REST_GET(this, gparams);
    this.REST_POST   = generic_REST_POST(this);
    this.REST_PUT    = generic_REST_PUT(this);
    this.REST_DELETE = generic_REST_DELETE(this);
}
%>