allow edit of media files

This commit is contained in:
Dennis Eichhorn 2020-06-11 16:42:49 +02:00
parent abffbdcd49
commit 2c10418578
2 changed files with 25 additions and 20 deletions

View File

@ -308,8 +308,10 @@ final class ApiController extends Controller
{ {
/** @var Media $old */ /** @var Media $old */
$old = clone MediaMapper::get((int) $request->getData('id')); $old = clone MediaMapper::get((int) $request->getData('id'));
/** @var Media $new */ /** @var Media $new */
$new = $this->updateMediaFromRequest($request); $new = $this->updateMediaFromRequest($request);
$this->updateModel($request->getHeader()->getAccount(), $old, $new, MediaMapper::class, 'media', $request->getOrigin()); $this->updateModel($request->getHeader()->getAccount(), $old, $new, MediaMapper::class, 'media', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Media', 'Media successfully updated', $new); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Media', 'Media successfully updated', $new);
} }

View File

@ -19,11 +19,10 @@ use \phpOMS\Uri\UriFactory;
include __DIR__ . '/template-functions.php'; include __DIR__ . '/template-functions.php';
/** /** @var \Modules\Media\Models\Media $media */
* @var \Modules\Media\Views\MediaView $this
* @var \Modules\Media\Models\Media $media
*/
$media = $this->getData('media'); $media = $this->getData('media');
/** @var \Modules\Media\Views\MediaView $this */
echo $this->getData('nav')->render(); echo $this->getData('nav')->render();
?> ?>
<?php if ($this->request->getData('path') !== null) : ?> <?php if ($this->request->getData('path') !== null) : ?>
@ -51,6 +50,21 @@ echo $this->getData('nav')->render();
<tr><td colspan="2"><?= $media->getDescription(); ?> <tr><td colspan="2"><?= $media->getDescription(); ?>
</table> </table>
</div> </div>
<?php
$path = $this->filePathFunction($media, $this->request->getData('sub') ?? '');
if ($this->isTextFile($media, $path)) : ?>
<div id="iMediaFileUpdate" class="portlet-foot"
data-update-content="#mediaFile .portlet-body"
data-update-element="#mediaFile .textContent"
data-update-tpl="#iMediaUpdateTpl"
data-tag="form"
data-method="POST"
data-uri="<?= UriFactory::build('{/api}media?{?}&csrf={$CSRF}'); ?>">
<button class="save hidden"><?= $this->getHtml('Save', '0', '0') ?></button>
<button class="cancel hidden"><?= $this->getHtml('Cancel', '0', '0') ?></button>
<button class="update"><?= $this->getHtml('Edit', '0', '0') ?></button>
</div>
<?php endif; ?>
</section> </section>
</div> </div>
</div> </div>
@ -71,7 +85,7 @@ echo $this->getData('nav')->render();
<td><?= $this->getHtml('Created') ?> <td><?= $this->getHtml('Created') ?>
<tbody> <tbody>
<?php <?php
if (!\is_dir($media->isAbsolute() ? $path : __DIR__ . '/../../../../' . \ltrim($media->getPath(), '//')) if (!\is_dir($media->isAbsolute() ? $media->getPath() : __DIR__ . '/../../../../' . \ltrim($media->getPath(), '//'))
|| $media->getPath() === '' || $media->getPath() === ''
) : ) :
foreach ($media as $key => $value) : foreach ($media as $key => $value) :
@ -104,13 +118,8 @@ echo $this->getData('nav')->render();
</div> </div>
<?php else: ?> <?php else: ?>
<div class="col-xs-12"> <div class="col-xs-12">
<section id="mediaFile" class="portlet" <section id="mediaFile" class="portlet">
data-update-content=".inner" <div class="portlet-body">
data-update-element="#mediaFile .textContent"
data-tag="form"
data-method="POST"
data-uri="<?= \phpOMS\Uri\UriFactory::build('{/api}media?{?}&csrf={$CSRF}'); ?>">
<div class="portlet-body inner">
<?php <?php
$path = $this->filePathFunction($media, $this->request->getData('sub') ?? ''); $path = $this->filePathFunction($media, $this->request->getData('sub') ?? '');
@ -119,19 +128,13 @@ echo $this->getData('nav')->render();
<img src="<?= $media->isAbsolute() ? $this->printHtml($path) : $this->printHtml($this->request->getUri()->getBase() . $path); ?>"> <img src="<?= $media->isAbsolute() ? $this->printHtml($path) : $this->printHtml($this->request->getUri()->getBase() . $path); ?>">
</div> </div>
<?php elseif ($this->isTextFile($media, $path)) : ?> <?php elseif ($this->isTextFile($media, $path)) : ?>
<div class="vC">
<button class="save hidden"><?= $this->getHtml('Save', '0', '0') ?></button>
<button class="cancel hidden"><?= $this->getHtml('Cancel', '0', '0') ?></button>
<button class="update"><?= $this->getHtml('Edit', '0', '0') ?></button>
</div>
<!-- if markdown show markdown editor, if image show image editor, if text file show textarea only on edit --> <!-- if markdown show markdown editor, if image show image editor, if text file show textarea only on edit -->
<?php if (!\file_exists($media->isAbsolute() ? $path : __DIR__ . '/../../../../' . \ltrim($path, '/'))) : ?> <?php if (!\file_exists($media->isAbsolute() ? $path : __DIR__ . '/../../../../' . \ltrim($path, '/'))) : ?>
<div class="centerText"><i class="fa fa-question fa-5x"></i></div> <div class="centerText"><i class="fa fa-question fa-5x"></i></div>
<?php else : ?> <?php else : ?>
<template></template><!-- todo: this is required because of selectorLength + i in Form.js = first element = add template, second element = edit element. Fix --> <template id="iMediaUpdateTpl">
<template> <textarea class="textContent" form="iMediaFileUpdate" data-tpl-text="/media/content" data-tpl-value="/media/content" data-marker="tpl" name="content"></textarea>
<textarea class="textContent" data-tpl-text="/media/content" data-tpl-value="/media/content" data-marker="tpl" name="content"></textarea>
</template> </template>
<pre class="textContent" data-tpl-text="/media/content" data-tpl-value="/media/content"><?= $this->printHtml( <pre class="textContent" data-tpl-text="/media/content" data-tpl-value="/media/content"><?= $this->printHtml(
$this->getFileContent( $this->getFileContent(