2016-02-14 20:58:49 +00:00
|
|
|
// On referencie toutes les sections
|
|
|
|
var section = {
|
|
|
|
view: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="view"] ',
|
2016-02-16 21:10:36 +00:00
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="view"]'),
|
|
|
|
searchbar: document.querySelector('#CONTAINER > section[data-sublink="view"] > .searchbar')
|
2016-02-14 20:58:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
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-07-20 23:19:19 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
groups: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="groups"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="groups"]'),
|
|
|
|
searchbar: document.querySelector('#CONTAINER > section[data-sublink="groups"] > .searchbar')
|
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 ){
|
|
|
|
|
2016-07-12 13:16:07 +00:00
|
|
|
/* (0) On gère le zoom sur un utilisateur via URL */
|
|
|
|
if( pageManager.vars.length > 1 && !isNaN(pageManager.vars[1]) ){
|
|
|
|
document.location = '#'+pageManager.vars[1];
|
|
|
|
document.getElementById(pageManager.vars[1]).addClass('selected');
|
|
|
|
}
|
|
|
|
|
2016-02-16 21:10:36 +00:00
|
|
|
/* (1) On recupere tous les liens */
|
2016-02-14 21:50:07 +00:00
|
|
|
section.view.link = {
|
|
|
|
edit: document.querySelectorAll(section.view.text + '.link_edit[data-machine]'),
|
|
|
|
remove: document.querySelectorAll(section.view.text + '.link_remove[data-machine]')
|
|
|
|
};
|
|
|
|
|
2016-07-08 17:33:58 +00:00
|
|
|
/* (2) On récupère toutes les actions de groupes */
|
|
|
|
section.view.group = {
|
|
|
|
rem: document.querySelectorAll(section.view.text + '.rem-group[data-machine][data-group]'),
|
|
|
|
add: document.querySelectorAll(section.view.text + '.add-group[data-machine]')
|
|
|
|
};
|
|
|
|
|
2016-02-16 21:10:36 +00:00
|
|
|
|
2016-07-08 17:33:58 +00:00
|
|
|
/* (3) Gestion de la recherche instantannee */
|
2016-02-16 21:10:36 +00:00
|
|
|
section.view.searchbar.addEventListener('keyup', function(e){
|
|
|
|
|
|
|
|
var search = {
|
|
|
|
path: 'machineDefault/search',
|
2016-07-03 12:57:25 +00:00
|
|
|
keywords: section.view.searchbar.value
|
2016-02-16 21:10:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// On envoie la requete
|
|
|
|
api.send(search, function(result){
|
|
|
|
if( result.ModuleError == 0 ){ // si aucune erreur
|
2016-07-03 12:57:25 +00:00
|
|
|
|
2016-02-16 21:10:36 +00:00
|
|
|
// On enregistre tous les UID dans un tableau
|
|
|
|
var uid_list = [];
|
|
|
|
for( var i = 0 ; i < result.machines.length ; i++ )
|
|
|
|
uid_list.push( result.machines[i].id_machine);
|
|
|
|
|
|
|
|
// On recupere la liste des elements correspondants aux utilisateurs
|
|
|
|
var machine_list = document.querySelectorAll(section.view.text + '> article.inline-box[id]');
|
|
|
|
|
|
|
|
// Pour chaque machine
|
|
|
|
for( var i = 0 ; i < machine_list.length ; i++ ){
|
|
|
|
// Si doit etre visible
|
|
|
|
if( uid_list.indexOf(machine_list[i].id) > -1 )
|
|
|
|
machine_list[i].remClass('hidden');
|
|
|
|
// Si ne doit pas etre visible
|
|
|
|
else
|
|
|
|
machine_list[i].addClass('hidden');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
2016-07-08 17:33:58 +00:00
|
|
|
/* (4) On gere la "redirection" vers la modification */
|
2016-02-14 21:50:07 +00:00
|
|
|
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');
|
|
|
|
navSubMenu('edit');
|
2016-07-20 17:57:05 +00:00
|
|
|
document.location = '';
|
2016-02-14 21:50:07 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-08 17:33:58 +00:00
|
|
|
/* (5) On gere la "redirection" vers la suppression */
|
2016-02-14 21:50:07 +00:00
|
|
|
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');
|
|
|
|
navSubMenu('remove');
|
2016-07-20 17:57:05 +00:00
|
|
|
document.location = '';
|
2016-02-14 21:50:07 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-08 17:33:58 +00:00
|
|
|
/* (6) On gere la "suppression" d'un groupe */
|
|
|
|
for( var i = 0 ; i < section.view.group.rem.length ; i++ ){
|
|
|
|
|
|
|
|
section.view.group.rem[i].addEventListener('click', function(e){
|
|
|
|
// {1} On rédige la requête //
|
|
|
|
var request = {
|
|
|
|
path: 'machineDefault/unlink',
|
|
|
|
id_machine: e.target.getData('machine'),
|
|
|
|
id_cluster: e.target.getData('group')
|
|
|
|
};
|
|
|
|
|
|
|
|
// {2} On envoie la requête //
|
|
|
|
api.send(request, function(response){
|
|
|
|
|
|
|
|
// {3} Si erreur, on ne fait rien //
|
|
|
|
if( response.ModuleError != 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// {4} Si tout s'est bien passé //
|
|
|
|
e.target.parentNode.parentNode.removeChild( e.target.parentNode );
|
|
|
|
});
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-14 21:50:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 20:58:49 +00:00
|
|
|
|
|
|
|
/* GESTION DE LA CREATION D'UNE MACHINE
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
if( section.create.element != null ){
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (1) On recupere tous les champs */
|
2016-02-14 20:58:49 +00:00
|
|
|
section.create.input = {
|
2016-07-12 13:16:07 +00:00
|
|
|
name: document.querySelector(section.create.text + '#create_name'),
|
|
|
|
submit: document.querySelector(section.create.text + '#create_submit')
|
2016-02-14 20:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (2) Gestion de l'envoi du formulaire */
|
2016-02-14 20:58:49 +00:00
|
|
|
section.create.input.submit.addEventListener('click', function(e){
|
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (3) On rédige la requête */
|
2016-02-14 20:58:49 +00:00
|
|
|
var request = {
|
|
|
|
path: 'machineDefault/create', // On veut creer un utilisateur
|
2016-07-03 13:03:31 +00:00
|
|
|
name: section.create.input.name.value
|
2016-02-14 20:58:49 +00:00
|
|
|
};
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (4) On lance la requête */
|
2016-02-14 20:58:49 +00:00
|
|
|
api.send(request, function(answer){
|
2016-02-18 09:57:53 +00:00
|
|
|
if( answer.ModuleError == 0 ){ // Tout s'est bien deroule
|
2016-02-14 20:58:49 +00:00
|
|
|
console.log('Machine cree!');
|
2016-02-18 09:57:53 +00:00
|
|
|
|
2016-07-12 13:16:07 +00:00
|
|
|
// On redirige sur la machine
|
|
|
|
pageManager.vars = ['view', answer.id_machine];
|
|
|
|
pageManager.refresh();
|
|
|
|
document.location = '';
|
|
|
|
|
2016-02-18 09:57:53 +00:00
|
|
|
section.create.input.submit.anim('active', 1500);
|
2016-07-12 13:16:07 +00:00
|
|
|
}
|
2016-02-14 20:58:49 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
2016-02-15 21:08:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] remove -> Suppression de machine
|
|
|
|
=========================================================*/
|
|
|
|
if( section.remove.element != null ){
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
/* (1) Definition des champs et variables
|
|
|
|
---------------------------------------------------------*/
|
2016-02-15 21:08:49 +00:00
|
|
|
section.remove.input = {
|
2016-02-17 10:24:26 +00:00
|
|
|
search: {
|
2016-02-17 11:09:23 +00:00
|
|
|
view: document.querySelector(section.remove.text + '.remove_search_view'),
|
|
|
|
num: document.querySelector(section.remove.text + '.remove_search_num'),
|
|
|
|
sum: document.querySelector(section.remove.text + '.remove_search_sum'),
|
|
|
|
|
2016-02-17 10:24:26 +00:00
|
|
|
keyword: document.querySelector(section.remove.text + '#remove_search_keyword'),
|
|
|
|
id: document.querySelector(section.remove.text + '#remove_search_id'),
|
|
|
|
submit: document.querySelector(section.remove.text + '#remove_search_submit')
|
|
|
|
},
|
|
|
|
|
2016-02-15 21:08:49 +00:00
|
|
|
name: document.querySelector(section.remove.text + '#remove_name'),
|
|
|
|
|
|
|
|
submit: document.querySelector(section.remove.text + '#remove_submit')
|
|
|
|
};
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
var lastkeywords_remove = '';
|
|
|
|
var found_remove = [];
|
|
|
|
var searchindex_remove = 0;
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-02-15 21:08:49 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
/* (2) Gestion de l'auto-remplissage par lien
|
|
|
|
---------------------------------------------------------*/
|
2016-07-13 15:05:53 +00:00
|
|
|
function autofill_remove(){
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (0) Valeurs par défaut */
|
2016-07-12 10:06:46 +00:00
|
|
|
var machine_data = {
|
2016-07-13 14:58:39 +00:00
|
|
|
id_machine: '',
|
|
|
|
name: '',
|
|
|
|
disable_input: true
|
2016-02-17 10:24:26 +00:00
|
|
|
};
|
2016-02-15 21:08:49 +00:00
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// {1} Si aucun résultat //
|
|
|
|
if( found_remove[searchindex_remove] == null ){
|
2016-02-18 10:13:45 +00:00
|
|
|
|
2016-02-17 10:24:26 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// Mise a jour des indices des resultats
|
|
|
|
section.remove.input.search.num.innerHTML = 0;
|
|
|
|
searchindex_remove = 0;
|
2016-02-17 10:24:26 +00:00
|
|
|
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// {2} Si au moins 1 résultat //
|
|
|
|
}else{
|
|
|
|
|
|
|
|
// On recupere les données de la machine selectionnee
|
|
|
|
machine_data = {
|
|
|
|
id_machine: found_remove[searchindex_remove]['id_machine'],
|
|
|
|
name: found_remove[searchindex_remove]['name'],
|
|
|
|
disable_input: false
|
|
|
|
};
|
|
|
|
|
|
|
|
// Mise a jour des indices des resultats
|
2016-02-17 11:09:23 +00:00
|
|
|
section.remove.input.search.num.innerHTML = searchindex_remove+1;
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// {3} On auto-remplit le formulaire //
|
|
|
|
// On enregistre l'UID de la machine
|
|
|
|
section.remove.input.search.id.value = machine_data.id_machine;
|
|
|
|
|
|
|
|
// Auto-remplissage du formulaire
|
|
|
|
section.remove.input.name.value = machine_data.name;
|
|
|
|
|
|
|
|
// On gere le caractere "inactif" du submit
|
|
|
|
section.remove.input.submit.disabled = machine_data.disable_input;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gestion automatique au chargement de la page si ID_MACHINE dans url "/machines/remove/:id_machine:"
|
|
|
|
if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ){
|
|
|
|
|
|
|
|
// On récupère la machine d'uid donné dans l'URL
|
|
|
|
api.send({path:'machineDefault/getById', id_machine:pageManager.vars[1]}, function(response){
|
|
|
|
// Si aucune erreur et un résultat
|
|
|
|
if( response.ModuleError == 0 ){
|
|
|
|
found_remove = [ response.machine ]; // On récupère le résultat
|
|
|
|
searchindex_remove = 0; // On remet le compteur à 0
|
|
|
|
autofill_remove(); // On auto-remplit
|
|
|
|
}
|
2016-02-15 21:08:49 +00:00
|
|
|
});
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
}
|
2016-02-15 22:07:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (3) Gestion de la recherche
|
|
|
|
---------------------------------------------------------*/
|
2016-02-17 10:24:26 +00:00
|
|
|
section.remove.input.search.submit.addEventListener('click', function(e){
|
2016-02-15 22:07:20 +00:00
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
/* (1) Si le champ n'est pas vide */
|
2016-02-17 10:24:26 +00:00
|
|
|
if( section.remove.input.search.keyword.value != '' ){
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (2) Si même mots-clés, on passe au prochain résultat */
|
|
|
|
if( section.remove.input.search.keyword.value == lastkeywords_remove ){
|
2016-02-18 10:17:59 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// on affiche le prochain (decalage cyclique)
|
|
|
|
searchindex_remove = (searchindex_remove+1) % found_remove.length;
|
|
|
|
// On met à jour l'auto-remplissage
|
|
|
|
autofill_remove();
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (3) Nouveaux mots-clés, on lance la recherche */
|
|
|
|
}else{
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (4) Redaction de la requete */
|
|
|
|
var getMachines = {
|
|
|
|
path: 'machineDefault/search',
|
|
|
|
keywords: section.remove.input.search.keyword.value
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (5) On envoie la requête */
|
|
|
|
api.send(getMachines, function(getMachinesResponse){
|
|
|
|
if( getMachinesResponse.ModuleError == 0 ){ // si pas d'erreur
|
|
|
|
|
|
|
|
// On notifie que la recherche est terminée
|
|
|
|
section.remove.input.search.submit.anim('active', 1000);
|
|
|
|
|
|
|
|
/* (6) On met à jour les données des machines, et le compteur */
|
|
|
|
searchindex_remove = 0;
|
|
|
|
found_remove = getMachinesResponse.machines;
|
|
|
|
section.remove.input.search.sum.innerHTML = found_remove.length;
|
|
|
|
|
|
|
|
// On met à jour l'auto-remplissage
|
|
|
|
autofill_remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
// On met à jour la dernière recherche
|
|
|
|
lastkeywords_remove = getMachines.keywords;
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-02-17 10:24:26 +00:00
|
|
|
}
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-02-17 10:24:26 +00:00
|
|
|
}, false);
|
2016-07-03 12:57:25 +00:00
|
|
|
|
2016-02-15 22:07:20 +00:00
|
|
|
|
|
|
|
|
2016-02-17 10:24:26 +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();
|
|
|
|
|
|
|
|
// Si l'id est defini
|
|
|
|
if( section.remove.input.search.id.value != '' ){
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-02-17 10:24:26 +00:00
|
|
|
/* (2) On supprime la machine */
|
|
|
|
var request = {
|
|
|
|
path: 'machineDefault/delete', // On veut supprimer cet utilisateur
|
2016-07-03 13:03:31 +00:00
|
|
|
id_machine: section.remove.input.search.id.value
|
2016-02-17 10:24:26 +00:00
|
|
|
};
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-02-17 10:24:26 +00:00
|
|
|
api.send(request, function(answer){
|
|
|
|
if( answer.ModuleError == 0 && answer.status == true ){ // Tout s'est bien deroule
|
|
|
|
console.log('Machine supprimee!');
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-02-18 09:57:53 +00:00
|
|
|
section.remove.input.submit.anim('active', 1500);
|
2016-07-20 17:57:05 +00:00
|
|
|
|
|
|
|
pageManager.vars[1] = '';
|
|
|
|
navSubMenu('view');
|
|
|
|
document.location = '';
|
|
|
|
|
2016-02-17 10:24:26 +00:00
|
|
|
}else // Erreur
|
|
|
|
console.error('ModuleError::'+answer.ModuleError);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2016-02-15 22:07:20 +00:00
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
2016-02-15 21:08:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
|
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: {
|
2016-02-17 11:09:23 +00:00
|
|
|
view: document.querySelector(section.edit.text + '.edit_search_view'),
|
|
|
|
num: document.querySelector(section.edit.text + '.edit_search_num'),
|
|
|
|
sum: document.querySelector(section.edit.text + '.edit_search_sum'),
|
|
|
|
|
2016-02-16 13:36:23 +00:00
|
|
|
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
|
|
|
name: document.querySelector(section.edit.text + '#edit_name'),
|
|
|
|
|
|
|
|
submit: document.querySelector(section.edit.text + '#edit_submit')
|
|
|
|
};
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
var lastkeywords_edit = '';
|
|
|
|
var found_edit = [];
|
|
|
|
var searchindex_edit = 0;
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-02-15 21:08:49 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
/* (2) Gestion de l'auto-remplissage par lien
|
|
|
|
---------------------------------------------------------*/
|
2016-07-13 15:05:53 +00:00
|
|
|
function autofill_edit(){
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (0) Valeurs par défaut */
|
2016-02-17 11:09:23 +00:00
|
|
|
var machine_data = {
|
2016-07-13 14:58:39 +00:00
|
|
|
id_machine: '',
|
|
|
|
name: '',
|
|
|
|
disable_input: true
|
2016-02-16 21:59:01 +00:00
|
|
|
};
|
2016-02-15 21:08:49 +00:00
|
|
|
|
2016-02-16 13:42:48 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// {1} Si aucun résultat //
|
|
|
|
if( found_edit[searchindex_edit] == null ){
|
2016-02-16 13:42:48 +00:00
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// Mise a jour des indices des resultats
|
|
|
|
section.edit.input.search.num.innerHTML = 0;
|
|
|
|
searchindex_edit = 0;
|
2016-02-17 11:09:23 +00:00
|
|
|
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// {2} Si au moins 1 résultat //
|
|
|
|
}else{
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// On recupere les données de la machine selectionnee
|
|
|
|
machine_data = {
|
|
|
|
id_machine: found_edit[searchindex_edit]['id_machine'],
|
|
|
|
name: found_edit[searchindex_edit]['name'],
|
|
|
|
disable_input: false
|
|
|
|
};
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// Mise a jour des indices des resultats
|
|
|
|
section.edit.input.search.num.innerHTML = searchindex_edit+1;
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// {3} On auto-remplit le formulaire //
|
|
|
|
// On enregistre l'UID de la machine
|
|
|
|
section.edit.input.search.id.value = machine_data.id_machine;
|
|
|
|
|
|
|
|
// Auto-remplissage du formulaire
|
|
|
|
section.edit.input.name.value = machine_data.name;
|
|
|
|
|
|
|
|
// On gere le caractere "inactif" du submit
|
|
|
|
section.edit.input.submit.disabled = machine_data.disable_input;
|
2016-02-16 21:59:01 +00:00
|
|
|
|
2016-02-16 13:36:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
}
|
2016-02-16 13:36:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// Gestion automatique au chargement de la page si ID_MACHINE dans url "/machines/edit/:id_machine:"
|
|
|
|
if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ){
|
2016-02-16 13:36:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// On récupère la machine d'uid donné dans l'URL
|
|
|
|
api.send({path:'machineDefault/getById', id_machine:pageManager.vars[1]}, function(response){
|
|
|
|
// Si aucune erreur et un résultat
|
|
|
|
if( response.ModuleError == 0 ){
|
|
|
|
found_edit = [ response.machine ]; // On récupère le résultat
|
|
|
|
searchindex_edit = 0; // On remet le compteur à 0
|
|
|
|
autofill_edit(); // On auto-remplit
|
|
|
|
}
|
|
|
|
});
|
2016-02-16 14:04:48 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
}
|
2016-02-16 14:04:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (3) Gestion de la recherche
|
|
|
|
---------------------------------------------------------*/
|
2016-02-16 13:36:23 +00:00
|
|
|
section.edit.input.search.submit.addEventListener('click', function(e){
|
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
/* (1) Si le champ n'est pas vide */
|
2016-02-16 13:36:23 +00:00
|
|
|
if( section.edit.input.search.keyword.value != '' ){
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (2) Si même mots-clés, on passe au prochain résultat */
|
|
|
|
if( section.edit.input.search.keyword.value == lastkeywords_edit ){
|
|
|
|
|
|
|
|
// on affiche le prochain (decalage cyclique)
|
|
|
|
searchindex_edit = (searchindex_edit+1) % found_edit.length;
|
|
|
|
// On met à jour l'auto-remplissage
|
|
|
|
autofill_edit();
|
|
|
|
|
2016-02-18 10:17:59 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (3) Nouveaux mots-clés, on lance la recherche */
|
|
|
|
}else{
|
|
|
|
|
|
|
|
/* (4) Redaction de la requete */
|
|
|
|
var getMachines = {
|
|
|
|
path: 'machineDefault/search',
|
|
|
|
keywords: section.edit.input.search.keyword.value
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (5) On envoie la requête */
|
|
|
|
api.send(getMachines, function(getMachinesResponse){
|
|
|
|
if( getMachinesResponse.ModuleError == 0 ){ // si pas d'erreur
|
|
|
|
|
|
|
|
// On notifie que la recherche est terminée
|
|
|
|
section.edit.input.search.submit.anim('active', 1000);
|
|
|
|
|
|
|
|
/* (6) On met à jour les données des machines, et le compteur */
|
2016-02-17 11:09:23 +00:00
|
|
|
searchindex_edit = 0;
|
2016-07-13 14:58:39 +00:00
|
|
|
found_edit = getMachinesResponse.machines;
|
|
|
|
section.edit.input.search.sum.innerHTML = found_edit.length;
|
2016-02-16 13:36:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// On met à jour l'auto-remplissage
|
|
|
|
autofill_edit();
|
|
|
|
}
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// On met à jour la dernière recherche
|
|
|
|
lastkeywords_edit = getMachines.keywords;
|
|
|
|
});
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
}
|
2016-02-16 13:36:23 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, false);
|
2016-07-03 12:57:25 +00:00
|
|
|
|
2016-02-16 13:36:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2016-07-03 13:03:31 +00:00
|
|
|
id_machine: section.edit.input.search.id.value,
|
|
|
|
name: section.edit.input.name.value
|
2016-02-16 14:04:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
api.send(request, function(answer){
|
2016-02-16 21:59:01 +00:00
|
|
|
if( answer.ModuleError == 0 && answer.status == true ){ // Tout s'est bien deroule
|
2016-02-16 14:04:48 +00:00
|
|
|
console.log('Machine modifiee!');
|
2016-02-16 21:59:01 +00:00
|
|
|
|
2016-02-18 09:57:53 +00:00
|
|
|
section.edit.input.submit.anim('active', 1500);
|
2016-07-20 17:41:43 +00:00
|
|
|
|
|
|
|
|
2016-02-16 21:59:01 +00:00
|
|
|
// On met a jour la machine
|
2016-07-20 17:41:43 +00:00
|
|
|
pageManager.vars[1] = request.id_machine;
|
|
|
|
navSubMenu('view');
|
|
|
|
document.location = '';
|
2016-02-16 21:59:01 +00:00
|
|
|
|
|
|
|
}else // Erreur
|
2016-02-16 14:04:48 +00:00
|
|
|
console.error('ModuleError::'+answer.ModuleError);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
|
|
|
|
}
|
2016-07-20 23:19:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [5] groups -> Groupes de machines
|
|
|
|
=========================================================*/
|
|
|
|
if( section.groups.element != null ){
|
|
|
|
|
|
|
|
/* (1) On recupere tous les liens vers des sous-sections */
|
|
|
|
section.groups.link = {
|
|
|
|
remove: document.querySelectorAll(section.groups.text + '.link_remove[data-cluster]'),
|
|
|
|
edit: document.querySelectorAll(section.groups.text + '.link_edit[data-cluster]')
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (2) On récupère toutes les actions de groupes */
|
|
|
|
section.groups.group = {
|
|
|
|
rem: document.querySelectorAll(section.groups.text + '.rem-member[data-cluster][data-member]'),
|
|
|
|
add: document.querySelectorAll(section.groups.text + '.add-member[data-cluster]')
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) Gestion de la recherche instantannee */
|
|
|
|
section.groups.searchbar.addEventListener('keyup', function(e){
|
|
|
|
|
|
|
|
var search = {
|
|
|
|
path: 'clusterDefault/search',
|
|
|
|
keywords: section.groups.searchbar.value,
|
|
|
|
class: 1
|
|
|
|
};
|
|
|
|
|
|
|
|
// On envoie la requete
|
|
|
|
api.send(search, function(result){
|
|
|
|
if( result.ModuleError == 0 ){ // si aucune erreur
|
|
|
|
|
|
|
|
// On enregistre tous les UID dans un tableau
|
|
|
|
var uid_list = [];
|
|
|
|
for( var i = 0 ; i < result.clusters.length ; i++ )
|
|
|
|
uid_list.push( result.clusters[i].id_machine_cluster);
|
|
|
|
|
|
|
|
// On recupere la liste des elements correspondants aux utilisateurs
|
|
|
|
var cluster_list = document.querySelectorAll(section.groups.text + '> article.inline-box[id]');
|
|
|
|
|
|
|
|
// Pour chaque cluster
|
|
|
|
for( var i = 0 ; i < cluster_list.length ; i++ ){
|
|
|
|
// Si doit etre visible
|
|
|
|
if( uid_list.indexOf(cluster_list[i].id) > -1 )
|
|
|
|
cluster_list[i].remClass('hidden');
|
|
|
|
// Si ne doit pas etre visible
|
|
|
|
else
|
|
|
|
cluster_list[i].addClass('hidden');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
var i;
|
|
|
|
|
|
|
|
|
|
|
|
/* (4) On gere la "redirection" vers la modification */
|
|
|
|
for( i = 0 ; i < section.groups.link.edit.length ; i++ ){
|
|
|
|
|
|
|
|
section.groups.link.edit[i].addEventListener('click', function(e){
|
|
|
|
pageManager.vars[0] = 'edit';
|
|
|
|
pageManager.vars[1] = 'm'+e.target.getData('cluster');
|
|
|
|
navMenu('groups', true);
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (5) On gere la "redirection" vers la suppression */
|
|
|
|
for( i = 0 ; i < section.groups.link.remove.length ; i++ ){
|
|
|
|
|
|
|
|
section.groups.link.remove[i].addEventListener('click', function(e){
|
|
|
|
pageManager.vars[0] = 'remove';
|
|
|
|
pageManager.vars[1] = 'm'+e.target.getData('cluster');
|
|
|
|
navMenu('groups', true);
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (6) On gere la "suppression" d'un groupe */
|
|
|
|
for( i = 0 ; i < section.groups.group.rem.length ; i++ ){
|
|
|
|
|
|
|
|
section.groups.group.rem[i].addEventListener('click', function(e){
|
|
|
|
// {1} On rédige la requête //
|
|
|
|
var request = {
|
|
|
|
path: 'machineDefault/unlink',
|
|
|
|
id_cluster: e.target.getData('cluster'),
|
|
|
|
id_machine: e.target.getData('member')
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// {2} On envoie la requête //
|
|
|
|
api.send(request, function(response){
|
|
|
|
|
|
|
|
// {3} Si erreur, on ne fait rien //
|
|
|
|
if( response.ModuleError != 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// {4} Si tout s'est bien passé //
|
|
|
|
e.target.parentNode.parentNode.removeChild( e.target.parentNode );
|
|
|
|
});
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (7) On gere la "modification" des membres d'un groupe */
|
|
|
|
for( i = 0 ; i < section.groups.group.add.length ; i++ ){
|
|
|
|
|
|
|
|
section.groups.group.add[i].addEventListener('click', function(e){
|
|
|
|
pageManager.vars[0] = 'members';
|
|
|
|
pageManager.vars[1] = 'm'+e.target.getData('cluster');
|
|
|
|
navMenu('groups', true);
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|