Gestion complète de la modification sur la page 'groups' et les vues 'groups/view' et 'groups/edit'

This commit is contained in:
xdrm-brackets 2016-07-20 19:41:43 +02:00
parent a9b0f5b02e
commit 727e3c6a87
13 changed files with 166 additions and 596 deletions

View File

@ -387,7 +387,8 @@
"description": "Liste de tous les groupes",
"permissions": ["warehouse", "admin"],
"parameters": {
"class": { "description": "Type de groupe.", "type": "id" }
"class": { "description": "Type de groupe.", "type": "id" },
"class": { "description": "Type de groupe.", "type": "id", "optional": true }
},
"output": {
"clusters": { "description": "Liste de tous les groupes.", "type": "array<array<mixed>>" }
@ -434,9 +435,9 @@
"description": "Modifie le nom d'un groupe.",
"permissions": ["warehouse", "admin"],
"parameters": {
"id_cluster": { "description": "UID du groupe.", "type": "id" },
"class": { "description": "Type de groupe.", "type": "id" },
"name": { "description": "Nom du groupe.", "type": "varchar(1,30,alphanumeric)", "optional": true }
"id_cluster": { "description": "UID du groupe.", "type": "id" },
"class": { "description": "Type de groupe.", "type": "id" },
"name": { "description": "Nom du groupe.", "type": "varchar(1,30,alphanumeric)" }
},
"output": {
"status": { "description": "Status de la modification.", "type": "boolean" }

View File

@ -53,6 +53,7 @@
"machine_cluster": [
"create",
"edit",
"delete",
"getAll",
@ -72,6 +73,7 @@
"user_cluster": [
"create",
"edit",
"delete",
"getAll",

View File

@ -104,12 +104,32 @@
public static function getAll($params){
extract($params);
$repoMethod = ($class==0) ? 'user_cluster/getAll' : 'machine_cluster/getAll';
$result = [];
// On recupere les donnees
$clusters = new Repo($repoMethod, [ $_SESSION['WAREHOUSE']['id'] ]);
if( is_null($class) || $class == 0 ){
return [ 'clusters' => $clusters->answer() ];
// On recupere les donnees des groupes utilisateurs
$userClusters = new Repo('user_cluster/getAll', [
$_SESSION['WAREHOUSE']['id']
]);
$result = array_merge($result, $userClusters->answer());
}
if( is_null($class) || $class == 1 ){
// On recupere les donnees des groupes utilisateurs
$machineClusters = new Repo('machine_cluster/getAll', [
$_SESSION['WAREHOUSE']['id']
]);
$result = array_merge($result, $machineClusters->answer());
}
return [ 'clusters' => $result ];
}
@ -214,7 +234,7 @@
/* MODIFIE UN groupe DONNEE
*
* @id_user<int> UID de l'utilisateur
* @id_cluster<int> UID du groupe
* @class<int> Type de groupe
* @name<String> Nouveau nom
*
@ -224,64 +244,42 @@
public static function edit($params){
extract($params);
// TODO:: Gestion de la modification de groupe
exit();
/* [1] On verifie l'existence de l'utilisateur
/* [1] On verifie l'existence du groupe
=========================================================*/
$user_exists = new Repo('user/getById', [
$repo = ($class==0) ? 'user_cluster' : 'machine_cluster';
$cluster_exists = new Repo($repo.'/getById', [
$_SESSION['WAREHOUSE']['id'],
$id_user
$id_cluster
]);
$user_data = $user_exists->answer();
$cluster_data = $cluster_exists->answer();
// Si on a recupere aucun utilisateur, on retourne une erreur
if( !is_array($user_data) )
if( $cluster_data === false )
return ['ModuleError' => ManagerError::NoMatchFound];
/* [2] Normalisation + verification des donnees
=========================================================*/
$password_hash = sessionManager::secure_hash($password);
/* (1) Verification des parametres (si non nul + differents)*/
$diff_param = [
'code' => !is_null($code) && $user_data['code'] != $code,
'username' => !is_null($username) && $user_data['username'] != $username,
'firstname' => !is_null($firstname) && $user_data['firstname'] != $firstname,
'lastname' => !is_null($lastname) && $user_data['lastname'] != $lastname,
'mail' => !is_null($mail) && $user_data['mail'] != $mail,
'password' => !is_null($password) && $user_data['password'] != $password_hash,
'status' => !is_null($status) && $user_data['status'] != $status
'name' => $cluster_data['name'] != $name
];
/* (2) Gestion des parametres optionnels */
$opt_data = [
'code' => ($diff_param['code']) ? $code : $user_data['code'],
'username' => ($diff_param['username']) ? $username : $user_data['username'],
'firstname' => ($diff_param['firstname']) ? $firstname : $user_data['firstname'],
'lastname' => ($diff_param['lastname']) ? $lastname : $user_data['lastname'],
'mail' => ($diff_param['mail']) ? $mail : $user_data['mail'],
'password' => ($diff_param['password']) ? $password : $user_data['password'],
'status' => ($diff_param['status']) ? $status : $user_data['status'],
'name' => ($diff_param['name']) ? $name : $cluster_data['name'],
];
/* [3] Modification de l'utilisateur
/* [3] Modification du groupe
=========================================================*/
$request = new Repo('user/edit', [
$request = new Repo($repo.'/edit', [
$_SESSION['WAREHOUSE']['id'],
$id_user,
$opt_data['code'],
$opt_data['username'],
$opt_data['firstname'],
$opt_data['lastname'],
$opt_data['mail'],
$opt_data['password'],
$opt_data['status']
$id_cluster,
$opt_data['name'],
]);

View File

@ -1,527 +0,0 @@
<?php
namespace manager\repo;
use \manager\Database;
use \manager\ManagerError;
use \manager\repo\machine as machineRepo;
use \manager\repo\user as userRepo;
class cluster extends parentRepo{
protected static function table_name(){ static $table_name = 'cluster'; return $table_name; }
const USER_CLASS = 0;
const MACHINE_CLASS = 1;
/* CREATION D'UN GROUPE
*
* @id_warehouse<int> UID de l'entrepot
* @name<String> Nom du groupe
* @class<int> Type d'entités du groupe
* @owner<int> Si défini -> UID de l'entité qui a ce groupe comme groupe PERSONNEL
*
* @return id_user<int> Renvoie l'UID du groupe cree
* Renvoie FALSE si une erreur occure
*
*/
public static function create($id_warehouse, $name, $class, $owner=null){
/* [1] Verification de l'unicite de name
=========================================================*/
$check_unique = ( self::getByName($id_warehouse, $name) === false );
// Si un groupe a deja ce nom, on renvoie une erreur
if( !$check_unique )
return false;
/* [2] Creation du groupe
=========================================================*/
$insert_user = Database::getPDO()->prepare("INSERT INTO cluster(id_cluster, id_warehouse, name, class, personal)
VALUES(DEFAULT, :id_warehouse, :name, :class, :personal)");
$insert_user->execute([
':id_warehouse' => $id_warehouse,
':name' => $name,
':class' => $class,
':personal' => $owner
]);
/* [3] On retourne l'id_group ou FALSE si erreur
=========================================================*/
$check_group = self::getByName($id_warehouse, $name);
// Si n'existe pas on retourne FALSE
if( $check_group === false )
return false;
// Sinon, on retourne son id
return $check_group['id_cluster'];
}
/* ASSOCIATION D'UN(E) UTILISATEUR/MACHINE A UN GROUPE
*
* @id_warehouse<int> UID de l'entrepot
* @id_cluster<int> UID du groupe
* @id_entity<int> UID de la machine ou de l'utilisateur
* @class<int> Spefication du type d'entite (0=user;1=machine)
*
* @return error<int> Renvoie le code 'ManagerError'
*
*/
public static function link($id_warehouse, $id_cluster, $id_entity, $class){
/* [1] Verification de l'existence du groupe
=========================================================*/
$group_check = self::getById($id_warehouse, $id_cluster);
// Si le groupe n'existe pas, on retourne ue erreur
if( $group_check === false )
return ManagerError::NoMatchFound;
/* [2] Verification de l'existente de l'entite
=========================================================*/
$entity_exists = false;
/* (1) Utilisateur */
if( $class == self::USER_CLASS ){
// On verifie si c'est un utilisateur
$user_check = userRepo::getById($id_warehouse, $id_entity);
$entity_exists = ( $user_check !== FALSE );
/* (2) Machine */
}elseif( $class == self::MACHINE_CLASS ){
// On verifie si c'est une machine
$machine_check = machineRepo::getById($id_warehouse, $id_entity);
$entity_exists = ( $machine_check !== FALSE );
}
// Si aucune entite existante, on retourne une erreur
if( !$entity_exists )
return ManagerError::NoMatchFound;
/* [3] Verification que l'existente n'existe pas deja
=========================================================*/
$already_cluster_merge = self::getMerge($id_warehouse, $id_cluster, $id_entity, $class);
// Si l'association existe deja, on ne la cree donc pas
if( $already_cluster_merge !== false )
return ManagerError::Success;
/* [4] On cree l'association
=========================================================*/
$link_entity = Database::getPDO()->prepare("INSERT INTO cluster_merge(id_cluster_merge, id_cluster, id_entity)
VALUES(DEFAULT, :id_cluster, :id_entity)");
$link_entity->execute([
':id_cluster' => $id_cluster,
':id_entity' => $id_entity
]);
/* [5] On retourne l'id_cluster_merge ou FALSE si erreur
=========================================================*/
$check_cluster_merge = self::getMerge($id_warehouse, $id_cluster, $id_entity, $class);
// Si n'existe pas on retourne FALSE
if( !is_array($check_cluster_merge) )
return ManagerError::RepoError;
// Sinon, on retourne son id
return ManagerError::Success;
}
/* SUPPRIME UNE ASSOCIATION D'UN(E) UTILISATEUR/MACHINE A UN GROUPE
*
* @id_warehouse<int> UID de l'entrepot
* @id_cluster<int> UID du groupe
* @id_entity<int> UID de la machine ou de l'utilisateur
* @class<int> Spefication du type d'entite (0=user;1=machine)
*
* @return error<int> Renvoie le code 'ManagerError'
*
*/
public static function unlink($id_warehouse, $id_cluster, $id_entity, $class){
/* [1] On récupère l'UID du lien
=========================================================*/
/* (1) On récupère le lien */
$get_merge_id = self::getMerge($id_warehouse, $id_cluster, $id_entity, $class);
/* (2) Si on ne trouve rien */
if( $get_merge_id == false )
return ManagerError::NoMatchFound;
/* [2] On supprime le lien
=========================================================*/
$delete_cluster_merge = Database::getPDO()->prepare("DELETE FROM cluster_merge
WHERE id_cluster_merge = :uid");
$delete_cluster_merge->execute([
':uid' => $get_merge_id['id_cluster_merge']
]);
/* [2] On verifie que l'association n'existe plus
=========================================================*/
if( self::getMerge($id_warehouse, $id_cluster, $id_entity, $class) !== false )
return ManagerError::ModuleError;
return ManagerError::Success;
}
/* RENVOIE L'ID D'UNE ASSOCIATION D'UN(E) UTILISATEUR/MACHINE A UN GROUPE
*
* @id_warehouse<int> UID de l'entrepot
* @id_cluster<int> UID du groupe
* @id_entity<int> UID de la machine ou de l'utilisateur
* @class<int> Spefication du type d'entite (0=user;1=machine)
*
* @return association<int> Renvoie l'UID de l'association cree
* Renvoie FALSE si une erreur occure
*
*/
public static function getMerge($id_warehouse, $id_cluster, $id_entity, $class){
// On ecrit la requete
$request = Database::getPDO()->prepare("SELECT cm.*
FROM cluster_merge as cm, cluster as c
WHERE cm.id_cluster = c.id_cluster
AND c.id_warehouse = :id_warehouse
AND cm.id_cluster = :id_cluster
AND cm.id_entity = :id_entity
AND c.class = :class");
// On execute la requete
$request->execute([
':id_warehouse' => $id_warehouse,
':id_cluster' => $id_cluster,
':id_entity' => $id_entity,
':class' => $class
]);
// On recupere 1 seule relation
$answer = $request->fetch();
// Gestion d'erreur -> aucun resultat
if( $answer === false )
return false;
// On retourne en supprimant les indices numeriques
return Database::delNumeric( $answer, true );
}
/* RENVOIE LA LISTE DES GROUPES D'UN ENTREPOT
*
* @id_warehouse<int> UID de l'entrepot
*
* @return clusters<Array> Renvoie la liste des groupes
* Renvoie FALSE si une erreur occure
*
*/
public static function getAll($id_warehouse){
// On ecrit la requete
$request = Database::getPDO()->prepare("SELECT c.id_cluster, c.name, c.class
FROM cluster as c
WHERE c.id_warehouse = :id_warehouse
AND c.personal is null
ORDER BY c.name ASC");
// On execute la requete
$request->execute([
':id_warehouse' => $id_warehouse
]);
// On retourne en supprimant les indices numeriques
return Database::delNumeric( $request->fetchAll() );
}
/* RENVOIE LA LISTE D'UN GROUPE SPECIFIQUE
*
* @id_warehouse<int> UID de l'entrepot
* @id<int> UID du groupe
*
* @return cluster<Array> Renvoie le groupe correspondant
* Renvoie FALSE si une erreur occure
*
*/
public static function getById($id_warehouse, $id){
// On ecrit la requete
$request = Database::getPDO()->prepare("SELECT c.*
FROM cluster as c
WHERE c.id_warehouse = :id_warehouse
AND c.id_cluster = :id");
// On execute la requete
$request->execute([
':id_warehouse' => $id_warehouse,
':id' => $id
]);
$fetch = $request->fetch();
// Si aucun résultat
if( $fetch == false )
return false;
// On retourne en supprimant les indices numeriques
return Database::delNumeric( $fetch, true );
}
/* RENVOIE LA LISTE D'UN GROUPE SPECIFIQUE
*
* @id_warehouse<int> UID de l'entrepot
* @name<String> Nom du groupe
*
* @return cluster<Array> Renvoie le groupe correspondant
* Renvoie FALSE si une erreur occure
*
*/
public static function getByName($id_warehouse, $name){
// On ecrit la requete
$request = Database::getPDO()->prepare("SELECT c.*
FROM cluster as c
WHERE c.id_warehouse = :id_warehouse
AND c.name = :name");
// On execute la requete
$request->execute([
':id_warehouse' => $id_warehouse,
':name' => $name
]);
$fetch = $request->fetch();
// Si aucun résultat
if( $fetch == false )
return false;
// On retourne en supprimant les indices numeriques
return Database::delNumeric( $fetch, true );
}
/* RENVOIE LE GROUPE PERSONNEL D'UNE ENTITE
*
* @id_warehouse<int> UID de l'entrepot
* @id_entity<int> UID de l'entité (user/machine)
* @class<int> Classe du groupe (0:user ; 1:machine)
*
* @return cluster<Array> Renvoie le groupe correspondant
* Renvoie FALSE si une erreur occure
*
*/
public static function getPersonal($id_warehouse, $id_entity, $class){
// On ecrit la requete
$request = Database::getPDO()->prepare("SELECT c.*
FROM cluster as c
WHERE c.id_warehouse = :id_warehouse
AND c.personal is not null
AND c.id_entity = :id_entity
AND c.class = :class");
// On execute la requete
$request->execute([
':id_warehouse' => $id_warehouse,
':id_entity' => $id_entity,
':class' => $class
]);
$fetch = $request->fetch();
// Si aucun résultat
if( $fetch == false )
return false;
// On retourne en supprimant les indices numeriques
return Database::delNumeric( $fetch, true );
}
/* RENVOIE LES MEMBRES D'UN GROUPE DONNE
*
* @id_warehouse<int> UID de l'entrepot
* @id_cluster<int> UID du groupe en question
*
* @return members<Array> Retourne la liste des membres du groupe
*
*/
public static function getMembers($id_warehouse, $id_cluster){
/* [1] On recupere la liste des associations
=========================================================*/
$get_members = Database::getPDO()->prepare("SELECT id_entity as id_member, c.class
FROM cluster_merge as cm, cluster as c
WHERE cm.id_cluster = c.id_cluster
AND c.id_cluster = :id_cluster
AND c.id_warehouse = :id_warehouse
AND c.personal is null
ORDER BY id_cluster_merge");
$get_members->execute([
':id_warehouse' => $id_warehouse,
':id_cluster' => $id_cluster
]);
$members = Database::delNumeric( $get_members->fetchAll() );
/* [2] On formatte recupere les entites
=========================================================*/
foreach($members as $i=>$member){
/* (1) On recupere les informations utilisateur */
if( $member['class'] == self::USER_CLASS ){
$get_user = userRepo::getById( $id_warehouse, $member['id_member'] );
// Si on a bien recu les informations, on les ajoute
if( $get_user !== false ){
$members[$i] = [
'id_member' => $get_user['id_user'],
'name' => $get_user['username'],
'class' => self::USER_CLASS
];
}
/* (2) On recupere les informations machine */
}elseif( $member['class'] == self::MACHINE_CLASS ){
$get_machine = machineRepo::getById( $id_warehouse, $member['id_member'] );
// Si on a bien recu les informations, on les ajoute
if( $get_machine !== false ){
$members[$i] = [
'id_member' => $get_machine['id_machine'],
'name' => $get_machine['name'],
'class' => self::MACHINE_CLASS
];
}
}
}
/* [2] On verifie que le groupe n'existe plus
=========================================================*/
return $members;
}
/* 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() );
}
/* SUPPRIME UN GROUPE DONNE
*
* @id_warehouse<int> UID de l'entrepot
* @id_cluster<int> UID du groupe en question
*
* @return status<Boolean> Retourne si oui ou non le groupe a bien ete supprime
*
*/
public static function delete($id_warehouse, $id_cluster){
/* [1] On redige/execute la requete
=========================================================*/
$delete_group = Database::getPDO()->prepare("DELETE FROM cluster
WHERE id_warehouse = :id_warehouse
AND id_cluster = :id_cluster");
$delete_group->execute([
':id_warehouse' => $id_warehouse,
':id_cluster' => $id_cluster
]);
/* [2] On verifie que le groupe n'existe plus
=========================================================*/
return ( self::getById($id_group) === false );
}
}
?>

View File

@ -380,6 +380,35 @@
/* MODIFIE LE NOM D'UN GROUPE DONNE
*
* @id_machine_cluster<int> UID du gorupe
* @name<String> Nouveau nom du groupe
*
* @return status<Boolean> TRUE si tout s'est bien passé, sinon FALSE
*
*/
public static function edit($id_warehouse, $id_machine_cluster, $name){
/* [1] On rédige la requête
=========================================================*/
$edit_group = Database::getPDO()->prepare("UPDATE machine_cluster
SET name = :name
WHERE id_machine_cluster = :id_machine_cluster");
$edited = $edit_group->execute([
':name' => $name,
':id_machine_cluster' => $id_machine_cluster
]);
return $edited;
}
/* SUPPRIME UN GROUPE DONNE
*
* @id_warehouse<int> UID de l'entrepot

View File

@ -380,6 +380,34 @@
/* MODIFIE LE NOM D'UN GROUPE DONNE
*
* @id_user_cluster<int> UID du gorupe
* @name<String> Nouveau nom du groupe
*
* @return status<Boolean> TRUE si tout s'est bien passé, sinon FALSE
*
*/
public static function edit($id_warehouse, $id_user_cluster, $name){
/* [1] On rédige la requête
=========================================================*/
$edit_group = Database::getPDO()->prepare("UPDATE user_cluster
SET name = :name
WHERE id_user_cluster = :id_user_cluster");
$edited = $edit_group->execute([
':name' => $name,
':id_user_cluster' => $id_user_cluster
]);
return $edited;
}
/* SUPPRIME UN GROUPE DONNE
*
* @id_warehouse<int> UID de l'entrepot

View File

@ -184,13 +184,11 @@
'id_cluster' => $m[2],
'class' => ($m[1]=='u') ? 0 : 1
]);
$membersChoice->view();
}else{
$groupChoice = new View('group.groupChoice', []);
$groupChoice->view();
}

20
view/js/groups-min.js vendored
View File

@ -3,21 +3,23 @@ edit:{text:'#CONTAINER > section[data-sublink="edit"] ',element:document.querySe
element:document.querySelector('#CONTAINER > section[data-sublink="permissions"]')}};
if(null!=section.view.element){1<pageManager.vars.length&&/^(u|m)\d+$/.test(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-member[data-cluster][data-member]"),add:document.querySelectorAll(section.view.text+
".add-member[data-cluster]")};section.view.searchbar.addEventListener("keyup",function(a){api.send({path:"clusterDefault/search",keywords:section.view.searchbar.value},function(a){if(0==a.ModuleError){for(var d=[],c=0;c<a.clusters.length;c++)d.push(a.clusters[c].id_cluster);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);var i;for(i=0;i<section.view.link.edit.length;i++)section.view.link.edit[i].addEventListener("click",
function(a){pageManager.vars[1]=a.target.getData("cluster");autofill_edit();navSubMenu("edit")},!1);for(i=0;i<section.view.link.remove.length;i++)section.view.link.remove[i].addEventListener("click",function(a){pageManager.vars[1]=a.target.getData("cluster");autofill_remove();navSubMenu("remove")},!1);for(i=0;i<section.view.group.rem.length;i++)section.view.group.rem[i].addEventListener("click",function(a){var b=a.target.getData("cluster")[0],d=a.target.getData("cluster").slice(1);console.log(a.target);
var c={};c.path="u"==b?"userDefault/unlink":"machineDefault/unlink";c.id_cluster=d;"u"==b?c.id_user=a.target.getData("member"):c.id_machine=a.target.getData("member");api.send(c,function(b){if(0!=b.ModuleError)return!1;a.target.parentNode.parentNode.removeChild(a.target.parentNode)})},!1);for(i=0;i<section.view.group.add.length;i++)section.view.group.add[i].addEventListener("click",function(a){pageManager.vars[1]=a.target.getData("cluster");navSubMenu("members");document.location=""},!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(a){a.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!"),
section.create.input.submit.anim("active",1500))})},!1));
function(a){pageManager.vars[1]=a.target.getData("cluster");autofill_edit();navSubMenu("edit");document.location=""},!1);for(i=0;i<section.view.link.remove.length;i++)section.view.link.remove[i].addEventListener("click",function(a){pageManager.vars[1]=a.target.getData("cluster");autofill_remove();navSubMenu("remove");document.location=""},!1);for(i=0;i<section.view.group.rem.length;i++)section.view.group.rem[i].addEventListener("click",function(a){var b=a.target.getData("cluster")[0],d=a.target.getData("cluster").slice(1);
console.log(a.target);var c={};c.path="u"==b?"userDefault/unlink":"machineDefault/unlink";c.id_cluster=d;"u"==b?c.id_user=a.target.getData("member"):c.id_machine=a.target.getData("member");api.send(c,function(b){if(0!=b.ModuleError)return!1;a.target.parentNode.parentNode.removeChild(a.target.parentNode)})},!1);for(i=0;i<section.view.group.add.length;i++)section.view.group.add[i].addEventListener("click",function(a){pageManager.vars[1]=a.target.getData("cluster");navSubMenu("members");document.location=
""},!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(a){a.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!"),section.create.input.submit.anim("active",
1500))})},!1));
if(null!=section.remove.element){var autofill_remove=function(){var a={id_cluster:"","class":"",name:"",disable_input:!0};if(null==found_remove[searchindex_remove])searchindex_remove=section.remove.input.search.num.innerHTML=0;else{var b;found_remove[searchindex_remove].hasOwnProperty("id_user_cluster")?(a=found_remove[searchindex_remove].id_user_cluster,b=0):(a=found_remove[searchindex_remove].id_machine_cluster,b=1);a={id_cluster:a,"class":b,name:found_remove[searchindex_remove].name,disable_input:!1};
section.remove.input.search.num.innerHTML=searchindex_remove+1}section.remove.input.search.id.value=a.id_cluster;section.remove.input.name.value=a.name;section.remove.input["class"].value=0==a["class"]?"utilisateur":"machine";console.log(a);section.remove.input.submit.disabled=a.disable_input};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"),"class":document.querySelector(section.remove.text+"#remove_class"),submit:document.querySelector(section.remove.text+"#remove_submit")};var lastkeywords_remove="",found_remove=[],searchindex_remove=
0;if(2<=pageManager.vars.length&&/^(u|m)\d+$/.test(pageManager.vars[1])){var prefix=pageManager.vars[1][0],cluster=pageManager.vars[1].slice(1),request={path:"clusterDefault/getById",id_cluster:cluster,"class":"u"==prefix?0:1};api.send(request,function(a){0==a.ModuleError&&(found_remove=[a.cluster],searchindex_remove=0,autofill_remove())})}section.remove.input.search.submit.addEventListener("click",function(a){a.preventDefault();if(""!=section.remove.input.search.keyword.value)if(section.remove.input.search.keyword.value==
lastkeywords_remove)searchindex_remove=(searchindex_remove+1)%found_remove.length,autofill_remove();else{var b={path:"clusterDefault/search",keywords:section.remove.input.search.keyword.value};api.send(b,function(a){0==a.ModuleError&&(section.remove.input.search.submit.anim("active",1E3),searchindex_remove=0,found_remove=a.clusters,section.remove.input.search.sum.innerHTML=found_remove.length,autofill_remove());lastkeywords_remove=b.keywords})}},!1);section.remove.input.submit.addEventListener("click",
function(a){a.preventDefault();""!=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(){var a="",b="",d=!0;null==found_edit[searchindex_edit]?searchindex_edit=section.edit.input.search.num.innerHTML=0:(a=found_edit[searchindex_edit].id_cluster,b=found_edit[searchindex_edit].name,d=!1,section.edit.input.search.num.innerHTML=searchindex_edit+1);section.edit.input.search.id.value=a;section.edit.input.name.value=b;section.edit.input.submit.disabled=d};section.edit.input={search:{view:document.querySelector(section.edit.text+".edit_search_view"),
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:"clusterDefault/getById",id_cluster:pageManager.vars[1]},function(a){0==a.ModuleError&&(found_edit=[a.cluster],searchindex_edit=0,autofill_edit())});section.edit.input.search.submit.addEventListener("click",function(a){a.preventDefault();if(""!=section.edit.input.search.keyword.value)if(section.edit.input.search.keyword.value==lastkeywords_edit)searchindex_edit=(searchindex_edit+1)%found_edit.length,autofill_edit();
else{var b={path:"clusterDefault/search",keywords:section.edit.input.search.keyword.value};api.send(b,function(a){0==a.ModuleError&&(section.edit.input.search.submit.anim("active",1E3),searchindex_edit=0,found_edit=a.clusters,section.edit.input.search.sum.innerHTML=found_edit.length,autofill_edit());lastkeywords_edit=b.keywords})}},!1);section.edit.input.submit.addEventListener("click",function(a){a.preventDefault();""!=section.edit.input.search.id.value&&api.send({path:"clusterDefault/edit",id_cluster:section.edit.input.search.id.value,
name:section.edit.input.name.value},function(a){0==a.ModuleError&&1==a.status?(console.log("Groupe modifiee!"),section.edit.input.submit.anim("active",1500),autofill_edit(section.edit.input.search.id.value)):console.error("ModuleError::"+a.ModuleError)})},!1)}
if(null!=section.edit.element){var autofill_edit=function(){var a="",b="",d=!0;if(null==found_edit[searchindex_edit])searchindex_edit=section.edit.input.search.num.innerHTML=0;else{var c;found_edit[searchindex_remove].hasOwnProperty("id_user_cluster")?(a=found_edit[searchindex_remove].id_user_cluster,c=0):(a=found_edit[searchindex_remove].id_machine_cluster,c=1);b=found_edit[searchindex_remove].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["class"].value=0==c?"utilisateur":"machine";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"),"class":document.querySelector(section.edit.text+"#edit_class"),submit:document.querySelector(section.edit.text+"#edit_submit")};var lastkeywords_edit="",found_edit=[],searchindex_edit=0;2<=pageManager.vars.length&&/^(u|m)\d+$/.test(pageManager.vars[1])&&(console.log("bla"),prefix=pageManager.vars[1][0],cluster=pageManager.vars[1].slice(1),request={path:"clusterDefault/getById",id_cluster:cluster,"class":"u"==prefix?
0:1},api.send(request,function(a){0==a.ModuleError&&(found_edit=[a.cluster],searchindex_edit=0,autofill_edit())}));section.edit.input.search.submit.addEventListener("click",function(a){a.preventDefault();if(""!=section.edit.input.search.keyword.value)if(section.edit.input.search.keyword.value==lastkeywords_edit)searchindex_edit=(searchindex_edit+1)%found_edit.length,autofill_edit();else{var b={path:"clusterDefault/search",keywords:section.edit.input.search.keyword.value};api.send(b,function(a){0==
a.ModuleError&&(section.edit.input.search.submit.anim("active",1E3),searchindex_edit=0,found_edit=a.clusters,section.edit.input.search.sum.innerHTML=found_edit.length,autofill_edit());lastkeywords_edit=b.keywords})}},!1);section.edit.input.submit.addEventListener("click",function(a){a.preventDefault();if(""!=section.edit.input.search.id.value){var b=found_edit[searchindex_edit].hasOwnProperty("id_user_cluster")?0:1,d={path:"clusterDefault/edit",id_cluster:section.edit.input.search.id.value,name:section.edit.input.name.value,
"class":b};api.send(d,function(a){0==a.ModuleError&&1==a.status?(console.log("Groupe modifiee!"),section.edit.input.submit.anim("active",1500),pageManager.vars[1]=(0==b?"u":"m")+d.id_cluster,navSubMenu("view"),document.location=""):console.error("ModuleError::"+a.ModuleError)})}},!1)}
null!=section.members.element&&null!=section.members.chooser.element&&(section.members.chooser.deflater=new FormDeflater(section.members.chooser.element,["select"],["data-name"]),section.members.chooser.submit=document.querySelector(section.members.chooser.text+"#choose-cluster"),section.members.chooser.submit.addEventListener("click",function(a){a.preventDefault();a=section.members.chooser.deflater.deflate().cluster;/^(u|m)\d+$/.test(a)&&(pageManager.vars[1]=a,pageManager.refresh(),document.location=
"")},!1));
null!=section.members.element&&null==section.members.chooser.element&&(section.members.deflater=new FormDeflater(section.members.element,["input"],["data-name"]),section.members.baseData=section.members.deflater.deflate().members,section.members["class"]=document.querySelector("#members-member-class").value,section.members.idcluster=document.querySelector("#members-member-idcluster").value,section.members.element.addEventListener("click",function(a){var b=[],d=[],c=section.members.deflater.deflate().members;c instanceof

View File

@ -107,6 +107,7 @@ if( section.view.element != null ){
pageManager.vars[1] = e.target.getData('cluster');
autofill_edit();
navSubMenu('edit');
document.location = '';
}, false);
}
@ -118,6 +119,7 @@ if( section.view.element != null ){
pageManager.vars[1] = e.target.getData('cluster');
autofill_remove();
navSubMenu('remove');
document.location = '';
}, false);
}
@ -465,6 +467,7 @@ if( section.edit.element != null ){
},
name: document.querySelector(section.edit.text + '#edit_name'),
class: document.querySelector(section.edit.text + '#edit_class'),
submit: document.querySelector(section.edit.text + '#edit_submit')
};
@ -481,6 +484,7 @@ if( section.edit.element != null ){
/* (0) Valeurs par défaut */
var cluster_data = {
id_cluster: '',
class: '',
name: '',
disable_input: true
};
@ -498,10 +502,23 @@ if( section.edit.element != null ){
// {2} Si au moins 1 résultat //
}else{
var tmpIdCluster, clusterClass;
// Si groupe utilisateur
if( found_edit[searchindex_remove].hasOwnProperty('id_user_cluster') ){
tmpIdCluster = found_edit[searchindex_remove].id_user_cluster;
clusterClass = 0;
// Sinon groupe machine
}else{
tmpIdCluster = found_edit[searchindex_remove].id_machine_cluster;
clusterClass = 1;
}
// On recupere les données de la user selectionnee
cluster_data = {
id_cluster: found_edit[searchindex_edit]['id_cluster'],
name: found_edit[searchindex_edit]['name'],
id_cluster: tmpIdCluster,
class: clusterClass,
name: found_edit[searchindex_remove]['name'],
disable_input: false
};
@ -517,6 +534,7 @@ if( section.edit.element != null ){
// Auto-remplissage du formulaire
section.edit.input.name.value = cluster_data.name;
section.edit.input.class.value = (clusterClass==0) ? 'utilisateur' : 'machine';
// On gere le caractere "inactif" du submit
section.edit.input.submit.disabled = cluster_data.disable_input;
@ -525,10 +543,19 @@ if( section.edit.element != null ){
}
// Gestion automatique au chargement de la page si ID_CLUSTER dans url "/users/edit/:id_cluster:"
if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ){
if( pageManager.vars.length >= 2 && /^(u|m)\d+$/.test(pageManager.vars[1]) ){
console.log('bla');
var prefix = pageManager.vars[1][0];
var cluster = pageManager.vars[1].slice(1);
var request = {
path: 'clusterDefault/getById',
id_cluster: cluster,
class: (prefix=='u') ? 0 : 1
};
// On récupère la user d'uid donné dans l'URL
api.send({path:'clusterDefault/getById', id_cluster:pageManager.vars[1]}, function(response){
api.send(request, function(response){
// Si aucune erreur et un résultat
if( response.ModuleError == 0 ){
found_edit = [ response.cluster ]; // On récupère le résultat
@ -608,10 +635,13 @@ if( section.edit.element != null ){
// Si l'id est defini
if( section.edit.input.search.id.value != '' ){
var clusterClass = (found_edit[searchindex_edit].hasOwnProperty('id_user_cluster')) ? 0 : 1;
var request = {
path: 'clusterDefault/edit', // On veut creer une cluster
id_cluster: section.edit.input.search.id.value,
name: section.edit.input.name.value
name: section.edit.input.name.value,
class: clusterClass
};
api.send(request, function(answer){
@ -619,8 +649,11 @@ if( section.edit.element != null ){
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);
// On met a jour le cluster
pageManager.vars[1] = ((clusterClass==0)?'u':'m') + request.id_cluster;
navSubMenu('view');
document.location = '';
}else // Erreur
console.error('ModuleError::'+answer.ModuleError);

View File

@ -4,7 +4,7 @@ if(null!=section.view.element){1<pageManager.vars.length&&!isNaN(pageManager.var
".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(b){0==b.ModuleError&&(console.log("Machine cree!"),pageManager.vars=["view",b.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));
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=
@ -14,5 +14,5 @@ api.send({path:"machineDefault/delete",id_machine:section.remove.input.search.id
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,
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)};
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();if(""!=section.edit.input.search.id.value){var b={path:"machineDefault/edit",id_machine:section.edit.input.search.id.value,
name:section.edit.input.name.value};api.send(b,function(a){0==a.ModuleError&&1==a.status?(console.log("Machine modifiee!"),section.edit.input.submit.anim("active",1500),pageManager.vars[1]=b.id_machine,navSubMenu("view"),document.location=""):console.error("ModuleError::"+a.ModuleError)})}},!1)};

View File

@ -563,8 +563,12 @@ if( section.edit.element != null ){
console.log('Machine modifiee!');
section.edit.input.submit.anim('active', 1500);
// On met a jour la machine
autofill_edit(section.edit.input.search.id.value);
pageManager.vars[1] = request.id_machine;
navSubMenu('view');
document.location = '';
}else // Erreur
console.error('ModuleError::'+answer.ModuleError);

View File

@ -17,5 +17,5 @@ a;section.edit.input.code.value=b;section.edit.input.username.value=d;section.ed
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)};
if(""!=section.edit.input.search.id.value){var 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),pageManager.vars[1]=b.id_user,navSubMenu("view"),document.location=""):console.error("ModuleError::"+a.ModuleError)})}},!1)};

View File

@ -615,7 +615,9 @@ if( section.edit.element != null ){
section.edit.input.submit.anim('active', 1500);
// On met a jour l'utilisateur
autofill_edit(section.edit.input.search.id.value);
pageManager.vars[1] = request.id_user;
navSubMenu('view');
document.location = '';
}else // Erreur
console.error('ModuleError::'+answer.ModuleError);