mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
Refactoring OwnerEditor and DateEditor breakout
Splitting OwnerEditor and DateEditor settings apart. Breaking off any knowledge in the CommonPart of the OwnerEditor and DateEditor. Changed the settings to appear as TypePart definition instead of Type. Based the ViewModel on Shape instead of EditorTemplates. The goal of these changes is to illustrate how a 3rd party module would accomplish the same kind of ContentPart extension w/out changing core code. --HG-- branch : 1.x rename : src/Orchard.Web/Core/Common/Drivers/DateEditorPartDriver.cs => src/Orchard.Web/Core/Common/DateEditor/DateEditorDriver.cs rename : src/Orchard.Web/Core/Common/Handlers/DateEditorPartHandler.cs => src/Orchard.Web/Core/Common/DateEditor/DateEditorHandler.cs rename : src/Orchard.Web/Core/Common/Settings/CommonEditorsSettings.cs => src/Orchard.Web/Core/Common/DateEditor/DateEditorSettings.cs rename : src/Orchard.Web/Core/Common/Drivers/OwnerEditorPartDriver.cs => src/Orchard.Web/Core/Common/OwnerEditor/OwnerEditorDriver.cs rename : src/Orchard.Web/Core/Common/Settings/CommonEditorsSettings.cs => src/Orchard.Web/Core/Common/OwnerEditor/OwnerEditorSettings.cs rename : src/Orchard.Web/Core/Common/ViewModels/OwnerEditorViewModel.cs => src/Orchard.Web/Core/Common/OwnerEditor/OwnerEditorViewModel.cs rename : src/Orchard.Web/Core/Common/Views/DefinitionTemplates/CommonEditorsSettings.cshtml => src/Orchard.Web/Core/Common/Views/DefinitionTemplates/DateEditorSettings.cshtml rename : src/Orchard.Web/Core/Common/Views/DefinitionTemplates/CommonEditorsSettings.cshtml => src/Orchard.Web/Core/Common/Views/DefinitionTemplates/OwnerEditorSettings.cshtml rename : src/Orchard.Web/Core/Common/Views/EditorTemplates/Parts.Common.CreatedUtc.cshtml => src/Orchard.Web/Core/Common/Views/Parts.Common.Date.Edit.cshtml extra : transplant_source : %D1%21c%ACa%F0%0FO%A1%9A%88YS%1Bk9.%CB%04%08
This commit is contained in:
87
src/Orchard.Web/Core/Common/DateEditor/DateEditorDriver.cs
Normal file
87
src/Orchard.Web/Core/Common/DateEditor/DateEditorDriver.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Core.Common.DateEditor {
|
||||
public class DateEditorDriver : ContentPartDriver<CommonPart> {
|
||||
private const string DatePattern = "M/d/yyyy";
|
||||
private const string TimePattern = "h:mm:ss tt";
|
||||
|
||||
public DateEditorDriver(
|
||||
IOrchardServices services) {
|
||||
T = NullLocalizer.Instance;
|
||||
Services = services;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
public IOrchardServices Services { get; set; }
|
||||
|
||||
protected override string Prefix {
|
||||
get { return "DateEditor"; }
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(CommonPart part, dynamic shapeHelper) {
|
||||
return Editor(part, null, shapeHelper);
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
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 == false) {
|
||||
model.CreatedDate = part.CreatedUtc.Value.ToLocalTime().ToString(DatePattern, CultureInfo.InvariantCulture);
|
||||
model.CreatedTime = part.CreatedUtc.Value.ToLocalTime().ToString(TimePattern, CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
|
||||
if (updater != null) {
|
||||
updater.TryUpdateModel(model, Prefix, null, null);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(model.CreatedDate) && !string.IsNullOrWhiteSpace(model.CreatedTime)) {
|
||||
DateTime createdUtc;
|
||||
string parseDateTime = String.Concat(model.CreatedDate, " ", model.CreatedTime);
|
||||
|
||||
// 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 createdUtc)) {
|
||||
part.CreatedUtc = createdUtc.ToUniversalTime();
|
||||
}
|
||||
else {
|
||||
updater.AddModelError(Prefix, T("{0} is an invalid date and time", parseDateTime));
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(model.CreatedDate) || !string.IsNullOrWhiteSpace(model.CreatedTime)) {
|
||||
// only one part is specified
|
||||
updater.AddModelError(Prefix, T("Both the date and time need to be specified."));
|
||||
}
|
||||
|
||||
// none date/time part is specified => do nothing
|
||||
}
|
||||
|
||||
return model;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
26
src/Orchard.Web/Core/Common/DateEditor/DateEditorHandler.cs
Normal file
26
src/Orchard.Web/Core/Common/DateEditor/DateEditorHandler.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
|
||||
namespace Orchard.Core.Common.DateEditor {
|
||||
[UsedImplicitly]
|
||||
public class DateEditorHandler : ContentHandler {
|
||||
public DateEditorHandler() {
|
||||
OnPublished<CommonPart>((context, part) => {
|
||||
var settings = part.ContentItem.TypeDefinition.Settings.GetModel<DateEditorSettings>();
|
||||
if (!settings.ShowDateEditor) {
|
||||
return;
|
||||
}
|
||||
|
||||
var thisIsTheInitialVersionRecord = part.ContentItem.Version < 2;
|
||||
var theDatesHaveNotBeenModified = part.CreatedUtc == part.VersionCreatedUtc;
|
||||
var theContentDateShouldBeUpdated = thisIsTheInitialVersionRecord && theDatesHaveNotBeenModified;
|
||||
|
||||
if (theContentDateShouldBeUpdated) {
|
||||
// "touch" CreatedUtc in ContentItemRecord
|
||||
part.CreatedUtc = part.PublishedUtc;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
31
src/Orchard.Web/Core/Common/DateEditor/DateEditorSettings.cs
Normal file
31
src/Orchard.Web/Core/Common/DateEditor/DateEditorSettings.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Builders;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentManagement.ViewModels;
|
||||
|
||||
namespace Orchard.Core.Common.DateEditor {
|
||||
public class DateEditorSettings {
|
||||
public bool ShowDateEditor { get; set; }
|
||||
}
|
||||
|
||||
public class DateEditorSettingsEvents : ContentDefinitionEditorEventsBase {
|
||||
public override IEnumerable<TemplateViewModel> TypePartEditor(ContentTypePartDefinition definition) {
|
||||
if (definition.PartDefinition.Name == "CommonPart") {
|
||||
var model = definition.Settings.GetModel<DateEditorSettings>();
|
||||
yield return DefinitionTemplate(model);
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerable<TemplateViewModel> TypePartEditorUpdate(ContentTypePartDefinitionBuilder builder, IUpdateModel updateModel) {
|
||||
if (builder.Name == "CommonPart") {
|
||||
var model = new DateEditorSettings();
|
||||
if (updateModel.TryUpdateModel(model, "DateEditorSettings", null, null)) {
|
||||
builder.WithSetting("DateEditorSettings.ShowDateEditor", model.ShowDateEditor.ToString());
|
||||
}
|
||||
yield return DefinitionTemplate(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.Core.Common.DateEditor {
|
||||
public class DateEditorViewModel : Shape {
|
||||
public virtual string CreatedDate { get; set; }
|
||||
public virtual string CreatedTime { get; set; }
|
||||
}
|
||||
}
|
@@ -1,96 +0,0 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Common.Settings;
|
||||
using Orchard.Core.Common.ViewModels;
|
||||
using Orchard.Data;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Services;
|
||||
|
||||
namespace Orchard.Core.Common.Drivers {
|
||||
public class DateEditorPartDriver : ContentPartDriver<CommonPart> {
|
||||
private readonly IRepository<CommonPartVersionRecord> _commonPartVersionRecordRepository;
|
||||
private readonly IClock _clock;
|
||||
|
||||
private const string DatePattern = "M/d/yyyy";
|
||||
private const string TimePattern = "h:mm tt";
|
||||
|
||||
public DateEditorPartDriver(
|
||||
IOrchardServices services,
|
||||
IRepository<CommonPartVersionRecord> commonPartVersionRecordRepository,
|
||||
IClock clock) {
|
||||
_commonPartVersionRecordRepository = commonPartVersionRecordRepository;
|
||||
_clock = clock;
|
||||
T = NullLocalizer.Instance;
|
||||
Services = services;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
public IOrchardServices Services { get; set; }
|
||||
|
||||
protected override string Prefix {
|
||||
get { return "DateEditorPart"; }
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(CommonPart part, dynamic shapeHelper) {
|
||||
return Editor(part, null, shapeHelper);
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(CommonPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
|
||||
var commonEditorsSettings = CommonEditorsSettings.Get(part.ContentItem);
|
||||
if(!commonEditorsSettings.ShowDateEditor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// this event is hooked so the modified timestamp is changed when an edit-post occurs
|
||||
part.Record.ModifiedUtc = _clock.UtcNow;
|
||||
|
||||
var model = new CreatedUtcEditorViewModel();
|
||||
|
||||
if (part.CreatedUtc != null) {
|
||||
// fetch CommonPartVersionRecord of first version
|
||||
var firstVersion = _commonPartVersionRecordRepository.Fetch(
|
||||
civr => civr.ContentItemRecord == part.ContentItem.Record,
|
||||
order => order.Asc(record => record.ContentItemVersionRecord.Number),
|
||||
0, 1).FirstOrDefault();
|
||||
|
||||
// show CreatedUtc only if is has been "touched",
|
||||
// i.e. it has been published once, or CreatedUtc has been set
|
||||
if (firstVersion != null && firstVersion.CreatedUtc != part.CreatedUtc) {
|
||||
model.CreatedDate = part.CreatedUtc.Value.ToLocalTime().ToString(DatePattern, CultureInfo.InvariantCulture);
|
||||
model.CreatedTime = part.CreatedUtc.Value.ToLocalTime().ToString(TimePattern, CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
|
||||
if (updater != null) {
|
||||
updater.TryUpdateModel(model, Prefix, null, null);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(model.CreatedDate) && !string.IsNullOrWhiteSpace(model.CreatedTime)) {
|
||||
DateTime createdUtc;
|
||||
string parseDateTime = String.Concat(model.CreatedDate, " ", model.CreatedTime);
|
||||
|
||||
// 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 createdUtc)) {
|
||||
part.CreatedUtc = createdUtc.ToUniversalTime();
|
||||
}
|
||||
else {
|
||||
updater.AddModelError(Prefix, T("{0} is an invalid date and time", parseDateTime));
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(model.CreatedDate) || !string.IsNullOrWhiteSpace(model.CreatedTime)) {
|
||||
// only one part is specified
|
||||
updater.AddModelError(Prefix, T("Both the date and time need to be specified."));
|
||||
}
|
||||
|
||||
// none date/time part is specified => do nothing
|
||||
}
|
||||
|
||||
return ContentShape("Parts_Common_CreatedUtc_Edit",
|
||||
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Common.CreatedUtc", Model: model, Prefix: Prefix));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
@@ -37,16 +38,15 @@ namespace Orchard.Core.Common.Handlers {
|
||||
OnActivated<CommonPart>(PropertySetHandlers);
|
||||
OnInitializing<CommonPart>(AssignCreatingOwner);
|
||||
OnInitializing<CommonPart>(AssignCreatingDates);
|
||||
OnInitializing<ContentPart<CommonPartVersionRecord>>(AssignCreatingDates);
|
||||
|
||||
OnLoading<CommonPart>((context, part) => LazyLoadHandlers(part));
|
||||
OnVersioning<CommonPart>((context, part, newVersionPart) => LazyLoadHandlers(newVersionPart));
|
||||
|
||||
OnVersioned<CommonPart>(AssignVersioningDates);
|
||||
OnVersioned<ContentPart<CommonPartVersionRecord>>(AssignVersioningDates);
|
||||
OnUpdateEditorShape<CommonPart>(AssignUpdateDates);
|
||||
|
||||
OnVersioning<CommonPart>(AssignVersioningDates);
|
||||
|
||||
OnPublishing<CommonPart>(AssignPublishingDates);
|
||||
OnPublishing<ContentPart<CommonPartVersionRecord>>(AssignPublishingDates);
|
||||
|
||||
OnIndexing<CommonPart>((context, commonPart) => context.DocumentIndex
|
||||
.Add("type", commonPart.ContentItem.ContentType).Analyze().Store()
|
||||
@@ -57,6 +57,7 @@ namespace Orchard.Core.Common.Handlers {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
protected override void Activating(ActivatingContentContext context) {
|
||||
@@ -83,42 +84,42 @@ namespace Orchard.Core.Common.Handlers {
|
||||
|
||||
protected void AssignCreatingDates(InitializingContentContext context, CommonPart part) {
|
||||
// assign default create/modified dates
|
||||
part.CreatedUtc = _clock.UtcNow;
|
||||
part.ModifiedUtc = _clock.UtcNow;
|
||||
var utcNow = _clock.UtcNow;
|
||||
part.CreatedUtc = utcNow;
|
||||
part.ModifiedUtc = utcNow;
|
||||
part.VersionCreatedUtc = utcNow;
|
||||
part.VersionModifiedUtc = utcNow;
|
||||
}
|
||||
|
||||
protected void AssignCreatingDates(InitializingContentContext context, ContentPart<CommonPartVersionRecord> part) {
|
||||
// assign default create/modified dates
|
||||
part.Record.CreatedUtc = _clock.UtcNow;
|
||||
part.Record.ModifiedUtc = _clock.UtcNow;
|
||||
private void AssignUpdateDates(UpdateEditorContext context, CommonPart part) {
|
||||
var utcNow = _clock.UtcNow;
|
||||
part.ModifiedUtc = utcNow;
|
||||
part.VersionModifiedUtc = utcNow;
|
||||
}
|
||||
|
||||
protected void AssignVersioningDates(VersionContentContext context, CommonPart existing, CommonPart building) {
|
||||
var utcNow = _clock.UtcNow;
|
||||
|
||||
// assign the created date
|
||||
building.VersionCreatedUtc = utcNow;
|
||||
// assign modified date for the new version
|
||||
building.VersionModifiedUtc = utcNow;
|
||||
// publish date should be null until publish method called
|
||||
building.VersionPublishedUtc = null;
|
||||
|
||||
// assign the created
|
||||
building.CreatedUtc = existing.CreatedUtc ?? _clock.UtcNow;
|
||||
// persist and published dates
|
||||
// persist any published dates
|
||||
building.PublishedUtc = existing.PublishedUtc;
|
||||
// assign modified date for the new version
|
||||
building.ModifiedUtc = _clock.UtcNow;
|
||||
}
|
||||
|
||||
protected void AssignVersioningDates(VersionContentContext context, ContentPart<CommonPartVersionRecord> existing, ContentPart<CommonPartVersionRecord> building) {
|
||||
// assign the created date
|
||||
building.Record.CreatedUtc = _clock.UtcNow;
|
||||
// assign modified date for the new version
|
||||
building.Record.ModifiedUtc = _clock.UtcNow;
|
||||
// publish date should be null until publish method called
|
||||
building.Record.PublishedUtc = null;
|
||||
}
|
||||
|
||||
protected void AssignPublishingDates(PublishContentContext context, CommonPart part) {
|
||||
// The non-versioned publish date is always the last publish date
|
||||
part.PublishedUtc = _clock.UtcNow;
|
||||
}
|
||||
|
||||
protected void AssignPublishingDates(PublishContentContext context, ContentPart<CommonPartVersionRecord> part) {
|
||||
// assign the version's published date
|
||||
part.Record.PublishedUtc = _clock.UtcNow;
|
||||
var utcNow = _clock.UtcNow;
|
||||
part.PublishedUtc = utcNow;
|
||||
part.VersionPublishedUtc = utcNow;
|
||||
}
|
||||
|
||||
protected void LazyLoadHandlers(CommonPart part) {
|
||||
|
@@ -1,43 +0,0 @@
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Common.Settings;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Services;
|
||||
|
||||
namespace Orchard.Core.Common.Handlers {
|
||||
[UsedImplicitly]
|
||||
public class DateEditorPartHandler : ContentHandler {
|
||||
private readonly IRepository<CommonPartVersionRecord> _commonPartVersionRepository;
|
||||
private readonly IClock _clock;
|
||||
|
||||
public DateEditorPartHandler(
|
||||
IRepository<CommonPartVersionRecord> commonPartVersionRepository,
|
||||
IClock clock) {
|
||||
_commonPartVersionRepository = commonPartVersionRepository;
|
||||
_clock = clock;
|
||||
|
||||
OnPublished<CommonPart>(AssignCreatingDates);
|
||||
|
||||
}
|
||||
|
||||
protected void AssignCreatingDates(PublishContentContext context, CommonPart part) {
|
||||
var commonEditorsSettings = CommonEditorsSettings.Get(part.ContentItem);
|
||||
if (!commonEditorsSettings.ShowDateEditor) {
|
||||
return;
|
||||
}
|
||||
|
||||
// fetch CommonPartVersionRecord of first version
|
||||
var firstVersion = _commonPartVersionRepository.Fetch(
|
||||
civr => civr.ContentItemRecord == part.ContentItem.Record,
|
||||
order => order.Asc(record => record.ContentItemVersionRecord.Number),
|
||||
0, 1).FirstOrDefault();
|
||||
|
||||
if (firstVersion != null && firstVersion.CreatedUtc == part.CreatedUtc) {
|
||||
// "touch" CreatedUtc in ContentItemRecord
|
||||
part.Record.CreatedUtc = _clock.UtcNow;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,18 +1,16 @@
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Common.Settings;
|
||||
using Orchard.Core.Common.ViewModels;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Security;
|
||||
|
||||
namespace Orchard.Core.Common.Drivers {
|
||||
public class OwnerEditorPartDriver : ContentPartDriver<CommonPart> {
|
||||
namespace Orchard.Core.Common.OwnerEditor {
|
||||
public class OwnerEditorDriver : ContentPartDriver<CommonPart> {
|
||||
private readonly IAuthenticationService _authenticationService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IMembershipService _membershipService;
|
||||
|
||||
public OwnerEditorPartDriver(
|
||||
public OwnerEditorDriver(
|
||||
IOrchardServices services,
|
||||
IAuthenticationService authenticationService,
|
||||
IAuthorizationService authorizationService,
|
||||
@@ -28,7 +26,7 @@ namespace Orchard.Core.Common.Drivers {
|
||||
public IOrchardServices Services { get; set; }
|
||||
|
||||
protected override string Prefix {
|
||||
get { return "OwnerEditorPart"; }
|
||||
get { return "OwnerEditor"; }
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(CommonPart part, dynamic shapeHelper) {
|
||||
@@ -41,31 +39,36 @@ namespace Orchard.Core.Common.Drivers {
|
||||
return null;
|
||||
}
|
||||
|
||||
var commonEditorsSettings = CommonEditorsSettings.Get(part.ContentItem);
|
||||
if (!commonEditorsSettings.ShowOwnerEditor) {
|
||||
var settings = part.TypePartDefinition.Settings.GetModel<OwnerEditorSettings>();
|
||||
if (!settings.ShowOwnerEditor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var model = new OwnerEditorViewModel();
|
||||
if (part.Owner != null)
|
||||
model.Owner = part.Owner.UserName;
|
||||
return ContentShape(
|
||||
"Parts_Common_Owner_Edit",
|
||||
() => {
|
||||
OwnerEditorViewModel model = shapeHelper.Parts_Common_Owner_Edit(typeof(OwnerEditorViewModel));
|
||||
|
||||
if (updater != null) {
|
||||
var priorOwner = model.Owner;
|
||||
updater.TryUpdateModel(model, Prefix, null, null);
|
||||
|
||||
if (model.Owner != null && model.Owner != priorOwner) {
|
||||
var newOwner = _membershipService.GetUser(model.Owner);
|
||||
if (newOwner == null) {
|
||||
updater.AddModelError("CommonPart.Owner", T("Invalid user name"));
|
||||
} else {
|
||||
part.Owner = newOwner;
|
||||
if (part.Owner != null) {
|
||||
model.Owner = part.Owner.UserName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ContentShape("Parts_Common_Owner_Edit",
|
||||
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Common.Owner", Model: model, Prefix: Prefix));
|
||||
if (updater != null) {
|
||||
var priorOwner = model.Owner;
|
||||
updater.TryUpdateModel(model, Prefix, null, null);
|
||||
|
||||
if (model.Owner != null && model.Owner != priorOwner) {
|
||||
var newOwner = _membershipService.GetUser(model.Owner);
|
||||
if (newOwner == null) {
|
||||
updater.AddModelError("OwnerEditor.Owner", T("Invalid user name"));
|
||||
}
|
||||
else {
|
||||
part.Owner = newOwner;
|
||||
}
|
||||
}
|
||||
}
|
||||
return model;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Builders;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentManagement.ViewModels;
|
||||
|
||||
namespace Orchard.Core.Common.OwnerEditor {
|
||||
public class OwnerEditorSettings {
|
||||
public bool ShowOwnerEditor { get; set; }
|
||||
}
|
||||
|
||||
public class OwnerEditorSettingsEvents : ContentDefinitionEditorEventsBase {
|
||||
public override IEnumerable<TemplateViewModel> TypePartEditor(ContentTypePartDefinition definition) {
|
||||
if (definition.PartDefinition.Name == "CommonPart") {
|
||||
var model = definition.Settings.GetModel<OwnerEditorSettings>();
|
||||
yield return DefinitionTemplate(model);
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerable<TemplateViewModel> TypePartEditorUpdate(ContentTypePartDefinitionBuilder builder, IUpdateModel upOwnerModel) {
|
||||
if (builder.Name == "CommonPart") {
|
||||
var model = new OwnerEditorSettings();
|
||||
if (upOwnerModel.TryUpdateModel(model, "OwnerEditorSettings", null, null)) {
|
||||
builder.WithSetting("OwnerEditorSettings.ShowOwnerEditor", model.ShowOwnerEditor.ToString());
|
||||
}
|
||||
yield return DefinitionTemplate(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.Core.Common.OwnerEditor {
|
||||
public class OwnerEditorViewModel : Shape {
|
||||
[Required]
|
||||
public string Owner { get; set; }
|
||||
}
|
||||
}
|
@@ -12,7 +12,7 @@
|
||||
<!-- edit "shape" -->
|
||||
<Place Parts_Common_Body_Edit="Content:2"/>
|
||||
<Place Parts_Common_Owner_Edit="Content:20"/>
|
||||
<Place Parts_Common_CreatedUtc_Edit="Content:18"/>
|
||||
<Place Parts_Common_Date_Edit="Content:18"/>
|
||||
<Place Parts_Common_Container_Edit="Content:20"/>
|
||||
<Place Fields_Common_Text_Edit="Content:2.5"/>
|
||||
<!-- default positioning -->
|
||||
|
@@ -1,52 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Builders;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentManagement.ViewModels;
|
||||
using Orchard.Core.Common.Models;
|
||||
|
||||
namespace Orchard.Core.Common.Settings {
|
||||
public class CommonEditorsSettings {
|
||||
public CommonEditorsSettings() {
|
||||
// defaults
|
||||
ShowOwnerEditor = true;
|
||||
ShowDateEditor = false;
|
||||
}
|
||||
|
||||
public bool ShowDateEditor { get; set; }
|
||||
public bool ShowOwnerEditor { get; set; }
|
||||
|
||||
public static CommonEditorsSettings Get(ContentItem contentItem) {
|
||||
if (contentItem == null ||
|
||||
contentItem.TypeDefinition == null ||
|
||||
contentItem.TypeDefinition.Settings == null) {
|
||||
return new CommonEditorsSettings();
|
||||
}
|
||||
return contentItem.TypeDefinition.Settings.GetModel<CommonEditorsSettings>();
|
||||
}
|
||||
}
|
||||
|
||||
public class CommonEditorsEvents : ContentDefinitionEditorEventsBase {
|
||||
public override IEnumerable<TemplateViewModel> TypeEditor(ContentTypeDefinition definition) {
|
||||
if (!definition.Parts.Any(part => part.PartDefinition.Name == typeof(CommonPart).Name)) {
|
||||
yield break;
|
||||
}
|
||||
|
||||
var model = definition.Settings.GetModel<CommonEditorsSettings>();
|
||||
yield return DefinitionTemplate(model);
|
||||
}
|
||||
|
||||
public override IEnumerable<TemplateViewModel> TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) {
|
||||
var model = new CommonEditorsSettings();
|
||||
updateModel.TryUpdateModel(model, "CommonEditorsSettings", null, null);
|
||||
|
||||
builder.WithSetting("CommonEditorsSettings.ShowDateEditor", model.ShowDateEditor.ToString());
|
||||
builder.WithSetting("CommonEditorsSettings.ShowOwnerEditor", model.ShowOwnerEditor.ToString());
|
||||
|
||||
yield return DefinitionTemplate(model);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
namespace Orchard.Core.Common.ViewModels {
|
||||
public class CreatedUtcEditorViewModel {
|
||||
public string CreatedDate { get; set; }
|
||||
public string CreatedTime { get; set; }
|
||||
}
|
||||
}
|
@@ -1,8 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Orchard.Core.Common.ViewModels {
|
||||
public class OwnerEditorViewModel {
|
||||
[Required]
|
||||
public string Owner { get; set; }
|
||||
}
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
@model Orchard.Core.Common.Settings.CommonEditorsSettings
|
||||
|
||||
<fieldset>
|
||||
<div>
|
||||
@Html.EditorFor(m=>m.ShowDateEditor)
|
||||
<label for="@Html.FieldIdFor(m => m.ShowDateEditor)" class="forcheckbox">@T("Show editor for creation date time")</label>
|
||||
@Html.ValidationMessageFor(m => m.ShowDateEditor)
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@Html.EditorFor(m=>m.ShowOwnerEditor)
|
||||
<label for="@Html.FieldIdFor(m => m.ShowOwnerEditor)" class="forcheckbox">@T("Show editor for owner")</label>
|
||||
@Html.ValidationMessageFor(m => m.ShowOwnerEditor)
|
||||
</div>
|
||||
</fieldset>
|
@@ -0,0 +1,8 @@
|
||||
@model Orchard.Core.Common.DateEditor.DateEditorSettings
|
||||
<fieldset>
|
||||
<div>
|
||||
@Html.EditorFor(m=>m.ShowDateEditor)
|
||||
<label for="@Html.FieldIdFor(m => m.ShowDateEditor)" class="forcheckbox">@T("Show editor for creation date time")</label>
|
||||
@Html.ValidationMessageFor(m => m.ShowDateEditor)
|
||||
</div>
|
||||
</fieldset>
|
@@ -0,0 +1,9 @@
|
||||
@model Orchard.Core.Common.OwnerEditor.OwnerEditorSettings
|
||||
|
||||
<fieldset>
|
||||
<div>
|
||||
@Html.EditorFor(m=>m.ShowOwnerEditor)
|
||||
<label for="@Html.FieldIdFor(m => m.ShowOwnerEditor)" class="forcheckbox">@T("Show editor for owner")</label>
|
||||
@Html.ValidationMessageFor(m => m.ShowOwnerEditor)
|
||||
</div>
|
||||
</fieldset>
|
@@ -1,7 +0,0 @@
|
||||
@model OwnerEditorViewModel
|
||||
@using Orchard.Core.Common.ViewModels;
|
||||
<fieldset>
|
||||
@Html.LabelFor(m => m.Owner, T("Owner"))
|
||||
@Html.EditorFor(m=>m.Owner)
|
||||
@Html.ValidationMessageFor(m=>m.Owner)
|
||||
</fieldset>
|
@@ -1,6 +1,6 @@
|
||||
@model CreatedUtcEditorViewModel
|
||||
@using Orchard.Core.Common.ViewModels;
|
||||
@model Orchard.Core.Common.DateEditor.DateEditorViewModel;
|
||||
@{
|
||||
var DateEditor = Model;
|
||||
Script.Require("jQueryUtils_TimePicker");
|
||||
Script.Require("jQueryUI_DatePicker");
|
||||
Style.Require("Common_DatePicker");
|
||||
@@ -8,11 +8,11 @@
|
||||
Style.Require("jQueryUI_DatePicker");
|
||||
}
|
||||
<fieldset class="createdutc-datetime">
|
||||
@Html.LabelFor(m => m.CreatedDate, T("Created On"))
|
||||
<label class="forpicker" for="@ViewData.TemplateInfo.GetFullHtmlFieldId("CreatedDate")">@T("Date")</label>
|
||||
@Html.EditorFor(m => m.CreatedDate)
|
||||
<label class="forpicker" for="@ViewData.TemplateInfo.GetFullHtmlFieldId("CreatedTime")">@T("Time")</label>
|
||||
@Html.EditorFor(m => m.CreatedTime)
|
||||
@Html.LabelFor(m => DateEditor.CreatedDate, T("Created On"))
|
||||
<label class="forpicker" for="@Html.FieldIdFor(m => DateEditor.CreatedDate)">@T("Date")</label>
|
||||
@Html.EditorFor(m => DateEditor.CreatedDate)
|
||||
<label class="forpicker" for="@Html.FieldIdFor(m => DateEditor.CreatedTime)">@T("Time")</label>
|
||||
@Html.EditorFor(m => DateEditor.CreatedTime)
|
||||
</fieldset>
|
||||
@using(Script.Foot()) {
|
||||
<script type="text/javascript">
|
||||
@@ -33,8 +33,8 @@
|
||||
$this.closest("form").submit(function() {clearHint(pickerInput); pickerInput = 0;});
|
||||
}
|
||||
});
|
||||
$('#@ViewData.TemplateInfo.GetFullHtmlFieldId("CreatedDate")').datepicker({ showAnim: "" }).focus(function () { $('#@ViewData.TemplateInfo.GetFullHtmlFieldId("Command_Created")').attr("checked", "checked") });
|
||||
$('#@ViewData.TemplateInfo.GetFullHtmlFieldId("CreatedTime")').timepickr({ showAnim: "" }).focus(function () { $('#@ViewData.TemplateInfo.GetFullHtmlFieldId("Command_Created")').attr("checked", "checked") });
|
||||
$('#@Html.FieldIdFor(m => DateEditor.CreatedDate)').datepicker({ showAnim: "" });
|
||||
$('#@Html.FieldIdFor(m => DateEditor.CreatedTime)').timepickr({ showAnim: "" });
|
||||
})
|
||||
//]]>
|
||||
</script>
|
@@ -0,0 +1,9 @@
|
||||
@model Orchard.Core.Common.OwnerEditor.OwnerEditorViewModel;
|
||||
@{
|
||||
var OwnerEditor = Model;
|
||||
}
|
||||
<fieldset>
|
||||
@Html.LabelFor(m => OwnerEditor.Owner, T("Owner"))
|
||||
@Html.EditorFor(m => OwnerEditor.Owner)
|
||||
@Html.ValidationMessageFor(m => OwnerEditor.Owner)
|
||||
</fieldset>
|
@@ -62,18 +62,19 @@
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Common\Drivers\OwnerEditorPartDriver.cs" />
|
||||
<Compile Include="Common\Drivers\DateEditorPartDriver.cs" />
|
||||
<Compile Include="Common\DateEditor\DateEditorSettings.cs" />
|
||||
<Compile Include="Common\OwnerEditor\OwnerEditorSettings.cs" />
|
||||
<Compile Include="Common\OwnerEditor\OwnerEditorDriver.cs" />
|
||||
<Compile Include="Common\DateEditor\DateEditorDriver.cs" />
|
||||
<Compile Include="Common\Drivers\IdentityPartDriver.cs" />
|
||||
<Compile Include="Common\Handlers\DateEditorPartHandler.cs" />
|
||||
<Compile Include="Common\DateEditor\DateEditorHandler.cs" />
|
||||
<Compile Include="Common\Handlers\IdentityPartHandler.cs" />
|
||||
<Compile Include="Common\Models\CommonPartVersionRecord.cs" />
|
||||
<Compile Include="Common\Models\IdentityPartRecord.cs" />
|
||||
<Compile Include="Common\Models\IdentityPart.cs" />
|
||||
<Compile Include="Common\ResourceManifest.cs" />
|
||||
<Compile Include="Common\Services\XmlRpcHandler.cs" />
|
||||
<Compile Include="Common\Settings\CommonEditorsSettings.cs" />
|
||||
<Compile Include="Common\ViewModels\CreatedUtcEditorViewModel.cs" />
|
||||
<Compile Include="Common\DateEditor\DateEditorViewModel.cs" />
|
||||
<Compile Include="Containers\Controllers\ItemController.cs" />
|
||||
<Compile Include="Containers\Drivers\ContainablePartDriver.cs" />
|
||||
<Compile Include="Containers\Drivers\ContainerPartDriver.cs" />
|
||||
@@ -148,7 +149,7 @@
|
||||
<Compile Include="Common\Models\BodyPartRecord.cs" />
|
||||
<Compile Include="Common\Models\CommonPartRecord.cs" />
|
||||
<Compile Include="Common\ViewModels\BodyEditorViewModel.cs" />
|
||||
<Compile Include="Common\ViewModels\OwnerEditorViewModel.cs" />
|
||||
<Compile Include="Common\OwnerEditor\OwnerEditorViewModel.cs" />
|
||||
<Compile Include="Contents\AdminMenu.cs" />
|
||||
<Compile Include="Contents\Controllers\AdminController.cs" />
|
||||
<Compile Include="Dashboard\AdminMenu.cs" />
|
||||
@@ -328,7 +329,7 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Common\Views\Parts.Common.Body.cshtml" />
|
||||
<Content Include="Common\Views\EditorTemplates\Parts.Common.Body.cshtml" />
|
||||
<Content Include="Common\Views\EditorTemplates\Parts.Common.Owner.cshtml" />
|
||||
<Content Include="Common\Views\Parts.Common.Owner.Edit.cshtml" />
|
||||
<Content Include="Feeds\Module.txt" />
|
||||
<Content Include="Navigation\Module.txt" />
|
||||
<Content Include="Scheduling\Module.txt" />
|
||||
@@ -435,7 +436,7 @@
|
||||
<Content Include="web.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Common\Views\EditorTemplates\Parts.Common.CreatedUtc.cshtml" />
|
||||
<Content Include="Common\Views\Parts.Common.Date.Edit.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Common\Styles\Web.config">
|
||||
@@ -443,7 +444,10 @@
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Common\Views\DefinitionTemplates\CommonEditorsSettings.cshtml" />
|
||||
<Content Include="Common\Views\DefinitionTemplates\DateEditorSettings.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Common\Views\DefinitionTemplates\OwnerEditorSettings.cshtml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||
|
Reference in New Issue
Block a user