- Added headers where they were missing

- Added comments where needed
- Beautified the code where needed, more readable and more compliant to CS
- loadResource function in helper fhc_helper.php is not using anymore CI
- Moved all constants from UDFWidget to UDFLib
- Added constant SORT to UDFLib
- Renamed constant REGEX_LANGUAGE to FE_REGEX_LANGUAGE in UDFLib
- Better formatting and indentation of the code of WidgetLib (more compliant to CS)
- Added missing validation attributes to HTML widgets
- Added constant HTML_DEFAULT_VALUE to CheckboxWidget
- Unset parameter multiple in DropdownWidget constructor
- Changed value of constant REQUIRED in widget HTMLWidget
- Added protected property $htmlParameters to widget HTMLWidget
  (it works as alias to $this->_args[HTMLWidget::HTML_ARG_NAME] -> better code)
- Replaced $this->_args[HTMLWidget::HTML_ARG_NAME] with $this->htmlParameters in the widgets
- Changed the CSS class label[udf-required=true]::after to label[required-field=true]::after in widgets.css
- Better use of constants in UDFWidget: constants from HTMLWidget are used only for the HTML parameters,
  while constants from UDFLib are used only for UDF parameters
This commit is contained in:
Paolo
2017-08-17 11:51:40 +02:00
parent 31e21acd67
commit e4160088e8
20 changed files with 478 additions and 293 deletions
+3 -1
View File
@@ -11,9 +11,11 @@ class CheckboxWidget extends HTMLWidget
const DESCRIPTION_FIELD = 'description';
// Value of value attribute of the checkbox
const CHECKBOX_VALUE = 'true';
// Default checkbox value
const HTML_DEFAULT_VALUE = false;
/**
*
* Loads the view that renders a checkbox
*/
protected function loadCheckboxView()
{
+15 -10
View File
@@ -15,11 +15,11 @@ class DropdownWidget extends HTMLWidget
// The name of the element of the data array given to the view
// this element is used to tell what element of the dropdown is selected
const SELECTED_ELEMENT = 'selectedElement';
//
// Default HTML value
const HTML_DEFAULT_VALUE = 'null';
const SIZE = 'size'; //
const MULTIPLE = 'multiple'; //
const SIZE = 'size'; // size of the dropdown
const MULTIPLE = 'multiple'; // multiple attribute
/**
*
@@ -28,31 +28,36 @@ class DropdownWidget extends HTMLWidget
{
parent::__construct($name, $args, $htmlArgs);
//
// If the selectd element is not set then set it to HTML_DEFAULT_VALUE
if (!isset($this->_args[DropdownWidget::SELECTED_ELEMENT]))
{
$this->_args[DropdownWidget::SELECTED_ELEMENT] = DropdownWidget::HTML_DEFAULT_VALUE;
}
// By default is not a multiple dropdown
unset($this->htmlParameters[DropdownWidget::MULTIPLE]);
}
/**
*
* Set this dropdown as multiple:
* - Setting the multiple attribute
* - Adding square brackets to the name
*/
public function setMultiple()
{
$this->_args[HTMLWidget::HTML_ARG_NAME][DropdownWidget::MULTIPLE] = DropdownWidget::MULTIPLE;
$this->_args[HTMLWidget::HTML_ARG_NAME][HTMLWidget::HTML_NAME] .= '[]';
$this->htmlParameters[DropdownWidget::MULTIPLE] = DropdownWidget::MULTIPLE;
$this->htmlParameters[HTMLWidget::HTML_NAME] .= '[]';
}
/**
*
* Checks if this object is a multiple dropdown
*/
public function isMultipleDropdown()
{
$isMultipleDropdown = false;
if (isset($this->_args[HTMLWidget::HTML_ARG_NAME][DropdownWidget::MULTIPLE])
&& $this->_args[HTMLWidget::HTML_ARG_NAME][DropdownWidget::MULTIPLE] == DropdownWidget::MULTIPLE)
if (isset($this->htmlParameters[DropdownWidget::MULTIPLE])
&& $this->htmlParameters[DropdownWidget::MULTIPLE] == DropdownWidget::MULTIPLE)
{
$isMultipleDropdown = true;
}
+15 -9
View File
@@ -11,22 +11,25 @@ class HTMLWidget extends Widget
const HTML_NAME = 'name'; // HTML name attribute
const HTML_ID = 'id'; // HTML id attribute
//
const EXTERNAL_BLOCK = 'externalBlock'; //
const EXTERNAL_START_BLOCK_HTML_TAG = '<div>'; //
const EXTERNAL_END_BLOCK_HTML_TAG = '</div>'; //
// External block definition
const EXTERNAL_BLOCK = 'externalBlock'; // External block name
const EXTERNAL_START_BLOCK_HTML_TAG = '<div>'; // External block start tag
const EXTERNAL_END_BLOCK_HTML_TAG = '</div>'; // External block end tag
//
// HTML attributes
const LABEL = 'title';
const REGEX = 'regex';
const TITLE = 'description';
const REQUIRED = 'udf-required';
const REQUIRED = 'required-field';
const MAX_VALUE = 'max-value';
const MIN_VALUE = 'min-value';
const MAX_LENGTH = 'max-length';
const MIN_LENGTH = 'min-length';
const PLACEHOLDER = 'placeholder';
// Alias of $this->_args[HTMLWidget::HTML_ARG_NAME] for a better code readability
protected $htmlParameters;
/**
* It gets also the htmlArgs array as parameter, it will be used to set the HTML properties
*/
@@ -61,10 +64,13 @@ class HTMLWidget extends Widget
$this->_args[HTMLWidget::HTML_ARG_NAME][$argName] = $argValue;
}
}
$this->htmlParameters =& $this->_args[HTMLWidget::HTML_ARG_NAME]; // Reference for a better code readability
}
/**
*
* Prints an attribute name and eventually also the value extracted from $htmlArgs
* Set $isValuePresent to false the value should not be displayed
*/
public static function printAttribute($htmlArgs, $attribute, $isValuePresent = true)
{
@@ -92,7 +98,7 @@ class HTMLWidget extends Widget
}
/**
*
* Prints the external block start tag
*/
public static function printStartBlock($htmlArgs)
{
@@ -104,7 +110,7 @@ class HTMLWidget extends Widget
}
/**
*
* Prints the external block end tag
*/
public static function printEndBlock($htmlArgs)
{
+5 -5
View File
@@ -5,12 +5,12 @@
*/
class TextareaWidget extends HTMLWidget
{
const TEXT = 'text'; //
const ROWS = 'rows'; //
const COLS = 'cols'; //
const TEXT = 'text'; // Text value
const ROWS = 'rows'; // Rows attribute
const COLS = 'cols'; // Cols attribute
/**
*
* Set the text value
*/
protected function setText($text)
{
@@ -18,7 +18,7 @@ class TextareaWidget extends HTMLWidget
}
/**
*
* Loads the view that renders a text area
*/
protected function loadTextareaView()
{
+4 -4
View File
@@ -5,11 +5,11 @@
*/
class TextfieldWidget extends HTMLWidget
{
const VALUE = 'text'; //
const SIZE = 'size'; //
const VALUE = 'text'; // Text value
const SIZE = 'size'; // Size attribute
/**
*
* Set the text value
*/
protected function setValue($value)
{
@@ -17,7 +17,7 @@ class TextfieldWidget extends HTMLWidget
}
/**
*
* Loads the view that renders an input text
*/
protected function loadTextfieldView()
{