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.

257 lines
9.1 KiB

7 years ago
  1. <div class="narrow">
  2. <?= partial('partials/header') ?>
  3. <div style="clear: both;" class="notice-pad">
  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. <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. <span><input type="text" class="form-control leg-departure-tz tz" style="max-width:75px;" value=""></span>
  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. <span><input type="text" class="form-control leg-arrival-tz tz" style="max-width:75px;" value=""></span>
  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</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>
  98. $(function(){
  99. $("#note_category").tokenfield({
  100. createTokensOnBlur: true,
  101. beautify: true
  102. });
  103. $("#btn_add_leg").click(function(){
  104. add_leg();
  105. return false;
  106. });
  107. function bind_leg_x() {
  108. $(".itinerary-leg .remove").unbind("click").click(function(){
  109. // Don't allow the only leg to be removed. (2 because there is an invisible one as the template)
  110. if($(".itinerary-leg").length > 2) {
  111. $(this).parent().remove();
  112. }
  113. });
  114. }
  115. function timezone_for_airport(code, date, callback) {
  116. $.getJSON("/airport-info?code="+code+"&date="+date, function(data){
  117. callback(data.offset);
  118. });
  119. }
  120. function bind_leg_timezone() {
  121. $(".itinerary-leg .leg-origin, .leg-departure-date").unbind("change").change(function(el){
  122. var airport = $(el.target).parents().find(".leg-origin").val();
  123. var date = $(el.target).parents().find(".leg-departure-date").val();
  124. $(el.target).parents(".itinerary-leg").find(".leg-arrival-date").val(date);
  125. timezone_for_airport(airport, date, function(offset){
  126. $(el.target).parents(".itinerary-leg").find(".leg-departure-tz").val(offset);
  127. $(el.target).parents(".itinerary-leg").find(".leg-arrival-tz").val(offset);
  128. $(el.target).parents(".itinerary-leg").find(".leg-departure-tz").parent().addClass("has-success");
  129. });
  130. });
  131. $(".itinerary-leg .leg-destination, .leg-arrival-date").unbind("change").change(function(el){
  132. var airport = $(el.target).parents().find(".leg-destination").val();
  133. var date = $(el.target).parents().find(".leg-arrival-date").val();
  134. timezone_for_airport(airport, date, function(offset){
  135. $(el.target).parents(".itinerary-leg").find(".leg-arrival-tz").val(offset);
  136. $(el.target).parents(".itinerary-leg").find(".leg-arrival-tz").parent().addClass("has-success");
  137. });
  138. });
  139. }
  140. function add_leg() {
  141. var last_date = $(".itinerary-leg:last .date").val();
  142. var last_airport = $(".itinerary-leg:last .leg-destination").val();
  143. var last_operator = $(".itinerary-leg:last .leg-operator").val();
  144. $("#itinerary-legs-container").append($("#leg-template").html());
  145. $(".itinerary-leg:last .template").val(0);
  146. var d = new Date();
  147. if(last_date) {
  148. $(".itinerary-leg:last .date").val(last_date);
  149. } else {
  150. $(".itinerary-leg:last .date").val(d.getFullYear()+"-"+zero_pad(d.getMonth()+1)+"-"+zero_pad(d.getDate()));
  151. }
  152. $(".itinerary-leg:last .time").val(zero_pad(d.getHours())+":"+zero_pad(d.getMinutes())+":00");
  153. $(".itinerary-leg:last .tz").val(tz_seconds_to_offset(d.getTimezoneOffset() * 60 * -1));
  154. $(".itinerary-leg:last .leg-origin").val(last_airport);
  155. $(".itinerary-leg:last .leg-operator").val(last_operator);
  156. /*
  157. $('.itinerary-leg:last .date').datepicker({
  158. 'format': 'yyyy-mm-dd',
  159. 'autoclose': true,
  160. 'todayHighlight': true
  161. });
  162. $('.itinerary-leg:last .time').timepicker({
  163. 'showDuration': true,
  164. 'timeFormat': 'g:ia'
  165. });
  166. $('.itinerary-leg:last').datepair();
  167. */
  168. bind_leg_x();
  169. bind_leg_timezone();
  170. }
  171. add_leg();
  172. $("#btn_post").click(function(){
  173. var itinerary = [];
  174. $(".itinerary-leg").each(function(){
  175. if($(this).find(".template").val() == 1) { return; }
  176. var departure = $(this).find(".leg-departure-date").val()+"T"+$(this).find(".leg-departure-time").val()+$(this).find(".leg-departure-tz").val();
  177. var arrival = $(this).find(".leg-arrival-date").val()+"T"+$(this).find(".leg-arrival-time").val()+$(this).find(".leg-arrival-tz").val();
  178. itinerary.push({
  179. "type": ["h-leg"],
  180. "properties": {
  181. "transit-type": [$(this).find(".leg-transit-type").val()],
  182. "operator": [$(this).find(".leg-operator").val()],
  183. "number": [$(this).find(".leg-number").val()],
  184. "origin": [$(this).find(".leg-origin").val()],
  185. "destination": [$(this).find(".leg-destination").val()],
  186. "departure": [departure],
  187. "arrival": [arrival]
  188. }
  189. });
  190. });
  191. var category = tokenfieldToArray("#note_category");
  192. properties = {
  193. itinerary: itinerary
  194. };
  195. if(category.length > 0) {
  196. properties['category'] = category;
  197. }
  198. $("#btn_post").addClass("loading disabled").text("Working...");
  199. $.post("/micropub/postjson", {
  200. data: JSON.stringify({
  201. "type": ["h-entry"],
  202. "properties": properties
  203. })
  204. }, function(response){
  205. if(response.location != false) {
  206. $("#test_success").removeClass('hidden');
  207. $("#test_error").addClass('hidden');
  208. $("#post_href").attr("href", response.location);
  209. $("#note_form").addClass("hidden");
  210. } else {
  211. $("#test_success").addClass('hidden');
  212. $("#test_error").removeClass('hidden');
  213. $("#btn_post").removeClass("loading disabled").text("Post");
  214. }
  215. });
  216. return false;
  217. });
  218. });
  219. <?= partial('partials/syndication-js') ?>
  220. </script>