diff --git a/loko/interventions/templates/interventions/detail/right_column.html b/loko/interventions/templates/interventions/detail/right_column.html index c796cb2..5f2c598 100644 --- a/loko/interventions/templates/interventions/detail/right_column.html +++ b/loko/interventions/templates/interventions/detail/right_column.html @@ -485,6 +485,21 @@ border: 2px solid #fff; line-height: 1; } +#discussion-fab .fab-flag-badge { + position: absolute; + top: -4px; + left: -4px; + width: 22px; + height: 22px; + border-radius: 50%; + display: flex; + align-items: center; + justify-content: center; + font-size: .75rem; + border: 2px solid #fff; + color: #fff; + box-shadow: 0 2px 4px rgba(0,0,0,.2); +} #discussion-panel { position: fixed; bottom: 92px; @@ -541,6 +556,11 @@ {% if discussion_messages %} {{ discussion_messages|length }} {% endif %} + + +
diff --git a/loko/interventions/templates/interventions/detail/scripts.html b/loko/interventions/templates/interventions/detail/scripts.html index 15d5895..dea2fb7 100644 --- a/loko/interventions/templates/interventions/detail/scripts.html +++ b/loko/interventions/templates/interventions/detail/scripts.html @@ -1020,6 +1020,74 @@ document.addEventListener('DOMContentLoaded', function () { })(); // ---- fin @mention autocomplete ---- +// ---- Changement de drapeau de la discussion ---- +{% if discussion %} +(function() { + document.querySelectorAll('.intervention-flag-opt').forEach(btn => { + btn.addEventListener('click', function() { + const flag = this.getAttribute('data-flag'); + const url = "{% url 'notifications:discussion_set_flag' discussion.pk %}"; + const formData = new FormData(); + formData.append('flag', flag); + formData.append('csrfmiddlewaretoken', '{{ csrf_token }}'); + + fetch(url, { + method: 'POST', + headers: { + 'X-Requested-With': 'XMLHttpRequest' + }, + body: formData + }) + .then(res => res.json()) + .then(data => { + if (data.ok) { + const fabFlagBadge = document.getElementById('discussion-fab-flag-badge'); + const headerIcon = document.getElementById('intervention-flag-icon-display'); + const headerLabel = document.getElementById('intervention-flag-label-display'); + + if (data.flag) { + if (fabFlagBadge) { + fabFlagBadge.classList.remove('d-none'); + fabFlagBadge.style.backgroundColor = data.flag_info.color; + fabFlagBadge.title = data.flag_info.label; + fabFlagBadge.innerHTML = ``; + } + } else { + if (fabFlagBadge) { + fabFlagBadge.classList.add('d-none'); + } + } + + if (headerIcon) { + if (data.flag === 'red') headerIcon.textContent = '🚩'; + else if (data.flag === 'orange') headerIcon.textContent = '🟧'; + else if (data.flag === 'green') headerIcon.textContent = '🟩'; + else headerIcon.textContent = '🏳️'; + } + if (headerLabel) { + headerLabel.textContent = data.flag_info.label || '{% translate "Statut" %}'; + } + + if (data.system_message) { + const thread = document.getElementById('discussion-thread'); + if (thread) { + const sysDiv = document.createElement('div'); + sysDiv.className = 'd-flex justify-content-center my-1'; + sysDiv.innerHTML = ` + ${data.system_message.content} + `; + thread.appendChild(sysDiv); + thread.scrollTop = thread.scrollHeight; + } + } + } + }) + .catch(err => console.error('Error changing discussion flag:', err)); + }); + }); +})(); +{% endif %} + function toggleSubscription(interventionId) { const btn = document.getElementById('subscription-btn'); const icon = document.getElementById('subscription-icon'); diff --git a/loko/interventions/templates/interventions/intervention_detail_mobile.html b/loko/interventions/templates/interventions/intervention_detail_mobile.html index 6c34475..c6d8c66 100644 --- a/loko/interventions/templates/interventions/intervention_detail_mobile.html +++ b/loko/interventions/templates/interventions/intervention_detail_mobile.html @@ -342,6 +342,21 @@ border: 2px solid #fff; line-height: 1; } + #discussion-mob-fab .mob-fab-flag-badge { + position: absolute; + top: -3px; + left: -3px; + width: 20px; + height: 20px; + border-radius: 50%; + display: flex; + align-items: center; + justify-content: center; + font-size: .7rem; + border: 2px solid #fff; + color: #fff; + box-shadow: 0 2px 4px rgba(0,0,0,.2); + } #discussion-mob-panel { position: fixed; top: 10.5rem; @@ -2542,6 +2557,11 @@ {% if discussion_messages %} {{ discussion_messages|length }} {% endif %} + + +
@@ -6640,6 +6691,74 @@ document.addEventListener('DOMContentLoaded', function () {
setTimeout(() => { textarea.value = ''; realInput.value = ''; mentions = []; }, 0);
});
})();
+
+// ---- Changement de drapeau de la discussion (mobile) ----
+{% if discussion %}
+(function() {
+ document.querySelectorAll('.mob-flag-opt').forEach(btn => {
+ btn.addEventListener('click', function() {
+ const flag = this.getAttribute('data-flag');
+ const url = "{% url 'notifications:discussion_set_flag' discussion.pk %}";
+ const formData = new FormData();
+ formData.append('flag', flag);
+ formData.append('csrfmiddlewaretoken', '{{ csrf_token }}');
+
+ fetch(url, {
+ method: 'POST',
+ headers: {
+ 'X-Requested-With': 'XMLHttpRequest'
+ },
+ body: formData
+ })
+ .then(res => res.json())
+ .then(data => {
+ if (data.ok) {
+ const fabFlagBadge = document.getElementById('discussion-mob-flag-badge');
+ const headerIcon = document.getElementById('mob-flag-icon-display');
+ const headerLabel = document.getElementById('mob-flag-label-display');
+
+ if (data.flag) {
+ if (fabFlagBadge) {
+ fabFlagBadge.classList.remove('d-none');
+ fabFlagBadge.style.backgroundColor = data.flag_info.color;
+ fabFlagBadge.title = data.flag_info.label;
+ fabFlagBadge.innerHTML = ``;
+ }
+ } else {
+ if (fabFlagBadge) {
+ fabFlagBadge.classList.add('d-none');
+ }
+ }
+
+ if (headerIcon) {
+ if (data.flag === 'red') headerIcon.textContent = '🚩';
+ else if (data.flag === 'orange') headerIcon.textContent = '🟧';
+ else if (data.flag === 'green') headerIcon.textContent = '🟩';
+ else headerIcon.textContent = '🏳️';
+ }
+ if (headerLabel) {
+ headerLabel.textContent = data.flag_info.label || '{% translate "Statut" %}';
+ }
+
+ if (data.system_message) {
+ const thread = document.getElementById('discussion-mob-thread');
+ if (thread) {
+ const sysDiv = document.createElement('div');
+ sysDiv.className = 'd-flex justify-content-center my-1';
+ sysDiv.innerHTML = `
+ ${data.system_message.content}
+ `;
+ thread.appendChild(sysDiv);
+ thread.scrollTop = thread.scrollHeight;
+ }
+ }
+ }
+ })
+ .catch(err => console.error('Error changing mobile discussion flag:', err));
+ });
+ });
+})();
+{% endif %}
{% endblock %}
diff --git a/loko/notifications/templates/notifications/discussion_list.html b/loko/notifications/templates/notifications/discussion_list.html
index c46df05..b28ba8b 100644
--- a/loko/notifications/templates/notifications/discussion_list.html
+++ b/loko/notifications/templates/notifications/discussion_list.html
@@ -110,6 +110,12 @@
{{ item.discussion.title|default:item.discussion }}
+ {% if item.discussion.flag %}
+
+ {{ item.discussion.flag_info.label }}
+
+ {% endif %}
{% if item.discussion.object_label and item.discussion.object_label != item.discussion.title %}
{{ item.discussion.object_label }}
diff --git a/loko/notifications/templates/notifications/inbox.html b/loko/notifications/templates/notifications/inbox.html
index 3810cf9..4b5758d 100644
--- a/loko/notifications/templates/notifications/inbox.html
+++ b/loko/notifications/templates/notifications/inbox.html
@@ -359,6 +359,34 @@
role="tabpanel"
aria-labelledby="tab-discussions-btn">
+
+
@@ -2073,5 +2124,73 @@ document.addEventListener('DOMContentLoaded', function () {
}
});
})();
+
+// ---- Changement de drapeau de la discussion (bon de préparation) ----
+{% if discussion %}
+(function() {
+ document.querySelectorAll('.po-flag-opt').forEach(btn => {
+ btn.addEventListener('click', function() {
+ const flag = this.getAttribute('data-flag');
+ const url = "{% url 'notifications:discussion_set_flag' discussion.pk %}";
+ const formData = new FormData();
+ formData.append('flag', flag);
+ formData.append('csrfmiddlewaretoken', '{{ csrf_token }}');
+
+ fetch(url, {
+ method: 'POST',
+ headers: {
+ 'X-Requested-With': 'XMLHttpRequest'
+ },
+ body: formData
+ })
+ .then(res => res.json())
+ .then(data => {
+ if (data.ok) {
+ const fabFlagBadge = document.getElementById('discussion-fab-flag-badge');
+ const headerIcon = document.getElementById('po-flag-icon-display');
+ const headerLabel = document.getElementById('po-flag-label-display');
+
+ if (data.flag) {
+ if (fabFlagBadge) {
+ fabFlagBadge.classList.remove('d-none');
+ fabFlagBadge.style.backgroundColor = data.flag_info.color;
+ fabFlagBadge.title = data.flag_info.label;
+ fabFlagBadge.innerHTML = ``;
+ }
+ } else {
+ if (fabFlagBadge) {
+ fabFlagBadge.classList.add('d-none');
+ }
+ }
+
+ if (headerIcon) {
+ if (data.flag === 'red') headerIcon.textContent = '🚩';
+ else if (data.flag === 'orange') headerIcon.textContent = '🟧';
+ else if (data.flag === 'green') headerIcon.textContent = '🟩';
+ else headerIcon.textContent = '🏳️';
+ }
+ if (headerLabel) {
+ headerLabel.textContent = data.flag_info.label || '{% translate "Statut" %}';
+ }
+
+ if (data.system_message) {
+ const thread = document.getElementById('discussion-thread');
+ if (thread) {
+ const sysDiv = document.createElement('div');
+ sysDiv.className = 'd-flex justify-content-center my-1';
+ sysDiv.innerHTML = `
+ ${data.system_message.content}
+ `;
+ thread.appendChild(sysDiv);
+ thread.scrollTop = thread.scrollHeight;
+ }
+ }
+ }
+ })
+ .catch(err => console.error('Error changing preparation order discussion flag:', err));
+ });
+ });
+})();
+{% endif %}
{% endblock content %}
diff --git a/loko/stock/views.py b/loko/stock/views.py
index 8f6b063..f52764e 100644
--- a/loko/stock/views.py
+++ b/loko/stock/views.py
@@ -3923,6 +3923,7 @@ def preparation_order_detail(request, pk):
return_batches = preparation_order.stock_batches.filter(movement_type='in').order_by('date')
# Discussion liée à ce bon de préparation
+ discussion = None
discussion_messages = []
can_post_discussion_message = False
try:
@@ -3959,6 +3960,7 @@ def preparation_order_detail(request, pk):
'has_executed_outputs': has_executed_outputs,
'is_reopened': is_reopened,
'deleted_items_to_return': deleted_items_to_return,
+ 'discussion': discussion,
'discussion_messages': discussion_messages,
'can_post_discussion_message': can_post_discussion_message,
}