Correction JS de la recherche interne aux formulaires pour la vue 'groups'
This commit is contained in:
parent
2a36946044
commit
6a5234917c
|
@ -1,18 +1,18 @@
|
||||||
var section={view:{text:'#CONTAINER > section[data-sublink="view"] ',element:document.querySelector('#CONTAINER > section[data-sublink="view"]'),searchbar:document.querySelector('#CONTAINER > section[data-sublink="view"] > .searchbar')},create:{text:'#CONTAINER > section[data-sublink="create"] ',element:document.querySelector('#CONTAINER > section[data-sublink="create"]')},remove:{text:'#CONTAINER > section[data-sublink="remove"] ',element:document.querySelector('#CONTAINER > section[data-sublink="remove"]')},
|
var section={view:{text:'#CONTAINER > section[data-sublink="view"] ',element:document.querySelector('#CONTAINER > section[data-sublink="view"]'),searchbar:document.querySelector('#CONTAINER > section[data-sublink="view"] > .searchbar')},create:{text:'#CONTAINER > section[data-sublink="create"] ',element:document.querySelector('#CONTAINER > section[data-sublink="create"]')},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"]')}};
|
edit:{text:'#CONTAINER > section[data-sublink="edit"] ',element:document.querySelector('#CONTAINER > section[data-sublink="edit"]')}};
|
||||||
if(null!=section.view.element){1<pageManager.vars.length&&!isNaN(pageManager.vars[1])&&(document.location="#"+pageManager.vars[1],document.getElementById(pageManager.vars[1]).addClass("selected"));section.view.link={edit:document.querySelectorAll(section.view.text+".link_edit[data-cluster]"),remove:document.querySelectorAll(section.view.text+".link_remove[data-cluster]")};section.view.group={rem:document.querySelectorAll(section.view.text+".rem-group[data-cluster][data-group]"),add:document.querySelectorAll(section.view.text+
|
if(null!=section.view.element){1<pageManager.vars.length&&!isNaN(pageManager.vars[1])&&(document.location="#"+pageManager.vars[1],document.getElementById(pageManager.vars[1]).addClass("selected"));section.view.link={edit:document.querySelectorAll(section.view.text+".link_edit[data-cluster]"),remove:document.querySelectorAll(section.view.text+".link_remove[data-cluster]")};section.view.group={rem:document.querySelectorAll(section.view.text+".rem-group[data-cluster][data-group]"),add:document.querySelectorAll(section.view.text+
|
||||||
".add-group[data-cluster]")};section.view.searchbar.addEventListener("keyup",function(b){api.send({path:"clusterDefault/search",keywords:section.view.searchbar.value},function(a){if(0==a.ModuleError){for(var b=[],c=0;c<a.clusters.length;c++)b.push(a.clusters[c].id_cluster);a=document.querySelectorAll(section.view.text+"> article.inline-box[id]");for(c=0;c<a.length;c++)-1<b.indexOf(a[c].id)?a[c].remClass("hidden"):a[c].addClass("hidden")}})},!1);for(var i=0;i<section.view.link.edit.length;i++)section.view.link.edit[i].addEventListener("click",
|
".add-group[data-cluster]")};section.view.searchbar.addEventListener("keyup",function(a){api.send({path:"clusterDefault/search",keywords:section.view.searchbar.value},function(b){if(0==b.ModuleError){for(var a=[],c=0;c<b.clusters.length;c++)a.push(b.clusters[c].id_cluster);b=document.querySelectorAll(section.view.text+"> article.inline-box[id]");for(c=0;c<b.length;c++)-1<a.indexOf(b[c].id)?b[c].remClass("hidden"):b[c].addClass("hidden")}})},!1);for(var i=0;i<section.view.link.edit.length;i++)section.view.link.edit[i].addEventListener("click",
|
||||||
function(b){pageManager.vars[1]=b.target.getData("cluster");autofill_edit(pageManager.vars[1]);navSubMenu("edit")},!1);for(i=0;i<section.view.link.remove.length;i++)section.view.link.remove[i].addEventListener("click",function(b){pageManager.vars[1]=b.target.getData("cluster");autofill_remove(pageManager.vars[1]);navSubMenu("remove")},!1);for(i=0;i<section.view.group.rem.length;i++)section.view.group.rem[i].addEventListener("click",function(b){var a={path:"clusterDefault/unlink",id_cluster:b.target.getData("cluster"),
|
function(a){pageManager.vars[1]=a.target.getData("cluster");autofill_edit(pageManager.vars[1]);navSubMenu("edit")},!1);for(i=0;i<section.view.link.remove.length;i++)section.view.link.remove[i].addEventListener("click",function(a){pageManager.vars[1]=a.target.getData("cluster");autofill_remove(pageManager.vars[1]);navSubMenu("remove")},!1);for(i=0;i<section.view.group.rem.length;i++)section.view.group.rem[i].addEventListener("click",function(a){var b={path:"clusterDefault/unlink",id_user:a.target.getData("user"),
|
||||||
id_cluster:b.target.getData("group")};api.send(a,function(a){if(0!=a.ModuleError)return!1;b.target.parentNode.parentNode.removeChild(b.target.parentNode)})},!1)}
|
id_cluster:a.target.getData("group")};api.send(b,function(b){if(0!=b.ModuleError)return!1;a.target.parentNode.parentNode.removeChild(a.target.parentNode)})},!1)}
|
||||||
null!=section.create.element&&(section.create.input={name:document.querySelector(section.create.text+"#create_name"),"class":document.querySelector(section.create.text+"#create_class"),submit:document.querySelector(section.create.text+"#create_submit")},section.create.input.submit.addEventListener("click",function(b){b.preventDefault();api.send({path:"clusterDefault/create",name:section.create.input.name.value,"class":section.create.input["class"].value},function(a){0==a.ModuleError&&(console.log("Groupe cree!"),
|
null!=section.create.element&&(section.create.input={name:document.querySelector(section.create.text+"#create_name"),"class":document.querySelector(section.create.text+"#create_class"),submit:document.querySelector(section.create.text+"#create_submit")},section.create.input.submit.addEventListener("click",function(a){a.preventDefault();api.send({path:"clusterDefault/create",name:section.create.input.name.value,"class":section.create.input["class"].value},function(b){0==b.ModuleError&&(console.log("Groupe cree!"),
|
||||||
pageManager.vars=["view",a.id_cluster],pageManager.refresh(),document.location="",section.create.input.submit.anim("active",1500))})},!1));
|
pageManager.vars=["view",b.id_cluster],pageManager.refresh(),document.location="",section.create.input.submit.anim("active",1500))})},!1));
|
||||||
if(null!=section.remove.element){var autofill_remove=function(b){var a={id_cluster:"",name:"",disable_input:!0};api.send({path:"clusterDefault/getById",id_cluster:b},function(b){0==b.ModuleError&&(a=b.cluster,a.diable_input=!1);section.remove.input.search.id.value=a.id_cluster;section.remove.input.name.value=a.name;section.remove.input.submit.disabled=a.disable_input;section.remove.input.search.num.innerHTML=searchindex_remove+1})};section.remove.input={search:{view:document.querySelector(section.remove.text+
|
if(null!=section.remove.element){var autofill_remove=function(){var a="",b="",d=!0;null==found_remove[searchindex_remove]?searchindex_remove=section.remove.input.search.num.innerHTML=0:(a=found_remove[searchindex_remove].id_cluster,b=found_remove[searchindex_remove].name,d=!1,section.remove.input.search.num.innerHTML=searchindex_remove+1);section.remove.input.search.id.value=a;section.remove.input.name.value=b;section.remove.input.submit.disabled=d};section.remove.input={search:{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"),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")},name:document.querySelector(section.remove.text+"#remove_name"),submit:document.querySelector(section.remove.text+"#remove_submit")};
|
".remove_search_view"),num:document.querySelector(section.remove.text+".remove_search_num"),sum:document.querySelector(section.remove.text+".remove_search_sum"),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")},name:document.querySelector(section.remove.text+"#remove_name"),submit:document.querySelector(section.remove.text+"#remove_submit")};
|
||||||
var lastsearch_remove=null,searchindex_remove=0;2<=pageManager.vars.length&&!isNaN(pageManager.vars[1])&&autofill_remove(pageManager.vars[1]);section.remove.input.search.submit.addEventListener("click",function(b){b.preventDefault();""!=section.remove.input.search.keyword.value&&api.send({path:"clusterDefault/search",keywords:section.remove.input.search.keyword.value},function(a){0==a.ModuleError&&0<a.clusters.length?(section.remove.input.search.submit.anim("active",1E3),lastsearch_remove==a.clusters[searchindex_remove].id_cluster&&
|
var lastkeywords_remove="",found_remove=[],searchindex_remove=0;2<=pageManager.vars.length&&!isNaN(pageManager.vars[1])&&api.send({path:"clusterDefault/getById",id_cluster:pageManager.vars[1]},function(a){0==a.ModuleError&&(found_remove=[a.cluster],searchindex_remove=0,autofill_remove())});section.remove.input.search.submit.addEventListener("click",function(a){a.preventDefault();if(""!=section.remove.input.search.keyword.value)if(section.remove.input.search.keyword.value==lastkeywords_remove)searchindex_remove=
|
||||||
(searchindex_remove=(searchindex_remove+1)%a.clusters.length),lastsearch_remove=a.clusters[searchindex_remove].id_cluster,section.remove.input.search.id.value=lastsearch_remove,section.remove.input.search.sum.innerHTML=a.clusters.length,autofill_remove(lastsearch_remove)):(section.remove.input.search.sum.innerHTML=0,autofill_remove(null))})},!1);section.remove.input.submit.addEventListener("click",function(b){b.preventDefault();""!=section.remove.input.search.id.value&&api.send({path:"clusterDefault/delete",
|
(searchindex_remove+1)%found_remove.length,autofill_remove();else{var b={path:"clusterDefault/search",keywords:section.remove.input.search.keyword.value};api.send(b,function(a){0==a.ModuleError&&(section.remove.input.search.submit.anim("active",1E3),searchindex_remove=0,found_remove=a.clusters,section.remove.input.search.sum.innerHTML=found_remove.length,autofill_remove());lastkeywords_remove=b.keywords})}},!1);section.remove.input.submit.addEventListener("click",function(a){a.preventDefault();""!=
|
||||||
id_cluster:section.remove.input.search.id.value},function(a){0==a.ModuleError&&1==a.status?(console.log("Groupe supprimee!"),section.remove.input.submit.anim("active",1500),autofill_remove(null)):console.error("ModuleError::"+a.ModuleError)})},!1)}
|
section.remove.input.search.id.value&&api.send({path:"clusterDefault/delete",id_cluster:section.remove.input.search.id.value},function(a){0==a.ModuleError&&1==a.status?(console.log("Groupe supprimee!"),section.remove.input.submit.anim("active",1500),autofill_remove(null)):console.error("ModuleError::"+a.ModuleError)})},!1)}
|
||||||
if(null!=section.edit.element){var autofill_edit=function(b){var a={id_cluster:"",name:"",disable_input:!0};isNaN(b)?section.edit.input.search.num.innerHTML=0:api.send({path:"clusterDefault/getById",id_cluster:b},function(b){0==b.ModuleError&&(a=b.cluster,a.disable_input=!1);section.edit.input.search.id.value=a.id_cluster;section.edit.input.name.value=a.name;section.edit.input.submit.disabled=a.disable_input;section.edit.input.search.num.innerHTML=searchindex_edit+1})};section.edit.input={search:{view:document.querySelector(section.edit.text+
|
if(null!=section.edit.element){var autofill_edit=function(){var a="",b="",d=!0;null==found_edit[searchindex_edit]?searchindex_edit=section.edit.input.search.num.innerHTML=0:(a=found_edit[searchindex_edit].id_cluster,b=found_edit[searchindex_edit].name,d=!1,section.edit.input.search.num.innerHTML=searchindex_edit+1);section.edit.input.search.id.value=a;section.edit.input.name.value=b;section.edit.input.submit.disabled=d};section.edit.input={search:{view:document.querySelector(section.edit.text+".edit_search_view"),
|
||||||
".edit_search_view"),num:document.querySelector(section.edit.text+".edit_search_num"),sum:document.querySelector(section.edit.text+".edit_search_sum"),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")},name:document.querySelector(section.edit.text+"#edit_name"),submit:document.querySelector(section.edit.text+"#edit_submit")};var lastsearch_edit=
|
num:document.querySelector(section.edit.text+".edit_search_num"),sum:document.querySelector(section.edit.text+".edit_search_sum"),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")},name:document.querySelector(section.edit.text+"#edit_name"),submit:document.querySelector(section.edit.text+"#edit_submit")};var lastkeywords_edit="",found_edit=[],
|
||||||
null,searchindex_edit=0;2<=pageManager.vars.length&&!isNaN(pageManager.vars[1])&&autofill_edit(pageManager.vars[1]);section.edit.input.search.submit.addEventListener("click",function(b){b.preventDefault();""!=section.edit.input.search.keyword.value&&api.send({path:"clusterDefault/search",keywords:section.edit.input.search.keyword.value},function(a){0==a.ModuleError&&0<a.clusters.length?(section.edit.input.search.submit.anim("active",1E3),searchindex_edit=lastsearch_edit==a.clusters[searchindex_edit].id_cluster?
|
searchindex_edit=0;2<=pageManager.vars.length&&!isNaN(pageManager.vars[1])&&api.send({path:"clusterDefault/getById",id_cluster:pageManager.vars[1]},function(a){0==a.ModuleError&&(found_edit=[a.cluster],searchindex_edit=0,autofill_edit())});section.edit.input.search.submit.addEventListener("click",function(a){a.preventDefault();if(""!=section.edit.input.search.keyword.value)if(section.edit.input.search.keyword.value==lastkeywords_edit)searchindex_edit=(searchindex_edit+1)%found_edit.length,autofill_edit();
|
||||||
(searchindex_edit+1)%a.clusters.length:0,lastsearch_edit=a.clusters[searchindex_edit].id_cluster,section.edit.input.search.id.value=lastsearch_edit,section.edit.input.search.sum.innerHTML=a.clusters.length,autofill_edit(lastsearch_edit)):(section.edit.input.search.sum.innerHTML=0,autofill_edit(null))})},!1);section.edit.input.submit.addEventListener("click",function(b){b.preventDefault();""!=section.edit.input.search.id.value&&api.send({path:"clusterDefault/edit",id_cluster:section.edit.input.search.id.value,
|
else{var b={path:"clusterDefault/search",keywords:section.edit.input.search.keyword.value};api.send(b,function(a){0==a.ModuleError&&(section.edit.input.search.submit.anim("active",1E3),searchindex_edit=0,found_edit=a.clusters,section.edit.input.search.sum.innerHTML=found_edit.length,autofill_edit());lastkeywords_edit=b.keywords})}},!1);section.edit.input.submit.addEventListener("click",function(a){a.preventDefault();""!=section.edit.input.search.id.value&&api.send({path:"clusterDefault/edit",id_cluster:section.edit.input.search.id.value,
|
||||||
name:section.edit.input.name.value},function(a){0==a.ModuleError&&1==a.status?(console.log("Groupe modifiee!"),section.edit.input.submit.anim("active",1500),autofill_edit(section.edit.input.search.id.value)):console.error("ModuleError::"+a.ModuleError)})},!1)};
|
name:section.edit.input.name.value},function(a){0==a.ModuleError&&1==a.status?(console.log("Groupe modifiee!"),section.edit.input.submit.anim("active",1500),autofill_edit(section.edit.input.search.id.value)):console.error("ModuleError::"+a.ModuleError)})},!1)};
|
||||||
|
|
|
@ -112,7 +112,7 @@ if( section.view.element != null ){
|
||||||
// {1} On rédige la requête //
|
// {1} On rédige la requête //
|
||||||
var request = {
|
var request = {
|
||||||
path: 'clusterDefault/unlink',
|
path: 'clusterDefault/unlink',
|
||||||
id_cluster: e.target.getData('cluster'),
|
id_user: e.target.getData('user'),
|
||||||
id_cluster: e.target.getData('group')
|
id_cluster: e.target.getData('group')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -220,26 +220,50 @@ if( section.remove.element != null ){
|
||||||
submit: document.querySelector(section.remove.text + '#remove_submit')
|
submit: document.querySelector(section.remove.text + '#remove_submit')
|
||||||
};
|
};
|
||||||
|
|
||||||
var lastsearch_remove = null;
|
var lastkeywords_remove = '';
|
||||||
|
var found_remove = [];
|
||||||
var searchindex_remove = 0;
|
var searchindex_remove = 0;
|
||||||
|
|
||||||
|
|
||||||
/* (2) Gestion de l'auto-remplissage par lien */
|
|
||||||
function autofill_remove(id_cluster){
|
/* (2) Gestion de l'auto-remplissage par lien
|
||||||
// On recupere le name de la cluster selectionnee
|
---------------------------------------------------------*/
|
||||||
|
function autofill_remove(){
|
||||||
|
/* (0) Valeurs par défaut */
|
||||||
var cluster_data = {
|
var cluster_data = {
|
||||||
id_cluster: '',
|
id_cluster: '',
|
||||||
name: '',
|
name: '',
|
||||||
disable_input: true
|
disable_input: true
|
||||||
};
|
};
|
||||||
|
|
||||||
api.send({path:'clusterDefault/getById', id_cluster: id_cluster}, function(answer){
|
|
||||||
if( answer.ModuleError == 0 ){ // Aucune erreur
|
// {1} Si aucun résultat //
|
||||||
cluster_data = answer.cluster;
|
if( found_remove[searchindex_remove] == null ){
|
||||||
cluster_data.diable_input = false;
|
|
||||||
|
|
||||||
|
// Mise a jour des indices des resultats
|
||||||
|
section.remove.input.search.num.innerHTML = 0;
|
||||||
|
searchindex_remove = 0;
|
||||||
|
|
||||||
|
|
||||||
|
// {2} Si au moins 1 résultat //
|
||||||
|
}else{
|
||||||
|
|
||||||
|
// On recupere les données de la user selectionnee
|
||||||
|
cluster_data = {
|
||||||
|
id_cluster: found_remove[searchindex_remove]['id_cluster'],
|
||||||
|
name: found_remove[searchindex_remove]['name'],
|
||||||
|
disable_input: false
|
||||||
|
};
|
||||||
|
|
||||||
|
// Mise a jour des indices des resultats
|
||||||
|
section.remove.input.search.num.innerHTML = searchindex_remove+1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// On enregistre l'UID de la cluster
|
|
||||||
|
// {3} On auto-remplit le formulaire //
|
||||||
|
// On enregistre l'UID du groupe
|
||||||
section.remove.input.search.id.value = cluster_data.id_cluster;
|
section.remove.input.search.id.value = cluster_data.id_cluster;
|
||||||
|
|
||||||
// Auto-remplissage du formulaire
|
// Auto-remplissage du formulaire
|
||||||
|
@ -248,49 +272,76 @@ if( section.remove.element != null ){
|
||||||
// On gere le caractere "inactif" du submit
|
// On gere le caractere "inactif" du submit
|
||||||
section.remove.input.submit.disabled = cluster_data.disable_input;
|
section.remove.input.submit.disabled = cluster_data.disable_input;
|
||||||
|
|
||||||
// Mise a jour des indices des resultats
|
|
||||||
section.remove.input.search.num.innerHTML = searchindex_remove+1;
|
}
|
||||||
|
|
||||||
|
// Gestion automatique au chargement de la page si ID_CLUSTER dans url "/users/remove/:id_cluster:"
|
||||||
|
if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ){
|
||||||
|
|
||||||
|
// On récupère la user d'uid donné dans l'URL
|
||||||
|
api.send({path:'clusterDefault/getById', id_cluster:pageManager.vars[1]}, function(response){
|
||||||
|
// Si aucune erreur et un résultat
|
||||||
|
if( response.ModuleError == 0 ){
|
||||||
|
found_remove = [ response.cluster ]; // On récupère le résultat
|
||||||
|
searchindex_remove = 0; // On remet le compteur à 0
|
||||||
|
autofill_remove(); // On auto-remplit
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ) autofill_remove(pageManager.vars[1]);
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* (3) Gestion de la recherche */
|
/* (3) Gestion de la recherche
|
||||||
|
---------------------------------------------------------*/
|
||||||
section.remove.input.search.submit.addEventListener('click', function(e){
|
section.remove.input.search.submit.addEventListener('click', function(e){
|
||||||
// On annule l'envoi de base (PHP)
|
// On annule l'envoi de base (PHP)
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
// Si le champ n'est pas vide, on lance la recherche
|
|
||||||
|
/* (1) Si le champ n'est pas vide */
|
||||||
if( section.remove.input.search.keyword.value != '' ){
|
if( section.remove.input.search.keyword.value != '' ){
|
||||||
// Redaction de la requete
|
|
||||||
var getuid = {
|
/* (2) Si même mots-clés, on passe au prochain résultat */
|
||||||
|
if( section.remove.input.search.keyword.value == lastkeywords_remove ){
|
||||||
|
|
||||||
|
// on affiche le prochain (decalage cyclique)
|
||||||
|
searchindex_remove = (searchindex_remove+1) % found_remove.length;
|
||||||
|
// On met à jour l'auto-remplissage
|
||||||
|
autofill_remove();
|
||||||
|
|
||||||
|
|
||||||
|
/* (3) Nouveaux mots-clés, on lance la recherche */
|
||||||
|
}else{
|
||||||
|
|
||||||
|
/* (4) Redaction de la requete */
|
||||||
|
var getClusters = {
|
||||||
path: 'clusterDefault/search',
|
path: 'clusterDefault/search',
|
||||||
keywords: section.remove.input.search.keyword.value
|
keywords: section.remove.input.search.keyword.value
|
||||||
};
|
};
|
||||||
|
|
||||||
// On envoie la requete
|
/* (5) On envoie la requête */
|
||||||
api.send(getuid, function(uidanswer){
|
api.send(getClusters, function(getClustersResponse){
|
||||||
if( uidanswer.ModuleError == 0 && uidanswer.clusters.length > 0){ // si on a trouve qqch
|
if( getClustersResponse.ModuleError == 0 ){ // si pas d'erreur
|
||||||
|
|
||||||
|
// On notifie que la recherche est terminée
|
||||||
section.remove.input.search.submit.anim('active', 1000);
|
section.remove.input.search.submit.anim('active', 1000);
|
||||||
|
|
||||||
// Si on trouve la meme cluster que lors de la derniere recherche
|
/* (6) On met à jour les données des users, et le compteur */
|
||||||
if( lastsearch_remove == uidanswer.clusters[searchindex_remove].id_cluster )
|
searchindex_remove = 0;
|
||||||
searchindex_remove = (searchindex_remove+1) % uidanswer.clusters.length; // on affiche le prochain (decalage cyclique)
|
found_remove = getClustersResponse.clusters;
|
||||||
|
section.remove.input.search.sum.innerHTML = found_remove.length;
|
||||||
|
|
||||||
lastsearch_remove = uidanswer.clusters[searchindex_remove].id_cluster;
|
// On met à jour l'auto-remplissage
|
||||||
section.remove.input.search.id.value = lastsearch_remove;
|
autofill_remove();
|
||||||
|
|
||||||
// Mise a jour des indices des resultats
|
|
||||||
section.remove.input.search.sum.innerHTML = uidanswer.clusters.length;
|
|
||||||
|
|
||||||
// on auto-remplit le formulaire
|
|
||||||
autofill_remove(lastsearch_remove);
|
|
||||||
|
|
||||||
}else{
|
|
||||||
section.remove.input.search.sum.innerHTML = 0;
|
|
||||||
autofill_remove(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// On met à jour la dernière recherche
|
||||||
|
lastkeywords_remove = getClusters.keywords;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}, false);
|
}, false);
|
||||||
|
@ -358,92 +409,128 @@ if( section.edit.element != null ){
|
||||||
submit: document.querySelector(section.edit.text + '#edit_submit')
|
submit: document.querySelector(section.edit.text + '#edit_submit')
|
||||||
};
|
};
|
||||||
|
|
||||||
var lastsearch_edit = null;
|
var lastkeywords_edit = '';
|
||||||
|
var found_edit = [];
|
||||||
var searchindex_edit = 0;
|
var searchindex_edit = 0;
|
||||||
|
|
||||||
|
|
||||||
// Gestion de l'auto-remplissage par lien
|
|
||||||
function autofill_edit(id_cluster){
|
/* (2) Gestion de l'auto-remplissage par lien
|
||||||
// On recupere le name de la cluster selectionnee
|
---------------------------------------------------------*/
|
||||||
|
function autofill_edit(){
|
||||||
|
/* (0) Valeurs par défaut */
|
||||||
var cluster_data = {
|
var cluster_data = {
|
||||||
id_cluster: '',
|
id_cluster: '',
|
||||||
name: '',
|
name: '',
|
||||||
disable_input: true
|
disable_input: true
|
||||||
};
|
};
|
||||||
|
|
||||||
// Si @id_cluster est un entier
|
|
||||||
if( !isNaN(id_cluster) ){
|
|
||||||
|
|
||||||
api.send({path:'clusterDefault/getById', id_cluster: id_cluster}, function(answer){
|
// {1} Si aucun résultat //
|
||||||
if( answer.ModuleError == 0 ){ // Aucune erreur
|
if( found_edit[searchindex_edit] == null ){
|
||||||
cluster_data = answer.cluster;
|
|
||||||
cluster_data.disable_input = false;
|
|
||||||
|
// Mise a jour des indices des resultats
|
||||||
|
section.edit.input.search.num.innerHTML = 0;
|
||||||
|
searchindex_edit = 0;
|
||||||
|
|
||||||
|
|
||||||
|
// {2} Si au moins 1 résultat //
|
||||||
|
}else{
|
||||||
|
|
||||||
|
// On recupere les données de la user selectionnee
|
||||||
|
cluster_data = {
|
||||||
|
id_cluster: found_edit[searchindex_edit]['id_cluster'],
|
||||||
|
name: found_edit[searchindex_edit]['name'],
|
||||||
|
disable_input: false
|
||||||
|
};
|
||||||
|
|
||||||
|
// Mise a jour des indices des resultats
|
||||||
|
section.edit.input.search.num.innerHTML = searchindex_edit+1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// On enregistre l'UID de la cluster
|
// {3} On auto-remplit le formulaire //
|
||||||
|
// On enregistre l'UID du groupe
|
||||||
section.edit.input.search.id.value = cluster_data.id_cluster;
|
section.edit.input.search.id.value = cluster_data.id_cluster;
|
||||||
|
|
||||||
// Auto-remplissage du formulaire
|
// Auto-remplissage du formulaire
|
||||||
section.edit.input.name.value = cluster_data.name;
|
section.edit.input.name.value = cluster_data.name;
|
||||||
|
|
||||||
// On active ou pas le bouton "Modifier"
|
// On gere le caractere "inactif" du submit
|
||||||
section.edit.input.submit.disabled = cluster_data.disable_input;
|
section.edit.input.submit.disabled = cluster_data.disable_input;
|
||||||
|
|
||||||
// Mise a jour des indices des resultats
|
|
||||||
section.edit.input.search.num.innerHTML = searchindex_edit+1;
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gestion automatique au chargement de la page si ID_CLUSTER dans url "/users/edit/:id_cluster:"
|
||||||
|
if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ){
|
||||||
|
|
||||||
|
// On récupère la user d'uid donné dans l'URL
|
||||||
|
api.send({path:'clusterDefault/getById', id_cluster:pageManager.vars[1]}, function(response){
|
||||||
|
// Si aucune erreur et un résultat
|
||||||
|
if( response.ModuleError == 0 ){
|
||||||
|
found_edit = [ response.cluster ]; // On récupère le résultat
|
||||||
|
searchindex_edit = 0; // On remet le compteur à 0
|
||||||
|
autofill_edit(); // On auto-remplit
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}else
|
}
|
||||||
section.edit.input.search.num.innerHTML = 0;
|
|
||||||
|
|
||||||
}if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ) autofill_edit(pageManager.vars[1]);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* (3) Gestion de la recherche
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/* (2) Gestion de la recherche de la cluster */
|
|
||||||
section.edit.input.search.submit.addEventListener('click', function(e){
|
section.edit.input.search.submit.addEventListener('click', function(e){
|
||||||
// On annule l'envoi de base (PHP)
|
// On annule l'envoi de base (PHP)
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
// Si le champ n'est pas vide, on lance la recherche
|
|
||||||
|
/* (1) Si le champ n'est pas vide */
|
||||||
if( section.edit.input.search.keyword.value != '' ){
|
if( section.edit.input.search.keyword.value != '' ){
|
||||||
// Redaction de la requete
|
|
||||||
var getuid = {
|
/* (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();
|
||||||
|
|
||||||
|
|
||||||
|
/* (3) Nouveaux mots-clés, on lance la recherche */
|
||||||
|
}else{
|
||||||
|
|
||||||
|
/* (4) Redaction de la requete */
|
||||||
|
var getClusters = {
|
||||||
path: 'clusterDefault/search',
|
path: 'clusterDefault/search',
|
||||||
keywords: section.edit.input.search.keyword.value
|
keywords: section.edit.input.search.keyword.value
|
||||||
};
|
};
|
||||||
|
|
||||||
// On envoie la requete
|
/* (5) On envoie la requête */
|
||||||
api.send(getuid, function(uidanswer){
|
api.send(getClusters, function(getClustersResponse){
|
||||||
if( uidanswer.ModuleError == 0 && uidanswer.clusters.length > 0 ){ // si on a trouve qqch
|
if( getClustersResponse.ModuleError == 0 ){ // si pas d'erreur
|
||||||
|
|
||||||
|
// On notifie que la recherche est terminée
|
||||||
section.edit.input.search.submit.anim('active', 1000);
|
section.edit.input.search.submit.anim('active', 1000);
|
||||||
|
|
||||||
// Si on trouve la meme cluster que lors de la derniere recherche
|
/* (6) On met à jour les données des users, et le compteur */
|
||||||
if( lastsearch_edit == uidanswer.clusters[searchindex_edit].id_cluster )
|
|
||||||
searchindex_edit = (searchindex_edit+1) % uidanswer.clusters.length; // on affiche le prochain (decalage cyclique)
|
|
||||||
else // si nouveau resultat, on remet l'indice a 0
|
|
||||||
searchindex_edit = 0;
|
searchindex_edit = 0;
|
||||||
|
found_edit = getClustersResponse.clusters;
|
||||||
|
section.edit.input.search.sum.innerHTML = found_edit.length;
|
||||||
|
|
||||||
lastsearch_edit = uidanswer.clusters[searchindex_edit].id_cluster;
|
// On met à jour l'auto-remplissage
|
||||||
section.edit.input.search.id.value = lastsearch_edit;
|
autofill_edit();
|
||||||
|
|
||||||
// Mise a jour des indices des resultats
|
|
||||||
section.edit.input.search.sum.innerHTML = uidanswer.clusters.length;
|
|
||||||
|
|
||||||
// on auto-remplit le formulaire
|
|
||||||
autofill_edit(lastsearch_edit);
|
|
||||||
|
|
||||||
}else{
|
|
||||||
section.edit.input.search.sum.innerHTML = 0;
|
|
||||||
autofill_edit(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// On met à jour la dernière recherche
|
||||||
|
lastkeywords_edit = getClusters.keywords;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}, false);
|
}, false);
|
||||||
|
|
Loading…
Reference in New Issue