<%@language = "javascript" %>
<%
/*
    $Revision$
    $Id$
*/
%>
<!-- #include file="../scf/scaffolding.inc" -->
<!-- #include file="../api2/model_res_deel.inc" -->
<%
var insMultiReserve = getQParamInt("insres",0);

var res_prs_perslid_key = getQParamInt("res_prs_perslid_key", -1);
var res_ins_deel_key = getQParamInt("res_ins_deel_key", -1);
var ins_min_level_arr = getQParamIntArray("ins_min_level", [1, 5]); // default 1 = ins_deel, 4 = prs_perslid, 5 = werkplek
var lcl_header = { s: L("res_deel"), m: L("res_deel_m") };
if (ins_min_level_arr.length == 1)
{
    switch (ins_min_level_arr[0])
    {
        case 1: lcl_header = { s: L("res_deel"), m: L("res_deel_m") }; break;
        case 2: break; // Reserveerbaar artikel: wordt gedaan in model_res_artikel.
        case 3: break; // Reserverbare ruimte (vergaderzaal): wordt gedaan in model_res_ruimte.
        case 4: lcl_header = { s: L("res_deel_prs"), m: L("res_deel_prs_m") }; break;
        case 5: lcl_header = { s: L("res_deel_wpl"), m: L("res_deel_wpl_m") }; break;
    }
}

var res_deelmodel = new model_res_deel(ins_min_level_arr, insMultiReserve)

var res_deel_key = getQParamInt("id", -1);
if (res_deel_key > 0)
{
    var sql = "SELECT isd.ins_srtdeel_key,"
            + "       isd.ins_srtgroep_key,"
            + "       idd.ins_deel_key,"
            + "       p.prs_perslid_key,"
            + lcl.xsqla("sp.prs_srtperslid_omschrijving", "sp.prs_srtperslid_key")  // TODO, Diensten en zo, wat kan deze man?
            + "     , isd.ins_srtgroep_key"
            + "     , res_deel_omschrijving"
            + "  FROM ins_srtdeel isd, "
            + "       ins_deel idd, "
            + "       prs_perslid p, "
            + "       prs_srtperslid sp, "
            + "       res_deel rd"
            + " WHERE isd.ins_srtdeel_key(+) = idd.ins_srtdeel_key"
            + "   AND idd.ins_deel_key(+) = rd.res_ins_deel_key"
            + "   AND p.prs_perslid_key(+) = rd.res_prs_perslid_key"
            + "   AND sp.prs_srtperslid_key(+) = p.prs_srtperslid_key"
            + "   AND res_deel_key = " + res_deel_key;
    var oRs = Oracle.Execute(sql);
    var srtdeel_key = oRs("ins_srtdeel_key").Value || -1;
    var res_deel_omschrijving = oRs("res_deel_omschrijving").Value;
    if (oRs("ins_deel_key").Value)
    {
        res_deelmodel.fields.res_ins_deel_key.urlAdd = [{urlParam: "srtdeel_key", "val": oRs("ins_srtdeel_key").Value }]
        //res_deelmodel.fields.res_ins_deel_key.urlAdd = [{urlParam: "srtgroup_key", "val": oRs("ins_srtgroep_key").Value }]
    }
    else
    {
        res_deelmodel.fields.res_prs_perslid_key.urlAdd = [{urlParam: "perslid_key", "val": oRs("prs_perslid_key").Value }]
    }
    oRs.Close();
}

res_deelmodel.hook_pre_show = function (obj, fld)
{
    if (fld.res_prs_perslid_key)
    {
        delete fld.bulkitem;

    }
}

res_deelmodel.hook_pre_edit = function (obj, fld, params)
{
    if (fld.res_prs_perslid_key)
    {
        delete fld.bulkitem;
    }
%>
    <script type="text/javascript">
        var s_vis_parking_key = <%=S("vis_parking_key")%>;
        var insMultiReserve = 0;
    </script>
<%
}

if (mode == "list")
{
    res_deelmodel.REST_POST = false;
}

if (mode == "list" && (inArray(1, ins_min_level_arr) || inArray(5, ins_min_level_arr)))
{
    var locatie_key = getQParamInt("locatiekey");
    var gebouw_key = getQParamInt("gebouwkey");
    var verdieping_key = getQParamInt("verdiepingkey");
    var ruimte_key = getQParamInt("ruimtekey");

    var onrgoed_key = -1;
    var niveau = "";
    if (ruimte_key > -1)
    {
        niveau = "ruimte";
        onrgoed_key = ruimte_key;
    }
    else if (verdieping_key > -1)
    {
        niveau = "verdieping";
        onrgoed_key = verdieping_key;
    }
    else if (gebouw_key > -1)
    {
        niveau = "gebouw";
        onrgoed_key = gebouw_key;
    }
    else if (locatie_key > -1)
    {
        niveau = "locatie";
        onrgoed_key = locatie_key;
    }

    if (niveau != "")
    {
        res_deelmodel.gparams.GET.wheres.push("res_v_ins_deelgegevens.alg_"+niveau+"_key = " + onrgoed_key);
    }

}

if (mode == "show" || mode == "edit")
{
    delete res_deelmodel.fields.ruimtekey;
}

var res_deelmodel_params = {
    "search": {
        "autosearch": false,
        "filters": [
            "ruimtekey",
            "bookingdiscipline",
            "name"
        ]
    },
    "list": {
        "columns": [
            "id",
            "res_ins_deel_key",
            "res_prs_perslid_key",
            "name",
            "bookingdiscipline",
            "unit",
            "price",
            "fixedprice",
            "scope"
        ]
    },
    "show": {
        "requires": {
            "js": ["../mgt/res_deel.js"]
        },
        "buttons": []
    },
    "edit": {
        "requires": {
            "js": ["../mgt/res_deel.js"]
        }
    },
    "transit": {
        "insres": insMultiReserve,
        "ins_min_level": ins_min_level_arr,
        "res_prs_perslid_key": res_prs_perslid_key,
        "res_ins_deel_key": res_ins_deel_key
    },
    "layout": {
        "miscellaneous": {
            "label": lcl_header.s,
            "icon" : "fa-calendar-edit"
        }
    }
};

if (mode == "show" && res_deel_key > -1 && user.has("WEB_RESMGT")) {
    res_deelmodel_params.show.buttons = [
        { title: L("lcl_make_qrc"), tooltip: L("lcl_make_qrc_title"), action: "qrcode(" + res_deel_key + ", '" + safe.htmlattr(res_deel_omschrijving) + "')", icon: "fa-qrcode" }
    ];
}

if (insMultiReserve)
{
    delete res_deelmodel_params.edit.buttons;
    res_deelmodel_params.insMultiReserve = true;
}

scaffolding(res_deelmodel, res_deelmodel_params);
%>
<% ASPPAGE_END(); %>
