support upload multiple
This commit is contained in:
parent
a372b76f9e
commit
a3f9094d8f
|
@ -13,7 +13,8 @@ class ControlFile extends ControlVisualInput {
|
||||||
"accept" => ["?string", ".pdf,image/*", "types MIME acceptés"],
|
"accept" => ["?string", ".pdf,image/*", "types MIME acceptés"],
|
||||||
"btn_class" => ["?string", "btn-default", "Classe du bouton"],
|
"btn_class" => ["?string", "btn-default", "Classe du bouton"],
|
||||||
"btn_style" => ["?string", null, "Style du bouton"],
|
"btn_style" => ["?string", null, "Style du bouton"],
|
||||||
"btn_label" => ["content", "Sélectionner un fichier", "Texte du bouton"],
|
"btn_label" => ["content", null, "Texte du bouton"],
|
||||||
|
"multiple" => ["?bool", null, "est-il possible de sélectionner plusieurs fichiers?"],
|
||||||
];
|
];
|
||||||
|
|
||||||
function __construct(Form $form, ?array $params=null) {
|
function __construct(Form $form, ?array $params=null) {
|
||||||
|
@ -31,9 +32,15 @@ class ControlFile extends ControlVisualInput {
|
||||||
/** @var string|array */
|
/** @var string|array */
|
||||||
protected $ppBtnLabel;
|
protected $ppBtnLabel;
|
||||||
|
|
||||||
|
/** @var ?bool */
|
||||||
|
protected $ppMultiple;
|
||||||
|
|
||||||
function buildControl(): array {
|
function buildControl(): array {
|
||||||
$name = $this->ppName;
|
$name = $this->ppName;
|
||||||
$value = $this->ppValue;
|
$value = $this->ppValue;
|
||||||
|
$multiple = $this->ppMultiple;
|
||||||
|
$defaultLabel = $multiple ? "Sélectionner des fichiers" : "Sélectionner un fichier";
|
||||||
|
$btnLabel = $this->ppBtnLabel ?? $defaultLabel;
|
||||||
return v::tag("label", [
|
return v::tag("label", [
|
||||||
"class" => ["btn btn-file", $this->ppBtnClass],
|
"class" => ["btn btn-file", $this->ppBtnClass],
|
||||||
v::tag1("input", [
|
v::tag1("input", [
|
||||||
|
@ -44,13 +51,14 @@ class ControlFile extends ControlVisualInput {
|
||||||
"readonly" => $this->ppReadonly? "readonly": false,
|
"readonly" => $this->ppReadonly? "readonly": false,
|
||||||
"disabled" => $this->ppDisabled? "disabled": false,
|
"disabled" => $this->ppDisabled? "disabled": false,
|
||||||
"required" => $this->ppRequired? "required": false,
|
"required" => $this->ppRequired? "required": false,
|
||||||
|
"multiple" => $multiple ? "multiple": false,
|
||||||
"style" => "display: inline; visibility: hidden; width: 0px; height: 0px; vertical-align: middle;",
|
"style" => "display: inline; visibility: hidden; width: 0px; height: 0px; vertical-align: middle;",
|
||||||
$this->ppAttrs,
|
$this->ppAttrs,
|
||||||
]),
|
]),
|
||||||
v::span([
|
v::span([
|
||||||
"class" => ["file-label", $this->ppClass],
|
"class" => ["file-label", $this->ppClass],
|
||||||
"style" => $this->ppStyle,
|
"style" => $this->ppStyle,
|
||||||
$this->ppBtnLabel,
|
$btnLabel,
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ class formfilePlugin extends BasePlugin {
|
||||||
$this->readyLabelSuffix = $readyLabelSuffix;
|
$this->readyLabelSuffix = $readyLabelSuffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
private $readyLabelClass = "btn-success";
|
private $readyLabelClass = "btn-success active";
|
||||||
|
|
||||||
function setReadyLabelClass(string $readyLabelClass): void {
|
function setReadyLabelClass(string $readyLabelClass): void {
|
||||||
$this->readyLabelClass = $readyLabelClass;
|
$this->readyLabelClass = $readyLabelClass;
|
||||||
|
@ -51,11 +51,24 @@ class formfilePlugin extends BasePlugin {
|
||||||
jQuery.noConflict()(function($) {
|
jQuery.noConflict()(function($) {
|
||||||
$("input[type='file']").change(function() {
|
$("input[type='file']").change(function() {
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
var filename = $this.prop("value");
|
var files = this.files;
|
||||||
var posas = filename.lastIndexOf("\\");
|
var filename;
|
||||||
var posfs = filename.lastIndexOf("/");
|
if (files !== undefined) {
|
||||||
if (posas !== -1) filename = filename.substr(posas + 1);
|
var count = files.length;
|
||||||
else if (posfs !== -1) filename = filename.substr(posfs + 1);
|
if (count === 1) {
|
||||||
|
filename = files[0].name;
|
||||||
|
} else if (count === 2) {
|
||||||
|
filename = "".concat(files[0].name, ", ", files[1].name, " (", count, ")");
|
||||||
|
} else {
|
||||||
|
filename = "".concat(files[0].name, ", ... (", count, ")");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
filename = $this.prop("value");
|
||||||
|
var posas = filename.lastIndexOf("\\");
|
||||||
|
var posfs = filename.lastIndexOf("/");
|
||||||
|
if (posas !== -1) filename = filename.substring(posas + 1);
|
||||||
|
else if (posfs !== -1) filename = filename.substring(posfs + 1);
|
||||||
|
}
|
||||||
var $label = $this.parent("label");
|
var $label = $this.parent("label");
|
||||||
$label.addClass(<?=js::qv($this->readyLabelClass)?>);
|
$label.addClass(<?=js::qv($this->readyLabelClass)?>);
|
||||||
var prefix = <?=js::qv($this->readyLabelPrefix)?>;
|
var prefix = <?=js::qv($this->readyLabelPrefix)?>;
|
||||||
|
|
|
@ -70,7 +70,7 @@ class Upload extends BaseArray {
|
||||||
"tmpName" => "tmp_name",
|
"tmpName" => "tmp_name",
|
||||||
"fullPath" => "full_path",
|
"fullPath" => "full_path",
|
||||||
];
|
];
|
||||||
function __get($name) {
|
function &__get($name) {
|
||||||
$name = static::_AUTO_PROPERTIES[$name] ?? $name;
|
$name = static::_AUTO_PROPERTIES[$name] ?? $name;
|
||||||
return parent::__get($name);
|
return parent::__get($name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue