protected override DriverResult Editor(PublishLaterPart part, dynamic shapeHelper) { var model = new PublishLaterViewModel(part) { Editor = new DateTimeEditor() { ShowDate = true, ShowTime = true, Date = !part.IsPublished() ? _dateServices.ConvertToLocalDateString(part.ScheduledPublishUtc.Value, "") : "", Time = !part.IsPublished() ? _dateServices.ConvertToLocalTimeString(part.ScheduledPublishUtc.Value, "") : "", } }; return(ContentShape("Parts_PublishLater_Edit", () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix))); }
protected override DriverResult Editor(ArchiveLaterPart part, dynamic shapeHelper) { var model = new ArchiveLaterViewModel(part) { ArchiveLater = part.ScheduledArchiveUtc.Value.HasValue, Editor = new DateTimeEditor() { ShowDate = true, ShowTime = true, Date = _dateServices.ConvertToLocalDateString(part.ScheduledArchiveUtc.Value, ""), Time = _dateServices.ConvertToLocalTimeString(part.ScheduledArchiveUtc.Value, ""), } }; return(ContentShape("Parts_ArchiveLater_Edit", () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix))); }
protected override DriverResult Editor(CommonPart part, IUpdateModel updater, dynamic shapeHelper) { var settings = part.TypePartDefinition.Settings.GetModel <DateEditorSettings>(); if (!settings.ShowDateEditor) { return(null); } return(ContentShape( "Parts_Common_Date_Edit", () => { DateEditorViewModel model = shapeHelper.Parts_Common_Date_Edit(typeof(DateEditorViewModel)); model.Editor = new DateTimeEditor() { ShowDate = true, ShowTime = true }; if (part.CreatedUtc != null) { // show CreatedUtc only if is has been "touched", // i.e. it has been published once, or CreatedUtc has been set var itemHasNeverBeenPublished = part.PublishedUtc == null; var thisIsTheInitialVersionRecord = part.ContentItem.Version < 2; var theDatesHaveNotBeenModified = part.CreatedUtc == part.VersionCreatedUtc; var theEditorShouldBeBlank = itemHasNeverBeenPublished && thisIsTheInitialVersionRecord && theDatesHaveNotBeenModified; if (!theEditorShouldBeBlank) { model.Editor.Date = _dateServices.ConvertToLocalDateString(part.CreatedUtc, ""); model.Editor.Time = _dateServices.ConvertToLocalTimeString(part.CreatedUtc, ""); } } if (updater != null) { updater.TryUpdateModel(model, Prefix, null, null); if (!String.IsNullOrWhiteSpace(model.Editor.Date) && !String.IsNullOrWhiteSpace(model.Editor.Time)) { try { var utcDateTime = _dateServices.ConvertFromLocalString(model.Editor.Date, model.Editor.Time); part.CreatedUtc = utcDateTime; part.VersionCreatedUtc = utcDateTime; } catch (FormatException) { updater.AddModelError(Prefix, T("'{0} {1}' could not be parsed as a valid date and time.", model.Editor.Date, model.Editor.Time)); } } else if (!String.IsNullOrWhiteSpace(model.Editor.Date) || !String.IsNullOrWhiteSpace(model.Editor.Time)) { updater.AddModelError(Prefix, T("Both the date and time need to be specified.")); } // Neither date/time part is specified => do nothing. } return model; })); }