Search does not work on Jquery Modal Screen

2

We have a search screen that works like this: There is a main screen. In it a button calls the search screen. This screen loads into a IFrame that is within a Modal jquery-ui(Dialog) . In this screen (search) I select some filters and clicking the search button opens a grid with the search result. Well, when I select a CPF or No. of Record, for example, it closes the screen and on the original caller page, the Textbox are then filled with those values. What is going on. This search screen was previously developed within ShowModalDialog . For this reason, it only works on IE(Modo Modal) . No Chrome it goes up normally, but not in a Modal way, which is why the company wants it to be validated in Chrome as well, but maintaining the functionality that exists in IE today. So, we start with a jquery solution, for now to meet this specification, but the problem is that. Even clicking does not give any error, but nothing happens. The survey does not complete. Someone told me to switch to ajax and see how it works, but I wonder if Dialog jquery can do.

See the screen below. When you click on contract, the Modal should be closed and on the background screen, the Contract field should be completed and the field next to it (ready only) should be filled with the Name.

Whenyouclickonthecontractorname,anyonewhohasa"link" is called a javascript () function and it closes Dialog and populates the bottom screen (calling page). See the function below:

function selecionar(num_contrato, cod_ts_contrato, nome_entidade){
    <%if trim(strAction) = "" then %>
        //ABRIU POPUP
        var txt_chamada = '';
        try {
            var oMyObject = window.dialogArguments;
            txt_chamada = "oMyObject";
            var aux = oMyObject.document;
        } catch (e) {
            txt_chamada = "window.parent.opener";
        }

      try{
           //COD_TS_CONTRATO
         <%if trim(txt_nome_campo_cod_ts)<>"" then %>
            var ocod_ts_contrato = eval(txt_chamada + ".document.form01.<%Response.write txt_nome_campo_cod_ts%>");
         <%else%>
            var ocod_ts_contrato = eval(txt_chamada + ".document.form01.cod_ts_contrato");
         <%end if %>

           if (ocod_ts_contrato != null )
               ocod_ts_contrato.value = cod_ts_contrato;

           //NUM_CONTRATO
           <%if trim(txt_nome_campo_cod)<>"" then%>
               var onum_contrato = eval(txt_chamada + ".document.form01.<%Response.write txt_nome_campo_cod%>");
           <%else%>
               var onum_contrato = eval(txt_chamada + ".document.form01.num_contrato");
           <%end if %>

           if (onum_contrato != null )
               onum_contrato.value = num_contrato;

           //NOME_CONTRATO
           <%if trim(txt_nome_campo_desc)<>"" then%>
               var onome_entidade = eval(txt_chamada + ".document.form01.<%Response.write txt_nome_campo_desc%>");
           <%else%>
               var onome_entidade = eval(txt_chamada + ".document.form01.nome_contrato");
           <%end if%>

           if (onome_entidade != null )
               onome_entidade.value = nome_entidade;

           <%if trim(funcao_executar) <> "" then%>
               try{
                   var aux = eval(txt_chamada+".<%Response.write funcao_executar%>");
               }catch(e){
                   window.returnValue = 'window.<%Response.write funcao_executar%>';            
               }
           <%end if%>

         <%if ucase(indsubmit) = "TRUE" then%>
            eval(txt_chamada + ".document.form01.submit()");
         <%else %>
            //Somente joga o Focus se o campo existir, e estiver desabilitado
            if (onum_contrato != null && onum_contrato.disabled==false && onum_contrato.enabled==true)
               onum_contrato.focus();
         <%end if%>
      }catch(e){

           //COD_TS_CONTRATO
         <%if trim(txt_nome_campo_cod_ts)<>"" then %>
            var ocod_ts_contrato = eval(txt_chamada + ".<%Response.write txt_nome_campo_cod_ts%>");
         <%else%>
            var ocod_ts_contrato = eval(txt_chamada + ".cod_ts_contrato");
         <%end if %>

           if (ocod_ts_contrato != null )
               ocod_ts_contrato.value = cod_ts_contrato;

           //NUM_CONTRATO
           <%if trim(txt_nome_campo_cod)<>"" then%>
               var onum_contrato = eval(txt_chamada + ".<%Response.write txt_nome_campo_cod%>");
           <%else%>
               var onum_contrato = eval(txt_chamada + ".num_contrato");
           <%end if %>

           if (onum_contrato != null )
               onum_contrato.value = num_contrato;

           //NOME_CONTRATO
           <%if trim(txt_nome_campo_desc)<>"" then%>
               var onome_entidade = eval(txt_chamada + ".<%Response.write txt_nome_campo_desc%>");
           <%else%>
               var onome_entidade = eval(txt_chamada + ".nome_contrato");
           <%end if%>

           if (onome_entidade != null )
               onome_entidade.value = nome_entidade;

           <%if trim(funcao_executar) <> "" then%>
               /*try{
                   var aux = eval(txt_chamada+".<%Response.write funcao_executar%>");
               }catch(e){
                   window.returnValue = 'window.<%Response.write funcao_executar%>';            
               }*/
               var opener_document = oMyObject.ownerDocument;
               var opener_window = opener_document.defaultView || opener_document.parentWindow;

                  try {
                     eval("opener_window." + "<%Response.write funcao_executar%>");
                  } catch (e) {
                     window.returnValue = "window." + "<%Response.write funcao_executar%>";
                  }

           <%end if%>

         <%if ucase(indsubmit) = "TRUE" then%>
            eval(txt_chamada + ".submit()");
         <%else %>
            //Somente joga o Focus se o campo existir, e estiver desabilitado
            if (onum_contrato != null && onum_contrato.disabled==false && onum_contrato.enabled==true)
               onum_contrato.focus();
         <%end if%>
      }  
      parent.self.close();

    <%else %>
        //ABRIU NORMAL ENTAO DAR SUBMIT
        document.form01.cod_ts_contrato.value   = cod_ts_contrato;
        document.form01.num_contrato.value      = num_contrato;
        document.form01.action = '<%Response.write strAction & "?PT=" & Request("PT")%>';
        document.form01.submit();
    <%end if %>
}

I started making the changes and see the following. In the code piece below, in the first alert () I have the value of the variable, already in the second it is not called. I believe he gets lost in this situation:

.document.form01.<%Response.write txt_nome_campo_cod_ts%>");

I think I should switch to document.getElementsByName() . I'm trying to make the change suggested by TobyMosque, but I confess I'm having some difficulty understanding, but I think it's the way.

try{
           alert(cod_ts_contrato); 

           //COD_TS_CONTRATO
         <%if trim(txt_nome_campo_cod_ts)<>"" then %>
            var ocod_ts_contrato = eval(txt_chamada + ".document.form01.<%Response.write txt_nome_campo_cod_ts%>");
         <%else%>
            var ocod_ts_contrato = eval(txt_chamada + ".document.form01.cod_ts_contrato");
         <%end if %>

           if (ocod_ts_contrato != null )
               ocod_ts_contrato.value = cod_ts_contrato;

           alert(cod_ts_contrato);

So it was with TobyMosque's help.

function selecionar(num_contrato, cod_ts_contrato, nome_entidade){
    <%if trim(strAction) = "" then %>
        //ABRIU POPUP
        var txt_chamada = '';
        if (window.dialogArguments) {
            txt_chamada = "window.dialogArguments";
        } else if (window.parent.opener) {
            txt_chamada = "window.parent.opener";
        } else if (window.parent.frameElement) {
            if (window.parent.frameElement.ownerDocument.defaultView) {
                txt_chamada = "window.parent.frameElement.ownerDocument.defaultView";
            } else {
                txt_chamada = "window.parent.frameElement.ownerDocument.parentWindow";
            }
        }

      try{

           //COD_TS_CONTRATO

            var janela = null;
            if (window.dialogArguments) {
                janela = window.dialogArguments;
            } else if (window.parent.opener) {
                janela = window.parent.opener;
            } else if (window.parent.frameElement) {
                var documento = window.parent.frameElement.ownerDocument
                var janela = documento.defaultView || documento.parentWindow;
            }

            if (janela) {
                var txt_nome_campo_cod_ts = "<%= trim(txt_nome_campo_cod_ts) %>" || "cod_ts_contrato";
                var txt_nome_campo_cod = "<%= trim(txt_nome_campo_cod) %>" || "num_contrato";

                var ocod_ts_contrato = janela.document.form01[txt_nome_campo_cod_ts];
                var onum_contrato = janela.document.form01[txt_nome_campo_cod];
//                var onum_contrato = janela.document.getElementsByName(txt_nome_campo_cod);
            }

//         //NUM_CONTRATO
      }catch(e){

// Aqui código do Catch. Retirei para não ficar grande a edição.

      }  
      parent.self.close();
      $("#dialog1", janela).dialog("close");

    <%else %>
        //ABRIU NORMAL ENTAO DAR SUBMIT
        document.form01.cod_ts_contrato.value   = cod_ts_contrato;
        document.form01.num_contrato.value      = num_contrato;
        document.form01.action = '<%Response.write strAction & "?PT=" & Request("PT")%>';
        document.form01.submit();
    <%end if %>
}
    
asked by anonymous 06.08.2015 / 19:53

1 answer

2

pnet, as far as I remember from your old questions, this page you've been uploading to iFrame before was opened in a popup.

In this way, this page should be communicating with the page that opened as follows:

if (window.opener) {
    //manipula os DOM da outra tela (a que abriu a atual) atraves do window.opener
}

But now you are viewing this screen through an iFrame, so the way to access the screen that requested it is a little different.

if (window.frameElement) {
    //manipula os DOM da tela pai (a que solicitou o iFrame) atraves do window.frameElement
}

The code below tries to normalize this by looking for the parent window, regardless of whether it is a separate screen or the document the iFrame belongs to.

var janela = null;
if (window.frameElement) {
    var documento = window.frameElement.ownerDocument
    var janela = documento.defaultView || documento.parentWindow;
} else if (window.opener) {
    var janela = window.opener;
}

if (janela) {
    //manipula os DOM da tela principal através da variável janela.
}

EDIT

try replacing the following block:

var txt_chamada = '';
try {
    var oMyObject = window.dialogArguments;
    txt_chamada = "oMyObject";
    var aux = oMyObject.document;
} catch (e) {
    txt_chamada = "window.parent.opener";
}

by this:

var txt_chamada = '';
if (window.dialogArguments) {
    txt_chamada = "window.dialogArguments";
} else if (window.parent.opener) {
    txt_chamada = "window.parent.opener";
} else if (window.parent.frameElement) {
    if (window.parent.frameElement.ownerDocument.defaultView) {
        txt_chamada = "window.parent.frameElement.ownerDocument.defaultView";
    } else {
        txt_chamada = "window.parent.frameElement.ownerDocument.parentWindow";
    }
}

SUGGESTION

Try to avoid using eval() too much, especially when it's not needed, your code could be something like the one below:

var txt_chamada = '';
try {
    var oMyObject = window.dialogArguments;
    txt_chamada = "oMyObject";
    var aux = oMyObject.document;
} catch (e) {
    txt_chamada = "window.parent.opener";
}

try {
    <%if trim(txt_nome_campo_cod_ts)<>"" then %>
        var ocod_ts_contrato = eval(txt_chamada + ".document.form01.<%Response.write txt_nome_campo_cod_ts%>");
    <%else%>
        var ocod_ts_contrato = eval(txt_chamada + ".document.form01.cod_ts_contrato");
    <%end if %>

    <%if trim(txt_nome_campo_cod)<>"" then%>
       var onum_contrato = eval(txt_chamada + ".document.form01.<%Response.write txt_nome_campo_cod%>");
    <%else%>
       var onum_contrato = eval(txt_chamada + ".document.form01.num_contrato");
    <%end if %>
} catch (e) {

}

for something cleaner:

function selecionar(num_contrato, cod_ts_contrato, nome_entidade){
<%if trim(strAction) = "" then %>
    //ABRIU POPUP
    var janela = null;
    var isIFrame = false;
    var isPopUp = false;        
    if (window.dialogArguments) {
        isPopUp = true;
        janela = window.dialogArguments;
    } else if (window.parent.opener) {
        isPopUp = true;
        janela = window.parent.opener;
    } else if (window.parent.frameElement) {
        isIFrame = true;
        var documento = window.parent.frameElement.ownerDocument
        var janela = documento.defaultView || documento.parentWindow;
    }

    if (janela) {
        var form01 = janela.document.form01 || janela;
        var cod_ts_contrato_id = "<%= trim(txt_nome_campo_cod_ts) %>" || "cod_ts_contrato";
        var num_contrato_id = "<%= trim(txt_nome_campo_cod) %>" || "num_contrato";
        var nome_contrato_id = "<%= trim(txt_nome_campo_desc) %>" || "nome_contrato";
        var funcao_executar_id = "<%= trim(funcao_executar) %>";
        var indsubmit = "<%= lcase(indsubmit) %>" === "true";

        var ocod_ts_contrato = form01[cod_ts_contrato_id];
        var onum_contrato = form01[num_contrato_id];
        var onome_entidade = form01[nome_contrato_id];
        var ofuncao_executar = funcao_executar_id ? janela[funcao_executar_id] : null;

        if (ocod_ts_contrato) ocod_ts_contrato.value = cod_ts_contrato;
        if (onum_contrato) onum_contrato.value = cod_ts_contrato;
        if (onome_entidade ) onome_entidade .value = nome_entidade;
        if (typeof ofuncao_executar === 'function') ofuncao_executar();

        if (indsubmit) {
            form01.submit();
        } else if (onum_contrato != null && onum_contrato.disabled==false && onum_contrato.enabled==true) {
            onum_contrato.focus();
        }
    }

    if (isIFrame) {
        janela.fecharModal();
    } 

    if (isPopUp) {
        parent.self.close();
    }

<%else %>
    //ABRIU NORMAL ENTAO DAR SUBMIT
    document.form01.cod_ts_contrato.value = cod_ts_contrato;
    document.form01.num_contrato.value = num_contrato;
    document.form01.action = '<%Response.write strAction & "?PT=" & Request("PT")%>';
    document.form01.submit();
<%end if %>
}

JS PAGE FATHER

var fecharModal = function () {
    var dialog = $(janela.document.getElementById("dialog"));
    dialog.dialog("close");
}
    
06.08.2015 / 21:42