-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
100 lines (80 loc) · 3.32 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var TextRegistro, TextDevolucao, nameFunc;
function submit() {
if(!TextRegistro || !TextDevolucao || !nameFunc){
const modal = new bootstrap.Modal(document.getElementById('ModalWarning'));
modal.show();
}
else{
const number = desmascararTelefone(document.getElementById('numberPhone').value);
const protocolo = document.getElementById('protocol').value;
const tipoMensagem = document.querySelector('input[name="opcao"]:checked').value;
var mensagem;
if (tipoMensagem == 1) { // Registro
mensagem = "https://api.whatsapp.com/send?phone=" + encodeURIComponent(number) + "&text=" +
encodeURIComponent(TextRegistro.replace("{prot}",protocolo).replace("{func}", nameFunc));
}
else if (tipoMensagem == 2) { // Devolução
mensagem = "https://api.whatsapp.com/send?phone=" + encodeURIComponent(number) + "&text=" +
encodeURIComponent(TextDevolucao.replace("{prot}",protocolo).replace("{func}", nameFunc));
}
if (mensagem) {
window.open(mensagem, "_blank"); // Abre a URL no WhatsApp em uma nova aba
} else {
alert("Por favor, selecione uma opção e preencha todos os campos.");
}
}
}
function openSettings(){
const modal = new bootstrap.Modal(document.getElementById('ModalConfiguracoes'));
const modalW = bootstrap.Modal.getInstance(document.getElementById('ModalWarning'));
modalW.hide();
modal.show();
}
function mascararTelefone(input) {
// Remove todos os caracteres que não são números
let telefone = input.value.replace(/\D/g, '');
// Formata o telefone com o padrão (XX) XXXXX-XXXX
if (telefone.length > 10) {
telefone = telefone.replace(/^(\d{2})(\d{5})(\d{4}).*/, '($1) $2-$3');
} else if (telefone.length > 6) {
telefone = telefone.replace(/^(\d{2})(\d{4})(\d{0,4}).*/, '($1) $2-$3');
} else if (telefone.length > 2) {
telefone = telefone.replace(/^(\d{2})(\d{0,5})/, '($1) $2');
} else {
telefone = telefone.replace(/^(\d*)/, '($1');
}
input.value = telefone;
}
function desmascararTelefone(input) {
const numeroDesmascarado = input.replace('(', '').replace(')', '').replace(' ','').replace('-','');
return numeroDesmascarado;
}
function saveChanges() {
const inputTextReg = document.getElementById("inputTextReg").value;
const inputTextDevol = document.getElementById("inputTextDevol").value;
const inputName = document.getElementById("inputName").value;
let mensagem = "";
if (inputTextReg) {
TextRegistro = inputTextReg;
mensagem += "Texto Registro alterado.\n";
}
if (inputTextDevol) {
TextDevolucao = inputTextDevol;
mensagem += "Texto Devolução alterado.\n";
}
if (inputName) {
nameFunc = inputName;
mensagem += "Nome funcionario alterado.\n";
}
if (!inputTextReg && !inputTextDevol) {
mensagem = "Nenhuma mudança foi feita.";
}
alert(mensagem);
}
function valueChange() {
if(TextDevolucao && TextRegistro && nameFunc){
document.getElementById("inputTextReg").value = TextRegistro;
document.getElementById("inputTextDevol").value = TextDevolucao;
document.getElementById("inputNmae").value = nameFunc;
}
}