From 8a985929ed84cdb458a13c66b25f84e41133b24f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:29:16 +0200 Subject: Adding upstream version 1.0.1. Signed-off-by: Daniel Baumann --- application/controllers/TemplatesController.php | 75 +++++++++++++------------ 1 file changed, 40 insertions(+), 35 deletions(-) (limited to 'application/controllers/TemplatesController.php') diff --git a/application/controllers/TemplatesController.php b/application/controllers/TemplatesController.php index 91a82b1..99a5dcb 100644 --- a/application/controllers/TemplatesController.php +++ b/application/controllers/TemplatesController.php @@ -1,22 +1,22 @@ hasPermission('reporting/templates'); if ($canManage) { - $this->addControl(new ButtonLink( - $this->translate('New Template'), - Url::fromPath('reporting/templates/new'), - 'plus' - )); + $this->addControl( + (new ButtonLink( + $this->translate('New Template'), + Url::fromPath('reporting/templates/new'), + 'plus' + ))->openInModal() + ); } - $select = (new Select()) - ->from('template') - ->columns(['id', 'name', 'author', 'ctime', 'mtime']) - ->orderBy('mtime', SORT_DESC); - - foreach ($this->getDb()->select($select) as $template) { - if ($canManage) { - // Edit URL - $subjectUrl = Url::fromPath( - 'reporting/template/edit', - ['id' => $template->id] - ); - } else { - // Preview URL - $subjectUrl = Url::fromPath( - 'reporting/template', - ['id' => $template->id] - ); - } + $templates = Model\Template::on(Database::get()); + + $sortControl = $this->createSortControl( + $templates, + [ + 'name' => $this->translate('Name'), + 'author' => $this->translate('Author'), + 'ctime' => $this->translate('Created At'), + 'mtime' => $this->translate('Modified At') + ] + ); + $this->addControl($sortControl); + + $tableRows = []; + + /** @var Model\Template $template */ + foreach ($templates as $template) { + // Preview URL + $subjectLink = new Link($template->name, Url::fromPath('reporting/template', ['id' => $template->id])); $tableRows[] = Html::tag('tr', null, [ - Html::tag('td', null, new Link($template->name, $subjectUrl)), + Html::tag('td', null, $subjectLink), Html::tag('td', null, $template->author), - Html::tag('td', null, date('Y-m-d H:i', $template->ctime / 1000)), - Html::tag('td', null, date('Y-m-d H:i', $template->mtime / 1000)) + Html::tag('td', null, $template->ctime->format('Y-m-d H:i')), + Html::tag('td', null, $template->mtime->format('Y-m-d H:i')) ]); } @@ -93,13 +95,16 @@ class TemplatesController extends Controller public function newAction() { $this->assertPermission('reporting/templates'); - $this->addTitleTab('New Template'); - - $form = new TemplateForm(); + $this->addTitleTab($this->translate('New Template')); - $form->handleRequest(ServerRequest::fromGlobals()); + $form = (new TemplateForm()) + ->setAction((string) Url::fromRequest()) + ->on(TemplateForm::ON_SUCCESS, function () { + Notification::success($this->translate('Created template successfully')); - $this->redirectForm($form, 'reporting/templates'); + $this->closeModalAndRefreshRelatedView(Url::fromPath('reporting/templates')); + }) + ->handleRequest($this->getServerRequest()); $this->addContent($form); } -- cgit v1.2.3