EditHtml fix

This commit is contained in:
Pavel Vesely 2020-03-06 22:51:00 +01:00
parent ff18059b06
commit 8730ecc6ad

View File

@ -58,19 +58,28 @@
} }
else else
{ {
<button type="button" class="btn btn-secondary" @onclick="RawHTMLEditor">Raw HTML Editor</button> <button type="button" class="btn btn-secondary" @onclick="RawHtmlEditor">Raw HTML Editor</button>
} }
<button type="button" class="btn btn-success" @onclick="SaveContent">Save</button> <button type="button" class="btn btn-success" @onclick="SaveContent">Save</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink> <NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
<br /> <br/>
<br /> <br/>
<AuditInfo CreatedBy="@createdby" CreatedOn="@createdon" ModifiedBy="@modifiedby" ModifiedOn="@modifiedon"></AuditInfo> <AuditInfo CreatedBy="@createdby" CreatedOn="@createdon" ModifiedBy="@modifiedby" ModifiedOn="@modifiedon"></AuditInfo>
@code { @code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Edit; } }
public override string Title { get { return "Edit Html/Text"; } } public override SecurityAccessLevel SecurityAccessLevel
{
get { return SecurityAccessLevel.Edit; }
}
public override string Title
{
get { return "Edit Html/Text"; }
}
bool RichTextEditorMode = true; bool RichTextEditorMode = true;
bool _richTextEditorLoading = false;
RichTextEditor RichTextEditorHtml; RichTextEditor RichTextEditorHtml;
string content; string content;
string createdby; string createdby;
@ -80,18 +89,29 @@ else
protected override async Task OnAfterRenderAsync(bool firstRender) protected override async Task OnAfterRenderAsync(bool firstRender)
{ {
if (firstRender) try
{ {
try if (firstRender)
{ {
await LoadText(); if (content == null)
{
await LoadText();
}
} }
catch (Exception ex) else
{ {
await logger.LogError(ex, "An Error Occurred Loading Html/Text Content. " + ex.Message); if (_richTextEditorLoading)
AddModuleMessage(ex.Message, MessageType.Error); {
await RichTextEditorHtml.LoadContent(content);
_richTextEditorLoading = false;
}
} }
} }
catch (Exception ex)
{
await logger.LogError(ex, "An Error Occurred Loading Html/Text Content. " + ex.Message);
AddModuleMessage(ex.Message, MessageType.Error);
}
} }
private async Task LoadText() private async Task LoadText()
@ -117,20 +137,18 @@ else
private async Task RichTextEditor() private async Task RichTextEditor()
{ {
RichTextEditorMode = true; RichTextEditorMode = true;
//TODO: maybe exists better solution than delay. Without this editor becomes corrupted. _richTextEditorLoading = true;
await Task.Delay(100);
await RichTextEditorHtml.LoadContent(content);
StateHasChanged(); StateHasChanged();
} }
private async Task RawHTMLEditor() private async Task RawHtmlEditor()
{ {
if (RichTextEditorMode) if (RichTextEditorMode)
{ {
content = await this.RichTextEditorHtml.GetHTML(); content = await this.RichTextEditorHtml.GetHTML();
} }
RichTextEditorMode = false; RichTextEditorMode = false;
// await LoadText(); // await LoadText();
} }
private async Task SaveContent() private async Task SaveContent()
@ -167,4 +185,5 @@ else
AddModuleMessage("Error Saving Content", MessageType.Error); AddModuleMessage("Error Saving Content", MessageType.Error);
} }
} }
} }