From b320fdd4dc7660dccb879c2569e42f6611d69a44 Mon Sep 17 00:00:00 2001 From: marina Date: Mon, 26 May 2025 11:04:11 +0300 Subject: [PATCH] ERP-417 --- erp24/views/write_offs_erp/_form.php | 56 ++++++++++++++++++---------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/erp24/views/write_offs_erp/_form.php b/erp24/views/write_offs_erp/_form.php index aff4ad65..c74a9970 100644 --- a/erp24/views/write_offs_erp/_form.php +++ b/erp24/views/write_offs_erp/_form.php @@ -6,6 +6,7 @@ use unclead\multipleinput\components\BaseColumn; use unclead\multipleinput\MultipleInput; use unclead\multipleinput\MultipleInputColumn; use yii\helpers\Html; +use yii\helpers\Url; use yii\widgets\ActiveForm; @@ -261,40 +262,57 @@ JS 'type' => FileInput::className(), 'value' => function ($data) { if (!$data || !isset($data['id'])) return null; + $file = Files::findOne([ 'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO, 'entity_id' => $data['id'] ]); - return $file ? basename($file->url) : null; + + return $file ? [ + 'caption' => basename($file->url), + 'url' => $file->url // URL для удаления или скачивания + ] : null; }, 'options' => [ 'options' => [ 'multiple' => false, 'accept' => 'video/*', - 'name' => 'video_name', - 'class' => 'file' + 'name' => 'video_name' ], 'pluginOptions' => [ 'showPreview' => true, - 'showCaption' => true, // ✅ Должно быть true - 'initialCaption' => '55656', - 'initialPreview' => '809', -// 'initialPreviewConfig' => function($data) { -// if (!$data || !isset($data['id'])) return []; -// $file = Files::findOne([ -// 'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO, -// 'entity_id' => $data['id'] -// ]); -// return $file ? [[ -// 'caption' => basename($file->url), // ✅ Обязательно! -// 'type' => 'video', -// 'size' => @filesize(Yii::getAlias('@webroot') . $file->url), -// ]] : []; -// }, + 'showCaption' => true, + 'showRemove' => true, + 'showUpload' => true, + 'initialPreview' => function ($data) { + $file = Files::findOne([ + 'entity' => self::WRITE_OFFS_VIDEO, + 'entity_id' => $data['id'] + ]); + return $file ? [$file->url] : []; + }, + 'initialPreviewConfig' => function ($data) { + $file = Files::findOne([ + 'entity' => self::WRITE_OFFS_VIDEO, + 'entity_id' => $data['id'] + ]); + + return $file ? [[ + 'type' => 'video', + 'filetype' => mime_content_type($file->path), + 'caption' => basename($file->url), + 'size' => filesize($file->path), + 'url' => Url::to(['delete-video', 'id' => $data['id']]) + ]] : []; + }, + 'previewFileType' => 'video', + 'allowedFileTypes' => ['video'], + 'allowedFileExtensions' => ['mp4', 'mov', 'avi'], + 'maxFileSize' => 10240, // 10MB ], ], 'columnOptions' => [ - 'style' => 'min-width: 240px; overflow: visible;', // ✅ Убедитесь, что не hidden + 'style' => 'min-width: 240px; overflow: visible;', ], ], [ -- 2.39.5