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.

194 lines
6.8 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. <div id="entry-buttons">
  5. <?= partial('partials/entry-buttons', ['options'=>$this->default_options]) ?>
  6. </div>
  7. <div class="form-group">
  8. <h3>Location <input type="checkbox" id="note_location_chk" value=""><img src="/images/spinner.gif" id="note_location_loading" style="display: none;"></h3>
  9. <input type="text" id="note_location_msg" value="" class="form-control" placeholder="" readonly="readonly">
  10. <input type="hidden" id="note_location" name="location">
  11. <input type="hidden" id="location_enabled" value="<?= $this->location_enabled ?>">
  12. <div id="note_location_img" style="display: none;">
  13. <img src="" height="180" id="note_location_img_wide" class="img-responsive">
  14. <img src="" height="320" id="note_location_img_small" class="img-responsive">
  15. </div>
  16. </div>
  17. <div class="form-group">
  18. <h3>Date</h3>
  19. <input type="date" id="note_date" name="note_date" value="<?= $this->date_str ?>">
  20. <input type="text" id="note_time" name="note_time" value="<?= $this->time_str ?>">
  21. <input type="text" id="note_tzoffset" name="note_tzoffset" value="<?= $this->tz_offset ?>">
  22. </div>
  23. </form>
  24. <?php if($this->micropub_endpoint): ?>
  25. <div class="scroll-container">
  26. <div class="callout">
  27. <p>Clicking an item will post this note to your Micropub endpoint. Below is some information about the request that will be made.</p>
  28. <table class="table table-condensed">
  29. <tr>
  30. <td>me</td>
  31. <td class="break"><code><?= session('me') ?></code> (should be your URL)</td>
  32. </tr>
  33. <tr>
  34. <td>scope</td>
  35. <td class="break"><code><?= $this->token_scope ?></code> (should be a space-separated list of permissions including "post")</td>
  36. </tr>
  37. <tr>
  38. <td>micropub endpoint</td>
  39. <td class="break"><code><?= $this->micropub_endpoint ?></code> (should be a URL)</td>
  40. </tr>
  41. <tr>
  42. <td>access token</td>
  43. <td class="break">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>
  44. </tr>
  45. <tr>
  46. <td>p3k-food</td>
  47. <td class="break">The button you tap (or your custom text) will be sent to your Micropub endpoint in a field named <code>p3k-food</code></td>
  48. </tr>
  49. <tr>
  50. <td>p3k-type</td>
  51. <td class="break">Will be either <code>drink</code> or <code>eat</code> depending on the type of entry</td>
  52. </tr>
  53. </table>
  54. </div>
  55. </div>
  56. <?php endif; ?>
  57. </div>
  58. <script>
  59. $(function(){
  60. function bind_keyboard_shortcuts() {
  61. $(".text-custom-eat").keydown(function(e){
  62. if(e.keyCode == 13) {
  63. $(".btn-custom-eat").click();
  64. return false;
  65. }
  66. });
  67. $(".text-custom-drink").keydown(function(e){
  68. if(e.keyCode == 13) {
  69. $(".btn-custom-drink").click();
  70. return false;
  71. }
  72. });
  73. }
  74. bind_keyboard_shortcuts();
  75. function location_error(msg) {
  76. $("#note_location_msg").val(msg);
  77. $("#note_location_chk").removeAttr("checked");
  78. $("#note_location_loading").hide();
  79. $("#note_location_img").hide();
  80. $("#note_location_msg").removeClass("img-visible");
  81. }
  82. var map_template_wide = "<?= build_static_map_url('{lat}', '{lng}', 180, 700, 15) ?>";
  83. var map_template_small = "<?= build_static_map_url('{lat}', '{lng}', 320, 480, 15) ?>";
  84. function fetch_location() {
  85. $("#note_location_loading").show();
  86. navigator.geolocation.getCurrentPosition(function(position){
  87. $.getJSON('/options.json', {
  88. latitude: position.coords.latitude,
  89. longitude: position.coords.longitude
  90. }, function(response) {
  91. // save and restore the value entered in the custom fields
  92. var custom_eat = $('#custom_eat').val();
  93. var custom_drink = $('#custom_drink').val();
  94. var selected = false;
  95. if($("#custom_drink:focus").length == 1) {
  96. selected = '#custom_drink';
  97. }
  98. if($("#custom_eat:focus").length == 1) {
  99. selected = '#custom_eat';
  100. }
  101. $("#entry-buttons").html(response.buttons);
  102. $("#note_tzoffset").val(response.tz_offset);
  103. $("#note_date").val(response.date_str);
  104. $("#note_time").val(response.time_str);
  105. // restore the custom values entered
  106. $('#custom_eat').val(custom_eat);
  107. $('#custom_drink').val(custom_drink);
  108. if(selected) {
  109. $(selected).focus();
  110. }
  111. bind_keyboard_shortcuts();
  112. });
  113. $("#note_location_loading").hide();
  114. var geo = "geo:" + (Math.round(position.coords.latitude * 100000) / 100000) + "," + (Math.round(position.coords.longitude * 100000) / 100000) + ";u=" + position.coords.accuracy;
  115. $("#note_location_msg").val(geo);
  116. $("#note_location").val(geo);
  117. $("#note_location_img_small").attr("src", map_template_small.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  118. $("#note_location_img_wide").attr("src", map_template_wide.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  119. $("#note_location_img").show();
  120. $("#note_location_msg").addClass("img-visible");
  121. }, function(err){
  122. if(err.code == 1) {
  123. location_error("The website was not able to get permission");
  124. } else if(err.code == 2) {
  125. location_error("Location information was unavailable");
  126. } else if(err.code == 3) {
  127. location_error("Timed out getting location");
  128. }
  129. });
  130. }
  131. $("#note_location_chk").click(function(){
  132. if($(this).attr("checked") == "checked") {
  133. if(navigator.geolocation) {
  134. $.post("/prefs", {
  135. enabled: 1
  136. });
  137. fetch_location();
  138. } else {
  139. location_error("Browser location is not supported");
  140. }
  141. } else {
  142. $("#note_location_img").hide();
  143. $("#note_location_msg").removeClass("img-visible");
  144. $("#note_location_msg").val('');
  145. $("#note_location").val('');
  146. $.post("/prefs", {
  147. enabled: 0
  148. });
  149. }
  150. });
  151. if($("#location_enabled").val() == 1) {
  152. $("#note_location_chk").attr("checked","checked");
  153. fetch_location();
  154. }
  155. });
  156. </script>
  157. <style type="text/css">
  158. .scroll-container {
  159. width: 100%;
  160. overflow-x: scroll;
  161. }
  162. .scroll-container .break {
  163. word-break: break-all;
  164. }
  165. </style>