vote_table_classic.tpl 18.1 KB
Newer Older
1
2
{if !is_array($best_choices) || empty($best_choices)}
    {$best_choices = [0]}
3
4
{/if}

Olivier PEREZ's avatar
Olivier PEREZ committed
5
<h3>
Olivier Perez's avatar
Olivier Perez committed
6
    {__('Poll results', 'Votes of the poll')} {if $hidden}<i>({__('PollInfo', 'Results are hidden')})</i>{/if}
7
    {if $accessGranted}
8
        <a href="" data-toggle="modal" data-target="#hint_modal"><i class="glyphicon glyphicon-info-sign"></i></a><!-- TODO Add accessibility -->
9
    {/if}
Olivier PEREZ's avatar
Olivier PEREZ committed
10
</h3>
11

12
13
14
15

{include 'part/scroll_left_right.tpl'}


16
<div id="tableContainer" class="tableContainer">
17
    <form action="{if $admin}{poll_url id=$admin_poll_id admin=true}{else}{poll_url id=$poll_id}{/if}" method="POST"  id="poll_form">
18
        <input type="hidden" name="control" value="{$slots_hash}"/>
19
        <table class="results">
20
            <caption class="sr-only">{__('Poll results', 'Votes of the poll')} {$poll->title|html}</caption>
21
            <thead>
Olivier PEREZ's avatar
Olivier PEREZ committed
22
            {if $admin && !$expired}
23
                <tr class="hidden-print">
24
                    <th role="presentation"></th>
25
26
                    {foreach $slots as $id=>$slot}
                        <td headers="C{$id}">
27
                            <a href="{poll_url id=$admin_poll_id admin=true action='delete_column' action_value=$slot->title}"
Antonin's avatar
Antonin committed
28
29
                               data-remove-confirmation="{__('adminstuds', 'Confirm removal of the column.')}"
                               class="btn btn-link btn-sm remove-column" title="{__('adminstuds', 'Remove the column')} {$slot->title|html}">
30
                                <i class="glyphicon glyphicon-remove text-danger"></i><span class="sr-only">{__('Generic', 'Remove')}</span>
31
32
                            </a>
                            </td>
33
34
                    {/foreach}
                    <td>
Olivier PEREZ's avatar
Olivier PEREZ committed
35
                        <a href="{poll_url id=$admin_poll_id admin=true action='add_column'}"
36
                           class="btn btn-link btn-sm" title="{__('adminstuds', 'Add a column')}">
37
                            <i class="glyphicon glyphicon-plus text-success"></i><span class="sr-only">{__('Poll results', 'Add a column')}</span>
38
                        </a>
39
40
41
                    </td>
                </tr>
            {/if}
42
43
44
            <tr>
                <th role="presentation"></th>
                {foreach $slots as $id=>$slot}
45
                    <th class="bg-info" id="C{$id}" title="{$slot->title|markdown:true}">{$slot->title|markdown}</th>
46
47
48
49
50
51
                {/foreach}
                <th></th>
            </tr>
            </thead>
            <tbody>
            {foreach $votes as $vote}
52
                {* Edited line *}
53

54
                {if $editingVoteId === $vote->uniqId && !$expired}
55

56
                <tr class="hidden-print">
Thomas Citharel's avatar
Thomas Citharel committed
57
                    <td class="bg-info btn-edit">
58
                        <div class="input-group input-group-sm" id="edit">
59
                            <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
60
                            <input type="hidden" name="edited_vote" value="{$vote->uniqId}"/>
JosephK's avatar
JosephK committed
61
                            <input type="text" id="name" name="name" value="{$vote->name|html}" class="form-control" title="{__('Generic', 'Your name')}" placeholder="{__('Generic', 'Your name')}" />
62
63
                        </div>
                    </td>
64

Olivier Perez's avatar
Olivier Perez committed
65
                    {$id=0}
66
67
68
                    {foreach $slots as $slot}
                        {$choice=$vote->choices[$id]}

69
70
71
                        <td class="bg-info" headers="C{$id}">
                            <ul class="list-unstyled choice">
                                <li class="yes">
72
                                    <input type="radio" id="y-choice-{$id}" name="choices[{$id}]" value="2" {if $choice=='2'}checked {/if}/>
73
                                    <label class="btn btn-default btn-xs" for="y-choice-{$id}" title="{__('Poll results', 'Vote yes for')|html} {$slots[$id]->title|html}">
74
                                        <i class="glyphicon glyphicon-ok"></i><span class="sr-only">{__('Generic', 'Yes')}</span>
75
76
77
                                    </label>
                                </li>
                                <li class="ifneedbe">
78
                                    <input type="radio" id="i-choice-{$id}" name="choices[{$id}]" value="1" {if $choice=='1'}checked {/if}/>
79
                                    <label class="btn btn-default btn-xs" for="i-choice-{$id}" title="{__('Poll results', 'Vote ifneedbe for')|html} {$slots[$id]->title|html}">
80
                                        (<i class="glyphicon glyphicon-ok"></i>)<span class="sr-only">{__('Generic', 'Ifneedbe')}</span>
81
82
83
                                    </label>
                                </li>
                                <li class="no">
84
                                    <input type="radio" id="n-choice-{$id}" name="choices[{$id}]" value="0" {if $choice=='0'}checked {/if}/>
85
                                    <label class="btn btn-default btn-xs" for="n-choice-{$id}" title="{__('Poll results', 'Vote no for')|html} {$slots[$id]->title|html}">
86
                                        <i class="glyphicon glyphicon-ban-circle"></i><span class="sr-only">{__('Generic', 'No')}</span>
87
88
                                    </label>
                                </li>
Thomas Citharel's avatar
Thomas Citharel committed
89
                                <li class="hide">
90
91
                                    <input type="radio" id="n-choice-{$id}" name="choices[{$id}]" value=" " {if $choice!='2' && $choice!='1' && $choice!='0'}checked {/if}/>
                                </li>
92
93
                            </ul>
                        </td>
94
95

                        {$id=$id + 1}
96
                    {/foreach}
97

Thomas Citharel's avatar
Thomas Citharel committed
98
                    <td class="btn-edit"><button type="submit" class="btn btn-success btn-xs" name="save" value="{$vote->id|html}" title="{__('Poll results', 'Save the choices')} {$vote->name|html}">{__('Generic', 'Save')}</button></td>
99
100
101
                </tr>
                {elseif !$hidden} {* Voted line *}
                <tr>
102

Erwan TERTRAIS's avatar
Erwan TERTRAIS committed
103
                    <th class="bg-info">{$vote->name|html}
104
105
106
107
108
109
110
                    {if $active && !$expired && $accessGranted &&
                    (
                    $poll->editable == constant('Framadate\Editable::EDITABLE_BY_ALL')
                    or $admin
                    or ($poll->editable == constant('Framadate\Editable::EDITABLE_BY_OWN') && $editedVoteUniqueId == $vote->uniqId)
                    ) && $slots gt 4
                    }
Thomas Citharel's avatar
Thomas Citharel committed
111
					<span class="edit-username-left">
Erwan TERTRAIS's avatar
Erwan TERTRAIS committed
112
113
114
115
116
117
						<a href="{if $admin}{poll_url id=$poll->admin_id vote_id=$vote->uniqId admin=true}{else}{poll_url id=$poll->id vote_id=$vote->uniqId}{/if}" class="btn btn-default btn-sm" title="{__f('Poll results', 'Edit the line: %s', $vote->name)|html}">
                    	<i class="glyphicon glyphicon-pencil"></i><span class="sr-only">{__('Generic', 'Edit')}</span>
                   	 	</a>
					</span>
					{/if}
					</th>
118

Olivier Perez's avatar
Olivier Perez committed
119
                    {$id=0}
120
121
                    {foreach $slots as $slot}
                        {$choice=$vote->choices[$id]}
122

123
                        {if $choice=='2'}
124
                            <td class="bg-success text-success" headers="C{$id}"><i class="glyphicon glyphicon-ok"></i><span class="sr-only">{__('Generic', 'Yes')}</span></td>
125
                        {elseif $choice=='1'}
126
                            <td class="bg-warning text-warning" headers="C{$id}">(<i class="glyphicon glyphicon-ok"></i>)<span class="sr-only">{__('Generic', 'Ifneedbe')}</span></td>
127
                        {elseif $choice=='0'}
128
                            <td class="bg-danger text-danger" headers="C{$id}"><i class="glyphicon glyphicon-ban-circle"></i><span class="sr-only">{__('Generic', 'No')}</span></td>
Olivier Perez's avatar
Olivier Perez committed
129
                        {else}
130
                            <td class="bg-info" headers="C{$id}"><span class="sr-only">{__('Generic', 'Unknown')}</span></td>
131
                        {/if}
132

133
                        {$id=$id + 1}
134
135
                    {/foreach}

Antonin's avatar
Antonin committed
136
                    {if $active && !$expired && $accessGranted &&
137
138
139
                        (
                         $poll->editable == constant('Framadate\Editable::EDITABLE_BY_ALL')
                         or $admin
140
                         or ($poll->editable == constant('Framadate\Editable::EDITABLE_BY_OWN') && $editedVoteUniqueId == $vote->uniqId)
141
142
143
                        )
                    }

144
                        <td class="hidden-print">
Antonin's avatar
Antonin committed
145
                            <a href="{if $admin}{poll_url id=$poll->admin_id vote_id=$vote->uniqId admin=true}{else}{poll_url id=$poll->id vote_id=$vote->uniqId}{/if}" class="btn btn-default btn-sm" title="{__f('Poll results', 'Edit the line: %s', $vote->name)|html}">
146
                                <i class="glyphicon glyphicon-pencil"></i><span class="sr-only">{__('Generic', 'Edit')}</span>
147
148
149
150
151
                            </a>
                            {if $admin}
                                <a href="{poll_url id=$admin_poll_id admin=true action='delete_vote' action_value=$vote->id}"
                                   class="btn btn-default btn-sm"
                                   title="{__('Poll results', 'Remove the line:')} {$vote->name|html}">
152
                                    <i class="glyphicon glyphicon-remove text-danger"></i><span class="sr-only">{__('Generic', 'Remove')}</span>
153
154
155
156
157
                                </a>
                            {/if}
                        </td>
                    {else}
                        <td></td>
158
159
                    {/if}
                </tr>
160
                {/if}
161
162
163
164
            {/foreach}

            {* Line to add a new vote *}

165
            {if $active && $editingVoteId === 0 && !$expired && $accessGranted}
166
                <tr id="vote-form" class="hidden-print">
Thomas Citharel's avatar
Thomas Citharel committed
167
                    <td class="bg-info" class="btn-edit">
168
                        <div class="input-group input-group-sm">
169
                            <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
170
                            <input type="text" id="name" name="name" class="form-control" title="{__('Generic', 'Your name')}" placeholder="{__('Generic', 'Your name')}" />
171
172
                        </div>
                    </td>
173
					{$i = 0}
174
175
176
                    {foreach $slots as $id=>$slot}
                        <td class="bg-info" headers="C{$id}">
                            <ul class="list-unstyled choice">
177
								{if $poll->ValueMax eq NULL || $best_choices['y'][$i] lt $poll->ValueMax}
178
179
180
181
182
183
184
185
186
187
188
189
190
                               	 	<li class="yes">
                                    	<input type="radio" id="y-choice-{$id}" name="choices[{$id}]" value="2" />
                                    	<label class="btn btn-default btn-xs" for="y-choice-{$id}" title="{__('Poll results', 'Vote yes for')|html} {$slot->title|html}">
                                       		<i class="glyphicon glyphicon-ok"></i><span class="sr-only">{__('Generic', 'Yes')}</span>
                                    	</label>
                                	</li>
                               		 <li class="ifneedbe">
                                  	  <input type="radio" id="i-choice-{$id}" name="choices[{$id}]" value="1" />
                                  	  <label class="btn btn-default btn-xs" for="i-choice-{$id}" title="{__('Poll results', 'Vote ifneedbe for')|html} {$slot->title|html}">
                                        <i class="glyphicon glyphicon-ok"></i>)<span class="sr-only">{__('Generic', 'Ifneedbe')}</span>
                                    	</label>
                               	 	</li>
								{/if}
191
                                <li class="no">
192
                                    <input type="radio" id="n-choice-{$id}" name="choices[{$id}]" value="0" />
193
194
                                    <label class="btn btn-default btn-xs startunchecked" for="n-choice-{$id}" title="{__('Poll results', 'Vote no for')|html} {$slot->title|html}">
                                        <i class="glyphicon glyphicon-ban-circle"></i><span class="sr-only">{__('Generic', 'No')}</span>
195
196
                                    </label>
                                </li>
Thomas Citharel's avatar
Thomas Citharel committed
197
                                <li class="hide">
198
199
                                  <input type="radio" id="n-choice-{$id}" name="choices[{$id}]" value=" " checked/>
                                </li>
200
201
                            </ul>
                        </td>
202
						{$i = $i+1}
203

204
                    {/foreach}
205
                    <td><button type="submit" class="btn btn-success btn-md" name="save" title="{__('Poll results', 'Save the choices')}">{__('Generic', 'Save')}</button></td>
206
207
208
                </tr>
            {/if}

209
210
211
            {if !$hidden}
                {* Line displaying best moments *}
                {$count_bests = 0}
212
                {$max = max($best_choices['y'])}
213
214
                {if $max > 0}
                    <tr id="addition">
JosephK's avatar
JosephK committed
215
                        <td>{__('Poll results', 'Addition')}<br/>{$votes|count} {if ($votes|count)==1}{__('Poll results', 'polled user')}{else}{__('Poll results', 'polled users')}{/if}</td>
216
                        {foreach $best_choices['y'] as $i=>$best_choice}
217
218
                            {if $max == $best_choice}
                                {$count_bests = $count_bests +1}
JosephK's avatar
JosephK committed
219
                                <td><i class="glyphicon glyphicon-star text-info"></i><span class="yes-count">{$best_choice|html}</span>{if $best_choices['inb'][$i]>0}<br/><span class="small text-muted">(+<span class="inb-count">{$best_choices['inb'][$i]|html}</span>)</span>{/if}</td>
220
                            {elseif $best_choice > 0}
JosephK's avatar
JosephK committed
221
222
223
                                <td><span class="yes-count">{$best_choice|html}</span>{if $best_choices['inb'][$i]>0}<br/><span class="small text-muted">(+<span class="inb-count">{$best_choices['inb'][$i]|html}</span>)</span>{/if}</td>
                            {elseif $best_choices['inb'][$i]>0}
                                <td><br/><span class="small text-muted">(+<span class="inb-count">{$best_choices['inb'][$i]|html}</span>)</span></td>
224
225
226
227
228
229
                            {else}
                                <td></td>
                            {/if}
                        {/foreach}
                    </tr>
                {/if}
230
            {/if}
231
232
233
234
235
            </tbody>
        </table>
    </form>
</div>

JosephK's avatar
JosephK committed
236
237
238
239
240
241
242
243
244
245
246
247
248
{if !$hidden && $max > 0}
    <div class="row" aria-hidden="true">
        <div class="col-xs-12">
            <p class="text-center" id="showChart">
                <button class="btn btn-lg btn-default">
                    <span class="fa fa-fw fa-bar-chart"></span> {__('Poll results', 'Display the chart of the results')}
                </button>
            </p>
        </div>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#showChart').on('click', function() {
249
250
251
                $('#showChart')
                        .after("<h3>{__('Poll results', 'Chart')}</h3><canvas id=\"Chart\"></canvas>")
                        .remove();
Thomas Citharel's avatar
Thomas Citharel committed
252

JosephK's avatar
JosephK committed
253
254
                var resIfneedbe = [];
                var resYes = [];
Thomas Citharel's avatar
Thomas Citharel committed
255

256
257
258
                $('#addition').find('td').each(function () {
                    var inbCountText = $(this).find('.inb-count').text();
                    if(inbCountText != '' && inbCountText != undefined) {
JosephK's avatar
JosephK committed
259
260
261
262
                        resIfneedbe.push($(this).find('.inb-count').html())
                    } else {
                        resIfneedbe.push(0);
                    }
263
264
265

                    var yesCountText = $(this).find('.yes-count').text();
                    if(yesCountText != '' && yesCountText != undefined) {
JosephK's avatar
JosephK committed
266
267
268
269
270
271
272
                        resYes.push($(this).find('.yes-count').html())
                    } else {
                        resYes.push(0);
                    }
                });
                var cols = [
                {foreach $slots as $id=>$slot}
Thomas Citharel's avatar
Thomas Citharel committed
273
                    $('<div/>').html('{$slot->title|markdown:true}').text(),
JosephK's avatar
JosephK committed
274
275
276
                {/foreach}
                ];

277
278
                resIfneedbe.shift();
                resYes.shift();
279

JosephK's avatar
JosephK committed
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
                var barChartData = {
                    labels : cols,
                    datasets : [
                    {
                        label: "{__('Generic', 'Ifneedbe')}",
                        fillColor : "rgba(255,207,79,0.8)",
                        highlightFill: "rgba(255,207,79,1)",
                        barShowStroke : false,
                        data : resIfneedbe
                    },
                    {
                        label: "{__('Generic', 'Yes')}",
                        fillColor : "rgba(103,120,53,0.8)",
                        highlightFill : "rgba(103,120,53,1)",
                        barShowStroke : false,
                        data : resYes
                    }
                    ]
                };

                var ctx = document.getElementById("Chart").getContext("2d");
                window.myBar = new Chart(ctx).StackedBar(barChartData, {
                    responsive : true
                });
                return false;
            });
        });
    </script>
Thomas Citharel's avatar
Thomas Citharel committed
308

JosephK's avatar
JosephK committed
309
310
311
312
{/if}



313
314
{if !$hidden}
    {* Best votes listing *}
315
    {$max = max($best_choices['y'])}
316
317
318
319
    {if $max > 0}
        <div class="row">
        {if $count_bests == 1}
        <div class="col-sm-12"><h3>{__('Poll results', 'Best choice')}</h3></div>
JosephK's avatar
JosephK committed
320
321
        <div class="col-sm-6 col-sm-offset-3 alert alert-info">
            <p><i class="glyphicon glyphicon-star text-info"></i> {__('Poll results', 'The best choice at this time is:')}</p>
322
323
            {elseif $count_bests > 1}
            <div class="col-sm-12"><h3>{__('Poll results', 'Best choices')}</h3></div>
JosephK's avatar
JosephK committed
324
325
            <div class="col-sm-6 col-sm-offset-3 alert alert-info">
                <p><i class="glyphicon glyphicon-star text-info"></i> {__('Poll results', 'The bests choices at this time are:')}</p>
326
327
328
329
                {/if}


                {$i = 0}
Thomas Citharel's avatar
Thomas Citharel committed
330
                <ul class="list-unstyled">
331
                    {foreach $slots as $slot}
332
                        {if $best_choices['y'][$i] == $max}
Olivier PEREZ's avatar
Olivier PEREZ committed
333
                            <li><strong>{$slot->title|markdown:true}</strong></li>
334
335
336
337
338
339
                        {/if}
                        {$i = $i+1}
                    {/foreach}
                </ul>
                <p>{__('Generic', 'with')} <b>{$max|html}</b> {if $max==1}{__('Generic', 'vote')}{else}{__('Generic', 'votes')}{/if}.</p>
            </div>
340
        </div>
341
    {/if}
JosephK's avatar
JosephK committed
342
{/if}