Portfolio: Add attachments when editing post - refs BT# 18201

It makes delete attachment by ajax
pull/3814/head
Angel Fernando Quiroz Campos 5 years ago
parent 3db29e3ce9
commit 36c9a4ed5e
  1. 44
      main/inc/lib/PortfolioController.php
  2. 11
      main/inc/lib/javascript/portfolio.js
  3. 2
      main/portfolio/index.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 = '<ul class="fa-ul">';
$deleteIcon = Display::return_icon(
'delete.png',
@ -2125,6 +2145,7 @@ class PortfolioController
['style' => 'display: inline-block'],
ICON_SIZE_TINY
);
$deleteAttrs = ['class' => 'btn-portfolio-delete'];
/** @var PortfolioAttachment $attachment */
foreach ($attachments as $attachment) {
@ -2139,7 +2160,7 @@ class PortfolioController
);
if ($currentUserId === $postOwnerId) {
$listItems .= PHP_EOL.Display::url($deleteIcon, $this->baseUrl.$deleteParams);
$listItems .= PHP_EOL.Display::url($deleteIcon, $this->baseUrl.$deleteParams, $deleteAttrs);
}
if ($attachment->getComment()) {
@ -2152,7 +2173,14 @@ class PortfolioController
$listItems .= '</li>';
}
return '<h5 class="h4">'.get_lang('AttachmentFiles').'</h5>'.'<ul class="fa-ul">'.$listItems.'</ul>';
$listItems .= '</ul>';
if ($includeHeader) {
$listItems = Display::page_subheader(get_lang('AttachmentFiles'), null, 'h5', ['class' => 'h4'])
.$listItems;
}
return $listItems;
}
private function generateItemContent(Portfolio $item): string

@ -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);
});
});
});

@ -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();

Loading…
Cancel
Save