v0.10.0c - Fixed WashingMachine create & update AJAX
This commit is contained in:
parent
3bde377caa
commit
5ac480454a
|
@ -70,7 +70,7 @@ class WashingMachineController extends Controller
|
||||||
|
|
||||||
// If there already is a washing machine with that name, then don't add it
|
// If there already is a washing machine with that name, then don't add it
|
||||||
if (count($allMachines) > 0)
|
if (count($allMachines) > 0)
|
||||||
return redirect()->route("washing-machines.store")->with('WashingNameExists', '<p><b>Der findes allerede en vaskemaskine med det navn!</b></p>');
|
return redirect()->route("washing-machines.store");
|
||||||
else { // Else - Add it
|
else { // Else - Add it
|
||||||
$machine->save();
|
$machine->save();
|
||||||
$machines = WashingMachine::query()->paginate($request->input("limit", 20));
|
$machines = WashingMachine::query()->paginate($request->input("limit", 20));
|
||||||
|
@ -127,7 +127,7 @@ class WashingMachineController extends Controller
|
||||||
|
|
||||||
// If there already is a washing machine with that name, then don't change it
|
// If there already is a washing machine with that name, then don't change it
|
||||||
if (count($allMachines) > 0)
|
if (count($allMachines) > 0)
|
||||||
return redirect()->route("washing-machines.store")->with('WashingNameExists', '<p><b>Der findes allerede en vaskemaskine med det navn!</b></p>');
|
return redirect()->route("washing-machines.store");
|
||||||
else { // Else - Change the name
|
else { // Else - Change the name
|
||||||
$machine->update($data);
|
$machine->update($data);
|
||||||
$machine->save();
|
$machine->save();
|
||||||
|
@ -154,14 +154,17 @@ class WashingMachineController extends Controller
|
||||||
return redirect()->route("washing-machines.index");
|
return redirect()->route("washing-machines.index");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function nameCheck(Request $request){
|
public function nameCheck(Request $request){
|
||||||
$washing = WashingMachine::query()->where('name', 'LIKE',$request->nameCheck)->get();
|
$washing = WashingMachine::query()->where('name', 'LIKE',$request->nameCheck)->where('location_id', '=', $request->location)->get();
|
||||||
if(count($washing) > 0 && $request->nameCheck !== NULL){
|
if(count($washing) > 0 && $request->nameCheck !== NULL){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function nameCheckUpdate(Request $request){
|
||||||
|
$washing = WashingMachine::query()->where('name', 'LIKE',$request->nameCheck)->where('location_id', '=', $request->location)->where('id', '!=', $request->id)->get();
|
||||||
|
if(count($washing) > 0 && $request->nameCheck !== NULL){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<form method="post" action="{{ route("washing-machines.store") }}">
|
<form method="post" action="{{ route("washing-machines.store") }}">
|
||||||
@csrf
|
@csrf
|
||||||
<label for="name_first">Vaskemaskine Navn:</label>
|
<label for="name_first">Vaskemaskine Navn:</label>
|
||||||
<label hidden id="error" for="errormesseages">Vaskemaskinen findes allerede</label>
|
<label hidden id="error" for="errormesseages">Vaskemaskinen med den lokation findes allerede</label>
|
||||||
<input type="text" name="name" id="name" max="60" placeholder="Vaskemaskine nr. 1" required>
|
<input type="text" name="name" id="name" max="60" placeholder="Vaskemaskine nr. 1" required>
|
||||||
<label for="location_id">Lokation:</label>
|
<label for="location_id">Lokation:</label>
|
||||||
<select name="location_id" id="location_id" class="mb-2" required>
|
<select name="location_id" id="location_id" class="mb-2" required>
|
||||||
|
@ -41,15 +41,13 @@
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Dont delete me, if the user reloads the pages with text in the text-box this code runs.
|
//Dont delete me, if the user reloads the pages with text in the text-box this code runs.
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$value = $('#name').val();
|
$value = $('#name').val();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'get',
|
type: 'get',
|
||||||
url: '{{route('washing-machines.nameCheck')}}',
|
url: '{{route('washing-machines.nameCheck')}}',
|
||||||
data: {'nameCheck':$value},
|
data: {'nameCheck':$value, 'location': $('#location_id').val()},
|
||||||
success:function (data) {
|
success:function (data) {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
if(data){
|
if(data){
|
||||||
|
@ -75,7 +73,7 @@
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'get',
|
type: 'get',
|
||||||
url: '{{route('washing-machines.nameCheck')}}',
|
url: '{{route('washing-machines.nameCheck')}}',
|
||||||
data: {'nameCheck':$value},
|
data: {'nameCheck':$value, 'location': $('#location_id').val()},
|
||||||
success:function (data) {
|
success:function (data) {
|
||||||
if(data){
|
if(data){
|
||||||
$("#error").show(100);
|
$("#error").show(100);
|
||||||
|
@ -95,5 +93,29 @@
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$('#location_id').on('change', function () {
|
||||||
|
$value = $('#name').val();
|
||||||
|
$.ajax({
|
||||||
|
type: 'get',
|
||||||
|
url: '{{route('washing-machines.nameCheck')}}',
|
||||||
|
data: {'nameCheck':$value, 'location': $('#location_id').val()},
|
||||||
|
success:function (data) {
|
||||||
|
if(data){
|
||||||
|
$("#error").show(100);
|
||||||
|
$("#error").css('color', 'red');
|
||||||
|
$("#disable").prop('disabled', true);
|
||||||
|
$('#disable').css('cursor','not-allowed');
|
||||||
|
}else{
|
||||||
|
$("#error").hide();
|
||||||
|
$("#disable").prop('disabled', false);
|
||||||
|
$('#disable').css('cursor','pointer');
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
error:function (data) {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
@csrf
|
@csrf
|
||||||
@method("put")
|
@method("put")
|
||||||
<label for="name_first">Vaskemaskine Navn:</label>
|
<label for="name_first">Vaskemaskine Navn:</label>
|
||||||
|
<label hidden id="error" for="errormesseages">Vaskemaskinen med den lokation findes allerede</label>
|
||||||
<input type="text" name="name" id="name" max="60" value="{{$machine->name}}" required>
|
<input type="text" name="name" id="name" max="60" value="{{$machine->name}}" required>
|
||||||
<select class="w-100" name="location_id" id="location_id" class="mb-2" required>
|
<select class="w-100" name="location_id" id="location_id" class="mb-2" required>
|
||||||
<option disabled> -- Vælg Lokation -- </option>
|
<option disabled> -- Vælg Lokation -- </option>
|
||||||
|
@ -25,7 +26,7 @@
|
||||||
<option {{ $selected }} value="{{ $location->id }}">{{ $location->name }}</option>
|
<option {{ $selected }} value="{{ $location->id }}">{{ $location->name }}</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
</select>
|
</select>
|
||||||
<input type="submit" class="btn btn-dark text-white" value="Rediger">
|
<input type="submit" id="disable" class="btn btn-dark text-white" value="Rediger">
|
||||||
</form>
|
</form>
|
||||||
@endsection
|
@endsection
|
||||||
@section("scripts")
|
@section("scripts")
|
||||||
|
@ -38,5 +39,82 @@
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Dont delete me, if the user reloads the pages with text in the text-box this code runs.
|
||||||
|
$(document).ready(function () {
|
||||||
|
$value = $('#name').val();
|
||||||
|
$.ajax({
|
||||||
|
type: 'get',
|
||||||
|
url: '{{route('washing-machines.nameCheckUpdate')}}',
|
||||||
|
data: {'nameCheck':$value, 'location': $('#location_id').val(), 'id': {{$machine->id}}},
|
||||||
|
success:function (data) {
|
||||||
|
console.log(data);
|
||||||
|
if(data){
|
||||||
|
$("#error").show(100);
|
||||||
|
$("#error").css('color', 'red');
|
||||||
|
$("#disable").prop('disabled', true);
|
||||||
|
$('#disable').css('cursor','not-allowed');
|
||||||
|
}else{
|
||||||
|
$("#error").hide();
|
||||||
|
$("#disable").prop('disabled', false);
|
||||||
|
$('#disable').css('cursor','pointer');
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
error:function (data) {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#name').on('keyup', function () {
|
||||||
|
$value = $(this).val();
|
||||||
|
$.ajax({
|
||||||
|
type: 'get',
|
||||||
|
url: '{{route('washing-machines.nameCheckUpdate')}}',
|
||||||
|
data: {'nameCheck':$value, 'location': $('#location_id').val(), 'id': {{$machine->id}}},
|
||||||
|
success:function (data) {
|
||||||
|
if(data){
|
||||||
|
$("#error").show(100);
|
||||||
|
$("#error").css('color', 'red');
|
||||||
|
$("#disable").prop('disabled', true);
|
||||||
|
$('#disable').css('cursor','not-allowed');
|
||||||
|
}else{
|
||||||
|
$("#error").hide();
|
||||||
|
$("#disable").prop('disabled', false);
|
||||||
|
$('#disable').css('cursor','pointer');
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
error:function (data) {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#location_id').on('change', function () {
|
||||||
|
$value = $('#name').val();
|
||||||
|
$.ajax({
|
||||||
|
type: 'get',
|
||||||
|
url: '{{route('washing-machines.nameCheckUpdate')}}',
|
||||||
|
data: {'nameCheck':$value, 'location': $('#location_id').val(), 'id': {{$machine->id}}},
|
||||||
|
success:function (data) {
|
||||||
|
if(data){
|
||||||
|
$("#error").show(100);
|
||||||
|
$("#error").css('color', 'red');
|
||||||
|
$("#disable").prop('disabled', true);
|
||||||
|
$('#disable').css('cursor','not-allowed');
|
||||||
|
}else{
|
||||||
|
$("#error").hide();
|
||||||
|
$("#disable").prop('disabled', false);
|
||||||
|
$('#disable').css('cursor','pointer');
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
error:function (data) {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
<div class="row align-items-center">
|
<div class="row align-items-center">
|
||||||
<a class="btn btn-inline btn-sde-blue mb-0" href="{{ route('washing-machines.create') }}"><img src="{{ asset('/images/icons/plus.svg') }}" alt="Create">Opret Vaskemaskine</a>
|
<a class="btn btn-inline btn-sde-blue mb-0" href="{{ route('washing-machines.create') }}"><img src="{{ asset('/images/icons/plus.svg') }}" alt="Create">Opret Vaskemaskine</a>
|
||||||
</div>
|
</div>
|
||||||
{!! session()->get('WashingNameExists') !!}
|
|
||||||
<table class="tbl mt-2">
|
<table class="tbl mt-2">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Navn</th>
|
<th>Navn</th>
|
||||||
|
|
|
@ -73,6 +73,7 @@ Route::get("/guidesCheckUpdate", "GuideController@nameCheckUpdate")->name("guide
|
||||||
Route::get("/newsCheckUpdate", "NewsController@nameCheckUpdate")->name("news.nameCheckUpdate");
|
Route::get("/newsCheckUpdate", "NewsController@nameCheckUpdate")->name("news.nameCheckUpdate");
|
||||||
Route::get("/menuplanCheckUpdate", "MenuPlanController@nameCheckUpdate")->name("menuplans.nameCheckUpdate");
|
Route::get("/menuplanCheckUpdate", "MenuPlanController@nameCheckUpdate")->name("menuplans.nameCheckUpdate");
|
||||||
Route::get("/locationsCheckUpdate", "LocationController@nameCheckUpdate")->name("locations.nameCheckUpdate");
|
Route::get("/locationsCheckUpdate", "LocationController@nameCheckUpdate")->name("locations.nameCheckUpdate");
|
||||||
|
Route::get("/washingCheckUpdate", "WashingMachineController@nameCheckUpdate")->name("washing-machines.nameCheckUpdate");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue