Added IsVisible property to recipe builders to control their visibility.

This is useful for builder steps that should only be rendered when there's actually something to render.
For example, the Custom Steps step should only be visible if there actually are any custom steps available for execution.
This commit is contained in:
Sipke Schoorstra
2015-07-19 23:36:37 +01:00
parent 531f8bc352
commit 46d88feb0c
6 changed files with 21 additions and 12 deletions

View File

@@ -38,7 +38,8 @@ namespace Orchard.ImportExport.Providers.ExportActions {
Name = x.Name,
DisplayName = x.DisplayName,
Description = x.Description,
Editor = x.BuildEditor(shapeFactory)
Editor = x.BuildEditor(shapeFactory),
IsVisible = x.IsVisible
});
var viewModel = new RecipeBuilderViewModel {

View File

@@ -32,6 +32,10 @@ namespace Orchard.ImportExport.Recipes.Builders {
get { return T("Exports additional items."); }
}
public override bool IsVisible {
get { return CustomSteps.Any(); }
}
public override int Priority { get { return -50; } }
public override int Position { get { return 500; } }

View File

@@ -7,5 +7,6 @@ namespace Orchard.ImportExport.ViewModels {
public LocalizedString Description { get; set; }
public bool IsSelected { get; set; }
public dynamic Editor { get; set; }
public bool IsVisible { get; set; }
}
}

View File

@@ -4,26 +4,27 @@
Script.Require("ShapesBase");
}
@{
var exportStepIndex = 0;
foreach (var exportStep in Model.Steps) {
var stepName = Html.NameFor(m => m.Steps[exportStepIndex].IsSelected).ToString();
var stepIndex = 0;
var steps = Model.Steps.Where(x => x.IsVisible).ToArray();
foreach (var step in steps) {
var stepName = Html.NameFor(m => m.Steps[stepIndex].IsSelected).ToString();
var stepId = stepName.HtmlClassify();
<fieldset class="recipe-builder-step recipe-builder-step-@exportStep.Name.HtmlClassify()">
<fieldset class="recipe-builder-step recipe-builder-step-@step.Name.HtmlClassify()">
<legend>
<input type="hidden" name="@Html.NameFor(m => m.Steps[exportStepIndex].Name)" value="@Model.Steps[exportStepIndex].Name" />
<input type="hidden" name="@Html.NameFor(m => m.Steps[stepIndex].Name)" value="@steps[stepIndex].Name" />
<input type="checkbox" id="@stepId" name="@stepName" value="true" />
<label for="@stepId" class="forcheckbox">@exportStep.DisplayName</label>
<label for="@stepId" class="forcheckbox">@step.DisplayName</label>
</legend>
@Html.Hint(@exportStep.Description)
@if (exportStep.Editor != null) {
@Html.Hint(step.Description)
@if (step.Editor != null) {
<div data-controllerid="@stepId">
@Display(exportStep.Editor)
@Display(step.Editor)
</div>
}
</fieldset>
exportStepIndex++;
if (exportStepIndex < Model.Steps.Count) {
stepIndex++;
if (stepIndex < steps.Count()) {
<hr />
}
}

View File

@@ -18,6 +18,7 @@ namespace Orchard.Recipes.Services {
/// The order in which this builder should be displayed.
/// </summary>
int Position { get; }
bool IsVisible { get; }
dynamic BuildEditor(dynamic shapeFactory);
dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater);

View File

@@ -9,6 +9,7 @@ namespace Orchard.Recipes.Services {
public abstract LocalizedString Description { get; }
public virtual int Priority { get { return 0; } }
public virtual int Position { get { return 0; } }
public virtual bool IsVisible { get { return true; } }
protected virtual string Prefix {
get { return GetType().Name; }