File: /var/www/vhost/disk-apps/demo-sigedo.teky.com.co/resources/js/views/automaticprocesses.js
$(document).ready(function() {
$("#report_id").change(function() {
$("#componentInstitution").addClass("displayNone");
$("#componentStudent").addClass("displayNone");
if (this.value == "1") {
$("#componentInstitution").removeClass("displayNone");
}
if (this.value == "2") {
$("#componentStudent").removeClass("displayNone");
}
setTimeout(() => {
$(".select2").select2();
}, 100);
});
$("#typeprocess_id").change(function() {
$("#containerNotification").addClass("displayNone");
$("#containerReport").addClass("displayNone");
$("#containerProcess").addClass("displayNone");
document.getElementById("notification_id").value = 0;
document.getElementById("report_id").value = 0;
document.getElementById("process_id").value = 0;
$("#notification_id").change();
$("#report_id").change();
$("#process_id").change();
if (this.value == "1") {
$("#containerNotification").removeClass("displayNone");
} else if (this.value == "2") {
$("#containerNotification").removeClass("displayNone");
$("#containerReport").removeClass("displayNone");
} else if (this.value == "3") {
$("#containerProcess").removeClass("displayNone");
}
setTimeout(() => {
$(".select2").select2();
}, 100);
});
function getData() {
var name = document.getElementById("name").value;
var typeprocess_id = document.getElementById("typeprocess_id").value;
var notification_id = document.getElementById("notification_id").value;
var report_id = document.getElementById("report_id").value;
var process_id = document.getElementById("process_id").value;
var active =
document.getElementById("active").value == "true" ? true : false;
if (!name || name == "") {
Swal.fire({
type: "error",
title: "Oops...",
text: Lang.get("fronjs.name_required"),
});
return;
}
if (!typeprocess_id || typeprocess_id == 0) {
Swal.fire({
type: "error",
title: "Oops...",
text: Lang.get("fronjs.typeprocess_required"),
});
return;
}
if (typeprocess_id == 1 && notification_id == 0) {
Swal.fire({
type: "error",
title: "Oops...",
text: Lang.get("fronjs.notification_required"),
});
return;
}
if (typeprocess_id == 2 && notification_id == 0) {
Swal.fire({
type: "error",
title: "Oops...",
text: Lang.get("fronjs.notification_required"),
});
return;
}
if (typeprocess_id == 2 && report_id == 0) {
Swal.fire({
type: "error",
title: "Oops...",
text: Lang.get("fronjs.report_required"),
});
return;
}
if (typeprocess_id == 3 && process_id == 0) {
Swal.fire({
type: "error",
title: "Oops...",
text: Lang.get("fronjs.process_required"),
});
return;
}
var params = null;
if (typeprocess_id == 2 && report_id == 1) {
var institution_id = document.getElementById("institution_id").value;
var program_id = document.getElementById("program_id").value;
var rotation_start_range_start = document.getElementById(
"rotation_start_range_start"
).value;
var rotation_start_range_end = document.getElementById(
"rotation_start_range_end"
).value;
var rotation_end_range_start = document.getElementById(
"rotation_end_range_start"
).value;
var rotation_end_range_end = document.getElementById(
"rotation_end_range_end"
).value;
params = {
institution_id,
program_id,
rotation_start_range_start,
rotation_start_range_end,
rotation_end_range_start,
rotation_end_range_end,
};
}
if (typeprocess_id == 2 && report_id == 2) {
var document_student = document.getElementById("document_student").value;
params = {
document_student,
};
}
var data = {
name,
typeprocess_id,
notification_id: notification_id != 0 ? notification_id : null,
report_id: report_id != 0 ? report_id : null,
process_id: process_id != 0 ? process_id : null,
params: params ? JSON.stringify(params) : null,
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: "/automaticprocesses",
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", "/automaticprocesses");
});
} 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 automaticprocess_id = $("#form_edit").attr("automaticprocess_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: "/automaticprocesses/" + automaticprocess_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", "/automaticprocesses");
});
} else {
ladda.stop();
Swal.fire({
type: response.type,
title: response.title,
text: response.message,
});
}
},
});
}
});
}
});
});
window.deleteRegistry = function(automaticprocess_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: "/automaticprocesses/" + automaticprocess_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", "/automaticprocesses");
});
} else {
Swal.fire({
type: response.type,
title: response.title,
text: response.message,
});
}
},
});
});
},
}).then((result) => {
console.log(result);
});
};