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.

276 lines
9.7 KiB

6 years ago
6 years ago
  1. <div class="narrow">
  2. <?= partial('partials/header') ?>
  3. <div style="clear: both;">
  4. <div class="alert alert-success hidden" id="test_success"><strong>Success! </strong><a href="" id="post_href">View your post</a></div>
  5. <div class="alert alert-danger hidden" id="test_error"><strong>Something went wrong!</strong><br>Your Micropub endpoint indicated that something went wrong creating the post.</div>
  6. </div>
  7. <form role="form" style="margin-top: 20px;" id="note_form">
  8. <div class="form-group" style="margin-top: 18px;">
  9. <label>Event Name</label>
  10. <input type="text" class="form-control" id="event_name" placeholder="" value="">
  11. </div>
  12. <div class="form-group" style="margin-top: 18px;">
  13. <label>Location</label>
  14. <input type="text" class="form-control" id="event_location" placeholder="" value="">
  15. <span class="help-block" id="location_preview"></span>
  16. </div>
  17. <div id="map" class="hidden" style="width: 100%; height: 180px; border-radius: 4px; border: 1px #ccc solid;"></div>
  18. <div class="form-group" id="start_date" style="margin-top: 18px;">
  19. <label>Start Date/Time</label>
  20. <div class="form-group">
  21. <input type="text" class="form-control date" placeholder="<?= date('Y-m-d') ?>" value="" style="max-width: 40%; margin-right: 4px; float: left;">
  22. <input type="text" class="form-control time" placeholder="14:30" value="" style="max-width: 40%; margin-right: 4px; float: left;">
  23. <input type="text" class="form-control timezone" placeholder="-08:00" style="max-width: 15%;">
  24. </div>
  25. </div>
  26. <div class="form-group" id="end_date" style="margin-top: 18px;">
  27. <label>End Date/Time (Optional)</label>
  28. <div class="form-group">
  29. <input type="text" class="form-control date" placeholder="<?= date('Y-m-d') ?>" value="" style="max-width: 40%; margin-right: 4px; float: left;">
  30. <input type="text" class="form-control time" placeholder="14:30" value="" style="max-width: 40%; margin-right: 4px; float: left;">
  31. <input type="text" class="form-control timezone" placeholder="-08:00" style="max-width: 15%;">
  32. </div>
  33. </div>
  34. <div class="form-group" style="margin-top: 18px;">
  35. <label for="note_category">Tags</label>
  36. <input type="text" id="note_category" value="" class="form-control">
  37. </div>
  38. <?php if($this->channels): ?>
  39. <div class="form-group">
  40. <label for="note_channel">Channel</label>
  41. <div id="channel-container">
  42. <?php
  43. echo '<select class="form-control" id="note_channel">';
  44. echo '<option value="none"></option>';
  45. foreach($this->channels as $ch) {
  46. echo '<option value="'.htmlspecialchars($ch).'" '.($ch == 'events' ? 'selected' : '').'>'
  47. . htmlspecialchars($ch)
  48. . '</option>';
  49. }
  50. echo '</select>';
  51. ?>
  52. </div>
  53. </div>
  54. <?php endif; ?>
  55. <div style="float: right; margin-top: 6px;">
  56. <button class="btn btn-success" id="btn_post">Post</button>
  57. </div>
  58. </form>
  59. </div>
  60. <link rel="stylesheet" href="/libs/bootstrap-typeahead/typeahead.css">
  61. <script src="/libs/bootstrap-typeahead/typeahead.min.js"></script>
  62. <?php if(Config::$googleMapsAPIKey): ?>
  63. <script src="https://maps.googleapis.com/maps/api/js?key=<?= Config::$googleMapsAPIKey ?>&libraries=places"></script>
  64. <?php endif ?>
  65. <script>
  66. <?php if(Config::$googleMapsAPIKey): ?>
  67. var map = new google.maps.Map(document.getElementById('map'), {
  68. center: new google.maps.LatLng(-45,122),
  69. zoom: 15
  70. });
  71. <?php else: ?>
  72. var map = null;
  73. <?php endif ?>
  74. var d = new Date();
  75. var tzOffset = tz_seconds_to_offset(d.getTimezoneOffset() * 60 * -1);
  76. var selectedPlace;
  77. if(map) {
  78. var gservice = new google.maps.places.AutocompleteService();
  79. var gplaces = new google.maps.places.PlacesService(map);
  80. var selectedPlacePin;
  81. }
  82. $(function(){
  83. // Start the event timezone offset in the browser's timezone
  84. $("#start_date .timezone").attr("placeholder", tzOffset);
  85. $("#end_date .timezone").attr("placeholder", tzOffset);
  86. // As soon as a time is entered, move the placeholder offset to the value
  87. $("#start_date .time").on("keydown", function(){
  88. $("#start_date .timezone").val($("#start_date .timezone").attr("placeholder"));
  89. });
  90. $("#end_date .time").on("keydown", function(){
  91. $("#end_date .timezone").val($("#end_date .timezone").attr("placeholder"));
  92. });
  93. if(map) {
  94. $("#event_location").typeahead({
  95. minLength: 3,
  96. highlight: true
  97. }, {
  98. limit: 5,
  99. async: true,
  100. source: function(query, sync, async) {
  101. gservice.getPlacePredictions({ input: query }, function(predictions, status) {
  102. if (status == google.maps.places.PlacesServiceStatus.OK) {
  103. async(predictions);
  104. }
  105. });
  106. },
  107. display: function(item) {
  108. return item.description;
  109. },
  110. templates: {
  111. suggestion: function(item) {
  112. return '<span>'+item.description+'</span>';
  113. }
  114. }
  115. }).bind('typeahead:select', function(ev, suggestion) {
  116. gplaces.getDetails({
  117. placeId: suggestion.place_id,
  118. fields: ["geometry", "name", "address_component", "url", "utc_offset"]
  119. }, function(result, status) {
  120. if(status != google.maps.places.PlacesServiceStatus.OK) {
  121. alert('Cannot find address');
  122. return;
  123. }
  124. console.log(result);
  125. map.setCenter(result.geometry.location);
  126. if(selectedPlacePin) {
  127. selectedPlacePin.setMap(null);
  128. selectedPlacePin = null;
  129. }
  130. selectedPlacePin = new google.maps.Marker({
  131. position: result.geometry.location,
  132. map: map
  133. });
  134. selectedPlace = {
  135. type: ["h-card"],
  136. properties: {
  137. name: [result.name],
  138. latitude: [result.geometry.location.lat()],
  139. longitude: [result.geometry.location.lng()],
  140. }
  141. };
  142. address = '';
  143. locality = '';
  144. region = '';
  145. country = '';
  146. for(var i in result.address_components) {
  147. if(result.address_components[i].types.includes('street_number')) {
  148. address += ' '+result.address_components[i].short_name;
  149. }
  150. if(result.address_components[i].types.includes('route')) {
  151. address += ' '+result.address_components[i].short_name;
  152. }
  153. if(result.address_components[i].types.includes('locality')) {
  154. locality = result.address_components[i].long_name;
  155. }
  156. if(result.address_components[i].types.includes('administrative_area_level_1')) {
  157. region = result.address_components[i].long_name;
  158. }
  159. if(result.address_components[i].types.includes('country')) {
  160. country = result.address_components[i].short_name;
  161. }
  162. }
  163. if(address) {
  164. selectedPlace['properties']['street-address'] = [address.trim()];
  165. }
  166. if(locality) {
  167. selectedPlace['properties']['locality'] = [locality];
  168. }
  169. if(region) {
  170. selectedPlace['properties']['region'] = [region];
  171. }
  172. if(country) {
  173. selectedPlace['properties']['country-name'] = [country];
  174. }
  175. if(result.utc_offset) {
  176. tzOffset = tz_seconds_to_offset(result.utc_offset * 60);
  177. $("#start_date .timezone").attr("placeholder", tzOffset);
  178. $("#end_date .timezone").attr("placeholder", tzOffset);
  179. if($("#start_date .timezone").val()) {
  180. $("#start_date .timezone").val($("#start_date .timezone").attr("placeholder"));
  181. }
  182. if($("#end_date .timezone").val()) {
  183. $("#end_date .timezone").val($("#end_date .timezone").attr("placeholder"));
  184. }
  185. }
  186. $("#map").removeClass("hidden");
  187. $("#location_preview").text('');
  188. });
  189. });
  190. }
  191. });
  192. $("#note_category").tokenfield({
  193. createTokensOnBlur: true,
  194. beautify: true
  195. });
  196. $("#btn_post").click(function(){
  197. var event_start = $("#start_date .date").val();
  198. if($("#start_date .time").val()) {
  199. event_start += "T"+$("#start_date .time").val()+$("#start_date .timezone").val();
  200. }
  201. var event_end;
  202. if($("#end_date .date").val()) {
  203. event_end = $("#end_date .date").val();
  204. if($("#end_date .time").val()) {
  205. event_end += "T"+$("#end_date .time").val()+$("#end_date .timezone").val();
  206. }
  207. }
  208. var properties = {
  209. name: [$("#event_name").val()],
  210. start: [event_start],
  211. location: (selectedPlace ? selectedPlace : $("#event_location").val()),
  212. category: tokenfieldToArray("#note_category")
  213. };
  214. if(event_end) {
  215. properties.end = event_end;
  216. }
  217. if($("#note_channel").val()) {
  218. properties['p3k-channel'] = $("#note_channel").val();
  219. }
  220. $.post("/micropub/postjson", {
  221. data: JSON.stringify({
  222. "type": ["h-event"],
  223. "properties": properties
  224. })
  225. }, function(response){
  226. if(response.location != false) {
  227. $("#test_success").removeClass('hidden');
  228. $("#test_error").addClass('hidden');
  229. $("#post_href").attr("href", response.location);
  230. $("#note_form").slideUp(200, function(){
  231. $(window).scrollTop($("#test_success").position().top);
  232. });
  233. } else {
  234. $("#test_success").addClass('hidden');
  235. $("#test_error").removeClass('hidden');
  236. }
  237. });
  238. return false;
  239. });
  240. </script>