Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
fix: Replace user edit with user add & user password reset
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanViknar committed Apr 16, 2024
1 parent 74a9d3d commit 0c55b8e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 91 deletions.
10 changes: 1 addition & 9 deletions public/css/admin_users.css
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,6 @@ div#user_details {
padding: 1vw;
}

/* Not loaded */

div#user_details div#user_details_not_loaded {
margin: auto;
}

/* Loaded */

div#user_details div#user_details_loaded {
div#user_details div {
margin: auto;
}
53 changes: 26 additions & 27 deletions public/js/admin_users.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ document.querySelector('.search_input').addEventListener('input', function() {
});

// User details system
let not_loaded_div = document.querySelector('#user_details_not_loaded');
let loaded_div = document.querySelector('#user_details_loaded');

let user_id = document.querySelector('#user_id');
let username_field = document.querySelector('#name');
let email_field = document.querySelector('#email');
Expand All @@ -29,30 +26,32 @@ let gender_field = {
};
let job_field = document.querySelector('#job');
let password_field = document.querySelector('#password');

let user_details_empty = document.querySelector('#user_details_empty');
let user_details_add = document.querySelector('#user_details_add');
let user_details_edit = document.querySelector('#user_details_edit');

// Add user

function displayUserAddMenu() {
// Display add menu
user_details_empty.classList.add('hidden');
user_details_edit.classList.add('hidden');
user_details_add.classList.remove('hidden');
}

// Edit user

let user_id_password_reset = document.querySelector('#user_id_password_reset');
let user_id_delete = document.querySelector('#user_id_delete');

function displayUserDetails(user) {
loaded_div.classList.remove('hidden');
not_loaded_div.classList.add('hidden');

// Set values
user_id.value = user.id;
username_field.value = user.name;
email_field.value = user.email;
first_name_field.value = user.first_name;
last_name_field.value = user.last_name;
birthday_field.value = user.birth;
switch (user.gender) {
case 0:
gender_field[0].checked = true;
break;
case 1:
gender_field[1].checked = true;
break;
default:
gender_field[2].checked = true;
break;
}
job_field.value = user.job_id;
user_id_delete.value = user.id;
function displayUserEditMenu(user) {
// Display edit menu
user_details_empty.classList.add('hidden');
user_details_add.classList.add('hidden');
user_details_edit.classList.remove('hidden');

// Set fields to the appropriate values
user_id_password_reset.value = user.id
user_id_delete.value = user.id
}
86 changes: 31 additions & 55 deletions resources/views/admin_users.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
@endforeach
<div class=manager>
<div id="user_list">
<div class="search_container">
<img class="search_icon"src="{{ asset('img/search-icon.svg') }}">
<input type="text" class="search_input" placeholder="Rechercher...">
<div class="top_bar">
<div class="search_container">
<img class="search_icon"src="{{ asset('img/search-icon.svg') }}">
<input type="text" class="search_input" placeholder="Rechercher...">
</div>

<button onclick="displayUserAddMenu()">+</button>
</div>
<hr>
<div id="user_table">
Expand All @@ -24,7 +28,7 @@

<tbody>
@foreach(\App\Models\User::all() as $user)
<tr onclick="displayUserDetails({{ $user }})">
<tr onclick="displayUserEditMenu({{ $user }})">
<td>{{ $user->id }}</td>
<td>{{ $user->name }}</td>
@if ($user->is_admin) <td>✅</td> @else <td>❌</td> @endif
Expand All @@ -36,15 +40,13 @@
</div>

<div id="user_details">
<div id="user_details_not_loaded">
<div id="user_details_empty">
<h2>Veuillez sélectionner un utilisateur</h2>
</div>
<div id="user_details_loaded" class="hidden">
<!-- img src="../img/user_image.jpg" /-->
<form action="/auth/update" method="post" autocomplete="off" >
@csrf

<input type="hidden" id="user_id" name="id"/>
<div id="user_details_add" class="hidden">
<form action="/admin/user/add" method="post" autocomplete="off" >
@csrf

<!-- Nom d'utilisateur -->
<div class="user_details_field">
Expand All @@ -58,59 +60,33 @@
<input type="text" id="email" name="email" required/>
</div>

<!-- First name -->
<div class="user_details_field">
<label for="first_name">Prénom :</label>
<input type="text" id="first_name" name="first_name" required/>
</div>

<!-- Last name -->
<div class="user_details_field">
<label for="last_name">Nom :</label>
<input type="text" id="last_name" name="last_name" required/>
</div>

<!-- Date de naissance -->
<div class="user_details_field">
<label for="birthday">Date de naissance :</label>
<input type="date" id="birthday" name="birth" required/>
</div>

<!-- Genre -->
<div class="user_details_field">
<label for="gender">Genre :</label>
<div id="gender">
<input type="radio" name="gender" value="male"/>
<label for="gender">Homme</label>
<input type="radio" name="gender" value="female"/>
<label for="gender">Femme</label>
<input type="radio" name="gender" value="null"/>
<label for="female">Autre</label>
</div>
</div>

<!-- Métier -->
<div class="user_details_field">
<label for="job">Métier: </label>
<select name="job" id="job">
<option value="null"></option>
@foreach(\App\Models\Job::all() as $job)
<option value="{{$job->id}}" @if(Auth::user()->job_id == $job->id) selected @endif>{{$job->name}} </option>
@endforeach
</select>
</div>

<!-- Mot de passe : Ne pas l'afficher, simplement en autoriser la modification -->
<!-- Mot de passe -->
<div class="user_details_field">
<label for="password">Mot de passe :</label>
<input type="password" name="password" id="password" autocomplete="new-password"/>
</div>

<!-- Submit -->
<!-- Admin -->
<div class="user_details_field">
<input type="submit" value="Enregistrer"/>
<label for="is_admin">Admin :</label>
<!-- Workaround for a route limitation -->
<input type="hidden" name="is_admin" value="0">
<input type="checkbox" id="checkbox" name="is_admin" value="1">
</div>

<input type="submit" value="Enregistrer"/>
</form>
</div>

<div id="user_details_edit" class="hidden">
<!-- Reset password button -->
<div class="user_details_field">
<form action="/admin/user/resetPassword" method="post">
@csrf
<input type="hidden" id="user_id_password_reset" name="id"/>
<input type="submit" value="Reinitialiser le mot de passe"/>
</form>
</div>

<!-- Delete button -->
<div class="user_details_field">
Expand Down

0 comments on commit 0c55b8e

Please sign in to comment.