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.

209 lines
7.1 KiB

  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. <h4>Legs</h4>
  9. <div class="form-group" id="itinerary-legs-container">
  10. <div style="display:none;" id="leg-template">
  11. <div class="itinerary-leg">
  12. <input type="hidden" class="template" value="1">
  13. <div class="remove">&times;</div>
  14. <div class="row">
  15. <div class="col-xs-3">
  16. <label>Transit Type</label>
  17. <select class="leg-transit-type form-control">
  18. <option value="air">Air</option>
  19. <option value="train">Train</option>
  20. <option value="bus">Bus</option>
  21. <option value="boat">Boat</option>
  22. <option value="generic">Generic</option>
  23. </select>
  24. </div>
  25. <div class="col-xs-3">
  26. <label>Operator</label>
  27. <input type="text" class="form-control leg-operator" placeholder="Operator" value="">
  28. </div>
  29. <div class="col-xs-3">
  30. <label>Number</label>
  31. <input type="text" class="form-control leg-number" placeholder="Number" value="">
  32. </div>
  33. </div>
  34. <div class="row">
  35. <div class="col-xs-2">
  36. <label>Origin</label>
  37. <input type="text" class="form-control leg-origin" placeholder="Origin" value="">
  38. </div>
  39. <div class="col-xs-9">
  40. <label>Departure</label>
  41. <div class="form-group leg-departure">
  42. <input type="text" class="form-control leg-departure-date date" style="max-width:160px; float:left; margin-right: 4px;" value="">
  43. <input type="text" class="form-control leg-departure-time time" style="max-width:85px; float:left; margin-right: 4px;" value="">
  44. <input type="text" class="form-control leg-departure-tz tz" style="max-width:75px;" value="">
  45. </div>
  46. </div>
  47. </div>
  48. <div class="row">
  49. <div class="col-xs-2">
  50. <label>Destination</label>
  51. <input type="text" class="form-control leg-destination" placeholder="Destination" value="">
  52. </div>
  53. <div class="col-xs-9">
  54. <label>Arrival</label>
  55. <div class="form-group leg-arrival">
  56. <input type="text" class="form-control leg-arrival-date date" style="max-width:160px; float:left; margin-right: 4px;" value="">
  57. <input type="text" class="form-control leg-arrival-time time" style="max-width:85px; float:left; margin-right: 4px;" value="">
  58. <input type="text" class="form-control leg-arrival-tz tz" style="max-width:75px;" value="">
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. <button class="btn btn-default" id="btn_add_leg">Add Leg</button>
  66. <div class="form-group" style="margin-top: 18px;">
  67. <label for="note_category">Tags (comma-separated)</label>
  68. <input type="text" id="note_category" value="" class="form-control">
  69. </div>
  70. <div style="float: right; margin-top: 6px;">
  71. <button class="btn btn-success" id="btn_post">Post</button>
  72. </div>
  73. </form>
  74. </div>
  75. <style type="text/css">
  76. .itinerary-leg {
  77. margin-bottom: 10px;
  78. padding: 8px 8px;
  79. border-left: 4px #5bc0de solid;
  80. background-color: #f4f8fa;
  81. }
  82. .itinerary-leg .row {
  83. margin-bottom: 10px;
  84. }
  85. .itinerary-leg .remove {
  86. float: right;
  87. margin-right: 10px;
  88. margin-top: 0;
  89. font-size: 20px;
  90. cursor: pointer;
  91. color: #40A9C7;
  92. }
  93. .itinerary-leg .remove:hover {
  94. color: #7ECDE4;
  95. }
  96. </style>
  97. <script src="/js/script.js"></script>
  98. <script>
  99. $(function(){
  100. $("#btn_add_leg").click(function(){
  101. add_leg();
  102. return false;
  103. });
  104. function bind_leg_x() {
  105. $(".itinerary-leg .remove").unbind("click").click(function(){
  106. // Don't allow the only leg to be removed. (2 because there is an invisible one as the template)
  107. if($(".itinerary-leg").length > 2) {
  108. $(this).parent().remove();
  109. }
  110. });
  111. }
  112. function add_leg() {
  113. $("#itinerary-legs-container").append($("#leg-template").html());
  114. $(".itinerary-leg:last .template").val(0);
  115. var d = new Date();
  116. $(".itinerary-leg:last .date").val(d.getFullYear()+"-"+zero_pad(d.getMonth()+1)+"-"+zero_pad(d.getDate()));
  117. $(".itinerary-leg:last .time").val(zero_pad(d.getHours())+":"+zero_pad(d.getMinutes())+":00");
  118. $(".itinerary-leg:last .tz").val(tz_seconds_to_offset(d.getTimezoneOffset() * 60 * -1));
  119. /*
  120. $('.itinerary-leg:last .date').datepicker({
  121. 'format': 'yyyy-mm-dd',
  122. 'autoclose': true,
  123. 'todayHighlight': true
  124. });
  125. $('.itinerary-leg:last .time').timepicker({
  126. 'showDuration': true,
  127. 'timeFormat': 'g:ia'
  128. });
  129. $('.itinerary-leg:last').datepair();
  130. */
  131. bind_leg_x();
  132. }
  133. add_leg();
  134. $("#btn_post").click(function(){
  135. var itinerary = [];
  136. $(".itinerary-leg").each(function(){
  137. if($(this).find(".template").val() == 1) { return; }
  138. var departure = $(this).find(".leg-departure-date").val()+"T"+$(this).find(".leg-departure-time").val()+$(this).find(".leg-departure-tz").val();
  139. var arrival = $(this).find(".leg-arrival-date").val()+"T"+$(this).find(".leg-arrival-time").val()+$(this).find(".leg-arrival-tz").val();
  140. itinerary.push({
  141. "type": "h-leg",
  142. "properties": {
  143. "transit-type": $(this).find(".leg-transit-type").val(),
  144. "operator": $(this).find(".leg-operator").val(),
  145. "number": $(this).find(".leg-number").val(),
  146. "origin": $(this).find(".leg-origin").val(),
  147. "destination": $(this).find(".leg-destination").val(),
  148. "departure": departure,
  149. "arrival": arrival
  150. }
  151. });
  152. });
  153. var category = $("#note_category").val().split(/[, ]+/)
  154. $.post("/itinerary", {
  155. data: JSON.stringify({
  156. "type": "h-entry",
  157. "properties": {
  158. "itinerary": itinerary,
  159. "category": category
  160. }
  161. })
  162. }, function(data){
  163. var response = JSON.parse(data);
  164. if(response.location != false) {
  165. $("#test_success").removeClass('hidden');
  166. $("#test_error").addClass('hidden');
  167. $("#post_href").attr("href", response.location);
  168. } else {
  169. $("#test_success").addClass('hidden');
  170. $("#test_error").removeClass('hidden');
  171. }
  172. });
  173. return false;
  174. });
  175. });
  176. <?= partial('partials/syndication-js') ?>
  177. </script>