$('#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 = '
';
html += '| '+coupon.coupon_code+' | ';
html += ''+coupon.coupon_name+' | ';
html += ' | ';
html += '
';
$('.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 : " 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 = "";
html += "";
html += "";
html += "
";
$("#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 : " 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('')
}
});
}
}
});
})
$('body').on('click', '.publish', function(event){
event.preventDefault();
var couponid = $(this).attr('data-couponid');
var element = $(this).parent();
$.fancyInfo({
title : " 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('')
}
});
}
}
});
})
$('body').on('click', '.unpublishcamp', function(event){
event.preventDefault();
var campid = $(this).attr('data-campid');
var element = $(this).parent();
$.fancyConfirm({
title : " 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('')
}
});
}
}
});
})
$('body').on('click', '.publishcamp', function(event){
event.preventDefault();
var campid = $(this).attr('data-campid');
var element = $(this).parent();
$.fancyInfo({
title : " 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('')
}
});
}
}
});
})