69 lines
1.7 KiB
JavaScript
69 lines
1.7 KiB
JavaScript
|
// On referencie toutes les sections
|
||
|
var section = {
|
||
|
view: {
|
||
|
text: '#CONTAINER > section[data-sublink="view"] ',
|
||
|
element: document.querySelector('#CONTAINER > section[data-sublink="view"]')
|
||
|
},
|
||
|
|
||
|
create: {
|
||
|
text: '#CONTAINER > section[data-sublink="create"] ',
|
||
|
element: document.querySelector('#CONTAINER > section[data-sublink="create"]')
|
||
|
}
|
||
|
|
||
|
};
|
||
|
|
||
|
|
||
|
|
||
|
/* GESTION DE LA CREATION D'UNE MACHINE
|
||
|
*
|
||
|
*/
|
||
|
if( section.create.element != null ){
|
||
|
|
||
|
// On recupere tous les champs
|
||
|
section.create.input = {
|
||
|
code: document.querySelector(section.create.text + '#create_code'),
|
||
|
name: document.querySelector(section.create.text + '#create_name'),
|
||
|
|
||
|
submit: document.querySelector(section.create.text + '#create_submit')
|
||
|
}
|
||
|
|
||
|
// On initialise le gestionnaire des saisies
|
||
|
var createChecker = new inputChecker();
|
||
|
|
||
|
|
||
|
/* (1) Gestion du code RFID */
|
||
|
createChecker.append( section.create.input.code, format_code, '01-AB-CD-23');
|
||
|
section.create.input.code.addEventListener('keyup', function(e){
|
||
|
e.target.value = e.target.value.toUpperCase();
|
||
|
if( !createChecker.check(e.target) )
|
||
|
createChecker.correct(e.target, false);
|
||
|
|
||
|
}, false);
|
||
|
|
||
|
|
||
|
/* (n) Gestion de l'envoi du formulaire */
|
||
|
section.create.input.submit.addEventListener('click', function(e){
|
||
|
// On annule l'envoi de base (PHP)
|
||
|
e.preventDefault();
|
||
|
|
||
|
var request = {
|
||
|
path: 'machineDefault/create', // On veut creer un utilisateur
|
||
|
data: [
|
||
|
section.create.input.code.value,
|
||
|
section.create.input.name.value
|
||
|
]
|
||
|
};
|
||
|
|
||
|
api.send(request, function(answer){
|
||
|
if( answer.ModuleError == 0 ) // Tout s'est bien deroule
|
||
|
console.log('Machine cree!');
|
||
|
else // Erreur
|
||
|
console.error('ModuleError::'+answer.ModuleError);
|
||
|
|
||
|
});
|
||
|
|
||
|
|
||
|
|
||
|
}, false);
|
||
|
|
||
|
}
|