mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Adding Width and Height properties to VectorGraphic element.
This commit is contained in:
@@ -17,12 +17,18 @@ namespace Orchard.Layouts.Drivers {
|
||||
|
||||
protected override EditorResult OnBuildEditor(VectorGraphic element, ElementEditorContext context) {
|
||||
|
||||
var viewModel = new VectorGraphicEditorViewModel();
|
||||
var viewModel = new VectorGraphicEditorViewModel {
|
||||
VectorGraphicId = element.MediaId.ToString(),
|
||||
Width = element.Width,
|
||||
Height = element.Height
|
||||
};
|
||||
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);
|
||||
element.Width = viewModel.Width;
|
||||
element.Height = viewModel.Height;
|
||||
}
|
||||
|
||||
var mediaId = element.MediaId;
|
||||
@@ -41,8 +47,8 @@ namespace Orchard.Layouts.Drivers {
|
||||
return _contentManager.Get<VectorGraphicPart>(id, VersionOptions.Published);
|
||||
}
|
||||
|
||||
private static int? ParseVectorGraphicId(string imageId) {
|
||||
return ContentItem.Deserialize(imageId).FirstOrDefault();
|
||||
private static int? ParseVectorGraphicId(string vectorGraphicId) {
|
||||
return ContentItem.Deserialize(vectorGraphicId).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,5 +15,15 @@ namespace Orchard.Layouts.Elements {
|
||||
get { return State.Get("MediaId").ToInt32(); }
|
||||
set { State["MediaId"] = value.ToString(); }
|
||||
}
|
||||
|
||||
public int? Width {
|
||||
get { return State.Get("Width").ToInt32(); }
|
||||
set { State["Width"] = value.ToString(); }
|
||||
}
|
||||
|
||||
public int? Height {
|
||||
get { return State.Get("Height").ToInt32(); }
|
||||
set { State["Height"] = value.ToString(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace Orchard.Layouts.ViewModels {
|
||||
public class VectorGraphicEditorViewModel {
|
||||
public string VectorGraphicId { get; set; }
|
||||
public int? Width { get; set; }
|
||||
public int? Height { get; set; }
|
||||
public VectorGraphicPart CurrentVectorGraphic { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -19,4 +19,16 @@
|
||||
PromptOnNavigate: false,
|
||||
ShowSaveWarning: false)
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(m => m.Width, T("Width"))
|
||||
@Html.TextBoxFor(m => m.Width, new { @class = "text medium" })
|
||||
@Html.Hint(T("Optional. Specify the width of this element."))
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(m => m.Height, T("Height"))
|
||||
@Html.TextBoxFor(m => m.Height, new { @class = "text medium" })
|
||||
@Html.Hint(T("Optional. Specify the height of this element."))
|
||||
</div>
|
||||
</fieldset>
|
||||
@@ -1,8 +1,10 @@
|
||||
@using Orchard.ContentManagement
|
||||
@using Orchard.DisplayManagement.Shapes
|
||||
@using Orchard.Layouts.Elements
|
||||
@using Orchard.Layouts.Helpers
|
||||
@using Orchard.MediaLibrary.Models
|
||||
@{
|
||||
var element = (VectorGraphic)Model.Element;
|
||||
var tagBuilder = (OrchardTagBuilder)TagBuilderExtensions.AddCommonElementAttributes(new OrchardTagBuilder("img"), Model);
|
||||
var vectorGraphicPart = (VectorGraphicPart)Model.VectorGraphicPart;
|
||||
var mediaPart = vectorGraphicPart != null ? vectorGraphicPart.As<MediaPart>() : default(MediaPart);
|
||||
@@ -14,6 +16,14 @@
|
||||
else {
|
||||
tagBuilder.Attributes["alt"] = T("Image not found").Text;
|
||||
}
|
||||
|
||||
if (element.Width != null) {
|
||||
tagBuilder.Attributes["width"] = element.Width.ToString();
|
||||
}
|
||||
|
||||
if (element.Height != null) {
|
||||
tagBuilder.Attributes["height"] = element.Height.ToString();
|
||||
}
|
||||
}
|
||||
<div class="element-component">
|
||||
<div>@T("Vector Graphic")</div>
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
@using Orchard.ContentManagement
|
||||
@using Orchard.DisplayManagement.Shapes
|
||||
@using Orchard.Layouts.Elements
|
||||
@using Orchard.Layouts.Helpers
|
||||
@using Orchard.MediaLibrary.Models
|
||||
@{
|
||||
var element = (VectorGraphic)Model.Element;
|
||||
var tagBuilder = (OrchardTagBuilder)TagBuilderExtensions.AddCommonElementAttributes(new OrchardTagBuilder("img"), Model);
|
||||
var vectorGraphicPart = (VectorGraphicPart)Model.VectorGraphicPart;
|
||||
var mediaPart = vectorGraphicPart != null ? vectorGraphicPart.As<MediaPart>() : default(MediaPart);
|
||||
@@ -14,5 +16,13 @@
|
||||
else {
|
||||
tagBuilder.Attributes["alt"] = T("Image not found").Text;
|
||||
}
|
||||
|
||||
if (element.Width != null) {
|
||||
tagBuilder.Attributes["width"] = element.Width.ToString();
|
||||
}
|
||||
|
||||
if (element.Height != null) {
|
||||
tagBuilder.Attributes["height"] = element.Height.ToString();
|
||||
}
|
||||
}
|
||||
@Html.Raw(tagBuilder.ToString(TagRenderMode.SelfClosing))
|
||||
Reference in New Issue
Block a user