Added a signature legal agreement warning and integrated the resource file (resx) as a JavaScript object into the _Layout.cshtml file. This enables the agreement warning to support multiple languages.
This commit is contained in:
33
EnvelopeGenerator.Web/Controllers/LocalizationController.cs
Normal file
33
EnvelopeGenerator.Web/Controllers/LocalizationController.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using EnvelopeGenerator.Application.Resources;
|
||||
using Ganss.Xss;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace EnvelopeGenerator.Web.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class LocalizationController : ControllerBase
|
||||
{
|
||||
private readonly IStringLocalizer<Resource> _localizer;
|
||||
private readonly ILogger<LocalizationController> _logger;
|
||||
private readonly HtmlSanitizer _sanitizer;
|
||||
|
||||
public LocalizationController(IStringLocalizer<Resource> localizer, ILogger<LocalizationController> logger, HtmlSanitizer sanitizer)
|
||||
{
|
||||
_localizer = localizer;
|
||||
_logger = logger;
|
||||
_sanitizer = sanitizer;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult GetLocalized([FromQuery] string[]? name = null, [FromQuery] string[]? ignore = null)
|
||||
{
|
||||
ignore ??= Array.Empty<string>();
|
||||
var pairs = name?.ToDictionary(n => n, n => _localizer[n].Value)
|
||||
?? _localizer.GetAllStrings().Where(ls => !ignore.Contains(ls.Name)).ToDictionary(ls => ls.Name, ls => ls.Value); ;
|
||||
return Ok(pairs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,11 +28,5 @@ namespace EnvelopeGenerator.Web.Controllers.Test
|
||||
|
||||
[HttpGet("culture")]
|
||||
public IActionResult GetCultures(string? lang = null) => lang is null ? Ok(_cultures) : Ok(_cultures[lang]);
|
||||
|
||||
[HttpGet("to-culture-info")]
|
||||
public IActionResult ToCultureInfo(string locale) => Ok(locale.ToCultureInfo());
|
||||
|
||||
[HttpGet("two-letter-iso-language-name")]
|
||||
public IActionResult TwoLetterISOLanguageName(string locale) => Ok(locale.TwoLetterISOLanguageName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
}
|
||||
@using DigitalData.Core.DTO;
|
||||
@using EnvelopeGenerator.Application.DTOs;
|
||||
@using Newtonsoft.Json
|
||||
@using Newtonsoft.Json.Serialization
|
||||
@model EnvelopeReceiverDto;
|
||||
@{
|
||||
ViewData["Title"] = _localizer[WebKey.SignDoc];
|
||||
@@ -88,11 +90,11 @@
|
||||
}
|
||||
@if (ViewData["DocumentBytes"] is byte[] documentBytes)
|
||||
{
|
||||
var settings = new Newtonsoft.Json.JsonSerializerSettings
|
||||
var settings = new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
};
|
||||
var envelopeReceiverJson = Newtonsoft.Json.JsonConvert.SerializeObject(Model, settings);
|
||||
var envelopeReceiverJson = JsonConvert.SerializeObject(Model, settings);
|
||||
var documentBase64String = Convert.ToBase64String(documentBytes);
|
||||
var envelopeKey = ViewData["EnvelopeKey"] as string;
|
||||
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
@using DigitalData.Core.API
|
||||
@using Newtonsoft.Json
|
||||
@{
|
||||
var nonce = _accessor.HttpContext?.Items["csp-nonce"] as string;
|
||||
}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
@@ -24,6 +29,13 @@
|
||||
<script src="~/js/util.js" asp-append-version="true"></script>
|
||||
<script src="~/js/api.js" asp-append-version="true"></script>
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
@{
|
||||
var lStrsJson = JsonConvert.SerializeObject(_localizer.ToDictionary()).TrySanitize(_sanitizer);
|
||||
}
|
||||
<script nonce="@nonce">
|
||||
var localized = @Html.Raw(lStrsJson)
|
||||
</script>
|
||||
|
||||
<main role="main">
|
||||
<partial name="_CookieConsentPartial" />
|
||||
@RenderBody()
|
||||
|
||||
@@ -177,52 +177,68 @@ class App {
|
||||
icon: 'warning',
|
||||
})
|
||||
return false
|
||||
|
||||
}
|
||||
|
||||
// Save changes before doing anything
|
||||
try {
|
||||
await this.Instance.save()
|
||||
} catch (e) {
|
||||
Swal.fire({
|
||||
title: 'Fehler',
|
||||
text: 'Umschlag konnte nicht signiert werden!',
|
||||
icon: 'error',
|
||||
})
|
||||
return false
|
||||
}
|
||||
return Swal.fire({
|
||||
title: localized.Confirmation,
|
||||
html: `<div class="text-start fs-6 p-0 m-0">${localized.SigAgree}</div>`,
|
||||
icon: "question",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#3085d6",
|
||||
cancelButtonColor: "#d33",
|
||||
confirmButtonText: localized.Finalize,
|
||||
cancelButtonText: localized.Review
|
||||
}).then(async (result) => {
|
||||
if (result.isConfirmed) {
|
||||
//---
|
||||
// Save changes before doing anything
|
||||
try {
|
||||
await this.Instance.save()
|
||||
} catch (e) {
|
||||
Swal.fire({
|
||||
title: 'Fehler',
|
||||
text: 'Umschlag konnte nicht signiert werden!',
|
||||
icon: 'error',
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
// Export annotation data and save to database
|
||||
try {
|
||||
const json = await this.Instance.exportInstantJSON()
|
||||
const postEnvelopeResult = await this.Network.postEnvelope(
|
||||
this.envelopeKey,
|
||||
this.currentDocument.id,
|
||||
json
|
||||
)
|
||||
// Export annotation data and save to database
|
||||
try {
|
||||
const json = await this.Instance.exportInstantJSON()
|
||||
const postEnvelopeResult = await this.Network.postEnvelope(
|
||||
this.envelopeKey,
|
||||
this.currentDocument.id,
|
||||
json
|
||||
)
|
||||
|
||||
if (postEnvelopeResult.fatal) {
|
||||
Swal.fire({
|
||||
title: 'Fehler',
|
||||
text: 'Umschlag konnte nicht signiert werden!',
|
||||
icon: 'error',
|
||||
})
|
||||
return false
|
||||
if (postEnvelopeResult.fatal) {
|
||||
Swal.fire({
|
||||
title: 'Fehler',
|
||||
text: 'Umschlag konnte nicht signiert werden!',
|
||||
icon: 'error',
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
if (postEnvelopeResult.error) {
|
||||
Swal.fire({
|
||||
title: 'Warnung',
|
||||
text: 'Umschlag ist nicht mehr verfügbar.',
|
||||
icon: 'warning',
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
//---
|
||||
}
|
||||
|
||||
if (postEnvelopeResult.error) {
|
||||
Swal.fire({
|
||||
title: 'Warnung',
|
||||
text: 'Umschlag ist nicht mehr verfügbar.',
|
||||
icon: 'warning',
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
else
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user