Skip to content
Merged
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
59 changes: 46 additions & 13 deletions Web/Resgrid.Web/Areas/User/Views/Dispatch/ViewCall.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -964,22 +964,55 @@
<script type="text/javascript">
var callId = @(Model.Call.CallId);

var newCallForm = $('#fb-template').formRender({
dataType: 'json',
formData: '@Html.Raw(Model.Call.CallFormData)',
notify: {
error: function(message) {

},
success: function(message) {
$('input, textarea, select', '.rendered-form').attr('readonly', true).attr('disabled', true)
},
warning: function(message) {
var callFormData = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model.Call.CallFormData ?? string.Empty, new Newtonsoft.Json.JsonSerializerSettings { StringEscapeHandling = Newtonsoft.Json.StringEscapeHandling.EscapeHtml }));

// CallFormData is API-writable free text; older/external clients stored plain text
// (e.g. "Submitted ...") which formRender's JSON.parse can't handle. Only render the
// form for valid formBuilder data, otherwise show the raw text read-only.
var callFormFields = null;
try {
callFormFields = JSON.parse(callFormData);
} catch (e) { }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Kody Rules high

The empty catch block on line 975 swallows the JSON.parse exception silently, leaving no diagnostic trail for malformed CallFormData despite Rule [28] requiring caught exceptions be logged with context. Add a minimal console.warn with the callId inside the catch block.

Kody rule violation: Avoid empty catch blocks

Prompt for LLM

File Web/Resgrid.Web/Areas/User/Views/Dispatch/ViewCall.cshtml:

Line 975:

The empty catch block on line 975 swallows the JSON.parse exception silently, leaving no diagnostic trail for malformed CallFormData despite Rule [28] requiring caught exceptions be logged with context. Add a minimal console.warn with the callId inside the catch block.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.


if (Array.isArray(callFormFields)) {
// form-render inserts label/option/description content as HTML and its sanitizer is a

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Kody Rules low

The var declaration of newCallForm violates Rule [37] which requires const/let for variable declarations. Since newCallForm is assigned once and never reassigned, replace var with const.

Kody rule violation: Always use const and let

Prompt for LLM

File Web/Resgrid.Web/Areas/User/Views/Dispatch/ViewCall.cshtml:

Line 978:

The var declaration of newCallForm violates Rule [37] which requires const/let for variable declarations. Since newCallForm is assigned once and never reassigned, replace var with const.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

// no-op unless DOMPurify is loaded (it isn't). CallFormData is API-writable, so escape
// the HTML-rendered props and show them as plain text.
var escapeHtml = function (value) {
return typeof value === 'string'
? value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;')
: value;
};
callFormFields.forEach(function (field) {
if (!field || typeof field !== 'object') return;
field.label = escapeHtml(field.label);
field.description = escapeHtml(field.description);
if (Array.isArray(field.values)) {
field.values.forEach(function (option) {
if (option && typeof option === 'object') option.label = escapeHtml(option.label);
});
}
});

var newCallForm = $('#fb-template').formRender({
dataType: 'json',
formData: JSON.stringify(callFormFields),
notify: {
error: function(message) {

},
success: function(message) {
$('input, textarea, select, button', '#fb-template .rendered-form').attr('readonly', true).attr('disabled', true)
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
warning: function(message) {

}
}
}

});
});
} else if (callFormData) {
$('#fb-template').text(callFormData);
}
</script>

<script src="~/js/app/common/signalr/resgrid.common.signalr.js" type="text/javascript"></script>
Expand Down
Loading