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

Support.php, AbstractBuildForm.php, BuildFormBootstrap.hp, BuildFormTable.php:...

Support.php, AbstractBuildForm.php, BuildFormBootstrap.hp, BuildFormTable.php: refactored doAtrribute() from AbstractBuildForm to Support.
parent 1e4480b0
......@@ -160,7 +160,7 @@ abstract class AbstractBuildForm {
public function head() {
$html = '';
$html .= '<div ' . $this->doAttribute('class', $this->formSpec['class'], TRUE) . '>'; // main <div class=...> around everything
$html .= '<div ' . Support::doAttribute('class', $this->formSpec['class'], TRUE) . '>'; // main <div class=...> around everything
// Logged in BE User will see a FormEdit Link
$sipParamString = OnArray::toString($this->store->getStore(STORE_SIP), ':', ', ', "'");
......@@ -175,21 +175,6 @@ abstract class AbstractBuildForm {
return $html;
}
/**
* Format's an attribute: $type=$value. If $flagOmitEmpty==true && $value=='': return ''.
*
* @param $type
* @param $value
* @param bool|false $flagOmitEmpty
* @return string
*/
public function doAttribute($type, $value, $flagOmitEmpty = true) {
if ($flagOmitEmpty && $value === "")
return '';
return $type . '="' . trim($value) . '" ';
}
/**
* If SHOW_DEBUG_INFO=yes: create a link (incl. SIP) to edit the current form. Show also the hidden content of the SIP.
*
......@@ -446,7 +431,7 @@ abstract class AbstractBuildForm {
public function buildInput(array $formElement, $htmlFormElementId, $value, &$json) {
$textarea = '';
$attribute = $this->doAttribute('name', $htmlFormElementId);
$attribute = Support::doAttribute('name', $htmlFormElementId);
// Check for input type 'textarea'
$colsRows = explode(',', $formElement['size'], 2);
......@@ -454,8 +439,8 @@ abstract class AbstractBuildForm {
// <textarea>
$htmlTag = '<textarea';
$attribute .= $this->doAttribute('cols', $colsRows[0]);
$attribute .= $this->doAttribute('rows', $colsRows[1]);
$attribute .= Support::doAttribute('cols', $colsRows[0]);
$attribute .= Support::doAttribute('rows', $colsRows[1]);
$textarea = htmlentities($value) . '</textarea>';
} else {
......@@ -471,13 +456,13 @@ abstract class AbstractBuildForm {
// 'maxLength' needs an upper 'L': naming convention for DB tables!
$attribute .= $this->getAttributeList($formElement, ['type', 'size', 'maxLength']);
$attribute .= $this->doAttribute('value', htmlentities($value), false);
$attribute .= Support::doAttribute('value', htmlentities($value), false);
}
}
$attribute .= $this->getAttributeList($formElement, ['autocomplete', 'autofocus', 'placeholder']);
$attribute .= $this->doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$attribute .= $this->doAttribute('title', $formElement['tooltip']);
$attribute .= Support::doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute('title', $formElement['tooltip']);
$attribute .= $this->getInputCheckPattern($formElement['checkType'], $formElement['checkPattern']);
$attribute .= $this->getAttributeMode($formElement);
......@@ -541,7 +526,7 @@ abstract class AbstractBuildForm {
$attribute = '';
foreach ($attributeList as $item) {
if (isset($formElement[$item]))
$attribute .= $this->doAttribute(strtolower($item), $formElement[$item]);
$attribute .= Support::doAttribute(strtolower($item), $formElement[$item]);
}
return $attribute;
}
......@@ -611,15 +596,15 @@ abstract class AbstractBuildForm {
case 'show':
break;
case 'readonly':
$attribute .= $this->doAttribute('readonly', 'readonly');
$attribute .= Support::doAttribute('readonly', 'readonly');
break;
case 'required':
$attribute .= $this->doAttribute('required', 'required');
$attribute .= Support::doAttribute('required', 'required');
break;
case 'lock':
break;
case 'disabled':
$attribute .= $this->doAttribute('disabled', 'disabled');
$attribute .= Support::doAttribute('disabled', 'disabled');
break;
default:
$this->store->setVar(SYSTEM_FORM_ELEMENT, $formElement['name'] . ' / ' . $formElement['id'], STORE_SYSTEM);
......@@ -683,7 +668,7 @@ abstract class AbstractBuildForm {
}
$attributeBase = $this->getAttributeMode($formElement);
$attributeBase .= $this->doAttribute('type', $formElement['type']);
$attributeBase .= Support::doAttribute('type', $formElement['type']);
switch ($formElement['checkBoxMode']) {
case 'single':
......@@ -865,12 +850,12 @@ abstract class AbstractBuildForm {
public function buildCheckboxSingle(array $formElement, $htmlFormElementId, $attribute, $value) {
$html = '';
$attribute .= $this->doAttribute('name', $htmlFormElementId);
$attribute .= $this->doAttribute('value', $formElement['checked'], false);
$attribute .= $this->doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute('name', $htmlFormElementId);
$attribute .= Support::doAttribute('value', $formElement['checked'], false);
$attribute .= Support::doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
if ($formElement['checked'] === $value) {
$attribute .= $this->doAttribute('checked', 'checked');
$attribute .= Support::doAttribute('checked', 'checked');
}
$attribute .= $this->getAttributeList($formElement, ['autofocus']);
......@@ -917,8 +902,8 @@ abstract class AbstractBuildForm {
// Defines which of the checkboxes will be checked.
$values = explode(',', $value);
$attributeBase .= $this->doAttribute('name', $htmlFormElementId);
$attributeBase .= $this->doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$attributeBase .= Support::doAttribute('name', $htmlFormElementId);
$attributeBase .= Support::doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$html = $this->buildNativeHidden($htmlFormElementId, '');
......@@ -933,14 +918,14 @@ abstract class AbstractBuildForm {
if ($flagFirst) {
$flagFirst = false;
if (isset($formElement['autofocus']))
$attribute .= $this->doAttribute('autofocus', $formElement['autofocus']);
$attribute .= Support::doAttribute('autofocus', $formElement['autofocus']);
}
$attribute .= $this->doAttribute('value', $itemKey[$ii]);
$attribute .= Support::doAttribute('value', $itemKey[$ii]);
// Check if the given key is found in field.
if (false !== array_search($itemKey[$ii], $values)) {
$attribute .= $this->doAttribute('checked', 'checked');
$attribute .= Support::doAttribute('checked', 'checked');
}
$htmlCheckbox = '<input ' . $attribute . '>';
......@@ -998,9 +983,9 @@ abstract class AbstractBuildForm {
$this->getKeyValueListFromSqlEnumSpec($formElement, $itemKey, $itemValue);
$attributeBase = $this->getAttributeMode($formElement);
$attributeBase .= $this->doAttribute('name', $htmlFormElementId);
$attributeBase .= $this->doAttribute('type', $formElement['type']);
$attributeBase .= $this->doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$attributeBase .= Support::doAttribute('name', $htmlFormElementId);
$attributeBase .= Support::doAttribute('type', $formElement['type']);
$attributeBase .= Support::doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$jj = 0;
$flagFirst = true;
......@@ -1012,12 +997,12 @@ abstract class AbstractBuildForm {
if ($flagFirst) {
$flagFirst = false;
if (isset($formElement['autofocus']))
$attribute .= $this->doAttribute('autofocus', $formElement['autofocus']);
$attribute .= Support::doAttribute('autofocus', $formElement['autofocus']);
}
$attribute .= $this->doAttribute('value', $itemKey[$ii]);
$attribute .= Support::doAttribute('value', $itemKey[$ii]);
if ($itemKey[$ii] === $value) {
$attribute .= $this->doAttribute('checked', 'checked');
$attribute .= Support::doAttribute('checked', 'checked');
}
$element = '<input ' . $attribute . '>' . $itemValue[$ii];
......@@ -1057,13 +1042,13 @@ abstract class AbstractBuildForm {
$this->getKeyValueListFromSqlEnumSpec($formElement, $itemKey, $itemValue);
$attribute = $this->getAttributeMode($formElement);
$attribute .= $this->doAttribute('name', $htmlFormElementId);
$attribute .= Support::doAttribute('name', $htmlFormElementId);
$attribute .= $this->getAttributeList($formElement, ['autofocus']);
$attribute .= $this->doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
if (isset($formElement['size']) && $formElement['size'] > 1) {
$attribute .= $this->doAttribute('size', $formElement['size']);
$attribute .= $this->doAttribute('multiple', 'multiple');
$attribute .= Support::doAttribute('size', $formElement['size']);
$attribute .= Support::doAttribute('multiple', 'multiple');
}
$option = '';
......@@ -1072,7 +1057,7 @@ abstract class AbstractBuildForm {
for ($ii = 0; $ii < count($itemValue); $ii++) {
$option .= '<option ';
$option .= $this->doAttribute('value', $itemKey[$ii]);
$option .= Support::doAttribute('value', $itemKey[$ii]);
$jsonValues[] = [
'value' => $itemKey[$ii],
......@@ -1416,10 +1401,10 @@ abstract class AbstractBuildForm {
public function buildFile(array $formElement, $htmlFormElementId, $value, &$json) {
$attribute = $this->getAttributeMode($formElement);
$attribute .= $this->doAttribute('type', 'file');
$attribute .= $this->doAttribute('name', $htmlFormElementId);
$attribute .= Support::doAttribute('type', 'file');
$attribute .= Support::doAttribute('name', $htmlFormElementId);
$attribute .= $this->getAttributeList($formElement, ['autofocus', 'accept']);
$attribute .= $this->doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement['mode']);
......@@ -1490,8 +1475,8 @@ abstract class AbstractBuildForm {
// save parent processed FE's
$tmpStore = $this->feSpecNative;
$attribute .= $this->doAttribute('name', $htmlFormElementId);
$attribute .= $this->doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute('name', $htmlFormElementId);
$attribute .= Support::doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
// <fieldset>
$html = '<fieldset ' . $attribute . '>';
......
......@@ -94,7 +94,7 @@ class BuildFormBootstrap extends AbstractBuildForm {
public function head() {
$html = '';
$html .= '<div ' . $this->doAttribute('class', $this->formSpec['class'], TRUE) . '>'; // main <div class=...> around everything, Whole FORM; class="container" or class="container-fluid"
$html .= '<div ' . Support::doAttribute('class', $this->formSpec['class'], TRUE) . '>'; // main <div class=...> around everything, Whole FORM; class="container" or class="container-fluid"
$title = Support::wrapTag('<div class="hidden-xs col-sm-6 col-md-8">', Support::wrapTag('<h3>', $this->formSpec['title']));
$button = Support::wrapTag('<div class="col-xs-12 col-sm-6 col-md-4">', $this->buildButtons());
......
......@@ -67,7 +67,7 @@ class BuildFormTable extends AbstractBuildForm {
public function head() {
$html = '';
$html .= '<div ' . $this->doAttribute('class', $this->formSpec['class'], TRUE) . '>'; // main <div class=...> around everything
$html .= '<div ' . Support::doAttribute('class', $this->formSpec['class'], TRUE) . '>'; // main <div class=...> around everything
// Logged in BE User will see a FormEdit Link
$sipParamString = OnArray::toString($this->store->getStore(STORE_SIP), ':', ', ', "'");
......
......@@ -70,6 +70,21 @@ class Support {
return $tag . $value . $closing;
}
/**
* Format's an attribute: $type=$value. If $flagOmitEmpty==true && $value=='': return ''.
*
* @param $type
* @param $value
* @param bool|false $flagOmitEmpty
* @return string
*/
public static function doAttribute($type, $value, $flagOmitEmpty = true) {
if ($flagOmitEmpty && $value === "")
return '';
return $type . '="' . trim($value) . '" ';
}
/**
* Wraps some $inner fragment with a CSS styled $tooltipText . CSS is configured in 'Resources/Public/qfq-jqw.css'.
*
......
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