Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💄 Transition validation markup #666

Open
wants to merge 1 commit into
base: support/3.2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pages/UI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,8 @@ function DisplayNavigatorGroupTab($oP)
if (count($aErrors) == 0)
{
$sIssues = '';
/** @var CoreCannotSaveObjectException|null $oException */
$oException = null;
$bApplyStimulus = true;
list($bRes, $aIssues) = $oObj->CheckToWrite(); // Check before trying to write the object
if ($bRes)
Expand All @@ -1315,6 +1317,11 @@ function DisplayNavigatorGroupTab($oP)
$oObj = MetaModel::GetObject(get_class($oObj), $oObj->GetKey());
$oObj->UpdateObjectFromPostedForm('', array_keys($aExpectedAttributes), $aExpectedAttributes);
$sIssues = $e->getMessage();

if($e instanceof CoreCannotSaveObjectException) {
$oException = $e;
}
Comment on lines 1319 to +1323
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you would do this instead? Then there's no need to do the if/else later on.

Suggested change
$sIssues = $e->getMessage();
if($e instanceof CoreCannotSaveObjectException) {
$oException = $e;
}
$sIssues = $e->getHtmlMessage();

(correct styling would still something to be done in CSS, maybe separate PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether or not we can expect other exceptions here, which don't support the getHtmlMessage(), so I was being cautious :)

Copy link
Contributor

@Hipska Hipska Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, CoreException doesn’t seem to have this method 🤔

Then maybe just do getHtmlMessage when it exists and the normal getMessage otherwise?


}
}
else
Expand Down Expand Up @@ -1355,7 +1362,7 @@ function DisplayNavigatorGroupTab($oP)
$sMessage = $e->getMessage();
$sSeverity = 'info';
}
$sIssueDesc = Dict::Format('UI:ObjectCouldNotBeWritten',$sIssues);
$sIssueDesc = ($oException !== null ? '<div style="display: block;"><style scoped> ul { list-style-type: disc; } </style>'.$oException->getHtmlMessage().'</div>' : Dict::Format('UI:ObjectCouldNotBeWritten', $sIssues));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While not ideal, this will be easier to maintain than a CSS rule somewhere in a file.

The main issues:

  • Error modal uses flex.
  • The "ul" element loses its standard formatting by default in iTop.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ErrorModal should be fixed IMHO

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, in the backoffice when you want HTML to retrieve its standard style like for lists, surround it with the .ibo-is-html-content.

I would strongly be against inline style like this. A dedicated rule in the right file would be better.

That being said, you should ping @jf-cbd or @rquetiez , they worked on error messages and removing/sanitizing HTML errors last summer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try the .ibo-is-html-content when I find some time.
Not sure if that would also change the display to block or if there's another CSS class which we can use.

$oP->add_ready_script("CombodoModal.OpenErrorModal('".addslashes($sIssueDesc)."');");
}
else
Expand Down