régler problème avec le bouton pour sauvegarder les dispo
This commit is contained in:
+22
-17
@@ -407,9 +407,18 @@ def add_disponibility():
|
|||||||
@users_bp.route('/disponibilities/add_bulk', methods=['POST'])
|
@users_bp.route('/disponibilities/add_bulk', methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def add_disponibilities_bulk():
|
def add_disponibilities_bulk():
|
||||||
"""Add multiple disponibility blocks at once."""
|
"""Replace the player's disponibilities with the submitted slots.
|
||||||
|
|
||||||
|
Performs a full replace (delete existing + insert submitted) so that
|
||||||
|
deselected slots are correctly removed, mirroring the coach availability
|
||||||
|
flow. This keeps the auto-save idempotent and correct.
|
||||||
|
"""
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
slots = data.get('slots', [])
|
slots = data.get('slots', []) if data else []
|
||||||
|
|
||||||
|
# Clear existing disponibilities for the current player.
|
||||||
|
PlayerDisponibility.query.filter_by(player_id=current_user.id).delete()
|
||||||
|
|
||||||
created = []
|
created = []
|
||||||
for slot in slots:
|
for slot in slots:
|
||||||
day_of_week = slot.get('day_of_week')
|
day_of_week = slot.get('day_of_week')
|
||||||
@@ -422,21 +431,17 @@ def add_disponibilities_bulk():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
end_time = add_30_minutes(start_time)
|
end_time = add_30_minutes(start_time)
|
||||||
existing = PlayerDisponibility.query.filter_by(
|
disponibility = PlayerDisponibility(
|
||||||
player_id=current_user.id, day_of_week=day_of_week, start_time=start_time,
|
player_id=current_user.id, day_of_week=day_of_week,
|
||||||
).first()
|
start_time=start_time, end_time=end_time,
|
||||||
if not existing:
|
)
|
||||||
disponibility = PlayerDisponibility(
|
db.session.add(disponibility)
|
||||||
player_id=current_user.id, day_of_week=day_of_week,
|
db.session.flush()
|
||||||
start_time=start_time, end_time=end_time,
|
created.append({
|
||||||
)
|
'id': disponibility.id, 'day_of_week': disponibility.day_of_week,
|
||||||
db.session.add(disponibility)
|
'day_name': DAY_NAMES[disponibility.day_of_week],
|
||||||
db.session.flush()
|
'start_time': disponibility.start_time.strftime('%H:%M'),
|
||||||
created.append({
|
})
|
||||||
'id': disponibility.id, 'day_of_week': disponibility.day_of_week,
|
|
||||||
'day_name': DAY_NAMES[disponibility.day_of_week],
|
|
||||||
'start_time': disponibility.start_time.strftime('%H:%M'),
|
|
||||||
})
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return jsonify({'success': True, 'created': created})
|
return jsonify({'success': True, 'created': created})
|
||||||
|
|
||||||
|
|||||||
@@ -193,9 +193,6 @@
|
|||||||
<p class="text-muted">Loading...</p>
|
<p class="text-muted">Loading...</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button type="button" class="btn btn-primary" onclick="saveDisponibilities()">
|
|
||||||
<i class="fas fa-save"></i> Save Disponibilities
|
|
||||||
</button>
|
|
||||||
<button type="button" class="btn btn-secondary" onclick="clearDisponibilities()">
|
<button type="button" class="btn btn-secondary" onclick="clearDisponibilities()">
|
||||||
<i class="fas fa-trash"></i> Clear All
|
<i class="fas fa-trash"></i> Clear All
|
||||||
</button>
|
</button>
|
||||||
@@ -369,7 +366,7 @@ function saveCoachAvailability() {
|
|||||||
const msg = document.createElement('div');
|
const msg = document.createElement('div');
|
||||||
msg.className = 'alert alert-success';
|
msg.className = 'alert alert-success';
|
||||||
msg.style.marginTop = '10px';
|
msg.style.marginTop = '10px';
|
||||||
msg.innerHTML = '<i class="fas fa-check"></i> Availability saved!';
|
msg.innerHTML = '<span><i class="fas fa-check"></i> Availability saved!</span>';
|
||||||
document.getElementById('availability-grid').appendChild(msg);
|
document.getElementById('availability-grid').appendChild(msg);
|
||||||
setTimeout(() => msg.remove(), 3000);
|
setTimeout(() => msg.remove(), 3000);
|
||||||
}
|
}
|
||||||
@@ -571,7 +568,7 @@ function saveDisponibilities() {
|
|||||||
var msg = document.createElement('div');
|
var msg = document.createElement('div');
|
||||||
msg.className = 'alert alert-success';
|
msg.className = 'alert alert-success';
|
||||||
msg.style.marginTop = '10px';
|
msg.style.marginTop = '10px';
|
||||||
msg.innerHTML = '<i class="fas fa-check"></i> Disponibilities saved successfully!';
|
msg.innerHTML = '<span><i class="fas fa-check"></i> Disponibilities saved successfully!</span>';
|
||||||
document.getElementById('disponibilities-grid').appendChild(msg);
|
document.getElementById('disponibilities-grid').appendChild(msg);
|
||||||
setTimeout(function() { msg.remove(); }, 3000);
|
setTimeout(function() { msg.remove(); }, 3000);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user