From 6f7e201edca2b84a14387b6d17d62ab661f7df05 Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 27 May 2025 09:28:19 +0300 Subject: [PATCH] ERP-417 --- erp24/views/write_offs_erp/_form.php | 103 ++++++++++++++------------- 1 file changed, 55 insertions(+), 48 deletions(-) diff --git a/erp24/views/write_offs_erp/_form.php b/erp24/views/write_offs_erp/_form.php index 2593b3b2..b6e4f8a4 100644 --- a/erp24/views/write_offs_erp/_form.php +++ b/erp24/views/write_offs_erp/_form.php @@ -253,55 +253,62 @@ JS ] ], [ - 'name' => 'videoFiles', - 'title' => 'Видео: mp4, mov, avi', - 'type' => FileInput::class, - 'options' => [ - 'options' => [ - 'multiple' => false, - 'accept' => 'video/*', - 'name' => 'video_name', - ], - 'pluginOptions' => [ - 'showPreview' => true, - 'showCaption' => false, - 'showRemove' => true, - 'showUpload' => false, - 'browseIcon' => '+', - 'cancelIcon' => 'x', - 'removeIcon' => '-', - 'buttonLabelClass' => 'hidden', - 'fileActionSettings' => [ - 'showUpload' => false - ], - 'previewFileType' => 'video', - 'allowedFileExtensions' => ['mp4', 'mov', 'avi'], - 'initialPreview' => isset($model->id) ? [ - Files::find() - ->select('url') - ->where([ - 'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO, - 'entity_id' => $model->id - ]) - ->scalar() - ] : [], - 'initialPreviewAsData' => true, - 'initialPreviewConfig' => isset($model->id) ? [[ - 'type' => 'video', - 'caption' => basename( - Files::find() - ->select('url') - ->where([ + 'name' => 'videoFiles', + 'title' => 'Видео: mp4, mov, avi', + 'type' => FileInput::className(), + 'value' => function ($row) { + if (!isset($row['id'])) return null; + + $file = Files::findOne([ 'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO, - 'entity_id' => $model->id - ]) - ->scalar() - ), - 'url' => Url::to(['delete-video', 'id' => $model->id]), - ]] : [], - ] - ] -], + 'entity_id' => $row['id'] + ]); + + return $file ? $file->url : null; + }, + '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' => \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', 'type' => 'textInput', -- 2.39.5