mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-27 04:19:04 +08:00
Merge
--HG-- branch : 1.x
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Routing;
|
||||
@@ -17,6 +17,7 @@ using Orchard.Core.Common.Models;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Core.Common.OwnerEditor;
|
||||
using Orchard.Core.Common.Services;
|
||||
using Orchard.Core.Scheduling.Models;
|
||||
using Orchard.Core.Scheduling.Services;
|
||||
|
||||
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.TypePartDefinition.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,16 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Xml;
|
||||
using System.Xml;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Common.Settings;
|
||||
using Orchard.Core.Common.ViewModels;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Security;
|
||||
using Orchard.Services;
|
||||
|
||||
namespace Orchard.Core.Common.Drivers {
|
||||
public class CommonPartDriver : ContentPartDriver<CommonPart> {
|
||||
@@ -18,23 +13,17 @@ namespace Orchard.Core.Common.Drivers {
|
||||
private readonly IAuthenticationService _authenticationService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IMembershipService _membershipService;
|
||||
private readonly IClock _clock;
|
||||
|
||||
private const string DatePattern = "M/d/yyyy";
|
||||
private const string TimePattern = "h:mm tt";
|
||||
|
||||
public CommonPartDriver(
|
||||
IOrchardServices services,
|
||||
IContentManager contentManager,
|
||||
IAuthenticationService authenticationService,
|
||||
IAuthorizationService authorizationService,
|
||||
IMembershipService membershipService,
|
||||
IClock clock) {
|
||||
IMembershipService membershipService) {
|
||||
_contentManager = contentManager;
|
||||
_authenticationService = authenticationService;
|
||||
_authorizationService = authorizationService;
|
||||
_membershipService = membershipService;
|
||||
_clock = clock;
|
||||
T = NullLocalizer.Instance;
|
||||
Services = services;
|
||||
}
|
||||
@@ -58,95 +47,10 @@ namespace Orchard.Core.Common.Drivers {
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(CommonPart part, dynamic shapeHelper) {
|
||||
return BuildEditor(part, null, shapeHelper);
|
||||
return Editor(part, null, shapeHelper);
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(CommonPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
// this event is hooked so the modified timestamp is changed when an edit-post occurs
|
||||
part.ModifiedUtc = _clock.UtcNow;
|
||||
part.VersionModifiedUtc = _clock.UtcNow;
|
||||
|
||||
return BuildEditor(part, updater, shapeHelper);
|
||||
}
|
||||
|
||||
private DriverResult BuildEditor(CommonPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
List<DriverResult> parts = new List<DriverResult>();
|
||||
CommonTypePartSettings commonTypePartSettings = GetTypeSettings(part);
|
||||
|
||||
if (commonTypePartSettings.ShowOwnerEditor) {
|
||||
parts.Add(OwnerEditor(part, updater, shapeHelper));
|
||||
}
|
||||
|
||||
if (commonTypePartSettings.ShowCreatedUtcEditor) {
|
||||
parts.Add(CreatedUtcEditor(part, updater, shapeHelper));
|
||||
}
|
||||
|
||||
parts.Add(ContainerEditor(part, updater, shapeHelper));
|
||||
|
||||
return Combined(parts.ToArray());
|
||||
}
|
||||
|
||||
DriverResult OwnerEditor(CommonPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
var currentUser = _authenticationService.GetAuthenticatedUser();
|
||||
if (!_authorizationService.TryCheckAccess(StandardPermissions.SiteOwner, currentUser, part)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var model = new OwnerEditorViewModel();
|
||||
if (part.Owner != null)
|
||||
model.Owner = part.Owner.UserName;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ContentShape("Parts_Common_Owner_Edit",
|
||||
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Common.Owner", Model: model, Prefix: Prefix));
|
||||
}
|
||||
|
||||
DriverResult CreatedUtcEditor(CommonPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
CreatedUtcEditorViewModel model = new CreatedUtcEditorViewModel();
|
||||
if (part.CreatedUtc != null) {
|
||||
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 {
|
||||
updater.AddModelError(Prefix, T("Both the date and time need to be specified."));
|
||||
}
|
||||
}
|
||||
|
||||
return ContentShape("Parts_Common_CreatedUtc_Edit",
|
||||
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Common.CreatedUtc", Model: model, Prefix: Prefix));
|
||||
}
|
||||
|
||||
DriverResult ContainerEditor(CommonPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
var currentUser = _authenticationService.GetAuthenticatedUser();
|
||||
if (!_authorizationService.TryCheckAccess(StandardPermissions.SiteOwner, currentUser, part)) {
|
||||
return null;
|
||||
@@ -164,8 +68,7 @@ namespace Orchard.Core.Common.Drivers {
|
||||
var newContainer = _contentManager.Get((int)model.ContainerId, VersionOptions.Latest);
|
||||
if (newContainer == null) {
|
||||
updater.AddModelError("CommonPart.ContainerId", T("Invalid container"));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
part.Container = newContainer;
|
||||
}
|
||||
}
|
||||
@@ -175,10 +78,6 @@ namespace Orchard.Core.Common.Drivers {
|
||||
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Common.Container", Model: model, Prefix: Prefix));
|
||||
}
|
||||
|
||||
private static CommonTypePartSettings GetTypeSettings(CommonPart part) {
|
||||
return part.Settings.GetModel<CommonTypePartSettings>();
|
||||
}
|
||||
|
||||
protected override void Importing(CommonPart part, ImportContentContext context) {
|
||||
var owner = context.Attribute(part.PartDefinition.Name, "Owner");
|
||||
if (owner != null) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
74
src/Orchard.Web/Core/Common/OwnerEditor/OwnerEditorDriver.cs
Normal file
74
src/Orchard.Web/Core/Common/OwnerEditor/OwnerEditorDriver.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Security;
|
||||
|
||||
namespace Orchard.Core.Common.OwnerEditor {
|
||||
public class OwnerEditorDriver : ContentPartDriver<CommonPart> {
|
||||
private readonly IAuthenticationService _authenticationService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IMembershipService _membershipService;
|
||||
|
||||
public OwnerEditorDriver(
|
||||
IOrchardServices services,
|
||||
IAuthenticationService authenticationService,
|
||||
IAuthorizationService authorizationService,
|
||||
IMembershipService membershipService) {
|
||||
_authenticationService = authenticationService;
|
||||
_authorizationService = authorizationService;
|
||||
_membershipService = membershipService;
|
||||
T = NullLocalizer.Instance;
|
||||
Services = services;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
public IOrchardServices Services { get; set; }
|
||||
|
||||
protected override string Prefix {
|
||||
get { return "OwnerEditor"; }
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(CommonPart part, dynamic shapeHelper) {
|
||||
return Editor(part, null, shapeHelper);
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(CommonPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
var currentUser = _authenticationService.GetAuthenticatedUser();
|
||||
if (!_authorizationService.TryCheckAccess(StandardPermissions.SiteOwner, currentUser, part)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var settings = part.TypePartDefinition.Settings.GetModel<OwnerEditorSettings>();
|
||||
if (!settings.ShowOwnerEditor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ContentShape(
|
||||
"Parts_Common_Owner_Edit",
|
||||
() => {
|
||||
OwnerEditorViewModel model = shapeHelper.Parts_Common_Owner_Edit(typeof(OwnerEditorViewModel));
|
||||
|
||||
if (part.Owner != null) {
|
||||
model.Owner = part.Owner.UserName;
|
||||
}
|
||||
|
||||
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,37 @@
|
||||
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 OwnerEditorSettings() {
|
||||
// owner editor should is displayed by default
|
||||
ShowOwnerEditor = true;
|
||||
}
|
||||
|
||||
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,38 +0,0 @@
|
||||
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.Settings {
|
||||
public class CommonTypePartSettings {
|
||||
public CommonTypePartSettings() {
|
||||
ShowOwnerEditor = true;
|
||||
}
|
||||
|
||||
public bool ShowCreatedUtcEditor { get; set; }
|
||||
public bool ShowOwnerEditor { get; set; }
|
||||
}
|
||||
|
||||
public class CommonSettingsHooks : ContentDefinitionEditorEventsBase {
|
||||
public override IEnumerable<TemplateViewModel> TypePartEditor(ContentTypePartDefinition definition) {
|
||||
if (definition.PartDefinition.Name != "CommonPart")
|
||||
yield break;
|
||||
|
||||
var model = definition.Settings.GetModel<CommonTypePartSettings>();
|
||||
yield return DefinitionTemplate(model);
|
||||
}
|
||||
|
||||
public override IEnumerable<TemplateViewModel> TypePartEditorUpdate(ContentTypePartDefinitionBuilder builder, IUpdateModel updateModel) {
|
||||
if (builder.Name != "CommonPart")
|
||||
yield break;
|
||||
|
||||
var model = new CommonTypePartSettings();
|
||||
updateModel.TryUpdateModel(model, "CommonTypePartSettings", null, null);
|
||||
builder.WithSetting("CommonTypePartSettings.ShowCreatedUtcEditor", model.ShowCreatedUtcEditor.ToString());
|
||||
builder.WithSetting("CommonTypePartSettings.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,12 +0,0 @@
|
||||
@model Orchard.Core.Common.Settings.CommonTypePartSettings
|
||||
<fieldset>
|
||||
@Html.CheckBoxFor(m => m.ShowCreatedUtcEditor)
|
||||
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.ShowCreatedUtcEditor)">@T("Show editor for creation date time")</label>
|
||||
@Html.ValidationMessageFor(m => m.ShowCreatedUtcEditor)
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
@Html.CheckBoxFor(m => m.ShowOwnerEditor)
|
||||
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.ShowOwnerEditor)">@T("Show editor for owner")</label>
|
||||
@Html.ValidationMessageFor(m => m.ShowOwnerEditor)
|
||||
</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>
|
||||
@@ -115,12 +115,12 @@ namespace Orchard.Core.Containers.Drivers {
|
||||
Filters.Add(StorageFilter.For(repository));
|
||||
OnInitializing<ContainerPart>((context, part) => {
|
||||
part.Record.PageSize = part.Settings.GetModel<ContainerTypePartSettings>().PageSizeDefault
|
||||
?? part.PartDefinition.Settings.GetModel<ContainerPartSettings>().PageSizeDefault;
|
||||
?? part.PartDefinition.Settings.GetModel<ContainerPartSettings>().PageSizeDefault;
|
||||
part.Record.Paginated = part.Settings.GetModel<ContainerTypePartSettings>().PaginatedDefault
|
||||
?? part.PartDefinition.Settings.GetModel<ContainerPartSettings>().PaginatedDefault;
|
||||
?? part.PartDefinition.Settings.GetModel<ContainerPartSettings>().PaginatedDefault;
|
||||
|
||||
//hard-coded defaults for ordering
|
||||
part.Record.OrderByProperty = part.Is<CommonPart>() ? "CommonPart.PublishedUtc" : "";
|
||||
// hard-coded defaults for ordering
|
||||
part.Record.OrderByProperty = part.Is<CommonPart>() ? "CommonPart.CreatedUtc" : string.Empty;
|
||||
part.Record.OrderByDirection = (int)OrderByDirection.Descending;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ namespace Orchard.Core.Containers.Drivers {
|
||||
OnInitializing<ContainerWidgetPart>((context, part) => {
|
||||
part.Record.ContainerId = 0;
|
||||
part.Record.PageSize = 5;
|
||||
part.Record.OrderByProperty = part.Is<CommonPart>() ? "CommonPart.PublishedUtc" : "";
|
||||
part.Record.OrderByProperty = part.Is<CommonPart>() ? "CommonPart.CreatedUtc" : string.Empty;
|
||||
part.Record.OrderByDirection = (int)OrderByDirection.Descending;
|
||||
part.Record.FilterByProperty = "CustomPropertiesPart.CustomOne";
|
||||
part.Record.FilterByOperator = "=";
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<UpgradeBackupLocation />
|
||||
<TargetFrameworkProfile />
|
||||
<UseIISExpress>false</UseIISExpress>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -61,15 +62,19 @@
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<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\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\CommonSettings.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" />
|
||||
@@ -144,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" />
|
||||
@@ -325,7 +330,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" />
|
||||
@@ -432,16 +437,19 @@
|
||||
<Content Include="web.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Common\Views\DefinitionTemplates\CommonTypePartSettings.cshtml" />
|
||||
</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">
|
||||
<SubType>Designer</SubType>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<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" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
@@ -54,11 +54,15 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
ModelState.AddModelError("DisplayName", T("The Display Name name can't be empty.").ToString());
|
||||
}
|
||||
|
||||
if ( _contentDefinitionService.GetTypes().Any(t => String.Equals(t.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase)) ) {
|
||||
if (_contentDefinitionService.GetTypes().Any(t => String.Equals(t.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase))) {
|
||||
ModelState.AddModelError("Name", T("A type with the same Id already exists.").ToString());
|
||||
}
|
||||
|
||||
if ( _contentDefinitionService.GetTypes().Any(t => String.Equals(t.DisplayName.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase)) ) {
|
||||
if (!String.IsNullOrWhiteSpace(viewModel.Name) && !ContentDefinitionService.IsLetter(viewModel.Name[0])) {
|
||||
ModelState.AddModelError("Name", T("The technical name must start with a letter.").ToString());
|
||||
}
|
||||
|
||||
if (_contentDefinitionService.GetTypes().Any(t => String.Equals(t.DisplayName.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase))) {
|
||||
ModelState.AddModelError("DisplayName", T("A type with the same Name already exists.").ToString());
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,11 @@ namespace Orchard.ContentTypes.Services {
|
||||
if(String.IsNullOrWhiteSpace(name)) {
|
||||
name = GenerateContentTypeNameFromDisplayName(displayName);
|
||||
}
|
||||
else {
|
||||
if(!IsLetter(name[0])) {
|
||||
throw new ArgumentException("Content type name must start with a letter", "name");
|
||||
}
|
||||
}
|
||||
|
||||
while ( _contentDefinitionManager.GetTypeDefinition(name) != null )
|
||||
name = VersionName(name);
|
||||
@@ -235,11 +240,23 @@ namespace Orchard.ContentTypes.Services {
|
||||
name = dissallowed.Replace(name, String.Empty);
|
||||
name = name.Trim();
|
||||
|
||||
// don't allow non A-Z chars as first letter, as they are not allowed in prefixes
|
||||
if(name.Length > 0) {
|
||||
if (!IsLetter(name[0])) {
|
||||
name = name.Substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (name.Length > 128)
|
||||
name = name.Substring(0, 128);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public static bool IsLetter(char c) {
|
||||
return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
|
||||
}
|
||||
|
||||
//gratuitously stolen from the RoutableService
|
||||
public string GenerateContentTypeNameFromDisplayName(string displayName) {
|
||||
displayName = SafeName(displayName);
|
||||
|
||||
@@ -12,6 +12,9 @@ namespace Orchard.ContentManagement.MetaData.Services {
|
||||
|
||||
public XElement Export(ContentTypeDefinition typeDefinition) {
|
||||
var typeElement = NewElement(typeDefinition.Name, typeDefinition.Settings);
|
||||
if (typeElement.Attribute("DisplayName") == null && typeDefinition.DisplayName != null) {
|
||||
typeElement.Add(new XAttribute("DisplayName", typeDefinition.DisplayName));
|
||||
}
|
||||
|
||||
foreach(var typePart in typeDefinition.Parts) {
|
||||
typeElement.Add(NewElement(typePart.PartDefinition.Name, typePart.Settings));
|
||||
|
||||
Reference in New Issue
Block a user