Browse Source

Fix file attachment UI, move code into a function class

Julio 6 years ago
parent
commit
77e36219ee

+ 8 - 6
main/inc/lib/pear/HTML/QuickForm/file.php

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

+ 50 - 0
main/inc/lib/pear/HTML/QuickForm/input.php

@@ -33,6 +33,8 @@
  */
 class HTML_QuickForm_input extends HTML_QuickForm_element
 {
+    protected $inputSize;
+
     /**
      * Class constructor
      *
@@ -112,6 +114,54 @@ class HTML_QuickForm_input extends HTML_QuickForm_element
         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
      *

+ 1 - 40
main/inc/lib/pear/HTML/QuickForm/text.php

@@ -33,8 +33,6 @@
  */
 class HTML_QuickForm_text extends HTML_QuickForm_input
 {
-    private $inputSize;
-
     /**
      * Class constructor
      *
@@ -101,30 +99,9 @@ class HTML_QuickForm_text extends HTML_QuickForm_input
      */
     public function getTemplate($layout)
     {
-        $size = $this->getColumnsSize();
+        $size = $this->calculateSize();
         $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) {
             case FormValidator::LAYOUT_INLINE:
                 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
      *