Commit b47ab4e7 authored by Carsten  Rose's avatar Carsten Rose
Browse files

save.php: new API. Will be called by every save action

parent 654a8011
...@@ -6,4 +6,93 @@ ...@@ -6,4 +6,93 @@
* Time: 6:16 PM * Time: 6:16 PM
*/ */
echo 'Hello World'; namespace qfq;
\ No newline at end of file
use qfq;
require_once(__DIR__ . '/../qfq/QuickFormQuery.php');
require_once(__DIR__ . '/../qfq/store/Store.php');
/**
* Return JSON encoded answer
*
* status: success|error
* message: <message>
* redirect: client|url|no
* redirect-url: <url>
* field-name:<field name>
* field-message: <message>
*
* Description:
*
* Save successfull. Button 'close', 'new'. Form.forward: 'auto'. Client logic decide to redirect or not. Show message if no redirect.
* status = 'success'
* message = <message>
* redirect = 'client'
*
* Save successfull. Button 'close': Form.forward: 'page'. Client redirect to url.
* status = 'success'
* message = <message>
* redirect = 'url'
* redirect-url = <URL>
*
* Save failed: Button: any. Show message and set 'alert' on _optional_ specified form element. Bring 'pill' of specified form element to front.
* status = 'error'
* message = <message>
* redirect = 'no'
* Optional:
* field-name = <field name>
* field-message = <message appearing as tooltip (or similar) near the form element>
*/
const SAVE_STATUS = 'status';
const SAVE_MESSAGE = 'message';
const SAVE_REDIRECT = 'redirect';
const SAVE_REDIRECT_URL = 'redirect-url';
const SAVE_FIELD_NAME = 'field-name';
const SAVE_FIELD_MESSAGE = 'field-message';
const ANSWER_STATUS_SUCCESS = 'succes';
const ANSWER_STATUS_ERROR = 'error';
const ANSWER_REDIRECT_CLIENT = 'client';
const ANSWER_REDIRECT_NO = 'no';
const ANSWER_REDIRECT_URL = 'url';
$answer = array();
$answer[SAVE_STATUS] = 'error';
$answer[SAVE_MESSAGE] = '';
$answer[SAVE_REDIRECT] = 'client';
try {
$qfq = new \qfq\QuickFormQuery(['bodytext' => "debugShowStack=1"]);
$qfq->saveForm();
$answer[SAVE_REDIRECT] = $qfq->getForwardMode($answer[SAVE_REDIRECT_URL]);
$answer[SAVE_MESSAGE] = 'save: success';
$answer[SAVE_STATUS] = ANSWER_STATUS_SUCCESS;
} catch (qfq\UserException $e) {
$answer[SAVE_MESSAGE] = $e->formatMessage();
$val = Store::getVar(SYSTEM_FORM_ELEMENT, STORE_SYSTEM);
if ($val !== false)
$answer[SAVE_FIELD_NAME] =
$val = Store::getVar(SYSTEM_FORM_ELEMENT_MESSAGE, STORE_SYSTEM);
if ($val !== false)
$answer[SAVE_FIELD_MESSAGE] = $val;
} catch (qfq\CodeException $e) {
$answer[SAVE_MESSAGE] = $e->formatMessage();
} catch (qfq\DbException $e) {
$answer[SAVE_MESSAGE] = $e->formatMessage();
} catch (\Exception $e) {
$answer[SAVE_MESSAGE] = "Generic Exception: " . $e->getMessage();
}
echo json_encode($answer);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment