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.

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