modify to range voting
[cavote.git] / templates / vote.html
index 47b1d29..a832684 100644 (file)
 {% extends "layout.html" %}
+{% block subtitle %}{{vote.title}}{% endblock %}
 {% block body %}
 <div class="row">
-<div class="span9">
-<h2 class='page-header'>{{ vote.title }}</h2>
+<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'>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 and (can_vote or (not vote['is_terminated'] and not vote['is_anonymous'])) %}
       <th></th>
+      {% endif %}
     </tr>
-  </thead>
-
-  <tbody>
-  {% for user in users %}
-  {% if vote.is_transparent or user.userid == session.user.id %}
+  {% if vote.is_transparent %}
+    <!--
     <tr>
-      <th>{% if 'user' in session and user.userid == session.user.id %}<i class="icon-user"></i>{% endif %} {{ user.username }}</th>
+      <th>Somme</th>
       {% for choice in choices %}
-      {% if choice.id in user.choices %}
-      <td class="yes">OUI</td>
-      {% else %}
-      <td class="no"></td>{% endif %}
+      <td>{{ choice.sum }}</td>
       {% endfor %}
-      <td>{% if 'user' in session and user.userid == session.user.id %}<a href="{{ url_for('vote_deletechoices', idvote=vote.id, iduser=session.user.id) }}" class="btn btn-mini btn-danger" title="Supprimer">X</a>{% endif %}</td>
+      {% if 'user' in session and (can_vote or (not vote['is_terminated'] and not vote['is_anonymous'])) %}
+      <td></td>
+      {% endif %}
     </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_multiple %}
-      {% for choice in choices %}
-      <td><input type='checkbox' name="{{ choice.id }}" /></td>
-      {% endfor %}
-      {% else %}
       {% for choice in choices %}
-      <td><input type='radio' name="{{ choice.id }}" /></td>
+      <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 %}
-      {% endif %}
       <td><input type="submit" class="btn btn-primary" value="OK" /></td>
     </tr>
     </form>
   {% endif %}
-  </tbody>
+  </thead>
 
-  <tfoot>
-  {% if vote.is_transparent %}
+  {% 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>Somme</th>
+      <th>{% if 'user' in session and user.userid == session.user.id %}<i class="icon-user"></i>{% endif %} {{ user.username }}</th>
       {% for choice in choices %}
-      <td>{{ choice.nb }}</td>
+      <td class="{{user.choices[choice.id].class}}"><span>{{ user.choices[choice.id].name }}</span></td>
       {% endfor %}
-      <td></td>
+      {% 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">
+          <div class="modal-header">
+            <button type="button" class="close" data-dismiss="modal">×</button>
+            <h3>Suppression de votre vote</h3>
+          </div>
+          <div class="modal-body">
+            <p>Voulez-vous vraiment supprimer votre vote ?</p>
+          </div>
+          <div class="modal-footer">
+            <a href="{{ url_for('vote_deletechoices', idvote=vote.id, iduser=session.user.id) }}" class="btn btn-danger">Confirmer</a>
+            <a href="#" class="btn" data-dismiss="modal">Annuler</a>
+          </div>
+        </div>
+      {% endif %}</td>
+      {% endif %}
     </tr>
   {% endif %}
-  </tfoot>
+  {% endfor %}
+  </tbody>
+  {% endif %}
 </table>
-</div>
-
-<div class="span3">
-<h3>Informations</h3>
-<dl class="dl-horizontal">
-  <dt>Publié par <dd><code>maethor</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.rolename }}</code>
-  <dt>Catégorie <dd><code>{{ vote.category }}</code>
-</dl>
-<dl>
-  <dt>Description : <dd>{{ vote.description }}
-  <dt>Documents :<dd>
-  <ul>
-    {% for attachment in attachments %}
-    <li><a href="{{ attachment.url }}">{{ attachment.url }}</a></li>
-    {% endfor %}
-  </ul>
-  </li>
-</dl>
+{% else %}
+{% if not can_vote %}
+<div class="alert alert-info">Vous avez déjà voté.</div>
+{% endif %}
+{% endif %}
 </div>
 
 </div>