SuiteConsultance/Templates/tasks/macros.html
2025-09-20 13:18:04 +02:00

413 lines
19 KiB
HTML

{# Macros de rendu pour les tâches #}
{% macro priority_badge(priority) -%}
{% set classes = {
'haute': 'background:#ffe5e5;color:#b30000;padding:.15rem .4rem;border-radius:.3rem;font-size:.8rem;',
'normale': 'background:#e8f1ff;color:#003a8c;padding:.15rem .4rem;border-radius:.3rem;font-size:.8rem;',
'basse': 'background:#e9f7ef;color:#1b5e20;padding:.15rem .4rem;border-radius:.3rem;font-size:.8rem;'
} %}
<span style="{{ classes.get(priority, classes['normale']) }}">{{ priority|capitalize }}</span>
{%- endmacro %}
{% macro status_badge(status) -%}
{% set classes = {
'todo': 'background:#fff3cd;color:#8a6d3b;padding:.15rem .4rem;border-radius:.3rem;font-size:.8rem;',
'done': 'background:#e6ffed;color:#155724;padding:.15rem .4rem;border-radius:.3rem;font-size:.8rem;',
'canceled': 'background:#f8d7da;color:#721c24;padding:.15rem .4rem;border-radius:.3rem;font-size:.8rem;'
} %}
{% set labels = {'todo': 'À faire', 'done': 'Fait', 'canceled': 'Annulée'} %}
<span style="{{ classes.get(status, classes['todo']) }}">{{ labels.get(status, status) }}</span>
{%- endmacro %}
{# Macros de rendu pour les tâches #}
{% macro priority_badge(priority) -%}
{% set classes = {
'haute': 'background:#ffe5e5;color:#b30000;padding:.15rem .4rem;border-radius:.3rem;font-size:.8rem;',
'normale': 'background:#e8f1ff;color:#003a8c;padding:.15rem .4rem;border-radius:.3rem;font-size:.8rem;',
'basse': 'background:#e9f7ef;color:#1b5e20;padding:.15rem .4rem;border-radius:.3rem;font-size:.8rem;'
} %}
<span style="{{ classes.get(priority, classes['normale']) }}">{{ priority|capitalize }}</span>
{%- endmacro %}
{% macro status_badge(status) -%}
{% set classes = {
'todo': 'background:#fff3cd;color:#8a6d3b;padding:.15rem .4rem;border-radius:.3rem;font-size:.8rem;',
'done': 'background:#e6ffed;color:#155724;padding:.15rem .4rem;border-radius:.3rem;font-size:.8rem;',
'canceled': 'background:#f8d7da;color:#721c24;padding:.15rem .4rem;border-radius:.3rem;font-size:.8rem;'
} %}
{% set labels = {'todo': 'À faire', 'done': 'Fait', 'canceled': 'Annulée'} %}
<span style="{{ classes.get(status, classes['todo']) }}">{{ labels.get(status, status) }}</span>
{%- endmacro %}
{% macro entity_badge(entity_type) -%}
{% if entity_type %}
{% set labels = {'client': 'Client', 'prospect': 'Prospect', 'project': 'Projet', 'campaign': 'Campagne'} %}
<span style="background:#f0f0f0;color:#333;padding:.15rem .4rem;border-radius:.3rem;font-size:.75rem;">
{{ labels.get(entity_type, entity_type|capitalize) }}
</span>
{% endif %}
{%- endmacro %}
{% macro render_task_row(task, show_entity=True, show_due_date=True) -%}
<tr style="border-bottom:1px solid #eee;">
<td style="white-space:nowrap;padding:.5rem .4rem;">
{{ status_badge(task.status) }}
</td>
<td style="padding:.5rem .4rem;">
<div style="font-weight:600;">{{ task.title }}</div>
{% if task.description %}
<div style="font-size:.9rem;color:#666;">{{ task.description }}</div>
{% endif %}
{% if task.metadata and task.metadata.ref %}
<div style="font-size:.85rem;color:#999;">Ref: {{ task.metadata.ref }}</div>
{% endif %}
</td>
{% if show_entity %}
<td style="white-space:nowrap;padding:.5rem .4rem;">
{{ entity_badge(task.entity_type) }}
{% if task.entity_id %}
<small style="color:#888;display:block;">{{ task.entity_id }}</small>
{% endif %}
</td>
{% endif %}
{% if show_due_date %}
<td style="white-space:nowrap;padding:.5rem .4rem;">
<span style="color:#333;">{{ task.due_date }}</span>
{% if task.completed_at and task.status == 'done' %}
<div style="font-size:.8rem;color:#6c757d;">Clôturée: {{ task.completed_at }}</div>
{% endif %}
</td>
{% endif %}
<td style="white-space:nowrap;text-align:right;padding:.5rem .4rem;">
{{ priority_badge(task.priority) }}
</td>
</tr>
{%- endmacro %}
{# Macros de rendu pour les tâches #}
{% macro priority_badge(priority) -%}
{% set cls = {'haute':'bg-danger','normale':'bg-primary','basse':'bg-success'} %}
<span class="badge {{ cls.get(priority, 'bg-primary') }}">{{ priority|capitalize }}</span>
{%- endmacro %}
{% macro status_badge(status) -%}
{% set cls = {'todo':'bg-warning text-dark','done':'bg-success','canceled':'bg-danger'} %}
{% set labels = {'todo': 'À faire', 'done': 'Fait', 'canceled': 'Annulée'} %}
<span class="badge {{ cls.get(status, 'bg-secondary') }}">{{ labels.get(status, status) }}</span>
{%- endmacro %}
{% macro entity_badge(entity_type) -%}
{% if entity_type %}
{% set labels = {'client': 'Client', 'prospect': 'Prospect', 'project': 'Projet', 'campaign': 'Campagne'} %}
<span class="badge bg-secondary-subtle text-dark">{{ labels.get(entity_type, entity_type|capitalize) }}</span>
{% endif %}
{%- endmacro %}
{% macro render_task_row(task, show_entity=True, show_due_date=True, show_actions=False) -%}
<tr>
<td class="text-nowrap">
{{ status_badge(task.status) }}
</td>
<td>
<div class="fw-semibold">{{ task.title }}</div>
{% if task.description %}
<div class="small text-muted">{{ task.description }}</div>
{% endif %}
{% if task.metadata and task.metadata.ref %}
<div class="small text-secondary">Ref: {{ task.metadata.ref }}</div>
{% endif %}
</td>
{% if show_entity %}
<td class="text-nowrap">
{{ entity_badge(task.entity_type) }}
{% if task.entity_id %}
<div class="small text-muted">{{ task.entity_id }}</div>
{% endif %}
</td>
{% endif %}
{% if show_due_date %}
<td class="text-nowrap">
<span>{{ task.due_date }}</span>
{% if task.completed_at and task.status == 'done' %}
<div class="small text-muted">Clôturée: {{ task.completed_at }}</div>
{% endif %}
</td>
{% endif %}
<td class="text-nowrap text-end">
{{ priority_badge(task.priority) }}
</td>
{% if show_actions %}
<td class="text-nowrap text-end">
<div class="d-flex gap-1 justify-content-end">
<button type="button"
class="btn btn-sm btn-outline-secondary btn-edit-task"
data-bs-toggle="modal"
data-bs-target="#editTaskModal"
data-id="{{ task.id }}"
data-title="{{ task.title }}"
data-due_date="{{ task.due_date }}"
data-priority="{{ task.priority }}"
data-description="{{ task.description or '' }}"
data-entity_type="{{ task.entity_type or '' }}"
data-entity_id="{{ task.entity_id or '' }}"
title="Éditer">
<i class="fas fa-pen"></i>
</button>
<div class="btn-group">
<button type="button" class="btn btn-sm btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" title="Changer le statut">
<i class="fas fa-exchange-alt"></i>
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li>
<form method="post" action="{{ url_for('tasks.set_status') }}">
<input type="hidden" name="task_id" value="{{ task.id }}">
<input type="hidden" name="status" value="todo">
<button type="submit" class="dropdown-item {% if task.status=='todo' %}active{% endif %}">À faire</button>
</form>
</li>
<li>
<form method="post" action="{{ url_for('tasks.set_status') }}">
<input type="hidden" name="task_id" value="{{ task.id }}">
<input type="hidden" name="status" value="done">
<button type="submit" class="dropdown-item {% if task.status=='done' %}active{% endif %}">Fait</button>
</form>
</li>
<li>
<form method="post" action="{{ url_for('tasks.set_status') }}">
<input type="hidden" name="task_id" value="{{ task.id }}">
<input type="hidden" name="status" value="canceled">
<button type="submit" class="dropdown-item {% if task.status=='canceled' %}active{% endif %}">Annulée</button>
</form>
</li>
</ul>
</div>
<form method="post" action="{{ url_for('tasks.delete_task') }}" onsubmit="return confirm('Supprimer cette tâche ?');">
<input type="hidden" name="task_id" value="{{ task.id }}">
<button type="submit" class="btn btn-sm btn-outline-danger" title="Supprimer">
<i class="fas fa-trash"></i>
</button>
</form>
</div>
</td>
{% endif %}
</tr>
{%- endmacro %}
{% macro render_tasks_table(tasks, show_entity=True, show_due_date=True, empty_text="Aucune tâche", show_actions=False, today=None) -%}
<div class="table-responsive">
<table class="table table-hover align-middle">
{% set cols = 3 + (1 if show_entity else 0) + (1 if show_due_date else 0) + (1 if show_actions else 0) %}
<thead class="table-light">
<tr>
<th>Statut</th>
<th>Tâche</th>
{% if show_entity %}<th>Liée à</th>{% endif %}
{% if show_due_date %}<th>Échéance</th>{% endif %}
<th class="text-end">Priorité</th>
{% if show_actions %}<th class="text-end">Actions</th>{% endif %}
</tr>
</thead>
<tbody>
{% if tasks and tasks|length > 0 %}
{% for task in tasks %}
{{ render_task_row(task, show_entity=show_entity, show_due_date=show_due_date, show_actions=show_actions) }}
{% endfor %}
{% else %}
<tr>
<td colspan="{{ cols }}" class="text-muted"> {{ empty_text }} </td>
</tr>
{% endif %}
</tbody>
</table>
</div>
{%- endmacro %}
{% macro render_tasks_table(tasks, show_entity=True, show_due_date=True, empty_text="Aucune tâche", show_actions=False, today=None) -%}
<div style="overflow:auto;">
<table style="width:100%;border-collapse:collapse;">
{% set cols = 3 + (1 if show_entity else 0) + (1 if show_due_date else 0) + (1 if show_actions else 0) %}
<thead>
<tr style="text-align:left;border-bottom:1px solid #e5e5e5;">
<th style="padding:.6rem .4rem;">Statut</th>
<th style="padding:.6rem .4rem;">Tâche</th>
{% if show_entity %}<th style="padding:.6rem .4rem;">Liée à</th>{% endif %}
{% if show_due_date %}<th style="padding:.6rem .4rem;">Échéance</th>{% endif %}
<th style="padding:.6rem .4rem;text-align:right;">Priorité</th>
{% if show_actions %}<th style="padding:.6rem .4rem;text-align:right;">Actions</th>{% endif %}
</tr>
</thead>
<tbody>
{% if tasks and tasks|length > 0 %}
{% for task in tasks %}
<tr style="border-bottom:1px solid #e5e5e5;">
<td style="white-space:nowrap;padding:.5rem .4rem;">
{{ status_badge(task.status) }}
</td>
<td style="padding:.5rem .4rem;">
<div style="font-weight:600;">{{ task.title }}</div>
{% if task.description %}
<div style="font-size:.9rem;color:#666;">{{ task.description }}</div>
{% endif %}
{% if task.metadata and task.metadata.ref %}
<div style="font-size:.85rem;color:#999;">Ref: {{ task.metadata.ref }}</div>
{% endif %}
</td>
{% if show_entity %}
<td style="white-space:nowrap;padding:.5rem .4rem;">
{{ entity_badge(task.entity_type) }}
{% if task.entity_id %}
<small style="color:#888;display:block;">{{ task.entity_id }}</small>
{% endif %}
</td>
{% endif %}
{% if show_due_date %}
<td style="white-space:nowrap;padding:.5rem .4rem;">
<span style="color:#333;">{{ task.due_date }}</span>
{% if task.completed_at and task.status == 'done' %}
<div style="font-size:.8rem;color:#6c757d;">Clôturée: {{ task.completed_at }}</div>
{% endif %}
</td>
{% endif %}
<td style="white-space:nowrap;text-align:right;padding:.5rem .4rem;">
{{ priority_badge(task.priority) }}
</td>
{% if show_actions %}
<td style="white-space:nowrap;text-align:right;padding:.5rem .4rem;">
<div style="display:flex;gap:.35rem;justify-content:flex-end;">
<button type="button"
class="btn btn-sm btn-outline-secondary btn-edit-task"
data-bs-toggle="modal"
data-bs-target="#editTaskModal"
data-id="{{ task.id }}"
data-title="{{ task.title }}"
data-due_date="{{ task.due_date }}"
data-priority="{{ task.priority }}"
data-description="{{ task.description or '' }}"
data-entity_type="{{ task.entity_type or '' }}"
data-entity_id="{{ task.entity_id or '' }}"
title="Éditer">
<i class="fas fa-pen"></i>
</button>
<div class="btn-group">
<button type="button" class="btn btn-sm btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" title="Changer le statut">
<i class="fas fa-exchange-alt"></i>
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li>
<form method="post" action="{{ url_for('tasks.set_status') }}">
<input type="hidden" name="task_id" value="{{ task.id }}">
<input type="hidden" name="status" value="todo">
<button type="submit" class="dropdown-item {% if task.status=='todo' %}active{% endif %}">À faire</button>
</form>
</li>
<li>
<form method="post" action="{{ url_for('tasks.set_status') }}">
<input type="hidden" name="task_id" value="{{ task.id }}">
<input type="hidden" name="status" value="done">
<button type="submit" class="dropdown-item {% if task.status=='done' %}active{% endif %}">Fait</button>
</form>
</li>
<li>
<form method="post" action="{{ url_for('tasks.set_status') }}">
<input type="hidden" name="task_id" value="{{ task.id }}">
<input type="hidden" name="status" value="canceled">
<button type="submit" class="dropdown-item {% if task.status=='canceled' %}active{% endif %}">Annulée</button>
</form>
</li>
</ul>
</div>
<form method="post" action="{{ url_for('tasks.delete_task') }}" onsubmit="return confirm('Supprimer cette tâche ?');">
<input type="hidden" name="task_id" value="{{ task.id }}">
<button type="submit" class="btn btn-sm btn-outline-danger" title="Supprimer">
<i class="fas fa-trash"></i>
</button>
</form>
</div>
</td>
{% endif %}
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="{{ cols }}" style="padding:.8rem;color:#777;">
{{ empty_text }}
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
{%- endmacro %}
{% macro entity_badge(entity_type) -%}
{% if entity_type %}
{% set labels = {'client': 'Client', 'prospect': 'Prospect', 'project': 'Projet', 'campaign': 'Campagne'} %}
<span style="background:#f0f0f0;color:#333;padding:.15rem .4rem;border-radius:.3rem;font-size:.75rem;">
{{ labels.get(entity_type, entity_type|capitalize) }}
</span>
{% endif %}
{%- endmacro %}
{% macro render_task_row(task, show_entity=True, show_due_date=True) -%}
<tr>
<td style="white-space:nowrap;">
{{ status_badge(task.status) }}
</td>
<td>
<div style="font-weight:600;">{{ task.title }}</div>
{% if task.description %}
<div style="font-size:.9rem;color:#666;">{{ task.description }}</div>
{% endif %}
{% if task.metadata and task.metadata.ref %}
<div style="font-size:.85rem;color:#999;">Ref: {{ task.metadata.ref }}</div>
{% endif %}
</td>
{% if show_entity %}
<td style="white-space:nowrap;">
{{ entity_badge(task.entity_type) }}
{% if task.entity_id %}
<small style="color:#888;display:block;">{{ task.entity_id }}</small>
{% endif %}
</td>
{% endif %}
{% if show_due_date %}
<td style="white-space:nowrap;">
<span style="color:#333;">{{ task.due_date }}</span>
{% if task.completed_at and task.status == 'done' %}
<div style="font-size:.8rem;color:#6c757d;">Clôturée: {{ task.completed_at }}</div>
{% endif %}
</td>
{% endif %}
<td style="white-space:nowrap;text-align:right;">
{{ priority_badge(task.priority) }}
</td>
</tr>
{%- endmacro %}
{% macro render_tasks_table(tasks, show_entity=True, show_due_date=True, empty_text="Aucune tâche") -%}
<div style="overflow:auto;">
<table style="width:100%;border-collapse:collapse;">
<thead>
<tr style="text-align:left;border-bottom:1px solid #e5e5e5;">
<th style="padding:.6rem .4rem;">Statut</th>
<th style="padding:.6rem .4rem;">Tâche</th>
{% if show_entity %}<th style="padding:.6rem .4rem;">Liée à</th>{% endif %}
{% if show_due_date %}<th style="padding:.6rem .4rem;">Échéance</th>{% endif %}
<th style="padding:.6rem .4rem;text-align:right;">Priorité</th>
</tr>
</thead>
<tbody>
{% if tasks and tasks|length > 0 %}
{% for task in tasks %}
{{ render_task_row(task, show_entity=show_entity, show_due_date=show_due_date) }}
{% endfor %}
{% else %}
<tr>
<td colspan="{{ 3 + (1 if show_entity else 0) + (1 if show_due_date else 0) }}" style="padding:.8rem;color:#777;">
{{ empty_text }}
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
{%- endmacro %}