myFirstAppStartStep11.html

by siennaemery

HTML

<head>

  <title>Populate Forms</title>

  <!-- Styles for example -->
  <link rel="stylesheet" href="https://playground.fmeserver.com/css/FMEServerExamples.css" type="text/css" />

  <!-- Include FMEServer.js -->
  <script type="text/javascript" src="https://api.fmeserver.com/js/v3/FMEServer.js"></script>

  <base target="_top">


</head>


<body>

  <form id="exampleForm">

    <label>Repository: </label>
    <input id="repository-name" type="text" value="Samples" /><br />


    <label>Workspace: </label>
    <input id="workspace-name" type="text" value="austinDownload.fmw" /><br />

    <input type="button" onclick="processForm();" value="Generate Full Form" />

  </form>

  <hr />
  <form id="output-form"></form>

</body>

JavaScript

window.onload = function() {
  FMEServer.init({
    server: "https://localhost:8443", //Update with your Server hostname - on FME training machines this is https://localhost:8443
    token: "568c604bc1f235bbe137c514e7c61a8436043070" //Update with your Server fmetoken 	
  });
};

function processForm() {
  var repository = document.getElementById("repository-name").value;
  var workspace = document.getElementById("workspace-name").value;

  // Get the workspace parameters from FME Server
  FMEServer.getWorkspaceParameters(repository, workspace, generateForm);
}

function generateForm(json) {
  // Build the form items using the API
  document.getElementById("output-form").innerHTML = ""; //Clears the output form
  FMEServer.generateFormItems("output-form", json); //Fill in the parameters here

  var form = document.getElementById("output-form");

  // Create the Run Data Download Button
  var submitButton = document.createElement("input");
  submitButton.type = "button"; //Fill in the type
  submitButton.value = "Run Data Download"; //Fill in the value
  submitButton.setAttribute("onclick", "runDataDownload();");
  form.appendChild(submitButton);
}

function showResults(json) {
  // The following is to write out the full return object for visualization of the example
  console.dir(json);
  var hr = document.createElement("hr");
  var div = document.createElement("div");

  // This extracts the download link to the clipped data
  var download = json.serviceResponse.url;
  div.innerHTML += "<hr><a href=\"" + download + "\">Download Result</a>";
  document.body.appendChild(div);
}

function runDataDownload() {
  var repository = document.getElementById("repository-name").value;
  var workspace = document.getElementById("workspace-name").value;
  var form = document.getElementById("output-form");
  var params = "";

  // Loop through unique parameters and build the parameter string
  for (var i = 0; i < form.length; i++) {
    var element = form.elements[i];
    if...