diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/Orchard.DynamicForms.csproj b/src/Orchard.Web/Modules/Orchard.DynamicForms/Orchard.DynamicForms.csproj index e3133ef21..6b2829aaa 100644 --- a/src/Orchard.Web/Modules/Orchard.DynamicForms/Orchard.DynamicForms.csproj +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/Orchard.DynamicForms.csproj @@ -118,6 +118,7 @@ + @@ -304,6 +305,7 @@ + @@ -549,6 +551,9 @@ + + + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/Recipes/Builders/FormSubmissionsStep.cs b/src/Orchard.Web/Modules/Orchard.DynamicForms/Recipes/Builders/FormSubmissionsStep.cs index 8a820dc05..206c15cf9 100644 --- a/src/Orchard.Web/Modules/Orchard.DynamicForms/Recipes/Builders/FormSubmissionsStep.cs +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/Recipes/Builders/FormSubmissionsStep.cs @@ -3,12 +3,17 @@ using System.Xml.Linq; using Orchard.DynamicForms.Services; using Orchard.Localization; using Orchard.Recipes.Services; +using System.Collections.Generic; +using Orchard.ContentManagement; +using Orchard.DynamicForms.ViewModels; namespace Orchard.DynamicForms.Recipes.Builders { public class FormSubmissionsStep : RecipeBuilderStep { private readonly IFormService _formService; + public FormSubmissionsStep(IFormService formService) { _formService = formService; + SelectedForms = new List(); } public override string Name { @@ -23,29 +28,43 @@ namespace Orchard.DynamicForms.Recipes.Builders { get { return T("Exports submitted forms."); } } + public IList SelectedForms { get; set; } + public override dynamic BuildEditor(dynamic shapeFactory) { - // TODO: Implement an editor that enables the user to select which forms to export. - return null; + return UpdateEditor(shapeFactory, null); + } + + public override dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater) { + List forms = new List(); + + if (updater != null && updater.TryUpdateModel(forms, Prefix, null, null)) { + SelectedForms = forms.Where(x => x.Export).Select(x => x.FormName).ToList(); + } + else { + forms = _formService.GetSubmissions().OrderBy(x => x.FormName).GroupBy(y => y.FormName) + .Select(x => new FormExportEntry { FormName = x.FirstOrDefault().FormName }) + .ToList(); + } + + return shapeFactory.EditorTemplate(TemplateName: "BuilderSteps/FormSubmissions", Model: forms, Prefix: Prefix); } public override void Build(BuildContext context) { - var submissions = _formService.GetSubmissions().ToArray(); + if (SelectedForms.Count() > 0) { + var root = new XElement("Forms"); + context.RecipeDocument.Element("Orchard").Add(root); - if (!submissions.Any()) { - return; - } - - var forms = submissions.GroupBy(x => x.FormName); - var root = new XElement("Forms"); - context.RecipeDocument.Element("Orchard").Add(root); - - foreach (var form in forms) { - root.Add(new XElement("Form", - new XAttribute("Name", form.Key), - new XElement("Submissions", form.Select(submission => - new XElement("Submission", - new XAttribute("CreatedUtc", submission.CreatedUtc), - new XCData(submission.FormData)))))); + foreach (var form in SelectedForms) { + var submissions = _formService.GetSubmissions(form); + if (submissions.Count() > 0) { + root.Add(new XElement("Form", + new XAttribute("Name", form), + new XElement("Submissions", submissions.Select(submission => + new XElement("Submission", + new XAttribute("CreatedUtc", submission.CreatedUtc), + new XCData(submission.FormData)))))); + } + } } } } diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/Styles/recipebuilderstep-forms.css b/src/Orchard.Web/Modules/Orchard.DynamicForms/Styles/recipebuilderstep-forms.css new file mode 100644 index 000000000..660a1b012 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/Styles/recipebuilderstep-forms.css @@ -0,0 +1,9 @@ +fieldset.recipe-builder-step-form-submissions table.items { + width: 500px; + margin: 0; +} + +fieldset.recipe-builder-step-form-submissions table.items td, +fieldset.recipe-builder-step-form-submissions table.items thead tr.sub th { + padding: 0 12px; +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/ViewModels/FormExportEntry.cs b/src/Orchard.Web/Modules/Orchard.DynamicForms/ViewModels/FormExportEntry.cs new file mode 100644 index 000000000..d3d1860d2 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/ViewModels/FormExportEntry.cs @@ -0,0 +1,6 @@ +namespace Orchard.DynamicForms.ViewModels { + public class FormExportEntry { + public string FormName { get; set; } + public bool Export { get; set; } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/Views/EditorTemplates/BuilderSteps/FormSubmissions.cshtml b/src/Orchard.Web/Modules/Orchard.DynamicForms/Views/EditorTemplates/BuilderSteps/FormSubmissions.cshtml new file mode 100644 index 000000000..bfcb2c065 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/Views/EditorTemplates/BuilderSteps/FormSubmissions.cshtml @@ -0,0 +1,35 @@ +@model List +@using Orchard.DynamicForms.ViewModels; + +@{ + Style.Include("recipebuilderstep-forms.css"); +} + +
+ + + + + + + + + + @for (int index = 0; index < Model.Count(); index++) { + var entry = Model.ElementAt(index); + + + + + + } + +
@T("Form") + + @T("Select All") +
@entry.FormName + + +
+ @Html.Hint(T("Choose the forms to include in the export file")) +