Correction JS de la recherche interne aux formulaires pour la vue 'machines'
This commit is contained in:
parent
9358444d97
commit
3b370fa3d9
|
@ -44,6 +44,8 @@
|
||||||
"getPersonal",
|
"getPersonal",
|
||||||
"getMembers",
|
"getMembers",
|
||||||
|
|
||||||
|
"search",
|
||||||
|
|
||||||
"link",
|
"link",
|
||||||
"unlink"
|
"unlink"
|
||||||
|
|
||||||
|
|
|
@ -582,9 +582,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* [4] Tableau à cocher
|
/* [4] Tableau à cocher
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
& article.check-table{
|
article.check-table{
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
||||||
|
@ -610,7 +614,15 @@
|
||||||
|
|
||||||
background: #f5f5f5;
|
background: #f5f5f5;
|
||||||
border-bottom: 1px solid #eee;
|
border-bottom: 1px solid #eee;
|
||||||
&:nth-child(2n){ background: #fdfdfd; }
|
|
||||||
|
transition: background .2s ease-in-out;
|
||||||
|
|
||||||
|
&:hover{ background: #f1f1f1; }
|
||||||
|
|
||||||
|
&:nth-child(2n){
|
||||||
|
background: #fdfdfd;
|
||||||
|
&:hover{ background: #fff; }
|
||||||
|
}
|
||||||
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
|
@ -658,6 +670,3 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -116,12 +116,12 @@
|
||||||
extract($params);
|
extract($params);
|
||||||
|
|
||||||
// On recupere les donnees
|
// On recupere les donnees
|
||||||
$user = new Repo('user/search', [
|
$cluster = new Repo('cluster/search', [
|
||||||
$_SESSION['WAREHOUSE']['id'],
|
$_SESSION['WAREHOUSE']['id'],
|
||||||
$keywords
|
$keywords
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return [ 'users' => $user->answer() ];
|
return [ 'clusters' => $cluster->answer() ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,20 +144,20 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* RENVOIE L'UTILISATEURS D'UID DONNE
|
/* RENVOIE UN GROUPE D'UID DONNE
|
||||||
*
|
*
|
||||||
* @id_user<int> UID de l'utilisateur en question
|
* @id_cluster<int> UID du groupe en question
|
||||||
*
|
*
|
||||||
* @return utilisateur<Array> Utilisateur d'UID donne
|
* @return cluster<Array> Groupe d'UID donne
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static function getById($params){
|
public static function getById($params){
|
||||||
extract($params);
|
extract($params);
|
||||||
|
|
||||||
// On recupere les donnees
|
// On recupere les donnees
|
||||||
$request = new Repo('user/getById', [
|
$request = new Repo('cluster/getById', [
|
||||||
$_SESSION['WAREHOUSE']['id'],
|
$_SESSION['WAREHOUSE']['id'],
|
||||||
$id_user
|
$id_cluster
|
||||||
]);
|
]);
|
||||||
$answer = $request->answer();
|
$answer = $request->answer();
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@
|
||||||
return [ 'ModuleError' => ManagerError::NoMatchFound ];
|
return [ 'ModuleError' => ManagerError::NoMatchFound ];
|
||||||
|
|
||||||
|
|
||||||
return [ 'user' => $answer ];
|
return [ 'cluster' => $answer ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -455,6 +455,32 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* RENVOIE UNE LISTE DE GROUPES EN FONCTION D'UN MOT CLE
|
||||||
|
*
|
||||||
|
* @id_warehouse<int> UID de l'entrepot
|
||||||
|
* @keyword<String> Element de recherche
|
||||||
|
*
|
||||||
|
* @return clusters<Array> Retourne les groupes trouves
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function search($id_warehouse, $keyword){
|
||||||
|
// On recupere les donnees
|
||||||
|
$searchclusters = Database::getPDO()->prepare("SELECT * FROM cluster
|
||||||
|
WHERE id_warehouse = :id_warehouse
|
||||||
|
AND name LIKE '%".$keyword."%'
|
||||||
|
AND personal is null");
|
||||||
|
|
||||||
|
$searchclusters->execute([
|
||||||
|
':id_warehouse' => $id_warehouse
|
||||||
|
]);
|
||||||
|
|
||||||
|
return Database::delNumeric( $searchclusters->fetchAll() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,102 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace manager\view\group;
|
||||||
|
use \manager\View;
|
||||||
|
use \manager\ModuleRequest;
|
||||||
|
use \manager\Authentification;
|
||||||
|
use \manager\ManagerError;
|
||||||
|
|
||||||
|
class machineChoice{
|
||||||
|
|
||||||
|
public static function template($type=null){
|
||||||
|
|
||||||
|
switch($type){
|
||||||
|
case 'machinelist': return "
|
||||||
|
<div>
|
||||||
|
<span>@name</span>
|
||||||
|
<span>
|
||||||
|
|
||||||
|
<input type='checkbox' value='@id_machine' data-name='members' id='checkbox_@id_machine' @already_in>
|
||||||
|
<label for='checkbox_@id_machine'></label>
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
";
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
default: return "
|
||||||
|
<article class='check-table'>
|
||||||
|
@machinelist
|
||||||
|
</article>";
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function view($params){
|
||||||
|
// On vérifie les paramètres
|
||||||
|
if( !isset($params['id_cluster']) && !is_number($params['id_cluster']) )
|
||||||
|
return "<span class='error'>Une erreur est survenue, veuilez contacter le webmaster si cette erreur persiste.</span>";
|
||||||
|
|
||||||
|
|
||||||
|
$view = '';
|
||||||
|
|
||||||
|
/* [1] On récupère la liste des machines
|
||||||
|
=========================================================*/
|
||||||
|
$request = new ModuleRequest('machineDefault/getAll'); // On utilise la methode 'getAll' du module 'machineDefault'
|
||||||
|
$answer = $request->dispatch(); // On recupere la reponse
|
||||||
|
|
||||||
|
// si erreur, on affiche l'explicitation
|
||||||
|
if( $answer->error != ManagerError::Success )
|
||||||
|
return "<span class='error'>Une erreur est survenue, veuilez contacter le webmaster si cette erreur persiste.</span>";
|
||||||
|
|
||||||
|
$MACHINELIST = $answer->get('machines');
|
||||||
|
|
||||||
|
/* [2] On récupère la liste des membres
|
||||||
|
=========================================================*/
|
||||||
|
$get_members = new ModuleRequest('clusterDefault/getMembers', [
|
||||||
|
'id_cluster' => $params['id_cluster']
|
||||||
|
]);
|
||||||
|
$members_response = $get_members->dispatch();
|
||||||
|
|
||||||
|
// On récupère la liste des UID uniquement
|
||||||
|
$members_id = [];
|
||||||
|
foreach($members_response->get('members') as $member)
|
||||||
|
$members_id[] = $member['id_member'];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
foreach($MACHINELIST as $m=>$machine)
|
||||||
|
$MACHINELIST[$m]['already_in'] = in_array($machine['id_machine'], $members_id) ? 'checked' : '';
|
||||||
|
|
||||||
|
|
||||||
|
$view_user = View::replaceMultiple(
|
||||||
|
self::template('machinelist'),
|
||||||
|
$MACHINELIST, [
|
||||||
|
'icon_remove' => file_get_contents( __ROOT__.'/src/static/sub-menu-side/remove.svg' ),
|
||||||
|
'icon_edit' => file_get_contents( __ROOT__.'/src/static/sub-menu-side/edit.svg' ),
|
||||||
|
'icon_card' => file_get_contents( __ROOT__.'/src/static/container/card.svg' ),
|
||||||
|
'icon_mail' => file_get_contents( __ROOT__.'/src/static/container/mail.svg' ),
|
||||||
|
'icon_group' => file_get_contents( __ROOT__.'/src/static/container/group.svg' ),
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return View::replaceSingle(self::template(), [ 'machinelist' => $view_user ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
|
@ -101,24 +101,23 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* [3] Suppression d'utilisateur
|
/* [3] Suppression de groupe
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
echo "<section data-sublink='remove'>";
|
echo "<section data-sublink='remove'>";
|
||||||
|
|
||||||
echo "<form class='invalid'>";
|
echo "<form class='invalid'>";
|
||||||
// Recherche d'utilisateur
|
// Recherche de groupe
|
||||||
echo "<input id='remove_search_keyword' type='text' class='search' placeholder='Recherche...'><br>";
|
echo "<input id='remove_search_keyword' type='text' class='search' placeholder='Recherche...'><br>";
|
||||||
echo "<input id='remove_search_id' type='hidden' value=''>";
|
echo "<input id='remove_search_id' type='hidden' value=''>";
|
||||||
// Indice du resultat
|
// Indice du resultat
|
||||||
echo "<span class='remove_search_view'>utilisateur <span class='remove_search_num'>0</span> sur <span class='remove_search_sum'>0</span></span><br><br>";
|
echo "<span class='remove_search_view'>groupe <span class='remove_search_num'>0</span> sur <span class='remove_search_sum'>0</span></span><br><br>";
|
||||||
echo "<button id='remove_search_submit' class='search'>Trouver</button><br>";
|
echo "<button id='remove_search_submit' class='search'>Trouver</button><br>";
|
||||||
|
|
||||||
|
|
||||||
echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>";
|
echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>";
|
||||||
|
|
||||||
// Suppression d'utilisateur
|
// Suppression de groupe
|
||||||
echo "<input id='remove_code' type='text' placeholder='Code'><br>";
|
echo "<input id='remove_name' type='text' placeholder='Nom'><br>";
|
||||||
echo "<input id='remove_username' type='text' placeholder='Username'><br>";
|
|
||||||
echo "<button id='remove_submit' disabled>Supprimer</button>";
|
echo "<button id='remove_submit' disabled>Supprimer</button>";
|
||||||
echo "</form>";
|
echo "</form>";
|
||||||
|
|
||||||
|
@ -135,7 +134,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* [4] Modification d'utilisateur
|
/* [4] Modification de groupe
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
echo "<section data-sublink='edit'>";
|
echo "<section data-sublink='edit'>";
|
||||||
|
|
||||||
|
@ -143,18 +142,12 @@
|
||||||
echo "<input id='edit_search_keyword' type='text' class='search' placeholder='Recherche...'><br>";
|
echo "<input id='edit_search_keyword' type='text' class='search' placeholder='Recherche...'><br>";
|
||||||
echo "<input id='edit_search_id' type='hidden' value=''>";
|
echo "<input id='edit_search_id' type='hidden' value=''>";
|
||||||
// Indice du resultat
|
// Indice du resultat
|
||||||
echo "<span class='edit_search_view'>utilisateur <span class='edit_search_num'>0</span> sur <span class='edit_search_sum'>0</span></span><br><br>";
|
echo "<span class='edit_search_view'>groupe <span class='edit_search_num'>0</span> sur <span class='edit_search_sum'>0</span></span><br><br>";
|
||||||
echo "<button id='edit_search_submit' class='search'>Trouver</button><br>";
|
echo "<button id='edit_search_submit' class='search'>Trouver</button><br>";
|
||||||
|
|
||||||
echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>";
|
echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>";
|
||||||
|
|
||||||
echo "<input id='edit_code' type='text' placeholder='CO-DE-RF-ID'><br>";
|
echo "<input id='edit_name' type='text' placeholder='Nom'><br>";
|
||||||
echo "<input id='edit_username' type='text' placeholder='Username'><br>";
|
|
||||||
echo "<input id='edit_firstname' type='text' placeholder='Firstname'><br>";
|
|
||||||
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 "<button id='edit_submit' disabled>Modifier</button>";
|
||||||
echo "</form>";
|
echo "</form>";
|
||||||
|
|
||||||
|
@ -177,7 +170,7 @@
|
||||||
|
|
||||||
debug();
|
debug();
|
||||||
|
|
||||||
$userForGroup = new View('group.userChoice', [
|
$userForGroup = new View('group.machineChoice', [
|
||||||
'id_cluster' => 201 // groupe "b" de type MACHINE
|
'id_cluster' => 201 // groupe "b" de type MACHINE
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +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"]')},
|
||||||
|
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+
|
||||||
|
".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",
|
||||||
|
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"),
|
||||||
|
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)}
|
||||||
|
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!"),
|
||||||
|
pageManager.vars=["view",a.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+
|
||||||
|
".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&&
|
||||||
|
(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",
|
||||||
|
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+
|
||||||
|
".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:"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+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,
|
||||||
|
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)};
|
|
@ -0,0 +1,488 @@
|
||||||
|
// On referencie toutes les sections
|
||||||
|
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"]')
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* GESTION DE L'AFFICHAGE DES GROUPES
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if( section.view.element != null ){
|
||||||
|
|
||||||
|
/* (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');
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (1) On recupere tous les liens */
|
||||||
|
section.view.link = {
|
||||||
|
edit: document.querySelectorAll(section.view.text + '.link_edit[data-cluster]'),
|
||||||
|
remove: document.querySelectorAll(section.view.text + '.link_remove[data-cluster]')
|
||||||
|
};
|
||||||
|
|
||||||
|
/* (2) On récupère toutes les actions de groupes */
|
||||||
|
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]')
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* (3) Gestion de la recherche instantannee */
|
||||||
|
section.view.searchbar.addEventListener('keyup', function(e){
|
||||||
|
|
||||||
|
var search = {
|
||||||
|
path: 'clusterDefault/search',
|
||||||
|
keywords: section.view.searchbar.value
|
||||||
|
};
|
||||||
|
|
||||||
|
// 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_cluster);
|
||||||
|
|
||||||
|
// On recupere la liste des elements correspondants aux utilisateurs
|
||||||
|
var cluster_list = document.querySelectorAll(section.view.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);
|
||||||
|
|
||||||
|
|
||||||
|
/* (4) On gere la "redirection" vers la modification */
|
||||||
|
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('cluster');
|
||||||
|
autofill_edit(pageManager.vars[1]);
|
||||||
|
navSubMenu('edit');
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (5) On gere la "redirection" vers la suppression */
|
||||||
|
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('cluster');
|
||||||
|
autofill_remove(pageManager.vars[1]);
|
||||||
|
navSubMenu('remove');
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (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: 'clusterDefault/unlink',
|
||||||
|
id_cluster: e.target.getData('cluster'),
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* GESTION DE LA CREATION D'UNE MACHINE
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if( section.create.element != null ){
|
||||||
|
|
||||||
|
// On recupere tous les champs
|
||||||
|
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')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* (n) Gestion de l'envoi du formulaire */
|
||||||
|
section.create.input.submit.addEventListener('click', function(e){
|
||||||
|
// On annule l'envoi de base (PHP)
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
var request = {
|
||||||
|
path: 'clusterDefault/create', // On veut creer un utilisateur
|
||||||
|
name: section.create.input.name.value,
|
||||||
|
class: section.create.input.class.value
|
||||||
|
};
|
||||||
|
|
||||||
|
api.send(request, function(answer){
|
||||||
|
if( answer.ModuleError == 0 ){ // Tout s'est bien deroule
|
||||||
|
console.log('Groupe cree!');
|
||||||
|
|
||||||
|
// On redirige sur la cluster
|
||||||
|
pageManager.vars = ['view', answer.id_cluster];
|
||||||
|
pageManager.refresh();
|
||||||
|
document.location = '';
|
||||||
|
|
||||||
|
section.create.input.submit.anim('active', 1500);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* [3] remove -> Suppression de cluster
|
||||||
|
=========================================================*/
|
||||||
|
if( section.remove.element != null ){
|
||||||
|
|
||||||
|
/* (1) Definition des champs */
|
||||||
|
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;
|
||||||
|
var searchindex_remove = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/* (2) Gestion de l'auto-remplissage par lien */
|
||||||
|
function autofill_remove(id_cluster){
|
||||||
|
// On recupere le name de la cluster selectionnee
|
||||||
|
var cluster_data = {
|
||||||
|
id_cluster: '',
|
||||||
|
name: '',
|
||||||
|
disable_input: true
|
||||||
|
};
|
||||||
|
|
||||||
|
api.send({path:'clusterDefault/getById', id_cluster: id_cluster}, function(answer){
|
||||||
|
if( answer.ModuleError == 0 ){ // Aucune erreur
|
||||||
|
cluster_data = answer.cluster;
|
||||||
|
cluster_data.diable_input = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// On enregistre l'UID de la cluster
|
||||||
|
section.remove.input.search.id.value = cluster_data.id_cluster;
|
||||||
|
|
||||||
|
// Auto-remplissage du formulaire
|
||||||
|
section.remove.input.name.value = cluster_data.name;
|
||||||
|
|
||||||
|
// On gere le caractere "inactif" du submit
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
}if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ) autofill_remove(pageManager.vars[1]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* (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
|
||||||
|
if( section.remove.input.search.keyword.value != '' ){
|
||||||
|
// Redaction de la requete
|
||||||
|
var getuid = {
|
||||||
|
path: 'clusterDefault/search',
|
||||||
|
keywords: section.remove.input.search.keyword.value
|
||||||
|
};
|
||||||
|
|
||||||
|
// On envoie la requete
|
||||||
|
api.send(getuid, function(uidanswer){
|
||||||
|
if( uidanswer.ModuleError == 0 && uidanswer.clusters.length > 0){ // si on a trouve qqch
|
||||||
|
section.remove.input.search.submit.anim('active', 1000);
|
||||||
|
|
||||||
|
// Si on trouve la meme cluster que lors de la derniere recherche
|
||||||
|
if( lastsearch_remove == uidanswer.clusters[searchindex_remove].id_cluster )
|
||||||
|
searchindex_remove = (searchindex_remove+1) % uidanswer.clusters.length; // on affiche le prochain (decalage cyclique)
|
||||||
|
|
||||||
|
lastsearch_remove = uidanswer.clusters[searchindex_remove].id_cluster;
|
||||||
|
section.remove.input.search.id.value = lastsearch_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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* (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 != '' ){
|
||||||
|
|
||||||
|
/* (2) On supprime la cluster */
|
||||||
|
var request = {
|
||||||
|
path: 'clusterDefault/delete', // On veut supprimer cet utilisateur
|
||||||
|
id_cluster: section.remove.input.search.id.value
|
||||||
|
};
|
||||||
|
|
||||||
|
api.send(request, function(answer){
|
||||||
|
if( answer.ModuleError == 0 && answer.status == true ){ // Tout s'est bien deroule
|
||||||
|
console.log('Groupe supprimee!');
|
||||||
|
|
||||||
|
section.remove.input.submit.anim('active', 1500);
|
||||||
|
// On vide le formulaire
|
||||||
|
autofill_remove(null);
|
||||||
|
}else // Erreur
|
||||||
|
console.error('ModuleError::'+answer.ModuleError);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* [4] edit -> Modification de cluster
|
||||||
|
=========================================================*/
|
||||||
|
if( section.edit.element != null ){
|
||||||
|
|
||||||
|
// Definition des champs
|
||||||
|
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;
|
||||||
|
var searchindex_edit = 0;
|
||||||
|
|
||||||
|
|
||||||
|
// Gestion de l'auto-remplissage par lien
|
||||||
|
function autofill_edit(id_cluster){
|
||||||
|
// On recupere le name de la cluster selectionnee
|
||||||
|
var cluster_data = {
|
||||||
|
id_cluster: '',
|
||||||
|
name: '',
|
||||||
|
disable_input: true
|
||||||
|
};
|
||||||
|
|
||||||
|
// Si @id_cluster est un entier
|
||||||
|
if( !isNaN(id_cluster) ){
|
||||||
|
|
||||||
|
api.send({path:'clusterDefault/getById', id_cluster: id_cluster}, function(answer){
|
||||||
|
if( answer.ModuleError == 0 ){ // Aucune erreur
|
||||||
|
cluster_data = answer.cluster;
|
||||||
|
cluster_data.disable_input = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// On enregistre l'UID de la cluster
|
||||||
|
section.edit.input.search.id.value = cluster_data.id_cluster;
|
||||||
|
|
||||||
|
// Auto-remplissage du formulaire
|
||||||
|
section.edit.input.name.value = cluster_data.name;
|
||||||
|
|
||||||
|
// On active ou pas le bouton "Modifier"
|
||||||
|
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;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}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 la cluster */
|
||||||
|
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
|
||||||
|
if( section.edit.input.search.keyword.value != '' ){
|
||||||
|
// Redaction de la requete
|
||||||
|
var getuid = {
|
||||||
|
path: 'clusterDefault/search',
|
||||||
|
keywords: section.edit.input.search.keyword.value
|
||||||
|
};
|
||||||
|
|
||||||
|
// On envoie la requete
|
||||||
|
api.send(getuid, function(uidanswer){
|
||||||
|
if( uidanswer.ModuleError == 0 && uidanswer.clusters.length > 0 ){ // si on a trouve qqch
|
||||||
|
section.edit.input.search.submit.anim('active', 1000);
|
||||||
|
|
||||||
|
// Si on trouve la meme cluster que lors de la derniere recherche
|
||||||
|
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;
|
||||||
|
|
||||||
|
lastsearch_edit = uidanswer.clusters[searchindex_edit].id_cluster;
|
||||||
|
section.edit.input.search.id.value = lastsearch_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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* (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: 'clusterDefault/edit', // On veut creer une cluster
|
||||||
|
id_cluster: section.edit.input.search.id.value,
|
||||||
|
name: section.edit.input.name.value
|
||||||
|
};
|
||||||
|
|
||||||
|
api.send(request, function(answer){
|
||||||
|
if( answer.ModuleError == 0 && answer.status == true ){ // Tout s'est bien deroule
|
||||||
|
console.log('Groupe modifiee!');
|
||||||
|
|
||||||
|
section.edit.input.submit.anim('active', 1500);
|
||||||
|
// On met a jour la cluster
|
||||||
|
autofill_edit(section.edit.input.search.id.value);
|
||||||
|
|
||||||
|
}else // Erreur
|
||||||
|
console.error('ModuleError::'+answer.ModuleError);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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-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+
|
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(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",
|
".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",
|
||||||
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"),
|
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: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"),submit:document.querySelector(section.create.text+"#create_submit")},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!"),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(a){0==a.ModuleError&&(console.log("Machine cree!"),pageManager.vars=["view",a.id_machine],pageManager.refresh(),document.location="",section.create.input.submit.anim("active",
|
||||||
1500))})},!1));
|
1500))})},!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"),
|
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"),
|
||||||
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=
|
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=
|
||||||
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&&
|
"",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+
|
||||||
(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",
|
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&&
|
||||||
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)}
|
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+
|
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"),
|
||||||
".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:"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=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();
|
||||||
(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,
|
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,
|
||||||
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)};
|
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)};
|
||||||
|
|
|
@ -153,23 +153,25 @@ if( section.view.element != null ){
|
||||||
*/
|
*/
|
||||||
if( section.create.element != null ){
|
if( section.create.element != null ){
|
||||||
|
|
||||||
// On recupere tous les champs
|
/* (1) On recupere tous les champs */
|
||||||
section.create.input = {
|
section.create.input = {
|
||||||
name: document.querySelector(section.create.text + '#create_name'),
|
name: document.querySelector(section.create.text + '#create_name'),
|
||||||
submit: document.querySelector(section.create.text + '#create_submit')
|
submit: document.querySelector(section.create.text + '#create_submit')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (n) Gestion de l'envoi du formulaire */
|
/* (2) Gestion de l'envoi du formulaire */
|
||||||
section.create.input.submit.addEventListener('click', function(e){
|
section.create.input.submit.addEventListener('click', function(e){
|
||||||
// On annule l'envoi de base (PHP)
|
// On annule l'envoi de base (PHP)
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
/* (3) On rédige la requête */
|
||||||
var request = {
|
var request = {
|
||||||
path: 'machineDefault/create', // On veut creer un utilisateur
|
path: 'machineDefault/create', // On veut creer un utilisateur
|
||||||
name: section.create.input.name.value
|
name: section.create.input.name.value
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* (4) On lance la requête */
|
||||||
api.send(request, function(answer){
|
api.send(request, function(answer){
|
||||||
if( answer.ModuleError == 0 ){ // Tout s'est bien deroule
|
if( answer.ModuleError == 0 ){ // Tout s'est bien deroule
|
||||||
console.log('Machine cree!');
|
console.log('Machine cree!');
|
||||||
|
@ -201,7 +203,9 @@ if( section.create.element != null ){
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
if( section.remove.element != null ){
|
if( section.remove.element != null ){
|
||||||
|
|
||||||
/* (1) Definition des champs */
|
|
||||||
|
/* (1) Definition des champs et variables
|
||||||
|
---------------------------------------------------------*/
|
||||||
section.remove.input = {
|
section.remove.input = {
|
||||||
search: {
|
search: {
|
||||||
view: document.querySelector(section.remove.text + '.remove_search_view'),
|
view: document.querySelector(section.remove.text + '.remove_search_view'),
|
||||||
|
@ -218,26 +222,49 @@ 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_machine){
|
/* (2) Gestion de l'auto-remplissage par lien
|
||||||
// On recupere le name de la machine selectionnee
|
---------------------------------------------------------*/
|
||||||
|
function autofill_remove(specific){
|
||||||
|
/* (0) Valeurs par défaut */
|
||||||
var machine_data = {
|
var machine_data = {
|
||||||
id_machine: '',
|
id_machine: '',
|
||||||
name: '',
|
name: '',
|
||||||
disable_input: true
|
disable_input: true
|
||||||
};
|
};
|
||||||
|
|
||||||
api.send({path:'machineDefault/getById', id_machine: id_machine}, function(answer){
|
|
||||||
if( answer.ModuleError == 0 ){ // Aucune erreur
|
// {1} Si aucun résultat //
|
||||||
machine_data = answer.machine;
|
if( found_remove[searchindex_remove] == null ){
|
||||||
machine_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 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
|
||||||
|
section.remove.input.search.num.innerHTML = searchindex_remove+1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// {3} On auto-remplit le formulaire //
|
||||||
// On enregistre l'UID de la machine
|
// On enregistre l'UID de la machine
|
||||||
section.remove.input.search.id.value = machine_data.id_machine;
|
section.remove.input.search.id.value = machine_data.id_machine;
|
||||||
|
|
||||||
|
@ -247,49 +274,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 = machine_data.disable_input;
|
section.remove.input.submit.disabled = machine_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 "/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
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}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 getMachines = {
|
||||||
path: 'machineDefault/search',
|
path: 'machineDefault/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(getMachines, function(getMachinesResponse){
|
||||||
if( uidanswer.ModuleError == 0 && uidanswer.machines.length > 0){ // si on a trouve qqch
|
if( getMachinesResponse.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 machine que lors de la derniere recherche
|
/* (6) On met à jour les données des machines, et le compteur */
|
||||||
if( lastsearch_remove == uidanswer.machines[searchindex_remove].id_machine )
|
searchindex_remove = 0;
|
||||||
searchindex_remove = (searchindex_remove+1) % uidanswer.machines.length; // on affiche le prochain (decalage cyclique)
|
found_remove = getMachinesResponse.machines;
|
||||||
|
section.remove.input.search.sum.innerHTML = found_remove.length;
|
||||||
|
|
||||||
lastsearch_remove = uidanswer.machines[searchindex_remove].id_machine;
|
// 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.machines.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 = getMachines.keywords;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}, false);
|
}, false);
|
||||||
|
@ -336,6 +390,8 @@ if( section.remove.element != null ){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* [4] edit -> Modification de machine
|
/* [4] edit -> Modification de machine
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
if( section.edit.element != null ){
|
if( section.edit.element != null ){
|
||||||
|
@ -357,92 +413,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_machine){
|
/* (2) Gestion de l'auto-remplissage par lien
|
||||||
// On recupere le name de la machine selectionnee
|
---------------------------------------------------------*/
|
||||||
|
function autofill_edit(specific){
|
||||||
|
/* (0) Valeurs par défaut */
|
||||||
var machine_data = {
|
var machine_data = {
|
||||||
id_machine: '',
|
id_machine: '',
|
||||||
name: '',
|
name: '',
|
||||||
disable_input: true
|
disable_input: true
|
||||||
};
|
};
|
||||||
|
|
||||||
// Si @id_machine est un entier
|
|
||||||
if( !isNaN(id_machine) ){
|
|
||||||
|
|
||||||
api.send({path:'machineDefault/getById', id_machine: id_machine}, function(answer){
|
// {1} Si aucun résultat //
|
||||||
if( answer.ModuleError == 0 ){ // Aucune erreur
|
if( found_edit[searchindex_edit] == null ){
|
||||||
machine_data = answer.machine;
|
|
||||||
machine_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 machine selectionnee
|
||||||
|
machine_data = {
|
||||||
|
id_machine: found_edit[searchindex_edit]['id_machine'],
|
||||||
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// {3} On auto-remplit le formulaire //
|
||||||
// On enregistre l'UID de la machine
|
// On enregistre l'UID de la machine
|
||||||
section.edit.input.search.id.value = machine_data.id_machine;
|
section.edit.input.search.id.value = machine_data.id_machine;
|
||||||
|
|
||||||
// Auto-remplissage du formulaire
|
// Auto-remplissage du formulaire
|
||||||
section.edit.input.name.value = machine_data.name;
|
section.edit.input.name.value = machine_data.name;
|
||||||
|
|
||||||
// On active ou pas le bouton "Modifier"
|
// On gere le caractere "inactif" du submit
|
||||||
section.edit.input.submit.disabled = machine_data.disable_input;
|
section.edit.input.submit.disabled = machine_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 "/machines/edit/: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_edit = [ response.machine ]; // 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 machine */
|
|
||||||
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 getMachines = {
|
||||||
path: 'machineDefault/search',
|
path: 'machineDefault/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(getMachines, function(getMachinesResponse){
|
||||||
if( uidanswer.ModuleError == 0 && uidanswer.machines.length > 0 ){ // si on a trouve qqch
|
if( getMachinesResponse.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 machine que lors de la derniere recherche
|
/* (6) On met à jour les données des machines, et le compteur */
|
||||||
if( lastsearch_edit == uidanswer.machines[searchindex_edit].id_machine )
|
|
||||||
searchindex_edit = (searchindex_edit+1) % uidanswer.machines.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 = getMachinesResponse.machines;
|
||||||
|
section.edit.input.search.sum.innerHTML = found_edit.length;
|
||||||
|
|
||||||
lastsearch_edit = uidanswer.machines[searchindex_edit].id_machine;
|
// 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.machines.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 = getMachines.keywords;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}, false);
|
}, false);
|
||||||
|
|
Loading…
Reference in New Issue