improve confirm dialog
This commit is contained in:
parent
d5031a052a
commit
f59ec7bdac
|
@ -17,7 +17,7 @@ else
|
|||
<th>Name</th>
|
||||
</Header>
|
||||
<Row>
|
||||
<td><ConfirmationDialog Header="Delete File" Message="@("Are You Sure You Wish To Delete " + context + "?")" Action="Delete" Class="btn btn-danger" OnClick="@(async () => await DeleteFile(context))" /></td>
|
||||
<td><ActionDialog Header="Delete File" Message="@("Are You Sure You Wish To Delete " + context + "?")" Action="Delete" Class="btn btn-danger" OnClick="@(async () => await DeleteFile(context))" /></td>
|
||||
<td><a href="@(uri.Scheme + "://" + uri.Authority + "/" + PageState.Site.SiteRootPath + context)" target="_new">@context</a></td>
|
||||
</Row>
|
||||
</Pager>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
}
|
||||
else
|
||||
{
|
||||
<ActionLink Action="Add" Text="Add Profile" Control="Edit" />
|
||||
<ActionLink Action="Add" Security="SecurityAccessLevel.Admin" Text="Add Profile" />
|
||||
|
||||
<Pager Items="@Profiles">
|
||||
<Header>
|
||||
|
@ -18,7 +18,7 @@ else
|
|||
</Header>
|
||||
<Row>
|
||||
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.ProfileId.ToString())" /></td>
|
||||
<td><ConfirmationDialog Header="Delete Profile" Message="@("Are You Sure You Wish To Delete " + context.Name + "?")" Action="Delete" Class="btn btn-danger" OnClick="@(async () => await DeleteProfile(context.ProfileId))" /></td>
|
||||
<td><ActionDialog Header="Delete Profile" Message="@("Are You Sure You Wish To Delete " + context.Name + "?")" Action="Delete" Class="btn btn-danger" OnClick="@(async () => await DeleteProfile(context.ProfileId))" /></td>
|
||||
<td>@context.Name</td>
|
||||
</Row>
|
||||
</Pager>
|
||||
|
|
123
Oqtane.Client/Modules/Controls/ActionDialog.razor
Normal file
123
Oqtane.Client/Modules/Controls/ActionDialog.razor
Normal file
|
@ -0,0 +1,123 @@
|
|||
@namespace Oqtane.Modules.Controls
|
||||
@inherits ModuleBase
|
||||
|
||||
@if (visible)
|
||||
{
|
||||
<div class="app-admin-modal">
|
||||
<div class="modal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">@Header</h5>
|
||||
<button type="button" class="close" @onclick="DisplayModal" aria-label="Close">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>@Message</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="@Class" @onclick="Confirm">@Action</button>
|
||||
<button type="button" class="btn btn-secondary" @onclick="DisplayModal">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@if (authorized)
|
||||
{
|
||||
<button class="@Class" @onclick="DisplayModal">@Action</button>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string Header { get; set; } // required
|
||||
|
||||
[Parameter]
|
||||
public string Message { get; set; } // required
|
||||
|
||||
[Parameter]
|
||||
public string Action { get; set; } // defaults to Ok if not specified
|
||||
|
||||
[Parameter]
|
||||
public SecurityAccessLevel? Security { get; set; } // optional - can be used to explicitly specify SecurityAccessLevel
|
||||
|
||||
[Parameter]
|
||||
public string Class { get; set; } // optional
|
||||
|
||||
[Parameter]
|
||||
public Action OnClick { get; set; } // required - executes a method in the calling component
|
||||
|
||||
bool visible = false;
|
||||
bool authorized = false;
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Action))
|
||||
{
|
||||
Action = "Ok";
|
||||
}
|
||||
if (string.IsNullOrEmpty(Class))
|
||||
{
|
||||
Class = "btn btn-success";
|
||||
}
|
||||
authorized = IsAuthorized();
|
||||
}
|
||||
|
||||
private bool IsAuthorized()
|
||||
{
|
||||
bool authorized = false;
|
||||
if (PageState.EditMode)
|
||||
{
|
||||
SecurityAccessLevel security = SecurityAccessLevel.Host;
|
||||
if (Security == null)
|
||||
{
|
||||
string typename = ModuleState.ModuleType.Replace(Utilities.GetTypeNameLastSegment(ModuleState.ModuleType, 0) + ",", Action + ",");
|
||||
Type moduleType = Type.GetType(typename);
|
||||
if (moduleType != null)
|
||||
{
|
||||
var moduleobject = Activator.CreateInstance(moduleType);
|
||||
security = (SecurityAccessLevel)moduleType.GetProperty("SecurityAccessLevel").GetValue(moduleobject, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
security = SecurityAccessLevel.Anonymous; // occurs when an action does not have a corresponding module control
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
security = Security.Value;
|
||||
}
|
||||
switch (security)
|
||||
{
|
||||
case SecurityAccessLevel.Anonymous:
|
||||
authorized = true;
|
||||
break;
|
||||
case SecurityAccessLevel.View:
|
||||
authorized = UserSecurity.IsAuthorized(PageState.User, "View", ModuleState.Permissions);
|
||||
break;
|
||||
case SecurityAccessLevel.Edit:
|
||||
authorized = UserSecurity.IsAuthorized(PageState.User, "Edit", ModuleState.Permissions);
|
||||
break;
|
||||
case SecurityAccessLevel.Admin:
|
||||
authorized = UserSecurity.IsAuthorized(PageState.User, Constants.AdminRole);
|
||||
break;
|
||||
case SecurityAccessLevel.Host:
|
||||
authorized = UserSecurity.IsAuthorized(PageState.User, Constants.HostRole);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return authorized;
|
||||
}
|
||||
|
||||
private void DisplayModal()
|
||||
{
|
||||
visible = !visible;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void Confirm()
|
||||
{
|
||||
DisplayModal();
|
||||
OnClick();
|
||||
}
|
||||
}
|
|
@ -9,7 +9,10 @@
|
|||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string Action { get; set; }
|
||||
public string Action { get; set; } // required
|
||||
|
||||
[Parameter]
|
||||
public SecurityAccessLevel? Security { get; set; } // optional - can be used to explicitly specify SecurityAccessLevel
|
||||
|
||||
[Parameter]
|
||||
public string Text { get; set; } // optional - defaults to Action if not specified
|
||||
|
@ -23,9 +26,6 @@
|
|||
[Parameter]
|
||||
public string Style { get; set; } // optional
|
||||
|
||||
[Parameter]
|
||||
public string Control { get; set; } // optional - can be used to explicitly link an Action to a Module Control
|
||||
|
||||
string text = "";
|
||||
string url = "";
|
||||
string parameters = "";
|
||||
|
@ -57,24 +57,35 @@
|
|||
}
|
||||
|
||||
url = EditUrl(Action, parameters);
|
||||
authorized = IsAuthorized();
|
||||
}
|
||||
|
||||
private bool IsAuthorized()
|
||||
{
|
||||
bool authorized = false;
|
||||
if (PageState.EditMode)
|
||||
{
|
||||
string typename;
|
||||
if (string.IsNullOrEmpty(Control))
|
||||
SecurityAccessLevel security = SecurityAccessLevel.Host;
|
||||
if (Security == null)
|
||||
{
|
||||
typename = ModuleState.ModuleType.Replace(Utilities.GetTypeNameLastSegment(ModuleState.ModuleType, 0) + ",", Action + ",");
|
||||
}
|
||||
else
|
||||
{
|
||||
typename = ModuleState.ModuleType.Replace(Utilities.GetTypeNameLastSegment(ModuleState.ModuleType, 0) + ",", Control + ",");
|
||||
}
|
||||
string typename = ModuleState.ModuleType.Replace(Utilities.GetTypeNameLastSegment(ModuleState.ModuleType, 0) + ",", Action + ",");
|
||||
Type moduleType = Type.GetType(typename);
|
||||
if (moduleType != null)
|
||||
{
|
||||
var moduleobject = Activator.CreateInstance(moduleType);
|
||||
SecurityAccessLevel SecurityAccessLevel = (SecurityAccessLevel)moduleType.GetProperty("SecurityAccessLevel").GetValue(moduleobject, null);
|
||||
switch (SecurityAccessLevel)
|
||||
security = (SecurityAccessLevel)moduleType.GetProperty("SecurityAccessLevel").GetValue(moduleobject, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
security = SecurityAccessLevel.Anonymous; // occurs when an action does not have a corresponding module control
|
||||
Class = "btn btn-warning"; // alert developer of missing module comtrol
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
security = Security.Value;
|
||||
}
|
||||
switch (security)
|
||||
{
|
||||
case SecurityAccessLevel.Anonymous:
|
||||
authorized = true;
|
||||
|
@ -93,15 +104,6 @@
|
|||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
authorized = true; // occurs when an action does not have a corresponding module control
|
||||
classname = "btn btn-warning"; // alert developer of missing module comtrol
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
authorized = false;
|
||||
}
|
||||
return authorized;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
@namespace Oqtane.Modules.Controls
|
||||
@inherits ModuleBase
|
||||
|
||||
@if (visible)
|
||||
{
|
||||
<div class="app-admin-modal">
|
||||
<div class="modal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">@Header</h5>
|
||||
<button type="button" class="close" @onclick="DisplayModal" aria-label="Close">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>@Message</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="@Class" @onclick="Confirm">@Action</button>
|
||||
<button type="button" class="btn btn-secondary" @onclick="DisplayModal">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<button class="@Class" @onclick="DisplayModal">@Action</button>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string Header { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string Message { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string Action { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string Class { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Action OnClick { get; set; }
|
||||
|
||||
bool visible = false;
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Action))
|
||||
{
|
||||
Action = "Ok";
|
||||
}
|
||||
if (string.IsNullOrEmpty(Class))
|
||||
{
|
||||
Class = "btn btn-success";
|
||||
}
|
||||
}
|
||||
|
||||
private void DisplayModal()
|
||||
{
|
||||
visible = !visible;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void Confirm()
|
||||
{
|
||||
DisplayModal();
|
||||
OnClick();
|
||||
}
|
||||
}
|
|
@ -2,7 +2,9 @@
|
|||
@inherits ModuleBase
|
||||
@typeparam TableItem
|
||||
|
||||
<p align="center">
|
||||
<p>
|
||||
@if(Format == "Table")
|
||||
{
|
||||
<table class="table table-borderless">
|
||||
<thead>
|
||||
<tr>@Header</tr>
|
||||
|
@ -14,7 +16,18 @@
|
|||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<div>
|
||||
}
|
||||
@if(Format == "Grid")
|
||||
{
|
||||
<div class="container">
|
||||
<div class="row">@Header</div>
|
||||
@foreach (var item in ItemList)
|
||||
{
|
||||
<div class="row">@Row(item)</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
<div class="mx-auto text-center">
|
||||
@if (Page > MaxPages)
|
||||
{
|
||||
<button class="btn btn-secondary" @onclick=@(async () => SetPagerSize("back"))><span class="oi oi-media-skip-backward" title="back" aria-hidden="true"></span></button>
|
||||
|
@ -50,6 +63,9 @@
|
|||
int StartPage;
|
||||
int EndPage;
|
||||
|
||||
[Parameter]
|
||||
public string Format { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public RenderFragment Header { get; set; }
|
||||
|
||||
|
@ -69,6 +85,10 @@
|
|||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Format))
|
||||
{
|
||||
Format = "Table";
|
||||
}
|
||||
if (string.IsNullOrEmpty(PageSize))
|
||||
{
|
||||
MaxItems = 10;
|
||||
|
|
|
@ -50,7 +50,6 @@ namespace Oqtane.Infrastructure
|
|||
case ".dll":
|
||||
entry.ExtractToFile(Path.Combine(binfolder, filename), true);
|
||||
break;
|
||||
case ".nuspec":
|
||||
case ".png":
|
||||
case ".jpg":
|
||||
case ".jpeg":
|
||||
|
|
Loading…
Reference in New Issue
Block a user