From 51ccee4d1626fb259117f2e7ead120dd6e1ecba0 Mon Sep 17 00:00:00 2001 From: Paolo Date: Mon, 8 May 2017 11:39:21 +0200 Subject: [PATCH] 8th release --- application/libraries/WidgetLib.php | 44 ++++++++++++++++++++------ application/views/system/testudf.php | 30 ++++++++++++++++++ application/views/widgets/checkbox.php | 12 +++---- application/widgets/UDFWidget.php | 6 ++++ 4 files changed, 77 insertions(+), 15 deletions(-) diff --git a/application/libraries/WidgetLib.php b/application/libraries/WidgetLib.php index bb4a46566..cd139adb7 100644 --- a/application/libraries/WidgetLib.php +++ b/application/libraries/WidgetLib.php @@ -1040,10 +1040,14 @@ class CheckboxWidget 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_VALUES_ARRAY_NAME = 'VALUES_ARRAY'; + 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 VALUE_FIELD = 'value'; + // 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 CHECKED_VALUE = 'checkedValue'; + const CHECKED_ELEMENT = 'checkedElement'; /** * @@ -1053,9 +1057,9 @@ class CheckboxWidget extends Widget parent::__construct($name, $args, $htmlArgs); // - if (!isset($this->_args[CheckboxWidget::CHECKED_VALUE])) + if (!isset($this->_args[CheckboxWidget::CHECKED_ELEMENT])) { - $this->_args[CheckboxWidget::CHECKED_VALUE] = Widget::HTML_DEFAULT_VALUE; + $this->_args[CheckboxWidget::CHECKED_ELEMENT] = Widget::HTML_DEFAULT_VALUE; } } @@ -1081,7 +1085,7 @@ class CheckboxWidget extends Widget } else { - $this->_args[CheckboxWidget::WIDGET_DATA_VALUES_ARRAY_NAME] = $values->retval; + $this->_args[CheckboxWidget::WIDGET_DATA_ELEMENTS_ARRAY_NAME] = $values->retval; } } @@ -1104,19 +1108,41 @@ class CheckboxWidgetUDF extends CheckboxWidget */ public function render($parameters) { - $tmpValues = array(); + $tmpElements = array(); // foreach($parameters as $parameter) { // - if (is_string($parameter) || is_numeric($parameter)) + if ((is_array($parameter) && count($parameter) == 2) + || (is_string($parameter) || is_numeric($parameter)) + || (is_object($parameter) && isset($parameter->{PARENT::VALUE_FIELD}) && isset($parameter->{PARENT::DESCRIPTION_FIELD}))) { - array_push($tmpValues, $parameter); // + $element = new stdClass(); // + // + if (is_array($parameter) && count($parameter) == 2) + { + $element->{PARENT::VALUE_FIELD} = $parameter[0]; // + $element->{PARENT::DESCRIPTION_FIELD} = $parameter[1]; // + } + // + else if (is_string($parameter) || is_numeric($parameter)) + { + $element->{PARENT::VALUE_FIELD} = $parameter; // + $element->{PARENT::DESCRIPTION_FIELD} = $parameter; // + } + // + else if (is_object($parameter) && isset($parameter->{PARENT::VALUE_FIELD}) && isset($parameter->{PARENT::DESCRIPTION_FIELD})) + { + $element->{PARENT::VALUE_FIELD} = $parameter->{PARENT::VALUE_FIELD}; // + $element->{PARENT::DESCRIPTION_FIELD} = $parameter->{PARENT::DESCRIPTION_FIELD}; // + } + + array_push($tmpElements, $element); // } } - $this->setValuesArray(success($tmpValues)); + $this->setValuesArray(success($tmpElements)); $this->loadCheckboxView(); diff --git a/application/views/system/testudf.php b/application/views/system/testudf.php index 1d5815446..dca677e4f 100644 --- a/application/views/system/testudf.php +++ b/application/views/system/testudf.php @@ -91,6 +91,36 @@ ?> +
+ +
+ widgetlib->UDFWidget( + array( + UDFWidgetTpl::SCHEMA_ARG_NAME => 'public', + UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person', + UDFWidgetTpl::FIELD_ARG_NAME => 'disagree' + ), + array('id' => 'disagreeID', 'name' => 'disagreeName') + ); + ?> +
+ +
+ +
+ widgetlib->UDFWidget( + array( + UDFWidgetTpl::SCHEMA_ARG_NAME => 'public', + UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person', + UDFWidgetTpl::FIELD_ARG_NAME => 'dunno' + ), + array('id' => 'dunnoID', 'name' => 'dunnoName') + ); + ?> +
+ load->view("templates/footer"); ?> \ No newline at end of file diff --git a/application/views/widgets/checkbox.php b/application/views/widgets/checkbox.php index 531aca9c3..b73ebb24a 100644 --- a/application/views/widgets/checkbox.php +++ b/application/views/widgets/checkbox.php @@ -15,14 +15,14 @@ > {CheckboxWidget::VALUE_FIELD} == $checkedElement) { $checked = 'checked'; } @@ -30,10 +30,10 @@ - value="" + value="{CheckboxWidget::VALUE_FIELD}; ?>" > - + {CheckboxWidget::DESCRIPTION_FIELD}; ?> diff --git a/application/widgets/UDFWidget.php b/application/widgets/UDFWidget.php index 920be185c..0f6fe934c 100644 --- a/application/widgets/UDFWidget.php +++ b/application/widgets/UDFWidget.php @@ -205,6 +205,12 @@ class UDFWidget extends UDFWidgetTpl */ private function _renderCheckbox($jsonSchema) { + // + if (!isset($this->_args[CheckboxWidget::CHECKED_ELEMENT])) + { + $this->_args[CheckboxWidget::CHECKED_ELEMENT] = $jsonSchema->defaultValue; + } + $checkboxWidgetUDF = new CheckboxWidgetUDF($this->_name, $this->_args); $parameters = array();