@using Oqtane.Themes
@using Oqtane.Services
@using Oqtane.Models
@inherits ContainerBase
@inject IUriHelper UriHelper
@inject IUserService UserService
@inject IPageModuleService PageModuleService
@functions {
string display = "display: none";
List actions;
protected override void OnInit()
{
actions = new List();
if (ModuleState.PaneModuleIndex > 0)
{
actions.Add(new ActionViewModel { Action = "up", Name = "Move Up" });
}
if (ModuleState.PaneModuleIndex < (ModuleState.PaneModuleCount - 1))
{
actions.Add(new ActionViewModel { Action = "down", Name = "Move Down" });
}
foreach (string pane in PageState.Page.Panes.Split(';'))
{
if (pane != ModuleState.Pane)
{
actions.Add(new ActionViewModel { Action = pane, Name = "Move To " + pane + " Pane" });
}
}
actions.Add(new ActionViewModel { Action = "settings", Name = "Settings" });
actions.Add(new ActionViewModel { Action = "delete", Name = "Delete" });
if (UserService.IsAuthorized(PageState.User, ModuleState.EditPermissions))
{
display = "display: inline";
}
}
protected async Task ModuleAction(string action)
{
PageModule pagemodule = new PageModule();
pagemodule.PageModuleId = ModuleState.PageModuleId;
pagemodule.PageId = ModuleState.PageId;
pagemodule.ModuleId = ModuleState.ModuleId;
pagemodule.Title = ModuleState.Title;
pagemodule.Pane = ModuleState.Pane;
pagemodule.Order = ModuleState.Order;
pagemodule.ContainerType = ModuleState.ContainerType;
string path = PageState.Page.Path + "?reload=true";
switch (action)
{
case "up":
pagemodule.Order += -1;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
break;
case "down":
pagemodule.Order += 1;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
break;
case "settings":
if (path == "") { path += "/"; }
path = PageState.Page.Path + "?mid=" + pagemodule.ModuleId.ToString() + "&ctl=Settings";
break;
case "delete":
await PageModuleService.DeletePageModuleAsync(pagemodule.PageModuleId);
break;
default: // move to pane
pagemodule.Pane = action;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
break;
}
UriHelper.NavigateTo(PageState.Alias + path);
}
public class ActionViewModel
{
public string Action { set; get; }
public string Name { set; get; }
}
}