option to restrict answers on a defined list of possibilities

This commit is contained in:
jelhan 2013-11-01 00:56:51 +01:00
parent 10f9824099
commit 53d4ed50dc
2 changed files with 34 additions and 5 deletions

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<title>pure</title>
<title>Croodle</title>
<script src="js/sjcl.js"></script>
<script src="js/mustache.js"></script>
<script src="js/jquery.js"></script>
@ -35,7 +35,18 @@
<tr id="addUser">
<td><input type="text" name="name" id="addUserName"/></td>
{{#data.options}}
<td><input type="text" name="selections[]" class="selection"/></td>
<td>
{{#data.answers.0}}
<select class="selection">
{{#data.answers}}
<option>{{.}}</option>
{{/data.answers}}
</select>
{{/data.answers.0}}
{{^data.answers}}
<input type="text" name="selections[]" class="selection"/>
{{/data.answers}}
</td>
{{/data.options}}
<td><button id="addUserSave">save</button></td>
</tr>
@ -55,9 +66,15 @@
<script type="text/html" id="PollAdd_template">
<h1>Create new poll</h1>
<div id="addPoll">
<p>Title: <input id="addPollTitle" type="text" name="title" /></p>
<p>Title: <input id="addPollTitle" type="text" /></p>
<p>Description: <br/>
<textarea id="addPollDescription" name="description" /></p>
<textarea id="addPollDescription" /></p>
<p>Answertype:
<select id="addPollAnswertype">
<option value="YesNo">YesNo</option>
<option value="YesNoMaybe">YesNoMaybe</option>
<option value="Text">Text</option>
</select>
<p id="options">
Options: <br/>
</p>

View file

@ -285,6 +285,19 @@ PollAdd = function (type) {
new_poll.data.options = [];
new_poll.data.title = $('#addPollTitle').val();
new_poll.data.description = $('#addPollDescription').val();
switch ($('#addPollAnswertype').val()) {
case 'YesNo':
new_poll.data.answers = ['yes', 'no'];
break;
case 'YesNoMaybe':
new_poll.data.answers = ['yes', 'maybe', 'no'];
break;
case 'Text':
new_poll.data.answers = [];
break;
}
$.each($('#addPoll .option'), function(key, value){
if (value.value !== '') { new_poll.data.options.push(value.value); }
});
@ -367,7 +380,6 @@ if (id !== '' && password !== '') {
// show existing poll
poll = new Poll(id);
poll.Load();
console.log(poll);
}
else {
page = new Startpage();