diff --git a/app/src/View/Helper/AlertHelper.php b/app/src/View/Helper/AlertHelper.php index b4b083af5..0c3d1ef68 100644 --- a/app/src/View/Helper/AlertHelper.php +++ b/app/src/View/Helper/AlertHelper.php @@ -32,19 +32,14 @@ use \Cake\View\Helper; use phpDocumentor\Reflection\Types\Boolean; -/** - * Helper which will produce Bootstrap based alert - * - * @param string $message Alert message - * @param string $type Define the type of Alert. The value should be one of - * [success,warning,danger,info]. Defaults to 'warning' - * @param boolean $dismissable Can the Alert be dismissed? Defaults to false. - * @param string|null $title Title to display (typically "Success", "Error", or "Warning"). Defaults to null. - * @param boolean $dis_text_dark Disable dark-text fonts for light|info color mode. - * @return mixed - a constructed HTML block - * @since COmanage Registry v5.0.0 - */ class AlertHelper extends Helper { + /** + * Map Alert Type to Icon + * + * @param string $type + * + * @return string + */ public function getAlertIcon(string $type): string { return match($type) { diff --git a/app/src/View/Helper/FieeldHelper.php b/app/src/View/Helper/FieeldHelper.php index e829b839e..39288877f 100644 --- a/app/src/View/Helper/FieeldHelper.php +++ b/app/src/View/Helper/FieeldHelper.php @@ -291,15 +291,19 @@ public function formField(string $fieldName, $fieldArgs = $fieldOptions ?? []; $fieldArgs['label'] = $fieldOptions['label'] ?? false; $fieldArgs['readonly'] = !$this->editable - || \boolval($fieldOptions['readonly']) + || (isset($fieldOptions['readonly']) && $fieldOptions['readonly']) || ($fieldName == 'plugin' && $this->action == 'edit'); // Selects, Checkboxes, and Radio Buttons use "disabled" $fieldArgs['disabled'] = $fieldArgs['readonly']; - $fieldArgs['required'] = $this->isReqField($fieldName) ?? boolval($fieldOptions['required']); + $fieldArgs['required'] = $this->isReqField($fieldName) + || (isset($fieldOptions['required']) && $fieldOptions['required']); - // Get the field type from the map of fields (e.g. 'boolean', 'string', 'timestamp') - $fieldType = $fieldType ?? $this->getFieldType($fieldName); + // Cause any select (except status) to render with a blank option, even + // if the field is required. This makes it clear when a value needs to be set. + // Note this will be ignored for non-select controls. + $fieldArgs['empty'] = !\in_array($fieldName, ['status', 'sync_status_on_delete'], true) + || (isset($fieldOptions['empty']) && $fieldOptions['empty']); // Remove prefix from field value if(!empty($fieldPrefix) && !empty($this->getEntity()->$fieldName)) { @@ -310,31 +314,23 @@ public function formField(string $fieldName, $this->getView()->set('vv_obj', $vv_obj); } - // Cause any select (except status) to render with a blank option, even - // if the field is required. This makes it clear when a value needs to be set. - // Note this will be ignored for non-select controls. - if(\in_array($fieldName, ['status', 'sync_status_on_delete'], true)) { - $fieldArgs['empty'] = false; - } elseif(isset($fieldOptions['empty'])) { - $fieldArgs['empty'] = $fieldOptions['empty']; - } else { - $fieldArgs['empty'] = true; - } - - // A boolean field is a checkbox. Set the label and class to improve rendering - // and accessibility. - if($fieldType === 'boolean') { - $fieldArgs['label'] = $fieldLabel; - $fieldArgs['class'] = 'form-check-input'; - } elseif($fieldType === 'date') { - return $this->dateField($fieldName, DateTypeEnum::DateOnly); - } elseif($fieldType == 'datetime' || $fieldType == 'timestamp') { - return $this->dateField($fieldName); - } - + // Get the field type from the map of fields (e.g. 'boolean', 'string', 'timestamp') + $fieldType = $fieldType ?? $this->getFieldType($fieldName); // Generate the form control or pass along the markup generated in a wrapper function - return $this->Form->control($fieldName, $fieldArgs); - + return match($fieldType) { + // A boolean field is a checkbox. Set the label and class to improve rendering + // and accessibility. + 'boolean' => $this->Form->control($fieldName, [ + // First import and then overwrite + ...$fieldArgs, + 'label' => $fieldLabel, + 'class' => 'form-check-input', + ]), + 'date' => $this->dateField($fieldName, DateTypeEnum::DateOnly), + 'datetime', + 'timestamp' => $this->dateField($fieldName), + default => $this->Form->control($fieldName, $fieldArgs) + }; } /** diff --git a/app/templates/element/form/listItem.php b/app/templates/element/form/listItem.php index 0d95d0355..a68337709 100644 --- a/app/templates/element/form/listItem.php +++ b/app/templates/element/form/listItem.php @@ -37,19 +37,25 @@ $this->set('fieldName', $arguments['fieldName']); $this->set('vv_field_arguments', $arguments); -// Additional classes calculation +// Class calculation by field Type $classes = match ($this->Fieeld->getFieldType($arguments['fieldName'])) { 'date', 'datetime', 'timestamp' => 'fields-datepicker ', + default => '' +}; + +// Class calculation by field name +$classes .= match ($arguments['fieldName']) { 'source_record' => 'source-record ', 'retry_interval', 'login' => 'subfield ', default => '' }; +// Class calculation by type of Info Div if(isset($arguments['autocomplete'])) { - $classes = 'fields-people-autocomplete '; + $classes .= 'fields-people-autocomplete '; } ?> diff --git a/app/templates/element/form/nameDiv.php b/app/templates/element/form/nameDiv.php index 45e80d0e6..e049384fe 100644 --- a/app/templates/element/form/nameDiv.php +++ b/app/templates/element/form/nameDiv.php @@ -61,7 +61,8 @@ // Override the default required behavior is the field has the required // option set -$optionsRequired = boolval($vv_field_arguments['fieldOptions']['required']); +$optionsRequired = isset($vv_field_arguments['fieldOptions']['required']) + && $vv_field_arguments['fieldOptions']['required']; // Extra class required for the grouped controls elements if(isset($groupedControls)) { diff --git a/app/templates/element/notify/alert.php b/app/templates/element/notify/alert.php index 2d316f8ea..d0e0af67a 100644 --- a/app/templates/element/notify/alert.php +++ b/app/templates/element/notify/alert.php @@ -39,6 +39,7 @@ $alertClass = "alert-{$type}"; $showButton = false; + if(isset($dismissible) && $dismissible) { $alertClass .= ' alert-dismissible'; $showButton = true; diff --git a/app/webroot/js/comanage/comanage.js b/app/webroot/js/comanage/comanage.js index f0d8b71fa..2d599837c 100644 --- a/app/webroot/js/comanage/comanage.js +++ b/app/webroot/js/comanage/comanage.js @@ -64,7 +64,7 @@ function showFields(fields, isPageLoad) { $('#' + field).closest('li').addClass('collapse show'); } else { $('#' + field).closest('li').collapse('show'); - } + } } }