From 5368fe4edf41f1ea3d9835712f48b5a3d1d717f9 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 18 Sep 2017 18:32:39 +0200 Subject: [PATCH] Added error message under the missing/invalid field (user/machine/group::create/edit) --- public_html/view/groups.php | 9 +++-- public_html/view/js/groups.js | 60 ++++++++++++++++++++++++++------- public_html/view/js/machines.js | 40 ++++++++++++++++++++-- public_html/view/js/users.js | 40 +++++++++++++++++++--- public_html/view/machines.php | 6 ++-- public_html/view/users.php | 12 +++---- 6 files changed, 138 insertions(+), 29 deletions(-) diff --git a/public_html/view/groups.php b/public_html/view/groups.php index 1388051..998cb23 100755 --- a/public_html/view/groups.php +++ b/public_html/view/groups.php @@ -82,6 +82,7 @@ echo "
"; echo "
"; + echo "
"; echo ""; + echo "
"; + echo ""; echo "
"; @@ -115,7 +118,7 @@ echo ""; // Indice du resultat echo "groupe 0 sur 0

"; - echo "
"; + echo "
"; echo "




"; @@ -148,11 +151,13 @@ echo ""; // Indice du resultat echo "groupe 0 sur 0

"; - echo "
"; + echo "
"; echo "




"; echo "
"; + echo "
"; + echo "
"; echo ""; echo ""; diff --git a/public_html/view/js/groups.js b/public_html/view/js/groups.js index 213f452..7110de0 100755 --- a/public_html/view/js/groups.js +++ b/public_html/view/js/groups.js @@ -199,7 +199,7 @@ if( section.view.element != null ){ console.warn('error loading list of members'); return; } - + // remove already members var members = (path == 'userDefault/getAll') ? response.users : response.machines; @@ -249,11 +249,11 @@ if( section.view.element != null ){ request.path = 'machineDefault/link'; request.id_machine = memberid; } - + // {3} Call link // api.send(request, function(response2){ - + // manage error if( response2.error != 0 ){ console.warn('cannot link user to group'); @@ -268,7 +268,7 @@ if( section.view.element != null ){ newMemberRemoveIcon.setAttribute('class', 'rem-member'); newMemberRemoveIcon.setAttribute('data-member', memberid); newMemberRemoveIcon.setAttribute('data-cluster', e.target.getData('cluster')); - + newMemberRemoveIcon.addEventListener('click', section.view.group.remfunc, false); var newMember = document.createElement('span'); @@ -289,9 +289,9 @@ if( section.view.element != null ){ }, false); } - - + + } @@ -319,7 +319,13 @@ if( section.create.element != null ){ name: document.querySelector(section.create.text + '#create_name'), class: document.querySelector(section.create.text + '#create_class'), submit: document.querySelector(section.create.text + '#create_submit') - } + }; + + // On recupere tous les messages d'erreur + section.create.errmsg = { + name: document.querySelector(section.create.text + '.error-msg.create_name'), + class: document.querySelector(section.create.text + '.error-msg.create_class') + }; /* (n) Gestion de l'envoi du formulaire */ @@ -327,6 +333,10 @@ if( section.create.element != null ){ // On annule l'envoi de base (PHP) e.preventDefault(); + // On vide les messages erreurs + section.create.errmsg.name.innerHTML = + section.create.errmsg.class.innerHTML = ''; + var request = { path: 'clusterDefault/create', // On veut creer un utilisateur name: section.create.input.name.value, @@ -334,6 +344,7 @@ if( section.create.element != null ){ }; api.send(request, function(answer){ + if( answer.error == 0 ){ // Tout s'est bien deroule console.log('Groupe cree!'); @@ -342,6 +353,15 @@ if( section.create.element != null ){ // On vide les champs section.create.input.name.value = ''; section.create.input.class.children[0].selected = 'selected'; + + }else{ // Erreur + console.error('ModuleError::'+answer.error); + + // if missing or incorrect param + if( answer.error == 16 || answer.error == 17 ){ + if( section.create.errmsg[answer.ErrorArguments[0]] != null ) + section.create.errmsg[answer.ErrorArguments[0]].innerHTML = 'Le champ est manquant ou incorrect !'; + } } }); @@ -603,6 +623,11 @@ if( section.edit.element != null ){ submit: document.querySelector(section.edit.text + '#edit_submit') }; + // On recupere tous les messages d'erreur + section.edit.errmsg = { + name: document.querySelector(section.edit.text + '.error-msg.edit_name') + }; + var lastkeywords_edit = ''; var found_edit = []; var searchindex_edit = 0; @@ -742,6 +767,9 @@ if( section.edit.element != null ){ // On annule l'envoi de base (PHP) e.preventDefault(); + // On vide les messages erreurs + section.edit.errmsg.name.innerHTML = ''; + // Si l'id est defini if( section.edit.input.search.id.value != '' ){ @@ -779,8 +807,16 @@ if( section.edit.element != null ){ }); - }else // Erreur + }else{ // Erreur console.error('ModuleError::'+answer.error); + + // if missing or incorrect param + if( answer.error == 16 || answer.error == 17 ){ + if( section.edit.errmsg[answer.ErrorArguments[0]] != null ) + section.edit.errmsg[answer.ErrorArguments[0]].innerHTML = 'Le champ est manquant ou incorrect !'; + } + + } }); } @@ -1128,7 +1164,7 @@ if( section.permissions.element != null && !section.permissions.member_view ){ console.warn('error loading list of members'); return; } - + // remove already authed var members = response.clusters; @@ -1171,11 +1207,11 @@ if( section.permissions.element != null && !section.permissions.member_view ){ id_source: memberid, id_action: permission_id }; - + // {3} Call link // api.send(request, function(response2){ - + // manage error if( response2.error != 0 ){ console.warn('cannot add permission to group'); @@ -1191,7 +1227,7 @@ if( section.permissions.element != null && !section.permissions.member_view ){ newMemberRemoveIcon.setAttribute('data-source', memberid); newMemberRemoveIcon.setAttribute('data-target', e.target.getData('target')); newMemberRemoveIcon.setAttribute('data-permission', e.target.getData('permission')); - + newMemberRemoveIcon.addEventListener('click', section.permissions.group.remfunc, false); var newMember = document.createElement('span'); diff --git a/public_html/view/js/machines.js b/public_html/view/js/machines.js index 25cf7bc..65810c7 100755 --- a/public_html/view/js/machines.js +++ b/public_html/view/js/machines.js @@ -302,7 +302,12 @@ if( section.create.element != null ){ section.create.input = { name: document.querySelector(section.create.text + '#create_name'), submit: document.querySelector(section.create.text + '#create_submit') - } + }; + + // On recupere tous les messages d'erreur + section.create.errmsg = { + name: document.querySelector(section.create.text + '.error-msg.create_name') + }; /* (2) Gestion de l'envoi du formulaire */ @@ -310,6 +315,9 @@ if( section.create.element != null ){ // On annule l'envoi de base (PHP) e.preventDefault(); + // On vide les messages erreurs + section.create.errmsg.name.innerHTML = ''; + /* (3) On rédige la requête */ var request = { path: 'machineDefault/create', // On veut creer un utilisateur @@ -326,6 +334,17 @@ if( section.create.element != null ){ section.create.input.submit.anim('active', 1500); + + }else{ // Erreur + + console.error('ModuleError::'+answer.error); + + // if missing or incorrect param + if( answer.error == 16 || answer.error == 17 ){ + if( section.create.errmsg[answer.ErrorArguments[0]] != null ) + section.create.errmsg[answer.ErrorArguments[0]].innerHTML = 'Le champ est manquant ou incorrect !'; + } + } }); @@ -567,6 +586,11 @@ if( section.edit.element != null ){ submit: document.querySelector(section.edit.text + '#edit_submit') }; + // On recupere tous les messages d'erreur + section.edit.errmsg = { + name: document.querySelector(section.edit.text + '.error-msg.edit_name') + }; + var lastkeywords_edit = ''; var found_edit = []; var searchindex_edit = 0; @@ -629,7 +653,6 @@ if( section.edit.element != null ){ // On annule l'envoi de base (PHP) e.preventDefault(); - /* (1) Si le champ n'est pas vide */ if( section.edit.input.search.keyword.value != '' ){ @@ -687,6 +710,9 @@ if( section.edit.element != null ){ // On annule l'envoi de base (PHP) e.preventDefault(); + // On vide les messages erreurs + section.edit.errmsg.name.innerHTML = ''; + // Si l'id est defini if( section.edit.input.search.id.value != '' ){ @@ -714,8 +740,16 @@ if( section.edit.element != null ){ } }); - }else // Erreur + }else{ // Erreur console.error('ModuleError::'+answer.error); + + // if missing or incorrect param + if( answer.error == 16 || answer.error == 17 ){ + if( section.edit.errmsg[answer.ErrorArguments[0]] != null ) + section.edit.errmsg[answer.ErrorArguments[0]].innerHTML = 'Le champ est manquant ou incorrect !'; + } + + } }); } diff --git a/public_html/view/js/users.js b/public_html/view/js/users.js index bd2729f..972b138 100755 --- a/public_html/view/js/users.js +++ b/public_html/view/js/users.js @@ -340,6 +340,7 @@ if( section.create.element != null ){ // On annule l'envoi de base (PHP) e.preventDefault(); + // On vide les messages erreurs section.create.errmsg.code.innerHTML = section.create.errmsg.username.innerHTML = section.create.errmsg.firstname.innerHTML = @@ -370,8 +371,12 @@ if( section.create.element != null ){ }else{ // Erreur console.error('ModuleError::'+answer.error); - if( /^[^']*'(\w+)'/i.test(answer.ErrorDescription) ) - section.create.errmsg[RegExp.$1].innerHTML = 'Champ manquant ou erronné.'; + + // if missing or incorrect param + if( answer.error == 16 || answer.error == 17 ){ + if( section.create.errmsg[answer.ErrorArguments[0]] != null ) + section.create.errmsg[answer.ErrorArguments[0]].innerHTML = 'Le champ est manquant ou incorrect !'; + } } }); @@ -516,6 +521,7 @@ if( section.remove.element != null ){ autofill_remove(); } + // On met à jour la dernière recherche lastkeywords_remove = getUsers.keywords; }); @@ -577,8 +583,10 @@ if( section.remove.element != null ){ autofill_remove(); - }else // Erreur + }else // Erreur console.error('ModuleError::'+answer.error); + + }); } @@ -625,6 +633,15 @@ if( section.edit.element != null ){ submit: document.querySelector(section.edit.text + '#edit_submit') }; + // On recupere tous les messages d'erreur + section.edit.errmsg = { + code: document.querySelector(section.edit.text + '.error-msg.edit_code'), + username: document.querySelector(section.edit.text + '.error-msg.edit_username'), + firstname: document.querySelector(section.edit.text + '.error-msg.edit_firstname'), + lastname: document.querySelector(section.edit.text + '.error-msg.edit_lastname'), + mail: document.querySelector(section.edit.text + '.error-msg.edit_mail') + }; + /* (1) Gestion du code RFID */ createChecker.append( section.edit.input.code, format_code, '01-AB-CD-23'); section.edit.input.code.addEventListener('keyup', function(e){ @@ -761,6 +778,13 @@ if( section.edit.element != null ){ // On annule l'envoi de base (PHP) e.preventDefault(); + // On vide les messages erreurs + section.edit.errmsg.code.innerHTML = + section.edit.errmsg.username.innerHTML = + section.edit.errmsg.firstname.innerHTML = + section.edit.errmsg.lastname.innerHTML = + section.edit.errmsg.mail.innerHTML = ''; + // Si l'id est defini if( section.edit.input.search.id.value != '' ){ @@ -793,8 +817,16 @@ if( section.edit.element != null ){ }); - }else // Erreur + }else{ // Erreur console.error('ModuleError::'+answer.error); + + // if missing or incorrect param + if( answer.error == 16 || answer.error == 17 ){ + if( section.edit.errmsg[answer.ErrorArguments[0]] != null ) + section.edit.errmsg[answer.ErrorArguments[0]].innerHTML = 'Le champ est manquant ou incorrect !'; + } + + } }); } diff --git a/public_html/view/machines.php b/public_html/view/machines.php index eb1d607..2ca2baa 100755 --- a/public_html/view/machines.php +++ b/public_html/view/machines.php @@ -71,6 +71,7 @@ echo "
"; echo "
"; + echo "
"; echo ""; echo "
"; @@ -96,7 +97,7 @@ echo ""; // Indice du resultat echo "machine 0 sur 0

"; - echo "
"; + echo "
"; echo "




"; @@ -126,11 +127,12 @@ echo ""; // Indice du resultat echo "machine 0 sur 0

"; - echo "
"; + echo "
"; echo "




"; echo "
"; + echo "
"; echo ""; echo ""; diff --git a/public_html/view/users.php b/public_html/view/users.php index e2d0d1d..e34d34c 100755 --- a/public_html/view/users.php +++ b/public_html/view/users.php @@ -108,7 +108,7 @@ echo ""; // Indice du resultat echo "utilisateur 0 sur 0

"; - echo "
"; + echo "
"; echo "




"; @@ -143,20 +143,20 @@ echo ""; // Indice du resultat echo "utilisateur 0 sur 0

"; - echo "
"; + echo "
"; echo "




"; echo "
"; echo "
"; echo "
"; - echo "
"; + echo "
"; echo "
"; - echo "
"; + echo "
"; echo "
"; - echo "
"; + echo "
"; echo "
"; - echo "
"; + echo "
"; echo ""; echo "";