@ -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 = "" >
< / t d >
< / t r > ` ;
}
} ;
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 ( )
$ ( "#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);
} )
}
} ) ;
} ;
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 ( ) {
$ ( "#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 ( )
$ ( "#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 ( )
$ ( "#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!' ) ;
$ ( "#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 ( 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 ) {
$ ( "#tableResponse" + nums [ 0 ] + ' tbody tr:nth-last-child(1) td' ) . append ( ultimoEle )
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 ( )
$ ( "#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 ? " " : " "
$ ( "#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 ? " " : " " ;
$ ( "#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 : 60 px " required > \ n \
< input name = " qst _descricao [ ' +
numTable +
"][" +
ct +
' ] " type=" text " value=" " title=" Descreva aqui a opção " size=" 50 " style=" width : 360 px " maxlength=" 60 " required > \ n \
< / t d > \ n \
< / t r > ' )
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 )
< / t r > '
) ;
// 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/> <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/> <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 ( )
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 ) {
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 ( )
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" + 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 ( )
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 ( )
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 )
$ ( "#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 ) )
$ ( "#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"> <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"> <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 ( ) )
} )
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 ) ;
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 ) ;
}
} ) ;
} ) ;