<% /*
    $Revision$
    $Id$

    File:           model_ins_discipline.inc

    Description:    Vanuit CodeCharge gegenereerd model voor ins_discipline

    Context:

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

function model_ins_discipline(disc_key, params)
{
    // Eén model voor de buitenwereld
    api2.merge_disc_params_model(this, _model_ins_discipline);

    this.hook_post_post = function (params, obj, key)
    {
        var org_disc_key = getQParamInt("id", -1);
        var clone_auth = getQParamInt("clone_auth", 0) == 1;
        if (clone_auth)
        {   // Ook de autorisatie van de oude discipline kopieren
            mgt.clone_authorization(key, org_disc_key);
        }
    }

    this.REST_GET    = generic_REST_GET(_model_ins_discipline,  // Let op: de originele _model_ins_discipline
                                           { "GET": {
                                               wheres: [ "ins_tab_discipline.ins_discipline_module = 'INS'"
                                                       ]
                                               }
                                           }
                                       );
    this.REST_POST   = generic_REST_POST(_model_ins_discipline);
    this.REST_PUT    = generic_REST_PUT(_model_ins_discipline);
    this.REST_DELETE = generic_REST_DELETE(this, {});
}


_model_ins_discipline = // Internal only
{
    "records_name": "objectdisciplines",
    "record_name": "objectdiscipline",
    "table": "ins_tab_discipline",
    "terms" : "ins_discipline",
    "audit": { "childtable": "ins_disc_params" }, // Parameters voor fac_audit.
    "primary": "ins_discipline_key",
    "soft_delete": "ins_discipline_verwijder",
    "autfunction": "WEB_INSMGT",
    "record_title": L("ins_discipline"),
    "records_title": L("ins_discipline_m"),


    "fields": {
        "id": {
            "dbs": "ins_discipline_key",
            "label": L("lcl_key"),
            "typ": "key",
            "required": true,
            "seq": "ins_s_ins_discipline_key"
        },
        "name": {
            "dbs": "ins_discipline_omschrijving",
            "label": L("ins_discipline_omschrijving"),
            "typ": "varchar",
            "translate": true,
            "required": true
        },
        "scope": {
            "dbs": "ins_discipline_min_level",
            "label": L("ins_discipline_minlevel"),
            "typ": "key",
            "required": true,
            "LOV": L("ins_discipline_minlevelLOV")
        },
        "costtype": {
            "dbs": "prs_kostensoort_key",
            "label": L("prs_kostensoort_key"),
            "typ": "key",
            "foreign": "prs_kostensoort"
        },
        "colors": {
            "dbs": "ins_discipline_color",
            "typ": "color",
            "label": L("lcl_ins_colors")
        },
        "symbolname": {
            "dbs": "ins_discipline_image",
            "typ": "icon",
            "module": "INSD",
            "label": L("lcl_ins_symbol_name")
        },
        "externnr": {
            "dbs": "ins_discipline_externnr",
            "typ": "varchar",
            "label": L("extern_nr")
        },
        "externsyncdate": {
            "dbs": "ins_discipline_externsyncdate",
            "typ": "datetime",
            "label": L("extern_syncdate"),
            "readonly": !(user.has("WEB_FACTAB") || user.has("WEB_FACXNR"))
        }
    },
    /* Velden van INS_DISC_PARAMS komen er dynamisch bij */
    "disc_params": {
        "model": model_ins_disc_params,
        "joinfield": "objectdiscipline"
    }
}
%>