Search does not work on Jquery Modal Screen

Asked

Viewed 474 times

2

We have a search screen that works like this: There is a main screen. On it a button calls the search screen. This screen is loaded into a IFrame that is inside a Modal jquery-ui(Dialog). On this screen (search) I select some filters and when clicking on the search button, I open a grid with the search result. Well, when I select a CPF or No. Chart, for example, it closes the screen and on the original calling page, the Textbox are then filled with these values. What’s going on. This search screen, previously developed within ShowModalDialog. For this reason, it works only on IE(Modo Modal). In the 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 retaining the functionality that’s in IE today. So we set out for a solution jquery, for now to meet this specification, but the problem is this. Even clicking does not give any error, but nothing happens. The survey does not complete. Someone told me to switch to the ajax and see how it works, but I wonder if with the Dialog of jquery can do.

See the screen below. When clicking on a contract, the Modal should be closed and in the background screen, the Contract field should be filled in and the field beside (ready only) should be filled in with the Name. inserir a descrição da imagem aqui

When clicking on the contract or name, anyone who has a "link" is called a javascript() function and it is she who closes the 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 look at this. In the code piece below, in the first Alert() I have the value of the variable, in the second it is not called. I believe it 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 was the function with the help of Tobymosque.

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 %>
}
  • If anyone has any idea to work, even if it is not by jquery-ui (Modal Dialog), it is welcome, as long as the behavior of the search screen is Modal.

1 answer

2


pnet, from what I remember from your old questions, this page that you are loading in iframe before was opened in a pop-up.

This way, this page should be communicating with the page that opened the following way:

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

however now you are displaying 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 to which iframe belongs.

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 to replace 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";
}

for 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 is not necessary, its code could be something like the 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 PAGINA PAI

var fecharModal = function () {
    var dialog = $(janela.document.getElementById("dialog"));
    dialog.dialog("close");
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.