mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Corrected Orchard.ArchiveLater
--HG-- branch : dev
This commit is contained in:
@@ -1,24 +1,19 @@
|
|||||||
using System;
|
using System;
|
||||||
using Orchard;
|
|
||||||
using Orchard.ArchiveLater.Models;
|
using Orchard.ArchiveLater.Models;
|
||||||
using Orchard.ArchiveLater.Services;
|
using Orchard.ArchiveLater.Services;
|
||||||
using Orchard.ArchiveLater.ViewModels;
|
using Orchard.ArchiveLater.ViewModels;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Drivers;
|
using Orchard.ContentManagement.Drivers;
|
||||||
using Orchard.Core.Common.Services;
|
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
|
|
||||||
namespace ArchiveLater.Drivers {
|
namespace Orchard.ArchiveLater.Drivers {
|
||||||
public class ArchiveLaterPartDriver : ContentPartDriver<ArchiveLaterPart> {
|
public class ArchiveLaterPartDriver : ContentPartDriver<ArchiveLaterPart> {
|
||||||
private const string TemplatePrefix = "ArchiveLater";
|
private const string TemplateName = "Parts/ArchiveLater";
|
||||||
private readonly ICommonService _commonService;
|
|
||||||
private readonly IArchiveLaterService _archiveLaterService;
|
private readonly IArchiveLaterService _archiveLaterService;
|
||||||
|
|
||||||
public ArchiveLaterPartDriver(
|
public ArchiveLaterPartDriver(
|
||||||
IOrchardServices services,
|
IOrchardServices services,
|
||||||
ICommonService commonService,
|
|
||||||
IArchiveLaterService archiveLaterService) {
|
IArchiveLaterService archiveLaterService) {
|
||||||
_commonService = commonService;
|
|
||||||
_archiveLaterService = archiveLaterService;
|
_archiveLaterService = archiveLaterService;
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
Services = services;
|
Services = services;
|
||||||
@@ -27,6 +22,8 @@ namespace ArchiveLater.Drivers {
|
|||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
public IOrchardServices Services { get; set; }
|
public IOrchardServices Services { get; set; }
|
||||||
|
|
||||||
|
protected override string Prefix { get { return "ArchiveLater"; } }
|
||||||
|
|
||||||
protected override DriverResult Display(ArchiveLaterPart part, string displayType, dynamic shapeHelper) {
|
protected override DriverResult Display(ArchiveLaterPart part, string displayType, dynamic shapeHelper) {
|
||||||
return ContentShape("Parts_ArchiveLater_Metadata_SummaryAdmin",
|
return ContentShape("Parts_ArchiveLater_Metadata_SummaryAdmin",
|
||||||
shape => {
|
shape => {
|
||||||
@@ -40,20 +37,24 @@ namespace ArchiveLater.Drivers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override DriverResult Editor(ArchiveLaterPart part, dynamic shapeHelper) {
|
protected override DriverResult Editor(ArchiveLaterPart part, dynamic shapeHelper) {
|
||||||
return ArchiveEditor(part, null, shapeHelper);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override DriverResult Editor(ArchiveLaterPart instance, IUpdateModel updater, dynamic shapeHelper) {
|
|
||||||
return ArchiveEditor(instance, updater, shapeHelper);
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverResult ArchiveEditor(ArchiveLaterPart part, IUpdateModel updater, dynamic shapeHelper) {
|
|
||||||
var model = new ArchiveLaterViewModel(part);
|
var model = new ArchiveLaterViewModel(part);
|
||||||
|
|
||||||
if ( updater != null && updater.TryUpdateModel(model, TemplatePrefix, null, null) ) {
|
model.ScheduledArchiveUtc = part.ScheduledArchiveUtc.Value;
|
||||||
if (model.ArchiveLater) {
|
model.ArchiveLater = model.ScheduledArchiveUtc.HasValue;
|
||||||
|
model.ScheduledArchiveDate = model.ScheduledArchiveUtc.HasValue ? model.ScheduledArchiveUtc.Value.ToLocalTime().ToShortDateString() : String.Empty;
|
||||||
|
model.ScheduledArchiveTime = model.ScheduledArchiveUtc.HasValue ? model.ScheduledArchiveUtc.Value.ToLocalTime().ToShortTimeString() : String.Empty;
|
||||||
|
|
||||||
|
return ContentShape("Parts_ArchiveLater_Edit",
|
||||||
|
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DriverResult Editor(ArchiveLaterPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||||
|
var model = new ArchiveLaterViewModel(part);
|
||||||
|
|
||||||
|
if (updater.TryUpdateModel(model, Prefix, null, null) ) {
|
||||||
|
if ( model.ArchiveLater ) {
|
||||||
DateTime scheduled;
|
DateTime scheduled;
|
||||||
if (DateTime.TryParse(string.Format("{0} {1}", model.ScheduledArchiveDate, model.ScheduledArchiveTime), out scheduled))
|
if ( DateTime.TryParse(string.Format("{0} {1}", model.ScheduledArchiveDate, model.ScheduledArchiveTime), out scheduled) )
|
||||||
model.ScheduledArchiveUtc = scheduled.ToUniversalTime();
|
model.ScheduledArchiveUtc = scheduled.ToUniversalTime();
|
||||||
_archiveLaterService.ArchiveLater(model.ContentItem, model.ScheduledArchiveUtc.HasValue ? model.ScheduledArchiveUtc.Value : DateTime.MaxValue);
|
_archiveLaterService.ArchiveLater(model.ContentItem, model.ScheduledArchiveUtc.HasValue ? model.ScheduledArchiveUtc.Value : DateTime.MaxValue);
|
||||||
}
|
}
|
||||||
@@ -63,7 +64,7 @@ namespace ArchiveLater.Drivers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ContentShape("Parts_ArchiveLater_Edit",
|
return ContentShape("Parts_ArchiveLater_Edit",
|
||||||
() => shapeHelper.EditorTemplate(TemplateName: "Parts/ArchiveLater", Model: model, Prefix: Prefix));
|
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,4 +9,4 @@ Features:
|
|||||||
Orchard.ArchiveLater:
|
Orchard.ArchiveLater:
|
||||||
Description: Scheduled archiving.
|
Description: Scheduled archiving.
|
||||||
Category: Content
|
Category: Content
|
||||||
Dependencies: Common, Settings
|
Dependencies: Common, Settings, Orchard.jQuery
|
||||||
|
|||||||
@@ -21,7 +21,10 @@
|
|||||||
@Html.EditorFor(m => m.ScheduledArchiveTime)
|
@Html.EditorFor(m => m.ScheduledArchiveTime)
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<script type="text/javascript"> $(function () {
|
@using(Script.Foot()) {
|
||||||
|
<script type="text/javascript">
|
||||||
|
//<![CDATA[
|
||||||
|
$(function () {
|
||||||
//todo: (heskew) make a plugin
|
//todo: (heskew) make a plugin
|
||||||
$("label.forpicker").each(function () {
|
$("label.forpicker").each(function () {
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
@@ -34,6 +37,9 @@
|
|||||||
.blur(function () { var $this = $(this); setTimeout(function () { if (!$this.val()) { $this.addClass("hinted").val($this.data("hint")) } }, 300) });
|
.blur(function () { var $this = $(this); setTimeout(function () { if (!$this.val()) { $this.addClass("hinted").val($this.data("hint")) } }, 300) });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$(@string.Format("\"#{0}\"", ViewData.TemplateInfo.GetFullHtmlFieldId("ScheduledArchiveDate"))).datepicker({ showAnim: "" }).focus(function () { $(@string.Format("\"#{0}\"", ViewData.TemplateInfo.GetFullHtmlFieldId("Command_ArchiveLater"))).attr("checked", "checked") });
|
$('#@ViewData.TemplateInfo.GetFullHtmlFieldId("ScheduledArchiveDate")').datepicker({ showAnim: "" }).focus(function () { $('#@ViewData.TemplateInfo.GetFullHtmlFieldId("Command_ArchiveLater")').attr("checked", "checked") });
|
||||||
$(@string.Format("\"#{0}\"", ViewData.TemplateInfo.GetFullHtmlFieldId("ScheduledArchiveTime"))).timepickr().focus(function () { $(@string.Format("\"#{0}\"", ViewData.TemplateInfo.GetFullHtmlFieldId("Command_ArchiveLater"))).attr("checked", "checked") });
|
$('#@ViewData.TemplateInfo.GetFullHtmlFieldId("ScheduledArchiveTime")').timepickr().focus(function () { $('#@ViewData.TemplateInfo.GetFullHtmlFieldId("Command_ArchiveLater")').attr("checked", "checked") });
|
||||||
})</script>
|
})
|
||||||
|
//]]>
|
||||||
|
</script>
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user