217 lines
7 KiB
JavaScript
Vendored
217 lines
7 KiB
JavaScript
Vendored
$('#addCoupons').on('click', function(event){
|
|
event.preventDefault();
|
|
let ids = [];
|
|
var campid = $(this).parent().find('#camp_id').val();
|
|
$(this).parent().find('.inputGroup input').each(function(event){
|
|
if($(this).is(':checked')){
|
|
ids.push($(this).val());
|
|
}
|
|
|
|
})
|
|
$.ajaxSetup({
|
|
headers: {
|
|
'X-CSRF-TOKEN': $(this).parent().find('#csrf').val()
|
|
}
|
|
});
|
|
|
|
$.ajax({
|
|
url: '/bo/campagne/'+ campid +'/add-coupons',
|
|
type: 'POST',
|
|
data: {
|
|
ids: ids
|
|
},
|
|
dataType: 'JSON',
|
|
success: function (reponse) {
|
|
$.each(reponse, function(index, coupon){
|
|
var html = '<tr>';
|
|
html += '<td>'+coupon.coupon_code+'</td>';
|
|
html += '<td>'+coupon.coupon_name+'</td>';
|
|
html += '<td><i class="fas fa-times delete-coupon" data-campid="'+campid+'" data-couponid="'+coupon.coupon_id+'"></i></td>';
|
|
html += '</tr>';
|
|
$('.no-result').remove();
|
|
$('.coupons-wrapper table').append(html);
|
|
$('#addCoupons').parent().find('.inputGroup input').each(function(event){
|
|
if($(this).val() == coupon.coupon_id){
|
|
$(this).parent('.inputGroup').remove();
|
|
}
|
|
})
|
|
$.fancybox.close();
|
|
});
|
|
},
|
|
error: function (e) {
|
|
console.log(e.responseText);
|
|
}
|
|
});
|
|
})
|
|
|
|
|
|
|
|
$('body').on('click', '.delete-coupon', function(event){
|
|
var campid = $(this).attr('data-campid');
|
|
var couponid = $(this).attr('data-couponid');
|
|
var trLinked = $(this).parent().parent();
|
|
$.fancyConfirm({
|
|
title : "<i class='fas fa-times-circle'></i> Retrait",
|
|
message : "Êtes-vous sûr de vouloir retirer ce coupon de cette campagne ?",
|
|
okButton : 'Retirer',
|
|
noButton : 'Annuler',
|
|
callback : function (value) {
|
|
if (value) {
|
|
event.preventDefault();
|
|
|
|
$.ajaxSetup({
|
|
headers: {
|
|
'X-CSRF-TOKEN': $('#csrf').val()
|
|
}
|
|
});
|
|
$.ajax({
|
|
url: '/bo/campagne/'+ campid +'/remove-coupon/' + couponid,
|
|
type: 'POST',
|
|
data: {},
|
|
dataType: 'JSON',
|
|
success: function (reponse) {
|
|
trLinked.remove();
|
|
var html = "<div class='inputGroup'>";
|
|
html += "<input id='coupon["+reponse.coupon_id+"]' name='coupon["+reponse.coupon_id+"]' type='checkbox' value='"+reponse.coupon_id+"' >";
|
|
html += "<label for='coupon["+reponse.coupon_id+"]'>"+reponse.coupon_name+"</label>";
|
|
html += "</div>";
|
|
$("#camp_id").before(html);
|
|
},
|
|
error: function (e) {
|
|
console.log(e.responseText);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
})
|
|
|
|
|
|
$('body').on('click', '.unpublish', function(event){
|
|
event.preventDefault();
|
|
var couponid = $(this).attr('data-couponid');
|
|
var element = $(this).parent();
|
|
$.fancyConfirm({
|
|
title : "<i class='fas fa-times-circle'></i> Dépublier",
|
|
message : "Êtes-vous sûr de vouloir dépublier ce coupon ?",
|
|
okButton : 'Dépublier',
|
|
noButton : 'Annuler',
|
|
callback : function (value) {
|
|
if (value) {
|
|
$.ajaxSetup({
|
|
headers: {
|
|
'X-CSRF-TOKEN': $('#csrf').val()
|
|
}
|
|
});
|
|
$.ajax({
|
|
url: '/unpublish-coupons-ajax',
|
|
type: 'POST',
|
|
data: {
|
|
couponid: couponid
|
|
},
|
|
dataType: 'JSON',
|
|
success: function (reponse) {
|
|
element.empty().html('<i data-couponid="'+couponid+'" class="fas fa-times-circle red publish"></i>')
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
})
|
|
|
|
$('body').on('click', '.publish', function(event){
|
|
event.preventDefault();
|
|
var couponid = $(this).attr('data-couponid');
|
|
var element = $(this).parent();
|
|
$.fancyInfo({
|
|
title : "<i class='fas fa-check-circle'></i> Publier",
|
|
message : "Êtes-vous sûr de vouloir publier ce coupon ?",
|
|
okButton : 'Publier',
|
|
noButton : 'Annuler',
|
|
callback : function (value) {
|
|
if (value) {
|
|
$.ajaxSetup({
|
|
headers: {
|
|
'X-CSRF-TOKEN': $('#csrf').val()
|
|
}
|
|
});
|
|
$.ajax({
|
|
url: '/publish-coupons-ajax',
|
|
type: 'POST',
|
|
data: {
|
|
couponid: couponid
|
|
},
|
|
dataType: 'JSON',
|
|
success: function (reponse) {
|
|
element.empty().html('<i data-couponid="'+couponid+'" class="fas fa-check-circle green unpublish"></i>')
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
})
|
|
|
|
|
|
$('body').on('click', '.unpublishcamp', function(event){
|
|
event.preventDefault();
|
|
var campid = $(this).attr('data-campid');
|
|
var element = $(this).parent();
|
|
$.fancyConfirm({
|
|
title : "<i class='fas fa-times-circle'></i> Dépublier",
|
|
message : "Êtes-vous sûr de vouloir dépublier cette campagne ?",
|
|
okButton : 'Dépublier',
|
|
noButton : 'Annuler',
|
|
callback : function (value) {
|
|
if (value) {
|
|
$.ajaxSetup({
|
|
headers: {
|
|
'X-CSRF-TOKEN': $('#csrf').val()
|
|
}
|
|
});
|
|
$.ajax({
|
|
url: '/bo/campagne/'+ campid +'/toggle-publish/0',
|
|
type: 'POST',
|
|
data: {},
|
|
dataType: 'JSON',
|
|
success: function (reponse) {
|
|
element.empty().html('<i data-campid="'+campid+'" class="fas fa-times-circle red publishcamp"></i>')
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
})
|
|
|
|
$('body').on('click', '.publishcamp', function(event){
|
|
event.preventDefault();
|
|
var campid = $(this).attr('data-campid');
|
|
var element = $(this).parent();
|
|
$.fancyInfo({
|
|
title : "<i class='fas fa-check-circle'></i> Publier",
|
|
message : "Êtes-vous sûr de vouloir publier cette campagne ?",
|
|
okButton : 'Publier',
|
|
noButton : 'Annuler',
|
|
callback : function (value) {
|
|
if (value) {
|
|
$.ajaxSetup({
|
|
headers: {
|
|
'X-CSRF-TOKEN': $('#csrf').val()
|
|
}
|
|
});
|
|
$.ajax({
|
|
url: '/bo/campagne/'+ campid +'/toggle-publish/1',
|
|
type: 'POST',
|
|
data: {},
|
|
dataType: 'JSON',
|
|
success: function (reponse) {
|
|
element.empty().html('<i data-campid="'+campid+'" class="fas fa-check-circle green unpublishcamp"></i>')
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
})
|