feat: Dodaj funkcjonalność usuwania komentarzy oraz wyświetlanie ich w historii produktów

This commit is contained in:
2026-01-26 23:40:20 +01:00
parent e165fd3ef3
commit cd5ab2b8b6
3 changed files with 104 additions and 5 deletions

View File

@@ -42,6 +42,7 @@
<th scope="col">Wartość konwersji</th>
<th scope="col">ROAS</th>
<th scope="col">Data</th>
<th scope="col">Komentarz</th>
</tr>
</thead>
<tbody></tbody>
@@ -90,6 +91,7 @@
{ width: '175px', name: 'conversions_value', className: "dt-type-numeric" },
{ width: '100px', name: 'roas', className: "dt-type-numeric", orderable: false },
{ width: '100px', name: 'date_add' },
{ width: '250px', name: 'comment', orderable: false },
],
order: [[0, false],[8, 'desc']]
});
@@ -157,10 +159,10 @@
})
}, false);
// 2) Dodaj „niewidzialne markery do hovera
// 2) Dodaj „niewidzialne" markery do hovera
var points = (parsedData.comments || []).map(function(c) {
var idx = parsedData.dates.indexOf((c.date_add || '').split(' ')[0]);
return { x: idx, y: 0, comment: c.comment };
return { x: idx, y: 0, comment: c.comment, comment_id: c.id };
});
chart.addSeries({
@@ -177,12 +179,43 @@
enabled: true,
radius: 4,
lineWidth: 0,
fillOpacity: 0 // marker „niewidoczny
fillOpacity: 0 // marker „niewidoczny"
},
states: {
hover: { enabled: true, halo: { size: 5 } }
},
enableMouseTracking: true
enableMouseTracking: true,
cursor: 'pointer',
point: {
events: {
click: function () {
var commentId = this.comment_id;
var commentText = this.comment;
if (confirm('Czy na pewno chcesz usunąć komentarz: "' + commentText + '"?')) {
$.ajax({
url: '/products/comment_delete/',
method: 'POST',
data: {
comment_id: commentId
},
success: function(res) {
res = JSON.parse(res);
if (res.status === 'ok') {
location.reload();
} else {
alert('Nie udało się usunąć komentarza. Spróbuj ponownie.');
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.error('Błąd usuwania komentarza:', textStatus, errorThrown);
alert('Nie udało się usunąć komentarza. Spróbuj ponownie.');
}
});
}
}
}
}
}, false);
chart.redraw();
@@ -282,5 +315,36 @@
}
});
});
// OBSŁUGA USUWANIA KOMENTARZA Z TABELI
$(document).on('click', '.delete-comment', function(e) {
e.preventDefault();
var comment_id = $(this).data('comment-id');
if (!confirm('Czy na pewno chcesz usunąć ten komentarz?')) {
return;
}
$.ajax({
url: '/products/comment_delete/',
method: 'POST',
data: {
comment_id: comment_id
},
success: function(res) {
res = JSON.parse(res);
if (res.status === 'ok') {
location.reload();
} else {
alert('Nie udało się usunąć komentarza. Spróbuj ponownie.');
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.error('Błąd usuwania komentarza:', textStatus, errorThrown);
alert('Nie udało się usunąć komentarza. Spróbuj ponownie.');
}
});
});
});
</script>