Skip to content

Commit 4130e97

Browse files
rpgmemclaude
andauthored
feat(reregistration): per-audience editable Termo de Ciência (form + ficha PDF) (#396)
The acknowledgment notice was hardcoded in both the reregistration form renderer and the ficha PDF template. It is now a display-only `acknowledgment` standard field whose HTML lives in field_options['html'], edited per-audience via wp_editor in the Custom Fields editor and propagated to descendants by the existing "Replicate lists to children" action. - New `acknowledgment` field type (display-only): skipped during value collection, validation and persistence. - Seeded per-audience with the shipped default notice (ReregistrationFieldOptions::get_default_termo_ciencia_html), which is also the render-time fallback for audiences predating the field. - Form renders the per-audience HTML block; ficha injects {{termo_ciencia}} via a dedicated replace so the notice's links survive (the per-variable allowlist omits <a>). - Admin: always-visible wp_editor in the acknowledgment row; builder JS collects the HTML and toggles the editor by type. https://claude.ai/code/session_01BEUEoUQmxb5d7akkVmaSVY Co-authored-by: Claude <noreply@anthropic.com>
1 parent 64be3d7 commit 4130e97

18 files changed

Lines changed: 396 additions & 34 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ The format follows [Keep a Changelog] (https://keepachangelog.com/en/1.1.0/).
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- **The "Termo de Ciência" (acknowledgment notice) is now editable per-audience.** It was hardcoded in two places — the reregistration form and the ficha PDF template — so changing the wording meant a code edit. It is now a display-only `acknowledgment` standard field stored in `wp_ffc_custom_fields.field_options['html']`, edited with the WordPress visual editor (`wp_editor`) inside the audience's Reregistration Fields section. Both the form's acknowledgment fieldset and the ficha PDF's section 6 render from this field (single source of truth), and "Replicate lists to children" propagates it to descendant audiences like any other standard field's options. Audiences that predate the field fall back to the shipped default notice (`ReregistrationFieldOptions::get_default_termo_ciencia_html()`), so existing forms are unchanged until edited. The block carries no user input — it's skipped during value collection, validation and persistence.
13+
1014
### Fixed
1115

1216
- **Ficha PDF: Divisão and Setor cells printed the literal placeholder instead of the values.** `default_ficha_template.html` referenced `{{divisao}}` / `{{setor}}`, but `FichaGenerator` only ever emits the combined `divisao_setor` value (`"<parent> - <child>"`), so neither placeholder was substituted. The generator now also exposes each `dependent_select` field's two halves as `{{<key>_parent}}` / `{{<key>_child}}` (the combined `{{<key>}}` form stays for back-compat), and the template's Divisão/Setor cells point at `{{divisao_setor_parent}}` / `{{divisao_setor_child}}`. The standard-field variable building moved into the unit-tested `FichaGenerator::build_standard_field_variables()`.

assets/js/ffc-custom-fields-admin.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@
8686
return;
8787
}
8888

89+
// Flush any TinyMCE (wp_editor) instances back to their textareas so
90+
// the acknowledgment HTML we read below reflects unsaved edits.
91+
if (window.tinymce && typeof window.tinymce.triggerSave === 'function') {
92+
window.tinymce.triggerSave();
93+
}
94+
8995
var fields = [];
9096
$('#ffc-custom-fields-list .ffc-custom-field-row').each(function (idx) {
9197
var $row = $(this);
@@ -120,6 +126,7 @@
120126
mask: $row.find('.ffc-field-mask').val() || '',
121127
choices: choices,
122128
groups: groups,
129+
html: $row.find('.ffc-field-html-container textarea').val() || '',
123130
help_text: $row.find('.ffc-field-help').val(),
124131
format: $row.find('.ffc-field-format').val(),
125132
custom_regex: $row.find('.ffc-field-regex').val(),
@@ -248,8 +255,10 @@
248255
var isSelect = (type === 'select');
249256
var isDependent = (type === 'dependent_select');
250257
var isWorkingHours = (type === 'working_hours');
258+
var isAcknowledgment = (type === 'acknowledgment');
251259
$row.find('.ffc-field-options-container').toggle(isSelect);
252260
$row.find('.ffc-field-groups-container').toggle(isDependent);
261+
$row.find('.ffc-field-html-container').toggle(isAcknowledgment);
253262
// Hide format validation for types that don't support it
254263
$row.find('.ffc-field-format').closest('.ffc-field-detail-row').toggle(!isWorkingHours);
255264
}

assets/js/ffc-custom-fields-admin.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

html/default_ficha_template.html

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,7 @@
148148
<div style="margin-bottom: 6px">
149149
<div style="font-size: 9pt;font-weight: bold;color: #000;text-transform: uppercase;letter-spacing: 1px;padding-bottom: 2px;border-bottom: 1px solid #e8e8e8;margin-bottom: 3px">6. Termo de Ciência</div>
150150
<div style="font-size: 7.5pt;color: #333;line-height: 1.3">
151-
<p style="margin: 0 0 4px">Eu, em exercício na Diretoria Regional de Educação de São Miguel – DRE-MP, declaro estar ciente das orientações para o ano corrente:</p>
152-
<ol style="margin: 0 0 0 14px;padding: 0">
153-
<li style="margin-bottom: 3px"><strong>Declaração de Família WEB:</strong> a Declaração de Família Web deverá ser feita dentro do mês de aniversário do servidor, por meio do site: https://www.declaracaofamilia.iprem.prefeitura.sp.gov.br/Login. Após, deverá ser impressa e entregue no Setor de Vida Funcional, para arquivo em prontuário;</li>
154-
<li style="margin-bottom: 3px"><strong>Recadastramento Auxílio Transporte:</strong> Permanecem as mesmas orientações para aqueles que fazem jus ao recebimento do auxílio, lembrando que o recadastramento deverá ser efetuado no mês do aniversário, e o servidor deverá providenciar o recadastramento do Auxílio Transporte ANTES de efetuar o recadastramento anual (prova de vida);</li>
155-
<li style="margin-bottom: 3px"><strong>Recadastramento Anual (Prova de Vida):</strong> Permanecem as mesmas orientações, lembrando que o RG com data de expedição acima de 10 anos não será aceito, e o servidor deverá providenciar novo documento antes de efetuar o recadastramento;</li>
156-
<li style="margin-bottom: 3px"><strong>Declaração de Bens (SISPATRI):</strong> Permanecem as mesmas orientações, lembrando que deverá ser feita após o encerramento do prazo da Receita Federal, do dia 1 ao 30 do mês de Junho, por meio do site: https://controladoriageralbens.prefeitura.sp.gov.br/PaginasPublicas/login.aspx;</li>
157-
<li style="margin-bottom: 3px"><strong>Antecipação de 13º Salário:</strong> A solicitação poderá ser preenchida e entregue à Unidade de RH a partir do 1º dia útil do exercício a que se refere a antecipação, independente do mês de aniversário do servidor.</li>
158-
<li style="margin-bottom: 3px"><strong>Entrega de Atestados Médicos/Odontológicos com pedido de Afastamento a partir de 1 (um) dia:</strong> Reiteramos que, qualquer pedido de afastamento para tratamento de saúde (pessoal ou de familiar) deverá ser informado imediatamente à chefia, mediante apresentação do atestado médico/odontológico. Em seguida, a documentação deverá ser entregue ao Setor de Vida Funcional EM MÃOS ou digitalizada para o e-mail: rhvidafuncionaldremp@sme.prefeitura.sp.gov.br. Importante: O setor de Vida Funcional e a Chefia não se responsabilizam pelos atestados deixados no livro de ponto ou na pasta destinada exclusivamente às Declarações de Horário, bem como os que forem entregues fora do prazo legal para agendamento de perícia, se for o caso.</li>
159-
</ol>
151+
{{termo_ciencia}}
160152
</div>
161153
</div>
162154

includes/audience/class-ffc-audience-admin-audience.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ private function render_custom_fields_section( int $audience_id ): void {
432432
<div class="ffc-field-options-container" style="display:none;">
433433
<textarea class="ffc-field-choices" placeholder="<?php esc_attr_e( 'Options (one per line)', 'ffcertificate' ); ?>" rows="3"></textarea>
434434
</div>
435+
<div class="ffc-field-html-container" style="display:none;">
436+
<textarea class="ffc-field-html" placeholder="<?php esc_attr_e( 'Notice HTML (supports basic formatting and links)', 'ffcertificate' ); ?>" rows="6"></textarea>
437+
</div>
435438
<div class="ffc-field-validation-container">
436439
<select class="ffc-field-format">
437440
<option value=""><?php esc_html_e( 'No format validation', 'ffcertificate' ); ?></option>
@@ -539,6 +542,28 @@ private function render_custom_field_row( object $field, array $field_types, arr
539542
<input type="checkbox" class="ffc-field-sensitive" <?php checked( $is_sensitive ); ?><?php echo esc_attr( $locked_attr ); ?>> <?php esc_html_e( 'Sensitive', 'ffcertificate' ); ?>
540543
</label>
541544
</div>
545+
<?php if ( 'acknowledgment' === $field->field_type ) : ?>
546+
<div class="ffc-field-html-container">
547+
<p class="description"><?php esc_html_e( 'Notice shown at the end of the reregistration form and printed on the ficha PDF. Use "Replicate lists to children" to push it to descendant audiences.', 'ffcertificate' ); ?></p>
548+
<?php
549+
wp_editor(
550+
isset( $options['html'] ) ? (string) $options['html'] : '',
551+
'ffc_termo_' . (int) $field->id,
552+
array(
553+
'textarea_name' => 'ffc_termo_' . (int) $field->id,
554+
'textarea_rows' => 12,
555+
'media_buttons' => false,
556+
'teeny' => true,
557+
'tinymce' => array(
558+
'toolbar1' => 'bold,italic,underline,bullist,numlist,link,unlink,undo,redo',
559+
'toolbar2' => '',
560+
),
561+
'quicktags' => array( 'buttons' => 'strong,em,link,ul,ol,li,close' ),
562+
)
563+
);
564+
?>
565+
</div>
566+
<?php endif; ?>
542567
<div class="ffc-field-details-row" style="display:none;">
543568
<input type="text" class="ffc-field-key" placeholder="<?php esc_attr_e( 'field_key', 'ffcertificate' ); ?>" value="<?php echo esc_attr( $field->field_key ); ?>"<?php echo esc_attr( $locked_attr ); ?>>
544569
<input type="text" class="ffc-field-profile-key" placeholder="<?php esc_attr_e( 'profile_key (optional)', 'ffcertificate' ); ?>" value="<?php echo esc_attr( $profile_key ); ?>"<?php echo esc_attr( $locked_attr ); ?>>

includes/audience/class-ffc-audience-loader.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,12 @@ function ( $c ) {
813813
$options['groups'] = $groups;
814814
}
815815
}
816+
// acknowledgment rich-text block (display-only field). Only
817+
// stored when non-empty so a bulk save never wipes an existing
818+
// notice (mirrors the standard-field wipe guard below).
819+
if ( isset( $field_data['html'] ) && '' !== trim( (string) $field_data['html'] ) ) {
820+
$options['html'] = wp_kses_post( (string) $field_data['html'] );
821+
}
816822

817823
// Build validation_rules JSON.
818824
$rules = array();

includes/reregistration/class-ffc-custom-field-repository.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ protected static function cache_group(): string {
5252
'checkbox',
5353
'textarea',
5454
'working_hours',
55+
'acknowledgment',
56+
);
57+
58+
/**
59+
* Display-only field types — they render static content (no user input),
60+
* so they're skipped during value collection, validation and persistence.
61+
* Their content lives in `field_options` (e.g. `acknowledgment` → `html`).
62+
*/
63+
public const DISPLAY_ONLY_TYPES = array(
64+
'acknowledgment',
5565
);
5666

5767
/**

0 commit comments

Comments
 (0)