2010-08-04 13:42:06 -07:00
|
|
|
using System;
|
|
|
|
|
using Orchard;
|
2010-08-04 14:52:18 -07:00
|
|
|
using Orchard.ArchiveLater.Models;
|
|
|
|
|
using Orchard.ArchiveLater.Services;
|
|
|
|
|
using Orchard.ArchiveLater.ViewModels;
|
2010-08-04 13:42:06 -07:00
|
|
|
using Orchard.ContentManagement;
|
|
|
|
|
using Orchard.ContentManagement.Drivers;
|
|
|
|
|
using Orchard.Core.Common.Services;
|
|
|
|
|
using Orchard.Localization;
|
|
|
|
|
|
|
|
|
|
namespace ArchiveLater.Drivers {
|
|
|
|
|
public class ArchiveLaterPartDriver : ContentPartDriver<ArchiveLaterPart> {
|
|
|
|
|
private const string TemplatePrefix = "ArchiveLater";
|
|
|
|
|
private readonly ICommonService _commonService;
|
|
|
|
|
private readonly IArchiveLaterService _archiveLaterService;
|
|
|
|
|
|
|
|
|
|
public ArchiveLaterPartDriver(
|
|
|
|
|
IOrchardServices services,
|
|
|
|
|
ICommonService commonService,
|
|
|
|
|
IArchiveLaterService archiveLaterService) {
|
|
|
|
|
_commonService = commonService;
|
|
|
|
|
_archiveLaterService = archiveLaterService;
|
|
|
|
|
T = NullLocalizer.Instance;
|
|
|
|
|
Services = services;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Localizer T { get; set; }
|
|
|
|
|
public IOrchardServices Services { get; set; }
|
|
|
|
|
|
2010-10-11 02:06:01 -07:00
|
|
|
protected override DriverResult Display(ArchiveLaterPart part, string displayType, dynamic shapeHelper) {
|
2010-10-18 13:17:37 -07:00
|
|
|
return ContentShape("Parts_ArchiveLater_Metadata_SummaryAdmin",
|
|
|
|
|
shape => {
|
|
|
|
|
part.ScheduledArchiveUtc.Value = DateTime.UtcNow.AddDays(5);
|
|
|
|
|
|
|
|
|
|
return shape
|
|
|
|
|
.ContentPart(part)
|
|
|
|
|
.ScheduledArchiveUtc(part.ScheduledArchiveUtc.Value)
|
|
|
|
|
.IsPublished(part.ContentItem.VersionRecord != null && part.ContentItem.VersionRecord.Published);
|
|
|
|
|
});
|
2010-08-04 13:42:06 -07:00
|
|
|
}
|
|
|
|
|
|
2010-10-11 02:06:01 -07:00
|
|
|
protected override DriverResult Editor(ArchiveLaterPart part, dynamic shapeHelper) {
|
2010-10-18 13:17:37 -07:00
|
|
|
return ArchiveEditor(part, null, shapeHelper);
|
2010-08-04 13:42:06 -07:00
|
|
|
}
|
|
|
|
|
|
2010-10-11 02:06:01 -07:00
|
|
|
protected override DriverResult Editor(ArchiveLaterPart instance, IUpdateModel updater, dynamic shapeHelper) {
|
2010-10-18 13:17:37 -07:00
|
|
|
return ArchiveEditor(instance, updater, shapeHelper);
|
2010-08-04 13:42:06 -07:00
|
|
|
}
|
|
|
|
|
|
2010-10-18 13:17:37 -07:00
|
|
|
DriverResult ArchiveEditor(ArchiveLaterPart part, IUpdateModel updater, dynamic shapeHelper) {
|
2010-08-04 13:42:06 -07:00
|
|
|
var model = new ArchiveLaterViewModel(part);
|
|
|
|
|
|
|
|
|
|
if ( updater != null && updater.TryUpdateModel(model, TemplatePrefix, null, null) ) {
|
|
|
|
|
if (model.ArchiveLater) {
|
|
|
|
|
DateTime scheduled;
|
|
|
|
|
if (DateTime.TryParse(string.Format("{0} {1}", model.ScheduledArchiveDate, model.ScheduledArchiveTime), out scheduled))
|
|
|
|
|
model.ScheduledArchiveUtc = scheduled.ToUniversalTime();
|
|
|
|
|
_archiveLaterService.ArchiveLater(model.ContentItem, model.ScheduledArchiveUtc.HasValue ? model.ScheduledArchiveUtc.Value : DateTime.MaxValue);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2010-10-18 13:17:37 -07:00
|
|
|
_archiveLaterService.RemoveArchiveLaterTasks(model.ContentItem);
|
2010-08-04 13:42:06 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-18 13:17:37 -07:00
|
|
|
return ContentShape("Parts_ArchiveLater_Edit",
|
|
|
|
|
() => shapeHelper.EditorTemplate(TemplateName: "Parts/ArchiveLater", Model: model, Prefix: Prefix));
|
2010-08-04 13:42:06 -07:00
|
|
|
}
|
|
|
|
|
}
|
2010-10-18 13:17:37 -07:00
|
|
|
}
|