summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/lijst/lijst.html46
-rw-r--r--modules/lijst/lijst.js46
2 files changed, 92 insertions, 0 deletions
diff --git a/modules/lijst/lijst.html b/modules/lijst/lijst.html
new file mode 100644
index 0000000..0c1a3dd
--- /dev/null
+++ b/modules/lijst/lijst.html
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Lijst</title>
+<script>
+function addItem() {
+ var text = document.getElementById("text").value;
+
+ var xhr = new XMLHttpRequest();
+ xhr.open("POST", location.href + "/add");
+ xhr.responseType = "text";
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState == 4 && xhr.status == 200) {
+ location.href = location.href;
+ }
+ };
+ xhr.send(text);
+}
+
+function removeItem() {
+ var xhr = new XMLHttpRequest();
+ xhr.open("POST", location.href + "/remove");
+ xhr.responseType = "text";
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState == 4 && xhr.status == 200) {
+ location.href = location.href;
+ }
+ };
+ xhr.send();
+}
+</script>
+<style>
+
+</style>
+</head>
+<body>
+<ol id="lijst">
+<!--[[LIJST_ITEMS]]-->
+</ol>
+<input type="text" id="text" placeholder="New item text">
+<input type="button" onclick="addItem()" value="Add item"><br>
+<br>
+<input type="button" onclick="removeItem()" value="Remove top item">
+</body>
+</html>
diff --git a/modules/lijst/lijst.js b/modules/lijst/lijst.js
new file mode 100644
index 0000000..fb1c70c
--- /dev/null
+++ b/modules/lijst/lijst.js
@@ -0,0 +1,46 @@
+var cmn=require("../$common.js"),
+ fs=require("fs"),
+ persist=require("node-persist"),
+ Naampje=require("naampje").name;
+
+persist=persist.create({
+ dir:"persist/lijst",
+ continuous:false,
+ interval:false
+});
+persist.initSync();
+
+var lijst=persist.getItemSync("lijst");
+if(!lijst){
+ lijst=[];
+ persist.setItemSync("lijst",lijst);
+}
+
+var moddir;
+
+function render(res){
+ var html=fs.readFileSync(moddir+"/lijst.html")+"";
+ var s="";
+ for(var i=0;i<lijst.length;i++){
+ s+="<li>"+escape(lijst[i])+"</li>\n";
+ }
+ html=html.replace("<!--[[LIJST_ITEMS]]-->",s);
+ res.send(html);
+}
+
+module.exports=function(app,io,_moddir){
+ moddir=_moddir;
+ app.get("/lijst",function(req,res){
+ render(res);
+ });
+ app.post("/lijst/add",function(req,res){
+ lijst.push(req.body.trim());
+ persist.setItemSync("lijst",lijst);
+ res.status(200).end();
+ });
+ app.post("/lijst/remove",function(req,res){
+ if(lijst.length>0)lijst.shift();
+ persist.setItemSync("lijst",lijst);
+ res.status(200).end();
+ });
+};