Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Administrační komponenta pro manipulaci a definici s obsahem tabulky.
- * @property-read TableModel
- */
- abstract class AdminControl extends BaseControl
- {
- ...
- /**
- * Component factory
- * @see Nette/ComponentContainer#createComponent()
- */
- protected function createComponent($name)
- {
- if (preg_match('~(.*)Form~', $name)) {
- $this->createComponentForm($name);
- return;
- }
- parent::createComponent($name);
- }
- /**
- * Component factory.
- * @param string
- * @return void
- */
- abstract protected function createComponentForm($name);
- /**
- * Form submit handler.
- * @param AppForm $form
- * @return void
- */
- public function formSubmitHandler(AppForm $form)
- {
- // was submitted?
- if ($form->isSubmitted() && $form->isValid()) {
- $values = new MyDibiRow($form->getValues());
- preg_match('~(?<action>.*)Form~', $form->getName(), $matches);
- $ucname = ucfirst($matches['action']);
- $method = 'handle' . $ucname;
- if ($ucname === $matches['action'] || !method_exists($this, $method) || $this->getReflection()->getMethod($method)->getName() !== $method) {
- throw new InvalidArgumentException("Unknown action '{$matches['action']}'. Method '$method' does not exists.");
- }
- if (isset($values[$this->getModel()->primary])) {
- $key = $values[$this->getModel()->primary];
- unset($values[$this->getModel()->primary]);
- } else {
- $key = NULL;
- }
- try {
- $this->$method($key, $values); // tryes to call handle<Action>($key, $values) method
- }
- catch (BadRequestException $e) {
- $this->presenter->flashMessage($e->getMessage(), 'error');
- }
- catch (Exception $e) {
- $this->presenter->flashMessage("Operace se nezdařila, zkuste ji provést znovu později.", 'error');
- Debug::processException($e);
- }
- $this->signal = NULL;
- $this->invalidateControl();
- $this['grid']->invalidateControl();
- }
- if (!$this->isAjax()) $this->redirect('this');
- }
- protected function handleAdd($key, $values)
- {
- $this->getModel()->insert($values);
- $this->presenter->flashMessage('Úspěšně přidáno', 'success');
- }
- protected function handleEdit($key, $values)
- {
- $this->getModel()->update($key, $values);
- $this->presenter->flashMessage('Úspěšně upraveno', 'success');
- }
- protected function handleDelete($key, $values = NULL)
- {
- $this->getModel()->delete($key);
- $this->presenter->flashMessage('Úspěšně odstraněno', 'success');
- }
- }
Add Comment
Please, Sign In to add comment