mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Adding Orchard.DynamicForms.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.DynamicForms.Elements;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Workflows.Models;
|
||||
using Orchard.Workflows.Services;
|
||||
|
||||
namespace Orchard.DynamicForms.Activities {
|
||||
public class FormSubmittedActivity : Event {
|
||||
|
||||
public const string EventName = "DynamicFormSubmitted";
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public override bool CanStartWorkflow {
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool CanExecute(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||
var state = activityContext.GetState<string>("DynamicForms");
|
||||
|
||||
// "" means 'any'.
|
||||
if (String.IsNullOrEmpty(state)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var form = workflowContext.Tokens["DynamicForm"] as Form;
|
||||
|
||||
if (form == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var formNames = state.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
return formNames.Any(x => x == form.Name);
|
||||
}
|
||||
|
||||
public override IEnumerable<LocalizedString> GetPossibleOutcomes(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||
return new[] { T("Done") };
|
||||
}
|
||||
|
||||
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||
yield return T("Done");
|
||||
}
|
||||
|
||||
public override string Form {
|
||||
get {
|
||||
return "SelectDynamicForms";
|
||||
}
|
||||
}
|
||||
|
||||
public override string Name {
|
||||
get { return EventName; }
|
||||
}
|
||||
|
||||
public override LocalizedString Category {
|
||||
get { return T("Forms"); }
|
||||
}
|
||||
|
||||
public override LocalizedString Description {
|
||||
get { return T("A dynamic form is submitted."); }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Forms.Services;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.DynamicForms.Activities {
|
||||
public class SelectDynamicForms : IFormProvider {
|
||||
protected dynamic Shape { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public SelectDynamicForms(IShapeFactory shapeFactory) {
|
||||
Shape = shapeFactory;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public void Describe(DescribeContext context) {
|
||||
context.Form("SelectDynamicForms", factory => {
|
||||
var shape = (dynamic)factory;
|
||||
var form = shape.Form(
|
||||
Id: "AnyOfDynamicForms",
|
||||
_Parts: Shape.Textbox(
|
||||
Id: "dynamicforms",
|
||||
Name: "DynamicForms",
|
||||
Title: T("Dynamic Forms"),
|
||||
Description: T("Enter a comma separated list of dynamic form names. Leave empty to handle all forms."),
|
||||
Classes: new[] { "text", "large" })
|
||||
);
|
||||
|
||||
return form;
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user