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

    File:         alg_edit_wp.asp
    Description:  wijzigen of toevoegen van een werkplek
    Parameters:   wp_key


    Context:
    Note:

*/ %>
<!--#include file="../Shared/common.inc" -->
<!--#include file="../Shared/iface.inc" -->
<!--#include file="../Shared/selector.inc" -->
<!--#include file="../Shared/plaatsselector.inc" -->
<!-- #include file="alg.inc" -->

<%
FCLTHeader.Requires({plugins:["jQuery"], js: []})

   var wp_key  = getQParamInt("wp_key");
   var room_key = getQParamInt("room_key", -1); // ruimte

   var authparams = alg.checkAutorisation();

   var canAdd = (authparams.ALGwritelevel < 9); // TODO: fijner, ik denk 3. Ik moet voor deze locatie, dit district of deze regio schrijfrechten hebben.
   readonly = !canAdd;

if (wp_key > 0)
{
    sql = " select * "
        + "  FROM PRS_WERKPLEK "
        + " WHERE prs_werkplek_key = " + wp_key;

    oRs = Oracle.Execute(sql);

      var wp_volgnr = oRs("PRS_WERKPLEK_VOLGNR").value;
      var wp_oms    = oRs("PRS_WERKPLEK_OMSCHRIJVING").value;
      var wp_vstopp = oRs("PRS_WERKPLEK_VASTOPP").value;
      var wp_opp    = oRs("PRS_WERKPLEK_OPP").value;
      var wp_vstopp = oRs("PRS_WERKPLEK_VASTOPP").value;
      var wp_virt   = oRs("PRS_WERKPLEK_VIRTUEEL").value;
      var wp_type   = oRs("PRS_WERKPLEK_TYPE").value;
      room_key  = oRs("PRS_ALG_RUIMTE_KEY").value;

    oRs.Close();
}
else if (S("prs_werkplek_implicit") == 1)
{
    wp_type = 1; // Bij impliciet altijd flex
}
%>

<html>
<head>
<%
   FCLTHeader.Generate();
%>
<script>
    async function alg_submit()
    {
        document.activeElement.blur(); // trigger laatste onChanges
        if (!await validateForm("u2"))
            return false;
        document.forms.u2.submit();

    }
    function alg_cancel()
    {
        FcltMgr.closeDetail(window, { cancel: true } );
    }
    function alg_next()
    {
        FcltMgr.alert("TODO: Next nog niet ondersteund")
    }

function process_host_info(data)
{
    $("#wp_volgnr").val(data.volgnr);
    $("#wp_oms").val($("#alg_ruimte_nr").val() + "/" + data.volgnr)
}

function onChangeRoom(room_key)
{
  $.getJSON("../alg/get_volgnr_ajax.asp?room_key=" + room_key, process_host_info);
}

function onChangeVolgnr()
{
    $("#wp_oms").val($("#alg_ruimte_nr").val() + "/" + $("#wp_volgnr").val()) //TODO: pakt nu ruimte waarde maar moet eigenlijk ruimte code pakken.
}

<% if (wp_key<0) { %>
$(function(){ onChangeRoom(<%=room_key%>)});
<% } %>

</script>
</head>

<body class="editmode">
<% SUBFRAME_START(); %>
<%
  var buttons =  [ {title: L("lcl_submit"), action:"alg_submit()", icon: "fa-fclt-save" },
                   {title: L("lcl_cancel"), action:"alg_cancel()", icon: "fa-fclt-cancel" } ];
  IFRAMER_HEADER(L("lcl_alg_wp_frame"), buttons);
%>
<form name="u2"
      action="alg_edit_wp_save.asp?wp_key=<%=wp_key%>"
      method="post"
      target="hidFrameSubmit"
      onSubmit="alg_submit();">
<%
      BLOCK_START("algInfo", L("lcl_alg_wp_frame"), {icon: "fa-map-pin"});
  FCLTplaatsselector(authparams.uALGwritelevel, { // ALGUSE schrijfscope bepaalt wat je mag bewerken
                    ruimtekey: room_key,
                    onRuiChange: "onChangeRoom(key)",
                    startlevel: 2, // Locatie
                    eindlevel: 5, // Ruimte
                    readonlylevel: wp_key > 0 ? 2 : -1, // Locatie niet readonly
                    filtercode: "INCVR",
                    required: true });

  RWFIELDTR("wp_volgnr",  "fldshort", L("lcl_estate_wp_seq"), wp_volgnr, {required: true,
                                                                     html: 'onChange="onChangeVolgnr()"',
                                                                     datatype: "number",
                                                                     maxlength: 8});
  RWFIELDTR("wp_oms",     "fld",      L("lcl_workplace"),     wp_oms,    {maxlength: 30});
%>
<tr>
<td class="label"><label for="wp_vstopp_v"><%=L("lcl_estate_wp_fixed")%></label></td>
                    <td>
                      <label for="wp_vstopp_v">
                        <input type="radio" name="wp_vstopp_v" id="wp_vstopp_v" value="" <%= wp_vstopp==null ? " checked " : "" %>><%=L("lcl_estate_wp_fixed_v")%>
                      </label>
                      <label for="wp_vstopp_f">
                        <input type="radio" name="wp_vstopp_v" id="wp_vstopp_f" value="1" <%= wp_vstopp==1 ? " checked " : "" %>><%=L("lcl_estate_wp_fixed_f")%>
                      </label>
                   </td>
</tr>
<%
  RWFIELDTR("wp_opp",  "fld",          L("lcl_estate_wp_area"),        wp_opp, {maxlength: 10, float: true});  //TODO: in de toekomst ook kijken naar tussen 0 en 99999.99 ?

  if (S("prs_werkplek_implicit")==0)
      CHECKBOXTR(L("lcl_estate_wp_virt"), "fldalgbez", "wp_virt", wp_virt==1);

  sql = "SELECT 0, "+safe.quoted_sql(L("lcl_wptype_0"))+ " FROM DUAL"
     + " UNION SELECT 1, " + safe.quoted_sql(L("lcl_wptype_1")) + " FROM DUAL";
  FCLTselector("wp_type", sql,
              {  label: L("lcl_wptype"),
                 initKey: wp_type,
                 readonly: S("prs_werkplek_implicit") == 1
              });

BLOCK_END();
IFACE.FORM_END();
%>
</form>
<iframe src="../Shared/empty.html" name="hidFrameSubmit" style="display:none"></iframe>
<% SUBFRAME_END(); %>
</body>
</html>
<% ASPPAGE_END(); %>
