2010-07-14 15:31:43 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using Orchard.ContentManagement;
|
|
|
|
|
|
using Orchard.ContentManagement.Drivers;
|
|
|
|
|
|
using Orchard.Core.Common.Services;
|
2010-10-25 18:21:19 -07:00
|
|
|
|
using Orchard.PublishLater.Models;
|
|
|
|
|
|
using Orchard.PublishLater.Services;
|
|
|
|
|
|
using Orchard.PublishLater.ViewModels;
|
2010-07-14 15:31:43 -07:00
|
|
|
|
using Orchard.Localization;
|
2010-10-26 07:56:56 -07:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using Orchard.Core.Localization.Services;
|
2010-07-14 15:31:43 -07:00
|
|
|
|
|
2010-10-25 18:21:19 -07:00
|
|
|
|
namespace Orchard.PublishLater.Drivers {
|
2010-07-14 15:31:43 -07:00
|
|
|
|
public class PublishLaterPartDriver : ContentPartDriver<PublishLaterPart> {
|
2010-10-13 04:51:15 -07:00
|
|
|
|
private const string TemplateName = "Parts/PublishLater";
|
2010-07-14 15:31:43 -07:00
|
|
|
|
private readonly ICommonService _commonService;
|
|
|
|
|
|
private readonly IPublishLaterService _publishLaterService;
|
2010-10-26 07:56:56 -07:00
|
|
|
|
private const string DatePattern = "M/d/yyyy";
|
|
|
|
|
|
private const string TimePattern = "h:mm tt";
|
2010-07-14 15:31:43 -07:00
|
|
|
|
|
|
|
|
|
|
public PublishLaterPartDriver(
|
|
|
|
|
|
IOrchardServices services,
|
|
|
|
|
|
ICommonService commonService,
|
|
|
|
|
|
IPublishLaterService publishLaterService) {
|
|
|
|
|
|
_commonService = commonService;
|
|
|
|
|
|
_publishLaterService = publishLaterService;
|
|
|
|
|
|
T = NullLocalizer.Instance;
|
|
|
|
|
|
Services = services;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Localizer T { get; set; }
|
|
|
|
|
|
public IOrchardServices Services { get; set; }
|
|
|
|
|
|
|
2010-10-13 04:51:15 -07:00
|
|
|
|
protected override string Prefix {
|
|
|
|
|
|
get { return "PublishLater"; }
|
2010-07-14 15:31:43 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2010-10-13 04:51:15 -07:00
|
|
|
|
protected override DriverResult Display(PublishLaterPart part, string displayType, dynamic shapeHelper) {
|
|
|
|
|
|
return Combined(
|
|
|
|
|
|
ContentShape("Parts_PublishLater_Metadata",
|
2010-10-15 18:11:06 -07:00
|
|
|
|
() => shapeHelper.Parts_PublishLater_Metadata(ContentPart: part, ScheduledPublishUtc: part.ScheduledPublishUtc.Value)),
|
2010-10-13 04:51:15 -07:00
|
|
|
|
ContentShape("Parts_PublishLater_Metadata_Summary",
|
|
|
|
|
|
() => shapeHelper.Parts_PublishLater_Metadata_Summary(ContentPart: part, ScheduledPublishUtc: part.ScheduledPublishUtc.Value)),
|
|
|
|
|
|
ContentShape("Parts_PublishLater_Metadata_SummaryAdmin",
|
|
|
|
|
|
() => shapeHelper.Parts_PublishLater_Metadata_SummaryAdmin(ContentPart: part, ScheduledPublishUtc: part.ScheduledPublishUtc.Value))
|
|
|
|
|
|
);
|
2010-07-14 15:31:43 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2010-10-13 04:51:15 -07:00
|
|
|
|
protected override DriverResult Editor(PublishLaterPart part, dynamic shapeHelper) {
|
2010-10-26 07:56:56 -07:00
|
|
|
|
// 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
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2010-10-15 11:55:48 -07:00
|
|
|
|
return ContentShape("Parts_PublishLater_Edit",
|
2010-10-13 04:51:15 -07:00
|
|
|
|
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix));
|
2010-07-14 15:31:43 -07:00
|
|
|
|
}
|
2010-10-13 04:51:15 -07:00
|
|
|
|
protected override DriverResult Editor(PublishLaterPart part, IUpdateModel updater, dynamic shapeHelper) {
|
2010-07-14 15:31:43 -07:00
|
|
|
|
var model = new PublishLaterViewModel(part);
|
2010-10-26 07:56:56 -07:00
|
|
|
|
|
2010-10-13 04:51:15 -07:00
|
|
|
|
updater.TryUpdateModel(model, Prefix, null, null);
|
|
|
|
|
|
switch (model.Command) {
|
|
|
|
|
|
case "PublishNow":
|
|
|
|
|
|
_commonService.Publish(model.ContentItem);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "PublishLater":
|
|
|
|
|
|
DateTime scheduled;
|
2010-10-26 07:56:56 -07:00
|
|
|
|
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));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-10-13 04:51:15 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case "SaveDraft":
|
|
|
|
|
|
break;
|
2010-07-14 15:31:43 -07:00
|
|
|
|
}
|
2010-10-15 11:55:48 -07:00
|
|
|
|
return ContentShape("Parts_PublishLater_Edit",
|
2010-10-13 04:51:15 -07:00
|
|
|
|
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix));
|
|
|
|
|
|
}
|
2010-07-14 15:31:43 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|