Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Structures): SiaeActivity : pouvoir supprimer une activité #1277

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lemarche/static/js/siae_activity_delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
document.addEventListener("DOMContentLoaded", function() {
$('#siae_activity_delete_modal').on('show.bs.modal', function (event) {
// Button that triggered the modal
var button = $(event.relatedTarget);

// Extract info from data-* attributes
var siaeId = button.data('siae-id');
var siaeSlug = button.data('siae-slug');
var siaeActivityId = button.data('siae-activity-id');
var siaeActivityNameDisplay = button.data('siae-activity-name-display');

// Update the modal's content
// - siae name display
// - edit the form action url
var modal = document.querySelector('#siae_activity_delete_modal');
var modalForm = modal.querySelector('form');
if (modal.querySelector('#siae-activity-name-display')) {
modal.querySelector('#siae-activity-name-display').textContent = siaeActivityNameDisplay;
}
var formActionUrl = modalForm.getAttribute('action');
modalForm.setAttribute('action', formActionUrl.replace('siae-slug-to-replace', siaeSlug).replace('siae-activity-id-to-replace', siaeActivityId));
});
});
6 changes: 6 additions & 0 deletions lemarche/templates/dashboard/_siae_activity_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@
<span>{{ siae.geo_range_pretty_display }}</span>
</p>
</div>

<div class="col-12 col-lg-4 text-right">
<a href="#" id="siae-activity-delete-modal-btn" class="btn" data-toggle="modal" data-target="#siae_activity_delete_modal" data-siae-id="{{ activity.siae.id }}" data-siae-slug="{{ activity.siae.slug }}" data-siae-activity-id="{{ activity.id }}" data-siae-activity-name-display="{{ activity.sector_group }}" title="Supprimer l'activité">
<i class="ri-delete-bin-line ri-xl"></i>
</a>
</div>
</div>
</div>
23 changes: 23 additions & 0 deletions lemarche/templates/dashboard/_siae_activity_delete_modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<div class="modal fade modal-siae" id="siae_activity_delete_modal" tabindex="-1" role="dialog" aria-modal="true" data-backdrop="static" data-keyboard="false" aria-labelledby="modalTitle">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="modalTitle">Supprimer</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Fermer">
<i class="ri-close-line"></i>
</button>
</div>
<form method="POST" action="{% url 'dashboard_siaes:siae_edit_activities_delete' siae.slug|default:'siae-slug-to-replace' activity.id|default:'siae-activity-id-to-replace' %}">
{% csrf_token %}
<div class="modal-body home-content-body">
<p class="font-weight-bold">Voulez-vous supprimer cette activité ?</p>
<i><span id="siae-activity-name-display"></span></i>
</div>
<div class="modal-footer">
<button class="btn btn-sm btn-outline-primary" type="button" data-dismiss="modal" aria-label="Fermer">Annuler</button>
<button class="btn btn-sm btn-primary" type="submit">Confirmer</button>
</div>
</form>
</div>
</div>
</div>
5 changes: 5 additions & 0 deletions lemarche/templates/dashboard/siae_edit_activities.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ <h3>Ajoutez vos secteurs d'activité et recevez des opportunités commerciales c
{% endif %}
{% endblock %}

{% block modals %}
{% include "dashboard/_siae_activity_delete_modal.html" %}
{% endblock %}

{% block extra_js %}
<script type="text/javascript" src="{% static 'js/siae_activity_delete.js' %}"></script>
{% endblock %}
6 changes: 6 additions & 0 deletions lemarche/www/dashboard_siaes/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.views.generic.base import RedirectView

from lemarche.www.dashboard_siaes.views import (
SiaeEditActivitiesDeleteView,
SiaeEditActivitiesView,
SiaeEditContactView,
SiaeEditInfoView,
Expand Down Expand Up @@ -35,6 +36,11 @@
path("contact/", SiaeEditContactView.as_view(), name="siae_edit_contact"),
path("recherche/", SiaeEditSearchView.as_view(), name="siae_edit_search"),
path("activites/", SiaeEditActivitiesView.as_view(), name="siae_edit_activities"),
path(
"activites/<str:activity_id>/supprimer/",
SiaeEditActivitiesDeleteView.as_view(),
name="siae_edit_activities_delete",
),
path("info/", SiaeEditInfoView.as_view(), name="siae_edit_info"),
path("offre/", SiaeEditOfferView.as_view(), name="siae_edit_offer"),
path("liens/", SiaeEditLinksView.as_view(), name="siae_edit_links"),
Expand Down
19 changes: 18 additions & 1 deletion lemarche/www/dashboard_siaes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.views.generic import DeleteView, DetailView, ListView, UpdateView
from django.views.generic.edit import FormMixin

from lemarche.siaes.models import Siae, SiaeUser, SiaeUserRequest
from lemarche.siaes.models import Siae, SiaeActivity, SiaeUser, SiaeUserRequest
from lemarche.utils.apis import api_brevo
from lemarche.utils.mixins import SiaeMemberRequiredMixin, SiaeUserAndNotMemberRequiredMixin, SiaeUserRequiredMixin
from lemarche.utils.s3 import S3Upload
Expand Down Expand Up @@ -128,6 +128,23 @@ class SiaeEditActivitiesView(SiaeMemberRequiredMixin, DetailView):
queryset = Siae.objects.all()


class SiaeEditActivitiesDeleteView(SiaeMemberRequiredMixin, SuccessMessageMixin, DeleteView):
template_name = "dashboard/_siae_activity_delete_modal.html"
model = SiaeActivity
# success_url = reverse_lazy("dashboard_siaes:siae_edit_activities")
# success_message = "Votre activité a été supprimée avec succès."

def get_object(self):
siae = Siae.objects.get(slug=self.kwargs.get("slug"))
return get_object_or_404(SiaeActivity, id=self.kwargs.get("activity_id"), siae=siae)

def get_success_url(self):
return reverse_lazy("dashboard_siaes:siae_edit_activities", args=[self.kwargs.get("slug")])

def get_success_message(self, cleaned_data):
return mark_safe(f"Votre activité <strong>{self.object.sector_group}</strong> a été supprimée avec succès.")


class SiaeEditInfoView(SiaeMemberRequiredMixin, SuccessMessageMixin, UpdateView):
form_class = SiaeEditInfoForm
template_name = "dashboard/siae_edit_info.html"
Expand Down
Loading