<% /*
    $Revision$
    $Id$

    File:           model_fac_usrtab.inc

    Description:    Vanuit CodeCharge gegenereerd model voor fac_usrtab

    Context:

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

function model_fac_usrtab()
{
    var tab_key = getQParamInt("fac_usrtab_key", -1);
    var params = params || {};
    this.table = "fac_usrtab";
    this.primary = "fac_usrtab_key";
    this.records_name = "fac_usrtabs";
    this.record_name = "fac_usrtab";
    this.soft_delete = "fac_usrtab_verwijder";
    this.autfunction = false; // we controleren het zelf
    this.record_title = L("fac_usrtab");
    this.records_title = L("fac_usrtab_m");


    this.fields = {
        "id": {
            "dbs": "fac_usrtab_key",
            "label": "Key",
            "typ": "key",
            "required": true,
            "filter": "exact",
            "seq": "fac_s_fac_usrtab_key"
        },
        "name": {
            "dbs": "fac_usrtab_naam",
            "label": L("fac_usrtab_naam"),
            "typ": "varchar",
            "required": true
        },
        "description": {
            "dbs": "fac_usrtab_omschrijving",
            "label": L("fac_usrtab_omschrijving"),
            "typ": "varchar",
            "translate": true,
            "filter": "like"
        },
        "objectname": {
            "dbs": "fac_usrtab_object",
            "label": L("fac_usrtab_object"),
            "typ": "varchar",
            "hidden_fld": true
        },
        "parent": {
            "dbs": "fac_usrtab_parentkey",
            "label": L("fac_usrtab_parentkey"),
            "typ": "key",
            "foreign": {
                "tbl": "(SELECT fac_usrtab_key"
                     + "      , fac_usrtab_naam"
                     + "   FROM fac_usrtab"
                     + "  ORDER BY fac_usrtab_naam)",
                "key": "fac_usrtab_key",
                "desc": "fac_usrtab_naam"
            }
        },
        "authorization": {
            "dbs": "fac_functie_key",
            "label": L("lcl_mgt_aut_group"),
            "typ": "key",
            "foreign": "fac_functie",
            "filter": "exact"
        }
    };


    this.show = {};
    this.includes = {
        "fac_usrdatas": {
            "model": new model_fac_usrdata(),
            "joinfield": "usertable",
            "enable_update": true
        }
    };


    var gparams = { GET: { } };
    var authparams = user.checkAutorisation("WEB_PRSSYS", true);
    if (!authparams)
    {
        gparams.GET.wheres = [ "fac_functie_key IN"
                             + " (SELECT w.fac_functie_key"
                             + "    FROM fac_v_webgebruiker W"
                             + "   WHERE w.prs_perslid_key = " + user_key
                             + " )"];
    }
    else
        this.autfunction = authparams.autfunction;

    this.REST_GET = generic_REST_GET(this, gparams);
    if (authparams)
    {
      this.REST_POST   = generic_REST_POST(this);
      this.REST_PUT    = generic_REST_PUT(this);
      this.REST_DELETE = generic_REST_DELETE(this, {});
    }

    this.hook_pre_edit = function (obj, fld)
    {
        fld.parent.foreign.tbl = "(SELECT fac_usrtab_key, fac_usrtab_naam FROM fac_usrtab"
                               + (obj.id ? " WHERE fac_usrtab_key <> " + obj.id : "")
                               + " ORDER BY fac_usrtab_naam)";
    }

    if (tab_key > 0)
    {
        params.filter = params.filter || {};
        params.filter.id = tab_key;

        var xxx_array = this.REST_GET(params);
        if (!xxx_array.length)
            shared.record_not_found();
        this.data = xxx_array[0];
    }
}
%>