Skip to content

[3.0] Theme split (wave 4, part 15) — move the issue-warning page's script into profile.js - #9436

Open
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/theme-warning-script
Open

[3.0] Theme split (wave 4, part 15) — move the issue-warning page's script into profile.js#9436
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/theme-warning-script

Conversation

@albertlast

Copy link
Copy Markdown
Collaborator

Description

Part of the #7933 split, wave 4.
Profile area, first slice.

template_issueWarning() generated all of its JavaScript. populateNotifyTemplate() was
written out as one if branch per notification template, each carrying a whole message
body through Utils::escapeJavaScript(); updateSlider() the same, one branch per warning
level. The handlers were attached with onclick / onchange attributes, and a second
<script> block at the bottom of the page held the jQuery preview call.

The template now emits only the data:

var notification_templates = ['', '', ''];
var level_effects = {"0":"None.","10":"…","35":"…","60":"…"};

and profile.js — which every profile page already loads — carries modifyWarnNotify(),
populateNotifyTemplate(), updateSlider() and ajax_getTemplatePreview(), wiring itself
up on DOMContentLoaded. The preview call is fetch rather than $.ajax.

Two things changed shape

The current level is an <output name="cur_level" for="warning_level"> instead of
<span id="cur_level_div">, so the script reaches it as this.form.cur_level and does not
need to know an id. percent_format — which the text is built from, and which the old
inline script also used — rides along in a data-format attribute next to it, so the
string stays localised.

The Preview button is disabled while the notification is switched off, where it used
to be hidden. .button sets display: inline-block, and an author rule beats the
[hidden] rule the browser brings, so hidden does nothing to it — hiding it needs an
inline style. disabled says the same thing and picks up the styling index.css:175
already has for it. The "create a template" link beside it is a plain <span>, so that one
still hides.

Checked

Same page, before and after, on the slider (input now, so it tracks the drag rather than
waiting for release) — identical text at every stop:

slider text
0, 5 0% (None.) / 5% (None.)
10 10% (User will be added to moderator watch list.)
35 35% (All users posts will be moderated.)
60, 95, 100 60% / 95% / 100% (User will not be able to post.)

One thing that had to be got right: both operands are strings, so a plain >= compares
them as text and "100" sorts below "35". Number() on each side.

Also checked each of the three templates fills the body with the same text as before,
that picking the placeholder row leaves the body alone, that the notify checkbox enables
and disables the same four controls in both directions, and the preview both ways — a
good body renders into #box_preview, an empty one puts "You selected to notify the user
but did not fill in the subject/message fields"
into #profile_error. No console errors,
nothing in smf_log_errors.

The is_me branch draws the slider with no notification block at all, and the script
guards for that separately. It is not reachable through the menu as things stand
(Main.php gives the area 'own' => []), so it was exercised by granting that
temporarily.

Issues References (Fixes|Related|Closes)

Part of #7933

Co-Authored-By: live627 john@jbrock.us

The page generated all of its JavaScript from the template, which meant
one if branch per notification template, each carrying a whole message
body through Utils::escapeJavaScript(). The bodies and the level texts go
out as JSON now and profile.js does the rest, wiring itself up on
DOMContentLoaded instead of through onclick and onchange attributes.

Two things changed shape along the way:

The current level is an <output> rather than a span, so the script can
reach it as this.form.cur_level and does not have to know the id. It
keeps percent_format, which the string comes from, in a data attribute
next to it.

The Preview button is disabled rather than hidden while the notification
is switched off. .button sets display, and an author rule beats the
[hidden] rule the browser brings, so hiding it needs an inline style;
disabled says the same thing and picks up the styling that is already
there for it. The "create a template" link next to it is a plain span, so
that one does hide.

Signed-off-by: Mathias Alberts <mathiaspapealbert@hotmail.com>
Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
@jdarwood007 jdarwood007 added this to the 3.0 Alpha 5 milestone Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants