Allow InputList component to be localizable and support multiple instances on a page. Implement icon localization in Page Add/Edit using IconResources.resx

This commit is contained in:
sbwalker
2023-08-23 16:43:14 -04:00
parent 82d128974c
commit 261ed05fa3
5 changed files with 160 additions and 8 deletions

View File

@ -113,7 +113,7 @@
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="icon" HelpText="Optionally provide an icon class name for this page which will be displayed in the site navigation" ResourceKey="Icon">Icon: </Label>
<div class="col-sm-8">
<InputList Value="@_icon" ValueChanged="IconChanged" InputValues="@_icons" />
<InputList Value="@_icon" ValueChanged="IconChanged" DataList="@_icons" ResourceKey="Icon" ResourceType="@_iconresources" />
</div>
<div class="col-sm-1">
<i class="@_icon"></i>
@ -232,6 +232,7 @@
private bool _refresh = false;
protected Page _parent = null;
protected Dictionary<string, string> _icons;
private string _iconresources = "";
protected override async Task OnInitializedAsync()
{
@ -247,6 +248,7 @@
}
}
_icons = await SystemService.GetIconsAsync();
_iconresources = typeof(IconResources).FullName;
// if admin or user has edit access to parent page
if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Admin) || (_parent != null && UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, _parent.PermissionList)))

View File

@ -125,7 +125,7 @@
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="icon" HelpText="Optionally provide an icon class name for this page which will be displayed in the site navigation" ResourceKey="Icon">Icon: </Label>
<div class="col-sm-8">
<InputList Value="@_icon" ValueChanged="IconChanged" InputValues="@_icons" />
<InputList Value="@_icon" ValueChanged="IconChanged" DataList="@_icons" ResourceKey="Icon" ResourceType="@_iconresources" />
</div>
<div class="col-sm-1">
<i class="@_icon"></i>
@ -317,6 +317,7 @@
protected Page _page = null;
protected Page _parent = null;
protected Dictionary<string, string> _icons;
private string _iconresources = "";
protected override async Task OnInitializedAsync()
{
@ -326,6 +327,7 @@
_pageId = Int32.Parse(PageState.QueryString["id"]);
_page = await PageService.GetPageAsync(_pageId);
_icons = await SystemService.GetIconsAsync();
_iconresources = Utilities.GetFullTypeName(typeof(IconResources).AssemblyQualifiedName);
if (_page != null && UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, _page.PermissionList))
{

View File

@ -1,24 +1,35 @@
@namespace Oqtane.Modules.Controls
@using System.Linq.Expressions;
@inherits ModuleControlBase
<input type="text" value="@Value" list="Dictionarylist" class="form-select" @onchange="(e => OnChange(e))" />
<datalist id="Dictionarylist" value="@Value">
@foreach(var iv in InputValues)
@inherits LocalizableComponent
<input type="text" value="@Value" list="@_id" class="form-select" @onchange="(e => OnChange(e))" />
<datalist id="@_id" value="@Value">
@foreach(var kvp in DataList)
{
<option value="@iv.Value">@iv.Key</option>
<option value="@kvp.Value">@Localize(kvp.Key, kvp.Key)</option>
}
</datalist>
@code {
private string _id;
[Parameter]
public string Value { get; set; }
[EditorRequired]
[Parameter]
public Dictionary<string, string> InputValues { get; set; }
public Dictionary<string, string> DataList { get; set; }
[EditorRequired]
[Parameter]
public EventCallback<string> ValueChanged { get; set; }
protected override void OnInitialized()
{
// create unique id for component
_id = "DataList_" + Guid.NewGuid().ToString("N");
}
protected void OnChange(ChangeEventArgs e)
{
if (string.IsNullOrWhiteSpace(e.Value.ToString())) { return; }