diff options
| author | tomsmeding <tom.smeding@gmail.com> | 2019-09-18 17:29:27 +0200 | 
|---|---|---|
| committer | tomsmeding <tom.smeding@gmail.com> | 2019-09-18 17:31:22 +0200 | 
| commit | c4c121cd5460da02db1563ad1118cd0db09ceb69 (patch) | |
| tree | 7e94902e538d03470282b9f34ff9bd3a8ace42b1 /modules/lijst/lijst.html | |
| parent | 2e2f642cf6144cbc84bff0094d34ab40de6a4b11 (diff) | |
lijst: Voting
Diffstat (limited to 'modules/lijst/lijst.html')
| -rw-r--r-- | modules/lijst/lijst.html | 48 | 
1 files changed, 26 insertions, 22 deletions
| diff --git a/modules/lijst/lijst.html b/modules/lijst/lijst.html index b849720..66c33a8 100644 --- a/modules/lijst/lijst.html +++ b/modules/lijst/lijst.html @@ -4,48 +4,52 @@  <meta charset="utf-8">  <title>Lijst</title>  <script> -function addItem() { -	var text = document.getElementById("text").value; - +function postReq(url, body) {  	var xhr = new XMLHttpRequest(); -	xhr.open("POST", location.href + "/add"); +	xhr.open("POST", location.href + url);  	xhr.responseType = "text";  	xhr.onreadystatechange = function() {  		if (xhr.readyState == 4) {  			if (xhr.status == 200) { -				location.href = location.href; +				document.getElementById("tbody").innerHTML = xhr.responseText;  			} else {  				alert(xhr.responseText);  			}  		}  	}; -	xhr.send(text); +	xhr.send(body); +} + +function addItem() { +	postReq("/add", document.getElementById("text").value); +	document.getElementById("text").value = "";  }  function removeItem(id) { -	var xhr = new XMLHttpRequest(); -	xhr.open("POST", location.href + "/remove/" + id); -	xhr.responseType = "text"; -	xhr.onreadystatechange = function() { -		if (xhr.readyState == 4) { -			if (xhr.status == 200) { -				location.href = location.href; -			} else { -				alert(xhr.responseText); -			} -		} -	}; -	xhr.send(); +	postReq("/remove/" + id); +} + +function vote(id, num) { +	postReq("/vote/" + id + "/" + num);  }  </script>  <style> - +#table { +	border-collapse: collapse; +} +#table td { +	padding: 2px; +	padding-left: 7px; +	padding-right: 7px; +	border: 1px #eee solid; +}  </style>  </head>  <body> -<ol id="lijst"> +<table id="table"><tbody id="tbody">  <!--[[LIJST_ITEMS]]--> -</ol> +</tbody></table> +<br>  <input type="text" id="text" placeholder="New item text">  <input type="button" onclick="addItem()" value="Add item"><br>  </body> | 
