--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-03-03 03:32:31 -08:00
6 changed files with 115 additions and 96 deletions

View File

@@ -1,5 +1,7 @@
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.Blogs.Models; using Orchard.Blogs.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Mvc.Html; using Orchard.Mvc.Html;
namespace Orchard.Blogs.Extensions { namespace Orchard.Blogs.Extensions {
@@ -9,7 +11,7 @@ namespace Orchard.Blogs.Extensions {
} }
public static string PublishedState(this HtmlHelper htmlHelper, BlogPost blogPost) { public static string PublishedState(this HtmlHelper htmlHelper, BlogPost blogPost) {
return htmlHelper.DateTime(blogPost.PublishedUtc, "Draft"); return htmlHelper.DateTime(blogPost.As<ICommonAspect>().VersionPublishedUtc, "Draft");
} }
public static string PublishedWhen(this HtmlHelper<BlogPost> htmlHelper) { public static string PublishedWhen(this HtmlHelper<BlogPost> htmlHelper) {
@@ -17,7 +19,7 @@ namespace Orchard.Blogs.Extensions {
} }
public static string PublishedWhen(this HtmlHelper htmlHelper, BlogPost blogPost) { public static string PublishedWhen(this HtmlHelper htmlHelper, BlogPost blogPost) {
return htmlHelper.DateTimeRelative(blogPost.PublishedUtc, "as a Draft"); return htmlHelper.DateTimeRelative(blogPost.As<ICommonAspect>().VersionPublishedUtc, "as a Draft");
} }
} }
} }

View File

@@ -60,10 +60,6 @@ namespace Orchard.Blogs.Models {
get { return this.As<ICommonAspect>().CreatedUtc; } get { return this.As<ICommonAspect>().CreatedUtc; }
} }
public DateTime? PublishedUtc {
get { return this.As<ICommonAspect>().VersionPublishedUtc; }
}
public DateTime? ScheduledPublishUtc { get; set; } public DateTime? ScheduledPublishUtc { get; set; }
private string _scheduledPublishUtcDate; private string _scheduledPublishUtcDate;

View File

@@ -1,4 +1,5 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %>
<%@ Import Namespace="Orchard.ContentManagement.Aspects"%>
<%@ Import Namespace="Orchard.ContentManagement"%> <%@ Import Namespace="Orchard.ContentManagement"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%> <%@ Import Namespace="Orchard.Core.Common.Models"%>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%> <%@ Import Namespace="Orchard.Mvc.ViewModels"%>
@@ -30,20 +31,20 @@
<%=Html.DateTime(Model.Item.ScheduledPublishUtc.Value, "M/d/yyyy h:mm tt")%><% <%=Html.DateTime(Model.Item.ScheduledPublishUtc.Value, "M/d/yyyy h:mm tt")%><%
} }
else if (Model.Item.IsPublished) { %> else if (Model.Item.IsPublished) { %>
<%=_Encoded("Published: ") + Html.PublishedWhen(Model.Item) %><% <%=_Encoded("Published: ") + Html.DateTimeRelative(Model.Item.As<ICommonAspect>().VersionPublishedUtc.Value)%><%
} }
else { %> else { %>
<%=_Encoded("Last modified: ") + Html.DateTimeRelative(Model.Item.As<CommonAspect>().ModifiedUtc.Value) %><% <%=_Encoded("Last modified: ") + Html.DateTimeRelative(Model.Item.As<ICommonAspect>().ModifiedUtc.Value) %><%
} %>&nbsp;&#124;&nbsp; } %>&nbsp;&#124;&nbsp;
</li> </li>
<li><%=_Encoded("By {0}", Model.Item.Creator == null ? String.Empty : Model.Item.Creator.UserName)%></li> <li><%=_Encoded("By {0}", Model.Item.Creator.UserName)%></li>
</ul> </ul>
</div> </div>
<div class="related"><% <div class="related"><%
if (Model.Item.HasPublished){ %> if (Model.Item.HasPublished){ %>
<a href="<%=Url.BlogPost(Model.Item) %>" title="<%=_Encoded("View Post")%>"><%=_Encoded("View")%></a><%=_Encoded(" | ")%><% <a href="<%=Url.BlogPost(Model.Item) %>" title="<%=_Encoded("View Post")%>"><%=_Encoded("View")%></a><%=_Encoded(" | ")%><%
if (Model.Item.HasDraft) { %> if (Model.Item.HasDraft) { %>
<a href="<%=Html.AntiForgeryTokenGetUrl(Url.BlogPostPublish(Model.Item)) %>" title="<%=_Encoded("Publish Draft")%>"><%=_Encoded("Publish Draft")%></a><%=_Encoded(" | ")%><% <a href="<%=Html.AntiForgeryTokenGetUrl(Url.BlogPostPublish(Model.Item)) %>" title="<%=_Encoded("Publish Draft")%>"><%=_Encoded("Publish Draft")%></a><%=_Encoded(" | ")%><%
} %> } %>
<a href="<%=Html.AntiForgeryTokenGetUrl(Url.BlogPostUnpublish(Model.Item)) %>" title="<%=_Encoded("Unpublish Post")%>"><%=_Encoded("Unpublish")%></a><%=_Encoded(" | ")%><% <a href="<%=Html.AntiForgeryTokenGetUrl(Url.BlogPostUnpublish(Model.Item)) %>" title="<%=_Encoded("Unpublish Post")%>"><%=_Encoded("Unpublish")%></a><%=_Encoded(" | ")%><%
} }
@@ -51,7 +52,7 @@
<a href="<%=Html.AntiForgeryTokenGetUrl(Url.BlogPostPublish(Model.Item)) %>" title="<%=_Encoded("Publish Post")%>"><%=_Encoded("Publish")%></a><%=_Encoded(" | ")%><% <a href="<%=Html.AntiForgeryTokenGetUrl(Url.BlogPostPublish(Model.Item)) %>" title="<%=_Encoded("Publish Post")%>"><%=_Encoded("Publish")%></a><%=_Encoded(" | ")%><%
} %> } %>
<a href="<%=Url.BlogPostEdit(Model.Item) %>" title="<%=_Encoded("Edit Post")%>"><%=_Encoded("Edit")%></a><%=_Encoded(" | ")%> <a href="<%=Url.BlogPostEdit(Model.Item) %>" title="<%=_Encoded("Edit Post")%>"><%=_Encoded("Edit")%></a><%=_Encoded(" | ")%>
<a href="<%=Html.AntiForgeryTokenGetUrl(Url.BlogPostDelete(Model.Item)) %>" title="<%=_Encoded("Delete")%>"><%=_Encoded("Delete")%></a> <a href="<%=Html.AntiForgeryTokenGetUrl(Url.BlogPostDelete(Model.Item)) %>" title="<%=_Encoded("Delete Post")%>"><%=_Encoded("Delete")%></a>
<br /><%Html.Zone("meta");%> <br /><%Html.Zone("meta");%>
</div> </div>
<div style="clear:both;"></div> <div style="clear:both;"></div>

View File

@@ -6,6 +6,7 @@ using System.Web.Mvc;
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.Localization; using Orchard.Localization;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.Mvc.AntiForgery;
using Orchard.Mvc.Results; using Orchard.Mvc.Results;
using Orchard.Pages.Models; using Orchard.Pages.Models;
using Orchard.Pages.Services; using Orchard.Pages.Services;
@@ -210,7 +211,6 @@ namespace Orchard.Pages.Controllers {
return RedirectToAction("Edit", "Admin", new { id = model.Page.Item.ContentItem.Id }); return RedirectToAction("Edit", "Admin", new { id = model.Page.Item.ContentItem.Id });
} }
public ActionResult DiscardDraft(int id) { public ActionResult DiscardDraft(int id) {
// get the current draft version // get the current draft version
var draft = Services.ContentManager.Get(id, VersionOptions.Draft); var draft = Services.ContentManager.Get(id, VersionOptions.Draft);
@@ -239,9 +239,41 @@ namespace Orchard.Pages.Controllers {
return RedirectToAction("Edit", new { draft.Id }); return RedirectToAction("Edit", new { draft.Id });
} }
[HttpPost] [ValidateAntiForgeryTokenOrchard]
public ActionResult Publish(int id) {
if (!Services.Authorizer.Authorize(Permissions.PublishPages, T("Couldn't publish page")))
return new HttpUnauthorizedResult();
var page = _pageService.GetLatest(id);
if (page == null)
return new NotFoundResult();
_pageService.Publish(page);
Services.ContentManager.Flush();
Services.Notifier.Information(T("Page successfully published."));
return RedirectToAction("List");
}
[ValidateAntiForgeryTokenOrchard]
public ActionResult Unpublish(int id) {
if (!Services.Authorizer.Authorize(Permissions.PublishPages, T("Couldn't unpublish page")))
return new HttpUnauthorizedResult();
var page = _pageService.GetLatest(id);
if (page == null)
return new NotFoundResult();
_pageService.Unpublish(page);
Services.ContentManager.Flush();
Services.Notifier.Information(T("Page successfully unpublished."));
return RedirectToAction("List");
}
[ValidateAntiForgeryTokenOrchard]
public ActionResult Delete(int id) { public ActionResult Delete(int id) {
Page page = _pageService.Get(id); var page = _pageService.GetLatest(id);
if (page == null) if (page == null)
return new NotFoundResult(); return new NotFoundResult();
@@ -249,7 +281,7 @@ namespace Orchard.Pages.Controllers {
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
_pageService.Delete(page); _pageService.Delete(page);
Services.Notifier.Information(T("Page was successfully deleted")); Services.Notifier.Information(T("Page successfully deleted"));
return RedirectToAction("List"); return RedirectToAction("List");
} }

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Core.Common.Models; using Orchard.Core.Common.Models;
using Orchard.Security; using Orchard.Security;

View File

@@ -1,11 +1,13 @@
<%@ Page Language="C#" Inherits="Orchard.Mvc.ViewPage<PagesViewModel>" %> <%@ 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.Mvc.Html"%>
<%@ Import Namespace="Orchard.Pages.ViewModels"%> <%@ Import Namespace="Orchard.Pages.ViewModels"%>
<h1><%=Html.TitleForPage(T("Manage Pages").ToString())%></h1> <h1><%=Html.TitleForPage(T("Manage Pages").ToString())%></h1>
<%-- todo: Add helper text here when ready. <p><%=_Encoded("Possible text about setting up a page goes here.")%></p>--%> <%-- todo: Add helper text here when ready. <p><%=_Encoded("Possible text about setting up a page goes here.")%></p>--%>
<div class="manage"><%=Html.ActionLink(T("Add a page").ToString(), "Create", new { }, new { @class = "button primaryAction" })%></div> <div class="manage"><%=Html.ActionLink(T("Add a page").ToString(), "Create", new { }, new { @class = "button primaryAction" })%></div><%
<% using (Html.BeginFormAntiForgeryPost()) using (Html.BeginFormAntiForgeryPost()) { %>
{ %>
<%=Html.ValidationSummary()%> <%=Html.ValidationSummary()%>
<fieldset class="actions bulk"> <fieldset class="actions bulk">
<label for="publishActions"><%=_Encoded("Actions:")%></label> <label for="publishActions"><%=_Encoded("Actions:")%></label>
@@ -27,85 +29,70 @@
<input class="button" type="submit" name="submit.Filter" value="<%=_Encoded("Apply") %>"/> <input class="button" type="submit" name="submit.Filter" value="<%=_Encoded("Apply") %>"/>
</fieldset> </fieldset>
<fieldset class="pageList"> <fieldset class="pageList">
<ul class="contentItems"><%
var pageIndex = 0;
<ul class="contentItems"> foreach (var pageEntry in Model.PageEntries) {
<% var pi = pageIndex; %>
int pageIndex = 0;
foreach (var pageEntry in Model.PageEntries)
{
var pi = pageIndex; %>
<li>
<div class="summary">
<div class="properties">
<input type="hidden" value="<%=Model.PageEntries[pageIndex].PageId %>" name="<%=Html.NameOf(m => m.PageEntries[pi].PageId) %>"/>
<input type="checkbox" value="true" name="<%=Html.NameOf(m => m.PageEntries[pi].IsChecked) %>"/>
<h3><%=Html.ActionLink(pageEntry.Page.Title, "Edit", new { id = pageEntry.PageId })%></h3>
<ul class="pageStatus">
<li><%--Published or not--%>
<% if (pageEntry.Page.HasPublished)
{ %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Pages/Content/Admin/images/online.gif") %>" alt="<%=_Encoded("Online") %>" title="<%=_Encoded("The page is currently online") %>" /><%=_Encoded("Published") %>&nbsp;&#124;&nbsp;
<% }
else
{ %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Pages/Content/Admin/images/offline.gif") %>" alt="<%=_Encoded("Offline") %>" title="<%=_Encoded("The page is currently offline") %>" /><%=_Encoded("Not Published")%>&nbsp;&#124;&nbsp;
<% } %>
</li>
<li><%--Does the page have a draft--%>
<% if (pageEntry.Page.HasDraft)
{ %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Pages/Content/Admin/images/draft.gif") %>" alt="<%=_Encoded("Draft") %>" title="<%=_Encoded("The page has a draft") %>" /><%=_Encoded("Draft")%>&nbsp;&#124;&nbsp;
<% }
else
{ %>
<%=_Encoded("No Draft")%>&nbsp;&#124;&nbsp;
<% } %>
<%--Scheduled--%>
<% if (!pageEntry.Page.IsPublished)
{ %>
<%if (pageEntry.Page.ScheduledPublishUtc != null) { %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Pages/Content/Admin/images/scheduled.gif") %>" alt="<%=_Encoded("Scheduled") %>" title="<%=_Encoded("The page is scheduled for publishing") %>" /><%=string.Format("Scheduled: {0:d}", pageEntry.Page.ScheduledPublishUtc.Value) %>&nbsp;&#124;&nbsp;
<% }%>
<% } %>
</li>
<li> <li>
<%--Author--%> <div class="summary">
<%=_Encoded("By {0}", pageEntry.Page.Creator.UserName)%> <div class="properties">
</li> <input type="hidden" value="<%=Model.PageEntries[pageIndex].PageId %>" name="<%=Html.NameOf(m => m.PageEntries[pi].PageId) %>"/>
<input type="checkbox" value="true" name="<%=Html.NameOf(m => m.PageEntries[pi].IsChecked) %>"/>
<h3><%=Html.ActionLink(pageEntry.Page.Title, "Edit", new { id = pageEntry.PageId })%></h3>
<ul class="pageStatus">
<li><%
// Published or not
if (pageEntry.Page.HasPublished) { %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Pages/Content/Admin/images/online.gif") %>" alt="<%=_Encoded("Online") %>" title="<%=_Encoded("The page is currently online") %>" /><%=_Encoded("Published") %>&nbsp;&#124;&nbsp;<%
}
else { %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Pages/Content/Admin/images/offline.gif") %>" alt="<%=_Encoded("Offline") %>" title="<%=_Encoded("The page is currently offline") %>" /><%=_Encoded("Not Published")%>&nbsp;&#124;&nbsp;<%
} %>
</li>
<li><%
// Does the page have a draft
if (pageEntry.Page.HasDraft) { %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Pages/Content/Admin/images/draft.gif") %>" alt="<%=_Encoded("Draft") %>" title="<%=_Encoded("The page has a draft") %>" /><%=_Encoded("Draft")%>&nbsp;&#124;&nbsp;<%
}
else { %>
<%=_Encoded("No Draft")%>&nbsp;&#124;&nbsp;<%
} %>
</li>
<li><%
if (pageEntry.Page.ScheduledPublishUtc.HasValue && pageEntry.Page.ScheduledPublishUtc.Value > DateTime.UtcNow) { %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Pages/Content/Admin/images/scheduled.gif") %>" alt="<%=_Encoded("Scheduled") %>" title="<%=_Encoded("The page is scheduled for publishing") %>" /><%=_Encoded("Scheduled")%>
<%=Html.DateTime(pageEntry.Page.ScheduledPublishUtc.Value, "M/d/yyyy h:mm tt")%><%
}
else if (pageEntry.Page.IsPublished) { %>
<%=_Encoded("Published: ") + Html.DateTimeRelative(pageEntry.Page.As<ICommonAspect>().VersionPublishedUtc.Value) %><%
}
else { %>
<%=_Encoded("Last modified: ") + Html.DateTimeRelative(pageEntry.Page.As<ICommonAspect>().ModifiedUtc.Value) %><%
} %>&nbsp;&#124;&nbsp;
</li>
<li><%=_Encoded("By {0}", pageEntry.Page.Creator.UserName)%></li>
</ul>
</div>
<div class="related"><%
if (pageEntry.Page.HasPublished) { %>
<%=Html.ActionLink("View", "Item", new { controller = "Page", slug = pageEntry.Page.PublishedSlug }, new {title = _Encoded("View Page")})%><%=_Encoded(" | ")%><%
if (pageEntry.Page.HasDraft) { %>
<a href="<%=Html.AntiForgeryTokenGetUrl(Url.Action("Publish", new {id = pageEntry.Page.Id})) %>" title="<%=_Encoded("Publish Draft")%>"><%=_Encoded("Publish Draft")%></a><%=_Encoded(" | ")%><%
} %>
<a href="<%=Html.AntiForgeryTokenGetUrl(Url.Action("Unpublish", new {id = pageEntry.Page.Id})) %>" title="<%=_Encoded("Unpublish Page")%>"><%=_Encoded("Unpublish")%></a><%=_Encoded(" | ")%><%
}
else { %>
<a href="<%=Html.AntiForgeryTokenGetUrl(Url.Action("Publish", new {id = pageEntry.Page.Id})) %>" title="<%=_Encoded("Publish Page")%>"><%=_Encoded("Publish")%></a><%=_Encoded(" | ")%><%
} %>
<%=Html.ActionLink(_Encoded("Edit").ToString(), "Edit", new {id = pageEntry.Page.Id}, new {title = _Encoded("Edit Page")})%><%=_Encoded(" | ")%>
<a href="<%=Html.AntiForgeryTokenGetUrl(Url.Action("Delete", new {id = pageEntry.Page.Id})) %>" title="<%=_Encoded("Delete Page")%>"><%=_Encoded("Delete")%></a>
</div>
<div style="clear:both;"></div>
</div>
</li><%
pageIndex++;
} %>
</ul> </ul>
</div> </fieldset><%
<div class="related">
<% if (pageEntry.Page.HasPublished)
{ %>
<%=Html.ActionLink("View", "Item", new { controller = "Page", slug = pageEntry.Page.PublishedSlug })%>
<%=_Encoded("|")%>
<% }
else
{%>
<%=""%>
<% } %>
<%=Html.ActionLink(T("Edit").ToString(), "Edit", new { id = pageEntry.PageId })%>
</div>
<div style="clear:both;"></div>
</div>
</li>
<%
pageIndex++;
} %> } %>
</ul>
</fieldset>
<% } %>
<div class="manage"><%=Html.ActionLink(T("Add a page").ToString(), "Create", new { }, new { @class = "button primaryAction" })%></div> <div class="manage"><%=Html.ActionLink(T("Add a page").ToString(), "Create", new { }, new { @class = "button primaryAction" })%></div>