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-16 13:36:23 +00:00
|
|
|
autofill_edit(pageManager.vars[1]);
|
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-16 13:36:23 +00:00
|
|
|
autofill_remove(pageManager.vars[1]);
|
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
|
2016-02-16 13:36:23 +00:00
|
|
|
function autofill_remove(id_machine){
|
2016-02-15 21:08:49 +00:00
|
|
|
// On recupere le code + name de la machine selectionnee
|
|
|
|
var machine_data = null;
|
|
|
|
|
2016-02-16 13:36:23 +00:00
|
|
|
api.send({path:'machineDefault/getById', data: [id_machine]}, function(answer){
|
2016-02-15 21:08:49 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
2016-02-16 13:36:23 +00:00
|
|
|
}if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ) autofill_remove(pageManager.vars[1]);
|
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 = {
|
2016-02-16 13:36:23 +00:00
|
|
|
search: {
|
|
|
|
keyword: document.querySelector(section.edit.text + '#edit_search_keyword'),
|
|
|
|
id: document.querySelector(section.edit.text + '#edit_search_id'),
|
|
|
|
submit: document.querySelector(section.edit.text + '#edit_search_submit')
|
|
|
|
},
|
2016-02-16 13:42:48 +00:00
|
|
|
|
2016-02-15 21:08:49 +00:00
|
|
|
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
|
2016-02-16 13:36:23 +00:00
|
|
|
function autofill_edit(id_machine){
|
2016-02-15 21:08:49 +00:00
|
|
|
// On recupere le code + name de la machine selectionnee
|
|
|
|
var machine_data = null;
|
|
|
|
|
2016-02-16 13:36:23 +00:00
|
|
|
api.send({path:'machineDefault/getById', data: [id_machine]}, function(answer){
|
2016-02-15 21:08:49 +00:00
|
|
|
if( answer.ModuleError == 0 ){ // Aucune erreur
|
|
|
|
machine_data = answer.machine;
|
2016-02-16 13:42:48 +00:00
|
|
|
|
|
|
|
}else{ // Si erreuron utilise un jeu de donnees vides
|
|
|
|
machine_data = {
|
|
|
|
id_machine: '',
|
|
|
|
code: '',
|
|
|
|
name: ''
|
|
|
|
};
|
2016-02-15 21:08:49 +00:00
|
|
|
}
|
2016-02-16 13:42:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
// 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;
|
2016-02-15 21:08:49 +00:00
|
|
|
});
|
2016-02-16 13:36:23 +00:00
|
|
|
}if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ) autofill_edit(pageManager.vars[1]);
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 14:04:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 13:42:48 +00:00
|
|
|
/* (2) Gestion de la recherche de la machine */
|
2016-02-16 13:36:23 +00:00
|
|
|
var lastsearch = null;
|
|
|
|
var searchindex = 0;
|
|
|
|
section.edit.input.search.submit.addEventListener('click', function(e){
|
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
// Si le champ n'est pas vide, on lance la recherche
|
|
|
|
if( section.edit.input.search.keyword.value != '' ){
|
|
|
|
// Redaction de la requete
|
|
|
|
var getuid = {
|
2016-02-16 13:42:48 +00:00
|
|
|
path: 'machineDefault/search',
|
2016-02-16 13:36:23 +00:00
|
|
|
data: [section.edit.input.search.keyword.value]
|
|
|
|
};
|
|
|
|
|
|
|
|
// On envoie la requete
|
|
|
|
api.send(getuid, function(uidanswer){
|
2016-02-16 13:42:48 +00:00
|
|
|
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)
|
2016-02-16 13:36:23 +00:00
|
|
|
|
2016-02-16 13:42:48 +00:00
|
|
|
lastsearch = uidanswer.machines[searchindex].id_machine;
|
2016-02-16 13:36:23 +00:00
|
|
|
section.edit.input.search.id.value = lastsearch;
|
|
|
|
// on auto-remplit le formulaire
|
|
|
|
autofill_edit(lastsearch);
|
|
|
|
|
2016-02-16 13:42:48 +00:00
|
|
|
}else
|
2016-02-16 13:36:23 +00:00
|
|
|
autofill_edit(null);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 14:04:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* (n) Gestion de l'envoi du formulaire */
|
|
|
|
section.edit.input.submit.addEventListener('click', function(e){
|
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
// Si l'id est defini
|
|
|
|
if( section.edit.input.search.id.value != '' ){
|
|
|
|
|
|
|
|
var request = {
|
|
|
|
path: 'machineDefault/edit', // On veut creer une machine
|
|
|
|
data: [
|
|
|
|
section.edit.input.search.id.value,
|
|
|
|
section.edit.input.code.value,
|
|
|
|
section.edit.input.name.value
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
api.send(request, function(answer){
|
|
|
|
if( answer.ModuleError == 0 && answer.status == true ) // Tout s'est bien deroule
|
|
|
|
console.log('Machine modifiee!');
|
|
|
|
else // Erreur
|
|
|
|
console.error('ModuleError::'+answer.ModuleError);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 13:36:23 +00:00
|
|
|
|
2016-02-15 21:08:49 +00:00
|
|
|
|
2016-02-14 20:58:49 +00:00
|
|
|
}
|