2016-02-14 20:58:49 +00:00
|
|
|
// 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"]')
|
2016-02-15 21:08:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
remove: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="remove"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="remove"]')
|
|
|
|
},
|
|
|
|
|
|
|
|
edit: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="edit"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="edit"]')
|
2016-02-14 20:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-02-14 21:50:07 +00:00
|
|
|
/* GESTION DE L'AFFICHAGE DES MACHINES
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
if( section.view.element != null ){
|
|
|
|
|
|
|
|
// On recupere tous les liens
|
|
|
|
section.view.link = {
|
|
|
|
edit: document.querySelectorAll(section.view.text + '.link_edit[data-machine]'),
|
|
|
|
remove: document.querySelectorAll(section.view.text + '.link_remove[data-machine]')
|
|
|
|
};
|
|
|
|
|
|
|
|
// On gere la "redirection" vers la modification
|
|
|
|
for( var i = 0 ; i < section.view.link.edit.length ; i++ ){
|
|
|
|
|
|
|
|
section.view.link.edit[i].addEventListener('click', function(e){
|
|
|
|
pageManager.vars[1] = e.target.getData('machine');
|
2016-02-15 21:08:49 +00:00
|
|
|
autofill_edit();
|
2016-02-14 21:50:07 +00:00
|
|
|
navSubMenu('edit');
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// On gere la "redirection" vers la suppression
|
|
|
|
for( var i = 0 ; i < section.view.link.remove.length ; i++ ){
|
|
|
|
|
|
|
|
section.view.link.remove[i].addEventListener('click', function(e){
|
|
|
|
pageManager.vars[1] = e.target.getData('machine');
|
2016-02-15 21:08:49 +00:00
|
|
|
autofill_remove();
|
2016-02-14 21:50:07 +00:00
|
|
|
navSubMenu('remove');
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 20:58:49 +00:00
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2016-02-15 21:08:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] remove -> Suppression de machine
|
|
|
|
=========================================================*/
|
|
|
|
if( section.remove.element != null ){
|
|
|
|
|
|
|
|
// Definition des champs
|
|
|
|
section.remove.input = {
|
|
|
|
code: document.querySelector(section.remove.text + '#remove_code'),
|
|
|
|
name: document.querySelector(section.remove.text + '#remove_name'),
|
|
|
|
|
|
|
|
submit: document.querySelector(section.remove.text + '#remove_submit')
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Gestion de l'auto-remplissage par lien
|
|
|
|
function autofill_remove(){ if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ){
|
|
|
|
// On recupere le code + name de la machine selectionnee
|
|
|
|
var machine_data = null;
|
|
|
|
|
|
|
|
api.send({path:'machineDefault/getById', data: [pageManager.vars[1]]}, function(answer){
|
|
|
|
if( answer.ModuleError == 0 ){ // Aucune erreur
|
|
|
|
machine_data = answer.machine;
|
|
|
|
|
|
|
|
// Auto-remplissage du formulaire
|
|
|
|
section.remove.input.code.value = machine_data.code;
|
|
|
|
section.remove.input.name.value = machine_data.name;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}}autofill_remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [4] edit -> Modification de machine
|
|
|
|
=========================================================*/
|
|
|
|
if( section.edit.element != null ){
|
|
|
|
|
|
|
|
// Definition des champs
|
|
|
|
section.edit.input = {
|
|
|
|
code: document.querySelector(section.edit.text + '#edit_code'),
|
|
|
|
name: document.querySelector(section.edit.text + '#edit_name'),
|
|
|
|
|
|
|
|
submit: document.querySelector(section.edit.text + '#edit_submit')
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Gestion de l'auto-remplissage par lien
|
|
|
|
function autofill_edit(){ if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ){
|
|
|
|
// On recupere le code + name de la machine selectionnee
|
|
|
|
var machine_data = null;
|
|
|
|
|
|
|
|
api.send({path:'machineDefault/getById', data: [pageManager.vars[1]]}, function(answer){
|
|
|
|
if( answer.ModuleError == 0 ){ // Aucune erreur
|
|
|
|
machine_data = answer.machine;
|
|
|
|
|
|
|
|
// Auto-remplissage du formulaire
|
|
|
|
section.edit.input.code.placeholder = machine_data.code;
|
|
|
|
section.edit.input.name.placeholder = machine_data.name;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}}autofill_edit();
|
|
|
|
|
2016-02-14 20:58:49 +00:00
|
|
|
}
|