diff --git a/participate.py b/participate.py index 001be88..8c01d1b 100755 --- a/participate.py +++ b/participate.py @@ -334,6 +334,19 @@ def delete_user(user_id): print "------------------------------" return False +def get_user_name(user_id): + """ Get pseudo from user ID """ + try: + user = Tetawebapp_users.query.filter_by(id=int(user_id)).first() + return user.name + except Exception as e: + print "[+] Error at get_pseudo:" + print "------------------------------" + print "%s" % e.message + print "------------------------------" + return False + + def save_turn(role_id, day, start, end, num_slot): """ Save a new turn """ days = ['2018-05-08', '2018-05-09', '2018-05-10', '2018-05-11', '2018-05-12', '2018-05-13', '2018-05-14'] @@ -1117,16 +1130,9 @@ def clear_staff_slot(TURN_ID, SLOT_ID): turn_id = int(TURN_ID.encode('utf-8')) slot_id = int(SLOT_ID.encode('utf-8')) user_id = session['user_id'] - message = "Erreur lors de l'enregistrement des données" if (drop_staff_slot(turn_id, slot_id, user_id)): - message = '' - page = str(request.url_rule) - menu = get_menu(page) - turns = turns_list() - staffs = get_staffs() - roles = get_roles() - user_id = session['user_id'] - return render_template('staffsheet.html', menu=menu, turns=turns, staffs=staffs, user_id=user_id, roles=roles, message=message.decode('utf-8')) + return " " + return "Erreur" except AttributeError: # User is not logged in return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide") @@ -1141,16 +1147,11 @@ def update_staff_slot(TURN_ID, SLOT_ID): turn_id = int(TURN_ID.encode('utf-8')) slot_id = int(SLOT_ID.encode('utf-8')) user_id = session['user_id'] - message = "Erreur lors de l'enregistrement des données" - if (save_staff_slot(turn_id, slot_id, user_id)): - message = '' - page = str(request.url_rule) - menu = get_menu(page) - turns = turns_list() - staffs = get_staffs() - roles = get_roles() - user_id = session['user_id'] - return render_template('staffsheet.html', menu=menu, turns=turns, staffs=staffs, user_id=user_id, roles=roles, message=message.decode('utf-8')) + user_name = get_user_name(user_id) + if user_name != None: + if (save_staff_slot(turn_id, slot_id, user_id)): + return user_name + return "Erreur" except AttributeError as e: # User is not logged in print e diff --git a/static/scripts/participate.js b/static/scripts/participate.js index c4af181..b4c11d9 100644 --- a/static/scripts/participate.js +++ b/static/scripts/participate.js @@ -60,14 +60,18 @@ function save_turn() { } } -function update_sheet(turn, slot) { - document.location = '/staffsheet/update/'+turn+'/'+slot; +function update_sheet(obj, turn, slot) { + var url = '/staffsheet/update/'+turn+'/'+slot; + get_html_from_ajax(obj, url); + obj.onclick=function (){ return clear_sheet(obj, turn, slot);} return true; } -function clear_sheet(turn, slot) { +function clear_sheet(obj, turn, slot) { if (confirm("Voulez-vous vraiment libérer ce créneau ? \n\n Confirmer ?")) { - document.location = '/staffsheet/clear/'+turn+'/'+slot; + var url = '/staffsheet/clear/'+turn+'/'+slot; + get_html_from_ajax(obj, url); + obj.onclick=function (){ return update_sheet(obj, turn, slot);} } return false; } diff --git a/templates/staffsheet.html b/templates/staffsheet.html index 74ca3b6..ca064c5 100644 --- a/templates/staffsheet.html +++ b/templates/staffsheet.html @@ -67,14 +67,14 @@ {% if allocated_slot.append(sslot[0].slot_num) %} {% endif %} {% if user_id == sslot[0].user_id %} -
{{ sslot[1] }}
+
{{ sslot[1] }}
{% else %} -
{{ sslot[1] }}
+
{{ sslot[1] }}
{% endif %} {% endif %} {% endfor %} {% if slot not in allocated_slot %} -
 
+
 
{% endif %} {% endfor %}