|
@@ -1,69 +1,94 @@
|
|
1
|
+/***************************************************************
|
|
2
|
+* *
|
|
3
|
+* SMAM: Send Me A Mail *
|
|
4
|
+* *
|
|
5
|
+* Made with ♥ by Brendan Abolivier <foss@brendanabolivier.com> *
|
|
6
|
+* Source code available under GPLv3 license here: *
|
|
7
|
+* https://github.com/babolivier/smam/ *
|
|
8
|
+* *
|
|
9
|
+***************************************************************/
|
|
10
|
+
|
|
11
|
+var prefix = 'form'
|
|
12
|
+
|
1
|
13
|
var items = {
|
2
|
|
- name: 'form_name',
|
3
|
|
- addr: 'form_addr',
|
4
|
|
- subj: 'form_subj',
|
5
|
|
- text: 'form_text',
|
|
14
|
+ name: 'name',
|
|
15
|
+ addr: 'addr',
|
|
16
|
+ subj: 'subj',
|
|
17
|
+ text: 'text',
|
6
|
18
|
};
|
7
|
19
|
|
8
|
|
-var server = getServer();
|
9
|
|
-var token = "";
|
10
|
|
-var labels = true;
|
11
|
|
-var lang = {};
|
|
20
|
+var DOMFields = {};
|
|
21
|
+
|
|
22
|
+var server = getServer();
|
|
23
|
+var token = "";
|
|
24
|
+var labels = true;
|
|
25
|
+var lang = [];
|
|
26
|
+var customFields = {};
|
12
|
27
|
|
13
|
28
|
var xhr = {
|
14
|
|
- lang: new XMLHttpRequest(),
|
15
|
|
- token: new XMLHttpRequest(),
|
16
|
|
- send: new XMLHttpRequest()
|
|
29
|
+ customFields: new XMLHttpRequest(),
|
|
30
|
+ lang: new XMLHttpRequest(),
|
|
31
|
+ token: new XMLHttpRequest(),
|
|
32
|
+ send: new XMLHttpRequest()
|
17
|
33
|
}
|
18
|
34
|
|
19
|
35
|
// XHR callbacks
|
20
|
36
|
|
|
37
|
+xhr.customFields.onreadystatechange = function() {
|
|
38
|
+ if(xhr.customFields.readyState == XMLHttpRequest.DONE) {
|
|
39
|
+ customFields = JSON.parse(xhr.customFields.responseText);
|
|
40
|
+ for(let field in customFields) {
|
|
41
|
+ customFields[field].name = field;
|
|
42
|
+ }
|
|
43
|
+ }
|
|
44
|
+};
|
|
45
|
+
|
21
|
46
|
xhr.token.onreadystatechange = function() {
|
22
|
|
- if(xhr.token.readyState == XMLHttpRequest.DONE) {
|
23
|
|
- token = xhr.token.responseText;
|
24
|
|
- }
|
|
47
|
+ if(xhr.token.readyState == XMLHttpRequest.DONE) {
|
|
48
|
+ token = xhr.token.responseText;
|
|
49
|
+ }
|
25
|
50
|
};
|
26
|
51
|
|
27
|
52
|
xhr.lang.onreadystatechange = function() {
|
28
|
|
- if(xhr.lang.readyState == XMLHttpRequest.DONE) {
|
29
|
|
- let response = JSON.parse(xhr.lang.responseText);
|
30
|
|
- lang = response.translations;
|
31
|
|
- labels = response.labels;
|
32
|
|
- }
|
|
53
|
+ if(xhr.lang.readyState == XMLHttpRequest.DONE) {
|
|
54
|
+ let response = JSON.parse(xhr.lang.responseText);
|
|
55
|
+ lang = response.translations;
|
|
56
|
+ labels = response.labels;
|
|
57
|
+ }
|
33
|
58
|
};
|
34
|
59
|
|
35
|
60
|
xhr.send.onreadystatechange = function() {
|
36
|
|
- if(xhr.send.readyState == XMLHttpRequest.DONE) {
|
37
|
|
- let status = document.getElementById('form_status');
|
38
|
|
- status.setAttribute('class', '');
|
39
|
|
- if(xhr.send.status === 200) {
|
40
|
|
- cleanForm();
|
41
|
|
- status.setAttribute('class', 'success');
|
42
|
|
- status.innerHTML = lang.send_status_success;
|
43
|
|
- } else {
|
44
|
|
- status.setAttribute('class', 'failure');
|
45
|
|
- status.innerHTML = lang.send_status_failure;
|
46
|
|
- }
|
47
|
|
- }
|
|
61
|
+ if(xhr.send.readyState == XMLHttpRequest.DONE) {
|
|
62
|
+ let status = document.getElementById('form_status');
|
|
63
|
+ status.setAttribute('class', '');
|
|
64
|
+ if(xhr.send.status === 200) {
|
|
65
|
+ cleanForm();
|
|
66
|
+ status.setAttribute('class', 'success');
|
|
67
|
+ status.innerHTML = lang.send_status_success;
|
|
68
|
+ } else {
|
|
69
|
+ status.setAttribute('class', 'failure');
|
|
70
|
+ status.innerHTML = lang.send_status_failure;
|
|
71
|
+ }
|
|
72
|
+ }
|
48
|
73
|
};
|
49
|
74
|
|
50
|
75
|
|
51
|
76
|
// Returns the server's base URI based on the user's script tag
|
52
|
77
|
// return: the SMAM server's base URI
|
53
|
78
|
function getServer() {
|
54
|
|
- var scripts = document.getElementsByTagName('script');
|
55
|
|
- // Parsing all the <script> tags to find the URL to our file
|
56
|
|
- for(var i = 0; i < scripts.length; i++) {
|
57
|
|
- let script = scripts[i];
|
58
|
|
- if(script.src) {
|
59
|
|
- let url = script.src;
|
60
|
|
- // This should be our script
|
61
|
|
- if(url.match(/form\.js$/)) {
|
62
|
|
- // Port has been found
|
63
|
|
- return url.match(/^(https?:\/\/[^\/]+)/)[1];
|
64
|
|
- }
|
65
|
|
- }
|
66
|
|
- }
|
|
79
|
+ var scripts = document.getElementsByTagName('script');
|
|
80
|
+ // Parsing all the <script> tags to find the URL to our file
|
|
81
|
+ for(var i = 0; i < scripts.length; i++) {
|
|
82
|
+ let script = scripts[i];
|
|
83
|
+ if(script.src) {
|
|
84
|
+ let url = script.src;
|
|
85
|
+ // This should be our script
|
|
86
|
+ if(url.match(/form\.js$/)) {
|
|
87
|
+ // Port has been found
|
|
88
|
+ return url.match(/^(https?:\/\/[^\/]+)/)[1];
|
|
89
|
+ }
|
|
90
|
+ }
|
|
91
|
+ }
|
67
|
92
|
}
|
68
|
93
|
|
69
|
94
|
|
|
@@ -71,100 +96,191 @@ function getServer() {
|
71
|
96
|
// id: HTML identifier of the document's block to create the form into
|
72
|
97
|
// return: nothing
|
73
|
98
|
function generateForm(id) {
|
74
|
|
- // Get translated strings
|
75
|
|
- getLangSync();
|
76
|
|
-
|
77
|
|
- var el = document.getElementById(id);
|
78
|
|
-
|
79
|
|
- // Set the form's behaviour
|
80
|
|
- el.setAttribute('onsubmit', 'sendForm(); return false;');
|
81
|
|
-
|
82
|
|
- // Add an empty paragraph for status
|
83
|
|
- var status = document.createElement('p');
|
84
|
|
- status.setAttribute('id', 'form_status');
|
85
|
|
- el.appendChild(status);
|
86
|
|
-
|
87
|
|
- var input = {
|
88
|
|
- name: getField(items.name, lang.form_name_label, false, 'input'),
|
89
|
|
- addr: getField(items.addr, lang.form_addr_label, true, 'input'),
|
90
|
|
- subj: getField(items.subj, lang.form_subj_label, false, 'input'),
|
91
|
|
- text: getField(items.text, lang.form_mesg_label, false, 'textarea')
|
92
|
|
- };
|
93
|
|
-
|
94
|
|
- // Adding nodes to document
|
95
|
|
-
|
96
|
|
- el.appendChild(input.name);
|
97
|
|
- el.appendChild(input.addr);
|
98
|
|
- el.appendChild(input.subj);
|
99
|
|
- el.appendChild(input.text);
|
100
|
|
-
|
101
|
|
- // Adding submit button
|
102
|
|
-
|
103
|
|
- el.appendChild(getSubmitButton('form_subm', lang.form_subm_label));
|
104
|
|
-
|
105
|
|
- // Retrieve the token from the server
|
106
|
|
-
|
107
|
|
- getToken();
|
|
99
|
+ // Get translated strings
|
|
100
|
+ getLangSync();
|
|
101
|
+ // Get custom fields if defined in the configuration
|
|
102
|
+ getCustomFieldsSync();
|
|
103
|
+
|
|
104
|
+ var el = document.getElementById(id);
|
|
105
|
+
|
|
106
|
+ // Set the form's behaviour
|
|
107
|
+ el.setAttribute('onsubmit', 'sendForm(); return false;');
|
|
108
|
+
|
|
109
|
+ // Add an empty paragraph for status
|
|
110
|
+ var status = document.createElement('p');
|
|
111
|
+ status.setAttribute('id', 'form_status');
|
|
112
|
+ el.appendChild(status);
|
|
113
|
+
|
|
114
|
+ // Default fields
|
|
115
|
+ DOMFields = {
|
|
116
|
+ name: getField({
|
|
117
|
+ name: items.name,
|
|
118
|
+ label: lang.form_name_label,
|
|
119
|
+ type: 'text',
|
|
120
|
+ required: true
|
|
121
|
+ }),
|
|
122
|
+ addr: getField({
|
|
123
|
+ name: items.addr,
|
|
124
|
+ label: lang.form_addr_label,
|
|
125
|
+ type: 'email',
|
|
126
|
+ required: true
|
|
127
|
+ }),
|
|
128
|
+ subj: getField({
|
|
129
|
+ name: items.subj,
|
|
130
|
+ label: lang.form_subj_label,
|
|
131
|
+ type: 'text',
|
|
132
|
+ required: true
|
|
133
|
+ }),
|
|
134
|
+ text: getField({
|
|
135
|
+ name: items.text,
|
|
136
|
+ label: lang.form_mesg_label,
|
|
137
|
+ type: 'textarea',
|
|
138
|
+ required: true
|
|
139
|
+ })
|
|
140
|
+ };
|
|
141
|
+
|
|
142
|
+ // Adding custom fields
|
|
143
|
+ for(let fieldName in customFields) {
|
|
144
|
+ let field = customFields[fieldName];
|
|
145
|
+ DOMFields[fieldName] = getField(field);
|
|
146
|
+ }
|
|
147
|
+
|
|
148
|
+ // Adding all nodes to document
|
|
149
|
+ for(let field in DOMFields) {
|
|
150
|
+ el.appendChild(DOMFields[field]);
|
|
151
|
+ }
|
|
152
|
+
|
|
153
|
+ // Adding submit button
|
|
154
|
+ el.appendChild(getSubmitButton('form_subm', lang.form_subm_label));
|
|
155
|
+
|
|
156
|
+ // Retrieve the token from the server
|
|
157
|
+ getToken();
|
108
|
158
|
}
|
109
|
159
|
|
110
|
160
|
|
111
|
|
-// Returns a form field
|
112
|
|
-// id: field HTML identifier
|
113
|
|
-// placeholder: placeholder text
|
114
|
|
-// email: boolean: is it an email field?
|
115
|
|
-// type: 'input' or 'textarea'
|
116
|
|
-// return: a div node containing a label and an input text field
|
117
|
|
-function getField(id, placeholder, email, type) {
|
118
|
|
- var field = document.createElement('div');
|
119
|
|
-
|
120
|
|
- field.setAttribute('id', id); // TODO: configurable prefix
|
121
|
|
- if(labels) {
|
122
|
|
- field.appendChild(getLabel(id, placeholder, type));
|
123
|
|
- }
|
124
|
|
- field.appendChild(getInputField(id, placeholder, email, type));
|
125
|
|
-
|
126
|
|
- return field;
|
|
161
|
+// Get the HTML element for a given field
|
|
162
|
+// fieldInfos: object describing the field
|
|
163
|
+// required: boolean on whether the field is required or optional
|
|
164
|
+// return: a block containing the field and a label describing it (if enabled)
|
|
165
|
+function getField(fieldInfos) {
|
|
166
|
+ var block = document.createElement('div');
|
|
167
|
+ block.setAttribute('id', fieldInfos.name);
|
|
168
|
+
|
|
169
|
+ // Declare the variable first
|
|
170
|
+ let field = {};
|
|
171
|
+
|
|
172
|
+ // Easily add new supported input types
|
|
173
|
+ switch(fieldInfos.type) {
|
|
174
|
+ case 'textarea': field = getTextarea(fieldInfos);
|
|
175
|
+ break;
|
|
176
|
+ case 'select': field = getSelectField(fieldInfos);
|
|
177
|
+ break;
|
|
178
|
+ default: field = getInputField(fieldInfos);
|
|
179
|
+ break;
|
|
180
|
+ }
|
|
181
|
+
|
|
182
|
+ // We need the input field's ID to bind it to the label, so we generate the
|
|
183
|
+ // field first
|
|
184
|
+ if(labels) {
|
|
185
|
+ block.appendChild(getLabel(fieldInfos.label, field.id));
|
|
186
|
+ }
|
|
187
|
+
|
|
188
|
+ // Assemble the block and return it
|
|
189
|
+ block.appendChild(field);
|
|
190
|
+ return block;
|
127
|
191
|
}
|
128
|
192
|
|
129
|
193
|
|
130
|
194
|
// Returns a label
|
131
|
|
-// id: field HTML identifier
|
132
|
195
|
// content: label's inner content
|
133
|
|
-// type: 'input' or 'textarea'
|
|
196
|
+// id: field HTML identifier
|
134
|
197
|
// return: a label node the field's description
|
135
|
|
-function getLabel(id, content, type) {
|
136
|
|
- var label = document.createElement('label');
|
137
|
|
-
|
138
|
|
- label.setAttribute('for', id + '_' + type);
|
139
|
|
- label.innerHTML = content;
|
140
|
|
-
|
141
|
|
- return label;
|
|
198
|
+function getLabel(content, id) {
|
|
199
|
+ var label = document.createElement('label');
|
|
200
|
+
|
|
201
|
+ label.setAttribute('for', id);
|
|
202
|
+ label.innerHTML = content;
|
|
203
|
+
|
|
204
|
+ return label;
|
142
|
205
|
}
|
143
|
206
|
|
144
|
207
|
|
145
|
|
-// Returns an input text field
|
146
|
|
-// id: field HTML identifier
|
147
|
|
-// placeholder: placeholder text, field description
|
148
|
|
-// email: boolean: is it an email field?
|
149
|
|
-// type: 'input' or 'textarea'
|
150
|
|
-// return: an input text or email field (depending on "email"'s value') with an
|
151
|
|
-// HTML id and a placeholder text
|
152
|
|
-function getInputField(id, placeholder, email, type) {
|
153
|
|
- var input = document.createElement(type);
|
154
|
|
-
|
155
|
|
- if(!type.localeCompare('input')) { // Set input type if input
|
156
|
|
- if(email) {
|
157
|
|
- input.setAttribute('type', 'email');
|
158
|
|
- } else {
|
159
|
|
- input.setAttribute('type', 'text');
|
160
|
|
- }
|
161
|
|
- }
|
162
|
|
-
|
163
|
|
- input.setAttribute('required', 'required');
|
164
|
|
- input.setAttribute('placeholder', placeholder);
|
165
|
|
- input.setAttribute('id', id + '_' + type);
|
166
|
|
-
|
167
|
|
- return input;
|
|
208
|
+// Returns a <select> HTML element
|
|
209
|
+// fieldInfos: object describing the field
|
|
210
|
+// required: boolean on whether the field is required or optional
|
|
211
|
+// return: a <select> element corresponding to the info passed as input
|
|
212
|
+function getSelectField(fieldInfos) {
|
|
213
|
+ let field = document.createElement('select');
|
|
214
|
+
|
|
215
|
+ // Set attributes when necessary
|
|
216
|
+ if(fieldInfos.required) {
|
|
217
|
+ field.setAttribute('required', 'required');
|
|
218
|
+ }
|
|
219
|
+ field.setAttribute('id', prefix + '_' + fieldInfos.name + '_select');
|
|
220
|
+
|
|
221
|
+ let index = 0;
|
|
222
|
+
|
|
223
|
+ // Add header option, useful if the field is required
|
|
224
|
+ let header = document.createElement('option');
|
|
225
|
+ // The value must be an empty string so the browser can block the submit
|
|
226
|
+ // event if the field is required
|
|
227
|
+ header.setAttribute('value', '');
|
|
228
|
+ header.innerHTML = lang.form_select_header_option;
|
|
229
|
+ field.appendChild(header);
|
|
230
|
+
|
|
231
|
+ // Add all options to select
|
|
232
|
+ for(let choice of fieldInfos.options) {
|
|
233
|
+ let option = document.createElement('option');
|
|
234
|
+ // Options' values are incremental numeric indexes
|
|
235
|
+ option.setAttribute('value', index);
|
|
236
|
+ // Set the value defined by the user
|
|
237
|
+ option.innerHTML = choice;
|
|
238
|
+ field.appendChild(option);
|
|
239
|
+ // Increment the index
|
|
240
|
+ index++;
|
|
241
|
+ }
|
|
242
|
+
|
|
243
|
+ return field
|
|
244
|
+}
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+// Returns a <input> HTML element with desired type
|
|
248
|
+// fieldInfos: object describing the field
|
|
249
|
+// required: boolean on whether the field is required or optional
|
|
250
|
+// type: type of the input field (text, email, date...)
|
|
251
|
+// return: a <input> HTML element corresponding to the info passed as input
|
|
252
|
+function getInputField(fieldInfos, required) {
|
|
253
|
+ let field = getBaseField(fieldInfos, required, 'input')
|
|
254
|
+ field.setAttribute('type', fieldInfos.type);
|
|
255
|
+ return field;
|
|
256
|
+}
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+// Returns a <textarea> HTML element
|
|
260
|
+// fieldInfos: object describing the field
|
|
261
|
+// required: boolean on whether the field is required or optional
|
|
262
|
+// return: a <textarea> element corresponding to the info passed as input
|
|
263
|
+function getTextarea(fieldInfos, required) {
|
|
264
|
+ return getBaseField(fieldInfos, required, 'textarea');
|
|
265
|
+}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+// Returns a base HTML element with generic info to be processed by functions at
|
|
269
|
+// higher level
|
|
270
|
+// fieldInfos: object describing the field
|
|
271
|
+// required: boolean on whether the field is required or optional
|
|
272
|
+// tag: the HTML tag the field element must have
|
|
273
|
+// return: a HTML element of the given tag with basic info given as input
|
|
274
|
+function getBaseField(fieldInfos, required, tag) {
|
|
275
|
+ let field = document.createElement(tag);
|
|
276
|
+
|
|
277
|
+ if(fieldInfos.required) {
|
|
278
|
+ field.setAttribute('required', 'required');
|
|
279
|
+ }
|
|
280
|
+ field.setAttribute('placeholder', fieldInfos.label);
|
|
281
|
+ field.setAttribute('id', prefix + '_' + fieldInfos.name + '_' + tag);
|
|
282
|
+
|
|
283
|
+ return field;
|
168
|
284
|
}
|
169
|
285
|
|
170
|
286
|
|
|
@@ -173,74 +289,111 @@ function getInputField(id, placeholder, email, type) {
|
173
|
289
|
// text: button text
|
174
|
290
|
// return: a div node containing the button
|
175
|
291
|
function getSubmitButton(id, text) {
|
176
|
|
- var submit = document.createElement('div');
|
177
|
|
-
|
178
|
|
- submit.setAttribute('id', id);
|
179
|
|
-
|
180
|
|
- var button = document.createElement('button');
|
181
|
|
-
|
182
|
|
- button.setAttribute('type', 'submit');
|
183
|
|
- button.setAttribute('id', id + '_btn');
|
184
|
|
-
|
185
|
|
- button.innerHTML = text;
|
186
|
|
-
|
187
|
|
- submit.appendChild(button);
|
188
|
|
-
|
189
|
|
- return submit;
|
|
292
|
+ var submit = document.createElement('div');
|
|
293
|
+
|
|
294
|
+ submit.setAttribute('id', id);
|
|
295
|
+
|
|
296
|
+ var button = document.createElement('button');
|
|
297
|
+
|
|
298
|
+ button.setAttribute('type', 'submit');
|
|
299
|
+ button.setAttribute('id', id + '_btn');
|
|
300
|
+
|
|
301
|
+ button.innerHTML = text;
|
|
302
|
+
|
|
303
|
+ submit.appendChild(button);
|
|
304
|
+
|
|
305
|
+ return submit;
|
190
|
306
|
}
|
191
|
307
|
|
192
|
308
|
|
193
|
309
|
// Send form data through the XHR object
|
194
|
310
|
// return: nothing
|
195
|
311
|
function sendForm() {
|
196
|
|
- // Clear status
|
197
|
|
- let status = document.getElementById('form_status');
|
198
|
|
- status.setAttribute('class', 'sending');
|
199
|
|
- status.innerHTML = lang.send_status_progress;
|
200
|
|
-
|
201
|
|
- xhr.send.open('POST', server + '/send');
|
202
|
|
- xhr.send.setRequestHeader('Content-Type', 'application/json');
|
203
|
|
- xhr.send.send(JSON.stringify(getFormData()));
|
204
|
|
-
|
205
|
|
- // Get a new token
|
206
|
|
- getToken();
|
|
312
|
+ // Clear status
|
|
313
|
+ let status = document.getElementById('form_status');
|
|
314
|
+ status.setAttribute('class', 'sending');
|
|
315
|
+ status.innerHTML = lang.send_status_progress;
|
|
316
|
+
|
|
317
|
+ xhr.send.open('POST', server + '/send');
|
|
318
|
+ xhr.send.setRequestHeader('Content-Type', 'application/json');
|
|
319
|
+ xhr.send.send(JSON.stringify(getFormData()));
|
|
320
|
+
|
|
321
|
+ // Get a new token
|
|
322
|
+ getToken();
|
207
|
323
|
}
|
208
|
324
|
|
209
|
325
|
|
210
|
326
|
// Fetch form inputs from HTML elements
|
211
|
327
|
// return: an object containing all the user's input
|
212
|
328
|
function getFormData() {
|
213
|
|
- return {
|
214
|
|
- name: document.getElementById(items.name + '_input').value,
|
215
|
|
- addr: document.getElementById(items.addr + '_input').value,
|
216
|
|
- subj: document.getElementById(items.subj + '_input').value,
|
217
|
|
- text: document.getElementById(items.text + '_textarea').value,
|
218
|
|
- token: token
|
219
|
|
- }
|
|
329
|
+ let data = {};
|
|
330
|
+ data.token = token;
|
|
331
|
+ data.custom = {};
|
|
332
|
+
|
|
333
|
+ // Select the field
|
|
334
|
+ let index = 0;
|
|
335
|
+ if(labels) {
|
|
336
|
+ index = 1;
|
|
337
|
+ }
|
|
338
|
+
|
|
339
|
+ // Iterate over all the fields
|
|
340
|
+ for(let field in DOMFields) {
|
|
341
|
+ let el = DOMFields[field].children[index];
|
|
342
|
+ // Do we need to push this field into default or custom fields?
|
|
343
|
+ if(field in customFields) {
|
|
344
|
+ data.custom[field] = el.value;
|
|
345
|
+ } else {
|
|
346
|
+ data[field] = el.value;
|
|
347
|
+ }
|
|
348
|
+ }
|
|
349
|
+
|
|
350
|
+ return data;
|
220
|
351
|
}
|
221
|
352
|
|
222
|
353
|
|
223
|
354
|
// Empties the form fields
|
224
|
355
|
// return: nothing
|
225
|
356
|
function cleanForm() {
|
226
|
|
- document.getElementById(items.name + '_input').value = '';
|
227
|
|
- document.getElementById(items.addr + '_input').value = '';
|
228
|
|
- document.getElementById(items.subj + '_input').value = '';
|
229
|
|
- document.getElementById(items.text + '_textarea').value = '';
|
|
357
|
+ // Select the field
|
|
358
|
+ let index = 0;
|
|
359
|
+ if(labels) {
|
|
360
|
+ index = 1;
|
|
361
|
+ }
|
|
362
|
+
|
|
363
|
+ // Iterate over all the fields
|
|
364
|
+ for(let field in DOMFields) {
|
|
365
|
+ let el = DOMFields[field].children[index];
|
|
366
|
+ // If it's a <select> element, select the first element so it looks
|
|
367
|
+ // like a reset
|
|
368
|
+ if(!el.tagName.toLowerCase().localeCompare('select')) {
|
|
369
|
+ el.children[0].selected = true;
|
|
370
|
+ } else {
|
|
371
|
+ el.value = '';
|
|
372
|
+ }
|
|
373
|
+ }
|
230
|
374
|
}
|
231
|
375
|
|
232
|
376
|
|
233
|
377
|
// Asks the server for a token
|
234
|
378
|
// return: nothing
|
235
|
379
|
function getToken() {
|
236
|
|
- xhr.token.open('GET', server + '/register');
|
237
|
|
- xhr.token.send();
|
|
380
|
+ xhr.token.open('GET', server + '/register');
|
|
381
|
+ xhr.token.send();
|
238
|
382
|
}
|
239
|
383
|
|
240
|
384
|
|
241
|
385
|
// Asks the server for translated strings to display
|
242
|
386
|
// return: notghing
|
243
|
387
|
function getLangSync() {
|
244
|
|
- xhr.lang.open('GET', server + '/lang', false);
|
245
|
|
- xhr.lang.send();
|
|
388
|
+ xhr.lang.open('GET', server + '/lang', false);
|
|
389
|
+ xhr.lang.send();
|
|
390
|
+}
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+// Asks the server for the custom fields if there's one or more set in the
|
|
394
|
+// configuration file
|
|
395
|
+// return: nothing
|
|
396
|
+function getCustomFieldsSync() {
|
|
397
|
+ xhr.customFields.open('GET', server + '/fields', false);
|
|
398
|
+ xhr.customFields.send();
|
246
|
399
|
}
|