From 11a68e62e6d0f858ef7d76f8b7f8809f9ea92a89 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Fri, 20 Nov 2009 22:15:57 +0100 Subject: Implement automatic construction of score input rows. --- logikorr.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 6 deletions(-) (limited to 'logikorr.js') 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); -- cgit v1.2.3