]> git.sesse.net Git - itkacl/blobdiff - itkacl-web-1.0/web/itkacl.js
Add the bare minimum of what is required for the web interface to work (but be butt...
[itkacl] / itkacl-web-1.0 / web / itkacl.js
diff --git a/itkacl-web-1.0/web/itkacl.js b/itkacl-web-1.0/web/itkacl.js
new file mode 100644 (file)
index 0000000..f7464f6
--- /dev/null
@@ -0,0 +1,36 @@
+function enableEdit(td) {
+       var oldComment = '';
+       if (td.firstChild) {
+               var oldComment = td.firstChild.nodeValue;
+               td.removeChild(td.firstChild);
+       }
+       var commentBox = document.createElement("input");
+       commentBox.value = oldComment;
+       // commentBox.setAttribute("size", oldComment.length + 10);
+       commentBox.onblur = function() { commitEdit(td); }
+       commentBox.onkeyup = function(evt) { if (evt.keyCode == 13) { commitEdit(td); } }
+       td.ondblclick = function() {}
+       td.appendChild(commentBox);
+       commentBox.focus();
+}
+
+function commitEdit(td) {
+       var newComment = td.firstChild.value;
+       $.ajax({
+               type: 'POST',
+               url: 'change-comment.pl',
+               data: {
+                       'entry': td.getAttributeNS('http://acl.samfundet.no/', 'entry'),
+                       'entity_type': td.getAttributeNS('http://acl.samfundet.no/', 'entity-type'),
+                       'entity': td.getAttributeNS('http://acl.samfundet.no/', 'entity'),
+                       'comment': newComment
+               }
+       }).fail(function() { alert("Klarte ikke å endre kommentaren"); });
+
+       td.firstChild.onblur = function() {};
+       td.removeChild(td.firstChild);
+
+       var commentLabel = document.createTextNode(newComment);
+       td.appendChild(commentLabel);
+       td.ondblclick = function() { enableEdit(td); }
+}