You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.0 KiB

  1. <div class="narrow">
  2. <?= partial('partials/header') ?>
  3. <div style="clear: both;" class="notice-pad">
  4. <div class="alert alert-success hidden" id="test_success"><strong>Success! </strong><a href="" id="post_href">View your post</a></div>
  5. <div class="alert alert-danger hidden" id="test_error"><strong>Something went wrong!</strong><br>Your Micropub endpoint indicated that something went wrong creating the post.</div>
  6. </div>
  7. <form style="margin-top: 20px;" id="weight_form">
  8. <div class="form-group">
  9. <label for="weight_num">Weight (in <?= $this->unit ?>)</label>
  10. <input type="number" id="weight_num" class="form-control">
  11. </div>
  12. <div class="form-group">
  13. <label for="date">Date and Time</label>
  14. <input type="text" id="date" class="form-control" value="<?= date('Y-m-d H:i:s') ?>">
  15. </div>
  16. <div style="float: right; margin-top: 6px;">
  17. <button class="btn btn-success" id="btn_post">Post</button>
  18. </div>
  19. </form>
  20. <div style="clear: both;"></div>
  21. </div>
  22. <script>
  23. $(function(){
  24. var d = new Date();
  25. var tzOffset = tz_seconds_to_offset(d.getTimezoneOffset() * 60 * -1);
  26. $("#date").val( $("#date").val() + " " + tzOffset);
  27. $("#btn_post").click(function(){
  28. $("#btn_post").addClass("loading disabled");
  29. $.post("/weight", {
  30. weight_num: $("#weight_num").val(),
  31. published: $("#date").val()
  32. }, function(response){
  33. if(response.location != false) {
  34. $("#test_success").removeClass('hidden');
  35. $("#test_error").addClass('hidden');
  36. $("#post_href").attr("href", response.location);
  37. window.location = response.location;
  38. } else {
  39. $("#test_success").addClass('hidden');
  40. $("#test_error").removeClass('hidden');
  41. if(response.error_details) {
  42. $("#test_error").text(response.error_details);
  43. }
  44. $("#btn_post").removeClass("loading disabled");
  45. }
  46. });
  47. return false;
  48. });
  49. });
  50. </script>