利用bootstrap模式创建和编辑用户

时间:2015-06-22 14:41:28

标签: javascript jquery html5 laravel-5 bootstrap-modal

我的视图包含两个元素:

  1. 按钮:用于为表格创建行的add按钮
  2. 表:我从数据库动态填充的表,每行有一个编辑按钮
  3. 我想要做的是当我点击add按钮时,它会显示一个带有表单的模式(lastnamefirstnamerolelogin等等) 当我点击edit按钮(表格中的行)时,它会打开相同的模态,但会在表单中显示用户的所有属性。

    我的观点Users.blade.php

     ....
    // include modal
    @include('CreateOrEditModal', array('user' => isset($user) ? $user: null))
    
    // add button
    <button data-toggle="modal"  data-target="#create_edit_modal" class="btn btn-primary"><i class="fa fa-plus"></i> Add user</button>
     ...
     ...
    <tbody>
        @foreach($users as $user)               
            <tr>
                <td>{{$user->lastname}}</td>
                <td>{{$user->firstname}}</td>
                <td>{{$user->role}}</td>
                <td>{{$user->login}}</td>
                <td>{{$user->password}}</td>
                <td>
                    <button class="btn btn-primary" data-target="#create_edit_modal" data="{{$user}}"><span class="fa fa-pencil"></span>Edit</button>
                </td>
            </tr>
        @endforeach
    </tbody>
    

    我的模态

    <div class="modal hide fade" id="create_edit_modal" tabindex="-1"  aria-hidden="true">
        <div class="modal-dialog" >
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
             @if(isset($user))
                <h4 class="modal-title">{{$user->name}}</h4>
             @else
                <h4 class="modal-title">Add a new user</h4>
             @endif
          </div>
         <div class="modal-body"> 
                    @if(isset($user))
                        {!! Form::model($user, array('class' => 'form-horizontal','route' => array('site.update', $user->id), 'method' => 'PUT')); !!}
                    @else
                        {!! Form::open(array('url' => 'site','class' => 'form-horizontal')) !!}
                    @endif
                    <div class="row">
                     ....
    

0 个答案:

没有答案