@extends('layouts.master')

@section('content')
<div class="content">
    <div class="row">
        <form action="{{ url('admin/roles/update/'.$role->id) }}" enctype="multipart/form-data" method="POST" role="form">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <header class="panel-heading" style="height:50px;">
                <div class="pull-left">
                    {{$title}}
                </div>
                <div>
                     @if(\Auth::user()->utype==1)
                        <a style="margin-left: 3px" href="{{ url('admin/roles') }}" class="btn btn-sm btn-info pull-right"><i class="fa fa-list"></i> Roles List</a> <br><br>
                    @endif
                </div>
            </header>
        </div>
        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-body">
                    {{ csrf_field() }}
                    <div class="col-md-6 col-md-offset-3">
                        <div class="form-group {{ $errors->has('name') ? 'has-error' : '' }}">
                            <label for="name">Roles Name <i class="text-danger">*</i></label>
                            <input type='text' name="name" id="name" class="form-control" value="{{ $role->name }}" placeholder="Name">
                            <lebel class="text-danger"> {{ $errors->first('name') }}</lebel>
                        </div>
                        <div class="form-group {{ $errors->has('display_name') ? 'has-error' : '' }}">
                            <label for="display_name">Display Name <i class="text-danger">*</i></label>
                            <input type='text' name="display_name" id="display_name" class="form-control" value="{{ $role->display_name }}" placeholder="Display Name">
                            <lebel class="text-danger"> {{ $errors->first('display_name') }}</lebel>
                        </div>
                        <div class="form-group {{ $errors->has('permission') ? 'has-error' : '' }}" style="height: 310px;overflow: scroll;">
                        <label for="permission">Assign Permission <i class="text-danger">*</i></label>
                            <div style="color: green;margin-bottom: 15px" class="checkbox">
                              <label ><input type="checkbox" name="select-all" id="select_all" /> Select All Items </label></br>
                            </div>
                            @foreach($all_permissions as $value)
                                <label>{{ Form::checkbox('permission[]', $value->id, in_array($value->id, $rolePermissions) ? true : false, array('class' => 'name')) }}
                                {{ $value->display_name }}</label>
                                <br/>
                            @endforeach
                             <lebel class="text-danger"> {{ $errors->first('permission') }}</lebel>
                        </div>

                        <div class="form-group pull-right">
                            <label for="level_name"></label>
                           <button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> Update</button>
                            <a href="{{ url('admin/roles') }}" class="btn btn-default">
                            <i class="fa fa-times"></i> Cancel</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        </form>
    </div>
</div>
@stop


@section('script')
<script type="text/javascript">
    $('#select_all').click(function(event) {
  if(this.checked) {
      // Iterate each checkbox
      $(':checkbox').each(function() {
          this.checked = true;
      });
  }
  else {
    $(':checkbox').each(function() {
          this.checked = false;
      });
  }
});

</script>
@if(Session::has('msg'))
    <div class="alert alert-success center-block msg_alt" >
        <a class="close" data-dismiss="alert" href="#">&times;</a>
        <strong><i class="fa fa-check"></i></strong>&nbsp;
    {{Session::get('msg')}}
    </div>
@endif

@stop