- [x] [view/js/machines] Implementer la recherche pour la suppression

This commit is contained in:
xdrm-brackets 2016-02-17 11:24:26 +01:00
parent fb3023e75f
commit 30ae797c32
6 changed files with 106 additions and 57 deletions

File diff suppressed because one or more lines are too long

View File

@ -406,7 +406,7 @@
} }
// "OU" separant les boutons // "OU" separant les boutons
hr.OR{ hr.OR[data-label]{
display: block; display: block;
position: relative; position: relative;
width: 100%; width: 100%;
@ -416,7 +416,7 @@
border-bottom: 1px dashed $form-invalid-color; border-bottom: 1px dashed $form-invalid-color;
&:before{ &:before{
content: 'OU'; content: attr(data-label);
display: inline-block; display: inline-block;
position: relative; position: relative;
top: 50%; top: 50%;

View File

@ -7,7 +7,8 @@
############ ############
# EN COURS # # EN COURS #
############ ############
- [ ] [container.scss] Icone dans bouton quand succes sur l'operation - [ ] [view/js/users] Implementer la recherche pour la suppression
- [ ] [container.scss] Icone dans bouton quand succes sur l'operation
- [ ] [view/users][view/js/users.js] Suppression avec recherche comme pour la modification - [ ] [view/users][view/js/users.js] Suppression avec recherche comme pour la modification
- [ ] [view/machines][view/js/machines.js] Suppression avec recherche comme pour la modification - [ ] [view/machines][view/js/machines.js] Suppression avec recherche comme pour la modification
@ -16,6 +17,7 @@
######## ########
# FAIT # # FAIT #
######## ########
- [x] [view/js/machines] Implementer la recherche pour la suppression
- [x] Nettoyage git - [x] Nettoyage git
- [x] [ResourceDispatcher] Gestion de la coloration de svg - [x] [ResourceDispatcher] Gestion de la coloration de svg
- [x] [src/*.svg] Modification des svg (attribution des ID) - [x] [src/*.svg] Modification des svg (attribution des ID)

View File

@ -174,8 +174,14 @@ if( section.create.element != null ){
=========================================================*/ =========================================================*/
if( section.remove.element != null ){ if( section.remove.element != null ){
// Definition des champs /* (1) Definition des champs */
section.remove.input = { section.remove.input = {
search: {
keyword: document.querySelector(section.remove.text + '#remove_search_keyword'),
id: document.querySelector(section.remove.text + '#remove_search_id'),
submit: document.querySelector(section.remove.text + '#remove_search_submit')
},
code: document.querySelector(section.remove.text + '#remove_code'), code: document.querySelector(section.remove.text + '#remove_code'),
name: document.querySelector(section.remove.text + '#remove_name'), name: document.querySelector(section.remove.text + '#remove_name'),
@ -183,68 +189,98 @@ if( section.remove.element != null ){
}; };
// Gestion de l'auto-remplissage par lien /* (2) Gestion de l'auto-remplissage par lien */
function autofill_remove(id_machine){ function autofill_remove(id_machine){
// On recupere le code + name de la machine selectionnee // On recupere le code + name de la machine selectionnee
var machine_data = null; var machine_data = machine_data = {
id_machine: '',
code: '',
name: '',
disable_input: true
};
api.send({path:'machineDefault/getById', data: [id_machine]}, function(answer){ api.send({path:'machineDefault/getById', data: [id_machine]}, function(answer){
if( answer.ModuleError == 0 ){ // Aucune erreur if( answer.ModuleError == 0 ){ // Aucune erreur
machine_data = answer.machine; machine_data = answer.machine;
machine_data.diable_input = false;
// Auto-remplissage du formulaire
section.remove.input.code.value = machine_data.code;
section.remove.input.name.value = machine_data.name;
} }
// Auto-remplissage du formulaire
section.remove.input.code.value = machine_data.code;
section.remove.input.name.value = machine_data.name;
// On gere le caractere "inactif" du submit
section.remove.input.submit.disabled = machine_data.disable_input;
}); });
}if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ) autofill_remove(pageManager.vars[1]); }if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ) autofill_remove(pageManager.vars[1]);
/* (3) Gestion de la recherche */
var lastsearch_remove = null;
var searchindex_remove = 0;
section.remove.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.remove.input.search.keyword.value != '' ){
// Redaction de la requete
var getuid = {
path: 'machineDefault/search',
data: [section.remove.input.search.keyword.value]
};
// On envoie la requete
api.send(getuid, function(uidanswer){
if( uidanswer.ModuleError == 0 && uidanswer.machines.length > 0){ // si on a trouve qqch
// Si on trouve la meme machine que lors de la derniere recherche
if( lastsearch_remove == uidanswer.machines[searchindex_remove].id_machine )
searchindex_remove = (searchindex_remove+1) % uidanswer.machines.length; // on affiche le prochain (decalage cyclique)
lastsearch_remove = uidanswer.machines[searchindex_remove].id_machine;
section.remove.input.search.id.value = lastsearch_remove;
// on auto-remplit le formulaire
autofill_remove(lastsearch_remove);
}else
autofill_remove(null);
});
}
}, false);
/* (n) Gestion de l'envoi du formulaire */ /* (n) Gestion de l'envoi du formulaire */
section.remove.input.submit.addEventListener('click', function(e){ section.remove.input.submit.addEventListener('click', function(e){
// On annule l'envoi de base (PHP) // On annule l'envoi de base (PHP)
e.preventDefault(); e.preventDefault();
/* (1) On recupere l'UID de la machine */ /* (1) On recupere l'UID de la machine */
var getuid = {}; var getuid = {};
// Si l'id est defini
if( section.remove.input.search.id.value != '' ){
// recuperation par CODE /* (2) On supprime la machine */
if( section.remove.input.code.value != '' ){ var request = {
getuid.path = 'machineDefault/getByCode'; path: 'machineDefault/delete', // On veut supprimer cet utilisateur
getuid.data = [section.remove.input.code.value]; data: [section.remove.input.search.id.value]
};
api.send(request, function(answer){
if( answer.ModuleError == 0 && answer.status == true ){ // Tout s'est bien deroule
console.log('Machine supprimee!');
// On vide le formulaire
autofill_remove(null);
}else // Erreur
console.error('ModuleError::'+answer.ModuleError);
});
// recuperation par NAME
}else if( section.remove.input.name.value != '' ){
getuid.path = 'machineDefault/getByName';
getuid.data = [section.remove.input.name.value];
} }
// On envoie la requete de demande d'uid
api.send(getuid, function(uid_answer){
if( uid_answer.ModuleError == 0 ){ // Si aucune erreur
/* (2) On supprime la machine */
var request = {
path: 'machineDefault/delete', // On veut supprimer cet utilisateur
data: [uid_answer.machine.id_machine]
};
api.send(request, function(answer){
if( answer.ModuleError == 0 && answer.status == true ) // Tout s'est bien deroule
console.log('Machine supprimee!');
else // Erreur
console.error('ModuleError::'+answer.ModuleError);
});
}
});
}, false); }, false);
} }
@ -313,8 +349,8 @@ if( section.edit.element != null ){
/* (2) Gestion de la recherche de la machine */ /* (2) Gestion de la recherche de la machine */
var lastsearch = null; var lastsearch_edit = null;
var searchindex = 0; var searchindex_edit = 0;
section.edit.input.search.submit.addEventListener('click', function(e){ section.edit.input.search.submit.addEventListener('click', function(e){
// On annule l'envoi de base (PHP) // On annule l'envoi de base (PHP)
e.preventDefault(); e.preventDefault();
@ -331,13 +367,13 @@ if( section.edit.element != null ){
api.send(getuid, function(uidanswer){ api.send(getuid, function(uidanswer){
if( uidanswer.ModuleError == 0 && uidanswer.machines.length > 0 ){ // si on a trouve qqch if( uidanswer.ModuleError == 0 && uidanswer.machines.length > 0 ){ // si on a trouve qqch
// Si on trouve la meme machine que lors de la derniere recherche // Si on trouve la meme machine que lors de la derniere recherche
if( lastsearch == uidanswer.machines[searchindex].id_machine ) if( lastsearch_edit == uidanswer.machines[searchindex_edit].id_machine )
searchindex = (searchindex+1) % uidanswer.machines.length; // on affiche le prochain (decalage cyclique) searchindex_edit = (searchindex_edit+1) % uidanswer.machines.length; // on affiche le prochain (decalage cyclique)
lastsearch = uidanswer.machines[searchindex].id_machine; lastsearch_edit = uidanswer.machines[searchindex_edit].id_machine;
section.edit.input.search.id.value = lastsearch; section.edit.input.search.id.value = lastsearch_edit;
// on auto-remplit le formulaire // on auto-remplit le formulaire
autofill_edit(lastsearch); autofill_edit(lastsearch_edit);
}else }else
autofill_edit(null); autofill_edit(null);

View File

@ -158,8 +158,13 @@
echo "<section data-sublink='remove'>"; echo "<section data-sublink='remove'>";
echo "<form class='invalid'>"; echo "<form class='invalid'>";
echo "<input id='remove_code' type='text' placeholder='Code'><br>"; echo "<input id='remove_search_keyword' type='text' class='search' placeholder='Recherche...'><br>";
echo "<hr class='OR' />"; echo "<input id='remove_search_id' type='hidden' value=''><br>";
echo "<button id='remove_search_submit' class='search'>Trouver</button><br>";
echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>";
echo "<input id='remove_code' type='text' placeholder='CO-DE-RF-ID'><br>";
echo "<input id='remove_name' type='text' placeholder='Name'><br>"; echo "<input id='remove_name' type='text' placeholder='Name'><br>";
echo "<button id='remove_submit'>Supprimer</button>"; echo "<button id='remove_submit'>Supprimer</button>";
echo "</form>"; echo "</form>";
@ -184,7 +189,9 @@
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_keyword' type='text' class='search' placeholder='Recherche...'><br>";
echo "<input id='edit_search_id' type='hidden' value=''><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 "<button id='edit_search_submit' class='search'>Trouver</button><br>";
echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>";
echo "<input id='edit_code' type='text' placeholder='Code'><br>"; echo "<input id='edit_code' type='text' placeholder='Code'><br>";
echo "<input id='edit_name' type='text' placeholder='Name'><br>"; echo "<input id='edit_name' type='text' placeholder='Name'><br>";

View File

@ -173,12 +173,14 @@
echo "<section data-sublink='remove'>"; echo "<section data-sublink='remove'>";
echo "<form class='invalid'>"; echo "<form class='invalid'>";
echo "<input id='remove_id' type='hidden' value=''><br>"; echo "<input id='remove_search_keyword' type='text' class='search' placeholder='Recherche...'><br>";
echo "<input id='remove_search_id' type='hidden' value=''><br>";
echo "<button id='remove_search_submit' class='search'>Trouver</button><br>";
echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>";
echo "<input id='remove_code' type='text' placeholder='Code'><br>"; echo "<input id='remove_code' type='text' placeholder='Code'><br>";
echo "<hr class='OR' />";
echo "<input id='remove_username' type='text' placeholder='Username'><br>"; echo "<input id='remove_username' type='text' placeholder='Username'><br>";
echo "<button id='remove_search' class='search'>Rechercher</button><br><br>";
echo "<button id='remove_submit' disabled>Supprimer</button>"; echo "<button id='remove_submit' disabled>Supprimer</button>";
echo "</form>"; echo "</form>";
@ -202,7 +204,9 @@
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_keyword' type='text' class='search' placeholder='Recherche...'><br>";
echo "<input id='edit_search_id' type='hidden' value=''><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 "<button id='edit_search_submit' class='search'>Trouver</button><br>";
echo "<br><br><hr class='OR' data-label='PUIS' /><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>";