Skip to content
Snippets Groups Projects
Commit fc40da4e authored by Pierre Fleutot's avatar Pierre Fleutot
Browse files

Rechargement panneau notifications quand on marque une notif comme lue. Les...

Rechargement panneau notifications quand on marque une notif comme lue. Les notifs associées à une invitation traitée passe au statut "lue"
parent db3b03ab
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@ $(function() {
initializeForm();
initializeAjaxLinks();
initializeAjaxAndRunResponse();
initializeSearchHeadwords();
// Pour améliorer en spécifiant la méthode (DELETE, POST...) Voir https://stackoverflow.com/a/8983053/4954580
initializeFormToggles();
......@@ -420,4 +421,35 @@ function initializeSearchHeadwords() {
}
})
});
}
function initializeAjaxAndRunResponse() {
$('body').on('click', '.ajax-and-run', function () {
var $overlay = $('#overlay').show();
var method = $(this).data('method');
$.ajax({
type: 'GET',
url: $(this).data('url'),
dataType: "script"
});
});
}
function reloadNotifications() {
var $notifications = $('#box');
var $overlay = $('#overlay').show();
$.ajax({
type: "GET",
url: Routing.generate('app_notification_reload'),
cache: false,
success: function (resp) {
// console.log($(resp).find('#box'));
$notifications.html($(resp).find('#box').html());
},
complete: function () {
$overlay.hide();
}
});
}
\ No newline at end of file
......@@ -124,6 +124,7 @@ class FriendController extends AbstractController
public function denyFriendshipInvitationRequest(Request $request, InvitationRequest $invitationRequest): Response
{
$invitationRequest->setStatus(InvitationRequest::STATUS_DENIED);
$invitationRequest->markAllNotificationsAsRead();
$notification = new Notification();
$notification->setUser($invitationRequest->getSender());
$notification->setContent("Invitation refusée");
......@@ -141,7 +142,7 @@ class FriendController extends AbstractController
public function acceptFriendshipInvitationRequest(Request $request, InvitationRequest $invitationRequest): Response
{
$invitationRequest->setStatus(InvitationRequest::STATUS_ACCEPTED);
$this->getUser()->addMyFriend($invitationRequest->getSender());
$invitationRequest->markAllNotificationsAsRead();
$notification = new Notification();
$notification->setUser($invitationRequest->getSender());
$notification->setContent("Invitation acceptée");
......
......@@ -38,6 +38,13 @@ class NotificationController extends AppBaseController
$this->doctrine->getManager()->flush();
return $this->redirect($request->get('backUrl') ? : ($request->headers->get('referer')));
return $this->render('reloadNotifications.js.twig');
}
/**
* @Route("/reload-list", name="app_notification_reload", options={"expose" = true})
*/
public function reloadList(Request $request): Response
{
return $this->render('base.html.twig');
}
}
......@@ -82,6 +82,13 @@ class InvitationRequest
*/
private $notifications;
public function markAllNotificationsAsRead()
{
foreach ($this->getNotifications() as $notification) {
$notification->setStatus(Notification::STATUS_READ);
}
}
public function isAccepted()
{
return $this->getStatus() === self::STATUS_ACCEPTED;
......
......@@ -31,10 +31,10 @@ class UserAddFriendType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$user = $this->security->getUser();
$hiddenUsers = [];
$hiddenUsers = ['4444'];
if ($user) {
$hiddenUsers[] = $user;
$hiddenUsers = array_merge($user->getMyFriends(), $user->getUsersFromPendingInvitationRequests());
$hiddenUsers = array_merge($hiddenUsers, $user->getMyFriends(), $user->getUsersFromPendingInvitationRequests());
}
$builder
......
......@@ -21,7 +21,7 @@
</div>
</a>
<a title="{{ "Marquer comme lu"|trans }}" href="{{ path('app_notification_mark_as_read', {id: notification.id}) }}"><i class="fa fa-envelope"></i></a>
<a title="{{ "Marquer comme lu"|trans }}" class="ajax-and-run" href="#" data-url="{{ path('app_notification_mark_as_read', {id: notification.id}) }}"><i class="fa fa-envelope"></i></a>
</div>
{% endfor %}
......
reloadNotifications();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment