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.

212 lines
7.4 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 class="form-group">
  5. <h3>Date</h3>
  6. <input type="date" class="form-control" style="max-width:160px; float:left; margin-right: 4px;" id="note_date" name="note_date" value="">
  7. <input type="text" class="form-control" style="max-width:90px; float:left; margin-right: 4px;" id="note_time" name="note_time" value="">
  8. <input type="text" class="form-control" style="max-width:90px;" id="note_tzoffset" name="note_tzoffset" value="">
  9. </div>
  10. <div id="entry-buttons">
  11. <?= partial('partials/entry-buttons', ['options'=>$this->default_options]) ?>
  12. </div>
  13. <div class="form-group">
  14. <h3>Location <input type="checkbox" id="note_location_chk" value=""><img src="/images/spinner.gif" id="note_location_loading" style="display: none;"></h3>
  15. <input type="text" id="note_location_msg" value="" class="form-control" placeholder="" readonly="readonly">
  16. <input type="hidden" id="note_location" name="location">
  17. <input type="hidden" id="location_enabled" value="<?= $this->location_enabled ?>">
  18. <div id="note_location_img" style="display: none;">
  19. <img src="" height="180" id="note_location_img_wide" class="img-responsive">
  20. <img src="" height="320" id="note_location_img_small" class="img-responsive">
  21. </div>
  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 tz_seconds_to_offset(seconds) {
  61. var tz_offset = '';
  62. var hours = zero_pad(Math.abs(seconds / 60 / 60));
  63. var minutes = zero_pad(Math.floor(seconds / 60) % 60);
  64. return (seconds < 0 ? '-' : '+') + hours + ":" + minutes;
  65. }
  66. function zero_pad(num) {
  67. num = "" + num;
  68. if(num.length == 1) {
  69. num = "0" + num;
  70. }
  71. return num;
  72. }
  73. // Set the date from JS
  74. var d = new Date();
  75. $("#note_date").val(d.getFullYear()+"-"+zero_pad(d.getMonth()+1)+"-"+zero_pad(d.getDate()));
  76. $("#note_time").val(zero_pad(d.getHours())+":"+zero_pad(d.getMinutes())+":"+zero_pad(d.getSeconds()));
  77. $("#note_tzoffset").val(tz_seconds_to_offset(d.getTimezoneOffset() * 60 * -1));
  78. function bind_keyboard_shortcuts() {
  79. $(".text-custom-eat").keydown(function(e){
  80. if(e.keyCode == 13) {
  81. $(".btn-custom-eat").click();
  82. return false;
  83. }
  84. });
  85. $(".text-custom-drink").keydown(function(e){
  86. if(e.keyCode == 13) {
  87. $(".btn-custom-drink").click();
  88. return false;
  89. }
  90. });
  91. }
  92. bind_keyboard_shortcuts();
  93. function location_error(msg) {
  94. $("#note_location_msg").val(msg);
  95. $("#note_location_chk").removeAttr("checked");
  96. $("#note_location_loading").hide();
  97. $("#note_location_img").hide();
  98. $("#note_location_msg").removeClass("img-visible");
  99. }
  100. var map_template_wide = "<?= build_static_map_url('{lat}', '{lng}', 180, 700, 15) ?>";
  101. var map_template_small = "<?= build_static_map_url('{lat}', '{lng}', 320, 480, 15) ?>";
  102. function fetch_location() {
  103. $("#note_location_loading").show();
  104. navigator.geolocation.getCurrentPosition(function(position){
  105. $.getJSON('/options.json', {
  106. latitude: position.coords.latitude,
  107. longitude: position.coords.longitude
  108. }, function(response) {
  109. // save and restore the value entered in the custom fields
  110. var custom_eat = $('#custom_eat').val();
  111. var custom_drink = $('#custom_drink').val();
  112. var selected = false;
  113. if($("#custom_drink:focus").length == 1) {
  114. selected = '#custom_drink';
  115. }
  116. if($("#custom_eat:focus").length == 1) {
  117. selected = '#custom_eat';
  118. }
  119. $("#entry-buttons").html(response.buttons);
  120. // restore the custom values entered
  121. $('#custom_eat').val(custom_eat);
  122. $('#custom_drink').val(custom_drink);
  123. if(selected) {
  124. $(selected).focus();
  125. }
  126. bind_keyboard_shortcuts();
  127. });
  128. $("#note_location_loading").hide();
  129. var geo = "geo:" + (Math.round(position.coords.latitude * 100000) / 100000) + "," + (Math.round(position.coords.longitude * 100000) / 100000) + ";u=" + position.coords.accuracy;
  130. $("#note_location_msg").val(geo);
  131. $("#note_location").val(geo);
  132. $("#note_location_img_small").attr("src", map_template_small.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  133. $("#note_location_img_wide").attr("src", map_template_wide.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  134. $("#note_location_img").show();
  135. $("#note_location_msg").addClass("img-visible");
  136. }, function(err){
  137. if(err.code == 1) {
  138. location_error("The website was not able to get permission");
  139. } else if(err.code == 2) {
  140. location_error("Location information was unavailable");
  141. } else if(err.code == 3) {
  142. location_error("Timed out getting location");
  143. }
  144. });
  145. }
  146. $("#note_location_chk").click(function(){
  147. if($(this).attr("checked") == "checked") {
  148. if(navigator.geolocation) {
  149. $.post("/prefs", {
  150. enabled: 1
  151. });
  152. fetch_location();
  153. } else {
  154. location_error("Browser location is not supported");
  155. }
  156. } else {
  157. $("#note_location_img").hide();
  158. $("#note_location_msg").removeClass("img-visible");
  159. $("#note_location_msg").val('');
  160. $("#note_location").val('');
  161. $.post("/prefs", {
  162. enabled: 0
  163. });
  164. }
  165. });
  166. if($("#location_enabled").val() == 1) {
  167. $("#note_location_chk").attr("checked","checked");
  168. fetch_location();
  169. }
  170. });
  171. </script>
  172. <style type="text/css">
  173. .scroll-container {
  174. width: 100%;
  175. overflow-x: scroll;
  176. }
  177. .scroll-container .break {
  178. word-break: break-all;
  179. }
  180. </style>