Adding I/E handlers for the last few types.

--HG--
branch : dev
This commit is contained in:
Suha Can
2011-03-16 12:38:04 -07:00
parent 0aeed66ad0
commit cbf5235b0c
5 changed files with 122 additions and 5 deletions

View File

@@ -4,7 +4,6 @@ using System.Web.Mvc;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.Drivers;
using Orchard.Core.Common.Models;
using Orchard.Core.Containers.Models;
using Orchard.Core.Containers.ViewModels;
using Orchard.Localization;

View File

@@ -1,9 +1,7 @@
using System;
using System.Linq;
using System.Web.Mvc;
using System.Web.Routing;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.MetaData;
@@ -54,7 +52,7 @@ namespace Orchard.Core.Containers.Drivers {
"Parts_Container_Edit",
() => {
var model = new ContainerViewModel { Part = part };
// todo: is there a non-string comparison way to find ConaintableParts?
// todo: is there a non-string comparison way to find ContainableParts?
var containables = _contentDefinitionManager.ListTypeDefinitions().Where(td => td.Parts.Any(p => p.PartDefinition.Name == "ContainablePart")).ToList();
var listItems = new[] { new SelectListItem { Text = T("(Any)").Text, Value = "" } }
.Concat(containables.Select(x => new SelectListItem {
@@ -73,6 +71,43 @@ namespace Orchard.Core.Containers.Drivers {
return shapeHelper.EditorTemplate(TemplateName: "Container", Model: model, Prefix: "Container");
});
}
protected override void Importing(ContainerPart part, ImportContentContext context) {
var itemContentType = context.Attribute(part.PartDefinition.Name, "ItemContentType");
if (itemContentType != null) {
if (_contentDefinitionManager.GetTypeDefinition(itemContentType) != null) {
part.Record.ItemContentType = itemContentType;
}
}
var paginated = context.Attribute(part.PartDefinition.Name, "Paginated");
if (paginated != null) {
part.Record.Paginated = Convert.ToBoolean(paginated);
}
var pageSize = context.Attribute(part.PartDefinition.Name, "PageSize");
if (pageSize != null) {
part.Record.PageSize = Convert.ToInt32(pageSize);
}
var orderByProperty = context.Attribute(part.PartDefinition.Name, "OrderByProperty");
if (orderByProperty != null) {
part.Record.OrderByProperty = orderByProperty;
}
var orderByDirection = context.Attribute(part.PartDefinition.Name, "OrderByDirection");
if (orderByDirection != null) {
part.Record.OrderByDirection = Convert.ToInt32(orderByDirection);
}
}
protected override void Exporting(ContainerPart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("ItemContentType", part.Record.ItemContentType);
context.Element(part.PartDefinition.Name).SetAttributeValue("Paginated", part.Record.Paginated);
context.Element(part.PartDefinition.Name).SetAttributeValue("PageSize", part.Record.PageSize);
context.Element(part.PartDefinition.Name).SetAttributeValue("OrderByProperty", part.Record.OrderByProperty);
context.Element(part.PartDefinition.Name).SetAttributeValue("OrderByDirection", part.Record.OrderByDirection);
}
}
public class ContainerPartHandler : ContentHandler {

View File

@@ -76,6 +76,67 @@ namespace Orchard.Core.Containers.Drivers {
return shapeHelper.EditorTemplate(TemplateName: "ContainerWidget", Model: model, Prefix: "ContainerWidget");
});
}
protected override void Importing(ContainerWidgetPart part, ImportContentContext context) {
var containerIdentity = context.Attribute(part.PartDefinition.Name, "Container");
if (containerIdentity != null) {
var container = context.Session.Get(containerIdentity);
if (container != null) {
part.Record.ContainerId = container.Id;
}
}
var pageSize = context.Attribute(part.PartDefinition.Name, "PageSize");
if (pageSize != null) {
part.Record.PageSize = Convert.ToInt32(pageSize);
}
var orderByProperty = context.Attribute(part.PartDefinition.Name, "OrderByProperty");
if (orderByProperty != null) {
part.Record.OrderByProperty = orderByProperty;
}
var orderByDirection = context.Attribute(part.PartDefinition.Name, "OrderByDirection");
if (orderByDirection != null) {
part.Record.OrderByDirection = Convert.ToInt32(orderByDirection);
}
var applyByFilter = context.Attribute(part.PartDefinition.Name, "ApplyFilter");
if (applyByFilter != null) {
part.Record.ApplyFilter = Convert.ToBoolean(applyByFilter);
}
var filterByProperty = context.Attribute(part.PartDefinition.Name, "FilterByProperty");
if (filterByProperty != null) {
part.Record.FilterByProperty = filterByProperty;
}
var filterByOperator = context.Attribute(part.PartDefinition.Name, "FilterByOperator");
if (filterByOperator != null) {
part.Record.FilterByOperator = filterByOperator;
}
var filterByValue = context.Attribute(part.PartDefinition.Name, "FilterByValue");
if (filterByValue != null) {
part.Record.FilterByValue = filterByValue;
}
}
protected override void Exporting(ContainerWidgetPart part, ExportContentContext context) {
var container = _contentManager.Get(part.Record.ContainerId);
if (container != null) {
var containerIdentity = _contentManager.GetItemMetadata(container).Identity;
context.Element(part.PartDefinition.Name).SetAttributeValue("Container", containerIdentity.ToString());
}
context.Element(part.PartDefinition.Name).SetAttributeValue("PageSize", part.Record.PageSize);
context.Element(part.PartDefinition.Name).SetAttributeValue("OrderByProperty", part.Record.OrderByProperty);
context.Element(part.PartDefinition.Name).SetAttributeValue("OrderByDirection", part.Record.OrderByDirection);
context.Element(part.PartDefinition.Name).SetAttributeValue("ApplyFilter", part.Record.ApplyFilter);
context.Element(part.PartDefinition.Name).SetAttributeValue("FilterByProperty", part.Record.FilterByProperty);
context.Element(part.PartDefinition.Name).SetAttributeValue("FilterByOperator", part.Record.FilterByOperator);
context.Element(part.PartDefinition.Name).SetAttributeValue("FilterByValue", part.Record.FilterByValue);
}
}
public class ContainerWidgetPartHandler : ContentHandler {

View File

@@ -20,6 +20,29 @@ namespace Orchard.Core.Containers.Drivers {
return shapeHelper.EditorTemplate(TemplateName: "CustomProperties", Model: part, Prefix: "CustomProperties");
});
}
protected override void Importing(CustomPropertiesPart part, ImportContentContext context) {
var customOne = context.Attribute(part.PartDefinition.Name, "CustomOne");
if (customOne != null) {
part.Record.CustomOne = customOne;
}
var customTwo = context.Attribute(part.PartDefinition.Name, "CustomTwo");
if (customTwo != null) {
part.Record.CustomTwo = customTwo;
}
var customThree = context.Attribute(part.PartDefinition.Name, "CustomThree");
if (customThree != null) {
part.Record.CustomThree = customThree;
}
}
protected override void Exporting(CustomPropertiesPart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("CustomOne", part.Record.CustomOne);
context.Element(part.PartDefinition.Name).SetAttributeValue("CustomTwo", part.Record.CustomTwo);
context.Element(part.PartDefinition.Name).SetAttributeValue("CustomThree", part.Record.CustomThree);
}
}
public class CustomPropertiesPartHandler : ContentHandler {

View File

@@ -6,7 +6,6 @@ using Orchard.Core.Routable.Models;
using Orchard.Environment;
using Orchard.Logging;
using Orchard.Tasks;
using Orchard.UI.Admin;
namespace Orchard.Core.Containers.Services {
public class ContainersPathConstraintUpdater : IOrchardShellEvents, IBackgroundTask {