forked from luwes/craft-polls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic.html
137 lines (116 loc) · 4.44 KB
/
basic.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
{% includeCssResource 'polls/css/polls.css' %}
{% includeJsFile 'https://code.jquery.com/jquery-1.11.3.min.js' %}
{% includeJsResource 'polls/js/polls.js' %}
<form class="poll-form" method="post" accept-charset="UTF-8">
{{ getCsrfInput() }}
<input type="hidden" name="action" value="polls/answers/saveAnswers">
{% macro errorList(errors) %}
{% if errors %}
<div class="errors">
{% for error in errors %}
{% if error is iterable %}
{% for e in error %}
<div class="alert alert-danger">{{ e }}</div>
{% endfor %}
{% else %}
<div class="alert alert-danger">{{ error }}</div>
{% endif %}
{% endfor %}
</div>
{% endif %}
{% endmacro %}
{% from _self import errorList %}
{% if pollResponse.errors is defined %}
{{ errorList(pollResponse.errors) }}
{% endif %}
{% if pollResponse.success is defined and pollResponse.success %}
<div class="alert alert-success">
Thanks, your answers have been saved.
</div>
{% endif %}
{% if questions is not defined %}
{% set questions = craft.polls.questions %}
{% endif %}
{% if pollResponse.questions is defined %}
{% set questions = pollResponse.questions %}
{% endif %}
<div class="panel panel-default">
<ul class="list-group">
{% for question in questions %}
{% set questionErrors = question.getErrors() %}
{% set errorClass = questionErrors|length > 0 ? 'has-error' : '' %}
<li class="list-group-item poll-question {{ errorClass }}" style="padding: 8px 25px;">
<div class="pull-right text-muted" style="margin-top: 10px;">
{{ question.totalAnswers }} votes
</div>
<h3 class="poll-title">{{ question.title }}</h3>
{% if questionErrors|length > 0 %}
{% for error in questionErrors %}
{% if error is iterable %}
{% for e in error %}
<span class="help-block">{{ e }}</span>
{% endfor %}
{% else %}
<span class="help-block">{{ error }}</span>
{% endif %}
{% endfor %}
{% endif %}
{% set inputType = question.multipleOptions ? 'checkbox' : 'radio' %}
<div class="poll-options">
{% for option in question.options %}
<div class="{{ inputType }} poll-option {{ option.kind }}">
<label>
<input type="hidden" value="" name="{{ option.optionInputName }}">
<input class="poll-option-input {{ option.kind }}" type="{{ inputType }}" value="{{ option.id }}" name="{{ option.optionInputName }}" {% if option.selected %} checked="checked"{% endif %}>
{{ option.label }}
</label>
</div>
{% if option.kind == 'other' %}
<div class="form-group poll-other hide">
<input class="form-control" type="text" value="{{ option.value }}" name="{{ option.textInputName }}">
</div>
{% endif %}
{% endfor %}
</div>
</li>
{% endfor %}
</ul>
<div class="panel-footer">
<button class="btn btn-default" type="submit">Vote</button>
{% if craft.polls.hasAnswered(questions) %}
<span style="padding-left: 20px;">
<a class="poll-results-link" href="#">Results</a>
</span>
{% endif %}
</div>
</div>
</form>
<div class="poll-results hide">
<div class="panel panel-default">
<ul class="list-group">
{% for question in questions %}
<li class="list-group-item" style="padding: 8px 25px;">
<h3 class="poll-title">Results: {{ question.title }}</h3>
<p class="lead">{{ question.totalAnswers }} votes</p>
<ul class="list-group">
{% for option in question.options %}
{% if question.totalAnswers > 0 %}
{% set answersPercent = option.totalAnswers / question.totalAnswers * 100 %}
{% else %}
{% set answersPercent = 0 %}
{% endif %}
<li class="list-group-item" style="position: relative; background: none; z-index: 10;">
<span style="position: absolute; top: 0; left: 0; bottom: 0; z-index: -1; background-color: #f7f7f7; width: {{ answersPercent|round }}%;"></span>
<span class="pull-right">{{ answersPercent|round }}%</span>
{{ option.label }} ({{ option.totalAnswers }} votes)
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
<div class="panel-footer">
<button class="btn btn-default poll-back-button">Back to poll</button>
</div>
</div>
</div>