mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-08-12 00:49:35 +02:00
Visual improvement on manage page
This commit is contained in:
@@ -57,7 +57,6 @@ function addChallenge (id, name, amount) {
|
|||||||
/** Ajout de 1 à chaque clic d'un bouton déjà choisi */
|
/** Ajout de 1 à chaque clic d'un bouton déjà choisi */
|
||||||
buttons.forEach(function (b) {
|
buttons.forEach(function (b) {
|
||||||
if (b.id === id) {
|
if (b.id === id) {
|
||||||
b.quantity += 1
|
|
||||||
challenge = b
|
challenge = b
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -65,8 +64,6 @@ function addChallenge (id, name, amount) {
|
|||||||
challenge = {
|
challenge = {
|
||||||
id: id,
|
id: id,
|
||||||
name: name,
|
name: name,
|
||||||
quantity: 1,
|
|
||||||
amount: amount,
|
|
||||||
}
|
}
|
||||||
buttons.push(challenge)
|
buttons.push(challenge)
|
||||||
}
|
}
|
||||||
@@ -76,8 +73,7 @@ function addChallenge (id, name, amount) {
|
|||||||
const list = 'consos_list'
|
const list = 'consos_list'
|
||||||
let html = ''
|
let html = ''
|
||||||
buttons.forEach(function (challenge) {
|
buttons.forEach(function (challenge) {
|
||||||
html += li('conso_button_' + challenge.id, challenge.name +
|
html += li('conso_button_' + challenge.id, challenge.name)
|
||||||
'<span class="badge badge-dark badge-pill">' + challenge.quantity + '</span>')
|
|
||||||
})
|
})
|
||||||
document.getElementById(list).innerHTML = html
|
document.getElementById(list).innerHTML = html
|
||||||
|
|
||||||
@@ -94,7 +90,6 @@ function addChallenge (id, name, amount) {
|
|||||||
* Reset the page as its initial state.
|
* Reset the page as its initial state.
|
||||||
*/
|
*/
|
||||||
function reset () {
|
function reset () {
|
||||||
console.log("reset lancée")
|
|
||||||
notes_display.length = 0
|
notes_display.length = 0
|
||||||
notes.length = 0
|
notes.length = 0
|
||||||
buttons.length = 0
|
buttons.length = 0
|
||||||
@@ -113,7 +108,6 @@ function reset () {
|
|||||||
* Apply all transactions: all notes in `notes` buy each item in `buttons`
|
* Apply all transactions: all notes in `notes` buy each item in `buttons`
|
||||||
*/
|
*/
|
||||||
function consumeAll () {
|
function consumeAll () {
|
||||||
console.log("test");
|
|
||||||
if (LOCK) { return }
|
if (LOCK) { return }
|
||||||
LOCK = true
|
LOCK = true
|
||||||
|
|
||||||
@@ -131,13 +125,10 @@ function consumeAll () {
|
|||||||
LOCK = false
|
LOCK = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log("couocu")
|
|
||||||
// Récupérer les IDs des familles et des challenges
|
// Récupérer les IDs des familles et des challenges
|
||||||
const family_ids = notes_display.map(fam => fam.id)
|
const family_ids = notes_display.map(fam => fam.id)
|
||||||
const challenge_ids = buttons.map(chal => chal.id)
|
const challenge_ids = buttons.map(chal => chal.id)
|
||||||
|
|
||||||
console.log(family_ids)
|
|
||||||
console.log(challenge_ids)
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/family/api/family/achievements/batch/',
|
url: '/family/api/family/achievements/batch/',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
@@ -318,7 +309,6 @@ function autoCompleteFamily(field_id, family_list_id, families, families_display
|
|||||||
var disp = null
|
var disp = null
|
||||||
families_display.forEach(function (d) {
|
families_display.forEach(function (d) {
|
||||||
if (d.id === family.id) {
|
if (d.id === family.id) {
|
||||||
d.quantity += 1
|
|
||||||
disp = d
|
disp = d
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -327,7 +317,6 @@ function autoCompleteFamily(field_id, family_list_id, families, families_display
|
|||||||
name: family.name,
|
name: family.name,
|
||||||
id: family.id,
|
id: family.id,
|
||||||
family: family,
|
family: family,
|
||||||
quantity: 1
|
|
||||||
}
|
}
|
||||||
families_display.push(disp)
|
families_display.push(disp)
|
||||||
}
|
}
|
||||||
@@ -338,9 +327,7 @@ function autoCompleteFamily(field_id, family_list_id, families, families_display
|
|||||||
let html = ''
|
let html = ''
|
||||||
families_display.forEach(function (disp) {
|
families_display.forEach(function (disp) {
|
||||||
html += li(family_prefix + '_' + disp.id,
|
html += li(family_prefix + '_' + disp.id,
|
||||||
disp.name +
|
disp.name,
|
||||||
'<span class="badge badge-dark badge-pill">' +
|
|
||||||
disp.quantity + '</span>',
|
|
||||||
'')
|
'')
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -398,12 +385,6 @@ function removeFamily(d, family_prefix, families_display, family_list_id, user_f
|
|||||||
const new_families_display = []
|
const new_families_display = []
|
||||||
let html = ''
|
let html = ''
|
||||||
families_display.forEach(function (disp) {
|
families_display.forEach(function (disp) {
|
||||||
if (disp.quantity > 1 || disp.id !== d.id) {
|
|
||||||
disp.quantity -= disp.id === d.id ? 1 : 0
|
|
||||||
new_families_display.push(disp)
|
|
||||||
html += li(family_prefix + '_' + disp.id, disp.name +
|
|
||||||
'<span class="badge badge-dark badge-pill">' + disp.quantity + '</span>')
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
families_display.length = 0
|
families_display.length = 0
|
||||||
|
@@ -5,14 +5,13 @@ import django_tables2 as tables
|
|||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django_tables2 import A
|
from django_tables2 import A
|
||||||
|
|
||||||
from django.urls import reverse, reverse_lazy
|
from django.urls import reverse, reverse_lazy
|
||||||
|
|
||||||
from note_kfet.middlewares import get_current_request
|
from note_kfet.middlewares import get_current_request
|
||||||
from permission.backends import PermissionBackend
|
from permission.backends import PermissionBackend
|
||||||
|
|
||||||
from .models import Achievement, Challenge, Family, FamilyMembership
|
from .models import Achievement, Challenge, Family, FamilyMembership
|
||||||
|
|
||||||
|
|
||||||
class FamilyTable(tables.Table):
|
class FamilyTable(tables.Table):
|
||||||
"""
|
"""
|
||||||
List all families
|
List all families
|
||||||
|
@@ -52,7 +52,12 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
</div>
|
</div>
|
||||||
{# User search with autocompletion #}
|
{# User search with autocompletion #}
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<input class="form-control mx-auto d-block" placeholder="{% trans "Name" %}" type="text" id="note" autofocus />
|
<input class="form-control mx-auto d-block mb-2" placeholder="{% trans "Name" %}" type="text" id="note" autofocus />
|
||||||
|
{% if user_family %}
|
||||||
|
<button class="btn btn-sm btn-secondary btn-block" id="select_my_family">
|
||||||
|
{% trans "Select my family" %} ({{ user_family.name }})
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -210,6 +215,55 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
document.getElementById("consume_all").addEventListener("click", function () {
|
document.getElementById("consume_all").addEventListener("click", function () {
|
||||||
$('#validationModal').modal('show');
|
$('#validationModal').modal('show');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
{% if user_family %}
|
||||||
|
document.getElementById("select_my_family").addEventListener("click", function () {
|
||||||
|
// Simulate selecting the user's family
|
||||||
|
var userFamily = {
|
||||||
|
id: {{ user_family.id }},
|
||||||
|
name: "{{ user_family.name|escapejs }}",
|
||||||
|
display_image: "{{ user_family.display_image.url|default:'/static/member/img/default_picture.png'|escapejs }}"
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if family is already selected
|
||||||
|
var alreadySelected = false;
|
||||||
|
notes_display.forEach(function (d) {
|
||||||
|
if (d.id === userFamily.id) {
|
||||||
|
alreadySelected = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!alreadySelected) {
|
||||||
|
// Add the family to the selected families
|
||||||
|
var disp = {
|
||||||
|
name: userFamily.name,
|
||||||
|
id: userFamily.id,
|
||||||
|
family: userFamily,
|
||||||
|
};
|
||||||
|
notes_display.push(disp);
|
||||||
|
|
||||||
|
// Update the display
|
||||||
|
const family_list = $('#note_list');
|
||||||
|
let html = '';
|
||||||
|
notes_display.forEach(function (disp) {
|
||||||
|
html += li('note_' + disp.id, disp.name, '');
|
||||||
|
});
|
||||||
|
|
||||||
|
family_list.html(html);
|
||||||
|
|
||||||
|
// Add click handlers for removal
|
||||||
|
notes_display.forEach(function (disp) {
|
||||||
|
const line_obj = $('#note_' + disp.id);
|
||||||
|
line_obj.hover(function () {
|
||||||
|
displayFamily(disp.family, disp.name, 'user_note', 'profile_pic');
|
||||||
|
});
|
||||||
|
line_obj.click(removeFamily(disp, 'note', notes_display, 'note_list', 'user_note', 'profile_pic'));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Display the family info
|
||||||
|
displayFamily(userFamily, userFamily.name, 'user_note', 'profile_pic');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
{% endif %}
|
||||||
</script>
|
</script>
|
||||||
</script>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
@@ -301,6 +301,13 @@ class FamilyManageView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView
|
|||||||
context["can_add_family"] = PermissionBackend.check_perm(self.request, "family.family_create")
|
context["can_add_family"] = PermissionBackend.check_perm(self.request, "family.family_create")
|
||||||
context["can_add_challenge"] = PermissionBackend.check_perm(self.request, "family.challenge_create")
|
context["can_add_challenge"] = PermissionBackend.check_perm(self.request, "family.challenge_create")
|
||||||
|
|
||||||
|
# Get the user's family if they have one
|
||||||
|
try:
|
||||||
|
user_family_membership = FamilyMembership.objects.get(user=self.request.user)
|
||||||
|
context["user_family"] = user_family_membership.family
|
||||||
|
except FamilyMembership.DoesNotExist:
|
||||||
|
context["user_family"] = None
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_table(self, **kwargs):
|
def get_table(self, **kwargs):
|
||||||
|
Reference in New Issue
Block a user