<%@language = "javascript" %>
<% /*
    $Revision$
    $Id$

    File:         alg_edit_ruimte_save.asp

*/ %>
<%
var JSON_Result = true;
%>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../API2/api2.inc" -->
<!-- #include file="../API2/model_rooms.inc" -->

<%
protectRequest.validateToken();
var room_key = getQParamInt( "room_key" );
var room_action = getFParam( "room_action", "" );

var formfields = [ { name: "name",         frm: "room_nr"  },
                   { name: "roomtype",     frm: "room_srt" },
                   { name: "floor",        frm: "verdiepingkey" },
                   { name: "description",  frm: "room_oms" },
                   { name: "grossarea",    frm: "room_opp" },
                   { name: "perimeter",    frm: "room_omt" },
                   { name: "remark",       frm: "room_opm" },
                   { name: "volume",       frm: "room_inh" },
                   { name: "area1",        frm: "room_oppa1" },
                   { name: "area2",        frm: "room_oppa2" },
                   { name: "servicelevel", frm: "dienstniveau" },
                   { name: "workdays",     frm: "room_werkdagen" },
                   { name: "openfrom",     frm: "room_beginuur" },
                   { name: "opento",       frm: "room_einduur" }
                 ];
var params = { filter: { id: room_key,
                         scope: "fe"
                       },
               properties: { extraserie: false,
                             nameprefix: "k",
                             returnArray: true
                           }
             };
var rooms = new model_rooms();
var jsondata = api2.form2JSONdata(rooms, params, formfields);
jsondata.custom_fields = flexkenmerken2jsondata(params.properties);

switch (room_action)
{
    case "I":
        var room_array = rooms.REST_POST(params, jsondata);
        room_key = room_array.key;
        break;
    case "U":
        var room_array = rooms.REST_PUT(params, jsondata, params.filter.id);
        break;
    case "D":
        var room_array = rooms.REST_DELETE(params, params.filter.id);
        break;
    default :
        var room_array = {warning: L("lcl_cnt_Del_Fails_Auth")};
}
var warning = room_array.warning;


var result = { room_key: room_key,
               warning: warning,
               keepForm: !!warning,
               success: true };
Response.Write(JSON.stringify(result));
%>
<% ASPPAGE_END(); %>
