File manager - Edit - /var/www/html/portalHomolog/public/pmar/js/demandas.js
Back
(function () { 'use strict'; document.addEventListener('submit', function (e) { var msg = e.target.getAttribute('data-confirm'); if (msg && !window.confirm(msg)) { e.preventDefault(); } }); function dmAutocomplete(opts) { var input = document.getElementById(opts.inputId); var hidden = document.getElementById(opts.hiddenId); var suggest = document.getElementById(opts.suggestId); if (!input || !hidden || !suggest) { return; } var clear = opts.clearId ? document.getElementById(opts.clearId) : null; var tipo = opts.tipoId ? document.getElementById(opts.tipoId) : null; var url = input.getAttribute('data-url') || ''; var timer; function hide() { suggest.classList.add('d-none'); suggest.innerHTML = ''; } function reset() { hidden.value = ''; if (tipo) { tipo.value = ''; } } input.addEventListener('input', function () { reset(); clearTimeout(timer); var q = input.value.trim(); if (q.length < 2) { hide(); return; } timer = setTimeout(function () { fetch(url + '?q=' + encodeURIComponent(q), { headers: { 'Accept': 'application/json', 'X-Requested-With': 'XMLHttpRequest' } }) .then(function (r) { return r.json(); }) .then(function (data) { suggest.innerHTML = ''; if (!data.length) { suggest.classList.add('d-none'); return; } data.forEach(function (item) { var btn = document.createElement('button'); btn.type = 'button'; btn.className = 'list-group-item list-group-item-action py-1 px-2 small'; btn.innerHTML = opts.render ? opts.render(item) : '<strong>' + (item.label || item.nome || item.name) + '</strong>'; btn.addEventListener('click', function () { input.value = item.label || item.nome || item.name; hidden.value = item.id; if (tipo) { tipo.value = item.tipo || ''; } hide(); }); suggest.appendChild(btn); }); suggest.classList.remove('d-none'); }) .catch(function () { }); }, 280); }); input.addEventListener('keydown', function (e) { if (e.key === 'Escape') { hide(); } }); if (clear) { clear.addEventListener('click', function () { input.value = ''; reset(); hide(); }); } document.addEventListener('click', function (e) { if (!suggest.contains(e.target) && e.target !== input) { suggest.classList.add('d-none'); } }); return { input: input, hidden: hidden, tipo: tipo, hide: hide }; } function initKanban() { var root = document.getElementById('demandas-quadro'); if (!root) { return; } var csrf = (document.querySelector('meta[name="csrf-token"]') || {}).content || ''; var urlTpl = root.getAttribute('data-url-mover') || ''; var urlDestTpl = root.getAttribute('data-url-dest-status') || ''; var statusColor = JSON.parse(root.getAttribute('data-status-color') || '{}'); var destStatusMap = { pendente: 'pendente', em_andamento: 'em_andamento', atendido: 'concluido' }; var dragged = null; function toast(msg, type) { var el = document.createElement('div'); el.className = 'alert alert-' + (type || 'success') + ' position-fixed bottom-0 end-0 m-3 shadow'; el.style.zIndex = '2000'; el.setAttribute('role', 'status'); el.textContent = msg; document.body.appendChild(el); setTimeout(function () { el.remove(); }, 3000); } function updateColBadges() { document.querySelectorAll('.dm-kanban-body[data-status]').forEach(function (body) { var badge = document.querySelector('.dm-col-badge[data-col-status="' + body.getAttribute('data-status') + '"]'); if (badge) { badge.textContent = body.querySelectorAll('.dm-kanban-card').length; } }); } document.querySelectorAll('.dm-kanban-card').forEach(function (card) { card.addEventListener('dragstart', function (e) { dragged = card; e.dataTransfer.effectAllowed = 'move'; setTimeout(function () { card.classList.add('opacity-50'); }, 0); }); card.addEventListener('dragend', function () { card.classList.remove('opacity-50'); dragged = null; }); }); document.querySelectorAll('.dm-kanban-body[data-droppable="1"]').forEach(function (col) { col.addEventListener('dragover', function (e) { e.preventDefault(); col.classList.add('dm-drag-over'); }); col.addEventListener('dragleave', function () { col.classList.remove('dm-drag-over'); }); col.addEventListener('drop', function (e) { e.preventDefault(); col.classList.remove('dm-drag-over'); if (!dragged) { return; } var novoStatus = col.getAttribute('data-status'); var demandaId = dragged.getAttribute('data-demanda-id'); var destId = dragged.getAttribute('data-destinatario-id'); col.appendChild(dragged); dragged.style.borderLeftColor = 'var(--bs-' + (statusColor[novoStatus] || 'secondary') + ')'; dragged = null; updateColBadges(); var url, body = new URLSearchParams(); body.append('_token', csrf); if (destId) { var destStatus = destStatusMap[novoStatus]; if (!destStatus) { return; } url = urlDestTpl.replace('__DID__', demandaId).replace('__DESTID__', destId); body.append('_method', 'PATCH'); body.append('status', destStatus); } else { url = urlTpl.replace('__ID__', demandaId); body.append('status', novoStatus); } fetch(url, { method: 'POST', headers: { 'Accept': 'application/json', 'X-Requested-With': 'XMLHttpRequest' }, body: body }).then(function (r) { if (!r.ok) { throw new Error('fail'); } return r.json(); }).then(function (data) { if (!data.ok) { throw new Error('fail'); } toast(root.getAttribute('data-msg-saved') || 'Salvo!', 'success'); }).catch(function () { toast(root.getAttribute('data-msg-error') || 'Erro ao salvar.', 'danger'); }); }); }); } function initDestinatarioForm() { var form = document.getElementById('form-destinatario'); if (!form) { return; } var tipo = document.getElementById('dest-tipo'); var campoUnidade = document.getElementById('dest-campo-unidade'); var campoUsuario = document.getElementById('dest-campo-usuario'); var input = document.getElementById('dest-pessoa-nome'); var hidden = document.getElementById('dest-pessoa-id'); var sugest = document.getElementById('dest-pessoa-sugest'); var urlBusca = form.getAttribute('data-url-buscar'); tipo.addEventListener('change', function () { var isUsuario = this.value === 'usuario'; campoUnidade.classList.toggle('d-none', isUsuario); campoUsuario.classList.toggle('d-none', !isUsuario); hidden.value = ''; input.value = ''; sugest.classList.add('d-none'); sugest.innerHTML = ''; }); var timer; input.addEventListener('input', function () { hidden.value = ''; clearTimeout(timer); var q = input.value.trim(); if (q.length < 2) { sugest.classList.add('d-none'); sugest.innerHTML = ''; return; } timer = setTimeout(function () { fetch(urlBusca + '?q=' + encodeURIComponent(q), { headers: { 'Accept': 'application/json', 'X-Requested-With': 'XMLHttpRequest' } }).then(function (r) { return r.json(); }) .then(function (data) { sugest.innerHTML = ''; if (!data.length) { sugest.classList.add('d-none'); return; } data.forEach(function (u) { var btn = document.createElement('button'); btn.type = 'button'; btn.className = 'list-group-item list-group-item-action py-1 px-2 small'; btn.textContent = u.name + (u.email ? ' — ' + u.email : ''); btn.addEventListener('click', function () { hidden.value = u.id; input.value = u.name; sugest.classList.add('d-none'); }); sugest.appendChild(btn); }); sugest.classList.remove('d-none'); }).catch(function () { }); }, 280); }); document.addEventListener('click', function (e) { if (!sugest.contains(e.target) && e.target !== input) { sugest.classList.add('d-none'); } }); } function initSubtarefas() { var lista = document.getElementById('subtarefas-lista'); if (!lista) { return; } var urlTpl = lista.getAttribute('data-url-toggle') || ''; var csrf = (document.querySelector('meta[name="csrf-token"]') || {}).content || ''; lista.querySelectorAll('.subtarefa-check').forEach(function (chk) { chk.addEventListener('change', function () { var item = chk.closest('.subtarefa-item'); var id = item.getAttribute('data-id'); var url = urlTpl.replace('__ID__', id); var body = new URLSearchParams(); body.append('_token', csrf); body.append('_method', 'PATCH'); chk.disabled = true; fetch(url, { method: 'POST', headers: { 'Accept': 'application/json', 'X-Requested-With': 'XMLHttpRequest' }, body: body, }).then(function (r) { return r.json(); }) .then(function (data) { chk.disabled = false; if (!data.ok) { chk.checked = !chk.checked; return; } var wrap = item.querySelector('.flex-grow-1'); var label = wrap ? wrap.querySelector('span.small') : null; var meta = wrap ? wrap.querySelector('.sub-conclusor') : null; if (label) { label.classList.toggle('text-decoration-line-through', data.concluida); label.classList.toggle('text-muted', data.concluida); } if (data.concluida && data.conclusor) { if (!meta) { meta = document.createElement('div'); meta.className = 'text-muted sub-conclusor'; meta.style.fontSize = '.7rem'; if (wrap) { wrap.appendChild(meta); } } meta.innerHTML = '<i class="fa-solid fa-circle-check text-success"></i> ' + data.conclusor + (data.concluida_em ? ' · ' + data.concluida_em : ''); } else if (meta) { meta.remove(); } var done = lista.querySelectorAll('.subtarefa-check:checked').length; var total = lista.querySelectorAll('.subtarefa-check').length; var bar = document.querySelector('.progress-bar'); var counter = document.querySelector('.dm-subtarefa-counter'); if (bar) { bar.style.width = (total > 0 ? Math.round(done / total * 100) : 0) + '%'; } if (counter) { counter.textContent = done + '/' + total; } }).catch(function () { chk.disabled = false; chk.checked = !chk.checked; }); }); }); } function initTiForm() { var setor = document.getElementById('ti-setor'); var assunto = document.getElementById('ti-assunto'); var subassunto = document.getElementById('ti-subassunto'); var nomeInput = document.getElementById('ti-solicitante-nome'); var idHidden = document.getElementById('ti-solicitante-id'); var tipoHidden = document.getElementById('ti-solicitante-tipo'); var sugest = document.getElementById('ti-solicitante-sugest'); var btnSalvar = document.getElementById('modal-cli-salvar'); if (!setor) { return; } var urlAssuntosTpl = setor.getAttribute('data-url-assuntos') || ''; var urlSubassTpl = assunto ? (assunto.getAttribute('data-url-subassuntos') || '') : ''; var csrf = (document.querySelector('meta[name="csrf-token"]') || {}).content || ''; function setOptions(sel, items, placeholder) { sel.innerHTML = ''; var opt = document.createElement('option'); opt.value = ''; opt.textContent = placeholder; sel.appendChild(opt); items.forEach(function (i) { var o = document.createElement('option'); o.value = i.id; o.textContent = i.nome || i.name; sel.appendChild(o); }); } setor.addEventListener('change', function () { var id = setor.value; setOptions(assunto, [], '— Carregando… —'); setOptions(subassunto, [], '— Selecione o assunto primeiro —'); if (!id) { setOptions(assunto, [], '— Selecione o setor primeiro —'); return; } var url = urlAssuntosTpl.replace('__SETOR__', id); fetch(url, { headers: { 'Accept': 'application/json', 'X-Requested-With': 'XMLHttpRequest' } }) .then(function (r) { return r.json(); }) .then(function (data) { setOptions(assunto, data, '— Selecione —'); }) .catch(function () { setOptions(assunto, [], '— Erro ao carregar —'); }); }); assunto.addEventListener('change', function () { var id = assunto.value; setOptions(subassunto, [], '— Carregando… —'); if (!id) { setOptions(subassunto, [], '— Selecione o assunto primeiro —'); return; } var url = urlSubassTpl.replace('__ASSUNTO__', id); fetch(url, { headers: { 'Accept': 'application/json', 'X-Requested-With': 'XMLHttpRequest' } }) .then(function (r) { return r.json(); }) .then(function (data) { setOptions(subassunto, data, '— Selecione (opcional) —'); }) .catch(function () { setOptions(subassunto, [], '— Erro ao carregar —'); }); }); if (!nomeInput || !sugest) { return; } dmAutocomplete({ inputId: 'ti-solicitante-nome', hiddenId: 'ti-solicitante-id', suggestId: 'ti-solicitante-sugest', clearId: 'ti-solicitante-limpar', tipoId: 'ti-solicitante-tipo', render: function (item) { var badge = item.tipo === 'usuario' ? '<span class="badge bg-secondary ms-1" style="font-size:.6rem">interno</span>' : '<span class="badge bg-info text-dark ms-1" style="font-size:.6rem">externo</span>'; return '<strong>' + (item.nome || item.name) + '</strong>' + badge + (item.extra ? ' <span class="text-muted">· ' + item.extra + '</span>' : ''); } }); if (!btnSalvar) { return; } btnSalvar.addEventListener('click', function () { var nome = (document.getElementById('modal-cli-nome') || {}).value; var erroEl = document.getElementById('modal-cli-erro'); erroEl.classList.add('d-none'); erroEl.textContent = ''; if (!nome || !nome.trim()) { erroEl.textContent = 'O nome é obrigatório.'; erroEl.classList.remove('d-none'); return; } var body = new URLSearchParams(); body.append('_token', csrf); body.append('nome', (document.getElementById('modal-cli-nome') || {}).value || ''); body.append('cpf', (document.getElementById('modal-cli-cpf') || {}).value || ''); body.append('telefone', (document.getElementById('modal-cli-telefone') || {}).value || ''); body.append('email', (document.getElementById('modal-cli-email') || {}).value || ''); btnSalvar.disabled = true; fetch(btnSalvar.getAttribute('data-url'), { method: 'POST', headers: { 'Accept': 'application/json', 'X-Requested-With': 'XMLHttpRequest' }, body: body, }).then(function (r) { if (!r.ok) { return r.json().then(function (d) { throw d; }); } return r.json(); }).then(function (data) { nomeInput.value = data.nome; idHidden.value = data.id; if (tipoHidden) { tipoHidden.value = 'cliente'; } var modal = bootstrap.Modal.getInstance(document.getElementById('modalNovoClienteTi')); if (modal) { modal.hide(); } ['modal-cli-nome', 'modal-cli-cpf', 'modal-cli-telefone', 'modal-cli-email'].forEach(function (id) { var el = document.getElementById(id); if (el) { el.value = ''; } }); btnSalvar.disabled = false; }).catch(function (err) { var msg = (err && err.message) ? err.message : 'Erro ao salvar. Tente novamente.'; erroEl.textContent = msg; erroEl.classList.remove('d-none'); btnSalvar.disabled = false; }); }); } function initEquipamentoVincular() { dmAutocomplete({ inputId: 'eq-busca', hiddenId: 'eq-id', suggestId: 'eq-sugest', render: function (item) { return item.label; } }); } function boot() { initKanban(); initDestinatarioForm(); initSubtarefas(); initTiForm(); initEquipamentoVincular(); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', boot); } else { boot(); } })();
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings