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

#3773 / Button: Info / Unlock / ShowPassword

Implemented Checkbox
parent df6c448f
......@@ -81,46 +81,46 @@ abstract class AbstractBuildForm {
$this->fillWrap();
$this->buildElementFunctionName = [
'checkbox' => 'Checkbox',
'date' => 'DateTime',
'datetime' => 'DateTime',
FE_TYPE_CHECKBOX => 'Checkbox',
FE_TYPE_DATE => 'DateTime',
FE_TYPE_DATETIME => 'DateTime',
'dateJQW' => 'DateJQW',
'datetimeJQW' => 'DateJQW',
'email' => 'Input',
'gridJQW' => 'GridJQW',
FE_TYPE_EXTRA => 'Extra',
'text' => 'Input',
'editor' => 'Editor',
'time' => 'DateTime',
'note' => 'Note',
'password' => 'Input',
'radio' => 'Radio',
'select' => 'Select',
'subrecord' => 'Subrecord',
'upload' => 'File',
FE_TYPE_TEXT => 'Input',
FE_TYPE_EDITOR => 'Editor',
FE_TYPE_TIME => 'DateTime',
FE_TYPE_NOTE => 'Note',
FE_TYPE_PASSWORD => 'Input',
FE_TYPE_RADIO => 'Radio',
FE_TYPE_SELECT => 'Select',
FE_TYPE_SUBRECORD => 'Subrecord',
FE_TYPE_UPLOAD => 'File',
'fieldset' => 'Fieldset',
'pill' => 'Pill',
'templateGroup' => 'TemplateGroup'
];
$this->buildRowName = [
'checkbox' => 'Native',
'date' => 'Native',
'datetime' => 'Native',
FE_TYPE_CHECKBOX => 'Native',
FE_TYPE_DATE => 'Native',
FE_TYPE_DATETIME => 'Native',
'dateJQW' => 'Native',
'datetimeJQW' => 'Native',
'email' => 'Native',
'gridJQW' => 'Native',
FE_TYPE_EXTRA => 'Native',
'text' => 'Native',
'editor' => 'Native',
'time' => 'Native',
'note' => 'Native',
'password' => 'Native',
'radio' => 'Native',
'select' => 'Native',
'subrecord' => 'Subrecord',
'upload' => 'Native',
FE_TYPE_TEXT => 'Native',
FE_TYPE_EDITOR => 'Native',
FE_TYPE_TIME => 'Native',
FE_TYPE_NOTE => 'Native',
FE_TYPE_PASSWORD => 'Native',
FE_TYPE_RADIO => 'Native',
FE_TYPE_SELECT => 'Native',
FE_TYPE_SUBRECORD => 'Subrecord',
FE_TYPE_UPLOAD => 'Native',
'fieldset' => 'Fieldset',
'pill' => 'Pill',
'templateGroup' => 'TemplateGroup'
......@@ -894,17 +894,16 @@ abstract class AbstractBuildForm {
// Check for input type 'textarea'.
$colsRows = explode(',', $formElement['size'], 2);
$inputTypeTextarea = (count($colsRows) === 2);
$flagTextarea = (count($colsRows) === 2);
$formElement = $this->inputExtraButton($formElement, $inputTypeTextarea, $extraButton);
if ($inputTypeTextarea) {
$formElement = HelperFormElement::prepareExtraButton($formElement, !$flagTextarea, $extraButton);
if ($flagTextarea) {
// <textarea>
$htmlTag = '<textarea';
$attribute .= Support::doAttribute('cols', $colsRows[0]);
$attribute .= Support::doAttribute('rows', $colsRows[1]);
$textarea = htmlentities($value) . '</textarea>';
} else {
$htmlTag = '<input';
$attribute .= $this->getAttributeList($formElement, ['type', 'size']);
......@@ -925,7 +924,7 @@ abstract class AbstractBuildForm {
if ($extraButton !== '') {
if ($inputTypeTextarea) {
if ($flagTextarea) {
$input .= $extraButton;
} else {
$input = Support::wrapTag('<div class="input-group">', $input . $extraButton);
......@@ -934,98 +933,14 @@ abstract class AbstractBuildForm {
$input .= $elementCharacterCount;
if ($extraButton !== '') {
if (!empty($formElement[FE_INPUT_EXTRA_BUTTON_INFO])) {
$input .= $formElement[FE_INPUT_EXTRA_BUTTON_INFO];
}
if (isset($formElement[FE_INPUT_EXTRA_BUTTON_INFO])) {
$input .= $formElement[FE_INPUT_EXTRA_BUTTON_INFO];
}
return $input;
}
/**
* @param array $formElement
* @param bool $inputTypeTextarea
* @param string $rcExtraButton
* @return array
*/
private function inputExtraButton(array $formElement, $inputTypeTextarea, &$rcExtraButton) {
if (!($formElement[FE_MODE] == FE_MODE_SHOW || $formElement[FE_MODE] == FE_MODE_REQUIRED)) {
return $formElement;
}
$rcExtraButton = '';
$id = $formElement[FE_HTML_ID];
// LOCK
if (isset($formElement[FE_INPUT_EXTRA_BUTTON_LOCK])) {
$formElement[FE_MODE] = FE_MODE_READONLY;
$rcExtraButton .= <<<EOF
<div class="input-group-btn">
<button class="btn btn-success"
onclick="$('#$id').prop('readonly',!$('#$id').prop('readonly'))">
<span class="glyphicon glyphicon-lock" aria-hidden="true"></span>
</button>
</div>
EOF;
}
// PASSWORD
if (isset($formElement[FE_INPUT_EXTRA_BUTTON_PASSWORD])) {
$formElement[FE_TYPE] = 'password';
$rcExtraButton .= <<<EOF
<div class="input-group-btn">
<button class="btn btn-info"
onclick="$('#$id').attr('type',$('#$id').attr('type')==='password' ? 'text': 'password')">
<span class="glyphicon glyphicon-eye-close" aria-hidden="true"></span>
</button>
</div>
EOF;
}
// INFO: regular 'input'
if (isset($formElement[FE_INPUT_EXTRA_BUTTON_INFO]) && !$inputTypeTextarea) {
$rcExtraButton .= <<<EOF
<div class="input-group-btn">
<button class="btn btn-info" onclick="$('#$id-extra-info').slideToggle('swing')">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
</button>
</div>
EOF;
$value = $formElement[FE_INPUT_EXTRA_BUTTON_INFO];
$formElement[FE_INPUT_EXTRA_BUTTON_INFO] = <<<EOF
<div class="alert alert-info" id="$id-extra-info" style="display: none;">
<p>$value</p>
</div>
EOF;
}
// INFO: 'textarea'
if (isset($formElement[FE_INPUT_EXTRA_BUTTON_INFO]) && $inputTypeTextarea) {
$rcExtraButton .= <<<EOF
<span class="glyphicon glyphicon-info-sign text-info" aria-hidden="true" onclick="$('#$id-extra-info').slideToggle('swing')"></span>
EOF;
$value = $formElement[FE_INPUT_EXTRA_BUTTON_INFO];
$formElement[FE_INPUT_EXTRA_BUTTON_INFO] = <<<EOF
<div class="alert alert-info" id="$id-extra-info" style="display: none;">
<p>$value</p>
</div>
EOF;
}
return $formElement;
}
/**
* Check $formElement for FE_TYPE_AHEAD_SQL or FE_TYPE_AHEAD_LDAP_SERVER.
* If one of them is given: build $urlParam with typeAhead Params.
......@@ -1380,7 +1295,7 @@ EOF;
throw new UserFormException('checkBoxMode: \'' . $formElement['checkBoxMode'] . '\' is unknown.', ERROR_CHECKBOXMODE_UNKNOWN);
}
return $html . $this->getHelpBlock();
return $html . $this->getHelpBlock() . HelperFormElement::buildExtraButton($formElement);
}
/**
......@@ -1929,7 +1844,7 @@ EOF;
$html = $this->constructRadioPlain($formElement, $htmlFormElementName, $value, $json, $mode);
}
return $html . $this->getHelpBlock();
return $html . $this->getHelpBlock() . HelperFormElement::buildExtraButton($formElement);
}
/**
......@@ -2163,7 +2078,7 @@ EOF;
$json = $this->getFormElementForJson($htmlFormElementName, $jsonValues, $formElement);
return '<select ' . $attribute . '>' . $option . '</select>' . $this->getHelpBlock();
return '<select ' . $attribute . '>' . $option . '</select>' . $this->getHelpBlock() . HelperFormElement::buildExtraButton($formElement);
}
/**
......@@ -2890,7 +2805,7 @@ EOF;
$element = Support::wrapTag("<textarea $attribute>", htmlentities($value), false);
return $element . $this->getHelpBlock();
return $element . $this->getHelpBlock() . HelperFormElement::buildExtraButton($formElement);
}
/**
......
......@@ -692,7 +692,6 @@ const FE_PARAMETER = 'parameter';
const FE_ENCODE = 'encode';
const FE_CHECK_TYPE = 'checkType';
const FE_CHECK_PATTERN = 'checkPattern';
const FE_TYPE_CHECKBOX = 'checkbox';
// FormElement columns: via parameter field
const FE_DATE_FORMAT = 'dateFormat'; // value: FORMAT_DATE_INTERNATIONAL | FORMAT_DATE_GERMAN
......@@ -780,11 +779,21 @@ const FE_ENCODE_NONE = 'none';
const FE_FILE_CAPTURE_CAMERA = 'camera';
// FormElement Types
const FE_TYPE_CHECKBOX = 'checkbox';
const FE_TYPE_DATE = 'date';
const FE_TYPE_TIME = 'time';
const FE_TYPE_DATETIME = 'datetime';
const FE_TYPE_TEXT = 'text';
const FE_TYPE_EDITOR = 'editor';
const FE_TYPE_PASSWORD = 'password';
const FE_TYPE_RADIO = 'radio';
const FE_TYPE_SELECT = 'select';
const FE_TYPE_UPLOAD = 'upload';
const FE_TYPE_EXTRA = 'extra';
const FE_TYPE_SUBRECORD = 'subrecord';
const FE_TYPE_NOTE = 'note';
const FE_TYPE_SENDMAIL = 'sendMail';
const FE_TYPE_BEFORE_LOAD = 'beforeLoad';
const FE_TYPE_BEFORE_SAVE = 'beforeSave';
......
......@@ -199,4 +199,125 @@ class HelperFormElement {
return $fe;
}
/**
* @param array $formElement
* @return string
* @throws CodeException
*/
public static function buildExtraButton(array $formElement) {
$inline = true;
switch ($formElement[FE_TYPE]) {
case FE_TYPE_CHECKBOX:
case FE_TYPE_EDITOR:
case FE_TYPE_RADIO:
case FE_TYPE_UPLOAD:
$inline = false;
break;
default:
return '';
}
$extraButton = '';
$formElement = self::prepareExtraButton($formElement, $inline, $extraButton);
$info = isset($formElement[FE_INPUT_EXTRA_BUTTON_INFO]) ? $formElement[FE_INPUT_EXTRA_BUTTON_INFO] : '';
return $extraButton . $info;
}
/**
* Prepare code of 'lock', 'password', 'info' to extend a FormElement.
* The 'info' will always be added, 'lock' and 'password' only on FE with mode=show|required
* Depending on $showInside:
* * true: a button is shown inside the 'input' or 'select' element.
* * false: an icon is shown below the FormElement.
*
* 'Add' means:
* * $rcButton contains all HTML button code. The calling function is responsible to build the correct code.
* * $formElement[FE_INPUT_EXTRA_BUTTON_INFO] has been wrapped with HTML-tag and HTML-id.
* * $formElement[FE_MODE] - for 'lock' it will be faked to 'readonly'
* * $formElement[FE_TYPE] - for 'password' it will be faked to 'password'
*
* @param array $formElement
* @param bool $showInline
* @param string $rcExtraButton
* @return array
*/
public static function prepareExtraButton(array $formElement, $showInline, &$rcExtraButton) {
$rcExtraButton = '';
$id = $formElement[FE_HTML_ID];
// INFO: $showinline =- TRUE ('input' elemente)
if (isset($formElement[FE_INPUT_EXTRA_BUTTON_INFO]) && $showInline) {
$rcExtraButton .= <<<EOF
<div class="input-group-btn">
<button class="btn btn-info" onclick="$('#$id-extra-info').slideToggle('swing')">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
</button>
</div>
EOF;
$value = $formElement[FE_INPUT_EXTRA_BUTTON_INFO];
$formElement[FE_INPUT_EXTRA_BUTTON_INFO] = <<<EOF
<div class="alert alert-info" id="$id-extra-info" style="display: none;">
<p>$value</p>
</div>
EOF;
}
// INFO: $showinline == FALSE (z.B. 'textarea' elemente)
if (isset($formElement[FE_INPUT_EXTRA_BUTTON_INFO]) && !$showInline) {
$rcExtraButton .= <<<EOF
<span class="glyphicon glyphicon-info-sign text-info" aria-hidden="true" onclick="$('#$id-extra-info').slideToggle('swing')"></span>
EOF;
$value = $formElement[FE_INPUT_EXTRA_BUTTON_INFO];
$formElement[FE_INPUT_EXTRA_BUTTON_INFO] = <<<EOF
<div class="alert alert-info" id="$id-extra-info" style="display: none;">
<p>$value</p>
</div>
EOF;
}
// Check if remaining 'lock' and 'password' buttons appliable
if (!($formElement[FE_MODE] == FE_MODE_SHOW || $formElement[FE_MODE] == FE_MODE_REQUIRED)) {
return $formElement;
}
// LOCK
if (isset($formElement[FE_INPUT_EXTRA_BUTTON_LOCK])) {
$formElement[FE_MODE] = FE_MODE_READONLY;
$rcExtraButton .= <<<EOF
<div class="input-group-btn">
<button class="btn btn-info"
onclick="$('#$id').prop('readonly',!$('#$id').prop('readonly'))">
<span class="glyphicon glyphicon-lock" aria-hidden="true"></span>
</button>
</div>
EOF;
}
// PASSWORD
if (isset($formElement[FE_INPUT_EXTRA_BUTTON_PASSWORD])) {
$formElement[FE_TYPE] = 'password';
$rcExtraButton .= <<<EOF
<div class="input-group-btn">
<button class="btn btn-info"
onclick="$('#$id').attr('type',$('#$id').attr('type')==='password' ? 'text': 'password')">
<span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span>
</button>
</div>
EOF;
}
return $formElement;
}
}
\ No newline at end of file
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