Skip to content

Commit

Permalink
Allow for supplemental JavaScript and markup on a per-field basis.
Browse files Browse the repository at this point in the history
Provide an inline Jobs json formatter. (CFM-252)
  • Loading branch information
arlen committed Mar 13, 2023
1 parent b8f3f87 commit 18b33db
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
3 changes: 3 additions & 0 deletions app/resources/locales/en_US/field.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
17 changes: 11 additions & 6 deletions app/src/View/Helper/FieldHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public function control(string $fieldName,

// Specify a class on the <li> form control wrapper
$liClass = $cssClass;

// Collect any supplemental markup and/or JavaScript to pass along for field construction
$fieldSupplement = !empty($config['supplement']) ? $config['supplement'] : '';

// Remove prefix from field value
if(isset($config['prefix'], $this->getView()->get('vv_obj')->$fieldName)) {
Expand Down Expand Up @@ -154,8 +157,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();
}

Expand Down Expand Up @@ -275,9 +278,9 @@ protected function endLine(): string {
* @return string Form Info HTML
*/

protected function formInfoDiv(string $content): string {
protected function formInfoDiv(string $content, string $supplement): string {
return '<div class="field-info">
' . $content . '
' . $content . $supplement . '
</div>';
}

Expand All @@ -290,14 +293,16 @@ protected function formInfoDiv(string $content): string {
* @return string Form Info HTML
*/

protected function formInfoWithPrefixDiv(string $context, string $prefix): string {
protected function formInfoWithPrefixDiv(string $context, string $prefix, string $supplement): string {
$div = '<div class="field-info">' . PHP_EOL
. '<div class="input-group mb-3">' . PHP_EOL
. '<div class="input-group-prepend">' . PHP_EOL
. '<span class="input-group-text" id="basic-addon3">' . $prefix . '</span>'
. '</div>' . PHP_EOL
. $context
. '</div></div>';
. '</div>'
. $supplement
. '</div>';

return $div;
}
Expand Down
28 changes: 26 additions & 2 deletions app/templates/Jobs/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,32 @@ if($vv_action == 'view') {
status: (string)$vv_obj->percent_complete
);
}

print $this->Field->control('parameters');

$fieldSupplement = '
<div class="field-suppliment">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="format-toggle">
<label class="form-check-label" for="format-toggle">' .
__d('field','format')
. '</label>
</div>
</div>
<script>
parametersValue = $("#parameters").val();
parametersJSON = JSON.parse(parametersValue);
$("#format-toggle").click(function() {
if($(this).is(":checked")) {
$("#parameters").val(JSON.stringify(parametersJSON, null, 4));
paramsHeight = Object.keys(parametersJSON).length + 6 + "em";
$("#parameters").css("height",paramsHeight);
} else {
$("#parameters").val(parametersValue);
$("#parameters").css("height","4em");
}
});
</script>
';
print $this->Field->control('parameters', [], null, ['supplement' => $fieldSupplement]);

print $this->Field->control('register_time');

Expand Down

0 comments on commit 18b33db

Please sign in to comment.