Newer
Older
const TEMPLATE_CHOICE_STR = `
<script type="text/javascript">
function checkForm() {
{{ if not .Question.VoteOpen }}
return false;
{{ else }}
var nbOfAnswers = 0;
var answers = document.getElementsByName("answer");
for (var i=0; i<answers.length; i++) {
if (answers[i].checked) {
nbOfAnswers++;
if (nbOfAnswers < {{.Question.MinChoices}}) {
alert("Vous devez sélectionner au minimum {{.Question.MinChoices}} réponse(s)");
if ({{.Question.MaxChoices}} >=0 && (nbOfAnswers > {{.Question.MaxChoices}})) {
alert("Vous devez sélectionner au maximum {{.Question.MinChoices}} réponse(s)");
return confirm("Tout vote est définitif. Cliquez sur OK pour valider le vote.");
{{ end }}
}
</script>
<div class="vote-page">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item" aria-current="page"><a href="../votes?private_token={{.User.PrivateToken}}">AG Électrolab 2020</a></li>
<li class="breadcrumb-item active" aria-current="page">
<a href="?private_token={{.User.PrivateToken}}">
Vote nº{{.Question.Position}} - {{.Question.Title}}
{{ if .Question.VotedAlready }}
<span class="badge badge-info">a voté</span>
{{ end }}
{{ if .Question.VoteOpen }}
<span class="badge badge-success">en cours</span>
{{ else if and (gt .Question.VoteCount 0) (not .Question.VotedAlready) }}
<span class="badge badge-danger">clos</span>
{{ end }}
</a></li>
{{ if .VoteError }}
<p class="alert alert-danger">
Votre vote n'a pas pu être pris en compte!<br/>
Erreur lors de la procédure: {{.VoteError}}.
</p>
{{ end}}
{{ if .Error }}
<p class="alert alert-danger">
Erreur: {{.VoteError}}.
</p>
{{ end}}
{{ if .User.Admin }}
<form id="openclose" method="post" autocomplete="off">
<input type="hidden" name="action" value="openclose"/>
{{ if .Question.VoteOpen }}
<input type="hidden" name="open" value="false"/>
<button type="submit" class="btn btn-primary">Clore le vote</button>
{{ else }}
<input type="hidden" name="open" value="true"/>
<button type="submit" class="btn btn-primary">Ouvrir le vote</button>
{{ end }}
</form>
{{ end }}
{{ if or .Question.VoteOpen (eq .Question.VoteCount 0) }}
{{ if .Question.VotedAlready }}
<p>Votre vote a été enregistré. Vous pourrez rafraichir la page au moment de la cloture pour voir les résultats.</p>
{{ else }}
{{ if not .User.Admin }}
{{ if not .Question.VoteOpen }}
<div class="alert alert-primary">Le vote n'est pas encore ouvert. Vous pourrez <a href="?private_token={{.User.PrivateToken}}">rafraichir</a> la page au moment de l'ouverture pour voter.</div>
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
{{ end }}
<form id="answers_form" method="post" onsubmit="return checkForm();" autocomplete="off">
<input type="hidden" name="action" value="vote"/>
<label>
{{ if (and (eq 1 $.Question.MinChoices) (eq 1 $.Question.MaxChoices)) }}
Liste des choix :
{{ else if (and (gt $.Question.MinChoices 0) (ge $.Question.MaxChoices 0)) }}
{{if .Question.VoteOpen}}
Cochez
{{else}}
Vous devrez cocher
{{end}}
entre {{$.Question.MinChoices}} et {{$.Question.MaxChoices}} choix) :
{{ else if gt $.Question.MinChoices 0 }}
{{if .Question.VoteOpen}}
Cochez
{{else}}
Vous devrez cocher
{{end}}
au minimum {{$.Question.MinChoices}} choix :
{{ else if ge $.Question.MaxChoices 0 }}
{{if .Question.VoteOpen}}
Cochez
{{else}}
Vous devrez cocher
{{end}}
au maximum {{$.Question.MaxChoices}} choix :
{{ else }}
Liste des choix :
{{ end }}
</label>
<div class="form-group">
{{ range .Question.Answers }}
<div class="form-check">
<input
class="form-check-input"
{{if not $.Question.VoteOpen}}
disabled
{{end}}
{{if .Checked}}
checked
{{end}}
type="{{ if (and (eq 1 $.Question.MinChoices) (eq 1 $.Question.MaxChoices)) }}radio{{else}}checkbox{{end}}"
id="answer_{{.Name}}"
name="answer"
value="{{.Name}}"
>
<label
class="form-check-label"
for="answer_{{.Name}}"
>{{.Sentence}}</label>
</div>
{{ end }}
</div>
{{ if .Question.VoteOpen }}
<button type="submit" class="btn btn-danger">Voter</button>
{{ else }}
<p>Le vote est clos. Résultats:</p>
{{ range .Question.Answers }}
{{ if gt .VoteCount 1 }}
<p>{{.Sentence}}: {{.VoteCount}} votes</p>
{{ else }}
<p>{{.Sentence}}: {{.VoteCount}} vote</p>