summaryrefslogtreecommitdiff
path: root/views/new-itinerary.php
blob: 7020e1097b78aeb1271c2aed639beeeeccf6dea4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<div class="narrow">
  <?= partial('partials/header') ?>

    <div style="clear: both;">
      <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>
      <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>
    </div>

    <form role="form" style="margin-top: 20px;" id="note_form">

      <h4>Legs</h4>
      <div class="form-group" id="itinerary-legs-container">
        <div style="display:none;" id="leg-template">
          <div class="itinerary-leg">
            <input type="hidden" class="template" value="1">
            <div class="remove">&times;</div>
            <div class="row">
              <div class="col-xs-3">
                <label>Transit Type</label>
                <select class="leg-transit-type form-control">
                  <option value="air">Air</option>
                  <option value="train">Train</option>
                  <option value="bus">Bus</option>
                  <option value="boat">Boat</option>
                  <option value="generic">Generic</option>
                </select>
              </div>
              <div class="col-xs-3">
                <label>Operator</label>
                <input type="text" class="form-control leg-operator" placeholder="Operator" value="">
              </div>
              <div class="col-xs-3">
                <label>Number</label>
                <input type="text" class="form-control leg-number" placeholder="Number" value="">
              </div>
            </div>
            <div class="row">
              <div class="col-xs-2">
                <label>Origin</label>
                <input type="text" class="form-control leg-origin" placeholder="Origin" value="">
              </div>
              <div class="col-xs-9">
                <label>Departure</label>
                <div class="form-group leg-departure">
                  <input type="text" class="form-control leg-departure-date date" style="max-width:160px; float:left; margin-right: 4px;" value="">
                  <input type="text" class="form-control leg-departure-time time" style="max-width:85px; float:left; margin-right: 4px;" value="">
                  <input type="text" class="form-control leg-departure-tz tz" style="max-width:75px;" value="">
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xs-2">
                <label>Destination</label>
                <input type="text" class="form-control leg-destination" placeholder="Destination" value="">
              </div>
              <div class="col-xs-9">
                <label>Arrival</label>
                <div class="form-group leg-arrival">
                  <input type="text" class="form-control leg-arrival-date date" style="max-width:160px; float:left; margin-right: 4px;" value="">
                  <input type="text" class="form-control leg-arrival-time time" style="max-width:85px; float:left; margin-right: 4px;" value="">
                  <input type="text" class="form-control leg-arrival-tz tz" style="max-width:75px;" value="">
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <button class="btn btn-default" id="btn_add_leg">Add Leg</button>

      <div class="form-group" style="margin-top: 18px;">
        <label for="note_category">Tags (comma-separated)</label>
        <input type="text" id="note_category" value="" class="form-control">
      </div>

      <div style="float: right; margin-top: 6px;">
        <button class="btn btn-success" id="btn_post">Post</button>
      </div>

    </form>

</div>



<style type="text/css">
.itinerary-leg {
  margin-bottom: 10px;
  padding: 8px 8px;
  border-left: 4px #5bc0de solid;
  background-color: #f4f8fa;
}
.itinerary-leg .row {
  margin-bottom: 10px;
}
.itinerary-leg .remove {
  float: right;
  margin-right: 10px;
  margin-top: 0;
  font-size: 20px;
  cursor: pointer;
  color: #40A9C7;
}
.itinerary-leg .remove:hover {
  color: #7ECDE4;
}
</style>

<script>
$(function(){

  $("#btn_add_leg").click(function(){
    add_leg();
    return false;
  });

  function bind_leg_x() {
    $(".itinerary-leg .remove").unbind("click").click(function(){
      // Don't allow the only leg to be removed. (2 because there is an invisible one as the template)
      if($(".itinerary-leg").length > 2) {
        $(this).parent().remove();
      }
    });
  }

  function add_leg() {
    $("#itinerary-legs-container").append($("#leg-template").html());

    $(".itinerary-leg:last .template").val(0);
    var d = new Date();
    $(".itinerary-leg:last .date").val(d.getFullYear()+"-"+zero_pad(d.getMonth()+1)+"-"+zero_pad(d.getDate()));
    $(".itinerary-leg:last .time").val(zero_pad(d.getHours())+":"+zero_pad(d.getMinutes())+":00");
    $(".itinerary-leg:last .tz").val(tz_seconds_to_offset(d.getTimezoneOffset() * 60 * -1));

    /*
    $('.itinerary-leg:last .date').datepicker({
      'format': 'yyyy-mm-dd',
      'autoclose': true,
      'todayHighlight': true
    });

    $('.itinerary-leg:last .time').timepicker({
      'showDuration': true,
      'timeFormat': 'g:ia'
    });

    $('.itinerary-leg:last').datepair();
    */

    bind_leg_x();
  }

  add_leg();

  $("#btn_post").click(function(){

    var itinerary = [];

    $(".itinerary-leg").each(function(){
      if($(this).find(".template").val() == 1) { return; }

      var departure = $(this).find(".leg-departure-date").val()+"T"+$(this).find(".leg-departure-time").val()+$(this).find(".leg-departure-tz").val();
      var arrival = $(this).find(".leg-arrival-date").val()+"T"+$(this).find(".leg-arrival-time").val()+$(this).find(".leg-arrival-tz").val();

      itinerary.push({
        "type": "h-leg",
        "properties": {
          "transit-type": $(this).find(".leg-transit-type").val(),
          "operator": $(this).find(".leg-operator").val(),
          "number": $(this).find(".leg-number").val(),
          "origin": $(this).find(".leg-origin").val(),
          "destination": $(this).find(".leg-destination").val(),
          "departure": departure,
          "arrival": arrival
        }
      });
    });

    var category = csv_to_array($("#note_category").val());

    $.post("/micropub/postjson", {
      data: JSON.stringify({
        "type": "h-entry",
        "properties": {
          "itinerary": itinerary,
          "category": category
        }
      })
    }, function(data){
      var response = JSON.parse(data);

      if(response.location != false) {
        $("#test_success").removeClass('hidden');
        $("#test_error").addClass('hidden');
        $("#post_href").attr("href", response.location);
      } else {
        $("#test_success").addClass('hidden');
        $("#test_error").removeClass('hidden');
      }

    });
    return false;
  });

});

<?= partial('partials/syndication-js') ?>

</script>