33# fixed problems with wishlist

This commit is contained in:
Eligiusz Kurzawa 2021-01-16 20:04:36 +01:00
parent 21e9f74911
commit b9f93a6dc5

View File

@ -229,11 +229,11 @@
<a href="{% url 'jobs:single_job' job.slug job.pk %}" class="btn btn-primary py-2 mr-1">Apply Job</a> <a href="{% url 'jobs:single_job' job.slug job.pk %}" class="btn btn-primary py-2 mr-1">Apply Job</a>
{% if job.id in wish_list %} {% if job.id in wish_list %}
<a href="javascripts:void(0);" id="jobwl{{ job.id }}" title="Remove from my wish list" onclick="removefrommywishlist({{ job.id }})" class="btn btn-danger rounded-circle btn-favorite d-flex align-items-center"> <a href="javascripts:void(0);" id="jobwl{{ job.id }}" title="Remove from my wish list" onclick="addorremove({{ job.id }})" class="btn btn-danger rounded-circle btn-favorite d-flex align-items-center">
<span class="icon-heart"></span> <span class="icon-heart"></span>
</a> </a>
{% else %} {% else %}
<a href="javascripts:void(0);" id="jobwl{{ job.id }}" title="Add to my wish list" onclick="addtomywishlist({{ job.id }})" class="btn btn-primary rounded-circle btn-favorite d-flex align-items-center"> <a href="javascripts:void(0);" id="jobwl{{ job.id }}" title="Add to my wish list" onclick="addorremove({{ job.id }})" class="btn btn-primary rounded-circle btn-favorite d-flex align-items-center">
<span class="icon-heart"></span> <span class="icon-heart"></span>
</a> </a>
{% endif %} {% endif %}
@ -478,62 +478,91 @@
</div> </div>
</section> </section>
<script type="text/javascript"> {% if user.is_authenticated and user.is_employee%}
function addtomywishlist(id) { <script type="text/javascript">
if (id){ function addorremove(id) {
$.ajax({ if (id){
url:"/users/add-wishlist/" + id, var wishlist = $('#jobwl' + id).data('wl');
method:"GET", if(wishlist == 0) {
success:function () { $.ajax({
$('#jobwl' + id).removeClass('btn-primary').addClass('btn-danger') url: "/users/add-wishlist/" + id,
const Toast = Swal.mixin({ method: "GET",
toast: true, success: function () {
position: 'top', $('#jobwl' + id).removeClass('btn-primary').addClass('btn-danger')
showConfirmButton: true, const Toast = Swal.mixin({
timer: 3000, toast: true,
timerProgressBar: true, position: 'top',
didOpen: (toast) => { showConfirmButton: true,
toast.addEventListener('mouseenter', Swal.stopTimer) timer: 3000,
toast.addEventListener('mouseleave', Swal.resumeTimer) timerProgressBar: true,
} didOpen: (toast) => {
}) toast.addEventListener('mouseenter', Swal.stopTimer)
toast.addEventListener('mouseleave', Swal.resumeTimer)
}
})
Toast.fire({ Toast.fire({
icon: 'success', icon: 'success',
title: 'Added' 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);
}
});
}
}
} }
} </script>
{% else %}
<script type="text/javascript">
function addtomywishlist(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)
}
})
function removefrommywishlist(id) { Toast.fire({
if (id){ icon: 'error',
$.ajax({ title: 'You are not an employee!'
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'
})
}
});
} }
} </script>
</script> {% endif %}
{% endblock %} {% endblock %}