mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-07-16 07:26:43 +08:00
Create Display/Editor location settings for Parts and Fields
--HG-- branch : dev
This commit is contained in:
parent
d8a1478200
commit
cda6ae3d06
6
src/Orchard.Web/Core/Common/Settings/LocationSettings.cs
Normal file
6
src/Orchard.Web/Core/Common/Settings/LocationSettings.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
namespace Orchard.Core.Common.Settings {
|
||||||
|
public class LocationSettings {
|
||||||
|
public string Zone { get; set; }
|
||||||
|
public string Position { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
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 LocationSettingsEditorEvents : ContentDefinitionEditorEventsBase {
|
||||||
|
|
||||||
|
public override IEnumerable<TemplateViewModel> TypePartEditor(ContentTypeDefinition.Part definition) {
|
||||||
|
yield return TypePartEditorForLocation(definition, "DisplayLocation");
|
||||||
|
yield return TypePartEditorForLocation(definition, "EditorLocation");
|
||||||
|
}
|
||||||
|
|
||||||
|
private TemplateViewModel TypePartEditorForLocation(ContentTypeDefinition.Part definition, string locationSettings) {
|
||||||
|
// Look for the setting in the most specific settings first (part definition in type)
|
||||||
|
// then in the global part definition.
|
||||||
|
var settings =
|
||||||
|
definition.Settings.TryGetModel<LocationSettings>(locationSettings) ??
|
||||||
|
definition.PartDefinition.Settings.GetModel<LocationSettings>(locationSettings);
|
||||||
|
|
||||||
|
return DefinitionTemplate(settings, locationSettings, locationSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<TemplateViewModel> TypePartEditorUpdate(ContentTypeDefinitionBuilder.PartConfigurer builder, IUpdateModel updateModel) {
|
||||||
|
yield return TypePartEditorUpdateForLocation(builder, updateModel, "DisplayLocation");
|
||||||
|
yield return TypePartEditorUpdateForLocation(builder, updateModel, "EditorLocation");
|
||||||
|
}
|
||||||
|
|
||||||
|
private TemplateViewModel TypePartEditorUpdateForLocation(ContentTypeDefinitionBuilder.PartConfigurer builder, IUpdateModel updateModel, string locationSettings) {
|
||||||
|
var locationsettings = new LocationSettings();
|
||||||
|
updateModel.TryUpdateModel(locationsettings, locationSettings, null, null);
|
||||||
|
builder.WithLocation("EditorLocation", locationsettings.Zone, locationsettings.Position);
|
||||||
|
return DefinitionTemplate(locationsettings, locationSettings, locationSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<TemplateViewModel> PartFieldEditor(ContentPartDefinition.Field definition) {
|
||||||
|
yield return PartFieldEditorForLocation(definition, "DisplayLocation");
|
||||||
|
yield return PartFieldEditorForLocation(definition, "EditorLocation");
|
||||||
|
}
|
||||||
|
|
||||||
|
private TemplateViewModel PartFieldEditorForLocation(ContentPartDefinition.Field definition, string locationSettings) {
|
||||||
|
var settings = definition.Settings.GetModel<LocationSettings>(locationSettings);
|
||||||
|
return DefinitionTemplate(settings, locationSettings, locationSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override IEnumerable<TemplateViewModel> PartFieldEditorUpdate(ContentPartDefinitionBuilder.FieldConfigurer builder, IUpdateModel updateModel) {
|
||||||
|
yield return PartFieldEditorUpdateForLocation(builder, updateModel, "DisplayLocation");
|
||||||
|
yield return PartFieldEditorUpdateForLocation(builder, updateModel, "EditorLocation");
|
||||||
|
}
|
||||||
|
|
||||||
|
private TemplateViewModel PartFieldEditorUpdateForLocation(ContentPartDefinitionBuilder.FieldConfigurer builder, IUpdateModel updateModel, string locationSettings) {
|
||||||
|
var model = new LocationSettings();
|
||||||
|
updateModel.TryUpdateModel(model, locationSettings, null, null);
|
||||||
|
builder.WithLocation(locationSettings, model.Zone, model.Position);
|
||||||
|
return DefinitionTemplate(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Common.Settings.LocationSettings>" %>
|
||||||
|
<fieldset >
|
||||||
|
<legend><%:T("Display location") %></legend>
|
||||||
|
|
||||||
|
<label for="<%:Html.FieldIdFor(m => m.Zone) %>"><%:T("Zone name") %></label>
|
||||||
|
<%:Html.EditorFor(m=>m.Zone) %>
|
||||||
|
<%:Html.ValidationMessageFor(m => m.Zone)%>
|
||||||
|
|
||||||
|
<label for="<%:Html.FieldIdFor(m => m.Position) %>"><%:T("Location in zone (e.g. 1, 1.0, 2.5.1)") %></label>
|
||||||
|
<%:Html.EditorFor(m=>m.Position) %>
|
||||||
|
<%:Html.ValidationMessageFor(m => m.Position)%>
|
||||||
|
</fieldset>
|
@ -0,0 +1,12 @@
|
|||||||
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Common.Settings.LocationSettings>" %>
|
||||||
|
<fieldset >
|
||||||
|
<legend><%:T("Editor Location") %></legend>
|
||||||
|
|
||||||
|
<label for="<%:Html.FieldIdFor(m => m.Zone) %>"><%:T("Zone name") %></label>
|
||||||
|
<%:Html.EditorFor(m=>m.Zone) %>
|
||||||
|
<%:Html.ValidationMessageFor(m => m.Zone)%>
|
||||||
|
|
||||||
|
<label for="<%:Html.FieldIdFor(m => m.Position) %>"><%:T("Location in zone (e.g. 1, 1.0, 2.5.1)") %></label>
|
||||||
|
<%:Html.EditorFor(m=>m.Position) %>
|
||||||
|
<%:Html.ValidationMessageFor(m => m.Position)%>
|
||||||
|
</fieldset>
|
@ -70,6 +70,8 @@
|
|||||||
<Compile Include="Common\Services\ICommonService.cs" />
|
<Compile Include="Common\Services\ICommonService.cs" />
|
||||||
<Compile Include="Common\Services\CommonService.cs" />
|
<Compile Include="Common\Services\CommonService.cs" />
|
||||||
<Compile Include="Common\Settings\BodySettings.cs" />
|
<Compile Include="Common\Settings\BodySettings.cs" />
|
||||||
|
<Compile Include="Common\Settings\LocationSettingsEditorEvents.cs" />
|
||||||
|
<Compile Include="Common\Settings\LocationSettings.cs" />
|
||||||
<Compile Include="Common\ViewModels\CommonMetadataViewModel.cs" />
|
<Compile Include="Common\ViewModels\CommonMetadataViewModel.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" />
|
||||||
@ -224,6 +226,8 @@
|
|||||||
<Content Include="Common\Module.txt" />
|
<Content Include="Common\Module.txt" />
|
||||||
<Content Include="Common\Views\DefinitionTemplates\BodyTypePartSettings.ascx" />
|
<Content Include="Common\Views\DefinitionTemplates\BodyTypePartSettings.ascx" />
|
||||||
<Content Include="Common\Views\DefinitionTemplates\BodyPartSettings.ascx" />
|
<Content Include="Common\Views\DefinitionTemplates\BodyPartSettings.ascx" />
|
||||||
|
<Content Include="Common\Views\DefinitionTemplates\DisplayLocation.ascx" />
|
||||||
|
<Content Include="Common\Views\DefinitionTemplates\EditorLocation.ascx" />
|
||||||
<Content Include="Common\Views\DisplayTemplates\Fields\Common.TextField.ascx" />
|
<Content Include="Common\Views\DisplayTemplates\Fields\Common.TextField.ascx" />
|
||||||
<Content Include="Common\Views\DisplayTemplates\Parts\Common.Body.SummaryAdmin.ascx" />
|
<Content Include="Common\Views\DisplayTemplates\Parts\Common.Body.SummaryAdmin.ascx" />
|
||||||
<Content Include="Common\Views\DisplayTemplates\Parts\Common.Body.Manage.SummaryAdmin.ascx" />
|
<Content Include="Common\Views\DisplayTemplates\Parts\Common.Body.Manage.SummaryAdmin.ascx" />
|
||||||
|
@ -111,6 +111,38 @@ namespace Orchard.ContentManagement.MetaData.Builders {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ContentPartDefinitionBuilderExtensions {
|
||||||
|
|
||||||
|
public static ContentPartDefinitionBuilder WithLocation(this ContentPartDefinitionBuilder obj, string location, string zone, string position) {
|
||||||
|
if (string.IsNullOrEmpty(zone))
|
||||||
|
zone = null;
|
||||||
|
if (string.IsNullOrEmpty(position))
|
||||||
|
position = null;
|
||||||
|
return obj
|
||||||
|
.WithSetting(string.Format("{0}.Zone", location), zone)
|
||||||
|
.WithSetting(string.Format("{0}.Position", location), position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ContentTypeDefinitionBuilder.PartConfigurer WithLocation(this ContentTypeDefinitionBuilder.PartConfigurer obj, string location, string zone, string position) {
|
||||||
|
if (string.IsNullOrEmpty(zone))
|
||||||
|
zone = null;
|
||||||
|
if (string.IsNullOrEmpty(position))
|
||||||
|
position = null;
|
||||||
|
return obj
|
||||||
|
.WithSetting(string.Format("{0}.Zone", location), zone)
|
||||||
|
.WithSetting(string.Format("{0}.Position", location), position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ContentPartDefinitionBuilder.FieldConfigurer WithLocation(this ContentPartDefinitionBuilder.FieldConfigurer obj, string location, string zone, string position) {
|
||||||
|
if (string.IsNullOrEmpty(zone))
|
||||||
|
zone = null;
|
||||||
|
if (string.IsNullOrEmpty(position))
|
||||||
|
position = null;
|
||||||
|
return obj
|
||||||
|
.WithSetting(string.Format("{0}.Zone", location), zone)
|
||||||
|
.WithSetting(string.Format("{0}.Position", location), position);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -52,8 +52,12 @@ namespace Orchard.ContentManagement.MetaData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static TemplateViewModel DefinitionTemplate<TModel>(TModel model) {
|
protected static TemplateViewModel DefinitionTemplate<TModel>(TModel model) {
|
||||||
return new TemplateViewModel(model, typeof(TModel).Name) {
|
return DefinitionTemplate(model, typeof(TModel).Name, typeof(TModel).Name);
|
||||||
TemplateName = "DefinitionTemplates/" + typeof(TModel).Name
|
}
|
||||||
|
|
||||||
|
protected static TemplateViewModel DefinitionTemplate<TModel>(TModel model, string templateName, string prefix) {
|
||||||
|
return new TemplateViewModel(model, prefix) {
|
||||||
|
TemplateName = "DefinitionTemplates/" + templateName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ namespace Orchard.ContentManagement.MetaData.Models {
|
|||||||
public SettingsDictionary() { }
|
public SettingsDictionary() { }
|
||||||
public SettingsDictionary(IDictionary<string, string> dictionary) : base(dictionary) { }
|
public SettingsDictionary(IDictionary<string, string> dictionary) : base(dictionary) { }
|
||||||
|
|
||||||
private T TryGetModel<T>(string key) where T : class {
|
public T TryGetModel<T>(string key) where T : class {
|
||||||
var binder = new DefaultModelBinder();
|
var binder = new DefaultModelBinder();
|
||||||
var controllerContext = new ControllerContext();
|
var controllerContext = new ControllerContext();
|
||||||
var context = new ModelBindingContext {
|
var context = new ModelBindingContext {
|
||||||
@ -19,6 +19,10 @@ namespace Orchard.ContentManagement.MetaData.Models {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T TryGetModel<T>() where T : class {
|
||||||
|
return TryGetModel<T>(typeof (T).Name);
|
||||||
|
}
|
||||||
|
|
||||||
public T GetModel<T>() where T : class, new() {
|
public T GetModel<T>() where T : class, new() {
|
||||||
return GetModel<T>(typeof(T).Name);
|
return GetModel<T>(typeof(T).Name);
|
||||||
}
|
}
|
||||||
@ -26,13 +30,5 @@ namespace Orchard.ContentManagement.MetaData.Models {
|
|||||||
public T GetModel<T>(string key) where T : class, new() {
|
public T GetModel<T>(string key) where T : class, new() {
|
||||||
return TryGetModel<T>(key) ?? new T();
|
return TryGetModel<T>(key) ?? new T();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ContainsModel<T>() where T : class {
|
|
||||||
return TryGetModel<T>(typeof(T).Name) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ContainsModel<T>(string key) where T : class {
|
|
||||||
return TryGetModel<T>(key) != null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user