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 { ...@@ -81,46 +81,46 @@ abstract class AbstractBuildForm {
$this->fillWrap(); $this->fillWrap();
$this->buildElementFunctionName = [ $this->buildElementFunctionName = [
'checkbox' => 'Checkbox', FE_TYPE_CHECKBOX => 'Checkbox',
'date' => 'DateTime', FE_TYPE_DATE => 'DateTime',
'datetime' => 'DateTime', FE_TYPE_DATETIME => 'DateTime',
'dateJQW' => 'DateJQW', 'dateJQW' => 'DateJQW',
'datetimeJQW' => 'DateJQW', 'datetimeJQW' => 'DateJQW',
'email' => 'Input', 'email' => 'Input',
'gridJQW' => 'GridJQW', 'gridJQW' => 'GridJQW',
FE_TYPE_EXTRA => 'Extra', FE_TYPE_EXTRA => 'Extra',
'text' => 'Input', FE_TYPE_TEXT => 'Input',
'editor' => 'Editor', FE_TYPE_EDITOR => 'Editor',
'time' => 'DateTime', FE_TYPE_TIME => 'DateTime',
'note' => 'Note', FE_TYPE_NOTE => 'Note',
'password' => 'Input', FE_TYPE_PASSWORD => 'Input',
'radio' => 'Radio', FE_TYPE_RADIO => 'Radio',
'select' => 'Select', FE_TYPE_SELECT => 'Select',
'subrecord' => 'Subrecord', FE_TYPE_SUBRECORD => 'Subrecord',
'upload' => 'File', FE_TYPE_UPLOAD => 'File',
'fieldset' => 'Fieldset', 'fieldset' => 'Fieldset',
'pill' => 'Pill', 'pill' => 'Pill',
'templateGroup' => 'TemplateGroup' 'templateGroup' => 'TemplateGroup'
]; ];
$this->buildRowName = [ $this->buildRowName = [
'checkbox' => 'Native', FE_TYPE_CHECKBOX => 'Native',
'date' => 'Native', FE_TYPE_DATE => 'Native',
'datetime' => 'Native', FE_TYPE_DATETIME => 'Native',
'dateJQW' => 'Native', 'dateJQW' => 'Native',
'datetimeJQW' => 'Native', 'datetimeJQW' => 'Native',
'email' => 'Native', 'email' => 'Native',
'gridJQW' => 'Native', 'gridJQW' => 'Native',
FE_TYPE_EXTRA => 'Native', FE_TYPE_EXTRA => 'Native',
'text' => 'Native', FE_TYPE_TEXT => 'Native',
'editor' => 'Native', FE_TYPE_EDITOR => 'Native',
'time' => 'Native', FE_TYPE_TIME => 'Native',
'note' => 'Native', FE_TYPE_NOTE => 'Native',
'password' => 'Native', FE_TYPE_PASSWORD => 'Native',
'radio' => 'Native', FE_TYPE_RADIO => 'Native',
'select' => 'Native', FE_TYPE_SELECT => 'Native',
'subrecord' => 'Subrecord', FE_TYPE_SUBRECORD => 'Subrecord',
'upload' => 'Native', FE_TYPE_UPLOAD => 'Native',
'fieldset' => 'Fieldset', 'fieldset' => 'Fieldset',
'pill' => 'Pill', 'pill' => 'Pill',
'templateGroup' => 'TemplateGroup' 'templateGroup' => 'TemplateGroup'
...@@ -894,17 +894,16 @@ abstract class AbstractBuildForm { ...@@ -894,17 +894,16 @@ abstract class AbstractBuildForm {
// Check for input type 'textarea'. // Check for input type 'textarea'.
$colsRows = explode(',', $formElement['size'], 2); $colsRows = explode(',', $formElement['size'], 2);
$inputTypeTextarea = (count($colsRows) === 2); $flagTextarea = (count($colsRows) === 2);
$formElement = $this->inputExtraButton($formElement, $inputTypeTextarea, $extraButton); $formElement = HelperFormElement::prepareExtraButton($formElement, !$flagTextarea, $extraButton);
if ($inputTypeTextarea) { if ($flagTextarea) {
// <textarea> // <textarea>
$htmlTag = '<textarea'; $htmlTag = '<textarea';
$attribute .= Support::doAttribute('cols', $colsRows[0]); $attribute .= Support::doAttribute('cols', $colsRows[0]);
$attribute .= Support::doAttribute('rows', $colsRows[1]); $attribute .= Support::doAttribute('rows', $colsRows[1]);
$textarea = htmlentities($value) . '</textarea>'; $textarea = htmlentities($value) . '</textarea>';
} else { } else {
$htmlTag = '<input'; $htmlTag = '<input';
$attribute .= $this->getAttributeList($formElement, ['type', 'size']); $attribute .= $this->getAttributeList($formElement, ['type', 'size']);
...@@ -925,7 +924,7 @@ abstract class AbstractBuildForm { ...@@ -925,7 +924,7 @@ abstract class AbstractBuildForm {
if ($extraButton !== '') { if ($extraButton !== '') {
if ($inputTypeTextarea) { if ($flagTextarea) {
$input .= $extraButton; $input .= $extraButton;
} else { } else {
$input = Support::wrapTag('<div class="input-group">', $input . $extraButton); $input = Support::wrapTag('<div class="input-group">', $input . $extraButton);
...@@ -934,98 +933,14 @@ abstract class AbstractBuildForm { ...@@ -934,98 +933,14 @@ abstract class AbstractBuildForm {
$input .= $elementCharacterCount; $input .= $elementCharacterCount;
if ($extraButton !== '') { if (isset($formElement[FE_INPUT_EXTRA_BUTTON_INFO])) {
$input .= $formElement[FE_INPUT_EXTRA_BUTTON_INFO];
if (!empty($formElement[FE_INPUT_EXTRA_BUTTON_INFO])) {
$input .= $formElement[FE_INPUT_EXTRA_BUTTON_INFO];
}
} }
return $input; 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. * Check $formElement for FE_TYPE_AHEAD_SQL or FE_TYPE_AHEAD_LDAP_SERVER.
* If one of them is given: build $urlParam with typeAhead Params. * If one of them is given: build $urlParam with typeAhead Params.
...@@ -1380,7 +1295,7 @@ EOF; ...@@ -1380,7 +1295,7 @@ EOF;
throw new UserFormException('checkBoxMode: \'' . $formElement['checkBoxMode'] . '\' is unknown.', ERROR_CHECKBOXMODE_UNKNOWN); 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; ...@@ -1929,7 +1844,7 @@ EOF;
$html = $this->constructRadioPlain($formElement, $htmlFormElementName, $value, $json, $mode); $html = $this->constructRadioPlain($formElement, $htmlFormElementName, $value, $json, $mode);
} }
return $html . $this->getHelpBlock(); return $html . $this->getHelpBlock() . HelperFormElement::buildExtraButton($formElement);
} }
/** /**
...@@ -2163,7 +2078,7 @@ EOF; ...@@ -2163,7 +2078,7 @@ EOF;
$json = $this->getFormElementForJson($htmlFormElementName, $jsonValues, $formElement); $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; ...@@ -2890,7 +2805,7 @@ EOF;
$element = Support::wrapTag("<textarea $attribute>", htmlentities($value), false); $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'; ...@@ -692,7 +692,6 @@ const FE_PARAMETER = 'parameter';
const FE_ENCODE = 'encode'; const FE_ENCODE = 'encode';
const FE_CHECK_TYPE = 'checkType'; const FE_CHECK_TYPE = 'checkType';
const FE_CHECK_PATTERN = 'checkPattern'; const FE_CHECK_PATTERN = 'checkPattern';
const FE_TYPE_CHECKBOX = 'checkbox';
// FormElement columns: via parameter field // FormElement columns: via parameter field
const FE_DATE_FORMAT = 'dateFormat'; // value: FORMAT_DATE_INTERNATIONAL | FORMAT_DATE_GERMAN const FE_DATE_FORMAT = 'dateFormat'; // value: FORMAT_DATE_INTERNATIONAL | FORMAT_DATE_GERMAN
...@@ -780,11 +779,21 @@ const FE_ENCODE_NONE = 'none'; ...@@ -780,11 +779,21 @@ const FE_ENCODE_NONE = 'none';
const FE_FILE_CAPTURE_CAMERA = 'camera'; const FE_FILE_CAPTURE_CAMERA = 'camera';
// FormElement Types // 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_UPLOAD = 'upload';
const FE_TYPE_EXTRA = 'extra'; const FE_TYPE_EXTRA = 'extra';
const FE_TYPE_SUBRECORD = 'subrecord'; const FE_TYPE_SUBRECORD = 'subrecord';
const FE_TYPE_NOTE = 'note'; const FE_TYPE_NOTE = 'note';
const FE_TYPE_SENDMAIL = 'sendMail'; const FE_TYPE_SENDMAIL = 'sendMail';
const FE_TYPE_BEFORE_LOAD = 'beforeLoad'; const FE_TYPE_BEFORE_LOAD = 'beforeLoad';
const FE_TYPE_BEFORE_SAVE = 'beforeSave'; const FE_TYPE_BEFORE_SAVE = 'beforeSave';
......
...@@ -199,4 +199,125 @@ class HelperFormElement { ...@@ -199,4 +199,125 @@ class HelperFormElement {
return $fe; 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
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