diff --git a/components/D3FilesColumn.php b/components/D3FilesColumn.php index 874265c..12561ad 100644 --- a/components/D3FilesColumn.php +++ b/components/D3FilesColumn.php @@ -21,11 +21,17 @@ class D3FilesColumn extends DataColumn public $model; public $modelClass; public $listBoxOptions = []; + public $listTemplate; private $dataProviderIds = []; private $recordsWithFiles = []; private $controllerRoute = false; + public const TEMPLATE_DROPDOWN_LIST = 'dropdown-list'; + public const TEMPLATE_UL_LIST = 'list'; + public const TEMPLATE_FILES = 'files'; + public const TEMPLATE_ATTACHMENT_ICON = 'attachment-icon'; + /** * Set the initial properties on class init */ @@ -42,6 +48,8 @@ public function init(): void 'prompt' => \Yii::t('d3files', 'Filter by Attachment') ]; + $this->listTemplate = self::TEMPLATE_FILES; + parent::init(); } @@ -86,15 +94,13 @@ public function renderDataCellContent($model, $key, $index): string $search = Yii::$app->request->get('RkInvoiceSearch'); $files = !empty($model->filesList) ? json_decode($model->filesList, true) : []; - - $filesCount = count($files); - + $params = [ 'model' => $this->modelClass, 'model_id' => $model->id, 'readOnly' => true, 'viewByFancyBox' => true, - 'template' => $filesCount > 1 ? 'dropdown-list' : 'list', + 'template' => self::TEMPLATE_ATTACHMENT_ICON, 'fileList' => $files, ]; diff --git a/views/d3files/attachment-icon_readonly.php b/views/d3files/attachment-icon_readonly.php new file mode 100644 index 0000000..2ad6f58 --- /dev/null +++ b/views/d3files/attachment-icon_readonly.php @@ -0,0 +1,46 @@ + $file) { + if (strstr($file['file_name'], '.pdf')) { + $file['file_url'] = [$url_prefix . 'd3filesopen', 'id' => $file['file_model_id']]; + $pdfFile = $file; + break; + } +} + +if (!$pdfFile) { + return; +} + +$dataAttributes = D3FilesWidget::getModalLoadAttributes( + $pdfFile['file_url'], + $pdfFile, + '#' . ThModal::MODAL_ID, + '.' . ThModal::MODAL_CONTENT_CLASS +); + +$dataAttributesStr = ''; + +foreach ($dataAttributes as $key => $val) { + $dataAttributesStr .= ' ' . $key . '="' . $val . '"'; +} +?> + + class="d3files-attachment-load" data-files-list=''> diff --git a/views/d3files/dropdown-list_readonly.php b/views/d3files/dropdown-list_readonly.php new file mode 100644 index 0000000..90685cd --- /dev/null +++ b/views/d3files/dropdown-list_readonly.php @@ -0,0 +1,46 @@ + + diff --git a/widgets/D3FilesWidget.php b/widgets/D3FilesWidget.php index 16fc482..a634df0 100644 --- a/widgets/D3FilesWidget.php +++ b/widgets/D3FilesWidget.php @@ -145,7 +145,7 @@ public static function getModalLoadAttributes(array $attachmentUrl, array $file, $attrs = [ 'data-toggle' => 'modal', - 'data-src' => Url::to($attachmentUrl), + 'data-src' => Url::to($attachmentUrl, true), 'data-target' => $modalSelector, 'data-content-target' => $modalContentSelector, ];