modify to range voting
[cavote.git] / templates / vote.html
index e3ecbfc..a832684 100644 (file)
 {% extends "layout.html" %}
+{% block subtitle %}{{vote.title}}{% endblock %}
 {% block body %}
 <div class="row">
+<div class="span3">
+<h2 class="page-header">Informations</h2>
+<div class="progress progress-striped progress-{% if vote.nb_votes > 0 and vote.nb_votes / vote.max_votes >= vote.quorum %}success{% else %}danger{% endif %}">
+  <div class="bar" style="width: {{ vote.percent }}%;">
+    <strong>{{ vote.nb_votes }} vote{{ 's' if vote.nb_votes > 1 else '' }} / {{ vote.max_votes }} ({{ vote.percent }}%)</strong></div>
+</div>
+<dl class="dl-horizontal">
+  <dt>Publié par <dd><code>{{ vote.author }}</code>
+  <dt>Début le <dd><code>{{ vote.date_begin }}</code>
+  <dt>Fin le <dd><code>{{ vote.date_end }}</code>
+  <dt>Groupe <dd><code>{{ vote.groupname }}</code>
+  <dt>Catégorie <dd><code>{{ vote.category }}</code>
+  <dt>Quorum <dd><code>{{ vote.quorum * 100 }}%</code>
+</dl>
+<dl>
+  {% if vote.description %}
+  <dt>Description : <dd>{{ vote.description }}
+  {% endif %}
+  {% if attachments %}
+  <dt>Documents :<dd>
+  <ul>
+    {% for attachment in attachments %}
+    <li><a href="{{ attachment.url }}">{{ attachment.url }}</a></li>
+    {% endfor %}
+  </ul>
+  {% endif %}
+</dl>
+</div>
+
+{% if vote.is_transparent or (session.user and user.userid == session.user.id )%}
+<div class="span8">
+  <h2 class='page-header'>Résultats</h2>
+  <svg class="results cardinal-{{ vote.id_cardinal }}"
+       width="{{ 150 + (100 * 5) + 50 + 100 + 100 }}"
+       height="{{25 + results.list|length * 20 + 40}}">
+    <g class="choice" transform="translate(100,0)">
+      <text class="choice-legend" x="-10" y="9.5" dy=".35em">Légende :</text>
+     </g>
+    {% for value in values %}
+    <g transform="translate({{ 150 + (loop.index0 * 640 / loop.length) }},0)">
+      <rect width="{{ 640 / loop.length }}" height="20"></rect>
+      <rect class="{{ value.class }}" x="1" y ="1" width="{{ 640 / loop.length - 1}}" height="19"></rect>
+      <text class="choice-legend-item" text-anchor="start" x="{{ 640 / loop.length - 2 }}" y="9.5" dy=".35em"
+       >{{ value.name }}</text>
+     </g>
+    {% endfor %}
+    <g transform="translate({{150 + (100 * 5) + 35}},20)">
+      <text class="choice-sum-legend" x="20" y="9.5" dy=".35em">somme↓</text>
+     </g>
+    <g transform="translate({{150 + (100 * 5) + 115}},20)">
+      <text class="choice-average-legend" x="20" y="9.5" dy=".35em">moyenne↓</text>
+     </g>
+    {% for choice in results.list %}
+    <g class="choice" transform="translate(150,{{ 35 + loop.index0 * 20 }})">
+      <text class="choice" x="-10" y="9.5" dy=".35em">{{ choice.name }}</text>
+     </g>
+    {% set choice_loop = loop %}
+    {% for value in choice.values_ %}
+    <g transform="translate({{ 150 + (value.previous_percent * 5) }},{{ 35 + choice_loop.index0 * 20 }})">
+      {% if value.percent > 0 %}
+      <rect class="{{ value.class }}" width="{{ (value.percent * 5)|int }}" height="19"></rect>
+      <text text-anchor="middle" x="{{ (value.percent * 5 / 2 + 10)|int }}" y="9.5" dy=".35em"
+       >{{ value.percent|int }}%</text>
+      {% endif %}
+     </g>
+    {% endfor %}
+    <g transform="translate({{150 + (100 * 5) + 35}},{{35 + loop.index0 * 20}})">
+      <text class="choice-sum" x="20" y="9.5" dy=".35em">{{ choice.sum }}</text>
+     </g>
+    <g transform="translate({{150 + (100 * 5) + 115}},{{35 + loop.index0 * 20}})">
+      <text class="choice-average" x="20" y="9.5" dy=".35em">{{ "%.2f"|format(choice.average) }}</text>
+     </g>
+    {% if loop.length > 1 and choice.id in results.medians %}
+    <g transform="translate({{150 + (100 * 5) + 125}},{{35 + loop.index0 * 20}})">
+      <text class="choice-median" x="75" y="9.5" dy=".35em">← médiane</text>
+     </g>
+    {%endif%}
+    {% endfor %}
+    <g class="axis" transform="translate(150,{{35 + results.list|length * 20}})">
+      <g transform="translate(0,0)" style="opacity: 1;" class="tick">
+        <line x1="0" y1="6" x2="0" y2="0"></line>
+        <text style="text-anchor: middle;" dy=".71em" x="0" y="9">0%</text>
+       </g>
+      <g transform="translate(125,0)" style="opacity: 1;" class="tick">
+        <line x1="0" y1="6" x2="0" y2="0"></line>
+        <text style="text-anchor: middle;" dy=".71em" x="0" y="9">25%</text>
+       </g>
+      <g transform="translate(250,0)" style="opacity: 1;" class="tick">
+        <line x1="0" y1="6" x2="0" y2="0"></line>
+        <text style="text-anchor: middle;" dy=".71em" x="0" y="9">50%</text>
+       </g>
+      <g transform="translate(375,0)" style="opacity: 1;" class="tick">
+        <line x1="0" y1="6" x2="0" y2="0"></line>
+        <text style="text-anchor: middle;" dy=".71em" x="0" y="9">75%</text>
+       </g>
+      <g transform="translate(500,0)" style="opacity: 1;" class="tick">
+        <line x1="0" y1="6" x2="0" y2="0"></line>
+        <text style="text-anchor: middle;" dy=".71em" x="0" y="9">100%</text>
+       </g>
+      <path d="M0,6V0H500V6" class="domain"></path>
+     </g>
+   </svg>
+</div>
+{% endif %}
+
 <div class="span9">
-  <h2 class='page-header'>{{ vote.title }}</h2> 
+  <h2 class='page-header'>Suffrages</h2>
+{% if vote.is_anonymous %}
+<div class="alert alert-info">Ce vote est anonymisé, les suffrages ne sont ni visibles ni modifiables.</div>
+{% endif %}
 {% if not vote.is_transparent %}
-<div class="alert alert-info">Ce sondage n'est pas transparent, vous ne pouvez pas voir les votes des autres.</div>
+<div class="alert alert-info">Ce vote n’est pas transparent, vous ne pouvez pas voir les votes des autres.</div>
 {% endif %}
 
-<table class="table table-condensed table-bordered table-votes">
+{% if (vote['is_anonymous'] and can_vote) or not vote['is_anonymous'] %}
+<table class="table table-condensed table-bordered table-votes cardinal-{{ vote.id_cardinal }}">
   <thead>
     <tr>
       <th></th>
       {% for choice in choices %}
-      <th>{{ choice.name }}</th>
+      <th class="choice-name">{{ choice.name }}</th>
       {% endfor %}
-      {% if 'user' in session %}
+      {% if 'user' in session and (can_vote or (not vote['is_terminated'] and not vote['is_anonymous'])) %}
       <th></th>
       {% endif %}
     </tr>
+  {% if vote.is_transparent %}
+    <!--
+    <tr>
+      <th>Somme</th>
+      {% for choice in choices %}
+      <td>{{ choice.sum }}</td>
+      {% endfor %}
+      {% if 'user' in session and (can_vote or (not vote['is_terminated'] and not vote['is_anonymous'])) %}
+      <td></td>
+      {% endif %}
+    </tr>
+    -->
+  {% endif %}
+
+  {% if can_vote %}
+    <form class="form-inline" action="{{ url_for('vote', idvote=vote.id) }}" method="post">
+    <tr>
+      <th><input type='text' name="username" value='{{ session.user.name }}' disabled /></th>
+      {% for choice in choices %}
+      <td>
+        <select name="value-{{ choice.id }}" id="value-{{ choice.id }}">
+          {% for value in values %}
+          <option value="{% if value.weight is not none %}{{ value.weight }}{% endif %}" class="{{ value.class }}">{{ value.name }}</option>
+          {% endfor %}
+        </select>
+      </td>
+      {% endfor %}
+      <td><input type="submit" class="btn btn-primary" value="OK" /></td>
+    </tr>
+    </form>
+  {% endif %}
   </thead>
 
+  {% if not vote['is_anonymous'] %}
   <tbody>
   {% for user in users %}
   {% if vote.is_transparent or (session.user and user.userid == session.user.id )%}
     <tr>
       <th>{% if 'user' in session and user.userid == session.user.id %}<i class="icon-user"></i>{% endif %} {{ user.username }}</th>
       {% for choice in choices %}
-      {% if choice.id in user.choices %}
-      <td class="yes"><i class="icon-ok icon-white"></i></td>
-      {% else %}
-      <td class="no"></td>{% endif %}
+      <td class="{{user.choices[choice.id].class}}"><span>{{ user.choices[choice.id].name }}</span></td>
       {% endfor %}
-      {% if 'user' in session %}
+      {% if 'user' in session and (can_vote or (not vote['is_terminated'] and not vote['is_anonymous'])) %}
       <td>{% if user.userid == session.user.id %}
         <a href="#delete" data-toggle="modal" class="btn btn-danger btn-mini" title="Supprimer"><i class="icon-remove icon-white"></i></a>
         <div class="modal hide fade" id="delete">
     </tr>
   {% endif %}
   {% endfor %}
-
-  {% if can_vote %}
-    <form class="form-inline" action="{{ url_for('vote', idvote=vote.id) }}" method="post">
-    <tr>
-      <th><input type='text' name="username" value='{{ session.user.name }}' disabled /></th>
-      {% if vote.is_multiplechoice %}
-      {% for choice in choices %}
-      <td><input type='checkbox' name="{{ choice.id }}" value="{{ choice.id }}" /></td>
-      {% endfor %}
-      {% else %}
-      {% for choice in choices %}
-      <td><input type='radio' name="choice" value="{{ choice.id }}" /></td>
-      {% endfor %}
-      {% endif %}
-      <td><input type="submit" class="btn btn-primary" value="OK" /></td>
-    </tr>
-    </form>
-  {% endif %}
   </tbody>
-
-  <tfoot>
-  {% if vote.is_transparent %}
-    <tr>
-      <th>Somme</th>
-      {% for choice in choices %}
-      <td>{{ choice.nb }}</td>
-      {% endfor %}
-      {% if 'user' in session %}
-      <td></td>
-      {% endif %}
-    </tr>
   {% endif %}
-  </tfoot>
 </table>
-</div>
-
-<div class="span3">
-<h3>Informations</h3>
-{% if vote.nb_votes == 0 %}
-<div class="progress progress-striped progress-danger">
-  <div class="bar" style="width: 100%;"><strong>{{ vote.nb_votes }} / {{ vote.max_votes }}</strong></div>
-</div>
 {% else %}
-<div class="progress progress-striped {% if vote.nb_votes == vote.max_votes %}progress-success{% endif %}">
-  <div class="bar" style="width: {{ vote.percent }}%;"><strong>{{ vote.nb_votes }} / {{ vote.max_votes }}</strong></div>
-</div>
+{% if not can_vote %}
+<div class="alert alert-info">Vous avez déjà voté.</div>
+{% endif %}
 {% endif %}
-<dl class="dl-horizontal">
-  <dt>Publié par <dd><code>{{ vote.author }}</code>
-  <dt>Début le <dd><code>{{ vote.date_begin }}</code>
-  <dt>Deadline le <dd><code>{{ vote.date_end }}</code>
-  <dt>Groupe <dd><code>{{ vote.groupname }}</code>
-  <dt>Catégorie <dd><code>{{ vote.category }}</code>
-</dl>
-<dl>
-  {% if vote.description %}
-  <dt>Description : <dd>{{ vote.description }}
-  {% endif %}
-  {% if attachments %}
-  <dt>Documents :<dd>
-  <ul>
-    {% for attachment in attachments %}
-    <li><a href="{{ attachment.url }}">{{ attachment.url }}</a></li>
-    {% endfor %}
-  </ul>
-  {% endif %}
-</dl>
 </div>
 
 </div>