add basic edit

This commit is contained in:
Dennis Eichhorn 2020-06-06 14:16:30 +02:00
parent 4b7806f527
commit a8064c7baa
3 changed files with 81 additions and 18 deletions

View File

@ -59,4 +59,24 @@ return [
], ],
], ],
], ],
'^.*/news/edit.*$' => [
[
'dest' => '\Modules\Editor\Controller\BackendController:setUpEditorEditor',
'verb' => RouteVerb::GET,
'permission' => [
'module' => BackendController::MODULE_NAME,
'type' => PermissionType::MODIFY,
'state' => PermissionState::NEWS,
],
],
[
'dest' => '\Modules\News\Controller\BackendController:viewNewsEdit',
'verb' => RouteVerb::GET,
'permission' => [
'module' => BackendController::MODULE_NAME,
'type' => PermissionType::MODIFY,
'state' => PermissionState::NEWS,
],
],
],
]; ];

View File

@ -183,4 +183,34 @@ final class BackendController extends Controller implements DashboardElementInte
return $view; return $view;
} }
/**
* Routing end-point for application behaviour.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return RenderableInterface
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function viewNewsEdit(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface
{
$view = new View($this->app->l11nManager, $request, $response);
$view->setTemplate('/Modules/News/Theme/Backend/news-create');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000701001, $request, $response));
$editor = new \Modules\Editor\Theme\Backend\Components\Editor\BaseView($this->app->l11nManager, $request, $response);
$view->addData('editor', $editor);
$accGrpSelector = new \Modules\Profile\Theme\Backend\Components\AccountGroupSelector\BaseView($this->app->l11nManager, $request, $response);
$view->addData('accGrpSelector', $accGrpSelector);
$view->addData('news', NewsArticleMapper::get((int) ($request->getData('id') ?? 0)));
return $view;
}
} }

View File

@ -12,9 +12,15 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
/** use Modules\News\Models\NullNewsArticle;
* @var \phpOMS\Views\View $this use Modules\News\Models\NewsStatus;
*/ use phpOMS\Uri\UriFactory;
use Modules\News\Models\NewsType;
/** @var \Modules\News\Models\NewsArticle $news */
$news = $this->getData('news') ?? new NullNewsArticle();
/** @var \phpOMS\Views\View $this */
echo $this->getData('nav')->render(); ?> echo $this->getData('nav')->render(); ?>
<div class="row"> <div class="row">
@ -22,7 +28,7 @@ echo $this->getData('nav')->render(); ?>
<div id="testEditor" class="m-editor"> <div id="testEditor" class="m-editor">
<section class="portlet"> <section class="portlet">
<div class="portlet-body"> <div class="portlet-body">
<input id="iTitle" type="text" name="title" form="docForm"> <input id="iTitle" type="text" name="title" form="docForm" value="<?= $news->getTitle(); ?>">
</div> </div>
</section> </section>
@ -40,28 +46,35 @@ echo $this->getData('nav')->render(); ?>
<div class="col-xs-12 col-md-3"> <div class="col-xs-12 col-md-3">
<section class="portlet"> <section class="portlet">
<div class="portlet-head"><?= $this->getHtml('Status'); ?></div> <form id="docForm" method="PUT" action="<?= UriFactory::build('{/api}news?csrf={$CSRF}'); ?>">
<div class="portlet-body"> <div class="portlet-head"><?= $this->getHtml('Status'); ?></div>
<form id="docForm" method="PUT" action="<?= \phpOMS\Uri\UriFactory::build('{/api}news?{?}&csrf={$CSRF}'); ?>"> <div class="portlet-body">
<table class="layout wf-100"> <table class="layout wf-100">
<tr><td colspan="2"><select name="status" id="iStatus"> <tr><td colspan="2"><select name="status" id="iStatus">
<option value="<?= $this->printHtml(Modules\News\Models\NewsStatus::DRAFT); ?>" selected><?= $this->getHtml('Draft'); ?> <option value="<?= $this->printHtml(NewsStatus::DRAFT); ?>"<?= $news->getStatus() === NewsStatus::DRAFT ? ' selected' : ''; ?>><?= $this->getHtml('Draft'); ?>
<option value="<?= $this->printHtml(Modules\News\Models\NewsStatus::VISIBLE); ?>"><?= $this->getHtml('Visible'); ?> <option value="<?= $this->printHtml(NewsStatus::VISIBLE); ?>"<?= $news->getStatus() === NewsStatus::VISIBLE ? ' selected' : ''; ?>><?= $this->getHtml('Visible'); ?>
<tr> <tr>
<td colspan="2"> <td colspan="2">
<label for="iPublish"><?= $this->getHtml('Publish'); ?></label> <label for="iPublish"><?= $this->getHtml('Publish'); ?></label>
<tr> <tr>
<td colspan="2"> <td colspan="2">
<input type="datetime-local" name="publish" id="iPublish" value="<?= $this->printHtml((new \DateTime('NOW'))->format('Y-m-d\TH:i:s')); ?>"> <input type="datetime-local" name="publish" id="iPublish" value="<?= $this->printHtml($news->getPublish()->format('Y-m-d\TH:i:s')); ?>">
</table>
</div>
<div class="portlet-foot">
<table class="layout wf-100">
<tr> <tr>
<td> <td>
<input type="submit" name="deleteButton" id="iDeleteButton" value="<?= $this->getHtml('Delete', '0', '0'); ?>"> <?php if ($news instanceof NullNewsArticle) : ?>
<a href="<?= UriFactory::build('/news/dashboard'); ?>" class="button"><?= $this->getHtml('Delete', '0', '0'); ?></a>
<?php else : ?>
<input type="submit" name="deleteButton" id="iDeleteButton" value="<?= $this->getHtml('Delete', '0', '0'); ?>">
<?php endif; ?>
<td class="rightText"> <td class="rightText">
<input type="submit" formaction="<?= \phpOMS\Uri\UriFactory::build('{/api}news?{?}&release=false&csrf={$CSRF}'); ?>" name="saveButton" id="iSaveButton" value="<?= $this->getHtml('Save', '0', '0'); ?>"> <input type="submit" formaction="<?= UriFactory::build('{/api}news&csrf={$CSRF}'); ?>" name="saveButton" id="iSaveButton" value="<?= $this->getHtml('Save', '0', '0'); ?>">
<input type="submit" name="publishButton" id="iPublishButton" value="<?= $this->getHtml('Publish'); ?>">
</table> </table>
</form> </div>
</div> </form>
</section> </section>
<section class="portlet"> <section class="portlet">
<div class="portlet-head"><?= $this->getHtml('Type'); ?></div> <div class="portlet-head"><?= $this->getHtml('Type'); ?></div>
@ -69,19 +82,19 @@ echo $this->getData('nav')->render(); ?>
<table class="layout wf-100"> <table class="layout wf-100">
<tr><td> <tr><td>
<label class="radio" for="iNewsTypeArticle"> <label class="radio" for="iNewsTypeArticle">
<input type="radio" name="type" id="iNewsTypeArticle" form="docForm" value="<?= $this->printHtml(Modules\News\Models\NewsType::ARTICLE); ?>" checked> <input type="radio" name="type" id="iNewsTypeArticle" form="docForm" value="<?= $this->printHtml(NewsType::ARTICLE); ?>"<?= $news->getType() === NewsType::ARTICLE ? ' checked' : ''; ?>>
<span class="checkmark"></span> <span class="checkmark"></span>
<?= $this->getHtml('News'); ?> <?= $this->getHtml('News'); ?>
</label> </label>
<tr><td> <tr><td>
<label class="radio" for="iNewsTypeHeadline"> <label class="radio" for="iNewsTypeHeadline">
<input type="radio" name="type" id="iNewsTypeHeadline" form="docForm" value="<?= $this->printHtml(Modules\News\Models\NewsType::HEADLINE); ?>"> <input type="radio" name="type" id="iNewsTypeHeadline" form="docForm" value="<?= $this->printHtml(NewsType::HEADLINE); ?>"<?= $news->getType() === NewsType::HEADLINE ? ' checked' : ''; ?>>
<span class="checkmark"></span> <span class="checkmark"></span>
<?= $this->getHtml('Headline'); ?> <?= $this->getHtml('Headline'); ?>
</label> </label>
<tr><td> <tr><td>
<label class="radio" for="iNewsTypeLink"> <label class="radio" for="iNewsTypeLink">
<input type="radio" name="type" id="iNewsTypeLink" form="docForm" value="<?= $this->printHtml(Modules\News\Models\NewsType::LINK); ?>"> <input type="radio" name="type" id="iNewsTypeLink" form="docForm" value="<?= $this->printHtml(NewsType::LINK); ?>"<?= $news->getType() === NewsType::LINK ? ' checked' : ''; ?>>
<span class="checkmark"></span> <span class="checkmark"></span>
<?= $this->getHtml('Link'); ?> <?= $this->getHtml('Link'); ?>
</label> </label>