File: /var/www/vhost/disk-apps/sigedo-qas.allup.com.co/resources/js/views/notifications.js
$(document).ready(function() {
function getData() {
var subject = document.getElementById("subject").value;
var to = document.getElementById("to").value;
var $html = $(".ql-editor");
var body = $html.prop("outerHTML");
var roles = $("#roles").val();
var users = $("#users").val();
if (!subject || subject == "") {
Swal.fire({
type: "error",
title: "Oops...",
text: Lang.get("fronjs.subject_required"),
});
return;
}
if (!roles.length && !users.length && to == "") {
Swal.fire({
type: "error",
title: "Oops...",
text: Lang.get("fronjs.users_roles_required"),
});
return;
}
var data = {
roles,
users,
subject,
body,
to,
};
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: "/notifications",
type: "POST",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(data),
success: function(response) {
ladda.stop();
if (response.status) {
Swal.fire({
type: response.type,
title: response.title,
text: response.message,
showConfirmButton: true,
}).then((val) => {
$(location).attr("href", "/notifications");
});
} else {
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 notification_id = $("#form_edit").attr("notification_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: "/notifications/" + notification_id,
type: "POST",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(newData),
success: function(response) {
ladda.stop();
if (response.status) {
Swal.fire({
type: response.type,
title: response.title,
text: response.message,
showConfirmButton: true,
}).then((val) => {
$(location).attr("href", "/notifications");
});
} else {
Swal.fire({
type: response.type,
title: response.title,
text: response.message,
});
}
},
});
}
});
}
});
});
window.deleteRegistry = function(notification_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: "/notifications/" + notification_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", "/notifications");
});
} else {
Swal.fire({
type: response.type,
title: response.title,
text: response.message,
});
}
},
});
});
},
}).then((result) => {
console.log(result);
});
};
window.sendNotification = function(notification_id) {
Swal.fire({
title: Lang.get("fronjs.title_send_notification"),
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: "/notifications/send/" + notification_id,
type: "GET",
dataType: "json",
contentType: "application/json",
data: null,
success: function(response) {
if (response.status) {
Swal.fire({
type: response.type,
title: response.title,
text: response.message,
showConfirmButton: true,
}).then((val) => {
$(location).attr("href", "/notifications");
});
} else {
Swal.fire({
type: response.type,
title: response.title,
text: response.message,
});
}
},
});
});
},
}).then((result) => {
console.log(result);
});
};