<% /*
    $Revision$
    $Id$

    File:           model_buildings.inc

    Description:    Gebouwen model.
    Parameters:
    Context:

    Notes:
*/

%>
<!-- #include file="../Shared/discxalg3d.inc"-->
<%
model_buildings =
{
    table: "alg_gebouw",
    primary: "alg_gebouw_key",
    records_name: "buildings",
    record_name: "building",
    fields: {"id"          : { dbs: "alg_gebouw_key",          typ: "key",     filter: "exact" },
             "code"        : { dbs: "alg_gebouw_code",         typ: "varchar", filter: "like" },
             "name"        : { dbs: "alg_gebouw_naam",         typ: "varchar", filter: "like" },
             // is afgeleid gegeven { name: "description",  dbs: "alg_gebouw_omschrijving", typ: "varchar"},
             "visitable"   : { dbs: "alg_gebouw_bez",          typ: "check",   filter: "exact"},
             "location"    : { dbs: "alg_locatie_key",         typ: "key",     foreign: "alg_locatie", filter: "exact"},
             "coordinate_x": { dbs: "alg_gebouw_x",            typ: "number"},
             "coordinate_y": { dbs: "alg_gebouw_y",            typ: "number"}
            },
    REST_GET: function _GET(params)
        {
            var urole = "fe"; // TODO: Moet echt niet ter zake doen
            var autfunction = urole == "fe"? "WEB_ALGUSE" : "WEB_ALGMAN";
            params.authparams = user.checkAutorisation(autfunction, null, null, true); // pessimistisch

            // TODO: Add authorization
            var query = api2.sqlfields(params, model_buildings);
            query.wheres.push("alg_gebouw_verwijder IS NULL");

            var wheres = api2.sqlfilter(params, model_buildings)
            query.wheres = query.wheres.concat(wheres);

            var sql = "SELECT " + query.selects.join(", ")
                    + "  FROM " + query.tables.join(", ")
                    + " WHERE " + query.wheres.join(" AND " )
                    + " ORDER BY alg_gebouw_code";

            var json = api2.sql2json (params, sql, model_buildings);

            return json;
        },
    PUT: function (params) /* update building */
    {
    },
    POST: function (params) /* new building */
    {
    },
    DELETE: function (params) /* delete building */
    {
    }
}
%>