# -*- coding: utf-8 -*- 
<%inherit file="jm2l:templates/layout.mako"/>
<%
from slugify import slugify
%>
<a style="float:right;" class="btn btn-mini btn-info" role="button" href="/Salles">
    <i class="icon-plus-sign icon-white"></i> Ajouter une Salle
</a>
<h3>Gestion des salles JM2L</h3>

<div class="row-fluid">
  <div class="span10 offset1">

<div class="tabbable" id="main_tab">
    <ul class="nav nav-tabs" style="margin-bottom: 5px;">
        % for Num, Entity in enumerate(sorted(DicSalle.keys(), key=lambda x:x.year_uid, reverse=True)):
        <li class="${["","active"][Num==0]}">
            <a href="#${Entity.year_uid}" id="Map_Pole_${Entity.year_uid}" data-toggle="tab">${Entity.year_uid}</a>
        </li>
        % endfor
    </ul>

    <div class="tab-content" style="padding:0 10px">

% for Num, Entity in enumerate(sorted(DicSalle.keys(), key=lambda x:x.year_uid, reverse=True)):
        <div class="tab-pane fade ${["","active "][Num==0]} in" id="${Entity.year_uid}">
            <h4>${Entity.year_uid}</h4>
<table class="table table-striped table-bordered table-hover">
  <thead>
    <tr>
        <th colspan="2" style="text-align:center;">
            Liste des salles
        </th>
    </tr>
  </thead>
  <tbody>
    % if len(DicSalle[Entity])==0:
        <tr> 
            <td style="text-align:center;">
                <i>Il n'y a pas de salle définie pour l'année ${Entity.year_uid}</i>
            </td>
        </tr>
    % endif
    % for Salle in DicSalle[Entity]:
        <tr> 
            <td>
                ${Salle.place_type or ""} <a href="/Salles/${Salle.salle_id}">${Salle.name or ""}</a>
                ${len(Salle.allevents)} : [
                % for e in Salle.allevents:
                    <a href="/event/${e.for_year}/${e.slug}">${e.uid}</a>,
                % endfor
                ]
                <div class="pull-right">
                % if Salle.phy_salle_id:
                [ <a href="/PhySalles/${Salle.phy_salle_id}">${Salle.phy.name}</a> ${Salle.phy.nb_places} places ]
                % else:
                [ <a href="/PhySalles">Créer</a> ]
                % endif
                </div>
            </td>
        </tr>
        % if Salle.description:
        <tr>
            <td><div>${Salle.description | n}</div></td>
        </tr>
        % endif
    % endfor
  </tbody>
</table>
        </div>
% endfor
    </div>
</div>

  </div>
</div>
<%def name="jsAddOn()">
<script>
    $('a[data-toggle="tab"]')
        .on('shown', function(e) {
            //stateObj = { tab: $(e.target).attr('href').substr(1) };
            //history.replaceState(stateObj, "", "/Staff" + $(e.target).attr('href') );
            location.hash = $(e.target).attr('href');
        }); 
    
    if (location.hash !== '') {
        $('a[href="' + location.hash + '"]').tab('show');
    }
</script>
</%def>
