vote_table_date.tpl 21.3 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
8
9
    {if $accessGranted}
        <a href="" data-toggle="modal" data-target="#hint_modal"><i class="glyphicon glyphicon-info-sign"></i></a>
    {/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
25
26
27
28
                    <th role="presentation"></th>
                    {$headersDCount=0}
                    {foreach $slots as $slot}
                        {foreach $slot->moments as $id=>$moment}
                            <td headers="M{$slot@key} D{$headersDCount} H{$headersDCount}">
29
                                <a href="{poll_url id=$admin_poll_id admin=true action='delete_column' action_value=$slot->day|cat:'@'|cat:$moment}"
Antonin's avatar
Antonin committed
30
31
                                   data-remove-confirmation="{__('adminstuds', 'Confirm removal of the column.')}"
                                   class="btn btn-link btn-sm remove-column"
32
                                   title="{__('adminstuds', 'Remove the column')} {$slot->day|date_format:$date_format.txt_short|html} - {$moment|html}">
33
                                    <i class="glyphicon glyphicon-remove text-danger"></i><span class="sr-only">{__('Generic', 'Remove')}</span>
34
                                </a>
35
36
37
38
39
                            </td>
                            {$headersDCount = $headersDCount+1}
                        {/foreach}
                    {/foreach}
                    <td>
Olivier PEREZ's avatar
Olivier PEREZ committed
40
                        <a href="{poll_url id=$admin_poll_id admin=true action='add_column'}"
41
                           class="btn btn-link btn-sm" title="{__('adminstuds', 'Add a column')}">
42
                            <i class="glyphicon glyphicon-plus text-success"></i><span class="sr-only">{__('Poll results', 'Add a column')}</span>
43
                        </a>
44
45
46
                    </td>
                </tr>
            {/if}
47
48
            <tr>
                <th role="presentation"></th>
49
50
                {$count_same = 0}
                {$previous = 0}
51
                {foreach $slots as $id=>$slot}
52
                    {$display = $slot->day|date_format:$date_format.txt_month_year|html}
53
54
55
56
57
58
59
60
61
62
63
64
65
                    {if $previous !== 0 && $previous != $display}
                        <th colspan="{$count_same}" class="bg-primary month" id="M{$id}">{$previous}</th>
                        {$count_same = 0}
                    {/if}

                    {$count_same = $count_same + $slot->moments|count}

                    {if $slot@last}
                        <th colspan="{$count_same}" class="bg-primary month" id="M{$id}">{$display}</th>
                    {/if}

                    {$previous = $display}

66
67
68
69
70
71
72
73
74
                    {for $foo=0 to ($slot->moments|count)-1}
                        {append var='headersM' value=$id}
                    {/for}
                {/foreach}
                <th></th>
            </tr>
            <tr>
                <th role="presentation"></th>
                {foreach $slots as $id=>$slot}
75
                    <th colspan="{$slot->moments|count}" class="bg-primary day" id="D{$id}">{$slot->day|date_format:$date_format.txt_day|html}</th>
76
77
78
                    {for $foo=0 to ($slot->moments|count)-1}
                        {append var='headersD' value=$id}
                    {/for}
79
80
81
82
83
84
                {/foreach}
                <th></th>
            </tr>
            <tr>
                <th role="presentation"></th>
                {$headersDCount=0}
85
                {$slots_raw = array()}
86
87
                {foreach $slots as $slot}
                    {foreach $slot->moments as $id=>$moment}
88
                        <th colspan="1" class="bg-info" id="H{$headersDCount}">{$moment|html}</th>
89
                        {append var='headersH' value=$headersDCount}
90
                        {$headersDCount = $headersDCount+1}
91
                        {$slots_raw[] = $slot->day|date_format:$date_format.txt_full|cat:' - '|cat:$moment}
92
93
94
95
96
97
98
                    {/foreach}
                {/foreach}
                <th></th>
            </tr>
            </thead>
            <tbody>
            {foreach $votes as $vote}
99
                {* Edited line *}
100

101
102
                {if $editingVoteId === $vote->uniqId && !$expired}
                <tr class="hidden-print">
Thomas Citharel's avatar
Thomas Citharel committed
103
                    <td class="bg-info btn-edit">
104
                        <div class="input-group input-group-sm" id="edit">
105
                            <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
106
107
                            <input type="hidden" name="edited_vote" value="{$vote->uniqId}"/>
                            <input type="text" id="name" name="name" value="{$vote->name|html}" class="form-control" title="{__('Generic', 'Your name')}" placeholder="{__('Generic', 'Your name')}" />
Thomas Citharel's avatar
Thomas Citharel committed
108

109
110
                        </div>
                    </td>
111

Erwan TERTRAIS's avatar
Erwan TERTRAIS committed
112

Olivier Perez's avatar
Olivier Perez committed
113
                    {$k=0}
114
115
116
117
                    {foreach $slots as $slot}
                      {foreach $slot->moments as $moment}
                        {$choice=$vote->choices[$k]}

118
119
120
121

                        <td class="bg-info" headers="M{$headersM[$k]} D{$headersD[$k]} H{$headersH[$k]}">
                            <ul class="list-unstyled choice">
                                <li class="yes">
122
                                    <input type="radio" id="y-choice-{$k}" name="choices[{$k}]" value="2" {if $choice=='2'}checked {/if}/>
123
                                    <label class="btn btn-default btn-xs" for="y-choice-{$k}" title="{__('Poll results', 'Vote yes for')|html} {$slots_raw[$k]}">
124
                                        <i class="glyphicon glyphicon-ok"></i><span class="sr-only">{__('Generic', 'Yes')}</span>
125
126
127
                                    </label>
                                </li>
                                <li class="ifneedbe">
128
                                    <input type="radio" id="i-choice-{$k}" name="choices[{$k}]" value="1" {if $choice=='1'}checked {/if}/>
129
                                    <label class="btn btn-default btn-xs" for="i-choice-{$k}" title="{__('Poll results', 'Vote ifneedbe for')|html} {$slots_raw[$k]}">
130
                                        (<i class="glyphicon glyphicon-ok"></i>)<span class="sr-only">{__('Generic', 'Ifneedbe')}</span>
131
132
133
                                    </label>
                                </li>
                                <li class="no">
134
                                    <input type="radio" id="n-choice-{$k}" name="choices[{$k}]" value="0" {if $choice=='0'}checked {/if}/>
135
                                    <label class="btn btn-default btn-xs" for="n-choice-{$k}" title="{__('Poll results', 'Vote no for')|html} {$slots_raw[$k]}">
136
                                        <i class="glyphicon glyphicon-ban-circle"></i><span class="sr-only">{__('Generic', 'No')}</span>
137
138
                                    </label>
                                </li>
Thomas Citharel's avatar
Thomas Citharel committed
139
                                <li class="hide">
140
141
                                    <input type="radio" id="n-choice-{$k}" name="choices[{$k}]" value=" " {if $choice!='2' && $choice!='1' && $choice!='0'}checked {/if}/>
                                </li>
142
143
                            </ul>
                        </td>
144
145
146

                        {$k=$k + 1}
                      {/foreach}
147
                    {/foreach}
148

Thomas Citharel's avatar
Thomas Citharel committed
149
                    <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>
150

151
152
153
                </tr>
                {elseif !$hidden}
                <tr>
154

155
                    {* Voted line *}
Erwan TERTRAIS's avatar
Erwan TERTRAIS committed
156
                    <th class="bg-info">{$vote->name|html}
157
158
159
160
161
162
163
164
                    {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|count gt 4
                    }
Thomas Citharel's avatar
Thomas Citharel committed
165
						<span class="edit-username-left">
Erwan TERTRAIS's avatar
Erwan TERTRAIS committed
166
167
168
							<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>
Erwan TERTRAIS's avatar
Erwan TERTRAIS committed
169
					</span>
Erwan TERTRAIS's avatar
Erwan TERTRAIS committed
170
					{/if}
Erwan TERTRAIS's avatar
Erwan TERTRAIS committed
171
					</th>
172

Thomas Citharel's avatar
Thomas Citharel committed
173
174
175



Olivier Perez's avatar
Olivier Perez committed
176
                    {$k=0}
177
178
179
                    {foreach $slots as $slot}
                      {foreach $slot->moments as $moment}
                        {$choice=$vote->choices[$k]}
180

181
                        {if $choice=='2'}
182
                            <td class="bg-success text-success" headers="M{$headersM[$k]} D{$headersD[$k]} H{$k}"><i class="glyphicon glyphicon-ok"></i><span class="sr-only">{__('Generic', 'Yes')}</span></td>
183
                        {elseif $choice=='1'}
184
                            <td class="bg-warning text-warning" headers="M{$headersM[$k]} D{$headersD[$k]} H{$k}">(<i class="glyphicon glyphicon-ok"></i>)<span class="sr-only">{__('Generic', 'Ifneedbe')}</span></td>
185
                        {elseif $choice=='0'}
186
                            <td class="bg-danger text-danger" headers="M{$headersM[$k]} D{$headersD[$k]} H{$k}"><i class="glyphicon glyphicon-ban-circle"></i><span class="sr-only">{__('Generic', 'No')}</span></td>
Olivier Perez's avatar
Olivier Perez committed
187
                        {else}
188
                            <td class="bg-info" headers="M{$headersM[$k]} D{$headersD[$k]} H{$k}"><span class="sr-only">{__('Generic', 'Unknown')}</span></td>
189
                        {/if}
190

191
192
                        {$k=$k + 1}
                      {/foreach}
193
194
                    {/foreach}

Antonin's avatar
Antonin committed
195
                    {if $active && !$expired && $accessGranted &&
196
197
198
                        (
                            $poll->editable == constant('Framadate\Editable::EDITABLE_BY_ALL')
                            or $admin
199
                            or ($poll->editable == constant('Framadate\Editable::EDITABLE_BY_OWN') && $editedVoteUniqueId == $vote->uniqId)
200
201
                        )
                    }
202
                        <td class="hidden-print">
Antonin's avatar
Antonin committed
203
                            <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}">
204
                                <i class="glyphicon glyphicon-pencil"></i><span class="sr-only">{__('Generic', 'Edit')}</span>
205
206
207
208
209
                            </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}">
210
                                    <i class="glyphicon glyphicon-remove text-danger"></i><span class="sr-only">{__('Generic', 'Remove')}</span>
211
212
213
214
215
                                </a>
                            {/if}
                        </td>
                    {else}
                        <td></td>
216
217
                    {/if}
                </tr>
218
                {/if}
219
220
221
222
            {/foreach}

            {* Line to add a new vote *}

223
            {if $active && $editingVoteId === 0 && !$expired && $accessGranted}
224
                <tr id="vote-form" class="hidden-print">
Thomas Citharel's avatar
Thomas Citharel committed
225
                    <td class="bg-info btn-edit">
226
                        <div class="input-group input-group-sm">
227
                            <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
228
                            <input type="text" id="name" name="name" class="form-control" title="{__('Generic', 'Your name')}" placeholder="{__('Generic', 'Your name')}" />
229
230
                        </div>
                    </td>
231
232


233
                    {$i = 0}
234
                    {foreach $slots as $slot}
235
                        {foreach $slot->moments as $moment}
236

237

238

239
                            <td class="bg-info" headers="M{$headersM[$i]} D{$headersD[$i]} H{$headersH[$i]}">
240
                                <ul class="list-unstyled choice">
241
                                    {if $poll->ValueMax eq NULL || $best_choices['y'][$i] lt $poll->ValueMax}
242
243
                                    <li class="yes">
                                        <input type="radio" id="y-choice-{$i}" name="choices[{$i}]" value="2" />
244
                                        <label class="btn btn-default btn-xs" for="y-choice-{$i}" title="{__('Poll results', 'Vote yes for')|html} {$slot->day|date_format:$date_format.txt_short|html} - {$moment|html}">
245
                                            <i class="glyphicon glyphicon-ok"></i><span class="sr-only">{__('Generic', 'Yes')}</span>
246
247
248
249
                                        </label>
                                    </li>
                                    <li class="ifneedbe">
                                        <input type="radio" id="i-choice-{$i}" name="choices[{$i}]" value="1" />
250
                                        <label class="btn btn-default btn-xs" for="i-choice-{$i}" title="{__('Poll results', 'Vote ifneedbe for')|html} {$slot->day|date_format:$date_format.txt_short|html} - {$moment|html}">
251
                                            (<i class="glyphicon glyphicon-ok"></i>)<span class="sr-only">{__('Generic', 'Ifneedbe')}</span>
252
253
                                        </label>
                                    </li>
254

255
256
				{/if}

257
                                    <li class="no">
258
                                        <input type="radio" id="n-choice-{$i}" name="choices[{$i}]" value="0" />
259
260
                                        <label class="btn btn-default btn-xs startunchecked" for="n-choice-{$i}" title="{__('Poll results', 'Vote no for')|html} {$slot->day|date_format:$date_format.txt_short|html} - {$moment|html}">
                                            <i class="glyphicon glyphicon-ban-circle"></i><span class="sr-only">{__('Generic', 'No')}</span>
261
262
                                        </label>
                                    </li>
Thomas Citharel's avatar
Thomas Citharel committed
263
                                    <li class="hide">
264
265
                                      <input type="radio" id="n-choice-{$i}" name="choices[{$i}]" value=" " checked/>
                                    </li>
266
267
                                </ul>
                            </td>
268

269

270

271
272
273
                            {$i = $i+1}
                        {/foreach}
                    {/foreach}
274
                    <td><button type="submit" class="btn btn-success btn-md" name="save" title="{__('Poll results', 'Save the choices')}">{__('Generic', 'Save')}</button></td>
275
276
277
                </tr>
            {/if}

278
279
280
            {if !$hidden}
                {* Line displaying best moments *}
                {$count_bests = 0}
281
                {$max = max($best_choices['y'])}
282
283
                {if $max > 0}
                    <tr id="addition">
JosephK's avatar
JosephK committed
284
                        <td>{__('Poll results', 'Addition')}<br/>{$votes|count} {if ($votes|count)==1}{__('Poll results', 'polled user')}{else}{__('Poll results', 'polled users')}{/if}</td>
285
                        {foreach $best_choices['y'] as $i=>$best_moment}
286
287
                            {if $max == $best_moment}
                                {$count_bests = $count_bests +1}
JosephK's avatar
JosephK committed
288
                                <td><i class="glyphicon glyphicon-star text-info"></i><span class="yes-count">{$best_moment|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>
289
                            {elseif $best_moment > 0}
JosephK's avatar
JosephK committed
290
291
292
                                <td><span class="yes-count">{$best_moment|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>
293
294
295
296
297
298
                            {else}
                                <td></td>
                            {/if}
                        {/foreach}
                    </tr>
                {/if}
299
            {/if}
300
301
302
303
304
            </tbody>
        </table>
    </form>
</div>

JosephK's avatar
JosephK committed
305
306
307
308
309
310
311
312
313
314
315
316
317
{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() {
318
319
320
                $('#showChart')
                        .after("<h3>{__('Poll results', 'Chart')}</h3><canvas id=\"Chart\"></canvas>")
                        .remove();
Thomas Citharel's avatar
Thomas Citharel committed
321

JosephK's avatar
JosephK committed
322
323
                var resIfneedbe = [];
                var resYes = [];
Thomas Citharel's avatar
Thomas Citharel committed
324

325
326
327
328
                $('#addition').find('td').each(function () {
                    var inbCountText = $(this).find('.inb-count').text();
                    if(inbCountText != '' && inbCountText != undefined) {
                        resIfneedbe.push(inbCountText)
JosephK's avatar
JosephK committed
329
330
331
                    } else {
                        resIfneedbe.push(0);
                    }
332
333
334
                    var yesCountText = $(this).find('.yes-count').text();
                    if(yesCountText != '' && yesCountText != undefined) {
                        resYes.push(yesCountText)
JosephK's avatar
JosephK committed
335
336
337
338
339
340
341
                    } else {
                        resYes.push(0);
                    }
                });
                var cols = [
                {foreach $slots as $slot}
                    {foreach $slot->moments as $moment}
Thomas Citharel's avatar
Thomas Citharel committed
342
                        $('<div/>').html('{$slot->day|date_format:$date_format.txt_short|html} - {$moment|html}').text(),
JosephK's avatar
JosephK committed
343
344
345
346
                    {/foreach}
                {/foreach}
                ];

347
348
                resIfneedbe.shift();
                resYes.shift();
349

JosephK's avatar
JosephK committed
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
                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
378

JosephK's avatar
JosephK committed
379
380
{/if}

381
382
{if !$hidden}
    {* Best votes listing *}
383
    {$max = max($best_choices['y'])}
384
385
386
387
    {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
388
389
        <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>
390
391
            {elseif $count_bests > 1}
            <div class="col-sm-12"><h3>{__('Poll results', 'Best choices')}</h3></div>
JosephK's avatar
JosephK committed
392
393
            <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>
394
                {/if}
395
396


397
                {$i = 0}
Thomas Citharel's avatar
Thomas Citharel committed
398
                <ul class="list-unstyled">
399
400
                    {foreach $slots as $slot}
                        {foreach $slot->moments as $moment}
401
                            {if $best_choices['y'][$i] == $max}
402
403
404
405
                                <li><strong>{$slot->day|date_format:$date_format.txt_full|html} - {$moment|html}</strong></li>
                            {/if}
                            {$i = $i+1}
                        {/foreach}
406
                    {/foreach}
407
408
409
                </ul>
                <p>{__('Generic', 'with')} <b>{$max|html}</b> {if $max==1}{__('Generic', 'vote')}{else}{__('Generic', 'votes')}{/if}.</p>
            </div>
410
        </div>
411
    {/if}
JosephK's avatar
JosephK committed
412
{/if}