-
Notifications
You must be signed in to change notification settings - Fork 16
/
account_details.jinja2
230 lines (218 loc) · 10.8 KB
/
account_details.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
{% extends "sitebase.jinja2" %}
{% set page_title = _("Account Details") %}
{% set show_breadcrumbs = True %}
{% block head %}
<script type="text/javascript" language="javascript" src="/static/js/ruleset.js"></script>
<!-- Defines COUNTRIES_LIST, based on ebaranov's country/state json with corrections -->
<!-- See https://gist.github.com/ebaranov/41bf38fdb1a2cb19a781 -->
<script type="text/javascript" language="javascript" src="/static/js/country_state_list.js"></script>
<script type="text/javascript" language="javascript" src="/static/js/us_states.js"></script>
<script type="text/javascript" language="javascript" src="/static/vendor/jquery-validation/messages_{{ _(EN_US_KEY) }}.js"></script>
<script>
$(document).ready(function(){
let form_name = 'acct_form';
preventImplicitSubmission(form_name);
preclude_whitespace("#kit_name");
// Initialize form validation on the registration form.
// It has the name attribute "registration"
$("form[name='" + form_name + "']").validate({
// 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
first_name: "required",
last_name: "required",
street: "required",
city: "required",
state: "required",
post_code: "required",
language: "required",
{% if CREATE_ACCT %}
kit_name: {
required: "#code:blank",
remote: {
url: "/check_kit_valid"
}
},
code: {
required: "#kit_name:blank",
remote: {
url: "/check_activation_code",
data: {
email: function() {
return $("#email").val();
}
}
}
},
{% 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();
}
}
});
// Link Handlers
// In our test databases, state sometimes has line breaks, so
// more complex parsing becomes necessary
var start_code = {{ account.address.state | e | tojson }};
cc = new JQuerySelectInput("country_code", "#country_code");
new DelegateOutput(function(code){
if (code == "GB")
{
$("#city_label").text("Town*");
$("#state_label").text("County*");
$("#post_code_label").text("Postcode*");
$("#state").empty();
for (var country of COUNTRIES_LIST)
{
if (country.country != "United Kingdom")
continue;
for (var state of country.states)
{
var option = $('<option></option>')
.attr("value", state)
.text(state);
// We don't really have state codes for other
// countries...
if (state == start_code)
option.attr('selected','selected');
$("#state").append(option);
}
}
}
else if (code === "MX") {
$("#city_label").text("{{ _('City') }}*");
$("#state_label").text("{{ _('State') }}*");
$("#post_code_label").text("{{ _('Zip Code') }}*");
$("#state").empty();
for (var country of COUNTRIES_LIST)
{
if (country.country !== "Mexico")
continue;
for (var state of country.states)
{
var option = $('<option></option>')
.attr("value", state)
.text(state);
// We don't really have state codes for other
// countries...
if (state == start_code)
option.attr('selected','selected');
$("#state").append(option);
}
}
}
else
{
$("#city_label").text("{{ _('City') }}*");
$("#state_label").text("{{ _('State') }}*");
$("#post_code_label").text("{{ _('Zip Code') }}*");
$("#state").empty();
for (var state of US_STATES)
{
var option = $('<option></option>')
.attr("value", state[0])
.text(state[1]);
if (state[0] == start_code)
option.attr('selected','selected');
$("#state").append(option);
}
}
},cc);
});
</script>
{% endblock %}
{% block breadcrumb %}
{% if not CREATE_ACCT %}
<li class="breadcrumb-item"><a href="/accounts/{{account.account_id}}">{{ _('Account') }}</a></li>
{% endif %}
<li class="breadcrumb-item active" aria-current="page">{{ _('Account Details') }}</li>
{% endblock %}
{% block content %}
<div class="card">
<h5 class="card-header">{{ _('Account Details') }}</h5>
<div class="card-body">
<form id="acct_form" name="acct_form" method="post">
<div class="form-group">
<label for="email" name="email_label">{{ _('Email') }}*</label>
<input id="email" name="email" class="form-control" type="hidden" value="{{account.email |e}}"/>
<input id="view_email" name="view_email" class="form-control" type="email" value="{{account.email |e}}" disabled="disabled" readonly/>
</div>
<div class="form-group">
<label for="first_name" name="first_name_label">{{ _('First Name') }}*</label>
<input id="first_name" name="first_name" class="form-control" value="{{account.first_name |e}}" type="text" />
</div>
<div class="form-group">
<label for="last_name" name="last_name_label">{{ _('Last Name') }}*</label>
<input id="last_name" name="last_name" class="form-control" value="{{account.last_name |e}}" type="text" />
</div>
<div class="form-group">
<label for="country_code" id="country_code_label">{{ _('Country') }}*</label>
<br>
<select id="country_code" name="country_code">
<option value="MX" {% if account.address.country_code == "MX" %} selected {% endif %} >{{ _('Mexico') }}</option>
<option value="US" {% if account.address.country_code == "US" %} selected {% endif %} >{{ _('United States') }}</option>
<option value="GB" {% if account.address.country_code == "GB" %} selected {% endif %} >{{ _('United Kingdom') }}</option>
</select>
</div>
<div class="form-group">
<label for="street" id="street_label" >{{ _('Street Address') }}*</label>
<input id="street" name="street" class="form-control" value="{{account.address.street |e}}" type="text" />
</div>
<div class="form-group">
<label for="city" id="city_label"></label>
<input id="city" name="city" class="form-control" value="{{account.address.city |e}}" type="text" />
</div>
<div class="form-group">
<label for="state" id="state_label"></label>
<select id="state" name="state" class="form-control">
{% for code, full_name in US_STATES %}
<option value="{{code}}" {% if account.address.state == code %}selected {% endif %}>{{full_name}}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="post_code" id="post_code_label"></label>
<input id="post_code" name="post_code" class="form-control" value="{{account.address.post_code |e}}" type="text" />
</div>
<div class="form-group">
<label for="language" name="language_label">{{ _('Preferred language for future communications') }}*</label>
<br>
<select id="language" name="language">
{% for lang_key in languages %}
{% set lang_val = languages[lang_key].value %}
{% set lang_display = languages[lang_key].display_text %}
<option value={{ lang_val }} {% if account.language == lang_val %} selected {% endif %} >{{ lang_display }}</option>
{% endfor %}
</select>
</div>
{% if CREATE_ACCT %}
<div class="card mb-3">
<div class="card-header">
{{ _('Activation Info') }}
</div>
<div class="card-body">
<div class="form-group">
<label for="kit_name" name="kit_name_label">{{ _('Kit ID') }}</label>
<input id="kit_name" name="kit_name" class="form-control" type="text"/>
</div>
<div class="text-center">-{{ _('OR') }}-</div>
<div class="form-group">
<label for="code" name="code_label">{{ _('Activation Code') }}</label>
<input id="code" name="code" class="form-control" type="text" placeholder="TMI-XXXXX-XXXXX-XXXXX"/>
</div>
</div>
</div>
{% endif %}
{% if CREATE_ACCT %}
<button type="submit" class="btn btn-primary">{{ _('Save') }}</button>
{% else %}
<button type="submit" class="btn btn-primary">{{ _('Save') }}</button>
{% endif %}
</form>
</div>
</div>
{% endblock %}