diff --git a/jobs/views.py b/jobs/views.py index c03081e..8e32909 100644 --- a/jobs/views.py +++ b/jobs/views.py @@ -57,6 +57,7 @@ class SingleJobView(SuccessMessageMixin, UpdateView): context = super(SingleJobView, self).get_context_data(**kwargs) context['categories'] = Category.objects.all() context['employee_applied'] = Job.objects.get(pk=self.kwargs['pk']).employee.all().filter(id=self.request.user.id) + context['in_my_list'] = Job.objects.get(pk=self.kwargs['pk']).wish_list.all().filter(user_id=self.request.user.id) try: context['applied_employees'] = Job.objects.get(pk=self.kwargs['pk'], employer_id=self.request.user.id).employee.all() context['employer_id'] = Job.objects.get(pk=self.kwargs['pk']).employer_id diff --git a/static/js/addorremove.js b/static/js/addorremove.js new file mode 100644 index 0000000..49d7bde --- /dev/null +++ b/static/js/addorremove.js @@ -0,0 +1,56 @@ +function addorremove(id) { + if (id){ + var wishlist = $('#jobwl' + id).data('wl'); + if(wishlist == 0) { + $.ajax({ + url: "/users/add-wishlist/" + id, + method: "GET", + success: function () { + $('#jobwl' + id).removeClass('btn-primary').addClass('btn-danger') + const Toast = Swal.mixin({ + toast: true, + position: 'top', + showConfirmButton: true, + timer: 3000, + timerProgressBar: true, + didOpen: (toast) => { + toast.addEventListener('mouseenter', Swal.stopTimer) + toast.addEventListener('mouseleave', Swal.resumeTimer) + } + }) + + Toast.fire({ + icon: 'success', + title: 'Added' + }) + $('#jobwl' + id).data('wl', 1); + } + }); + }else{ + $.ajax({ + url:"/users/remove-from-wishlist/" + id, + method:"GET", + success:function () { + $('#jobwl' + id).removeClass('btn-danger').addClass('btn-primary') + const Toast = Swal.mixin({ + toast: true, + position: 'top', + showConfirmButton: true, + timer: 3000, + timerProgressBar: true, + didOpen: (toast) => { + toast.addEventListener('mouseenter', Swal.stopTimer) + toast.addEventListener('mouseleave', Swal.resumeTimer) + } + }) + + Toast.fire({ + icon: 'error', + title: 'Removed' + }) + $('#jobwl' + id).data('wl', 0); + } + }); + } + } + } \ No newline at end of file diff --git a/static/js/addorremovenotauth.js b/static/js/addorremovenotauth.js new file mode 100644 index 0000000..abac3d4 --- /dev/null +++ b/static/js/addorremovenotauth.js @@ -0,0 +1,24 @@ +function addorremove(id) { + if (id){ + $.ajax({ + success:function () { + const Toast = Swal.mixin({ + toast: true, + position: 'top', + showConfirmButton: true, + timer: 3000, + timerProgressBar: true, + didOpen: (toast) => { + toast.addEventListener('mouseenter', Swal.stopTimer) + toast.addEventListener('mouseleave', Swal.resumeTimer) + } + }) + + Toast.fire({ + icon: 'error', + title: 'You are not an employee!' + }) + } + }); + } + } \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 76f19b8..da31f61 100644 --- a/templates/base.html +++ b/templates/base.html @@ -202,13 +202,12 @@ + {% if user.is_authenticated and user.is_employee %} {% else %} - + {% endif %} - - diff --git a/templates/jobs/index.html b/templates/jobs/index.html index 0ba0524..0b07b0b 100644 --- a/templates/jobs/index.html +++ b/templates/jobs/index.html @@ -478,91 +478,4 @@ -{% if user.is_authenticated and user.is_employee%} - -{% else %} - -{% endif %} {% endblock %} \ No newline at end of file diff --git a/templates/jobs/single.html b/templates/jobs/single.html index 8a4e312..d4d21f6 100644 --- a/templates/jobs/single.html +++ b/templates/jobs/single.html @@ -28,9 +28,15 @@ {% else %} - - - + {% if in_my_list %} + + + + {% else %} + + + + {% endif %} {% endif %} {% endif %} diff --git a/templates/users/my-wish-list.html b/templates/users/my-wish-list.html index dd492bd..8c59b70 100644 --- a/templates/users/my-wish-list.html +++ b/templates/users/my-wish-list.html @@ -168,11 +168,11 @@ Apply Job {% if job.id in wish_list %} - + {% else %} - + {% endif %} @@ -196,62 +196,36 @@ {% endif %} -
- {% if is_paginated %} -
-
-
    - {% if page_obj.has_previous %} -
  • <
  • - {% else %} -
  • <
  • - {% endif %} - {% for i in paginator.page_range %} - {% if page_obj.number == i %} -
  • {{ i }}
  • + {% if user.is_authenticated %} +
    + {% if is_paginated %} +
    +
    +
      + {% if page_obj.has_previous %} +
    • <
    • {% else %} -
    • {{ i }}
    • +
    • <
    • {% endif %} - {% endfor %} - {% if page_obj.has_next %} -
    • >
    • - {% else %} -
    • >
    • - {% endif %} -
    -
    -
    + {% for i in paginator.page_range %} + {% if page_obj.number == i %} +
  • {{ i }}
  • + {% else %} +
  • {{ i }}
  • + {% endif %} + {% endfor %} + {% if page_obj.has_next %} +
  • >
  • + {% else %} +
  • >
  • + {% endif %} +
+
+
+ {% endif %} +
{% endif %} - - - {% endblock %} \ No newline at end of file