dsfw2154 2015-03-02 16:09
浏览 68

(Laravel)使用来自DB的数据动态打开模态

I'm pretty new in programming and I'm stuck with a problem which I really don't know how to solve.

Basically I have a view wich contains a table filled with events:

// routes.php
Route::get('calendario/calendario_personale', 'CalendarioController@creaCalendarioPersonaleLista');

// controller
public function creaCalendarioPersonaleLista() {

    $lista_militi = Milite::where('Aktiv', '=', 'True')
        ->orderBy('Name')
        ->orderBy('Vorname')
        ->get();

    $milite = Milite::where('eMailB', '=', Auth::user()->email)
        ->first();

    $agenda = Milite::find($milite->KeyPerson)
        ->AgendaPersonale
        ->all();

    return View::make('calendario_personale', compact('agenda'))
        ->with('lista_militi', $lista_militi);

}

// view
<!-- ********** INIZIO EXTENDED MODAL - FORMULARIO ANNUNCIO ASSENZE ********** -->
<div id="annuncio_assenza" class="modal fade" tabindex="-1" data-width="550">
@var $key = '4000';
@var $spec_agenda = Agenda::find($key)

<div class="modal-body">
{{ Form::open(['action' => 'CalendarioController@inviaAnnuncioAssenza']) }}

    <div class="row">
        <div class="col-md-12">
            <span class="_red"><h3> Annuncio d'assenza </h3>
            <h5> Da inviare almeno 48 ore prima dell'evento </h5></span>
            <br/>
            <h5> Non posso essere presente a <span class="_bold"> {{ $spec_agenda->Bezeichnung }} </span></h5>
            <h5> che si terr&agrave; il giorno <span class="_bold"> {{ date('d.m.Y', strtotime($spec_agenda->Datum)) }} </span> alle ore <span class="_bold"> {{ date('H:i', strtotime($spec_agenda->Zeit)) }} </span></h5>
            <h5> per il seguente motivo: </h5><br/>
            <table id="form-assenza">
                <tr>
                    <td> {{ Form::checkbox('personale') }} Personale </td>
                    <td> {{ Form::checkbox('vacanza') }} Vacanza </td>
                </tr>
                <tr>
                    <td> {{ Form::checkbox('professionale') }} Professionale </td>
                    <td> {{ Form::checkbox('militare') }} Servizio militare/PCi </td>
                </tr>
                <tr>
                    <td> {{ Form::checkbox('infortunio') }} Infortunio/malattia </td>
                    <td> {{ Form::checkbox('altri_impegni') }} Altri impegni </td>
                </tr>
            </table>
            {{ Form::hidden('cosa', $spec_agenda->Bezeichnung) }}
            {{ Form::hidden('data', date('d.m.Y', strtotime($spec_agenda->Datum))) }}
            {{ Form::hidden('ora', date('H:i', strtotime($spec_agenda->Zeit))) }}
            <br/><br/>
            <h5><span class="_red"> Da compilare in caso di assenza per Guardia Festiva, picchetto e/o appoggio: </span></h5>
            <h5> Verr&ograve; sostituita/o da: </h5>
            <div class="form-group">
                <select class="form-control" style="font-size: 1em" name="sostituto">
                    <option value=""> Seleziona un milite... </option>
                    @foreach($lista_militi as $militi)
                    <option value="{{ $militi->KeyPerson }}"> {{ $militi->Dienstgrad }} {{ $militi->Name }} {{ $militi->Vorname }} </option>
                    @endforeach
                </select>
            </div>
            <br/><h5> Altro/Osservazioni </h5>
            <p> {{ Form::textarea('altro', null, ['class'=>'form-control _small', 'rows' => '3']) }} </p>
        </div>
    </div>
</div>
<div class="modal-footer">
    {{ Form::button('Annulla', ['class'=>'btn btn-default', 'data-dismiss'=>'modal']) }}
    {{ Form::submit('Invia il formulario', ['class'=>'btn red']) }}
</div>
{{ Form::close() }}
</div>    
<!-- ********** FINE EXTENDED MODAL - FORMULARIO ANNUNCIO ASSENZE ********** -->

<!-- BEGIN PAGE CONTENT-->
<div class="row">
<div class="col-md-12">
    <!-- ********** INIZIO PORTLET ********** -->
    <div class="portlet box red profile margin-top-minus5">
        <div class="portlet-title">
            <div class="caption">
                <i class="fa fa-calendar-o"></i> Calendario personale
            </div>
            <ul class="nav nav-tabs">
                <li class="active">
                    <a href="calendario_personale"> Personale </a>
                </li>
                <li>
                    <a href="calendario_corpo"> Corpo </a>
                </li>
            </ul>
        </div>
        <div class="portlet-body">
            <div class="row">
                <div class="col-lg-12">
                    <table class="table table-striped table-bordered table-hover _dark-grey" id="table_custom">
                        <thead>
                        <tr>
                            <!-- Visualizzazione su xs -->
                            <th class="hidden-sm hidden-md hidden-lg on-one-line"> Data </th>
                            <!-- Visualizzazione su sm, md e lg -->
                            <th class="hidden-xs on-one-line"> Data </th>
                            <th> Descrizione </th>
                            <!-- Visualizzazione sm, md e lg -->
                            <th class="hidden-xs on-one-line"> Assenza </th>
                            <!-- Visualizzazione xs -->
                            <th class="hidden-sm hidden-md hidden-lg on-one-line"> Ass. </th>
                        </tr>
                        </thead>
                        <tbody id="link-disable">
                        @foreach($agenda as $evento)
                        <tr>
                            <!-- Visualizzazione su xs -->
                            <td class="hidden-sm hidden-md hidden-lg on-one-line">
                                <span class="_bold">
                                {{ date('d.m.Y', strtotime($evento->Datum)) }}
                                </span><br/>
                                {{ $evento->dalle_alle }}
                            </td>
                            <!-- Visualizzazione su sm, md e lg -->
                            <td class="hidden-xs on-one-line">
                                <span class="_bold">
                                {{ date('d.m.Y', strtotime($evento->Datum)) }}
                                </span> &nbsp;
                                {{ $evento->dalle_alle }}
                            </td>
                            <td>
                                {{ $evento->Bezeichnung }}
                                @if($evento->Objekt != null) , luogo: {{ $evento->Objekt }} @endif
                                , {{ $evento->Einsatzart }}
                                @if($evento->Leiter != null) , responsabile: {{ $evento->Leiter }} @endif
                            </td>
                            <!-- Visualizzazione sm, md e lg -->
                            <td class="hidden-xs on-one-line">
                                {{ HTML::link('#annuncio_assenza', 'Annuncia', ['onclick' => 'specAgenda('.$evento->KeyAgenda.')', 'id' => 'form_assenza', 'data-toggle' => 'modal', 'name' => 'link_form_assenza', 'data-value' => $evento->KeyAgenda]) }}
                            </td>
                            <!-- Visualizzazione xs -->
                            <td class="hidden-sm hidden-md hidden-lg on-one-line">
                                {{ HTML::link('#annuncio_assenza', 'Ann.', ['onclick' => 'specAgenda('.$evento->KeyAgenda.')', 'id' => 'form_assenza', 'data-toggle' => 'modal', 'name' => 'link_form_assenza', 'data-value' => $evento->KeyAgenda]) }}
                            </td>
                        </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <!-- ********** FINE PORTLET ********** -->
</div>

As you can imagine every event has a key, which I save in the data-value of my link ($evento->KeyAgenda). Now, as the page does not reload how can I pass my key to my modal form? I tried with some JavaScript but it doesn't seem to work and it's been to day wasted now, I'm sick.

Can someone help me making this work??? Thank you in advance!!

  • 写回答

1条回答 默认 最新

  • doukanxi4246 2015-03-03 10:39
    关注

    Let me try to explain better the situation...

    I have the view with the calendar. I populate the table using a foreach and data from a model. See the image at this link: https://www.dropbox.com/s/3ewcmy73gksjwcw/calendario.jpg?dl=0

    Then I have my modal form, which is linked to the word "Annuncia" on the last column, like that: https://www.dropbox.com/s/sjft7a1wtb6wvj2/modaleassenza.jpg?dl=0

    What I'd like to do is to populate the form with some information which are connected to the row event. For example when I click on the first raw the modal should have the bold parts already filled with the right records (description, date and time).

    I hope it's clearer now... and sorry but English is not my mother language.

    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害