-
Notifications
You must be signed in to change notification settings - Fork 16
/
sample.jinja2
212 lines (190 loc) · 10.2 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
{% extends "sitebase.jinja2" %}
{% set page_title = _("Sample Information") %}
{% set show_breadcrumbs = True %}
{% set disable_bootstrap = True %}
{% 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-validation/messages_{{ _(EN_US_KEY) }}.js"></script>
<script>
$(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') }}");
$("#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: '8',
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
},
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 %}
});
</script>
{% endblock %}
{% block breadcrumb %}
<li class="breadcrumb-item"><a href="/accounts/{{account_id}}">{{ _('Account') }}</a></li>
<li class="breadcrumb-item"><a href="/accounts/{{account_id}}/sources/{{source_id}}">{{ _('Source') }}</a></li>
<li class="breadcrumb-item active" aria-current="page">{{ _('Sample Information') }}</li>
{% endblock %}
{% block content %}
<div class="container">
<form method="post" id="sample_form" name="sample_form">
{% if sample.sample_edit_locked %}
<div class="alert alert-success" role="alert">
{{ _('Sample Recorded, Editing is Locked') }}
</div>
{% endif %}
<div class="form-group row">
<label for="sample" name="sample_label" class="col-sm-2 col-form-label">{{ _('Barcode') }}</label>
<div class="col-sm-4">
<input id="view_sample" name="view_sample" class="form-control" type="text" value="{{ sample.sample_barcode |e }}" disabled="disabled" readonly/>
</div>
</div>
<div class="form-group row">
<label for="sample_date" name="sample_date_label" class="col-sm-2 col-form-label">{{ _('Date') }}</label>
<div class="col-sm-4">
<input id="sample_date" name="sample_date" class="form-control" type="text" autocomplete="off" required\>
</div>
<input id="sample_date_normalized" name="sample_date_normalized" type="hidden" value="{{ sample.date | e }}" />
<label for="sample_date" generated="true" class="error"></label>
</div>
<div class="form-group row">
<label for="sample_time" name="sample_time_label" class="col-sm-2 col-form-label">{{ _('Time') }}</label>
<div class="col-sm-4">
<input id="sample_time" name="sample_time" class="form-control" type="text" value="{{ sample.time | e}}" autocomplete="off" required\>
</div>
<label for="sample_time" generated="true" class="error"></label>
</div>
{% if not is_environmental %}
<div class="form-group row">
<div class="col-sm-12">
{% if not sample.sample_edit_locked or admin_mode %}
<div class="row">
<div class="col-sm-6">
<ul>
<lh><small id="sample_site_help" class="form-text text-muted">{{ _('Guidelines for site identification') }}:</small></lh>
<li><small id="sample_site_help" class="form-text text-muted">{{ _('If collecting a') }} <i>{{ _('BLOOD') }}</i> {{ _('sample, please select Blood (skin prick)') }}</small></li>
<li><small id="sample_site_help" class="form-text text-muted">{{ _('For all swabs, please select the site as precisely as possible from the options available') }}</small></li>
</ul>
</div>
</div>
{% endif %}
<div class="row">
<label for="sample_site" name="sample_site_label" class="col-sm-2 col-form-label">{{ _('Site sampled') }}</label>
<div class="col-sm-4">
<select id="sample_site" name="sample_site" class="form-control" required {% if sample.sample_edit_locked and not admin_mode %}disabled{% endif %}>
{% if not sample.sample_site %}
<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>
<label for="sample_site" generated="true" class="error"></label>
</div>
</div>
</div>
{% endif %}
<div class="form-group">
<label for="sample_notes" id="sample_notes_label">{{ _('Notes') }}</label>
<div class="col-sm-10">
<textarea class="form-control" id="sample_notes" name="sample_notes" placeholder="{{ _('(Optional) Is there else about this sample that you would like to add?') }}" rows=3 {% if sample.sample_edit_locked and not admin_mode %}disabled{% endif %}>{{ sample.sample_notes if sample.sample_notes is not none else '' |e}}</textarea>
</div>
</div>
<button type="submit" class="btn btn-primary" {% if sample.sample_edit_locked and not admin_mode %}disabled{% endif %}>{{ _('Update') }}</button>
</form>
</div>
{% endblock %}