<% /*
    $Revision$
    $Id$

    File:           model_mld_discipline.inc

    Description:    Vanuit CodeCharge gegenereerd model voor mld_discipline

    Context:

    Notes:
*/
%>
<!-- #include file="model_mld_disc_params.inc" -->
<!-- #include file="model_mld_discipline_discipline.inc" -->
<!-- #include file="../mgt/mgt.inc"-->
<%
function model_mld_discipline(disc_key, params)
{
    // Eén model voor de buitenwereld
    api2.merge_disc_params_model(this, _model_mld_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_mld_discipline,  // Let op: de originele _model_res_discipline
                                           { "GET": { tables: [ "ins_srtdiscipline" ]
                                                    , wheres: [ "ins_tab_discipline.ins_discipline_module = 'MLD'"
                                                              , "ins_tab_discipline.ins_srtdiscipline_key = ins_srtdiscipline.ins_srtdiscipline_key(+)"
                                                              ,"(ins_tab_discipline.ins_srtdiscipline_key IS NULL OR ins_tab_discipline.ins_srtdiscipline_key = ins_srtdiscipline.ins_srtdiscipline_key)"
                                                              ]
                                                    }
                                            }
                                       )

    this.REST_POST   = generic_REST_POST(_model_mld_discipline);
    this.REST_PUT    = generic_REST_PUT(_model_mld_discipline);
    this.REST_DELETE = generic_REST_DELETE(this);
}

_model_mld_discipline = // Internal only
{
    "records_name": "issuedisciplines",
    "record_name": "issuediscipline",
    "table": "ins_tab_discipline",
    "audit": { "childtable": "mld_disc_params" }, // Parameters voor fac_audit.
    "primary": "ins_discipline_key",
    "autfunction": "WEB_MLDMGT",
    "record_title": L("mld_discipline"),
    "records_title": L("mld_discipline_m"),
    "soft_delete": "ins_discipline_verwijder",
    "reload_after_save": true,

    "fields": {
        "id": {
            "dbs": "ins_discipline_key",
            "label": L("lcl_key"),
            "typ": "key",
            "seq": "ins_s_ins_discipline_key"
        },
        "disciplinetype": {
            "dbs": "ins_srtdiscipline_key",
            "label": L("ins_srtdiscipline"),
            "typ": "key",
            "foreign" : {
                "tbl": "ins_srtdiscipline",
                "key": "ins_srtdiscipline_key",
                "desc": "ins_srtdiscipline_omschrijving",
                "where": "ins_srtdiscipline_verwijder IS NULL"
            },
            "emptyoption": null,
            "required": true,
            "showtransit": true
        },
        "name": {
            "dbs": "ins_discipline_omschrijving",
            "label": L("ins_discipline_omschrijving"),
            "typ": "varchar",
            "required": true,
            "translate": true
        },
        "sequence": {
            "dbs": "ins_discipline_volgnr",
            "label": L("ins_discipline_volgnr"),
            "typ": "number"
        },
        "costtype": {
            "dbs": "prs_kostensoort_key",
            "label": L("prs_kostensoort"),
            "typ": "key",
            "foreign": "prs_kostensoort"
        },
        "costcentremandatory": {
            "dbs": "ins_discipline_kpnverplicht",
            "label": L("ins_discipline_kpnverplicht"),
            "typ": "check0",
			"multiedit": true
        },
        "module": {
            "dbs": "ins_discipline_module",
            "label": L("ins_discipline_module"),
            "typ": "varchar",
            "required": true,
            "defaultvalue": "MLD",
            "hidden_fld": true
        },
        "email": {
            "dbs": "ins_discipline_email",
            "label": L("ins_discipline_email"),
            "typ": "varchar",
			"multiedit": true
        },
        "satisfactionpercentage": {
            "dbs": "ins_discipline_ktopercentage",
            "label": L("ins_discipline_ktopercentage"),
            "typ": "number"
        },
        "satisfactionthreshold": {
            "dbs": "ins_discipline_ktodrempel",
            "label": L("ins_discipline_ktodrempel"),
            "typ": "number"
        },
        "colors": {
            "dbs": "ins_discipline_color",
            "typ": "color",
            "label": L("lcl_ins_colors")
        },
        "symbolname": {
            "dbs": "ins_discipline_image",
            "typ": "icon",
            "module": "MLDD",
            "label": L("lcl_mld_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"))
        }
    },
    "disc_params": {
        "model": model_mld_disc_params,
        "joinfield": "issuediscipline"
    },

    "includes": {
        "disciplines1": {
            "model": new model_mld_discipline_discipline(),
            "joinfield": "discipline1",
            "label": L("mld_discipline_discipline_m"),
            "enable_update": true,
            "multiadd": "discipline2",
            "notransport": true // te ingewikkeld
        },
        "disciplines2": {
            "model": new model_mld_discipline_discipline(),
            "joinfield": "discipline2",
            "label": L("mld_discipline_discipline_m2"),
            "enable_update": "true",
            "multiadd": "discipline1",
            "notransport": true
        }
    }
}
%>