aboutsummaryrefslogtreecommitdiffstats
path: root/templates/manage.html.j2
blob: 55a14bd23e65504dd7a5617637dd3cd05cfaebc3 (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
{% extends "base.html.j2" %}

{% block content %}

<h2>Managing poll <span class="contrast">{{ poll.title }}</span> by <i>{{ poll.author_name }}</i></h2>

<p>
  Share this URL with your peers:<br>
  <a href="{{ poll.share_url() }}">{{ poll.share_url() }}</a>
</p>
<p>
  <strong>Note!</strong> You can only edit this poll if you have this URL or use the same browser session:<br>
  <a href="{{ poll.manage_url() }}">{{ poll.manage_url() }}</a>
</p>

<form class="poll-form" action="/manage/{{ poll.manage_code }}/update_info" method="post">
  <table>
    <tbody>
      <tr>
        <td><label for="title">Title</label></td>
        <td><input type="text" name="title" value="{{ poll.title }}" required></td>
      </tr>
      <tr>
        <td><label for="description">Description (optional)</label></td>
        <td><textarea name="description">{{ poll.description }}</textarea></td>
      </tr>
      <tr>
        <td><label for="author_name">Your name</label></td>
        <td><input type="text" name="author_name" value="{{ poll.author_name }}" required></td>
      </tr>
      <tr>
        <td><label for="author_email">Your email (optional)</label></td>
        <td><input type="text" name="author_email" value="{{ poll.author_email }}"></td>
      </tr>
    </tbody>
  </table>
  <br>
  <input type="submit" value="Update">
</form>

<div>
  <h3>Options</h3>
</div>

<table class="manage-table">
  <thead>
    <tr>
      <th>Start time</th>
      <th>End time</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    {% for choice in poll.choices %}
    <form action="/manage/{{ poll.manage_code }}/delete_choice/{{ choice.id }}" method="post">
      <tr>
        <td>
          <input type="datetime-local" name="start_datetime_{{ choice.id }}" value="{{ choice.start_datetime_notz() }}" disabled
                 {% if last_choice_id == choice.id %}id="last-start-datetime"{% endif %}>
        </td>
        <td>
          <input type="datetime-local" name="end_datetime_{{ choice.id }}" value="{{ choice.end_datetime_notz() }}" disabled
                 {% if last_choice_id == choice.id %}id="last-end-datetime"{% endif %}>
        </td>
        <td>
          <input class="red" type="submit" value="Delete">
        </td>
      </tr>
    </form>
    {% endfor %}
    <form action="/manage/{{ poll.manage_code }}/add_choice" method="post">
      <tr>
        <td>
          <input type="datetime-local" name="start_datetime" required>
        </td>
        <td>
          <input type="datetime-local" name="end_datetime" required>
        </td>
        <td>
          <input class="green" type="submit" value="Add">
        </td>
      </tr>
    </form>
  </tbody>
</table>

<div class="danger-zone">
  <h3>Danger zone</h3>
  <form action="/manage/{{ poll.manage_code }}/delete" method="post">
    <!-- Empty forms make Lynx use HTTP method GET incorrectly, so we add a useless field -->
    <input type="hidden" name="poll_id" value="{{ poll.id }}">
    <input class="red" type="submit" value="Delete poll">
  </form>
</div>

<script>
const hour = 1000 * 60 * 60;

const startDatetimeInput = document.querySelector('input[name="start_datetime"]');
const endDatetimeInput = document.querySelector('input[name="end_datetime"]');

const lastStartDatetimeInput = document.getElementById('last-start-datetime');
const lastEndDatetimeInput = document.getElementById('last-end-datetime');

if (lastStartDatetimeInput !== null && startDatetimeInput.valueAsDate === null) {
  startDatetimeInput.valueAsDate = new Date(lastStartDatetimeInput.valueAsDate.getTime() + hour);
}

startDatetimeInput.addEventListener('blur', onStartDatetimeBlur);

function onStartDatetimeBlur(event) {
  const endDatetimeInput = document.querySelector('input[name="end_datetime"]');
  if (endDatetimeInput.valueAsDate === null) {
    endDatetimeInput.valueAsDate = new Date(event.target.valueAsDate.getTime() + hour);
  }
}
</script>

{% endblock %}