window.addEventListener("error",function(err){ try { var str="("+err+") "+err.filename+":"+err.lineno+" "+err.error+": "+err.message; var xhr=new XMLHttpRequest(); xhr.responseType="text"; xhr.open("POST","/zelfoverhoor/error"); xhr.setRequestHeader("Content-Type", "text/plain"); xhr.send(str); } catch(e){ console.log("Error sending error:", e); } }); window.onbeforeunload=function(ev){ if(editorIsOpen){ var text="Je bent momenteel een vragenset aan het bewerken; weet je zeker dat je het window wilt sluiten?"; ev.returnValue=text; return text; } return undefined; }; var questionsets=null; var currentlyEditing=null; var editorIsOpen=false; function getQuestionSets(){ var xhr=new XMLHttpRequest(); xhr.onreadystatechange=function(){ if(xhr.readyState==4){ questionsets=JSON.parse(xhr.responseText); updateQuestionSetsList(); } }; xhr.open("GET","/zelfoverhoor/docent/sets"); xhr.responseType="text"; xhr.send(); } function updateQuestionSetsList(){ var tbody=document.getElementById("qsets"); clearElement(tbody); if(questionsets.length==0){ var tr=document.createElement("tr"); var td=document.createElement("td"); td.appendChild(document.createTextNode("Nog geen vragensets...")); td.setAttribute("colspan","4"); tr.appendChild(td); tbody.appendChild(tr); } for(var i=0;i0){ var insertbtn=document.createElement("input"); insertbtn.setAttribute("type","button"); insertbtn.setAttribute("value","Voeg vraag hier toe"); insertbtn.setAttribute("style","margin-bottom:5px"); insertbtn.addEventListener("click",function(){ addNewQuestion(); var newdiv=parent.children[parent.children.length-1]; parent.insertBefore(newdiv,div); renumberQuestions(); }); div.appendChild(insertbtn); div.appendChild(document.createElement("br")); } var span=document.createElement("span"); span.setAttribute("style","display:inline-block"); var b=document.createElement("b"); b.appendChild(document.createTextNode("Vraag ")); var span2=document.createElement("span"); span2.classList.add("questionindex"); span2.innerHTML=number+1; b.appendChild(span2); b.appendChild(document.createTextNode(":")); span.appendChild(b); span.appendChild(document.createElement("br")); var qta=document.createElement("textarea"); span.appendChild(qta); div.appendChild(span); span=document.createElement("span"); span.setAttribute("style","display:inline-block"); b=document.createElement("b"); b.appendChild(document.createTextNode("Antwoord:")); span.appendChild(b); span.appendChild(document.createElement("br")); span.appendChild(document.createElement("textarea")); div.appendChild(span); span=document.createElement("span"); var input=document.createElement("input"); input.setAttribute("type","button"); input.setAttribute("value","verwijder vraag"); input.setAttribute("style","vertical-align:50px"); input.addEventListener("click",function(){ var index=div.getElementsByClassName("questionindex")[0].innerHTML; if(confirm("Weet je zeker dat je vraag "+index+" wilt verwijderen?")){ parent.removeChild(div); renumberQuestions(); } }); span.appendChild(input); div.appendChild(span); parent.appendChild(div); return div; } function submitQSet(){ var name=document.getElementById("newqsetname").value.trim(); var description=document.getElementById("newqsetdescr").value.trim(); if(name==""||description==""){ alert("Naam en beschrijving zijn nodig."); return; } var div=document.getElementById("newquestions"); var ch=div.children,nq=ch.length; var questions=[]; for(var i=0;i