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.Core.ContentsLocation.Models;
|
|
|
|
|
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-11 09:45:29 -07:00
|
|
|
var metadata = shapeHelper.Parts_ArchiveLater_Metadata(ContentPart: part, ScheduledArchiveUtc: part.ScheduledArchiveUtc.Value);
|
2010-10-11 02:06:01 -07:00
|
|
|
if (!string.IsNullOrWhiteSpace(displayType))
|
|
|
|
|
metadata.Metadata.Type = string.Format("{0}.{1}", metadata.Metadata.Type, displayType);
|
|
|
|
|
var location = part.GetLocation(displayType);
|
|
|
|
|
return ContentShape(metadata).Location(location);
|
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-08-04 13:42:06 -07:00
|
|
|
return ArchiveEditor(part, null);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-11 02:06:01 -07:00
|
|
|
protected override DriverResult Editor(ArchiveLaterPart instance, IUpdateModel updater, dynamic shapeHelper) {
|
2010-08-04 13:42:06 -07:00
|
|
|
return ArchiveEditor(instance, updater);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DriverResult ArchiveEditor(ArchiveLaterPart part, IUpdateModel updater) {
|
|
|
|
|
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);
|
|
|
|
|
//Services.Notifier.Information(T("{0} has been scheduled for publishing!", model.ContentItem.TypeDefinition.DisplayName));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
//_archiveLaterService.RemoveArchiveLaterTasks(model.ContentItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ContentPartTemplate(model, "Parts/ArchiveLater", TemplatePrefix).Location(part.GetLocation("Editor"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|