File: /var/www/vhost/disk-apps/sigedo-qas.allup.com.co/resources/js/views/programmings.js
$(document).ready(function() {
function getData() {
var automaticprocess_id = document.getElementById("automaticprocess_id").value;
var minutes = document.getElementById("minutes").value;
var hour = document.getElementById("hour").value;
var day = document.getElementById("day").value;
var month = document.getElementById("month").value;
var weekday = document.getElementById("weekday").value;
var active = document.getElementById("active").value == "true" ? true : false;
if (!automaticprocess_id || automaticprocess_id == 0) {
Swal.fire({
type: "error",
title: "Oops...",
text: Lang.get("fronjs.automaticprocess_required"),
});
return;
}
var str1 = "0";
var str2 = "0";
var str3 = "*";
if (minutes != "") {
str1 = minutes;
}
if (hour != "") {
str2 = hour;
}
if (day != "") {
str3 = day;
}
var cron = str1 + " " + str2 + " " + str3 + " " + month + " " + weekday;
var data = {
automaticprocess_id,
cron,
active,
};
return data;
}
$("#button_create").on("click", function(e) {
e.preventDefault();
if ((data = getData())) {
Swal.fire({
title: Lang.get("fronjs.title_create"),
text: Lang.get("fronjs.text_create"),
type: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: Lang.get("fronjs.yes"),
cancelButtonText: Lang.get("fronjs.not"),
}).then((result) => {
if (result.value) {
var laddaBtn = e.currentTarget;
var ladda = Ladda.create(laddaBtn);
ladda.start();
$.ajax({
url: "/programmings",
type: "POST",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(data),
success: function(response) {
if (response.status) {
ladda.stop();
Swal.fire({
type: response.type,
title: response.title,
text: response.message,
showConfirmButton: true,
}).then((val) => {
$(location).attr("href", "/programmings");
});
} else {
ladda.stop();
Swal.fire({
type: response.type,
title: response.title,
text: response.message,
});
}
},
});
}
});
}
});
$("#button_update").on("click", function(e) {
e.preventDefault();
var data = getData();
if (data) {
var programming_id = $("#form_edit").attr("programming_id");
const newData = Object.assign({ _method: $("input[name=_method]").val() }, data);
Swal.fire({
title: Lang.get("fronjs.title_update"),
text: Lang.get("fronjs.text_update"),
type: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: Lang.get("fronjs.yes"),
cancelButtonText: Lang.get("fronjs.not"),
}).then((result) => {
if (result.value) {
var laddaBtn = e.currentTarget;
var ladda = Ladda.create(laddaBtn);
ladda.start();
$.ajax({
url: "/programmings/" + programming_id,
type: "POST",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(newData),
success: function(response) {
if (response.status) {
ladda.stop();
Swal.fire({
type: response.type,
title: response.title,
text: response.message,
showConfirmButton: true,
}).then((val) => {
$(location).attr("href", "/programmings");
});
} else {
ladda.stop();
Swal.fire({
type: response.type,
title: response.title,
text: response.message,
});
}
},
});
}
});
}
});
});
window.deleteRegistry = function(programming_id) {
var data = {
_method: "DELETE",
};
Swal.fire({
title: Lang.get("fronjs.title_delete"),
type: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: Lang.get("fronjs.yes"),
cancelButtonText: Lang.get("fronjs.not"),
showLoaderOnConfirm: true,
allowOutsideClick: false,
allowEscapeKey: false,
preConfirm: (login) => {
return new Promise((resolve, reject) => {
$.ajax({
url: "/programmings/" + programming_id,
type: "POST",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(data),
success: function(response) {
if (response.status) {
Swal.fire({
type: response.type,
title: response.title,
text: response.message,
showConfirmButton: true,
}).then((val) => {
$(location).attr("href", "/programmings");
});
} else {
Swal.fire({
type: response.type,
title: response.title,
text: response.message,
});
}
},
});
});
},
}).then((result) => {
console.log(result);
});
};