mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-20 02:37:55 +08:00
Hooking up part setting management when editing content types/parts
--HG-- branch : dev
This commit is contained in:
@@ -4,6 +4,7 @@ using Orchard.ContentManagement;
|
|||||||
using Orchard.ContentManagement.Aspects;
|
using Orchard.ContentManagement.Aspects;
|
||||||
using Orchard.ContentManagement.Drivers;
|
using Orchard.ContentManagement.Drivers;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
|
using Orchard.Core.Common.Settings;
|
||||||
using Orchard.Core.Common.ViewModels;
|
using Orchard.Core.Common.ViewModels;
|
||||||
|
|
||||||
namespace Orchard.Core.Common.Drivers {
|
namespace Orchard.Core.Common.Drivers {
|
||||||
@@ -12,6 +13,7 @@ namespace Orchard.Core.Common.Drivers {
|
|||||||
public IOrchardServices Services { get; set; }
|
public IOrchardServices Services { get; set; }
|
||||||
private const string TemplateName = "Parts/Common.Body";
|
private const string TemplateName = "Parts/Common.Body";
|
||||||
private const string DefaultTextEditorTemplate = "TinyMceTextEditor";
|
private const string DefaultTextEditorTemplate = "TinyMceTextEditor";
|
||||||
|
private const string PlainTextEditorTemplate = "PlainTextEditor";
|
||||||
|
|
||||||
public BodyDriver(IOrchardServices services) {
|
public BodyDriver(IOrchardServices services) {
|
||||||
Services = services;
|
Services = services;
|
||||||
@@ -21,7 +23,7 @@ namespace Orchard.Core.Common.Drivers {
|
|||||||
get { return "Body"; }
|
get { return "Body"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// \/\/ Haackalicious on many accounts - don't copy what has been done here for the wrapper \/\/
|
// \/\/ Hackalicious on many accounts - don't copy what has been done here for the wrapper \/\/
|
||||||
protected override DriverResult Display(BodyAspect part, string displayType) {
|
protected override DriverResult Display(BodyAspect part, string displayType) {
|
||||||
var model = new BodyDisplayViewModel { BodyAspect = part, Text = BbcodeReplace(part.Text) };
|
var model = new BodyDisplayViewModel { BodyAspect = part, Text = BbcodeReplace(part.Text) };
|
||||||
|
|
||||||
@@ -40,16 +42,29 @@ namespace Orchard.Core.Common.Drivers {
|
|||||||
protected override DriverResult Editor(BodyAspect part, IUpdateModel updater) {
|
protected override DriverResult Editor(BodyAspect part, IUpdateModel updater) {
|
||||||
var model = BuildEditorViewModel(part);
|
var model = BuildEditorViewModel(part);
|
||||||
updater.TryUpdateModel(model, Prefix, null, null);
|
updater.TryUpdateModel(model, Prefix, null, null);
|
||||||
|
|
||||||
|
// only set the format if it has not yet been set to preserve the initial format type - might want to change this later to support changing body formats but...later
|
||||||
|
if (string.IsNullOrWhiteSpace(model.Format))
|
||||||
|
model.Format = GetFlavor(part);
|
||||||
|
|
||||||
return ContentPartTemplate(model, TemplateName, Prefix).Location("primary", "5");
|
return ContentPartTemplate(model, TemplateName, Prefix).Location("primary", "5");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BodyEditorViewModel BuildEditorViewModel(BodyAspect part) {
|
private static BodyEditorViewModel BuildEditorViewModel(BodyAspect part) {
|
||||||
return new BodyEditorViewModel {
|
return new BodyEditorViewModel {
|
||||||
BodyAspect = part,
|
BodyAspect = part,
|
||||||
TextEditorTemplate = DefaultTextEditorTemplate,
|
TextEditorTemplate = GetFlavor(part) == "html" ? DefaultTextEditorTemplate : PlainTextEditorTemplate,
|
||||||
AddMediaPath= new PathBuilder(part).AddContentType().AddContainerSlug().AddSlug().ToString()
|
AddMediaPath= new PathBuilder(part).AddContentType().AddContainerSlug().AddSlug().ToString()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetFlavor(BodyAspect part) {
|
||||||
|
var typePartSettings = part.Settings.GetModel<BodyTypePartSettings>();
|
||||||
|
return (typePartSettings != null && !string.IsNullOrWhiteSpace(typePartSettings.Flavor))
|
||||||
|
? typePartSettings.Flavor
|
||||||
|
: part.PartDefinition.Settings.GetModel<BodyPartSettings>().FlavorDefault;
|
||||||
|
}
|
||||||
|
|
||||||
class PathBuilder {
|
class PathBuilder {
|
||||||
private readonly IContent _content;
|
private readonly IContent _content;
|
||||||
private string _path;
|
private string _path;
|
||||||
|
67
src/Orchard.Web/Core/Common/Settings/BodySettings.cs
Normal file
67
src/Orchard.Web/Core/Common/Settings/BodySettings.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
|
using Orchard.ContentManagement.MetaData.Builders;
|
||||||
|
using Orchard.ContentManagement.MetaData.Models;
|
||||||
|
using Orchard.ContentManagement.ViewModels;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Common.Settings {
|
||||||
|
public class BodyPartSettings {
|
||||||
|
public const string FlavorDefaultDefault = "html";
|
||||||
|
private string _flavorDefault;
|
||||||
|
public string FlavorDefault {
|
||||||
|
get { return !string.IsNullOrWhiteSpace(_flavorDefault)
|
||||||
|
? _flavorDefault
|
||||||
|
: FlavorDefaultDefault; }
|
||||||
|
set { _flavorDefault = value; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BodyTypePartSettings {
|
||||||
|
public string Flavor { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BodySettingsHooks : ContentDefinitionEditorEventsBase {
|
||||||
|
public override IEnumerable<TemplateViewModel> TypePartEditor(ContentTypeDefinition.Part definition) {
|
||||||
|
if (definition.PartDefinition.Name != "BodyAspect")
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
var model = definition.Settings.GetModel<BodyTypePartSettings>();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(model.Flavor)) {
|
||||||
|
var partModel = definition.PartDefinition.Settings.GetModel<BodyPartSettings>();
|
||||||
|
model.Flavor = partModel.FlavorDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
yield return DefinitionTemplate(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<TemplateViewModel> PartEditor(ContentPartDefinition definition) {
|
||||||
|
if (definition.Name != "BodyAspect")
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
var model = definition.Settings.GetModel<BodyPartSettings>();
|
||||||
|
yield return DefinitionTemplate(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<TemplateViewModel> TypePartEditorUpdate(ContentTypeDefinitionBuilder.PartConfigurer builder, IUpdateModel updateModel) {
|
||||||
|
if (builder.Name != "BodyAspect")
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
var model = new BodyTypePartSettings();
|
||||||
|
updateModel.TryUpdateModel(model, "BodyTypePartSettings", null, null);
|
||||||
|
builder.WithSetting("BodyTypePartSettings.Flavor", !string.IsNullOrWhiteSpace(model.Flavor) ? model.Flavor : null);
|
||||||
|
yield return DefinitionTemplate(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<TemplateViewModel> PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel) {
|
||||||
|
if (builder.Name != "BodyAspect")
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
var model = new BodyPartSettings();
|
||||||
|
updateModel.TryUpdateModel(model, "BodyPartSettings", null, null);
|
||||||
|
builder.WithSetting("BodyPartSettings.FlavorDefault", !string.IsNullOrWhiteSpace(model.FlavorDefault) ? model.FlavorDefault : null);
|
||||||
|
yield return DefinitionTemplate(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,6 @@
|
|||||||
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Common.Settings.BodyPartSettings>" %>
|
||||||
|
<fieldset>
|
||||||
|
<label for="<%:Html.FieldIdFor(m => m.FlavorDefault) %>"><%:T("Default flavor") %></label>
|
||||||
|
<%:Html.EditorFor(m => m.FlavorDefault)%>
|
||||||
|
<%:Html.ValidationMessageFor(m => m.FlavorDefault)%>
|
||||||
|
</fieldset>
|
@@ -0,0 +1,6 @@
|
|||||||
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Common.Settings.BodyTypePartSettings>" %>
|
||||||
|
<fieldset>
|
||||||
|
<label for="<%:Html.FieldIdFor(m => m.Flavor) %>"><%:T("Flavor") %></label>
|
||||||
|
<%:Html.EditorFor(m => m.Flavor) %>
|
||||||
|
<%:Html.ValidationMessageFor(m => m.Flavor) %>
|
||||||
|
</fieldset>
|
@@ -0,0 +1,3 @@
|
|||||||
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BodyEditorViewModel>" %>
|
||||||
|
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
|
||||||
|
<%: Html.TextArea("Text", Model.Text, 25, 80, new { @class = Model.Format }) %>
|
@@ -68,6 +68,7 @@
|
|||||||
<Compile Include="Common\Drivers\TextFieldDriver.cs" />
|
<Compile Include="Common\Drivers\TextFieldDriver.cs" />
|
||||||
<Compile Include="Common\Fields\TextField.cs" />
|
<Compile Include="Common\Fields\TextField.cs" />
|
||||||
<Compile Include="Common\Handlers\RoutableAspectHandler.cs" />
|
<Compile Include="Common\Handlers\RoutableAspectHandler.cs" />
|
||||||
|
<Compile Include="Common\Settings\BodySettings.cs" />
|
||||||
<Compile Include="Common\ViewModels\ContainerEditorViewModel.cs" />
|
<Compile Include="Common\ViewModels\ContainerEditorViewModel.cs" />
|
||||||
<Compile Include="Common\ViewModels\TextContentFieldDisplayViewModel.cs" />
|
<Compile Include="Common\ViewModels\TextContentFieldDisplayViewModel.cs" />
|
||||||
<Compile Include="Common\ViewModels\TextContentFieldEditorViewModel.cs" />
|
<Compile Include="Common\ViewModels\TextContentFieldEditorViewModel.cs" />
|
||||||
@@ -197,9 +198,12 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Common\Module.txt" />
|
<Content Include="Common\Module.txt" />
|
||||||
|
<Content Include="Common\Views\DefinitionTemplates\BodyTypePartSettings.ascx" />
|
||||||
|
<Content Include="Common\Views\DefinitionTemplates\BodyPartSettings.ascx" />
|
||||||
<Content Include="Common\Views\DisplayTemplates\Fields\Common.TextField.ascx" />
|
<Content Include="Common\Views\DisplayTemplates\Fields\Common.TextField.ascx" />
|
||||||
<Content Include="Common\Views\EditorTemplates\Fields\Common.TextField.ascx" />
|
<Content Include="Common\Views\EditorTemplates\Fields\Common.TextField.ascx" />
|
||||||
<Content Include="Common\Views\EditorTemplates\Parts\Common.Container.ascx" />
|
<Content Include="Common\Views\EditorTemplates\Parts\Common.Container.ascx" />
|
||||||
|
<Content Include="Common\Views\EditorTemplates\PlainTextEditor.ascx" />
|
||||||
<Content Include="Contents\Module.txt" />
|
<Content Include="Contents\Module.txt" />
|
||||||
<Content Include="Contents\Views\Admin\List.aspx" />
|
<Content Include="Contents\Views\Admin\List.aspx" />
|
||||||
<Content Include="Contents\Views\Admin\Edit.aspx" />
|
<Content Include="Contents\Views\Admin\Edit.aspx" />
|
||||||
|
@@ -1,50 +1,34 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.MetaData;
|
using Orchard.ContentManagement.MetaData;
|
||||||
using Orchard.ContentManagement.MetaData.Models;
|
using Orchard.ContentManagement.MetaData.Models;
|
||||||
using Orchard.ContentManagement.ViewModels;
|
|
||||||
using Orchard.ContentTypes.Services;
|
using Orchard.ContentTypes.Services;
|
||||||
using Orchard.ContentTypes.ViewModels;
|
using Orchard.ContentTypes.ViewModels;
|
||||||
using Orchard.Data;
|
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Logging;
|
|
||||||
using Orchard.Mvc.Results;
|
using Orchard.Mvc.Results;
|
||||||
using Orchard.UI.Notify;
|
|
||||||
|
|
||||||
namespace Orchard.ContentTypes.Controllers {
|
namespace Orchard.ContentTypes.Controllers {
|
||||||
public class AdminController : Controller {
|
public class AdminController : Controller {
|
||||||
private readonly INotifier _notifier;
|
|
||||||
private readonly IContentDefinitionService _contentDefinitionService;
|
private readonly IContentDefinitionService _contentDefinitionService;
|
||||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||||
private readonly IContentManager _contentManager;
|
|
||||||
private readonly ITransactionManager _transactionManager;
|
|
||||||
private readonly IContentDefinitionEditorEvents _extendViewModels;
|
private readonly IContentDefinitionEditorEvents _extendViewModels;
|
||||||
|
|
||||||
public AdminController(
|
public AdminController(
|
||||||
IOrchardServices orchardServices,
|
IOrchardServices orchardServices,
|
||||||
INotifier notifier,
|
|
||||||
IContentDefinitionService contentDefinitionService,
|
IContentDefinitionService contentDefinitionService,
|
||||||
IContentDefinitionManager contentDefinitionManager,
|
IContentDefinitionManager contentDefinitionManager,
|
||||||
IContentManager contentManager,
|
|
||||||
ITransactionManager transactionManager,
|
|
||||||
IContentDefinitionEditorEvents extendViewModels) {
|
IContentDefinitionEditorEvents extendViewModels) {
|
||||||
Services = orchardServices;
|
Services = orchardServices;
|
||||||
_notifier = notifier;
|
|
||||||
_contentDefinitionService = contentDefinitionService;
|
_contentDefinitionService = contentDefinitionService;
|
||||||
_contentDefinitionManager = contentDefinitionManager;
|
_contentDefinitionManager = contentDefinitionManager;
|
||||||
_contentManager = contentManager;
|
|
||||||
_transactionManager = transactionManager;
|
|
||||||
_extendViewModels = extendViewModels;
|
_extendViewModels = extendViewModels;
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
Logger = NullLogger.Instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IOrchardServices Services { get; private set; }
|
public IOrchardServices Services { get; private set; }
|
||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
public ILogger Logger { get; set; }
|
|
||||||
public ActionResult Index() {
|
public ActionResult Index() {
|
||||||
return List();
|
return List();
|
||||||
}
|
}
|
||||||
@@ -69,32 +53,14 @@ namespace Orchard.ContentTypes.Controllers {
|
|||||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to create a content type.")))
|
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to create a content type.")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var model = new ContentTypeDefinition("");
|
if (!ModelState.IsValid)
|
||||||
TryUpdateModel(model);
|
|
||||||
|
|
||||||
if (!ModelState.IsValid) {
|
|
||||||
Services.TransactionManager.Cancel();
|
|
||||||
return View(viewModel);
|
return View(viewModel);
|
||||||
}
|
|
||||||
|
|
||||||
_contentDefinitionService.AddTypeDefinition(model);
|
_contentDefinitionService.AddTypeDefinition(viewModel.DisplayName);
|
||||||
|
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
class Updater : IUpdateModel {
|
|
||||||
public AdminController Thunk { get; set; }
|
|
||||||
public Func<string, string> _prefix = x => x;
|
|
||||||
|
|
||||||
public bool TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) where TModel : class {
|
|
||||||
return Thunk.TryUpdateModel(model, _prefix(prefix), includeProperties, excludeProperties);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddModelError(string key, LocalizedString errorMessage) {
|
|
||||||
Thunk.ModelState.AddModelError(_prefix(key), errorMessage.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ActionResult Edit(string id) {
|
public ActionResult Edit(string id) {
|
||||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type.")))
|
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type.")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
@@ -106,36 +72,30 @@ namespace Orchard.ContentTypes.Controllers {
|
|||||||
|
|
||||||
var viewModel = new EditTypeViewModel(contentTypeDefinition);
|
var viewModel = new EditTypeViewModel(contentTypeDefinition);
|
||||||
viewModel.Parts = viewModel.Parts.ToArray();
|
viewModel.Parts = viewModel.Parts.ToArray();
|
||||||
|
|
||||||
viewModel.Templates = _extendViewModels.TypeEditor(contentTypeDefinition);
|
viewModel.Templates = _extendViewModels.TypeEditor(contentTypeDefinition);
|
||||||
|
|
||||||
var entries = viewModel.Parts.Join(contentTypeDefinition.Parts,
|
var entries = viewModel.Parts.Join(contentTypeDefinition.Parts,
|
||||||
m => m.PartDefinition.Name,
|
m => m.PartDefinition.Name,
|
||||||
d => d.PartDefinition.Name,
|
d => d.PartDefinition.Name,
|
||||||
(model, definition) => new { model, definition });
|
(model, definition) => new {model, definition});
|
||||||
foreach (var entry in entries) {
|
foreach (var entry in entries)
|
||||||
entry.model.Templates = _extendViewModels.TypePartEditor(entry.definition);
|
entry.model.Templates = _extendViewModels.TypePartEditor(entry.definition);
|
||||||
}
|
|
||||||
|
|
||||||
return View(viewModel);
|
return View(viewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost, ActionName("Edit")]
|
[HttpPost, ActionName("Edit")]
|
||||||
public ActionResult EditPOST(string id) {
|
public ActionResult EditPOST(EditTypeViewModel viewModel) {
|
||||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type.")))
|
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type.")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(id);
|
var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(viewModel.Name);
|
||||||
|
|
||||||
if (contentTypeDefinition == null)
|
if (contentTypeDefinition == null)
|
||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
var updater = new Updater { Thunk = this };
|
var updater = new Updater(this);
|
||||||
|
_contentDefinitionManager.AlterTypeDefinition(viewModel.Name, typeBuilder => {
|
||||||
var viewModel = new EditTypeViewModel();
|
|
||||||
TryUpdateModel(viewModel);
|
|
||||||
|
|
||||||
|
|
||||||
_contentDefinitionManager.AlterTypeDefinition(id, typeBuilder => {
|
|
||||||
|
|
||||||
typeBuilder.DisplayedAs(viewModel.DisplayName);
|
typeBuilder.DisplayedAs(viewModel.DisplayName);
|
||||||
|
|
||||||
@@ -156,63 +116,14 @@ namespace Orchard.ContentTypes.Controllers {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid) {
|
||||||
_transactionManager.Cancel();
|
Services.TransactionManager.Cancel();
|
||||||
return View(viewModel);
|
return View(viewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
//var contentTypeDefinitionParts = viewModel.Parts.Select(GenerateTypePart).ToList();
|
|
||||||
//if (viewModel.Fields.Any())
|
|
||||||
// contentTypeDefinitionParts.Add(GenerateTypePart(viewModel));
|
|
||||||
|
|
||||||
////todo: apply the changes along the lines of but definately not resembling
|
|
||||||
//// for now this _might_ just get a little messy ->
|
|
||||||
//_contentDefinitionService.AlterTypeDefinition(
|
|
||||||
// new ContentTypeDefinition(
|
|
||||||
// viewModel.Name,
|
|
||||||
// viewModel.DisplayName,
|
|
||||||
// contentTypeDefinitionParts,
|
|
||||||
// viewModel.Settings
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
|
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ContentTypeDefinition.Part GenerateTypePart(EditTypePartViewModel viewModel) {
|
|
||||||
return new ContentTypeDefinition.Part(
|
|
||||||
new ContentPartDefinition(
|
|
||||||
viewModel.PartDefinition.Name,
|
|
||||||
viewModel.PartDefinition.Fields.Select(
|
|
||||||
f => new ContentPartDefinition.Field(
|
|
||||||
new ContentFieldDefinition(f.FieldDefinition.Name),
|
|
||||||
f.Name,
|
|
||||||
f.Settings
|
|
||||||
)
|
|
||||||
),
|
|
||||||
viewModel.PartDefinition.Settings
|
|
||||||
),
|
|
||||||
viewModel.Settings
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ContentTypeDefinition.Part GenerateTypePart(EditTypeViewModel viewModel) {
|
|
||||||
return new ContentTypeDefinition.Part(
|
|
||||||
new ContentPartDefinition(
|
|
||||||
viewModel.Name,
|
|
||||||
viewModel.Fields.Select(
|
|
||||||
f => new ContentPartDefinition.Field(
|
|
||||||
new ContentFieldDefinition(f.FieldDefinition.Name),
|
|
||||||
f.Name,
|
|
||||||
f.Settings
|
|
||||||
)
|
|
||||||
),
|
|
||||||
null
|
|
||||||
),
|
|
||||||
null
|
|
||||||
);
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Parts
|
#region Parts
|
||||||
@@ -226,28 +137,33 @@ namespace Orchard.ContentTypes.Controllers {
|
|||||||
if (contentPartDefinition == null)
|
if (contentPartDefinition == null)
|
||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
return View(new EditPartViewModel(contentPartDefinition));
|
var viewModel = new EditPartViewModel(contentPartDefinition) {
|
||||||
|
Templates = _extendViewModels.PartEditor(contentPartDefinition)
|
||||||
|
};
|
||||||
|
|
||||||
|
return View(viewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost, ActionName("EditPart")]
|
[HttpPost, ActionName("EditPart")]
|
||||||
public ActionResult EditPartPOST(string id) {
|
public ActionResult EditPartPOST(EditPartViewModel viewModel) {
|
||||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a part.")))
|
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a part.")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id);
|
var contentPartDefinition = _contentDefinitionService.GetPartDefinition(viewModel.Name);
|
||||||
|
|
||||||
if (contentPartDefinition == null)
|
if (contentPartDefinition == null)
|
||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
var viewModel = new EditPartViewModel();
|
var updater = new Updater(this);
|
||||||
TryUpdateModel(viewModel);
|
_contentDefinitionManager.AlterPartDefinition(viewModel.Name, partBuilder => {
|
||||||
|
// allow extensions to alter part configuration
|
||||||
|
viewModel.Templates = _extendViewModels.PartEditorUpdate(partBuilder, updater);
|
||||||
|
});
|
||||||
|
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid) {
|
||||||
return EditPart(id);
|
Services.TransactionManager.Cancel();
|
||||||
|
return View(viewModel);
|
||||||
//todo: apply the changes along the lines of but definately not resembling
|
}
|
||||||
// for now this _might_ just get a little messy ->
|
|
||||||
_contentDefinitionService.AlterPartDefinition(GeneratePart(viewModel));
|
|
||||||
|
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
@@ -319,21 +235,25 @@ namespace Orchard.ContentTypes.Controllers {
|
|||||||
return RedirectToAction("EditPart", new { id });
|
return RedirectToAction("EditPart", new { id });
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ContentPartDefinition GeneratePart(EditPartViewModel viewModel) {
|
#endregion
|
||||||
return new ContentPartDefinition(
|
|
||||||
viewModel.Name,
|
class Updater : IUpdateModel {
|
||||||
viewModel.Fields.Select(
|
private readonly AdminController _thunk;
|
||||||
f => new ContentPartDefinition.Field(
|
|
||||||
new ContentFieldDefinition(f.FieldDefinition.Name),
|
public Updater(AdminController thunk) {
|
||||||
f.Name,
|
_thunk = thunk;
|
||||||
f.Settings
|
|
||||||
)
|
|
||||||
),
|
|
||||||
viewModel.Settings
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
public Func<string, string> _prefix = x => x;
|
||||||
|
|
||||||
|
public bool TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) where TModel : class {
|
||||||
|
return _thunk.TryUpdateModel(model, _prefix(prefix), includeProperties, excludeProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddModelError(string key, LocalizedString errorMessage) {
|
||||||
|
_thunk.ModelState.AddModelError(_prefix(key), errorMessage.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,23 +31,21 @@ namespace Orchard.ContentTypes.Services {
|
|||||||
return _contentDefinitionManager.GetTypeDefinition(name);
|
return _contentDefinitionManager.GetTypeDefinition(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddTypeDefinition(ContentTypeDefinition contentTypeDefinition) {
|
public void AddTypeDefinition(string displayName) {
|
||||||
var typeName = string.IsNullOrWhiteSpace(contentTypeDefinition.Name)
|
var name = GenerateTypeName(displayName);
|
||||||
? GenerateTypeName(contentTypeDefinition.DisplayName)
|
|
||||||
: contentTypeDefinition.Name;
|
|
||||||
|
|
||||||
while (_contentDefinitionManager.GetTypeDefinition(typeName) != null)
|
while (_contentDefinitionManager.GetTypeDefinition(name) != null)
|
||||||
typeName = VersionTypeName(typeName);
|
name = VersionTypeName(name);
|
||||||
|
|
||||||
//just giving the new type some default parts for now
|
//just giving the new type some default parts for now
|
||||||
|
_contentDefinitionManager.StoreTypeDefinition(new ContentTypeDefinition(name) {DisplayName = displayName});
|
||||||
_contentDefinitionManager.AlterTypeDefinition(
|
_contentDefinitionManager.AlterTypeDefinition(
|
||||||
typeName,
|
name,
|
||||||
cfg => cfg.DisplayedAs(contentTypeDefinition.DisplayName)
|
cfg => cfg.WithPart("CommonAspect")
|
||||||
.WithPart("CommonAspect")
|
|
||||||
//.WithPart("RoutableAspect") //need to go the new routable route
|
//.WithPart("RoutableAspect") //need to go the new routable route
|
||||||
.WithPart("BodyAspect"));
|
.WithPart("BodyAspect"));
|
||||||
|
|
||||||
Services.Notifier.Information(T("Created content type: {0}", contentTypeDefinition.DisplayName));
|
Services.Notifier.Information(T("Created content type: {0}", displayName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition) {
|
public void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition) {
|
||||||
|
@@ -6,7 +6,7 @@ namespace Orchard.ContentTypes.Services {
|
|||||||
public interface IContentDefinitionService : IDependency {
|
public interface IContentDefinitionService : IDependency {
|
||||||
IEnumerable<ContentTypeDefinition> GetTypeDefinitions();
|
IEnumerable<ContentTypeDefinition> GetTypeDefinitions();
|
||||||
ContentTypeDefinition GetTypeDefinition(string name);
|
ContentTypeDefinition GetTypeDefinition(string name);
|
||||||
void AddTypeDefinition(ContentTypeDefinition contentTypeDefinition);
|
void AddTypeDefinition(string displayName);
|
||||||
void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition);
|
void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition);
|
||||||
void RemoveTypeDefinition(string name);
|
void RemoveTypeDefinition(string name);
|
||||||
|
|
||||||
|
@@ -66,6 +66,7 @@ namespace Orchard.ContentTypes.ViewModels {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
public IEnumerable<TemplateViewModel> Templates { get; set; }
|
||||||
public IEnumerable<EditPartFieldViewModel> Fields { get; set; }
|
public IEnumerable<EditPartFieldViewModel> Fields { get; set; }
|
||||||
public SettingsDictionary Settings { get; set; }
|
public SettingsDictionary Settings { get; set; }
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@ using (Html.BeginFormAntiForgeryPost()) { %>
|
|||||||
<%--// has unintended consequences (renamging the part) - changing the name creates a new part of that name--%>
|
<%--// has unintended consequences (renamging the part) - changing the name creates a new part of that name--%>
|
||||||
<%:Html.TextBoxFor(m => m.Name, new {@class = "textMedium"}) %>
|
<%:Html.TextBoxFor(m => m.Name, new {@class = "textMedium"}) %>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<%:Html.EditorFor(m => m.Settings, "Settings", "") %>
|
<% Html.RenderTemplates(Model.Templates); %>
|
||||||
<h2><%:T("Fields") %></h2>
|
<h2><%:T("Fields") %></h2>
|
||||||
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddFieldTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" }) %></div>
|
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddFieldTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" }) %></div>
|
||||||
<%:Html.EditorFor(m => m.Fields, "Fields", "") %>
|
<%:Html.EditorFor(m => m.Fields, "Fields", "") %>
|
||||||
|
@@ -5,6 +5,7 @@ using Orchard.Comments.Models;
|
|||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.MetaData;
|
using Orchard.ContentManagement.MetaData;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
|
using Orchard.Core.Common.Settings;
|
||||||
using Orchard.Core.Navigation.Models;
|
using Orchard.Core.Navigation.Models;
|
||||||
using Orchard.Core.Settings.Models;
|
using Orchard.Core.Settings.Models;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
@@ -150,6 +151,7 @@ namespace Orchard.Setup.Services {
|
|||||||
contentDefinitionManager.AlterTypeDefinition("BlogPost", cfg => cfg.DisplayedAs("Blog Post").WithPart("HasComments").WithPart("HasTags").WithPart("Localized"));
|
contentDefinitionManager.AlterTypeDefinition("BlogPost", cfg => cfg.DisplayedAs("Blog Post").WithPart("HasComments").WithPart("HasTags").WithPart("Localized"));
|
||||||
contentDefinitionManager.AlterTypeDefinition("Page", cfg => cfg.DisplayedAs("Page").WithPart("HasComments").WithPart("HasTags").WithPart("Localized"));
|
contentDefinitionManager.AlterTypeDefinition("Page", cfg => cfg.DisplayedAs("Page").WithPart("HasComments").WithPart("HasTags").WithPart("Localized"));
|
||||||
contentDefinitionManager.AlterTypeDefinition("SandboxPage", cfg => cfg.DisplayedAs("Sandbox Page").WithPart("HasComments").WithPart("HasTags").WithPart("Localized"));
|
contentDefinitionManager.AlterTypeDefinition("SandboxPage", cfg => cfg.DisplayedAs("Sandbox Page").WithPart("HasComments").WithPart("HasTags").WithPart("Localized"));
|
||||||
|
contentDefinitionManager.AlterPartDefinition("BodyAspect", cfg => cfg.WithSetting("BodyPartSettings.FlavorDefault", BodyPartSettings.FlavorDefaultDefault));
|
||||||
|
|
||||||
// create home page as a CMS page
|
// create home page as a CMS page
|
||||||
var page = contentManager.Create("Page", VersionOptions.Draft);
|
var page = contentManager.Create("Page", VersionOptions.Draft);
|
||||||
|
@@ -16,6 +16,7 @@ namespace Orchard.ContentManagement {
|
|||||||
public ContentTypeDefinition TypeDefinition { get { return ContentItem.TypeDefinition; } }
|
public ContentTypeDefinition TypeDefinition { get { return ContentItem.TypeDefinition; } }
|
||||||
public ContentTypeDefinition.Part TypePartDefinition { get; set; }
|
public ContentTypeDefinition.Part TypePartDefinition { get; set; }
|
||||||
public ContentPartDefinition PartDefinition { get { return TypePartDefinition.PartDefinition; } }
|
public ContentPartDefinition PartDefinition { get { return TypePartDefinition.PartDefinition; } }
|
||||||
|
public SettingsDictionary Settings { get { return TypePartDefinition.Settings; } }
|
||||||
|
|
||||||
public IEnumerable<ContentField> Fields { get { return _fields; } }
|
public IEnumerable<ContentField> Fields { get { return _fields; } }
|
||||||
|
|
||||||
|
@@ -25,6 +25,8 @@ namespace Orchard.ContentManagement.MetaData.Builders {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Name { get { return _name; } }
|
||||||
|
|
||||||
public ContentPartDefinition Build() {
|
public ContentPartDefinition Build() {
|
||||||
return new ContentPartDefinition(_name, _fields, _settings);
|
return new ContentPartDefinition(_name, _fields, _settings);
|
||||||
}
|
}
|
||||||
|
@@ -9,9 +9,11 @@ namespace Orchard.ContentManagement.MetaData {
|
|||||||
public interface IContentDefinitionEditorEvents : IEventHandler {
|
public interface IContentDefinitionEditorEvents : IEventHandler {
|
||||||
IEnumerable<TemplateViewModel> TypeEditor(ContentTypeDefinition definition);
|
IEnumerable<TemplateViewModel> TypeEditor(ContentTypeDefinition definition);
|
||||||
IEnumerable<TemplateViewModel> TypePartEditor(ContentTypeDefinition.Part definition);
|
IEnumerable<TemplateViewModel> TypePartEditor(ContentTypeDefinition.Part definition);
|
||||||
|
IEnumerable<TemplateViewModel> PartEditor(ContentPartDefinition definition);
|
||||||
|
|
||||||
IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel);
|
IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel);
|
||||||
IEnumerable<TemplateViewModel> TypePartEditorUpdate(ContentTypeDefinitionBuilder.PartConfigurer builder, IUpdateModel updateModel);
|
IEnumerable<TemplateViewModel> TypePartEditorUpdate(ContentTypeDefinitionBuilder.PartConfigurer builder, IUpdateModel updateModel);
|
||||||
|
IEnumerable<TemplateViewModel> PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class ContentDefinitionEditorEventsBase : IContentDefinitionEditorEvents {
|
public abstract class ContentDefinitionEditorEventsBase : IContentDefinitionEditorEvents {
|
||||||
@@ -23,6 +25,10 @@ namespace Orchard.ContentManagement.MetaData {
|
|||||||
return Enumerable.Empty<TemplateViewModel>();
|
return Enumerable.Empty<TemplateViewModel>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual IEnumerable<TemplateViewModel> PartEditor(ContentPartDefinition definition) {
|
||||||
|
return Enumerable.Empty<TemplateViewModel>();
|
||||||
|
}
|
||||||
|
|
||||||
public virtual IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) {
|
public virtual IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) {
|
||||||
return Enumerable.Empty<TemplateViewModel>();
|
return Enumerable.Empty<TemplateViewModel>();
|
||||||
}
|
}
|
||||||
@@ -31,6 +37,10 @@ namespace Orchard.ContentManagement.MetaData {
|
|||||||
return Enumerable.Empty<TemplateViewModel>();
|
return Enumerable.Empty<TemplateViewModel>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual IEnumerable<TemplateViewModel> PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel) {
|
||||||
|
return Enumerable.Empty<TemplateViewModel>();
|
||||||
|
}
|
||||||
|
|
||||||
protected static TemplateViewModel DefinitionTemplate<TModel>(TModel model) {
|
protected static TemplateViewModel DefinitionTemplate<TModel>(TModel model) {
|
||||||
return new TemplateViewModel(model, typeof(TModel).Name) {
|
return new TemplateViewModel(model, typeof(TModel).Name) {
|
||||||
TemplateName = "DefinitionTemplates/" + typeof(TModel).Name
|
TemplateName = "DefinitionTemplates/" + typeof(TModel).Name
|
||||||
|
Reference in New Issue
Block a user