mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-21 19:34:40 +08:00
Adding support for editor groups. Still need to hook up dedup and ordering of groupinfos in GetEditorGroupInfos and GetDisplayGroupInfos.
--HG-- branch : dev
This commit is contained in:
@@ -189,6 +189,7 @@
|
||||
<Compile Include="Settings\ResourceManifest.cs" />
|
||||
<Compile Include="Settings\Migrations.cs" />
|
||||
<Compile Include="Settings\Drivers\SiteSettingsPartDriver.cs" />
|
||||
<Compile Include="Settings\Routes.cs" />
|
||||
<Compile Include="Settings\ViewModels\SiteCulturesViewModel.cs" />
|
||||
<Compile Include="Settings\Metadata\ContentDefinitionManager.cs" />
|
||||
<Compile Include="Settings\Metadata\Records\ContentFieldDefinitionRecord.cs" />
|
||||
|
@@ -1,16 +1,38 @@
|
||||
using Orchard.Localization;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Security;
|
||||
using Orchard.Settings;
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
namespace Orchard.Core.Settings {
|
||||
public class AdminMenu : INavigationProvider {
|
||||
private readonly ISiteService _siteService;
|
||||
|
||||
public AdminMenu(ISiteService siteService, IOrchardServices orchardServices) {
|
||||
_siteService = siteService;
|
||||
Services = orchardServices;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
public string MenuName { get { return "admin"; } }
|
||||
public IOrchardServices Services { get; private set; }
|
||||
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
builder.Add(T("Configuration"), "50",
|
||||
menu => menu.Add(T("Settings"), "10", item => item.Action("Index", "Admin", new { area = "Settings" })
|
||||
builder.Add(T("Settings"), "50",
|
||||
menu => menu.Add(T("General"), "0", item => item.Action("Index", "Admin", new { area = "Settings", groupInfoId = "Index" })
|
||||
.Permission(StandardPermissions.SiteOwner)));
|
||||
|
||||
var site = _siteService.GetSiteSettings();
|
||||
if (site == null)
|
||||
return;
|
||||
|
||||
foreach (var groupInfo in Services.ContentManager.GetEditorGroupInfos(site.ContentItem)) {
|
||||
GroupInfo info = groupInfo;
|
||||
builder.Add(T("Settings"), "50",
|
||||
menu => menu.Add(info.Name, info.Position, item => item.Action("Index", "Admin", new { area = "Settings", groupInfoId = info.Id })
|
||||
.Permission(StandardPermissions.SiteOwner)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
using System.Globalization;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Core.Settings.ViewModels;
|
||||
using Orchard.Localization;
|
||||
using Orchard.ContentManagement;
|
||||
@@ -28,25 +30,55 @@ namespace Orchard.Core.Settings.Controllers {
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ActionResult Index(string tabName) {
|
||||
public ActionResult Index(string groupInfoId) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage settings")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
dynamic model = Services.ContentManager.BuildEditor(_siteService.GetSiteSettings());
|
||||
dynamic model;
|
||||
var site = _siteService.GetSiteSettings();
|
||||
if (!string.IsNullOrWhiteSpace(groupInfoId)) {
|
||||
model = Services.ContentManager.BuildEditor(site, groupInfoId);
|
||||
|
||||
if (model == null)
|
||||
return HttpNotFound();
|
||||
|
||||
var groupInfo = Services.ContentManager.GetEditorGroupInfo(site, groupInfoId);
|
||||
if (groupInfo == null)
|
||||
return HttpNotFound();
|
||||
|
||||
model.GroupInfo = groupInfo;
|
||||
}
|
||||
else {
|
||||
model = Services.ContentManager.BuildEditor(site);
|
||||
}
|
||||
|
||||
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
||||
return View((object)model);
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Index")]
|
||||
public ActionResult IndexPOST(string tabName) {
|
||||
public ActionResult IndexPOST(string groupInfoId) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage settings")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var site = _siteService.GetSiteSettings();
|
||||
dynamic model = Services.ContentManager.UpdateEditor(site, this);
|
||||
|
||||
if (model == null) {
|
||||
Services.TransactionManager.Cancel();
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
var groupInfo = Services.ContentManager.GetEditorGroupInfo(site, groupInfoId);
|
||||
if (groupInfo == null) {
|
||||
Services.TransactionManager.Cancel();
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel();
|
||||
model.GroupInfo = groupInfo;
|
||||
|
||||
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
||||
return View((object)model);
|
||||
}
|
||||
|
57
src/Orchard.Web/Core/Settings/Routes.cs
Normal file
57
src/Orchard.Web/Core/Settings/Routes.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Orchard.Core.Settings.Controllers;
|
||||
using Orchard.Mvc.Routes;
|
||||
|
||||
namespace Orchard.Core.Settings {
|
||||
public class Routes : IRouteProvider {
|
||||
public void GetRoutes(ICollection<RouteDescriptor> routes) {
|
||||
foreach (var routeDescriptor in GetRoutes())
|
||||
routes.Add(routeDescriptor);
|
||||
}
|
||||
|
||||
public IEnumerable<RouteDescriptor> GetRoutes() {
|
||||
return new[] {
|
||||
new RouteDescriptor {
|
||||
Route = new Route(
|
||||
"Admin/Settings/{groupInfoId}",
|
||||
new RouteValueDictionary {
|
||||
{"area", "Settings"},
|
||||
{"controller", "Admin"},
|
||||
{"action", "Index"}
|
||||
},
|
||||
new RouteValueDictionary {
|
||||
{"groupInfoId", new SettingsActionConstraint()}
|
||||
},
|
||||
new RouteValueDictionary {
|
||||
{"area", "Settings"},
|
||||
{"groupInfoId", ""}
|
||||
},
|
||||
new MvcRouteHandler())
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class SettingsActionConstraint : IRouteConstraint {
|
||||
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) {
|
||||
if (routeDirection == RouteDirection.UrlGeneration)
|
||||
return true;
|
||||
|
||||
if (!values.ContainsKey(parameterName))
|
||||
return false;
|
||||
|
||||
// just hard-coding to know action name strings for now
|
||||
var potentialActionName = values[parameterName] as string;
|
||||
return !string.IsNullOrWhiteSpace(potentialActionName)
|
||||
&& potentialActionName != "Index"
|
||||
&& potentialActionName != "Culture"
|
||||
&& potentialActionName != "AddCulture"
|
||||
&& potentialActionName != "DeleteCulture";
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,8 @@
|
||||
@{ Layout.Title = T("Manage Settings").ToString(); }
|
||||
@using Orchard.ContentManagement
|
||||
@{
|
||||
GroupInfo groupInfo = Model.GroupInfo;
|
||||
Layout.Title = (groupInfo != null ? T("Manage Settings for {0}", groupInfo.Name) : T("Manage Settings")).ToString();
|
||||
}
|
||||
|
||||
@using (Html.BeginFormAntiForgeryPost()) {
|
||||
@Html.ValidationSummary()
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using Orchard.Comments.Models;
|
||||
using System;
|
||||
using Orchard.Comments.Models;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Localization;
|
||||
@@ -13,12 +14,18 @@ namespace Orchard.Comments.Drivers {
|
||||
|
||||
protected override string Prefix { get { return "CommentSettings"; } }
|
||||
|
||||
protected override DriverResult Editor(CommentSettingsPart part, dynamic shapeHelper) {
|
||||
protected override DriverResult Editor(CommentSettingsPart part, string groupInfoId, dynamic shapeHelper) {
|
||||
if (!string.Equals(groupInfoId, "comments", StringComparison.OrdinalIgnoreCase))
|
||||
return null;
|
||||
|
||||
return ContentShape("Parts_Comments_SiteSettings",
|
||||
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Comments.SiteSettings", Model: part.Record, Prefix: Prefix));
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(CommentSettingsPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
protected override DriverResult Editor(CommentSettingsPart part, IUpdateModel updater, string groupInfoId, dynamic shapeHelper) {
|
||||
if (!string.Equals(groupInfoId, "comments", StringComparison.OrdinalIgnoreCase))
|
||||
return null;
|
||||
|
||||
updater.TryUpdateModel(part.Record, Prefix, null, null);
|
||||
return Editor(part, shapeHelper);
|
||||
}
|
||||
|
@@ -1,14 +1,24 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Comments.Models;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Comments.Handlers {
|
||||
[UsedImplicitly]
|
||||
public class CommentSettingsPartHandler : ContentHandler {
|
||||
public CommentSettingsPartHandler(IRepository<CommentSettingsPartRecord> repository) {
|
||||
T = NullLocalizer.Instance;
|
||||
Filters.Add(new ActivatingFilter<CommentSettingsPart>("Site"));
|
||||
Filters.Add(StorageFilter.For(repository));
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
|
||||
base.GetItemMetadata(context);
|
||||
context.Metadata.EditorGroupInfo.Add(new GroupInfo(T("Comments")));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,15 +1,25 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Media.Models;
|
||||
|
||||
namespace Orchard.Media.Handlers {
|
||||
[UsedImplicitly]
|
||||
public class MediaSettingsPartHandler : ContentHandler {
|
||||
public MediaSettingsPartHandler(IRepository<MediaSettingsPartRecord> repository) {
|
||||
T = NullLocalizer.Instance;
|
||||
Filters.Add(new ActivatingFilter<MediaSettingsPart>("Site"));
|
||||
Filters.Add(StorageFilter.For(repository));
|
||||
Filters.Add(new TemplateFilterForRecord<MediaSettingsPartRecord>("MediaSettings", "Parts/Media.MediaSettings"));
|
||||
Filters.Add(new TemplateFilterForRecord<MediaSettingsPartRecord>("MediaSettings", "Parts/Media.MediaSettings", "media"));
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
|
||||
base.GetItemMetadata(context);
|
||||
context.Metadata.EditorGroupInfo.Add(new GroupInfo(T("Media")));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,15 +1,25 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Users.Models;
|
||||
|
||||
namespace Orchard.Users.Handlers {
|
||||
[UsedImplicitly]
|
||||
public class RegistrationSettingsPartHandler : ContentHandler {
|
||||
public RegistrationSettingsPartHandler(IRepository<RegistrationSettingsPartRecord> repository) {
|
||||
T = NullLocalizer.Instance;
|
||||
Filters.Add(new ActivatingFilter<RegistrationSettingsPart>("Site"));
|
||||
Filters.Add(StorageFilter.For(repository));
|
||||
Filters.Add(new TemplateFilterForRecord<RegistrationSettingsPartRecord>("RegistrationSettings", "Parts/Users.RegistrationSettings"));
|
||||
Filters.Add(new TemplateFilterForRecord<RegistrationSettingsPartRecord>("RegistrationSettings", "Parts/Users.RegistrationSettings", "users"));
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
|
||||
base.GetItemMetadata(context);
|
||||
context.Metadata.EditorGroupInfo.Add(new GroupInfo(T("Users")));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user