summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2009-11-20 23:14:38 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2009-11-20 23:14:38 +0100
commitace1b74222742f839f4a9356eb64966e3b9eb5e2 (patch)
treef94f215c997c239219d6ccf70f6f68e0a4eb8aa6
parent74a99c8b40af27786745800b0e98943f66fffa35 (diff)
JavaScript: Send modifications back to the server.
-rw-r--r--logikorr.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/logikorr.js b/logikorr.js
index 87ca4b1..7c32d6e 100644
--- a/logikorr.js
+++ b/logikorr.js
@@ -1,6 +1,32 @@
var loader;
var autocompleteList;
YUI().use('node-base', 'io-base', 'io-form', 'io-queue', 'json', function (Y) {
+ function markAsChanged(input) {
+ input.setAttribute("style", "background-color: #faa");
+ }
+
+ function markAsRegistered(input) {
+ input.setAttribute("style", "background-color: #afa");
+ }
+
+ function registerScoreInputChange(event, input, row) {
+ var id = row.getAttribute("mulk:id");
+ var inputnum = 0;
+ var inputSiblings = input.parentNode.childNodes;
+ for (; inputnum < inputSiblings.length; inputnum++) {
+ if (inputSiblings[inputnum] == input) {
+ break;
+ }
+ };
+ Y.io("update-student-score",
+ { 'on' : { 'complete': function(id, o, args) {
+ try { Y.log(o.responseText); Y.JSON.parse(o.responseText); }
+ catch(e) { return null; }
+ markAsRegistered(input);
+ } },
+ 'data': "id=" + id + "&score-number=" + inputnum + "&score=" + input.value });
+ }
+
function makeScoreInput(cell, value) {
var input = document.createElement('input');
input.setAttribute('type', 'text');
@@ -11,6 +37,8 @@ YUI().use('node-base', 'io-base', 'io-form', 'io-queue', 'json', function (Y) {
}
cell.appendChild(input);
Y.on("keyup", function(e) { ensureFreeInput(cell); }, input, Y);
+ Y.on("keyup", function(e) { markAsChanged(input); }, input, Y);
+ Y.on("change", registerScoreInputChange, input, Y, input, cell.parentNode);
return input;
};
@@ -37,6 +65,8 @@ YUI().use('node-base', 'io-base', 'io-form', 'io-queue', 'json', function (Y) {
};
Y.log(student);
+ scoreCell.parentNode.setAttribute("mulk:id", student.id);
+
while (scoreCell.firstChild) {
scoreCell.removeChild(scoreCell.firstChild);
};