2010-11-08 17:44:43 -08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
using Orchard.ContentManagement;
|
|
|
|
|
using Orchard.ContentManagement.Aspects;
|
|
|
|
|
using Orchard.ContentManagement.Drivers;
|
2010-11-08 15:33:56 -08:00
|
|
|
|
using Orchard.Core.Containers.Models;
|
2010-11-08 17:44:43 -08:00
|
|
|
|
using Orchard.Core.Containers.ViewModels;
|
|
|
|
|
using Orchard.Localization;
|
2010-11-08 15:33:56 -08:00
|
|
|
|
|
|
|
|
|
namespace Orchard.Core.Containers.Drivers {
|
|
|
|
|
public class ContainablePartDriver : ContentPartDriver<ContainablePart> {
|
2010-11-08 17:44:43 -08:00
|
|
|
|
private readonly IContentManager _contentManager;
|
|
|
|
|
|
2010-12-01 15:55:02 -08:00
|
|
|
|
public ContainablePartDriver(IContentManager contentManager) {
|
2010-11-08 17:44:43 -08:00
|
|
|
|
_contentManager = contentManager;
|
|
|
|
|
T = NullLocalizer.Instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Localizer T { get; set; }
|
|
|
|
|
|
|
|
|
|
protected override DriverResult Editor(ContainablePart part, dynamic shapeHelper) {
|
|
|
|
|
return Editor(part, null, shapeHelper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override DriverResult Editor(ContainablePart part, IUpdateModel updater, dynamic shapeHelper) {
|
|
|
|
|
return ContentShape(
|
|
|
|
|
"Parts_Containable_Edit",
|
|
|
|
|
() => {
|
|
|
|
|
var commonPart = part.As<ICommonPart>();
|
|
|
|
|
|
|
|
|
|
var model = new ContainableViewModel();
|
|
|
|
|
if (commonPart.Container != null) {
|
|
|
|
|
model.ContainerId = commonPart.Container.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (updater != null) {
|
|
|
|
|
var oldContainerId = model.ContainerId;
|
|
|
|
|
updater.TryUpdateModel(model, "Containable", null, null);
|
2010-11-13 08:37:13 -08:00
|
|
|
|
if (oldContainerId != model.ContainerId)
|
2010-11-08 17:44:43 -08:00
|
|
|
|
commonPart.Container = _contentManager.Get(model.ContainerId, VersionOptions.Latest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var containers = _contentManager.Query<ContainerPart, ContainerPartRecord>(VersionOptions.Latest).List();
|
|
|
|
|
var listItems = new[] { new SelectListItem { Text = T("(None)").Text, Value = "0" } }
|
|
|
|
|
.Concat(containers.Select(x => new SelectListItem {
|
|
|
|
|
Value = Convert.ToString(x.Id),
|
|
|
|
|
Text = x.ContentItem.TypeDefinition.DisplayName + ": " + x.As<IRoutableAspect>().Title,
|
|
|
|
|
Selected = x.Id == model.ContainerId,
|
|
|
|
|
}))
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
model.AvailableContainers = new SelectList(listItems, "Value", "Text", model.ContainerId);
|
|
|
|
|
|
|
|
|
|
return shapeHelper.EditorTemplate(TemplateName: "Containable", Model: model, Prefix: "Containable");
|
|
|
|
|
});
|
|
|
|
|
}
|
2010-11-08 15:33:56 -08:00
|
|
|
|
}
|
2010-11-08 17:44:43 -08:00
|
|
|
|
}
|