From 16c4bd4da8dbb60deadf4e894eaa5438b78a6691 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 10 Dec 2015 12:50:10 +0100 Subject: [PATCH] QuickForm: add API helpers --- library/Director/Web/Form/QuickForm.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/library/Director/Web/Form/QuickForm.php b/library/Director/Web/Form/QuickForm.php index 1cfcdeb1..9e178725 100644 --- a/library/Director/Web/Form/QuickForm.php +++ b/library/Director/Web/Form/QuickForm.php @@ -68,6 +68,8 @@ abstract class QuickForm extends Zend_Form protected $hintCount = 0; + protected $isApiRequest = false; + public function __construct($options = null) { parent::__construct($this->handleOptions($options)); @@ -153,6 +155,17 @@ abstract class QuickForm extends Zend_Form return $this; } + public function setApiRequest($isApiRequest = true) + { + $this->isApiRequest = $isApiRequest; + return $this; + } + + public function isApiRequest() + { + return $this->isApiRequest; + } + protected function loadForm($name, Module $module = null) { if ($module === null) { @@ -363,6 +376,11 @@ abstract class QuickForm extends Zend_Form public function redirectOnSuccess($message = null) { + if ($this->isApiRequest()) { + Icinga::app()->getFrontController()->getResponse()->setMessage($message); + return; // TODO: Shutdown? + } + $url = $this->getSuccessUrl(); $this->notifySuccess($this->getSuccessMessage($message)); $this->redirectAndExit($url); @@ -392,6 +410,12 @@ abstract class QuickForm extends Zend_Form Icinga::app()->getFrontController()->getResponse()->redirectAndExit($url); } + protected function setHttpResponseCode($code) + { + Icinga::app()->getFrontController()->getResponse()->setHttpResponseCode($code); + return $this; + } + protected function onRequest() { }