19 lines
7.3 KiB
JavaScript
19 lines
7.3 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-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(b){api.send({path:"machineDefault/search",keywords:section.view.searchbar.value},
|
|
function(a){if(0==a.ModuleError){for(var b=[],c=0;c<a.machines.length;c++)b.push(a.machines[c].id_machine);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("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(b){pageManager.vars[1]=b.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(b){var a={path:"machineDefault/unlink",id_machine:b.target.getData("machine"),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.create.element){section.create.input={name:document.querySelector(section.create.text+"#create_name"),submit:document.querySelector(section.create.text+"#create_submit")};var createChecker=new inputChecker;section.create.input.submit.addEventListener("click",function(b){b.preventDefault();api.send({path:"machineDefault/create",name:section.create.input.name.value},function(a){0==a.ModuleError?(console.log("Machine 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_machine:"",name:"",disable_input:!0};api.send({path:"machineDefault/getById",id_machine:b},function(b){0==b.ModuleError&&(a=b.machine,a.diable_input=!1);section.remove.input.search.id.value=a.id_machine;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+".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:"machineDefault/search",keywords:section.remove.input.search.keyword.value},function(a){0==a.ModuleError&&0<a.machines.length?(section.remove.input.search.submit.anim("active",1E3),lastsearch_remove==a.machines[searchindex_remove].id_machine&&
|
|
(searchindex_remove=(searchindex_remove+1)%a.machines.length),lastsearch_remove=a.machines[searchindex_remove].id_machine,section.remove.input.search.id.value=lastsearch_remove,section.remove.input.search.sum.innerHTML=a.machines.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:"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(b){var a={id_machine:"",name:"",disable_input:!0};isNaN(b)?section.edit.input.search.num.innerHTML=0:api.send({path:"machineDefault/getById",id_machine:b},function(b){0==b.ModuleError&&(a=b.machine,a.disable_input=!1);section.edit.input.search.id.value=a.id_machine;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+
|
|
".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=
|
|
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:"machineDefault/search",keywords:section.edit.input.search.keyword.value},function(a){0==a.ModuleError&&0<a.machines.length?(section.edit.input.search.submit.anim("active",1E3),searchindex_edit=lastsearch_edit==a.machines[searchindex_edit].id_machine?
|
|
(searchindex_edit+1)%a.machines.length:0,lastsearch_edit=a.machines[searchindex_edit].id_machine,section.edit.input.search.id.value=lastsearch_edit,section.edit.input.search.sum.innerHTML=a.machines.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:"machineDefault/edit",id_machine:section.edit.input.search.id.value,
|
|
name:section.edit.input.name.value},function(a){0==a.ModuleError&&1==a.status?(console.log("Machine modifiee!"),section.edit.input.submit.anim("active",1500),autofill_edit(section.edit.input.search.id.value)):console.error("ModuleError::"+a.ModuleError)})},!1)};
|