mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Adding VectorGraphic element.
This commit is contained in:
@@ -22,17 +22,17 @@ namespace Orchard.Layouts.Drivers {
|
||||
|
||||
if (context.Updater != null) {
|
||||
context.Updater.TryUpdateModel(viewModel, context.Prefix, null, null);
|
||||
element.ImageId = ParseImageId(viewModel.ImageId);
|
||||
element.MediaId = ParseImageId(viewModel.ImageId);
|
||||
}
|
||||
|
||||
var imageId = element.ImageId;
|
||||
var imageId = element.MediaId;
|
||||
viewModel.CurrentImage = imageId != null ? GetImage(imageId.Value) : default(ImagePart);
|
||||
|
||||
return Editor(context, editor);
|
||||
}
|
||||
|
||||
protected override void OnDisplaying(Image element, ElementDisplayContext context) {
|
||||
var imageId = element.ImageId;
|
||||
var imageId = element.MediaId;
|
||||
var image = imageId != null ? GetImage(imageId.Value) : default(ImagePart);
|
||||
context.ElementShape.ImagePart = image;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
using System.Linq;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Layouts.Elements;
|
||||
using Orchard.Layouts.Framework.Display;
|
||||
using Orchard.Layouts.Framework.Drivers;
|
||||
using Orchard.Layouts.ViewModels;
|
||||
using Orchard.MediaLibrary.Models;
|
||||
using ContentItem = Orchard.Layouts.Elements.ContentItem;
|
||||
|
||||
namespace Orchard.Layouts.Drivers {
|
||||
public class VectorGraphicDriver : ElementDriver<VectorGraphic> {
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public VectorGraphicDriver(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
}
|
||||
|
||||
protected override EditorResult OnBuildEditor(VectorGraphic element, ElementEditorContext context) {
|
||||
|
||||
var viewModel = new VectorGraphicEditorViewModel();
|
||||
var editor = context.ShapeFactory.EditorTemplate(TemplateName: "Elements.VectorGraphic", Model: viewModel);
|
||||
|
||||
if (context.Updater != null) {
|
||||
context.Updater.TryUpdateModel(viewModel, context.Prefix, null, null);
|
||||
element.MediaId = ParseVectorGraphicId(viewModel.VectorGraphicId);
|
||||
}
|
||||
|
||||
var mediaId = element.MediaId;
|
||||
viewModel.CurrentVectorGraphic = mediaId != null ? GetVectorGraphic(mediaId.Value) : default(VectorGraphicPart);
|
||||
|
||||
return Editor(context, editor);
|
||||
}
|
||||
|
||||
protected override void OnDisplaying(VectorGraphic element, ElementDisplayContext context) {
|
||||
var mediaId = element.MediaId;
|
||||
var vectorGraphic = mediaId != null ? GetVectorGraphic(mediaId.Value) : default(VectorGraphicPart);
|
||||
context.ElementShape.VectorGraphicPart = vectorGraphic;
|
||||
}
|
||||
|
||||
protected VectorGraphicPart GetVectorGraphic(int id) {
|
||||
return _contentManager.Get<VectorGraphicPart>(id, VersionOptions.Published);
|
||||
}
|
||||
|
||||
private static int? ParseVectorGraphicId(string imageId) {
|
||||
return ContentItem.Deserialize(imageId).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,9 @@ namespace Orchard.Layouts.Elements {
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public int? ImageId {
|
||||
get { return State.Get("ImageId").ToInt32(); }
|
||||
set { State["ImageId"] = value.ToString(); }
|
||||
public int? MediaId {
|
||||
get { return State.Get("MediaId").ToInt32(); }
|
||||
set { State["MediaId"] = value.ToString(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Orchard.Layouts.Framework.Elements;
|
||||
using Orchard.Layouts.Helpers;
|
||||
|
||||
namespace Orchard.Layouts.Elements {
|
||||
public class VectorGraphic : Element {
|
||||
public override string Category {
|
||||
get { return "Media"; }
|
||||
}
|
||||
|
||||
public override bool HasEditor {
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public int? MediaId {
|
||||
get { return State.Get("MediaId").ToInt32(); }
|
||||
set { State["MediaId"] = value.ToString(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -214,9 +214,11 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Controllers\BlueprintAdminController.cs" />
|
||||
<Compile Include="Drivers\VectorGraphicDriver.cs" />
|
||||
<Compile Include="Drivers\ProjectionDriver.cs" />
|
||||
<Compile Include="Drivers\ImageDriver.cs" />
|
||||
<Compile Include="Drivers\ParagraphDriver.cs" />
|
||||
<Compile Include="Elements\VectorGraphic.cs" />
|
||||
<Compile Include="Elements\Image.cs" />
|
||||
<Compile Include="Elements\Paragraph.cs" />
|
||||
<Compile Include="Elements\Projection.cs" />
|
||||
@@ -279,6 +281,7 @@
|
||||
<Compile Include="ViewModels\EditElementBlueprintViewModel.cs" />
|
||||
<Compile Include="ViewModels\ElementWrapperPartViewModel.cs" />
|
||||
<Compile Include="ViewModels\HtmlEditorViewModel.cs" />
|
||||
<Compile Include="ViewModels\VectorGraphicEditorViewModel.cs" />
|
||||
<Compile Include="ViewModels\ImageEditorViewModel.cs" />
|
||||
<Compile Include="ViewModels\MarkdownEditorViewModel.cs" />
|
||||
<Compile Include="ViewModels\ParagraphEditorViewModel.cs" />
|
||||
@@ -365,6 +368,15 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Element-ContentPart.Design.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\EditorTemplates\Elements.VectorGraphic.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Element-Media-VectorGraphic.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Element-Media-VectorGraphic.Design.cshtml" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
using Orchard.MediaLibrary.Models;
|
||||
|
||||
namespace Orchard.Layouts.ViewModels {
|
||||
public class VectorGraphicEditorViewModel {
|
||||
public string VectorGraphicId { get; set; }
|
||||
public VectorGraphicPart CurrentVectorGraphic { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
@using Orchard.ContentManagement
|
||||
@model Orchard.Layouts.ViewModels.VectorGraphicEditorViewModel
|
||||
@{
|
||||
var contentItems = new List<ContentItem>();
|
||||
|
||||
if (Model.CurrentVectorGraphic != null) {
|
||||
contentItems.Add(Model.CurrentVectorGraphic.ContentItem);
|
||||
}
|
||||
}
|
||||
<fieldset>
|
||||
<div>
|
||||
@Display.MediaLibraryPicker(
|
||||
Required: false,
|
||||
Multiple: false,
|
||||
DisplayName: T("Vector Graphic").Text,
|
||||
FieldName: Html.FieldNameFor(m => m.VectorGraphicId),
|
||||
ContentItems: contentItems.ToArray(),
|
||||
Hint: "",
|
||||
PromptOnNavigate: false,
|
||||
ShowSaveWarning: false)
|
||||
</div>
|
||||
</fieldset>
|
||||
@@ -0,0 +1,21 @@
|
||||
@using Orchard.ContentManagement
|
||||
@using Orchard.DisplayManagement.Shapes
|
||||
@using Orchard.Layouts.Helpers
|
||||
@using Orchard.MediaLibrary.Models
|
||||
@{
|
||||
var tagBuilder = (OrchardTagBuilder)TagBuilderExtensions.AddCommonElementAttributes(new OrchardTagBuilder("img"), Model);
|
||||
var vectorGraphicPart = (VectorGraphicPart)Model.VectorGraphicPart;
|
||||
var mediaPart = vectorGraphicPart != null ? vectorGraphicPart.As<MediaPart>() : default(MediaPart);
|
||||
|
||||
if (mediaPart != null) {
|
||||
tagBuilder.Attributes["src"] = mediaPart.MediaUrl;
|
||||
tagBuilder.Attributes["alt"] = mediaPart.AlternateText;
|
||||
}
|
||||
else {
|
||||
tagBuilder.Attributes["alt"] = T("Image not found").Text;
|
||||
}
|
||||
}
|
||||
<div class="element-component">
|
||||
<div>@T("Vector Graphic")</div>
|
||||
@Html.Raw(tagBuilder.ToString(TagRenderMode.SelfClosing))
|
||||
</div>
|
||||
@@ -0,0 +1,18 @@
|
||||
@using Orchard.ContentManagement
|
||||
@using Orchard.DisplayManagement.Shapes
|
||||
@using Orchard.Layouts.Helpers
|
||||
@using Orchard.MediaLibrary.Models
|
||||
@{
|
||||
var tagBuilder = (OrchardTagBuilder)TagBuilderExtensions.AddCommonElementAttributes(new OrchardTagBuilder("img"), Model);
|
||||
var vectorGraphicPart = (VectorGraphicPart)Model.ImagePart;
|
||||
var mediaPart = vectorGraphicPart != null ? vectorGraphicPart.As<MediaPart>() : default(MediaPart);
|
||||
|
||||
if (mediaPart != null) {
|
||||
tagBuilder.Attributes["src"] = Url.Content(mediaPart.MediaUrl);
|
||||
tagBuilder.Attributes["alt"] = mediaPart.AlternateText;
|
||||
}
|
||||
else {
|
||||
tagBuilder.Attributes["alt"] = T("Image not found").Text;
|
||||
}
|
||||
}
|
||||
@Html.Raw(tagBuilder.ToString(TagRenderMode.SelfClosing))
|
||||
Reference in New Issue
Block a user