Ewl » Canonical The canonical version of EWL Read More
Clone URL:  
FlowCheckbox.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System; using System.Collections.Generic; using System.Linq; using EnterpriseWebLibrary.InputValidation; using Humanizer; using JetBrains.Annotations; namespace EnterpriseWebLibrary.EnterpriseWebFramework { /// <summary> /// A checkbox that supports nested components. /// </summary> public class FlowCheckbox: FormControl<FlowComponent> { private static readonly ElementClass unhighlightedClass = new ElementClass( "ewfFcu" ); private static readonly ElementClass highlightedClass = new ElementClass( "ewfFch" ); private static readonly ElementClass nestedContentClass = new ElementClass( "ewfFcc" ); [ UsedImplicitly ] private class CssElementCreator: ControlCssElementCreator { IReadOnlyCollection<CssElement> ControlCssElementCreator.CreateCssElements() => new[] { new CssElement( "FlowCheckboxAllStates", new[] { unhighlightedClass, highlightedClass }.Select( getSelector ).ToArray() ), new CssElement( "FlowCheckboxUnhighlightedState", getSelector( unhighlightedClass ) ), new CssElement( "FlowCheckboxHighlightedState", getSelector( highlightedClass ) ), new CssElement( "FlowCheckboxNestedContentContainer", "div.{0}".FormatWith( nestedContentClass.ClassName ) ) }; private string getSelector( ElementClass elementClass ) => "div.{0}".FormatWith( elementClass.ClassName ); } public FlowComponent PageComponent { get; } public EwfValidation Validation { get; } /// <summary> /// Creates a checkbox. /// </summary> /// <param name="value"></param> /// <param name="label">The checkbox label. Do not pass null. Pass an empty collection for no label.</param> /// <param name="setup">The setup object for the flow checkbox.</param> /// <param name="validationMethod">The validation method. Pass null if you’re only using the checkbox for page modification.</param> public FlowCheckbox( bool value, IReadOnlyCollection<PhrasingComponent> label, FlowCheckboxSetup setup = null, Action<PostBackValue<bool>, Validator> validationMethod = null ) { setup = setup ?? FlowCheckboxSetup.Create(); var checkbox = new Checkbox( value, label, setup: setup.CheckboxSetup, validationMethod: validationMethod ); PageComponent = getComponent( setup.DisplaySetup, setup.Classes, setup.CheckboxSetup.PageModificationValue, checkbox, setup.HighlightedWhenChecked, setup.NestedContentGetter, setup.NestedContentAlwaysDisplayed ); Validation = checkbox.Validation; } /// <summary> /// Creates a radio button. /// </summary> internal FlowCheckbox( FlowRadioButtonSetup setup, Checkbox checkbox ) { PageComponent = getComponent( setup.DisplaySetup, setup.Classes, setup.RadioButtonSetup.PageModificationValue, checkbox, setup.HighlightedWhenSelected, setup.NestedContentGetter, setup.NestedContentAlwaysDisplayed ); Validation = checkbox.Validation; } private FlowComponent getComponent( DisplaySetup displaySetup, ElementClassSet classes, PageModificationValue<bool> pageModificationValue, Checkbox checkbox, bool highlightedWhenChecked, Func<IReadOnlyCollection<FlowComponent>> nestedContentGetter, bool nestedContentAlwaysDisplayed ) { var nestedContent = nestedContentGetter?.Invoke() ?? Enumerable.Empty<FlowComponent>().Materialize(); return new GenericFlowContainer( checkbox.PageComponent.ToCollection() .Concat( nestedContent.Any() ? new GenericFlowContainer( nestedContent, displaySetup: nestedContentAlwaysDisplayed ? null : pageModificationValue.ToCondition().ToDisplaySetup(), classes: nestedContentClass ).ToCollection() : Enumerable.Empty<FlowComponent>() ) .Materialize(), displaySetup: displaySetup, classes: ( highlightedWhenChecked ? pageModificationValue.ToCondition( isTrueWhenValueSet: false ) .ToElementClassSet( unhighlightedClass ) .Add( pageModificationValue.ToCondition().ToElementClassSet( highlightedClass ) ) : unhighlightedClass ).Add( classes ?? ElementClassSet.Empty ) ); } FormControlLabeler FormControl<FlowComponent>.Labeler => null; } }