SMMP/view/js/users-min.js

21 lines
8.7 KiB
JavaScript

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){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.searchbar.addEventListener("keyup",function(b){api.send({path:"userDefault/search",data:[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)}
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",data:[section.create.input.code.value,
section.create.input.username.value,section.create.input.firstname.value,section.create.input.lastname.value,section.create.input.mail.value,section.create.input.password.value,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",data:[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",data:[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",data:[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",data:[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",data:[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&&api.send({path:"userDefault/edit",data:[section.edit.input.search.id.value,section.edit.input.code.value,section.edit.input.username.value,section.edit.input.firstname.value,section.edit.input.lastname.value,section.edit.input.mail.value,section.edit.input.password.value,section.edit.input.status.value]},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)};