Set hours to read-only once they've changed away from PENDING #167
This commit is contained in:
parent
ac0058e951
commit
531c7ddba3
@ -141,11 +141,12 @@ class PirepController extends BaseController
|
||||
*/
|
||||
public function store(CreatePirepRequest $request)
|
||||
{
|
||||
$input = $request->all();
|
||||
$pirep = $this->pirepRepo->create($input);
|
||||
$attrs = $request->all();
|
||||
$pirep = $this->pirepRepo->create($attrs);
|
||||
|
||||
$pirep->flight_time = ((int) Utils::hoursToMinutes($request['hours']))
|
||||
+ ((int) $request['minutes']);
|
||||
$hours = (int) $attrs['hours'];
|
||||
$minutes = (int) $attrs['minutes'];
|
||||
$pirep->flight_time = Utils::hoursToMinutes($hours) + $minutes;
|
||||
|
||||
Flash::success('Pirep saved successfully.');
|
||||
return redirect(route('admin.pireps.index'));
|
||||
@ -187,8 +188,15 @@ class PirepController extends BaseController
|
||||
$pirep->hours = $hms['h'];
|
||||
$pirep->minutes = $hms['m'];
|
||||
|
||||
# Can we modify?
|
||||
$read_only = false;
|
||||
if($pirep->state !== PirepState::PENDING) {
|
||||
$read_only = false;
|
||||
}
|
||||
|
||||
return view('admin.pireps.edit', [
|
||||
'pirep' => $pirep,
|
||||
'read_only' => $read_only,
|
||||
'aircraft' => $this->aircraftList(),
|
||||
'airports' => $this->airportRepo->selectBoxList(),
|
||||
'airlines' => $this->airlineRepo->selectBoxList(),
|
||||
@ -205,16 +213,21 @@ class PirepController extends BaseController
|
||||
{
|
||||
$pirep = $this->pirepRepo->findWithoutFail($id);
|
||||
|
||||
$pirep->flight_time = ((int) Utils::hoursToMinutes($request['hours']))
|
||||
+ ((int) $request['minutes']);
|
||||
|
||||
if (empty($pirep)) {
|
||||
Flash::error('Pirep not found');
|
||||
return redirect(route('admin.pireps.index'));
|
||||
}
|
||||
|
||||
$attrs = $request->all();
|
||||
$orig_route = $pirep->route;
|
||||
$orig_flight_time = $pirep->flight_time;
|
||||
|
||||
$attrs = $request->all();
|
||||
|
||||
# Fix the time
|
||||
$hours = (int) $attrs['hours'];
|
||||
$minutes = (int) $attrs['minutes'];
|
||||
$attrs['flight_time'] = Utils::hoursToMinutes($hours) + $minutes;
|
||||
|
||||
$pirep = $this->pirepRepo->update($attrs, $id);
|
||||
|
||||
// A route change in the PIREP, so update the saved points in the ACARS table
|
||||
@ -257,12 +270,12 @@ class PirepController extends BaseController
|
||||
|
||||
$pirep = $this->pirepRepo->findWithoutFail($request->id);
|
||||
if($request->isMethod('post')) {
|
||||
$new_status = (int) $request->new_status;
|
||||
$new_status = (int) $request->post('new_status');
|
||||
$pirep = $this->pirepSvc->changeState($pirep, $new_status);
|
||||
}
|
||||
|
||||
$pirep->refresh();
|
||||
return view('admin.pireps.actions', ['pirep' => $pirep]);
|
||||
return view('admin.pireps.actions', ['pirep' => $pirep, 'on_edit_page' => false]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,6 +99,16 @@ class Pirep extends BaseModel
|
||||
return $flight_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do some cleanup on the route
|
||||
* @param $route
|
||||
*/
|
||||
public function setRouteAttribute($route)
|
||||
{
|
||||
$route = strtoupper(trim($route));
|
||||
$this->attributes['route'] = $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this PIREP is allowed to be updated
|
||||
* @return bool
|
||||
|
@ -21,6 +21,12 @@
|
||||
|
||||
<style type="text/css">
|
||||
@yield('css')
|
||||
|
||||
label {
|
||||
text-transform: uppercase;
|
||||
font-size: 14px;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
|
@ -1,30 +1,28 @@
|
||||
<table class="">
|
||||
<tr>
|
||||
<td>
|
||||
@if($pirep->state === PirepState::PENDING
|
||||
|| $pirep->state === PirepState::REJECTED)
|
||||
{!! Form::open(['url' => route('admin.pirep.status', ['id'=>$pirep->id]),
|
||||
@if($pirep->state === PirepState::PENDING || $pirep->state === PirepState::REJECTED)
|
||||
{!! Form::open(['url' => route('admin.pirep.status', ['id' => $pirep->id]),
|
||||
'method' => 'post',
|
||||
'name' => 'accept_'.$pirep->id,
|
||||
'id' => $pirep->id.'_accept',
|
||||
'pirep_id' => $pirep->id,
|
||||
'new_status' => PirepState::ACCEPTED,
|
||||
'class' => 'pirep_submit_status']) !!}
|
||||
'class' => $on_edit_page ? 'pirep_change_status': 'pirep_submit_status']) !!}
|
||||
{!! Form::button('Accept', ['type' => 'submit', 'class' => 'btn btn-info']) !!}
|
||||
{!! Form::close() !!}
|
||||
@endif
|
||||
</td>
|
||||
<td> </td>
|
||||
<td>
|
||||
@if($pirep->state === PirepState::PENDING
|
||||
|| $pirep->state === PirepState::ACCEPTED)
|
||||
{!! Form::open(['url' => route('admin.pirep.status', ['id'=>$pirep->id]),
|
||||
@if($pirep->state === PirepState::PENDING || $pirep->state === PirepState::ACCEPTED)
|
||||
{!! Form::open(['url' => route('admin.pirep.status', ['id' => $pirep->id]),
|
||||
'method' => 'post',
|
||||
'name' => 'reject_'.$pirep->id,
|
||||
'id' => $pirep->id.'_reject',
|
||||
'pirep_id' => $pirep->id,
|
||||
'new_status' => PirepState::REJECTED,
|
||||
'class' => 'pirep_submit_status']) !!}
|
||||
'class' => $on_edit_page ? 'pirep_change_status': 'pirep_submit_status']) !!}
|
||||
{!! Form::button('Reject', ['type' => 'submit', 'class' => 'btn btn-danger']) !!}
|
||||
{!! Form::close() !!}
|
||||
@endif
|
||||
|
@ -1,24 +1,14 @@
|
||||
@extends('admin.app')
|
||||
@section('title', 'Create PIREP')
|
||||
|
||||
@section('content')
|
||||
<section class="content-header">
|
||||
<h1>
|
||||
$MODEL_NAME_HUMAN$
|
||||
</h1>
|
||||
</section>
|
||||
<div class="content">
|
||||
<div class="card border-blue-bottom">
|
||||
<div class="content">
|
||||
<div class="box box-primary">
|
||||
|
||||
<div class="box-body">
|
||||
<div class="row">
|
||||
{!! Form::open(['route' => 'admin.pireps.store']) !!}
|
||||
|
||||
@include('admin.pireps.fields')
|
||||
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@include('admin.pireps.scripts')
|
||||
|
@ -1,10 +1,27 @@
|
||||
@extends('admin.app')
|
||||
|
||||
@section('title', 'Edit ' . $pirep->ident )
|
||||
|
||||
@section('content')
|
||||
<div class="content">
|
||||
<div class="card border-blue-bottom">
|
||||
<div class="content">
|
||||
|
||||
{{-- pulled out to here otherwise the form::close() within a form undo it --}}
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<h5 style="margin-top: 0px;">
|
||||
Filed By: <a href="{!! route('admin.users.edit', [$pirep->user_id]) !!}" target="_blank">
|
||||
{!! $pirep->user->pilot_id !!} {!! $pirep->user->name !!}
|
||||
</a>
|
||||
</h5>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="pull-right">
|
||||
@include('admin.pireps.actions', ['pirep' => $pirep, 'on_edit_page' => true])
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{!! Form::model($pirep, ['route' => ['admin.pireps.update', $pirep->id], 'method' => 'patch']) !!}
|
||||
@include('admin.pireps.fields')
|
||||
{!! Form::close() !!}
|
||||
@ -26,4 +43,5 @@
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@include('admin.pireps.scripts')
|
||||
|
@ -1,13 +1,3 @@
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-12">
|
||||
{{--<div class="avatar">
|
||||
<img src="{!! $pirep->pilot->gravatar() !!}" />
|
||||
</div>--}}
|
||||
Filed By: <a href="{!! route('admin.users.edit', [$pirep->pilot->id]) !!}" target="_blank">
|
||||
{!! $pirep->pilot->pilot_id !!} {!! $pirep->pilot->name !!}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-6">
|
||||
{!! Form::label('flight_number', 'Flight Number/Route Code/Leg') !!}
|
||||
@ -60,10 +50,10 @@
|
||||
{!! Form::label('flight_time', 'Flight Time (hours & minutes):') !!}
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
{!! Form::number('hours', null, ['class' => 'form-control', 'placeholder' => 'hours']) !!}
|
||||
{!! Form::number('hours', null, ['class' => 'form-control', 'placeholder' => 'hours', 'readonly' => $read_only]) !!}
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
{!! Form::number('minutes', null, ['class' => 'form-control', 'placeholder' => 'minutes']) !!}
|
||||
{!! Form::number('minutes', null, ['class' => 'form-control', 'placeholder' => 'minutes', 'readonly' => $read_only]) !!}
|
||||
</div>
|
||||
<p class="text-danger">{{ $errors->first('hours') }}</p>
|
||||
<p class="text-danger">{{ $errors->first('minutes') }}</p>
|
||||
|
@ -56,7 +56,7 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div id="pirep_{!! $pirep->id !!}_actionbar" class="pull-right">
|
||||
@include('admin.pireps.actions')
|
||||
@include('admin.pireps.actions', ['pirep' => $pirep, 'on_edit_page' => false])
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,7 +1,7 @@
|
||||
@section('scripts')
|
||||
<script>
|
||||
function changeStatus(values) {
|
||||
const destContainer = '#pirep_' + values.pirep_id + '_actionbar';
|
||||
const changeStatus = (values, fn) => {
|
||||
console.log('Changing PIREP ' + values.pirep_id + ' to state ' + values.new_status);
|
||||
$.ajax({
|
||||
url: BASE_URL + '/admin/pireps/' + values.pirep_id + '/status',
|
||||
data: values,
|
||||
@ -10,11 +10,10 @@ function changeStatus(values) {
|
||||
'x-api-key': PHPVMS_USER_API_KEY
|
||||
},
|
||||
success: function (data) {
|
||||
// console.log(data);
|
||||
$(destContainer).html(data);
|
||||
fn(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
@ -36,11 +35,22 @@ $(document).ready(function() {
|
||||
new_status: $(this).attr('new_status')
|
||||
};
|
||||
|
||||
console.log(values);
|
||||
console.log('Changing PIREP ' + values.pirep_id + ' to state ' + values.new_status);
|
||||
|
||||
changeStatus(values);
|
||||
changeStatus(values, (data) => {
|
||||
const destContainer = '#pirep_' + values.pirep_id + '_actionbar';
|
||||
$(destContainer).html(data);
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('submit', 'form.pirep_change_status', function(event) {
|
||||
event.preventDefault();
|
||||
changeStatus({
|
||||
pirep_id: $(this).attr('pirep_id'),
|
||||
new_status: $(this).attr('new_status')
|
||||
}, (data) => {
|
||||
location.reload();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
|
Loading…
Reference in New Issue
Block a user