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

    File:               alg_edit_terreinsector_multi.asp
    Description:        Multi editten van terreinsectoren
    Parameters:         alg_keys

    Context:
    Note:

*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/save2db.inc" -->
<!-- #include file="../Shared/calendar.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/kostenplaatsselector.inc" -->
<!-- #include file="../Shared/afdelingselector.inc" -->
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="../Shared/kenmerk_common.inc" -->
<!-- #include file="../API2/api2.inc" -->
<!-- #include file="./alg_flexkenmerk.inc" -->
<!-- #include file="./alg.inc" -->

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

var ter_key_arr = getQParamIntArray("ter_keys");
var warning = "";
var result = {};
var tobeedited = 0;
var ingesloten = [];
// Bepaal de terreinsectoren in de selectie die
// ook echt bewerkt kunnen of mogen worden.
for (var i = 0; i < ter_key_arr.length; i++)
{
    var this_alg = alg.func_enabled(ter_key_arr[i], "T");
    if (this_alg.writeman || this_alg.writeuse)
    {
        ingesloten.push(ter_key_arr[i]);
        tobeedited++;
        var last_this_alg = this_alg; // deze gebruiken we voor rechtencontrole. Niet 100% zuiver maar goed genoeg
    }
}
user.auth_required_or_abort(tobeedited > 0); // We klagen niet over enkele wel en enkele niet
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script type="text/javascript">

        $(function () { $("select option[value=-1]").val(""); }); // prevents removal of values from listboxes
        function alg_submit()
        {
            $.post($("form[name=u2]")[0].action,
                   $("[name=u2]").serialize(),
                   FcltCallbackAndThenAlways(alg_submit_callback),
                   "json");
            return true; // disable button
        }

        function alg_submit_callback(json)
        {
            iface.button.enable("btn_alg_submit");
            if (json.success)
                FcltMgr.closeDetail(window, json);
        }

        function alg_cancel()
        {
            FcltMgr.closeDetail(window, { cancel: true } );
        }

    </script>
  </head>

  <body class="fclt-modal" id="mod_algmultiedit">
  <% MODAL_START(); %>
    <form name="u2" action="alg_edit_terreinsector_multi_save.asp?ter_keys=<%=ingesloten.join(",")%>" method="post">
<%
        MODAL_BLOCK_START("algFlex", L("lcl_ins_meta_data"), { icon: "fa-draw-polygon" });
            // terreinsector specifieke velden
            sql = "SELECT   alg_srtterreinsector_key,"
                + lcl.xsqla('alg_srtterreinsec_omschrijving', 'alg_srtterreinsector_key')
                + "  FROM alg_v_aanwezigsrtterreinsector"
                + " ORDER BY UPPER("+lcl.xsql('alg_srtterreinsec_omschrijving', 'alg_srtterreinsector_key')+")";
            FCLTselector( "ter_srt",
                           sql,
                           { label: L("lcl_estate_ruimte_man_sort"),
                             emptyOption: "",
                             initEmpty: true
                           });
            FCLTcalendar("vervaldatum",
                         { initEmpty: true,
                           label: L("lcl_alg_vervaldatum"),
                           onChange: "DateChangedVerval()",
                           readonly: !this_alg.writeman
                         });
            FCLTkostenplaatsselector("prs_kstn",
                                     "prs_kstn",
                                     user_key,
                                     { //kostenplaatsKey: prs_kstn,
                                       label: L("lcl_prs_dept_kosten")
                                     });
            FCLTpersoonselector("verantw",
                                "sgVerantw",
                                { //perslidKey: verantw_key,
                                  label: L("lcl_alg_verantw"),
                                  autlevel: this_alg.authparams("WEB_TERMAN") && this_alg.authparams("WEB_TERMAN").PRSwritelevel
                                });
            FCLTpersoonselector("verantw2",
                                "sgVerantw2",
                                { //perslidKey: verantw_key2,
                                  label: L("lcl_alg_verantw2"),
                                  autlevel: this_alg.authparams("WEB_TERMAN") && this_alg.authparams("WEB_TERMAN").PRSwritelevel
                                });
            FCLTafdelingselector("prs_afd",
                                 "sgDept",
                                 { label: L("lcl_dep_name_level2")
                                   //departmentKey: prs_afd
                                   //autlevel: authparams.PRSreadlevel
                                 });
            var sql = api2.splitLOV2sql(L("lcl_estate_gebouw_toontelfLOV"));
            FCLTselector("toon_telefoon",
                        sql,
                        { label: L("lcl_estate_gebouw_toon_telefoon"),
                          emptyOption: "",
                          initEmpty: true
                        });
            sql = api2.splitLOV2sql(L("lcl_estate_gebouw_toonmailLOV"));
            FCLTselector("toon_email",
                       sql,
                       { label: L("lcl_estate_gebouw_toon_email"),
                         emptyOption: "",
                         initEmpty: true
                       });
            sql = api2.splitLOV2sql(L("lcl_estate_gebouw_toonkentLOV"));
            FCLTselector("toon_kenteken",
                       sql,
                       { label: L("lcl_estate_gebouw_toon_kenteken"),
                         emptyOption: "",
                         initEmpty: true
                       });
        MODAL_BLOCK_END();


        generateFlexKenmerkBlock({
            onrgoed_niveau: "T",
            onrgoed_key: -1,
            this_alg: last_this_alg,
            reado: false,
            multi: true
          });

%>
    <script>
        $(function()
          {
            init_multi();
          });
    </script>
<%

    var buttons =  [];
    buttons.push({title: L("lcl_submit"), action: "alg_submit()", singlepress: true, id: "btn_alg_submit", importance: 1, icon: "fa-fclt-save"});
    buttons.push({title: L("lcl_cancel"), action: "alg_cancel()", importance: 3, icon: "fa-fclt-cancel"});
    SIMPLE_BLOCK_START();
    CreateButtons(buttons);
    SIMPLE_BLOCK_END();
IFACE.FORM_END();
%>
    </form>
    <% MODAL_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
