//Função que carrega conteúdo sem refresh
function Conteudo(url, div) {
ShowLoader();
$.ajax({
url: url,
success: function (data) {
$('#' + div).html(data);
HideLoader();
},
error: function () {
HideLoader();
}
});
}
/*ENVIA DADOS AO SetSession.php, QUE DEFINE VALORES DE UM JSON EM $_SESSION, ::::APENAS JSON EM STRING - EX: {'nome':'jose', 'idade':'30'}:::::*/
function SetSession(aJSON) {
return $.ajax({
type: "POST",
url: '../Source/App/SetSession.php',
cache: false,
data: {
js: aJSON
}
});
}
function CleanSession() {
$.ajax({
url: '../Source/App/CleanSession.php',
success: function (data) {
location.reload();
},
error: function () {
//
}
});
}
/*COOKIES*/
function setCookie(aName, aValue) {
document.cookie = aName + "=" + aValue;
}
function getCookie(name) {
var cookies = document.cookie;
var prefix = name + "=";
var begin = cookies.indexOf("; " + prefix);
if (begin == -1) {
begin = cookies.indexOf(prefix);
if (begin != 0) {
return null;
}
} else {
begin += 2;
}
var end = cookies.indexOf(";", begin);
if (end == -1) {
end = cookies.length;
}
return unescape(cookies.substring(begin + prefix.length, end));
}
/*FULL MODAL*/
function FullModal(aConteudo, aDivPai, aTitle) {
return $.ajax({
url: '../View/Pages/Body/modal_full.php',
contentType: "application/html; charset=utf-8",
cache: false,
success: function (data) {
$("body").prepend(data);
$('#titleFullChart').html(aTitle);
$('#bgFull').fadeIn();
$('#actFullModal').attr("onclick", "CloseFullDFash('" + aConteudo + "', '" + aDivPai + "')");
}
});
}
function CloseFullDFash(aConteudo, aDivPai) {
$('#' + aConteudo).remove().appendTo($('#' + aDivPai));
$('#bgFull').fadeOut('fast');
setTimeout(function () {
$('#bgFull').remove();
}, 500);
}
function MoveChartFull(aDivConteudo) {
$('#' + aDivConteudo).remove().appendTo($('*[ref="fullChart"]'));
}
/*MODAL*/
function OpenModal(aText) {
$.ajax({
url: '../View/Pages/Body/modal.php',
contentType: "application/html; charset=utf-8",
success: function (data) {
$("body").append(data);
$("#aBodyModal").html(aText);
},
error: function () {
//
}
});
}
function CloseModal() {
$('#aModal').remove();
}
/*TOAST*/
function OpenToast(aText) {
$.ajax({
url: '../View/Pages/Body/toast.php',
contentType: "application/html; charset=utf-8",
success: function (data) {
$("body").append(data);
$("#aBodyToast").html(aText);
$('#aToast').slideDown();
setTimeout(function () {
$('#aToast').slideUp();
setTimeout(function () {
$('#aToast').slideUp();
CloseToast();
}, 1000);
}, 5000);
},
error: function () {
//
}
});
}
function CloseToast() {
$('#aToast').remove();
}
/*PROGRESS*/
function ShowProgress() {
html = '
';
$("body").append(html);
}
function CloseProgress() {
$('#aProgress').remove();
}
$(document).ajaxStart(function () {
ShowProgress();
});
$(document).ajaxComplete(function () {
CloseProgress();
});
$(document).ajaxError(function () {
CloseProgress();
});
/*VALIDAÇÃO FORMS*/
function ValidaForm(aForm) {
var Campos = '';
if (aForm == '' || isUndefined(aForm)) {
aForm = 'ajax_form';
}
$("#" + aForm + " input[valida='true']").each(function (index) {
if ($.trim($(this).val()) == '') {
if (!$(this).attr("disabled") && !$(this).attr("readonly")) {
$(this).addClass('border-invalid');
Campos += '
* ' + $(this).attr("text-valid");
} else {
$(this).removeClass('border-invalid');
}
}
});
$("#" + aForm + " select[valida='true']").each(function (index) {
if (!$(this).val()) {
if (!$(this).attr("disabled") && !$(this).attr("readonly")) {
$(this).addClass('border-invalid');
Campos += '
* ' + $(this).attr("text-valid");
}
}
});
$("#" + aForm + " input[doc='cpfcnpj']").each(function (index) {
if ($.trim($(this).val()) !== '') {
if (!$(this).attr("disabled") && !$(this).attr("readonly")) {
if (!validaCpfCnpj($.trim($(this).val()))) {
$(this).addClass('border-invalid');
Campos += '
* Informar CPF ou CNPJ Válido';
}
} else {
$(this).removeClass('border-invalid');
}
}
});
$("#" + aForm + " input[tp='mail']").each(function (index) {
if ($.trim($(this).val()) !== '') {
if (!$(this).attr("disabled") && !$(this).attr("readonly")) {
if (!IsEmail($.trim($(this).val()))) {
$(this).addClass('border-invalid');
Campos += '
* Informar E-mail Válido';
}
} else {
$(this).removeClass('border-invalid');
}
}
});
$("#" + aForm + " input[tp='data']").each(function (index) {
if ($.trim($(this).val()) !== '') {
if (!$(this).attr("disabled") && !$(this).attr("readonly")) {
if ($.trim($(this).val()) !== '00/00/0000') {
if (!validateDate($.trim($(this).val()))) {
//$(this).addClass('border-invalid');
var legenda = $("label[for='" + $(this).attr('name') + "']").html();
if (legenda !== '') {
Campos += '
* Informe uma ' + legenda + ' válida';
} else {
Campos += '
* Data Válida';
}
}
}
}
}
});
if (Campos !== '') {
OpenModal(' Campos Obrigatórios
Os campos abaixo devem ser preenchidos !!!
' + Campos);
return false;
}
}
function SelectOptionText(idcombo, valor) {
$("#" + idcombo).val($('option:contains("' + valor + '")').val());
}
function SelectOptionValue(idcombo, valor) {
$('#' + idcombo + ' option[value="' + valor + '"]').attr({
selected: "selected"
});
}
function LimpaForm(Form) {
$('#' + Form).each(function () {
this.reset();
});
}
function SetTitle(NamePage) {
document.title = NamePage + ' - ' + document.title;
}
function SetLS(nome, valor) {
localStorage.setItem(nome, valor);
}
function GetLS(nome) {
var LS;
LS = localStorage.getItem(nome);
if (LS == null) {
return "";
} else {
return LS;
}
}
function ClearLS(nome) {
localStorage.setItem(nome, '');
}
function SaveMenu(ItemMenu) {
SetLS('open_menu', ItemMenu);
}
function OpenMenu() {
var NomeMenu = GetLS('open_menu');
$('#' + NomeMenu).click();
}
function OpenPage(link) {
window.open(link, "_self");
}
function UpperPrime(text) {
if (text !== '') {
var words = text.toLowerCase().split(" ");
for (var a = 0; a < words.length; a++) {
var w = words[a];
words[a] = w[0].toUpperCase() + w.slice(1);
}
return words.join(" ");
}
}
function formatReal(int) {
var tmp = int + '';
tmp = tmp.replace(/([0-9]{2})$/g, ",$1");
if (tmp.length > 6)
tmp = tmp.replace(/([0-9]{3}),([0-9]{2}$)/g, ".$1,$2");
return tmp;
}
function keypressed(obj, e) {
var tecla = (window.event) ? e.keyCode : e.which;
if (tecla == 8 || tecla == 0)
return true;
if (tecla != 44 && tecla < 48 || tecla > 57)
return false;
}
function ValidaData(date) {
var matches = /^(\d{2})[-\/](\d{2})[-\/](\d{4})$/.exec(date);
if (matches == null) return "";
var d = matches[2];
var m = matches[1] - 1;
var y = matches[3];
var composedDate = new Date(y, m, d);
var DtValida = composedDate.getDate() == d && composedDate.getMonth() == m && composedDate.getFullYear() == y;
if (DtValida) {
return date;
}
}
function ValidaDatass(dt) {
var RegExPattern = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02]) [\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
if (!((dt.value.match(RegExPattern)) && (dt.value != ''))) {
return '';
} else {
return dt;
}
}
function ChekUnchek(id) {
$('#' + id).each(function () {
if (this.checked) this.checked = false;
else this.checked = true;
});
}
function marcarTodos(marcardesmarcar) {
var dataTable = $('#rel-table').dataTable();
$(dataTable.fnGetNodes()).each(function () { // https://legacy.datatables.net/ref
$(this).find('input[type="checkbox"]').each(function () {
this.checked = marcardesmarcar;
});
});
}
function formatXml(xml) {
var formatted = '';
var reg = /(>)(<)(\/*)/g;
xml = xml.replace(reg, '$1\r\n$2$3');
var pad = 0;
jQuery.each(xml.split('\r\n'), function (index, node) {
var indent = 0;
if (node.match(/.+<\/\w[^>]*>$/)) {
indent = 0;
} else if (node.match(/^<\/\w/)) {
if (pad != 0) {
pad -= 1;
}
} else if (node.match(/^<\w[^>]*[^\/]>.*$/)) {
indent = 1;
} else {
indent = 0;
}
var padding = '';
for (var i = 0; i < pad; i++) {
padding += ' ';
}
formatted += padding + node + '\r\n';
pad += indent;
});
return formatted;
}
function IsEmail(email) {
var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
if (!er.test(email)) {
return false;
} else {
return true;
}
}
function isUndefined(aVal) {
return (typeof aVal === "undefined");
}
function $val(aId) {
var r = $('#' + aId).val();
return r;
}
function Invert(aText) {
return aText.split('').reverse().join('');
}
function Cript(aText, aTp = 'c') {
return $.ajax({
type: "POST",
url: '../Source/App/Cript.php',
cache: false,
data: {
aText: aText,
aTp: aTp
}
});
}
function MoedaPrint(aValor) {
aValor = parseFloat(aValor);
aValor = aValor.toLocaleString('pt-br', {
minimumFractionDigits: 2
});
return aValor;
}
/*FULL SCREEN*/
function toggleFullscreen(elem) {
elem = elem || document.documentElement;
if (!document.fullscreenElement && !document.mozFullScreenElement &&
!document.webkitFullscreenElement && !document.msFullscreenElement) {
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) {
elem.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
}
function requestFullScreen() {
var el = document.body;
// Supports most browsers and their versions.
var requestMethod = el.requestFullScreen || el.webkitRequestFullScreen ||
el.mozRequestFullScreen || el.msRequestFullScreen;
if (requestMethod) {
// Native full screen.
requestMethod.call(el);
} else if (typeof window.ActiveXObject !== "undefined") {
// Older IE.
var wscript = new ActiveXObject("WScript.Shell");
if (wscript !== null) {
wscript.SendKeys("{F11}");
}
}
}
function Share() {
if (navigator.share !== undefined) {
navigator.share({
title: 'AresDash',
text: 'Gráficos Analíticos em Tempo Real',
url: 'https://aresdash.appg3.com.br/',
})
.then(() => console.log('Successful share'))
.catch((error) => console.log('Error sharing', error));
}
}