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();
|
2016-02-15 22:07:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (n) Gestion de l'envoi du formulaire */
|
|
|
|
section.remove.input.submit.addEventListener('click', function(e){
|
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (1) On recupere l'UID de la machine */
|
|
|
|
var getuid = {};
|
|
|
|
|
|
|
|
|
|
|
|
// recuperation par CODE
|
|
|
|
if( section.remove.input.code.value != '' ){
|
|
|
|
getuid.path = 'machineDefault/getByCode';
|
|
|
|
getuid.data = [section.remove.input.code.value];
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2016-02-15 21:08:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [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
|
2016-02-16 08:03:12 +00:00
|
|
|
section.edit.input.code.value = machine_data.code;
|
|
|
|
section.edit.input.name.value = machine_data.name;
|
2016-02-15 21:08:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}}autofill_edit();
|
|
|
|
|
2016-02-14 20:58:49 +00:00
|
|
|
}
|