From c13c66f7bcfdb3d1eadc1d5168c2d29944c9dcec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20Cuello=20Principal?= Date: Thu, 24 Oct 2024 09:19:43 +0200 Subject: [PATCH] =?UTF-8?q?Corregido=20bug=20por=20p=C3=A9rdida=20de=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/Assets/JS/WidgetLibrary.js | 4 +- .../ExtendedController/PanelController.php | 18 +++--- Core/Lib/Widget/WidgetLibrary.php | 56 +++++++++---------- 3 files changed, 37 insertions(+), 41 deletions(-) diff --git a/Core/Assets/JS/WidgetLibrary.js b/Core/Assets/JS/WidgetLibrary.js index cf043045ef..51df0d4a80 100644 --- a/Core/Assets/JS/WidgetLibrary.js +++ b/Core/Assets/JS/WidgetLibrary.js @@ -23,9 +23,9 @@ function widgetLibrarySearch(id) { action: 'widget-library-search', active_tab: input.closest('form').find('input[name="activetab"]').val(), col_name: input.attr("name"), - widget_id: id, query: $("#modal_" + id + "_q").val(), sort: $("#modal_" + id + "_s").val(), + unique_id: id, }; $.ajax({ @@ -64,8 +64,8 @@ function widgetLibraryUpload(id, file) { data.append('action', 'widget-library-upload'); data.append('active_tab', input.closest('form').find('input[name="activetab"]').val()); data.append('col_name', input.attr("name")); - data.append('widget_id', id); data.append('file', file); + data.append('unique_id', id); $.ajax({ method: "POST", diff --git a/Core/Lib/ExtendedController/PanelController.php b/Core/Lib/ExtendedController/PanelController.php index e5bd4f2bd9..3257126ec3 100644 --- a/Core/Lib/ExtendedController/PanelController.php +++ b/Core/Lib/ExtendedController/PanelController.php @@ -393,13 +393,13 @@ protected function insertAction() protected function widgetLibrarySearchAction(): array { - // localizamos la pestaña y el nombre de la columna + // localizamos la pestaña, el nombre de la columna y el unique id $activeTab = $this->request->request->get('active_tab', ''); $colName = $this->request->request->get('col_name', ''); - $widgetId = $this->request->request->get('widget_id', ''); + $uniqueId = (int)$this->request->request->get('unique_id', -1); // si está vacío, no hacemos nada - if (empty($activeTab) || empty($colName)) { + if (empty($activeTab) || empty($colName) || $uniqueId < 0) { return ['records' => 0, 'html' => '']; } @@ -414,22 +414,22 @@ protected function widgetLibrarySearchAction(): array $this->request->request->get('sort', '') ); - $selectedValue = (int)$column->widget->plainText($this->tab($activeTab)->model); + $selected_value = (int)$column->widget->plainText($this->tab($activeTab)->model); return [ - 'html' => $column->widget->renderFileList($files, $selectedValue, $widgetId), + 'html' => $column->widget->renderFileList($uniqueId, $files, $selected_value), 'records' => count($files), ]; } protected function widgetLibraryUploadAction(): array { - // localizamos la pestaña y el nombre de la columna + // localizamos la pestaña, el nombre de la columna y el unique id $activeTab = $this->request->request->get('active_tab', ''); $colName = $this->request->request->get('col_name', ''); - $widgetId = $this->request->request->get('widget_id', ''); + $uniqueId = (int)$this->request->request->get('unique_id', -1); // si está vacío, no hacemos nada - if (empty($activeTab) || empty($colName)) { + if (empty($activeTab) || empty($colName) || $uniqueId < 0) { return []; } @@ -446,7 +446,7 @@ protected function widgetLibraryUploadAction(): array $files = $column->widget->files(); return [ - 'html' => $column->widget->renderFileList($files, $file->idfile, $widgetId), + 'html' => $column->widget->renderFileList($uniqueId, $files), 'records' => count($files), 'new_file' => $file->idfile, 'new_filename' => $file->shortFileName(), diff --git a/Core/Lib/Widget/WidgetLibrary.php b/Core/Lib/Widget/WidgetLibrary.php index ae7daad019..3296140c1d 100644 --- a/Core/Lib/Widget/WidgetLibrary.php +++ b/Core/Lib/Widget/WidgetLibrary.php @@ -78,7 +78,7 @@ public function edit($model, $title = '', $description = '', $titleurl = '') . '' . $descriptionHtml . '' - . $this->renderModal($icon, $label) + . $this->renderModal($icon, $label, $this->id) . "\n"; @@ -160,7 +160,7 @@ public function files(string $query = '', string $sort = 'date-desc'): array return $list; } - public function renderFileList(array $files = [], ?int $selected_value = null, ?string $id = null): string + public function renderFileList(int $id, array $files = [], ?int $selected_value = null): string { $html = ''; @@ -185,7 +185,7 @@ public function renderFileList(array $files = [], ?int $selected_value = null, ? if ($file->isImage()) { $html .= '
' - . '' . $file->filename
+                    . '<img src=url('download-permanent') . '" class="mr-3" alt="' . $file->filename . '" width="64" type="button" onclick="' . $js . '" title="' . Tools::lang()->trans('select') . '">' . '
' . '
' . $file->filename . '
' @@ -235,27 +235,27 @@ public function uploadFile(UploadedFile $uploadFile): AttachedFile return new AttachedFile(); } - protected function renderQueryFilter(): string + protected function renderQueryFilter(int $id): string { return '
' - . '' + . '' . '
' - . '' . '
' . '
'; } - protected function renderModal(string $icon, string $label): string + protected function renderModal(string $icon, string $label, int $id): string { - return '