From 2b1fe615821ef4eb51aef6510962959ea46c24fc Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 16 Feb 2016 14:42:48 +0100 Subject: [PATCH] - [x] [view/js/machines] Modification de machine --- todo.md | 2 +- view/js/machines.js | 38 ++++++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/todo.md b/todo.md index 30a44c7..c0a4718 100755 --- a/todo.md +++ b/todo.md @@ -12,12 +12,12 @@ - [ ] [view/js/machines] Recherche instantanee - [ ] [view/js/users] Recherche instantanee -- [ ] [view/js/machines] Modification de machine ######## # FAIT # ######## +- [x] [view/js/machines] Modification de machine - [x] [machineDefault] Implementer la modification - [x] [userDefault] Implementer la modification - [x] [userRepo] Gestion des parametres optionnels diff --git a/view/js/machines.js b/view/js/machines.js index ed26921..67e6c7b 100644 --- a/view/js/machines.js +++ b/view/js/machines.js @@ -232,7 +232,7 @@ if( section.edit.element != null ){ 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'), name: document.querySelector(section.edit.text + '#edit_name'), @@ -248,17 +248,28 @@ if( section.edit.element != null ){ api.send({path:'machineDefault/getById', data: [id_machine]}, function(answer){ if( answer.ModuleError == 0 ){ // Aucune erreur machine_data = answer.machine; - - // Auto-remplissage du formulaire - section.edit.input.code.value = machine_data.code; - section.edit.input.name.value = machine_data.name; + + }else{ // Si erreuron utilise un jeu de donnees vides + machine_data = { + id_machine: '', + code: '', + name: '' + }; } + + + // On enregistre l'UID de la machine + section.edit.input.search.id.value = machine_data.id_machine; + + // Auto-remplissage du formulaire + section.edit.input.code.value = machine_data.code; + section.edit.input.name.value = machine_data.name; }); }if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ) autofill_edit(pageManager.vars[1]); - /* (2) Gestion de la recherche de l'utilisateur */ + /* (2) Gestion de la recherche de la machine */ var lastsearch = null; var searchindex = 0; section.edit.input.search.submit.addEventListener('click', function(e){ @@ -269,25 +280,24 @@ if( section.edit.element != null ){ if( section.edit.input.search.keyword.value != '' ){ // Redaction de la requete var getuid = { - path: 'userDefault/search', + path: 'machineDefault/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) + 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 == uidanswer.machines[searchindex].id_machine ) + searchindex = (searchindex+1) % uidanswer.machines.length; // on affiche le prochain (decalage cyclique) - lastsearch = uidanswer.users[searchindex].id_user; + lastsearch = uidanswer.machines[searchindex].id_machine; section.edit.input.search.id.value = lastsearch; // on auto-remplit le formulaire autofill_edit(lastsearch); - }else{ + }else autofill_edit(null); - } }); }