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

AbstractBuildForm.php: buildFile recoded to display either 'filename + trash' or 'Upload button'

parent f63ed7b0
......@@ -1503,8 +1503,11 @@ abstract class AbstractBuildForm {
* @throws UserFormException
*/
public function buildFile(array $formElement, $htmlFormElementId, $value, &$json) {
$attribute = '';
$sip = $this->store->getVar(SIP_SIP, STORE_SIP);
$value = basename($value); // Strip directories
$attribute = $this->getAttributeMode($formElement);
$attribute .= Support::doAttribute('name', $htmlFormElementId);
// $attribute .= Support::doAttribute('class', 'form-control');
$attribute .= Support::doAttribute('type', 'file');
......@@ -1512,9 +1515,29 @@ abstract class AbstractBuildForm {
$attribute .= $this->getAttributeList($formElement, ['autofocus', 'accept']);
$attribute .= Support::doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
if ($value === '') {
$textDeleteClass = 'hidden';
$uploadClass = '';
} else {
$textDeleteClass = '';
$uploadClass = 'hidden';
$formElement['mode'] = 'disabled';
}
$attribute .= $this->getAttributeMode($formElement);
$attribute .= Support::doAttribute('class', $uploadClass, true);
$htmlInputFile = '<input ' . $attribute . '>' . $this->getHelpBlock();
$deleteButton = Support::wrapTag("<button class='delete-file' data-sip='$sip' name='trash-$htmlFormElementId'>", $this->symbol[SYMBOL_DELETE]);
$htmlFilename = Support::wrapTag("<span class='uploaded-file-name'>", $value, false);
$htmlTextDelete = Support::wrapTag("<div class='uploaded-file $textDeleteClass'>", $htmlFilename . ' ' . $deleteButton);
// <button type="button" class="file-delete" data-sip="571d1fc9e6974"><span class="glyphicon glyphicon-trash"></span></button>
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement['mode']);
return '<input ' . $attribute . '>' . $this->getHelpBlock();
return $htmlTextDelete . $htmlInputFile;
}
/**
......
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