Commit 98fefcce authored by Carsten  Rose's avatar Carsten Rose
Browse files

AbstractBuildForm.php: fixed 'checkbox' update (api/load.php) - raw values...

AbstractBuildForm.php: fixed 'checkbox' update (api/load.php) - raw values like 'yes', 'no', 'enabled', 'disabled' are not understandable by the client (delivered via JSON) and needs to be converted to true/false.
parent 26d66e71
...@@ -319,12 +319,16 @@ abstract class AbstractBuildForm { ...@@ -319,12 +319,16 @@ abstract class AbstractBuildForm {
* @param $recordId * @param $recordId
* @param string $filter FORM_ELEMENTS_NATIVE | FORM_ELEMENTS_SUBRECORD | FORM_ELEMENTS_NATIVE_SUBRECORD * @param string $filter FORM_ELEMENTS_NATIVE | FORM_ELEMENTS_SUBRECORD | FORM_ELEMENTS_NATIVE_SUBRECORD
* @param int $feIdContainer * @param int $feIdContainer
* @param array $json
* @param string $modeCollectFe
* @param bool $htmlElementNameIdZero
* @param string $storeUse
* @return string * @return string
* @throws CodeException * @throws CodeException
* @throws DbException * @throws DbException
* @throws \qfq\UserFormException * @throws \qfq\UserFormException
*/ */
public function elements($recordId, $filter = FORM_ELEMENTS_NATIVE, $feIdContainer = 0, &$json, public function elements($recordId, $filter = FORM_ELEMENTS_NATIVE, $feIdContainer = 0, array &$json,
$modeCollectFe = FLAG_DYNAMIC_UPDATE, $htmlElementNameIdZero = false, $storeUse = STORE_USE_DEFAULT) { $modeCollectFe = FLAG_DYNAMIC_UPDATE, $htmlElementNameIdZero = false, $storeUse = STORE_USE_DEFAULT) {
$html = ''; $html = '';
...@@ -417,12 +421,12 @@ abstract class AbstractBuildForm { ...@@ -417,12 +421,12 @@ abstract class AbstractBuildForm {
/** /**
* Create a hidden sip, based on latest STORE_SIP Values. Return complete HTML 'hidden' element. * Create a hidden sip, based on latest STORE_SIP Values. Return complete HTML 'hidden' element.
* *
* @param $json * @param array $json
* @return string <input type='hidden' name='s' value='<sip>'> * @return string <input type='hidden' name='s' value='<sip>'>
* @throws CodeException * @throws CodeException
* @throws \qfq\UserFormException * @throws \qfq\UserFormException
*/ */
public function buildHiddenSip(&$json) { public function buildHiddenSip(array &$json) {
$sipArray = $this->store->getStore(STORE_SIP); $sipArray = $this->store->getStore(STORE_SIP);
unset($sipArray[SIP_SIP]); unset($sipArray[SIP_SIP]);
unset($sipArray[SIP_URLPARAM]); unset($sipArray[SIP_URLPARAM]);
...@@ -444,12 +448,11 @@ abstract class AbstractBuildForm { ...@@ -444,12 +448,11 @@ abstract class AbstractBuildForm {
* @return array * @return array
*/ */
private function getJsonElementUpdate($htmlFormElementId, $value, $feMode) { private function getJsonElementUpdate($htmlFormElementId, $value, $feMode) {
$json = $this->getJsonFeMode($feMode); $json = $this->getJsonFeMode($feMode);
$json['form-element'] = $htmlFormElementId; $json['form-element'] = $htmlFormElementId;
$json['value'] = $value; $json['value'] = $value;
// $json['disabled'] = ($feMode === 'disabled');
// $json['readonly'] = ($feMode === 'readonly');
return $json; return $json;
} }
...@@ -570,10 +573,11 @@ abstract class AbstractBuildForm { ...@@ -570,10 +573,11 @@ abstract class AbstractBuildForm {
* @param array $formElement * @param array $formElement
* @param $htmlFormElementId * @param $htmlFormElementId
* @param $value * @param $value
* @param array $json
* @return string * @return string
* @throws UserFormException * @throws \qfq\UserFormException
*/ */
public function buildInput(array $formElement, $htmlFormElementId, $value, &$json) { public function buildInput(array $formElement, $htmlFormElementId, $value, array &$json) {
$textarea = ''; $textarea = '';
$attribute = Support::doAttribute('name', $htmlFormElementId); $attribute = Support::doAttribute('name', $htmlFormElementId);
...@@ -812,10 +816,12 @@ abstract class AbstractBuildForm { ...@@ -812,10 +816,12 @@ abstract class AbstractBuildForm {
* @param array $formElement * @param array $formElement
* @param $htmlFormElementId * @param $htmlFormElementId
* @param $value * @param $value
* @param array $json
* @return string * @return string
* @throws UserFormException * @throws CodeException
* @throws \qfq\UserFormException
*/ */
public function buildCheckbox(array $formElement, $htmlFormElementId, $value, &$json) { public function buildCheckbox(array $formElement, $htmlFormElementId, $value, array &$json) {
$itemKey = array(); $itemKey = array();
$itemValue = array(); $itemValue = array();
...@@ -840,17 +846,15 @@ abstract class AbstractBuildForm { ...@@ -840,17 +846,15 @@ abstract class AbstractBuildForm {
switch ($formElement['checkBoxMode']) { switch ($formElement['checkBoxMode']) {
case 'single': case 'single':
$html = $this->buildCheckboxSingle($formElement, $htmlFormElementId, $attributeBase, $value); $html = $this->buildCheckboxSingle($formElement, $htmlFormElementId, $attributeBase, $value, $json);
break; break;
case 'multi'; case 'multi';
$html = $this->buildCheckboxMulti($formElement, $htmlFormElementId, $attributeBase, $value, $itemKey, $itemValue); $html = $this->buildCheckboxMulti($formElement, $htmlFormElementId, $attributeBase, $value, $itemKey, $itemValue, $json);
break; break;
default: default:
throw new UserFormException('checkBoxMode: \'' . $formElement['checkBoxMode'] . '\' is unknown.', ERROR_CHECKBOXMODE_UNKNOWN); throw new UserFormException('checkBoxMode: \'' . $formElement['checkBoxMode'] . '\' is unknown.', ERROR_CHECKBOXMODE_UNKNOWN);
} }
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement[FE_MODE]);
// return Support::wrapTag('<div class="checkbox">', $html, true);
return $html; return $html;
} }
...@@ -1016,10 +1020,12 @@ abstract class AbstractBuildForm { ...@@ -1016,10 +1020,12 @@ abstract class AbstractBuildForm {
* @param $htmlFormElementId * @param $htmlFormElementId
* @param $attribute * @param $attribute
* @param $value * @param $value
* @param array $json
* @return string * @return string
*/ */
public function buildCheckboxSingle(array $formElement, $htmlFormElementId, $attribute, $value) { public function buildCheckboxSingle(array $formElement, $htmlFormElementId, $attribute, $value, array &$json) {
$html = ''; $html = '';
$valueJson = false;
$attribute .= Support::doAttribute('name', $htmlFormElementId); $attribute .= Support::doAttribute('name', $htmlFormElementId);
$attribute .= Support::doAttribute('value', $formElement['checked'], false); $attribute .= Support::doAttribute('value', $formElement['checked'], false);
...@@ -1028,6 +1034,7 @@ abstract class AbstractBuildForm { ...@@ -1028,6 +1034,7 @@ abstract class AbstractBuildForm {
if ($formElement['checked'] === $value) { if ($formElement['checked'] === $value) {
$attribute .= Support::doAttribute('checked', 'checked'); $attribute .= Support::doAttribute('checked', 'checked');
$valueJson = true;
} }
$attribute .= $this->getAttributeList($formElement, ['autofocus']); $attribute .= $this->getAttributeList($formElement, ['autofocus']);
...@@ -1042,6 +1049,8 @@ abstract class AbstractBuildForm { ...@@ -1042,6 +1049,8 @@ abstract class AbstractBuildForm {
$html = Support::wrapTag("<label>", $html, true); $html = Support::wrapTag("<label>", $html, true);
$html = Support::wrapTag("<div class='checkbox'>", $html, true); $html = Support::wrapTag("<div class='checkbox'>", $html, true);
$json = $this->getJsonElementUpdate($htmlFormElementId, $valueJson, $formElement[FE_MODE]);
return $html; return $html;
} }
...@@ -1057,9 +1066,10 @@ abstract class AbstractBuildForm { ...@@ -1057,9 +1066,10 @@ abstract class AbstractBuildForm {
* @param $value * @param $value
* @param array $itemKey * @param array $itemKey
* @param array $itemValue * @param array $itemValue
* @param array $json
* @return string * @return string
*/ */
public function buildCheckboxMulti(array $formElement, $htmlFormElementId, $attributeBase, $value, array $itemKey, array $itemValue) { public function buildCheckboxMulti(array $formElement, $htmlFormElementId, $attributeBase, $value, array $itemKey, array $itemValue, array &$json) {
// Defines which of the checkboxes will be checked. // Defines which of the checkboxes will be checked.
$values = explode(',', $value); $values = explode(',', $value);
...@@ -1075,7 +1085,7 @@ abstract class AbstractBuildForm { ...@@ -1075,7 +1085,7 @@ abstract class AbstractBuildForm {
$flagFirst = true; $flagFirst = true;
for ($ii = 0, $jj = 1; $ii < count($itemKey); $ii++, $jj++) { for ($ii = 0, $jj = 1; $ii < count($itemKey); $ii++, $jj++) {
$jsonValue = false;
$attribute = $attributeBase; $attribute = $attributeBase;
// Do this only the first round. // Do this only the first round.
...@@ -1090,6 +1100,7 @@ abstract class AbstractBuildForm { ...@@ -1090,6 +1100,7 @@ abstract class AbstractBuildForm {
// Check if the given key is found in field. // Check if the given key is found in field.
if (false !== array_search($itemKey[$ii], $values)) { if (false !== array_search($itemKey[$ii], $values)) {
$attribute .= Support::doAttribute('checked', 'checked'); $attribute .= Support::doAttribute('checked', 'checked');
$jsonValue = true;
} }
// '&nbsp;' - This is necessary to correctly align an empty input. // '&nbsp;' - This is necessary to correctly align an empty input.
...@@ -1118,6 +1129,8 @@ abstract class AbstractBuildForm { ...@@ -1118,6 +1129,8 @@ abstract class AbstractBuildForm {
} }
$html .= $htmlElement . $br; $html .= $htmlElement . $br;
$json[] = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement[FE_MODE]);
} }
// if (isset($formElement[CHECKBOX_ORIENTATION]) && $formElement[CHECKBOX_ORIENTATION] !== 'vertical') // if (isset($formElement[CHECKBOX_ORIENTATION]) && $formElement[CHECKBOX_ORIENTATION] !== 'vertical')
...@@ -1135,9 +1148,12 @@ abstract class AbstractBuildForm { ...@@ -1135,9 +1148,12 @@ abstract class AbstractBuildForm {
* @param array $formElement * @param array $formElement
* @param $htmlFormElementId * @param $htmlFormElementId
* @param $value * @param $value
* @param array $json
* @return string * @return string
* @throws CodeException
* @throws \qfq\UserFormException
*/ */
public function buildHidden(array $formElement, $htmlFormElementId, $value, &$json) { public function buildHidden(array $formElement, $htmlFormElementId, $value, array &$json) {
$this->store->setVar($htmlFormElementId, $value, STORE_SIP, false); $this->store->setVar($htmlFormElementId, $value, STORE_SIP, false);
} }
...@@ -1154,10 +1170,12 @@ abstract class AbstractBuildForm { ...@@ -1154,10 +1170,12 @@ abstract class AbstractBuildForm {
* @param array $formElement * @param array $formElement
* @param $htmlFormElementId * @param $htmlFormElementId
* @param $value * @param $value
* @param array $json
* @return string * @return string
* @throws UserFormException * @throws CodeException
* @throws \qfq\UserFormException
*/ */
public function buildRadio(array $formElement, $htmlFormElementId, $value, &$json) { public function buildRadio(array $formElement, $htmlFormElementId, $value, array &$json) {
$itemKey = array(); $itemKey = array();
$itemValue = array(); $itemValue = array();
...@@ -1229,9 +1247,12 @@ abstract class AbstractBuildForm { ...@@ -1229,9 +1247,12 @@ abstract class AbstractBuildForm {
* @param array $formElement * @param array $formElement
* @param $htmlFormElementId * @param $htmlFormElementId
* @param $value * @param $value
* @param array $json
* @return mixed * @return mixed
* @throws CodeException
* @throws \qfq\UserFormException
*/ */
public function buildSelect(array $formElement, $htmlFormElementId, $value, &$json) { public function buildSelect(array $formElement, $htmlFormElementId, $value, array &$json) {
$itemKey = array(); $itemKey = array();
$itemValue = array(); $itemValue = array();
...@@ -1284,10 +1305,12 @@ abstract class AbstractBuildForm { ...@@ -1284,10 +1305,12 @@ abstract class AbstractBuildForm {
* @param array $formElement * @param array $formElement
* @param $htmlFormElementId * @param $htmlFormElementId
* @param $value * @param $value
* @param array $json
* @return string * @return string
* @throws UserFormException * @throws CodeException
* @throws \qfq\UserFormException
*/ */
public function buildSubrecord(array $formElement, $htmlFormElementId, $value, &$json) { public function buildSubrecord(array $formElement, $htmlFormElementId, $value, array &$json) {
$rcText = false; $rcText = false;
$nameColumnId = 'id'; $nameColumnId = 'id';
$targetTableName = ''; $targetTableName = '';
...@@ -1626,10 +1649,12 @@ abstract class AbstractBuildForm { ...@@ -1626,10 +1649,12 @@ abstract class AbstractBuildForm {
* @param array $formElement * @param array $formElement
* @param $htmlFormElementId * @param $htmlFormElementId
* @param $value * @param $value
* @param array $json
* @return string * @return string
* @throws UserFormException * @throws CodeException
* @throws \qfq\UserFormException
*/ */
public function buildFile(array $formElement, $htmlFormElementId, $value, &$json) { public function buildFile(array $formElement, $htmlFormElementId, $value, array &$json) {
$attribute = ''; $attribute = '';
$arr = array(); $arr = array();
...@@ -1686,10 +1711,11 @@ abstract class AbstractBuildForm { ...@@ -1686,10 +1711,11 @@ abstract class AbstractBuildForm {
* @param array $formElement * @param array $formElement
* @param $htmlFormElementId * @param $htmlFormElementId
* @param $value * @param $value
* @param array $json
* @return string * @return string
* @throws UserFormException * @throws \qfq\UserFormException
*/ */
public function builddateJQW(array $formElement, $htmlFormElementId, $value, &$json) { public function builddateJQW(array $formElement, $htmlFormElementId, $value, array &$json) {
$textarea = ''; $textarea = '';
$attribute = Support::doAttribute('name', $htmlFormElementId); $attribute = Support::doAttribute('name', $htmlFormElementId);
...@@ -1739,11 +1765,11 @@ abstract class AbstractBuildForm { ...@@ -1739,11 +1765,11 @@ abstract class AbstractBuildForm {
* @param array $formElement * @param array $formElement
* @param $htmlFormElementId * @param $htmlFormElementId
* @param $value * @param $value
* @param $json * @param array $json
* @return string * @return string
* @throws UserFormException * @throws UserFormException
*/ */
public function buildDateTime(array $formElement, $htmlFormElementId, $value, &$json) { public function buildDateTime(array $formElement, $htmlFormElementId, $value, array &$json) {
$attribute = Support::doAttribute('name', $htmlFormElementId); $attribute = Support::doAttribute('name', $htmlFormElementId);
$attribute .= Support::doAttribute('class', 'form-control'); $attribute .= Support::doAttribute('class', 'form-control');
...@@ -1848,9 +1874,10 @@ abstract class AbstractBuildForm { ...@@ -1848,9 +1874,10 @@ abstract class AbstractBuildForm {
* @param array $formElement * @param array $formElement
* @param $htmlFormElementId * @param $htmlFormElementId
* @param $value * @param $value
* @param array $json
* @return mixed * @return mixed
*/ */
public function buildNote(array $formElement, $htmlFormElementId, $value, &$json) { public function buildNote(array $formElement, $htmlFormElementId, $value, array &$json) {
return $value; return $value;
} }
...@@ -1860,9 +1887,10 @@ abstract class AbstractBuildForm { ...@@ -1860,9 +1887,10 @@ abstract class AbstractBuildForm {
* @param array $formElement * @param array $formElement
* @param $htmlFormElementId * @param $htmlFormElementId
* @param $value * @param $value
* @param array $json
* @return mixed * @return mixed
*/ */
public function buildPill(array $formElement, $htmlFormElementId, $value, &$json) { public function buildPill(array $formElement, $htmlFormElementId, $value, array &$json) {
return $value; return $value;
} }
...@@ -1872,9 +1900,12 @@ abstract class AbstractBuildForm { ...@@ -1872,9 +1900,12 @@ abstract class AbstractBuildForm {
* @param array $formElement * @param array $formElement
* @param $htmlFormElementId * @param $htmlFormElementId
* @param $value * @param $value
* @param array $json
* @return mixed * @return mixed
* @throws CodeException
* @throws DbException
*/ */
public function buildFieldset(array $formElement, $htmlFormElementId, $value, &$json) { public function buildFieldset(array $formElement, $htmlFormElementId, $value, array &$json) {
$attribute = ''; $attribute = '';
// save parent processed FE's // save parent processed FE's
......
Markdown is supported
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