From be128e038942d44f89e319025a6ae17ee537748c Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Fri, 21 Jun 2024 12:54:40 +0400 Subject: [PATCH] modifs.mineures sans commentaires --- nur_src/v/bs3/plugins/formfilePlugin.php | 5 +- nur_src/v/bs3/vc/CTable.php | 46 +++++++++++++++---- .../v/plugins/autosubmitOnChangePlugin.php | 35 ++++++++++++++ 3 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 nur_src/v/plugins/autosubmitOnChangePlugin.php diff --git a/nur_src/v/bs3/plugins/formfilePlugin.php b/nur_src/v/bs3/plugins/formfilePlugin.php index 59491fa..4bf76de 100644 --- a/nur_src/v/bs3/plugins/formfilePlugin.php +++ b/nur_src/v/bs3/plugins/formfilePlugin.php @@ -5,9 +5,12 @@ use nur\v\BasePlugin; use nur\v\js; class formfilePlugin extends BasePlugin { - function __construct(?string $readyLabelPrefix=null, ?string $readyLabelSuffix=null) { + const AUTOSUBMIT_ON_CHANGE = '$(this).closest("form").submit();'; + + function __construct(?string $readyLabelPrefix=null, ?string $readyLabelSuffix=null, ?string $afterModified_js=null) { $this->readyLabelPrefix = $readyLabelPrefix; $this->readyLabelSuffix = $readyLabelSuffix; + $this->afterModified_js = $afterModified_js; } /** @var bool */ diff --git a/nur_src/v/bs3/vc/CTable.php b/nur_src/v/bs3/vc/CTable.php index 4b53ada..aa72ac3 100644 --- a/nur_src/v/bs3/vc/CTable.php +++ b/nur_src/v/bs3/vc/CTable.php @@ -88,6 +88,8 @@ class CTable extends ComponentPrintable implements IParametrable { "table_class" => ["?array", null, "classe CSS du tableau"], "table_attrs" => ["?array", null, "autres attributs à placer sur le tableau"], "before_table" => ["?content", null, "Contenu à afficher avant le tableau s'il y a des lignes à afficher"], + "row_func" => ["?callable", null, "fonction avec la signature (\$vs, \$row, \$rawRow) retournant la ligne à afficher"], + "col_func" => ["?callable", null, "fonction avec la signature (\$vs, \$value, \$col, \$index) retournant la colonne à afficher"], "after_table" => ["?content", null, "Contenu à afficher après le tableau s'il y a des lignes à afficher"], "no_data" => ["?content", null, "Contenu à afficher s'il n'y a pas de lignes à afficher"], "on_exception" => ["?callable", null, "fonction à appeler en cas d'exception"], @@ -125,7 +127,7 @@ class CTable extends ComponentPrintable implements IParametrable { /** @var array */ protected $filterCtx; - function pp_setFilterFunc(?callable $filterFunc): void { + function pp_setFilterFunc($filterFunc): void { if ($filterFunc === null) $this->filterCtx = null; else $this->filterCtx = func::_prepare($filterFunc); } @@ -133,7 +135,7 @@ class CTable extends ComponentPrintable implements IParametrable { /** @var array */ protected $mapCtx; - function pp_setMapFunc(?callable $mapFunc): void { + function pp_setMapFunc($mapFunc): void { if ($mapFunc === null) $this->mapCtx = null; else $this->mapCtx = func::_prepare($mapFunc); } @@ -164,6 +166,22 @@ class CTable extends ComponentPrintable implements IParametrable { /** @var array|string */ protected $ppBeforeTable; + /** @var array */ + protected $rowCtx; + + function pp_setRowFunc($rowFunc): void { + if ($rowFunc === null) $this->rowCtx = null; + else $this->rowCtx = func::_prepare($rowFunc); + } + + /** @var array */ + protected $colCtx; + + function pp_setColFunc($colFunc): void { + if ($colFunc === null) $this->colCtx = null; + else $this->colCtx = func::_prepare($colFunc); + } + /** @var array|string */ protected $ppAfterTable; @@ -591,7 +609,11 @@ class CTable extends ComponentPrintable implements IParametrable { } function rowTr(array $row): array { - return v::tr($this->row($row)); + $vs = $this->row($row); + if ($this->rowCtx !== null) { + $vs = func::_call($this->rowCtx, [$vs, $row, $this->rawRow]); + } + return v::tr($vs); } function row(array $row): ?iterable { @@ -613,12 +635,18 @@ class CTable extends ComponentPrintable implements IParametrable { protected $col; function colTd($value): array { - $result = A::get($this->results, $this->col); - $valid = $result === null || $result["valid"]; - return v::td([ - "class" => ["danger" => !$valid], - $this->col($value), - ]); + $vs = $this->col($value); + if ($this->colCtx !== null) { + $vs = func::_call($this->colCtx, [$vs, $value, $this->col, $this->index, $this->row, $this->rawRow]); + } else { + $result = A::get($this->results, $this->col); + $valid = $result === null || $result["valid"]; + $vs= [ + "class" => ["danger" => !$valid], + $vs, + ]; + } + return v::td($vs); } function col($value): ?iterable { diff --git a/nur_src/v/plugins/autosubmitOnChangePlugin.php b/nur_src/v/plugins/autosubmitOnChangePlugin.php new file mode 100644 index 0000000..b4911b8 --- /dev/null +++ b/nur_src/v/plugins/autosubmitOnChangePlugin.php @@ -0,0 +1,35 @@ +selector = $selector; + $this->cond = $cond; + } + + /** + * @var string sélecteur pour les composants concernés. + */ + private $selector; + + /** @var bool ce plugin est-il activé? */ + private $cond; + + function printJquery(): void { + if (!$this->cond) return; + ?> +$(selector)?>).change(function() { + $(this).closest("form").submit(); + return false; +}); +