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.

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