-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
529 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
use App\Area; | ||
use App\Area_en; | ||
use flash; | ||
use DB; | ||
|
||
class AreasController extends Controller | ||
{ | ||
public function index(){ | ||
$dbData = Area::get(); | ||
// Si terminó de borrar el registro | ||
$toast = session('delete_failed'); | ||
if($toast){ | ||
session()->forget('delete_failed'); | ||
} | ||
return view('areas.list')->with('dbData', $dbData)->with('toast', $toast); | ||
} | ||
|
||
public function create(){ | ||
return view('areas.create'); | ||
} | ||
|
||
public function store(Request $request){ | ||
DB::transaction(function() use($request){ | ||
//Cargamos el área en español | ||
$dbData = new Area($request->all()); | ||
//Cargamos el área en inglés | ||
$dbDataEn = new Area_en(); | ||
$dbDataEn->descripcion = $request->descripcion_en; | ||
//Guardamos los registros | ||
$dbData->save(); | ||
$dbDataEn->save(); | ||
}); | ||
|
||
return redirect()->route('areas.index'); | ||
} | ||
|
||
public function show($id) | ||
{ | ||
// | ||
} | ||
|
||
public function edit($id){ | ||
$dbData = Area::find($id); | ||
return view('areas.edit')->with('dbData', $dbData); | ||
} | ||
|
||
public function update(Request $request, $id){ | ||
|
||
//Area en español | ||
$dbData = Area::find($id); | ||
//Area en inglés | ||
$dbDataEn = Area_en::find($id); | ||
DB::transaction(function() use($request, $id, $dbData, $dbDataEn){ | ||
//Cargamos el área en español | ||
$dbData->fill($request->all()); | ||
//Cargamos el área en inglés | ||
$dbDataEn->descripcion = $request->descripcion_en; | ||
//Guardamos los registos | ||
$dbData->save(); | ||
$dbDataEn->save(); | ||
}); | ||
|
||
|
||
|
||
return redirect()->route('areas.index'); | ||
} | ||
|
||
public function destroy($id){ | ||
DB::beginTransaction(); | ||
try{ | ||
$dbData = Area::find($id); | ||
$dbDataEn = Area_en::find($id); | ||
$dbData->delete(); | ||
$dbDataEn->delete(); | ||
}catch(\Exception $e){ | ||
DB::rollback(); | ||
session(['delete_failed'=>"true"]); | ||
return redirect()->back()->withErrors($e->getMessage()); | ||
} | ||
DB::commit(); | ||
|
||
return redirect()->route('areas.index'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
use App\Nivel; | ||
use App\Nivel_en; | ||
use flash; | ||
use DB; | ||
|
||
class NivelesController extends Controller | ||
{ | ||
public function index(){ | ||
$dbData = Nivel::get(); | ||
// Si terminó de borrar el registro | ||
$toast = session('delete_failed'); | ||
if($toast){ | ||
session()->forget('delete_failed'); | ||
} | ||
return view('niveles.list')->with('dbData', $dbData)->with('toast', $toast); | ||
} | ||
|
||
public function create(){ | ||
return view('niveles.create'); | ||
} | ||
|
||
public function store(Request $request){ | ||
DB::transaction(function() use($request){ | ||
//Cargamos el área en español | ||
$dbData = new Nivel($request->all()); | ||
//Cargamos el área en inglés | ||
$dbDataEn = new Nivel_en(); | ||
$dbDataEn->descripcion = $request->descripcion_en; | ||
//Guardamos los registros | ||
$dbData->save(); | ||
$dbDataEn->save(); | ||
}); | ||
|
||
return redirect()->route('niveles.index'); | ||
} | ||
|
||
public function show($id) | ||
{ | ||
// | ||
} | ||
|
||
public function edit($id){ | ||
$dbData = nivel::find($id); | ||
return view('niveles.edit')->with('dbData', $dbData); | ||
} | ||
|
||
public function update(Request $request, $id){ | ||
|
||
//nivel en español | ||
$dbData = Nivel::find($id); | ||
//nivel en inglés | ||
$dbDataEn = Nivel_en::find($id); | ||
DB::transaction(function() use($request, $id, $dbData, $dbDataEn){ | ||
//Cargamos el área en español | ||
$dbData->fill($request->all()); | ||
//Cargamos el área en inglés | ||
$dbDataEn->descripcion = $request->descripcion_en; | ||
//Guardamos los registos | ||
$dbData->save(); | ||
$dbDataEn->save(); | ||
}); | ||
return redirect()->route('niveles.index'); | ||
} | ||
|
||
public function destroy($id){ | ||
DB::beginTransaction(); | ||
try{ | ||
$dbData = Nivel::find($id); | ||
$dbDataEn = Nivel_en::find($id); | ||
$dbData->delete(); | ||
$dbDataEn->delete(); | ||
|
||
}catch(\Exception $e){ | ||
DB::rollback(); | ||
session(['delete_failed'=>"true"]); | ||
return redirect()->back()->withErrors($e->getMessage()); | ||
} | ||
DB::commit(); | ||
return redirect()->route('niveles.index'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
@extends('layout') | ||
@section('content') | ||
<div class="row"> | ||
<div class="browser-window"> | ||
<div class="top-bar"> | ||
<h4>Crear Nueva Area</h4> | ||
</div> | ||
<div class="content"> | ||
<form class="col s12" action="{{route('areas.store')}}" method="POST"> | ||
<div class="row"> | ||
<div class="input-field col s6"> | ||
<input id="descripcion" type="text" class="validate" name="descripcion" > | ||
<label for="descripcion">Descripción (En español)</label> | ||
</div> | ||
<div class="input-field col s6"> | ||
<input id="descripcion_en" type="text" class="validate" name="descripcion_en" > | ||
<label for="descripcion_en">Descripción (en inglés)</label> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<input type="hidden" name="_token" value="{{{ csrf_token() }}}" /> | ||
<button class="btn waves-effect waves-light" type="submit" name="submit">Guardar | ||
<i class="material-icons left">save</i> | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
@stop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@extends('layout') | ||
@section('content') | ||
<div class="row"> | ||
<div class="browser-window"> | ||
<div class="top-bar"> | ||
<h4>Editar Area</h4> | ||
</div> | ||
<div class="content"> | ||
<form class="col s12" action="{{route('areas.update', $dbData->id)}}" method="POST"> | ||
<div class="row"> | ||
<div class="input-field col s6"> | ||
<input id="descripcion" type="text" class="validate" name="descripcion" value="{{$dbData->descripcion}}"> | ||
<label for="descripcion">Descripción (En español)</label> | ||
</div> | ||
<div class="input-field col s6"> | ||
<input id="descripcion_en" type="text" class="validate" name="descripcion_en" value="{{$dbData->areaEn->descripcion}}"> | ||
<label for="descripcion_en">Descripción (en inglés)</label> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<input type="hidden" name="_token" value="{{{ csrf_token() }}}" /> | ||
{{ method_field('PUT') }} | ||
<button class="btn waves-effect waves-light" type="submit" name="submit">Guardar | ||
<i class="material-icons left">save</i> | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
@stop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
@extends('layout') | ||
|
||
@section('content') | ||
<div class="row"> | ||
<div class="col l4"> | ||
<a href="{{ route('areas.create') }}" class="btn waves-effect waves-light lighten-1 white-text"><i class="material-icons left">add</i>Area</a> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="browser-window"> | ||
<div class="top-bar"> | ||
<h4>Listado de Areas</h4> | ||
</div> | ||
<div class="content"> | ||
<table id="Listado" class="highlight"> | ||
<thead> | ||
<tr> | ||
<th>Id</th> | ||
<th>Descripción</th> | ||
<th>Descripción (Inglés)</th> | ||
<th>Opciones</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach($dbData as $est) | ||
<tr> | ||
<td>{{ $est->id }}</td> | ||
<td>{{ $est->descripcion }}</td> | ||
<td>{{ $est->areaEn->descripcion }}</td> | ||
<td><a href="{{ route('areas.edit', $est->id) }}" class="btn waves-light waves-effect lighten-1 white-text "> | ||
<i class="material-icons left">edit</i>Editar | ||
</a> | ||
|
||
<a href="{{ route('areas.destroy', $est->id) }}" class="btn waves-light waves-effect lighten-1 red white-text" onclick="delete_row({{$est->id}})"> | ||
<i class="material-icons left">delete</i>Borrar | ||
</a> | ||
<form id="delete-form{{$est->id}}" action="{{ route('areas.destroy', $est->id) }}" method="POST" style="display: none;"> | ||
{{ csrf_field() }} | ||
{{ method_field('DELETE') }} | ||
|
||
</form> | ||
</td> | ||
</tr> | ||
@endforeach | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
@if($toast) | ||
<div id="toast"></div> | ||
@endif | ||
|
||
@endsection | ||
@push('scripts') | ||
<script type="text/javascript"> | ||
$(function(){ | ||
$('#Listado').DataTable({ | ||
"scrollX": false, | ||
"scrollCollapse": false, | ||
"lengthChange": false, | ||
"columnDefs": [ | ||
{ "targets": [2], | ||
"orderable": false, | ||
"searchable": false | ||
} | ||
], | ||
"language": { | ||
"decimal": ",", | ||
"thousands": ".", | ||
"zeroRecords": "No hay registros - Lo sentimos", | ||
"info": "Página _PAGE_ de _PAGES_", | ||
"infoEmpty": "No hay registros disponibles", | ||
"infoFiltered": "(Filtrado de un total de _MAX_ registros)" | ||
} | ||
}); | ||
}); | ||
if($("#toast").length > 0){ | ||
M.toast({html: 'Error al borrar el Registro'}); | ||
} | ||
function delete_row(row){ | ||
event.preventDefault(); | ||
if (confirm('Seguro que desea eliminar el registro?')){ | ||
document.getElementById('delete-form'+row).submit(); | ||
} else { | ||
return false; | ||
} | ||
} | ||
</script> | ||
@endpush |
Oops, something went wrong.