2010-12-01 15:55:02 -08:00
using System.Linq ;
2011-03-07 11:04:48 -08:00
using System.Web.Routing ;
2010-12-01 15:55:02 -08:00
using Orchard.ContentManagement ;
2010-11-09 16:00:51 -08:00
using Orchard.ContentManagement.Drivers ;
2010-11-08 17:44:43 -08:00
using Orchard.ContentManagement.Handlers ;
2010-12-01 15:55:02 -08:00
using Orchard.ContentManagement.MetaData ;
2010-11-10 16:35:17 -08:00
using Orchard.Core.Common.Models ;
2010-11-08 15:33:56 -08:00
using Orchard.Core.Containers.Models ;
2010-11-10 16:35:17 -08:00
using Orchard.Core.Containers.Settings ;
2010-11-08 17:44:43 -08:00
using Orchard.Data ;
2010-12-01 15:55:02 -08:00
using Orchard.Localization ;
using Orchard.UI.Notify ;
2010-11-08 15:33:56 -08:00
namespace Orchard.Core.Containers.Drivers {
2010-11-08 17:44:43 -08:00
public class ContainerPartDriver : ContentPartDriver < ContainerPart > {
2010-12-01 15:55:02 -08:00
private readonly IContentDefinitionManager _contentDefinitionManager ;
public ContainerPartDriver ( IContentDefinitionManager contentDefinitionManager , IOrchardServices orchardServices ) {
_contentDefinitionManager = contentDefinitionManager ;
Services = orchardServices ;
T = NullLocalizer . Instance ;
}
public IOrchardServices Services { get ; private set ; }
public Localizer T { get ; set ; }
protected override DriverResult Display ( ContainerPart part , string displayType , dynamic shapeHelper ) {
return Combined (
ContentShape ( "Parts_Container_Contained" ,
( ) = > shapeHelper . Parts_Container_Contained ( ContentPart : part ) ) ,
ContentShape ( "Parts_Container_Contained_Summary" ,
( ) = > shapeHelper . Parts_Container_Contained_Summary ( ContentPart : part ) ) ,
ContentShape ( "Parts_Container_Contained_SummaryAdmin" ,
( ) = > shapeHelper . Parts_Container_Contained_SummaryAdmin ( ContentPart : part ) )
) ;
}
2010-11-08 17:44:43 -08:00
protected override DriverResult Editor ( ContainerPart part , dynamic shapeHelper ) {
2010-12-01 15:55:02 -08:00
// if there are no containable items then show a nice little warning
if ( ! _contentDefinitionManager . ListTypeDefinitions ( )
. Where ( typeDefinition = > typeDefinition . Parts . Any ( partDefinition = > partDefinition . PartDefinition . Name = = "ContainablePart" ) ) . Any ( ) ) {
Services . Notifier . Warning ( T ( "There are no content types in the system with a Containable part attached. Consider adding a Containable part to some content type, existing or new, in order to relate items to this (Container enabled) item." ) ) ;
}
2010-12-01 23:59:10 -08:00
return Editor ( part , null , shapeHelper ) ;
}
protected override DriverResult Editor ( ContainerPart part , IUpdateModel updater , dynamic shapeHelper ) {
2010-11-08 17:44:43 -08:00
return ContentShape (
"Parts_Container_Edit" ,
( ) = > {
if ( updater ! = null )
updater . TryUpdateModel ( part , "Container" , null , null ) ;
return shapeHelper . EditorTemplate ( TemplateName : "Container" , Model : part , Prefix : "Container" ) ;
} ) ;
}
}
public class ContainerPartHandler : ContentHandler {
2010-12-01 15:55:02 -08:00
public ContainerPartHandler ( IRepository < ContainerPartRecord > repository ) {
2010-11-08 17:44:43 -08:00
Filters . Add ( StorageFilter . For ( repository ) ) ;
2010-11-09 16:00:51 -08:00
OnInitializing < ContainerPart > ( ( context , part ) = > {
2010-11-10 16:35:17 -08:00
part . Record . PageSize = part . Settings . GetModel < ContainerTypePartSettings > ( ) . PageSizeDefault
? ? part . PartDefinition . Settings . GetModel < ContainerPartSettings > ( ) . PageSizeDefault ;
part . Record . Paginated = part . Settings . GetModel < ContainerTypePartSettings > ( ) . PaginatedDefault
? ? part . PartDefinition . Settings . GetModel < ContainerPartSettings > ( ) . PaginatedDefault ;
//hard-coded defaults for ordering
part . Record . OrderByProperty = part . Is < CommonPart > ( ) ? "CommonPart.PublishedUtc" : "" ;
part . Record . OrderByDirection = ( int ) OrderByDirection . Descending ;
2010-11-09 16:00:51 -08:00
} ) ;
2010-11-08 17:44:43 -08:00
}
2011-03-07 11:04:48 -08:00
protected override void GetItemMetadata ( GetContentItemMetadataContext context ) {
var container = context . ContentItem . As < ContainerPart > ( ) ;
if ( container = = null )
return ;
// containers link to their contents in admin screens
context . Metadata . AdminRouteValues = new RouteValueDictionary {
{ "Area" , "Contents" } ,
{ "Controller" , "Admin" } ,
{ "Action" , "List" } ,
{ "containerId" , container . Id }
} ;
}
2010-11-08 15:33:56 -08:00
}
2010-11-08 17:44:43 -08:00
}