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

     File:               fac_algfaq.asp
     Description:        Laat aan een FAQ meerdere standaardmeldingen toevoegen
     Parameters:         faq_key: fac_faq_key waaraan de standaardmeldingen gekoppeld moeten worden
     Context:
     Note:

k
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/plaatsselector.inc" -->
<!-- #include file="../fac/fac.inc" -->

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

var faq_key = getQParamInt("faq_key");
var submitting = getQParamInt("submit", 0) == 1;

var this_faq = fac.func_enabled_faq(faq_key); // Wat heb ik zoal aan rechten op deze specifieke kennisbankitem.

user.auth_required_or_abort(this_faq.canChange);

var loc_key = -1;
var bld_key = -1;
var flr_key = -1;
var room_key = -1;
%>
  <html>
    <head>
<%    FCLTHeader.Generate(); %>
      <script type="text/javascript">
        function onChangeAlg(alg_level)
        {
            if ($("#locatiekey").val() > 0)
            {
                var alg_key = -1;
                var loc_key = $("#locatiekey").val();
                switch (alg_level)
                {
                    case 3: alg_key = $("#gebouwkey").val(); break;
                    case 4: alg_key = $("#verdiepingkey").val(); break;
                    case 5: alg_key = $("#ruimtekey").val(); break;
                }
                $.getJSON("../mld/get_mld_info_ajax.asp",
                          { req_info: "alg_algfaq_info",
                            loc_key: loc_key,
                            alg_key: alg_key },
                            process_algfaq_info);
            }
        }

        function process_algfaq_info(data)
        {
          $("#scope").val(fnScope(data.scope));
          $("#plaats").val(data.plaats);
        }

        function fnScope(scopeAbbr)
        {
          switch (scopeAbbr)
          {
              case "L": return L("lcl_location");
              case "G": return L("lcl_building");
              case "T": return L("lcl_terra");
              case "V": return L("lcl_floor");
              case "R": return L("lcl_room");
          }
          return "";
        }
      </script>
    </head>

    <body class="fclt-modal" id="mod_algfaq">
      <% MODAL_START(); %>
        <form name="u2" method="post" action="fac_algfaq_save.asp?faq_key=<%=faq_key%>">
        <% MODAL_BLOCK_START(); %>
          <input type="hidden" id="nrRows" name="nrRows" value="0">
          <input type="hidden" id="plaats" name="plaats" value="">
          <input type="hidden" id="scope" name="scope" value="">
<%
          // <!-- Toevoegen -->
          // Plaats
          FCLTplaatsselector(-1,
                                 { label: L("lcl_plaatsgegevens"),
                                   locatiekey: loc_key,
                                   gebouwkey: bld_key,
                                   verdiepingkey: flr_key,
                                   ruimtekey: room_key,
                                   terrein: true,
                                   filtercode: "FAC",
                                   onLocChange: "onChangeAlg(2)",
                                   onGebChange: "onChangeAlg(3)",
                                   onVerChange: "onChangeAlg(4)",
                                   onRuiChange: "onChangeAlg(5)",
                                   startlevel: 2, // Locatie
                                   eindlevel: 5, // Ruimte
                                   multitoggle: true,
                                   multionchange: true
                                 });
%>
          <tr>
            <td></td> <!-- jQuery 3.5 does not auto-convert xhtml (<td/>) to html (<td></td>) anymore -->
            <td>
              <div id="addroomfaqbuttons">
<%
              var buttons =  [ {title: L("lcl_add"), icon: "fa-plus", action: "fac_add()", id: "btn_faq_add_room", importance: 1  }];
              CreateButtons(buttons, { showIcons: true });
%>
              </div>
            </td>
          </tr>
          <tr>
            <td class="label" colspan="2">
              <label for="algfaqtable" style="white-space: nowrap"><%=L("lcl_faq_voor_alg")%></label>
            </td>
          </tr>
          <tr>
            <td colspan="2">
              <table id="algfaqtable" cellspacing=0 cellpadding=0 class="rstable">
                <thead>
                  <tr>
                    <th style='width:15px'></th>
                    <th><%=L("lcl_faq_alg_scope")%></th>
                    <th colspan="2"><%=L("lcl_plaatsgegevens")%></th>
                  </tr>
                </thead>
                <tbody>

<%
                var sql = "SELECT f.alg_algfaq_key"
                        + "     , l.alg_locatie_key loc_key"
                        + "     , NVL(f.alg_onroerendgoed_keys, -1) onr_key"
                        + "     , NVL(o.alg_type, 'L') scope"
                        + "     , l.alg_locatie_code ||"
                        + "       DECODE(o.alg_plaatsaanduiding, NULL, NULL, '-' || o.alg_plaatsaanduiding) plaats"
                        + "  FROM alg_algfaq f"
                        + "     , alg_locatie l"
                        + "     , alg_v_onroerendgoed_gegevens o"
                        + " WHERE f.alg_locatie_key = l.alg_locatie_key"
                        + "   AND f.alg_onroerendgoed_keys = o.alg_onroerendgoed_keys(+)"
                        + "   AND f.fac_faq_key = " + faq_key;

                oRs = Oracle.Execute(sql);
                while (!oRs.eof)
                {
%>
                  <script type="text/javascript">

                    CreateRow(<%=oRs("loc_key").value%>
                             ,<%=oRs("onr_key").value%>
                             ,fnScope("<%=oRs("scope").value%>")
                             ,'<%=safe.jsstring(oRs("plaats").value)%>'
                             );

                  </script>
<%
                  oRs.MoveNext();
                }
%>
                </tbody>
              </table>
            </td>
          </tr>
<%
          MODAL_BLOCK_END();
          var buttons1 =  [{title: L("lcl_submit"), icon: "fa-fclt-save", action: "fac_submit()", importance: 1 }];
          SIMPLE_BLOCK_START();
            CreateButtons(buttons1);
          SIMPLE_BLOCK_END();
          IFACE.FORM_END();
%>
        </form>
        <% MODAL_END(); %>
    </body>
  </html>
<%

%><% ASPPAGE_END(); %>
