_show.html.erb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <p>
  2. Use this form to manually emit Events from this Agent (usually for testing).
  3. </p>
  4. <p>
  5. If you add a top-level key called <code>payloads</code> that points to an array of objects, they will be emitted as a series
  6. of Events. Otherwise, everything entered will be emitted as a single Event.
  7. </p>
  8. <p>
  9. Liquid formatting is supported.
  10. </p>
  11. <h4 id='event-creation-status'></h4>
  12. <%= form_tag handle_details_post_agent_path(@agent), :id => "create-event-form" do %>
  13. <div class="form-group">
  14. <textarea rows="10" id="payload" name="payload" class="payload-editor" data-height="200">
  15. {}
  16. </textarea>
  17. </div>
  18. <%= submit_tag "Submit", :class => "btn btn-primary" %>
  19. <% end %>
  20. <script>
  21. $(function () {
  22. var payloadJsonEditor = window.setupJsonEditor($(".payload-editor"))[0];
  23. $("#create-event-form").submit(function (e) {
  24. e.preventDefault();
  25. var $form = $("#create-event-form");
  26. var $status = $("#event-creation-status");
  27. try{
  28. JSON.parse($form.find("textarea").val());
  29. }
  30. catch(err){
  31. alert ('Sorry, there appears to be an error in your JSON input. Please fix it before continuing.');
  32. return false;
  33. }
  34. $.ajax({
  35. url: $form.attr('action'),
  36. method: "post",
  37. data: { payload: $form.find("textarea").val() },
  38. dataType: "JSON",
  39. success: function(json) {
  40. if (json.success) {
  41. $status.text("Success!");
  42. } else {
  43. $status.text("An error occurred: " + json.error);
  44. }
  45. },
  46. error: function(response) {
  47. $status.text("An error occurred: " + response.responseText)
  48. }
  49. });
  50. });
  51. });
  52. </script>