jobportal/static/js/addorremove.js
2021-01-17 10:12:40 +01:00

56 lines
2.2 KiB
JavaScript

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);
}
});
}
}
}