diff --git a/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs b/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs index 0dc8901ed..610bf27e4 100644 --- a/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs +++ b/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs @@ -8,6 +8,7 @@ using Orchard.ContentManagement; using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.MetaData; using Orchard.ContentManagement.MetaData.Models; +using Orchard.ContentManagement.Records; using Orchard.Core.Common.Models; using Orchard.Core.Contents.Settings; using Orchard.Core.Contents.ViewModels; @@ -67,12 +68,14 @@ namespace Orchard.Core.Contents.Controllers { switch (model.Options.OrderBy) { case ContentsOrder.Modified: + //query = query.OrderByDescending(ci => ci.ContentItemRecord.Versions.Single(civr => civr.Latest).Id); query = query.OrderByDescending(cr => cr.ModifiedUtc); break; case ContentsOrder.Published: query = query.OrderByDescending(cr => cr.PublishedUtc); break; case ContentsOrder.Created: + //query = query.OrderByDescending(ci => ci.Id); query = query.OrderByDescending(cr => cr.CreatedUtc); break; } @@ -189,24 +192,39 @@ namespace Orchard.Core.Contents.Controllers { return View(model); } + [HttpPost, ActionName("Create")] + [FormValueRequired("submit.Save")] + public ActionResult CreatePOST(string id) { + return CreatePOST(id, contentItem => { + if (!contentItem.Has() && !contentItem.TypeDefinition.Settings.GetModel().Draftable) + _contentManager.Publish(contentItem); + }); + } [HttpPost, ActionName("Create")] - public ActionResult CreatePOST(string id) { + [FormValueRequired("submit.Publish")] + public ActionResult CreateAndPublishPOST(string id) { + return CreatePOST(id, contentItem => _contentManager.Publish(contentItem)); + } + + private ActionResult CreatePOST(string id, Action conditionallyPublish) { var contentItem = _contentManager.New(id); if (!Services.Authorizer.Authorize(Permissions.PublishContent, contentItem, T("Couldn't create content"))) return new HttpUnauthorizedResult(); - _contentManager.Create(contentItem, VersionOptions.Draft); - var model = _contentManager.UpdateEditor(contentItem, this); + var isDraftable = contentItem.TypeDefinition.Settings.GetModel().Draftable; + _contentManager.Create( + contentItem, + isDraftable ? VersionOptions.Draft : VersionOptions.Published); + var model = _contentManager.UpdateEditor(contentItem, this); if (!ModelState.IsValid) { _transactionManager.Cancel(); return View(model); } - if (!contentItem.Has()) - _contentManager.Publish(contentItem); + conditionallyPublish(contentItem); Services.Notifier.Information(string.IsNullOrWhiteSpace(contentItem.TypeDefinition.DisplayName) ? T("Your content has been created.") @@ -229,7 +247,21 @@ namespace Orchard.Core.Contents.Controllers { } [HttpPost, ActionName("Edit")] + [FormValueRequired("submit.Save")] public ActionResult EditPOST(int id, string returnUrl) { + return EditPOST(id, returnUrl, contentItem => { + if (!contentItem.Has() && !contentItem.TypeDefinition.Settings.GetModel().Draftable) + _contentManager.Publish(contentItem); + }); + } + + [HttpPost, ActionName("Edit")] + [FormValueRequired("submit.Publish")] + public ActionResult EditAndPublishPOST(int id, string returnUrl) { + return EditPOST(id, returnUrl, contentItem => _contentManager.Publish(contentItem)); + } + + private ActionResult EditPOST(int id, string returnUrl, Action conditionallyPublish) { var contentItem = _contentManager.Get(id, VersionOptions.DraftRequired); if (contentItem == null) @@ -244,9 +276,7 @@ namespace Orchard.Core.Contents.Controllers { return View("Edit", model); } - //need to go about this differently - to know when to publish (IPlublishableAspect ?) - if (!contentItem.Has()) - _contentManager.Publish(contentItem); + conditionallyPublish(contentItem); Services.Notifier.Information(string.IsNullOrWhiteSpace(contentItem.TypeDefinition.DisplayName) ? T("Your content has been saved.") diff --git a/src/Orchard.Web/Core/Contents/Drivers/ContentsDriver.cs b/src/Orchard.Web/Core/Contents/Drivers/ContentsDriver.cs index 5c25bcc7b..44fba0439 100644 --- a/src/Orchard.Web/Core/Contents/Drivers/ContentsDriver.cs +++ b/src/Orchard.Web/Core/Contents/Drivers/ContentsDriver.cs @@ -1,5 +1,7 @@ -using Orchard.ContentManagement; +using System.Collections.Generic; +using Orchard.ContentManagement; using Orchard.ContentManagement.Drivers; +using Orchard.Core.Contents.Settings; namespace Orchard.Core.Contents.Drivers { public class ContentsDriver : ContentPartDriver { @@ -13,5 +15,18 @@ namespace Orchard.Core.Contents.Drivers { () => shapeHelper.Parts_Contents_Publish_SummaryAdmin(ContentPart: part)) ); } + + protected override DriverResult Editor(ContentPart part, dynamic shapeHelper) { + var results = new List { ContentShape("Content_SaveButton", saveButton => saveButton) }; + + if (part.TypeDefinition.Settings.GetModel().Draftable) + results.Add(ContentShape("Content_PublishButton", publishButton => publishButton)); + + return Combined(results.ToArray()); + } + + protected override DriverResult Editor(ContentPart part, IUpdateModel updater, dynamic shapeHelper) { + return Editor(part, updater); + } } } \ No newline at end of file diff --git a/src/Orchard.Web/Core/Contents/Placement.info b/src/Orchard.Web/Core/Contents/Placement.info index 8cc668cba..3d99c94b2 100644 --- a/src/Orchard.Web/Core/Contents/Placement.info +++ b/src/Orchard.Web/Core/Contents/Placement.info @@ -4,6 +4,9 @@ Parts_Contents_Publish Parts_Contents_Publish_SummaryAdmin --> + + + diff --git a/src/Orchard.Web/Core/Contents/Views/Content.PublishButton.cshtml b/src/Orchard.Web/Core/Contents/Views/Content.PublishButton.cshtml new file mode 100644 index 000000000..b8f48a08f --- /dev/null +++ b/src/Orchard.Web/Core/Contents/Views/Content.PublishButton.cshtml @@ -0,0 +1,3 @@ +
+ +
\ No newline at end of file diff --git a/src/Orchard.Web/Core/Contents/Views/Content.SaveButton.cshtml b/src/Orchard.Web/Core/Contents/Views/Content.SaveButton.cshtml new file mode 100644 index 000000000..cab18005a --- /dev/null +++ b/src/Orchard.Web/Core/Contents/Views/Content.SaveButton.cshtml @@ -0,0 +1,3 @@ +
+ +
\ No newline at end of file diff --git a/src/Orchard.Web/Core/Contents/Views/Items/Content.Edit.cshtml b/src/Orchard.Web/Core/Contents/Views/Items/Content.Edit.cshtml index e0f0cd87b..af834ed7e 100644 --- a/src/Orchard.Web/Core/Contents/Views/Items/Content.Edit.cshtml +++ b/src/Orchard.Web/Core/Contents/Views/Items/Content.Edit.cshtml @@ -4,9 +4,5 @@
@Display(Model.Sidebar) - @* todo: (heskew) remove when the CommonPart is adding the save button *@ -
- -
\ No newline at end of file diff --git a/src/Orchard.Web/Core/Orchard.Core.csproj b/src/Orchard.Web/Core/Orchard.Core.csproj index 54c8e7862..130141afa 100644 --- a/src/Orchard.Web/Core/Orchard.Core.csproj +++ b/src/Orchard.Web/Core/Orchard.Core.csproj @@ -274,12 +274,8 @@ - - Designer - - - Designer - + + @@ -358,18 +354,16 @@ - - Designer - - - Designer - + + + + Designer diff --git a/src/Orchard.Web/Modules/Orchard.PublishLater/Drivers/PublishLaterPartDriver.cs b/src/Orchard.Web/Modules/Orchard.PublishLater/Drivers/PublishLaterPartDriver.cs index a8ba7544a..5724829e3 100644 --- a/src/Orchard.Web/Modules/Orchard.PublishLater/Drivers/PublishLaterPartDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.PublishLater/Drivers/PublishLaterPartDriver.cs @@ -7,7 +7,6 @@ using Orchard.PublishLater.Services; using Orchard.PublishLater.ViewModels; using Orchard.Localization; using System.Globalization; -using Orchard.Core.Localization.Services; namespace Orchard.PublishLater.Drivers { public class PublishLaterPartDriver : ContentPartDriver { @@ -49,8 +48,8 @@ namespace Orchard.PublishLater.Drivers { // date and time are formatted using the same patterns as DateTimePicker is, preventing other cultures issues var model = new PublishLaterViewModel(part) { ScheduledPublishUtc = part.ScheduledPublishUtc.Value, - ScheduledPublishDate = part.ScheduledPublishUtc.Value.HasValue ? part.ScheduledPublishUtc.Value.Value.ToLocalTime().ToString(DatePattern, CultureInfo.InvariantCulture) : String.Empty, - ScheduledPublishTime = part.ScheduledPublishUtc.Value.HasValue ? part.ScheduledPublishUtc.Value.Value.ToLocalTime().ToString(TimePattern, CultureInfo.InvariantCulture) : String.Empty + ScheduledPublishDate = part.ScheduledPublishUtc.Value.HasValue && !part.IsPublished() ? part.ScheduledPublishUtc.Value.Value.ToLocalTime().ToString(DatePattern, CultureInfo.InvariantCulture) : String.Empty, + ScheduledPublishTime = part.ScheduledPublishUtc.Value.HasValue && !part.IsPublished() ? part.ScheduledPublishUtc.Value.Value.ToLocalTime().ToString(TimePattern, CultureInfo.InvariantCulture) : String.Empty }; return ContentShape("Parts_PublishLater_Edit", @@ -60,27 +59,24 @@ namespace Orchard.PublishLater.Drivers { var model = new PublishLaterViewModel(part); updater.TryUpdateModel(model, Prefix, null, null); - switch (model.Command) { - case "PublishNow": - _commonService.Publish(model.ContentItem); - break; - case "PublishLater": - DateTime scheduled; - string parseDateTime = String.Concat(model.ScheduledPublishDate, " ", model.ScheduledPublishTime); - - // use an english culture as it is the one used by jQuery.datepicker by default - if (DateTime.TryParse(parseDateTime, CultureInfo.GetCultureInfo("en-US"), DateTimeStyles.AssumeLocal, out scheduled)) { - model.ScheduledPublishUtc = part.ScheduledPublishUtc.Value = scheduled.ToUniversalTime(); - _publishLaterService.Publish(model.ContentItem, model.ScheduledPublishUtc.Value); - } - else { - updater.AddModelError(Prefix, T("{0} is an invalid date and time", parseDateTime)); - } - break; - case "SaveDraft": - break; + if (!string.IsNullOrWhiteSpace(model.ScheduledPublishDate) && !string.IsNullOrWhiteSpace(model.ScheduledPublishTime)) { + DateTime scheduled; + string parseDateTime = String.Concat(model.ScheduledPublishDate, " ", model.ScheduledPublishTime); + + // use an english culture as it is the one used by jQuery.datepicker by default + if (DateTime.TryParse(parseDateTime, CultureInfo.GetCultureInfo("en-US"), DateTimeStyles.AssumeLocal, out scheduled)) { + model.ScheduledPublishUtc = part.ScheduledPublishUtc.Value = scheduled.ToUniversalTime(); + _publishLaterService.Publish(model.ContentItem, model.ScheduledPublishUtc.Value); + } + else { + updater.AddModelError(Prefix, T("{0} is an invalid date and time", parseDateTime)); + } } + else if (!string.IsNullOrWhiteSpace(model.ScheduledPublishDate) || !string.IsNullOrWhiteSpace(model.ScheduledPublishTime)) { + updater.AddModelError(Prefix, T("Both the date and time need to be specified for when this is to be published. If you don't want to schedule publishing then clear both the date and time fields.")); + } + return ContentShape("Parts_PublishLater_Edit", () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix)); } diff --git a/src/Orchard.Web/Modules/Orchard.PublishLater/Placement.info b/src/Orchard.Web/Modules/Orchard.PublishLater/Placement.info index f321cd6a5..e1671d67b 100644 --- a/src/Orchard.Web/Modules/Orchard.PublishLater/Placement.info +++ b/src/Orchard.Web/Modules/Orchard.PublishLater/Placement.info @@ -7,7 +7,7 @@ --> - + diff --git a/src/Orchard.Web/Modules/Orchard.PublishLater/Styles/datetime.css b/src/Orchard.Web/Modules/Orchard.PublishLater/Styles/datetime.css index 21684b460..af6b87158 100644 --- a/src/Orchard.Web/Modules/Orchard.PublishLater/Styles/datetime.css +++ b/src/Orchard.Web/Modules/Orchard.PublishLater/Styles/datetime.css @@ -7,8 +7,8 @@ html.dyn input.hinted { font-style:italic; } input#PublishLater_ScheduledPublishDate { - width:50%; + width:49%; } input#PublishLater_ScheduledPublishTime { - width:36%; + width:43%; } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.PublishLater/ViewModels/PublishLaterViewModel.cs b/src/Orchard.Web/Modules/Orchard.PublishLater/ViewModels/PublishLaterViewModel.cs index 3961d56c4..4c5392c16 100644 --- a/src/Orchard.Web/Modules/Orchard.PublishLater/ViewModels/PublishLaterViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.PublishLater/ViewModels/PublishLaterViewModel.cs @@ -11,7 +11,6 @@ namespace Orchard.PublishLater.ViewModels { _publishLaterPart = publishLaterPart; } - public string Command { get; set; } public ContentItem ContentItem { get { return _publishLaterPart.ContentItem; } } public bool IsPublished { diff --git a/src/Orchard.Web/Modules/Orchard.PublishLater/Views/EditorTemplates/Parts/PublishLater.cshtml b/src/Orchard.Web/Modules/Orchard.PublishLater/Views/EditorTemplates/Parts/PublishLater.cshtml index 5b7681ce3..1ac58b8ee 100644 --- a/src/Orchard.Web/Modules/Orchard.PublishLater/Views/EditorTemplates/Parts/PublishLater.cshtml +++ b/src/Orchard.Web/Modules/Orchard.PublishLater/Views/EditorTemplates/Parts/PublishLater.cshtml @@ -4,48 +4,36 @@ Script.Require("jQueryUI_DatePicker"); Style.Require("PublishLater_DatePicker"); Style.Require("jQueryUtils_TimePicker"); - Style.Require("jQueryUI_DatePicker"); + Style.Require("jQueryUI_DatePicker"); } -
+
@T("Publish Settings") -
- @Html.RadioButton("Command", "SaveDraft", Model.ContentItem.VersionRecord == null || !Model.ContentItem.VersionRecord.Published, new { id = ViewData.TemplateInfo.GetFullHtmlFieldId("Command_SaveDraft") }) - -
-
- @Html.RadioButton("Command", "PublishNow", Model.ContentItem.VersionRecord != null && Model.ContentItem.VersionRecord.Published, new { id = ViewData.TemplateInfo.GetFullHtmlFieldId("Command_PublishNow") }) - -
-
- @Html.RadioButton("Command", "PublishLater", Model.ScheduledPublishUtc != null, new { id = ViewData.TemplateInfo.GetFullHtmlFieldId("Command_PublishLater") }) - -
-
- - @Html.EditorFor(m => m.ScheduledPublishDate) - - @Html.EditorFor(m => m.ScheduledPublishTime) -
+ + @Html.EditorFor(m => m.ScheduledPublishDate) + + @Html.EditorFor(m => m.ScheduledPublishTime)
@using(Script.Foot()) { diff --git a/src/Orchard.Web/Modules/Orchard.Users/Views/Admin/Edit.cshtml b/src/Orchard.Web/Modules/Orchard.Users/Views/Admin/Edit.cshtml index 362228de1..d3c8ccb8d 100644 --- a/src/Orchard.Web/Modules/Orchard.Users/Views/Admin/Edit.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Users/Views/Admin/Edit.cshtml @@ -19,6 +19,6 @@ @Display(Model.User)
- +
} diff --git a/src/Orchard.Web/Themes/TheAdmin/Styles/site.css b/src/Orchard.Web/Themes/TheAdmin/Styles/site.css index 8ae765e65..865e0ee9f 100644 --- a/src/Orchard.Web/Themes/TheAdmin/Styles/site.css +++ b/src/Orchard.Web/Themes/TheAdmin/Styles/site.css @@ -128,13 +128,13 @@ number of columns: 24; actual width: 946; column width: 26; gutter width:14 .sections .primary { display:inline; float:left; - width:74.543%; + width:69.452%; } .sections .secondary { display:inline; float:left; margin-left:1.71%; - width:23.629%; + width:28.721%; } /* Headings and defaults @@ -842,6 +842,29 @@ table .button { .settings legend { margin:0 0 -.4em 0; } +/* Core Contents and Orchard.PublishLater */ +fieldset.save-button { + clear:none; + float:left; + padding-right:0; + width:auto; +} +fieldset.publish-later-datetime { + clear:none; + float:left; + min-width:13.6em; + padding-left:6px; + padding-right:0; + width:68%; +} +fieldset.publish-later-datetime legend { + display:none; +} +fieldset.publish-later-datetime input { + padding:1px; + text-align:center; + color:#666; +} /* Fields ----------------------------------------------------------*/