--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-06-10 16:08:30 -07:00
35 changed files with 344 additions and 111 deletions

View File

@@ -1,7 +1,8 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<SiteCulturesViewModel>" %>
<%@ Import Namespace="Orchard.Core.Settings.ViewModels" %><%
Html.RegisterStyle("admin.css"); %>
<h1><%:Html.TitleForPage(T("Manage Settings").ToString()) %></h1>
<h1><%:Html.TitleForPage(T("Supported Cultures").ToString()) %></h1>
<p class="breadcrumb"><%:Html.ActionLink(T("Manage Settings").Text, "index") %><%:T(" &#62; ") %><%:T("Supported Cultures")%></p>
<h2><%:T("Cultures this site supports") %></h2>
<%=Html.UnorderedList(
Model.SiteCultures.OrderBy(s => s),
@@ -10,7 +11,7 @@
<% using (Html.BeginFormAntiForgeryPost("AddCulture")) { %>
<%:Html.ValidationSummary() %>
<fieldset>
<legend><%:T("Add a culture...") %></legend>
<label for="CultureName"><%:T("Add a culture...") %></label>
<%:Html.DropDownList("CultureName", new SelectList(Model.AvailableSystemCultures.OrderBy(s => s), Model.CurrentCulture)) %>
<button class="primaryAction" type="submit"><%:T("Add") %></button>
</fieldset>

View File

@@ -2,5 +2,5 @@
<div><%:Model %></div>
<% using (Html.BeginFormAntiForgeryPost(Url.Action("DeleteCulture", "Admin", new { area = "Settings" }), FormMethod.Post, new {@class = "inline link"})) { %>
<%=Html.Hidden("cultureName", Model, new { id = "" }) %>
<button type="submit" title="<%:T("Delete") %>">x</button>
<button type="submit" class="remove" title="<%:T("Delete") %>">x</button>
<% } %>

View File

@@ -2,24 +2,25 @@ using System.Web.Mvc;
using Orchard.Blogs.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Localization;
using Orchard.Mvc.Html;
namespace Orchard.Blogs.Extensions {
public static class HtmlHelperExtensions {
public static string PublishedState(this HtmlHelper<BlogPost> htmlHelper) {
return htmlHelper.PublishedState(htmlHelper.ViewData.Model);
public static LocalizedString PublishedState(this HtmlHelper<BlogPost> htmlHelper, Localizer T) {
return htmlHelper.PublishedState(htmlHelper.ViewData.Model, T);
}
public static string PublishedState(this HtmlHelper htmlHelper, BlogPost blogPost) {
return htmlHelper.DateTime(blogPost.As<ICommonAspect>().VersionPublishedUtc, "Draft");
public static LocalizedString PublishedState(this HtmlHelper htmlHelper, BlogPost blogPost, Localizer T) {
return htmlHelper.DateTime(blogPost.As<ICommonAspect>().VersionPublishedUtc, T("Draft"));
}
public static string PublishedWhen(this HtmlHelper<BlogPost> htmlHelper) {
return htmlHelper.PublishedWhen(htmlHelper.ViewData.Model);
public static LocalizedString PublishedWhen(this HtmlHelper<BlogPost> htmlHelper, Localizer T) {
return htmlHelper.PublishedWhen(htmlHelper.ViewData.Model, T);
}
public static string PublishedWhen(this HtmlHelper htmlHelper, BlogPost blogPost) {
return htmlHelper.DateTimeRelative(blogPost.As<ICommonAspect>().VersionPublishedUtc, "as a Draft");
public static LocalizedString PublishedWhen(this HtmlHelper htmlHelper, BlogPost blogPost, Localizer T) {
return htmlHelper.DateTimeRelative(blogPost.As<ICommonAspect>().VersionPublishedUtc, T("as a Draft"), T);
}
}
}

View File

@@ -1,9 +1,7 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %>
<%@ Import Namespace="Orchard.ContentManagement"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<h2><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPost(Model.Item)) %></h2>
<div class="meta"><%=Html.PublishedState(Model.Item) %> | <%Html.Zone("meta");%></div>
<div class="meta"><%=Html.PublishedState(Model.Item, T) %> | <%Html.Zone("meta");%></div>
<div class="content"><% Html.Zone("primary", ":manage :metadata");%></div>

View File

@@ -1,7 +1,6 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %>
<%@ Import Namespace="Orchard.ContentManagement.Aspects"%>
<%@ Import Namespace="Orchard.ContentManagement"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
@@ -11,15 +10,15 @@
<ul>
<li><%
if (Model.Item.HasPublished) { %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/online.gif") %>" alt="<%: T("Online") %>" title="<%: T("The page is currently online") %>" /><%: T(" Published")%><%
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/online.gif") %>" alt="<%: T("Online") %>" title="<%: T("The page is currently online") %>" /> <%: T("Published")%><%
}
else { %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/offline.gif") %>" alt="<%: T("Offline") %>" title="<%: T("The page is currently offline") %>" /><%: T(" Not Published")%><%
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/offline.gif") %>" alt="<%: T("Offline") %>" title="<%: T("The page is currently offline") %>" /> <%: T("Not Published")%><%
} %>&nbsp;&#124;&nbsp;
</li>
<li><%
if (Model.Item.HasDraft) { %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/draft.gif") %>" alt="<%: T("Draft") %>" title="<%: T("The post has a draft") %>" /><%=Html.PublishedState(Model.Item)%><%
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/draft.gif") %>" alt="<%: T("Draft") %>" title="<%: T("The post has a draft") %>" /><%=Html.PublishedState(Model.Item, T) %><%
}
else { %>
<%: T("No draft")%><%
@@ -31,10 +30,10 @@
<%=Html.DateTime(Model.Item.ScheduledPublishUtc.Value, "M/d/yyyy h:mm tt")%><%
}
else if (Model.Item.IsPublished) { %>
<%: T("Published: ") + Html.DateTimeRelative(Model.Item.As<ICommonAspect>().VersionPublishedUtc.Value)%><%
<%: T("Published: {0}", Html.DateTimeRelative(Model.Item.As<ICommonAspect>().VersionPublishedUtc.Value, T)) %><%
}
else { %>
<%: T("Last modified: ") + Html.DateTimeRelative(Model.Item.As<ICommonAspect>().ModifiedUtc.Value) %><%
<%: T("Last modified: {0}", Html.DateTimeRelative(Model.Item.As<ICommonAspect>().ModifiedUtc.Value, T)) %><%
} %>&nbsp;&#124;&nbsp;
</li>
<li><%: T("By {0}", Model.Item.Creator.UserName)%></li>

View File

@@ -2,5 +2,5 @@
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%><%
if (Model.Creator != null) {
%><span class="posted"><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model)) %> | </span><%
%><span class="posted"><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model, T)) %> | </span><%
} %>

View File

@@ -3,6 +3,6 @@
<%@ Import Namespace="Orchard.Blogs.Models"%>
<div class="metadata"><%
if (Model.Creator != null) {
%><div class="posted"><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model)) %></div><%
%><div class="posted"><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model, T)) %></div><%
} %>
</div>

View File

@@ -6,7 +6,7 @@ foreach (var comment in Model) { %>
<div class="comment">
<span class="who"><%=Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span>
<%-- todo: (heskew) need comment permalink --%>
<span>said <%=Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault()), "#")%></span>
<span>said <%=Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault(), T).Text, "#")%></span>
</div>
<div class="text">
<%-- todo: (heskew) comment text needs processing depending on comment markup style --%>

View File

@@ -1,7 +1,6 @@
<%@ Page Language="C#" Inherits="Orchard.Mvc.ViewPage<PagesViewModel>" %>
<%@ Import Namespace="Orchard.ContentManagement.Aspects"%>
<%@ Import Namespace="Orchard.ContentManagement"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%>
<%@ Import Namespace="Orchard.Mvc.Html"%>
<%@ Import Namespace="Orchard.Pages.ViewModels"%><%
Html.RegisterStyle("admin.css"); %>
@@ -45,10 +44,10 @@ using (Html.BeginFormAntiForgeryPost()) { %>
<li><%
// Published or not
if (pageEntry.Page.HasPublished) { %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Pages/Content/Admin/images/online.gif") %>" alt="<%: T("Online") %>" title="<%: T("The page is currently online") %>" /><%: T("Published") %>&nbsp;&#124;&nbsp;<%
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Pages/Content/Admin/images/online.gif") %>" alt="<%: T("Online") %>" title="<%: T("The page is currently online") %>" /> <%: T("Published") %>&nbsp;&#124;&nbsp;<%
}
else { %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Pages/Content/Admin/images/offline.gif") %>" alt="<%: T("Offline") %>" title="<%: T("The page is currently offline") %>" /><%: T("Not Published")%>&nbsp;&#124;&nbsp;<%
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Pages/Content/Admin/images/offline.gif") %>" alt="<%: T("Offline") %>" title="<%: T("The page is currently offline") %>" /> <%: T("Not Published")%>&nbsp;&#124;&nbsp;<%
} %>
</li>
<li><%
@@ -66,10 +65,10 @@ using (Html.BeginFormAntiForgeryPost()) { %>
<%=Html.DateTime(pageEntry.Page.ScheduledPublishUtc.Value, "M/d/yyyy h:mm tt")%><%
}
else if (pageEntry.Page.IsPublished) { %>
<%: T("Published: ") + Html.DateTimeRelative(pageEntry.Page.As<ICommonAspect>().VersionPublishedUtc.Value) %><%
<%: T("Published: {0}", Html.DateTimeRelative(pageEntry.Page.As<ICommonAspect>().VersionPublishedUtc.Value, T)) %><%
}
else { %>
<%: T("Last modified: ") + Html.DateTimeRelative(pageEntry.Page.As<ICommonAspect>().ModifiedUtc.Value) %><%
<%: T("Last modified: {0}", Html.DateTimeRelative(pageEntry.Page.As<ICommonAspect>().ModifiedUtc.Value, T)) %><%
} %>&nbsp;&#124;&nbsp;
</li>
<li><%: T("By {0}", pageEntry.Page.Creator.UserName)%></li>

View File

@@ -4,7 +4,7 @@ Html.RegisterStyle("admin.css"); %>
<h1><%=Html.TitleForPage(T("Search Index Management").ToString()) %></h1><%
using (Html.BeginForm("update", "admin", FormMethod.Post, new {area = "Orchard.Search"})) { %>
<fieldset>
<p><%=T("The search index was last updated {0}. <button type=\"submit\" title=\"Update the search index.\" class=\"primaryAction\">Update</button>", Html.DateTimeRelative(Model.IndexUpdatedUtc))%></p>
<p><%=T("The search index was last updated {0}. <button type=\"submit\" title=\"Update the search index.\" class=\"primaryAction\">Update</button>", Html.DateTimeRelative(Model.IndexUpdatedUtc, T))%></p>
<%=Html.AntiForgeryTokenOrchard() %>
</fieldset><%
}

View File

@@ -1,12 +1,10 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %>
<%@ Import Namespace="Orchard.ContentManagement"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<%Model.Zones.AddRenderPartial("zonetest", "ZoneTest", Model); %>
<h2><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPost(Model.Item)) %></h2>
<div class="meta"><%=Html.PublishedState(Model.Item) %> | <%Html.Zone("meta");%></div>
<div class="meta"><%=Html.PublishedState(Model.Item, T) %> | <%Html.Zone("meta");%></div>
<div class="postsummary">
<% Html.Zone("primary"); %>
</div>

View File

@@ -1,7 +1,6 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPost>" %>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<%
if (Model.Creator != null) {
%><%: T("Posted by {0} {1}", Model.Creator.UserName, "|", Html.PublishedWhen(Model)) %><%
} %>
<%@ Import Namespace="Orchard.Blogs.Models"%><%
if (Model.Creator != null) {
%><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model, T)) %><%
} %>

View File

@@ -1,12 +1,10 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %>
<%@ Import Namespace="Orchard.ContentManagement"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<%Model.Zones.AddRenderPartial("zonetest", "ZoneTest", Model); %>
<h2><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPost(Model.Item)) %></h2>
<div class="meta"><%=Html.PublishedState(Model.Item) %> | <%Html.Zone("meta");%></div>
<div class="meta"><%=Html.PublishedState(Model.Item, T) %> | <%Html.Zone("meta");%></div>
<div class="postsummary">
<% Html.Zone("primary"); %>
</div>

View File

@@ -1,7 +1,6 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPost>" %>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<%
if (Model.Creator != null) {
%><%: T("Posted by {0} {1}", Model.Creator.UserName, "|", Html.PublishedWhen(Model)) %><%
} %>
<%@ Import Namespace="Orchard.Blogs.Models"%><%
if (Model.Creator != null) {
%><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model, T)) %><%
} %>

View File

@@ -3,15 +3,12 @@
<ul class="comments"><%
foreach (var comment in Model) { %>
<li>
<div class="comment">
<p><%: comment.Record.CommentText %></p>
</div>
<div class="commentauthor">
<span class="who"><%=Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span>&nbsp;<span>said <%=Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault()), "#")%></span>
</div>
<div class="comment">
<p><%: comment.Record.CommentText %></p>
</div>
<div class="commentauthor">
<span class="who"><%=Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span>&nbsp;<span>said <%=Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault(), T).Text, "#")%></span>
</div>
</li><%
} %>
</ul>

View File

@@ -3,15 +3,12 @@
<ul class="comments"><%
foreach (var comment in Model) { %>
<li>
<div class="comment">
<p><%: comment.Record.CommentText %></p>
</div>
<div class="commentauthor">
<span class="who"><%=Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span>&nbsp;<span>said <%=Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault()), "#")%></span>
</div>
<div class="comment">
<p><%: comment.Record.CommentText %></p>
</div>
<div class="commentauthor">
<span class="who"><%=Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span>&nbsp;<span>said <%=Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault(), T).Text, "#")%></span>
</div>
</li><%
} %>
</ul>

View File

@@ -1,14 +1,9 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %>
<%@ Import Namespace="Orchard.ContentManagement"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<h3><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPost(Model.Item)) %></h3>
<div class="meta"><%=Html.PublishedState(Model.Item) %> | <%Html.Zone("meta");%></div>
<div class="meta"><%=Html.PublishedState(Model.Item, T) %> | <%Html.Zone("meta");%></div>
<div class="postsummary">
<% Html.Zone("primary"); %>
</div>
</div>

View File

@@ -1,7 +1,6 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPost>" %>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<%
if (Model.Creator != null) {
%><%: T("Posted by {0} {1}", Model.Creator.UserName, "|", Html.PublishedWhen(Model)) %><%
} %>
<%@ Import Namespace="Orchard.Blogs.Models"%><%
if (Model.Creator != null) {
%><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model, T)) %><%
} %>

View File

@@ -3,15 +3,12 @@
<ul class="comments"><%
foreach (var comment in Model) { %>
<li>
<div class="comment">
<p><%: comment.Record.CommentText %></p>
</div>
<div class="commentauthor">
<span class="who"><%=Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span>&nbsp;<span>said <%=Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault()), "#")%></span>
</div>
<div class="comment">
<p><%: comment.Record.CommentText %></p>
</div>
<div class="commentauthor">
<span class="who"><%=Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span>&nbsp;<span>said <%=Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault(), T).Text, "#")%></span>
</div>
</li><%
} %>
</ul>

View File

@@ -721,6 +721,9 @@ table .button {
/* ---------- Generic ---------- */
#main .breadcrumb {
margin-top:-1.5em;
}
/* todo: needed? */
.clearBoth {
clear:both;

View File

@@ -1,8 +1,20 @@
using Orchard.ContentManagement.MetaData.Models;
using System.Collections.Generic;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.Utilities;
namespace Orchard.ContentManagement {
public class ContentField {
public class ContentField : ContentPart {
public virtual ContentPart ContentPart { get; set; }
public string Name { get; set; }
public ContentFieldDefinition Definition { get; set; }
public IDictionary<string, string> Settings { get; private set; }
public new ContentPartDefinition PartDefinition { get { return ContentPart.PartDefinition; } }
public ContentPartDefinition.Field PartFieldDefinition { get; set; }
public ContentFieldDefinition FieldDefinition { get { return PartFieldDefinition.FieldDefinition; } }
}
public class ContentField<TRecord> : ContentField {
public readonly LazyField<TRecord> _record = new LazyField<TRecord>();
public TRecord Record { get { return _record.Value; } set { _record.Value = value; } }
}
}

View File

@@ -1,12 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.Utilities;
namespace Orchard.ContentManagement {
public abstract class ContentPart : IContent {
private readonly IList<ContentField> _fields;
public ContentPart() {
_fields = new List<ContentField>();
}
public virtual ContentItem ContentItem { get; set; }
public ContentTypeDefinition TypeDefinition { get { return ContentItem.TypeDefinition; } }
public ContentTypeDefinition.Part TypePartDefinition { get; set; }
public ContentPartDefinition PartDefinition { get { return TypePartDefinition.PartDefinition; } }
public IEnumerable<ContentField> Fields { get { return _fields; } }
public bool Has(Type fieldType) {
return fieldType == typeof(ContentItem) || _fields.Any(field => fieldType.IsAssignableFrom(field.GetType()));
}
public IContent Get(Type fieldType) {
if (fieldType == typeof(ContentItem))
return this;
return _fields.FirstOrDefault(field => fieldType.IsAssignableFrom(field.GetType()));
}
public void Weld(ContentField field) {
field.ContentPart = this;
_fields.Add(field);
}
}
public class ContentPart<TRecord> : ContentPart {

View File

@@ -0,0 +1,51 @@
using Orchard.ContentManagement.Handlers;
namespace Orchard.ContentManagement.Drivers {
public interface IContentFieldDriver : IEvents {
DriverResult BuildDisplayModel(BuildDisplayModelContext context);
DriverResult BuildEditorModel(BuildEditorModelContext context);
DriverResult UpdateEditorModel(UpdateEditorModelContext context);
}
public abstract class ContentFieldDriver<TContent> : IContentFieldDriver where TContent : ContentField, new() {
protected virtual string Prefix { get { return ""; } }
protected virtual string Zone { get { return "body"; } }
DriverResult IContentFieldDriver.BuildDisplayModel(BuildDisplayModelContext context) {
var field = context.ContentItem.As<TContent>();
return field == null ? null : Display(field, context.DisplayType);
}
DriverResult IContentFieldDriver.BuildEditorModel(BuildEditorModelContext context) {
var field = context.ContentItem.As<TContent>();
return field == null ? null : Editor(field);
}
DriverResult IContentFieldDriver.UpdateEditorModel(UpdateEditorModelContext context) {
var field = context.ContentItem.As<TContent>();
return field == null ? null : Editor(field, context.Updater);
}
protected virtual DriverResult Display(TContent field, string displayType) { return null; }
protected virtual DriverResult Editor(TContent field) { return null; }
protected virtual DriverResult Editor(TContent field, IUpdateModel updater) { return null; }
public ContentFieldTemplateResult ContentPartTemplate(object model) {
return new ContentFieldTemplateResult(model, null, Prefix).Location(Zone);
}
public ContentFieldTemplateResult ContentPartTemplate(object model, string template) {
return new ContentFieldTemplateResult(model, template, Prefix).Location(Zone);
}
public ContentFieldTemplateResult ContentPartTemplate(object model, string template, string prefix) {
return new ContentFieldTemplateResult(model, template, prefix).Location(Zone);
}
public CombinedResult Combined(params DriverResult[] results) {
return new CombinedResult(results);
}
}
}

View File

@@ -0,0 +1,42 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using Orchard.ContentManagement.Handlers;
using Orchard.Logging;
namespace Orchard.ContentManagement.Drivers {
[UsedImplicitly]
public class ContentFieldDriverHandler : ContentHandlerBase {
private readonly IEnumerable<IContentPartDriver> _drivers;
public ContentFieldDriverHandler(IEnumerable<IContentPartDriver> drivers) {
_drivers = drivers;
Logger = NullLogger.Instance;
}
public ILogger Logger { get; set; }
public override void BuildDisplayModel(BuildDisplayModelContext context) {
_drivers.Invoke(driver => {
var result = driver.BuildDisplayModel(context);
if (result != null)
result.Apply(context);
}, Logger);
}
public override void BuildEditorModel(BuildEditorModelContext context) {
_drivers.Invoke(driver => {
var result = driver.BuildEditorModel(context);
if (result != null)
result.Apply(context);
}, Logger);
}
public override void UpdateEditorModel(UpdateEditorModelContext context) {
_drivers.Invoke(driver => {
var result = driver.UpdateEditorModel(context);
if (result != null)
result.Apply(context);
}, Logger);
}
}
}

View File

@@ -0,0 +1,56 @@
using System.Linq;
using Orchard.ContentManagement.Handlers;
namespace Orchard.ContentManagement.Drivers {
public class ContentFieldTemplateResult : DriverResult {
public object Model { get; set; }
public string TemplateName { get; set; }
public string Prefix { get; set; }
public string Zone { get; set; }
public string Position { get; set; }
public ContentFieldTemplateResult(object model, string templateName, string prefix) {
Model = model;
TemplateName = templateName;
Prefix = prefix;
}
public override void Apply(BuildDisplayModelContext context) {
context.ViewModel.Zones.AddDisplayPart(
Zone + ":" + Position, Model, TemplateName, Prefix);
}
public override void Apply(BuildEditorModelContext context) {
context.ViewModel.Zones.AddEditorPart(
Zone + ":" + Position, Model, TemplateName, Prefix);
}
public ContentFieldTemplateResult Location(string zone) {
Zone = zone;
return this;
}
public ContentFieldTemplateResult Location(string zone, string position) {
Zone = zone;
Position = position;
return this;
}
public ContentFieldTemplateResult LongestMatch(string displayType, params string[] knownDisplayTypes) {
if (string.IsNullOrEmpty(displayType))
return this;
var longest = knownDisplayTypes.Aggregate("", (best, x) => {
if (displayType.StartsWith(x) && x.Length > best.Length) return x;
return best;
});
if (string.IsNullOrEmpty(longest))
return this;
TemplateName += "." + longest;
return this;
}
}
}

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Orchard.ContentManagement.Handlers;
using Orchard.Logging;

View File

@@ -25,6 +25,14 @@ namespace Orchard.ContentManagement.Handlers {
Filters.Add(new InlineStorageFilter<TPart> { OnCreated = handler });
}
protected void OnSaving<TPart>(Action<SaveContentContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineStorageFilter<TPart> { OnSaving = handler });
}
protected void OnSaved<TPart>(Action<SaveContentContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineStorageFilter<TPart> { OnSaved = handler });
}
protected void OnLoading<TPart>(Action<LoadContentContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineStorageFilter<TPart> { OnLoading = handler });
}
@@ -84,6 +92,8 @@ namespace Orchard.ContentManagement.Handlers {
public Action<ActivatedContentContext, TPart> OnActivated { get; set; }
public Action<CreateContentContext, TPart> OnCreating { get; set; }
public Action<CreateContentContext, TPart> OnCreated { get; set; }
public Action<SaveContentContext, TPart> OnSaving { get; set; }
public Action<SaveContentContext, TPart> OnSaved { get; set; }
public Action<LoadContentContext, TPart> OnLoading { get; set; }
public Action<LoadContentContext, TPart> OnLoaded { get; set; }
public Action<VersionContentContext, TPart, TPart> OnVersioning { get; set; }
@@ -103,6 +113,12 @@ namespace Orchard.ContentManagement.Handlers {
protected override void Created(CreateContentContext context, TPart instance) {
if (OnCreated != null) OnCreated(context, instance);
}
protected override void Saving(SaveContentContext context, TPart instance) {
if (OnSaving != null) OnSaving(context, instance);
}
protected override void Saved(SaveContentContext context, TPart instance) {
if (OnSaved != null) OnSaved(context, instance);
}
protected override void Loading(LoadContentContext context, TPart instance) {
if (OnLoading != null) OnLoading(context, instance);
}
@@ -185,6 +201,18 @@ namespace Orchard.ContentManagement.Handlers {
Created(context);
}
void IContentHandler.Saving(SaveContentContext context) {
foreach (var filter in Filters.OfType<IContentStorageFilter>())
filter.Saving(context);
Saving(context);
}
void IContentHandler.Saved(SaveContentContext context) {
foreach (var filter in Filters.OfType<IContentStorageFilter>())
filter.Saved(context);
Saved(context);
}
void IContentHandler.Loading(LoadContentContext context) {
foreach (var filter in Filters.OfType<IContentStorageFilter>())
filter.Loading(context);
@@ -272,6 +300,9 @@ namespace Orchard.ContentManagement.Handlers {
protected virtual void Creating(CreateContentContext context) { }
protected virtual void Created(CreateContentContext context) { }
protected virtual void Saving(SaveContentContext context) { }
protected virtual void Saved(SaveContentContext context) { }
protected virtual void Loading(LoadContentContext context) { }
protected virtual void Loaded(LoadContentContext context) { }

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
namespace Orchard.ContentManagement.Handlers {
@@ -20,6 +19,12 @@ namespace Orchard.ContentManagement.Handlers {
public virtual void Created(CreateContentContext context) {
}
public virtual void Saving(SaveContentContext context) {
}
public virtual void Saved(SaveContentContext context) {
}
public virtual void Loading(LoadContentContext context) {
}

View File

@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using Orchard.Events;
using System.Collections.Generic;
namespace Orchard.ContentManagement.Handlers {
public interface IContentHandler : IEvents {
@@ -10,6 +8,8 @@ namespace Orchard.ContentManagement.Handlers {
void Activated(ActivatedContentContext context);
void Creating(CreateContentContext context);
void Created(CreateContentContext context);
void Saving(SaveContentContext context);
void Saved(SaveContentContext context);
void Loading(LoadContentContext context);
void Loaded(LoadContentContext context);
void Versioning(VersionContentContext context);

View File

@@ -3,6 +3,8 @@ namespace Orchard.ContentManagement.Handlers {
void Activated(ActivatedContentContext context);
void Creating(CreateContentContext context);
void Created(CreateContentContext context);
void Saving(SaveContentContext context);
void Saved(SaveContentContext context);
void Loading(LoadContentContext context);
void Loaded(LoadContentContext context);
void Versioning(VersionContentContext context);

View File

@@ -0,0 +1,12 @@
using Orchard.ContentManagement.Records;
namespace Orchard.ContentManagement.Handlers {
public class SaveContentContext : ContentContextBase {
public SaveContentContext(ContentItem contentItem)
: base(contentItem) {
ContentItemVersionRecord = contentItem.VersionRecord;
}
public ContentItemVersionRecord ContentItemVersionRecord { get; set; }
}
}

View File

@@ -4,6 +4,8 @@ namespace Orchard.ContentManagement.Handlers {
protected virtual void Activated(ActivatedContentContext context, TPart instance) { }
protected virtual void Creating(CreateContentContext context, TPart instance) { }
protected virtual void Created(CreateContentContext context, TPart instance) { }
protected virtual void Saving(SaveContentContext context, TPart instance) { }
protected virtual void Saved(SaveContentContext context, TPart instance) { }
protected virtual void Loading(LoadContentContext context, TPart instance) { }
protected virtual void Loaded(LoadContentContext context, TPart instance) { }
protected virtual void Versioning(VersionContentContext context, TPart existing, TPart building) { }
@@ -31,6 +33,16 @@ namespace Orchard.ContentManagement.Handlers {
Created(context, context.ContentItem.As<TPart>());
}
void IContentStorageFilter.Saving(SaveContentContext context) {
if (context.ContentItem.Is<TPart>())
Saving(context, context.ContentItem.As<TPart>());
}
void IContentStorageFilter.Saved(SaveContentContext context) {
if (context.ContentItem.Is<TPart>())
Saved(context, context.ContentItem.As<TPart>());
}
void IContentStorageFilter.Loading(LoadContentContext context) {
if (context.ContentItem.Is<TPart>())
Loading(context, context.ContentItem.As<TPart>());

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Orchard.Utility.Extensions;

View File

@@ -7,6 +7,7 @@ using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;
using Orchard.Collections;
using Orchard.Localization;
using Orchard.Mvc.ViewModels;
using Orchard.Services;
using Orchard.Settings;
@@ -178,44 +179,44 @@ namespace Orchard.Mvc.Html {
#region Format Date/Time
public static string DateTimeRelative(this HtmlHelper htmlHelper, DateTime? value, string defaultIfNull) {
return value.HasValue ? htmlHelper.DateTimeRelative(value.Value) : defaultIfNull;
public static LocalizedString DateTimeRelative(this HtmlHelper htmlHelper, DateTime? value, LocalizedString defaultIfNull, Localizer T) {
return value.HasValue ? htmlHelper.DateTimeRelative(value.Value, T) : defaultIfNull;
}
//TODO: (erikpo) This method needs localized
public static string DateTimeRelative(this HtmlHelper htmlHelper, DateTime value) {
TimeSpan time = htmlHelper.Resolve<IClock>().UtcNow - value;
public static LocalizedString DateTimeRelative(this HtmlHelper htmlHelper, DateTime value, Localizer T) {
var time = htmlHelper.Resolve<IClock>().UtcNow - value;
if (time.TotalDays > 7)
return "on " + htmlHelper.DateTime(value, "MMM d yyyy 'at' h:mm tt");
return htmlHelper.DateTime(value, T("'on' MMM d yyyy 'at' h:mm tt"));
if (time.TotalHours > 24)
return string.Format("{0} day{1} ago", time.Days, time.Days == 1 ? "" : "s");
return T.Plural("1 day ago", "{0} days ago", time.Days);
if (time.TotalMinutes > 60)
return string.Format("{0} hour{1} ago", time.Hours, time.Hours == 1 ? "" : "s");
return T.Plural("1 hour ago", "{0} hours ago", time.Hours);
if (time.TotalSeconds > 60)
return string.Format("{0} minute{1} ago", time.Minutes, time.Minutes == 1 ? "" : "s");
return T.Plural("1 minute ago", "{0} minutes ago", time.Minutes);
if (time.TotalSeconds > 10)
return string.Format("{0} second{1} ago", time.Seconds, time.Seconds == 1 ? "" : "s");
return T.Plural("1 second ago", "{0} seconds ago", time.Seconds); //aware that the singular won't be used
return "a moment ago";
return T("a moment ago");
}
public static string DateTime(this HtmlHelper htmlHelper, DateTime? value, string defaultIfNull) {
public static LocalizedString DateTime(this HtmlHelper htmlHelper, DateTime? value, LocalizedString defaultIfNull) {
return value.HasValue ? htmlHelper.DateTime(value.Value) : defaultIfNull;
}
public static string DateTime(this HtmlHelper htmlHelper, DateTime? value, string defaultIfNull, string customFormat) {
public static LocalizedString DateTime(this HtmlHelper htmlHelper, DateTime? value, LocalizedString defaultIfNull, LocalizedString customFormat) {
return value.HasValue ? htmlHelper.DateTime(value.Value, customFormat) : defaultIfNull;
}
public static string DateTime(this HtmlHelper htmlHelper, DateTime value) {
public static LocalizedString DateTime(this HtmlHelper htmlHelper, DateTime value) {
//TODO: (erikpo) This default format should come from a site setting
return htmlHelper.DateTime(value, "MMM d yyyy h:mm tt");
return htmlHelper.DateTime(value, new LocalizedString("MMM d yyyy h:mm tt")); //todo: above comment and get rid of just wrapping this as a localized string
}
public static string DateTime(this HtmlHelper htmlHelper, DateTime value, string customFormat) {
public static LocalizedString DateTime(this HtmlHelper htmlHelper, DateTime value, LocalizedString customFormat) {
//TODO: (erikpo) In the future, convert this to "local" time before calling ToString
return value.ToString(customFormat);
return value.ToString(customFormat.Text);
}
#endregion

View File

@@ -170,6 +170,9 @@
<Compile Include="ContentManagement\Drivers\CombinedResult.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="ContentManagement\Drivers\ContentFieldDriver.cs" />
<Compile Include="ContentManagement\Drivers\ContentFieldDriverHandler.cs" />
<Compile Include="ContentManagement\Drivers\ContentFieldTemplateResult.cs" />
<Compile Include="ContentManagement\Drivers\ContentItemDriver.cs">
<SubType>Code</SubType>
</Compile>
@@ -255,6 +258,7 @@
<Compile Include="ContentManagement\Handlers\RemoveContentContext.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="ContentManagement\Handlers\SaveContentContext.cs" />
<Compile Include="ContentManagement\Handlers\StorageFilter.cs">
<SubType>Code</SubType>
</Compile>