@extends('layouts.dashboard')

@section('page_title')
 Create / View Permission
@endsection

@section('page_breadcrumb')
    {{ Breadcrumbs::render('view_user_permission',Auth::user()->name) }}
@endsection

@section('page_body')
   <!--begin::Card-->
   <div class="card card-custom">
                <!--begin::Header-->
                <div class="card-header f">
                    <div class="card-title">
                        <h3 class="card-label">Create / View Permission</h3>
                    </div>
                    <div class="card-toolbar">

                      <div style="width: 100%;">
                        {{ Form::open(array('route' => 'permission.store', 'id' => 'form_add_permission', 'class' => 'cls_form')) }}
                            <input type="hidden" name="pass" value="reqtocreateper">

                            <div class="row">
                                <div class="col-sm-12 col-md-12 col-lg-4">
                                    <label class="label-color"> Module:</label>
                                    <small class="form-errors pull-right req" value="*">{{ $errors->first('module',":message") }}</small>
                                      <select class="form-control fstdropdown-select" name="module">
                                      @foreach(EF::getModuleList() as $rows)
                                        <option value="{{$rows}}">{{$rows}}</option>
                                      @endforeach
                                    </select>
                                  </div>
                                <div class="col-sm-12 col-md-12 col-lg-4">

                              <label class="label-color"> Feature Name:</label>
                                <small class="form-errors pull-right req" value="*">{{ $errors->first('feature',":message") }}</small>

                                  
                                  {{Form::Text('feature', '', ['class' => 'form-control form-control-sm  cls_required', 'placeholder' => 'Feature' , 'aria-label' => 'Default', 'aria-describedby' => 'inputGroup-sizing-default'])}}
                              </div>

                              <div class="col-sm-12 col-md-12 col-lg-4">

                                <button type="submit" onclick="storePermission(event,this);" class="btn btn-sm btn-primary mt-7">Create Permission</button>
                              </div>
                            </div>


                        {{ Form::close() }}
                      </div>
                    </div>
                </div>
                <!--end::Header-->
                <!--begin::Body-->
                <div class="card-body">
                    
                    <!--begin: Datatable-->
                    <div class="datatable datatable-bordered datatable-head-custom" ></div>
                    <div class="table-responsive">
                     <table  class="cls_datatable table table-hover table-outline  text-nowrap table-head-custom table-vertical-center text-center">
                      <thead>
                        <tr>

                            <th>#</th>
                            <th>Module</th>
                            <th>Permission</th>
                          </tr>
                      </thead>

                      <tbody>
                        @foreach($permission_list as $rows)
                        <tr>
                          <td>{{$loop->iteration}}</td>
                          <td>{{$rows->module}}</td>
                          <td>{{$rows->name}}</td>
                        </tr>
                        @endforeach
                      </tbody>
                      
                    </table>
                  </div>
                    <!--end: Datatable-->
                </div>
                <!--end::Body-->
            </div>
            <!--end::Card-->
@endsection


@section('page_script')
<script type="text/javascript">
    
  function storePermission(event,obj)
  {
      event.preventDefault();

      var obj = $('#form_add_permission');
      var route = obj.attr('action');
      var formdata = obj.serialize();

      showLoader();

      $.post(route, formdata, function(result)
      {
          if(result)
          {
              if(result.status == true)
              {
               $('#form_add_permission')[0].reset();
                
                // Reload the current page without the browser cache
                messageToaster('success',result.message,'Success');
            }
            else{

                messageToaster('error',result.message , 'Failed');

            }

          }
      removeLoader();


      },'json')
      .fail(function(result) {

          messageToaster('error','Required form validation.','Failed');

          ajax_show_error(result,obj);

          removeLoader();

        });
  }
</script>
@endsection


