mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 04:43:35 +08:00
Relocating some actions and forms to their parent module
--HG-- branch : 1.x
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
a68798a582e59af49b71eef4e3c87ac16201f888 src/Orchard.Web/Modules/Orchard.Forms
|
a68798a582e59af49b71eef4e3c87ac16201f888 src/Orchard.Web/Modules/Orchard.Forms
|
||||||
c489ef139826577d208574c5f87a3bf64566c4e8 src/Orchard.Web/Modules/Orchard.Rules
|
73e4207bde986aebe82f6fd5d942ee453c1adc9f src/Orchard.Web/Modules/Orchard.Rules
|
||||||
3d4e08a8d72d048af0dfee049d74ebf52a5054fa src/Orchard.Web/Modules/Orchard.TaskLease
|
3d4e08a8d72d048af0dfee049d74ebf52a5054fa src/Orchard.Web/Modules/Orchard.TaskLease
|
||||||
9f88379b8a6260362aff1f57de5e9e8c5e0f296f src/Orchard.Web/Modules/Orchard.Tokens
|
9f88379b8a6260362aff1f57de5e9e8c5e0f296f src/Orchard.Web/Modules/Orchard.Tokens
|
||||||
|
@@ -15,11 +15,6 @@ namespace Orchard.Core.Contents.Handlers {
|
|||||||
public class RulePartHandler : ContentHandler {
|
public class RulePartHandler : ContentHandler {
|
||||||
public RulePartHandler(IRulesManager rulesManager) {
|
public RulePartHandler(IRulesManager rulesManager) {
|
||||||
|
|
||||||
OnPublished<ContentPart>(
|
|
||||||
(context, part) =>
|
|
||||||
rulesManager.TriggerEvent("Content", "Published",
|
|
||||||
() => new Dictionary<string, object> { { "Content", context.ContentItem } }));
|
|
||||||
|
|
||||||
OnPublished<ContentPart>(
|
OnPublished<ContentPart>(
|
||||||
(context, part) =>
|
(context, part) =>
|
||||||
rulesManager.TriggerEvent("Content", "Published",
|
rulesManager.TriggerEvent("Content", "Published",
|
||||||
|
@@ -5,49 +5,43 @@ using Orchard.Events;
|
|||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
|
|
||||||
namespace Orchard.Comments.Rules
|
namespace Orchard.Comments.Rules {
|
||||||
{
|
public interface IActionProvider : IEventHandler {
|
||||||
public interface IActionProvider : IEventHandler
|
|
||||||
{
|
|
||||||
void Describe(dynamic describe);
|
void Describe(dynamic describe);
|
||||||
}
|
}
|
||||||
|
|
||||||
[OrchardFeature("Orchard.Comments.Rules")]
|
[OrchardFeature("Orchard.Comments.Rules")]
|
||||||
public class CommentsActions : IActionProvider
|
public class CommentsActions : IActionProvider {
|
||||||
{
|
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
|
|
||||||
public CommentsActions(IContentManager contentManager)
|
public CommentsActions(IContentManager contentManager) {
|
||||||
{
|
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
public void Describe(dynamic describe)
|
public void Describe(dynamic describe) {
|
||||||
{
|
|
||||||
Func<dynamic, LocalizedString> display = context => T("Close comments");
|
Func<dynamic, LocalizedString> display = context => T("Close comments");
|
||||||
|
|
||||||
describe.For("Comments", T("Comments"), T("Comments"))
|
describe.For("Comments", T("Comments"), T("Comments"))
|
||||||
.Element("Close", T("Close Comments"), T("Closes comments on a content item."), (Action<dynamic>) Close, display, "ActionCloseComments");
|
.Element("Close", T("Close Comments"), T("Closes comments on a content item."), (Func<dynamic, bool>)Close, display, "ActionCloseComments");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Closes the comments on the content represented by "ContentId"
|
/// Closes the comments on the content represented by "ContentId"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Close(dynamic context)
|
private bool Close(dynamic context) {
|
||||||
{
|
|
||||||
var contentId = Convert.ToInt32(context.Properties["ContentId"]);
|
var contentId = Convert.ToInt32(context.Properties["ContentId"]);
|
||||||
var content = _contentManager.Get(contentId);
|
var content = _contentManager.Get(contentId);
|
||||||
|
|
||||||
if (content != null)
|
if (content != null) {
|
||||||
{
|
|
||||||
var comments = content.As<CommentsPart>();
|
var comments = content.As<CommentsPart>();
|
||||||
if (comments != null)
|
if (comments != null) {
|
||||||
{
|
|
||||||
comments.CommentsActive = false;
|
comments.CommentsActive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -4,34 +4,30 @@ using Orchard.Environment.Extensions;
|
|||||||
using Orchard.Events;
|
using Orchard.Events;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
|
|
||||||
namespace Orchard.Comments.Rules
|
namespace Orchard.Comments.Rules {
|
||||||
{
|
public interface IFormProvider : IEventHandler {
|
||||||
public interface IFormProvider : IEventHandler
|
|
||||||
{
|
|
||||||
void Describe(dynamic context);
|
void Describe(dynamic context);
|
||||||
}
|
}
|
||||||
|
|
||||||
[OrchardFeature("Orchard.Comments.Rules")]
|
[OrchardFeature("Orchard.Comments.Rules")]
|
||||||
public class CommentsForms : IFormProvider
|
public class CommentsForms : IFormProvider {
|
||||||
{
|
|
||||||
protected dynamic Shape { get; set; }
|
protected dynamic Shape { get; set; }
|
||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
public CommentsForms(IShapeFactory shapeFactory)
|
public CommentsForms(IShapeFactory shapeFactory) {
|
||||||
{
|
|
||||||
Shape = shapeFactory;
|
Shape = shapeFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Describe(dynamic context)
|
public void Describe(dynamic context) {
|
||||||
{
|
|
||||||
|
|
||||||
Func<IShapeFactory, dynamic> form =
|
Func<IShapeFactory, dynamic> form =
|
||||||
shape => Shape.Form(
|
shape => Shape.Form(
|
||||||
Id: "ActionCloseComments",
|
Id: "ActionCloseComments",
|
||||||
_Type: Shape.Textbox(
|
_Type: Shape.Textbox(
|
||||||
Id: "ContentId", Name: "ContentId",
|
Id: "ContentId", Name: "ContentId",
|
||||||
Title: T("Content Item Id"),
|
Title: T("Content Item Id"),
|
||||||
Description: T("Content Item Id."))
|
Description: T("Content Item Id."),
|
||||||
|
Classes: new [] { "tokenized" })
|
||||||
);
|
);
|
||||||
|
|
||||||
context.Form("ActionCloseComments", form);
|
context.Form("ActionCloseComments", form);
|
||||||
|
@@ -5,6 +5,14 @@ Website: http://orchardproject.net
|
|||||||
Version: 1.2.0
|
Version: 1.2.0
|
||||||
OrchardVersion: 1.2.0
|
OrchardVersion: 1.2.0
|
||||||
Description: The Email Messaging module adds Email sending functionalities.
|
Description: The Email Messaging module adds Email sending functionalities.
|
||||||
FeatureDescription: Email Messaging services.
|
Features:
|
||||||
Category: Messaging
|
Orchard.Email:
|
||||||
Dependencies: Orchard.Messaging
|
Name: Email Messaging
|
||||||
|
FeatureDescription: Email Messaging services.
|
||||||
|
Category: Messaging
|
||||||
|
Dependencies: Orchard.Messaging
|
||||||
|
Orchard.Email.Rules:
|
||||||
|
Name: Email Rules
|
||||||
|
Description: Rules for the Email modules
|
||||||
|
Category: Rules
|
||||||
|
Dependencies: Orchard.Email, Orchard.Rules
|
@@ -18,6 +18,7 @@
|
|||||||
<OldToolsVersion>3.5</OldToolsVersion>
|
<OldToolsVersion>3.5</OldToolsVersion>
|
||||||
<UpgradeBackupLocation />
|
<UpgradeBackupLocation />
|
||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
|
<UseIISExpress>false</UseIISExpress>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
@@ -54,6 +55,8 @@
|
|||||||
<Compile Include="Models\SmtpSettingsPart.cs" />
|
<Compile Include="Models\SmtpSettingsPart.cs" />
|
||||||
<Compile Include="Models\SmtpSettingsPartRecord.cs" />
|
<Compile Include="Models\SmtpSettingsPartRecord.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Rules\MailActions.cs" />
|
||||||
|
<Compile Include="Rules\MailForms.cs" />
|
||||||
<Compile Include="Services\EmailMessageEventHandler.cs" />
|
<Compile Include="Services\EmailMessageEventHandler.cs" />
|
||||||
<Compile Include="Services\EmailMessagingChannel.cs" />
|
<Compile Include="Services\EmailMessagingChannel.cs" />
|
||||||
<Compile Include="Services\MissingSettingsBanner.cs" />
|
<Compile Include="Services\MissingSettingsBanner.cs" />
|
||||||
|
128
src/Orchard.Web/Modules/Orchard.Email/Rules/MailActions.cs
Normal file
128
src/Orchard.Web/Modules/Orchard.Email/Rules/MailActions.cs
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Orchard.ContentManagement.Records;
|
||||||
|
using Orchard.Core.Common.Models;
|
||||||
|
using Orchard.Environment.Extensions;
|
||||||
|
using Orchard.Events;
|
||||||
|
using Orchard.Messaging.Events;
|
||||||
|
using Orchard.Messaging.Models;
|
||||||
|
using Orchard.Messaging.Services;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.Localization;
|
||||||
|
using Orchard.Security;
|
||||||
|
|
||||||
|
namespace Orchard.Email.Rules {
|
||||||
|
|
||||||
|
public interface IActionProvider : IEventHandler {
|
||||||
|
void Describe(dynamic describe);
|
||||||
|
}
|
||||||
|
|
||||||
|
[OrchardFeature("Orchard.Email.Rules")]
|
||||||
|
public class MailActions : IActionProvider {
|
||||||
|
private readonly IMessageManager _messageManager;
|
||||||
|
private readonly IOrchardServices _orchardServices;
|
||||||
|
private readonly IMembershipService _membershipService;
|
||||||
|
public const string MessageType = "ActionEmail";
|
||||||
|
|
||||||
|
public MailActions(
|
||||||
|
IMessageManager messageManager,
|
||||||
|
IOrchardServices orchardServices,
|
||||||
|
IMembershipService membershipService) {
|
||||||
|
_messageManager = messageManager;
|
||||||
|
_orchardServices = orchardServices;
|
||||||
|
_membershipService = membershipService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
public void Describe(dynamic describe) {
|
||||||
|
Func<dynamic, LocalizedString> display = context => T("Send an e-mail");
|
||||||
|
|
||||||
|
describe.For("Messaging", T("Messaging"), T("Messages"))
|
||||||
|
.Element("SendEmail", T("Send e-mail"), T("Sends an e-mail to a specific user."), (Func<dynamic, bool>)Send, display, "ActionEmail");
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool Send(dynamic context) {
|
||||||
|
var recipient = context.Properties["Recipient"];
|
||||||
|
ContentItemRecord recipientRecord = null;
|
||||||
|
|
||||||
|
if (recipient == "owner") {
|
||||||
|
var content = context.Tokens["Content"] as IContent;
|
||||||
|
if (content.Has<CommonPart>()) {
|
||||||
|
recipientRecord = content.As<CommonPart>().Owner.ContentItem.Record;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recipient == "author") {
|
||||||
|
var user = _orchardServices.WorkContext.CurrentUser;
|
||||||
|
|
||||||
|
// can be null if user is anonymous
|
||||||
|
if (user != null && String.IsNullOrWhiteSpace(user.Email)) {
|
||||||
|
recipientRecord = user.ContentItem.Record;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recipient == "admin") {
|
||||||
|
var username = _orchardServices.WorkContext.CurrentSite.SuperUser;
|
||||||
|
var user = _membershipService.GetUser(username);
|
||||||
|
|
||||||
|
// can be null if user is no super user is defined
|
||||||
|
if (user != null && !String.IsNullOrWhiteSpace(user.Email)) {
|
||||||
|
recipientRecord = user.ContentItem.Record;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recipientRecord == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var properties = new Dictionary<string, string>(context.Properties);
|
||||||
|
|
||||||
|
_messageManager.Send(recipientRecord, MessageType, "email", properties);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MailActionsHandler : IMessageEventHandler {
|
||||||
|
private readonly IContentManager _contentManager;
|
||||||
|
|
||||||
|
public MailActionsHandler(IContentManager contentManager) {
|
||||||
|
_contentManager = contentManager;
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
public void Sending(MessageContext context) {
|
||||||
|
if (context.MessagePrepared)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var contentItem = _contentManager.Get(context.Recipient.Id);
|
||||||
|
if (contentItem == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var recipient = contentItem.As<IUser>();
|
||||||
|
if (recipient == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (context.Type) {
|
||||||
|
case MailActions.MessageType:
|
||||||
|
context.MailMessage.Subject = context.Properties["Subject"];
|
||||||
|
context.MailMessage.Body = context.Properties["Body"];
|
||||||
|
FormatEmailBody(context);
|
||||||
|
context.MessagePrepared = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void FormatEmailBody(MessageContext context) {
|
||||||
|
context.MailMessage.Body = "<p style=\"font-family:Arial, Helvetica; font-size:10pt;\">" + context.MailMessage.Body;
|
||||||
|
context.MailMessage.Body += "</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Sent(MessageContext context) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
73
src/Orchard.Web/Modules/Orchard.Email/Rules/MailForms.cs
Normal file
73
src/Orchard.Web/Modules/Orchard.Email/Rules/MailForms.cs
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
using System;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using Orchard.DisplayManagement;
|
||||||
|
using Orchard.Environment.Extensions;
|
||||||
|
using Orchard.Events;
|
||||||
|
using Orchard.Localization;
|
||||||
|
|
||||||
|
namespace Orchard.Email.Rules {
|
||||||
|
public interface IFormProvider : IEventHandler {
|
||||||
|
void Describe(dynamic context);
|
||||||
|
}
|
||||||
|
|
||||||
|
[OrchardFeature("Orchard.Email.Rules")]
|
||||||
|
public class MailForms : IFormProvider {
|
||||||
|
protected dynamic Shape { get; set; }
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
public MailForms(IShapeFactory shapeFactory) {
|
||||||
|
Shape = shapeFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Describe(dynamic context) {
|
||||||
|
Func<IShapeFactory, dynamic> form =
|
||||||
|
shape => Shape.Form(
|
||||||
|
Id: "ActionEmail",
|
||||||
|
_Type: Shape.SelectList(
|
||||||
|
Id: "Recipient", Name: "Recipient",
|
||||||
|
Title: T("Send to"),
|
||||||
|
Description: T("Select who should be the recipient of this e-mail."))
|
||||||
|
.Add(new SelectListItem { Value = "owner", Text = T("Owner").Text })
|
||||||
|
.Add(new SelectListItem { Value = "author", Text = T("Author").Text })
|
||||||
|
.Add(new SelectListItem { Value = "admin", Text = T("Site Admin").Text }),
|
||||||
|
_Subject: Shape.Textbox(
|
||||||
|
Id: "Subject", Name: "Subject",
|
||||||
|
Title: T("Subject"),
|
||||||
|
Description: T("The subject of the e-mail."),
|
||||||
|
Classes: new[] { "large", "text", "tokenized" }),
|
||||||
|
_Message: Shape.Textarea(
|
||||||
|
Id: "Body", Name: "Body",
|
||||||
|
Title: T("Body"),
|
||||||
|
Description: T("The body of the e-mail."),
|
||||||
|
Classes: new[] { "tokenized" }
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
context.Form("ActionEmail", form);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IFormHandler : IEventHandler {
|
||||||
|
void Validating(dynamic context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MailFormsValitator : IFormHandler {
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
public void Validating(dynamic context) {
|
||||||
|
if (context.FormName == "ActionEmail") {
|
||||||
|
if (context.ValueProdiver.GetValue("Recipient").AttemptedValue == String.Empty) {
|
||||||
|
context.ModelState.AddModelError("Recipient", T("You must select at least one recipient").Text);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.ValueProdiver.GetValue("Subject").AttemptedValue == String.Empty) {
|
||||||
|
context.ModelState.AddModelError("Subject", T("You must provide a Subject").Text);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.ValueProdiver.GetValue("Body").AttemptedValue == String.Empty) {
|
||||||
|
context.ModelState.AddModelError("Body", T("You must provide a Body").Text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -13,3 +13,8 @@ Features:
|
|||||||
Description: Custom lightweight and simple scripting language.
|
Description: Custom lightweight and simple scripting language.
|
||||||
Dependencies: Orchard.Scripting
|
Dependencies: Orchard.Scripting
|
||||||
Category: Scripting
|
Category: Scripting
|
||||||
|
Orchard.Scripting.Rules:
|
||||||
|
Name: Scripting Rules
|
||||||
|
Description: Rules for the Scripting modules
|
||||||
|
Category: Rules
|
||||||
|
Dependencies: Orchard.Scripting, Orchard.Rules
|
@@ -14,6 +14,7 @@
|
|||||||
<AssemblyName>Orchard.Scripting</AssemblyName>
|
<AssemblyName>Orchard.Scripting</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||||
<MvcBuildViews>false</MvcBuildViews>
|
<MvcBuildViews>false</MvcBuildViews>
|
||||||
|
<UseIISExpress>false</UseIISExpress>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
@@ -66,6 +67,8 @@
|
|||||||
<Compile Include="Compiler\Token.cs" />
|
<Compile Include="Compiler\Token.cs" />
|
||||||
<Compile Include="Compiler\Tokenizer.cs" />
|
<Compile Include="Compiler\Tokenizer.cs" />
|
||||||
<Compile Include="Compiler\TokenKind.cs" />
|
<Compile Include="Compiler\TokenKind.cs" />
|
||||||
|
<Compile Include="Rules\ConditionActions.cs" />
|
||||||
|
<Compile Include="Rules\ConditionForms.cs" />
|
||||||
<Compile Include="ScriptExpressionEvaluator.cs" />
|
<Compile Include="ScriptExpressionEvaluator.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Orchard.Environment.Extensions;
|
||||||
|
using Orchard.Events;
|
||||||
|
using Orchard.Localization;
|
||||||
|
|
||||||
|
namespace Orchard.Scripting.Rules {
|
||||||
|
public interface IActionProvider : IEventHandler {
|
||||||
|
void Describe(dynamic describe);
|
||||||
|
}
|
||||||
|
|
||||||
|
[OrchardFeature("Orchard.Scripting.Rules")]
|
||||||
|
public class ConditionActions : IActionProvider {
|
||||||
|
private readonly IEnumerable<IScriptExpressionEvaluator> _evaluators;
|
||||||
|
|
||||||
|
public ConditionActions(IEnumerable<IScriptExpressionEvaluator> evaluators) {
|
||||||
|
_evaluators = evaluators;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
public void Describe(dynamic describe) {
|
||||||
|
Func<dynamic, LocalizedString> display = context => new LocalizedString(context.Properties["description"]);
|
||||||
|
|
||||||
|
describe.For("Condition", T("Conditions"), T("Conditions"))
|
||||||
|
.Element("ScriptCondition", T("Script condition"), T("Evaluates a boolean using a scripting engine."), (Func<dynamic, bool>)Evaluate, display, "ScriptCondition");
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool Evaluate(dynamic context) {
|
||||||
|
var evaluator = _evaluators.FirstOrDefault();
|
||||||
|
if (evaluator == null) {
|
||||||
|
throw new OrchardException(T("There are currently no scripting engine enabled"));
|
||||||
|
}
|
||||||
|
|
||||||
|
var condition = context.Properties["condition"];
|
||||||
|
|
||||||
|
// assume condition as True if empty
|
||||||
|
if (!String.IsNullOrWhiteSpace(condition)) {
|
||||||
|
var result = evaluator.Evaluate(condition, new List<IGlobalMethodProvider>());
|
||||||
|
if (!(result is bool)) {
|
||||||
|
throw new OrchardException(T("Expression is not a boolean value"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return (bool) result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using Orchard.DisplayManagement;
|
||||||
|
using Orchard.Environment.Extensions;
|
||||||
|
using Orchard.Events;
|
||||||
|
using Orchard.Localization;
|
||||||
|
|
||||||
|
namespace Orchard.Scripting.Rules {
|
||||||
|
public interface IFormProvider : IEventHandler {
|
||||||
|
void Describe(dynamic context);
|
||||||
|
}
|
||||||
|
|
||||||
|
[OrchardFeature("Orchard.Scripting.Rules")]
|
||||||
|
public class ConditionForms : IFormProvider {
|
||||||
|
protected dynamic Shape { get; set; }
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
public ConditionForms(IShapeFactory shapeFactory) {
|
||||||
|
Shape = shapeFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Describe(dynamic context) {
|
||||||
|
Func<IShapeFactory, dynamic> form =
|
||||||
|
shape => Shape.Form(
|
||||||
|
Id: "ScriptCondition",
|
||||||
|
_Description: Shape.Textbox(
|
||||||
|
Id: "description", Name: "description",
|
||||||
|
Title: T("Description"),
|
||||||
|
Description: T("Message that will be displayed in the Actions list."),
|
||||||
|
Classes: new[] { "textMedium" }),
|
||||||
|
_Condition: Shape.TextArea(
|
||||||
|
Id: "condition", Name: "condition",
|
||||||
|
Title: T("Condition"),
|
||||||
|
Description: T("Enter a valid boolean expression to evaluate."),
|
||||||
|
Classes: new[] { "tokenized" })
|
||||||
|
);
|
||||||
|
|
||||||
|
context.Form("ScriptCondition", form);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user