v0.10.0a - Added last support for NameCheck

This commit is contained in:
Neerholt 2020-08-17 10:31:33 +02:00
parent 5f516992d7
commit fe9eb4fd4d
5 changed files with 139 additions and 4 deletions

View File

@ -131,4 +131,12 @@ class LocationController extends Controller
{
}
public function nameCheck(Request $request){
$locations = Location::query()->where('name', 'LIKE',$request->nameCheck)->get();
if(count($locations) > 0 && $request->nameCheck !== NULL){
return 1;
}
}
}

View File

@ -153,4 +153,15 @@ class WashingMachineController extends Controller
return redirect()->route("washing-machines.index");
}
public function nameCheck(Request $request){
$washing = WashingMachine::query()->where('name', 'LIKE',$request->nameCheck)->get();
if(count($washing) > 0 && $request->nameCheck !== NULL){
return 1;
}
}
}

View File

@ -10,12 +10,13 @@
@endsection
@section("content")
<h1>Opret Lokation</h1>
<h1 id="errormesseages" >Opret Lokation</h1>
<form method="post" action="{{ route("locations.store") }}">
@csrf
<label for="name">Lokationsnavn:</label>
<label hidden id="error" for="errormesseages">Lokation findes allerede</label>
<input type="text" name="name" id="name" placeholder="Bygning A" required>
<input type="submit" class="btn btn-dark text-white" value="Opret">
<input type="submit" id="disable" class="btn btn-dark text-white" value="Opret">
</form>
@endsection
@section("scripts")
@ -28,5 +29,61 @@
}
);
});
//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('locations.nameCheck')}}',
data: {'nameCheck':$value},
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('locations.nameCheck')}}',
data: {'nameCheck':$value},
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>
@endsection

View File

@ -10,10 +10,11 @@
@endsection
@section("content")
<h1>Opret Vaskemaskine:</h1>
<h1 id="errormesseages" >Opret Vaskemaskine:</h1>
<form method="post" action="{{ route("washing-machines.store") }}">
@csrf
<label for="name_first">Vaskemaskine Navn:</label>
<label hidden id="error" for="errormesseages">Vaskemaskinen findes allerede</label>
<input type="text" name="name" id="name" max="60" placeholder="Vaskemaskine nr. 1" required>
<label for="location_id">Lokation:</label>
<select name="location_id" id="location_id" class="mb-2" required>
@ -26,7 +27,7 @@
<option disabled> Der er ingen lokationer oprettet!</option>
@endif
</select>
<input type="submit" class="btn btn-dark text-white" value="Opret">
<input type="submit" id="disable" class="btn btn-dark text-white" value="Opret">
</form>
@endsection
@section("scripts")
@ -39,5 +40,60 @@
}
);
});
//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.nameCheck')}}',
data: {'nameCheck':$value},
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.nameCheck')}}',
data: {'nameCheck':$value},
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>
@endsection

View File

@ -62,6 +62,9 @@ Route::get("/usersCheck", "UserController@nameCheck")->name("users.nameCheck");
Route::get("/guidesCheck", "GuideController@nameCheck")->name("guides.nameCheck");
Route::get("/newsCheck", "NewsController@nameCheck")->name("news.nameCheck");
Route::get("/menuplanCheck", "MenuPlanController@nameCheck")->name("menuplans.nameCheck");
Route::get("/locationsCheck", "LocationController@nameCheck")->name("locations.nameCheck");
Route::get("/washingCheck", "WashingMachineController@nameCheck")->name("washing-machines.nameCheck");