<% /*
    $Revision$
    $Id$

    File:           model_res_discipline.inc

    Description:    Vanuit CodeCharge gegenereerd model voor res_catalogus

    Context:

    Notes:          intern hebben we een apart model voor _res_disc_params
                    Naar de buitenwereld presenteren we het als één model
*/
%>

<!-- #include file="model_res_disc_params.inc" -->
<!-- #include file="./model_res_activiteit_discipline.inc" -->
<!-- #include file="./model_res_kenmerk.inc"-->
<!-- #include file="../mgt/mgt.inc"-->

<%
function model_res_discipline(disc_key, params)
{
    // Eén model voor de buitenwereld
    api2.merge_disc_params_model(this, _model_res_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_res_discipline,  // Let op: de originele _model_res_discipline
                                           { "GET": {
                                                     wheres: [ "ins_tab_discipline.ins_discipline_module = 'RES'"
                                                             ]
                                                    }
                                            }
                                      )

    this.REST_POST   = generic_REST_POST(_model_res_discipline);
    this.REST_PUT    = generic_REST_PUT(_model_res_discipline);
    this.REST_DELETE = generic_REST_DELETE(this, {});
}

_model_res_discipline = // Internal only
{
    "records_name": "bookingdisciplines",
    "record_name": "bookingdiscipline",
    "table": "ins_tab_discipline",
    "audit": { "childtable": "res_disc_params" }, // Parameters voor fac_audit.
    "primary": "ins_discipline_key",
    "soft_delete": "ins_discipline_verwijder",
    "autfunction": "WEB_RESMGT",

    "record_title": L("res_discipline"),
    "records_title": L("res_discipline_m"),

//    "record_title": L("res_v_res_catalogus"),
//    "records_title": L("res_v_res_catalogus_m"),


    "fields": {
        "id": {
            "dbs": "ins_discipline_key",
            "label": L("lcl_key"),
            "typ": "key",
            "required": true,
            "seq": "ins_s_ins_discipline_key"
        },
        "module": {
            "dbs": "ins_discipline_module",
            "label": L("ins_discipline_module"),
            "typ": "varchar",
            "required": true,
            "defaultvalue": "RES",
            "hidden_fld": true
        },
        "scope": {
            "dbs": "ins_discipline_min_level",
            "label": L("ins_discipline_min_level"),
            "typ": "key",
            "required": true,
            "LOV": L("ins_discipline_min_levelLOV"),
            "LOVinit": "",
            "showtransit": true
        },
        "name": {
            "dbs": "ins_discipline_omschrijving",
            "label": L("ins_discipline_omschrijving"),
            "typ": "varchar",
            "filter": "like",
            "translate": true,
            "required": true
        },
        "sequence": {
            "dbs": "ins_discipline_volgnr",
            "label": L("ins_discipline_volgnr"),
            "typ": "number"
        },
        "costtype": {
            "dbs": "prs_kostensoort_key",
            "label": L("prs_kostensoort_key"),
            "typ": "key",
            "foreign": "prs_kostensoort",
            "multiedit": true,
            "showtransit": true
        },
        "costcentremandatory": {
            "dbs": "ins_discipline_kpnverplicht",
            "label": L("ins_discipline_kpnverplicht"),
            "typ": "check0",
            "multiedit": 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",
            "multiedit": true
        },
        "satisfactionthreshold": {
            "dbs": "ins_discipline_ktodrempel",
            "label": L("ins_discipline_ktodrempel"),
            "typ": "number",
            "multiedit": true
        },
        "symbolname": {
            "dbs": "ins_discipline_image",
            "typ": "icon",
            "module": "RESD",
            "label": L("lcl_res_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 RES_DISC_PARAMS komen er dynamisch bij */
    },
    "disc_params": {
        model: model_res_disc_params,
        joinfield: "bookingdiscipline"
    },

    includes : {
        "bookingactivities": {
            "model": new model_res_activiteit_discipline(),
            "joinfield": "bookingdiscipline",
            "enable_update": true,
            "multiadd" : "bookingactivity",
            "required": true
        },
        "custom_properties": {
            "model": new model_res_kenmerk("D", { internal: true }), // Discipline/Catalogus artikel.
            "joinfield": "bookingdiscipline",
            "enable_update": true
        }
  }
}
%>