# -*- 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="/${year}/Staff/poles">
    <i class="icon-plus-sign icon-white"></i> Ajouter un Pôle d'activit&eacute;
</a>
<h3>Liste des tâches JM2L Staff</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(tasks.keys(), key=lambda x:x.name)):
        <li class="${["","active"][Num==0]}">
            <a href="#${slugify(Entity.name)}" id="Map_Pole_${slugify(Entity.name)}" data-toggle="tab">${Entity.name}</a>
        </li>
        % endfor
    </ul>

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

% for Num, Entity in enumerate(sorted(tasks.keys(), key=lambda x:x.name)):
        <div class="tab-pane fade ${["","active "][Num==0]} in" id="${slugify(Entity.name)}">
            <a style="float:right;" class="btn btn-mini btn-info" role="button" href="/${year}/Staff/poles/${Entity.uid}">
                <i class="icon-pencil icon-white"></i> Editer le pôle
            </a>
            <h4>${Entity.name}</h4>
            % if Entity.description:
            <div>${Entity.description | n}</div>
            % endif
<table class="table table-striped table-bordered table-hover">
  <thead>
    <tr>
        <th colspan="2" style="text-align:center;">
            <a style="float:right;" class="btn btn-mini btn-info" role="button" href="${request.route_path('handle_task', sep="", task_id="", year=year, _query={"pole_id":Entity.uid})}">
                <i class="icon-plus-sign icon-white"></i> Ajouter une tâche
            </a>
            Liste des tâches
        </th>
    </tr>
  </thead>
  <tbody>
    % if len(tasks[Entity])==0:
        <tr> 
            <td colspan="2" style="text-align:center;">
                <i>Il n'y a pas de tâches dans ce pôle</i>
            </td>
        </tr>
    % endif
    % for task in tasks[Entity]:
        <tr> 
            <td>
                % if task.closed:
                    <a href="/${year}/Staff/tasks/${task.uid}">
                        <span class="name" style="text-decoration: line-through;">${task.name}</span>
                    </a>
                % else:
                    <a href="/${year}/Staff/tasks/${task.uid}">
                        <span class="name">${task.name}</span>
                    </a>
                    <span style="float:right;">
                    - <a href="/user/${task.assignee.slug}">${task.assignee.pseudo or ' '.join([task.assignee.prenom, task.assignee.nom]) }</a>
                    - ${task.due_date.strftime("%d %b")}
                    </span>
                % endif
            </td>
            <td style="position: relative;width:70px;">
                <div class="actions">
                % if task.closed:
                [ <a href="/${year}/Staff/open/${task.uid}">r&eacute;-ouvrir</a> ]
                % else:
                [ <a href="/${year}/Staff/close/${task.uid}">c'est fait</a> ]
                % endif
                </div>
            </td>
        </tr>
        % if task.description and not task.closed:
        <tr>
            <td colspan="2"><div>${task.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, "", "/${year}/Staff" + $(e.target).attr('href') );
            location.hash = $(e.target).attr('href');
        }); 
    
    if (location.hash !== '') {
        $('a[href="' + location.hash + '"]').tab('show');
    }
</script>
</%def>
