_show.html.erb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <h3>Manually Create Events</h3>
  2. <h4 id='event-creation-status'></h4>
  3. <%= form_tag handle_details_post_agent_path(@agent), :id => "create-event-form" do %>
  4. <div class="form-group">
  5. <textarea rows="10" id="payload" name="payload" class="payload-editor" data-height="200">
  6. {}
  7. </textarea>
  8. </div>
  9. <%= submit_tag "Submit", :class => "btn btn-primary" %>
  10. <% end %>
  11. <script>
  12. $(function () {
  13. var payloadJsonEditor = window.setupJsonEditor($(".payload-editor"))[0];
  14. $("#create-event-form").submit(function (e) {
  15. e.preventDefault();
  16. var $form = $("#create-event-form");
  17. var $status = $("#event-creation-status");
  18. $.ajax({
  19. url: $form.attr('action'),
  20. method: "post",
  21. data: { payload: JSON.parse($form.find("textarea").val()) },
  22. dataType: "JSON",
  23. success: function(json) {
  24. if (json.success) {
  25. $status.text("Success!");
  26. } else {
  27. $status.text("An error occurred: " + json.error);
  28. }
  29. },
  30. error: function(response) {
  31. $status.text("An error occurred: " + response.responseText)
  32. }
  33. });
  34. });
  35. });
  36. </script>