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.

171 lines
6.1 KiB

  1. <div class="narrow">
  2. <?= partial('partials/header') ?>
  3. <form role="form" style="margin-top: 20px;" id="note_form" action="/post" method="post">
  4. <h3>Caffeine</h3>
  5. <ul class="caffeine entry-buttons">
  6. <?php foreach(caffeine_options() as $val): ?>
  7. <li><input type="submit" name="drank" class="btn btn-default" value="<?= $val ?>"></li>
  8. <?php endforeach; ?>
  9. </ul>
  10. <br>
  11. <h3>Alcohol</h3>
  12. <ul class="alcohol entry-buttons">
  13. <?php foreach(alcohol_options() as $val): ?>
  14. <li><input type="submit" name="drank" class="btn btn-default" value="<?= $val ?>"></li>
  15. <?php endforeach; ?>
  16. </ul>
  17. <br>
  18. <h3>Drank</h3>
  19. <ul class="other entry-buttons">
  20. <li>
  21. <input type="text" class="form-control text-custom-drank" name="custom_drank" placeholder="Custom" style="width: 72%; float: left; margin-right: 2px;">
  22. <input type="submit" class="btn btn-default btn-custom-drank" value="Post" style="width: 26%; float: right;">
  23. </li>
  24. </ul>
  25. <br><br>
  26. <h3>Ate</h3>
  27. <ul class="other entry-buttons">
  28. <li>
  29. <input type="text" class="form-control text-custom-ate" name="custom_ate" placeholder="Custom" style="width: 72%; float: left; margin-right: 2px;">
  30. <input type="submit" class="btn btn-default btn-custom-ate" value="Post" style="width: 26%; float: right;">
  31. </li>
  32. </ul>
  33. <br><br>
  34. <div class="form-group">
  35. <h3>Location <input type="checkbox" id="note_location_chk" value=""><img src="/images/spinner.gif" id="note_location_loading" style="display: none;"></h3>
  36. <input type="text" id="note_location_msg" value="" class="form-control" placeholder="" readonly="readonly">
  37. <input type="hidden" id="note_location" name="location">
  38. <input type="hidden" id="location_enabled" value="<?= $this->location_enabled ?>">
  39. <div id="note_location_img" style="display: none;">
  40. <img src="" height="180" id="note_location_img_wide" class="img-responsive">
  41. <img src="" height="320" id="note_location_img_small" class="img-responsive">
  42. </div>
  43. </div>
  44. </form>
  45. <?php if($this->micropub_endpoint): ?>
  46. <div class="callout">
  47. <p>Clicking an item will post this note to your Micropub endpoint. Below is some information about the request that will be made.</p>
  48. <table class="table table-condensed">
  49. <tr>
  50. <td>me</td>
  51. <td><code><?= session('me') ?></code> (should be your URL)</td>
  52. </tr>
  53. <tr>
  54. <td>scope</td>
  55. <td><code><?= $this->token_scope ?></code> (should be a space-separated list of permissions including "post")</td>
  56. </tr>
  57. <tr>
  58. <td>micropub endpoint</td>
  59. <td><code><?= $this->micropub_endpoint ?></code> (should be a URL)</td>
  60. </tr>
  61. <tr>
  62. <td>access token</td>
  63. <td>String of length <b><?= strlen($this->access_token) ?></b><?= (strlen($this->access_token) > 0) ? (', ending in <code>' . substr($this->access_token, -7) . '</code>') : '' ?> (should be greater than length 0)</td>
  64. </tr>
  65. <tr>
  66. <td>p3k-food</td>
  67. <td>The button you tap (or your custom text) will be sent to your Micropub endpoint in a field named <code>p3k-food</code></td>
  68. </tr>
  69. </table>
  70. </div>
  71. <?php endif; ?>
  72. </div>
  73. <script>
  74. $(function(){
  75. $(".text-custom-ate").keydown(function(e){
  76. if(e.keyCode == 13) {
  77. $(".btn-custom-ate").click();
  78. return false;
  79. }
  80. });
  81. $(".text-custom-drank").keydown(function(e){
  82. if(e.keyCode == 13) {
  83. $(".btn-custom-drank").click();
  84. return false;
  85. }
  86. });
  87. function location_error(msg) {
  88. $("#note_location_msg").val(msg);
  89. $("#note_location_chk").removeAttr("checked");
  90. $("#note_location_loading").hide();
  91. $("#note_location_img").hide();
  92. $("#note_location_msg").removeClass("img-visible");
  93. }
  94. var map_template_wide = "<?= static_map('{lat}', '{lng}', 180, 700, 15) ?>";
  95. var map_template_small = "<?= static_map('{lat}', '{lng}', 320, 480, 15) ?>";
  96. function fetch_location() {
  97. $("#note_location_loading").show();
  98. navigator.geolocation.getCurrentPosition(function(position){
  99. $("#note_location_loading").hide();
  100. var geo = "geo:" + (Math.round(position.coords.latitude * 100000) / 100000) + "," + (Math.round(position.coords.longitude * 100000) / 100000) + ";u=" + position.coords.accuracy;
  101. $("#note_location_msg").val(geo);
  102. $("#note_location").val(geo);
  103. $("#note_location_img_small").attr("src", map_template_small.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  104. $("#note_location_img_wide").attr("src", map_template_wide.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  105. $("#note_location_img").show();
  106. $("#note_location_msg").addClass("img-visible");
  107. }, function(err){
  108. if(err.code == 1) {
  109. location_error("The website was not able to get permission");
  110. } else if(err.code == 2) {
  111. location_error("Location information was unavailable");
  112. } else if(err.code == 3) {
  113. location_error("Timed out getting location");
  114. }
  115. });
  116. }
  117. $("#note_location_chk").click(function(){
  118. if($(this).attr("checked") == "checked") {
  119. if(navigator.geolocation) {
  120. $.post("/prefs", {
  121. enabled: 1
  122. });
  123. fetch_location();
  124. } else {
  125. location_error("Browser location is not supported");
  126. }
  127. } else {
  128. $("#note_location_img").hide();
  129. $("#note_location_msg").removeClass("img-visible");
  130. $("#note_location_msg").val('');
  131. $("#note_location").val('');
  132. $.post("/prefs", {
  133. enabled: 0
  134. });
  135. }
  136. });
  137. if($("#location_enabled").val() == 1) {
  138. $("#note_location_chk").attr("checked","checked");
  139. fetch_location();
  140. }
  141. });
  142. </script>