diff --git a/conf/db_struct.php b/conf/db_struct.php
index 6ab2c56..d9cbcb0 100644
--- a/conf/db_struct.php
+++ b/conf/db_struct.php
@@ -32,6 +32,12 @@ define('PANIERS_TYPES_TABLE_STRUCT', array(
"del" => array( "type" => "bool", "default" => 0 )
));
+function getCountPaniersTypesListSelectBaseSQL() {
+ return "SELECT count(*) as nb"
+ ." FROM ".PANIERS_TYPES_TABLE
+ ." LEFT JOIN ".PANIERS_GROUPES_TABLE." ON ".PANIERS_TYPES_TABLE.".`groupe`=".PANIERS_GROUPES_TABLE.".`ref`";
+}
+
function getPaniersTypesSelectBaseSQL() {
return "SELECT "
.PANIERS_TYPES_TABLE.".`ref`,"
@@ -63,6 +69,10 @@ define('CLIENTS_TABLE_STRUCT', array(
"del" => array( "type" => "bool", "default" => 0 )
));
+function getCountClientsListSelectBaseSQL() {
+ return "SELECT count(*) as nb FROM ".CLIENTS_TABLE;
+}
+
function getClientsTableSelectBaseSQL() {
return "SELECT "
.CLIENTS_TABLE.".`ref`,"
@@ -138,6 +148,17 @@ define('CONTRATS_TABLE_STRUCT', array(
define('CONTRATS_PANIERS_STATUT',"contrats_paniers_statut");
+function getCountContratsListSelectBaseSQL() {
+ return "SELECT count(*) as nb"
+ ." FROM ".CONTRATS_TABLE
+ ." LEFT JOIN ".CLIENTS_TABLE." ON ".CONTRATS_TABLE.".`client`=".CLIENTS_TABLE.".`ref`"
+ ." LEFT JOIN ".CONTRATS_TYPES_TABLE." ON ".CONTRATS_TABLE.".`type`=".CONTRATS_TYPES_TABLE.".`ref`"
+ ." LEFT JOIN ".PANIERS_GROUPES_TABLE." ON ".CONTRATS_TABLE.".`groupe`=".PANIERS_GROUPES_TABLE.".`ref`"
+ ." LEFT JOIN ".PANIERS_TYPES_TABLE." ON ".CONTRATS_TABLE.".`panier_type`=".PANIERS_TYPES_TABLE.".`ref`"
+ ." LEFT JOIN ".LIEUX_TABLE." ON ".CONTRATS_TABLE.".`lieu_depot`=".LIEUX_TABLE.".`ref`"
+ ." LEFT JOIN ".CONTRATS_PANIERS_STATUT." ON ".CONTRATS_TABLE.".`ref`=".CONTRATS_PANIERS_STATUT.".`ref`";
+}
+
function getContratsTableSelectBaseSQL() {
return "SELECT "
.CONTRATS_TABLE.".`ref`,"
@@ -183,6 +204,23 @@ function buildContratsListSearchSQL($search) {
return $sql;
}
+function buildContratsListFiltresSQL($sql, $filtres) {
+ if(array_key_exists('client', $filtres) && (int)$filtres['client']>0) $sql.=" AND ".CONTRATS_TABLE.".`client`=".intval($filtres['client']);
+ if(array_key_exists('groupe', $filtres) && (int)$filtres['groupe']>0) $sql.=" AND ".CONTRATS_TABLE.".`groupe`=".intval($filtres['groupe']);
+ if(array_key_exists('frequence', $filtres) && $filtres['frequence']!="") {
+ switch($filtres['frequence']) {
+ case 'hebdo' : $sql.=" AND ".CONTRATS_TABLE.".`frequence`='hebdo'"; break;
+ case 'quinz' : $sql.=" AND ".CONTRATS_TABLE.".`frequence`='quinz'"; break;
+ case 'quinz_A' : $sql.=" AND ".CONTRATS_TABLE.".`frequence`='quinz' AND ".CONTRATS_TABLE.".`quinz_groupe`='A'"; break;
+ case 'quinz_B' : $sql.=" AND ".CONTRATS_TABLE.".`frequence`='quinz' AND ".CONTRATS_TABLE.".`quinz_groupe`='B'"; break;
+ }
+ }
+ if(array_key_exists('panier', $filtres) && (int)$filtres['panier']>0) $sql.=" AND ".CONTRATS_TABLE.".`panier_type`=".intval($filtres['panier']);
+ if(array_key_exists('lieu', $filtres) && (int)$filtres['lieu']>0) $sql.=" AND ".CONTRATS_TABLE.".`lieu_depot`=".intval($filtres['lieu']);
+ if(array_key_exists('archive', $filtres) && (int)$filtres['archive']>=0) $sql.=" AND ".CONTRATS_TABLE.".`archive`=".intval($filtres['archive']);
+ return $sql;
+}
+
////////////////////////////////////////////////////////////////////////
// CONTRATS - TYPES ////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
@@ -230,6 +268,10 @@ define('LEGUMES_TABLE_STRUCT', array(
"del" => array( "type" => "bool", "default" => 0 )
));
+function getCountLegumesListSelectBaseSQL() {
+ return "SELECT count(*) as nb FROM ".LEGUMES_TABLE;
+}
+
function getLegumesTableSelectBaseSQL() {
return "SELECT "
.LEGUMES_TABLE.".`ref`,"
@@ -254,9 +296,11 @@ define('LEGUMES_TARIFS_UNITES_ACRONYMES',array( 'kg' => 'kg', 'pièce' => 'pc',
define('LEGUMES_TARIFS_TABLE',"legumes_tarifs");
define('LEGUMES_TARIFS_TABLE_STRUCT', array(
"legume" => array( "type" => "int", "min" => 1, "max" => NULL, "default" => NULL, "force_default_under_min" => true ),
+ "groupe" => array( "type" => "int", "min" => 1, "max" => NULL, "default" => NULL, "force_default_under_min" => true ),
"prix" => array( "type" => "float", "min" => 0, "max" => 999.99, "default" => 0, "force_default_under_min" => true ),
"unite" => array( "type" => "set", "values" => LEGUMES_TARIFS_UNITES, "default" => "poids" ),
"date" => array( "type" => "date", "default" => "today" ),
+ "archive" => array( "type" => "bool", "default" => 0 ),
"del" => array( "type" => "bool", "default" => 0 )
));
@@ -265,12 +309,15 @@ function getLegumesTarifsTableSelectBaseSQL() {
.LEGUMES_TARIFS_TABLE.".`ref`,"
.LEGUMES_TARIFS_TABLE.".`legume` as 'legume_ref',"
.LEGUMES_TABLE.".`nom` as 'legume_nom',"
- .LEGUMES_TARIFS_TABLE.".`ref` as 'tarif_ref',"
+ .LEGUMES_TARIFS_TABLE.".`groupe` as 'groupe_ref',"
+ .PANIERS_GROUPES_TABLE.".`nom` as 'groupe_nom',"
.LEGUMES_TARIFS_TABLE.".`prix` as 'tarif_prix',"
.LEGUMES_TARIFS_TABLE.".`unite` as 'tarif_unite',"
- .LEGUMES_TARIFS_TABLE.".`date` as 'tarif_date'"
+ .LEGUMES_TARIFS_TABLE.".`date` as 'tarif_date',"
+ .LEGUMES_TARIFS_TABLE.".`archive`"
." FROM ".LEGUMES_TARIFS_TABLE
- ." LEFT JOIN ".LEGUMES_TABLE." ON ".LEGUMES_TARIFS_TABLE.".`legume`=".LEGUMES_TABLE.".`ref`";
+ ." LEFT JOIN ".LEGUMES_TABLE." ON ".LEGUMES_TARIFS_TABLE.".`legume`=".LEGUMES_TABLE.".`ref`"
+ ." LEFT JOIN ".PANIERS_GROUPES_TABLE." ON ".LEGUMES_TARIFS_TABLE.".`groupe`=".PANIERS_GROUPES_TABLE.".`ref`";
}
////////////////////////////////////////////////////////////////////////
@@ -303,12 +350,19 @@ define('LIVRAISONS_TABLE',"livraisons");
define('LIVRAISONS_TABLE_STRUCT', array(
"paniers_groupe" => array( "type" => "int", "min" => 1, "max" => NULL, "default" => NULL, "force_default_under_min" => true ),
"date" => array( "type" => "date", "default" => "today" ),
- "quinz_groupe" => array( "type" => "set", "values" => ['A', 'B'], "default" => NULL ),
+ "quinz_groupe" => array( "type" => "set", "values" => ['A', 'B'], "default" => NULL ),
"archive" => array( "type" => "bool", "default" => 0 ),
"force_not_archive" => array( "type" => "bool", "default" => 0 ),
"del" => array( "type" => "bool", "default" => 0 )
));
+function getCountLivraisonsListSelectBaseSQL() {
+ return "SELECT count(*) as nb"
+ ." FROM ".LIVRAISONS_TABLE
+ ." LEFT JOIN ".PANIERS_GROUPES_TABLE." ON ".LIVRAISONS_TABLE.".`paniers_groupe`=".PANIERS_GROUPES_TABLE.".`ref`"
+ ." LEFT JOIN ".LIVRAISONS_NB_PANIERS_VIEW." ON ".LIVRAISONS_TABLE.".`ref`=".LIVRAISONS_NB_PANIERS_VIEW.".`ref`";
+}
+
function getLivraisonsTableSelectBaseSQL() {
return "SELECT "
.LIVRAISONS_TABLE.".`ref`,"
diff --git a/conf/settings.php b/conf/settings.php
index fa4b240..f701c11 100644
--- a/conf/settings.php
+++ b/conf/settings.php
@@ -67,6 +67,12 @@ $GLOBALS['db_admin'] = array(
define('AUTO_ARCHIVE_OLD_LIVRAISONS_DELAY',5); // NB DE JOURS
define('AUTO_ARCHIVE_OLD_CONTRATS_DELAY',5); // NB DE JOURS (après le dernier panier livré)
+////////////////////////////////////////////////////////////////////////
+// LISTES - NB DE LIGNE PAR PAGE ///////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+
+define('LIST_NB_LIGNES_PAR_PAGE',30);
+
////////////////////////////////////////////////////////////////////////
// WARNINGS CONTRATS ///////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
diff --git a/functions/functions.php b/functions/functions.php
index 08d907f..5380210 100644
--- a/functions/functions.php
+++ b/functions/functions.php
@@ -2462,6 +2462,23 @@ function getRequestTableDatas($table_structure, $force_default_values=false) {
return $ret;
}
+function buildSqlSearch($sql, $search, $partBuilderFct) {
+ if($search && $search!="" && is_callable($partBuilderFct)) {
+ $parts = explode(" ", $search);
+ if(is_array($parts) && count($parts>0)) {
+ $search_sql = "";
+ foreach($parts as $p) {
+ if($p!="") $search_sql .= (($search_sql!="") ? " OR " : "").$partBuilderFct($p);
+ }
+ if($search_sql!="") {
+ if(strpos($sql, "WHERE")>0) $sql .= " AND (".$search_sql.")";
+ else $sql .= " WHERE (".$search_sql.")";
+ }
+ }
+ }
+ return $sql;
+}
+
function buildTableDatas($table_structure, $datas, $force_default_values=false) {
$ret = array();
foreach($table_structure as $key => $infos) {
diff --git a/functions/functions_clients.php b/functions/functions_clients.php
index 24fdf95..72fd460 100644
--- a/functions/functions_clients.php
+++ b/functions/functions_clients.php
@@ -14,22 +14,24 @@ $allowClientsListOrder = array(
'email' => "email"
);
-function getClientsList($order='nom',$sens='ASC',$simple=false,$search=false) {
+function getNbClientsInList($search=false) {
+ $sql = getCountClientsListSelectBaseSQL()." WHERE ".CLIENTS_TABLE.".`del`=0";
+ $sql = buildSqlSearch($sql, $search, buildClientsListSearchSQL);
+ $r = $GLOBALS['db_admin']['man']->select($sql, 1);
+ if(!$r['erreur']) return intval($r['datas']['nb']);
+ else {
+ $er = "sql: ".$sql."error: ".getReadableVar($r['erreur']);
+ return "Une erreur est survenue durant du nombre d'item dans la liste !".$er;
+ }
+}
+
+function getClientsList($order='nom',$sens='ASC',$simple=false,$search=false,$limits=false) {
$list = array();
$sql = getClientsTableSelectBaseSQL()." WHERE ".CLIENTS_TABLE.".`del`=0";
// SEARCH
- if($search && $search!="") {
- $parts = explode(" ", $search);
- if(is_array($parts) && count($parts>0)) {
- $search_sql = "";
- foreach($parts as $p) {
- if($p!="") $search_sql .= (($search_sql!="") ? " OR " : "").buildClientsListSearchSQL($p);
- }
- if($search_sql!="") $sql .= " AND (".$search_sql.")";
- }
- }
+ $sql = buildSqlSearch($sql, $search, buildClientsListSearchSQL);
// ORDRE
$sql.=" ORDER BY ";
@@ -45,6 +47,9 @@ function getClientsList($order='nom',$sens='ASC',$simple=false,$search=false) {
if($sens=='DESC') $sql .= ' DESC';
else $sql .= ' ASC';
+ // LIMITS
+ if(is_array($limits)) $sql .= " LIMIT ".$limits['start'].", ".$limits['nbItemsByPage'];
+
$r = $GLOBALS['db_admin']['man']->select($sql);
if(!$r['erreur']) {
diff --git a/functions/functions_contrats.php b/functions/functions_contrats.php
index a22fb8d..1fa1a7f 100644
--- a/functions/functions_contrats.php
+++ b/functions/functions_contrats.php
@@ -20,7 +20,19 @@ $allowContratsListOrder = array(
'lieu_depot' => "lieu de dépôt"
);
-function getContratsList($order='id',$sens='ASC', $filtres=array(), $search=false) {
+function getNbContratsInList($filtres=array(), $search=false) {
+ $sql = getCountContratsListSelectBaseSQL()." WHERE ".CONTRATS_TABLE.".`del`=0";
+ $sql = buildContratsListFiltresSQL($sql, $filtres);
+ $sql = buildSqlSearch($sql, $search, buildContratsListSearchSQL);
+ $r = $GLOBALS['db_admin']['man']->select($sql, 1);
+ if(!$r['erreur']) return intval($r['datas']['nb']);
+ else {
+ $er = "sql: ".$sql."error: ".getReadableVar($r['erreur']);
+ return "Une erreur est survenue durant du nombre d'item dans la liste !".$er;
+ }
+}
+
+function getContratsList($order='id', $sens='ASC', $filtres=array(), $search=false, $limits=false) {
// ARCHIVES OLD CONTRATS
archiveOldContrat();
@@ -30,31 +42,10 @@ function getContratsList($order='id',$sens='ASC', $filtres=array(), $search=fals
$sql = getContratsTableSelectBaseSQL()." WHERE ".CONTRATS_TABLE.".`del`=0";
// FILTRES
- if(array_key_exists('client', $filtres) && (int)$filtres['client']>0) $sql.=" AND ".CONTRATS_TABLE.".`client`=".intval($filtres['client']);
- if(array_key_exists('groupe', $filtres) && (int)$filtres['groupe']>0) $sql.=" AND ".CONTRATS_TABLE.".`groupe`=".intval($filtres['groupe']);
- if(array_key_exists('frequence', $filtres) && $filtres['frequence']!="") {
- switch($filtres['frequence']) {
- case 'hebdo' : $sql.=" AND ".CONTRATS_TABLE.".`frequence`='hebdo'"; break;
- case 'quinz' : $sql.=" AND ".CONTRATS_TABLE.".`frequence`='quinz'"; break;
- case 'quinz_A' : $sql.=" AND ".CONTRATS_TABLE.".`frequence`='quinz' AND ".CONTRATS_TABLE.".`quinz_groupe`='A'"; break;
- case 'quinz_B' : $sql.=" AND ".CONTRATS_TABLE.".`frequence`='quinz' AND ".CONTRATS_TABLE.".`quinz_groupe`='B'"; break;
- }
- }
- if(array_key_exists('panier', $filtres) && (int)$filtres['panier']>0) $sql.=" AND ".CONTRATS_TABLE.".`panier_type`=".intval($filtres['panier']);
- if(array_key_exists('lieu', $filtres) && (int)$filtres['lieu']>0) $sql.=" AND ".CONTRATS_TABLE.".`lieu_depot`=".intval($filtres['lieu']);
- if(array_key_exists('archive', $filtres) && (int)$filtres['archive']>=0) $sql.=" AND ".CONTRATS_TABLE.".`archive`=".intval($filtres['archive']);
-
+ $sql = buildContratsListFiltresSQL($sql, $filtres);
+
// SEARCH
- if($search && $search!="") {
- $parts = explode(" ", $search);
- if(is_array($parts) && count($parts>0)) {
- $search_sql = "";
- foreach($parts as $p) {
- if($p!="") $search_sql .= (($search_sql!="") ? " OR " : "").buildContratsListSearchSQL($p);
- }
- if($search_sql!="") $sql .= " AND (".$search_sql.")";
- }
- }
+ $sql = buildSqlSearch($sql, $search, buildContratsListSearchSQL);
// ORDRE
$sql.=" ORDER BY ";
@@ -75,6 +66,9 @@ function getContratsList($order='id',$sens='ASC', $filtres=array(), $search=fals
// SENS
if($sens=='DESC') $sql .= ' DESC';
else $sql .= ' ASC';
+
+ // LIMITS
+ if(is_array($limits)) $sql .= " LIMIT ".$limits['start'].", ".$limits['nbItemsByPage'];
$r = $GLOBALS['db_admin']['man']->select($sql);
diff --git a/functions/functions_legumes.php b/functions/functions_legumes.php
index cb4b2de..25d8656 100644
--- a/functions/functions_legumes.php
+++ b/functions/functions_legumes.php
@@ -13,22 +13,24 @@ $allowLegumesListOrder = array(
'date' => "date"
);
-function getLegumesList($order='nom',$sens='ASC', $search=false) {
+function getNbLegumesInList($search=false) {
+ $sql = getCountLegumesListSelectBaseSQL()." WHERE ".LEGUMES_TABLE.".`del`=0";
+ $sql = buildSqlSearch($sql, $search, buildLegumesListSearchSQL);
+ $r = $GLOBALS['db_admin']['man']->select($sql, 1);
+ if(!$r['erreur']) return intval($r['datas']['nb']);
+ else {
+ $er = "sql: ".$sql."error: ".getReadableVar($r['erreur']);
+ return "Une erreur est survenue durant du nombre d'item dans la liste !".$er;
+ }
+}
+
+function getLegumesList($order='nom',$sens='ASC', $search=false, $limits=false) {
$list = array();
$sql = getLegumesTableSelectBaseSQL()." WHERE ".LEGUMES_TABLE.".`del`=0";
// SEARCH
- if($search && $search!="") {
- $parts = explode(" ", $search);
- if(is_array($parts) && count($parts>0)) {
- $search_sql = "";
- foreach($parts as $p) {
- if($p!="") $search_sql .= (($search_sql!="") ? " OR " : "").buildLegumesListSearchSQL($p);
- }
- if($search_sql!="") $sql .= " AND (".$search_sql.")";
- }
- }
+ $sql = buildSqlSearch($sql, $search, buildLegumesListSearchSQL);
// ORDRE
$sql.=" ORDER BY ";
@@ -43,6 +45,9 @@ function getLegumesList($order='nom',$sens='ASC', $search=false) {
if($sens=='DESC') $sql .= ' DESC';
else $sql .= ' ASC';
+ // LIMITS
+ if(is_array($limits)) $sql .= " LIMIT ".$limits['start'].", ".$limits['nbItemsByPage'];
+
$r = $GLOBALS['db_admin']['man']->select($sql);
if(!$r['erreur']) {
@@ -185,6 +190,40 @@ function eraseLegume($id) {
// LEGUMES - TARIFS ////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
+function getLegumeTarifs($legume) {
+ $list = array();
+
+
+
+ return $list;
+}
+
+function getLegumeTarif($legume, $groupe) {
+ $i = array();
+
+ $sql = getLegumesTarifsTableSelectBaseSQL()
+ ." WHERE ".LEGUMES_TARIFS_TABLE.".`legume`=".intval($legume);
+
+ if($groupe>0) $sql .= " AND ".LEGUMES_TARIFS_TABLE.".`groupe`=".intval($groupe);
+ else $sql .= " AND ".LEGUMES_TARIFS_TABLE.".`groupe` IS NULL";
+
+ $r = $GLOBALS['db_admin']['man']->select($sql,1);
+
+ if(!$r['erreur']) {
+ $i = $r['datas'];
+
+ $i["tarif_print"] = $i["tarif_prix"]." €/".$i["tarif_unite"];
+ $i["tarif_date_print"] = formatDate($i["tarif_date"], "mysql_date", "print_date");
+ }
+ else {
+ $er = "sql: ".$sql."error: ".getReadableVar($r['erreur']);
+ $GLOBALS['errors'][] = "Une erreur est survenue durant la récupération des informations du légume dans le base de données !".$er;
+ }
+
+ return $i;
+
+}
+
function addLegumeTarif($datas) {
return addDatasInTable(
$GLOBALS['db_admin']['man'], // DB MANAGER
diff --git a/functions/functions_livraisons.php b/functions/functions_livraisons.php
index 66e53d2..ecf51c1 100644
--- a/functions/functions_livraisons.php
+++ b/functions/functions_livraisons.php
@@ -14,7 +14,19 @@ $allowLivraisonsListOrder = array(
'nb_paniers' => "nb. de paniers"
);
-function getLivraisonsList($order='id',$sens='ASC', $groupe=0, $archive=0) {
+function getNbLivraisonsInList($groupe=0, $archive=0) {
+ $sql = getCountLivraisonsListSelectBaseSQL()." WHERE ".LIVRAISONS_TABLE.".`del`=0";
+ if((int)$groupe>0) $sql.=" AND ".LIVRAISONS_TABLE.".`paniers_groupe`=".intval($groupe);
+ if((int)$archive>=0) $sql.=" AND ".LIVRAISONS_TABLE.".`archive`=".intval($archive);
+ $r = $GLOBALS['db_admin']['man']->select($sql, 1);
+ if(!$r['erreur']) return intval($r['datas']['nb']);
+ else {
+ $er = "sql: ".$sql."error: ".getReadableVar($r['erreur']);
+ return "Une erreur est survenue durant du nombre d'item dans la liste !".$er;
+ }
+}
+
+function getLivraisonsList($order='id',$sens='ASC', $groupe=0, $archive=0, $limits=false) {
// ARCHIVES OLD LIVRAISONS
archiveOldLivraison();
@@ -41,6 +53,9 @@ function getLivraisonsList($order='id',$sens='ASC', $groupe=0, $archive=0) {
if($sens=='DESC') $sql .= ' DESC';
else $sql .= ' ASC';
+ // LIMITS
+ if(is_array($limits)) $sql .= " LIMIT ".$limits['start'].", ".$limits['nbItemsByPage'];
+
$r = $GLOBALS['db_admin']['man']->select($sql);
if(!$r['erreur']) {
diff --git a/functions/functions_paniers_groupes.php b/functions/functions_paniers_groupes.php
index efce23d..2c71b37 100644
--- a/functions/functions_paniers_groupes.php
+++ b/functions/functions_paniers_groupes.php
@@ -14,7 +14,7 @@ $allowPaniersGroupesListOrder = array(
function getPaniersGroupesList($order='nom',$sens='ASC', $search=false) {
$list = array();
- $sql = getPaniersGroupesSelectBaseSQL()." WHERE ".PANIERS_GROUPES_TABLE.".`ref`>0";
+ $sql = getPaniersGroupesSelectBaseSQL()." WHERE ".PANIERS_GROUPES_TABLE.".`del`=0";
// SEARCH
if($search && $search!="") {
diff --git a/functions/functions_paniers_types.php b/functions/functions_paniers_types.php
index 0a72db0..07382bc 100644
--- a/functions/functions_paniers_types.php
+++ b/functions/functions_paniers_types.php
@@ -13,22 +13,25 @@ $allowPaniersTypesListOrder = array(
'valeur' => 'valeur'
);
-function getPaniersTypesList($order='nom',$sens='ASC', $search=false, $groupe=0) {
+function getNbPaniersInList($search=false, $groupe=0) {
+ $sql = getCountPaniersTypesListSelectBaseSQL()." WHERE ".PANIERS_TYPES_TABLE.".`del`=0";
+ $sql = buildSqlSearch($sql, $search, buildPaniersTypesListSearchSQL);
+ if($groupe>0) $sql .= " AND ".PANIERS_TYPES_TABLE.".`groupe`=".intval($groupe);
+ $r = $GLOBALS['db_admin']['man']->select($sql, 1);
+ if(!$r['erreur']) return intval($r['datas']['nb']);
+ else {
+ $er = "sql: ".$sql."error: ".getReadableVar($r['erreur']);
+ return "Une erreur est survenue durant du nombre d'item dans la liste !".$er;
+ }
+}
+
+function getPaniersTypesList($order='nom',$sens='ASC', $search=false, $groupe=0, $limits=false) {
$list = array();
- $sql = getPaniersTypesSelectBaseSQL()." WHERE ".PANIERS_TYPES_TABLE.".`ref`>0";
+ $sql = getPaniersTypesSelectBaseSQL()." WHERE ".PANIERS_TYPES_TABLE.".`del`=0";
// SEARCH
- if($search && $search!="") {
- $parts = explode(" ", $search);
- if(is_array($parts) && count($parts>0)) {
- $search_sql = "";
- foreach($parts as $p) {
- if($p!="") $search_sql .= (($search_sql!="") ? " OR " : "").buildPaniersTypesListSearchSQL($p);
- }
- if($search_sql!="") $sql .= " AND (".$search_sql.")";
- }
- }
+ $sql = buildSqlSearch($sql, $search, buildPaniersTypesListSearchSQL);
// GROUPE
if($groupe>0) $sql .= " AND ".PANIERS_TYPES_TABLE.".`groupe`=".intval($groupe);
@@ -46,6 +49,9 @@ function getPaniersTypesList($order='nom',$sens='ASC', $search=false, $groupe=0)
if($sens=='DESC') $sql .= ' DESC';
else $sql .= ' ASC';
+ // LIMITS
+ if(is_array($limits)) $sql .= " LIMIT ".$limits['start'].", ".$limits['nbItemsByPage'];
+
$r = $GLOBALS['db_admin']['man']->select($sql);
if(!$r['erreur']) {
diff --git a/paniers.sql b/paniers.sql
index 5f4f315..e81f449 100644
--- a/paniers.sql
+++ b/paniers.sql
@@ -163,12 +163,16 @@ DEFAULT CHARSET=utf8;
CREATE TABLE `legumes_tarifs` (
`ref` smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT,
`legume` smallint(5) UNSIGNED NOT NULL,
+ `groupe` smallint(5) UNSIGNED NULL DEFAULT NULL,
`prix` float(5,2) UNSIGNED NOT NULL,
`unite` set('kg','pièce','botte') NOT NULL DEFAULT 'kg',
`date` date NOT NULL,
+ `archive` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
`del` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`ref`),
- CONSTRAINT `legumes_tarifs_legume_fk` FOREIGN KEY (`legume`) REFERENCES `legumes`(`ref`) ON DELETE RESTRICT ON UPDATE RESTRICT,
+ CONSTRAINT `legumes_tarifs_legume_fk` FOREIGN KEY (`legume`) REFERENCES `legumes`(`ref`) ON DELETE RESTRICT ON UPDATE RESTRICT,
+ CONSTRAINT `legumes_tarifs_groupe_fk` FOREIGN KEY (`groupe`) REFERENCES `paniers_groupes`(`ref`) ON DELETE RESTRICT ON UPDATE RESTRICT,
+ INDEX (`archive`),
INDEX (`del`)
)
ENGINE=InnoDB
diff --git a/public_html_admin/clients.php b/public_html_admin/clients.php
index dfe8b21..b561fef 100644
--- a/public_html_admin/clients.php
+++ b/public_html_admin/clients.php
@@ -94,13 +94,31 @@ switch($action) {
// AUTOCOMPLETE LIST
case "autocomplete_list": die( json_encode( getClientsAutocompleteList() ) ); break;
// DEFAULT - LIST
- default: {
- // LIST
+ default: {
+ // SEARCH
$search = getSearch("clients_search");
+
+ // LIMITS
+ $limits = array("start" => 0, "end" => LIST_NB_LIGNES_PAR_PAGE, "nbItemsByPage" => LIST_NB_LIGNES_PAR_PAGE, "max" => getNbClientsInList($search));
+ if(isset($_REQUEST['startListAt']) && (int)$_REQUEST['startListAt']>0) {
+ $limits['start'] = intval($_REQUEST['startListAt']);
+ $limits['end'] = $limits['start'] + $limits['nbItemsByPage'];
+ if($limits['end'] > $limits['max']) $limits['end'] = $limits['max'];
+ }
+ $limits['rest'] = $limits['max'] - $limits['end'];
+ $GLOBALS['smarty'] -> assign('list_limits',$limits);
+
+ // LIST
$order = getListOrder('clients_list_order', 'clients_list_sens', $allowClientsListOrder, 'prenom');
- $list = getClientsList($order["order"], $order["sens"], false, $search);
+ $list = getClientsList($order["order"], $order["sens"], false, $search, $limits);
$GLOBALS['smarty'] -> assign('list',$list);
+ // LIST PART
+ if(isset($_REQUEST['startListAt']) && (int)$_REQUEST['startListAt']>0) {
+ $limits["list"] = $GLOBALS['smarty']->fetch("clients/clients_list_builder.tpl");
+ die(json_encode($limits));
+ }
+
// TEMPLATE
$GLOBALS['template'] = 'clients/clients_list.tpl';
$jsFiles[] = PUBLIC_HTML_ADMIN.'js/clients.js';
diff --git a/public_html_admin/contrats.php b/public_html_admin/contrats.php
index de09138..7344c84 100644
--- a/public_html_admin/contrats.php
+++ b/public_html_admin/contrats.php
@@ -140,12 +140,30 @@ switch($action) {
"archive" => getRequestAndSessionSave("archive", "livraisons_filtre_archive", "archive", "int", 0, array(-1,0,1))
);
- // LIST
+ // SEARCH
$search = getSearch("contrats_search");
+
+ // LIMITS
+ $limits = array("start" => 0, "end" => LIST_NB_LIGNES_PAR_PAGE, "nbItemsByPage" => LIST_NB_LIGNES_PAR_PAGE, "max" => getNbContratsInList($filtres, $search));
+ if(isset($_REQUEST['startListAt']) && (int)$_REQUEST['startListAt']>0) {
+ $limits['start'] = intval($_REQUEST['startListAt']);
+ $limits['end'] = $limits['start'] + $limits['nbItemsByPage'];
+ if($limits['end'] > $limits['max']) $limits['end'] = $limits['max'];
+ }
+ $limits['rest'] = $limits['max'] - $limits['end'];
+ $GLOBALS['smarty'] -> assign('list_limits',$limits);
+
+ // LIST
$order = getListOrder('contrats_list_order', 'contrats_list_sens', $allowContratsListOrder, 'prenom');
- $list = getContratsList($order["order"], $order["sens"], $filtres, $search);
+ $list = getContratsList($order["order"], $order["sens"], $filtres, $search, $limits);
$GLOBALS['smarty'] -> assign('list',$list);
+ // LIST PART
+ if(isset($_REQUEST['startListAt']) && (int)$_REQUEST['startListAt']>0) {
+ $limits["list"] = $GLOBALS['smarty']->fetch("contrats/contrats_list_builder.tpl");
+ die(json_encode($limits));
+ }
+
// TEMPLATE
$GLOBALS['template'] = 'contrats/contrats_list.tpl';
$jsFiles[] = PUBLIC_HTML_ADMIN.'js/contrats.js';
diff --git a/public_html_admin/css/admin.css b/public_html_admin/css/admin.css
index 838d51e..8c8979a 100644
--- a/public_html_admin/css/admin.css
+++ b/public_html_admin/css/admin.css
@@ -117,6 +117,59 @@ div.intl-tel-input { display: block; }
font-style: italic;
}
+/* LIST */
+
+table.scrollingTableList { margin: 0; }
+
+table.scrollingTableList ::-webkit-scrollbar {
+ -webkit-appearance: none;
+ width: 16px;
+ background-color: rgba(51, 122, 183, .2);
+}
+
+table.scrollingTableList ::-webkit-scrollbar-thumb {
+ border-radius: 4px;
+ background-color: rgba(51, 122, 183, .5);
+ box-shadow: 0 0 1px rgba(51, 122, 183, .5);
+}
+
+table.scrollingTableList tbody { display: block; overflow: auto; margin: 0; }
+
+table.scrollingTableList tbody tr:first-child td { border: none; }
+
+table.scrollingTableList thead, table.scrollingTableList tbody tr {
+ display: table;
+ width: 100%;
+ table-layout: fixed;
+}
+
+table.scrollingTableList:not(.no-scroll) thead { width: calc( 100% - 16px ); }
+
+table.scrollingTableList th.id, table.scrollingTableList td.id { width: 45px; }
+table.scrollingTableList th.groupe, table.scrollingTableList td.groupe { width: 100px; }
+table.scrollingTableList th.valeur, table.scrollingTableList td.valeur { width: 130px; }
+table.scrollingTableList th.tel, table.scrollingTableList td.tel { width: 150px; }
+table.scrollingTableList th.email, table.scrollingTableList td.email { width: 300px; }
+table.scrollingTableList th.contrat_type, table.scrollingTableList td.contrat_type { width: 300px; }
+table.scrollingTableList th.panier_type, table.scrollingTableList td.panier_type { width: 160px; }
+table.scrollingTableList th.date, table.scrollingTableList td.date { width: 140px; }
+table.scrollingTableList th.freq, table.scrollingTableList td.freq { width: 160px; }
+table.scrollingTableList th.lieu, table.scrollingTableList td.lieu { width: 200px; }
+table.scrollingTableList th.items_long, table.scrollingTableList td.items_long { width: 120px; }
+table.scrollingTableList th.items, table.scrollingTableList td.items { width: 55px; }
+table.scrollingTableList th.btn_action, table.scrollingTableList td.td_btn_action { width: 30px; }
+table.scrollingTableList th.btn_action[colspan="2"] { width: 60px; }
+table.scrollingTableList th.btn_action[colspan="3"] { width: 90px; }
+
+table.scrollingTableList td.loader {
+ background-color: rgba(161, 95, 150, .1);
+ height: 100px;
+ background-image: url('../img/wait.svg');
+ background-position: center;
+ background-size: contain;
+ background-repeat: no-repeat;
+}
+
/* FEEDBACKS */
span.form-control-feedback { position: absolute; }
@@ -448,6 +501,22 @@ table.modal-body tr:last-child td:first-child { border-bottom-left-radius: 6px;
table.modal-body tr:last-child th:first-child { border-bottom-left-radius: 6px; }
table.modal-body tr:last-child td:last-child { border-bottom-right-radius: 6px; }
+/* INLINE SELECT MANAGER */
+
+.btnSecondAction {
+ border-radius: 0;
+ border-left: none;
+}
+
+/* FORM TABS */
+
+div.formTabs div.tab:not(.active) { display: none; }
+
+div.formTabs div.tab { overflow-y: scroll; }
+
+div.formTabs table.modal-body tr:first-child th,
+div.formTabs table.modal-body tr:first-child td { border-top: none; }
+
/* PANIER FORM */
.formPanier .btnGroupeSecondAction {
diff --git a/public_html_admin/css/contrats.css b/public_html_admin/css/contrats.css
index 51b674f..0769037 100644
--- a/public_html_admin/css/contrats.css
+++ b/public_html_admin/css/contrats.css
@@ -6,6 +6,8 @@
#modalViewContrat .formContrat { margin: -15px; }
+#modalViewContrat div.tabPaniers table { margin-bottom: 0!important; }
+
/* NAV TABS */
.formContrat ul.nav.nav-tabs { padding-left: 10px; }
diff --git a/public_html_admin/css/livraisons.css b/public_html_admin/css/livraisons.css
index cdf48d1..2aa813d 100644
--- a/public_html_admin/css/livraisons.css
+++ b/public_html_admin/css/livraisons.css
@@ -12,28 +12,28 @@
.formLivraison ul.nav.nav-tabs { padding-left: 10px; }
-div.formLivraisonTabs > div.tab {
+.formLivraison div.formTabs > div.tab {
display: none;
border-bottom-left-radius: 6px;
border-bottom-right-radius: 6px;
overflow-y: scroll;
}
-div.formLivraisonTabs > div.tab.active { display: block; }
+.formLivraison div.formTabs > div.tab.active { display: block; }
-div.formLivraisonTabs > div.tab span.nullChild { display: block; padding: 10px; }
+.formLivraison div.formTabs > div.tab span.nullChild { display: block; padding: 10px; }
/* TAB GENERAL */
-#modalAddLivraison div.formLivraisonTabs > div.tabGeneral,
-#modalEditLivraison div.formLivraisonTabs > div.tabGeneral { padding: 15px; }
+#modalAddLivraison div.formTabs > div.tabGeneral,
+#modalEditLivraison div.formTabs > div.tabGeneral { padding: 15px; }
-div.formLivraisonTabs > div.tabGeneral table,
-div.formLivraisonTabs > div.tabGeneral div.form-group:last-child { margin-bottom: 0; }
+.formLivraison div.formTabs > div.tabGeneral table,
+.formLivraison div.formTabs > div.tabGeneral div.form-group:last-child { margin-bottom: 0; }
-div.formLivraisonTabs > div.tabGeneral table tr:first-child > th,
-div.formLivraisonTabs > div.tabGeneral table tr:first-child > td { border-top: none; }
+.formLivraison div.formTabs > div.tabGeneral table tr:first-child > th,
+.formLivraison div.formTabs > div.tabGeneral table tr:first-child > td { border-top: none; }
-div.formLivraisonTabs > div.tabGeneral table th { width: 160px; }
+.formLivraison div.formTabs > div.tabGeneral table th { width: 160px; }
/* TABLE PANIER */
@@ -71,7 +71,8 @@ div.formLivraisonTabs > div.tabGeneral table th { width: 160px; }
.formLivraison table.panier th.titre small { font-size: 0.75em; font-weight: 400; font-style: italic; }
.formLivraison table.panier th.total { text-align: right; vertical-align: bottom; }
.formLivraison table.panier th.total.unite { text-align: left; }
-.formLivraison table.panier th.action { padding-top: 0!important; }
+.formLivraison table.panier th.action { padding-top: 0!important; text-align: center; }
+.formLivraison table.panier th.action .btnCopyCompo { margin-top: -3px; }
.formLivraison table.panier tr.head > th {
background-color: #3296c8;
@@ -105,26 +106,26 @@ div.formLivraisonTabs > div.tabGeneral table th { width: 160px; }
/* TAB PANIERS */
-div.formLivraisonTabs > div.tabPaniers input[type=checkbox] { cursor: pointer; }
+.formLivraison div.formTabs > div.tabPaniers input[type=checkbox] { cursor: pointer; }
-div.formLivraisonTabs > div.tabPaniers table.panier tbody div.tooltip { max-width: 170px; }
+.formLivraison div.formTabs > div.tabPaniers table.panier tbody div.tooltip { max-width: 170px; }
-div.formLivraisonTabs > div.tabPaniers tr.panier { cursor: pointer; }
-div.formLivraisonTabs > div.tabPaniers tr.panier.absent,
-div.formLivraisonTabs > div.tabPaniers tr.panier.absent input[type=checkbox] { cursor: not-allowed; }
+.formLivraison div.formTabs > div.tabPaniers tr.panier { cursor: pointer; }
+.formLivraison div.formTabs > div.tabPaniers tr.panier.absent,
+.formLivraison div.formTabs > div.tabPaniers tr.panier.absent input[type=checkbox] { cursor: not-allowed; }
/* TAB COMPO */
-div.formLivraisonTabs > div.tabCompo table.panier { margin: 10px 0; }
+.formLivraison div.formTabs > div.tabCompo table.panier { margin: 10px 0; }
-div.formLivraisonTabs > div.tabCompo table.panier tr.legume.editable td.nom,
-div.formLivraisonTabs > div.tabCompo table.panier tr.legume.editable td.quantite { cursor: pointer; }
+.formLivraison div.formTabs > div.tabCompo table.panier tr.legume.editable td.nom,
+.formLivraison div.formTabs > div.tabCompo table.panier tr.legume.editable td.quantite { cursor: pointer; }
/* TAB LEGUMES */
-div.formLivraisonTabs > div.tabLegumes table.panier { margin-top: 10px; }
-div.formLivraisonTabs > div.tabLegumes table.panier th.total.montant { font-size: 1.5em; }
-div.formLivraisonTabs > div.tabLegumes table.panier th.total.unite { font-size: 1.5em; }
+.formLivraison div.formTabs > div.tabLegumes table.panier { margin-top: 10px; }
+.formLivraison div.formTabs > div.tabLegumes table.panier th.total.montant { font-size: 1.5em; }
+.formLivraison div.formTabs > div.tabLegumes table.panier th.total.unite { font-size: 1.5em; }
/* PRINT */
diff --git a/public_html_admin/js/clients.js b/public_html_admin/js/clients.js
index 3e3e7fb..3de3540 100644
--- a/public_html_admin/js/clients.js
+++ b/public_html_admin/js/clients.js
@@ -1,121 +1,80 @@
-// SEARCH
-var clientsSearch = false;
+// SETTINGS
+var clientsConf = {
+ type : "client",
+ baseURL : "clients.php",
+ // LIST
+ list_selector : "#clientsList",
+ // SEARCH
+ search_selector : "#clientsSearch .searchGrp",
+ // VIEW
+ view_modalSelector : "#modalViewClient",
+ view_btnSelector : ".btnViewClient",
+ // ADD
+ add_modalSelector : "#modalAddClient",
+ add_btnSelector : "#btnAddClient",
+ // EDIT
+ edit_modalSelector : "#modalEditClient",
+ edit_btnSelector : ".btnEditClient",
+ // DELETE
+ delete_modalSelector : "#modalDeleteClient",
+ delete_btnSelector : ".btnDeleteClient",
+}
-// VIEW
-var modalViewClient = false;
-var btnViewClient = false;
-var currentViewClient = 0;
+// MODALS
+var modalViewClient = false;
+var modalAddClient = false;
+var modalEditClient = false;
+var modalDeleteClient = false;
-var clientsBaseURL = "clients.php";
-
-// ADD
-var modalAddClient = false;
-var formAddClient = false;
-var btnAddClient = false;
-
-// EDIT
-var modalEditClient = false;
-var formEditClient = false;
-var btnEditClient = false;
-var currentEditClient = 0;
-
-// DELETE
-var modalDeleteClient = false;
-var btnDeleteClient = false;
-var currentDeleteClient = 0;
-
-$(document).ready( function() {
- // INIT SEARCH
- clientsSearch = $("#clientsSearch");
- if(clientsSearch.length>0) initSearchClients();
+$(document).ready( function() {
+ // LIST LOADER
+ initListProgressLoad($(clientsConf.list_selector), clientsConf.baseURL, clientsConf.type+" list");
- // INIT VIEW CLIENT
- modalViewClient = $("#modalViewClient");
- btnViewClient = $(".btnViewClient");
- if(modalViewClient.length>0 && btnViewClient.length>0) {
+ // SEARCH
+ $(clientsConf.search_selector).initSearchGroup();
+
+ // VIEW
+ modalViewClient = $(clientsConf.view_modalSelector);
+ if(modalViewClient.length>0) {
initViewClient();
// VIEW REQUEST
- var id = getUrlParameter("id");
- if(id!==false && parseInt(id)>0) loadDatasInViewClientModal(id);
+ var id = getUrlParameter("ref");
+ if(id!==false && parseInt(id)>0 && current_page == "clients") {
+ modalViewClient_clear(modalViewClient);
+ modalViewClient_loadDatas(modalViewClient, id);
+ }
}
- // INIT ADD CLIENT
- modalAddClient = $("#modalAddClient");
- formAddClient = $("#formAddClient");
- btnAddClient = $("#btnAddClient");
- if(modalAddClient.length>0 && formAddClient.length>0 && btnAddClient.length>0) initAddClient();
-
- // INIT EDIT CLIENT
- modalEditClient = $("#modalEditClient");
- formEditClient = $("#formEditClient");
- btnEditClient = $(".btnEditClient");
- if(modalEditClient.length>0 && formEditClient.length>0 && btnEditClient.length>0) initEditClient();
-
- // INIT DELETE CLIENT
- modalDeleteClient = $("#modalDeleteClient");
- btnDeleteClient = $(".btnDeleteClient");
- if(modalDeleteClient.length>0 && btnDeleteClient.length>0) initDeleteClient();
+ // ADD
+ modalAddClient = $(clientsConf.add_modalSelector);
+ if(modalAddClient.length>0) initAddClient();
+
+ // EDIT
+ modalEditClient = $(clientsConf.edit_modalSelector);
+ if(modalEditClient.length>0) initEditClient();
+
+ // DELETE
+ modalDeleteClient = $(clientsConf.delete_modalSelector);
+ if(modalDeleteClient.length>0) initDeleteClient();
});
-/***** SEARCH CLIENTS *****/
-function initSearchClients() {
- clientsSearch.find("input[name=search]").unbind('keypress').keypress( function(event) {
- if(event.keyCode==13) searchClient(false);
- });
- clientsSearch.find(".btnClearSearch").unbind('click').click( function(event) {
- searchClient(true);
- });
-}
-
-function searchClient(clear) {
- clientsSearch.find("input[name=search]").blur();
- clientsSearch.find(".btnClearSearch").blur();
- if(clear) document.location = "?clearSearch";
- else document.location = "?search="+clientsSearch.find("input[name=search]").val();
-}
-
-/***** VIEW CLIENT *****/
-function initViewClient() {
- // BTN VIEW
- btnViewClient.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
- clearViewClientModal();
- currentViewClient = id;
- loadDatasInViewClientModal(id);
- });
-
- // INIT FORM VIEW
- var form = modalViewClient.find("div.formClient");
+/***** MODAL VIEW *****/
+function initViewClient() {
+ // INIT VIEW BTNs
+ var initBtnFct = function() { modalForm_initBtnView(
+ $(clientsConf.view_btnSelector), // BTNs
+ modalViewClient, // MODAL
+ modalViewClient_clear, // CLEAR FUNCTION
+ modalViewClient_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
// TABS
- form.find("a.formClientTabBtn").click(function(e) {
- e.preventDefault();
-
- // BTN
- if(!$(this).parent().hasClass("active")) {
- form.find("ul.formClientTabs > li").removeClass('active');
- $(this).parent().addClass("active");
- }
-
- // TAB
- var tab = form.find("div.tab."+$(this).attr("tab"));
- if(tab.length>0) {
- if(tab.hasClass("active")) return;
-
- form.find("div.formClientTabs > div.tab").removeClass("active");
- tab.addClass("active");
- }
- });
- resizeFormClient(form);
- $( window ).on( "resize", function() { resizeFormClient(form) });
+ modalForm_initTabs(modalViewClient);
// CANCEL
- modalViewClient.on('hidden.bs.modal', function (e) {
- clearViewClientModal();
- currentViewClient = 0;
- });
+ modalViewClient.on('hidden.bs.modal', function() { modalViewClient_clear(modalViewClient); });
// EMPECHE LA FERMETURE SI ON EST ENTRAIN D'EDITER UNE LIGNE D'ABSENCE
modalViewClient.on('hide.bs.modal', function(e) {
@@ -123,58 +82,55 @@ function initViewClient() {
});
}
-function resizeFormClient(form) {
- var wh = window.innerHeight;
- form.find("div.formClientTabs div.tab").css("max-height", (wh-180)+"px");
-}
+function modalViewClient_loadDatas(modal, id) {
+ $.post(clientsConf.baseURL, { 'ref' : id, 'action' : 'getDatas' }, function(jsonTxt) {
+ var datas = JSON.parse(jsonTxt);
-function loadDatasInViewClientModal(id) {
- datas = {
- 'ref' : id,
- 'action' : 'getDatas'
- };
- $.post( clientsBaseURL, datas, function( result ) {
- var datas = JSON.parse(result);
+ modal.find("small.db_ref > span").html(datas.ref);
- currentViewClient = parseInt(datas.ref);
- modalViewClient.find("small.db_ref > span").html(datas.ref);
-
- modalViewClient.find("td.nom").html(datas.prenom+" "+datas.nom);
- modalViewClient.find("td.tel").html( (datas.tel!="" && datas.tel!=null) ? ''+datas.tel+' ' : "." );
- modalViewClient.find("td.email").html( (datas.email!="" && datas.email!=null) ? ''+datas.email+' ' : ".");
+ modal.find("td.nom").html(datas.prenom+" "+datas.nom);
+ modal.find("td.tel").html( (datas.tel!="" && datas.tel!=null) ? ''+datas.tel+' ' : "." );
+ modal.find("td.email").html( (datas.email!="" && datas.email!=null) ? ''+datas.email+' ' : ".");
// CONTRATS
- $.post(clientsBaseURL, { 'ref' : id, 'action' : 'modalView_getTab', 'tab' : 'contrats' }, function(result) {
- modalViewClient.find("div.tabContrats").html(result);
- }).fail(function() { alert(srvErrorMsg+" (load modal view client - tab contrats)"); });
+ $.post(clientsConf.baseURL, { 'ref' : id, 'action' : 'modalView_getTab', 'tab' : 'contrats' }, function(result) {
+ modal.find("div.tabContrats").html(result);
+ }).fail(function() { alert("ERREUR SERVEUR ! (client modal view - load tab contrats)"); });
// ABSENCES
- loadModalViewTabAbsences();
+ modalViewClient_loadTabAbsences();
- modalViewClient.modal('show');
- }).fail(function() { alert(srvErrorMsg+" (load modal view client)"); });
+ modal.modal('show');
+ }).fail(function() { alert("("+clientsConf.type+" - load modal view)"); });
}
-function clearViewClientModal() {
- modalViewClient.find("small.db_ref > span").html("");
+function modalViewClient_clear(modal) {
+ modal.removeAttr("view_id");
- modalViewClient.find("ul.formClientTabs > li").removeClass('active hide');
- modalViewClient.find("ul.formClientTabs > li:first-child").addClass('active');
- modalViewClient.find("div.formClientTabs > div.tab").removeClass("active");
- modalViewClient.find("div.formClientTabs > div.tab:first-child").addClass("active");
+ modal.find("small.db_ref > span").html("");
- modalViewClient.find("td.nom").html("");
- modalViewClient.find("td.tel").html("");
- modalViewClient.find("td.email").html("");
+ modalForm_resetTabs(modal);
- modalViewClient.find("div.tabContrats").html("");
- modalViewClient.find("div.tabAbsences").html("");
+ modal.find("td.nom").html("");
+ modal.find("td.tel").html("");
+ modal.find("td.email").html("");
+
+ modal.find("div.tabContrats").html("");
+ modal.find("div.tabAbsences").html("");
+
+ modal.find("table.modal-body tfoot").addClass("hide").find("tr:not(.header)").remove();
}
-function initModalViewClientTabAbsences() {
+function modalViewClient_loadTabAbsences() {
+ $.post(clientsConf.baseURL, { 'ref' : modalViewClient.attr("view_id"), 'action' : 'modalView_getTab', 'tab' : 'absences' }, function(result) {
+ modalViewClient.find("div.tabAbsences").html(result);
+ modalViewClient_initTabAbsences();
+ }).fail(function() { alert(srvErrorMsg+" (load modal view client - tab absences)"); });
+}
+
+function modalViewClient_initTabAbsences() {
// BTN ADD ABSENCES
modalViewClient.find("#btnAddAbsence").click(function(e) {
- e.preventDefault();
- $(this).blur();
+ e.preventDefault(); $(this).blur();
var tr = $("
").html( modalViewClient.find("tr.absenceNewRowTemplate").html() );
modalViewClient.find("div.tabAbsences table tbody").append(tr);
@@ -182,14 +138,14 @@ function initModalViewClientTabAbsences() {
nullChild = modalViewClient.find("div.tabAbsences table tbody tr.nullChild");
if(nullChild.length>0) nullChild.remove();
- initModalViewClientAbsenceRow(tr);
+ modalViewClient_initAbsenceRow(tr);
});
// INIT ROWS
- modalViewClient.find("div.tabAbsences table tbody tr.absence").each(function(n,e) { initModalViewClientAbsenceRow($(this)); })
+ modalViewClient.find("div.tabAbsences table tbody tr.absence").each(function(n,e) { modalViewClient_initAbsenceRow($(this)); })
}
-function initModalViewClientAbsenceRow(row) {
+function modalViewClient_initAbsenceRow(row) {
var ref = row.attr("ref"); if(parseInt(ref)>0) ref = parseInt(ref);
var tdDebut = row.find("td.debut"); var tdFin = row.find("td.fin"); var tdRmq = row.find("td.remarque");
@@ -229,24 +185,25 @@ function initModalViewClientAbsenceRow(row) {
var btnDel = row.find("button.btnDeleteAbsence");
btnEdit.click(function(e) {
- e.preventDefault();
- $(this).blur();
+ e.preventDefault(); $(this).blur();
if(modalViewClient.find("tr.editable").length>0 && !row.hasClass("editable")) return;
// SAVE
if(row.hasClass("editable")) {
iptDebut.blur(); iptFin.blur(); iptRmq.blur();
- datas = { 'client' : currentViewClient, 'debut' : debut, 'fin' : fin, 'remarque' : rmq };
+ datas = {
+ 'client' : modalViewClient.attr("view_id"),
+ 'debut' : debut,
+ 'fin' : fin,
+ 'remarque' : rmq
+ };
if(ref=='new') datas.action = "add_client_absence";
else { datas.action = "edit_client_absence"; datas.absence_ref = ref; }
- $.post(clientsBaseURL, datas, function(result) {
- if(parseInt(result)>0) loadModalViewTabAbsences();
- else {
- console.error(result);
- alert(result);
- }
- }).fail(function() { alert(srvErrorMsg+" (modal view client - save absence)"); });
+ $.post(clientsConf.baseURL, datas, function(result) {
+ if(parseInt(result)>0) modalViewClient_loadTabAbsences();
+ else { console.error(result); alert(result); }
+ }).fail(function() { alert("ERREUR SERVEUR ! (modal view client - save absence)"); });
}
// EDIT
else {
@@ -263,8 +220,7 @@ function initModalViewClientAbsenceRow(row) {
});
btnDel.click(function(e) {
- e.preventDefault();
- $(this).blur();
+ e.preventDefault(); $(this).blur();
if(modalViewClient.find("tr.editable").length>0 && !row.hasClass("editable")) return;
// CANCEL
@@ -286,13 +242,10 @@ function initModalViewClientAbsenceRow(row) {
else {
if(!ref>0) return;
if(confirm("Êtes-vous sur de vouloir supprimer cette absence ?")) {
- $.post(clientsBaseURL, { 'action': "delete_client_absence", 'absence_ref': ref }, function(result) {
- if(parseInt(result)>0) loadModalViewTabAbsences();
- else {
- console.error(result);
- alert(result);
- }
- }).fail(function() { alert(srvErrorMsg+" (modal view client - delete absence)"); });
+ $.post(clientsConf.baseURL, { 'action': "delete_client_absence", 'absence_ref': ref }, function(result) {
+ if(parseInt(result)>0) modalViewClient_loadTabAbsences();
+ else { console.error(result); alert(result); }
+ }).fail(function() { alert("ERREUR SERVEUR ! (modal view client - delete absence)"); });
}
}
});
@@ -300,220 +253,148 @@ function initModalViewClientAbsenceRow(row) {
if(ref == "new") row.find("button.btnEditAbsence").click();
}
-function loadModalViewTabAbsences() {
- $.post(clientsBaseURL, { 'ref' : currentViewClient, 'action' : 'modalView_getTab', 'tab' : 'absences' }, function(result) {
- modalViewClient.find("div.tabAbsences").html(result);
- initModalViewClientTabAbsences();
- }).fail(function() { alert(srvErrorMsg+" (load modal view client - tab absences)"); });
-}
-
-/***** FORM CLIENT *****/
-function initFormClient(form) {
- form.on("submit", function(e) { e.preventDefault(); });
+/***** MODAL FORM ADD/EDIT *****/
+function modalFormClient_init(modal) {
+ modal.find("form").on("submit", function(e) { e.preventDefault(); });
// NOM
- initUpperCaseInput(form.find("input[name=nom]"), null, function() { $(this).blur(); });
+ initUpperCaseInput(modal.find("input[name=nom]"), null, function() { $(this).blur(); });
// PRENOM
- initFirstUpperCaseInput(form.find("input[name=prenom]"), null, function() { $(this).blur(); });
+ initFirstUpperCaseInput(modal.find("input[name=prenom]"), null, function() { $(this).blur(); });
// TEL
- initTelInput(form.find("input[name=tel]"), true, "libs/intl-tel-input-15.0.0/build/js/utils.js");
+ initTelInput(modal.find("input[name=tel]"), true, "libs/intl-tel-input-15.0.0/build/js/utils.js");
// EMAIL
- initEmailInput(form.find("input[name=email]"));
+ initEmailInput(modal.find("input[name=email]"));
}
-function loadDatasInFormClientDatas(modal,form,id) {
- datas = {
- 'ref' : id,
- 'action' : 'getDatas'
- };
- $.post( clientsBaseURL, datas, function( result ) {
- var datas = JSON.parse(result);
+function modalFormClient_loadDatas(modal,id) {
+ $.post(clientsConf.baseURL, { 'ref' : id, 'action' : 'getDatas' }, function(jsonTxt) {
+ var datas = JSON.parse(jsonTxt);
+
+ modal.find("input[name=nom]").val(datas.nom);
+ modal.find("input[name=prenom]").val(datas.prenom);
+ modal.find("input[name=tel]").val(datas.tel);
+ modal.find("input[name=email]").val(datas.email);
- form.find("input[name=nom]").val(datas.nom);
- form.find("input[name=prenom]").val(datas.prenom);
- form.find("input[name=tel]").val(datas.tel);
- form.find("input[name=email]").val(datas.email);
-
if(modal) modal.modal('show');
- }).fail(function() { alert(srvErrorMsg+" (form client - load datas)"); });
+ }).fail(function() { alert("("+clientsConf.type+" - load datas in modal form)"); });
}
-function clearFormClientDatas(form) {
- form.find("input[name=nom]").val("");
- form.find("input[name=prenom]").val("");
- form.find("input[name=tel]").val("");
- form.find("input[name=email]").val("");
+function modalFormClient_clear(modal) {
+ modal.removeAttr("edit_id");
+ modal.find("div.modaLoader").removeClass("show");
- // MODALOADER
- form.find("div.modaLoader").removeClass("show");
+ modal.find("input[name=nom]").val("");
+ modal.find("input[name=prenom]").val("");
+ modal.find("input[name=tel]").val("");
+ modal.find("input[name=email]").val("");
}
-// GET FORM DATAS
-
-function getClientFormDatas(form) {
+function modalFormClient_getDatas(modal) {
var datas = {
- 'nom' : form.find("input[name=nom]").val(),
- 'prenom' : form.find("input[name=prenom]").val(),
- 'tel' : form.find("input[name=tel]").intlTelInput("isValidNumber") ? form.find("input[name=tel]").val() : "",
- 'email' : validateEmail(form.find("input[name=email]").val()) ? form.find("input[name=email]").val() : "",
+ 'nom' : modal.find("input[name=nom]").val(),
+ 'prenom' : modal.find("input[name=prenom]").val(),
+ 'tel' : modal.find("input[name=tel]").intlTelInput("isValidNumber") ? modal.find("input[name=tel]").val() : "",
+ 'email' : validateEmail(modal.find("input[name=email]").val()) ? modal.find("input[name=email]").val() : ""
};
return datas;
}
-/***** ADD CLIENT *****/
+function modalFormClient_checkDatas(datas) {
+ if(datas.nom=="" || datas.prenom=="") {
+ alert("ERREUR : au minimum, un nom et un prénom doivent être renseigné !");
+ return false;
+ }
+ return true;
+}
+
+/***** ADD *****/
function initAddClient() {
- // BTN ADD
- btnAddClient.unbind('click').click( function(event) {
- event.preventDefault();
- clearFormClientDatas(formAddClient);
- modalAddClient.modal('show');
- });
+ // INIT FORM
+ modalFormClient_init(modalAddClient);
+
+ // INIT ADD BTN
+ modalForm_initBtnAdd(
+ $(clientsConf.add_btnSelector), // BTN ADD
+ modalAddClient, // MODAL
+ modalFormClient_clear // CLEAR FORM FUNCTION
+ );
- // INIT FORM ADD
- initFormClient(formAddClient);
-
- // SAVE CLIENT
- $(".btnSaveAddClient").unbind('click').click( function(event) {
- event.preventDefault();
-
- var datas = getClientFormDatas(formAddClient);
- if(datas.nom=="" || datas.prenom=="") {
- alert("ERREUR : au minimum, un nom et un prénom doivent être renseigné !");
- return;
- }
-
- datas.action = 'add';
-
- formAddClient.find("div.modaLoader").addClass("show");
- $(".btnSaveAddClient").prop("disabled", true);
-
- $.post( clientsBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- modalAddClient.modal('hide');
- setTimeout(function() {
- document.location.reload();
- },200);
- }
- else {
- console.error(result);
- alert(result);
- formAddClient.find("div.modaLoader").removeClass("show");
- $(".btnSaveAddClient").prop("disabled", false);
- }
- }).fail(function() {
- alert(srvErrorMsg+" (add client)");
- formAddClient.find("div.modaLoader").removeClass("show");
- $(".btnSaveAddClient").prop("disabled", false);
- });
- });
+ // INIT SAVE BTN
+ modalForm_initBtnSaveAdd(
+ modalAddClient.find(".btnSave"), // BTN SAVE
+ clientsConf.type, // ADD TYPE
+ modalAddClient, // MODAL
+ modalFormClient_getDatas, // GET FORM DATAS FUNCTION
+ modalFormClient_checkDatas, // CHECK FORM DATAS FUNCTION
+ clientsConf.baseURL // SAVE URL
+ );
// CANCEL
- modalAddClient.on('hidden.bs.modal', function (e) { clearFormClientDatas(formAddClient); });
+ modalAddClient.on('hidden.bs.modal', function (e) { modalFormClient_clear(modalAddClient); });
}
-/***** EDIT CLIENT *****/
+/***** EDIT *****/
function initEditClient() {
- // BTN EDIT
- btnEditClient.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
- currentEditClient = id;
- clearFormClientDatas(formEditClient);
- loadDatasInFormClientDatas(modalEditClient,formEditClient,id);
- });
-
- // INIT FORM EDIT
- initFormClient(formEditClient);
+ // INIT FORM
+ modalFormClient_init(modalEditClient);
- // SAVE CLIENT
- $(".btnSaveEditClient").unbind('click').click( function(event) {
- event.preventDefault();
-
- if(!currentEditClient>0) return;
-
- var datas = getClientFormDatas(formEditClient);
- if(datas.nom=="" || datas.prenom=="") {
- alert("ERREUR : au minimum, un nom et un prénom doivent être renseigné !");
- return;
- }
-
- datas.action = 'edit';
- datas.ref = currentEditClient;
-
- formEditClient.find("div.modaLoader").addClass("show");
- $(".btnSaveEditClient").prop("disabled", true);
-
- $.post( clientsBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- modalEditClient.modal('hide');
- setTimeout(function() {
- document.location.reload();
- },200);
- }
- else {
- console.error(result);
- alert(result);
- formEditClient.find("div.modaLoader").removeClass("show");
- $(".btnSaveEditClient").prop("disabled", false);
- }
- }).fail(function() {
- alert(srvErrorMsg+" (edit client)");
- formEditClient.find("div.modaLoader").removeClass("show");
- $(".btnSaveEditClient").prop("disabled", false);
- });
- });
+ // INIT EDIT BTNs
+ var initBtnFct = function() { modalForm_initBtnEdit(
+ $(clientsConf.edit_btnSelector), // BTNs
+ modalEditClient, // MODAL
+ modalFormClient_clear, // CLEAR FUNCTION
+ modalFormClient_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
+
+ // INIT SAVE EDIT BTN
+ modalForm_initBtnSaveEdit(
+ modalEditClient.find(".btnSave"), // BTN SAVE
+ clientsConf.type, // EDIT TYPE
+ modalEditClient, // MODAL
+ modalFormClient_getDatas, // GET FORM DATAS FUNCTION
+ modalFormClient_checkDatas, // CHECK FORM DATAS FUNCTION
+ clientsConf.baseURL // SAVE URL
+ );
// CANCEL
- modalEditClient.on('hidden.bs.modal', function (e) {
- clearFormClientDatas(formEditClient);
- currentEditClient = 0;
- });
+ modalEditClient.on('hidden.bs.modal', function (e) { modalFormClient_clear(modalEditClient); });
}
-/***** DELETE CLIENT *****/
+/***** DELETE *****/
function initDeleteClient() {
- // BTN DELETE
- btnDeleteClient.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
- currentDeleteClient = id;
-
- modalDeleteClient.find('b.name').html( $(this).attr('nom') );
-
- modalDeleteClient.modal('show');
- });
-
- // DELETE
- $("#btnDeleteClient").unbind('click').click( function(event) {
- event.preventDefault();
- $(this).blur();
-
- if(!currentDeleteClient>0) return;
-
- var datas = {
- action : 'delete',
- ref : currentDeleteClient
- };
-
- $.post( clientsBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- modalEditClient.modal('hide');
- setTimeout(function() {
- document.location.reload();
- },200);
- }
- else {
- console.error(result);
- alert(result);
- }
- }).fail(function() { alert(srvErrorMsg+" (delete client)"); });
- });
+ // INIT DELETE BTNs
+ var initBtnFct = function() { modalForm_initBtnDelete(
+ $(clientsConf.delete_btnSelector), // BTNs
+ modalDeleteClient, // MODAL
+ modalDeleteClient_clear, // CLEAR MODAL FUNCTION
+ modalDeleteClient_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
+
+ // INIT SAVE DELETE BTN
+ modalForm_initBtnSaveDelete(
+ modalDeleteClient.find(".btnSave"), // BTN SAVE
+ clientsConf.type, // DELETE TYPE
+ modalDeleteClient, // MODAL
+ false, // GET FORM DATAS FUNCTION
+ false, // CHECK FORM DATAS FUNCTION
+ clientsConf.baseURL // SAVE URL
+ );
// CANCEL
- modalDeleteClient.on('hidden.bs.modal', function (e) {
- modalDeleteClient.find('b.name').html("");
- currentDeleteClient = 0;
- });
+ modalDeleteClient.on('hidden.bs.modal', function (e) { modalDeleteClient_clear(); });
+}
+
+function modalDeleteClient_loadDatas(btn, id) {
+ modalDeleteClient.find('b.name').html( btn.attr('nom') );
+ modalDeleteClient.modal('show');
+}
+
+function modalDeleteClient_clear() {
+ modalDeleteClient.removeAttr("delete_id");
+ modalDeleteClient.find('b.name').html("");
}
\ No newline at end of file
diff --git a/public_html_admin/js/contrats.js b/public_html_admin/js/contrats.js
index ce06102..dc99245 100644
--- a/public_html_admin/js/contrats.js
+++ b/public_html_admin/js/contrats.js
@@ -1,186 +1,100 @@
-// SEARCH
-var contratsSearch = false;
+// SETTINGS
+var contratsConf = {
+ type : "contrat",
+ baseURL : "contrats.php",
+ // LIST
+ list_selector : "#contratsList",
+ // SEARCH
+ search_selector : "#contratsSearch .searchGrp",
+ filtres_selector : "#contratsSearch select",
+ // VIEW
+ view_modalSelector : "#modalViewContrat",
+ view_btnSelector : ".btnViewContrat",
+ // ADD
+ add_modalSelector : "#modalAddContrat",
+ add_btnSelector : "#btnAddContrat",
+ // EDIT
+ edit_modalSelector : "#modalEditContrat",
+ edit_btnSelector : ".btnEditContrat",
+ // ARCHIVE
+ archive_modalSelector : "#modalArchiveContrat",
+ archive_btnSelector : ".btnArchiveContrat",
+ unarchive_btnSelector : ".btnUnarchiveContrat",
+ // DELETE
+ delete_modalSelector : "#modalDeleteContrat",
+ delete_btnSelector : ".btnDeleteContrat"
+}
-// VIEW
-var modalViewContrat = false;
-var btnViewContrat = false;
-var currentViewContrat = 0;
-
-var contratsBaseURL = "contrats.php";
-
-// ADD
-var modalAddContrat = false;
-var formAddContrat = false;
-var btnAddContrat = false;
-
-// EDIT
-var modalEditContrat = false;
-var formEditContrat = false;
-var btnEditContrat = false;
-var currentEditContrat = 0;
-
-// ARCHIVE
+// MODALS
+var modalViewContrat = false;
+var modalAddContrat = false;
+var modalEditContrat = false;
var modalArchiveContrat = false;
-var btnArchiveContrat = false;
-var btnUnarchiveContrat = false;
-var currentArchiveContrat = 0;
+var modalDeleteContrat = false;
-// DELETE
-var modalDeleteContrat = false;
-var btnDeleteContrat = false;
-var currentDeleteContrat = 0;
-
-$(document).ready( function() {
- // INIT SEARCH
- contratsSearch = $("#contratsSearch");
- if(contratsSearch.length>0) initSearchContrats();
+$(document).ready( function() {
+ // LIST LOADER
+ initListProgressLoad($(contratsConf.list_selector), contratsConf.baseURL, contratsConf.type+" list");
- // INIT VIEW CONTRAT
- modalViewContrat = $("#modalViewContrat");
- btnViewContrat = $(".btnViewContrat");
- if(modalViewContrat.length>0 && btnViewContrat.length>0) {
+ // SEARCH / FILTRES
+ $(contratsConf.search_selector).initSearchGroup();
+ $(contratsConf.filtres_selector).initFiltreSelect();
+
+ // VIEW
+ modalViewContrat = $(contratsConf.view_modalSelector);
+ if(modalViewContrat.length>0) {
initViewContrat();
// VIEW REQUEST
- var id = getUrlParameter("id");
- if(id!==false && parseInt(id)>0) loadDatasInViewContratModal(id);
+ var id = getUrlParameter("ref");
+ if(id!==false && parseInt(id)>0 && current_page == "contrats") {
+ modalViewContrat_clear(modalViewContrat);
+ modalViewContrat_loadDatas(modalViewContrat, id);
+ }
}
- // INIT ADD CONTRAT
- modalAddContrat = $("#modalAddContrat");
- formAddContrat = $("#formAddContrat");
- btnAddContrat = $("#btnAddContrat");
- if(modalAddContrat.length>0 && formAddContrat.length>0 && btnAddContrat.length>0) initAddContrat();
+ // ADD
+ modalAddContrat = $(contratsConf.add_modalSelector);
+ if(modalAddContrat.length>0) initAddContrat();
+
+ // EDIT
+ modalEditContrat = $(contratsConf.edit_modalSelector);
+ if(modalEditContrat.length>0) initEditContrat();
+
+ // ARCHIVE
+ modalArchiveContrat = $(contratsConf.archive_modalSelector);
+ if(modalArchiveContrat.length>0) initArchiveContrat();
- // INIT EDIT CONTRAT
- modalEditContrat = $("#modalEditContrat");
- formEditContrat = $("#formEditContrat");
- btnEditContrat = $(".btnEditContrat");
- if(modalEditContrat.length>0 && formEditContrat.length>0 && btnEditContrat.length>0) initEditContrat();
-
- // INIT ARCHIVE CONTRAT
- modalArchiveContrat = $("#modalArchiveContrat");
- btnArchiveContrat = $(".btnArchiveContrat");
- btnUnarchiveContrat = $(".btnUnarchiveContrat");
- if(modalArchiveContrat.length>0 && (btnArchiveContrat.length>0 || btnUnarchiveContrat.length>0)) initArchiveContrat();
-
- // INIT DELETE CONTRAT
- modalDeleteContrat = $("#modalDeleteContrat");
- btnDeleteContrat = $(".btnDeleteContrat");
- if(modalDeleteContrat.length>0 && btnDeleteContrat.length>0) initDeleteContrat();
+ // DELETE
+ modalDeleteContrat = $(contratsConf.delete_modalSelector);
+ if(modalDeleteContrat.length>0) initDeleteContrat();
});
-/***** SEARCH CONTRATS *****/
-function initSearchContrats() {
- // SEARCH
- contratsSearch.find("input[name=search]").unbind('keypress').keypress( function(event) {
- if(event.keyCode==13) searchContrat(false);
- });
- contratsSearch.find(".btnClearSearch").unbind('click').click( function(event) {
- searchContrat(true);
- });
-
- // FILTRE GROUPE
- loadValue = contratsSearch.find("select[name=groupe]").attr("load_value");
- contratsSearch.find("select[name=groupe]").change(function(e) {
- $(this).blur();
- document.location = "?groupe="+parseInt($(this).val());
- }).val(loadValue);
-
- // FILTRE FREQUENCE
- loadValue = contratsSearch.find("select[name=frequence]").attr("load_value");
- contratsSearch.find("select[name=frequence]").change(function(e) {
- $(this).blur();
- document.location = "?frequence="+$(this).val();
- }).val(loadValue);
-
- // FILTRE PANIER
- loadValue = contratsSearch.find("select[name=panier]").attr("load_value");
- contratsSearch.find("select[name=panier]").change(function(e) {
- $(this).blur();
- document.location = "?panier="+$(this).val();
- }).val(loadValue);
-
- // FILTRE LIEU
- loadValue = contratsSearch.find("select[name=lieu]").attr("load_value");
- contratsSearch.find("select[name=lieu]").change(function(e) {
- $(this).blur();
- document.location = "?lieu="+parseInt($(this).val());
- }).val(loadValue);
-
- // FILTRE ARCHIVE
- loadValue = contratsSearch.find("select[name=archive]").attr("load_value");
- contratsSearch.find("select[name=archive]").change(function(e) {
- $(this).blur();
- document.location = "?archive="+parseInt($(this).val());
- }).val(loadValue);
-}
-
-function searchContrat(clear) {
- contratsSearch.find("input[name=search]").blur();
- contratsSearch.find(".btnClearSearch").blur();
- if(clear) document.location = "?clearSearch";
- else document.location = "?search="+contratsSearch.find("input[name=search]").val();
-}
-
-/***** VIEW CONTRAT *****/
+/***** MODAL VIEW *****/
function initViewContrat() {
- // BTN VIEW
- btnViewContrat.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
- clearViewContratModal();
- currentViewContrat = id;
- loadDatasInViewContratModal(id);
- });
-
- var form = modalViewContrat.find("div.formContrat");
+ // INIT VIEW BTNs
+ var initBtnFct = function() { modalForm_initBtnView(
+ $(contratsConf.view_btnSelector), // BTNs
+ modalViewContrat, // MODAL
+ modalViewContrat_clear, // CLEAR FUNCTION
+ modalViewContrat_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
// TABS
- form.find("a.formContratTabBtn").click(function(e) {
- e.preventDefault();
-
- // BTN
- if(!$(this).parent().hasClass("active")) {
- form.find("ul.formContratTabs > li").removeClass('active');
- $(this).parent().addClass("active");
- }
-
- // TAB
- var tab = form.find("div.tab."+$(this).attr("tab"));
- if(tab.length>0) {
- if(tab.hasClass("active")) return;
-
- form.find("div.formContratTabs > div.tab").removeClass("active");
- tab.addClass("active");
- }
- });
- resizeFormContrat(form);
- $( window ).on( "resize", function() { resizeFormContrat(form) });
+ modalForm_initTabs(modalViewContrat);
// CANCEL
- modalViewContrat.on('hidden.bs.modal', function (e) {
- clearViewContratModal();
- currentViewContrat = 0;
- });
+ modalViewContrat.on('hidden.bs.modal', function() { modalViewContrat_clear(modalViewContrat); });
}
-function resizeFormContrat(form) {
- var wh = window.innerHeight;
- form.find("div.formContratTabs div.tab").css("max-height", (wh-180)+"px");
-}
+function modalViewContrat_loadDatas(modal, id) {
+ $.post(contratsConf.baseURL, { 'ref' : id, 'action' : 'getDatas' }, function(jsonTxt) {
+ var datas = JSON.parse(jsonTxt);
-function loadDatasInViewContratModal(id) {
- datas = {
- 'ref' : id,
- 'action' : 'getDatas'
- };
- $.post( contratsBaseURL, datas, function( result ) {
- var datas = JSON.parse(result);
+ modal.find("small.db_ref > span").html(datas.ref);
- modalViewContrat.find("small.db_ref > span").html(datas.ref);
-
- modalViewContrat.find("td.type").html(datas.type_nom);
+ modal.find("td.type").html(datas.type_nom);
client = datas.client_prenom+" "+datas.client_nom;
if((datas.client_tel!="" && datas.client_tel!=null) || (datas.client_email!="" && datas.client_email!=null)) {
@@ -192,16 +106,16 @@ function loadDatasInViewContratModal(id) {
else if(datas.client_email!="" && datas.client_email!=null) client += ''+datas.client_email+' ';
client += ")";
}
- modalViewContrat.find("td.client").html(client);
- modalViewContrat.find("td.tel").html((datas.client_tel!="") ? ''+datas.client_tel+' ' : '.');
- modalViewContrat.find("td.email").html((datas.client_email!="") ? ''+datas.client_email+' ' : '.');
+ modal.find("td.client").html(client);
+ modal.find("td.tel").html((datas.client_tel!="") ? ''+datas.client_tel+' ' : '.');
+ modal.find("td.email").html((datas.client_email!="") ? ''+datas.client_email+' ' : '.');
- modalViewContrat.find("td.date").html(datas.date_print);
- modalViewContrat.find("td.frequence").html(datas.frequence_print);
- modalViewContrat.find("td.paniers").html(datas.nb_panier + datas.panier_type);
- modalViewContrat.find("td.panier_type").html(datas.panier_type);
- modalViewContrat.find("td.lieu_depot").html(datas.lieu_depot_nom);
- modalViewContrat.find("td.nb_cheque").html(datas.nb_cheque);
+ modal.find("td.date").html(datas.date_print);
+ modal.find("td.frequence").html(datas.frequence_print);
+ modal.find("td.paniers").html(datas.nb_panier + datas.panier_type);
+ modal.find("td.panier_type").html(datas.panier_type);
+ modal.find("td.lieu_depot").html(datas.lieu_depot_nom);
+ modal.find("td.nb_cheque").html(datas.nb_cheque);
nb_panier_livre = datas.nb_paniers_livres + " / " + datas.nb_paniers;
if(datas.np_paniers_distrib_avt_saisie>0) {
@@ -209,629 +123,201 @@ function loadDatasInViewContratModal(id) {
if(datas.np_paniers_distrib_avt_saisie>1) nb_panier_livre += "s";
nb_panier_livre += " avant la saisie du contrat)";
}
- modalViewContrat.find("td.nb_panier_livre").html(nb_panier_livre);
- modalViewContrat.find("td.nb_panier_restant").html(datas.nb_paniers_restants + " / " + datas.nb_paniers);
+ modal.find("td.nb_panier_livre").html(nb_panier_livre);
+ modal.find("td.nb_panier_restant").html(datas.nb_paniers_restants + " / " + datas.nb_paniers);
// PANIERS
- $.post(contratsBaseURL, { 'ref' : id, 'action' : 'modalView_getTab', 'tab' : 'paniers' }, function(result) {
- modalViewContrat.find("div.tabPaniers").html(result);
- }).fail(function() { alert(srvErrorMsg+" (load modal view client - tab paniers)"); });
+ $.post(contratsConf.baseURL, { 'ref' : id, 'action' : 'modalView_getTab', 'tab' : 'paniers' }, function(result) {
+ modal.find("div.tabPaniers").html(result);
+ }).fail(function() { alert("ERREUR SERVEUR ! (modal view client - load tab paniers)"); });
- modalViewContrat.modal('show');
- }).fail(function() { alert(srvErrorMsg+" (load modal view contrat)"); });
+ modal.modal('show');
+ }).fail(function() { alert("("+contratsConf.type+" - load modal view)"); });
}
-function clearViewContratModal() {
- modalViewContrat.find("small.db_ref > span").html("");
+function modalViewContrat_clear(modal) {
+ modal.removeAttr("view_id");
+ modalForm_resetTabs(modal);
- modalViewContrat.find("ul.formContratTabs > li").removeClass('active hide');
- modalViewContrat.find("ul.formContratTabs > li:first-child").addClass('active');
- modalViewContrat.find("div.formContratTabs > div.tab").removeClass("active");
- modalViewContrat.find("div.formContratTabs > div.tab:first-child").addClass("active");
+ modal.find("small.db_ref > span").html("");
- modalViewContrat.find("td.nom").html("");
- modalViewContrat.find("td.tel").html("");
- modalViewContrat.find("td.email").html("");
+ modal.find("ul.formContratTabs > li").removeClass('active hide');
+ modal.find("ul.formContratTabs > li:first-child").addClass('active');
+ modal.find("div.formContratTabs > div.tab").removeClass("active");
+ modal.find("div.formContratTabs > div.tab:first-child").addClass("active");
- modalViewContrat.find("td.date").html("");
- modalViewContrat.find("td.frequence").html("");
- modalViewContrat.find("td.nb_panier").html("");
- modalViewContrat.find("td.panier_type").html("");
- modalViewContrat.find("td.lieu_depot").html("");
- modalViewContrat.find("td.nb_cheque").html("");
+ modal.find("td.nom").html("");
+ modal.find("td.tel").html("");
+ modal.find("td.email").html("");
- modalViewContrat.find("td.nb_panier_livre").html("");
- modalViewContrat.find("td.nb_panier_restant").html("");
+ modal.find("td.date").html("");
+ modal.find("td.frequence").html("");
+ modal.find("td.nb_panier").html("");
+ modal.find("td.panier_type").html("");
+ modal.find("td.lieu_depot").html("");
+ modal.find("td.nb_cheque").html("");
- modalViewContrat.find("div.tabPaniers").html("");
+ modal.find("td.nb_panier_livre").html("");
+ modal.find("td.nb_panier_restant").html("");
+
+ modal.find("div.tabPaniers").html("");
}
-/***** FORM CONTRAT *****/
-function initFormContrat(form) {
- form.on("submit", function(e) { e.preventDefault(); });
+/***** MODAL FORM ADD/EDIT *****/
+function modalFormContrat_init(modal) {
+ modal.find("form").on("submit", function(e) { e.preventDefault(); });
- // CLIENT
- form.find("input[name=client]").autocomplete({
- html: true,
- delay: 200,
- source: function(requete, reponse) {
- datas = {
- 'action' : 'autocomplete_list',
- 'search' : form.find("input[name=client]").val(),
- 'nohist' : true
- };
- $.post("clients.php", datas, function(jsonTxt) {
- datas = JSON.parse(jsonTxt);
- reponse(datas);
- }).fail(function() { alert(srvErrorMsg+" (form contrat - client autocomplete)"); });
- },
- focus: function(event, ui) { event.preventDefault(); },
- select: function(event, ui) {
- event.preventDefault();
- form.find("input[name=client]").val( ui.item.value ).attr('ref', ui.item.ref).blur();
- }
- });
- form.find("input[name=client]").keydown(function(e) {
- if(e.keyCode==13) { e.preventDefault(); $(this).blur(); }
- else if(parseInt($(this).attr('ref'))>0) $(this).val("").removeAttr('ref');
- });
- form.find("input[name=client]").on("blur", function(e) {
- if(!parseInt($(this).attr('ref'))>0) $(this).val("").removeAttr('ref');
- });
+ // CLIENT AUTOCOMPLETE
+ initAutocompleteInput(
+ modal, // FORMULAIRE
+ modal.find("input[name=client]"), // INPUT
+ "clients.php", // URL
+ 'autocomplete_list', // REQUEST ACTION
+ "(form contrat - client autocomplete)" // ERROR CONTEXT
+ );
// TYPE
- form.find("select[name=type]").change(function(e) {
- $(this).blur();
- // CUSTOM
- if($(this).val() == "custom") {
- form.find("div.custom_type").removeClass("hide");
-
- switchBtnContratTypeAction(form, "save_new");
- switchBtnContratTypeSecondAction(form, "hide");
- }
- // EXISTING
- else if(parseInt($(this).val())>0) {
- switchBtnContratTypeAction(form, "delete");
- switchBtnContratTypeSecondAction(form, "edit");
-
- form.find("div.custom_type").addClass("hide");
-
- sel = $(this).find("option:selected");
- grp = sel.attr('grp');
- freq = sel.attr('freq');
- panier = parseInt( sel.attr('panier') );
- nb_paniers = parseInt( sel.attr('nb_paniers') );
-
- form.find("select[name=groupe]").val(grp);
- form.find("select[name=frequence]").val(freq);
- form.find("select[name=panier_type]").val(panier);
- form.find("input[name=nb_paniers]").val(nb_paniers);
-
- // BTN ACTION
- switchBtnContratTypeAction(form, "delete");
-
- // ADD BTN EDIT
-
- // QUINZE-GROUPE
- if(freq=="quinz") form.find("select[name=quinz_groupe]").parent().removeClass("hide");
- else form.find("select[name=quinz_groupe]").parent().addClass("hide");
- }
- // CHOISIR...
- else {
- switchBtnContratTypeAction(form, "add");
- switchBtnContratTypeSecondAction(form, "hide");
- }
- });
-
- form.find("button.btnContratTypeAction").click(function(e) {
- e.preventDefault();
- $(this).blur();
- // ADD / SAVE NEW
- if($(this).hasClass("add") || $(this).hasClass("save_new")) {
- addInputContratTypeName(form, "add");
- form.find("div.custom_type").removeClass("hide");
-
- switchBtnContratTypeAction(form, "save");
- switchBtnContratTypeSecondAction(form, "cancel");
- }
- // SAVE
- else if($(this).hasClass("save")) {
- var ipt = form.find("input[name=contratTypeName]");
- if(ipt.length>0) {
- var ref = ipt.attr("ref");
-
- var datas = {
- 'nom' : ipt.val(),
- 'groupe' : parseInt(form.find("select[name=groupe]").val()),
- 'frequence' : form.find("select[name=frequence]").val(),
- 'panier_type' : parseInt(form.find("select[name=panier_type]").val()),
- 'panier_type_valeur' : parseFloat(form.find("select[name=panier_type] option:selected").attr("valeur")),
- 'nb_paniers' : parseInt(form.find("input[name=nb_paniers]").val())
- };
-
- if(datas.nom=="" || !datas.groupe>0 || (datas.frequence!="hebdo" && datas.frequence!="quinz") || !datas.panier_type>0 || !datas.nb_paniers>0 || !datas.panier_type_valeur>0) {
- alert("Merci de renseigner tous les critères du contrat !");
- return;
- }
-
- datas.prix_total = datas.panier_type_valeur * datas.nb_paniers;
-
- // ADD CONTRAT TYPE
- if(ref == "new") datas.action = "add_contrats_type";
- // EDIT CONTRAT TYPE
- else if(parseInt(ref)>0) {
- ref = parseInt(ref);
- datas.action = "edit_contrats_type";
- datas.type_ref = ref;
- }
-
- form.find("div.modaLoader").addClass("show");
- form.find("button.btnContratTypeAction").prop("disabled", true);
-
- $.post( contratsBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- switchBtnContratTypeAction(form, "delete");
- switchBtnContratTypeSecondAction(form, "edit");
- removeInputContratTypeName(form);
- form.find("div.custom_type").addClass("hide");
-
- if(ref == "new") ref = parseInt(result);
-
- // REFRESH CONTRATS TYPES LIST
- $.post( contratsBaseURL, {action: "contrats_types_select_list"}, function( result ) {
- form.find("select[name=type]").html(result).val(ref);
- }).fail(function() { alert(srvErrorMsg+" (form contrat - add/edit contrat type - refresh list after)"); });
- }
- else {
- console.error(result);
- alert(result);
- }
- }).always(function() {
- form.find("div.modaLoader").removeClass("show");
- form.find("button.btnContratTypeAction").prop("disabled", false);
- }).fail(function() { alert(srvErrorMsg+" (form contrat - add/edit contrat type)"); });
- }
- }
- // DELETE
- else if($(this).hasClass("delete")) {
- var ref = parseInt(form.find("select[name=type]").val());
- var nom = form.find("select[name=type] option:selected").html();
- if(confirm('Etês vous sûr de vouloir supprimer le type de contrat "'+nom+'" ?')) {
- var datas = { action : 'delete_contrats_type', type_ref : ref };
- $.post( contratsBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- // REFRESH CONTRATS TYPES LIST
- $.post( contratsBaseURL, {action: "contrats_types_select_list"}, function( result ) {
- form.find("select[name=type]").html(result).val("0");
- }).fail(function() { alert(srvErrorMsg+" (form contrat - delete contrat type - refresh list after)"); });
- }
- else {
- console.error(result);
- alert(result);
- }
- }).always(function() {
- form.find("div.modaLoader").removeClass("show");
- form.find("button.btnContratTypeAction").prop("disabled", false);
- }).fail(function() { alert(srvErrorMsg+" (form contrat - delete contrat type)"); });
- }
- }
- });
-
- form.find("button.btnContratTypeSecondAction").click(function(e) {
- e.preventDefault();
- $(this).blur();
- // EDIT
- if($(this).hasClass("edit")) {
- addInputContratTypeName(form, "edit");
- switchBtnContratTypeAction(form, "save");
- switchBtnContratTypeSecondAction(form, "cancel");
- form.find("div.custom_type").removeClass("hide");
- }
- // CANCEL
- else if($(this).hasClass("cancel")) {
- removeInputContratTypeName(form);
- type = form.find("select[name=type]").val();
- // EDIT
- if(parseInt(type)>0) {
- switchBtnContratTypeAction(form, "delete");
- switchBtnContratTypeSecondAction(form, "edit");
- form.find("div.custom_type").addClass("hide");
- }
- // CUSTOM
- else if(type == "custom") {
- switchBtnContratTypeAction(form, "save_new");
- form.find("div.custom_type").removeClass("hide");
- }
- // ADD
- else {
- switchBtnContratTypeAction(form, "add");
- switchBtnContratTypeSecondAction(form, "hide");
- form.find("div.custom_type").addClass("hide");
- }
- }
- });
+ inlineSelectManager_init(
+ modal, // MODAL
+ "contrat", // MODAL FORM NAME
+ modal.find("select[name=type]").parent(), // SELECT GROUPE
+ "le type de contrat", // VALUE NAME
+ contratsConf.baseURL, // URL
+ "type_ref", // REF ATTR
+ "add_contrats_type", // ADD ACTION
+ "edit_contrats_type", // EDIT ACTION
+ "delete_contrats_type", // DELETE ACTION
+ "contrats_types_select_list", // REFRESH LIST ACTION
+ modalFormContrat_contratType_selectClbkFct, // SELECT CLBK FCT
+ modalFormContrat_showCustomType, // ADD CKBK FCT
+ modalFormContrat_showCustomType, // EDIT CKBK FCT
+ modalFormContrat_hideCustomType, // CANCEL CKBK FCT
+ modalFormContrat_contratType_getDatas, // GET DATAS FCT
+ modalFormContrat_contratType_checkDatas, // CHECK DATAS FCT
+ modalFormContrat_hideCustomType // SAVED CLBK FCT
+ );
// GROUPE
- form.find("select[name=groupe]").change(function(e) { refreshPaniersTypesSelectList(form, $(this).val()); });
+ modal.find("select[name=groupe]").change(function(e) { modalFormContrat_refreshPaniersTypesSelectList(modal, $(this).val()); });
- // FREQUENCE
- form.find("select[name=frequence]").change(function(e) {
+ // FREQUENCE => SHOW/HIDE QUINZ GROUPE
+ modal.find("select[name=frequence]").change(function(e) {
freq = $(this).val();
- if(freq=="quinz") form.find("select[name=quinz_groupe]").parent().removeClass("hide");
- else form.find("select[name=quinz_groupe]").parent().addClass("hide");
+ if(freq=="quinz") modal.find("select[name=quinz_groupe]").parent().removeClass("hide");
+ else modal.find("select[name=quinz_groupe]").parent().addClass("hide");
});
// PANIERS TYPE
- form.find("select[name=panier_type]").change(function(e) { $(this).blur(); });
+ modal.find("select[name=panier_type]").change(function(e) { $(this).blur(); });
// LIEU DEPOT
- form.find("select[name=lieu_depot]").change(function(e) {
- $(this).blur();
- // EXISTING
- if(parseInt($(this).val())>0) {
- switchBtnLieuAction(form, "delete");
- switchBtnLieuSecondAction(form, "edit");
- }
- // CHOISIR...
- else {
- switchBtnLieuAction(form, "add");
- switchBtnLieuSecondAction(form, "hide");
- }
- });
-
- form.find("button.btnLieuAction").click(function(e) {
- e.preventDefault();
- $(this).blur();
- // ADD / SAVE NEW
- if($(this).hasClass("add") || $(this).hasClass("save_new")) {
- addInputLieuName(form, "add");
-
- switchBtnLieuAction(form, "save");
- switchBtnLieuSecondAction(form, "cancel");
- }
- // SAVE
- else if($(this).hasClass("save")) {
- var ipt = form.find("input[name=lieuName]");
- if(ipt.length>0) {
- var ref = ipt.attr("ref");
-
- var datas = { 'nom' : ipt.val() };
-
- if(datas.nom=="") {
- alert("Merci de renseigner le nom du lieu !");
- return;
- }
-
- // ADD LIEU
- if(ref == "new") datas.action = "add_lieu";
- // EDIT LIEU
- else if(parseInt(ref)>0) {
- ref = parseInt(ref);
- datas.action = "edit_lieu";
- datas.lieu_ref = ref;
- }
-
- form.find("div.modaLoader").addClass("show");
- form.find("button.btnLieuAction").prop("disabled", true);
-
- $.post( contratsBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- switchBtnLieuAction(form, "delete");
- switchBtnLieuSecondAction(form, "edit");
- removeInputLieuName(form);
-
- if(ref == "new") ref = parseInt(result);
-
- // REFRESH LIEUX LIST
- $.post( contratsBaseURL, {action:"lieux_select_list"}, function( result ) {
- form.find("select[name=lieu_depot]").html(result).val(ref);
- }).fail(function() { alert(srvErrorMsg+" (form contrat - add/edit lieu - refresh list after)"); });
- }
- else {
- console.error(result);
- alert(result);
- }
- }).always(function() {
- form.find("div.modaLoader").removeClass("show");
- form.find("button.btnLieuAction").prop("disabled", false);
- }).fail(function() { alert(srvErrorMsg+" (form contrat - add/edit lieu)"); });
- }
- }
- // DELETE
- else if($(this).hasClass("delete")) {
- var ref = parseInt(form.find("select[name=lieu_depot]").val());
- var nom = form.find("select[name=lieu_depot] option:selected").html();
- if(confirm('Etês vous sûr de vouloir supprimer le lieu de dépôt "'+nom+'" ?')) {
- form.find("div.modaLoader").addClass("show");
- form.find("button.btnLieuAction").prop("disabled", false);
-
- var datas = { action : 'delete_lieu', lieu_ref : ref };
- $.post( contratsBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- // REFRESH CONTRATS TYPES LIST
- $.post( contratsBaseURL, {action: "lieux_select_list"}, function( result ) {
- form.find("select[name=lieu_depot]").html(result).val("0");
- }).fail(function() { alert(srvErrorMsg+" (form contrat - delete lieu - refresh list after)"); });
- }
- else {
- console.error(result);
- alert(result);
- }
- }).always(function() {
- form.find("div.modaLoader").removeClass("show");
- form.find("button.btnLieuAction").prop("disabled", false);
- }).fail(function() { alert(srvErrorMsg+" (form contrat - delete lieu)"); });
- }
- }
- });
-
- form.find("button.btnLieuSecondAction").click(function(e) {
- e.preventDefault();
- $(this).blur();
- // EDIT
- if($(this).hasClass("edit")) {
- addInputLieuName(form, "edit");
- switchBtnLieuAction(form, "save");
- switchBtnLieuSecondAction(form, "cancel");
- }
- // CANCEL
- else if($(this).hasClass("cancel")) {
- removeInputLieuName(form);
- // EDIT
- if(parseInt(form.find("select[name=lieu_depot]").val())>0) {
- switchBtnLieuAction(form, "delete");
- switchBtnLieuSecondAction(form, "edit");
- }
- // ADD
- else {
- switchBtnLieuAction(form, "add");
- switchBtnLieuSecondAction(form, "hide");
- }
- }
- });
+ inlineSelectManager_init(
+ modal, // MODAL
+ "contrat", // MODAL FORM NAME
+ modal.find("select[name=lieu_depot]").parent(), // SELECT GROUPE
+ "le lieu de dépôt", // VALUE NAME
+ contratsConf.baseURL, // URL
+ "lieu_ref", // REF ATTR
+ "add_lieu", // ADD ACTION
+ "edit_lieu", // EDIT ACTION
+ "delete_lieu", // DELETE ACTION
+ "lieux_select_list" // REFRESH LIST ACTION
+ );
// NB PANIERS
- initIntInput(form.find("input[name=nb_paniers]"));
+ initIntInput(modal.find("input[name=nb_paniers]"));
// NB CHEQUE
- initIntInput(form.find("input[name=nb_cheque]"));
+ initIntInput(modal.find("input[name=nb_cheque]"));
// NB PANIER AVANT SAISIE
- initIntInput(form.find("input[name=np_paniers_distrib_avt_saisie]"));
+ initIntInput(modal.find("input[name=np_paniers_distrib_avt_saisie]"));
+
+ modalFormContrat_clear(modal);
}
-function loadDatasInFormContratDatas(modal,form,id) {
- datas = {
- 'ref' : id,
- 'action' : 'getDatas'
- };
- $.post( contratsBaseURL, datas, function( result ) {
- var datas = JSON.parse(result);
+function modalFormContrat_loadDatas(modal,id) {
+ $.post(contratsConf.baseURL, { 'ref' : id, 'action' : 'getDatas' }, function(jsonTxt) {
+ var datas = JSON.parse(jsonTxt);
- form.find("input[name=client]").val(datas.client_prenom+" "+datas.client_nom).attr('ref', datas.client_ref);
+ modal.find("input[name=client]").val(datas.client_prenom+" "+datas.client_nom).attr('ref', datas.client_ref);
- if(parseInt(datas.type_ref) > 0) {
- form.find("select[name=type]").val(datas.type_ref);
- switchBtnContratTypeAction(form, "delete");
- switchBtnContratTypeSecondAction(form, "edit");
- form.find("div.custom_type").addClass("hide");
- }
- else {
- form.find("select[name=type]").val("custom");
- switchBtnContratTypeAction(form, "save_new");
- switchBtnContratTypeSecondAction(form, "hide");
- form.find("div.custom_type").removeClass("hide");
+ inlineSelectManager_setValue(modal.find("select[name=type]").parent(), datas.type_ref);
+ if(!datas.type_ref > 0) {
+ modal.find("select[name=type]").val("custom");
+ modal.find("div.custom_type").removeClass("hide");
+ inlineSelectManager_switchBtnAction(modal.find("div.custom_type").parent(), "save_new");
}
- form.find("select[name=groupe]").val(datas.groupe_ref);
- form.find("select[name=frequence]").val(datas.frequence);
- form.find("select[name=panier_type]").val(datas.panier_type_ref);
- form.find("input[name=nb_paniers]").val(datas.nb_paniers);
+ modal.find("select[name=groupe]").val(datas.groupe_ref);
+ modal.find("select[name=frequence]").val(datas.frequence);
+ modal.find("select[name=panier_type]").val(datas.panier_type_ref);
+ modal.find("input[name=nb_paniers]").val(datas.nb_paniers);
- if(datas.frequence == "quinz") form.find("select[name=quinz_groupe]").parent().removeClass("hide");
- form.find("select[name=quinz_groupe]").val(datas.quinz_groupe);
+ if(datas.frequence == "quinz") modal.find("select[name=quinz_groupe]").parent().removeClass("hide");
+ modal.find("select[name=quinz_groupe]").val(datas.quinz_groupe);
- form.find("input[name=date]").val(datas.date);
+ modal.find("input[name=date]").val(datas.date);
- if(parseInt(datas.lieu_depot_ref) > 0) {
- form.find("select[name=lieu_depot]").val(datas.lieu_depot_ref);
- switchBtnLieuAction(form, "delete");
- switchBtnLieuSecondAction(form, "edit");
- }
- else {
- form.find("select[name=lieu_depot]").val("0");
- switchBtnLieuAction(form, "add");
- switchBtnLieuSecondAction(form, "hide");
- }
+ inlineSelectManager_setValue(modal.find("select[name=lieu_depot]").parent(), datas.lieu_depot_ref);
- form.find("input[name=nb_cheque]").val(datas.nb_cheque);
- form.find("input[name=np_paniers_distrib_avt_saisie]").val(datas.np_paniers_distrib_avt_saisie);
- form.find("input[type=checkbox][name=force_eligible]").prop("checked",datas.force_eligible>0);
+ modal.find("input[name=nb_cheque]").val(datas.nb_cheque);
+ modal.find("input[name=np_paniers_distrib_avt_saisie]").val(datas.np_paniers_distrib_avt_saisie);
+ modal.find("input[type=checkbox][name=force_eligible]").prop("checked",datas.force_eligible>0);
+
if(modal) modal.modal('show');
- }).fail(function() { alert(srvErrorMsg+" (load datas form contrat)"); });
+ }).fail(function() { alert("("+contratsConf.type+" - load datas in modal form)"); });
}
-function clearFormContratDatas(form) {
- form.find("input[name=client]").val("");
-
- form.find("select[name=type]").val("0");
- form.find("div.custom_type").addClass("hide");
- removeInputContratTypeName(form);
- switchBtnContratTypeAction(form, "add");
- switchBtnContratTypeSecondAction(form, "hide");
-
- form.find("select[name=groupe]").val("");
- form.find("select[name=frequence]").val("hebdo");
- form.find("select[name=panier_type]").val("");
- form.find("input[name=nb_paniers]").val("");
-
- form.find("select[name=quinz_groupe]").val("A").parent().addClass("hide");
- form.find("input[name=date]").val(getTodayDate("yyyy-mm-dd"));
-
- form.find("select[name=lieu_depot]").val("0");
- removeInputLieuName(form);
- switchBtnLieuAction(form, "add");
- switchBtnLieuSecondAction(form, "hide");
-
- form.find("input[name=nb_cheque]").val("");
- form.find("input[name=np_paniers_distrib_avt_saisie]").val("");
- form.find("input[type=checkbox][name=force_eligible]").prop("checked",false);
-
- // MODALOADER
- form.find("div.modaLoader").removeClass("show");
-}
-
-function refreshPaniersTypesSelectList(form, groupe) {
+function modalFormContrat_refreshPaniersTypesSelectList(modal, groupe) {
datas = {
'action' : 'select_list',
'groupe' : groupe
};
$.post("paniers.php", datas, function(result) {
- var oldVal = parseInt( form.find("select[name=panier_type]").val() );
- form.find("select[name=panier_type]").html(result);
- if(oldVal>0 && form.find("select[name=panier_type] option[value="+oldVal+"]")) form.find("select[name=panier_type]").val(oldVal);
- }).fail(function() { alert(srvErrorMsg+" (form contrat - refresh paniers types select list)"); });
+ var oldVal = parseInt( modal.find("select[name=panier_type]").val() );
+ modal.find("select[name=panier_type]").html(result);
+ if(oldVal>0 && modal.find("select[name=panier_type] option[value="+oldVal+"]")) modal.find("select[name=panier_type]").val(oldVal);
+ }).fail(function() { alert("ERREUR SERVEUR ! (form contrat - refresh paniers types select list)"); });
}
-// CONTRATS TYPES
-
-function switchBtnContratTypeAction(form, action) { // ADD / SAVE / DELETE
- var btn = form.find("button.btnContratTypeAction");
+function modalFormContrat_clear(modal) {
+ modal.removeAttr("edit_id");
+ modal.find("div.modaLoader").removeClass("show");
- if(action == "add") {
- btn.removeClass("save save_new delete").addClass("add").removeClass("btn-danger btn-primary").addClass("btn-default")
- .find("i").removeClass("glyphicon-floppy-saved glyphicon-floppy-disk glyphicon-trash").addClass("glyphicon-plus");
- }
- else if(action == "save") {
- btn.removeClass("add save_new delete").addClass("save").removeClass("btn-danger btn-default").addClass("btn-primary")
- .find("i").removeClass("glyphicon-plus glyphicon-floppy-disk glyphicon-trash").addClass("glyphicon-floppy-saved");
- }
- else if(action == "save_new") {
- btn.removeClass("add save delete").addClass("save_new").removeClass("btn-danger btn-primary").addClass("btn-default")
- .find("i").removeClass("glyphicon-plus glyphicon-floppy-saved glyphicon-trash").addClass("glyphicon-floppy-disk");
- }
- else if(action == "delete") {
- btn.removeClass("add save_new save").addClass("delete").removeClass("btn-default btn-primary").addClass("btn-danger")
- .find("i").removeClass("glyphicon-plus glyphicon-floppy-saved glyphicon-floppy-disk").addClass("glyphicon-trash");
- }
-}
-
-function switchBtnContratTypeSecondAction(form, action) { // CANCEL / EDIT
- var btn = form.find("button.btnContratTypeSecondAction");
+ modal.find("input[name=client]").val("");
- if(action == "cancel") {
- btn.removeClass("edit").addClass("cancel").removeClass("btn-default").addClass("btn-danger")
- .find("i").removeClass("glyphicon-edit").addClass("glyphicon-floppy-remove");
- btn.parent().removeClass("hide");
- }
- else if(action == "edit") {
- btn.removeClass("cancel").addClass("edit").removeClass("btn-danger").addClass("btn-default")
- .find("i").removeClass("glyphicon-floppy-remove").addClass("glyphicon-edit");
- btn.parent().removeClass("hide");
- }
- else if(action == "hide") {
- btn.parent().addClass("hide");
- }
-}
-
-function addInputContratTypeName(form, action) {
- var select = form.find("select[name=type]");
- var ipt = $(' ').attr("action", action);
- select.addClass("hide");
- ipt.insertBefore(select);
- if(action=="edit") {
- ipt.attr("ref", select.val());
- ipt.val( select.find("option:selected").html() );
- }
- else ipt.attr("ref", "new");
- ipt.focus();
-}
-
-function removeInputContratTypeName(form) {
- var ipt = form.find("input[name=contratTypeName]");
- if(ipt.length>0) ipt.remove();
- form.find("select[name=type]").removeClass("hide");
-}
-
-// LIEUX
-
-function switchBtnLieuAction(form, action) { // ADD / SAVE / DELETE
- var btn = form.find("button.btnLieuAction");
+ inlineSelectManager_setValue(modal.find("select[name=type]").parent(), 0);
- if(action == "add") {
- btn.removeClass("save save_new delete").addClass("add").removeClass("btn-danger btn-primary").addClass("btn-default")
- .find("i").removeClass("glyphicon-floppy-saved glyphicon-trash").addClass("glyphicon-plus");
- }
- else if(action == "save") {
- btn.removeClass("add save_new delete").addClass("save").removeClass("btn-danger btn-default").addClass("btn-primary")
- .find("i").removeClass("glyphicon-plus glyphicon-trash").addClass("glyphicon-floppy-saved");
- }
- else if(action == "delete") {
- btn.removeClass("add save_new save").addClass("delete").removeClass("btn-default btn-primary").addClass("btn-danger")
- .find("i").removeClass("glyphicon-plus glyphicon-floppy-saved").addClass("glyphicon-trash");
- }
-}
-
-function switchBtnLieuSecondAction(form, action) { // CANCEL / EDIT
- var btn = form.find("button.btnLieuSecondAction");
+ modal.find("select[name=groupe]").val("");
+ modal.find("select[name=frequence]").val("hebdo");
+ modal.find("select[name=panier_type]").val("");
+ modal.find("input[name=nb_paniers]").val("");
- if(action == "cancel") {
- btn.removeClass("edit").addClass("cancel").removeClass("btn-default").addClass("btn-danger")
- .find("i").removeClass("glyphicon-edit").addClass("glyphicon-floppy-remove");
- btn.parent().removeClass("hide");
- }
- else if(action == "edit") {
- btn.removeClass("cancel").addClass("edit").removeClass("btn-danger").addClass("btn-default")
- .find("i").removeClass("glyphicon-floppy-remove").addClass("glyphicon-edit");
- btn.parent().removeClass("hide");
- }
- else if(action == "hide") {
- btn.parent().addClass("hide");
- }
-}
-
-function addInputLieuName(form, action) {
- var select = form.find("select[name=lieu_depot]");
- var ipt = $(' ').attr("action", action);
- select.addClass("hide");
- ipt.insertBefore(select);
- if(action=="edit") {
- ipt.attr("ref", select.val());
- ipt.val( select.find("option:selected").html() );
- }
- else ipt.attr("ref", "new");
- ipt.focus();
+ modal.find("select[name=quinz_groupe]").val("A").parent().addClass("hide");
+ modal.find("input[name=date]").val(getTodayDate("yyyy-mm-dd"));
- ipt.keypress(function(e) {
- if(e.keyCode==13) {
- e.preventDefault();
- form.find("button.btnLieuAction").click();
- }
- });
+ inlineSelectManager_setValue(modal.find("select[name=lieu_depot]").parent(), 0);
+
+ modal.find("input[name=nb_cheque]").val("");
+ modal.find("input[name=np_paniers_distrib_avt_saisie]").val("");
+ modal.find("input[type=checkbox][name=force_eligible]").prop("checked",false);
}
-function removeInputLieuName(form) {
- var ipt = form.find("input[name=lieuName]");
- if(ipt.length>0) ipt.remove();
- form.find("select[name=lieu_depot]").removeClass("hide");
-}
-
-// GET FORM DATAS
-
-function getContratFormDatas(form) {
+function modalFormContrat_getDatas(modal) {
var datas = {
- 'client' : parseInt(form.find("input[name=client]").attr('ref')),
- 'type' : parseInt(form.find("select[name=type]").val()),
- 'groupe' : parseInt(form.find("select[name=groupe]").val()),
- 'frequence' : form.find("select[name=frequence]").val(),
- 'panier_type' : parseInt(form.find("select[name=panier_type]").val()),
- 'nb_paniers' : parseInt(form.find("input[name=nb_paniers]").val()),
- 'quinz_groupe' : form.find("select[name=quinz_groupe]").val(),
- 'date' : form.find("input[name=date]").val(),
- 'lieu_depot' : parseInt(form.find("select[name=lieu_depot]").val()),
- 'nb_cheque' : parseInt(form.find("input[name=nb_cheque]").val()),
- 'np_paniers_distrib_avt_saisie' : form.find("input[name=np_paniers_distrib_avt_saisie]").val(),
- 'force_eligible' : form.find("input[type=checkbox][name=force_eligible]").prop("checked") ? 1 : 0
+ 'client' : parseInt( modal.find("input[name=client]").attr('ref') ),
+ 'type' : parseInt( modal.find("select[name=type]").val() ),
+ 'groupe' : parseInt( modal.find("select[name=groupe]").val() ),
+ 'frequence' : modal.find("select[name=frequence]").val(),
+ 'panier_type' : parseInt( modal.find("select[name=panier_type]").val() ),
+ 'nb_paniers' : parseInt( modal.find("input[name=nb_paniers]").val() ),
+ 'quinz_groupe' : modal.find("select[name=quinz_groupe]").val(),
+ 'date' : modal.find("input[name=date]").val(),
+ 'lieu_depot' : parseInt( modal.find("select[name=lieu_depot]").val() ),
+ 'nb_cheque' : parseInt( modal.find("input[name=nb_cheque]").val() ),
+ 'np_paniers_distrib_avt_saisie' : modal.find("input[name=np_paniers_distrib_avt_saisie]").val(),
+ 'force_eligible' : modal.find("input[type=checkbox][name=force_eligible]").prop("checked") ? 1 : 0
};
// CHECK TYPE_EXIST
@@ -842,230 +328,214 @@ function getContratFormDatas(form) {
sel+= "[freq="+datas.frequence+"]";
sel+= "[panier="+datas.panier_type+"]";
sel+= "[nb_paniers="+datas.nb_paniers+"]";
- var opt = form.find(sel);
+ var opt = modal.find(sel);
if(opt.length>0) datas.type = parseInt( opt.attr("value") );
}
return datas;
}
-/***** ADD CONTRAT *****/
+function modalFormContrat_checkDatas(datas) {
+ if(datas.nom=="") {
+ alert("ERREUR : au minimum, un nom doit être renseigné !");
+ return false;
+ }
+ return true;
+}
+
+// CONTRAT TYPE
+
+function modalFormContrat_contratType_selectClbkFct(modal, grp, select) {
+ // CUSTOM
+ if(select.val() == "custom") {
+ modal.find("div.custom_type").removeClass("hide");
+
+ inlineSelectManager_switchBtnAction(grp, "save_new");
+ inlineSelectManager_switchBtnSecondAction(grp, "hide");
+ }
+ // EXISTING
+ else if(parseInt(select.val())>0) {
+ modal.find("div.custom_type").addClass("hide");
+
+ sel = select.find("option:selected");
+ grp = sel.attr('grp');
+ freq = sel.attr('freq');
+ panier = parseInt( sel.attr('panier') );
+ nb_paniers = parseInt( sel.attr('nb_paniers') );
+
+ modal.find("select[name=groupe]").val(grp);
+ modal.find("select[name=frequence]").val(freq);
+ modal.find("select[name=panier_type]").val(panier);
+ modal.find("input[name=nb_paniers]").val(nb_paniers);
+
+ // QUINZE-GROUPE
+ if(freq=="quinz") modal.find("select[name=quinz_groupe]").parent().removeClass("hide");
+ else modal.find("select[name=quinz_groupe]").parent().addClass("hide");
+ }
+ // CHOISIR...
+ else modal.find("div.custom_type").addClass("hide");
+}
+
+function modalFormContrat_showCustomType(modal) { modal.find("div.custom_type").removeClass("hide"); }
+
+function modalFormContrat_hideCustomType(modal) { modal.find("div.custom_type").addClass("hide"); }
+
+function modalFormContrat_contratType_getDatas(modal, grp) {
+ var datas = {
+ 'nom' : grp.find("input[name=name]").val(),
+ 'groupe' : parseInt(modal.find("select[name=groupe]").val()),
+ 'frequence' : modal.find("select[name=frequence]").val(),
+ 'panier_type' : parseInt(modal.find("select[name=panier_type]").val()),
+ 'panier_type_valeur' : parseFloat(modal.find("select[name=panier_type] option:selected").attr("valeur")),
+ 'nb_paniers' : parseInt(modal.find("input[name=nb_paniers]").val())
+ };
+ datas.prix_total = datas.panier_type_valeur * datas.nb_paniers;
+ return datas;
+}
+
+function modalFormContrat_contratType_checkDatas(datas) {
+ if(datas.nom=="" || !datas.groupe>0 || (datas.frequence!="hebdo" && datas.frequence!="quinz") || !datas.panier_type>0 || !datas.nb_paniers>0 || !datas.panier_type_valeur>0) {
+ alert("Merci de renseigner tous les critères du contrat !");
+ return false;
+ }
+ return true;
+}
+
+/***** ADD *****/
function initAddContrat() {
- // BTN ADD
- btnAddContrat.unbind('click').click( function(event) {
- event.preventDefault();
- clearFormContratDatas(formAddContrat);
- modalAddContrat.modal('show');
- });
+ // INIT FORM
+ modalFormContrat_init(modalAddContrat);
+
+ // INIT ADD BTN
+ modalForm_initBtnAdd(
+ $(contratsConf.add_btnSelector), // BTN ADD
+ modalAddContrat, // MODAL
+ modalFormContrat_clear // CLEAR FORM FUNCTION
+ );
- // INIT FORM ADD
- initFormContrat(formAddContrat);
-
- // SAVE CONTRAT
- $(".btnSaveAddContrat").unbind('click').click( function(event) {
- event.preventDefault();
-
- var datas = getContratFormDatas(formAddContrat);
-
- if(!datas.client>0 || !datas.type>0 || datas.date=="" || !datas.lieu_depot>0) {
- alert("ERREUR : au minimum un client, un type de contrat, une date et un lieu de dépôt doivent être renseigné !");
- return;
- }
-
- datas.action = 'add';
-
- formAddContrat.find("div.modaLoader").addClass("show");
- $(".btnSaveAddContrat").prop("disabled", true);
-
- $.post( contratsBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- modalAddContrat.modal('hide');
- setTimeout(function() {
- document.location.reload();
- },200);
- }
- else {
- console.error(result);
- alert(result);
- formAddContrat.find("div.modaLoader").removeClass("show");
- $(".btnSaveAddContrat").prop("disabled", false);
- }
- }).fail(function() {
- alert(srvErrorMsg+" (add contrat)");
- formAddContrat.find("div.modaLoader").removeClass("show");
- $(".btnSaveAddContrat").prop("disabled", false);
- });
- });
+ // INIT SAVE BTN
+ modalForm_initBtnSaveAdd(
+ modalAddContrat.find(".btnSave"), // BTN SAVE
+ contratsConf.type, // ADD TYPE
+ modalAddContrat, // MODAL
+ modalFormContrat_getDatas, // GET FORM DATAS FUNCTION
+ modalFormContrat_checkDatas, // CHECK FORM DATAS FUNCTION
+ contratsConf.baseURL // SAVE URL
+ );
// CANCEL
- modalAddContrat.on('hidden.bs.modal', function (e) { clearFormContratDatas(formAddContrat); });
+ modalAddContrat.on('hidden.bs.modal', function (e) { modalFormContrat_clear(modalAddContrat); });
}
-/***** EDIT CONTRAT *****/
+/***** EDIT *****/
function initEditContrat() {
- // BTN EDIT
- btnEditContrat.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
- currentEditContrat = id;
- clearFormContratDatas(formEditContrat);
- loadDatasInFormContratDatas(modalEditContrat,formEditContrat,id);
- });
-
- // INIT FORM EDIT
- initFormContrat(formEditContrat);
+ // INIT FORM
+ modalFormContrat_init(modalEditContrat);
- // SAVE CONTRAT
- $(".btnSaveEditContrat").unbind('click').click( function(event) {
- event.preventDefault();
-
- if(!currentEditContrat>0) return;
-
- var datas = getContratFormDatas(formEditContrat);
- if(!datas.client>0 || !datas.type>0 || datas.date=="" || !datas.lieu_depot>0) {
- alert("ERREUR : au minimum un client, un type de contrat, une date et un lieu de dépôt doivent être renseigné !");
- return;
- }
-
- datas.action = 'edit';
- datas.ref = currentEditContrat;
-
- formEditContrat.find("div.modaLoader").addClass("show");
- $(".btnSaveEditContrat").prop("disabled", true);
-
- $.post( contratsBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- modalEditContrat.modal('hide');
- setTimeout(function() {
- document.location.reload();
- },200);
- }
- else {
- console.error(result);
- alert(result);
- formEditContrat.find("div.modaLoader").removeClass("show");
- $(".btnSaveEditContrat").prop("disabled", false);
- }
- }).fail(function() {
- alert(srvErrorMsg+" (edit contrat)");
- formEditContrat.find("div.modaLoader").removeClass("show");
- $(".btnSaveEditContrat").prop("disabled", false);
- });
- });
+ // INIT EDIT BTNs
+ var initBtnFct = function() { modalForm_initBtnEdit(
+ $(contratsConf.edit_btnSelector), // BTNs
+ modalEditContrat, // MODAL
+ modalFormContrat_clear, // CLEAR FUNCTION
+ modalFormContrat_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
+
+ // INIT SAVE EDIT BTN
+ modalForm_initBtnSaveEdit(
+ modalEditContrat.find(".btnSave"), // BTN SAVE
+ contratsConf.type, // EDIT TYPE
+ modalEditContrat, // MODAL
+ modalFormContrat_getDatas, // GET FORM DATAS FUNCTION
+ modalFormContrat_checkDatas, // CHECK FORM DATAS FUNCTION
+ contratsConf.baseURL // SAVE URL
+ );
// CANCEL
- modalEditContrat.on('hidden.bs.modal', function (e) {
- clearFormContratDatas(formEditContrat);
- currentEditContrat = 0;
- });
+ modalEditContrat.on('hidden.bs.modal', function (e) { modalFormContrat_clear(modalEditContrat); });
}
-/***** ARCHIVE CONTRAT *****/
+/***** ARCHIVE *****/
function initArchiveContrat() {
- // BTN ARCHIVE
- btnArchiveContrat.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
- currentArchiveContrat = id;
- modalArchiveContrat.find('b.ref').html( "#"+$(this).attr('ref') );
- modalArchiveContrat.find('b.name').html( $(this).attr('nom') );
- modalArchiveContrat.modal('show');
- });
+ // INIT ARCHIVE BTNs
+ var initBtnFct = function() { modalForm_initBtnArchive(
+ $(contratsConf.archive_btnSelector), // BTNs
+ modalArchiveContrat, // MODAL
+ modalArchiveContrat_clear, // CLEAR MODAL FUNCTION
+ modalArchiveContrat_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
- // ARCHIVE
- $("#btnArchiveContrat").unbind('click').click( function(event) {
- event.preventDefault();
- $(this).blur();
-
- if(!currentArchiveContrat>0) return;
-
- var datas = {
- action : 'archive',
- ref : currentArchiveContrat
- };
-
- $.post( contratsBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- modalArchiveContrat.modal('hide');
- setTimeout(function() { document.location.reload(); },200);
- }
- else {
- console.error(result);
- alert(result);
- }
- }).fail( function() { alert(srvErrorMsg+" (archive contrat)"); });
- });
+ // INIT UNARCHIVE BTNs
+ var initUnBtnFct = function() { modalForm_initBtnUnarchive(
+ $(contratsConf.unarchive_btnSelector), // BTNs
+ contratsConf.type, // DELETE TYPE
+ modalArchiveContrat, // MODAL
+ contratsConf.baseURL // SAVE URL
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initUnBtnFct );
+ initUnBtnFct();
+
+ // INIT SAVE DELETE BTN
+ modalForm_initBtnSaveArchive(
+ modalArchiveContrat.find(".btnSave"), // BTN SAVE
+ contratsConf.type, // DELETE TYPE
+ modalArchiveContrat, // MODAL
+ contratsConf.baseURL // SAVE URL
+ );
// CANCEL
- modalArchiveContrat.on('hidden.bs.modal', function (e) {
- modalArchiveContrat.find('b.date').html("");
- currentArchiveContrat = 0;
- });
-
- // UNARCHIVE
- btnUnarchiveContrat.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
-
- var datas = { action : 'unarchive', ref : id };
- $.post( contratsBaseURL, datas, function( result ) {
- if(parseInt(result)>0) document.location.reload();
- else {
- console.error(result);
- alert(result);
- }
- }).fail( function() { alert(srvErrorMsg+" (unarchive contrat)"); });
- });
-
+ modalArchiveContrat.on('hidden.bs.modal', function (e) { modalArchiveContrat_clear(); });
}
-/***** DELETE CONTRAT *****/
+function modalArchiveContrat_loadDatas(btn, id) {
+ modalArchiveContrat.find('b.ref').html( "#"+btn.attr('ref') );
+ modalArchiveContrat.find('b.name').html( btn.attr('nom') );
+ modalArchiveContrat.modal('show');
+}
+
+function modalArchiveContrat_clear() {
+ modalArchiveContrat.removeAttr("archive_id");
+ modalArchiveContrat.find('b.ref').html("");
+ modalArchiveContrat.find('b.name').html("");
+}
+
+/***** DELETE *****/
function initDeleteContrat() {
- // BTN DELETE
- btnDeleteContrat.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
- currentDeleteContrat = id;
-
- modalDeleteContrat.find('b.ref').html( "#"+$(this).attr('ref') );
- modalDeleteContrat.find('b.name').html( $(this).attr('nom') );
-
- modalDeleteContrat.modal('show');
- });
-
- // DELETE
- $("#btnDeleteContrat").unbind('click').click( function(event) {
- event.preventDefault();
- $(this).blur();
-
- if(!currentDeleteContrat>0) return;
-
- var datas = {
- action : 'delete',
- ref : currentDeleteContrat
- };
-
- $.post( contratsBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- modalEditContrat.modal('hide');
- setTimeout(function() {
- document.location.reload();
- },200);
- }
- else {
- console.error(result);
- alert(result);
- }
- }).fail(function() { alert(srvErrorMsg+" (delete contrat)"); });
- });
+ // INIT DELETE BTNs
+ var initBtnFct = function() { modalForm_initBtnDelete(
+ $(contratsConf.delete_btnSelector), // BTNs
+ modalDeleteContrat, // MODAL
+ modalDeleteContrat_clear, // CLEAR MODAL FUNCTION
+ modalDeleteContrat_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
+
+ // INIT SAVE DELETE BTN
+ modalForm_initBtnSaveDelete(
+ modalDeleteContrat.find(".btnSave"), // BTN SAVE
+ contratsConf.type, // DELETE TYPE
+ modalDeleteContrat, // MODAL
+ false, // GET FORM DATAS FUNCTION
+ false, // CHECK FORM DATAS FUNCTION
+ contratsConf.baseURL // SAVE URL
+ );
// CANCEL
- modalDeleteContrat.on('hidden.bs.modal', function (e) {
- modalDeleteContrat.find('b.name').html("");
- currentDeleteContrat = 0;
- });
+ modalDeleteContrat.on('hidden.bs.modal', function (e) { modalDeleteContrat_clear(); });
+}
+
+function modalDeleteContrat_loadDatas(btn, id) {
+ modalDeleteContrat.find('b.ref').html( "#"+btn.attr('ref') );
+ modalDeleteContrat.find('b.name').html( btn.attr('nom') );
+ modalDeleteContrat.modal('show');
+}
+
+function modalDeleteContrat_clear() {
+ modalDeleteContrat.removeAttr("delete_id");
+ modalDeleteContrat.find('b.ref').html("");
+ modalDeleteContrat.find('b.name').html("");
}
\ No newline at end of file
diff --git a/public_html_admin/js/functions.js b/public_html_admin/js/functions.js
index 8959565..6ecbbec 100644
--- a/public_html_admin/js/functions.js
+++ b/public_html_admin/js/functions.js
@@ -5,6 +5,632 @@ var array_keys_ponctuations = ['.','-','_','#','@'];
var array_keys_minuscules = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
var array_keys_majuscules = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
+function isDefined(val){
+ return (val === undefined || val == null || val.length <= 0) ? false : true;
+}
+
+/* MODAL FORM UTIL */
+
+function modalForm_initBtnView(btn, modal, clearFormFct, loadFormDatasFct) {
+ btn.unbind('click').click( function(e) {
+ e.preventDefault(); $(this).blur();
+ id = parseInt($(this).attr('ref'));
+ if(!id>0) return;
+ clearFormFct(modal);
+ modal.attr("view_id", id);
+ loadFormDatasFct(modal, id);
+ });
+}
+
+function modalForm_initBtnAdd(btn, modal, clearFormFct) {
+ btn.unbind('click').click( function(e) {
+ e.preventDefault(); $(this).blur();
+ clearFormFct(modal);
+ modal.modal('show');
+ });
+}
+
+function modalForm_initBtnCopy(btn, modal, clearFormFct, loadFormDatasFct) {
+ btn.unbind('click').click( function(e) {
+ e.preventDefault(); $(this).blur();
+ id = parseInt($(this).attr('ref'));
+ if(!id>0) return;
+ clearFormFct(modal);
+ loadFormDatasFct(modal,id, true);
+ });
+}
+
+function modalForm_initBtnSaveAdd(btn, addType, modal, getModalFormDataFct, checkModalFormDataFct, saveURL) {
+ btn.unbind('click').click( function(e) {
+ e.preventDefault(); $(this).blur();
+
+ // GET & CHECK DATAS
+ var datas = getModalFormDataFct(modal);
+ console.log("modalForm_btnSaveAdd", datas);
+ if( !checkModalFormDataFct(datas) ) return;
+ datas.action = 'add';
+
+ // RUN REQUEST
+ modalForm_runFormRequest( saveURL, datas, ("add "+addType) , modal, $(this) );
+ });
+}
+
+function modalForm_initBtnEdit(btn, modal, clearFormFct, loadFormDatasFct) {
+ btn.unbind('click').click( function(e) {
+ e.preventDefault(); $(this).blur();
+ id = parseInt($(this).attr('ref'));
+ if(!id>0) return;
+ clearFormFct(modal);
+ modal.attr("edit_id", id);
+ loadFormDatasFct(modal,id);
+ });
+}
+
+function modalForm_initBtnSaveEdit(btn, editType, modal, getModalFormDataFct, checkModalFormDataFct, saveURL) {
+ btn.unbind('click').click( function(e) {
+ e.preventDefault(); $(this).blur();
+
+ // GET MODAL EDIT ID
+ var id = parseInt( modal.attr("edit_id") );
+ if(!id>0) return;
+
+ // GET & CHECK DATAS
+ var datas = getModalFormDataFct(modal);
+ console.log("modalForm_btnSaveEdit", datas);
+ if( !checkModalFormDataFct(datas) ) return;
+ datas.action = 'edit';
+ datas.ref = id;
+
+ // RUN REQUEST
+ modalForm_runFormRequest( saveURL, datas, ("edit "+editType) , modal, $(this) );
+ });
+}
+
+function modalForm_initBtnArchive(btn, modal, clearFormFct, loadFormDatasFct) {
+ btn.unbind('click').click( function(e) {
+ e.preventDefault(); $(this).blur();
+ id = parseInt($(this).attr('ref'));
+ if(!id>0) return;
+ clearFormFct(modal);
+ modal.attr("archive_id", id);
+ loadFormDatasFct($(this),id);
+ });
+}
+
+function modalForm_initBtnSaveArchive(btn, archiveType, modal, saveURL) {
+ btn.unbind('click').click( function(e) {
+ e.preventDefault(); $(this).blur();
+
+ // GET MODAL DELETE ID
+ var id = parseInt( modal.attr("archive_id") );
+ if(!id>0) return;
+
+ // GET DATAS
+ var datas = {
+ 'action' : 'archive',
+ 'ref' : id
+ };
+ console.log("ARCHIVE", id, datas );
+
+ // RUN REQUEST
+ modalForm_runFormRequest( saveURL, datas, ("archive "+archiveType) , modal, $(this) );
+ });
+}
+
+function modalForm_initBtnUnarchive(btn, archiveType, modal, saveURL) {
+ btn.unbind('click').click( function(e) {
+ e.preventDefault(); $(this).blur();
+ id = parseInt($(this).attr('ref'));
+ if(!id>0) return;
+
+ var datas = {
+ 'action' : 'unarchive',
+ 'ref' : id
+ };
+ console.log("UNARCHIVE", id, datas );
+
+ // RUN REQUEST
+ $.post( saveURL, datas, function( result ) {
+ if(parseInt(result)>0) document.location.reload();
+ else {
+ console.error(result); alert(result);
+ }
+ }).fail(function(xhr) {
+ var errMsg = "SERVER ERROR (unarchive "+archiveType+")";
+ if( xhr['responseText']!="" ) errMsg += " : " + xhr['responseText'];
+ console.error(errMsg); alert(errMsg);
+ });
+ });
+}
+
+
+function modalForm_initBtnDelete(btn, modal, clearFormFct, loadFormDatasFct) {
+ btn.unbind('click').click( function(e) {
+ e.preventDefault(); $(this).blur();
+ id = parseInt($(this).attr('ref'));
+ if(!id>0) return;
+ clearFormFct(modal);
+ modal.attr("delete_id", id);
+ loadFormDatasFct($(this),id);
+ });
+}
+
+function modalForm_initBtnSaveDelete(btn, deleteType, modal, getModalFormDataFct, checkModalFormDataFct, saveURL) {
+ btn.unbind('click').click( function(e) {
+ e.preventDefault(); $(this).blur();
+
+ // GET MODAL DELETE ID
+ var id = parseInt( modal.attr("delete_id") );
+ if(!id>0) return;
+
+ // GET & CHECK DATAS
+ var datas = {};
+ if(typeof getModalFormDataFct === 'function') datas = getModalFormDataFct(modal);
+ console.log("DELETE", id, datas );
+ if(typeof checkModalFormDataFct === 'function') { if( !checkModalFormDataFct(datas) ) return; }
+ datas.action = 'delete';
+ datas.ref = id;
+
+ // RUN REQUEST
+ modalForm_runFormRequest( saveURL, datas, ("delete "+deleteType) , modal, $(this) );
+ });
+}
+
+function modalForm_runFormRequest(url, datas, srvErrorAction, modal, btnRun) {
+ modalForm_runFormRequest_lockModal(modal, btnRun);
+ $.post( url, datas, function( result ) {
+ if(parseInt(result)>0) {
+ if(modal && modal.length>0) {
+ modal.modal('hide');
+ setTimeout(function() { document.location.reload(); },200);
+ }
+ else document.location.reload();
+ }
+ else {
+ console.error(result); alert(result);
+ modalForm_runFormRequest_unlockModal(modal, btnRun);
+ }
+ }).fail(function(xhr) {
+ var errMsg = "SERVER ERROR";
+ if( isDefined( srvErrorAction ) ) errMsg += " ("+srvErrorAction+")";
+ if( xhr['responseText']!="" ) errMsg += " : " + xhr['responseText'];
+ console.error(errMsg); alert(errMsg);
+ modalForm_runFormRequest_unlockModal(modal, btnRun);
+ });
+}
+
+function modalForm_runFormRequest_lockModal(modal, btnRun) {
+ if( isDefined( modal ) && modal.find("div.modaLoader").length>0) modal.find("div.modaLoader").addClass("show");
+ if( isDefined( btnRun ) ) btnRun.prop("disabled", true);
+}
+
+function modalForm_runFormRequest_unlockModal(modal, btnRun) {
+ if( isDefined( modal ) && modal.find("div.modaLoader").length>0) modal.find("div.modaLoader").removeClass("show");
+ if( isDefined( btnRun ) ) btnRun.prop("disabled", false);
+}
+
+function modalForm_initTabs(modal) {
+ // TABS
+ modal.find("a.formTabBtn").click(function(e) {
+ e.preventDefault();
+
+ // BTN
+ if(!$(this).parent().hasClass("active")) {
+ modal.find("ul.formTabsBtns > li").removeClass('active');
+ $(this).parent().addClass("active");
+ }
+
+ // TAB
+ var tab = modal.find("div.tab."+$(this).attr("tab"));
+ if(tab.length>0) {
+ if(tab.hasClass("active")) return;
+
+ modal.find("div.formTabs > div.tab").removeClass("active");
+ tab.addClass("active");
+ }
+ });
+
+ // RESIZE TABS
+ var resizeFct = function resizeFormClient(modal) {
+ var wh = window.innerHeight;
+ modal.find("div.formTabs div.tab").css("max-height", (wh-180)+"px");
+ }
+ resizeFct(modal);
+ $( window ).on( "resize", function() { resizeFct(modal) });
+}
+
+function modalForm_resetTabs(modal) {
+ modal.find("ul.formTabsBtns > li").removeClass('active hide');
+ modal.find("ul.formTabsBtns > li:first-child").addClass('active');
+ modal.find("div.formTabs > div.tab").removeClass("active");
+ modal.find("div.formTabs > div.tab:first-child").addClass("active");
+}
+
+/* INLINE SELECT MANAGER */
+
+function inlineSelectManager_init(
+ modal,
+ modal_form_name,
+ grp,
+ value_name,
+ url,
+ ref_attr,
+ add_action,
+ edit_action,
+ delete_action,
+ refresh_list_action,
+ selectClbkFct,
+ addClbkFct,
+ editClbkFct,
+ cancelClbkFct,
+ getDatasFct,
+ checkDatasFct,
+ saveClbkFct
+) {
+ grp.attr("modal_form_name", modal_form_name)
+ .attr("value_name", value_name)
+ .attr("ref_attr", ref_attr)
+ .attr("add_action", add_action)
+ .attr("edit_action", edit_action)
+ .attr("delete_action", delete_action)
+ .attr("refresh_list_action", refresh_list_action);
+
+ // SELECT CHANGE => SWITCH ACTION
+ grp.find("select").change(function(e) {
+ $(this).blur();
+ // EXISTING
+ if(parseInt($(this).val())>0) {
+ inlineSelectManager_switchBtnAction(grp, "delete");
+ inlineSelectManager_switchBtnSecondAction(grp, "edit");
+ }
+ // CHOISIR...
+ else {
+ inlineSelectManager_switchBtnAction(grp, "add");
+ inlineSelectManager_switchBtnSecondAction(grp, "hide");
+ }
+
+ if(typeof selectClbkFct === 'function') selectClbkFct(modal, grp, $(this));
+ });
+
+ // BTN ACTION
+ grp.find("button.btnAction").click(function(e) {
+ e.preventDefault(); $(this).blur();
+ // ADD / SAVE NEW
+ if($(this).hasClass("add") || $(this).hasClass("save_new")) {
+ inlineSelectManager_addInputName(grp, "add");
+ inlineSelectManager_switchBtnAction(grp, "save");
+ inlineSelectManager_switchBtnSecondAction(grp, "cancel");
+ if(typeof addClbkFct === 'function') addClbkFct(modal, grp);
+ }
+ // SAVE
+ else if($(this).hasClass("save")) inlineSelectManager_save(modal, grp, url, getDatasFct, checkDatasFct, saveClbkFct);
+ // DELETE
+ else if($(this).hasClass("delete")) inlineSelectManager_delete(modal, grp, url);
+ });
+
+ // BTN SECOND ACTION
+ grp.find("button.btnSecondAction").click(function(e) {
+ e.preventDefault(); $(this).blur();
+ // EDIT
+ if($(this).hasClass("edit")) {
+ inlineSelectManager_addInputName(grp, "edit");
+ inlineSelectManager_switchBtnAction(grp, "save");
+ inlineSelectManager_switchBtnSecondAction(grp, "cancel");
+ if(typeof editClbkFct === 'function') editClbkFct(modal, grp);
+ }
+ // CANCEL
+ else if($(this).hasClass("cancel")) {
+ inlineSelectManager_removeInputName(grp);
+ // EDIT
+ if(parseInt(grp.find("select").val())>0) {
+ inlineSelectManager_switchBtnAction(grp, "delete");
+ inlineSelectManager_switchBtnSecondAction(grp, "edit");
+ }
+ // ADD
+ else {
+ inlineSelectManager_switchBtnAction(grp, "add");
+ inlineSelectManager_switchBtnSecondAction(grp, "hide");
+ }
+
+ if(typeof cancelClbkFct === 'function') cancelClbkFct(modal, grp);
+ }
+ });
+}
+
+function inlineSelectManager_setValue(grp, val) {
+ if(isDefined(val) && parseInt(val) > 0) {
+ grp.find("select").val(val);
+ inlineSelectManager_switchBtnAction(grp, "delete");
+ inlineSelectManager_switchBtnSecondAction(grp, "edit");
+ }
+ else {
+ grp.find("select").val("0");
+ inlineSelectManager_switchBtnAction(grp, "add");
+ inlineSelectManager_switchBtnSecondAction(grp, "hide");
+ }
+}
+
+function inlineSelectManager_switchBtnAction(grp, action) {
+ var btn = grp.find("button.btnAction");
+
+ if(action == "add") {
+ btn.removeClass("save save_new delete").addClass("add").removeClass("btn-danger btn-primary").addClass("btn-default")
+ .find("i").removeClass("glyphicon-floppy-saved glyphicon-floppy-disk glyphicon-trash").addClass("glyphicon-plus");
+ }
+ else if(action == "save") {
+ btn.removeClass("add save_new delete").addClass("save").removeClass("btn-danger btn-default").addClass("btn-primary")
+ .find("i").removeClass("glyphicon-plus glyphicon-floppy-disk glyphicon-trash").addClass("glyphicon-floppy-saved");
+ }
+ else if(action == "save_new") {
+ btn.removeClass("add save delete").addClass("save_new").removeClass("btn-danger btn-primary").addClass("btn-default")
+ .find("i").removeClass("glyphicon-plus glyphicon-floppy-saved glyphicon-trash").addClass("glyphicon-floppy-disk");
+ }
+ else if(action == "delete") {
+ btn.removeClass("add save_new save").addClass("delete").removeClass("btn-default btn-primary").addClass("btn-danger")
+ .find("i").removeClass("glyphicon-plus glyphicon-floppy-saved glyphicon-floppy-disk").addClass("glyphicon-trash");
+ }
+}
+
+function inlineSelectManager_switchBtnSecondAction(grp, action) {
+ var btn = grp.find("button.btnSecondAction");
+
+ if(action == "cancel") {
+ btn.removeClass("edit").addClass("cancel").removeClass("btn-default").addClass("btn-danger")
+ .find("i").removeClass("glyphicon-edit").addClass("glyphicon-floppy-remove");
+ btn.parent().removeClass("hide");
+ }
+ else if(action == "edit") {
+ btn.removeClass("cancel").addClass("edit").removeClass("btn-danger").addClass("btn-default")
+ .find("i").removeClass("glyphicon-floppy-remove").addClass("glyphicon-edit");
+ btn.parent().removeClass("hide");
+ }
+ else if(action == "hide") {
+ btn.parent().addClass("hide");
+ }
+}
+
+function inlineSelectManager_addInputName(grp, action) {
+ var select = grp.find("select");
+ select.addClass("hide");
+
+ var ipt = $(' ').attr("action", action);
+ ipt.insertBefore(select);
+
+ if(action=="edit") {
+ ipt.attr("ref", select.val());
+ ipt.val( select.find("option:selected").html() );
+ }
+ else ipt.attr("ref", "new");
+ ipt.focus();
+
+ ipt.keypress(function(e) {
+ if(e.keyCode==13) {
+ e.preventDefault();
+ $(this).parent().find("button.btnAction").click();
+ }
+ });
+}
+
+function inlineSelectManager_removeInputName(grp) {
+ var ipt = grp.find("input[name=name]");
+ if(ipt.length>0) ipt.remove();
+ grp.find("select").removeClass("hide");
+}
+
+function inlineSelectManager_save(modal, grp, url, getDatasFct, checkDatasFct, saveClbkFct) {
+ // GET DATAS
+ var datas = (typeof getDatasFct === 'function') ? getDatasFct(modal, grp) : inlineSelectManager_getDatas(grp);
+
+ // CHECK DATAS
+ if(typeof checkDatasFct === 'function') { if( !checkDatasFct(datas) ) return; }
+ else { if( !inlineSelectManager_checkDatas(datas) ) return; }
+
+ var ref = grp.find("input[name=name]").attr("ref");
+
+ // ADD
+ if(ref == "new") datas.action = grp.attr("add_action");
+ // EDIT
+ else if(parseInt(ref)>0) {
+ ref = parseInt(ref);
+ datas.action = grp.attr("edit_action");
+ datas[grp.attr("ref_attr")] = ref;
+ }
+
+ // LOCK
+ modal.find("div.modaLoader").addClass("show");
+ modal.find("button.btnAction").prop("disabled", true);
+
+ $.post( url, datas, function( result ) {
+ if(parseInt(result)>0) {
+ inlineSelectManager_switchBtnAction(grp, "delete");
+ inlineSelectManager_switchBtnSecondAction(grp, "edit");
+ inlineSelectManager_removeInputName(grp);
+
+ if(ref == "new") ref = parseInt(result);
+
+ if(typeof saveClbkFct === 'function') saveClbkFct(modal, grp, ref);
+
+ // REFRESH LIST
+ $.post( url, { action: grp.attr("refresh_list_action") }, function( result ) {
+ grp.find("select").html(result).val(ref);
+ }).fail(function() {
+ alert("ERREUR SERVEUR ! (modal form "+grp.attr("modal_form_name")+" - add/edit "+grp.find("select").attr("name")+" - refresh list after)");
+ });
+ }
+ else { console.error(result); alert(result); }
+ }).fail(function() {
+ alert("ERREUR SERVEUR ! (modal form "+grp.attr("modal_form_name")+" - add/edit "+grp.find("select").attr("name")+")");
+ }).always(function() {
+ // UNLOCK
+ modal.find("div.modaLoader").removeClass("show");
+ modal.find("button.btnAction").prop("disabled", false);
+ });
+}
+
+function inlineSelectManager_delete(modal, grp, url) {
+ var ref = parseInt(grp.find("select").val());
+ var nom = grp.find("select option:selected").html();
+
+ if(confirm('Etês vous sûr de vouloir supprimer '+grp.attr('value_name')+' "'+nom+'" ?')) {
+ // LOCK
+ modal.find("div.modaLoader").addClass("show");
+ modal.find("button.btnGroupeAction").prop("disabled", false);
+
+ var datas = { action : grp.attr("delete_action") };
+ datas[grp.attr("ref_attr")] = ref;
+
+ $.post( url, datas, function( result ) {
+ if(parseInt(result)>0) {
+ // REFRESH LIST
+ $.post( url, { action: grp.attr("refresh_list_action") }, function( result ) {
+ grp.find("select").html(result).val("0");
+ }).fail(function() {
+ alert("ERREUR SERVEUR ! (modal form "+grp.attr("modal_form_name")+" - delete "+grp.find("select").attr("name")+" - refresh list after)");
+ });
+ }
+ else { console.error(result); alert(result); }
+ }).fail(function() {
+ alert("ERREUR SERVEUR ! (modal form "+grp.attr("modal_form_name")+" - delete "+grp.find("select").attr("name")+")");
+ }).always(function() {
+ // UNLOCK
+ modal.find("div.modaLoader").removeClass("show");
+ modal.find("button.btnAction").prop("disabled", false);
+ });
+ }
+}
+
+function inlineSelectManager_getDatas(grp) {
+ var datas = { 'nom' : grp.find("input[name=name]").val() };
+ return datas;
+}
+
+function inlineSelectManager_checkDatas(datas) {
+ if(datas.nom=="") {
+ alert("Merci de renseigner un nom !");
+ return false;
+ }
+ return true;
+}
+
+/* AUTOCOMPLETE INPUT */
+
+function initAutocompleteInput(form, ipt, url, action, errContext, requestDataFct, selectFct, clearFct, blurFct) {
+ ipt.autocomplete({
+ html: true,
+ delay: 200,
+ source: function(requete, reponse) {
+ datas = {
+ 'action' : action,
+ 'search' : ipt.val(),
+ 'nohist' : true
+ };
+ if(typeof requestDataFct === 'function') datas = requestDataFct(form, ipt, datas);
+ $.post(url, datas, function(jsonTxt) {
+ datas = JSON.parse(jsonTxt);
+ reponse(datas);
+ }).fail(function() { alert("ERREUR SERVEUR !"+( (isDefined(errContext)) ? " "+errContext : "" )); });
+ },
+ focus: function(event, ui) { event.preventDefault(); },
+ select: function(event, ui) {
+ event.preventDefault();
+ if(typeof selectFct === 'function') selectFct(form, ipt, ui.item);
+ else ipt.val( ui.item.value ).attr('ref', ui.item.ref).blur();
+ }
+ });
+ ipt.keydown(function(e) {
+ if(e.keyCode==13) { e.preventDefault(); $(this).blur(); }
+ else if(parseInt($(this).attr('ref'))>0) {
+ if(typeof clearFct === 'function') clearFct(form, $(this));
+ else $(this).val("").removeAttr('ref');
+ }
+ });
+ ipt.on("blur", function(e) {
+ if(typeof blurFct === 'function') blurFct(form, $(this));
+ else if(!parseInt($(this).attr('ref'))>0) $(this).val("").removeAttr('ref');
+ });
+}
+
+/* LIST PROGRESS LOAD */
+
+function initListProgressLoad(list, url, listName) {
+ if(isDefined(list)) {
+ var contentH = list.innerHeight();
+
+ list.listProgressLoad_resize();
+ $(window).resize( function() { list.listProgressLoad_resize(); } );
+
+ list.scroll(function(e) {
+ var rest = list.prop("scrollHeight") - list.innerHeight() - list.scrollTop();
+ if(rest<300 && list.find("td.loader").length==0 && parseInt(list.attr('rest'))>0) {
+ // APPEND LOADER
+ var tr = $(" ");
+ list.append(tr);
+
+ // LOAD
+ $.post(url, { 'startListAt' : parseInt(list.attr('end')) }, function(jsonTxt) {
+ datas = JSON.parse(jsonTxt);
+
+ list.attr("start", datas.start);
+ list.attr("end", datas.end);
+ list.attr("rest", datas.rest);
+ list.append($(datas.list));
+
+ list.trigger( "loaded" );
+
+ tr.remove();
+ }).fail(function(xhr) {
+ errMsg = "SERVER ERROR ("+(( isDefined( listName ) && listName != "" ) ? listName : "list")+" - load items)";
+ if( xhr['responseText']!="" ) errMsg += " : " + xhr['responseText'];
+ console.error(errMsg); alert(errMsg);
+ });
+ }
+ });
+
+ // FORCE LOAD IF WINDOWS NOT FULL
+ h = $(window).innerHeight() - list.position().top;
+ if(parseInt(list.attr("rest"))>0 && contentH0) initSearchLegumes();
+$(document).ready( function() {
+ // LIST LOADER
+ initListProgressLoad($(legumesConf.list_selector), legumesConf.baseURL, legumesConf.type+" list");
- // INIT VIEW LEGUME
- modalViewLegume = $("#modalViewLegume");
- btnViewLegume = $(".btnViewLegume");
- if(modalViewLegume.length>0 && btnViewLegume.length>0) {
+ // SEARCH
+ $(legumesConf.search_selector).initSearchGroup();
+
+ // VIEW
+ modalViewLegume = $(legumesConf.view_modalSelector);
+ if(modalViewLegume.length>0) {
initViewLegume();
// VIEW REQUEST
- var id = getUrlParameter("id");
- if(id!==false && parseInt(id)>0) loadDatasInViewLegumeModal(id);
+ var id = getUrlParameter("ref");
+ if(id!==false && parseInt(id)>0 && current_page == "legumes") {
+ modalViewLegume_clear(modalViewLegume);
+ modalViewLegume_loadDatas(modalViewLegume, id);
+ }
}
- // INIT ADD LEGUME
- modalAddLegume = $("#modalAddLegume");
- formAddLegume = $("#formAddLegume");
- btnAddLegume = $("#btnAddLegume");
- if(modalAddLegume.length>0 && formAddLegume.length>0 && btnAddLegume.length>0) initAddLegume();
-
- // INIT EDIT LEGUME
- modalEditLegume = $("#modalEditLegume");
- formEditLegume = $("#formEditLegume");
- btnEditLegume = $(".btnEditLegume");
- if(modalEditLegume.length>0 && formEditLegume.length>0 && btnEditLegume.length>0) initEditLegume();
-
- // INIT DELETE LEGUME
- modalDeleteLegume = $("#modalDeleteLegume");
- btnDeleteLegume = $(".btnDeleteLegume");
- if(modalDeleteLegume.length>0 && btnDeleteLegume.length>0) initDeleteLegume();
+ // ADD
+ modalAddLegume = $(legumesConf.add_modalSelector);
+ if(modalAddLegume.length>0) initAddLegume();
+
+ // EDIT
+ modalEditLegume = $(legumesConf.edit_modalSelector);
+ if(modalEditLegume.length>0) initEditLegume();
+
+ // DELETE
+ modalDeleteLegume = $(legumesConf.delete_modalSelector);
+ if(modalDeleteLegume.length>0) initDeleteLegume();
});
-/***** SEARCH LEGUMES *****/
-function initSearchLegumes() {
- legumesSearch.find("input[name=search]").unbind('keypress').keypress( function(event) {
- if(event.keyCode==13) searchLegume(false);
- });
- legumesSearch.find(".btnClearSearch").unbind('click').click( function(event) {
- searchLegume(true);
- });
-}
-
-function searchLegume(clear) {
- legumesSearch.find("input[name=search]").blur();
- legumesSearch.find(".btnClearSearch").blur();
- if(clear) document.location = "?clearSearch";
- else document.location = "?search="+legumesSearch.find("input[name=search]").val();
-}
-
-/***** VIEW LEGUME *****/
+/***** MODAL VIEW *****/
function initViewLegume() {
- // BTN VIEW
- btnViewLegume.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
- clearViewLegumeModal();
- currentViewLegume = id;
- loadDatasInViewLegumeModal(id);
- });
+ // INIT VIEW BTNs
+ var initBtnFct = function() { modalForm_initBtnView(
+ $(legumesConf.view_btnSelector), // BTNs
+ modalViewLegume, // MODAL
+ modalViewLegume_clear, // CLEAR FUNCTION
+ modalViewLegume_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
// CANCEL
- modalViewLegume.on('hidden.bs.modal', function (e) {
- clearViewLegumeModal();
- currentViewLegume = 0;
- });
+ modalViewLegume.on('hidden.bs.modal', function() { modalViewLegume_clear(modalViewLegume); });
}
-function loadDatasInViewLegumeModal(id) {
- datas = {
- 'ref' : id,
- 'action' : 'getDatas'
- };
- $.post( legumesBaseURL, datas, function( result ) {
- var datas = JSON.parse(result);
+function modalViewLegume_loadDatas(modal, id) {
+ $.post(legumesConf.baseURL, { 'ref' : id, 'action' : 'getDatas' }, function(jsonTxt) {
+ var datas = JSON.parse(jsonTxt);
+
+ modal.find("small.db_ref > span").html(datas.ref);
- modalViewLegume.find("small.db_ref > span").html(datas.ref);
-
- modalViewLegume.find("td.nom").html(datas.nom);
- modalViewLegume.find("td.tarif").html(datas.tarif_print+" (depuis le "+datas.tarif_date_print+") ");
+ modal.find("td.nom").html(datas.nom);
+ modal.find("td.tarif").html(datas.tarif_print+" (depuis le "+datas.tarif_date_print+") ");
if(datas.historique_tarif.length>0) {
- modalViewLegume.find("table.modal-body tfoot").removeClass("hide");
+ modal.find("table.modal-body tfoot").removeClass("hide");
$.each(datas.historique_tarif, function(n,e) { addTarifLegumeHist(e); });
}
- modalViewLegume.modal('show');
- }).fail(function() { alert(srvErrorMsg+" (load modal view legume)"); });
+ modal.modal('show');
+ }).fail(function() { alert("("+legumesConf.type+" - load modal view)"); });
}
-function addTarifLegumeHist(datas) {
+function modalViewLegume_clear(modal) {
+ modal.find("small.db_ref > span").html("");
+
+ modal.find("td.nom").html("");
+ modal.find("td.tarif").html("");
+
+ modal.find("table.modal-body tfoot").addClass("hide").find("tr:not(.header)").remove();
+}
+
+function modalViewLegume_addTarifLegumeHist(modal, datas) {
var tr = $(" ").attr("ref", datas.ref);
tr.append($(" ").html(datas.tarif_print));
tr.append($(" ").html(datas.tarif_periode));
btnDel = $(' ').attr('ref', datas.ref).attr('tarif', datas.tarif_print).attr('periode', datas.tarif_periode);
tr.append($(" ").append(btnDel));
- modalViewLegume.find("table.modal-body tfoot").append(tr);
+ modal.find("table.modal-body tfoot").append(tr);
btnDel.click(function(e) {
+ e.preventDefault(); $(this).blur();
tr = $(this).parent().parent();
- e.preventDefault();
- $(this).blur();
id = parseInt( $(this).attr("ref") );
if(!id>0) return;
msg = "Êtes vous sûr de vouloir supprimer le tarif de "+$(this).attr("tarif")+" en application "+$(this).attr("periode")+" ?";
if(confirm(msg)) {
- datas = {
- 'action' : 'deleteTarif',
- 'tarif' : id
- };
- $.post( legumesBaseURL, datas, function( result ) {
+ datas = { 'action' : 'deleteTarif', 'tarif' : id };
+ $.post( legumesConf.baseURL, datas, function( result ) {
if(parseInt(result)>0) {
tr.remove();
- if(modalViewLegume.find("table.modal-body tfoot tr:not(.header)").length == 0) modalViewLegume.find("table.modal-body tfoot").addClass("hide");
+ if(modal.find("table.modal-body tfoot tr:not(.header)").length == 0) modal.find("table.modal-body tfoot").addClass("hide");
}
- else {
- console.error(result);
- alert(result);
- }
- }).fail(function() { alert(srvErrorMsg+" (form legume - delete tarif)"); });
+ else { console.error(result); alert(result); }
+ }).fail(function() { alert("("+legumesConf.type+" - delete tarif)"); });
}
})
}
-function clearViewLegumeModal() {
- modalViewLegume.find("small.db_ref > span").html("");
+/***** MODAL FORM ADD/EDIT *****/
+function modalFormLegume_init(modal) {
+ modal.find("form").on("submit", function(e) { e.preventDefault(); });
- modalViewLegume.find("td.nom").html("");
- modalViewLegume.find("td.tarif").html("");
-
- modalViewLegume.find("table.modal-body tfoot").addClass("hide").find("tr:not(.header)").remove();
-}
-
-/***** FORM LEGUME *****/
-function initFormLegume(form) {
- form.on("submit", function(e) { e.preventDefault(); });
-
- form.find("button.btnEditTarif").click(function(e) {
+ // BTN EDIT TARIF
+ modal.find("button.btnEditTarif").click(function(e) {
e.preventDefault();
$(this).blur().addClass('hide');
- form.find("input[name=prix]").attr('ref', 'new').prop('disabled', false);
- form.find("select[name=unite]").prop('disabled', false);
- form.find("input[name=date]").prop('disabled', false).val(getTodayDate("yyyy-mm-dd"));
+ modal.find("input[name=prix]").attr('ref', 'new').prop('disabled', false);
+ modal.find("select[name=unite]").prop('disabled', false);
+ modal.find("input[name=date]").prop('disabled', false).val(getTodayDate("yyyy-mm-dd"));
});
- initFloatInput(form.find("input[name=prix]"));
-}
-
-function loadDatasInFormLegumeDatas(modal,form,id) {
- datas = {
- 'ref' : id,
- 'action' : 'getDatas'
- };
- $.post( legumesBaseURL, datas, function( result ) {
- var datas = JSON.parse(result);
-
- form.find("input[name=nom]").val(datas.nom);
- form.find("input[name=prix]").val(datas.tarif_prix).attr('ref', datas.tarif_ref);
- form.find("select[name=unite]").val(datas.tarif_unite);
- form.find("input[name=date]").val(datas.tarif_date);
-
- if(modal) modal.modal('show');
- }).fail(function() { alert(srvErrorMsg+" (form legume - load datas)"); });
-}
-
-function clearFormLegumeDatas(form) {
- add = (form.attr('id') == "formAddLegume");
- form.find("input[name=nom]").val("");
- if(add) form.find("button.btnEditTarif").addClass('hide');
- else form.find("button.btnEditTarif").removeClass('hide');
- form.find("input[name=prix]").val("").attr('ref', "new").prop('disabled', !add);
- form.find("select[name=unite]").val("kg").prop('disabled', !add);
- form.find("input[name=date]").val(getTodayDate("yyyy-mm-dd")).prop('disabled', !add);
-
- // MODALOADER
- form.find("div.modaLoader").removeClass("show");
+ // PRIX
+ initFloatInput(modal.find("input[name=prix]"));
}
-// GET FORM DATAS
+function modalFormLegume_loadDatas(modal,id) {
+ $.post(legumesConf.baseURL, { 'ref' : id, 'action' : 'getDatas' }, function(jsonTxt) {
+ var datas = JSON.parse(jsonTxt);
-function getLegumeFormDatas(form) {
+ modal.find("input[name=nom]").val(datas.nom);
+ modal.find("input[name=prix]").val(datas.tarif_prix).attr('ref', datas.tarif_ref);
+ modal.find("select[name=unite]").val(datas.tarif_unite);
+ modal.find("input[name=date]").val(datas.tarif_date);
+
+ if(modal) modal.modal('show');
+ }).fail(function() { alert("("+legumesConf.type+" - load datas in modal form)"); });
+}
+
+function modalFormLegume_clear(modal) {
+ modal.removeAttr("edit_id");
+ modal.find("div.modaLoader").removeClass("show");
+
+ add = modal.hasClass("add");
+
+ modal.find("input[name=nom]").val("");
+ if(add) modal.find("button.btnEditTarif").addClass('hide');
+ else modal.find("button.btnEditTarif").removeClass('hide');
+ modal.find("input[name=prix]").val("").attr('ref', "new").prop('disabled', !add);
+ modal.find("select[name=unite]").val("kg").prop('disabled', !add);
+ modal.find("input[name=date]").val(getTodayDate("yyyy-mm-dd")).prop('disabled', !add);
+}
+
+function modalFormLegume_getDatas(modal) {
var datas = {
- 'nom' : form.find("input[name=nom]").val(),
- 'tarif_ref' : (form.find("input[name=prix]").attr('ref')=="new") ? "new" : parseInt(form.find("input[name=prix]").attr('ref')),
- 'tarif_prix' : parseFloat( form.find("input[name=prix]").val() ),
- 'tarif_unite' : form.find("select[name=unite]").val(),
- 'tarif_date' : form.find("input[name=date]").val()
+ 'nom' : modal.find("input[name=nom]").val(),
+ 'tarif_ref' : (modal.find("input[name=prix]").attr('ref')=="new") ? "new" : parseInt(modal.find("input[name=prix]").attr('ref')),
+ 'tarif_prix' : parseFloat( modal.find("input[name=prix]").val() ),
+ 'tarif_unite' : modal.find("select[name=unite]").val(),
+ 'tarif_date' : modal.find("input[name=date]").val()
};
return datas;
}
-/***** ADD LEGUME *****/
+function modalFormLegume_checkDatas(datas) {
+ if(datas.nom=="") {
+ alert("ERREUR : au minimum, un nom doit être renseigné !");
+ return false;
+ }
+ return true;
+}
+
+/***** ADD *****/
function initAddLegume() {
- // BTN ADD
- btnAddLegume.unbind('click').click( function(event) {
- event.preventDefault();
- clearFormLegumeDatas(formAddLegume);
- modalAddLegume.modal('show');
- });
+ // INIT FORM
+ modalFormLegume_init(modalAddLegume);
+
+ // INIT ADD BTN
+ modalForm_initBtnAdd(
+ $(legumesConf.add_btnSelector), // BTN ADD
+ modalAddLegume, // MODAL
+ modalFormLegume_clear // CLEAR FORM FUNCTION
+ );
- // INIT FORM ADD
- initFormLegume(formAddLegume);
-
- // SAVE LEGUME
- $(".btnSaveAddLegume").unbind('click').click( function(event) {
- event.preventDefault();
-
- var datas = getLegumeFormDatas(formAddLegume);
-
- if(datas.nom=="") {
- alert("ERREUR : au minimum un nom doit être renseigné !");
- return;
- }
-
- datas.action = 'add';
-
- formAddLegume.find("div.modaLoader").addClass("show");
- $(".btnSaveAddLegume").prop("disabled", true);
-
- $.post( legumesBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- modalAddLegume.modal('hide');
- setTimeout(function() {
- document.location.reload();
- },200);
- }
- else {
- console.error(result);
- alert(result);
- formAddLegume.find("div.modaLoader").removeClass("show");
- $(".btnSaveAddLegume").prop("disabled", false);
- }
- }).fail(function() {
- alert(srvErrorMsg+" (add legume)");
- formAddLegume.find("div.modaLoader").removeClass("show");
- $(".btnSaveAddLegume").prop("disabled", false);
- });
- });
+ // INIT SAVE BTN
+ modalForm_initBtnSaveAdd(
+ modalAddLegume.find(".btnSave"), // BTN SAVE
+ legumesConf.type, // ADD TYPE
+ modalAddLegume, // MODAL
+ modalFormLegume_getDatas, // GET FORM DATAS FUNCTION
+ modalFormLegume_checkDatas, // CHECK FORM DATAS FUNCTION
+ legumesConf.baseURL // SAVE URL
+ );
// CANCEL
- modalAddLegume.on('hidden.bs.modal', function (e) { clearFormLegumeDatas(formAddLegume); });
+ modalAddLegume.on('hidden.bs.modal', function (e) { modalFormLegume_clear(modalAddLegume); });
}
-/***** EDIT LEGUME *****/
+/***** EDIT *****/
function initEditLegume() {
- // BTN EDIT
- btnEditLegume.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
- currentEditLegume = id;
- clearFormLegumeDatas(formEditLegume);
- loadDatasInFormLegumeDatas(modalEditLegume,formEditLegume,id);
- });
-
- // INIT FORM EDIT
- initFormLegume(formEditLegume);
+ // INIT FORM
+ modalFormLegume_init(modalEditLegume);
- // SAVE LEGUME
- $(".btnSaveEditLegume").unbind('click').click( function(event) {
- event.preventDefault();
-
- if(!currentEditLegume>0) return;
-
- var datas = getLegumeFormDatas(formEditLegume);
- if(datas.nom=="") {
- alert("ERREUR : au minimum un nom doit être renseigné !");
- return;
- }
-
- datas.action = 'edit';
- datas.ref = currentEditLegume;
-
- formEditLegume.find("div.modaLoader").addClass("show");
- $(".btnSaveEditLegume").prop("disabled", true);
-
- $.post( legumesBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- modalEditLegume.modal('hide');
- setTimeout(function() {
- document.location.reload();
- },200);
- }
- else {
- console.error(result);
- alert(result);
- formEditLegume.find("div.modaLoader").removeClass("show");
- $(".btnSaveEditLegume").prop("disabled", false);
- }
- }).fail(function() {
- alert(srvErrorMsg+" (edit legume)");
- formEditLegume.find("div.modaLoader").removeClass("show");
- $(".btnSaveEditLegume").prop("disabled", false);
- });
- });
+ // INIT EDIT BTNs
+ var initBtnFct = function() { modalForm_initBtnEdit(
+ $(legumesConf.edit_btnSelector), // BTNs
+ modalEditLegume, // MODAL
+ modalFormLegume_clear, // CLEAR FUNCTION
+ modalFormLegume_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
+
+ // INIT SAVE EDIT BTN
+ modalForm_initBtnSaveEdit(
+ modalEditLegume.find(".btnSave"), // BTN SAVE
+ legumesConf.type, // EDIT TYPE
+ modalEditLegume, // MODAL
+ modalFormLegume_getDatas, // GET FORM DATAS FUNCTION
+ modalFormLegume_checkDatas, // CHECK FORM DATAS FUNCTION
+ legumesConf.baseURL // SAVE URL
+ );
// CANCEL
- modalEditLegume.on('hidden.bs.modal', function (e) {
- clearFormLegumeDatas(formEditLegume);
- currentEditLegume = 0;
- });
+ modalEditLegume.on('hidden.bs.modal', function (e) { modalFormLegume_clear(modalEditLegume); });
}
-/***** DELETE LEGUME *****/
+/***** DELETE *****/
function initDeleteLegume() {
- // BTN DELETE
- btnDeleteLegume.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
- currentDeleteLegume = id;
-
- modalDeleteLegume.find('b.name').html( $(this).attr('nom') );
-
- modalDeleteLegume.modal('show');
- });
-
- // DELETE
- $("#btnDeleteLegume").unbind('click').click( function(event) {
- event.preventDefault();
- $(this).blur();
-
- if(!currentDeleteLegume>0) return;
-
- var datas = {
- action : 'delete',
- ref : currentDeleteLegume
- };
-
- $.post( legumesBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- modalEditLegume.modal('hide');
- setTimeout(function() {
- document.location.reload();
- },200);
- }
- else {
- console.error(result);
- alert(result);
- }
- }).fail(function() { alert(srvErrorMsg+" (delete legume)"); });
- });
+ // INIT DELETE BTNs
+ var initBtnFct = function() { modalForm_initBtnDelete(
+ $(legumesConf.delete_btnSelector), // BTNs
+ modalDeleteLegume, // MODAL
+ modalDeleteLegume_clear, // CLEAR MODAL FUNCTION
+ modalDeleteLegume_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
+
+ // INIT SAVE DELETE BTN
+ modalForm_initBtnSaveDelete(
+ modalDeleteLegume.find(".btnSave"), // BTN SAVE
+ legumesConf.type, // DELETE TYPE
+ modalDeleteLegume, // MODAL
+ false, // GET FORM DATAS FUNCTION
+ false, // CHECK FORM DATAS FUNCTION
+ legumesConf.baseURL // SAVE URL
+ );
// CANCEL
- modalDeleteLegume.on('hidden.bs.modal', function (e) {
- modalDeleteLegume.find('b.name').html("");
- currentDeleteLegume = 0;
- });
+ modalDeleteLegume.on('hidden.bs.modal', function (e) { modalDeleteLegume_clear(); });
+}
+
+function modalDeleteLegume_loadDatas(btn, id) {
+ modalDeleteLegume.find('b.name').html( btn.attr('nom') );
+ modalDeleteLegume.modal('show');
+}
+
+function modalDeleteLegume_clear() {
+ modalDeleteLegume.removeAttr("delete_id");
+ modalDeleteLegume.find('b.name').html("");
}
\ No newline at end of file
diff --git a/public_html_admin/js/livraisons.js b/public_html_admin/js/livraisons.js
index 62c8080..b5dac37 100644
--- a/public_html_admin/js/livraisons.js
+++ b/public_html_admin/js/livraisons.js
@@ -1,332 +1,267 @@
-// FILTRES
-var filtreLivraisonGroupe = false;
-var filtreLivraisonArchive = false;
-
-// VIEW
-var modalViewLivraison = false;
-var btnViewLivraison = false;
-var currentViewLivraison = 0;
-
-var livraisonsBaseURL = "livraisons.php";
-
-// ADD
-var modalAddLivraison = false;
-var formAddLivraison = false;
-var btnAddLivraison = false;
-
-// EDIT
-var modalEditLivraison = false;
-var formEditLivraison = false;
-var btnEditLivraison = false;
-var currentEditLivraison = 0;
-
-// ARCHIVE
-var modalArchiveLivraison = false;
-var btnArchiveLivraison = false;
-var btnUnarchiveLivraison = false;
-var currentArchiveLivraison = 0;
-
-// DELETE
-var modalDeleteLivraison = false;
-var btnDeleteLivraison = false;
-var currentDeleteLivraison = 0;
-
-$(document).ready( function() {
+// SETTINGS
+var livraisonsConf = {
+ type : "livraison",
+ baseURL : "livraisons.php",
+ // LIST
+ list_selector : "#livraisonsList",
// FILTRES
- filtreLivraisonGroupe = $("#livraisonsFiltre select[name=groupe]");
- filtreLivraisonArchive = $("#livraisonsFiltre select[name=archive]");
- if(filtreLivraisonGroupe.length>0 && filtreLivraisonArchive.length>0) initFiltresLivraisons();
-
- // INIT VIEW LIVRAISON
- modalViewLivraison = $("#modalViewLivraison");
- btnViewLivraison = $(".btnViewLivraison");
- if(modalViewLivraison.length>0 && btnViewLivraison.length>0) {
- initViewLivraison();
- // VIEW REQUEST
- var id = getUrlParameter("id");
- if(id!==false && parseInt(id)>0) loadDatasInViewLivraisonModal(id);
- }
-
- // INIT ADD LIVRAISON
- modalAddLivraison = $("#modalAddLivraison");
- formAddLivraison = $("#formAddLivraison");
- btnAddLivraison = $("#btnAddLivraison");
- if(modalAddLivraison.length>0 && formAddLivraison.length>0 && btnAddLivraison.length>0) initAddLivraison();
-
- // INIT EDIT LIVRAISON
- modalEditLivraison = $("#modalEditLivraison");
- formEditLivraison = $("#formEditLivraison");
- btnEditLivraison = $(".btnEditLivraison");
- if(modalEditLivraison.length>0 && formEditLivraison.length>0 && btnEditLivraison.length>0) initEditLivraison();
-
- // INIT ARCHIVE LIVRAISON
- modalArchiveLivraison = $("#modalArchiveLivraison");
- btnArchiveLivraison = $(".btnArchiveLivraison");
- btnUnarchiveLivraison = $(".btnUnarchiveLivraison");
- if(modalArchiveLivraison.length>0 && (btnArchiveLivraison.length>0 || btnUnarchiveLivraison.length>0)) initArchiveLivraison();
-
- // INIT DELETE LIVRAISON
- modalDeleteLivraison = $("#modalDeleteLivraison");
- btnDeleteLivraison = $(".btnDeleteLivraison");
- if(modalDeleteLivraison.length>0 && btnDeleteLivraison.length>0) initDeleteLivraison();
-});
-
-/***** FILTRES LIVRAISONS *****/
-function initFiltresLivraisons() {
- // GROUPE
- loadValue = filtreLivraisonGroupe.attr("load_value");
- filtreLivraisonGroupe.change(function(e) {
- $(this).blur();
- document.location = "?groupe="+parseInt($(this).val());
- }).val(loadValue);
+ filtres_selector : "#livraisonsSearch select",
+ // VIEW
+ view_modalSelector : "#modalViewLivraison",
+ view_btnSelector : ".btnViewLivraison",
+ // ADD
+ add_modalSelector : "#modalAddLivraison",
+ add_btnSelector : "#btnAddLivraison",
+ // EDIT
+ edit_modalSelector : "#modalEditLivraison",
+ edit_btnSelector : ".btnEditLivraison",
+ // COPY
+ copy_btnSelector : ".btnCopyLivraison",
// ARCHIVE
- loadValue = filtreLivraisonArchive.attr("load_value");
- filtreLivraisonArchive.change(function(e) {
- $(this).blur();
- document.location = "?archive="+parseInt($(this).val());
- }).val(loadValue);
+ archive_modalSelector : "#modalArchiveLivraison",
+ archive_btnSelector : ".btnArchiveLivraison",
+ unarchive_btnSelector : ".btnUnarchiveLivraison",
+ // DELETE
+ delete_modalSelector : "#modalDeleteLivraison",
+ delete_btnSelector : ".btnDeleteLivraison",
}
-/***** VIEW LIVRAISON *****/
-function initViewLivraison() {
- var form = modalViewLivraison.find("div.formLivraison");
+var legumeTarifUnitesAccronymes = { 'kg' : 'kg', 'pièce' : 'pc', 'botte' : 'bt' }
+
+var modalFormLivraison_copyCompoOrigin = false;
+
+// MODALS
+var modalViewLivraison = false;
+var modalAddLivraison = false;
+var modalEditLivraison = false;
+var modalArchiveLivraison = false;
+var modalDeleteLivraison = false;
+
+$(document).ready( function() {
+ // LIST LOADER
+ initListProgressLoad($(livraisonsConf.list_selector), livraisonsConf.baseURL, livraisonsConf.type+" list");
+
+ // SEARCH / FILTRES
+ $(livraisonsConf.filtres_selector).initFiltreSelect();
+
+ // VIEW
+ modalViewLivraison = $(livraisonsConf.view_modalSelector);
+ if(modalViewLivraison.length>0) {
+ initViewLivraison();
+ // VIEW REQUEST
+ var id = getUrlParameter("ref");
+ if(id!==false && parseInt(id)>0 && current_page == "livraisons") {
+ modalViewLivraison_clear(modalViewLivraison);
+ modalViewLivraison_loadDatas(modalViewLivraison, id);
+ }
+ }
+
+ // ADD
+ modalAddLivraison = $(livraisonsConf.add_modalSelector);
+ if(modalAddLivraison.length>0) initAddLivraison();
+
+ // EDIT
+ modalEditLivraison = $(livraisonsConf.edit_modalSelector);
+ if(modalEditLivraison.length>0) initEditLivraison();
+
+ // COPY
+ if(modalAddLivraison.length>0) initCopyLivraison();
+
+ // ARCHIVE
+ modalArchiveLivraison = $(livraisonsConf.archive_modalSelector);
+ if(modalArchiveLivraison.length>0) initArchiveLivraison();
+
+ // DELETE
+ modalDeleteLivraison = $(livraisonsConf.delete_modalSelector);
+ if(modalDeleteLivraison.length>0) initDeleteLivraison();
+});
+
+/***** MODAL VIEW *****/
+function initViewLivraison() {
+ // INIT VIEW BTNs
+ var initBtnFct = function() { modalForm_initBtnView(
+ $(livraisonsConf.view_btnSelector), // BTNs
+ modalViewLivraison, // MODAL
+ modalViewLivraison_clear, // CLEAR FUNCTION
+ modalViewLivraison_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
// TABS
- form.find("a.formLivraisonTabBtn").click(function(e) {
- e.preventDefault();
-
- // BTN
- if(!$(this).parent().hasClass("active")) {
- form.find("ul.formLivraisonTabs > li").removeClass('active');
- $(this).parent().addClass("active");
- }
-
- // TAB
- var tab = form.find("div.tab."+$(this).attr("tab"));
- if(tab.length>0) {
- if(tab.hasClass("active")) return;
-
- form.find("div.formLivraisonTabs > div.tab").removeClass("active");
- tab.addClass("active");
- }
- });
- resizeFormLivraison(form);
- $( window ).on( "resize", function() { resizeFormLivraison(form) });
+ modalForm_initTabs(modalViewLivraison);
// BTN PRINT
- form.find("div.btnPrint a").click(function(e) {
- e.preventDefault();
- url = livraisonsBaseURL+"?ref="+currentViewLivraison+"&action=getPDF&type="+$(this).attr("print_type");
- window.open(url, '_blank');
- });
-
- // BTN VIEW
- btnViewLivraison.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
+ modalViewLivraison.find("div.btnPrint a").click(function(e) {
+ e.preventDefault(); $(this).blur();
+ id = parseInt( modalViewLivraison.attr("view_id") );
if(!id>0) return;
- clearViewLivraisonModal();
- currentViewLivraison = id;
- loadDatasInViewLivraisonModal(id);
+ url = livraisonsConf.baseURL+"?ref="+id+"&action=getPDF&type="+$(this).attr("print_type");
+ window.open(url, '_blank');
});
// CANCEL
- modalViewLivraison.on('hidden.bs.modal', function (e) {
- clearViewLivraisonModal();
- currentViewLivraison = 0;
- });
+ modalViewLivraison.on('hidden.bs.modal', function() { modalViewLivraison_clear(modalViewLivraison); });
}
-function loadDatasInViewLivraisonModal(id) {
- datas = {
- 'ref' : id,
- 'action' : 'getDatas'
- };
- $.post( livraisonsBaseURL, datas, function( result ) {
- var datas = JSON.parse(result);
+function modalViewLivraison_loadDatas(modal, id) {
+ $.post(livraisonsConf.baseURL, { 'ref' : id, 'action' : 'getDatas' }, function(jsonTxt) {
+ var datas = JSON.parse(jsonTxt);
- modalViewLivraison.find("small.db_ref > span").html(datas.ref);
+ modal.find("small.db_ref > span").html(datas.ref);
- modalViewLivraison.find("td.groupe").html(datas.paniers_groupe_nom);
- modalViewLivraison.find("td.date").html(datas.date_print);
- modalViewLivraison.find("td.quinz_groupe").html(datas.quinz_groupe);
+ modal.find("td.groupe").html(datas.paniers_groupe_nom);
+ modal.find("td.date").html(datas.date_print);
+ modal.find("td.quinz_groupe").html(datas.quinz_groupe);
if(datas.paniers_contrats.length>0) {
// PANIERS
- $.post(livraisonsBaseURL, { 'ref' : id, 'action' : 'modalView_getTab', 'tab' : 'paniers' }, function(result) {
- modalViewLivraison.find("div.tabPaniers").html(result);
- }).fail(function() { alert(srvErrorMsg+" (load modal view livraison - tab paniers)"); });
+ $.post(livraisonsConf.baseURL, { 'ref' : id, 'action' : 'modalView_getTab', 'tab' : 'paniers' }, function(result) {
+ modal.find("div.tabPaniers").html(result);
+ }).fail(function() { alert("ERREUR SERVEUR (modal view livraison - load tab paniers)"); });
// COMPO
if(datas.legumes.length>0) {
- $.post(livraisonsBaseURL, { 'ref' : id, 'action' : 'modalView_getTab', 'tab' : 'compo' }, function(result) {
- modalViewLivraison.find("div.tabCompo").html(result);
- }).fail(function() { alert(srvErrorMsg+" (load modal view livraison - tab compo)"); });
+ $.post(livraisonsConf.baseURL, { 'ref' : id, 'action' : 'modalView_getTab', 'tab' : 'compo' }, function(result) {
+ modal.find("div.tabCompo").html(result);
+ }).fail(function() { alert("ERREUR SERVEUR (modal view livraison - load tab compo)"); });
}
else {
- modalViewLivraison.find("ul.formLivraisonTabs li[tab=tabCompo]").addClass("hide");
- modalViewLivraison.find("div.btnPrint li[print_type=compo]").addClass("hide");
+ modal.find("ul.modalLivraisonTabs li[tab=tabCompo]").addClass("hide");
+ modal.find("div.btnPrint li[print_type=compo]").addClass("hide");
}
// LEGUMES
if(Object.keys(datas.total_legumes.legumes).length>0) {
- $.post(livraisonsBaseURL, { 'ref' : id, 'action' : 'modalView_getTab', 'tab' : 'legumes' }, function(result) {
- modalViewLivraison.find("div.tabLegumes").html(result);
- }).fail(function() { alert(srvErrorMsg+" (load modal view livraison - tab legumes)"); });
+ $.post(livraisonsConf.baseURL, { 'ref' : id, 'action' : 'modalView_getTab', 'tab' : 'legumes' }, function(result) {
+ modal.find("div.tabLegumes").html(result);
+ }).fail(function() { alert("ERREUR SERVEUR (modal view livraison - load tab legumes)"); });
}
else {
- modalViewLivraison.find("ul.formLivraisonTabs li[tab=tabLegumes]").addClass("hide");
- modalViewLivraison.find("div.btnPrint li[print_type=legumes]").addClass("hide");
+ modal.find("ul.modalLivraisonTabs li[tab=tabLegumes]").addClass("hide");
+ modal.find("div.btnPrint li[print_type=legumes]").addClass("hide");
}
}
else {
- modalViewLivraison.find("ul.formLivraisonTabs li:not([tab=tabGeneral])").addClass("hide");
- modalViewLivraison.find("div.btnPrint").addClass("hide");
- }
-
- modalViewLivraison.modal('show');
- }).fail(function() { alert(srvErrorMsg+" (load modal view livraison)"); });
-}
-
-function clearViewLivraisonModal() {
- modalViewLivraison.find("small.db_ref > span").html("");
-
- modalViewLivraison.find("ul.formLivraisonTabs > li").removeClass('active hide');
- modalViewLivraison.find("ul.formLivraisonTabs > li:first-child").addClass('active');
- modalViewLivraison.find("div.formLivraisonTabs > div.tab").removeClass("active");
- modalViewLivraison.find("div.formLivraisonTabs > div.tab:first-child").addClass("active");
- modalViewLivraison.find("div.btnPrint").removeClass("hide").find('li').removeClass("hide");
-
- modalViewLivraison.find("td.groupe").html("");
- modalViewLivraison.find("td.date").html("");
- modalViewLivraison.find("td.quinz_groupe").html("");
-
- modalViewLivraison.find("div.tabPaniers").html("aucun panier ");
- modalViewLivraison.find("div.tabCompo").html("aucun panier ");
- modalViewLivraison.find("div.tabLegumes").html("aucun légume ");
-
- modalViewLivraison.find("td.date").html("");
-}
-
-/***** FORM LIVRAISON *****/
-function initFormLivraison(form) {
- form.on("submit", function(e) { e.preventDefault(); });
-
- // TABS
- form.find("a.formLivraisonTabBtn").click(function(e) {
- e.preventDefault();
-
- // BTN
- if(!$(this).parent().hasClass("active")) {
- form.find("ul.formLivraisonTabs > li").removeClass('active');
- $(this).parent().addClass("active");
+ modal.find("ul.modalLivraisonTabs li:not([tab=tabGeneral])").addClass("hide");
+ modal.find("div.btnPrint").addClass("hide");
}
- // TAB
- var tab = form.find("div.tab."+$(this).attr("tab"));
- if(tab.length>0) {
- if(tab.hasClass("active")) return;
-
- form.find("div.formLivraisonTabs > div.tab").removeClass("active");
- tab.addClass("active");
- }
- });
+ modal.modal('show');
+ }).fail(function() { alert("("+livraisonsConf.type+" - load modal view)"); });
+}
+
+function modalViewLivraison_clear(modal) {
+ modal.removeAttr("view_id");
+ modalForm_resetTabs(modal);
+
+ modal.find("small.db_ref > span").html("");
+
+ modal.find("td.groupe").html("");
+ modal.find("td.date").html("");
+ modal.find("td.quinz_groupe").html("");
+
+ modal.find("div.tabPaniers").html("aucun panier ");
+ modal.find("div.tabCompo").html("aucun panier ");
+ modal.find("div.tabLegumes").html("aucun légume ");
+}
+
+/***** MODAL FORM ADD/EDIT *****/
+function modalFormLivraison_init(modal) {
+ modal.find("modal").on("submit", function(e) { e.preventDefault(); });
+ modalForm_initTabs(modal);
// TAB GENERAL
- form.find("select[name=paniers_groupe]").change(function(e) { $(this).blur(); loadLivraisonsPaniers(form, []); loadLivraisonNextGroupe(form); });
- form.find("input[name=date]").blur(function(e) { loadLivraisonsPaniers(form, []); loadLivraisonNextGroupe(form); });
- form.find("input[name=date]").keydown(function(e) { if(e.keyCode==13) { e.preventDefault(); $(this).blur(); } })
- form.find("select[name=quinz_groupe]").change(function(e) { $(this).blur(); loadLivraisonsPaniers(form, []); });
+ modal.find("select[name=paniers_groupe]").change(function(e) {
+ $(this).blur();
+ modalFormLivraison_loadPaniers(modal, []);
+ modalFormLivraison_loadNextGroupe(modal);
+ });
+ modal.find("input[name=date]").on("blur change", function(e) {
+ modalFormLivraison_loadPaniers(modal, []);
+ modalFormLivraison_loadNextGroupe(modal);
+ });
+ modal.find("input[name=date]").keydown(function(e) { if(e.keyCode==13) { e.preventDefault(); $(this).blur(); } })
+ modal.find("select[name=quinz_groupe]").change(function(e) {
+ $(this).blur();
+ modalFormLivraison_loadPaniers(modal, []);
+ });
// TAB PANIERS
- form.find("thead.paniersList td.status").click(function(e) {
+ modal.find("thead.paniersList td.status").click(function(e) {
var allChecked = true;
- form.find("tbody.paniersList input[name='status']").each(function(n,e) { if(!$(this).prop("checked")) allChecked = false; });
- if(allChecked) form.find("tbody.paniersList input[name='status']").prop("checked", false);
- else form.find("tbody.paniersList input[name='status']").prop("checked", true);
+ modal.find("tbody.paniersList input[name='status']").each(function(n,e) { if(!$(this).prop("checked")) allChecked = false; });
+ if(allChecked) modal.find("tbody.paniersList input[name='status']").prop("checked", false);
+ else modal.find("tbody.paniersList input[name='status']").prop("checked", true);
});
- resizeFormLivraison(form);
- $( window ).on( "resize", function() { resizeFormLivraison(form) });
+ modalFormLivraison_clear(modal);
}
-function resizeFormLivraison(form) {
- var wh = window.innerHeight;
- form.find("div.formLivraisonTabs div.tab").css("max-height", (wh-180)+"px");
-}
+function modalFormLivraison_loadDatas(modal,id) {
+ $.post(livraisonsConf.baseURL, { 'ref' : id, 'action' : 'getDatas' }, function(jsonTxt) {
+ var datas = JSON.parse(jsonTxt);
-function loadDatasInFormLivraisonDatas(modal,form,id) {
- datas = {
- 'ref' : id,
- 'action' : 'getDatas'
- };
- $.post(livraisonsBaseURL, datas, function(result) {
- var datas = JSON.parse(result);
-
- form.find("select[name=paniers_groupe]").val(datas.paniers_groupe_ref);
- form.find("input[name=date]").val(datas.date);
- form.find("select[name=quinz_groupe]").val(datas.quinz_groupe);
-
- loadLivraisonsPaniers(form, datas.paniers_contrats);
- udpateCompo(form, datas.legumes);
+ modal.find("select[name=paniers_groupe]").val(datas.paniers_groupe_ref);
+ modal.find("input[name=date]").val(datas.date);
+ modal.find("select[name=quinz_groupe]").val(datas.quinz_groupe);
+ modalFormLivraison_loadPaniers(modal, datas.paniers_contrats);
+ modalFormLivraison_udpateCompo(modal, datas.legumes);
+
if(modal) modal.modal('show');
- }).fail(function() { alert(srvErrorMsg+" (form livraison - load datas)"); });
+ }).fail(function() { alert("("+livraisonsConf.type+" - load datas in modal form)"); });
}
-function clearFormLivraisonDatas(form) {
- form.find("ul.formLivraisonTabs > li").removeClass('active');
- form.find("ul.formLivraisonTabs > li:first-child").addClass('active');
- form.find("div.formLivraisonTabs > div.tab").removeClass("active");
- form.find("div.formLivraisonTabs > div.tab:first-child").addClass("active");
+function modalFormLivraison_clear(modal) {
+ modal.removeAttr("edit_id");
+ modal.find("div.modaLoader").removeClass("show");
+ modalForm_resetTabs(modal);
- form.find("select[name=paniers_groupe]").val("");
- form.find("input[name=date]").val(getTodayDate("yyyy-mm-dd"));
- form.find("select[name=quinz_groupe]").val("A");
+ modal.find("select[name=paniers_groupe]").val("");
+ modal.find("input[name=date]").val(getTodayDate("yyyy-mm-dd"));
+ modal.find("select[name=quinz_groupe]").val("A");
- clearPanierItems(form);
- clearCompo(form);
-
- // MODALOADER
- form.find("div.modaLoader").removeClass("show");
+ modalFormLivraison_clearPaniers(modal);
+ modalFormLivraison_clearCompo(modal);
}
// LIVRAISON - PANIERS
-function loadLivraisonNextGroupe(form) {
+function modalFormLivraison_loadNextGroupe(modal) {
$datas = {
'action' : 'last_quinz_groupe',
- 'groupe' : form.find("select[name=paniers_groupe]").val(),
- 'date' : form.find("input[name=date]").val()
+ 'groupe' : modal.find("select[name=paniers_groupe]").val(),
+ 'date' : modal.find("input[name=date]").val()
};
- $.post(livraisonsBaseURL, $datas, function(result) {
+ $.post(livraisonsConf.baseURL, $datas, function(result) {
$grp = "A";
if(result == "A") $grp = "B";
else if(result != "B") return;
- form.find("select[name=quinz_groupe]").val($grp);
- }).fail(function() { alert(srvErrorMsg+" (form livraison - get next groupe)"); });
+ modal.find("select[name=quinz_groupe]").val($grp);
+ }).fail(function() { alert("ERREUR SERVEUR (modal form livraison - get next groupe)"); });
}
-function loadLivraisonsPaniers(form, paniers) {
+function modalFormLivraison_loadPaniers(modal, paniers) {
var oldPaniersStates = {};
- form.find("div.tabPaniers table.panier tbody tr.panier").each(function(e) {
+ modal.find("div.tabPaniers table.panier tbody tr.panier").each(function(e) {
oldPaniersStates[ $(this).attr("contrat") ] = $(this).find("input[name=status]").prop("checked");
});
- clearPanierItems(form);
+ modalFormLivraison_clearPaniers(modal);
datas = {
'action' : 'paniers_eligibles',
- 'paniers_groupe' : parseInt( form.find("select[name=paniers_groupe]").val() ),
- 'date' : form.find("input[name=date]").val(),
- 'quinz_groupe' : form.find("select[name=quinz_groupe]").val()
+ 'paniers_groupe' : parseInt( modal.find("select[name=paniers_groupe]").val() ),
+ 'date' : modal.find("input[name=date]").val(),
+ 'quinz_groupe' : modal.find("select[name=quinz_groupe]").val()
};
if(datas.paniers_groupe>0 && datas.date != "" && datas.quinz_groupe!="") {
- $.post(livraisonsBaseURL, datas, function(result) {
- form.find("div.tabPaniers").html(result);
+ $.post(livraisonsConf.baseURL, datas, function(result) {
+ modal.find("div.tabPaniers").html(result);
$('[data-toggle="tooltip"]').tooltip();
// APPLY CB STATUS
- form.find("div.tabPaniers table.panier tbody tr.panier").each(function(n,e) {
+ modal.find("div.tabPaniers table.panier tbody tr.panier").each(function(n,e) {
ref = parseInt($(this).attr("contrat"));
if($(this).hasClass('absent')) return;
state = true;
@@ -336,38 +271,38 @@ function loadLivraisonsPaniers(form, paniers) {
});
// INIT CHECKBOX
- form.find("div.tabPaniers table.panier input[name=status]").click(function(e) { $(this).blur(); updateNbPaniersType(form); });
+ modal.find("div.tabPaniers table.panier input[name=status]").click(function(e) { $(this).blur(); modalFormLivraison_updateNbPaniersType(modal); });
// INIT TR CLICK
- form.find("div.tabPaniers table.panier tr.panier").click(function(e) { $(this).find("input[name=status]").click(); });
+ modal.find("div.tabPaniers table.panier tr.panier").click(function(e) { $(this).find("input[name=status]").click(); });
// CHECK GROUP
- form.find("div.tabPaniers tr.lieuTitre").click(function(e) {
+ modal.find("div.tabPaniers tr.lieuTitre").click(function(e) {
var tr = $(this).parent().parent().find("tr.panier:not(.absent)");
if( tr.find("input:not(:checked)").length>0 ) tr.find("input:not(:checked)").prop("checked", true);
else tr.find("input").prop("checked", false);
});
- form.find("div.tabPaniers tr.panierTitre").click(function(e) {
+ modal.find("div.tabPaniers tr.panierTitre").click(function(e) {
var tr = $(this).parent().find("tr.panier:not(.absent)[type_ref="+$(this).attr("type_ref")+"]");
if( tr.find("input:not(:checked)").length>0 ) tr.find("input:not(:checked)").prop("checked", true);
else tr.find("input").prop("checked", false);
});
// UPDATE NB PANIERS
- updateNbPaniersType(form);
+ modalFormLivraison_updateNbPaniersType(modal);
- }).fail(function() { alert(srvErrorMsg+" (form livraison - load paniers eligibles)"); });
+ }).fail(function() { alert("ERREUR SERVEUR (modal form livraison - load paniers eligibles)"); });
}
}
-function clearPanierItems(form) {
- form.find("div.tabPaniers").html('aucun panier éligible ');
+function modalFormLivraison_clearPaniers(modal) {
+ modal.find("div.tabPaniers").html('aucun panier éligible ');
}
-function calcNbPanierType(form) {
+function modalFormLivraison_calcNbPanierType(modal) {
var calc = {};
- form.find("div.tabPaniers table.panier tbody tr.panier").each(function(e) {
+ modal.find("div.tabPaniers table.panier tbody tr.panier").each(function(e) {
if($(this).find("input[name=status]").prop("checked")) {
ref = parseInt($(this).attr("type_ref"));
nom = $(this).attr("type_nom");
@@ -386,9 +321,9 @@ function calcNbPanierType(form) {
return calc;
}
-function updateNbPaniersType(form) {
+function modalFormLivraison_updateNbPaniersType(modal) {
// CHAQUE LIEU
- form.find("div.tabPaniers table.panier").each(function(n,e) {
+ modal.find("div.tabPaniers table.panier").each(function(n,e) {
var table = $(this);
var nbTotalPaniers = 0;
// CHAQUE TYPE DE PANIER
@@ -405,39 +340,46 @@ function updateNbPaniersType(form) {
table.find("tr.lieuTitre th.nb_total_paniers").html(nbTotalPaniers+" panier"+(nbTotalPaniers>1?"s":""));
});
- udpateCompo(form);
+ modalFormLivraison_udpateCompo(modal);
}
// LIVRAISON - COMPO
-function udpateCompo(form, paniersTypes) {
+function modalFormLivraison_udpateCompo(modal, paniersTypes) {
// GET PANIERS TYPES LIST
- if(typeof(paniersTypes)!="object") paniersTypes = getLivraisonPaniersCompo(form);
+ if(typeof(paniersTypes)!="object") paniersTypes = modalFormLivraison_getPaniersCompo(modal);
// CLEAR COMPO
- clearCompo(form);
+ modalFormLivraison_clearCompo(modal);
// CREATE PANIERS
- $.each(paniersTypes, function(n,e) { addPanierTypeCompo(form, e); form.find("div.tabCompo span.nullChild").addClass("hide"); });
+ $.each(paniersTypes, function(n,e) { modalFormLivraison_addPanierTypeCompo(modal, e); modal.find("div.tabCompo span.nullChild").addClass("hide"); });
// UPDATE TOTAL
- updateLivraisonTotalPaniersLegumes(form);
+ modalFormLivraison_updateTotalLegumes(modal);
}
-function addPanierTypeCompo(form, datas) {
+function modalFormLivraison_addPanierTypeCompo(modal, datas) {
var table = $("")
.attr("ref", datas.ref)
- .attr("form", form.attr('id'));
+ .attr("modal", modal.attr('id'));
// HEADER
var thead = $(" ");
var trT = $(" ");
trT.append( $(" ").html(datas.nom+" (x"+datas.nb+") ") );
trT.append( $("TOTAL : ") );
- trT.append( $("0.00 ") );
+ trT.append( $("0.00 ") );
trT.append( $("€ ") );
+ btnCopyCompo = $(" ");
+ trT.append( $(" ").append(btnCopyCompo) );
thead.append(trT);
+ btnCopyCompo.click(function(e) {
+ e.preventDefault(); $(this).blur();
+ modalFormLivraison_copyPanierTypeCompo(modal, table, $(this));
+ })
+
var trH = $(" ");
trH.append( $("légume ") );
trH.append( $("tarif ") );
@@ -448,7 +390,7 @@ function addPanierTypeCompo(form, datas) {
thead.append(trH);
table.append(thead);
- btnAddLegume.click(function(e) { e.preventDefault(); $(this).blur(); addPanierTypeCompoLegume(table, "new"); });
+ btnAddLegume.click(function(e) { e.preventDefault(); $(this).blur(); modalFormLivraison_addPanierTypeCompoLegume(modal, table, "new"); });
// LEGUMES
var tbody = $(" ");
@@ -456,21 +398,19 @@ function addPanierTypeCompo(form, datas) {
tbody.append(trNull);
table.append(tbody);
if(datas.legumes && datas.legumes.length>0) {
- datas.legumes.forEach(l => { addPanierTypeCompoLegume(table, l); });
- updateMontantTotalPanier(table);
+ datas.legumes.forEach(l => { modalFormLivraison_addPanierTypeCompoLegume(modal, table, l); });
+ modalFormLivraison_updateMontantTotalPanier(table);
}
else trNull.removeClass("hide");
- form.find("div.tabCompo").append(table);
+ modal.find("div.tabCompo").append(table);
}
-var legumeTarifUnitesAccronymes = { 'kg' : 'kg', 'pièce' : 'pc', 'botte' : 'bt' }
-
-function addPanierTypeCompoLegume(panier, datas) {
+function modalFormLivraison_addPanierTypeCompoLegume(modal, panier, datas) {
panier.find("tbody tr.nullChild").addClass("hide");
/*** CREATE ***/
- var trL = $(" ");
+ var trL = $(" ");
tdNom = $(" ");
tdTarif = $("0.00 ");
tdTarifUnit = $("€/kg ");
@@ -515,74 +455,73 @@ function addPanierTypeCompoLegume(panier, datas) {
.attr('tarif_unite', $(this).attr('tarif_unite'));
$(this).html("").append(ipt);
- ipt.autocomplete({
- html: true,
- delay: 200,
- source: function(requete, reponse) {
- datas = {
- 'action' : 'autocomplete_list',
- 'search' : ipt.val(),
- 'nohist' : true
- };
- $.post("legumes.php", datas, function(jsonTxt) {
- reponse(JSON.parse(jsonTxt));
- }).fail(function() { alert(srvErrorMsg+" (form livraison - compo - legume autocomplete)"); });;
+ initAutocompleteInput(
+ modal, // FORMULAIRE
+ ipt, // INPUT
+ "legumes.php", // URL
+ 'autocomplete_list', // REQUEST ACTION
+ "(modal form livraison - compo legume autocomplete)", // ERROR CONTEXT
+ // REQUEST DATAS
+ function(modal, ipt, datas) {
+ datas.paniers_groupe = modal.find("select[name=paniers_groupe]").val();
+ return datas;
},
- focus: function(event, ui) { event.preventDefault(); },
- select: function(event, ui) {
- event.preventDefault();
- ipt.val( ui.item.value )
- .attr('ref', ui.item.ref)
- .attr('tarif_ref', ui.item.tarif_ref)
- .attr('tarif_prix', ui.item.tarif_prix)
- .attr('tarif_unite', ui.item.tarif_unite)
- .blur();
+ // SELECT
+ function(modal, ipt, datas) {
+ ipt.val( datas.value )
+ .attr('ref', datas.ref)
+ .attr('tarif_ref', datas.tarif_ref)
+ .attr('tarif_prix', datas.tarif_prix)
+ .attr('tarif_unite', datas.tarif_unite)
+ .blur();
+ },
+ // CLEAR
+ function(modal, ipt) {
+ ipt.val("")
+ .removeAttr('ref')
+ .removeAttr('tarif_ref')
+ .removeAttr('tarif_prix')
+ .removeAttr('tarif_unite');
+ },
+ // BLUR
+ function(modal, ipt) {
+ val = ipt.val();
+ ref = parseInt( ipt.attr("ref") );
+ tarif_ref = parseInt( ipt.attr("tarif_ref") );
+ tarif_prix = parseFloat( ipt.attr("tarif_prix") );
+ tarif_unite = ipt.attr("tarif_unite");
+ unite = legumeTarifUnitesAccronymes[tarif_unite];
+
+ if(ref>0 && tarif_ref>0) {
+ var td = ipt.parent(); var tr = td.parent();
+
+ tr.attr("ref", ref);
+
+ td.html( val )
+ .attr('ref', ref)
+ .attr('tarif_ref', tarif_ref)
+ .attr('tarif_prix', tarif_prix)
+ .attr('tarif_unite', tarif_unite);
+
+ tr.find("td.tarif").html(number_format(tarif_prix,2)).attr("ref", tarif_ref);
+ tr.find("td.tarif_unite").html("€/"+unite);
+
+ q = tr.find("td.quantite").attr('unite', tarif_unite).html();
+ if(tarif_unite=="kg") tr.find("td.quantite").html( number_format(q,3) );
+ else tr.find("td.quantite").html( parseInt(q) );
+
+ tr.find("td.quantite_unite").html(unite);
+
+ tr.updateCompoLegumeMontant();
+
+ tr.find("td.quantite").dblclick();
+ }
+ else {
+ beep(50, 800, null, "square");
+ ipt.focus();
+ }
}
- });
- ipt.keydown(function(e) {
- if(parseInt($(this).attr('ref'))>0) {
- if(e.keyCode==13) { e.preventDefault(); $(this).blur(); }
- else $(this).val("").removeAttr('ref').removeAttr('tarif_ref').removeAttr('tarif_prix').removeAttr('tarif_unite');
- }
- });
-
- ipt.blur(function(e) {
- val = $(this).val();
- ref = parseInt( $(this).attr("ref") );
- tarif_ref = parseInt( $(this).attr("tarif_ref") );
- tarif_prix = parseFloat( $(this).attr("tarif_prix") );
- tarif_unite = $(this).attr("tarif_unite");
- unite = legumeTarifUnitesAccronymes[tarif_unite];
-
- if(ref>0 && tarif_ref>0) {
- var td = $(this).parent(); var tr = td.parent();
-
- tr.attr("ref", ref);
-
- td.html( val )
- .attr('ref', ref)
- .attr('tarif_ref', tarif_ref)
- .attr('tarif_prix', tarif_prix)
- .attr('tarif_unite', tarif_unite);
-
- tr.find("td.tarif").html(number_format(tarif_prix,2)).attr("ref", tarif_ref);
- tr.find("td.tarif_unite").html("€/"+unite);
-
- q = tr.find("td.quantite").attr('unite', tarif_unite).html();
- if(tarif_unite=="kg") tr.find("td.quantite").html( number_format(q,3) );
- else tr.find("td.quantite").html( parseInt(q) );
-
- tr.find("td.quantite_unite").html(unite);
-
- tr.updateCompoLegumeMontant();
-
- tr.find("td.quantite").dblclick();
- }
- else {
- beep(50, 800, null, "square");
- $(this).focus();
- }
- });
+ );
ipt.select();
});
tdQ.dblclick(function(e) {
@@ -606,13 +545,43 @@ function addPanierTypeCompoLegume(panier, datas) {
e.preventDefault();
trL.remove();
if(panier.find("tbody tr.legume").length==0) panier.find("tbody tr.nullChild").removeClass("hide");
- updateMontantTotalPanier(panier);
+ modalFormLivraison_updateMontantTotalPanier(panier);
})
/*** START ***/
if(datas == "new") tdNom.dblclick();
}
+function modalFormLivraison_copyPanierTypeCompo(modal, panier, btn) {
+ // COPY
+ if(!modalFormLivraison_copyCompoOrigin>0) {
+ var compo = modalFormLivraison_getPanierCompoLegumes(modal, panier.attr('ref'));
+ if(!compo.length>0) return;
+ modalFormLivraison_copyCompoOrigin = panier.attr("ref");
+ modal.find(".btnCopyCompo").removeClass("btn-default").addClass("btn-warning")
+ .removeClass("glyphicon-copy").addClass("glyphicon-paste");
+ btn.removeClass("btn-warning").addClass("btn-info")
+ .removeClass("glyphicon-paste").addClass("glyphicon-remove");
+ }
+ // PASTE
+ else {
+ if(modalFormLivraison_copyCompoOrigin != panier.attr("ref")) {
+ var oldCompo = modalFormLivraison_getPanierCompoLegumes(modal, panier.attr('ref'));
+ if(oldCompo.length>0) { if(!confirm("Etês-vous sûr de vouloir remplacer le contenu de ce panier ?")) return; }
+ var legumes = modalFormLivraison_getPanierCompoLegumes(modal, modalFormLivraison_copyCompoOrigin);
+ // CLEAR
+ panier.find("tbody").children().remove();
+ // PASTE
+ legumes.forEach(l => { modalFormLivraison_addPanierTypeCompoLegume(modal, panier, l); });
+ modalFormLivraison_updateMontantTotalPanier(panier);
+ }
+
+ modalFormLivraison_copyCompoOrigin = false;
+ modal.find(".btnCopyCompo").removeClass("btn-warning").removeClass("btn-info").addClass("btn-default")
+ .removeClass("glyphicon-paste").removeClass("glyphicon-remove").addClass("glyphicon-copy");
+ }
+}
+
$.fn.updateCompoLegumeMontant = function() {
q = parseFloat($(this).find("td.quantite").html());
t = parseFloat($(this).find("td.tarif").html());
@@ -620,32 +589,33 @@ $.fn.updateCompoLegumeMontant = function() {
// UPDATE TOTAL
panier = $(this).parent().parent();
- updateMontantTotalPanier(panier);
+ modalFormLivraison_updateMontantTotalPanier(panier);
+ panier.find(".btnAddLegume").focus();
};
-function updateMontantTotalPanier(panier) {
+function modalFormLivraison_updateMontantTotalPanier(panier) {
var total = 0;
panier.find("tr.legume td.montant").each(function(n,e) { total += parseFloat($(this).html()); })
panier.find("th.total.montant").html(number_format(total, 2));
- form = $("#"+panier.attr('form'));
- if(form.length>0) updateLivraisonTotalPaniersLegumes(form);
+ modal = $("#"+panier.attr('modal'));
+ if(modal.length>0) modalFormLivraison_updateTotalLegumes(modal);
}
-function clearCompo(form) {
- form.find("div.tabCompo table.panier").remove();
- form.find("div.tabCompo span.nullChild").removeClass("hide");
+function modalFormLivraison_clearCompo(modal) {
+ modal.find("div.tabCompo table.panier").remove();
+ modal.find("div.tabCompo span.nullChild").removeClass("hide");
}
// LIVRAISON - LEGUMES
-function updateLivraisonTotalPaniersLegumes(form) {
+function modalFormLivraison_updateTotalLegumes(modal) {
var legumes = {};
- form.find("table.legumesTotal tr.legume").remove();
- form.find("table.legumesTotal tr.nullChild").removeClass('hide');
+ modal.find("table.legumesTotal tr.legume").remove();
+ modal.find("table.legumesTotal tr.nullChild").removeClass('hide');
/*** CALC TOTAL LEGUMES ***/
- var paniers = getLivraisonPaniersCompo(form);
+ var paniers = modalFormLivraison_getPaniersCompo(modal);
for(r in paniers) {
p = paniers[r];
for (const l of p.legumes) {
@@ -673,59 +643,59 @@ function updateLivraisonTotalPaniersLegumes(form) {
tdMunit = $("€ ");
trL.append(tdNom).append(tdTarif).append(tdTarifUnit).append(tdQ).append(tdQunit).append(tdMontant).append(tdMunit);
- form.find("table.legumesTotal tbody").append(trL);
- form.find("table.legumesTotal tr.nullChild").addClass('hide');
+ modal.find("table.legumesTotal tbody").append(trL);
+ modal.find("table.legumesTotal tr.nullChild").addClass('hide');
total += l.quantite * l.tarif_prix;
}
/*** MONTANT TOTAL ***/
- form.find("table.legumesTotal th.total.montant").html(number_format(total, 2));
+ modal.find("table.legumesTotal th.total.montant").html(number_format(total, 2));
}
// GET FORM DATAS
-function getLivraisonFormDatas(form) {
+function modalFormLivraison_getDatas(modal) {
var datas = {
- "paniers_groupe" : parseInt(form.find("select[name=paniers_groupe]").val()),
- 'date' : form.find("input[name=date]").val(),
- 'quinz_groupe' : form.find("select[name=quinz_groupe]").val(),
- 'paniers' : JSON.stringify(getLivraionPaniers(form)),
- 'paniersCompo' : JSON.stringify(getLivraisonPaniersCompo(form))
+ "paniers_groupe" : parseInt(modal.find("select[name=paniers_groupe]").val()),
+ 'date' : modal.find("input[name=date]").val(),
+ 'quinz_groupe' : modal.find("select[name=quinz_groupe]").val(),
+ 'paniers' : JSON.stringify( modalFormLivraison_getPaniers(modal) ),
+ 'paniersCompo' : JSON.stringify( modalFormLivraison_getPaniersCompo(modal) )
};
return datas;
}
-function getLivraionPaniers(form) {
+function modalFormLivraison_getPaniers(modal) {
var paniers = [];
- form.find("div.tabPaniers table.panier tbody tr.panier").each(function(e) {
+ modal.find("div.tabPaniers table.panier tbody tr.panier").each(function(e) {
if($(this).find("input[name=status]").prop("checked")) paniers.push(parseInt($(this).attr("contrat")));
});
return paniers;
}
-function getLivraisonPaniersCompo(form) {
- var paniersTypes = calcNbPanierType(form);
+function modalFormLivraison_getPaniersCompo(modal) {
+ var paniersTypes = modalFormLivraison_calcNbPanierType(modal);
var legumes = {};
for(p in paniersTypes) {
legumes[p] = paniersTypes[p];
- legumes[p].legumes = getLivraisonPanierCompoLegumes(form, p);
+ legumes[p].legumes = modalFormLivraison_getPanierCompoLegumes(modal, p);
}
return legumes;
}
-function getLivraisonPanierCompoLegumes(form, ref) {
- var table = form.find("table.panier[ref="+ref+"]");
+function modalFormLivraison_getPanierCompoLegumes(modal, ref) {
+ var table = modal.find("table.panier[ref="+ref+"]");
var legumes = [];
table.find("tr.legume").each(function(n,e) {
- datas = getLivraisonPanierCompoLegumeDatas($(this));
+ datas = modalFormLivraison_getPanierCompoLegumeDatas($(this));
if(typeof(datas) == "object") legumes.push(datas);
});
return legumes;
}
-function getLivraisonPanierCompoLegumeDatas(tr) {
+function modalFormLivraison_getPanierCompoLegumeDatas(tr) {
ref = parseInt( tr.attr('ref') );
if(ref>0) {
tdNom = tr.find("td.nom");
@@ -741,221 +711,162 @@ function getLivraisonPanierCompoLegumeDatas(tr) {
return null;
}
-/***** ADD LIVRAISON *****/
-function initAddLivraison() {
- // BTN ADD
- btnAddLivraison.unbind('click').click( function(event) {
- event.preventDefault();
- clearFormLivraisonDatas(formAddLivraison);
- modalAddLivraison.modal('show');
- });
-
- // INIT FORM ADD
- initFormLivraison(formAddLivraison);
-
- // SAVE LIVRAISON
- $(".btnSaveAddLivraison").unbind('click').click( function(event) {
- event.preventDefault();
-
- var datas = getLivraisonFormDatas(formAddLivraison);
-
- if(!datas.paniers_groupe>0 ||datas.date=="" || datas.quinz_groupe=="") {
- alert("ERREUR : au minimum un groupe de contrats, une date et un groupe bi-hebdo doivent être renseigné !");
- return;
- }
-
- datas.action = 'add';
-
- formAddLivraison.find("div.modaLoader").addClass("show");
- $(".btnSaveAddLivraison").prop("disabled", true);
-
- $.post( livraisonsBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- modalAddLivraison.modal('hide');
- setTimeout(function() {
- document.location.reload();
- },200);
- }
- else {
- console.error(result);
- alert(result);
- formAddLivraison.find("div.modaLoader").removeClass("show");
- $(".btnSaveAddLivraison").prop("disabled", false);
- }
- }).fail(function() {
- alert(srvErrorMsg+" (add livraison)");
- formAddLivraison.find("div.modaLoader").removeClass("show");
- $(".btnSaveAddLivraison").prop("disabled", false);
- });
- });
-
- // CANCEL
- modalAddLivraison.on('hidden.bs.modal', function (e) { clearFormLivraisonDatas(formAddLivraison); });
+function modalFormLivraison_checkDatas(datas) {
+ if(!datas.paniers_groupe>0 ||datas.date=="" || datas.quinz_groupe=="") {
+ alert("ERREUR : au minimum un groupe de contrats, une date et un groupe bi-hebdo doivent être renseigné !");
+ return false;
+ }
+ return true;
}
-/***** EDIT LIVRAISON *****/
+/***** ADD *****/
+function initAddLivraison() {
+ // INIT FORM
+ modalFormLivraison_init(modalAddLivraison);
+
+ // INIT ADD BTN
+ modalForm_initBtnAdd(
+ $(livraisonsConf.add_btnSelector), // BTN ADD
+ modalAddLivraison, // MODAL
+ modalFormLivraison_clear // CLEAR FORM FUNCTION
+ );
+
+ // INIT SAVE BTN
+ modalForm_initBtnSaveAdd(
+ modalAddLivraison.find(".btnSave"), // BTN SAVE
+ livraisonsConf.type, // ADD TYPE
+ modalAddLivraison, // MODAL
+ modalFormLivraison_getDatas, // GET FORM DATAS FUNCTION
+ modalFormLivraison_checkDatas, // CHECK FORM DATAS FUNCTION
+ livraisonsConf.baseURL // SAVE URL
+ );
+
+ // CANCEL
+ modalAddLivraison.on('hidden.bs.modal', function (e) { modalFormLivraison_clear(modalAddLivraison); });
+}
+
+/***** COPY ARTICLE *****/
+function initCopyLivraison() {
+ // INIT COPY BTNs
+ var initBtnFct = function() { modalForm_initBtnCopy(
+ $(livraisonsConf.copy_btnSelector), // BTNs
+ modalAddLivraison, // MODAL
+ modalFormLivraison_clear, // CLEAR FUNCTION
+ modalFormLivraison_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
+}
+
+/***** EDIT *****/
function initEditLivraison() {
- // BTN EDIT
- btnEditLivraison.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
- currentEditLivraison = id;
- clearFormLivraisonDatas(formEditLivraison);
- loadDatasInFormLivraisonDatas(modalEditLivraison,formEditLivraison,id);
- });
-
- // INIT FORM EDIT
- initFormLivraison(formEditLivraison);
+ // INIT FORM
+ modalFormLivraison_init(modalEditLivraison);
- // SAVE LIVRAISON
- $(".btnSaveEditLivraison").unbind('click').click( function(event) {
- event.preventDefault();
-
- if(!currentEditLivraison>0) return;
-
- var datas = getLivraisonFormDatas(formEditLivraison);
- if(!datas.paniers_groupe>0 ||datas.date=="" || datas.quinz_groupe=="") {
- alert("ERREUR : au minimum un groupe de contrats, une date et un groupe bi-hebdo doivent être renseigné !");
- return;
- }
-
- datas.action = 'edit';
- datas.ref = currentEditLivraison;
-
- formEditLivraison.find("div.modaLoader").addClass("show");
- $(".btnSaveEditLivraison").prop("disabled", true);
-
- $.post( livraisonsBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- modalEditLivraison.modal('hide');
- setTimeout(function() {
- document.location.reload();
- },200);
- }
- else {
- console.error(result);
- alert(result);
- formEditLivraison.find("div.modaLoader").removeClass("show");
- $(".btnSaveEditLivraison").prop("disabled", false);
- }
- }).fail( function() {
- alert(srvErrorMsg+" (edit livraison)");
- formEditLivraison.find("div.modaLoader").removeClass("show");
- $(".btnSaveEditLivraison").prop("disabled", false);
- });
- });
+ // INIT EDIT BTNs
+ var initBtnFct = function() { modalForm_initBtnEdit(
+ $(livraisonsConf.edit_btnSelector), // BTNs
+ modalEditLivraison, // MODAL
+ modalFormLivraison_clear, // CLEAR FUNCTION
+ modalFormLivraison_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
+
+ // INIT SAVE EDIT BTN
+ modalForm_initBtnSaveEdit(
+ modalEditLivraison.find(".btnSave"), // BTN SAVE
+ livraisonsConf.type, // EDIT TYPE
+ modalEditLivraison, // MODAL
+ modalFormLivraison_getDatas, // GET FORM DATAS FUNCTION
+ modalFormLivraison_checkDatas, // CHECK FORM DATAS FUNCTION
+ livraisonsConf.baseURL // SAVE URL
+ );
// CANCEL
- modalEditLivraison.on('hidden.bs.modal', function (e) {
- clearFormLivraisonDatas(formEditLivraison);
- currentEditLivraison = 0;
- });
+ modalEditLivraison.on('hidden.bs.modal', function (e) { modalFormLivraison_clear(modalEditLivraison); });
}
-/***** ARCHIVE LIVRAISON *****/
+/***** ARCHIVE *****/
function initArchiveLivraison() {
- // BTN ARCHIVE
- btnArchiveLivraison.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
- currentArchiveLivraison = id;
- modalArchiveLivraison.find('b.date').html( $(this).attr('date') );
- modalArchiveLivraison.modal('show');
- });
+ // INIT ARCHIVE BTNs
+ var initBtnFct = function() { modalForm_initBtnArchive(
+ $(livraisonsConf.archive_btnSelector), // BTNs
+ modalArchiveLivraison, // MODAL
+ modalArchiveLivraison_clear, // CLEAR MODAL FUNCTION
+ modalArchiveLivraison_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
- // ARCHIVE
- $("#btnArchiveLivraison").unbind('click').click( function(event) {
- event.preventDefault();
- $(this).blur();
-
- if(!currentArchiveLivraison>0) return;
-
- var datas = {
- action : 'archive',
- ref : currentArchiveLivraison
- };
-
- $.post( livraisonsBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- modalArchiveLivraison.modal('hide');
- setTimeout(function() { document.location.reload(); },200);
- }
- else {
- console.error(result);
- alert(result);
- }
- }).fail( function() { alert(srvErrorMsg+" (archive livraison)"); });
- });
+ // INIT UNARCHIVE BTNs
+ var initUnBtnFct = function() { modalForm_initBtnUnarchive(
+ $(livraisonsConf.unarchive_btnSelector), // BTNs
+ livraisonsConf.type, // DELETE TYPE
+ modalArchiveLivraison, // MODAL
+ livraisonsConf.baseURL // SAVE URL
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initUnBtnFct );
+ initUnBtnFct();
+
+ // INIT SAVE DELETE BTN
+ modalForm_initBtnSaveArchive(
+ modalArchiveLivraison.find(".btnSave"), // BTN SAVE
+ livraisonsConf.type, // DELETE TYPE
+ modalArchiveLivraison, // MODAL
+ livraisonsConf.baseURL // SAVE URL
+ );
// CANCEL
- modalArchiveLivraison.on('hidden.bs.modal', function (e) {
- modalArchiveLivraison.find('b.date').html("");
- currentArchiveLivraison = 0;
- });
-
- // UNARCHIVE
- btnUnarchiveLivraison.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
-
- var datas = { action : 'unarchive', ref : id };
- $.post( livraisonsBaseURL, datas, function( result ) {
- if(parseInt(result)>0) document.location.reload();
- else {
- console.error(result);
- alert(result);
- }
- }).fail( function() { alert(srvErrorMsg+" (unarchive livraison)"); });
- });
-
+ modalArchiveLivraison.on('hidden.bs.modal', function (e) { modalArchiveLivraison_clear(); });
}
-/***** DELETE LIVRAISON *****/
+function modalArchiveLivraison_loadDatas(btn, id) {
+ modalArchiveLivraison.find('b.groupe').html( btn.attr('groupe') );
+ modalArchiveLivraison.find('b.date').html( btn.attr('date') );
+ modalArchiveLivraison.modal('show');
+}
+
+function modalArchiveLivraison_clear() {
+ modalArchiveLivraison.removeAttr("archive_id");
+ modalArchiveLivraison.find('b.groupe').html("");
+ modalArchiveLivraison.find('b.date').html("");
+}
+
+/***** DELETE *****/
function initDeleteLivraison() {
- // BTN DELETE
- btnDeleteLivraison.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
- currentDeleteLivraison = id;
-
- modalDeleteLivraison.find('b.date').html( $(this).attr('date') );
-
- modalDeleteLivraison.modal('show');
- });
-
- // DELETE
- $("#btnDeleteLivraison").unbind('click').click( function(event) {
- event.preventDefault();
- $(this).blur();
-
- if(!currentDeleteLivraison>0) return;
-
- var datas = {
- action : 'delete',
- ref : currentDeleteLivraison
- };
-
- $.post( livraisonsBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- modalEditLivraison.modal('hide');
- setTimeout(function() {
- document.location.reload();
- },200);
- }
- else {
- console.error(result);
- alert(result);
- }
- }).fail( function() { alert(srvErrorMsg+" (delete livraison)"); });
- });
+ // INIT DELETE BTNs
+ var initBtnFct = function() { modalForm_initBtnDelete(
+ $(livraisonsConf.delete_btnSelector), // BTNs
+ modalDeleteLivraison, // MODAL
+ modalDeleteLivraison_clear, // CLEAR MODAL FUNCTION
+ modalDeleteLivraison_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
+
+ // INIT SAVE DELETE BTN
+ modalForm_initBtnSaveDelete(
+ modalDeleteLivraison.find(".btnSave"), // BTN SAVE
+ livraisonsConf.type, // DELETE TYPE
+ modalDeleteLivraison, // MODAL
+ false, // GET FORM DATAS FUNCTION
+ false, // CHECK FORM DATAS FUNCTION
+ livraisonsConf.baseURL // SAVE URL
+ );
// CANCEL
- modalDeleteLivraison.on('hidden.bs.modal', function (e) {
- modalDeleteLivraison.find('b.date').html("");
- currentDeleteLivraison = 0;
- });
+ modalDeleteLivraison.on('hidden.bs.modal', function (e) { modalDeleteLivraison_clear(); });
+}
+
+function modalDeleteLivraison_loadDatas(btn, id) {
+ modalDeleteLivraison.find('b.groupe').html( btn.attr('groupe') );
+ modalDeleteLivraison.find('b.date').html( btn.attr('date') );
+ modalDeleteLivraison.modal('show');
+}
+
+function modalDeleteLivraison_clear() {
+ modalDeleteLivraison.removeAttr("delete_id");
+ modalDeleteLivraison.find('b.groupe').html("");
+ modalDeleteLivraison.find('b.date').html("");
}
\ No newline at end of file
diff --git a/public_html_admin/js/paniers.js b/public_html_admin/js/paniers.js
index 125b220..af74787 100644
--- a/public_html_admin/js/paniers.js
+++ b/public_html_admin/js/paniers.js
@@ -1,544 +1,265 @@
-// SEARCH
-var paniersSearch = false;
+// SETTINGS
+var paniersConf = {
+ type : "panier",
+ baseURL : "paniers.php",
+ // LIST
+ list_selector : "#paniersList",
+ // SEARCH / FILTRES
+ search_selector : "#paniersSearch .searchGrp",
+ filtres_selector : "#paniersSearch select",
+ // VIEW
+ view_modalSelector : "#modalViewPanier",
+ view_btnSelector : ".btnViewPanier",
+ // ADD
+ add_modalSelector : "#modalAddPanier",
+ add_btnSelector : "#btnAddPanier",
+ // EDIT
+ edit_modalSelector : "#modalEditPanier",
+ edit_btnSelector : ".btnEditPanier",
+ // DELETE
+ delete_modalSelector : "#modalDeletePanier",
+ delete_btnSelector : ".btnDeletePanier",
+}
-// VIEW
-var modalViewPanier = false;
-var btnViewPanier = false;
-var currentViewPanier = 0;
+// MODALS
+var modalViewPanier = false;
+var modalAddPanier = false;
+var modalEditPanier = false;
+var modalDeletePanier = false;
-var paniersBaseURL = "paniers.php";
-
-// ADD
-var modalAddPanier = false;
-var formAddPanier = false;
-var btnAddPanier = false;
-
-// EDIT
-var modalEditPanier = false;
-var formEditPanier = false;
-var btnEditPanier = false;
-var currentEditPanier = 0;
-
-// DELETE
-var modalDeletePanier = false;
-var btnDeletePanier = false;
-var currentDeletePanier = 0;
-
-$(document).ready( function() {
- // INIT SEARCH
- paniersSearch = $("#paniersSearch");
- if(paniersSearch.length>0) initSearchPaniers();
+$(document).ready( function() {
+ // LIST LOADER
+ initListProgressLoad($(paniersConf.list_selector), paniersConf.baseURL, paniersConf.type+" list");
- // INIT VIEW PANIER
- modalViewPanier = $("#modalViewPanier");
- btnViewPanier = $(".btnViewPanier");
- if(modalViewPanier.length>0 && btnViewPanier.length>0) {
+ // SEARCH / FILTRES
+ $(paniersConf.search_selector).initSearchGroup();
+ $(paniersConf.filtres_selector).initFiltreSelect();
+
+ // VIEW
+ modalViewPanier = $(paniersConf.view_modalSelector);
+ if(modalViewPanier.length>0) {
initViewPanier();
// VIEW REQUEST
- var id = getUrlParameter("id");
- if(id!==false && parseInt(id)>0) loadDatasInViewPanierModal(id);
+ var id = getUrlParameter("ref");
+ if(id!==false && parseInt(id)>0 && current_page == "paniers") {
+ modalViewPanier_clear(modalViewPanier);
+ modalViewPanier_loadDatas(modalViewPanier, id);
+ }
}
- // INIT ADD PANIER
- modalAddPanier = $("#modalAddPanier");
- formAddPanier = $("#formAddPanier");
- btnAddPanier = $("#btnAddPanier");
- if(modalAddPanier.length>0 && formAddPanier.length>0 && btnAddPanier.length>0) initAddPanier();
-
- // INIT EDIT PANIER
- modalEditPanier = $("#modalEditPanier");
- formEditPanier = $("#formEditPanier");
- btnEditPanier = $(".btnEditPanier");
- if(modalEditPanier.length>0 && formEditPanier.length>0 && btnEditPanier.length>0) initEditPanier();
-
- // INIT DELETE PANIER
- modalDeletePanier = $("#modalDeletePanier");
- btnDeletePanier = $(".btnDeletePanier");
- if(modalDeletePanier.length>0 && btnDeletePanier.length>0) initDeletePanier();
+ // ADD
+ modalAddPanier = $(paniersConf.add_modalSelector);
+ if(modalAddPanier.length>0) initAddPanier();
+
+ // EDIT
+ modalEditPanier = $(paniersConf.edit_modalSelector);
+ if(modalEditPanier.length>0) initEditPanier();
+
+ // DELETE
+ modalDeletePanier = $(paniersConf.delete_modalSelector);
+ if(modalDeletePanier.length>0) initDeletePanier();
});
-/***** SEARCH PANIERS *****/
-function initSearchPaniers() {
- // SEARCH
- paniersSearch.find("input[name=search]").unbind('keypress').keypress( function(event) {
- if(event.keyCode==13) searchPanier(false);
- });
- paniersSearch.find(".btnClearSearch").unbind('click').click( function(event) {
- searchPanier(true);
- });
-
- // FILTRE GROUPE
- loadValue = paniersSearch.find("select[name=groupe]").attr("load_value");
- paniersSearch.find("select[name=groupe]").change(function(e) {
- $(this).blur();
- document.location = "?groupe="+parseInt($(this).val());
- }).val(loadValue);
-}
-
-function searchPanier(clear) {
- paniersSearch.find("input[name=search]").blur();
- paniersSearch.find(".btnClearSearch").blur();
- if(clear) document.location = "?clearSearch";
- else document.location = "?search="+paniersSearch.find("input[name=search]").val();
-}
-
-/***** VIEW PANIER *****/
+/***** MODAL VIEW *****/
function initViewPanier() {
- // BTN VIEW
- btnViewPanier.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
- clearViewPanierModal();
- currentViewPanier = id;
- loadDatasInViewPanierModal(id);
- });
+ // INIT VIEW BTNs
+ var initBtnFct = function() { modalForm_initBtnView(
+ $(paniersConf.view_btnSelector), // BTNs
+ modalViewPanier, // MODAL
+ modalViewPanier_clear, // CLEAR FUNCTION
+ modalViewPanier_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
// CANCEL
- modalViewPanier.on('hidden.bs.modal', function (e) {
- clearViewPanierModal();
- currentViewPanier = 0;
- });
+ modalViewPanier.on('hidden.bs.modal', function() { modalViewPanier_clear(modalViewPanier); });
}
-function loadDatasInViewPanierModal(id) {
- datas = {
- 'ref' : id,
- 'action' : 'getDatas'
- };
- $.post(paniersBaseURL, datas, function(jsonTxt) {
+function modalViewPanier_loadDatas(modal, id) {
+ $.post(paniersConf.baseURL, { 'ref' : id, 'action' : 'getDatas' }, function(jsonTxt) {
var datas = JSON.parse(jsonTxt);
+
+ modal.find("small.db_ref > span").html(datas.ref);
- modalViewPanier.find("small.db_ref > span").html(datas.ref);
+ modal.find("td.nom").html(datas.nom);
+ modal.find("td.groupe").html(datas.groupe_nom);
+ modal.find("td.valeur").html(number_format(datas.valeur,2)+" €");
- modalViewPanier.find("td.nom").html(datas.nom);
- modalViewPanier.find("td.groupe").html(datas.groupe_nom);
- modalViewPanier.find("td.valeur").html(number_format(datas.valeur,2)+" €");
-
- modalViewPanier.modal('show');
- }).fail(function() { alert(srvErrorMsg+" (load modal view panier)"); });;
+ modal.modal('show');
+ }).fail(function() { alert("("+paniersConf.type+" - load modal view)"); });
}
-function clearViewPanierModal() {
- modalViewPanier.find("small.db_ref > span").html("");
+function modalViewPanier_clear(modal) {
+ modal.removeAttr("view_id");
- modalViewPanier.find("td.nom").html("");
- modalViewPanier.find("td.groupe").html("");
- modalViewPanier.find("td.valeur").html("");
+ modal.find("small.db_ref > span").html("");
+
+ modal.find("td.nom").html("");
+ modal.find("td.groupe").html("");
+ modal.find("td.valeur").html("");
+
+ modal.find("table.modal-body tfoot").addClass("hide").find("tr:not(.header)").remove();
}
-/***** FORM PANIER *****/
-function initFormPanier(form) {
- form.on("submit", function(e) { e.preventDefault(); });
+/***** MODAL FORM ADD/EDIT *****/
+function modalFormPanier_init(modal) {
+ modal.find("form").on("submit", function(e) { e.preventDefault(); });
// NOM
- initFirstUpperCaseInput(form.find("input[name=nom]"), null, function() { $(this).blur(); });
- form.find("input[name=nom]").keydown(function(e) {
+ initFirstUpperCaseInput(modal.find("input[name=nom]"), null, function() { $(this).blur(); });
+ modal.find("input[name=nom]").keydown(function(e) {
if(e.keyCode==13) { e.preventDefault(); $(this).blur(); }
});
// GROUPE
- form.find("select[name=groupe]").change(function(e) {
- $(this).blur();
- // EXISTING
- if(parseInt($(this).val())>0) {
- switchBtnGroupeAction(form, "delete");
- switchBtnGroupeSecondAction(form, "edit");
- }
- // CHOISIR...
- else {
- switchBtnGroupeAction(form, "add");
- switchBtnGroupeSecondAction(form, "hide");
- }
- });
-
- form.find("button.btnGroupeAction").click(function(e) {
- e.preventDefault();
- $(this).blur();
- // ADD / SAVE NEW
- if($(this).hasClass("add") || $(this).hasClass("save_new")) {
- addInputGroupeName(form, "add");
-
- switchBtnGroupeAction(form, "save");
- switchBtnGroupeSecondAction(form, "cancel");
- }
- // SAVE
- else if($(this).hasClass("save")) {
- var ipt = form.find("input[name=groupeName]");
- if(ipt.length>0) {
- var ref = ipt.attr("ref");
-
- var datas = { 'nom' : ipt.val() };
-
- if(datas.nom=="") {
- alert("Merci de renseigner le nom du groupe !");
- return;
- }
-
- // ADD GROUPE
- if(ref == "new") datas.action = "add_groupe";
- // EDIT GROUPE
- else if(parseInt(ref)>0) {
- ref = parseInt(ref);
- datas.action = "edit_groupe";
- datas.groupe_ref = ref;
- }
-
- form.find("div.modaLoader").addClass("show");
- form.find("button.btnGroupeAction").prop("disabled", true);
-
- $.post( paniersBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- switchBtnGroupeAction(form, "delete");
- switchBtnGroupeSecondAction(form, "edit");
- removeInputGroupeName(form);
-
- if(ref == "new") ref = parseInt(result);
-
- // REFRESH GROUPES LIST
- $.post( paniersBaseURL, {action: "groupes_select_list"}, function( result ) {
- form.find("select[name=groupe]").html(result).val(ref);
- }).fail(function() { alert(srvErrorMsg+" (form panier - add/edit groupe - refresh list after)"); });
- }
- else {
- console.error(result);
- alert(result);
- }
- }).always(function() {
- form.find("div.modaLoader").removeClass("show");
- form.find("button.btnGroupeAction").prop("disabled", false);
- }).fail(function() { alert(srvErrorMsg+" (form panier - add/edit groupe)"); });
- }
- }
- // DELETE
- else if($(this).hasClass("delete")) {
- var ref = parseInt(form.find("select[name=groupe]").val());
- var nom = form.find("select[name=groupe] option:selected").html();
- if(confirm('Etês vous sûr de vouloir supprimer le groupe de panier "'+nom+'" ?')) {
- form.find("div.modaLoader").addClass("show");
- form.find("button.btnGroupeAction").prop("disabled", false);
-
- var datas = { action : 'delete_groupe', groupe_ref : ref };
- $.post( paniersBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- // REFRESH CONTRATS TYPES LIST
- $.post( paniersBaseURL, {action: "groupes_select_list"}, function( result ) {
- form.find("select[name=groupe]").html(result).val("0");
- }).fail(function() { alert(srvErrorMsg+" (form panier - delete groupe - refresh list after)"); });
- }
- else {
- console.error(result);
- alert(result);
- }
- }).always(function() {
- form.find("div.modaLoader").removeClass("show");
- form.find("button.btnGroupeAction").prop("disabled", false);
- }).fail(function() { alert(srvErrorMsg+" (form panier - delete groupe)"); });
- }
- }
- });
-
- form.find("button.btnGroupeSecondAction").click(function(e) {
- e.preventDefault();
- $(this).blur();
- // EDIT
- if($(this).hasClass("edit")) {
- addInputGroupeName(form, "edit");
- switchBtnGroupeAction(form, "save");
- switchBtnGroupeSecondAction(form, "cancel");
- }
- // CANCEL
- else if($(this).hasClass("cancel")) {
- removeInputGroupeName(form);
- // EDIT
- if(parseInt(form.find("select[name=groupe]").val())>0) {
- switchBtnGroupeAction(form, "delete");
- switchBtnGroupeSecondAction(form, "edit");
- }
- // ADD
- else {
- switchBtnGroupeAction(form, "add");
- switchBtnGroupeSecondAction(form, "hide");
- }
- }
- });
+ inlineSelectManager_init(
+ modal, // MODAL
+ "panier", // MODAL FORM NAME
+ modal.find("select[name=groupe]").parent(), // SELECT GROUPE
+ "le groupe de panier", // VALUE NAME
+ paniersConf.baseURL, // URL
+ "groupe_ref", // REF ATTR
+ "add_groupe", // ADD ACTION
+ "edit_groupe", // EDIT ACTION
+ "delete_groupe", // DELETE ACTION
+ "groupes_select_list" // REFRESH LIST ACTION
+ );
// VALEUR
- initFloatInput(form.find("input[name=valeur]"));
- form.find("input[name=valeur]").keydown(function(e) {
+ initFloatInput(modal.find("input[name=valeur]"));
+ modal.find("input[name=valeur]").keydown(function(e) {
if(e.keyCode==13) { e.preventDefault(); $(this).blur(); }
});
}
-function loadDatasInFormPanierDatas(modal,form,id) {
- datas = {
- 'ref' : id,
- 'action' : 'getDatas'
- };
- $.post(paniersBaseURL, datas, function(jsonTxt) {
+function modalFormPanier_loadDatas(modal,id) {
+ $.post(paniersConf.baseURL, { 'ref' : id, 'action' : 'getDatas' }, function(jsonTxt) {
var datas = JSON.parse(jsonTxt);
- form.find("input[name=nom]").val(datas.nom);
+ modal.find("input[name=nom]").val(datas.nom);
- if(parseInt(datas.groupe_ref) > 0) {
- form.find("select[name=groupe]").val(datas.groupe_ref);
- switchBtnGroupeAction(form, "delete");
- switchBtnGroupeSecondAction(form, "edit");
- }
- else {
- form.find("select[name=groupe]").val("0");
- switchBtnGroupeAction(form, "add");
- switchBtnGroupeSecondAction(form, "hide");
- }
+ inlineSelectManager_setValue(modal.find("select[name=groupe]").parent(), datas.groupe_ref);
- form.find("input[name=valeur]").val(datas.valeur);
-
+ modal.find("input[name=valeur]").val(datas.valeur);
+
if(modal) modal.modal('show');
- }).fail(function() { alert(srvErrorMsg+" (form panier - load datas)"); });
+ }).fail(function() { alert("("+paniersConf.type+" - load datas in modal form)"); });
}
-function clearFormPanierDatas(form) {
- form.find("input[name=nom]").val("");
+function modalFormPanier_clear(modal) {
+ modal.removeAttr("edit_id");
+ modal.find("div.modaLoader").removeClass("show");
- form.find("select[name=groupe]").val("0");
- removeInputGroupeName(form);
- switchBtnGroupeAction(form, "add");
- switchBtnGroupeSecondAction(form, "hide");
-
- form.find("input[name=valeur]").val("0");
-
- // MODALOADER
- form.find("div.modaLoader").removeClass("show");
+ modal.find("input[name=nom]").val("");
+ inlineSelectManager_setValue(modal.find("select[name=groupe]").parent(), 0);
+ modal.find("input[name=valeur]").val("0");
}
-// GROUPE
-
-function switchBtnGroupeAction(form, action) { // ADD / SAVE / DELETE
- var btn = form.find("button.btnGroupeAction");
-
- if(action == "add") {
- btn.removeClass("save delete").addClass("add").removeClass("btn-danger btn-primary").addClass("btn-default")
- .find("i").removeClass("glyphicon-floppy-saved glyphicon-trash").addClass("glyphicon-plus");
- }
- else if(action == "save") {
- btn.removeClass("add save_new delete").addClass("save").removeClass("btn-danger btn-default").addClass("btn-primary")
- .find("i").removeClass("glyphicon-plus glyphicon-trash").addClass("glyphicon-floppy-saved");
- }
- else if(action == "delete") {
- btn.removeClass("add save_new save").addClass("delete").removeClass("btn-default btn-primary").addClass("btn-danger")
- .find("i").removeClass("glyphicon-plus glyphicon-floppy-saved").addClass("glyphicon-trash");
- }
-}
-
-function switchBtnGroupeSecondAction(form, action) { // CANCEL / EDIT
- var btn = form.find("button.btnGroupeSecondAction");
-
- if(action == "cancel") {
- btn.removeClass("edit").addClass("cancel").removeClass("btn-default").addClass("btn-danger")
- .find("i").removeClass("glyphicon-edit").addClass("glyphicon-floppy-remove");
- btn.parent().removeClass("hide");
- }
- else if(action == "edit") {
- btn.removeClass("cancel").addClass("edit").removeClass("btn-danger").addClass("btn-default")
- .find("i").removeClass("glyphicon-floppy-remove").addClass("glyphicon-edit");
- btn.parent().removeClass("hide");
- }
- else if(action == "hide") {
- btn.parent().addClass("hide");
- }
-}
-
-function addInputGroupeName(form, action) {
- var select = form.find("select[name=groupe]");
- var ipt = $(' ').attr("action", action);
- select.addClass("hide");
- ipt.insertBefore(select);
- if(action=="edit") {
- ipt.attr("ref", select.val());
- ipt.val( select.find("option:selected").html() );
- }
- else ipt.attr("ref", "new");
- ipt.focus();
-
- ipt.keypress(function(e) {
- if(e.keyCode==13) {
- e.preventDefault();
- form.find("button.btnGroupeAction").click();
- }
- });
-}
-
-function removeInputGroupeName(form) {
- var ipt = form.find("input[name=groupeName]");
- if(ipt.length>0) ipt.remove();
- form.find("select[name=groupe]").removeClass("hide");
-}
-
-// GET FORM DATAS
-
-function getPanierFormDatas(form) {
+function modalFormPanier_getDatas(modal) {
var datas = {
- 'nom' : form.find("input[name=nom]").val(),
- 'groupe' : parseInt(form.find("select[name=groupe]").val()),
- 'valeur' : parseFloat(form.find("input[name=valeur]").val())
+ 'nom' : modal.find("input[name=nom]").val(),
+ 'groupe' : parseInt(modal.find("select[name=groupe]").val()),
+ 'valeur' : parseFloat(modal.find("input[name=valeur]").val())
};
return datas;
}
-/***** ADD PANIER *****/
+function modalFormPanier_checkDatas(datas) {
+ if(datas.nom=="") {
+ alert("ERREUR : au minimum, un nom doit être renseigné !");
+ return false;
+ }
+ return true;
+}
+
+/***** ADD *****/
function initAddPanier() {
- // BTN ADD
- btnAddPanier.unbind('click').click( function(event) {
- event.preventDefault();
- clearFormPanierDatas(formAddPanier);
- modalAddPanier.modal('show');
- });
+ // INIT FORM
+ modalFormPanier_init(modalAddPanier);
+
+ // INIT ADD BTN
+ modalForm_initBtnAdd(
+ $(paniersConf.add_btnSelector), // BTN ADD
+ modalAddPanier, // MODAL
+ modalFormPanier_clear // CLEAR FORM FUNCTION
+ );
- // INIT FORM ADD
- initFormPanier(formAddPanier);
-
- // SAVE PANIER
- $(".btnSaveAddPanier").unbind('click').click( function(event) {
- event.preventDefault();
-
- var datas = getPanierFormDatas(formAddPanier);
- if(datas.nom=="" || !datas.groupe>0) {
- alert("ERREUR : au minimum, un nom et un groupe doivent être renseigné !");
- return;
- }
-
- datas.action = 'add';
-
- formAddPanier.find("div.modaLoader").addClass("show");
- $(".btnSaveAddPanier").prop("disabled", true);
-
- $.post( paniersBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- modalAddPanier.modal('hide');
- setTimeout(function() {
- document.location.reload();
- },200);
- }
- else {
- console.error(result);
- alert(result);
- formAddPanier.find("div.modaLoader").removeClass("show");
- $(".btnSaveAddPanier").prop("disabled", false);
- }
- }).fail( function() {
- alert(srvErrorMsg+" (add panier)");
- formAddPanier.find("div.modaLoader").removeClass("show");
- $(".btnSaveAddPanier").prop("disabled", false);
- });
- });
+ // INIT SAVE BTN
+ modalForm_initBtnSaveAdd(
+ modalAddPanier.find(".btnSave"), // BTN SAVE
+ paniersConf.type, // ADD TYPE
+ modalAddPanier, // MODAL
+ modalFormPanier_getDatas, // GET FORM DATAS FUNCTION
+ modalFormPanier_checkDatas, // CHECK FORM DATAS FUNCTION
+ paniersConf.baseURL // SAVE URL
+ );
// CANCEL
- modalAddPanier.on('hidden.bs.modal', function (e) { clearFormPanierDatas(formAddPanier); });
+ modalAddPanier.on('hidden.bs.modal', function (e) { modalFormPanier_clear(modalAddPanier); });
}
-/***** EDIT PANIER *****/
+/***** EDIT *****/
function initEditPanier() {
- // BTN EDIT
- btnEditPanier.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
- currentEditPanier = id;
- clearFormPanierDatas(formEditPanier);
- loadDatasInFormPanierDatas(modalEditPanier,formEditPanier,id);
- });
-
- // INIT FORM EDIT
- initFormPanier(formEditPanier);
+ // INIT FORM
+ modalFormPanier_init(modalEditPanier);
- // SAVE PANIER
- $(".btnSaveEditPanier").unbind('click').click( function(event) {
- event.preventDefault();
-
- if(!currentEditPanier>0) return;
-
- var datas = getPanierFormDatas(formEditPanier);
- if(datas.nom=="" || !datas.groupe>0) {
- alert("ERREUR : au minimum, un nom et un groupe doivent être renseigné !");
- return;
- }
-
- datas.action = 'edit';
- datas.ref = currentEditPanier;
-
- formEditPanier.find("div.modaLoader").addClass("show");
- $(".btnSaveEditPanier").prop("disabled", true);
-
- $.post( paniersBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- modalEditPanier.modal('hide');
- setTimeout(function() {
- document.location.reload();
- },200);
- }
- else {
- console.error(result);
- alert(result);
- formEditPanier.find("div.modaLoader").removeClass("show");
- $(".btnSaveEditPanier").prop("disabled", false);
- }
- }).fail( function() {
- alert(srvErrorMsg+" (edit panier)");
- formEditPanier.find("div.modaLoader").removeClass("show");
- $(".btnSaveEditPanier").prop("disabled", false);
- });
- });
+ // INIT EDIT BTNs
+ var initBtnFct = function() { modalForm_initBtnEdit(
+ $(paniersConf.edit_btnSelector), // BTNs
+ modalEditPanier, // MODAL
+ modalFormPanier_clear, // CLEAR FUNCTION
+ modalFormPanier_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
+
+ // INIT SAVE EDIT BTN
+ modalForm_initBtnSaveEdit(
+ modalEditPanier.find(".btnSave"), // BTN SAVE
+ paniersConf.type, // EDIT TYPE
+ modalEditPanier, // MODAL
+ modalFormPanier_getDatas, // GET FORM DATAS FUNCTION
+ modalFormPanier_checkDatas, // CHECK FORM DATAS FUNCTION
+ paniersConf.baseURL // SAVE URL
+ );
// CANCEL
- modalEditPanier.on('hidden.bs.modal', function (e) {
- clearFormPanierDatas(formEditPanier);
- currentEditPanier = 0;
- });
+ modalEditPanier.on('hidden.bs.modal', function (e) { modalFormPanier_clear(modalEditPanier); });
}
-/***** DELETE PANIER *****/
+/***** DELETE *****/
function initDeletePanier() {
- // BTN DELETE
- btnDeletePanier.unbind('click').click( function(event) {
- event.preventDefault();
- id = parseInt($(this).attr('ref'));
- if(!id>0) return;
- currentDeletePanier = id;
-
- modalDeletePanier.find('b.name').html( $(this).attr('nom') );
-
- modalDeletePanier.modal('show');
- });
-
- // DELETE
- $("#btnDeletePanier").unbind('click').click( function(event) {
- event.preventDefault();
- $(this).blur();
-
- if(!currentDeletePanier>0) return;
-
- var datas = {
- action : 'delete',
- ref : currentDeletePanier
- };
-
- $.post( paniersBaseURL, datas, function( result ) {
- if(parseInt(result)>0) {
- modalEditPanier.modal('hide');
- setTimeout(function() {
- document.location.reload();
- },200);
- }
- else {
- console.error(result);
- alert(result);
- }
- }).fail(function() { alert(srvErrorMsg+" (delete panier)"); });
- });
+ // INIT DELETE BTNs
+ var initBtnFct = function() { modalForm_initBtnDelete(
+ $(paniersConf.delete_btnSelector), // BTNs
+ modalDeletePanier, // MODAL
+ modalDeletePanier_clear, // CLEAR MODAL FUNCTION
+ modalDeletePanier_loadDatas // LOAD DATAS FUNCTION
+ )};
+ registerListProgressLoadCbkFct( $("tbody.progressLoadList"), initBtnFct );
+ initBtnFct();
+
+ // INIT SAVE DELETE BTN
+ modalForm_initBtnSaveDelete(
+ modalDeletePanier.find(".btnSave"), // BTN SAVE
+ paniersConf.type, // DELETE TYPE
+ modalDeletePanier, // MODAL
+ false, // GET FORM DATAS FUNCTION
+ false, // CHECK FORM DATAS FUNCTION
+ paniersConf.baseURL // SAVE URL
+ );
// CANCEL
- modalDeletePanier.on('hidden.bs.modal', function (e) {
- modalDeletePanier.find('b.name').html("");
- currentDeletePanier = 0;
- });
+ modalDeletePanier.on('hidden.bs.modal', function (e) { modalDeletePanier_clear(); });
+}
+
+function modalDeletePanier_loadDatas(btn, id) {
+ modalDeletePanier.find('b.name').html( btn.attr('nom') );
+ modalDeletePanier.modal('show');
+}
+
+function modalDeletePanier_clear() {
+ modalDeletePanier.removeAttr("delete_id");
+ modalDeletePanier.find('b.name').html("");
}
\ No newline at end of file
diff --git a/public_html_admin/legumes.php b/public_html_admin/legumes.php
index fbd87d9..0819556 100644
--- a/public_html_admin/legumes.php
+++ b/public_html_admin/legumes.php
@@ -89,11 +89,29 @@ switch($action) {
case "autocomplete_list": die( json_encode( getLegumesAutocompleteList() ) ); break;
// DEFAULT - LIST
default: {
- // LIST
+ // SEARCH
$search = getSearch("legumes_search");
+
+ // LIMITS
+ $limits = array("start" => 0, "end" => LIST_NB_LIGNES_PAR_PAGE, "nbItemsByPage" => LIST_NB_LIGNES_PAR_PAGE, "max" => getNbLegumesInList($search));
+ if(isset($_REQUEST['startListAt']) && (int)$_REQUEST['startListAt']>0) {
+ $limits['start'] = intval($_REQUEST['startListAt']);
+ $limits['end'] = $limits['start'] + $limits['nbItemsByPage'];
+ if($limits['end'] > $limits['max']) $limits['end'] = $limits['max'];
+ }
+ $limits['rest'] = $limits['max'] - $limits['end'];
+ $GLOBALS['smarty'] -> assign('list_limits',$limits);
+
+ // LIST
$order = getListOrder('legumes_list_order', 'legumes_list_sens', $allowLegumesListOrder, 'prenom');
- $list = getLegumesList($order["order"], $order["sens"], $search);
+ $list = getLegumesList($order["order"], $order["sens"], $search, $limits);
$GLOBALS['smarty'] -> assign('list',$list);
+
+ // LIST PART
+ if(isset($_REQUEST['startListAt']) && (int)$_REQUEST['startListAt']>0) {
+ $limits["list"] = $GLOBALS['smarty']->fetch("legumes/legumes_list_builder.tpl");
+ die(json_encode($limits));
+ }
// TEMPLATE
$GLOBALS['template'] = 'legumes/legumes_list.tpl';
diff --git a/public_html_admin/livraisons.php b/public_html_admin/livraisons.php
index b266500..ef9115c 100644
--- a/public_html_admin/livraisons.php
+++ b/public_html_admin/livraisons.php
@@ -172,14 +172,34 @@ switch($action) {
die( $GLOBALS['smarty']->fetch("livraisons/livraison_form_tab_paniers.tpl") );
} break;
// DEFAULT - LIST
- default: {
- // LIST
+ default: {
+ // GROUPE
$groupesList = getPaniersGroupesList();
$groupe = getRequestAndSessionSave("groupe", "livraisons_list_groupe", "groupe", "int", 0, $groupesList, true);
+
+ // ARCHIVE
$archive = getRequestAndSessionSave("archive", "livraisons_list_archive", "archive", "int", 0);
+
+ // LIMITS
+ $limits = array("start" => 0, "end" => LIST_NB_LIGNES_PAR_PAGE, "nbItemsByPage" => LIST_NB_LIGNES_PAR_PAGE, "max" => getNbLivraisonsInList($groupe, $archive));
+ if(isset($_REQUEST['startListAt']) && (int)$_REQUEST['startListAt']>0) {
+ $limits['start'] = intval($_REQUEST['startListAt']);
+ $limits['end'] = $limits['start'] + $limits['nbItemsByPage'];
+ if($limits['end'] > $limits['max']) $limits['end'] = $limits['max'];
+ }
+ $limits['rest'] = $limits['max'] - $limits['end'];
+ $GLOBALS['smarty'] -> assign('list_limits',$limits);
+
+ // LIST
$order = getListOrder('livraisons_list_order', 'livraisons_list_sens', $allowLivraisonsListOrder, "date", "DESC");
- $list = getLivraisonsList($order["order"], $order["sens"], $groupe, $archive);
+ $list = getLivraisonsList($order["order"], $order["sens"], $groupe, $archive, $limits);
$GLOBALS['smarty'] -> assign('list',$list);
+
+ // LIST PART
+ if(isset($_REQUEST['startListAt']) && (int)$_REQUEST['startListAt']>0) {
+ $limits["list"] = $GLOBALS['smarty']->fetch("livraisons/livraisons_list_builder.tpl");
+ die(json_encode($limits));
+ }
// TEMPLATE
$GLOBALS['template'] = 'livraisons/livraisons_list.tpl';
diff --git a/public_html_admin/paniers.php b/public_html_admin/paniers.php
index 98f7c48..6bb7bd6 100644
--- a/public_html_admin/paniers.php
+++ b/public_html_admin/paniers.php
@@ -58,7 +58,7 @@ switch($action) {
$id = isset($_REQUEST['groupe_ref']) ? intval($_REQUEST['groupe_ref']) : 0;
if($id>0) {
$datas = getPaniersGroupeDatasFromRequest();
- die( strval( updatePaniersGroupe($datas) ) );
+ die( strval( updatePaniersGroupe($id, $datas) ) );
}
else die("ERREUR : aucune référence de groupe transmis...");
} break;
@@ -88,14 +88,34 @@ switch($action) {
} break;
// DEFAULT - LIST
default: {
- // LIST
+ // GROUPE
$groupesList = getPaniersGroupesList();
$groupe = getRequestAndSessionSave("groupe", "paniers_filtre_groupe", "groupe", "int", 0, $groupesList, true);
+
+ // SEARCH
$search = getSearch("paniers_search");
+
+ // LIMITS
+ $limits = array("start" => 0, "end" => LIST_NB_LIGNES_PAR_PAGE, "nbItemsByPage" => LIST_NB_LIGNES_PAR_PAGE, "max" => getNbPaniersInList($search, $groupe));
+ if(isset($_REQUEST['startListAt']) && (int)$_REQUEST['startListAt']>0) {
+ $limits['start'] = intval($_REQUEST['startListAt']);
+ $limits['end'] = $limits['start'] + $limits['nbItemsByPage'];
+ if($limits['end'] > $limits['max']) $limits['end'] = $limits['max'];
+ }
+ $limits['rest'] = $limits['max'] - $limits['end'];
+ $GLOBALS['smarty'] -> assign('list_limits',$limits);
+
+ // LIST
$order = getListOrder('paniers_list_order', 'paniers_list_sens', $allowPaniersTypesListOrder);
- $list = getPaniersTypesList($order["order"], $order["sens"], $search, $groupe);
+ $list = getPaniersTypesList($order["order"], $order["sens"], $search, $groupe, $limits);
$GLOBALS['smarty'] -> assign('list',$list);
-
+
+ // LIST PART
+ if(isset($_REQUEST['startListAt']) && (int)$_REQUEST['startListAt']>0) {
+ $limits["list"] = $GLOBALS['smarty']->fetch("paniers/paniers_list_builder.tpl");
+ die(json_encode($limits));
+ }
+
// TEMPLATE
$GLOBALS['template'] = 'paniers/paniers_list.tpl';
$jsFiles[] = PUBLIC_HTML_ADMIN.'js/paniers.js';
diff --git a/public_html_admin/templates/clients/client_modal_view.tpl b/public_html_admin/templates/clients/client_modal_view.tpl
index 1f39e47..231f7b6 100644
--- a/public_html_admin/templates/clients/client_modal_view.tpl
+++ b/public_html_admin/templates/clients/client_modal_view.tpl
@@ -11,12 +11,12 @@