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

    File:                  prs_edit_inzetbaar.asp
    Description:           Activate apikey prs_perslid_apikey
    Parameters:
       prs_key             perslid key

    Context:
    Note:
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/encoding.inc" -->
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="../prs/prs.inc" -->

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

var prs_perslid_key = getQParamInt("prs_key");

var prsauthparams = prs.checkAutorisation(prs_perslid_key);
user.auth_required_or_abort(prsauthparams.writesys);

var newapi = user.has("WEB_FACTAB")?shared.random(20):"<<"+L("lcl_prs_generate_apikey") + ">>";
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script  type="text/javascript">
      function prs_activate_apikey()
      {
        var data = { prs_key: <%=prs_perslid_key%>,
                     prs_apikey: $("#prs_apikey").val()
                   };
        <% protectRequest.dataToken("data"); %>
        $.post("prs_perslid_apikey_save.asp",
               data,
               FcltCallbackClose,
               "json");
      }

      function prs_cancel()
      {
        FcltMgr.closeDetail(window, { cancel: true, refresh: false } );
      }
    </script>
  </head>

  <body class="fclt-modal" id="mod_prsinzetbaar">
    <% MODAL_START(); %>
      <form name="u2">
<%
        MODAL_BLOCK_START("prsActivateAPIKey", L("lcl_prs_basisblok"), {icon: "fa-user"});
        FCLTpersoonselector("prs_key",
                            "sgPerson",
                            { label: L("lcl_prs_name"),
                              perslidKey: prs_perslid_key,
                              readonly: true
                            });
        RWFIELDTR("prs_apikey", "fld", L("lcl_prs_apiuser"), newapi, {maxlength: 64, readonly: !user.has("WEB_FACTAB") });
%>
        <tr>
          <td></td>
          <td><%=L("lcl_prs_apikey_warning")%></td>
        </tr>
<%

        Response.Write("<tr><td colspan='2'><br><br><div id='added'></div></td></tr>");
        MODAL_BLOCK_END();
%>
<%      var buttons =  [ {title: L("lcl_prs_activate_apikey"), action:"prs_activate_apikey()", icon: "fa-fclt-save" },
                         {title: L("lcl_cancel"), action:"prs_cancel()", icon: "fa-fclt-cancel" }];
        SIMPLE_BLOCK_START();
          CreateButtons(buttons);
        SIMPLE_BLOCK_END();
        IFACE.FORM_END();
%>
      </form>
    <% MODAL_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
