mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 10:54:50 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -57,9 +57,9 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
if (!ModelState.IsValid)
|
||||
return View(viewModel);
|
||||
|
||||
_contentDefinitionService.AddTypeDefinition(viewModel.DisplayName);
|
||||
var definition = _contentDefinitionService.AddTypeDefinition(viewModel.DisplayName);
|
||||
|
||||
return RedirectToAction("Index");
|
||||
return RedirectToAction("Edit", new { id = definition.Name });
|
||||
}
|
||||
|
||||
public ActionResult Edit(string id) {
|
||||
@@ -71,42 +71,19 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
if (contentTypeDefinition == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
var viewModel = new EditTypeViewModel(contentTypeDefinition);
|
||||
viewModel.Parts = viewModel.Parts.ToArray();
|
||||
viewModel.Templates = _extendViewModels.TypeEditor(contentTypeDefinition);
|
||||
var viewModel = new EditTypeViewModel(contentTypeDefinition) {
|
||||
Templates = _extendViewModels.TypeEditor(contentTypeDefinition)
|
||||
};
|
||||
|
||||
var entries = viewModel.Parts.Join(contentTypeDefinition.Parts,
|
||||
m => m.PartDefinition.Name,
|
||||
d => d.PartDefinition.Name,
|
||||
(model, definition) => new {model, definition});
|
||||
foreach (var entry in entries) {
|
||||
entry.model.PartDefinition.Fields = entry.model.PartDefinition.Fields.ToArray();
|
||||
entry.model.Templates = _extendViewModels.TypePartEditor(entry.definition);
|
||||
|
||||
var fields = entry.model.PartDefinition.Fields.Join(entry.definition.PartDefinition.Fields,
|
||||
m => m.Name,
|
||||
d => d.Name,
|
||||
(model, definition) => new { model, definition });
|
||||
|
||||
foreach (var field in fields) {
|
||||
field.model.Templates = _extendViewModels.PartFieldEditor(field.definition);
|
||||
}
|
||||
foreach (var part in viewModel.Parts) {
|
||||
part.Templates = _extendViewModels.TypePartEditor(new ContentTypeDefinition.Part(part.PartDefinition.Definition, part.Settings));
|
||||
foreach (var field in part.PartDefinition.Fields)
|
||||
field.Templates = _extendViewModels.PartFieldEditor(new ContentPartDefinition.Field(field.FieldDefinition.Definition, field.Name, field.Settings));
|
||||
}
|
||||
|
||||
|
||||
//Oy, this action is getting massive :(
|
||||
//todo: put this action on a diet
|
||||
var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id);
|
||||
if (contentPartDefinition != null) {
|
||||
viewModel.Fields = viewModel.Fields.ToArray();
|
||||
var fields = viewModel.Fields.Join(contentPartDefinition.Fields,
|
||||
m => m.Name,
|
||||
d => d.Name,
|
||||
(model, definition) => new { model, definition });
|
||||
|
||||
foreach (var field in fields) {
|
||||
field.model.Templates = _extendViewModels.PartFieldEditor(field.definition);
|
||||
}
|
||||
if (viewModel.Fields.Any()) {
|
||||
foreach (var field in viewModel.Fields)
|
||||
field.Templates = _extendViewModels.PartFieldEditor(new ContentPartDefinition.Field(field.FieldDefinition.Definition, field.Name, field.Settings));
|
||||
}
|
||||
|
||||
return View(viewModel);
|
||||
@@ -288,6 +265,26 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
});
|
||||
}
|
||||
|
||||
public ActionResult CreatePart() {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to create a content part.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
return View(new CreatePartViewModel());
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("CreatePart")]
|
||||
public ActionResult CreatePartPOST(CreatePartViewModel viewModel) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to create a content part.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return View(viewModel);
|
||||
|
||||
var definition = _contentDefinitionService.AddPartDefinition(viewModel.Name);
|
||||
|
||||
return RedirectToAction("EditPart", new { id = definition.Name });
|
||||
}
|
||||
|
||||
public ActionResult EditPart(string id) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
@@ -325,7 +322,7 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
return RedirectToAction("Index");
|
||||
return RedirectToAction("ListParts");
|
||||
}
|
||||
|
||||
public ActionResult AddFieldTo(string id) {
|
||||
|
@@ -77,6 +77,7 @@
|
||||
<Compile Include="Services\ContentDefinitionService.cs" />
|
||||
<Compile Include="Services\IContentDefinitionService.cs" />
|
||||
<Compile Include="ViewModels\AddFieldViewModel.cs" />
|
||||
<Compile Include="ViewModels\CreatePartViewModel.cs" />
|
||||
<Compile Include="ViewModels\ListContentPartsViewModel.cs" />
|
||||
<Compile Include="ViewModels\RemoveFieldViewModel.cs" />
|
||||
<Compile Include="ViewModels\RemovePartViewModel.cs" />
|
||||
@@ -90,6 +91,7 @@
|
||||
<Content Include="Styles\admin.css" />
|
||||
<Content Include="Views\Admin\AddFieldTo.ascx" />
|
||||
<Content Include="Views\Admin\AddPartsTo.ascx" />
|
||||
<Content Include="Views\Admin\CreatePart.ascx" />
|
||||
<Content Include="Views\Admin\ListParts.ascx" />
|
||||
<Content Include="Views\Admin\RemoveFieldFrom.ascx" />
|
||||
<Content Include="Views\Admin\RemovePartFrom.ascx" />
|
||||
|
@@ -31,21 +31,24 @@ namespace Orchard.ContentTypes.Services {
|
||||
return _contentDefinitionManager.GetTypeDefinition(name);
|
||||
}
|
||||
|
||||
public void AddTypeDefinition(string displayName) {
|
||||
var name = GenerateTypeName(displayName);
|
||||
public ContentTypeDefinition AddTypeDefinition(string displayName) {
|
||||
var name = GenerateName(displayName);
|
||||
|
||||
while (_contentDefinitionManager.GetTypeDefinition(name) != null)
|
||||
name = VersionTypeName(name);
|
||||
name = VersionName(name);
|
||||
|
||||
var contentTypeDefinition = new ContentTypeDefinition(name) { DisplayName = displayName };
|
||||
//just giving the new type some default parts for now
|
||||
_contentDefinitionManager.StoreTypeDefinition(new ContentTypeDefinition(name) {DisplayName = displayName});
|
||||
_contentDefinitionManager.StoreTypeDefinition(contentTypeDefinition);
|
||||
_contentDefinitionManager.AlterTypeDefinition(
|
||||
name,
|
||||
contentTypeDefinition.Name,
|
||||
cfg => cfg.WithPart("CommonAspect")
|
||||
//.WithPart("RoutableAspect") //need to go the new routable route
|
||||
.WithPart("BodyAspect"));
|
||||
|
||||
Services.Notifier.Information(T("The \"{0}\" content type has created.", displayName));
|
||||
Services.Notifier.Information(T("The \"{0}\" content type has created.", contentTypeDefinition.DisplayName));
|
||||
|
||||
return contentTypeDefinition;
|
||||
}
|
||||
|
||||
public void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition) {
|
||||
@@ -70,8 +73,16 @@ namespace Orchard.ContentTypes.Services {
|
||||
return _contentDefinitionManager.GetPartDefinition(name);
|
||||
}
|
||||
|
||||
public void AddPartDefinition(ContentPartDefinition contentPartDefinition) {
|
||||
throw new NotImplementedException();
|
||||
public ContentPartDefinition AddPartDefinition(string name) {
|
||||
name = GenerateName(name);
|
||||
|
||||
while (_contentDefinitionManager.GetPartDefinition(name) != null)
|
||||
name = VersionName(name);
|
||||
|
||||
var contentPartDefinition = new ContentPartDefinition(name);
|
||||
_contentDefinitionManager.StorePartDefinition(contentPartDefinition);
|
||||
|
||||
return contentPartDefinition;
|
||||
}
|
||||
|
||||
public void AlterPartDefinition(ContentPartDefinition contentPartDefinition) {
|
||||
@@ -87,7 +98,7 @@ namespace Orchard.ContentTypes.Services {
|
||||
}
|
||||
|
||||
//gratuitously stolen from the RoutableService
|
||||
private static string GenerateTypeName(string displayName) {
|
||||
private static string GenerateName(string displayName) {
|
||||
if (string.IsNullOrWhiteSpace(displayName))
|
||||
return "";
|
||||
|
||||
@@ -104,7 +115,7 @@ namespace Orchard.ContentTypes.Services {
|
||||
return name.ToLowerInvariant();
|
||||
}
|
||||
|
||||
private static string VersionTypeName(string name) {
|
||||
private static string VersionName(string name) {
|
||||
int version;
|
||||
var nameParts = name.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
|
@@ -6,13 +6,13 @@ namespace Orchard.ContentTypes.Services {
|
||||
public interface IContentDefinitionService : IDependency {
|
||||
IEnumerable<ContentTypeDefinition> GetTypeDefinitions();
|
||||
ContentTypeDefinition GetTypeDefinition(string name);
|
||||
void AddTypeDefinition(string displayName);
|
||||
ContentTypeDefinition AddTypeDefinition(string displayName);
|
||||
void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition);
|
||||
void RemoveTypeDefinition(string name);
|
||||
|
||||
IEnumerable<ContentPartDefinition> GetPartDefinitions();
|
||||
ContentPartDefinition GetPartDefinition(string name);
|
||||
void AddPartDefinition(ContentPartDefinition contentPartDefinition);
|
||||
ContentPartDefinition AddPartDefinition(string name);
|
||||
void AlterPartDefinition(ContentPartDefinition contentPartDefinition);
|
||||
void RemovePartDefinition(string name);
|
||||
|
||||
|
@@ -0,0 +1,7 @@
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.ContentTypes.ViewModels {
|
||||
public class CreatePartViewModel : BaseViewModel {
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
@@ -15,12 +15,14 @@ namespace Orchard.ContentTypes.ViewModels {
|
||||
Name = contentTypeDefinition.Name;
|
||||
DisplayName = contentTypeDefinition.DisplayName;
|
||||
Settings = contentTypeDefinition.Settings;
|
||||
Fields = GetTypeFields(contentTypeDefinition);
|
||||
Parts = GetTypeParts(contentTypeDefinition);
|
||||
Fields = GetTypeFields(contentTypeDefinition).ToList();
|
||||
Parts = GetTypeParts(contentTypeDefinition).ToList();
|
||||
Definition = contentTypeDefinition;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public string DisplayName { get; set; }
|
||||
public ContentTypeDefinition Definition { get; private set; }
|
||||
public IEnumerable<TemplateViewModel> Templates { get; set; }
|
||||
|
||||
public SettingsDictionary Settings { get; set; }
|
||||
@@ -62,13 +64,15 @@ namespace Orchard.ContentTypes.ViewModels {
|
||||
}
|
||||
public EditPartViewModel(ContentPartDefinition contentPartDefinition) {
|
||||
Name = contentPartDefinition.Name;
|
||||
Fields = contentPartDefinition.Fields.Select(f => new EditPartFieldViewModel(f) { Part = this });
|
||||
Fields = contentPartDefinition.Fields.Select(f => new EditPartFieldViewModel(f) { Part = this }).ToList();
|
||||
Settings = contentPartDefinition.Settings;
|
||||
Definition = contentPartDefinition;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public IEnumerable<TemplateViewModel> Templates { get; set; }
|
||||
public IEnumerable<EditPartFieldViewModel> Fields { get; set; }
|
||||
public ContentPartDefinition Definition { get; private set; }
|
||||
public SettingsDictionary Settings { get; set; }
|
||||
}
|
||||
|
||||
@@ -93,8 +97,10 @@ namespace Orchard.ContentTypes.ViewModels {
|
||||
public EditFieldViewModel() { }
|
||||
public EditFieldViewModel(ContentFieldDefinition contentFieldDefinition) {
|
||||
Name = contentFieldDefinition.Name;
|
||||
Definition = contentFieldDefinition;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public ContentFieldDefinition Definition { get; private set; }
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.CreateTypeViewModel>" %>
|
||||
|
||||
<h1><%:Html.TitleForPage(T("New Content Type").ToString())%></h1><%
|
||||
using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<%:Html.ValidationSummary() %>
|
||||
|
@@ -0,0 +1,12 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.CreatePartViewModel>" %>
|
||||
<h1><%:Html.TitleForPage(T("New Content Part").ToString())%></h1><%
|
||||
using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<%:Html.ValidationSummary() %>
|
||||
<fieldset>
|
||||
<label for="DisplayName"><%:T("Name") %></label>
|
||||
<%:Html.TextBoxFor(m => m.Name, new {@class = "textMedium", autofocus = "autofocus"}) %>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<button class="primaryAction" type="submit"><%:T("Create") %></button>
|
||||
</fieldset><%
|
||||
} %>
|
@@ -1,14 +1,14 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.EditPartViewModel>" %>
|
||||
<%
|
||||
Html.RegisterStyle("admin.css"); %>
|
||||
<% Html.RegisterStyle("admin.css"); %>
|
||||
<h1><%:Html.TitleForPage(T("Edit Part").ToString()) %></h1>
|
||||
<p class="breadcrumb"><%:Html.ActionLink(T("Content Types").Text, "index") %><%:T(" > ") %><%:T("Edit Part") %></p><%
|
||||
<p class="breadcrumb"><%:Html.ActionLink(T("Content Types").Text, "index") %><%:T(" > ") %><%:Html.ActionLink(T("Content Parts").Text, "listparts") %><%:T(" > ") %><%:T("Edit Part") %></p><%
|
||||
using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<%:Html.ValidationSummary() %>
|
||||
<fieldset>
|
||||
<label for="Name"><%:T("Name") %></label>
|
||||
<%--// 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", disabled = "disabled"}) %>
|
||||
<%:Html.HiddenFor(m => m.Name) %>
|
||||
</fieldset>
|
||||
<% Html.RenderTemplates(Model.Templates); %>
|
||||
<h2><%:T("Fields") %></h2>
|
||||
|
@@ -1,6 +1,5 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.ListContentTypesViewModel>" %>
|
||||
<%
|
||||
Html.RegisterStyle("admin.css"); %>
|
||||
<% Html.RegisterStyle("admin.css"); %>
|
||||
<h1><%:Html.TitleForPage(T("Content Types").ToString())%></h1>
|
||||
<div class="manage">
|
||||
<%:Html.ActionLink(T("Create new type").ToString(), "Create", new{Controller="Admin",Area="Orchard.ContentTypes"}, new { @class = "button primaryAction" }) %>
|
||||
|
Reference in New Issue
Block a user