From c1b8445d772b55f8e6d49ced40c1baae5d8ed79c Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Fri, 26 Apr 2024 10:45:41 +0300 Subject: [PATCH] CoSettings --- app/templates/ApiUsers/fields.inc | 8 +- app/templates/CoSettings/fields.inc | 121 ++++++++++++------ app/templates/element/form/fieldDiv.php | 10 +- .../form/{infoDiv.php => infoDiv/default.php} | 0 .../element/form/infoDiv/grouped.php | 51 ++++++++ .../{infoDivStatus.php => infoDiv/status.php} | 1 - .../withPrefix.php} | 0 app/templates/element/form/listItem.php | 9 +- app/templates/element/form/nameDiv.php | 21 ++- 9 files changed, 161 insertions(+), 60 deletions(-) rename app/templates/element/form/{infoDiv.php => infoDiv/default.php} (100%) create mode 100644 app/templates/element/form/infoDiv/grouped.php rename app/templates/element/form/{infoDivStatus.php => infoDiv/status.php} (99%) rename app/templates/element/form/{infoDivWithPrefix.php => infoDiv/withPrefix.php} (100%) diff --git a/app/templates/ApiUsers/fields.inc b/app/templates/ApiUsers/fields.inc index 007a2681b..f5390c24e 100644 --- a/app/templates/ApiUsers/fields.inc +++ b/app/templates/ApiUsers/fields.inc @@ -26,11 +26,11 @@ */ // This view does not support read-only -if($vv_action == 'add' || $vv_action == 'edit') { +if($vv_action == 'add' || $vv_action == 'edit') { if($vv_cur_co->id == 1) { print $this->element('banner', __d('information', 'api.cmp')); } - + // AR-ApiUser-3 For namespacing purposes, API Users are named with a prefix consisting of the string "co_#.". print $this->element('form/listItem', [ 'arguments' => [ @@ -38,7 +38,7 @@ if($vv_action == 'add' || $vv_action == 'edit') { 'prefix' => 'co_' . $vv_cur_co->id . '.' ] ]); - + // We link to the "Generate" button on edit only $generateLink = []; $labelIsTextOnly = false; @@ -67,14 +67,12 @@ if($vv_action == 'add' || $vv_action == 'edit') { ] ]); - print $this->element('form/listItem', [ 'arguments' => [ 'fieldName' => 'status', // select ] ]); - print $this->element('form/listItem', [ 'arguments' => [ 'fieldName' => 'valid_from', // timestamp diff --git a/app/templates/CoSettings/fields.inc b/app/templates/CoSettings/fields.inc index 983f808ea..0b0968ba9 100644 --- a/app/templates/CoSettings/fields.inc +++ b/app/templates/CoSettings/fields.inc @@ -28,50 +28,95 @@ Field->control('required_fields_address', ['suppressBlank' => true]); - - print $this->Field->control('default_address_type_id'); - - print $this->Field->control('default_email_address_type_id'); - - print $this->Field->control('default_identifier_type_id'); - - print $this->Field->control('default_name_type_id'); + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'required_fields_address', + 'options' => ['empty' => false] + ]]); - print $this->Field->control('permitted_fields_name', ['suppressBlank' => true]); - - print $this->Field->control('required_fields_name', ['suppressBlank' => true]); + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'default_address_type_id' + ]]); - print $this->Field->control('default_pronoun_type_id'); + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'default_email_address_type_id' + ]]); - print $this->Field->control('default_telephone_number_type_id'); + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'default_identifier_type_id' + ]]); - print $this->Field->control('permitted_fields_telephone_number', ['suppressBlank' => true]); - - print $this->Field->control('default_url_type_id'); - - print $this->Field->control('search_global_limit'); - - print $this->Field->control('search_global_limited_models'); + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'default_name_type_id' + ]]); - print $this->Field->groupedControls( - [ - 'person_picker_email_address_type_id' => [ - 'options' => [ - 'suppressBlank' => true, - 'label' => __d('field', 'mail'), + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'permitted_fields_name', + 'options' => ['empty' => false] + ]]); + + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'required_fields_name', + 'options' => ['empty' => false] + ]]); + + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'default_pronoun_type_id' + ]]); + + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'default_telephone_number_type_id' + ]]); + + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'permitted_fields_telephone_number', + 'options' => ['empty' => false] + ]]); + + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'default_url_type_id' + ]]); + + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'search_global_limit' + ]]); + + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'search_global_limited_models' + ]]); + + print $this->element('form/listItem', [ + 'arguments' => [ + 'fieldName' => 'person_picker_display_fields', + 'groupedControls' => [ + // each key is the fieldName of the control we are going to create + 'person_picker_email_address_type_id' => [ + 'options' => [ + 'empty' => true, + 'label' => __d('field', 'mail'), + ], ], - ], - 'person_picker_identifier_type_id' => [ - 'options' => [ - 'suppressBlank' => true, - 'label' => __d('field', 'identifier'), + 'person_picker_identifier_type_id' => [ + 'options' => [ + 'empty' => true, + 'label' => __d('field', 'identifier'), + ], ], + 'person_picker_display_types' => [ + 'singleRowItem' => true + ] ], - 'person_picker_display_types' => [ - 'singleRowItem' => true - ] - ], - 'person_picker_display_fields' - ); + ]]); } diff --git a/app/templates/element/form/fieldDiv.php b/app/templates/element/form/fieldDiv.php index 6248982b3..c494c2fdc 100644 --- a/app/templates/element/form/fieldDiv.php +++ b/app/templates/element/form/fieldDiv.php @@ -33,14 +33,16 @@ element('form/nameDiv'); - + // Info Div if(isset($vv_field_arguments['prefix'])) { - print $this->element('form/infoDivWithPrefix'); + print $this->element('form/infoDiv/withPrefix'); } elseif(isset($vv_field_arguments['status'])) { - print $this->element('form/infoDivStatus'); + print $this->element('form/infoDiv/status'); + } elseif(isset($vv_field_arguments['groupedControls'])) { + print $this->element('form/infoDiv/grouped'); } else { - print $this->element('form/infoDiv'); + print $this->element('form/infoDiv/default'); } ?> \ No newline at end of file diff --git a/app/templates/element/form/infoDiv.php b/app/templates/element/form/infoDiv/default.php similarity index 100% rename from app/templates/element/form/infoDiv.php rename to app/templates/element/form/infoDiv/default.php diff --git a/app/templates/element/form/infoDiv/grouped.php b/app/templates/element/form/infoDiv/grouped.php new file mode 100644 index 000000000..d5278f945 --- /dev/null +++ b/app/templates/element/form/infoDiv/grouped.php @@ -0,0 +1,51 @@ + + +
+ $fieldArguments): ?> + +
+
+ Fieeld->formField($fieldName, ...$fieldArguments) ?> +
+
+ +
\ No newline at end of file diff --git a/app/templates/element/form/infoDivStatus.php b/app/templates/element/form/infoDiv/status.php similarity index 99% rename from app/templates/element/form/infoDivStatus.php rename to app/templates/element/form/infoDiv/status.php index 47443b023..0d117520c 100644 --- a/app/templates/element/form/infoDivStatus.php +++ b/app/templates/element/form/infoDiv/status.php @@ -33,7 +33,6 @@ if($link) { // Construct HTML for the requested link - if(!empty($link['label'])) { // Create a separate link after $status diff --git a/app/templates/element/form/infoDivWithPrefix.php b/app/templates/element/form/infoDiv/withPrefix.php similarity index 100% rename from app/templates/element/form/infoDivWithPrefix.php rename to app/templates/element/form/infoDiv/withPrefix.php diff --git a/app/templates/element/form/listItem.php b/app/templates/element/form/listItem.php index 2f9ef736a..cf4f50b3b 100644 --- a/app/templates/element/form/listItem.php +++ b/app/templates/element/form/listItem.php @@ -29,6 +29,13 @@ declare(strict_types = 1); // Make the element configuration available downstream +// XXX Even though we pass the parameters to the view globally +// they only live in the context of this element and its ancestors +// XXX Unfortunately CAKEPHP doe not create a viewvar space for the element +// parameters. As a result we do not know which one is which unles we: +// - add a prefix and create a namespace +// - wrap them in an array. +// We choose the latter. foreach($arguments as $key => $value) { $this->set($key, $value); } @@ -43,6 +50,6 @@ ?> -
  • +
  • element('form/fieldDiv')?>
  • diff --git a/app/templates/element/form/nameDiv.php b/app/templates/element/form/nameDiv.php index 07598383c..ad0562998 100644 --- a/app/templates/element/form/nameDiv.php +++ b/app/templates/element/form/nameDiv.php @@ -30,13 +30,13 @@ // $fieldName: parameter -$fieldType = $vv_field_types[$fieldName]; +$classes = ''; // We'll accept a fieldName of the form other_models.0.foo for forms that // request associated data. Note, however, that model names for language // keys are OtherModel, so we'll need to inflect. -$mn = $this->name; +$mn = $this->Fieeld->getModelName(); $fn = $fieldName; if(str_contains($fieldName, '.')) { @@ -47,28 +47,27 @@ $fn = $bits[2]; } -// First, try to autogenerate the field label (if we weren't given one). -$pluginDomain = (!empty($this->Fieeld->pluginName()) - ? Inflector::underscore($this->Fieeld->pluginName()) - : null); - -[$label, $desc] = $this->Fieeld->calculateLabelAndDescription($pluginDomain, $mn, $fn); +[$label, $desc] = $this->Fieeld->calculateLabelAndDescription($fn); $label = $labelText ?? $label; +// Extra class required for the grouped controls elements +if(isset($groupedControls)) { + $classes .= 'align-top '; +} ?> -
    +
    + && $this->Fieeld->getFieldType($fieldName) !== 'boolean'): ?> Form->label($fn, $label) ?> Fieeld->isEditable() && in_array($fn, $vv_required_fields, true)) { + if($this->Fieeld->isEditable() && in_array($fn, $this->Fieeld->getReqFields(), true)) { print $this->element('form/requiredSpan'); } ?>