131 lines
3.2 KiB
Plaintext
131 lines
3.2 KiB
Plaintext
@namespace Oqtane.Modules.Controls
|
|
@inherits ModuleBase
|
|
@inject IJSRuntime JSRuntime
|
|
|
|
@if (filemanagervisible)
|
|
{
|
|
<FileManager @ref="filemanager" Filter="@Constants.ImageFiles" />
|
|
@((MarkupString)@message)
|
|
<br />
|
|
}
|
|
<div class="row justify-content-center">
|
|
<button type="button" class="btn btn-success" @onclick="InsertImage">Insert Image</button>
|
|
@if (filemanagervisible)
|
|
{
|
|
@((MarkupString)" ")
|
|
<button type="button" class="btn btn-secondary" @onclick="CloseFileManager">Close</button>
|
|
}
|
|
</div>
|
|
<br />
|
|
<div @ref="@ToolBar">
|
|
@ToolbarContent
|
|
</div>
|
|
<div @ref="@EditorElement">
|
|
</div>
|
|
|
|
@code {
|
|
[Parameter]
|
|
public RenderFragment ToolbarContent { get; set; }
|
|
|
|
[Parameter]
|
|
public bool ReadOnly { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public string Placeholder { get; set; } = "Enter Your Content...";
|
|
|
|
[Parameter]
|
|
public string Theme { get; set; } = "snow";
|
|
|
|
[Parameter]
|
|
public string DebugLevel { get; set; } = "info";
|
|
|
|
private ElementReference EditorElement;
|
|
private ElementReference ToolBar;
|
|
bool filemanagervisible = false;
|
|
FileManager filemanager;
|
|
string message = "";
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
await RichTextEditorInterop.CreateEditor(
|
|
JSRuntime,
|
|
EditorElement,
|
|
ToolBar,
|
|
ReadOnly,
|
|
Placeholder,
|
|
Theme,
|
|
DebugLevel);
|
|
}
|
|
}
|
|
|
|
public async Task<string> GetText()
|
|
{
|
|
return await RichTextEditorInterop.GetText(
|
|
JSRuntime,
|
|
EditorElement);
|
|
}
|
|
|
|
public async Task<string> GetHTML()
|
|
{
|
|
return await RichTextEditorInterop.GetHTML(
|
|
JSRuntime,
|
|
EditorElement);
|
|
}
|
|
|
|
public async Task<string> GetContent()
|
|
{
|
|
return await RichTextEditorInterop.GetContent(
|
|
JSRuntime,
|
|
EditorElement);
|
|
}
|
|
|
|
public async Task LoadContent(string Content)
|
|
{
|
|
await RichTextEditorInterop.LoadEditorContent(
|
|
JSRuntime,
|
|
EditorElement, Content);
|
|
}
|
|
|
|
public async Task EnableEditor(bool mode)
|
|
{
|
|
await RichTextEditorInterop.EnableEditor(
|
|
JSRuntime,
|
|
EditorElement, mode);
|
|
}
|
|
|
|
public async Task InsertImage()
|
|
{
|
|
if (filemanagervisible)
|
|
{
|
|
int fileid = filemanager.GetFileId();
|
|
if (fileid != -1)
|
|
{
|
|
await RichTextEditorInterop.InsertImage(
|
|
JSRuntime,
|
|
EditorElement, ContentUrl(fileid));
|
|
filemanagervisible = false;
|
|
message = "";
|
|
}
|
|
else
|
|
{
|
|
message = "<br /><div class=\"alert alert-warning\" role=\"alert\">You Must Select An Image To Insert</div>";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
filemanagervisible = true;
|
|
message = "";
|
|
}
|
|
StateHasChanged();
|
|
}
|
|
|
|
public async Task CloseFileManager()
|
|
{
|
|
filemanagervisible = false;
|
|
message = "";
|
|
StateHasChanged();
|
|
}
|
|
|
|
} |