From e2239f22690490b749f85db3af53ebfa06e11016 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 3 Nov 2015 09:57:16 +0100 Subject: [PATCH] ImportsourceController: combine related actions --- .../controllers/ImportsourceController.php | 63 ++++++++++++------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/application/controllers/ImportsourceController.php b/application/controllers/ImportsourceController.php index 4aff7632..dcea204f 100644 --- a/application/controllers/ImportsourceController.php +++ b/application/controllers/ImportsourceController.php @@ -33,7 +33,17 @@ class ImportsourceController extends ActionController public function previewAction() { - $source = ImportSource::load($this->params->get('id'), $this->db()); + $id = $this->params->get('id'); + + $this->view->addLink = $this->view->qlink( + $this->translate('Run'), + 'director/importsource/add', + array('id' => $id) + ); + + $source = ImportSource::load($id, $this->db()); + $this->prepareTabs($id)->activate('preview'); + $this->view->title = sprintf( $this->translate('Import source preview: "%s"'), $source->source_name @@ -49,36 +59,45 @@ class ImportsourceController extends ActionController public function indexAction() { - $edit = false; - - if ($id = $this->params->get('id')) { - $edit = true; - } - - if ($edit) { - $this->view->title = $this->translate('Edit import source'); - $this->getTabs()->add('edit', array( - 'url' => 'director/importsource/edit' . '?id=' . $id, - 'label' => $this->view->title, - ))->activate('edit'); - } else { - $this->view->title = $this->translate('Add import source'); - $this->getTabs()->add('add', array( - 'url' => 'director/importsource/add', - 'label' => $this->view->title, - ))->activate('add'); - } + $id = $this->params->get('id'); $form = $this->view->form = $this->loadForm('importSource') ->setSuccessUrl('director/list/importsource') ->setDb($this->db()); - if ($edit) { + if ($id) { $form->loadObject($id); + $this->prepareTabs($id)->activate('edit'); + $this->view->title = $this->translate('Edit import source'); + } else { + $this->view->title = $this->translate('Add import source'); + $this->prepareTabs()->activate('add'); } $form->handleRequest(); - $this->render('object/form', null, true); } + + protected function prepareTabs($id = null) + { + $tabs = $this->getTabs(); + + if ($id) { + $tabs->add('edit', array( + 'url' => 'director/importsource/edit' . '?id=' . $id, + 'label' => $this->translate('Import source'), + ))->add('preview', array( + 'url' => 'director/importsource/preview' . '?id=' . $id, + 'label' => $this->translate('Preview'), + )); + + } else { + $tabs->add('add', array( + 'url' => 'director/importsource/add', + 'label' => $this->translate('New import source'), + ))->activate('add'); + } + + return $tabs; + } }