<% /*
    $Revision$
    $Id$

    File:           model_mld_stdmelding_srtinst.inc

    Description:    Model voor mld_stdmelding_srtinst

    Context:

    Notes:          Eerste opzet, under construction
*/
%>
<!-- #include file="model_mld_stdmelding.inc"-->
<%

function model_mld_stdmelding_srtinst(params)
{
    params = params || {};
    this.records_name = "issuetypeobjecttypes";
    this.record_name = "issuetypeobjecttype";
    this.table = "mld_stdmelding_srtinst";
    this.primary = "mld_stdmelding_srtinst_key";
    this.autfunction = params.internal?false:"WEB_MLDMGT";
    this.record_title = L("mld_stdmelding_srtinst");
    this.records_title = L("mld_stdmelding_srtinst_m");

    this.fields = {
        "id": {
            "dbs": "mld_stdmelding_srtinst_key",
            "label": L("lcl_key"),
            "typ": "key",
            "required": true,
            "seq": "mld_s_mld_stdm_srtinst_key",
            "readonly": true
        },
        "disciplinetype": { // Voor filtering
            "dbs": "ins_srtdiscipline.ins_srtdiscipline_key",
            "label": L("lcl_mld_vakgroeptype"),
            "typ": "key",
            "foreign" : {
                "tbl": "(SELECT ins_srtdiscipline_key"
                     + "      , ins_srtdiscipline_omschrijving srtdiscipline_oms"
                     + "   FROM ins_srtdiscipline"
                     + "  WHERE ins_srtdiscipline_module = 'MLD'"
                     + "    AND ins_srtdiscipline_ins = 1"
                     + "  ORDER BY 2 ASC"
                     + ")",
                "key": "ins_srtdiscipline_key",
                "desc": "srtdiscipline_oms"
            }
        },
        "discipline": { // Voor filtering
            "dbs": "mld_stdmelding.mld_ins_discipline_key",
            "typ": "key",
            "label": L("lcl_mld_vakgroep"),
            "foreign": {
                "tbl": "(SELECT ins_discipline_key"
                     + "      , ins_discipline_omschrijving"
                     + "   FROM mld_v_aanwezigdiscipline"
                     + "  ORDER BY ins_discipline_omschrijving ASC"
                     + ")",
                "key": "ins_discipline_key",
                "desc": "ins_discipline_omschrijving"
            },
            "required": (mode == "edit")
        },
        "issuetype": {
            "dbs": "mld_stdmelding_key",
            "label": L("mld_stdmelding_key"),
            "typ": "key",
            "hidden_fld": true,
            "foreign": {
                "tbl": "(SELECT m.mld_stdmelding_key"
                     + "      , d.ins_discipline_omschrijving || '/' || m.mld_stdmelding_omschrijving  stdmelding_omschr"
                     + "   FROM mld_stdmelding m"
                     + "      , mld_v_aanwezigdiscipline d"
                     + "  WHERE m.mld_ins_discipline_key = d.ins_discipline_key"
                     + "  ORDER BY d.ins_discipline_omschrijving ASC"
                     + "         , m.mld_stdmelding_omschrijving ASC"
                     + ")",
                "key": "mld_stdmelding_key",
                "desc": "stdmelding_omschr"
            },
            "LOVinit": ""
        },
        "level": {
            "dbs": "ins_srtinstallatie_niveau",
            "label": L("lcl_niveau"),
            "typ": "varchar",
            "hidden_fld": true
        },
        "objectkey": {
            "dbs": "ins_srtinstallatie_key",
            "label": L("lcl_ins_object"),
            "typ": "key",
            "hidden_fld": true
        },
        "objectdiscipline": {
            "dbs": "ins_v_allsrtinstallatie.ins_discipline_key",
            "label": L("ins_srtinstallatie_discipline"),
            "typ": "key",
            "foreign": {
                "tbl": "ins_v_aanwezigdiscipline",
                "key": "ins_discipline_key",
                "desc": "ins_discipline_omschrijving"
            },
            "required": true
        },
        "objectgroup": {
            "dbs": "ins_v_allsrtinstallatie.ins_srtgroep_key",
            "label": L("ins_srtinstallatie_srtgroep"),
            "typ": "key",
            "foreign": { "tbl": "ins_v_aanwezigsrtgroep",
                         "key": "ins_srtgroep_key",
                         "desc": "ins_srtgroep_omschrijving"
                       }
        },
        "objecttype": {
            "dbs": "ins_v_allsrtinstallatie.ins_srtdeel_key",
            "label": L("ins_srtinstallatie_srtdeel"),
            "typ": "key",
            "foreign": { "tbl": "ins_v_aanwezigsrtdeel",
                         "key": "ins_srtdeel_key",
                         "desc": "ins_srtdeel_omschrijving"
                       }
        }
    };


    this.hook_pre_edit = function (obj, fld)
    {
%>
  <script>
    var srtinstallatieselector_available = 1; // toon alleen actuele disciplines/groepen en objecten.
  </script>
<%
        this.fields.disciplinetype.hidden_fld = true;
        this.fields.discipline.hidden_fld = true;
    }

    var xparams = {
        GET: {
            tables: [ "ins_v_allsrtinstallatie, ins_srtdiscipline, mld_v_aanwezigdiscipline, mld_stdmelding" ],
            wheres: [ "mld_stdmelding_srtinst.ins_srtinstallatie_key = ins_v_allsrtinstallatie.ins_srtinstallatie_key(+)",
                      "mld_stdmelding_srtinst.ins_srtinstallatie_niveau = ins_v_allsrtinstallatie.niveau(+)",
                      "mld_stdmelding.mld_stdmelding_key = mld_stdmelding_srtinst.mld_stdmelding_key",
                      "mld_v_aanwezigdiscipline.ins_discipline_key = mld_stdmelding.mld_ins_discipline_key",
                      "mld_v_aanwezigdiscipline.ins_srtdiscipline_key = ins_srtdiscipline.ins_srtdiscipline_key"
                    ]
        }
    };

    this.REST_GET    = generic_REST_GET(this, xparams);
    if (mld_stdmelding_key != -1)
        this.REST_POST   = generic_REST_POST(this);
    this.REST_PUT    = generic_REST_PUT(this);
    this.REST_DELETE = generic_REST_DELETE(this);
}
%>