diff options
-rw-r--r-- | logikorr.js | 55 | ||||
-rw-r--r-- | logikorr.lisp | 14 |
2 files changed, 56 insertions, 13 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); diff --git a/logikorr.lisp b/logikorr.lisp index fefa795..6431144 100644 --- a/logikorr.lisp +++ b/logikorr.lisp @@ -157,16 +157,16 @@ div.autocomplete ul li { (defun find-student-by-id (id) (find id (find-students) :key #'student-id)) -(define-easy-handler (find-student :uri "/find-student") - (name) +(define-easy-handler (find-student :uri "/find-student") (name) (let ((student (find-student-by-name name))) (setf (header-out :content-type) "text/json; charset=UTF-8") (with-slots (id first-name last-name score) student - (json:encode-json-plist - (list :id id - :first-name first-name - :last-name last-name - :score score))))) + (with-output-to-string (*standard-output*) + (json:encode-json-plist + (list :id id + :first-name first-name + :last-name last-name + :score score)))))) (define-easy-handler (update-student-score :uri "/update-student-score") (id score-number score) |