-
Notifications
You must be signed in to change notification settings - Fork 16
/
sample.jinja2
267 lines (242 loc) · 13.7 KB
/
sample.jinja2
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
{% extends "sitebase.jinja2" %}
{% set page_title = _("My Kits") %}
{% set show_breadcrumbs = True %}
{% set profile_header = True %}
{% set profile_header_active = "kits" %}
{% set profile_header_name = source_name %}
{% set profile_account_id = account_id %}
{% set profile_source_id = source_id %}
{% block head %}
<link rel="stylesheet" href="/static/vendor/jquery-ui-1.12.1/jquery-ui.min.css"/>
<link rel="stylesheet" href="/static/vendor/css/jquery.timepicker.min.css"/>
<script type="text/javascript" src="/static/vendor/jquery-ui-1.12.1/jquery-ui.min.js"></script>
<script type="text/javascript" src="/static/vendor/js/jquery.timepicker.min.js"></script>
<!-- Download and include supported languages and dialects here -->
<script type="text/javascript" src="/static/vendor/jquery-ui-i18n/datepicker-es.js"></script>
<script type="text/javascript" src="/static/vendor/jquery-ui-i18n/datepicker-ja.js"></script>
<script type="text/javascript" src="/static/vendor/jquery-validation/messages_{{ _(EN_US_KEY) }}.js"></script>
<script>
function verifyDissociateSample() {
let confirmMsg = "{{ _('Do you really want to remove this sample from this source?') }} " +
"{{ _('Doing so will remove any collection info saved for this sample and will') }} " +
"{{ _('unlink it from all surveys.') }}";
if (confirm(confirmMsg)) {
window.location.replace('/accounts/{{ account_id }}/sources/{{ source_id }}/samples/{{ sample.sample_id }}/remove');
}
return false;
}
$(document).ready(function(){
let form_name = 'sample_form';
preventImplicitSubmission(form_name);
// TODO - this parsing will break for one part and three part language tags.
let lang = "{{ _(EN_US_KEY) }}";
let first = lang.split("_")[0];
let second = lang.split("_")[1];
let datepicker_args = {};
if (first != null && second != null && (first + "-" + second.toUpperCase()) in $.datepicker.regional)
datepicker_args = $.datepicker.regional[first + "-" + second.toUpperCase()]
else if (first != null && first in $.datepicker.regional)
datepicker_args = $.datepicker.regional[first]
else
console.log("Unsupported datepicker language, defaulting to english")
datepicker_args.onClose = function(){
$(this).valid()
}
// Determine date picker format
let datePickerFormat = "mm/dd/yy" //datepicker defaults to this if unspecified
if ("dateFormat" in datepicker_args)
datePickerFormat = datepicker_args.dateFormat;
// Set initial date from normalized hidden field
let normalizedInitialDate = $("#sample_date_normalized").val()
if (normalizedInitialDate !== "") {
let initial = $.datepicker.parseDate("mm/dd/yy", normalizedInitialDate)
$("#sample_date").val($.datepicker.formatDate(datePickerFormat, initial))
}
// Let jquery validate check date format, update hidden field with normalized value
$.validator.addMethod("monthDayYear", function(value, element)
{
let localizedValue = value;
let check;
try {
let parsed = $.datepicker.parseDate(datePickerFormat, localizedValue);
let normalized = $.datepicker.formatDate("mm/dd/yy", parsed)
$("#sample_date_normalized").val(normalized)
check = true
}
catch (e) {
check = false
}
return this.optional(element) || check;
//Note that when we translate this string,
//we have to switch MM/DD/YYYY to the
//expected localized date format matching the datepicker settings.
}, "{{ _('Required Format: MM/DD/YYYY') }}");
$.validator.addMethod("dateInPast", function(value, element)
{
let check;
let date = new Date($("#sample_date_normalized").val());
var lower_limit = new Date();
lower_limit.setFullYear(lower_limit.getFullYear() - 10);
if(date < lower_limit) {
check = false;
} else {
check = true;
}
return this.optional(element) || check;
}, "{{ _('Please select a date within the last 10 years.') }}");
$.validator.addMethod("dateInFuture", function(value, element)
{
let check;
let date = new Date($("#sample_date_normalized").val());
var upper_limit = new Date();
upper_limit.setMonth(upper_limit.getMonth() + 1);
if(date > upper_limit) {
check = false;
} else {
check = true;
}
return this.optional(element) || check;
}, "{{ _('Please select a date within the next 30 days.') }}");
$("#sample_date").datepicker(datepicker_args)
$( "#sample_time" ).timepicker({
timeFormat: 'h:mm p',
interval: 30,
{% if sample.sample_time == "" %}
defaultTime: 'now',
{% else %}
defaultTime: '{{ sample.sample_time }}',
{% endif %}
startTime: '0',
dynamic: false,
dropdown: true,
scrollbar: true,
change: function() {
$(this).valid();
}
});
{% if sample.sample_edit_locked and not admin_mode %}
$("#sample_date").datepicker('disable');
$("#sample_time").prop('disabled', true);
{% endif %}
$("form[name='" + form_name + "']").validate({
// don't automatically move into the Date field
// as that triggers the pop up and it's annoying
focusInvalid: false,
// Specify validation rules
rules: {
// The key name on the left side is the name attribute
// of an input field. Validation rules are defined
// on the right side
sample_date: {
required: true,
monthDayYear: true,
dateInPast: true,
dateInFuture: true
},
sample_time: "required",
{% if not is_environmental %}
sample_site: "required",
{% endif %}
// Make sure the form is submitted to the destination defined
// in the "action" attribute of the form when valid
submitHandler: function (form) {
form.submit();
}
}
});
{% if not is_environmental %}
// https://github.com/jquery-validation/jquery-validation/issues/1872#issuecomment-257874743
$('#sample_site').on('change', function(){
$("form[name='" + form_name + "']").validate().element('select');
});
{% endif %}
});
function goToKits() {
window.location.replace("/accounts/{{ account_id }}/sources/{{ source_id }}/kits");
return false;
}
</script>
{% endblock %}
{% block breadcrumb %}
<li class="breadcrumb-item"><a href="/accounts/{{account_id}}" class="breadcrumb-item-profile">{{ _('Dashboard') }}</a></li>
<li class="breadcrumb-item"><a href="/accounts/{{account_id}}/sources/{{source_id}}" class="breadcrumb-item-profile">{{ source_name }}</a></li>
<li class="breadcrumb-item active-profile" aria-current="page">{{ _('My Kits') }}</li>
{% endblock %}
{% block content %}
<form method="post" id="sample_form" name="sample_form">
<input id="sample_date_normalized" name="sample_date_normalized" type="hidden" value="{{ sample.date | e }}" />
<div class="container profile-container">
{% if need_reconsent_data or need_reconsent_biospecimen %}
<div id="consent_alert" class="alert alert-consent mt-4" role="alert">
{{ _('To update your existing samples or contribute new samples, please review the following:') }}<br />
<ul>
{% if need_reconsent_data %}
<li><a href="/accounts/{{account_id}}/sources/{{source_id}}/reconsent/data">{{ _('Consent to Act as a Research Subject') }}</a></li>
{% endif %}
{% if need_reconsent_biospecimen %}
<li><a href="/accounts/{{account_id}}/sources/{{source_id}}/reconsent/biospecimen">{{ _('Consent to Act as a Research Subject - Biospecimen and Future Use Research') }}</a></li>
{% endif %}
</ul>
</div>
{% endif %}
<div class="card mt-4 p-4">
<div class="row barcode-row">
<div class="barcode-col">
<img src="/static/img/tube_icon.svg" width="24" height="24" />
</div>
<div class="barcode-col barcode-text">
<span>{{ sample.sample_barcode }}</span>
</div>
</div>
<div class="card mt-4 sample-card">
<div class="row">
<div class="col-12 col-md-6">
<label for="sample_date" name="sample_date_label" class="sample-label">{{ _('Date of Sample Collection') }}*</label>
<input id="sample_date" name="sample_date" class="form-control" type="text" autocomplete="off" {% if (need_reconsent_data or need_reconsent_biospecimen) and not admin_mode %}disabled{% endif %} required\>
</div>
<div class="col-12 col-md-6">
<label for="sample_time" name="sample_time_label" class="sample-label">{{ _('Time of Sample Collection') }}*</label>
<input id="sample_time" name="sample_time" class="form-control" type="text" value="{{ sample.time | e}}" autocomplete="off" {% if (need_reconsent_data or need_reconsent_biospecimen) and not admin_mode %}disabled{% endif %} required\>
</div>
</div>
<div class="row mt-2">
<div class="col-12">
<label for="sample_site" name="sample_site_label" class="sample-label">{{ _('Sample Type') }}*</label>
<select id="sample_site" name="sample_site" class="form-control" required {% if not admin_mode and (sample.sample_edit_locked or need_reconsent_data or need_reconsent_biospecimen) %}disabled{% endif %}>
{% if sample.sample_site is none %}
<option disabled selected value> -- {{ _('Select a sample type') }} -- </option>
{% endif %}
{% for i in range(sample_sites| length) %}
{% set site=sample_sites[i] %}
{% set site_text=sample_sites_text[i] %}
<option value="{{site}}" {% if sample.sample_site == site %}selected {% endif %}>{{site_text}}</option>
{% endfor %}
</select>
</div>
</div>
<div class="row mt-2">
<div class="col-12">
<label for="sample_notes" id="sample_notes_label" class="sample-label">{{ _('Notes') }}</label>
<textarea class="form-control" id="sample_notes" name="sample_notes" placeholder="{{ _('(Optional) Is there anything else about this sample that you would like to add?') }}" rows=3 {% if not admin_mode and (sample.sample_edit_locked or need_reconsent_data or need_reconsent_biospecimen) %}disabled{% endif %}>{{ sample.sample_notes if sample.sample_notes is not none else '' |e}}</textarea>
</div>
</div>
<div class="row">
<div class="col-12 mt-4 text-end">
{% if not sample.sample_remove_locked and not admin_mode %}
<button class="btn btn-white-red-border m-2" name="remove_button" onClick="return verifyDissociateSample();">{{ _('Remove') }}</button>
{% endif %}
{% if sample.sample_edit_locked and not admin_mode %}
<span class="kit-tooltip-text">{{ _('Your sample has been received by our lab and can no longer be edited. Please <a href="mailto:microsetta@ucsd.edu">contact us</a> with any questions.') }}</span>
{% else %}
<button class="btn btn-white-blue-border m-2" name="cancel_button" onClick="return goToKits();">{{ _('Cancel') }}</button>
{% if (not need_reconsent_data and not need_reconsent_biospecimen) or admin_mode %}
<button type="submit" class="btn btn-blue-gradient m-2" name="kit_id_button" id="kit_id_button">{{ _('Save') }}</button>
{% endif %}
{% endif %}
</div>
</div>
</div>
</div>
</div>
</form>
{% endblock %}