poprawki w synchronizacji produktow
This commit is contained in:
13
app.py
13
app.py
@@ -220,7 +220,7 @@ def require_system_password():
|
||||
# specjalny wyjątek dla statycznych, ale sprawdzany ręcznie niżej
|
||||
if request.endpoint == 'static_bp.serve_js':
|
||||
# tu sprawdzamy czy to JS, który ma być chroniony
|
||||
protected_js = ["live.js", "list_guest.js", "hide_list.js", "socket_reconnect.js","sync_products.js", "expenses.js", "toggle_button.js"]
|
||||
protected_js = ["live.js", "list_guest.js", "hide_list.js", "socket_reconnect.js","product_suggestion.js", "expenses.js", "toggle_button.js"]
|
||||
requested_file = request.view_args.get("filename", "")
|
||||
if requested_file in protected_js:
|
||||
return redirect(url_for('system_auth', next=request.url))
|
||||
@@ -875,16 +875,17 @@ def sync_suggestion_ajax(item_id):
|
||||
else:
|
||||
return jsonify({'success': True, 'message': f'Sugestia dla produktu „{item.name}” już istnieje.'})
|
||||
|
||||
@app.route('/admin/delete_suggestion/<int:suggestion_id>')
|
||||
@app.route('/admin/delete_suggestion/<int:suggestion_id>', methods=['POST'])
|
||||
@login_required
|
||||
def delete_suggestion(suggestion_id):
|
||||
def delete_suggestion_ajax(suggestion_id):
|
||||
if not current_user.is_admin:
|
||||
return redirect(url_for('index_guest'))
|
||||
return jsonify({'success': False, 'message': 'Brak uprawnień'}), 403
|
||||
|
||||
suggestion = SuggestedProduct.query.get_or_404(suggestion_id)
|
||||
db.session.delete(suggestion)
|
||||
db.session.commit()
|
||||
flash('Sugestia została usunięta', 'success')
|
||||
return redirect(url_for('list_products'))
|
||||
|
||||
return jsonify({'success': True, 'message': 'Sugestia została usunięta.'})
|
||||
|
||||
@app.route('/admin/expenses_data')
|
||||
@login_required
|
||||
|
@@ -3,10 +3,12 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||
document.querySelectorAll('.sync-btn').forEach(btn => {
|
||||
btn.replaceWith(btn.cloneNode(true));
|
||||
});
|
||||
document.querySelectorAll('.delete-suggestion-btn').forEach(btn => {
|
||||
btn.replaceWith(btn.cloneNode(true));
|
||||
});
|
||||
|
||||
// Pobierz już "czyste" przyciski
|
||||
// Synchronizacja sugestii
|
||||
const buttons = document.querySelectorAll('.sync-btn');
|
||||
|
||||
buttons.forEach(btn => {
|
||||
btn.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
@@ -16,7 +18,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||
|
||||
button.disabled = true;
|
||||
|
||||
fetch(`/admin/sync_suggestion_ajax/${itemId}`, {
|
||||
fetch(`/admin/sync_suggestion/${itemId}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
@@ -40,6 +42,44 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Usuwanie sugestii
|
||||
const deleteButtons = document.querySelectorAll('.delete-suggestion-btn');
|
||||
deleteButtons.forEach(btn => {
|
||||
btn.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const suggestionId = this.getAttribute('data-suggestion-id');
|
||||
const button = this;
|
||||
|
||||
button.disabled = true;
|
||||
|
||||
fetch(`/admin/delete_suggestion/${suggestionId}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
showToast(data.message, data.success ? 'success' : 'danger');
|
||||
|
||||
if (data.success) {
|
||||
// Możesz usunąć cały wiersz lub np. odświeżyć kolumnę
|
||||
const row = button.closest('tr');
|
||||
if (row) {
|
||||
row.remove();
|
||||
}
|
||||
} else {
|
||||
button.disabled = false;
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
showToast('Błąd usuwania sugestii', 'danger');
|
||||
button.disabled = false;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -58,8 +98,8 @@ function showToast(message, type = 'success') {
|
||||
`;
|
||||
toastContainer.appendChild(toast);
|
||||
|
||||
// Automatyczne usunięcie po 3 sekundach
|
||||
// Automatyczne usunięcie po 1.75 sekundy
|
||||
setTimeout(() => {
|
||||
toast.remove();
|
||||
}, 1750);
|
||||
}
|
||||
}
|
@@ -39,7 +39,8 @@
|
||||
{% set suggestion = suggestions_dict.get(item.name.lower()) %}
|
||||
{% if suggestion %}
|
||||
✅ Istnieje (ID: {{ suggestion.id }})
|
||||
<a href="/admin/delete_suggestion/{{ suggestion.id }}" class="btn btn-sm btn-outline-danger ms-1">🗑️ Usuń</a>
|
||||
<button class="btn btn-sm btn-outline-danger ms-1 delete-suggestion-btn" data-suggestion-id="{{ suggestion.id }}">🗑️ Usuń</button>
|
||||
|
||||
{% else %}
|
||||
<button class="btn btn-sm btn-outline-primary sync-btn" data-item-id="{{ item.id }}">🔄 Synchronizuj</button>
|
||||
{% endif %}
|
||||
@@ -61,7 +62,7 @@
|
||||
|
||||
{% block scripts %}
|
||||
|
||||
<script src="{{ url_for('static_bp.serve_js', filename='sync_products.js') }}"></script>
|
||||
<script src="{{ url_for('static_bp.serve_js', filename='product_suggestion.js') }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% endblock %}
|
||||
|
Reference in New Issue
Block a user