Commit 75846ed4 authored by Rafael Ostertag's avatar Rafael Ostertag
Browse files

Merge remote-tracking branch 'origin/crose_work' into raos_work

parents d46d4110 8afc4275
API: Client / Server
====================
Form initial call
-----------------
Request: index.php (QuickFormQuery.php, included by Typo3 extension)
Response:
Form attributes:
data-hidden: 'yes'|'no' - yes: The element is not visible yet, maybe later.
data-disabled: 'yes'|'no' - yes: The element is visible, but the user can't interact with it.
data-required: 'yes'|'no' - yes: The element is required. The form can't be submitted if any required element is empty.
General
-------
Asynchronous request (read AJAX) initiated by the client receive a JSON Response from the server containing at least:
{
"status": "success"|"error",
"message": "<message>"
}
`status` indicates whether or not the request has been fullfiled by the server (`"success"`) or encountered an error (`"error"`).
On `"error"` the client must display `"<message>"` to the user. On `"success"`, the client may display `"<message>"` to the user.
Form load (update)
------------------
### Trigger
Form Element with attribute `data-load="data-load"`.
The client side JavaScript installs on change handlers for all HTML Form Elements having the `data-load` attribute.
### Request: api/load.php
#### Type
POST
#### Parameters
##### URL
none
##### POST
HTML Form without `<input>` elements of type `file`. The HTML Form is required to have a HTML Form Element named `s`, which must contain the SIP.
### Response
JSON Stream
{
"status": "success"|"error",
"message": "<message>",
"redirect": "client"|"url"|"no",
"field-name": "<field name>",
"field-message": "<message>",
"form-update": [
{
"form-element": "<element_name>",
"hidden": true | false,
"disabled": true | false,
"required": true | false,
"value": <value>
}
]
}
Name | Description
------- | -----------
status | see General
message | see General
redirect | not used
field-name | HTML Form Element Name which raised error on server side. Requires status to be `"error"`
field-message | reason of error. Requires status to be `"error"`.
form-update | Array of Objects. Each object describes the state and value of a HTML Form Element identfied by its `name` attribute.
Form save
---------
### Trigger
none
### Request: api/save.php
#### Type
POST
#### Parameters
##### URL
none
##### POST
HTML Form without `<input>` elements of type `file`. The HTML Form is required to have a HTML Form Element named `s`, which must contain the SIP.
### Response
JSON Stream
{
"status": "success"|"error",
"message": "<message>",
"redirect": "client"|"url"|"no",
"field-name": "<field name>",
"field-message": "<message>",
"form-update": [
{
"form-element": "<element_name>",
"hidden": true | false,
"disabled": true | false,
"required": true | false,
"value": <value>
}
]
}
Name | Description
------- | -----------
status | see General
message | see General
redirect | not used
field-name | HTML Form Element Name which raised error on server side. Requires status to be `"error"`
field-message | reason of error. Requires status to be `"error"`.
form-update | Array of Objects. Each object describes the state and value of a HTML Form Element identfied by its `name` attribute.
File (upload)
-------------
### Trigger
none
### Request: api/file.php
#### Type
POST
#### Parameters
##### URL
`action=upload`
##### POST
Multi part form with file content, parameter `s` containing SIP, and parameter `name` containing the name of the HTML Form Element.
### Response
JSON Stream
{
"status": "success"|"error",
"message": "<message>"
}
Name | Description
------- | -----------
status | see General
message | see General
Record delete
-------------
Request: api/delete.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:
Delete successfull.
status = 'success'
message = <message>
redirect = 'client'
Delete successfull.
status = 'success'
message = <message>
redirect = 'url'
redirect-url = <URL>
Delete failed: Show message.
status = 'error'
message = <message>
redirect = 'no'
Notes / Best Practices for Coding
=================================
Design / Notes / Best Practices for Coding
==========================================
General
=======
......@@ -88,6 +88,7 @@ Button status
Save Button
-----------
* User presses the button
* Reset all validation states
* Client validates HTML Form
......
......@@ -355,6 +355,9 @@ abstract class AbstractBuildForm {
// Some Defaults
$formElement = Support::setFeDefaults($formElement);
Support::setIfNotSet($formElement, F_BS_LABEL_COLUMNS);
Support::setIfNotSet($formElement, F_BS_INPUT_COLUMNS);
Support::setIfNotSet($formElement, F_BS_NOTE_COLUMNS);
$label = ($formElement[F_BS_LABEL_COLUMNS] == '') ? $this->formSpec[F_BS_LABEL_COLUMNS] : $formElement[F_BS_LABEL_COLUMNS];
$input = ($formElement[F_BS_INPUT_COLUMNS] == '') ? $this->formSpec[F_BS_INPUT_COLUMNS] : $formElement[F_BS_INPUT_COLUMNS];
$note = ($formElement[F_BS_NOTE_COLUMNS] == '') ? $this->formSpec[F_BS_NOTE_COLUMNS] : $formElement[F_BS_NOTE_COLUMNS];
......
......@@ -192,6 +192,10 @@ class Store {
$config[SYSTEM_PATH_EXT] = substr($_SERVER['SCRIPT_FILENAME'], 0, $pos + strlen($relExtDir));
$config[SYSTEM_SITE_PATH] = substr($_SERVER['SCRIPT_FILENAME'], 0, $pos);
}
} else {
// No $_SERVER >>this means phpUnit.
$config[SYSTEM_SITE_PATH] = getcwd();
$config[SYSTEM_PATH_EXT] = getcwd();
}
}
......
......@@ -97,33 +97,33 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
// Defaults
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => '', 'disabled' => false, 'readonly' => false], $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => ''], $json);
// CheckType
$formElement['checkType'] = SANITIZE_ALLOW_MIN_MAX;
$formElement['checkPattern'] = '1|10';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" min="1" max="10" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => '', 'disabled' => false, 'readonly' => false], $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" min="1" max="10" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false], $json);
$formElement['checkType'] = SANITIZE_ALLOW_PATTERN;
$formElement['checkPattern'] = '^[a-z]*$';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" pattern="^[a-z]*$" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => '', 'disabled' => false, 'readonly' => false], $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" pattern="^[a-z]*$" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false], $json);
$formElement['checkType'] = SANITIZE_ALLOW_DIGIT;
$formElement['checkPattern'] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" pattern="^[\d]*$" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => '', 'disabled' => false, 'readonly' => false], $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" pattern="^[\d]*$" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false], $json);
$formElement['checkType'] = SANITIZE_ALLOW_EMAIL;
$formElement['checkPattern'] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" pattern="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => '', 'disabled' => false, 'readonly' => false], $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" pattern="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false], $json);
$formElement['checkType'] = '';
$formElement['checkPattern'] = '';
......@@ -133,32 +133,32 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement['size'] = 40;
$formElement['maxLength'] = 40;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" size="40" maxlength="40" value="" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => '', 'disabled' => false, 'readonly' => false], $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" size="40" maxlength="40" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false], $json);
// maxlength bigger than physical spec:
$formElement['maxLength'] = 1000;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" size="40" maxlength="255" value="" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => '', 'disabled' => false, 'readonly' => false], $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" size="40" maxlength="255" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false], $json);
// Explicit: further
$formElement['tooltip'] = 'Nice Tooltip';
$formElement['placeholder'] = 'Please type a name';
$result = $build->buildInput($formElement, 'name:1', 'Hello World', $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" size="40" maxlength="255" value="Hello World" placeholder="Please type a name" title="Nice Tooltip" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false, 'readonly' => false], $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" size="40" maxlength="255" value="Hello World" placeholder="Please type a name" title="Nice Tooltip" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false], $json);
// textarea
$formElement['size'] = '40,10';
$result = $build->buildInput($formElement, 'name:1', 'Hello World', $json);
$this->assertEquals('<textarea name="name:1" class="form-control" cols="40" rows="10" placeholder="Please type a name" title="Nice Tooltip" >Hello World</textarea><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false, 'readonly' => false], $json);
$this->assertEquals('<textarea name="name:1" class="form-control" cols="40" rows="10" placeholder="Please type a name" title="Nice Tooltip" data-hidden="no" data-disabled="no" data-required="no" >Hello World</textarea><div class="help-block with-errors"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false], $json);
$formElement['size'] = ' 40 , 10 ';
$result = $build->buildInput($formElement, 'name:1', 'Hello World', $json);
$this->assertEquals('<textarea name="name:1" class="form-control" cols="40" rows="10" placeholder="Please type a name" title="Nice Tooltip" >Hello World</textarea><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false, 'readonly' => false], $json);
$this->assertEquals('<textarea name="name:1" class="form-control" cols="40" rows="10" placeholder="Please type a name" title="Nice Tooltip" data-hidden="no" data-disabled="no" data-required="no" >Hello World</textarea><div class="help-block with-errors"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false], $json);
}
private function setFormFormElement(array &$form, array &$formElement) {
......
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