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.

231 lines
8.1 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! We found a Location header in the response!</strong><br>Your post should be on your website now!<br><a href="" id="post_href">View your post</a></div>
  5. <div class="alert alert-danger hidden" id="test_error"><strong>Your endpoint did not return a Location header.</strong><br>See <a href="/creating-a-micropub-endpoint">Creating a Micropub Endpoint</a> for more information.</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" id="start_date" style="margin-top: 18px;">
  13. <label>Start Date/Time</label>
  14. <div class="form-group">
  15. <input type="text" class="form-control date" placeholder="<?= date('Y-m-d') ?>" value="" style="max-width: 40%; margin-right: 4px; float: left;">
  16. <input type="text" class="form-control time" placeholder="14:30" value="" style="max-width: 40%; margin-right: 4px; float: left;">
  17. <input type="text" class="form-control timezone" placeholder="-08:00" style="max-width: 15%;">
  18. </div>
  19. </div>
  20. <div class="form-group" id="end_date" style="margin-top: 18px;">
  21. <label>End Date/Time (Optional)</label>
  22. <div class="form-group">
  23. <input type="text" class="form-control date" placeholder="<?= date('Y-m-d') ?>" value="" style="max-width: 40%; margin-right: 4px; float: left;">
  24. <input type="text" class="form-control time" placeholder="14:30" value="" style="max-width: 40%; margin-right: 4px; float: left;">
  25. <input type="text" class="form-control timezone" placeholder="-08:00" style="max-width: 15%;">
  26. </div>
  27. </div>
  28. <div class="form-group" style="margin-top: 18px;">
  29. <label>Location</label>
  30. <input type="text" class="form-control" id="event_location" placeholder="" value="">
  31. <span class="help-block" id="location_preview"></span>
  32. </div>
  33. <div id="map" class="hidden" style="width: 100%; height: 180px; border-radius: 4px; border: 1px #ccc solid;"></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. <div style="float: right; margin-top: 6px;">
  39. <button class="btn btn-success" id="btn_post">Post</button>
  40. </div>
  41. </form>
  42. </div>
  43. <link rel="stylesheet" href="/libs/bootstrap-typeahead/typeahead.css">
  44. <script src="/libs/bootstrap-typeahead/typeahead.min.js"></script>
  45. <?php if(Config::$googleMapsAPIKey): ?>
  46. <script src="https://maps.googleapis.com/maps/api/js?key=<?= Config::$googleMapsAPIKey ?>&libraries=places"></script>
  47. <?php endif ?>
  48. <script>
  49. <?php if(Config::$googleMapsAPIKey): ?>
  50. var map = new google.maps.Map(document.getElementById('map'), {
  51. center: new google.maps.LatLng(-45,122),
  52. zoom: 15
  53. });
  54. <?php else: ?>
  55. var map = null;
  56. <?php endif ?>
  57. var selectedPlace;
  58. if(map) {
  59. var gservice = new google.maps.places.AutocompleteService();
  60. var gplaces = new google.maps.places.PlacesService(map);
  61. var selectedPlacePin;
  62. }
  63. $(function(){
  64. var d = new Date();
  65. $("#start_date .timezone").val(tz_seconds_to_offset(d.getTimezoneOffset() * 60 * -1));
  66. /* $("#end_date .timezone").val(tz_seconds_to_offset(d.getTimezoneOffset() * 60 * -1)); */
  67. if(map) {
  68. $("#event_location").typeahead({
  69. minLength: 3,
  70. highlight: true
  71. }, {
  72. limit: 5,
  73. async: true,
  74. source: function(query, sync, async) {
  75. gservice.getPlacePredictions({ input: query }, function(predictions, status) {
  76. if (status == google.maps.places.PlacesServiceStatus.OK) {
  77. async(predictions);
  78. }
  79. });
  80. },
  81. display: function(item) {
  82. return item.description;
  83. },
  84. templates: {
  85. suggestion: function(item) {
  86. return '<span>'+item.description+'</span>';
  87. }
  88. }
  89. }).bind('typeahead:select', function(ev, suggestion) {
  90. gplaces.getDetails({
  91. placeId: suggestion.place_id,
  92. fields: ["geometry", "name", "address_component", "url"]
  93. }, function(result, status) {
  94. if(status != google.maps.places.PlacesServiceStatus.OK) {
  95. alert('Cannot find address');
  96. return;
  97. }
  98. map.setCenter(result.geometry.location);
  99. if(selectedPlacePin) {
  100. selectedPlacePin.setMap(null);
  101. selectedPlacePin = null;
  102. }
  103. selectedPlacePin = new google.maps.Marker({
  104. position: result.geometry.location,
  105. map: map
  106. });
  107. selectedPlace = {
  108. type: ["h-card"],
  109. properties: {
  110. name: [result.name],
  111. latitude: [result.geometry.location.lat()],
  112. longitude: [result.geometry.location.lng()],
  113. }
  114. };
  115. address = '';
  116. locality = '';
  117. region = '';
  118. country = '';
  119. for(var i in result.address_components) {
  120. if(result.address_components[i].types.includes('street_number')) {
  121. address += ' '+result.address_components[i].short_name;
  122. }
  123. if(result.address_components[i].types.includes('route')) {
  124. address += ' '+result.address_components[i].short_name;
  125. }
  126. if(result.address_components[i].types.includes('locality')) {
  127. locality = result.address_components[i].long_name;
  128. }
  129. if(result.address_components[i].types.includes('administrative_area_level_1')) {
  130. region = result.address_components[i].long_name;
  131. }
  132. if(result.address_components[i].types.includes('country')) {
  133. country = result.address_components[i].short_name;
  134. }
  135. }
  136. if(address) {
  137. selectedPlace['properties']['street-address'] = [address.trim()];
  138. }
  139. if(locality) {
  140. selectedPlace['properties']['locality'] = [locality];
  141. }
  142. if(region) {
  143. selectedPlace['properties']['region'] = [region];
  144. }
  145. if(country) {
  146. selectedPlace['properties']['country-name'] = [country];
  147. }
  148. $("#map").removeClass("hidden");
  149. $("#location_preview").text('');
  150. });
  151. });
  152. }
  153. });
  154. $("#note_category").tokenfield({
  155. createTokensOnBlur: true,
  156. beautify: true
  157. });
  158. $("#btn_post").click(function(){
  159. var event_start = $("#start_date .date").val();
  160. if($("#start_date .time").val()) {
  161. event_start += "T"+$("#start_date .time").val()+$("#start_date .timezone").val();
  162. }
  163. var event_end;
  164. if($("#end_date .date").val()) {
  165. event_end = $("#end_date .date").val();
  166. if($("#end_date .time").val()) {
  167. event_end += "T"+$("#end_date .time").val()+$("#end_date .timezone").val();
  168. }
  169. }
  170. var properties = {
  171. name: [$("#event_name").val()],
  172. start: [event_start],
  173. location: (selectedPlace ? selectedPlace : $("#event_location").val()),
  174. category: tokenfieldToArray("#note_category")
  175. };
  176. if(event_end) {
  177. properties.end = event_end;
  178. }
  179. $.post("/micropub/postjson", {
  180. data: JSON.stringify({
  181. "type": ["h-event"],
  182. "properties": properties
  183. })
  184. }, function(response){
  185. if(response.location != false) {
  186. $("#test_success").removeClass('hidden');
  187. $("#test_error").addClass('hidden');
  188. $("#post_href").attr("href", response.location);
  189. $("#note_form").slideUp(200, function(){
  190. $(window).scrollTop($("#test_success").position().top);
  191. });
  192. } else {
  193. $("#test_success").addClass('hidden');
  194. $("#test_error").removeClass('hidden');
  195. }
  196. });
  197. return false;
  198. });
  199. </script>