Fix file attachment UI, move code into a function class

pull/2874/head
Julio 7 years ago
parent 460521a23e
commit 77e36219ee
  1. 12
      main/inc/lib/pear/HTML/QuickForm/file.php
  2. 50
      main/inc/lib/pear/HTML/QuickForm/input.php
  3. 41
      main/inc/lib/pear/HTML/QuickForm/text.php

@ -263,7 +263,7 @@ class HTML_QuickForm_file extends HTML_QuickForm_input
} }
return '<script> return '<script>
$(document).ready(function() { $(function() {
var $inputFile = $(\'#'.$id.'\'), var $inputFile = $(\'#'.$id.'\'),
$image = $(\'#'.$id.'_preview_image\'), $image = $(\'#'.$id.'_preview_image\'),
$input = $(\'[name="'.$id.'_crop_result"]\'), $input = $(\'[name="'.$id.'_crop_result"]\'),
@ -386,6 +386,7 @@ class HTML_QuickForm_file extends HTML_QuickForm_input
{ {
$name = $this->getName(); $name = $this->getName();
$attributes = $this->getAttributes(); $attributes = $this->getAttributes();
$size = $this->calculateSize();
switch ($layout) { switch ($layout) {
case FormValidator::LAYOUT_INLINE: case FormValidator::LAYOUT_INLINE:
@ -399,7 +400,7 @@ class HTML_QuickForm_file extends HTML_QuickForm_input
</div>'; </div>';
break; break;
case FormValidator::LAYOUT_HORIZONTAL: case FormValidator::LAYOUT_HORIZONTAL:
if (isset($attributes['custom']) && $attributes['custom'] == true) { if (isset($attributes['custom']) && $attributes['custom']) {
$template = ' $template = '
<div class="input-file-container"> <div class="input-file-container">
{element} {element}
@ -435,11 +436,12 @@ class HTML_QuickForm_file extends HTML_QuickForm_input
} else { } else {
$template = ' $template = '
<div id="file_'.$name.'" class="form-group {error_class}"> <div id="file_'.$name.'" class="form-group {error_class}">
<label {label-for} class="col-sm-3 control-label" >
<label {label-for} class="col-sm-'.$size[0].' control-label" >
<!-- BEGIN required --><span class="form_required">*</span><!-- END required --> <!-- BEGIN required --><span class="form_required">*</span><!-- END required -->
{label} {label}
</label> </label>
<div class="col-sm-7"> <div class="col-sm-'.$size[1].'">
{icon} {icon}
{element} {element}
<!-- BEGIN label_2 --> <!-- BEGIN label_2 -->
@ -449,7 +451,7 @@ class HTML_QuickForm_file extends HTML_QuickForm_input
<span class="help-inline help-block">{error}</span> <span class="help-inline help-block">{error}</span>
<!-- END error --> <!-- END error -->
</div> </div>
<div class="col-sm-2"> <div class="col-sm-'.$size[2].'">
<!-- BEGIN label_3 --> <!-- BEGIN label_3 -->
{label_3} {label_3}
<!-- END label_3 --> <!-- END label_3 -->

@ -33,6 +33,8 @@
*/ */
class HTML_QuickForm_input extends HTML_QuickForm_element class HTML_QuickForm_input extends HTML_QuickForm_element
{ {
protected $inputSize;
/** /**
* Class constructor * Class constructor
* *
@ -112,6 +114,54 @@ class HTML_QuickForm_input extends HTML_QuickForm_element
return $this->getAttribute('value'); return $this->getAttribute('value');
} }
/**
* @return null
*/
public function getInputSize()
{
return $this->inputSize;
}
/**
* @param null $inputSize
*/
public function setInputSize($inputSize)
{
$this->inputSize = $inputSize;
}
/**
* @return array|null
*/
public function calculateSize()
{
$size = $this->getColumnsSize();
if (empty($size)) {
$sizeTemp = $this->getInputSize();
if (empty($size)) {
$sizeTemp = 8;
}
$size = array(2, $sizeTemp, 2);
} else {
if (is_array($size)) {
if (count($size) != 3) {
$sizeTemp = $this->getInputSize();
if (empty($size)) {
$sizeTemp = 8;
}
$size = array(2, $sizeTemp, 2);
}
} else {
// else just keep the $size array as received
$size = array(2, (int) $size, 2);
}
}
return $size;
}
/** /**
* Returns the input field in HTML * Returns the input field in HTML
* *

@ -33,8 +33,6 @@
*/ */
class HTML_QuickForm_text extends HTML_QuickForm_input class HTML_QuickForm_text extends HTML_QuickForm_input
{ {
private $inputSize;
/** /**
* Class constructor * Class constructor
* *
@ -101,30 +99,9 @@ class HTML_QuickForm_text extends HTML_QuickForm_input
*/ */
public function getTemplate($layout) public function getTemplate($layout)
{ {
$size = $this->getColumnsSize(); $size = $this->calculateSize();
$attributes = $this->getAttributes(); $attributes = $this->getAttributes();
if (empty($size)) {
$sizeTemp = $this->getInputSize();
if (empty($size)) {
$sizeTemp = 8;
}
$size = array(2, $sizeTemp, 2);
} else {
if (is_array($size)) {
if (count($size) != 3) {
$sizeTemp = $this->getInputSize();
if (empty($size)) {
$sizeTemp = 8;
}
$size = array(2, $sizeTemp, 2);
}
// else just keep the $size array as received
} else {
$size = array(2, intval($size), 2);
}
}
switch ($layout) { switch ($layout) {
case FormValidator::LAYOUT_INLINE: case FormValidator::LAYOUT_INLINE:
return ' return '
@ -191,22 +168,6 @@ class HTML_QuickForm_text extends HTML_QuickForm_input
} }
} }
/**
* @return null
*/
public function getInputSize()
{
return $this->inputSize;
}
/**
* @param null $inputSize
*/
public function setInputSize($inputSize)
{
$this->inputSize = $inputSize;
}
/** /**
* Sets size of text field * Sets size of text field
* *

Loading…
Cancel
Save