- [x] [view/js/users] Recherche instantanee

- [x] [userDefault] Implementation de la recherche
This commit is contained in:
xdrm-brackets 2016-02-16 14:25:06 +01:00
parent 1e650949ac
commit 5ceaf5c0ae
10 changed files with 179 additions and 17 deletions

View File

@ -5,6 +5,8 @@
"link", "link",
"unlink", "unlink",
"search",
"getAll", "getAll",
"getById", "getById",
"getByCode", "getByCode",

View File

@ -2,6 +2,8 @@
"user" :[ "user" :[
"create", "create",
"search",
"getAll", "getAll",
"getById", "getById",
"getByCode", "getByCode",

View File

@ -10,4 +10,5 @@ $error-color: #cc5857;
/* FORMULAIRES */ /* FORMULAIRES */
$form-valid-color: #27a560; $form-valid-color: #27a560;
$form-neutral-color: #2193e6; $form-neutral-color: #2193e6;
$form-search-color: #5630ed;
$form-invalid-color: darken($theme-color, 5); $form-invalid-color: darken($theme-color, 5);

File diff suppressed because one or more lines are too long

View File

@ -45,7 +45,7 @@
&:hover, &:hover,
&:focus{ &:focus{
border-color: #5630ed; border-color: $form-search-color;
} }
} }
@ -245,6 +245,10 @@
border-color: $form-neutral-color; border-color: $form-neutral-color;
} }
&.search{
border-color: $form-neutral-color;
}
/* (1) Champs de texte */ /* (1) Champs de texte */
input[type=text], input[type=text],
@ -299,6 +303,19 @@
} }
} }
// Champs neutres
&.search > input[type=text],
&.search > input[type=mail],
&.search > input[type=password],
input.search[type=text],
input.search[type=mail],
input.search[type=password]{
&:focus,
&:hover{
border-color: $form-search-color;
}
}
/* (2) Boutons */ /* (2) Boutons */
@ -358,6 +375,20 @@
} }
} }
// Boutons recherche
button.search,
&.search > button{
border-color: $form-search-color;
background-color: $form-search-color;
&:hover,
&:focus{
background-color: #fff;
color: $form-search-color;
}
}
// "OU" separant les boutons // "OU" separant les boutons
hr.OR{ hr.OR{
display: block; display: block;
@ -404,6 +435,16 @@
} }
} }
// "OU" recherche
.search > hr.OR,
hr.OR.search{
border-bottom: 1px dashed $form-search-color;
&:before{
color: $form-search-color;
}
}
} }
} }

View File

@ -153,6 +153,26 @@
/* RENVOIE UN UTILISATEUR EN FONCTION D'UN MOT CLE
*
* @keyword<String> Element de recherche
*
* @return user<Array> Retourne la liste des utilisateurs trouves
*
*/
public static function search($keyword){
// On recupere les donnees
$user = new Repo('user/search', array($keyword));
return array(
'users' => $user->answer()
);
}
/* RENVOIE LA LISTE EXHAUSTIVE DES UTILISATEURS /* RENVOIE LA LISTE EXHAUSTIVE DES UTILISATEURS
* *
* @return utilisateurs<Array> Liste des utilisateurs * @return utilisateurs<Array> Liste des utilisateurs

View File

@ -61,6 +61,30 @@
/* RENVOIE UN UTILISATEUR EN FONCTION D'UN MOT CLE
*
* @keyword<String> Element de recherche
*
* @return user<Array> Retourne l'utilisateur trouve ou FALSE si rien n'est trouve
*
*/
public static function search($keyword){
// On recupere les donnees
$searchusers = Database::getPDO()->query("SELECT * FROM user
WHERE code LIKE '%".$keyword."%'
OR username LIKE '%".$keyword."%'
OR firstname LIKE '%".$keyword."%'
OR lastname LIKE '%".$keyword."%'
OR mail LIKE '%".$keyword."%'
");
return Database::delNumeric( $searchusers->fetchAll() );
}
/* RENVOIE LA LISTE DE TOUS LES UTILISATEURS /* RENVOIE LA LISTE DE TOUS LES UTILISATEURS

View File

@ -7,12 +7,13 @@
############ ############
# EN COURS # # EN COURS #
############ ############
- [ ] [view/js/users] Recherche instantanee
- [ ] [view/js/machines] Recherche instantanee - [ ] [view/js/machines] Recherche instantanee
- [ ] [machineDefault] Implementation de la recherche
- [x] [userDefault] Implementer la modification - [x] [userDefault] Implementer la modification
- [ ] [userRepo] Gestion des parametres optionnels - [ ] [userRepo] Gestion des parametres optionnels
- [ ] [view/users] Gestion des parametres optionnels physiques -> separer la selection et modification
- [ ] [machineDefault] Implementer la modification - [ ] [machineDefault] Implementer la modification
- [ ] [view/js/machines] Modification de machine - [ ] [view/js/machines] Modification de machine
@ -21,6 +22,8 @@
######## ########
# FAIT # # FAIT #
######## ########
- [x] [view/js/users] Recherche instantanee
- [x] [userDefault] Implementation de la recherche
- [x] [view/js/users] Modification d'utilisateur - [x] [view/js/users] Modification d'utilisateur
- [x] [userDefault] Implementer la modification - [x] [userDefault] Implementer la modification
- [x] [view/js/users+machines] Modification @value plutot que @placeholder - [x] [view/js/users+machines] Modification @value plutot que @placeholder

View File

@ -43,7 +43,7 @@ if( section.view.element != null ){
section.view.link.edit[i].addEventListener('click', function(e){ section.view.link.edit[i].addEventListener('click', function(e){
pageManager.vars[1] = e.target.getData('user'); pageManager.vars[1] = e.target.getData('user');
autofill_edit(); autofill_edit(pageManager.vars[1]);
navSubMenu('edit'); navSubMenu('edit');
}, false); }, false);
@ -54,7 +54,7 @@ if( section.view.element != null ){
section.view.link.remove[i].addEventListener('click', function(e){ section.view.link.remove[i].addEventListener('click', function(e){
pageManager.vars[1] = e.target.getData('user'); pageManager.vars[1] = e.target.getData('user');
autofill_remove(); autofill_remove(pageManager.vars[1]);
navSubMenu('remove'); navSubMenu('remove');
}, false); }, false);
@ -158,11 +158,11 @@ if( section.remove.element != null ){
/* (1) Gestion de l'auto-remplissage par url */ /* (1) Gestion de l'auto-remplissage par url */
function autofill_remove(){ if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ){ function autofill_remove(id_user){
// On recupere le code + username de l'utilisateur selectionne // On recupere le code + username de l'utilisateur selectionne
var user_data = null; var user_data = null;
api.send({path:'userDefault/getById', data: [pageManager.vars[1]]}, function(answer){ api.send({path:'userDefault/getById', data: [id_user]}, function(answer){
if( answer.ModuleError == 0 ){ // Aucune erreur if( answer.ModuleError == 0 ){ // Aucune erreur
user_data = answer.user; user_data = answer.user;
@ -171,7 +171,7 @@ if( section.remove.element != null ){
section.remove.input.username.value = user_data.username; section.remove.input.username.value = user_data.username;
} }
}); });
}}autofill_remove(); }if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ) autofill_remove(pageManager.vars[1]);
@ -237,6 +237,12 @@ if( section.edit.element != null ){
// Definition des champs // Definition des champs
section.edit.input = { section.edit.input = {
search: {
keyword: document.querySelector(section.edit.text + '#edit_search_keyword'),
id: document.querySelector(section.edit.text + '#edit_search_id'),
submit: document.querySelector(section.edit.text + '#edit_search_submit')
},
code: document.querySelector(section.edit.text + '#edit_code'), code: document.querySelector(section.edit.text + '#edit_code'),
username: document.querySelector(section.edit.text + '#edit_username'), username: document.querySelector(section.edit.text + '#edit_username'),
firstname: document.querySelector(section.edit.text + '#edit_firstname'), firstname: document.querySelector(section.edit.text + '#edit_firstname'),
@ -250,14 +256,32 @@ if( section.edit.element != null ){
/* (1) Gestion de l'auto-remplissage par url */ /* (1) Gestion de l'auto-remplissage par url */
function autofill_edit(){ if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ){ function autofill_edit(id_user){
// On recupere le code + username de l'utilisateur selectionne // On recupere le code + username de l'utilisateur selectionne
var user_data = null; var user_data = null;
api.send({path:'userDefault/getById', data: [pageManager.vars[1]]}, function(answer){ // SI @id_user est un entier
if( answer.ModuleError == 0 ){ // Aucune erreur if( !isNaN(id_user) ){
user_data = answer.user; api.send({path:'userDefault/getById', data: [id_user]}, function(answer){
if( answer.ModuleError == 0 ){ // Si aucune erreur
user_data = answer.user;
}else{ // Si erreuron utilise un jeu de donnees vides
user_data = {
id_user: '',
code: '',
username: '',
firstname: '',
lastname: '',
mail: '',
status: ''
};
}
// On enregistre l'UID de l'utilisateur
section.edit.input.search.id.value = user_data.id_user;
// Auto-remplissage du formulaire // Auto-remplissage du formulaire
section.edit.input.code.value = user_data.code; section.edit.input.code.value = user_data.code;
section.edit.input.username.value = user_data.username; section.edit.input.username.value = user_data.username;
@ -266,9 +290,50 @@ if( section.edit.element != null ){
section.edit.input.mail.value = user_data.mail; section.edit.input.mail.value = user_data.mail;
section.edit.input.password.value = ''; section.edit.input.password.value = '';
section.edit.input.status.value = user_data.status; section.edit.input.status.value = user_data.status;
} });
}); // Si @id_user est incoherent
}}autofill_edit(); }
}if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ) autofill_edit(pageManager.vars[1]);
/* (2) Gestion de la recherche de l'utilisateur */
var lastsearch = null;
var searchindex = 0;
section.edit.input.search.submit.addEventListener('click', function(e){
// On annule l'envoi de base (PHP)
e.preventDefault();
// Si le champ n'est pas vide, on lance la recherche
if( section.edit.input.search.keyword.value != '' ){
// Redaction de la requete
var getuid = {
path: 'userDefault/search',
data: [section.edit.input.search.keyword.value]
};
// On envoie la requete
api.send(getuid, function(uidanswer){
if( uidanswer.ModuleError == 0 && uidanswer.users.length > 0 ){ // si on a trouve qqch
// Si on trouve le meme utilisateur que lors de la derniere recherche
if( lastsearch == uidanswer.users[searchindex].id_user )
searchindex = (searchindex+1) % uidanswer.users.length; // on affiche le prochain (decalage cyclique)
lastsearch = uidanswer.users[searchindex].id_user;
section.edit.input.search.id.value = lastsearch;
// on auto-remplit le formulaire
autofill_edit(lastsearch);
}else{
autofill_edit(null);
}
});
}
}, false);

View File

@ -202,6 +202,10 @@
echo "<section data-sublink='edit'>"; echo "<section data-sublink='edit'>";
echo "<form class='neutral'>"; echo "<form class='neutral'>";
echo "<input id='edit_search_keyword' type='text' class='search' placeholder='Recherche...'><br>";
echo "<input id='edit_search_id' type='hidden' value=''><br>";
echo "<button id='edit_search_submit' class='search'>Trouver</button><br><br><br>";
echo "<input id='edit_code' type='text' placeholder='CO-DE-RF-ID'><br>"; echo "<input id='edit_code' type='text' placeholder='CO-DE-RF-ID'><br>";
echo "<input id='edit_username' type='text' placeholder='Username'><br>"; echo "<input id='edit_username' type='text' placeholder='Username'><br>";
echo "<input id='edit_firstname' type='text' placeholder='Firstname'><br>"; echo "<input id='edit_firstname' type='text' placeholder='Firstname'><br>";