]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-417
authormarina <m.zozirova@gmail.com>
Tue, 27 May 2025 06:42:56 +0000 (09:42 +0300)
committermarina <m.zozirova@gmail.com>
Tue, 27 May 2025 06:42:56 +0000 (09:42 +0300)
erp24/views/write_offs_erp/_form.php

index 8ca58128806b399e06b6b57749fda2d13ad687ad..d0baaebfa73135582f098f1346fac6131e164e01 100644 (file)
@@ -246,68 +246,44 @@ JS
                     'name' => 'videoFiles',
                     'title' => 'Видео: mp4, mov, avi',
                     'type' => FileInput::class,
-                    'value' => function ($row) {
-                        if (!isset($row['id'])) return null;
-
-                        $file = Files::findOne([
-                            'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO,
-                            'entity_id' => $row['id'],
-                        ]);
-
-                        return $file ? $file->url : null;
-                    },
-                    'columnOptions' => function ($rowModel, $index, $context) {
-                        $file = null;
-                        $initialPreviewConfig = [];
-
-                        if (isset($rowModel['id'])) {
-                            $file = Files::findOne([
-                                'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO,
-                                'entity_id' => $rowModel['id'],
-                            ]);
-
-                            if ($file) {
-                                $initialPreviewConfig = [[
-                                    'caption' => basename($file->url),
-                                    'url' => \yii\helpers\Url::to(['delete-video', 'id' => $rowModel['id']]),
-                                ]];
-                            }
-                        }
-
-                        return [
-                            'attribute' => 'videoFiles',
-                            'options' => [
-                                'multiple' => false,
-                                'accept' => 'video/*',
-                                'name' => 'video_name',
-                                'class' => 'file',
-                            ],
-                            'pluginOptions' => [
-                                'showPreview' => false,           // отключаем превью видео
-                                'showCaption' => true,            // показываем название файла
-                                'showRemove' => true,
-                                'showUpload' => true,
-                                'initialPreview' => [],            // без превью
-                                'initialPreviewAsData' => false,  // без превью как данные
-                                'initialPreviewConfig' => $initialPreviewConfig,
-                                'browseLabel' => '+',
-                                'removeLabel' => '-',
-                                'cancelLabel' => 'x',
-                                'layoutTemplates' => [
-                                    'actions' => '<div class="file-actions">{remove} {upload} {cancel}</div>',
-                                    'actionUpload' => '<button type="button" title="{uploadTitle}" class="kv-file-upload {uploadClass}" style="margin-left:5px">{uploadIcon}</button>',
-                                    'actionRemove' => '<button type="button" title="{removeTitle}" class="kv-file-remove {removeClass}">{removeIcon}</button>',
-                                    'actionCancel' => '<button type="button" title="{cancelTitle}" class="kv-file-cancel {cancelClass}">{cancelIcon}</button>',
-                                ],
-                                'fileActionSettings' => [
-                                    'showUpload' => true,
-                                    'showRemove' => true,
-                                    'showZoom' => false,
-                                    'showDrag' => false,
-                                ],
-                            ],
-                        ];
-                    },
+                    'options' => [
+                        'options' => [
+                            'multiple' => false,
+                            'accept' => 'video/*',
+                            'name' => 'video_name',
+                        ],
+                        'pluginOptions' => [
+                            'showPreview' => true,
+                            'showCaption' => true,
+                            'showRemove' => true,
+                            'showUpload' => false,
+                            'previewFileType' => 'video',
+                            'allowedFileExtensions' => ['mp4', 'mov', 'avi'],
+                            'initialPreview' => isset($model->id) ? [ // или $row['id'], если это в цикле
+                                Files::find()
+                                    ->select('url')
+                                    ->where([
+                                        'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO,
+                                        'entity_id' => $model->id // или $row['id']
+                                    ])
+                                    ->scalar()
+                            ] : [],
+                            'initialPreviewAsData' => true,
+                            'initialPreviewConfig' => isset($model->id) ? [[
+                                'type' => 'video',
+                                'caption' => basename(
+                                    Files::find()
+                                        ->select('url')
+                                        ->where([
+                                            'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO,
+                                            'entity_id' => $model->id
+                                        ])
+                                        ->scalar()
+                                ),
+                                'url' => Url::to(['delete-video', 'id' => $model->id]),
+                            ]] : [],
+                        ]
+                    ]
                 ],
                 [
                     'name' => 'comment',