-
Notifications
You must be signed in to change notification settings - Fork 1
/
words.html
598 lines (533 loc) · 19.9 KB
/
words.html
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Review {{language}} Conversion</title>
<link rel="stylesheet" href="/css/blueprint/screen.css" type="text/css" media="screen">
<link rel="stylesheet" href="/css/blueprint/print.css" type="text/css" media="print">
<!--[if lt IE 8]>
<link rel="stylesheet" href="/css/blueprint/ie.css" type="text/css" media="screen, projection">
<![endif]-->
<link rel="stylesheet" type="text/css" href="/css/fonts.css">
<style>
textarea {
width: 500px;
height: 40px;
border: 2px solid #cccccc;
padding: 5px;
font-size: 18px;
font-variant-ligatures: normal;
}
.default {
font-family: "Courier New";
}
</style>
<script src="/js/utils.js"></script>
<script src="/js/osageConverter.js"></script>
<script src="/js/osage_utils.js"></script>
<script type="text/javascript" >
// Navigate to phrases.
function getPrevious() {
indexObj = document.getElementById('index');
index = parseInt(indexObj.innerText);
if (index > 1) {
dataRequest(index - 1, -1);
}
}
function getNext() {
indexObj = document.getElementById('index');
index = parseInt(indexObj.innerText);
if (index >= 0) {
dataRequest(index + 1, 1);
}
}
// Jump to specific index.
function goTo(inputArea) {
indexObj = document.getElementById(inputArea);
index = parseInt(indexObj.value);
if (index >= 0) {
dataRequest(index, 0);
}
}
// Code to request {{language}} data at index with optional filter.
// Direction indicates previous (-1) or next (+1)
function dataRequest(index, direction) {
// Prepare for the call to the backendvar xmlhttp;
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
// Deal with the results
xmlhttp.onreadystatechange=function() {
if(xmlhttp.readyState==4) {
var returned_json = xmlhttp.responseText;
var index = document.getElementById('index');
var oldOsage = document.getElementById('OldOsage');
var unicodeOsage = document.getElementById('UnicodeOsage');
var english = document.getElementById('English');
var newIndex = document.getElementById('newIndex');
var status = document.getElementById('status');
var errorMsg = document.getElementById('errorMsg');
var comment = document.getElementById('comment');
var dbName = document.getElementById('dbName');
var updatePhraseKey1 = document.getElementById('updatePhraseKeyStatus');
var updatePhraseKey2 = document.getElementById('updatePhraseKeyUpload');
var json_obj = JSON.parse(returned_json);
if (json_obj.error) {
// Warn, and don't change values.
alert(json_obj.error);
return;
}
index.value = index.innerHTML = json_obj.index;
newIndex.value = newIndex.innerHTML = json_obj.index;
oldOsage.value = oldOsage.innerHTML = json_obj.oldtext;
english.value = english.innerHTML = json_obj.english;
comment.value = comment.innerHTML = json_obj.comment;
unicodeOsage.value = unicodeOsage.innerHTML = json_obj.utext;
dbName.value = json_obj.dbName
if (updatePhraseKey1) updatePhraseKey1.value = json_obj.phraseKey;
if (updatePhraseKey2) updatePhraseKey2.value = json_obj.phraseKey;
var warnStatus = setWarningBox(json_obj.utext, json_obj.oldtext);
if (json_obj.oldtext && !warnStatus) {
// uText is either empty or same as converted.
convertToUnicode('OldOsage', 'UnicodeOsage', 'old_hex');
}
warning_box = document.getElementById('warning');
var newStatus = json_obj.status;
if (newStatus == "" || newStatus == "unknown") {
newStatus = "Unknown";
}
status.value = status.innerHTML = newStatus;
// Reset the status radio button
setStatusRadioButton("updateStatus", newStatus);
// Handle voice icons
var isMaleVoice = json_obj.soundMaleLink;
var sound = document.getElementById("audio_out_male");
if (isMaleVoice && isMaleVoice != "None") {
setDisplayState('maleVoice', 'block');
if (sound) sound.src = isMaleVoice;
} else {
setDisplayState('maleVoice', 'none');
if (sound) sound.src = null;
}
var isFemaleVoice = json_obj.soundFemaleLink;
sound = document.getElementById("audio_out_female");
if (isFemaleVoice && isFemaleVoice != "None") {
if (sound) sound.src = isFemaleVoice;
setDisplayState('femaleVoice', 'block');
} else {
if (sound) sound.src = null;
setDisplayState('femaleVoice', 'none');
}
}
}
// Set up the call, with filtering.
var filterStatus = getStatusRadioButton("filterStatus");
if (direction == 0) {
// Should not filter if a direct "go to".
filterStatus = "All";
}
dbName = document.getElementById('dbName').value;
var databases = getDatabases();
var target = "/words/getWords/?index=" + index + "&filterStatus=" +
filterStatus +
"&direction=" + direction +
"&dbName=" + dbName
for (var i = 0; i < databases.length; i++) {
target = target + "&databases=" + databases[i];
}
//xmlhttp.open("POST", target, true);
xmlhttp.open("GET", target, true);
var size = target.length;
xmlhttp.send(null);
}
function updatePhraseStatus(indexArea, statusSetter) {
// Get id and new status value.
// Prepare for the call to the backendvar xmlhttp;
var indexObj = document.getElementById(indexArea);
var index = parseInt(indexObj.innerText);
var unicodeData = document.getElementById("UnicodeOsage").value;
var oldOsageData = document.getElementById("OldOsage").value;
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
// Deal with the results
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4) {
var returned_json = xmlhttp.responseText;
var json_obj = JSON.parse(returned_json);
if (json_obj.status) {
var statusObj = document.getElementById("status");
statusObj.value = statusObj.innerHTML = json_obj.status;
}
}
}
// Set up the call with new status.
var newStatus = getStatusRadioButton(statusSetter);
var comment = document.getElementById("comment").value;
var dbName = document.getElementById("dbName").value;
var phraseKey =
document.getElementById("updatePhraseKeyStatus").value;
var target = "/words/updateStatus/?index=" + index + "&newStatus=" + newStatus +
"&unicodePhrase=" + unicodeData + "&comment=" + comment +
"&oldOsageData=" + oldOsageData +
"&dbName=" + dbName +
"&phraseKey=" + phraseKey;
xmlhttp.open("GET", target, true);
var size = target.length;
xmlhttp.send(null);
}
// Which radio button option is checked?
function getStatusRadioButton(statusSetter) {
var statusButtons = document.getElementsByName(statusSetter);
for (var i = 0; i < statusButtons.length; i++) {
if (statusButtons[i].checked) {
return statusButtons[i].value;
}
}
return "";
}
// Set which radio button is checked.
function setStatusRadioButton(statusSetter, status) {
// Set up the call with new status.
var statusButtons = document.getElementsByName(statusSetter);
for (var i = 0; i < statusButtons.length; i++) {
statusButtons[i].checked = (statusButtons[i].value == status);
}
}
function addPhraseToDatastore(oldOsageText, UnicodeOsageText, englishText) {
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
// Deal with the results
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4) {
var returned_json = xmlhttp.responseText;
var json_obj = JSON.parse(returned_json);
if (json_obj.new_index) {
// Update index value.
var indexObj = document.getElementById("index");
indexObj.innerHTML = indexObj.value = json_obj.new_index;
var numEntries = document.getElementById("numEntries");
numEntries.innerHTML = numEntries.value = json_obj.new_index;
}
// Set up alert for results.
alert(json_obj.message);
}
}
// Set up the call to store new phrase information.
var oldTextObj = document.getElementById(oldOsageText);
var uTextObj = document.getElementById(UnicodeOsageText);
var englishTextObj = document.getElementById(englishText);
var comment = document.getElementById('comment');
var oldText = oldTextObj.value;
var unicodeText = uTextObj.innerHTML;
var englishText = englishTextObj.value;
var dbName = document.getElementById("dbName").value;
var target = "/words/addPhrase/?oldtext=" + oldText + "&utext=" + unicodeText +
"&engtext=" + englishText + "&comment=" + comment + "&dbName=" + dbName;
xmlhttp.open("GET", target, true);
var size = target.length;
xmlhttp.send(null);
}
function switchDatabase() {
var dbList = getDatabases();
// TODO: change the database criteria
}
function getDatabases() {
var chk_array = document.getElementsByName("databases");
var dbList = [];
for (var i = 0; i < chk_array.length; i++) {
if (chk_array[i].checked) {
dbList.push(chk_array[i].value);
}
}
return dbList;
}
function onFontSelected(selected) {
var output_text = document.getElementById('UnicodeOsage');
var fontFam = selected.value;
output_text.style.fontFamily = fontFam + ', Arial';
}
function setWarningBox(oldUText, oldOsageText) {
var warning_box = document.getElementById('warning');
if (!oldUText) {
warning_box.style.display = 'none';
return false;
}
var oldTextArea = document.getElementById('oldOsageText');
if (oldOsageText == "") {
warning_box.style.display = 'none';
return false;
}
var convertedUText = oldOsageToUnicode(oldOsageText,
false, true, false);
if (convertedUText !== oldUText) {
warning_box.style.display = 'block';
return true;
}
else {
warning_box.style.display = 'none';
return false;
}
}
function onSoundLoaded(audio_id, target) {
var audio_out = document.getElementById(audio_id);
audio_out.src = target;
audio_out.controls = "true";
// document.getElementById('audio_out').play();
}
function removeSoundFile(genderOfRecording) {
var phraseKey =
document.getElementById("updatePhraseKeyStatus").value;
if (!phraseKey) {
window.alert("Problem getting the phrase Key. The recording is unchanged.");
}
result = window.confirm("Really delete the " + genderOfRecording + " voice recording?");
if (!result == true) {
window.alert("You pressed Cancel. The recording is unchanged.");
return;
}
// Send phrase key and gender to backend.
// Handle result.
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
// Deal with the results
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4) {
var returned_json = xmlhttp.responseText;
var json_obj = JSON.parse(returned_json);
if (json_obj.status) {
var status = document.getElementById("status");
var errorMsg = json_obj.errorMsg;
var retGender = json_obj.gender;
if (status) {
// Turn off the appropriate sound visual.
var sound;
if (retGender == "female") {
sound = document.getElementById("femaleVoice");
} else {
sound = document.getElementById("maleVoice");
}
sound.style.display = 'none';
}
}
}
}
// Set up the call with new status.
var target = "/sound/delete/?phraseKey=" + phraseKey + "&gender=" + genderOfRecording;
xmlhttp.open("GET", target, true);
var size = target.length;
xmlhttp.send(null);
}
// Update to toggle region on/off.
function setDisplayState(id, newstate) { // block or none
var obj = document.getElementById(id);
if(obj) {
obj.style.display = newstate;
}
}
// Initialize the page.
function init() {
// Set warning if store is not same as new conversion.
var oldOsageText = document.getElementById('OldOsage').value;
var uText = document.getElementById('UnicodeOsage').value;
var warnStatus = setWarningBox(uText, oldOsageText);
if (oldOsageText && !warnStatus) {
// uText is either empty or same as converted.
convertToUnicode('OldOsage', 'UnicodeOsage', 'old_hex');
}
// Set initial status.
var status = document.getElementById("status").innerHTML;
setStatusRadioButton("updateStatus", status);
// Reset the sound file display.
var sound = document.getElementById("audio_out_female");
if (sound.currentSrc) {
setDisplayState('femaleVoice', 'block');
} else {
setDisplayState('femaleVoice', 'none');
}
sound = document.getElementById("audio_out_male");
if (sound.currentSrc) {
setDisplayState('maleVoice', 'block');
} else {
setDisplayState('maleVoice', 'none');
}
}
</script>
</head>
<body onload="init()">
<div class="container">
<h2>Data from {{language}} word list: {{dbName}}</h2>
<div class="span-1">
</div>
<div class="span-16">
<h3>Index <span id="index">{{index}}</span> of <span id="numEntries">{{numEntries}}</span></h3>
<textarea id="OldOsage" class="oldOsageText" >{{oldtext}}</textarea>
<br />
<input type="button" value="Convert to Unicode"
onclick="convertToUnicode('OldOsage',
'UnicodeOsage', 'old_hex');">
<input type="checkbox" name="clearOsageDot" id="clearOsageDot" checked>Clear OldOsage dot?
<input type="checkbox" name="convertLatin" id="convertLatin" checked>Convert Latin?
<input type="checkbox" name="lowerCase" id="DoLower">To lower?
Select font: <select onchange="onFontSelected(this);" id="selectKeyboard">
{% for font in fontFamilies %}
<option value="{{font}}">{{font}}</option>
{% endfor %}
</select>
<br />
<textarea id="UnicodeOsage" class="unicodeOsageText">{{utext}}</textarea>
<br />
<textarea id="English" class="default">{{english}}</textarea>
<br />
In database:
<input type="input" id="dbName" class="default" value="{{dbName}}"/>
<input type="button" onclick="toOsageFonts('UnicodeOsage', 'English');"
value="Show Unicode in all fonts">
<br />
<div id="warning" style="font-size:18px; background-color: orange; display:none;">
Warning: The conversion of this data has changed!
<br />
Please select "Convert to Unicode", check the result, and update status!
</div>
<br>
<h4>Status: <span id="status">{{status}}
{% if editOrAdmin %}. Change status of this phrase:{% endif %}</h4>
<form action="" id="set_status">
<input type="radio" name="updateStatus" value="Unknown"> Unknown
<input type="radio" name="updateStatus" value="Verified"> Verified
<input type="radio" name="updateStatus" value="Incorrect"> Incorrect
<input type="radio" name="updateStatus" value="Font"> Font
<input type="radio" name="updateStatus" value="Other"> Other
{% if editOrAdmin %}
<input type="button" value="Update status"
onclick="updatePhraseStatus('index', 'updateStatus');"/>
<input type="hidden" id="updatePhraseKeyStatus" name="phraseKey" value="{{phraseKey}}">
{% endif %}
</form>
<br />
<h4>Comment:</h4>
<textarea id="comment" class="default">{{comment}}</textarea>
<br />
<div id='errorMsg'>{{error}}</div>
{% if showSounds %}
<span id="maleVoice">
M:
<audio id="audio_out_male" controls="controls">
<source src="{{soundMaleLink}}" type="audio/wav">
Your browser does not support the audio element.
</audio>
{% if editOrAdmin %}
<input type="button" value="Remove recording?"
onclick="removeSoundFile('male');"/>
{% endif %}
</span>
<br />
<span id="femaleVoice">
F:
<audio id="audio_out_female" controls="controls">
<source src="{{soundFemaleLink}}" type="audio/wav">
Your browser does not support the audio element.
</audio>
{% if editOrAdmin %}
<input type="button" value="Remove recording?"
onclick="removeSoundFile('female');"/>
{% endif %}
</span>
{% if editOrAdmin %}
<hr>
<h4>Upload sound file for this phrase:</h4>
<form action="/sound/start/" method="GET" enctype="multipart/form-data">
<input type="submit" name="submit" value="Upload sound file">
<input type="hidden" id="updatePhraseKeyUpload" name="phraseKey" value="{{phraseKey}}">
</form>
{% endif %}
{% endif %}
</div>
<div class="span-4 last">
{% if user_nickname %}
<h4>Welcome {{user_nickname}}
{% if user_logout %}
<a href={{user_logout}}>Logout</a>
{% endif %}
{% else %}
<a href='{{user_login_url}}'>Log in</a>
{% endif %}
<h4>Osage links</h4>
<ul>
<li>
<a href="/">Osage Main</a>
</li>
<li>
<a href="/keyboard/">Osage keyboard</a>
</li>
<li>
<a href="/words/getPhrases/">View database</a>
<br />
<br />
</li>
</ul>
{% if isAdmin %}
<hr>
<h4>Admin Functions</h4>
<ul>
<li><a href="/db/manageDB/">Manage database</a></li>
<li><a href="/users/">Manage users</a></li>
</ul>
{% endif %}
<hr>
<h4>Explore phrases:</h4>
<form action="javascript:goTo('newIndex');">
<input type="button" value="Previous"
onclick="getPrevious();"/>
<input type="button" value="Next"
onclick="getNext();"/>
<br />
<input type="submit" value="Go to: "/>
<input id='newIndex' type=text value='{{index}}' size='3'/>
</form>
<form action="" id="set_status">
<input type="radio" name="filterStatus" value="All" checked> All phrases (no filter)
<br />
<input type="radio" name="filterStatus" value="Unknown"> Unknown
<input type="radio" name="filterStatus" value="Verified"> Verified
<input type="radio" name="filterStatus" value="Incorrect"> Incorrect
<input type="radio" name="filterStatus" value="Font"> Font
<br />
<input type="radio" name="filterStatus" value="Other"> Other
<input type="hidden" name="phraseKey" value="{{phraseKey}}">
<br />
</form>
<form action="javascript:switchDatabase();" id="set_status">
<hr>Databases:<br />
{% for dbName in dbNames %}
<input type="checkbox" name="databases" value="{{dbName}}">{{dbName}}<br />
{% endfor %}
<input type="checkbox" name="databases" value="*All*">All<br />
<input type="submit" value="Change DB"/>
</select>
<br />
</form>
<br />
<hr />
<!-- Add a new value to the data store -->
{% if editOrAdmin %}
<input type="button" onclick="addPhraseToDatastore('OldOsage', 'UnicodeOsage', 'English');"
value="Add new phrase to database">
{% endif %}
</div> <!-- end span last -->
</div> <!-- end container -->
</body>
</html>