Browse Source

Merge pull request 'Páginas de pesquisa carregando mais rápido, implementei botão de excluir opção da pesquisa.' (#4) from Claudio/pabx-pesquisa:dev into master

Reviewed-on: SimplesIP/pabx-pesquisa#4
master
Claudio 4 months ago
parent
commit
e16d1d9e75
  1. 8
      .vscode/settings.json
  2. 12
      etc_asterisk/extensions_rotas_entrada.conf
  3. 14
      www/html/aplicativo/cadastros/pesquisa/pesquisa.php
  4. 931
      www/html/aplicativo/cadastros/pesquisa/pesquisaCad.php
  5. 31
      www/html/aplicativo/cadastros/pesquisa/pesquisaFuncoes.php
  6. 941
      www/html/aplicativo/cadastros/pesquisa/pesquisaRel.php
  7. 636
      www/html/aplicativo/contacteFunc.php
  8. 603
      www/html/aplicativo/scriptApl/pesquisa/index.js

8
.vscode/settings.json vendored

@ -0,0 +1,8 @@
{
"editor.tabSize": 4,
"files.encoding": "iso88591",
"[javascript]": {
"editor.tabSize": 4,
},
"prettier.tabWidth": 4
}

12
etc_asterisk/extensions_rotas_entrada.conf

@ -1,6 +1,6 @@
[entrada-VEIRTA-SIP]
include => entrada-VEIRTA-SIP-custom
exten => _90XX,1,Set(CDR(direcao)=E)
exten => _90XX,n,Set(__TIPO=EXTERNA)
exten => _90XX,n,AGI(${INTEGRACAO},7,${IF($[ "X${CALLERID(NUM)}" = "X" ]? "-" : ${CALLERID(NUM):-11})},${UNIQUEID},${IDORIGEM},${URA})
exten => _90XX,n,Hangup()
[entrada-VERITA_LOCAL]
include => entrada-VERITA_LOCAL-custom
exten => _9XXX,1,Set(CDR(direcao)=E)
exten => _9XXX,n,Set(__TIPO=EXTERNA)
exten => _9XXX,n,AGI(${INTEGRACAO},7,${IF($[ "X${CALLERID(NUM)}" = "X" ]? "-" : ${CALLERID(NUM):-11})},${UNIQUEID},${IDORIGEM},${URA})
exten => _9XXX,n,Hangup()

14
www/html/aplicativo/cadastros/pesquisa/pesquisa.php

@ -31,8 +31,8 @@ $imgNovo = "<a href=\"javaScript:NovaJanela('index.php?idProg=182&pp_id=0', 'pes
try {
if ($ajax){
if ($ajax) {
$response = isCloning($dbcon);
echo json_encode(['clone' => $response], true);
exit;
@ -152,9 +152,9 @@ while ($dados = pg_fetch_array($result)) {
$imgBlock = "<img src=\"imgSite/cadeado.gif\" width=\"12\" height=\"12\" border=\"0\">";
$imgDelete = $block ? $imgBlock : sprintf("<a href=\"javaScript:DeletaPesquisa('%s', '%s', '$params');\">%s</a>", $pp_id, $pp_nome, $imgDelete);
$imgClone = existeClonagemProcessando($pp_id) ? "<a title=\"Processando Clonagem\" onclick=\"return alert(' existe uma clonagem em andamento para esta pesquisa!')\"><img src=\"imgSite/Aguarde1.gif\" width=\"12\" height=\"12\" border=\"0\"></a>"
: "<a href=\"index.php?idProg=181&pp_id=$pp_id&action=clone\" title=\"Clonar pesquisa\" onclick=\"return confirm('Deseja clonar a pesquisa?')\"><img src=\"imgSite/recicle.png\" width=\"12\" height=\"12\" border=\"0\"></a>";
: "<a href=\"index.php?idProg=181&pp_id=$pp_id&action=clone\" title=\"Clonar pesquisa\" onclick=\"return confirm('Deseja clonar a pesquisa?')\"><img src=\"imgSite/recicle.png\" width=\"12\" height=\"12\" border=\"0\"></a>";
$imgLibera = "<a href=\"javaScript:NovaJanela('index.php?idProg=186&pp_id=$pp_id&pl_id=0')\" title=\"Liberar pesquisa\"><img src=\"imgSite/Unlock.png\" width=\"12\" height=\"12\ border=\"0\"></a>";
$linha .= trim("<tr>
@ -212,7 +212,6 @@ function preparaClonarPesquisa($ppId)
$jsJQuery[] = "let isCloning = true;";
pg_query($dbcon, 'commit;');
}
function existeClonagemProcessando($ppId)
@ -229,9 +228,10 @@ function existeClonagemProcessando($ppId)
}
}
function isCloning($dbcon){
function isCloning($dbcon)
{
$query = "SELECT COUNT(*) AS clone FROM pbx_pesquisa_clone";
$result = pg_query($dbcon, $query);
$response = pg_fetch_assoc($result);
return $response['clone'];
}
}

931
www/html/aplicativo/cadastros/pesquisa/pesquisaCad.php

File diff suppressed because it is too large Load Diff

31
www/html/aplicativo/cadastros/pesquisa/pesquisaFuncoes.php

@ -4,10 +4,19 @@
* Function interna
*/
function GetPesquisaRel($db, $plId, $matricula = null) {
define("LOG_PATH", '/var/log/asterisk/relatorio_pesquisaRel.log');
function GetPesquisaRel($db, $plId, $matricula = null)
{
$ret = "";
$sel = "";
$query = sprintf("SELECT DISTINCT a.pl_id, pl_descricao, pl_data_inicio, pl_data_fim, b.pp_id, b.pp_nome
//reduzi os filtros da query porque estava extremamente lenta, demorando 300 segundos para executar.
$query = "SELECT a.pl_id, pl_descricao, pl_data_inicio, pl_data_fim, b.pp_id, b.pp_nome
FROM pbx_pesquisa_liberacao a
INNER JOIN pbx_pesquisa b ON a.pp_id = b.pp_id
ORDER BY a.data_reg DESC";
//query antiga
/* $query = sprintf("SELECT DISTINCT a.pl_id, pl_descricao, pl_data_inicio, pl_data_fim, b.pp_id, b.pp_nome
FROM pbx_pesquisa_liberacao a
INNER JOIN pbx_pesquisa b ON a.pp_id = b.pp_id
INNER JOIN pbx_pesquisa_movimento f ON a.pp_id = f.pp_id
@ -15,10 +24,13 @@ function GetPesquisaRel($db, $plId, $matricula = null) {
INNER JOIN pbx_grupo_usuario d ON d.user_id = c.id
INNER JOIN pbx_fila_grupos e ON e.gp_id = d.gp_id
WHERE EXISTS(SELECT '' FROM pbx_pesquisa_movimento WHERE pl_id = a.pl_id AND e.id = id_dac)
%s", $matricula ? "and c.matricula = '$matricula'" : "");
$query .= " ORDER BY b.pp_nome";
%s", $matricula ? " and c.matricula = '$matricula'" : "");
$query .= " ORDER BY a.data_reg DESC"; */
//$query .= " ORDER BY b.pp_nome";
$result = pg_query($db, $query);
file_put_contents(LOG_PATH, "\nQuery: $query\n", FILE_APPEND);
if (!$plId) {
$ret = '<option value="0" selected="selected">---------------------</option>';
}
@ -31,7 +43,8 @@ function GetPesquisaRel($db, $plId, $matricula = null) {
return $ret;
}
function GetDadosPesq($db, $lst, &$plId, &$plDescricao, &$ppId, &$ppNome, &$datas) {
function GetDadosPesq($db, $lst, &$plId, &$plDescricao, &$ppId, &$ppNome, &$datas)
{
$dados = explode("|", $lst);
$plId = $dados[0];
$plDescricao = $dados[1];
@ -41,7 +54,8 @@ function GetDadosPesq($db, $lst, &$plId, &$plDescricao, &$ppId, &$ppNome, &$data
$ppNome = $dados[5];
}
function GetPesquisaDac($db, $idDac) {
function GetPesquisaDac($db, $idDac)
{
$ret = "";
$sel = "";
$login = GetLogin();
@ -67,7 +81,8 @@ function GetPesquisaDac($db, $idDac) {
return $ret;
}
function GetPesquisaAgente($db, $plId, $matricula, $idDac, $dtIni, $dtFim, $incTodos) {
function GetPesquisaAgente($db, $plId, $matricula, $idDac, $dtIni, $dtFim, $incTodos)
{
$ret = "";
$sel = "";
$dataIni = soNumero($dtIni) == "" ? "null" : "'$dtIni'";
@ -104,5 +119,3 @@ function GetPesquisaAgente($db, $plId, $matricula, $idDac, $dtIni, $dtFim, $incT
$ret = '<option value="0" selected="selected">---------------------</option>';
return $ret;
}
?>

941
www/html/aplicativo/cadastros/pesquisa/pesquisaRel.php

File diff suppressed because it is too large Load Diff

636
www/html/aplicativo/contacteFunc.php

File diff suppressed because it is too large Load Diff

603
www/html/aplicativo/scriptApl/pesquisa/index.js

@ -7,208 +7,310 @@ const request = ({ url, type, data }, handle) => {
error: function (err) {
console.log(err);
},
})
}
});
};
const buildResponse = (qst, opc) => {
return `<tr>
<td colspan="3"> &nbsp;&nbsp;
<input name="po_id[${qst}][${opc}]" type="number" value="791" hidden="true">
${opc}) <input name="qst_tecla[${qst}][${opc}]" class="qst_tecla" type="number" value="2" size="4" maxlength="2" min="0" max="999" required="" style="width:60px">
<input name="qst_descricao[${qst}][${opc}]" type="text" value="NÃO" title="Descreva aqui a opção" size="50" style="width:360px" maxlength="60" required="">
<input name="qst_descricao[${qst}][${opc}]" type="text" value="NãO" title="Descreva aqui a opção" size="50" style="width:360px" maxlength="60" required="">
</td>
</tr>`;
}
const optionResponse = (num, numEle) => {
$('#box' + num + ' input[name="qst_tecla[' + numEle + '][1]"]').prop('name', 'qst_tecla[' + num + '][1]')
$('#box' + num + ' input[name="qst_descricao[' + numEle + '][1]"]').prop('name', 'qst_descricao[' + num + '][1]')
$('#box' + num + ' input[name="qst_tecla[' + numEle + '][2]"]').prop('name', 'qst_tecla[' + num + '][2]')
$('#box' + num + ' input[name="qst_descricao[' + numEle + '][2]"]').prop('name', 'qst_descricao[' + num + '][2]')
if($("#pqt_id").val() == 2 && !$('#pp_id').val()){
$(`#tableResponse${num} tr:nth-last-child(1)`).remove()
$(`#box${num} #addResponse`+ numEle).remove()
};
const optionResponse = (num, numEle) => {
$("#box" + num + ' input[name="qst_tecla[' + numEle + '][1]"]').prop("name", "qst_tecla[" + num + "][1]");
$("#box" + num + ' input[name="qst_descricao[' + numEle + '][1]"]').prop("name", "qst_descricao[" + num + "][1]");
$("#box" + num + ' input[name="qst_tecla[' + numEle + '][2]"]').prop("name", "qst_tecla[" + num + "][2]");
$("#box" + num + ' input[name="qst_descricao[' + numEle + '][2]"]').prop("name", "qst_descricao[" + num + "][2]");
if ($("#pqt_id").val() == 2 && !$("#pp_id").val()) {
$(`#tableResponse${num} tr:nth-last-child(1)`).remove();
$(`#box${num} #addResponse` + numEle).remove();
}
if ($('#count' + numEle).val() == 1) {
$("#tableResponse" + num).append(buildResponse(num, 2))
if ($("#count" + numEle).val() == 1) {
$("#tableResponse" + num).append(buildResponse(num, 2));
}
}
};
const __resizeForms = () => {
const elements = ['body']
elements.forEach(e => {
const elements = ["body"];
elements.forEach((e) => {
let alturaJanela = $(e).height();
let novaAltura = alturaJanela * 1.2;
let novaLargura = novaAltura * 1.5;
// window.resizeTo(novaLargura, novaAltura);
})
}
let novaLargura = novaAltura * 1.5;
// window.resizeTo(novaLargura, novaAltura);
});
};
const createDeleteOptionBtn = (pq_index, po_index) => {
return $(
'<a href="#" id="delOp_' +
pq_index +
"|" +
po_index +
'" ><img id="delOpc_' +
pq_index +
"|" +
po_index +
'" src="imgSite/fecha16.png" width="12" height="12" border="0" align="absmiddle"></a>'
);
};
$(function () {
let ultimoEle = null
let ultimoEle = null;
const ppId = $("#pp_id").val();
$(".box").slideToggle("fast");
let el = document.getElementById("questions");
__resizeForms();
$('.box').slideToggle('fast')
let el = document.getElementById('questions');
__resizeForms()
if($('#pqt_id').prop('disabled')){
if ($("#pqt_id").prop("disabled")) {
$("#newquestion").show();
}
$('#pqt_id').change(function() {
if($(this).val() > 0){
$("#pqt_id").change(function () {
if ($(this).val() > 0) {
$("#labelQuestoes").show();
$("#newquestion").show();
$("#questions").show();
} else {
$("#labelQuestoes").hide()
$("#newquestion").hide()
$("#questions").hide()
$("#labelQuestoes").hide();
$("#newquestion").hide();
$("#questions").hide();
}
if($(this).val() == 2){
$('#addResponse1').hide()
$("#box1 #tableResponse1 tr:nth-last-child(1) td").hide()
$('#box1 input[name="qst_tecla[1][2]"]').hide()
$('#box1 input[name="qst_descricao[1][2]"]').hide()
$('#box1 #pq_tipo1').hide()
$('#box1 #pq_tipol1').hide()
} else{
$('#addResponse1').show()
$("#box1 #tableResponse1 tr:nth-last-child(1) td").show()
$('#box1 input[name="qst_tecla[1][2]"]').show()
$('#box1 input[name="qst_descricao[1][2]"]').show()
$('#box1 #pq_tipo1').show()
$('#box1 #pq_tipol1').show()
if ($(this).val() == 2) {
$("#addResponse1").hide();
$("#box1 #tableResponse1 tr:nth-last-child(1) td").hide();
$('#box1 input[name="qst_tecla[1][2]"]').hide();
$('#box1 input[name="qst_descricao[1][2]"]').hide();
$("#box1 #pq_tipo1").hide();
$("#box1 #pq_tipol1").hide();
} else {
$("#addResponse1").show();
$("#box1 #tableResponse1 tr:nth-last-child(1) td").show();
$('#box1 input[name="qst_tecla[1][2]"]').show();
$('#box1 input[name="qst_descricao[1][2]"]').show();
$("#box1 #pq_tipo1").show();
$("#box1 #pq_tipol1").show();
}
})
});
$('#btGravar').click(function () {
$('#formGeral').find('input[type="file"]').each(function () {
if (!$(this).val() && !$('#pp_id').val()) {
alert('Existe campos de áudios que não foram preenchidos, por favor, verifique todos os dados repassados!');
return;
}
});
$("#btGravar").click(function () {
$("#formGeral")
.find('input[type="file"]')
.each(function () {
if (!$(this).val() && !$("#pp_id").val()) {
alert("Existe campos de áudios que não foram preenchidos, por favor, verifique todos os dados repassados!");
return;
}
});
});
el.addEventListener('click', function (e) {
if (e.target.id.indexOf('animate') >= 0) {
let numBox = e.target.id.replace('animate', '')
let box = $('#box' + numBox);
let qtdRow = $("#tableResponse" + numBox + " tr").length
$("#box" + numBox + " div.scrollingArea").height(320 + (Number(qtdRow) * 25))
if (box.is(':visible')) {
box.slideToggle('slow');
$('#' + e.target.id).attr("src", "imgSite/expand.jpg");
$('#labelRotas' + numBox).text(" Exibir Questão");
el.addEventListener("click", function (e) {
if (e.target.id.indexOf("animate") >= 0) {
let numBox = e.target.id.replace("animate", "");
let box = $("#box" + numBox);
let qtdRow = $("#tableResponse" + numBox + " tr").length;
$("#box" + numBox + " div.scrollingArea").height(320 + Number(qtdRow) * 25);
if (box.is(":visible")) {
box.slideToggle("slow");
$("#" + e.target.id).attr("src", "imgSite/expand.jpg");
$("#labelRotas" + numBox).text(" Exibir Questão");
} else {
$('#' + e.target.id).attr("src", "imgSite/collapse.jpg");
$('#labelRotas' + numBox).text(" Ocultar Questão");
box.slideToggle('slow');
$("#" + e.target.id).attr("src", "imgSite/collapse.jpg");
$("#labelRotas" + numBox).text(" Ocultar Questão");
box.slideToggle("slow");
}
}
if (e.target.id.indexOf('delOpc') >= 0) {
let numDelOpc = e.target.id.replace('delOpc_', '')
let nums = numDelOpc.split("|")
let ct = $("#count" + nums[0]).val()
$("#count" + nums[0]).val(Number(ct) - 1)
$("#tableResponse" + nums[0] + " tr:nth-last-child(1)").remove()
if (ct > 3) {
$("#tableResponse" + nums[0] + ' tbody tr:nth-last-child(1) td').append(ultimoEle)
}
if ($("#tableResponse" + nums[0] + " tr").length == 3){
$("#pq_tipo" + nums[0]).show()
$("#pq_tipol" + nums[0]).show()
if (e.target.id.indexOf("delOpc") >= 0) {
e.preventDefault();
let numDelOpc = e.target.id.replace("delOpc_", "");
let nums = numDelOpc.split("|");
//nums[0]: indice da questao. Inicia com 1.
//nums[1]: indice da opcao
//requisicao ajax para excluir a questao do banco
request(
{
type: "POST",
url: `index.php?idProg=182&ajax=1&a=delOption`,
data: { pp_id: ppId, pq_index: nums[0], po_index: nums[1] },
},
function (res) {
if (res.error === false) {
// ct recebe o numero de opcoes que a pesquisa atual possui
let ct = $("#count" + nums[0]).val();
$("#count" + nums[0]).val(Number(ct) - 1);
$("#tableResponse" + nums[0] + " tr:nth-last-child(1)").remove();
if (ct > 3) {
const deleteBtn = createDeleteOptionBtn(nums[0], nums[1] - 1);
$("#tableResponse" + nums[0] + " tbody tr:nth-last-child(1) td").append(deleteBtn);
}
} else {
window.alert("Não foi possível excluir a opção.");
}
}
);
if ($("#tableResponse" + nums[0] + " tr").length == 3) {
$("#pq_tipo" + nums[0]).show();
$("#pq_tipol" + nums[0]).show();
}
}
if (e.target.id.indexOf('addResponse') >= 0) {
e.preventDefault()
let numTable = e.target.id.replace('addResponse', '')
$('#pq_tipo' + numTable).hide()
$('#pq_tipol' + numTable).hide()
let ct = $("#count" + numTable).val()
if (e.target.id.indexOf("addResponse") >= 0) {
e.preventDefault();
let numTable = e.target.id.replace("addResponse", "");
$("#pq_tipo" + numTable).hide();
$("#pq_tipol" + numTable).hide();
let ct = $("#count" + numTable).val();
let htg = $("#box" + numTable + " .scrollingArea").height()
$("#box" + numTable + " div.scrollingArea").height(Number(htg) + 25)
let htg = $("#box" + numTable + " .scrollingArea").height();
$("#box" + numTable + " div.scrollingArea").height(Number(htg) + 25);
ct = ct > 1 ? ct : 2;
ct++
let strSpace = ct > 9 ? " &nbsp;" : " &nbsp;&nbsp; "
$("#tableResponse" + numTable).append('<tr><td colspan="3">' + strSpace + ct + ')\n\
<input name="po_id[' + numTable + '][' + ct + ']" type="number" value="" hidden="true">\n\
<input name="qst_tecla[' + numTable + '][' + ct + ']" class="qst_tecla" type="number" value="" size="4" maxlength="2" min="0" max="999" style="width:60px" required>\n\
<input name="qst_descricao[' + numTable + '][' + ct + ']" type="text" value="" title="Descreva aqui a opção" size="50" style="width:360px" maxlength="60" required>\n\
ct++;
let strSpace = ct > 9 ? " &nbsp;" : " &nbsp;&nbsp; ";
$("#tableResponse" + numTable).append(
'<tr><td colspan="3">' +
strSpace +
ct +
')\n\
<input name="po_id[' +
numTable +
"][" +
ct +
']" type="number" value="" hidden="true">\n\
<input name="qst_tecla[' +
numTable +
"][" +
ct +
']" class="qst_tecla" type="number" value="" size="4" maxlength="2" min="0" max="999" style="width:60px" required>\n\
<input name="qst_descricao[' +
numTable +
"][" +
ct +
']" type="text" value="" title="Descreva aqui a opção" size="50" style="width:360px" maxlength="60" required>\n\
</td>\n\
</tr>')
let novoEle = $('<a href="#" id="delOp_' + numTable + '|' + ct + '" ><img id="delOpc_' + numTable + '|' + ct + '" src="imgSite/fecha16.png" width=\"12\" height=\"12\" border=\"0\" align=\"absmiddle\"></a>')
$("#tableResponse" + numTable + ' tbody tr:nth-last-child(1) td').append(novoEle)
</tr>'
);
// novo botao de excluir opcao
let novoEle = $(
'<a href="#" id="delOp_' +
numTable +
"|" +
ct +
'" ><img id="delOpc_' +
numTable +
"|" +
ct +
'" src="imgSite/fecha16.png" width="12" height="12" border="0" align="absmiddle"></a>'
);
//removendo botao anterior de excluir opcao
const prev = ct - 1;
$("#delOp_" + numTable + "\\|" + prev).remove();
$("#tableResponse" + numTable + " tbody tr:nth-last-child(1) td").append(novoEle);
if (ct > 3) {
$(ultimoEle).remove()
$(ultimoEle).remove();
}
ultimoEle = novoEle
$("#count" + numTable).val(ct)
ultimoEle = novoEle;
$("#count" + numTable).val(ct);
}
if (e.target.id.indexOf('addAudio') >= 0) {
let q = e.target.id.replace('addAudio', '')
let v = $('#countAudio' + q).val() ? $('#countAudio' + q).val() : 1;
$('#audioQuestion' + q).append('<tr><td><span style="font-size: 12px"><b>Áudio (' + v + '):</b></span></td><td><input type="file" name="pp_audio[' + q + '][' + v + ']" title="Informe um audio para questão" size="40" style="width:560px" required/> &nbsp;&nbsp; <a href="#" id="delAudio' + v + '" title="DELETAR ÁUDIO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteAudio' + q + '|' + v + '"/></a></td></tr>')
$('#countAudio' + q).val(Number(v) + 1)
let htg = $("#box" + q + " .scrollingArea").height()
$("#box" + q + " div.scrollingArea").height(Number(htg) + 25)
$('#delAudio' + (v - 1)).remove()
if (e.target.id.indexOf("addAudio") >= 0) {
let q = e.target.id.replace("addAudio", "");
let v = $("#countAudio" + q).val() ? $("#countAudio" + q).val() : 1;
$("#audioQuestion" + q).append(
'<tr><td><span style="font-size: 12px"><b>áudio (' +
v +
'):</b></span></td><td><input type="file" name="pp_audio[' +
q +
"][" +
v +
']" title="Informe um audio para questão" size="40" style="width:560px" required/> &nbsp;&nbsp; <a href="#" id="delAudio' +
v +
'" title="DELETAR ÁUDIO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteAudio' +
q +
"|" +
v +
'"/></a></td></tr>'
);
$("#countAudio" + q).val(Number(v) + 1);
let htg = $("#box" + q + " .scrollingArea").height();
$("#box" + q + " div.scrollingArea").height(Number(htg) + 25);
$("#delAudio" + (v - 1)).remove();
}
if (e.target.id.indexOf('deleteAudio') >= 0) {
let q = e.target.id.replace('deleteAudio', '').split("|")
let v = $('#countAudio' + q[0]).val();
$('#countAudio' + q[0]).val(Number(v) - 1)
$('#audioQuestion' + q[0] + ' tr:nth-last-child(1)').remove()
if ((q[1] - 1) > 0) {
$('#audioQuestion' + q[0] + ' tr:nth-last-child(1) td:nth-last-child(1)').append('<a href="#" id="delAudio' + (q[1] - 1) + '" title="DELETAR ÁUDIO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteAudio' + q[0] + '|' + (q[1] - 1) + '"/></a>')
if (e.target.id.indexOf("deleteAudio") >= 0) {
let q = e.target.id.replace("deleteAudio", "").split("|");
let v = $("#countAudio" + q[0]).val();
$("#countAudio" + q[0]).val(Number(v) - 1);
$("#audioQuestion" + q[0] + " tr:nth-last-child(1)").remove();
if (q[1] - 1 > 0) {
$("#audioQuestion" + q[0] + " tr:nth-last-child(1) td:nth-last-child(1)").append(
'<a href="#" id="delAudio' +
(q[1] - 1) +
'" title="DELETAR ÁUDIO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteAudio' +
q[0] +
"|" +
(q[1] - 1) +
'"/></a>'
);
}
}
if (e.target.id.indexOf('deleteQuestion') >= 0) {
let q = e.target.id.replace('deleteQuestion', '').split('|')
if (e.target.id.indexOf("deleteQuestion") >= 0) {
let q = e.target.id.replace("deleteQuestion", "").split("|");
let question = q[0];
let display = q[1];
let ppId = $("#pp_id").val()
request({type: 'POST', url: `index.php?idProg=182&ajax=1&a=delQuestion`, data: {pp_id: ppId, pq_id: question}}, function (res) {
if (res.error === false) {
let oldDisplay = (display - 1)
let oldpqId = $('input[name="count_descricao[' + oldDisplay + ']"]').val()
if (oldDisplay > 1) {
let selector = `<td align="right"><a href="#" id="delQuestion${oldDisplay}" title="DELETAR QUESTÃO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteQuestion${oldpqId}|${oldDisplay}"/></a></td>`;
$('#collapse' + oldDisplay + ' #cabRota table tbody tr:nth-last-child(1)').append(selector)
let ppId = $("#pp_id").val();
request(
{
type: "POST",
url: `index.php?idProg=182&ajax=1&a=delQuestion`,
data: { pp_id: ppId, pq_id: question },
},
function (res) {
if (res.error === false) {
let oldDisplay = display - 1;
let oldpqId = $('input[name="count_descricao[' + oldDisplay + ']"]').val();
if (oldDisplay > 1) {
let selector = `<td align="right"><a href="#" id="delQuestion${oldDisplay}" title="DELETAR QUESTÃO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteQuestion${oldpqId}|${oldDisplay}"/></a></td>`;
$("#collapse" + oldDisplay + " #cabRota table tbody tr:nth-last-child(1)").append(selector);
}
$("#collapse" + display).remove();
}
$('#collapse' + display).remove();
}
})
);
}
if (e.target.id.indexOf('deleteNewQuestion') >= 0) {
let q = e.target.id.replace('deleteNewQuestion', '')
let novoEle = null
if (e.target.id.indexOf("deleteNewQuestion") >= 0) {
let q = e.target.id.replace("deleteNewQuestion", "");
let novoEle = null;
$("#collapse" + q).remove();
let labelPergunta = $('#collapse' + (q - 1) + ' #cabRota #labelPergunta').text()
//Validacao para que a primeira pergunta nao seja possivel de remover "(q - 1) > 1"
if (!labelPergunta && (q - 1) > 1) {
let novoEle = $('<td align="right"><a href="#" id="delnewQuestion' + (q - 1) + '" title="DELETAR QUESTÃO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteNewQuestion' + (q - 1) + '" /></a><td>')
$('#collapse' + (q - 1) + ' #cabRota table tbody tr:nth-last-child(1)').append(novoEle)
$('#collapse' + (q - 1) + ' #cabRota table tbody tr td:nth-last-child(1)').remove()
let labelPergunta = $("#collapse" + (q - 1) + " #cabRota #labelPergunta").text();
//Validacao para que a primeira pergunta nao seja possivel de remover "(q - 1) > 1"
if (!labelPergunta && q - 1 > 1) {
let novoEle = $(
'<td align="right"><a href="#" id="delnewQuestion' +
(q - 1) +
'" title="DELETAR QUESTãO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteNewQuestion' +
(q - 1) +
'" /></a><td>'
);
$("#collapse" + (q - 1) + " #cabRota table tbody tr:nth-last-child(1)").append(novoEle);
$("#collapse" + (q - 1) + " #cabRota table tbody tr td:nth-last-child(1)").remove();
}
}
});
@ -216,126 +318,143 @@ $(function () {
$("#newquestion").click(function () {
let div = $('div[id^="collapse"]:last');
let num = parseInt(div.prop("id").match(/\d+/g), 10) + 1;
let numEle = (num - 1)
$('#pqt_id').prop("readonly", true );
$('#pqt_id').css({"pointer-events": "none", opacity: 0.5})
//REMOVE O BOTÃO DE DELETE
$('#collapse' + numEle + ' #cabRota table tbody tr td:nth-child(3)').remove()
$('#collapse' + numEle).clone().prop('id', 'collapse' + num).appendTo('#questions');
$('#collapse' + num + ' #box' + numEle).prop('id', 'box' + num)
$('#collapse' + num + ' #animate' + numEle).prop('id', 'animate' + num)
$('#collapse' + num + ' #labelRotas' + numEle).prop('id', 'labelRotas' + num)
$('#collapse' + num + ' #labelPergunta').text('')
//RECRIAÇÃO DOS IDS E NAMES PARA O NOVO FORM
$('#box' + num + ' #pq_tipo' + numEle).prop('id', 'pq_tipo' + num).show()
$('#box' + num + ' #pq_tipol' + numEle).prop('id', 'pq_tipol' + num).show()
$('#pq_tipo' + num).removeAttr('checked')
$('#box' + num + ' input[name="qst_descricao[' + numEle + '][0]"]').prop('name', 'qst_descricao[' + num + '][0]')
$('#box' + num + ' input[name="pq_tipo[' + numEle + ']"').prop('name', 'pq_tipo[' + num + ']')
$('#box' + num + ' input[name="pp_audio[' + numEle + '][0]"]').prop('name', 'pp_audio[' + num + '][0]')
$('#box' + num + ' input[name="pp_audio[' + num + '][0]"]').prop('required',true);
$('#box' + num + ' input[name="pp_audio[' + num + '][0]"]').prop('id', num)
$('#box' + num + ' input[name="pp_audio[' + num + '][0]"]').val('')
$('#box' + num + ' #escuta_audio' + numEle).remove()
$('#box' + num + ' input[name="po_id[' + numEle + '][1]"]').prop('name', 'po_id[' + num + '][1]')
$('#box' + num + ' input[name="po_id[' + numEle + '][2]"]').prop('name', 'po_id[' + num + '][2]')
$('#box' + num + ' select[name="qst_opcoes[' + numEle + '][1]"]').remove()
$('#box' + num + ' select[name="qst_opcoes[' + numEle + '][2]"]').remove()
$('#box' + num + ' input[name="count_descricao[' + numEle + ']"]').prop('name', 'count_descricao[' + num + ']')
$('#box' + num + ' #tableResponse' + numEle).prop('id', 'tableResponse' + num)
$('#box' + num + ' #addResponse' + numEle).prop('id', 'addResponse' + num)
$('#addResponse' + num).show()
optionResponse(num, numEle)
$('#box' + num + ' #countAudio' + numEle).prop('id', 'countAudio' + num).prop('value', 1)
$('#box' + num + ' #audioQuestion' + numEle).prop('id', 'audioQuestion' + num);
$('#box' + num + ' #viewAudio' + numEle).prop('id', 'viewAudio' + num);
$('#box' + num + ' #addAudio' + numEle).prop('id', 'addAudio' + num);
$('table#audioQuestion' + num + ' tbody tr').each(function (indice) {
let numEle = num - 1;
$("#pqt_id").prop("readonly", true);
$("#pqt_id").css({ "pointer-events": "none", opacity: 0.5 });
//REMOVE O BOTãO DE DELETE
$("#collapse" + numEle + " #cabRota table tbody tr td:nth-child(3)").remove();
$("#collapse" + numEle)
.clone()
.prop("id", "collapse" + num)
.appendTo("#questions");
$("#collapse" + num + " #box" + numEle).prop("id", "box" + num);
$("#collapse" + num + " #animate" + numEle).prop("id", "animate" + num);
$("#collapse" + num + " #labelRotas" + numEle).prop("id", "labelRotas" + num);
$("#collapse" + num + " #labelPergunta").text("");
//RECRIAãO DOS IDS E NAMES PARA O NOVO FORM
$("#box" + num + " #pq_tipo" + numEle)
.prop("id", "pq_tipo" + num)
.show();
$("#box" + num + " #pq_tipol" + numEle)
.prop("id", "pq_tipol" + num)
.show();
$("#pq_tipo" + num).removeAttr("checked");
$("#box" + num + ' input[name="qst_descricao[' + numEle + '][0]"]').prop("name", "qst_descricao[" + num + "][0]");
$("#box" + num + ' input[name="pq_tipo[' + numEle + ']"').prop("name", "pq_tipo[" + num + "]");
$("#box" + num + ' input[name="pp_audio[' + numEle + '][0]"]').prop("name", "pp_audio[" + num + "][0]");
$("#box" + num + ' input[name="pp_audio[' + num + '][0]"]').prop("required", true);
$("#box" + num + ' input[name="pp_audio[' + num + '][0]"]').prop("id", num);
$("#box" + num + ' input[name="pp_audio[' + num + '][0]"]').val("");
$("#box" + num + " #escuta_audio" + numEle).remove();
$("#box" + num + ' input[name="po_id[' + numEle + '][1]"]').prop("name", "po_id[" + num + "][1]");
$("#box" + num + ' input[name="po_id[' + numEle + '][2]"]').prop("name", "po_id[" + num + "][2]");
$("#box" + num + ' select[name="qst_opcoes[' + numEle + '][1]"]').remove();
$("#box" + num + ' select[name="qst_opcoes[' + numEle + '][2]"]').remove();
$("#box" + num + ' input[name="count_descricao[' + numEle + ']"]').prop("name", "count_descricao[" + num + "]");
$("#box" + num + " #tableResponse" + numEle).prop("id", "tableResponse" + num);
$("#box" + num + " #addResponse" + numEle).prop("id", "addResponse" + num);
$("#addResponse" + num).show();
optionResponse(num, numEle);
$("#box" + num + " #countAudio" + numEle)
.prop("id", "countAudio" + num)
.prop("value", 1);
$("#box" + num + " #audioQuestion" + numEle).prop("id", "audioQuestion" + num);
$("#box" + num + " #viewAudio" + numEle).prop("id", "viewAudio" + num);
$("#box" + num + " #addAudio" + numEle).prop("id", "addAudio" + num);
$("table#audioQuestion" + num + " tbody tr").each(function (indice) {
if (indice >= 1) {
$(this).remove()
$(this).remove();
}
});
$('#box' + num + ' #pesquisaId' + numEle).prop('id', 'pesquisaId' + num)
$("#box" + num + " #pesquisaId" + numEle).prop("id", "pesquisaId" + num);
//$('#box' + num + ' #count' + numEle).prop('id', 'count' + num)
$('#box' + num + ' #count' + numEle).remove()
$('#tableResponse' + num + ' tbody tr td:nth-child(1)').append(`<input name="count${num}" id="count${num}" type="number" value="2" hidden="">`)
$('#box' + num + ' input[name="count' + numEle + '"]').prop('name', 'count' + num)
$('#box' + num + ' #countAsk' + numEle).prop('id', 'countAsk' + num)
$('#countAsk' + num).text(num + ')')
$('#count' + num).val(2)
if(!$(`input[name="qst_descricao[3][2]"`).val()){
$("#tableResponse" + num).append(buildResponse(num, 2))
$("#box" + num + " #count" + numEle).remove();
$("#tableResponse" + num + " tbody tr td:nth-child(1)").append(`<input name="count${num}" id="count${num}" type="number" value="2" hidden="">`);
$("#box" + num + ' input[name="count' + numEle + '"]').prop("name", "count" + num);
$("#box" + num + " #countAsk" + numEle).prop("id", "countAsk" + num);
$("#countAsk" + num).text(num + ")");
$("#count" + num).val(2);
if (!$(`input[name="qst_descricao[3][2]"`).val()) {
$("#tableResponse" + num).append(buildResponse(num, 2));
}
$('table#tableResponse' + num + ' tbody tr').each(function (indice) {
$("table#tableResponse" + num + " tbody tr").each(function (indice) {
if (indice > 2) {
$(this).remove()
$(this).remove();
}
});
let novoEle = $('<td align="right"><a href="#" id="delnewQuestion' + num + '" title="DELETAR QUESTÃO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteNewQuestion' + num + '" /></a><td>')
$('#collapse' + num + ' #cabRota table tbody tr:nth-last-child(1)').append(novoEle)
$('#collapse' + num + ' #cabRota table tbody tr td:nth-last-child(1)').remove()
$('#box' + num + ' #saveResponse' + numEle).prop('id', 'saveResponse' + num)
$('#collapse' + num + ' input').val('');
})
let novoEle = $(
'<td align="right"><a href="#" id="delnewQuestion' +
num +
'" title="DELETAR QUESTãO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteNewQuestion' +
num +
'" /></a><td>'
);
$("#collapse" + num + " #cabRota table tbody tr:nth-last-child(1)").append(novoEle);
$("#collapse" + num + " #cabRota table tbody tr td:nth-last-child(1)").remove();
$("#box" + num + " #saveResponse" + numEle).prop("id", "saveResponse" + num);
$("#collapse" + num + " input").val("");
});
$('#audio_saudacao').click(function () {
$('#saudacao').html('<input type="file" name="pp_audio_saudacao" id="pp_audio_saudacao" style="width: 451px"/>');
$("#audio_saudacao").click(function () {
$("#saudacao").html('<input type="file" name="pp_audio_saudacao" id="pp_audio_saudacao" style="width: 451px"/>');
});
$('#audio_encerramento').click(function () {
$('#encerramento').html('<input type="file" name="pp_audio_encerramento" id="pp_audio_encerramento" style="width: 451px" />');
$("#audio_encerramento").click(function () {
$("#encerramento").html('<input type="file" name="pp_audio_encerramento" id="pp_audio_encerramento" style="width: 451px" />');
});
el.addEventListener('change', function (e) {
if (e.target.id.indexOf('pq_tipo') >= 0) {
let q = e.target.id.replace('pq_tipo', '')
if($('#pq_tipo' + q).prop("checked")){
el.addEventListener("change", function (e) {
if (e.target.id.indexOf("pq_tipo") >= 0) {
let q = e.target.id.replace("pq_tipo", "");
if ($("#pq_tipo" + q).prop("checked")) {
$("#addResponse" + q).hide();
$("#box" + q +" #tableResponse"+ q +" tr:nth-child(3)").remove()
$("#box" + q + " #tableResponse" + q + " tr:nth-child(3)").remove();
} else {
$("#addResponse" + q).show();
$("#box"+ q +" #tableResponse"+ q).append(`<tr><td colspan="3"> &nbsp;&nbsp; <input name="po_id[${q}][2]" type="number" value="" hidden="true">2) <input name="qst_tecla[${q}][2]" class="qst_tecla" type="number" value="" size="4" maxlength="2" min="0" max="999" required="" style="width:60px"> <input name="qst_descricao[${q}][2]" type="text" value="" title="Descreva aqui a opção" size="50" style="width:360px" maxlength="60" required=""></td></tr>`)
$("#box" + q + " #tableResponse" + q).append(
`<tr><td colspan="3"> &nbsp;&nbsp; <input name="po_id[${q}][2]" type="number" value="" hidden="true">2) <input name="qst_tecla[${q}][2]" class="qst_tecla" type="number" value="" size="4" maxlength="2" min="0" max="999" required="" style="width:60px"> <input name="qst_descricao[${q}][2]" type="text" value="" title="Descreva aqui a opão" size="50" style="width:360px" maxlength="60" required=""></td></tr>`
);
}
}
let x = e.target.name.indexOf('[')
let y = e.target.name.indexOf(']')
let idtecla = e.target.name.substring((x + 1), y)
let posi = e.target.name.replace("qst_tecla[" + idtecla + "]", '').replace('[', '').replace(']', '')
let ar = []
$('#tableResponse' + idtecla + ' .qst_tecla').each(function (i, el) {
ar.push($(this).val())
})
ar.splice((posi - 1), 1);
let x = e.target.name.indexOf("[");
let y = e.target.name.indexOf("]");
let idtecla = e.target.name.substring(x + 1, y);
let posi = e.target.name
.replace("qst_tecla[" + idtecla + "]", "")
.replace("[", "")
.replace("]", "");
let ar = [];
$("#tableResponse" + idtecla + " .qst_tecla").each(function (i, el) {
ar.push($(this).val());
});
ar.splice(posi - 1, 1);
const maxValue = ar.reduce(function (prev, current) {
return prev > current ? prev : current;
});
if (ar.indexOf(e.target.value) >= 0) {
$('input[name="' + e.target.name + '"]').val(Number(maxValue) + 1)
$('input[name="' + e.target.name + '"]').val(Number(maxValue) + 1);
}
});
});

Loading…
Cancel
Save