From 43d2e6707518e9436be30176e5d814cbfbf26c28 Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 27 May 2025 09:10:36 +0300 Subject: [PATCH] ERP-417 --- erp24/views/write_offs_erp/_form.php | 81 +++++++++++++++------------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/erp24/views/write_offs_erp/_form.php b/erp24/views/write_offs_erp/_form.php index ec59f13d..ba726935 100644 --- a/erp24/views/write_offs_erp/_form.php +++ b/erp24/views/write_offs_erp/_form.php @@ -262,53 +262,58 @@ JS 'name' => 'videoFiles', 'title' => 'Видео: mp4, mov, avi', 'type' => FileInput::className(), - 'value' => function ($data) { - if (!$data || !isset($data['id'])) return null; + 'value' => function ($row) { + if (!isset($row['id'])) return null; $file = Files::findOne([ 'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO, - 'entity_id' => $data['id'] + 'entity_id' => $row['id'] ]); - return $file ? $file->url : null; // Return just the URL string + return $file ? $file->url : null; }, - 'options' => [ - 'options' => [ - 'multiple' => false, - 'accept' => 'video/*', - 'name' => 'video_name' - ], - 'pluginOptions' => [ - 'showPreview' => true, - 'showCaption' => true, - 'showRemove' => true, - 'showUpload' => true, - 'previewFileType' => 'video', - 'allowedFileTypes' => ['video'], - 'allowedFileExtensions' => ['mp4', 'mov', 'avi'], - 'maxFileSize' => 10240, - 'initialPreview' => function ($data) { - if (!$data || !isset($data['id'])) return []; - $file = Files::findOne([ - 'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO, - 'entity_id' => $data['id'] - ]); - return $file ? [$file->url] : []; - }, - 'initialPreviewConfig' => function ($data) { - if (!$data || !isset($data['id'])) return []; - $file = Files::findOne([ - 'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO, - 'entity_id' => $data['id'] - ]); - return $file ? [[ + 'columnOptions' => function($rowModel, $index, $context) { + $file = null; + $initialPreview = []; + $initialPreviewConfig = []; + + if (isset($rowModel['id'])) { + $file = Files::findOne([ + 'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO, + 'entity_id' => $rowModel['id'] + ]); + + if ($file) { + $initialPreview = [$file->url]; + $initialPreviewConfig = [[ 'type' => 'video', 'caption' => basename($file->url), - 'url' => Url::to(['delete-video', 'id' => $data['id']]) - ]] : []; + 'url' => \yii\helpers\Url::to(['delete-video', 'id' => $rowModel['id']]), + ]]; } - ], - ], + } + + return [ + 'options' => [ + 'multiple' => false, + 'accept' => 'video/*', + 'name' => 'video_name' + ], + 'pluginOptions' => [ + 'showPreview' => true, + 'showCaption' => true, + 'showRemove' => true, + 'showUpload' => true, + 'previewFileType' => 'video', + 'allowedFileTypes' => ['video'], + 'allowedFileExtensions' => ['mp4', 'mov', 'avi'], + 'maxFileSize' => 10240, + 'initialPreview' => $initialPreview, + 'initialPreviewAsData' => true, + 'initialPreviewConfig' => $initialPreviewConfig, + ], + ]; + }, ], [ 'name' => 'comment', -- 2.39.5