Jarvis/jarvis/objective/templates/trainingprograms/details.html

108 lines
4.8 KiB
HTML

{% extends "base.html" %}
{% load has_group %}
{% block page_title %}Training Program{% endblock %}
{% block content %}
<div class="row justify-content-center">
<div class="col-12 col-sm-12 col-md-8 col-lg-8 col-xl-6">
<div class="card">
<div class="card-body">
{% if trainingprogram_list %}
<table class="table table-striped tablesorter" id="trainingprogram_table">
<thead>
<tr>
<th colspan="5" class="text-center">{% if gymnast %}{{ gymnast }} - {% endif %}{{ date|date:"l j F Y" }}</th>
</tr>
</thead>
<tbody>
{% for trainingprogram in trainingprogram_list %}
<tr role="row" class="{% cycle 'odd' 'even' %}">
<td><b>{{ trainingprogram.rank }}</b></td>
<td class="text-center"><a href="{% url 'passe_details' trainingprogram.passe.id gymnast.id date %}">{{ trainingprogram.passe.label }}</a>{% if trainingprogram.repetition != 1 %}&nbsp;&nbsp;&nbsp;{{ trainingprogram.repetition }}{% endif %}</td>
<td class="text-center">{{ trainingprogram.number_of_skill}}</td>
<td class="text-center">{{ trainingprogram.difficulty }}</td>
{% if request.user|has_group:"trainer" %}
<td class="text-center p-2">
<a href="#" class="up" data-tp_id="{{ trainingprogram.id }}" data-rank="{{ trainingprogram.rank }}">
<button type="submit" value="" class="btn btn-icon btn-warning mr-2">
<i class="fas fa-chevron-up"></i>
</button>
</a>
<a href="#" class="down" data-tp_id="{{ trainingprogram.id }}" data-rank="{{ trainingprogram.rank }}">
<button type="submit" value="add" class="btn btn-icon btn-warning mr-2">
<i class="fas fa-chevron-down"></i>
</button>
</a>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
<tr>
<td colspan="2" class="text-right"><b>TOTAL</b></td>
<td class="text-center"><b>{{ number_of_skill }}</b></td>
<td class="text-center"><b>{{ difficulty }}</b></td>
{% if request.user|has_group:"trainer" %}
<td></td>
{% endif %}
</tr>
</table>
{% endif %}
</div>
</div>
</div>
</div>
{% endblock %}
{% block footerscript %}
<script type="text/javascript">
$(document).ready(function(){
$(".up,.down").click(function(){
var row = $(this).parents("tr:first");
var first_td = row.find("td:first");
saved_rank = first_td.text(); // jusque là, ca marche !
// alert("Rank : " + saved_rank);
if ($(this).is(".up")) {
$.ajax({
url: "{% url 'switch_trainingprogram_line' %}",
method: "POST",
data: {
tpid: $(this).data('tp_id'),
direction: 0,
csrfmiddlewaretoken: '{{ csrf_token }}'
},
}).done(function() {
var previous_td = row.prev().find('td:first');
saved_previous_rank = previous_td.text();
first_td.html("<b>" + String(saved_previous_rank) + "</b>");
previous_td.html("<b>" + String(saved_rank) + "</b>");
row.insertBefore(row.prev());
});
} else {
$.ajax({
url: "{% url 'switch_trainingprogram_line' %}",
method: "POST",
data: {
tpid: $(this).data('tp_id'),
direction: 1,
csrfmiddlewaretoken: '{{ csrf_token }}'
},
}).done(function() {
var next = row.next().find('td:first');
saved_next_rank = previous_td.text();
first_td.html("<b>" + String(saved_next_rank) + "</b>");
next.html("<b>" + String(saved_rank) + "</b>");
row.insertAfter(row.next());
});
}
});
});
</script>
{% endblock %}