summaryrefslogtreecommitdiff
path: root/logikorr.js
diff options
context:
space:
mode:
Diffstat (limited to 'logikorr.js')
-rw-r--r--logikorr.js55
1 files changed, 49 insertions, 6 deletions
diff --git a/logikorr.js b/logikorr.js
index efa3b2f..c8f0079 100644
--- a/logikorr.js
+++ b/logikorr.js
@@ -1,6 +1,51 @@
var loader;
var autocompleteList;
-YUI().use('node-base', 'io-base', 'io-form', 'io-queue', function (Y) {
+YUI().use('node-base', 'io-base', 'io-form', 'io-queue', 'json', function (Y) {
+ function makeScoreInput(cell, value) {
+ var input = document.createElement('input');
+ input.setAttribute('type', 'text');
+ input.setAttribute('maxlength', '3');
+ input.setAttribute('size', '3');
+ if (value != undefined) {
+ input.value = value;
+ }
+ cell.appendChild(input);
+ return input;
+ };
+
+ function ensureFreeInput(scoreCell) {
+ if (!(scoreCell.lastChild.value == undefined || scoreCell.lastChild.value == "")) {
+ return makeScoreInput(scoreCell);
+ } else {
+ return scoreCell.lastChild;
+ }
+ };
+
+ function updateStudentRowFromName(event, nameInput, scoreCell) {
+ Y.log(event);
+ Y.log(nameInput);
+ Y.log(scoreCell);
+ function doUpdate(id, o, args) {
+ var data = o.responseText;
+ var student = Y.JSON.parse(data);
+ Y.log(student);
+
+ while (scoreCell.firstChild) {
+ scoreCell.removeChild(scoreCell.firstChild);
+ };
+
+ for (var i = 0; i < student.score.length; i++) {
+ var x = student.score[i];
+ makeScoreInput(scoreCell, x);
+ };
+
+ var freeInput = makeScoreInput(scoreCell);
+ freeInput.focus();
+ }
+ var request = Y.io("find-student", { 'on' : { 'complete': doUpdate },
+ 'data': "name=" + nameInput.value });
+ };
+
function makeStudentRow() {
var table = document.getElementById('ergebnisse');
var num = table.rows.length;
@@ -16,11 +61,9 @@ YUI().use('node-base', 'io-base', 'io-form', 'io-queue', function (Y) {
new Autocompleter.Local(input, completion, autocompleteList, { 'fullSearch' : true });
var cell = row.insertCell(1);
- var input = document.createElement('input');
- input.setAttribute('type', 'text');
- input.setAttribute('maxlength', '3');
- input.setAttribute('size', '3');
- cell.appendChild(input);
+ makeScoreInput(cell);
+
+ Y.on("blur", updateStudentRowFromName, input, Y, input, cell);
};
return Y.on('domready', makeStudentRow);