$(function(){
$('#surf_add').submit(function(){
var url = '/ajax.php?action=surfv&type='+$("#type").val();//$(this).attr('action');
var data = $(this).serialize()+'&ajax=1';
$.post(url, data, function(result){
if(result['id'] != ''){
$('#'+result['id']).addClass('is-invalid');
}
swal(result['title'], result['error'], result['status']);
if(result['status'] == 'success'){
if(result['redirect'] != ''){
setTimeout(function(){
window.location.replace(result['redirect']);
}, 1000);
}
}
}, 'json');
return false;
});
$('.balance_add').submit(function(){
var url = '/ajax.php?action=surfv&type='+$("#type").val();//$(this).attr('action');
var balance = $('#balance').html();
var data = $(this).serialize()+'&balance='+balance+'&ajax=1';
$.post(url, data, function(result){
if(result['id'] != ''){
$('#'+result['id']).addClass('is-invalid');
}
swal(result['title'], result['error'], result['status']);
if(result['status'] == 'success'){
if(result['redirect'] != ''){
setTimeout(function(){
window.location.replace(result['redirect']);
}, 1000);
}
}
}, 'json');
return false;
});
$('#surf_edit').submit(function(){
var url = '/ajax.php?action=surfv&type='+$("#type").val();//$(this).attr('action');
var data = $(this).serialize()+'&ajax=1';
$.post(url, data, function(result){
if(result['id'] != ''){
$('#'+result['id']).addClass('is-invalid');
}
swal(result['title'], result['error'], result['status']);
if(result['status'] == 'success'){
if(result['redirect'] != ''){
setTimeout(function(){
window.location.replace(result['redirect']);
}, 1000);
}
}
}, 'json');
return false;
});
$(document).on('click', '.status_surf',function() {
var button = $(this);
var surf_id = button.attr('surf_id');
var status = button.attr('action');
$.post('/ajax.php?action=surfv&type=status', {'surf_id': surf_id,'status':status}, function(result) {
if(result['status'] == 'success'){
if(status === '1'){
button.attr('action','2');
button.html('<i class="fa fa-pause"></i>');
button.removeClass('icon-shape-success');
button.addClass('icon-shape-warning');
}else if(status === '2'){
button.attr('action','1');
button.html('<i class="fa fa-play"></i>');
button.removeClass('icon-shape-warning');
button.addClass('icon-shape-success');
}
}
}, 'json');
return false;
});
$(document).on('click', '.delete',function() {
var surf_id = $(this).attr('surf_id');
$.post('/ajax.php?action=surfv&type=delete', {'surf_id': surf_id}, function(result) {
swal(result['title'], result['error'], result['status']);
if(result['status'] == 'success'){
$('#surf_'+surf_id).remove();
}
}, 'json');
return false;
});
});