diff --git a/application/controllers/system/UDF.php b/application/controllers/system/UDF.php
index 4f08ad576..e4e53fa3f 100644
--- a/application/controllers/system/UDF.php
+++ b/application/controllers/system/UDF.php
@@ -11,8 +11,8 @@ class UDF extends VileSci_Controller
// Load session library
$this->load->library('session');
- // Loads the widget library
- $this->load->library('WidgetLib');
+ // Loads the UDF library
+ $this->load->library('UDFLib');
//
$this->load->model('person/Person_model', 'PersonModel');
diff --git a/application/helpers/fhc_helper.php b/application/helpers/fhc_helper.php
index c2832d55d..a29ac240d 100644
--- a/application/helpers/fhc_helper.php
+++ b/application/helpers/fhc_helper.php
@@ -1,4 +1,5 @@
_ci = & get_instance();
+
+ $this->_ci->load->helper('fhc');
+
+ // Loads the widget library
+ $this->_ci->load->library('WidgetLib');
+
+ // Loads widgets to render HTML elements
+ // NOTE: the first one to be loaded must be HTMLWidget
+ loadResource(APPPATH . 'widgets/udf');
+ }
+
+ /**
+ *
+ */
+ public function UDFWidget($args, $htmlArgs = array())
+ {
+ if (!empty($args[UDFLib::SCHEMA_ARG_NAME]) && !empty($args[UDFLib::TABLE_ARG_NAME]))
+ {
+ //
+ if (empty($args[UDFLib::FIELD_ARG_NAME]) && !isset($htmlArgs[HTMLWidget::EXTERNAL_BLOCK]))
+ {
+ $htmlArgs[HTMLWidget::EXTERNAL_BLOCK] = true;
+ }
+
+ return $this->_ci->widgetlib->widget(
+ UDFLib::WIDGET_NAME,
+ $args,
+ $htmlArgs
+ );
+ }
+ else
+ {
+ if (empty($args[UDFLib::SCHEMA_ARG_NAME]))
+ {
+ show_error(UDFLib::SCHEMA_ARG_NAME.' parameter is missing!');
+ }
+ if (empty($args[UDFLib::TABLE_ARG_NAME]))
+ {
+ show_error(UDFLib::TABLE_ARG_NAME.' parameter is missing!');
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/application/libraries/WidgetLib.php b/application/libraries/WidgetLib.php
index 9996ce684..bd6694136 100644
--- a/application/libraries/WidgetLib.php
+++ b/application/libraries/WidgetLib.php
@@ -28,6 +28,9 @@ if (!defined("BASEPATH")) exit("No direct script access allowed");
class WidgetLib
{
+ const DIR_HTML_WIDGETS = 'html';
+ const HTML_WIDGET_NAME = 'HTMLWidget';
+
/* default values */
private $_template = 'template';
private $_parser = FALSE;
@@ -45,8 +48,15 @@ class WidgetLib
{
$this->_ci = & get_instance();
- // set the default widget path with APPPATH
+ $this->_ci->load->helper('fhc');
+
+ // Set the default widget path with APPPATH
$this->_widget_path = APPPATH . 'widgets/';
+
+ // Loads widgets to render HTML elements
+ // NOTE: the first one to be loaded must be HTMLWidget
+ loadResource($this->_widget_path.WidgetLib::DIR_HTML_WIDGETS, WidgetLib::HTML_WIDGET_NAME);
+ loadResource($this->_widget_path.WidgetLib::DIR_HTML_WIDGETS);
if (!empty($config))
$this->initialize($config);
@@ -184,65 +194,15 @@ class WidgetLib
*/
public function widget($name, $data = array(), $htmlArgs = array())
{
- $class = str_replace('.php', '', trim($name, '/'));
+ //
+ loadResource($this->_widget_path, $name, true);
- // determine path and widget class name
- $path = $this->_widget_path;
- if (($last_slash = strrpos($class, '/')) !== FALSE) {
- $path += substr($class, 0, $last_slash);
- $class = substr($class, $last_slash + 1);
+ if (!class_exists($name))
+ {
+ show_error("Widget '" . $name . "' was not found.");
}
- // new widget
- if (!class_exists($class)) {
- // try both lowercase and capitalized versions
- foreach (array(ucfirst($class), strtolower($class)) as $class) {
- if (file_exists($path . $class . '.php')) {
- include_once ($path . $class . '.php');
-
- // found the file, stop looking
- break;
- }
- }
- }
-
- if (!class_exists($class)) {
- show_error("Widget '" . $class . "' was not found.");
- }
-
- return new $class($class, $data, $htmlArgs);
- }
-
- /**
- *
- */
- public function UDFWidget($args, $htmlArgs = array())
- {
- if (!empty($args[UDFWidgetTpl::SCHEMA_ARG_NAME]) && !empty($args[UDFWidgetTpl::TABLE_ARG_NAME]))
- {
- //
- if (empty($args[UDFWidgetTpl::FIELD_ARG_NAME]) && !isset($htmlArgs[Widget::EXTERNAL_BLOCK]))
- {
- $htmlArgs[Widget::EXTERNAL_BLOCK] = true;
- }
-
- return $this->widget(
- UDFWidgetTpl::WIDGET_NAME,
- $args,
- $htmlArgs
- );
- }
- else
- {
- if (empty($args[UDFWidgetTpl::SCHEMA_ARG_NAME]))
- {
- show_error(UDFWidgetTpl::SCHEMA_ARG_NAME.' parameter is missing!');
- }
- if (empty($args[UDFWidgetTpl::TABLE_ARG_NAME]))
- {
- show_error(UDFWidgetTpl::TABLE_ARG_NAME.' parameter is missing!');
- }
- }
+ return new $name($name, $data, $htmlArgs);
}
/**
@@ -635,35 +595,10 @@ class Partial
}
/**
- * The mother of all widgets
- * it represent a generic HTML element
+ * General widget element
*/
class Widget extends Partial
{
- // The name of the array present in the data array given to the view that will render this widget
- const HTML_ARG_NAME = 'HTML';
- const HTML_DEFAULT_VALUE = ''; // Default value of the html element
- const HTML_NAME = 'name'; // HTML name attribute
- const HTML_ID = 'id'; // HTML id attribute
-
- const EXTERNAL_BLOCK = 'externalBlock'; //
- const EXTERNAL_START_BLOCK_HTML_TAG = '
'; //
- const EXTERNAL_END_BLOCK_HTML_TAG = '
'; //
-
- /**
- * It gets also the htmlArgs array as parameter, it will be used to set the HTML properties
- */
- public function __construct($name, $args = array(), $htmlArgs = array())
- {
- parent::__construct($name, $args);
-
- // Initialising HTML properties
- $this->_setHtmlProperties($htmlArgs);
-
- // Loads helper message to manage returning messages
- $this->load->helper('message');
- }
-
/**
* (non-PHPdoc)
* @see Partial::content()
@@ -690,456 +625,4 @@ class Widget extends Partial
return parent::content();
}
-
- /**
- * Initialising html properties, such as the id and name attributes of the HTML element
- */
- private function _setHtmlProperties($htmlArgs)
- {
- // If $htmlArgs wasn't already stored in $this->_args
- if (!isset($this->_args[Widget::HTML_ARG_NAME]))
- {
- $this->_args[Widget::HTML_ARG_NAME] = array();
-
- // Avoids that elements in a HTML page have the same name or id
- $randomIdentifier = uniqid(rand(0, 1000));
- $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_ID] = $randomIdentifier;
- $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_NAME] = $randomIdentifier;
-
- foreach($htmlArgs as $argName => $argValue)
- {
- $this->_args[Widget::HTML_ARG_NAME][$argName] = $argValue;
- }
- }
- }
-
- /**
- *
- */
- public static function printAttribute($htmlArgs, $attribute, $isValuePresent = true)
- {
- if ($attribute != null)
- {
- if (isset($htmlArgs[$attribute]))
- {
- if ($isValuePresent === true)
- {
- $value = $htmlArgs[$attribute];
-
- if (is_bool($value))
- {
- $value = $value ? 'true' : 'false';
- }
-
- echo sprintf('%s="%s"', $attribute, $value);
- }
- else
- {
- echo $attribute;
- }
- }
- }
- }
-
- /**
- *
- */
- public static function printStartBlock($htmlArgs)
- {
- if (isset($htmlArgs[Widget::EXTERNAL_BLOCK])
- && $htmlArgs[Widget::EXTERNAL_BLOCK] === true)
- {
- echo Widget::EXTERNAL_START_BLOCK_HTML_TAG;
- }
- }
-
- /**
- *
- */
- public static function printEndBlock($htmlArgs)
- {
- if (isset($htmlArgs[Widget::EXTERNAL_BLOCK])
- && $htmlArgs[Widget::EXTERNAL_BLOCK] === true)
- {
- echo Widget::EXTERNAL_END_BLOCK_HTML_TAG;
- }
- }
-}
-
-/**
- * It exends the Widget class to represent an HTML dropdown
- */
-class DropdownWidget extends Widget
-{
- // The name of the element of the data array given to the view
- // this element is an array of elements to be place inside the dropdown
- const WIDGET_DATA_ELEMENTS_ARRAY_NAME = 'ELEMENTS_ARRAY';
- // Name of the property that will be used to store the value attribute of the option tag
- const ID_FIELD = 'id';
- // Name of the property that will be used to store the value between the option tags
- const DESCRIPTION_FIELD = 'description';
- // 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';
- //
- const HTML_DEFAULT_VALUE = 'null';
-
- const SIZE = 'size'; //
- const MULTIPLE = 'multiple'; //
-
- /**
- *
- */
- public function __construct($name, $args = array(), $htmlArgs = array())
- {
- parent::__construct($name, $args, $htmlArgs);
-
- //
- if (!isset($this->_args[DropdownWidget::SELECTED_ELEMENT]))
- {
- $this->_args[DropdownWidget::SELECTED_ELEMENT] = DropdownWidget::HTML_DEFAULT_VALUE;
- }
- }
-
- /**
- *
- */
- public function setMultiple()
- {
- $this->_args[Widget::HTML_ARG_NAME][DropdownWidget::MULTIPLE] = DropdownWidget::MULTIPLE;
- $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_NAME] .= '[]';
- }
-
- /**
- *
- */
- public function isMultipleDropdown()
- {
- $isMultipleDropdown = false;
-
- if (isset($this->_args[Widget::HTML_ARG_NAME][DropdownWidget::MULTIPLE])
- && $this->_args[Widget::HTML_ARG_NAME][DropdownWidget::MULTIPLE] == DropdownWidget::MULTIPLE)
- {
- $isMultipleDropdown = true;
- }
-
- return $isMultipleDropdown;
- }
-
- /**
- * Add the correct select to the model used to load a list of elemets for this dropdown
- * @param model $model the model used to load elements
- * @param string $idName the name of the field that will used to be the value of the option tag
- * @param string $descriptionName the name of the field that will used to be displayed in the dropdown
- */
- protected function addSelectToModel($model, $idName, $descriptionName)
- {
- $model->addSelect(
- sprintf(
- '%s AS %s, %s AS %s',
- $idName,
- DropdownWidget::ID_FIELD,
- $descriptionName,
- DropdownWidget::DESCRIPTION_FIELD
- )
- );
- }
-
- /**
- * Set the array used to populate the dropdown
- * @param array $elements list used to populate this dropdown
- * @param boolean $emptyElement if an empty element must be added at the beginning of the dropdown
- * @param string $stdDescription description of the empty element
- * @param string $noDataDescription description if no data are found
- * @param string $id value of the attribute value of the empty element
- */
- protected function setElementsArray(
- $elements, $emptyElement = false, $stdDescription = '' , $noDataDescription = 'No data found' , $id = DropdownWidget::HTML_DEFAULT_VALUE
- )
- {
- $tmpElements = array();
-
- if (isError($elements))
- {
- if (is_object($elements) && isset($elements->retval))
- {
- show_error($elements->retval);
- }
- else if (is_string($elements))
- {
- show_error($elements);
- }
- else
- {
- show_error('Generic error occurred');
- }
- }
- else
- {
- if ($emptyElement === true && $this->isMultipleDropdown() == false)
- {
- $tmpElements = $this->addElementAtBeginning(
- $elements,
- $stdDescription,
- $noDataDescription,
- $id
- );
- }
- else
- {
- $tmpElements = $elements->retval;
- }
-
- $this->_args[DropdownWidget::WIDGET_DATA_ELEMENTS_ARRAY_NAME] = $tmpElements;
- }
- }
-
- /**
- * Adds an element to the beginning of the array
- */
- protected function addElementAtBeginning($elements, $stdDescription, $noDataDescription, $id)
- {
- $element = new stdClass();
- $element->{DropdownWidget::ID_FIELD} = $id;
- $element->{DropdownWidget::DESCRIPTION_FIELD} = $stdDescription;
-
- if (!hasData($elements))
- {
- $element->{DropdownWidget::DESCRIPTION_FIELD} = $noDataDescription;
- }
-
- array_unshift($elements->retval, $element);
-
- return $elements->retval;
- }
-
- /**
- * Loads the dropdown view with all the elements to be displayed
- */
- protected function loadDropDownView()
- {
- $this->view('widgets/dropdown', $this->_args);
- }
-}
-
-/**
- *
- */
-class DropdownWidgetUDF extends DropdownWidget
-{
- /**
- *
- */
- public function render($parameters)
- {
- $tmpElements = array();
-
- //
- foreach($parameters as $parameter)
- {
- //
- if ((is_array($parameter) && count($parameter) == 2)
- || (is_string($parameter) || is_numeric($parameter))
- || (is_object($parameter) && isset($parameter->{PARENT::ID_FIELD}) && isset($parameter->{PARENT::DESCRIPTION_FIELD})))
- {
- $element = new stdClass(); //
- //
- if (is_array($parameter) && count($parameter) == 2)
- {
- $element->{PARENT::ID_FIELD} = $parameter[0]; //
- $element->{PARENT::DESCRIPTION_FIELD} = $parameter[1]; //
- }
- //
- else if (is_string($parameter) || is_numeric($parameter))
- {
- $element->{PARENT::ID_FIELD} = $parameter; //
- $element->{PARENT::DESCRIPTION_FIELD} = $parameter; //
- }
- //
- else if (is_object($parameter) && isset($parameter->{PARENT::ID_FIELD}) && isset($parameter->{PARENT::DESCRIPTION_FIELD}))
- {
- $element->{PARENT::ID_FIELD} = $parameter->{PARENT::ID_FIELD}; //
- $element->{PARENT::DESCRIPTION_FIELD} = $parameter->{PARENT::DESCRIPTION_FIELD}; //
- }
-
- array_push($tmpElements, $element); //
- }
- }
-
- $this->setElementsArray(
- success($tmpElements),
- true,
- $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::PLACEHOLDER],
- 'No data found for this UDF'
- );
-
- $this->loadDropDownView();
-
- echo $this->content();
- }
-}
-
-/**
- * It exends the Widget class to represent an HTML textarea
- */
-class TextareaWidget extends Widget
-{
- const TEXT = 'text'; //
- const ROWS = 'rows'; //
- const COLS = 'cols'; //
-
- /**
- *
- */
- protected function setText($text)
- {
- $this->_args[TextareaWidget::TEXT] = $text;
- }
-
- /**
- *
- */
- protected function loadTextareaView()
- {
- $this->view('widgets/textarea', $this->_args);
- }
-}
-
-/**
- *
- */
-class TextareaWidgetUDF extends TextareaWidget
-{
- /**
- *
- */
- public function render($parameters)
- {
- if ($parameters != null)
- {
- $this->setText($parameters);
- }
- else
- {
- $this->setText('');
- }
-
- $this->loadTextareaView();
-
- echo $this->content();
- }
-}
-
-/**
- * It exends the Widget class to represent an HTML textarea
- */
-class TextfieldWidget extends Widget
-{
- const VALUE = 'text'; //
- const SIZE = 'size'; //
-
- /**
- *
- */
- protected function setValue($value)
- {
- $this->_args[TextfieldWidget::VALUE] = $value;
- }
-
- /**
- *
- */
- protected function loadTextfieldView()
- {
- $this->view('widgets/textfield', $this->_args);
- }
-}
-
-/**
- *
- */
-class TextfieldWidgetUDF extends TextfieldWidget
-{
- /**
- *
- */
- public function render($parameters)
- {
- if ($parameters != null)
- {
- $this->setValue($parameters);
- }
- else
- {
- $this->setValue('');
- }
-
- $this->loadTextfieldView();
-
- echo $this->content();
- }
-}
-
-/**
- * It exends the Widget class to represent an HTML dropdown
- */
-class CheckboxWidget extends Widget
-{
- // Name of the property that will be used to store the value attribute of the option tag
- const VALUE_FIELD = 'value';
- // Name of the property that will be used to store the value between the option tags
- const DESCRIPTION_FIELD = 'description';
- // Value of value attribute of the checkbox
- const CHECKBOX_VALUE = 'true';
-
- /**
- *
- */
- protected function loadCheckboxView()
- {
- $this->view('widgets/checkbox', $this->_args);
- }
-}
-
-/**
- *
- */
-class CheckboxWidgetUDF extends CheckboxWidget
-{
- /**
- *
- */
- public function render()
- {
- $this->loadCheckboxView();
-
- echo $this->content();
- }
-}
-
-/**
- * Defined here because these constants can be used
- * in the views also
- */
-abstract class UDFWidgetTpl extends Widget
-{
- const WIDGET_NAME = 'UDFWidget';
- const SCHEMA_ARG_NAME = 'schema';
- const TABLE_ARG_NAME = 'table';
- const FIELD_ARG_NAME = 'field';
- const UDFS_ARG_NAME = 'udfs';
-
- // HTML components
- const TITLE = 'description';
- const LABEL = 'title';
- const PLACEHOLDER = 'placeholder';
- const DEFAULT_VALUE = 'defaultValue';
-
- // Validation attributes
- const REGEX = 'regex';
- const REQUIRED = 'required';
- const MAX_VALUE = 'max-value';
- const MIN_VALUE = 'min-value';
- const MAX_LENGTH = 'max-length';
- const MIN_LENGTH = 'min-length';
}
\ No newline at end of file
diff --git a/application/views/system/udf.php b/application/views/system/udf.php
index 5fd1bd6d9..058d73ec3 100644
--- a/application/views/system/udf.php
+++ b/application/views/system/udf.php
@@ -62,11 +62,11 @@
?>
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/application/views/widgets/dropdown.php b/application/views/widgets/dropdown.php
index 38a6ea973..5d6150a07 100644
--- a/application/views/widgets/dropdown.php
+++ b/application/views/widgets/dropdown.php
@@ -1,22 +1,22 @@
-
+
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/application/views/widgets/textarea.php b/application/views/widgets/textarea.php
index 7cbe67efb..6866c17a5 100644
--- a/application/views/widgets/textarea.php
+++ b/application/views/widgets/textarea.php
@@ -1,17 +1,17 @@
-
+
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/application/views/widgets/textfield.php b/application/views/widgets/textfield.php
index d9cba43e0..0807f3ed1 100644
--- a/application/views/widgets/textfield.php
+++ b/application/views/widgets/textfield.php
@@ -1,17 +1,17 @@
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
value=""
>
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/application/widgets/html/CheckboxWidget.php b/application/widgets/html/CheckboxWidget.php
new file mode 100644
index 000000000..6a77f0d43
--- /dev/null
+++ b/application/widgets/html/CheckboxWidget.php
@@ -0,0 +1,22 @@
+view('widgets/checkbox', $this->_args);
+ }
+}
\ No newline at end of file
diff --git a/application/widgets/html/DropdownWidget.php b/application/widgets/html/DropdownWidget.php
new file mode 100644
index 000000000..63e1b414d
--- /dev/null
+++ b/application/widgets/html/DropdownWidget.php
@@ -0,0 +1,157 @@
+_args[DropdownWidget::SELECTED_ELEMENT]))
+ {
+ $this->_args[DropdownWidget::SELECTED_ELEMENT] = DropdownWidget::HTML_DEFAULT_VALUE;
+ }
+ }
+
+ /**
+ *
+ */
+ public function setMultiple()
+ {
+ $this->_args[HTMLWidget::HTML_ARG_NAME][DropdownWidget::MULTIPLE] = DropdownWidget::MULTIPLE;
+ $this->_args[HTMLWidget::HTML_ARG_NAME][HTMLWidget::HTML_NAME] .= '[]';
+ }
+
+ /**
+ *
+ */
+ 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)
+ {
+ $isMultipleDropdown = true;
+ }
+
+ return $isMultipleDropdown;
+ }
+
+ /**
+ * Add the correct select to the model used to load a list of elemets for this dropdown
+ * @param model $model the model used to load elements
+ * @param string $idName the name of the field that will used to be the value of the option tag
+ * @param string $descriptionName the name of the field that will used to be displayed in the dropdown
+ */
+ protected function addSelectToModel($model, $idName, $descriptionName)
+ {
+ $model->addSelect(
+ sprintf(
+ '%s AS %s, %s AS %s',
+ $idName,
+ DropdownWidget::ID_FIELD,
+ $descriptionName,
+ DropdownWidget::DESCRIPTION_FIELD
+ )
+ );
+ }
+
+ /**
+ * Set the array used to populate the dropdown
+ * @param array $elements list used to populate this dropdown
+ * @param boolean $emptyElement if an empty element must be added at the beginning of the dropdown
+ * @param string $stdDescription description of the empty element
+ * @param string $noDataDescription description if no data are found
+ * @param string $id value of the attribute value of the empty element
+ */
+ protected function setElementsArray(
+ $elements, $emptyElement = false, $stdDescription = '' , $noDataDescription = 'No data found' , $id = DropdownWidget::HTML_DEFAULT_VALUE
+ )
+ {
+ $tmpElements = array();
+
+ if (isError($elements))
+ {
+ if (is_object($elements) && isset($elements->retval))
+ {
+ show_error($elements->retval);
+ }
+ else if (is_string($elements))
+ {
+ show_error($elements);
+ }
+ else
+ {
+ show_error('Generic error occurred');
+ }
+ }
+ else
+ {
+ if ($emptyElement === true && $this->isMultipleDropdown() == false)
+ {
+ $tmpElements = $this->addElementAtBeginning(
+ $elements,
+ $stdDescription,
+ $noDataDescription,
+ $id
+ );
+ }
+ else
+ {
+ $tmpElements = $elements->retval;
+ }
+
+ $this->_args[DropdownWidget::WIDGET_DATA_ELEMENTS_ARRAY_NAME] = $tmpElements;
+ }
+ }
+
+ /**
+ * Adds an element to the beginning of the array
+ */
+ protected function addElementAtBeginning($elements, $stdDescription, $noDataDescription, $id)
+ {
+ $element = new stdClass();
+ $element->{DropdownWidget::ID_FIELD} = $id;
+ $element->{DropdownWidget::DESCRIPTION_FIELD} = $stdDescription;
+
+ if (!hasData($elements))
+ {
+ $element->{DropdownWidget::DESCRIPTION_FIELD} = $noDataDescription;
+ }
+
+ array_unshift($elements->retval, $element);
+
+ return $elements->retval;
+ }
+
+ /**
+ * Loads the dropdown view with all the elements to be displayed
+ */
+ protected function loadDropDownView()
+ {
+ $this->view('widgets/dropdown', $this->_args);
+ }
+}
\ No newline at end of file
diff --git a/application/widgets/html/HTMLWidget.php b/application/widgets/html/HTMLWidget.php
new file mode 100644
index 000000000..04f5d4d5f
--- /dev/null
+++ b/application/widgets/html/HTMLWidget.php
@@ -0,0 +1,117 @@
+'; //
+ const EXTERNAL_END_BLOCK_HTML_TAG = '
'; //
+
+ //
+ const LABEL = 'title';
+ const REGEX = 'regex';
+ const TITLE = 'description';
+ const REQUIRED = 'udf-required';
+ const MAX_VALUE = 'max-value';
+ const MIN_VALUE = 'min-value';
+ const MAX_LENGTH = 'max-length';
+ const MIN_LENGTH = 'min-length';
+ const PLACEHOLDER = 'placeholder';
+
+ /**
+ * It gets also the htmlArgs array as parameter, it will be used to set the HTML properties
+ */
+ public function __construct($name, $args = array(), $htmlArgs = array())
+ {
+ parent::__construct($name, $args);
+
+ // Initialising HTML properties
+ $this->_setHtmlProperties($htmlArgs);
+
+ // Loads helper message to manage returning messages
+ $this->load->helper('message');
+ }
+
+ /**
+ * Initialising html properties, such as the id and name attributes of the HTML element
+ */
+ private function _setHtmlProperties($htmlArgs)
+ {
+ // If $htmlArgs wasn't already stored in $this->_args
+ if (!isset($this->_args[HTMLWidget::HTML_ARG_NAME]))
+ {
+ $this->_args[HTMLWidget::HTML_ARG_NAME] = array();
+
+ // Avoids that elements in a HTML page have the same name or id
+ $randomIdentifier = uniqid(rand(0, 1000));
+ $this->_args[HTMLWidget::HTML_ARG_NAME][HTMLWidget::HTML_ID] = $randomIdentifier;
+ $this->_args[HTMLWidget::HTML_ARG_NAME][HTMLWidget::HTML_NAME] = $randomIdentifier;
+
+ foreach($htmlArgs as $argName => $argValue)
+ {
+ $this->_args[HTMLWidget::HTML_ARG_NAME][$argName] = $argValue;
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ public static function printAttribute($htmlArgs, $attribute, $isValuePresent = true)
+ {
+ if ($attribute != null)
+ {
+ if (isset($htmlArgs[$attribute]))
+ {
+ if ($isValuePresent === true)
+ {
+ $value = $htmlArgs[$attribute];
+
+ if (is_bool($value))
+ {
+ $value = $value ? 'true' : 'false';
+ }
+
+ echo sprintf('%s="%s"', $attribute, $value);
+ }
+ else
+ {
+ echo $attribute;
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ public static function printStartBlock($htmlArgs)
+ {
+ if (isset($htmlArgs[HTMLWidget::EXTERNAL_BLOCK])
+ && $htmlArgs[HTMLWidget::EXTERNAL_BLOCK] === true)
+ {
+ echo HTMLWidget::EXTERNAL_START_BLOCK_HTML_TAG;
+ }
+ }
+
+ /**
+ *
+ */
+ public static function printEndBlock($htmlArgs)
+ {
+ if (isset($htmlArgs[HTMLWidget::EXTERNAL_BLOCK])
+ && $htmlArgs[HTMLWidget::EXTERNAL_BLOCK] === true)
+ {
+ echo HTMLWidget::EXTERNAL_END_BLOCK_HTML_TAG;
+ }
+ }
+}
\ No newline at end of file
diff --git a/application/widgets/html/TextareaWidget.php b/application/widgets/html/TextareaWidget.php
new file mode 100644
index 000000000..ffb9e538d
--- /dev/null
+++ b/application/widgets/html/TextareaWidget.php
@@ -0,0 +1,27 @@
+_args[TextareaWidget::TEXT] = $text;
+ }
+
+ /**
+ *
+ */
+ protected function loadTextareaView()
+ {
+ $this->view('widgets/textarea', $this->_args);
+ }
+}
\ No newline at end of file
diff --git a/application/widgets/html/TextfieldWidget.php b/application/widgets/html/TextfieldWidget.php
new file mode 100644
index 000000000..e5ad146c9
--- /dev/null
+++ b/application/widgets/html/TextfieldWidget.php
@@ -0,0 +1,26 @@
+_args[TextfieldWidget::VALUE] = $value;
+ }
+
+ /**
+ *
+ */
+ protected function loadTextfieldView()
+ {
+ $this->view('widgets/textfield', $this->_args);
+ }
+}
\ No newline at end of file
diff --git a/application/widgets/udf/CheckboxWidgetUDF.php b/application/widgets/udf/CheckboxWidgetUDF.php
new file mode 100644
index 000000000..096a7a737
--- /dev/null
+++ b/application/widgets/udf/CheckboxWidgetUDF.php
@@ -0,0 +1,17 @@
+loadCheckboxView();
+
+ echo $this->content();
+ }
+}
\ No newline at end of file
diff --git a/application/widgets/udf/DropdownWidgetUDF.php b/application/widgets/udf/DropdownWidgetUDF.php
new file mode 100644
index 000000000..46a3f9733
--- /dev/null
+++ b/application/widgets/udf/DropdownWidgetUDF.php
@@ -0,0 +1,58 @@
+{PARENT::ID_FIELD}) && isset($parameter->{PARENT::DESCRIPTION_FIELD})))
+ {
+ $element = new stdClass(); //
+ //
+ if (is_array($parameter) && count($parameter) == 2)
+ {
+ $element->{PARENT::ID_FIELD} = $parameter[0]; //
+ $element->{PARENT::DESCRIPTION_FIELD} = $parameter[1]; //
+ }
+ //
+ else if (is_string($parameter) || is_numeric($parameter))
+ {
+ $element->{PARENT::ID_FIELD} = $parameter; //
+ $element->{PARENT::DESCRIPTION_FIELD} = $parameter; //
+ }
+ //
+ else if (is_object($parameter) && isset($parameter->{PARENT::ID_FIELD}) && isset($parameter->{PARENT::DESCRIPTION_FIELD}))
+ {
+ $element->{PARENT::ID_FIELD} = $parameter->{PARENT::ID_FIELD}; //
+ $element->{PARENT::DESCRIPTION_FIELD} = $parameter->{PARENT::DESCRIPTION_FIELD}; //
+ }
+
+ array_push($tmpElements, $element); //
+ }
+ }
+
+ $this->setElementsArray(
+ success($tmpElements),
+ true,
+ $this->_args[HTMLWidget::HTML_ARG_NAME][HTMLWidget::PLACEHOLDER],
+ 'No data found for this UDF'
+ );
+
+ $this->loadDropDownView();
+
+ echo $this->content();
+ }
+}
\ No newline at end of file
diff --git a/application/widgets/udf/TextareaWidgetUDF.php b/application/widgets/udf/TextareaWidgetUDF.php
new file mode 100644
index 000000000..d64015190
--- /dev/null
+++ b/application/widgets/udf/TextareaWidgetUDF.php
@@ -0,0 +1,26 @@
+setText($parameters);
+ }
+ else
+ {
+ $this->setText('');
+ }
+
+ $this->loadTextareaView();
+
+ echo $this->content();
+ }
+}
\ No newline at end of file
diff --git a/application/widgets/udf/TextfieldWidgetUDF.php b/application/widgets/udf/TextfieldWidgetUDF.php
new file mode 100644
index 000000000..2d78b0d1a
--- /dev/null
+++ b/application/widgets/udf/TextfieldWidgetUDF.php
@@ -0,0 +1,26 @@
+setValue($parameters);
+ }
+ else
+ {
+ $this->setValue('');
+ }
+
+ $this->loadTextfieldView();
+
+ echo $this->content();
+ }
+}
\ No newline at end of file
diff --git a/application/widgets/UDFWidget.php b/application/widgets/udf/UDFWidget.php
similarity index 64%
rename from application/widgets/UDFWidget.php
rename to application/widgets/udf/UDFWidget.php
index 4f847c023..9168c86da 100644
--- a/application/widgets/UDFWidget.php
+++ b/application/widgets/udf/UDFWidget.php
@@ -3,11 +3,10 @@
/**
*
*/
-class UDFWidget extends UDFWidgetTpl
+class UDFWidget extends HTMLWidget
{
const NAME = 'name';
const TYPE = 'type';
- const REQUIRED = 'udf-required';
const VALIDATION = 'validation';
const LIST_VALUES = 'listValues';
const REGEX_LANGUAGE = 'js';
@@ -16,12 +15,12 @@ class UDFWidget extends UDFWidgetTpl
public function display($widgetData)
{
- $schema = $widgetData[UDFWidgetTpl::SCHEMA_ARG_NAME];
- $table = $widgetData[UDFWidgetTpl::TABLE_ARG_NAME];
+ $schema = $widgetData[UDFLib::SCHEMA_ARG_NAME];
+ $table = $widgetData[UDFLib::TABLE_ARG_NAME];
- if (isset($widgetData[UDFWidgetTpl::FIELD_ARG_NAME]))
+ if (isset($widgetData[UDFLib::FIELD_ARG_NAME]))
{
- $field = $widgetData[UDFWidgetTpl::FIELD_ARG_NAME];
+ $field = $widgetData[UDFLib::FIELD_ARG_NAME];
}
$udfResults = $this->_loadUDF($schema, $table);
@@ -105,8 +104,8 @@ class UDFWidget extends UDFWidgetTpl
*/
private function _setNameAndId($jsonSchema)
{
- $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_ID] = $jsonSchema->{UDFWidget::NAME};
- $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_NAME] = $jsonSchema->{UDFWidget::NAME};
+ $this->_args[HTMLWidget::HTML_ARG_NAME][HTMLWidget::HTML_ID] = $jsonSchema->{UDFWidget::NAME};
+ $this->_args[HTMLWidget::HTML_ARG_NAME][HTMLWidget::HTML_NAME] = $jsonSchema->{UDFWidget::NAME};
}
/**
@@ -210,10 +209,10 @@ class UDFWidget extends UDFWidgetTpl
*/
private function _renderDropdown($jsonSchema, $multiple = false)
{
- if (isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME])
- && isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
+ if (isset($this->_args[UDFLib::UDFS_ARG_NAME])
+ && isset($this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
{
- $this->_args[DropdownWidget::SELECTED_ELEMENT] = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
+ $this->_args[DropdownWidget::SELECTED_ELEMENT] = $this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
}
else
{
@@ -254,10 +253,10 @@ class UDFWidget extends UDFWidgetTpl
$textareaUDF = new TextareaWidgetUDF($this->_name, $this->_args);
$text = null;
- if (isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME])
- && isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
+ if (isset($this->_args[UDFLib::UDFS_ARG_NAME])
+ && isset($this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
{
- $text = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
+ $text = $this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
}
$textareaUDF->render($text);
@@ -271,10 +270,10 @@ class UDFWidget extends UDFWidgetTpl
$textareaUDF = new TextfieldWidgetUDF($this->_name, $this->_args);
$text = null;
- if (isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME])
- && isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
+ if (isset($this->_args[UDFLib::UDFS_ARG_NAME])
+ && isset($this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
{
- $text = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
+ $text = $this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
}
$textareaUDF->render($text);
@@ -285,14 +284,14 @@ class UDFWidget extends UDFWidgetTpl
*/
private function _renderCheckbox($jsonSchema)
{
- if (isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME])
- && isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
+ if (isset($this->_args[UDFLib::UDFS_ARG_NAME])
+ && isset($this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
{
- $this->_args[CheckboxWidget::VALUE_FIELD] = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
+ $this->_args[CheckboxWidget::VALUE_FIELD] = $this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
}
else
{
- $this->_args[CheckboxWidget::VALUE_FIELD] = Widget::HTML_DEFAULT_VALUE;
+ $this->_args[CheckboxWidget::VALUE_FIELD] = HTMLWidget::HTML_DEFAULT_VALUE;
}
$checkboxWidgetUDF = new CheckboxWidgetUDF($this->_name, $this->_args);
@@ -306,73 +305,73 @@ class UDFWidget extends UDFWidgetTpl
private function _setAttributesWithPhrases($jsonSchema)
{
// Description, title and placeholder
- if (isset($jsonSchema->{UDFWidgetTpl::LABEL})
- || isset($jsonSchema->{UDFWidgetTpl::TITLE})
- || isset($jsonSchema->{UDFWidgetTpl::PLACEHOLDER}))
+ if (isset($jsonSchema->{UDFLib::LABEL})
+ || isset($jsonSchema->{UDFLib::TITLE})
+ || isset($jsonSchema->{UDFLib::PLACEHOLDER}))
{
//
$this->_ci->load->library('PhrasesLib');
//
- if (isset($jsonSchema->{UDFWidgetTpl::LABEL}))
+ if (isset($jsonSchema->{UDFLib::LABEL}))
{
$tmpResult = $this->_ci->phraseslib->getPhrases(
UDFWidget::PHRASES_APP_NAME,
DEFAULT_LEHREINHEIT_SPRACHE,
- $jsonSchema->{UDFWidgetTpl::LABEL},
+ $jsonSchema->{UDFLib::LABEL},
null,
null,
'no'
);
if (hasData($tmpResult))
{
- $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::LABEL] = $tmpResult->retval[0]->text;
+ $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::LABEL] = $tmpResult->retval[0]->text;
}
else
{
- $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::LABEL] = null;
+ $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::LABEL] = null;
}
}
//
- if (isset($jsonSchema->{UDFWidgetTpl::TITLE}))
+ if (isset($jsonSchema->{UDFLib::TITLE}))
{
$tmpResult = $this->_ci->phraseslib->getPhrases(
UDFWidget::PHRASES_APP_NAME,
DEFAULT_LEHREINHEIT_SPRACHE,
- $jsonSchema->{UDFWidgetTpl::TITLE},
+ $jsonSchema->{UDFLib::TITLE},
null,
null,
'no'
);
if (hasData($tmpResult))
{
- $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::TITLE] = $tmpResult->retval[0]->text;
+ $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::TITLE] = $tmpResult->retval[0]->text;
}
else
{
- $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::TITLE] = null;
+ $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::TITLE] = null;
}
}
//
- if (isset($jsonSchema->{UDFWidgetTpl::PLACEHOLDER}))
+ if (isset($jsonSchema->{UDFLib::PLACEHOLDER}))
{
$tmpResult = $this->_ci->phraseslib->getPhrases(
UDFWidget::PHRASES_APP_NAME,
DEFAULT_LEHREINHEIT_SPRACHE,
- $jsonSchema->{UDFWidgetTpl::PLACEHOLDER},
+ $jsonSchema->{UDFLib::PLACEHOLDER},
null,
null,
'no'
);
if (hasData($tmpResult))
{
- $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::PLACEHOLDER] = $tmpResult->retval[0]->text;
+ $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::PLACEHOLDER] = $tmpResult->retval[0]->text;
}
else
{
- $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::PLACEHOLDER] = null;
+ $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::PLACEHOLDER] = null;
}
}
}
@@ -384,38 +383,38 @@ class UDFWidget extends UDFWidgetTpl
private function _setValidationAttributes($jsonSchema)
{
// Validation
- $this->_args[Widget::HTML_ARG_NAME][UDFWidget::REQUIRED] = null;
- $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::REGEX] = null;
- $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::MAX_VALUE] = null;
- $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::MIN_VALUE] = null;
+ $this->_args[HTMLWidget::HTML_ARG_NAME][UDFWidget::REQUIRED] = null;
+ $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::REGEX] = null;
+ $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::MAX_VALUE] = null;
+ $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::MIN_VALUE] = null;
if (isset($jsonSchema->validation))
{
- if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::REGEX})
- && is_array($jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::REGEX}))
+ if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::REGEX})
+ && is_array($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::REGEX}))
{
- foreach($jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::REGEX} as $regex)
+ foreach($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::REGEX} as $regex)
{
if ($regex->language === UDFWidget::REGEX_LANGUAGE)
{
- $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::REGEX] = $regex->expression;
+ $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::REGEX] = $regex->expression;
}
}
}
- if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::REQUIRED}))
+ if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::REQUIRED}))
{
- $this->_args[Widget::HTML_ARG_NAME][UDFWidget::REQUIRED] = $jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::REQUIRED};
+ $this->_args[HTMLWidget::HTML_ARG_NAME][UDFWidget::REQUIRED] = $jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::REQUIRED};
}
- if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::MAX_VALUE}))
+ if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::MAX_VALUE}))
{
- $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::MAX_VALUE] = $jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::MAX_VALUE};
+ $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::MAX_VALUE] = $jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::MAX_VALUE};
}
- if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::MIN_VALUE}))
+ if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::MIN_VALUE}))
{
- $this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::MIN_VALUE] = $jsonSchema->{UDFWidget::VALIDATION}->{UDFWidgetTpl::MIN_VALUE};
+ $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::MIN_VALUE] = $jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::MIN_VALUE};
}
}
}