X-Git-Url: https://git.sesse.net/?p=itkacl;a=blobdiff_plain;f=itkacl-web-1.0%2Fweb%2Fitkacl.js;fp=itkacl-web-1.0%2Fweb%2Fitkacl.js;h=f7464f631f787c366f3de330fa547272ed0e234c;hp=0000000000000000000000000000000000000000;hb=e7130e30ca2a76082de68a72fb2a52b4510f7bf1;hpb=b9014762b8051b457c68d8de11a08d64401026fa diff --git a/itkacl-web-1.0/web/itkacl.js b/itkacl-web-1.0/web/itkacl.js new file mode 100644 index 0000000..f7464f6 --- /dev/null +++ b/itkacl-web-1.0/web/itkacl.js @@ -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); } +}