<% /*
    $Revision$
    $Id$

    File            fac_reportx_import.asp
    Description:    Voor import van een rapport
    Parameters:
    Note:
*/ %>
<%
function scaffolding_import(model, scf_params)
{
    var transit = scf_transit2url(scf_params);
%>
    <html>
      <head>
    <%  FCLTHeader.Generate() %>
      <script>
          // Als ik *zeker* wist dat API2 is ingericht zou ik POSTen naar /api2/reportsx.json
          var url = "<%=scf_params.this_fullpath%>?mode=api2&format=json<%=transit%>";

          function importCallback(json, textStatus)
          {
            if ("<%=model.record_name%>" in json)
            {
                var id = json["<%=model.record_name%>"].id;
                FcltMgr.alert("Created {0} (key {1})".format("<%=safe.jsstring(model.record_title)%>",id));
            }
            else
                FcltMgr.alert("Strange, no '<%=safe.jsstring(model.record_name)%>' in json?\n{0}".format(json.warning));
          }
          function scf_import()
          {
            var data = $("#importeer").val();
            try {
                var tester = JSON.parse($("#importeer").val());
            } catch (e) {
                FcltMgr.alert(e.description || e.message);
                return;
            }

            $.ajax({
              type: "POST",
              url: url,
              data: data,
              contentType:"application/json; charset=utf-8",
              success: importCallback,
              dataType: "json",
              "headers": { "X-CSRF-TOKEN" : RVT_token }
            }).fail(function(xhr, status, error) {
                    // error handling
                    var data = JSON.parse(xhr.responseText);
                    FcltMgr.alert(data.error.message);
            });
          }

      </script>
    </head>
    <body>
<%
    var buttons = [];
    buttons.push({title: L("lcl_scf_paste"), action: "scf_import()", icon: "fa-brackets-curly"});
    SUBFRAME_START();
        IFRAMER_HEADER(L("lcl_scf_paste") + " " + model.record_title, buttons);
        Response.Write("<form method='post' action='../../api2/reportsx.json'>");
            BLOCK_START("scf_import", model.record_title, { wide: true });
                Response.Write("<textarea id='importeer' spellcheck='false' style='width:100%;height:500px;' placeholder='Plak hier wat je bij een record met transporteren hebt gemaakt'></textarea>");
            BLOCK_END();
        Response.Write("</form>");
    SUBFRAME_END();
%>
    </body>
<%
}
%>