aboutsummaryrefslogtreecommitdiffstats
path: root/templates/main/jams/join.html
blob: 4bd4f2b02aca5e825e18e0adcacbff17813b73f0 (plain) (blame)
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
{% extends "main/base.html" %}
{% block title %}Code Jams | Join{% endblock %}
{% block og_title %}Code Jams | Join{% endblock %}

{% macro show_question(question) %}
    <div id="div-{{ question.id }}">
        <div class="uk-form-label">
            {% if question.optional %}
                <label class="uk-form-label" style="margin-top: 0" for="{{ question.id }}">
                    <strong>{{ question.title }}</strong>
                    <br />
                    <span class="uk-text-meta">You may skip this question</span>
                </label>
            {% else %}
                <label class="uk-form-label" style="margin-top: 0" for="{{ question.id }}">
                    <strong>{{ question.title }}</strong>
                    <br />
                    <span class="uk-text-meta">This question is required</span>
                </label>
            {% endif %}
        </div>
        <div class="uk-form-controls uk-form-controls-text">
            {% if question.type == "checkbox" %}
                {% if question.optional %}
                    <input class="uk-checkbox" type="checkbox" name="{{ question.id }}" id="{{ question.id }}">
                    <label for="{{ question.id }}" style="padding-left: 0.7rem;">Confirm</label>
                {% else %}
                    <input class="uk-checkbox" type="checkbox" name="{{ question.id }}" id="{{ question.id }}" required>
                    <label for="{{ question.id }}" style="padding-left: 0.7rem;">Confirm</label>
                {% endif %}

            {% elif question.type == "email" %}
                {% if question.optional %}
                    <input class="uk-input" type="email" name="{{ question.id }}" id="{{ question.id }}" placeholder="[email protected]">
                {% else %}
                    <input class="uk-input" type="email" name="{{ question.id }}" id="{{ question.id }}" placeholder="[email protected]" required>
                {% endif %}

            {% elif question.type == "number" %}
                {% if question.optional %}
                    <input class="uk-input" type="number" max="{{ question.data.max }}" min="{{ question.data.min }}" name="{{ question.id }}" id="{{ question.id }}" value="{{ question.data.min }}">
                {% else %}
                    <input class="uk-input" type="number" max="{{ question.data.max }}" min="{{ question.data.min }}" name="{{ question.id }}" id="{{ question.id }}" value="{{ question.data.min }}" required>
                {% endif %}

            {% elif question.type == "radio" %}
                {% if question.optional %}
                    {% for option in question.data.options %}
                        <input class="uk-radio radio-{{ question.id }}" type="radio" name="{{ question.id }}" id="{{ question.id }}-{{ option }}" value="{{ option }}">
                        <label style="padding-left: 0.7rem; padding-right: 1rem;" for="{{ question.id }}-{{ option }}">{{ option }}</label>
                    {% endfor %}
                {% else %}
                    {% for option in question.data.options %}
                        <input class="uk-radio radio-{{ question.id }}" type="radio" name="{{ question.id }}" id="{{ question.id }}-{{ option }}" value="{{ option }}" required>
                        <label style="padding-left: 0.7rem; padding-right: 1rem;" for="{{ question.id }}-{{ option }}">{{ option }}</label>
                    {% endfor %}
                {% endif %}

            {% elif question.type == "range" %}
                <div class="uk-flex uk-flex-between">
                    {% if question.optional %}
                        {% for num in range(question.data.min, question.data.max + 1) %}
                            <span>
                                <input class="uk-radio radio-{{ question.id }}" type="radio" name="{{ question.id }}" id="{{ question.id }}-{{ num }}" value="{{ num }}">
                                <label style="padding-left: 0.3rem;" for="{{ question.id }}-{{ num }}">{{ num }}</label>
                            </span>
                        {% endfor %}
                    {% else %}
                        {% for num in range(question.data.min, question.data.max + 1) %}
                            <span>
                                <input class="uk-radio radio-{{ question.id }}" type="radio" name="{{ question.id }}" id="{{ question.id }}-{{ num }}" value="{{ num }}" required>
                                <label style="padding-left: 0.3rem;" for="{{ question.id }}-{{ num }}">{{ num }}</label>
                            </span>
                        {% endfor %}
                    {% endif %}
                </div>

            {% elif question.type == "text" %}
                {% if question.optional %}
                    <input class="uk-input" type="text" name="{{ question.id }}" id="{{ question.id }}">
                {% else %}
                    <input class="uk-input" type="text" name="{{ question.id }}" id="{{ question.id }}" required>
                {% endif %}

            {% elif question.type == "textarea" %}
                {% if question.optional %}
                    <textarea class="uk-input uk-textarea fira-code" name="{{ question.id }}" id="{{ question.id }}" style="resize: vertical; min-height: 15rem;"></textarea>
                {% else %}
                    <textarea class="uk-input uk-textarea fira-code" name="{{ question.id }}" id="{{ question.id }}" style="resize: vertical; min-height: 15rem;" required></textarea>
                {% endif %}

            {% elif question.type == "slider" %}
                <div class="uk-flex uk-flex-between">
                    <label class="uk-label" style="margin-right: 1rem;" for="{{ question.id }}" id="{{ question.id }}-slider-value">{{ question.data.min }}</label>
                    <input class="uk-range range-slider" name="{{ question.id }}" id="{{ question.id }}" min="{{ question.data.min }}" max="{{ question.data.max }}" step="1" value="{{ question.data.min }}" type="range">
                </div>

            {% endif %}
        </div>
    </div>
{% endmacro %}

{% block content %}
<div class="uk-section">
    <div class="uk-container uk-container-small">
        <h1 class="uk-header uk-article-title">
            Code Jam {{ jam.number }}: {{ jam.title }}
        </h1>
        <p class="uk-article-meta">
            Bring the thunder!
        </p>
        <p>
            Please fill out the form below to apply for this code jam. Once you've submitted your application and the
            application window has closed, we'll review it and let you know whether you've been entered!
        </p>
        <p>
            Please note that you will not be able to edit your application after you've submitted it.
        </p>
        <hr class="uk-divider-icon" />

        {{ form.preamble_html | safe }}

        <hr class="uk-divider-icon" />

        {% if jam.state != "announced" %}
            <p class="uk-alert uk-alert-primary">
                Unfortunately, we're not accepting applications for this code jam right now - but we appreciate your
                interest. Keep an eye on <code>#announcements</code> on Discord for information on the next jam!
            </p>
        {% else %}
            <form action="{{ url_for("main.jams.join", jam=jam.number) }}" method="post" class="uk-form-horizontal uk-flex uk-flex-column">
                {% for question in questions %}
                    {{ show_question(question) }}
                    <br />
                {% endfor %}
                <br />

                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>

                <div class="uk-text-center">
                    <a class="uk-button uk-button-default" href="{{ url_for("main.jams.index") }}">
                        <i class="uk-icon fa-fw far fa-arrow-left"></i> &nbsp;Back
                    </a>
                    <button type="submit" class="uk-button uk-button-primary" name="submit" id="submit" disabled>
                        <i class="uk-icon fa-fw far fa-check"></i> &nbsp;Apply
                    </button>
                </div>
            </form>

        {% endif %}
    </div>
</div>

<script type="application/javascript">
    "use strict";

    // noinspection JSAnnotator (It thinks I'm not assigning this for some reason)
    const questions = {{ questions | tojson }};
    const button = document.getElementById("submit");

    function validateEmail(email) {
        let re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(String(email).toLowerCase());
    }

    function isNum(value) {
        return !isNaN(parseInt(value));
    }

    function checkInputs() {
        let input, inputs, div;
        let disabled = false;

        for (let question of questions) {
            div = document.getElementById("div-" + question.id);

            switch (question.type) {
                case "checkbox":
                    if (!question.optional) {
                        let input = document.getElementById(question.id);

                        if (!input.checked) {
                            disabled = true;
                            div.classList.add("danger-input");
                        } else {
                            div.classList.remove("danger-input");
                        }
                    }
                    break;
                case "email":
                    input = document.getElementById(question.id);

                    if (!question.optional || input.value.length > 0) {
                        if (input.value.length < 5 || !validateEmail(input.value)) {
                            disabled = true;
                            div.classList.add("danger-input");
                        } else {
                            div.classList.remove("danger-input");
                        }
                    } else {
                        div.classList.remove("danger-input");
                    }
                    break;
                case "number":
                    input = document.getElementById(question.id);

                    if (!question.optional || input.value.length > 0) {
                        if (input.value.length < 1 || !isNum(input.value)) {
                            disabled = true;
                            div.classList.add("danger-input");
                        } else {
                            let val = parseInt(input.value);

                            if (val < question.data.min || val > question.data.max) {
                                disabled = true;
                                div.classList.add("danger-input");
                            } else {
                                div.classList.remove("danger-input");
                            }
                        }
                    }
                    break;
                case "radio":
                    if (! question.optional) {
                        inputs = document.getElementsByClassName("radio-" + question.id);
                        let selected = null;

                        for (let inner of inputs) {
                            if (inner.checked) {
                                selected = inner;
                            }
                        }

                        if (selected === null) {
                            disabled = true;
                            div.classList.add("danger-input");
                        } else {
                            div.classList.remove("danger-input");
                        }
                    }

                    break;
                case "range":
                    if (! question.optional) {
                        inputs = document.getElementsByClassName("radio-" + question.id);
                        let selected = null;

                        for (let inner of inputs) {
                            if (inner.checked) {
                                selected = inner;
                            }
                        }

                        if (selected === null) {
                            disabled = true;

                            div.classList.add("danger-input");
                        } else {
                            div.classList.remove("danger-input");
                        }
                    }

                    break;
                case "text":
                    if (!question.optional) {
                        input = document.getElementById(question.id);

                        if (input.value.length < 1) {
                            disabled = true;
                            div.classList.add("danger-input");
                        } else {
                            div.classList.remove("danger-input");
                        }
                    }

                    break;
                case "textarea":
                    if (!question.optional) {
                        input = document.getElementById(question.id);

                        if (input.value.length < 1) {
                            disabled = true;
                            div.classList.add("danger-input");
                        } else {
                            div.classList.remove("danger-input");
                        }
                    }

                    break;
                case "slider":
                    break;
            }
        }

        button.disabled = disabled;
    }

    function setUpChecks() {
        let input, inputs, label;

        for (let question of questions) {
            switch (question.type) {
                case "checkbox":
                    input = document.getElementById(question.id);
                    input.onchange = checkInputs;

                    break;
                case "email":
                    input = document.getElementById(question.id);
                    input.oninput = checkInputs;

                    break;
                case "number":
                    input = document.getElementById(question.id);
                    input.oninput = checkInputs;
                    input.onchange = checkInputs;

                    break;
                case "radio":
                    inputs = document.getElementsByClassName("radio-" + question.id);

                    for (let inner of inputs) {
                        inner.onchange = checkInputs;
                    }

                    break;
                case "range":
                    inputs = document.getElementsByClassName("radio-" + question.id);

                    for (let inner of inputs) {
                        inner.onchange = checkInputs;
                    }

                    break;
                case "text":
                    input = document.getElementById(question.id);
                    input.oninput = checkInputs;

                    break;
                case "textarea":
                    input = document.getElementById(question.id);
                    input.oninput = checkInputs;

                    break;
                case "slider":
                    input = document.getElementById(question.id);
                    label = document.getElementById(question.id + "-slider-value");

                    input.oninput = function() {
                        label.textContent = this.value;
                        checkInputs();
                    };
                    break;
            }
        }
    }

    setUpChecks();
    checkInputs();
</script>
{% endblock %}