From c048c8bb10fe734051fd7c03279f13e32aa870f4 Mon Sep 17 00:00:00 2001 From: Arlen Johnson Date: Wed, 22 Mar 2023 08:59:17 -0400 Subject: [PATCH] Provide an inline Jobs json formatter. (CFM-252) (#83) * Allow for supplemental markup and/or JavaScript on a per-field basis. (CFM-252) * Shrink the size of field supplement markup slightly. (CFM-252) * Break field supplement into a two-part array "beforeField" and "afterField" (CFM-252) --- app/resources/locales/en_US/field.po | 3 ++ app/src/View/Helper/FieldHelper.php | 47 +++++++++++++++++++--------- app/templates/Jobs/fields.inc | 33 +++++++++++++++++-- app/webroot/css/co-base.css | 3 ++ 4 files changed, 70 insertions(+), 16 deletions(-) diff --git a/app/resources/locales/en_US/field.po b/app/resources/locales/en_US/field.po index 28273eb27..61d51b6a1 100644 --- a/app/resources/locales/en_US/field.po +++ b/app/resources/locales/en_US/field.po @@ -312,6 +312,9 @@ msgstr "Limit Global Search Scope" msgid "CoSettings.search_global_limited_models.desc" msgstr "If true, Global Search will only search Names, Email Addresses, and Identifiers. This may result in faster searches for larger deployments." +msgid "format" +msgstr "format" + msgid "GroupMembers.source" msgstr "Membership Source" diff --git a/app/src/View/Helper/FieldHelper.php b/app/src/View/Helper/FieldHelper.php index 02f014cdb..bc0664d77 100644 --- a/app/src/View/Helper/FieldHelper.php +++ b/app/src/View/Helper/FieldHelper.php @@ -99,6 +99,10 @@ public function control(string $fieldName, // Specify a class on the
  • form control wrapper $liClass = $cssClass; + + // Collect any supplemental markup and/or JavaScript to pass along for field construction. + // Suppliment is an array: supplement['beforeField' => 'string', 'afterField' => 'string']. + $fieldSupplement = !empty($config['supplement']) ? $config['supplement'] : []; // Remove prefix from field value if(isset($config['prefix'], $this->getView()->get('vv_obj')->$fieldName)) { @@ -154,8 +158,8 @@ public function control(string $fieldName, return $this->startLine($liClass) . $this->formNameDiv($fieldName, $labelText) . ( !empty($config['prefix']) ? - $this->formInfoWithPrefixDiv($controlCode, $config['prefix']) : - $this->formInfoDiv($controlCode) ) + $this->formInfoWithPrefixDiv($controlCode, $config['prefix'], $fieldSupplement) : + $this->formInfoDiv($controlCode, $fieldSupplement) ) . $this->endLine(); } @@ -275,10 +279,18 @@ protected function endLine(): string { * @return string Form Info HTML */ - protected function formInfoDiv(string $content): string { - return '
    - ' . $content . ' -
    '; + protected function formInfoDiv(string $content, array $supplement): string { + $div = '
    ' . PHP_EOL; + if(!empty($supplement['beforeField'])) { + $div .= $supplement['beforeField'] . PHP_EOL; + } + $div .= $content . PHP_EOL; + if(!empty($supplement['afterField'])) { + $div .= $supplement['afterField'] . PHP_EOL; + } + $div .= '
    ' . PHP_EOL; + + return $div; } /** @@ -290,14 +302,21 @@ protected function formInfoDiv(string $content): string { * @return string Form Info HTML */ - protected function formInfoWithPrefixDiv(string $context, string $prefix): string { - $div = '
    ' . PHP_EOL - . '
    ' . PHP_EOL - . '
    ' . PHP_EOL - . '' . $prefix . '' - . '
    ' . PHP_EOL - . $context - . '
    '; + protected function formInfoWithPrefixDiv(string $context, string $prefix, array $supplement): string { + $div = '
    ' . PHP_EOL; + if(!empty($supplement['beforeField'])) { + $div .= $supplement['beforeField'] . PHP_EOL; + } + $div .= '
    ' . PHP_EOL; + $div .= '
    ' . PHP_EOL; + $div .= '' . $prefix . ''; + $div .= '
    ' . PHP_EOL; + $div .= $context; + $div .= '
    '; + if(!empty($supplement['afterField'])) { + $div .= $supplement['afterField'] . PHP_EOL; + } + $div .= '
    '; return $div; } diff --git a/app/templates/Jobs/fields.inc b/app/templates/Jobs/fields.inc index c646f41f8..71c3eee08 100644 --- a/app/templates/Jobs/fields.inc +++ b/app/templates/Jobs/fields.inc @@ -37,8 +37,37 @@ if($vv_action == 'view') { status: (string)$vv_obj->percent_complete ); } - - print $this->Field->control('parameters'); + + $fieldSupplement = + [ + 'beforeField' => ' +
    +
    + + +
    +
    + ', + 'afterField' => ' + + ' + ]; + print $this->Field->control('parameters', [], null, ['supplement' => $fieldSupplement]); print $this->Field->control('register_time'); diff --git a/app/webroot/css/co-base.css b/app/webroot/css/co-base.css index a2354152c..910eae59b 100644 --- a/app/webroot/css/co-base.css +++ b/app/webroot/css/co-base.css @@ -1175,6 +1175,9 @@ ul.form-list li.field-stack textarea { width: 100%; resize: vertical; } +ul.form-list .field-suppliment { + font-size: 0.9em; +} .checkbox { margin-bottom: 0.5em; }