How to maintain the presentation of modal data

Asked

Viewed 51 times

0

I developed a screen that presents the benefits granted to the citizen, system aimed at social assistance, follows the view :

<!--onblur ="validaNomeCidadaoGeral('dcbe_usu_codigo','dcbe_usu_nome','dcbealert_usu_nome')" -->
<div class="conteudo" >
    <legend>Itens benefício eventual</legend>
    <p class="msgAviso" id="beneficios-msg" <?=(count($this->dadosBenItens)>0 ? "style='display: none;'" : "style='display: show;'")?>>
    </p>
    <div class="msgAviso" id="dcbealert_exc_bei" style="display: none;"></div>
        <table class="table table-bordered" id="beneficios_inseridos" 
        <?=(count($this->dadosBenItens)>0 ? "style='display: show;'" : "style='display: none;'")?>>
        <thead>
            <tr>
            <th>Benefício</th>
            <th>Tipo de benefício</th>
            <th>Quantidade</th>
            <th>Valor</th>
            <th>Benefício concedido</th>
            <th>Data Prevista</th>
            <th>Data Entrega</th>
            <th>Finaliza Entrega</th>
            </tr>
        </thead>   
    <tbody>
        <?php 
        if (count($this->dadosBenItens)>0) {
        // die('sdsadas')
        foreach($this->dadosBenItens as $ite) { ?>
            <tr id='beneficio_inserido<?=$ite->asbdi_codigo?>'>

                <td class="center">
                    <?=$ite->beneficio?>
                </td>
                <td class="center">
                    Tipo de benefício
                </td>
                <td class="center">
                    <?=$ite->asbdi_qtd?>
                </td>
                <td class="center">
                    <?=$ite->asbdi_valor?>
                </td>
                <td class="center">
                    <?=($ite->asbdi_concedido == 1 ? 'Sim' : 'Não')?>
                </td>

                <td class="center">
                    <?=($ite->asbdi_data_entrega)?>
                </td>
                <td class="center">
                    <p id = "" style="display: none"><?=($ite->asbdi_entrega)?></p>
                </td>
                <td>
                    <div>
                        <button onclick="gerarDataEntrega(<?=$ite->asbdi_codigo?>)">Finliza Entrega</button>
                    </div>
                </td> 
            </tr>

        <?php }
            } ?>
        </tbody>
    </table>
</div>

Upshot : inserir a descrição da imagem aqui

Until then all right I click on the button it load the necessary functions , saves the date of delivery of the benefit and good. After the ajax Success I would like to hide the button and present the date .

function gerarDataEntrega (id){
    $.ajax({
        url: baseUrl + "/atendimentocras/beneficios-cidadao/data-entrega/",
        type: "POST",
        data: {id: id },
        success: function(resultado){

        }
    });
}

The problem is that everything is in a foreach making it difficult to present the delivery date if the citizen has more of a benefit . And how else can I keep this presentation fixed ? .

  • A use of the modal itself would be the easiest solution ?

  • I was using the result with a console.log just to check if it was getting the answer, have some feed in the process just that.

  • No, I click the button and the change does not happen , I need to close and open the modal.

  • So. You said in the answer below that when you close the modal and open again, the button appears again. So it seems to me that this list that appears in the modal is loaded dynamically, otherwise the button would not appear again, right?

2 answers

0

I made some changes to the code , validating if the citizen already has benefits . If he already has the generate date button is not shown. How was :

<!--onblur ="validaNomeCidadaoGeral('dcbe_usu_codigo','dcbe_usu_nome','dcbealert_usu_nome')" -->
<div class="conteudo" >
    <legend>Itens benefício eventual</legend>
    <p class="msgAviso" id="beneficios-msg" <?=(count($this->dadosBenItens)>0 ? "style='display: none;'" : "style='display: show;'")?>>
    </p>
    <div class="msgAviso" id="dcbealert_exc_bei" style="display: none;"></div>
        <table class="table table-bordered" id="beneficios_inseridos" 
        <?=(count($this->dadosBenItens)>0 ? "style='display: show;'" : "style='display: none;'")?>>
        <thead>
            <tr>
                <th>Benefício</th>
                <th>Tipo de benefício</th>
                <th>Quantidade</th>
                <th>Valor</th>
                <th>Benefício concedido</th>
                <th>Data Prevista</th>
                <th>Data Entrega</th>
                <th>Finaliza Entrega</th>
            </tr>
        </thead>   
    <tbody>
        <?php 
        if (count($this->dadosBenItens)>0) {
        // die('sdsadas')
        foreach($this->dadosBenItens as $ite) { ?>

                    <tr id='beneficio_inserido<?=$ite->asbdi_codigo?>'>

                        <td class="center">
                            <?=$ite->beneficio?>
                        </td>
                        <td class="center">
                            Tipo de benefício
                        </td>
                        <td class="center">
                            <?=$ite->asbdi_qtd?>
                        </td>
                        <td class="center">
                            <?=$ite->asbdi_valor?>
                        </td>
                        <td class="center">
                            <?=($ite->asbdi_concedido == 1 ? 'Sim' : 'Não')?>
                        </td>

                        <td class="center">
                            <?=($ite->asbdi_data_entrega)?>
                        </td>
                        <td class="center">
                            <p id="" style=""><?=($ite->asbdi_entrega)?></p>
                        </td>
                        <td>
            <?php if ($ite->asbdi_entrega == null): ?>
                            <div>
                                <button id="id-botao-<?=$ite->asbdi_codigo?>"
                                       onclick="gerarDataEntrega(<?=$ite->asbdi_codigo?>)">
                                  Finaliza Entrega
                                </button>
                            </div>
            <?php endif ?>
                        </td> 

                    </tr>
        <?php }
            } ?>
        </tbody>
    </table>
</div>

I made a small change in ajax :

function gerarDataEntrega (id){
    $.ajax({
        url: baseUrl + "/atendimentocras/beneficios-cidadao/data-entrega/",
        type: "POST",
        data: {id: id },
        success: function(resultado){
            alert("Data de entrega efetuada com sucesso.");
            location.reload()
        }
    });
}

That was the way I found to solve this problem , of course the ideas of the topic helped me and a lot in concluding.

0

You can add the id button, and AJAX Success you manipulate it with jQuery.

<div>
   <button id="id-botao-<?=$ite->asbdi_codigo?>"
           onclick="gerarDataEntrega(<?=$ite->asbdi_codigo?>)">
      Finliza Entrega
   </button>
</div>

success: function(resultado){
     $('#id-botao-'+id).hide();
     // faz o que precisa com a sua variável 'resultado' 
     ...
}

That’s what you want to do?

  • Almost this it works correctly however, closed the and opened the modal it returns to become visible . I keep it invisible understands . Type generated the missing delivery date no longer appears. I do not know if it is possible too.

  • Another thing also, I click the button the delivery date does not load I have to close the modal there yes it is visible. It seems to process everything but a Reload is necessary. Then the update in the view.

Browser other questions tagged

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