Correction JS de la recherche interne aux formulaires pour la vue 'users'
This commit is contained in:
parent
3b370fa3d9
commit
3b8f5d9f72
|
@ -1,17 +1,17 @@
|
|||
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"]')}};
|
||||
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-machine]"),remove:document.querySelectorAll(section.view.text+".link_remove[data-machine]")};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]")};section.view.searchbar.addEventListener("keyup",function(a){api.send({path:"machineDefault/search",keywords:section.view.searchbar.value},function(a){if(0==a.ModuleError){for(var d=[],c=0;c<a.machines.length;c++)d.push(a.machines[c].id_machine);a=document.querySelectorAll(section.view.text+"> article.inline-box[id]");for(c=0;c<a.length;c++)-1<d.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-machine]")};section.view.searchbar.addEventListener("keyup",function(a){api.send({path:"machineDefault/search",keywords:section.view.searchbar.value},function(b){if(0==b.ModuleError){for(var a=[],c=0;c<b.machines.length;c++)a.push(b.machines[c].id_machine);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(a){pageManager.vars[1]=a.target.getData("machine");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("machine");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:"machineDefault/unlink",id_machine:a.target.getData("machine"),
|
||||
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"),submit:document.querySelector(section.create.text+"#create_submit")},section.create.input.submit.addEventListener("click",function(a){a.preventDefault();api.send({path:"machineDefault/create",name:section.create.input.name.value},function(a){0==a.ModuleError&&(console.log("Machine cree!"),pageManager.vars=["view",a.id_machine],pageManager.refresh(),document.location="",section.create.input.submit.anim("active",
|
||||
null!=section.create.element&&(section.create.input={name:document.querySelector(section.create.text+"#create_name"),submit:document.querySelector(section.create.text+"#create_submit")},section.create.input.submit.addEventListener("click",function(a){a.preventDefault();api.send({path:"machineDefault/create",name:section.create.input.name.value},function(b){0==b.ModuleError&&(console.log("Machine cree!"),pageManager.vars=["view",b.id_machine],pageManager.refresh(),document.location="",section.create.input.submit.anim("active",
|
||||
1500))})},!1));
|
||||
if(null!=section.remove.element){var autofill_remove=function(a){var b=a="",d=!0;null==found_remove[searchindex_remove]?searchindex_remove=section.remove.input.search.num.innerHTML=0:(a=found_remove[searchindex_remove].id_machine,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"),
|
||||
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_machine,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")};var lastkeywords_remove=
|
||||
"",found_remove=[],searchindex_remove=0;2<=pageManager.vars.length&&!isNaN(pageManager.vars[1])&&api.send({path:"machineDefault/getById",id_machine:pageManager.vars[1]},function(a){0==a.ModuleError&&(found_remove=[a.machine],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+
|
||||
1)%found_remove.length,autofill_remove();else{var b={path:"machineDefault/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.machines,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();""!=section.remove.input.search.id.value&&
|
||||
api.send({path:"machineDefault/delete",id_machine:section.remove.input.search.id.value},function(a){0==a.ModuleError&&1==a.status?(console.log("Machine 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(a){var b=a="",d=!0;null==found_edit[searchindex_edit]?searchindex_edit=section.edit.input.search.num.innerHTML=0:(a=found_edit[searchindex_edit].id_machine,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"),
|
||||
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_machine,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"),
|
||||
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=[],
|
||||
searchindex_edit=0;2<=pageManager.vars.length&&!isNaN(pageManager.vars[1])&&api.send({path:"machineDefault/getById",id_machine:pageManager.vars[1]},function(a){0==a.ModuleError&&(found_edit=[a.machine],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();
|
||||
else{var b={path:"machineDefault/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.machines,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:"machineDefault/edit",id_machine:section.edit.input.search.id.value,
|
||||
|
|
|
@ -230,7 +230,7 @@ if( section.remove.element != null ){
|
|||
|
||||
/* (2) Gestion de l'auto-remplissage par lien
|
||||
---------------------------------------------------------*/
|
||||
function autofill_remove(specific){
|
||||
function autofill_remove(){
|
||||
/* (0) Valeurs par défaut */
|
||||
var machine_data = {
|
||||
id_machine: '',
|
||||
|
@ -421,7 +421,7 @@ if( section.edit.element != null ){
|
|||
|
||||
/* (2) Gestion de l'auto-remplissage par lien
|
||||
---------------------------------------------------------*/
|
||||
function autofill_edit(specific){
|
||||
function autofill_edit(){
|
||||
/* (0) Valeurs par défaut */
|
||||
var machine_data = {
|
||||
id_machine: '',
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
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"]')}};
|
||||
if(null!=section.view.element){1<pageManager.vars.length&&!isNaN(pageManager.vars[1])&&(document.location="#"+pageManager.vars[1]);section.view.link={edit:document.querySelectorAll(section.view.text+".link_edit[data-user]"),remove:document.querySelectorAll(section.view.text+".link_remove[data-user]")};section.view.group={rem:document.querySelectorAll(section.view.text+".rem-group[data-user][data-group]"),add:document.querySelectorAll(section.view.text+".add-group[data-user]")};section.view.searchbar.addEventListener("keyup",
|
||||
function(b){api.send({path:"userDefault/search",keywords:section.view.searchbar.value},function(a){if(0==a.ModuleError&&(console.log(a.users.length),0==a.ModuleError)){for(var b=[],c=0;c<a.users.length;c++)b.push(a.users[c].id_user);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",
|
||||
function(b){pageManager.vars[1]=b.target.getData("user");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("user");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:"userDefault/unlink",id_user:b.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)}
|
||||
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-user]"),remove:document.querySelectorAll(section.view.text+".link_remove[data-user]")};section.view.group={rem:document.querySelectorAll(section.view.text+".rem-group[data-user][data-group]"),add:document.querySelectorAll(section.view.text+
|
||||
".add-group[data-user]")};section.view.searchbar.addEventListener("keyup",function(a){api.send({path:"userDefault/search",keywords:section.view.searchbar.value},function(a){if(0==a.ModuleError&&(console.log(a.users.length),0==a.ModuleError)){for(var d=[],c=0;c<a.users.length;c++)d.push(a.users[c].id_user);a=document.querySelectorAll(section.view.text+"> article.inline-box[id]");for(c=0;c<a.length;c++)-1<d.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",
|
||||
function(a){pageManager.vars[1]=a.target.getData("user");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("user");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:"userDefault/unlink",id_user:a.target.getData("user"),
|
||||
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)}
|
||||
if(null!=section.create.element){section.create.input={code:document.querySelector(section.create.text+"#create_code"),username:document.querySelector(section.create.text+"#create_username"),firstname:document.querySelector(section.create.text+"#create_firstname"),lastname:document.querySelector(section.create.text+"#create_lastname"),mail:document.querySelector(section.create.text+"#create_mail"),password:document.querySelector(section.create.text+"#create_password"),status:document.querySelector(section.create.text+
|
||||
"#create_status"),submit:document.querySelector(section.create.text+"#create_submit")};var createChecker=new inputChecker;createChecker.append(section.create.input.code,format_code,"01-AB-CD-23");section.create.input.code.addEventListener("keyup",function(b){b.target.value=b.target.value.toUpperCase();createChecker.check(b.target)||createChecker.correct(b.target,!1)},!1);section.create.input.submit.addEventListener("click",function(b){b.preventDefault();api.send({path:"userDefault/create",code:section.create.input.code.value,
|
||||
"#create_status"),submit:document.querySelector(section.create.text+"#create_submit")};var createChecker=new inputChecker;createChecker.append(section.create.input.code,format_code,"01-AB-CD-23");section.create.input.code.addEventListener("keyup",function(a){a.target.value=a.target.value.toUpperCase();createChecker.check(a.target)||createChecker.correct(a.target,!1)},!1);section.create.input.submit.addEventListener("click",function(a){a.preventDefault();api.send({path:"userDefault/create",code:section.create.input.code.value,
|
||||
username:section.create.input.username.value,firstname:section.create.input.firstname.value,lastname:section.create.input.lastname.value,mail:section.create.input.mail.value,password:section.create.input.password.value,status:section.create.input.status.value},function(a){0==a.ModuleError?(console.log("Utilisateur cree!"),section.create.input.submit.anim("active",1500)):console.error("ModuleError::"+a.ModuleError)})},!1)}
|
||||
if(null!=section.remove.element){var autofill_remove=function(b){var a={id_user:"",code:"",username:"",firstname:"",lastname:"",mail:"",status:"",disable_input:!0};api.send({path:"userDefault/getById",id_user:b},function(b){0==b.ModuleError&&(a=b.user,a.disable_input=!1);section.remove.input.search.id.value=a.id_user;section.remove.input.code.value=a.code;section.remove.input.username.value=a.username;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+".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")},code:document.querySelector(section.remove.text+
|
||||
"#remove_code"),username:document.querySelector(section.remove.text+"#remove_username"),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:"userDefault/search",keywords:section.remove.input.search.keyword.value},
|
||||
function(a){0==a.ModuleError&&0<a.users.length?(section.remove.input.search.submit.anim("active",1E3),searchindex_remove=lastsearch_remove==a.users[searchindex_remove].id_user?(searchindex_remove+1)%a.users.length:0,lastsearch_remove=a.users[searchindex_remove].id_user,section.remove.input.search.id.value=lastsearch_remove,section.remove.input.search.sum.innerHTML=a.users.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:"userDefault/delete",id_user:section.remove.input.search.id.value},function(a){0==a.ModuleError&&1==a.status?(console.log("Utilisateur supprime!"),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_user:"",code:"",username:"",firstname:"",lastname:"",mail:"",status:"",disable_input:!0};isNaN(b)?section.edit.input.search.num.innerHTML=0:api.send({path:"userDefault/getById",id_user:b},function(b){0==b.ModuleError&&(a=b.user,a.disable_input=!1);section.edit.input.search.id.value=a.id_user;section.edit.input.code.value=a.code;section.edit.input.username.value=a.username;section.edit.input.firstname.value=a.firstname;section.edit.input.lastname.value=
|
||||
a.lastname;section.edit.input.mail.value=a.mail;section.edit.input.password.value="";section.edit.input.status.value=a.status;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+".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")},code:document.querySelector(section.edit.text+"#edit_code"),username:document.querySelector(section.edit.text+"#edit_username"),firstname:document.querySelector(section.edit.text+"#edit_firstname"),lastname:document.querySelector(section.edit.text+"#edit_lastname"),mail:document.querySelector(section.edit.text+"#edit_mail"),password:document.querySelector(section.edit.text+
|
||||
"#edit_password"),status:document.querySelector(section.edit.text+"#edit_status"),submit:document.querySelector(section.edit.text+"#edit_submit")};var lastsearch_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:"userDefault/search",keywords:section.edit.input.search.keyword.value},
|
||||
function(a){0==a.ModuleError&&0<a.users.length?(section.edit.input.search.submit.anim("active",1E3),searchindex_edit=lastsearch_edit==a.users[searchindex_edit].id_user?(searchindex_edit+1)%a.users.length:0,lastsearch_edit=a.users[searchindex_edit].id_user,section.edit.input.search.id.value=lastsearch_edit,section.edit.input.search.sum.innerHTML=a.users.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&&(b={path:"userDefault/edit",id_user:parseInt(section.edit.input.search.id.value),code:section.edit.input.code.value,username:section.edit.input.username.value,firstname:section.edit.input.firstname.value,lastname:section.edit.input.lastname.value,mail:section.edit.input.mail.value,password:section.edit.input.password.value,status:section.edit.input.status.value},api.send(b,function(a){console.log(a);0==a.ModuleError&&1==a.status?
|
||||
(console.log("Utilisateur modifie!"),section.edit.input.submit.anim("active",1500),autofill_edit(section.edit.input.search.id.value)):console.error("ModuleError::"+a.ModuleError)}))},!1)};
|
||||
if(null!=section.remove.element){var autofill_remove=function(){var a="",b="",d="",c=!0;null==found_remove[searchindex_remove]?searchindex_remove=section.remove.input.search.num.innerHTML=0:(a=found_remove[searchindex_remove].id_user,b=found_remove[searchindex_remove].username,d=found_remove[searchindex_remove].code,c=!1,section.remove.input.search.num.innerHTML=searchindex_remove+1);section.remove.input.search.id.value=a;section.remove.input.username.value=b;section.remove.input.code.value=d;section.remove.input.submit.disabled=
|
||||
c};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")},code:document.querySelector(section.remove.text+
|
||||
"#remove_code"),username:document.querySelector(section.remove.text+"#remove_username"),submit:document.querySelector(section.remove.text+"#remove_submit")};var lastkeywords_remove="",found_remove=[],searchindex_remove=0;2<=pageManager.vars.length&&!isNaN(pageManager.vars[1])&&api.send({path:"userDefault/getById",id_user:pageManager.vars[1]},function(a){0==a.ModuleError&&(found_remove=[a.user],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+1)%found_remove.length,autofill_remove();else{var b={path:"userDefault/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.users,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();""!=section.remove.input.search.id.value&&api.send({path:"userDefault/delete",id_user:section.remove.input.search.id.value},function(a){0==a.ModuleError&&1==a.status?(console.log("Utilisateur supprime!"),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(){var a="",b="",d="",c="",e="",f="",g=!0;null==found_edit[searchindex_edit]?searchindex_edit=section.edit.input.search.num.innerHTML=0:(a=found_edit[searchindex_edit].id_user,b=found_edit[searchindex_edit].code,d=found_edit[searchindex_edit].username,c=found_edit[searchindex_edit].firstname,e=found_edit[searchindex_edit].lastname,f=found_edit[searchindex_edit].mail,g=!1,section.edit.input.search.num.innerHTML=searchindex_edit+1);section.edit.input.search.id.value=
|
||||
a;section.edit.input.code.value=b;section.edit.input.username.value=d;section.edit.input.firstname.value=c;section.edit.input.lastname.value=e;section.edit.input.mail.value=f;section.edit.input.submit.disabled=g};section.edit.input={search:{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"),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")},code:document.querySelector(section.edit.text+"#edit_code"),username:document.querySelector(section.edit.text+"#edit_username"),firstname:document.querySelector(section.edit.text+"#edit_firstname"),lastname:document.querySelector(section.edit.text+"#edit_lastname"),mail:document.querySelector(section.edit.text+"#edit_mail"),password:document.querySelector(section.edit.text+
|
||||
"#edit_password"),submit:document.querySelector(section.edit.text+"#edit_submit")};var lastkeywords_edit="",found_edit=[],searchindex_edit=0;2<=pageManager.vars.length&&!isNaN(pageManager.vars[1])&&api.send({path:"userDefault/getById",id_user:pageManager.vars[1]},function(a){0==a.ModuleError&&(found_edit=[a.user],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();else{var b={path:"userDefault/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.users,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&&(a={path:"userDefault/edit",id_user:parseInt(section.edit.input.search.id.value),code:section.edit.input.code.value,username:section.edit.input.username.value,firstname:section.edit.input.firstname.value,lastname:section.edit.input.lastname.value,mail:section.edit.input.mail.value,password:section.edit.input.password.value,status:section.edit.input.status.value},api.send(a,function(a){console.log(a);0==a.ModuleError&&1==a.status?(console.log("Utilisateur modifie!"),
|
||||
section.edit.input.submit.anim("active",1500),autofill_edit(section.edit.input.search.id.value)):console.error("ModuleError::"+a.ModuleError)}))},!1)};
|
||||
|
|
259
view/js/users.js
259
view/js/users.js
|
@ -36,7 +36,6 @@ if( section.view.element != null ){
|
|||
document.location = '#'+pageManager.vars[1];
|
||||
document.getElementById(pageManager.vars[1]).addClass('selected');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -247,87 +246,131 @@ if( section.remove.element != null ){
|
|||
submit: document.querySelector(section.remove.text + '#remove_submit')
|
||||
};
|
||||
|
||||
var lastsearch_remove = null;
|
||||
var lastkeywords_remove = '';
|
||||
var found_remove = [];
|
||||
var searchindex_remove = 0;
|
||||
|
||||
|
||||
/* (2) Gestion de l'auto-remplissage par url */
|
||||
function autofill_remove(id_user){
|
||||
// On recupere le code + username de l'utilisateur selectionne
|
||||
|
||||
/* (2) Gestion de l'auto-remplissage par lien
|
||||
---------------------------------------------------------*/
|
||||
function autofill_remove(){
|
||||
/* (0) Valeurs par défaut */
|
||||
var user_data = {
|
||||
id_user: '',
|
||||
code: '',
|
||||
username: '',
|
||||
firstname: '',
|
||||
lastname: '',
|
||||
mail: '',
|
||||
status: '',
|
||||
code: '',
|
||||
disable_input: true
|
||||
};
|
||||
|
||||
api.send({path:'userDefault/getById', id_user: id_user}, function(answer){
|
||||
if( answer.ModuleError == 0 ){ // Si un resultat
|
||||
user_data = answer.user;
|
||||
user_data.disable_input = false;
|
||||
|
||||
// {1} Si aucun résultat //
|
||||
if( found_remove[searchindex_remove] == null ){
|
||||
|
||||
|
||||
// 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
|
||||
user_data = {
|
||||
id_user: found_remove[searchindex_remove]['id_user'],
|
||||
username: found_remove[searchindex_remove]['username'],
|
||||
code: found_remove[searchindex_remove]['code'],
|
||||
disable_input: false
|
||||
};
|
||||
|
||||
// Mise a jour des indices des resultats
|
||||
section.remove.input.search.num.innerHTML = searchindex_remove+1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// On enregistre l'UID de l'utilisateur
|
||||
// {3} On auto-remplit le formulaire //
|
||||
// On enregistre l'UID de la user
|
||||
section.remove.input.search.id.value = user_data.id_user;
|
||||
|
||||
// Auto-remplissage du formulaire
|
||||
section.remove.input.code.value = user_data.code;
|
||||
section.remove.input.username.value = user_data.username;
|
||||
section.remove.input.code.value = user_data.code;
|
||||
|
||||
// On affiche le bouton de suppression
|
||||
// On gere le caractere "inactif" du submit
|
||||
section.remove.input.submit.disabled = user_data.disable_input;
|
||||
|
||||
// Muse a jour des indices des resultats
|
||||
section.remove.input.search.num.innerHTML = searchindex_remove+1;
|
||||
|
||||
}
|
||||
|
||||
// Gestion automatique au chargement de la page si ID_MACHINE dans url "/users/remove/:id_user:"
|
||||
if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ){
|
||||
|
||||
// On récupère la user d'uid donné dans l'URL
|
||||
api.send({path:'userDefault/getById', id_user:pageManager.vars[1]}, function(response){
|
||||
// Si aucune erreur et un résultat
|
||||
if( response.ModuleError == 0 ){
|
||||
found_remove = [ response.user ]; // 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){
|
||||
// On annule l'envoi de base (PHP)
|
||||
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 != '' ){
|
||||
// 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 getUsers = {
|
||||
path: 'userDefault/search',
|
||||
keywords: section.remove.input.search.keyword.value
|
||||
};
|
||||
|
||||
// On envoie la requete
|
||||
api.send(getuid, function(uidanswer){
|
||||
if( uidanswer.ModuleError == 0 && uidanswer.users.length > 0){ // si on a trouve qqch
|
||||
/* (5) On envoie la requête */
|
||||
api.send(getUsers, function(getUsersResponse){
|
||||
if( getUsersResponse.ModuleError == 0 ){ // si pas d'erreur
|
||||
|
||||
// On notifie que la recherche est terminée
|
||||
section.remove.input.search.submit.anim('active', 1000);
|
||||
|
||||
// Si on trouve la meme machine que lors de la derniere recherche
|
||||
if( lastsearch_remove == uidanswer.users[searchindex_remove].id_user )
|
||||
searchindex_remove = (searchindex_remove+1) % uidanswer.users.length; // on affiche le prochain (decalage cyclique)
|
||||
else // si nouveau resultat, on remet l'indice a 0
|
||||
/* (6) On met à jour les données des users, et le compteur */
|
||||
searchindex_remove = 0;
|
||||
found_remove = getUsersResponse.users;
|
||||
section.remove.input.search.sum.innerHTML = found_remove.length;
|
||||
|
||||
lastsearch_remove = uidanswer.users[searchindex_remove].id_user;
|
||||
section.remove.input.search.id.value = lastsearch_remove;
|
||||
|
||||
// Mise a jour des indices des resultats
|
||||
section.remove.input.search.sum.innerHTML = uidanswer.users.length;
|
||||
|
||||
// on auto-remplit le formulaire
|
||||
autofill_remove(lastsearch_remove);
|
||||
|
||||
}else{
|
||||
section.remove.input.search.sum.innerHTML = 0;
|
||||
autofill_remove(null);
|
||||
// On met à jour l'auto-remplissage
|
||||
autofill_remove();
|
||||
}
|
||||
|
||||
// On met à jour la dernière recherche
|
||||
lastkeywords_remove = getUsers.keywords;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}, false);
|
||||
|
@ -399,17 +442,20 @@ if( section.edit.element != null ){
|
|||
lastname: document.querySelector(section.edit.text + '#edit_lastname'),
|
||||
mail: document.querySelector(section.edit.text + '#edit_mail'),
|
||||
password: document.querySelector(section.edit.text + '#edit_password'),
|
||||
status: document.querySelector(section.edit.text + '#edit_status'),
|
||||
|
||||
submit: document.querySelector(section.edit.text + '#edit_submit')
|
||||
};
|
||||
|
||||
var lastsearch_edit = null;
|
||||
var lastkeywords_edit = '';
|
||||
var found_edit = [];
|
||||
var searchindex_edit = 0;
|
||||
|
||||
/* (1) Gestion de l'auto-remplissage par url */
|
||||
function autofill_edit(id_user){
|
||||
// On definit les valeurs par defaut
|
||||
|
||||
|
||||
/* (2) Gestion de l'auto-remplissage par lien
|
||||
---------------------------------------------------------*/
|
||||
function autofill_edit(){
|
||||
/* (0) Valeurs par défaut */
|
||||
var user_data = {
|
||||
id_user: '',
|
||||
code: '',
|
||||
|
@ -417,23 +463,41 @@ if( section.edit.element != null ){
|
|||
firstname: '',
|
||||
lastname: '',
|
||||
mail: '',
|
||||
status: '',
|
||||
disable_input: true
|
||||
};
|
||||
|
||||
|
||||
// Si @id_user est un entier
|
||||
if( !isNaN(id_user) ){
|
||||
// {1} Si aucun résultat //
|
||||
if( found_edit[searchindex_edit] == null ){
|
||||
|
||||
|
||||
// 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
|
||||
user_data = {
|
||||
id_user: found_edit[searchindex_edit]['id_user'],
|
||||
code: found_edit[searchindex_edit]['code'],
|
||||
username: found_edit[searchindex_edit]['username'],
|
||||
firstname: found_edit[searchindex_edit]['firstname'],
|
||||
lastname: found_edit[searchindex_edit]['lastname'],
|
||||
mail: found_edit[searchindex_edit]['mail'],
|
||||
disable_input: false
|
||||
};
|
||||
|
||||
// Mise a jour des indices des resultats
|
||||
section.edit.input.search.num.innerHTML = searchindex_edit+1;
|
||||
|
||||
// On recupere le code + username de l'utilisateur selectionne
|
||||
api.send({path:'userDefault/getById', id_user: id_user}, function(answer){
|
||||
if( answer.ModuleError == 0 ){ // Si aucune erreur
|
||||
user_data = answer.user;
|
||||
user_data.disable_input = false;
|
||||
}
|
||||
|
||||
|
||||
// On enregistre l'UID de l'utilisateur
|
||||
// {3} On auto-remplit le formulaire //
|
||||
// On enregistre l'UID de la user
|
||||
section.edit.input.search.id.value = user_data.id_user;
|
||||
|
||||
// Auto-remplissage du formulaire
|
||||
|
@ -442,61 +506,80 @@ if( section.edit.element != null ){
|
|||
section.edit.input.firstname.value = user_data.firstname;
|
||||
section.edit.input.lastname.value = user_data.lastname;
|
||||
section.edit.input.mail.value = user_data.mail;
|
||||
section.edit.input.password.value = '';
|
||||
section.edit.input.status.value = user_data.status;
|
||||
|
||||
// On active ou pas le bouton "Modifier"
|
||||
// On gere le caractere "inactif" du submit
|
||||
section.edit.input.submit.disabled = user_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_MACHINE dans url "/users/edit/:id_user:"
|
||||
if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ){
|
||||
|
||||
// On récupère la user d'uid donné dans l'URL
|
||||
api.send({path:'userDefault/getById', id_user:pageManager.vars[1]}, function(response){
|
||||
// Si aucune erreur et un résultat
|
||||
if( response.ModuleError == 0 ){
|
||||
found_edit = [ response.user ]; // 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]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (2) Gestion de la recherche de l'utilisateur */
|
||||
/* (3) Gestion de la recherche
|
||||
---------------------------------------------------------*/
|
||||
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
|
||||
|
||||
/* (1) Si le champ n'est pas vide */
|
||||
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 getUsers = {
|
||||
path: 'userDefault/search',
|
||||
keywords: section.edit.input.search.keyword.value
|
||||
};
|
||||
|
||||
// On envoie la requete
|
||||
api.send(getuid, function(uidanswer){
|
||||
if( uidanswer.ModuleError == 0 && uidanswer.users.length > 0 ){ // si on a trouve qqch
|
||||
/* (5) On envoie la requête */
|
||||
api.send(getUsers, function(getUsersResponse){
|
||||
if( getUsersResponse.ModuleError == 0 ){ // si pas d'erreur
|
||||
|
||||
// On notifie que la recherche est terminée
|
||||
section.edit.input.search.submit.anim('active', 1000);
|
||||
|
||||
// Si on trouve le meme utilisateur que lors de la derniere recherche
|
||||
if( lastsearch_edit == uidanswer.users[searchindex_edit].id_user )
|
||||
searchindex_edit = (searchindex_edit+1) % uidanswer.users.length; // on affiche le prochain (decalage cyclique)
|
||||
else // si nouveau resultat, on remet l'indice a 0
|
||||
/* (6) On met à jour les données des users, et le compteur */
|
||||
searchindex_edit = 0;
|
||||
found_edit = getUsersResponse.users;
|
||||
section.edit.input.search.sum.innerHTML = found_edit.length;
|
||||
|
||||
lastsearch_edit = uidanswer.users[searchindex_edit].id_user;
|
||||
section.edit.input.search.id.value = lastsearch_edit;
|
||||
|
||||
// Mise a jour des indices des resultats
|
||||
section.edit.input.search.sum.innerHTML = uidanswer.users.length;
|
||||
|
||||
// on auto-remplit le formulaire
|
||||
autofill_edit(lastsearch_edit);
|
||||
|
||||
}else{
|
||||
section.edit.input.search.sum.innerHTML = 0;
|
||||
autofill_edit(null);
|
||||
// On met à jour l'auto-remplissage
|
||||
autofill_edit();
|
||||
}
|
||||
|
||||
// On met à jour la dernière recherche
|
||||
lastkeywords_edit = getUsers.keywords;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}, false);
|
||||
|
|
|
@ -80,7 +80,6 @@
|
|||
echo "<input id='create_lastname' type='text' placeholder='Lastname'><br>";
|
||||
echo "<input id='create_mail' type='text' placeholder='Mail'><br>";
|
||||
echo "<input id='create_password' type='password' placeholder='Password'><br>";
|
||||
echo "<input id='create_status' type='text' placeholder='Status'><br>";
|
||||
echo "<button id='create_submit'>Créer</button>";
|
||||
echo "</form>";
|
||||
|
||||
|
@ -150,7 +149,6 @@
|
|||
echo "<input id='edit_lastname' type='text' placeholder='Lastname'><br>";
|
||||
echo "<input id='edit_mail' type='text' placeholder='Mail'><br>";
|
||||
echo "<input id='edit_password' type='password' placeholder='Password'><br>";
|
||||
echo "<input id='edit_status' type='text' placeholder='Status'><br>";
|
||||
echo "<button id='edit_submit' disabled>Modifier</button>";
|
||||
echo "</form>";
|
||||
|
||||
|
|
Loading…
Reference in New Issue