diff --git a/main/inc/lib/PortfolioController.php b/main/inc/lib/PortfolioController.php index 7b184db524..276013d544 100644 --- a/main/inc/lib/PortfolioController.php +++ b/main/inc/lib/PortfolioController.php @@ -399,6 +399,14 @@ class PortfolioController $extraField = new ExtraField('portfolio'); $extra = $extraField->addElements($form, $item->getId()); + $attachmentList = $this->generateAttachmentList($item, false); + + if (!empty($attachmentList)) { + $form->addLabel(get_lang('AttachmentFiles'), $attachmentList); + } + + $this->addAttachmentsFieldToForm($form); + $form->addButtonUpdate(get_lang('Update')); $form->setDefaults( [ @@ -428,6 +436,13 @@ class PortfolioController $this->em->persist($item); $this->em->flush(); + $this->processAttachments( + $form, + $item->getUser(), + $item->getId(), + PortfolioAttachment::TYPE_ITEM + ); + Display::addFlash( Display::return_message(get_lang('ItemUpdated'), 'success') ); @@ -1707,11 +1722,16 @@ class PortfolioController $fs->remove($attachmentFilename); - Display::addFlash( - Display::return_message(get_lang('AttachmentFileDeleteSuccess'), 'success') - ); + if ($httpRequest->isXmlHttpRequest()) { + echo Display::return_message(get_lang('AttachmentFileDeleteSuccess'), 'success'); + } else { + Display::addFlash( + Display::return_message(get_lang('AttachmentFileDeleteSuccess'), 'success') + ); + + header('Location: '.$this->baseUrl.http_build_query(['action' => 'view', 'id' => $itemId])); + } - header('Location: '.$this->baseUrl.http_build_query(['action' => 'view', 'id' => $itemId])); exit; } @@ -2095,7 +2115,7 @@ class PortfolioController return $form->returnForm(); } - private function generateAttachmentList($post): string + private function generateAttachmentList($post, bool $includeHeader = true): string { $attachmentsRepo = $this->em->getRepository(PortfolioAttachment::class); @@ -2117,7 +2137,7 @@ class PortfolioController $currentUserId = api_get_user_id(); - $listItems = ''; + $listItems = ''; + + if ($includeHeader) { + $listItems = Display::page_subheader(get_lang('AttachmentFiles'), null, 'h5', ['class' => 'h4']) + .$listItems; + } + + return $listItems; } private function generateItemContent(Portfolio $item): string diff --git a/main/inc/lib/javascript/portfolio.js b/main/inc/lib/javascript/portfolio.js new file mode 100644 index 0000000000..0b10640afe --- /dev/null +++ b/main/inc/lib/javascript/portfolio.js @@ -0,0 +1,11 @@ +$(function () { + $('.btn-portfolio-delete').on('click', function (e) { + e.preventDefault(); + + var self = this; + + $.get(self.href, function (response) { + $(self).parent().html(response); + }); + }); +}); \ No newline at end of file diff --git a/main/portfolio/index.php b/main/portfolio/index.php index 14558d8953..ccf1f36989 100755 --- a/main/portfolio/index.php +++ b/main/portfolio/index.php @@ -26,6 +26,8 @@ $httpRequest = HttpRequest::createFromGlobals(); $action = $httpRequest->query->get('action', 'list'); +$htmlHeadXtra[] = api_get_js('portfolio.js'); + switch ($action) { case 'add_category': $controller->addCategory();