# -*- coding: utf-8 -*- 
<%inherit file="jm2l:templates/Participant/list.mako"/>

<%
import datetime
import itertools
now = datetime.datetime.now()
%>

<form class="filterform" action="#">
	<table class="table table-bordered table-hover">
      <thead>
        <tr>
            <th style="width:7em;text-align:center;"></th>
            <th style="width:5em;text-align:center;">Visite</th>
            <th style="width:7em;text-align:center;">Activité</th>
            <th style="text-align:center;">Arrivée prévue</th>
            <th style="width:5em;text-align:center;">${DicRepas['Ven']} Repas Vendredi</th>
            <th style="width:5em;text-align:center;">${DicRepas['Midi']} Repas Midi </th>
            <th style="width:5em;text-align:center;">${DicRepas['Soir']} Repas Soir</th>
            <th style="text-align:center;">Départ prévu</th>
            <th style="text-align:center;">Notes</th>
        </tr>
      </thead>
      <tbody id="list">
		% for u, s in Users:      
            <tr>
                <td style="text-align:center;">
                	<span class="data">${u.slug}</span>
					<a href="/MesJM2L?user=${u.uid}">${u.nom} ${u.prenom}</a><br /> 
                        <span style="align:center">
		                    ${u.vote_logo}
                            <a href="mailto:${u.mail}"> 
                                <i class="icon-envelope"></i>
                            </a>                            
							% if u.Staff==1:
	                            <a href="javascript:alert('${u.nom}, ${u.prenom}\nStaff JM2L');"> 
	                                <i class="icon-star"></i>
	                            </a>
							% endif
							% if u.Staff==0:
	                            <a href="javascript:alert('${u.nom}, ${u.prenom}\nIntervenant');"> 
	                                <i class="icon-user"></i>
	                            </a>
							% endif
							% if u.active==0:							
                            <a href="javascript:alert('${u.nom}, ${u.prenom}\nInactive');"> 
                                <i class="icon-ban-circle"></i>
                            </a>
							% endif
							% if u.phone:							
                            <a href="javascript:alert('${u.nom}, ${u.prenom}\n${u.phone}');"> 
                                <i class="icon-headphones"></i>
                            </a>
							% endif
							<a href="/user/${u.slug}/badge">
                                <i class="icon-qrcode"></i>
                            </a>
                        </span>
                </td>
                <td style="text-align:center;">
                	<span class="data">${(now - u.last_logged).days}</span>${(now - u.last_logged).days} j
                </td>
                <td style="text-align:center;">
                    % if u.events:
                    	<span class="data">${len(u.events)}</span>
                    	<select style="width:7em;">
                    		<option><strong>${len(u.events)} Intérv.</strong></option>
	                    	% for y, g in itertools.groupby(sorted(u.events, key=lambda k:k.for_year, reverse=True), key=lambda k:k.for_year):
						    <OPTGROUP LABEL="${y}">
						    	% for event in g:
		                    	${event.for_year}
		                    	<OPTION onclick="location='/event/${event.for_year}/${event.slug}';">${event.event_type} - ${event.name}</OPTION>
			                    % endfor
							</OPTGROUP>
		                    % endfor
	                    </select>
                    %else:
                        <span class="data"></span>
                    	<i> - </i>
                    % endif
                </td>
                <td style="text-align:center;">
                    % if s and s.arrival_time:
                    	<span class="data">${s.arrival_time.strftime('%m/%d/%Y %H:%M:%S')}</span>
                    	${s.arrival_time.strftime('%a %d <strong>%H:%M</strong>') | n}<br/>
                    	${s.arrival_place}
                    	% if s.arrival_text:
                    		- NB: <strong>${s.arrival_text}</strong>
                    	% endif
                    %else:
                    	<span class="data"></span>                    
                    	<i>Pas d'informations</i>
                    % endif
                </td>
	            % if s and s.repas:
	        		% for i, d in enumerate(['Ven Soir', 'Sam midi', 'Sam soir']):
	        		<td style="text-align:center">
	                	% if (s.repas & 2**i):
	                		<span class="data">Oui</span>Oui
	                	% else:
	                		<span class="data">Non</span>Non
	                	% endif
	        		</td>
	        		% endfor
                %else:
	                <td style="text-align:center;" colspan="3">
	                	<i>Pas d'informations</i>
	                </td>
                % endif
                </td>
                <td style="text-align:center;">
                    % if s and s.depart_time:
                    	<span class="data">${s.depart_time.strftime('%m/%d/%Y %H:%M:%S')}</span>                    
                    	${s.depart_time.strftime('%a %d <strong>%H:%M</strong>') | n}<br/>
                    	${s.depart_place}                    	
                    	% if s.depart_text:
                    		- NB: <strong>${s.arrival_text}</strong>
                    	% endif
                    %else:
                    	<span class="data"></span>
                    	<i>Pas d'informations</i>
                    % endif
                </td>
                <td>
		            % if s:
		            	% if s.repas_allerg:
		            		<u>Allergies</u> : ${s.repas_allerg}<br/>
		            	% endif
		            	% if s.repas_contr:
		            		<u>Contraintes</u> : ${s.repas_contr}<br/>
		            	% endif
                    % endif
                </td>
            </tr>
        % endfor
      </tbody>
    </table>
</form>
