Add/edit the award class in Admin #155

This commit is contained in:
Nabeel Shahzad
2018-03-17 12:17:38 -05:00
parent a21e2dd412
commit e9baf4acb5
14 changed files with 195 additions and 86 deletions

View File

@@ -3,9 +3,10 @@
@section('content')
<div class="card border-blue-bottom">
<div class="content">
{!! Form::open(['route' => 'admin.awards.store']) !!}
{{ Form::open(['route' => 'admin.awards.store']) }}
@include('admin.awards.fields')
{!! Form::close() !!}
{{ Form::close() }}
</div>
</div>
@endsection
@include('admin.awards.scripts')

View File

@@ -3,9 +3,10 @@
@section('content')
<div class="card border-blue-bottom">
<div class="content">
{!! Form::model($award, ['route' => ['admin.awards.update', $award->id], 'method' => 'patch']) !!}
{{ Form::model($award, ['route' => ['admin.awards.update', $award->id], 'method' => 'patch']) }}
@include('admin.awards.fields')
{!! Form::close() !!}
{{ Form::close() }}
</div>
</div>
@endsection
@include('admin.awards.scripts')

View File

@@ -1,46 +1,78 @@
<div class="row">
<div class="col-md-12">
<div class="callout callout-success">
Awards that can be granted to pilots.
<div class="col-sm-12">
@component('admin.components.info')
These are the awards that pilots can earn. Each award is assigned an
award class, which will be run whenever a pilot's stats are changed,
including after a PIREP is accepted.
@endcomponent
</div>
</div>
<div class="row">
<div class="form-group col-sm-6">
{!! Form::label('name', 'Name:') !!}&nbsp;<span class="required">*</span>
<div class="callout callout-info">
<i class="icon fa fa-info">&nbsp;&nbsp;</i>
This will be the title of the award
</div>
<br />
{!! Form::text('name', null, ['class' => 'form-control']) !!}
<p class="text-danger">{{ $errors->first('name') }}</p>
</div>
<div class="form-group col-sm-6">
{!! Form::label('image', 'Image:') !!}
<div class="callout callout-info">
<i class="icon fa fa-info">&nbsp;&nbsp;</i>
This is the image of the award. Be creative!
</div>
{!! Form::text('image_url', null, [
'class' => 'form-control',
'placeholder' => 'Enter the url of the image location'
]) !!}
<p class="text-danger">{{ $errors->first('image_url') }}</p>
</div>
</div>
<div class="row">
<div class="form-group col-sm-6">
{!! Form::label('title', 'Title:') !!}&nbsp;<span class="required">*</span>
<div class="callout callout-info">
<i class="icon fa fa-info">&nbsp;&nbsp;</i>
This will be the title of the award
<div class="form-group col-sm-6">
{!! Form::label('description', 'Description:') !!}&nbsp
<div class="callout callout-info">
<i class="icon fa fa-info">&nbsp;&nbsp;</i>
This is the description of the award.
</div>
{!! Form::textarea('description', null, ['class' => 'form-control']) !!}
<p class="text-danger">{{ $errors->first('description') }}</p>
</div>
{!! Form::text('title', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group col-sm-6">
<div>
{{ Form::label('ref_class', 'Award Class:') }}
{{ Form::select('ref_class', $award_classes, null , [
'class' => 'form-control select2',
'id' => 'award_class_select',
]) }}
<p class="text-danger">{{ $errors->first('ref_class') }}</p>
</div>
<div>
{{ Form::label('ref_class_params', 'Award Class parameters') }}
{{ Form::text('ref_class_params', null, ['class' => 'form-control']) }}
<p class="text-danger">{{ $errors->first('ref_class_params') }}</p>
<div class="form-group col-sm-6">
{!! Form::label('image', 'Image:') !!}
<div class="callout callout-info">
<i class="icon fa fa-info">&nbsp;&nbsp;</i>
This is the image of the award. Be creative!
</div>
{!! Form::text('image', null, ['class' => 'form-control', 'placeholder' => 'Enter the url of the image location']) !!}
</div>
<p id="ref_class_param_description">
<div class="form-group col-sm-6">
{!! Form::label('description', 'Description:') !!}&nbsp
<div class="callout callout-info">
<i class="icon fa fa-info">&nbsp;&nbsp;</i>
This is the description of the award.
</div>
{!! Form::textarea('description', null, ['class' => 'form-control']) !!}
</div>
</p>
</div>
<!-- Submit Field -->
<div class="form-group col-sm-12">
<div class="pull-right">
{!! Form::button('Save', ['type' => 'submit', 'class' => 'btn btn-success']) !!}
<a href="{!! route('admin.awards.index') !!}" class="btn btn-warn">Cancel</a>
</div>
</div>
<div class="row">
<!-- Submit Field -->
<div class="form-group col-sm-12">
<div class="pull-right">
{!! Form::button('Save', ['type' => 'submit', 'class' => 'btn btn-success']) !!}
<a href="{!! route('admin.awards.index') !!}" class="btn btn-warn">Cancel</a>
</div>
</div>
</div>

View File

@@ -0,0 +1,31 @@
@section('scripts')
<script>
@if(isset($award_descriptions))
const award_descriptions = {!! json_encode($award_descriptions) !!};
@else
const award_descriptions = {};
@endif
const changeParamDescription = (award_class) => {
const descrip = award_descriptions[award_class];
console.log('Found description: ', descrip);
$("p#ref_class_param_description").text(descrip);
};
$(document).ready(() => {
const select_id = "select#award_class_select";
console.log('award descriptions', award_descriptions);
$(select_id).change((e) => {
const award_class = $(select_id + " option:selected").val();
console.log('award class selected: ', award_class);
changeParamDescription(award_class);
});
// on load
const award_class = $(select_id + " option:selected").val();
changeParamDescription(award_class);
});
</script>
@endsection

View File

@@ -1,9 +0,0 @@
@extends('admin.app')
@section('content')
<div class="card border-blue-bottom">
<div class="content">
@include('admin.awards.show_fields')
</div>
</div>
@endsection

View File

@@ -1,17 +0,0 @@
<!-- Title Field -->
<div class="form-group">
{!! Form::label('title', 'Title:') !!}
<p>{!! $award->title !!}</p>
</div>
<!-- Description Field -->
<div class="form-group">
{!! Form::label('Description', 'Description:') !!}
<p>{!! $award->description !!}</p>
</div>
<!-- Image Field -->
<div class="form-group">
{!! Form::label('image', 'Image:') !!}
<p><img src="{!! $award->image !!}" alt="No Image Available" /></p>
</div>

View File

@@ -1,21 +1,38 @@
<table class="table table-hover table-responsive" id="awards-table">
<thead>
<th>Title</th>
<th class="text-center">Description</th>
<th class="text-center">Image</th>
<th>Name</th>
<th>Description</th>
<th>Image</th>
<th class="text-right">Action</th>
</thead>
<tbody>
@foreach($awards as $award)
<tr>
<td>{!! $award->title !!}</td>
<td class="text-center">{!! $award->description !!}</td>
<td class="text-center"><img src="{!! $award->image !!}" name="{!! $award->title !!}" alt="No Image Available" /></td>
<td>
<a href="{{ route('admin.awards.edit', [$award->id]) }}">
{{ $award->name }}</a>
</td>
<td>{{ $award->description }}</td>
<td>
@if($award->image)
<img src="{{ $award->image }}" name="{{ $award->name }}" alt="No Image Available" />
@else
-
@endif
</td>
<td class="text-right">
{!! Form::open(['route' => ['admin.awards.destroy', $award->id], 'method' => 'delete']) !!}
<a href="{!! route('admin.awards.edit', [$award->id]) !!}" class='btn btn-sm btn-success btn-icon'><i class="fa fa-pencil-square-o"></i></a>
{!! Form::button('<i class="fa fa-times"></i>', ['type' => 'submit', 'class' => 'btn btn-sm btn-danger btn-icon', 'onclick' => "return confirm('Are you sure you want to delete this award?')"]) !!}
{!! Form::close() !!}
{{ Form::open(['route' => ['admin.awards.destroy', $award->id], 'method' => 'delete']) }}
<a href="{{ route('admin.awards.edit', [$award->id]) }}" class='btn btn-sm btn-success btn-icon'>
<i class="fas fa-pencil-alt"></i></a>
{{ Form::button('<i class="fa fa-times"></i>', [
'type' => 'submit',
'class' => 'btn btn-sm btn-danger btn-icon',
'onclick' => "return confirm('Are you sure you want to delete this award?')"
]) }}
{{ Form::close() }}
</td>
</tr>
@endforeach