resource.html 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. {% extends 'SharixAdmin/index.html' %}
  2. {% load render_table from django_tables2 %}
  3. {% block contenthome %}
  4. <h1 >{{ title }}</h1>
  5. <div class="container text-center mt-2">
  6. {% render_table table %}
  7. </div>
  8. <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  9. <script>
  10. // Запрос на изменения статуса ресурса
  11. $('.status-toggle').change(function() {
  12. var resource_id = $(this).data('resource-id');
  13. var new_status = $(this).prop('checked') ? 'active' : 'deactivated';
  14. $.ajax({
  15. url: '{% url "resource/change_status" %}',
  16. type: 'POST',
  17. data: {
  18. 'resource_id': resource_id,
  19. 'new_status': new_status,
  20. 'csrfmiddlewaretoken': '{{ csrf_token }}'
  21. },
  22. success: function(response) {
  23. var scrollTop = window.pageYOffset;
  24. location.reload();
  25. window.scrollTo(0, scrollTop);
  26. },
  27. error: function(xhr, status, error) {
  28. console.log(xhr.responseText);
  29. }
  30. });
  31. });
  32. </script>
  33. {% endblock contenthome %}