<% /*
    $Revision$
    $Id$

    File:           model_ins_deel_state_history.inc

    Description:    State history model.
    Parameters:
    Context:

    Notes:          Altijd readonly.
                    Je moet WEB_INSUSE op de discipline hebben, er is (nog) geen 3D controle
                    Verondersteld wordt dat je in de praktijk altijd filtert op
                    bijvoorbeeld &start_statedate=2018-01-01T00:00:00Z
*/

%>
<%
function model_ins_deel_state_history(params)
{
    params = params || {};
    this.table        = "ins_deel_state_history";
    this.primary      = "ins_deel_state_history_key";
    this.records_name = "statehistory";
    this.record_name  = "statehistory";
    this.autfunction = false; // Authorisatie alleen via ins_deel.ins_discipline_key

    params.authparams = user.checkAutorisation("WEB_INSUSE");

    this.fields = { "id"       : { dbs: "ins_deel_state_history_key",   typ: "key" },
                    "object"   : { dbs: "ins_deel_key",                 typ: "key",    foreign: "ins_deel" },
                    "state"    : { dbs: "ins_deel_state",               typ: "varchar" },
                    "statedate": { dbs: "ins_deel_statedate",           typ: "datetime" },
                    "remark"   : {
                        "dbs": "ins_deel_state_history_opmerk",
                        "typ": "memo"
                    }
                  };

    var gparams = {
            GET: {
                tables: [
                    "ins_deel"
                ],
                wheres: [
                    "ins_deel_state_history.ins_deel_key = ins_deel.ins_deel_key",
                    "ins_deel.ins_discipline_key IN"
                            + " (SELECT ins_discipline_key"
                            + "    FROM fac_v_webgebruiker"
                            + "   WHERE fac_functie_key = " + params.authparams.autfunctionkey
                            + "     AND prs_perslid_key = " + user_key
                            + "     AND fac_gebruiker_prs_level_read < 9"
                            + "     AND fac_gebruiker_alg_level_read < 9)"
                ]
            }
        };
    this.REST_GET    = generic_REST_GET(this, gparams);
    // updaten doe je door ins_deel.ins_deel_state te wijzigen
}
%>