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

    File:         alg_edit_regio.asp
    Description:  scherm om regio gegevens te wijzigen.
    Parameters:   regio_key

*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="alg_flexkenmerk.inc" -->
<!-- #include file="../API2/api2.inc" -->
<!-- #include file="../API2/model_regions.inc" -->

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

var regio_key = getQParamInt("regio_key");
var onrgoedlvl = "E";

var params = { filter:  { id: regio_key,
                          isNew: (regio_key == -1 ? true : false)
                        }
             };
var model = new model_regions();
var regio_array = model.REST_GET(params);              // Roep de API2 GET aan
var regio_data = (regio_array[0] ? regio_array[0] : {id: -1}); // GET kan meerdere records opleveren, maar we verwachten hier maar 1.
var this_alg = params.func_enabled;                            // params bevat nu ook waarden die in API2 zijn bepaald.
var action = (regio_key == -1 ? "I" : "U");
%>

<html>
  <head>
<%
    FCLTHeader.Generate();
%>
    <script>
        async function alg_submit()
        {
            if (!await validateForm("u2"))
                return false;

            var data = $("[name=u2]").serialize();
            $.post($("form[name=u2]")[0].action,
                   data,
                   FcltCallbackClose,
                   "json");
            return true;
        }
        function alg_cancel()
        {
            FcltMgr.closeDetail(window, { cancel: true } );
        }
    </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_regio_frame"), buttons);
%>
      <form name="u2"
            action="alg_edit_regio_save.asp?regio_key=<%=regio_data.id%>&action=<%=action%>"
            method="post"
            onSubmit="return false">
<%
        if (this_alg.writeman)
            manRWFIELD = RWFIELDTR;
        else
            manRWFIELD = function (a,b,c,d,e) { ROFIELDTR(b,c,d,e) }; // als geen USE dan zijn er veel readonly

        BLOCK_START("algInfo", L("lcl_region"), {icon: "fa-globe"});

          manRWFIELD("reg_oms", "fld", L("lcl_name"), regio_data.name, {required: true, maxlength: 30});

        BLOCK_END();

        generateFlexKenmerkBlock ({
            onrgoed_key    : regio_key,
            onrgoed_niveau : onrgoedlvl,
            reado          : false,
            this_alg       : this_alg
        });

        IFACE.FORM_END();
%>
      </form>
      <% SUBFRAME_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
