$(document).ready(function () {
//Create slider
$("#create").click(function (event) {
event.preventDefault();
tinymce.triggerSave();
if (!$('#title').val() || $('#title').val().length === 0) {
swal({
title: "Error!",
text: "Please enter title..!",
type: 'error',
timer: 1500,
showConfirmButton: false
});
} else if (!$('#image').val() || $('#image').val().length === 0) {
swal({
title: "Error!",
text: "Please enter image..!",
type: 'error',
timer: 1500,
showConfirmButton: false
});
} else if (!$('#url').val() || $('#url').val().length === 0) {
swal({
title: "Error!",
text: "Please enter url..!",
type: 'error',
timer: 1500,
showConfirmButton: false
});
} else if (!$('#description').val() || $('#description').val().length === 0) {
swal({
title: "Error!",
text: "Please enter description..!",
type: 'error',
timer: 1500,
showConfirmButton: false
});
} else {
var formData = new FormData($('#form-data')[0]);
$.ajax({
url: "post-and-get/slider.php",
type: "POST",
data: formData,
async: false,
dataType: 'json',
success: function (result) {
swal({
title: "Success!",
text: "Your data was saved successfully!.....!",
type: 'success',
timer: 2000,
showConfirmButton: false
}, function () {
setTimeout(function () {
window.location.replace("create-slider.php");
}, 1500);
});
},
cache: false,
contentType: false,
processData: false
});
}
});
//Edit slider
$("#update").click(function (event) {
event.preventDefault();
tinymce.triggerSave();
if (!$('#title').val() || $('#title').val().length === 0) {
swal({
title: "Error!",
text: "Please enter title..!",
type: 'error',
timer: 1500,
showConfirmButton: false
});
} else if (!$('#image').val() || $('#image').val().length === 0) {
swal({
title: "Error!",
text: "Please enter image..!",
type: 'error',
timer: 1500,
showConfirmButton: false
});
} else if (!$('#url').val() || $('#url').val().length === 0) {
swal({
title: "Error!",
text: "Please enter url..!",
type: 'error',
timer: 1500,
showConfirmButton: false
});
} else if (!$('#description').val() || $('#description').val().length === 0) {
swal({
title: "Error!",
text: "Please enter description..!",
type: 'error',
timer: 1500,
showConfirmButton: false
});
} else {
var formData = new FormData($('#form-data')[0]);
$.ajax({
url: "post-and-get/slider.php",
type: "POST",
data: formData,
async: false,
dataType: 'json',
success: function (result) {
swal({
title: "Success!",
text: "Your data was saved successfully!.....!",
type: 'success',
timer: 2000,
showConfirmButton: false
}, function () {
setTimeout(function () {
window.location.replace("edit-slider.php?id=" + result.id);
}, 1500);
});
},
cache: false,
contentType: false,
processData: false
});
}
});
});
|