mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Formatting Decision Activity files and fixing help text
--HG-- branch : 1.x
This commit is contained in:
@@ -6,6 +6,6 @@
|
||||
<label for="@Html.FieldIdFor(m => m.Script)">@T("Script")</label>
|
||||
<div>
|
||||
@Html.TextAreaFor(m => m.Script, new { @class = "textMedium", rows = "5" })
|
||||
<span class="hint">@T("The script to run everytime the content item is edited. You can use contentItem, orchardServices, workContext, t() and addModelError().")</span>
|
||||
<span class="hint">@T("The script to run everytime the content item is edited. You can use ContentItem, Services, WorkContext, T() and AddModelError().")</span>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
@@ -8,19 +8,19 @@ using Orchard.Workflows.Services;
|
||||
|
||||
namespace Orchard.Workflows.Activities {
|
||||
public class DecisionActivity : Task {
|
||||
private readonly ICSharpService _csharpService;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
private readonly ICSharpService _csharpService;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
|
||||
public DecisionActivity(
|
||||
IOrchardServices orchardServices,
|
||||
ICSharpService csharpService,
|
||||
IWorkContextAccessor workContextAccessor) {
|
||||
_csharpService = csharpService;
|
||||
_orchardServices = orchardServices;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
public DecisionActivity(
|
||||
IOrchardServices orchardServices,
|
||||
ICSharpService csharpService,
|
||||
IWorkContextAccessor workContextAccessor) {
|
||||
_csharpService = csharpService;
|
||||
_orchardServices = orchardServices;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
@@ -33,43 +33,41 @@ namespace Orchard.Workflows.Activities {
|
||||
}
|
||||
|
||||
public override LocalizedString Description {
|
||||
get { return T("Evaluates an expression."); }
|
||||
get { return T("Evaluates an expression."); }
|
||||
}
|
||||
|
||||
public override string Form {
|
||||
get { return "ActivityActionDecision"; }
|
||||
get { return "ActivityActionDecision"; }
|
||||
}
|
||||
|
||||
public override IEnumerable<LocalizedString> GetPossibleOutcomes(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||
return GetOutcomes(activityContext).Select(outcome => T(outcome));
|
||||
return GetOutcomes(activityContext).Select(outcome => T(outcome));
|
||||
}
|
||||
|
||||
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||
var properties = new Dictionary<string, string> {
|
||||
var properties = new Dictionary<string, string> {
|
||||
{"Script", activityContext.GetState<string>("Script")}
|
||||
};
|
||||
|
||||
_csharpService.SetParameter("Services", _orchardServices);
|
||||
_csharpService.SetParameter("ContentItem", (dynamic)workflowContext.Content.ContentItem);
|
||||
_csharpService.SetParameter("WorkContext", _workContextAccessor.GetContext());
|
||||
_csharpService.SetFunction("T", (Func<string, string>)(x => T(x).Text));
|
||||
_csharpService.SetParameter("Services", _orchardServices);
|
||||
_csharpService.SetParameter("ContentItem", (dynamic)workflowContext.Content.ContentItem);
|
||||
_csharpService.SetParameter("WorkContext", _workContextAccessor.GetContext());
|
||||
_csharpService.SetFunction("T", (Func<string, string>)(x => T(x).Text));
|
||||
|
||||
var scriptResult = _csharpService.Evaluate(properties["Script"]).ToString();
|
||||
var scriptResult = _csharpService.Evaluate(properties["Script"]).ToString();
|
||||
|
||||
yield return T(scriptResult);
|
||||
yield return T(scriptResult);
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetOutcomes(ActivityContext context)
|
||||
{
|
||||
private IEnumerable<string> GetOutcomes(ActivityContext context) {
|
||||
|
||||
var outcomes = context.GetState<string>("Outcomes");
|
||||
var outcomes = context.GetState<string>("Outcomes");
|
||||
|
||||
if (String.IsNullOrEmpty(outcomes))
|
||||
{
|
||||
return Enumerable.Empty<string>();
|
||||
}
|
||||
if (String.IsNullOrEmpty(outcomes)) {
|
||||
return Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
return outcomes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList();
|
||||
return outcomes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList();
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -3,59 +3,58 @@ using Orchard.DisplayManagement;
|
||||
using Orchard.Forms.Services;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Workflows.Forms
|
||||
{
|
||||
public class DecisionForms : IFormProvider {
|
||||
protected dynamic Shape { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
namespace Orchard.Workflows.Forms {
|
||||
public class DecisionForms : IFormProvider {
|
||||
protected dynamic Shape { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public DecisionForms(IShapeFactory shapeFactory) {
|
||||
Shape = shapeFactory;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public void Describe(DescribeContext context) {
|
||||
Func<IShapeFactory, dynamic> form =
|
||||
shape => Shape.Form(
|
||||
Id: "ActionDecision",
|
||||
_Message: Shape.Textbox(
|
||||
Id: "outcomes", Name: "Outcomes",
|
||||
Title: T("Possible Outcomes."),
|
||||
Description: T("A comma separated list of possible outcomes."),
|
||||
Classes: new[] { "textMedium" }),
|
||||
_Script: Shape.TextArea(
|
||||
Id: "Script", Name: "Script",
|
||||
Title: T("Script"),
|
||||
Description: T("The script to run every time the Decision Activity is invoked. You can use ContentItem, orchardServices, workContext, and t(). Return type of script should be Boolean."),
|
||||
Classes: new[] { "tokenized" }
|
||||
)
|
||||
);
|
||||
|
||||
context.Form("ActivityActionDecision", form);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class DecisionFormsValidator : IFormEventHandler {
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public void Building(BuildingContext context) {
|
||||
}
|
||||
|
||||
public void Built(BuildingContext context) {
|
||||
}
|
||||
|
||||
public void Validating(ValidatingContext context) {
|
||||
if (context.FormName == "ActionDecision") {
|
||||
if (context.ValueProvider.GetValue("Script").AttemptedValue == string.Empty) {
|
||||
context.ModelState.AddModelError("Script", T("You must provide a Script").Text);
|
||||
public DecisionForms(IShapeFactory shapeFactory) {
|
||||
Shape = shapeFactory;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Validated(ValidatingContext context) {
|
||||
public void Describe(DescribeContext context) {
|
||||
Func<IShapeFactory, dynamic> form =
|
||||
shape => Shape.Form(
|
||||
Id: "ActionDecision",
|
||||
_Message: Shape.Textbox(
|
||||
Id: "outcomes", Name: "Outcomes",
|
||||
Title: T("Possible Outcomes."),
|
||||
Description: T("A comma separated list of possible outcomes."),
|
||||
Classes: new[] { "textMedium" }),
|
||||
_Script: Shape.TextArea(
|
||||
Id: "Script", Name: "Script",
|
||||
Title: T("Script"),
|
||||
Description: T("The script to run every time the Decision Activity is invoked. You can use ContentItem, Services, WorkContext, and T(). Return type must be a strin.gDecisionAc"),
|
||||
Classes: new[] { "tokenized" }
|
||||
)
|
||||
);
|
||||
|
||||
context.Form("ActivityActionDecision", form);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class DecisionFormsValidator : IFormEventHandler {
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public void Building(BuildingContext context) {
|
||||
}
|
||||
|
||||
public void Built(BuildingContext context) {
|
||||
}
|
||||
|
||||
public void Validating(ValidatingContext context) {
|
||||
if (context.FormName == "ActionDecision") {
|
||||
if (context.ValueProvider.GetValue("Script").AttemptedValue == string.Empty) {
|
||||
context.ModelState.AddModelError("Script", T("You must provide a Script").Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Validated(ValidatingContext context) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user