Ewl » Canonical The canonical version of EWL Read More
Clone URL:  
Pushed to 2 repositories · View In Graph Contained in tip and canonical

Merge

Changeset 47b04885683c

Parents 735ad84717da

Parents f2a10e3c3401

by Profile picture of William GrossWilliam Gross

Changes to 37 files · Browse files at 47b04885683c Showing diff from parent 735ad84717da f2a10e3c3401 Diff from another changeset...

Change 1 of 4 Show Entire File Core/​Core.csproj Stacked
 
377
378
379
380
381
382
 
 
 
 
 
 
383
384
385
 
400
401
402
 
 
403
404
405
 
593
594
595
 
 
 
596
597
598
599
600
 
738
739
740
741
742
743
744
 
377
378
379
 
380
381
382
383
384
385
386
387
388
389
390
 
405
406
407
408
409
410
411
412
 
600
601
602
603
604
605
606
 
607
608
609
 
747
748
749
 
750
751
752
@@ -377,9 +377,14 @@
  <Compile Include="EnterpriseWebFramework\Error Display\Styles\ListErrorDisplayStyle.cs" />   <Compile Include="EnterpriseWebFramework\Error Display\Styles\SectionErrorDisplayStyle.cs" />   <Compile Include="EnterpriseWebFramework\EwfInitializationOps.cs" /> - <Compile Include="EnterpriseWebFramework\EwfSafeResponseWriter.cs" />   <Compile Include="EnterpriseWebFramework\FontAwesomeIcon.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Check Boxes\BlockCheckBoxSetup.cs" /> + <Compile Include="EnterpriseWebFramework\Form Controls\Checkboxes\Checkbox.cs" /> + <Compile Include="EnterpriseWebFramework\Form Controls\Checkboxes\CheckboxSetup.cs" /> + <Compile Include="EnterpriseWebFramework\Form Controls\Checkboxes\FlowCheckbox.cs" /> + <Compile Include="EnterpriseWebFramework\Form Controls\Checkboxes\FlowCheckboxSetup.cs" /> + <Compile Include="EnterpriseWebFramework\Form Controls\Checkboxes\FlowRadioButtonSetup.cs" /> + <Compile Include="EnterpriseWebFramework\Form Controls\Checkboxes\RadioButtonSetup.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Date and Time\DateAndTimeControl.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Date and Time\DateAndTimeControlSetup.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Date and Time\DateControl.cs" /> @@ -400,6 +405,8 @@
  <Compile Include="EnterpriseWebFramework\Form Controls\Imprecise Number Control\ImpreciseNumberControl.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Imprecise Number Control\ImpreciseNumberControlSetup.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Lists\ChangeBasedCheckBoxList.cs" /> + <Compile Include="EnterpriseWebFramework\Form Controls\Lists\Free-Form Radio List\FreeFormRadioList.cs" /> + <Compile Include="EnterpriseWebFramework\Form Controls\Lists\Free-Form Radio List\FreeFormRadioListSetup.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Lists\List Items\ChangeBasedListItem.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Lists\List Items\ChangeBasedListItemWithSelectionState.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Lists\EwfCheckBoxList.cs" /> @@ -593,8 +600,10 @@
  <Compile Include="EnterpriseWebFramework\Page Infrastructure\SecondaryPostBackOperation.cs" />   <Compile Include="EnterpriseWebFramework\PaymentProcessing\PaymentProcessingStatics.cs" />   <Compile Include="EnterpriseWebFramework\PaymentProcessing\StatusMessageAndDestination.cs" /> + <Compile Include="EnterpriseWebFramework\Request Handling\EwfSafeRequestHandler.cs" /> + <Compile Include="EnterpriseWebFramework\Request Handling\EwfSafeResponseWriter.cs" /> + <Compile Include="EnterpriseWebFramework\Request Handling\StaticFileHandler.cs" />   <Compile Include="EnterpriseWebFramework\RevisionDisplayStatics.cs" /> - <Compile Include="EnterpriseWebFramework\StaticFileHandler.cs" />   <Compile Include="EnterpriseWebFramework\Text\EmphasizedContent.cs" />   <Compile Include="EnterpriseWebFramework\Text\ImportantContent.cs" />   <Compile Include="EnterpriseWebFramework\Text\LineBreak.cs" /> @@ -738,7 +747,6 @@
  <Compile Include="EnterpriseWebFramework\UserManagement\FormsAuthCapableUserManagementProvider.cs" />   <Compile Include="EnterpriseWebFramework\UserManagement\User.cs" />   <Compile Include="EnterpriseWebFramework\UserManagement\SystemUserManagementProvider.cs" /> - <Compile Include="EnterpriseWebFramework\Form Controls\Lists\FreeFormRadioList.cs" />   <Compile Include="Tools\CollectionTools.cs" />   <Compile Include="Collections\ListSet.cs" />   <Compile Include="FormattingMethods.cs" />
 
26
27
28
 
29
30
31
32
33
34
 
35
36
37
 
74
75
76
 
77
78
79
 
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 
76
77
78
79
80
81
82
@@ -26,12 +26,14 @@
  <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cerror_0020display_0020styles/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cerror_0020display_005Cstyles/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CForm_0020Controls/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cform_0020controls_005Ccheckboxes/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CForm_0020Controls_005CCheck_0020Boxes/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cform_0020controls_005Cdate_0020and_0020time/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cform_0020controls_005Cemail_0020address_0020control/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cform_0020controls_005Chtml_0020editor/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cform_0020controls_005Cimprecise_0020number_0020control/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CForm_0020Controls_005CLists/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cform_0020controls_005Clists_005Cfree_002Dform_0020radio_0020list/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CForm_0020Controls_005CLists_005CList_0020Items/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CForm_0020Controls_005CLists_005CSelect_0020List/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cform_0020controls_005Cnavigational_0020form_0020control/@EntryIndexedValue">True</s:Boolean> @@ -74,6 +76,7 @@
  <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cpage_0020infrastructure_005Cpage_0020structure_005Cnodes/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cpage_0020infrastructure_005Cpartial_0020updating/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CPaymentProcessing/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Crequest_0020handling/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CResource_0020Meta_0020Logic/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CResource_0020Meta_0020Logic_005CAlternative_0020Resource_0020Modes/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Ctext/@EntryIndexedValue">True</s:Boolean>
 
57
58
59
60
 
61
62
63
 
123
124
125
126
127
 
 
128
129
130
 
57
58
59
 
60
61
62
63
 
123
124
125
 
 
126
127
128
129
130
@@ -57,7 +57,7 @@
  b.AddFormItems( Email.ToEmailAddressControl( false, value: user != null ? user.Email : "" ).ToFormItem( label: "Email address".ToComponents() ) );     if( includePasswordControls() ) { - var group = new RadioButtonGroup( false ); + var group = new LegacyRadioButtonGroup( false );     var keepPassword = FormItem.Create(   "", @@ -123,8 +123,8 @@
  FormItem.Create(   "Role",   SelectList.CreateDropDown( from i in availableRoles select SelectListItem.Create( i.RoleId as int?, i.Name ), user?.Role.RoleId ), - validationGetter: control => - new EwfValidation( ( pbv, validator ) => RoleId.Value = control.ValidateAndGetSelectedItemIdInPostBack( pbv, validator ) ?? default( int ) ) ) ); + validationGetter: control => new EwfValidation( + ( pbv, validator ) => RoleId.Value = control.ValidateAndGetSelectedItemIdInPostBack( pbv, validator ) ?? default( int ) ) ) );     Controls.Add( b );   }
 
10
11
12
13
14
15
 
16
17
18
 
10
11
12
 
 
 
13
14
15
16
@@ -10,9 +10,7 @@
 using EnterpriseWebLibrary.InputValidation;    namespace EnterpriseWebLibrary.EnterpriseWebFramework { - /// <summary> - /// A block-level check box with the label vertically centered on the box. - /// </summary> + [ Obsolete( "Guaranteed through 28 Feb 2019. Use Checkbox instead." ) ]   [ ParseChildren( ChildrenAsProperties = true, DefaultProperty = "NestedControls" ) ]   public class BlockCheckBox: WebControl, CommonCheckBox, ControlTreeDataLoader, FormValueControl, ControlWithJsInitLogic, FormControl<FlowComponent> {   private readonly FormValue<bool> checkBoxFormValue;
 
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
23
24
25
 
38
39
40
41
42
43
44
45
 
 
46
47
48
 
6
7
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
10
11
12
 
25
26
27
 
 
 
 
 
28
29
30
31
32
@@ -6,20 +6,7 @@
 using EnterpriseWebLibrary.JavaScriptWriting;    namespace EnterpriseWebLibrary.EnterpriseWebFramework { - /* NOTE: This should be named InlineCheckBox. When we do this, rename CommonCheckBox to EwfCheckBox. - * - * InlineCheckBox is a check box that can be centered with text-align or used within a paragraph of text. This cannot be done with BlockCheckBox for two reasons: - * - * 1. BlockCheckBox needs to have 100% width in order for nested controls to work properly in Chrome and Safari. Specifically, a two-row shrink wrap table with wide content - * in the second column of the second row did not work properly in these browsers under certain circumstances (Sam may have details). Inline elements cannot specify width, - * so the BlockCheckBox must be non-inline, and non-inline elements cannot be centered with text-align or used within a paragraph of text. - * - * 2. We could not find a way to get Chrome and Safari to center a table-based check box control using text-align regardless of what CSS display value we used on the element. - * */ - - /// <summary> - /// An in-line check box with the label vertically centered on the box. - /// </summary> + [ Obsolete( "Guaranteed through 28 Feb 2019. Use Checkbox instead." ) ]   public class EwfCheckBox: WebControl, CommonCheckBox, ControlTreeDataLoader, FormValueControl {   private static readonly ElementClass elementClass = new ElementClass( "ewfCheckBox" );   @@ -38,11 +25,8 @@
  () => isChecked,   () => checkBox.IsOnPage() ? checkBox.UniqueID : "",   v => v.ToString(), - rawValue => rawValue == null - ? PostBackValueValidationResult<bool>.CreateValid( false ) - : rawValue == "on" - ? PostBackValueValidationResult<bool>.CreateValid( true ) - : PostBackValueValidationResult<bool>.CreateInvalid() ); + rawValue => rawValue == null ? PostBackValueValidationResult<bool>.CreateValid( false ) : + rawValue == "on" ? PostBackValueValidationResult<bool>.CreateValid( true ) : PostBackValueValidationResult<bool>.CreateInvalid() );   }     internal static void AddCheckBoxAttributes(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
 
@@ -0,0 +1,154 @@
+using System; +using System.Collections.Generic; +using System.Linq; +using EnterpriseWebLibrary.InputValidation; +using Humanizer; +using JetBrains.Annotations; + +namespace EnterpriseWebLibrary.EnterpriseWebFramework { + /// <summary> + /// A two-state control (i.e. checkbox). + /// </summary> + public class Checkbox: FormControl<PhrasingComponent> { + private static readonly ElementClass elementClass = new ElementClass( "ewfCb" ); + + [ UsedImplicitly ] + private class CssElementCreator: ControlCssElementCreator { + IReadOnlyCollection<CssElement> ControlCssElementCreator.CreateCssElements() => + new CssElement( "Checkbox", "label.{0}".FormatWith( elementClass.ClassName ) ).ToCollection() + .Append( new CssElement( "CheckboxControl", "input.{0}".FormatWith( elementClass.ClassName ) ) ) + .Append( new CssElement( "CheckboxLabel", "span.{0}".FormatWith( elementClass.ClassName ) ) ) + .Materialize(); + } + + public PhrasingComponent 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 checkbox.</param> + /// <param name="validationMethod">The validation method. Pass null if you’re only using this control for page modification.</param> + public Checkbox( + bool value, IReadOnlyCollection<PhrasingComponent> label, CheckboxSetup setup = null, Action<PostBackValue<bool>, Validator> validationMethod = null ) { + setup = setup ?? CheckboxSetup.Create(); + + var id = new ElementId(); + var formValue = new FormValue<bool>( + () => value, + () => setup.IsReadOnly ? "" : id.Id, + v => v.ToString(), + rawValue => rawValue == null ? PostBackValueValidationResult<bool>.CreateValid( false ) : + rawValue == "on" ? PostBackValueValidationResult<bool>.CreateValid( true ) : PostBackValueValidationResult<bool>.CreateInvalid() ); + + PageComponent = getComponent( + formValue, + id, + null, + setup.DisplaySetup, + setup.IsReadOnly, + setup.Classes, + setup.PageModificationValue, + label, + setup.Action, + setup.ValueChangedAction, + () => ( setup.ValueChangedAction?.GetJsStatements() ?? "" ).ConcatenateWithSpace( + setup.PageModificationValue.GetJsModificationStatements( "this.checked" ) ) ); + + formValue.AddPageModificationValue( setup.PageModificationValue, v => v ); + + if( validationMethod != null ) + Validation = formValue.CreateValidation( validationMethod ); + } + + /// <summary> + /// Creates a radio button. + /// </summary> + internal Checkbox( + FormValue<ElementId> formValue, ElementId id, RadioButtonSetup setup, IReadOnlyCollection<PhrasingComponent> label, FormAction selectionChangedAction, + Func<string> jsClickStatementGetter, EwfValidation validation, string listItemId = null ) { + PageComponent = getComponent( + formValue, + id, + listItemId, + setup.DisplaySetup, + setup.IsReadOnly, + setup.Classes, + setup.PageModificationValue, + label, + setup.Action, + selectionChangedAction, + () => setup.IsReadOnly + ? "" + : ( setup.PageModificationValue.Value ? "" : selectionChangedAction?.GetJsStatements() ?? "" ) + .ConcatenateWithSpace( jsClickStatementGetter() ) ); + Validation = validation; + } + + private PhrasingComponent getComponent( + FormValue formValue, ElementId id, string radioButtonListItemId, DisplaySetup displaySetup, bool isReadOnly, ElementClassSet classes, + PageModificationValue<bool> pageModificationValue, IReadOnlyCollection<PhrasingComponent> label, FormAction action, FormAction valueChangedAction, + Func<string> jsClickStatementGetter ) { + return new CustomPhrasingComponent( + new DisplayableElement( + labelContext => new DisplayableElementData( + displaySetup, + () => new DisplayableElementLocalData( "label" ), + classes: elementClass.Add( classes ?? ElementClassSet.Empty ), + children: new DisplayableElement( + context => { + id.AddId( context.Id ); + + if( !isReadOnly ) { + action.AddToPageIfNecessary(); + valueChangedAction?.AddToPageIfNecessary(); + } + + return new DisplayableElementData( + null, + () => { + var attributes = new List<Tuple<string, string>>(); + var radioButtonFormValue = formValue as FormValue<ElementId>; + attributes.Add( Tuple.Create( "type", radioButtonFormValue != null ? "radio" : "checkbox" ) ); + if( radioButtonFormValue != null || !isReadOnly ) + attributes.Add( + Tuple.Create( "name", radioButtonFormValue != null ? ( (FormValue)radioButtonFormValue ).GetPostBackValueKey() : context.Id ) ); + if( radioButtonFormValue != null ) + attributes.Add( Tuple.Create( "value", radioButtonListItemId ?? context.Id ) ); + if( pageModificationValue.Value ) + attributes.Add( Tuple.Create( "checked", "checked" ) ); + if( isReadOnly ) + attributes.Add( Tuple.Create( "disabled", "disabled" ) ); + + var jsInitStatements = StringTools.ConcatenateWithDelimiter( + " ", + !isReadOnly + ? SubmitButton.GetImplicitSubmissionKeyPressStatements( action, false ) + .Surround( "$( '#{0}' ).keypress( function( e ) {{ ".FormatWith( context.Id ), " } );" ) + : "", + jsClickStatementGetter().Surround( "$( '#{0}' ).click( function() {{ ".FormatWith( context.Id ), " } );" ) ); + + return new DisplayableElementLocalData( + "input", + new FocusabilityCondition( true ), + isFocused => { + if( isFocused ) + attributes.Add( Tuple.Create( "autofocus", "autofocus" ) ); + return new DisplayableElementFocusDependentData( + attributes: attributes, + includeIdAttribute: true, + jsInitStatements: jsInitStatements ); + } ); + }, + classes: elementClass ); + }, + formValue: formValue ).ToCollection() + .Concat( label.Any() ? new GenericPhrasingContainer( label, classes: elementClass ).ToCollection() : Enumerable.Empty<FlowComponent>() ) + .Materialize() ) ).ToCollection() ); + } + + FormControlLabeler FormControl<PhrasingComponent>.Labeler => null; + } +} \ No newline at end of file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
@@ -0,0 +1,47 @@
+namespace EnterpriseWebLibrary.EnterpriseWebFramework { + /// <summary> + /// The configuration for a checkbox. + /// </summary> + public class CheckboxSetup { + /// <summary> + /// Creates a setup object for a standard checkbox. + /// </summary> + /// <param name="displaySetup"></param> + /// <param name="classes">The classes on the control.</param> + /// <param name="action">The action that will occur when the user hits Enter on the control. Pass null to use the current default action.</param> + /// <param name="valueChangedAction">The action that will occur when the value is changed. Pass null for no action.</param> + /// <param name="pageModificationValue"></param> + public static CheckboxSetup Create( + DisplaySetup displaySetup = null, ElementClassSet classes = null, FormAction action = null, FormAction valueChangedAction = null, + PageModificationValue<bool> pageModificationValue = null ) { + return new CheckboxSetup( displaySetup, false, classes, action, valueChangedAction, pageModificationValue ); + } + + /// <summary> + /// Creates a setup object for a read-only checkbox. + /// </summary> + /// <param name="displaySetup"></param> + /// <param name="classes">The classes on the control.</param> + public static CheckboxSetup CreateReadOnly( DisplaySetup displaySetup = null, ElementClassSet classes = null ) { + return new CheckboxSetup( displaySetup, true, classes, null, null, null ); + } + + internal readonly DisplaySetup DisplaySetup; + internal readonly bool IsReadOnly; + internal readonly ElementClassSet Classes; + internal readonly FormAction Action; + internal readonly FormAction ValueChangedAction; + internal readonly PageModificationValue<bool> PageModificationValue; + + private CheckboxSetup( + DisplaySetup displaySetup, bool isReadOnly, ElementClassSet classes, FormAction action, FormAction valueChangedAction, + PageModificationValue<bool> pageModificationValue ) { + DisplaySetup = displaySetup; + IsReadOnly = isReadOnly; + Classes = classes; + Action = action ?? FormState.Current.DefaultAction; + ValueChangedAction = valueChangedAction; + PageModificationValue = pageModificationValue ?? new PageModificationValue<bool>(); + } + } +} \ No newline at end of file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
@@ -0,0 +1,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; + } +} \ No newline at end of file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
@@ -0,0 +1,71 @@
+using System; +using System.Collections.Generic; + +namespace EnterpriseWebLibrary.EnterpriseWebFramework { + /// <summary> + /// The configuration for a flow checkbox. + /// </summary> + public class FlowCheckboxSetup { + /// <summary> + /// Creates a setup object for a standard checkbox. + /// </summary> + /// <param name="displaySetup"></param> + /// <param name="classes">The classes on the container.</param> + /// <param name="highlightedWhenChecked"></param> + /// <param name="action">The action that will occur when the user hits Enter on the checkbox. Pass null to use the current default action.</param> + /// <param name="valueChangedAction">The action that will occur when the checkbox value is changed. Pass null for no action.</param> + /// <param name="pageModificationValue"></param> + /// <param name="nestedContentGetter">A function that gets the content that will appear beneath the checkbox.</param> + /// <param name="nestedContentAlwaysDisplayed">Pass true to force the nested content to always be displayed instead of only when the box is checked.</param> + public static FlowCheckboxSetup Create( + DisplaySetup displaySetup = null, ElementClassSet classes = null, bool highlightedWhenChecked = false, FormAction action = null, + FormAction valueChangedAction = null, PageModificationValue<bool> pageModificationValue = null, + Func<IReadOnlyCollection<FlowComponent>> nestedContentGetter = null, bool nestedContentAlwaysDisplayed = false ) { + return new FlowCheckboxSetup( + displaySetup, + classes, + CheckboxSetup.Create( action: action, valueChangedAction: valueChangedAction, pageModificationValue: pageModificationValue ), + highlightedWhenChecked, + nestedContentGetter, + nestedContentAlwaysDisplayed ); + } + + /// <summary> + /// Creates a setup object for a read-only checkbox. + /// </summary> + /// <param name="displaySetup"></param> + /// <param name="classes">The classes on the container.</param> + /// <param name="highlightedWhenChecked"></param> + /// <param name="nestedContentGetter">A function that gets the content that will appear beneath the checkbox.</param> + /// <param name="nestedContentAlwaysDisplayed">Pass true to force the nested content to always be displayed instead of only when the box is checked.</param> + public static FlowCheckboxSetup CreateReadOnly( + DisplaySetup displaySetup = null, ElementClassSet classes = null, bool highlightedWhenChecked = false, + Func<IReadOnlyCollection<FlowComponent>> nestedContentGetter = null, bool nestedContentAlwaysDisplayed = false ) { + return new FlowCheckboxSetup( + displaySetup, + classes, + CheckboxSetup.CreateReadOnly(), + highlightedWhenChecked, + nestedContentGetter, + nestedContentAlwaysDisplayed ); + } + + internal readonly DisplaySetup DisplaySetup; + internal readonly ElementClassSet Classes; + internal readonly CheckboxSetup CheckboxSetup; + internal readonly bool HighlightedWhenChecked; + internal readonly Func<IReadOnlyCollection<FlowComponent>> NestedContentGetter; + internal readonly bool NestedContentAlwaysDisplayed; + + private FlowCheckboxSetup( + DisplaySetup displaySetup, ElementClassSet classes, CheckboxSetup checkboxSetup, bool highlightedWhenChecked, + Func<IReadOnlyCollection<FlowComponent>> nestedContentGetter, bool nestedContentAlwaysDisplayed ) { + DisplaySetup = displaySetup; + Classes = classes; + CheckboxSetup = checkboxSetup; + HighlightedWhenChecked = highlightedWhenChecked; + NestedContentGetter = nestedContentGetter; + NestedContentAlwaysDisplayed = nestedContentAlwaysDisplayed; + } + } +} \ No newline at end of file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
@@ -0,0 +1,72 @@
+using System; +using System.Collections.Generic; + +namespace EnterpriseWebLibrary.EnterpriseWebFramework { + /// <summary> + /// The configuration for a flow radio button. + /// </summary> + public class FlowRadioButtonSetup { + /// <summary> + /// Creates a setup object for a standard radio button. + /// </summary> + /// <param name="displaySetup"></param> + /// <param name="classes">The classes on the container.</param> + /// <param name="highlightedWhenSelected"></param> + /// <param name="action">The action that will occur when the user hits Enter on the radio button. Pass null to use the current default action.</param> + /// <param name="pageModificationValue"></param> + /// <param name="nestedContentGetter">A function that gets the content that will appear beneath the radio button.</param> + /// <param name="nestedContentAlwaysDisplayed">Pass true to force the nested content to always be displayed instead of only when the button is selected. + /// </param> + public static FlowRadioButtonSetup Create( + DisplaySetup displaySetup = null, ElementClassSet classes = null, bool highlightedWhenSelected = false, FormAction action = null, + PageModificationValue<bool> pageModificationValue = null, Func<IReadOnlyCollection<FlowComponent>> nestedContentGetter = null, + bool nestedContentAlwaysDisplayed = false ) { + return new FlowRadioButtonSetup( + displaySetup, + classes, + RadioButtonSetup.Create( action: action, pageModificationValue: pageModificationValue ), + highlightedWhenSelected, + nestedContentGetter, + nestedContentAlwaysDisplayed ); + } + + /// <summary> + /// Creates a setup object for a read-only radio button. + /// </summary> + /// <param name="displaySetup"></param> + /// <param name="classes">The classes on the container.</param> + /// <param name="highlightedWhenSelected"></param> + /// <param name="nestedContentGetter">A function that gets the content that will appear beneath the radio button.</param> + /// <param name="nestedContentAlwaysDisplayed">Pass true to force the nested content to always be displayed instead of only when the button is selected. + /// </param> + public static FlowRadioButtonSetup CreateReadOnly( + DisplaySetup displaySetup = null, ElementClassSet classes = null, bool highlightedWhenSelected = false, + Func<IReadOnlyCollection<FlowComponent>> nestedContentGetter = null, bool nestedContentAlwaysDisplayed = false ) { + return new FlowRadioButtonSetup( + displaySetup, + classes, + RadioButtonSetup.CreateReadOnly(), + highlightedWhenSelected, + nestedContentGetter, + nestedContentAlwaysDisplayed ); + } + + internal readonly DisplaySetup DisplaySetup; + internal readonly ElementClassSet Classes; + internal readonly RadioButtonSetup RadioButtonSetup; + internal readonly bool HighlightedWhenSelected; + internal readonly Func<IReadOnlyCollection<FlowComponent>> NestedContentGetter; + internal readonly bool NestedContentAlwaysDisplayed; + + private FlowRadioButtonSetup( + DisplaySetup displaySetup, ElementClassSet classes, RadioButtonSetup radioButtonSetup, bool highlightedWhenSelected, + Func<IReadOnlyCollection<FlowComponent>> nestedContentGetter, bool nestedContentAlwaysDisplayed ) { + DisplaySetup = displaySetup; + Classes = classes; + RadioButtonSetup = radioButtonSetup; + HighlightedWhenSelected = highlightedWhenSelected; + NestedContentGetter = nestedContentGetter; + NestedContentAlwaysDisplayed = nestedContentAlwaysDisplayed; + } + } +} \ No newline at end of file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
@@ -0,0 +1,42 @@
+namespace EnterpriseWebLibrary.EnterpriseWebFramework { + /// <summary> + /// The configuration for a radio button. + /// </summary> + public class RadioButtonSetup { + /// <summary> + /// Creates a setup object for a standard radio button. + /// </summary> + /// <param name="displaySetup"></param> + /// <param name="classes">The classes on the control.</param> + /// <param name="action">The action that will occur when the user hits Enter on the control. Pass null to use the current default action.</param> + /// <param name="pageModificationValue"></param> + public static RadioButtonSetup Create( + DisplaySetup displaySetup = null, ElementClassSet classes = null, FormAction action = null, PageModificationValue<bool> pageModificationValue = null ) { + return new RadioButtonSetup( displaySetup, false, classes, action, pageModificationValue ); + } + + /// <summary> + /// Creates a setup object for a read-only radio button. + /// </summary> + /// <param name="displaySetup"></param> + /// <param name="classes">The classes on the control.</param> + public static RadioButtonSetup CreateReadOnly( DisplaySetup displaySetup = null, ElementClassSet classes = null ) { + return new RadioButtonSetup( displaySetup, true, classes, null, null ); + } + + internal readonly DisplaySetup DisplaySetup; + internal readonly bool IsReadOnly; + internal readonly ElementClassSet Classes; + internal readonly FormAction Action; + internal readonly PageModificationValue<bool> PageModificationValue; + + private RadioButtonSetup( + DisplaySetup displaySetup, bool isReadOnly, ElementClassSet classes, FormAction action, PageModificationValue<bool> pageModificationValue ) { + DisplaySetup = displaySetup; + IsReadOnly = isReadOnly; + Classes = classes; + Action = action ?? FormState.Current.DefaultAction; + PageModificationValue = pageModificationValue ?? new PageModificationValue<bool>(); + } + } +} \ No newline at end of file
 
411
412
413
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414
415
416
 
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
@@ -411,6 +411,180 @@
  }     /// <summary> + /// Creates a checkbox for this data value. + /// </summary> + /// <param name="dataValue"></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 checkbox.</param> + /// <param name="value"></param> + /// <param name="additionalValidationMethod"></param> + public static Checkbox ToCheckbox( + this DataValue<bool> dataValue, IReadOnlyCollection<PhrasingComponent> label, CheckboxSetup setup = null, bool? value = null, + Action<Validator> additionalValidationMethod = null ) { + return new Checkbox( + value ?? dataValue.Value, + label, + setup: setup, + validationMethod: ( postBackValue, validator ) => { + dataValue.Value = postBackValue.Value; + additionalValidationMethod?.Invoke( validator ); + } ); + } + + /// <summary> + /// Creates a checkbox for this data value. + /// </summary> + /// <param name="dataValue"></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 checkbox.</param> + /// <param name="value"></param> + /// <param name="additionalValidationMethod"></param> + public static Checkbox ToCheckbox( + this DataValue<decimal> dataValue, IReadOnlyCollection<PhrasingComponent> label, CheckboxSetup setup = null, decimal? value = null, + Action<Validator> additionalValidationMethod = null ) { + var boolValue = new DataValue<bool> { Value = ( value ?? dataValue.Value ).DecimalToBoolean() }; + return boolValue.ToCheckbox( + label, + setup: setup, + additionalValidationMethod: validator => { + dataValue.Value = boolValue.Value.BooleanToDecimal(); + additionalValidationMethod?.Invoke( validator ); + } ); + } + + /// <summary> + /// Creates a flow checkbox for this data value. + /// </summary> + /// <param name="dataValue"></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="value"></param> + /// <param name="additionalValidationMethod"></param> + public static FlowCheckbox ToFlowCheckbox( + this DataValue<bool> dataValue, IReadOnlyCollection<PhrasingComponent> label, FlowCheckboxSetup setup = null, bool? value = null, + Action<Validator> additionalValidationMethod = null ) { + return new FlowCheckbox( + value ?? dataValue.Value, + label, + setup: setup, + validationMethod: ( postBackValue, validator ) => { + dataValue.Value = postBackValue.Value; + additionalValidationMethod?.Invoke( validator ); + } ); + } + + /// <summary> + /// Creates a flow checkbox for this data value. + /// </summary> + /// <param name="dataValue"></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="value"></param> + /// <param name="additionalValidationMethod"></param> + public static FlowCheckbox ToFlowCheckbox( + this DataValue<decimal> dataValue, IReadOnlyCollection<PhrasingComponent> label, FlowCheckboxSetup setup = null, decimal? value = null, + Action<Validator> additionalValidationMethod = null ) { + var boolValue = new DataValue<bool> { Value = ( value ?? dataValue.Value ).DecimalToBoolean() }; + return boolValue.ToFlowCheckbox( + label, + setup: setup, + additionalValidationMethod: validator => { + dataValue.Value = boolValue.Value.BooleanToDecimal(); + additionalValidationMethod?.Invoke( validator ); + } ); + } + + /// <summary> + /// Creates a radio button for this data value. + /// </summary> + /// <param name="dataValue"></param> + /// <param name="group">The group of which this radio button will be a part. Do not pass null.</param> + /// <param name="label">The radio button label. Do not pass null. Pass an empty collection for no label.</param> + /// <param name="setup">The setup object for the radio button.</param> + /// <param name="value"></param> + /// <param name="additionalValidationMethod"></param> + public static Checkbox ToRadioButton( + this DataValue<bool> dataValue, RadioButtonGroup group, IReadOnlyCollection<PhrasingComponent> label, RadioButtonSetup setup = null, bool? value = null, + Action<Validator> additionalValidationMethod = null ) { + return group.CreateRadioButton( + value ?? dataValue.Value, + label, + setup: setup, + validationMethod: ( postBackValue, validator ) => { + dataValue.Value = postBackValue.Value; + additionalValidationMethod?.Invoke( validator ); + } ); + } + + /// <summary> + /// Creates a radio button for this data value. + /// </summary> + /// <param name="dataValue"></param> + /// <param name="group">The group of which this radio button will be a part. Do not pass null.</param> + /// <param name="label">The radio button label. Do not pass null. Pass an empty collection for no label.</param> + /// <param name="setup">The setup object for the radio button.</param> + /// <param name="value"></param> + /// <param name="additionalValidationMethod"></param> + public static Checkbox ToRadioButton( + this DataValue<decimal> dataValue, RadioButtonGroup group, IReadOnlyCollection<PhrasingComponent> label, RadioButtonSetup setup = null, + decimal? value = null, Action<Validator> additionalValidationMethod = null ) { + var boolValue = new DataValue<bool> { Value = ( value ?? dataValue.Value ).DecimalToBoolean() }; + return boolValue.ToRadioButton( + group, + label, + setup: setup, + additionalValidationMethod: validator => { + dataValue.Value = boolValue.Value.BooleanToDecimal(); + additionalValidationMethod?.Invoke( validator ); + } ); + } + + /// <summary> + /// Creates a flow radio button for this data value. + /// </summary> + /// <param name="dataValue"></param> + /// <param name="group">The group of which this radio button will be a part. Do not pass null.</param> + /// <param name="label">The radio button label. Do not pass null. Pass an empty collection for no label.</param> + /// <param name="setup">The setup object for the flow radio button.</param> + /// <param name="value"></param> + /// <param name="additionalValidationMethod"></param> + public static FlowCheckbox ToFlowRadioButton( + this DataValue<bool> dataValue, RadioButtonGroup group, IReadOnlyCollection<PhrasingComponent> label, FlowRadioButtonSetup setup = null, + bool? value = null, Action<Validator> additionalValidationMethod = null ) { + return group.CreateFlowRadioButton( + value ?? dataValue.Value, + label, + setup: setup, + validationMethod: ( postBackValue, validator ) => { + dataValue.Value = postBackValue.Value; + additionalValidationMethod?.Invoke( validator ); + } ); + } + + /// <summary> + /// Creates a flow radio button for this data value. + /// </summary> + /// <param name="dataValue"></param> + /// <param name="group">The group of which this radio button will be a part. Do not pass null.</param> + /// <param name="label">The radio button label. Do not pass null. Pass an empty collection for no label.</param> + /// <param name="setup">The setup object for the flow radio button.</param> + /// <param name="value"></param> + /// <param name="additionalValidationMethod"></param> + public static FlowCheckbox ToFlowRadioButton( + this DataValue<decimal> dataValue, RadioButtonGroup group, IReadOnlyCollection<PhrasingComponent> label, FlowRadioButtonSetup setup = null, + decimal? value = null, Action<Validator> additionalValidationMethod = null ) { + var boolValue = new DataValue<bool> { Value = ( value ?? dataValue.Value ).DecimalToBoolean() }; + return boolValue.ToFlowRadioButton( + group, + label, + setup: setup, + additionalValidationMethod: validator => { + dataValue.Value = boolValue.Value.BooleanToDecimal(); + additionalValidationMethod?.Invoke( validator ); + } ); + } + + /// <summary>   /// Creates a block checkbox for this data value.   /// </summary>   /// <param name="dataValue"></param>
Change 1 of 7 Show Entire File Core/​EnterpriseWebFramework/​Form Controls/​Lists/​Free-Form Radio List/​FreeFormRadioList.cs Stacked
renamed from Core/EnterpriseWebFramework/Form Controls/Lists/FreeFormRadioList.cs
 
5
6
7
 
8
 
9
10
11
12
 
13
14
15
16
17
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
20
21
 
24
25
26
27
 
28
29
30
31
 
32
33
34
 
41
42
43
44
 
45
46
47
48
49
50
51
 
52
53
54
55
56
57
 
58
59
60
 
65
66
67
68
 
69
70
71
 
76
77
78
79
 
 
80
81
82
 
84
85
86
87
 
 
88
89
90
 
127
128
129
130
 
 
131
132
133
 
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
 
169
170
171
 
172
173
174
175
 
176
177
178
179
 
186
187
188
 
189
190
191
192
193
194
195
 
196
197
198
199
200
201
 
202
203
204
205
 
210
211
212
 
213
214
215
216
 
221
222
223
 
224
225
226
227
228
 
230
231
232
 
233
234
235
236
237
 
274
275
276
 
277
278
279
280
281
@@ -5,17 +5,162 @@
 using System.Web.UI;  using System.Web.UI.WebControls;  using EnterpriseWebLibrary.EnterpriseWebFramework.DisplayLinking; +using EnterpriseWebLibrary.InputValidation;  using Humanizer; +using MoreLinq;    namespace EnterpriseWebLibrary.EnterpriseWebFramework {   /// <summary> - /// A radio button list that allows you to arrange the buttons on the page however you wish. If you want access to the individual selection state of each + /// A radio-button list that allows you to arrange the buttons on the page however you wish. If you want access to the individual selection state of each   /// radio button and do not need the concept of a selected item ID for the group, use RadioButtonGroup instead.   /// </summary>   public static class FreeFormRadioList {   /// <summary>   /// Creates a free-form radio button list.   /// </summary> + /// <param name="noSelectionIsValid">Pass a value to cause a selected item ID with the default value (or the empty string when the item ID type is string) + /// to represent the state in which none of the radio buttons are selected. Note that this is not recommended by the Nielsen Norman Group; see + /// http://www.nngroup.com/articles/checkboxes-vs-radio-buttons/ for more information. If you do pass a value, passing true will cause this no-selection + /// state to be valid.</param> + /// <param name="selectedItemId"></param> + /// <param name="setup">The setup object for the free-form radio list.</param> + /// <param name="validationMethod">The validation method. Pass null if you�re only using this radio-button list for page modification.</param> + public static FreeFormRadioList<ItemIdType> Create<ItemIdType>( + bool? noSelectionIsValid, ItemIdType selectedItemId, FreeFormRadioListSetup<ItemIdType> setup = null, + Action<ItemIdType, Validator> validationMethod = null ) { + return new FreeFormRadioList<ItemIdType>( noSelectionIsValid, setup, selectedItemId, validationMethod ); + } + } + + /// <summary> + /// A radio-button list that allows you to arrange the buttons on the page however you wish. If you want access to the individual selection state of each + /// radio button and do not need the concept of a selected item ID for the group, use RadioButtonGroup instead. + /// </summary> + public class FreeFormRadioList<ItemIdType> { + private readonly FormValue<ElementId> formValue; + private readonly bool? noSelectionIsValid; + + private readonly List<( ItemIdType itemId, ElementId buttonId, bool isReadOnly, PageModificationValue<bool> pmv )> + itemIdAndButtonIdAndIsReadOnlyAndPmvQuadruples = new List<( ItemIdType, ElementId, bool, PageModificationValue<bool> )>(); + + private readonly FreeFormRadioListSetup<ItemIdType> listSetup; + private readonly EwfValidation validation; + + internal FreeFormRadioList( + bool? noSelectionIsValid, FreeFormRadioListSetup<ItemIdType> setup, ItemIdType selectedItemId, Action<ItemIdType, Validator> validationMethod ) { + setup = setup ?? FreeFormRadioListSetup.Create<ItemIdType>(); + + formValue = RadioButtonGroup.GetFormValue( + () => from i in itemIdAndButtonIdAndIsReadOnlyAndPmvQuadruples select ( i.buttonId, i.isReadOnly, EwlStatics.AreEqual( i.itemId, selectedItemId ) ), + v => getStringId( v != null ? itemIdAndButtonIdAndIsReadOnlyAndPmvQuadruples.Single( i => i.buttonId == v ).itemId : getNoSelectionItemId() ), + rawValue => from quadruple in itemIdAndButtonIdAndIsReadOnlyAndPmvQuadruples + let buttonId = quadruple.buttonId + where buttonId.Id.Any() && !quadruple.isReadOnly && getStringId( quadruple.itemId ) == rawValue + select buttonId, + noSelectionIsValid.HasValue ); + + this.noSelectionIsValid = noSelectionIsValid; + listSetup = setup; + + if( setup.ItemIdPageModificationValue != null ) + formValue.AddPageModificationValue( setup.ItemIdPageModificationValue, getItemIdFromButtonId ); + + foreach( var i in setup.ItemMatchPageModificationSetups ) + formValue.AddPageModificationValue( i.PageModificationValue, v => i.ItemIds.Contains( getItemIdFromButtonId( v ) ) ); + + if( validationMethod != null ) + validation = formValue.CreateValidation( + ( postBackValue, validator ) => { + if( setup.ValidationPredicate != null && !setup.ValidationPredicate( postBackValue.ChangedOnPostBack ) ) + return; + + var postBackItemId = getItemIdFromButtonId( postBackValue.Value ); + if( noSelectionIsValid == false && EwlStatics.AreEqual( postBackItemId, getNoSelectionItemId() ) ) { + validator.NoteErrorAndAddMessage( "Please make a selection." ); + setup.ValidationErrorNotifier?.Invoke(); + return; + } + + validationMethod( postBackItemId, validator ); + } ); + + EwfPage.Instance.AddControlTreeValidation( + () => RadioButtonGroup.ValidateControls( + noSelectionIsValid.HasValue, + EwlStatics.AreEqual( getNoSelectionItemId(), selectedItemId ), + from i in itemIdAndButtonIdAndIsReadOnlyAndPmvQuadruples select ( i.buttonId, i.isReadOnly, EwlStatics.AreEqual( i.itemId, selectedItemId ) ), + setup.DisableSingleButtonDetection ) ); + } + + private ItemIdType getItemIdFromButtonId( ElementId buttonId ) => + itemIdAndButtonIdAndIsReadOnlyAndPmvQuadruples.Where( i => i.buttonId == buttonId ) + .Select( i => i.itemId ) + .FallbackIfEmpty( getNoSelectionItemId() ) + .Single(); + + /// <summary> + /// Creates a radio button that is part of the list. + /// </summary> + /// <param name="listItemId"></param> + /// <param name="label">The radio button label. Do not pass null. Pass an empty collection for no label.</param> + /// <param name="setup">The setup object for the radio button.</param> + public Checkbox CreateRadioButton( ItemIdType listItemId, IReadOnlyCollection<PhrasingComponent> label, RadioButtonSetup setup = null ) { + setup = setup ?? RadioButtonSetup.Create(); + + validateListItem( listItemId ); + + var id = new ElementId(); + formValue.AddPageModificationValue( setup.PageModificationValue, v => v == id ); + itemIdAndButtonIdAndIsReadOnlyAndPmvQuadruples.Add( ( listItemId, id, setup.IsReadOnly, setup.PageModificationValue ) ); + + return new Checkbox( + formValue, + id, + setup, + label, + listSetup.SelectionChangedAction, + () => StringTools.ConcatenateWithDelimiter( + " ", + ( listSetup.ItemIdPageModificationValue?.GetJsModificationStatements( "'{0}'".FormatWith( getStringId( listItemId ) ) ) ?? "" ).ToCollection() + .Concat( + listSetup.ItemMatchPageModificationSetups.Select( + i => i.PageModificationValue.GetJsModificationStatements( i.ItemIds.Contains( listItemId ) ? "true" : "false" ) ) ) + .Concat( itemIdAndButtonIdAndIsReadOnlyAndPmvQuadruples.Select( i => i.pmv.GetJsModificationStatements( i.buttonId == id ? "true" : "false" ) ) ) + .ToArray() ), + null, + listItemId: getStringId( listItemId ) ); + } + + /// <summary> + /// Creates a flow radio button that is part of the list. + /// </summary> + /// <param name="listItemId"></param> + /// <param name="label">The radio button label. Do not pass null. Pass an empty collection for no label.</param> + /// <param name="setup">The setup object for the flow radio button.</param> + public FlowCheckbox CreateBlockRadioButton( ItemIdType listItemId, IReadOnlyCollection<PhrasingComponent> label, FlowRadioButtonSetup setup = null ) { + setup = setup ?? FlowRadioButtonSetup.Create(); + return new FlowCheckbox( setup, CreateRadioButton( listItemId, label, setup: setup.RadioButtonSetup ) ); + } + + private void validateListItem( ItemIdType listItemId ) { + if( noSelectionIsValid.HasValue && EwlStatics.AreEqual( listItemId, getNoSelectionItemId() ) ) + throw new ApplicationException( "You cannot create a radio button with the ID that represents no selection." ); + if( itemIdAndButtonIdAndIsReadOnlyAndPmvQuadruples.Any( i => getStringId( i.itemId ) == getStringId( listItemId ) ) ) + throw new ApplicationException( "Item IDs, when converted to strings, must be unique." ); + } + + private ItemIdType getNoSelectionItemId() => EwlStatics.GetDefaultValue<ItemIdType>( true ); + + private string getStringId( ItemIdType id ) => id.ToString(); + + public EwfValidation Validation => validation; + } + + [ Obsolete( "Guaranteed through 28 Feb 2019. Use FreeFormRadioList instead." ) ] + public static class LegacyFreeFormRadioList { + /// <summary> + /// Creates a free-form radio button list. + /// </summary>   /// <param name="allowNoSelection">Pass true to cause a selected item ID with the default value (or the empty string when the item ID type is string) to   /// represent the state in which none of the radio buttons are selected. Note that this is not recommended by the Nielsen Norman Group; see   /// http://www.nngroup.com/articles/checkboxes-vs-radio-buttons/ for more information.</param> @@ -24,11 +169,11 @@
  /// violates the HTML specification.</param>   /// <param name="itemIdPageModificationValue"></param>   /// <param name="itemMatchPageModificationSetups"></param> - public static FreeFormRadioList<ItemIdType> Create<ItemIdType>( + public static LegacyFreeFormRadioList<ItemIdType> Create<ItemIdType>(   bool allowNoSelection, ItemIdType selectedItemId, bool disableSingleButtonDetection = false,   PageModificationValue<ItemIdType> itemIdPageModificationValue = null,   IEnumerable<ListItemMatchPageModificationSetup<ItemIdType>> itemMatchPageModificationSetups = null ) { - return new FreeFormRadioList<ItemIdType>( + return new LegacyFreeFormRadioList<ItemIdType>(   allowNoSelection,   disableSingleButtonDetection,   selectedItemId, @@ -41,20 +186,20 @@
  /// A radio button list that allows you to arrange the buttons on the page however you wish. If you want access to the individual selection state of each   /// radio button and do not need the concept of a selected item ID for the group, use RadioButtonGroup instead.   /// </summary> - public class FreeFormRadioList<ItemIdType>: DisplayLink { + public class LegacyFreeFormRadioList<ItemIdType>: DisplayLink {   private readonly bool allowNoSelection;   private readonly FormValue<CommonCheckBox> formValue;   private readonly List<Action<PostBackValueDictionary>> displayLinkingSetInitialDisplayMethods = new List<Action<PostBackValueDictionary>>();   private readonly List<Action> displayLinkingAddJavaScriptMethods = new List<Action>();   private readonly List<Tuple<ItemIdType, CommonCheckBox>> itemIdsAndCheckBoxes = new List<Tuple<ItemIdType, CommonCheckBox>>();   - internal FreeFormRadioList( + internal LegacyFreeFormRadioList(   bool allowNoSelection, bool disableSingleButtonDetection, ItemIdType selectedItemId, PageModificationValue<ItemIdType> itemIdPageModificationValue,   IEnumerable<ListItemMatchPageModificationSetup<ItemIdType>> itemMatchPageModificationSetups ) {   itemMatchPageModificationSetups = itemMatchPageModificationSetups ?? ImmutableArray<ListItemMatchPageModificationSetup<ItemIdType>>.Empty;     this.allowNoSelection = allowNoSelection; - formValue = RadioButtonGroup.GetFormValue( + formValue = LegacyRadioButtonGroup.GetFormValue(   allowNoSelection,   () => from i in itemIdsAndCheckBoxes select i.Item2,   () => from i in itemIdsAndCheckBoxes where EwlStatics.AreEqual( i.Item1, selectedItemId ) select i.Item2, @@ -65,7 +210,7 @@
  select itemIdAndCheckBox.Item2 );     EwfPage.Instance.AddControlTreeValidation( - () => RadioButtonGroup.ValidateControls( + () => LegacyRadioButtonGroup.ValidateControls(   allowNoSelection,   EwlStatics.AreEqual( getNoSelectionItemId(), selectedItemId ),   itemIdsAndCheckBoxes.Select( i => i.Item2 ), @@ -76,7 +221,8 @@
  displayLinkingAddJavaScriptMethods.Add(   () => {   foreach( var pair in itemIdsAndCheckBoxes ) - pair.Item2.AddOnClickJsMethod( itemIdPageModificationValue.GetJsModificationStatements( "'{0}'".FormatWith( pair.Item1.ObjectToString( true ) ) ) ); + pair.Item2.AddOnClickJsMethod( + itemIdPageModificationValue.GetJsModificationStatements( "'{0}'".FormatWith( pair.Item1.ObjectToString( true ) ) ) );   } );   }   foreach( var setup in itemMatchPageModificationSetups ) { @@ -84,7 +230,8 @@
  displayLinkingAddJavaScriptMethods.Add(   () => {   foreach( var pair in itemIdsAndCheckBoxes ) - pair.Item2.AddOnClickJsMethod( setup.PageModificationValue.GetJsModificationStatements( setup.ItemIds.Contains( pair.Item1 ) ? "true" : "false" ) ); + pair.Item2.AddOnClickJsMethod( + setup.PageModificationValue.GetJsModificationStatements( setup.ItemIds.Contains( pair.Item1 ) ? "true" : "false" ) );   } );   }   @@ -127,7 +274,8 @@
  /// Creates a block-level radio button that is part of the list.   /// </summary>   public BlockCheckBox CreateBlockRadioButton( - ItemIdType listItemId, string label = "", FormAction action = null, bool autoPostBack = false, Func<IEnumerable<Control>> nestedControlListGetter = null ) { + ItemIdType listItemId, string label = "", FormAction action = null, bool autoPostBack = false, + Func<IEnumerable<Control>> nestedControlListGetter = null ) {   validateListItem( listItemId );   var checkBox = new BlockCheckBox(   formValue,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
@@ -0,0 +1,60 @@
+using System; +using System.Collections.Generic; +using System.Linq; + +namespace EnterpriseWebLibrary.EnterpriseWebFramework { + /// <summary> + /// The configuration for a free-form radio list. + /// </summary> + public static class FreeFormRadioListSetup { + /// <summary> + /// Creates a setup object for a free-form radio list. + /// </summary> + /// <param name="disableSingleButtonDetection">Pass true to allow just a single radio button to be displayed for this list. Use with caution, as this + /// violates the HTML specification.</param> + /// <param name="selectionChangedAction">The action that will occur when the selection is changed. Pass null for no action.</param> + /// <param name="itemIdPageModificationValue"></param> + /// <param name="itemMatchPageModificationSetups"></param> + /// <param name="validationPredicate"></param> + /// <param name="validationErrorNotifier"></param> + public static FreeFormRadioListSetup<ItemIdType> Create<ItemIdType>( + bool disableSingleButtonDetection = false, FormAction selectionChangedAction = null, PageModificationValue<ItemIdType> itemIdPageModificationValue = null, + IReadOnlyCollection<ListItemMatchPageModificationSetup<ItemIdType>> itemMatchPageModificationSetups = null, Func<bool, bool> validationPredicate = null, + Action validationErrorNotifier = null ) { + return new FreeFormRadioListSetup<ItemIdType>( + disableSingleButtonDetection, + selectionChangedAction, + itemIdPageModificationValue, + itemMatchPageModificationSetups, + validationPredicate, + validationErrorNotifier ); + } + } + + /// <summary> + /// The configuration for a free-form radio list. + /// </summary> + public class FreeFormRadioListSetup<ItemIdType> { + internal readonly bool DisableSingleButtonDetection; + internal readonly FormAction SelectionChangedAction; + internal readonly PageModificationValue<ItemIdType> ItemIdPageModificationValue; + internal readonly IReadOnlyCollection<ListItemMatchPageModificationSetup<ItemIdType>> ItemMatchPageModificationSetups; + internal readonly Func<bool, bool> ValidationPredicate; + internal readonly Action ValidationErrorNotifier; + + /// <summary> + /// Creates a setup object for a free-form radio list. + /// </summary> + internal FreeFormRadioListSetup( + bool disableSingleButtonDetection, FormAction selectionChangedAction, PageModificationValue<ItemIdType> itemIdPageModificationValue, + IReadOnlyCollection<ListItemMatchPageModificationSetup<ItemIdType>> itemMatchPageModificationSetups, Func<bool, bool> validationPredicate, + Action validationErrorNotifier ) { + DisableSingleButtonDetection = disableSingleButtonDetection; + SelectionChangedAction = selectionChangedAction; + ItemIdPageModificationValue = itemIdPageModificationValue; + ItemMatchPageModificationSetups = itemMatchPageModificationSetups ?? Enumerable.Empty<ListItemMatchPageModificationSetup<ItemIdType>>().Materialize(); + ValidationPredicate = validationPredicate; + ValidationErrorNotifier = validationErrorNotifier; + } + } +} \ No newline at end of file
 
162
163
164
165
 
166
167
168
 
227
228
229
230
 
231
232
233
 
162
163
164
 
165
166
167
168
 
227
228
229
 
230
231
232
233
@@ -162,7 +162,7 @@
  private readonly List<Tuple<IEnumerable<ItemIdType>, bool, IEnumerable<System.Web.UI.WebControls.WebControl>>> displayLinks =   new List<Tuple<IEnumerable<ItemIdType>, bool, IEnumerable<System.Web.UI.WebControls.WebControl>>>();   - private FreeFormRadioList<ItemIdType> radioList; + private LegacyFreeFormRadioList<ItemIdType> radioList;   private EwfCheckBox firstRadioButton;   private FormValue<ItemIdType> formValue;   private System.Web.UI.WebControls.WebControl selectControl; @@ -227,7 +227,7 @@
    void ControlTreeDataLoader.LoadData() {   if( useHorizontalRadioLayout.HasValue ) { - radioList = FreeFormRadioList.Create( + radioList = LegacyFreeFormRadioList.Create(   items.Any( i => !i.IsValid ),   selectedItemId,   disableSingleButtonDetection: disableSingleRadioButtonDetection.Value,
 
211
212
213
214
215
216
217
 
 
 
 
 
218
219
220
 
211
212
213
 
 
 
 
214
215
216
217
218
219
220
221
@@ -211,10 +211,11 @@
  context.Id,   "setTimeout( function() { " + valueChangedAction.GetJsStatements() + " }, 0 );" )   : "", - isImprecise - ? ( (PageModificationValue<decimal>)pageModificationValue ).GetJsModificationStatements( "Number( $( this ).val() )" ) - : ( (PageModificationValue<decimal?>)pageModificationValue ).GetJsModificationStatements( "Number( $( this ).val() )" ) - .Surround( "$( '#{0}' ).change( function() {{ ".FormatWith( context.Id ), " } );" ), + ( isImprecise + ? ( (PageModificationValue<decimal>)pageModificationValue ).GetJsModificationStatements( "Number( $( this ).val() )" ) + : ( (PageModificationValue<decimal?>)pageModificationValue ).GetJsModificationStatements( "Number( $( this ).val() )" ) ).Surround( + "$( '#{0}' ).change( function() {{ ".FormatWith( context.Id ), + " } );" ),   autoCompleteStatements );     return new DisplayableElementLocalData(
 
10
11
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
14
15
 
66
67
68
69
 
70
71
72
 
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
 
193
194
195
 
196
197
198
199
@@ -10,6 +10,133 @@
  /// ID for the group. Otherwise use FreeFormRadioList.   /// </summary>   public class RadioButtonGroup { + internal static FormValue<ElementId> GetFormValue( + Func<IEnumerable<( ElementId id, bool isReadOnly, bool isSelected )>> buttonGetter, Func<ElementId, string> stringValueSelector, + Func<string, IEnumerable<ElementId>> selectedButtonIdInPostBackGetter, bool allowsNoSelection ) { + FormValue<ElementId> formValue = null; + return formValue = new FormValue<ElementId>( + () => buttonGetter().Where( i => i.isSelected ).Select( i => i.id ).FirstOrDefault(), + () => buttonGetter().Where( i => i.id.Id.Any() && !i.isReadOnly ).Select( i => i.id ).FirstOrDefault()?.Id ?? "", + stringValueSelector, + rawValue => { + if( rawValue != null ) { + var selectedButtonId = selectedButtonIdInPostBackGetter( rawValue ).SingleOrDefault(); + return selectedButtonId != null + ? PostBackValueValidationResult<ElementId>.CreateValid( selectedButtonId ) + : PostBackValueValidationResult<ElementId>.CreateInvalid(); + } + + var durableValue = formValue.GetDurableValue(); + if( durableValue != null ) { + var button = buttonGetter().Single( i => i.id == durableValue ); + if( !button.id.Id.Any() || button.isReadOnly ) + return PostBackValueValidationResult<ElementId>.CreateValid( durableValue ); + } + + return allowsNoSelection + ? PostBackValueValidationResult<ElementId>.CreateValid( null ) + : PostBackValueValidationResult<ElementId>.CreateInvalid(); + } ); + } + + internal static void ValidateControls( + bool allowsNoSelection, bool inNoSelectionState, IEnumerable<( ElementId id, bool isReadOnly, bool isSelected )> buttons, + bool disableSingleButtonDetection ) { + if( ( !allowsNoSelection || !inNoSelectionState ) && buttons.Count( i => i.isSelected ) != 1 ) + throw new ApplicationException( "If a radio button group is not in the no-selection state, then exactly one radio button must be selected." ); + + var activeButtons = buttons.Where( i => i.id.Id.Any() && !i.isReadOnly ).Materialize(); + if( activeButtons.Any() && !disableSingleButtonDetection && activeButtons.Count < 2 ) { + const string link = "http://developers.whatwg.org/states-of-the-type-attribute.html#radio-button-state-%28type=radio%29"; + throw new ApplicationException( "A radio button group must contain more than one element; see " + link + "." ); + } + } + + private readonly FormValue<ElementId> formValue; + + private readonly List<( ElementId id, bool isReadOnly, bool value, PageModificationValue<bool> pmv )> buttonIdAndIsReadOnlyAndValueAndPmvQuadruples = + new List<( ElementId, bool, bool, PageModificationValue<bool> )>(); + + private readonly FormAction selectionChangedAction; + + /// <summary> + /// Creates a radio button group. + /// </summary> + /// <param name="allowNoSelection">Pass true to allow the state in which none of the radio buttons are selected. Note that this is not recommended by the + /// Nielsen Norman Group; see http://www.nngroup.com/articles/checkboxes-vs-radio-buttons/ for more information.</param> + /// <param name="disableSingleButtonDetection">Pass true to allow just a single radio button to be displayed for this group. Use with caution, as this + /// violates the HTML specification.</param> + /// <param name="selectionChangedAction">The action that will occur when the selection is changed. Pass null for no action.</param> + public RadioButtonGroup( bool allowNoSelection, bool disableSingleButtonDetection = false, FormAction selectionChangedAction = null ) { + formValue = GetFormValue( + () => from i in buttonIdAndIsReadOnlyAndValueAndPmvQuadruples select ( i.id, i.isReadOnly, i.value ), + v => v?.Id ?? "", + rawValue => from quadruple in buttonIdAndIsReadOnlyAndValueAndPmvQuadruples + let id = quadruple.id + where id.Id.Any() && !quadruple.isReadOnly && id.Id == rawValue + select id, + allowNoSelection ); + + this.selectionChangedAction = selectionChangedAction; + + EwfPage.Instance.AddControlTreeValidation( + () => ValidateControls( + allowNoSelection, + buttonIdAndIsReadOnlyAndValueAndPmvQuadruples.All( i => !i.value ), + from i in buttonIdAndIsReadOnlyAndValueAndPmvQuadruples select ( i.id, i.isReadOnly, i.value ), + disableSingleButtonDetection ) ); + } + + /// <summary> + /// Creates a radio button that is part of the group. + /// </summary> + /// <param name="value"></param> + /// <param name="label">The radio button label. Do not pass null. Pass an empty collection for no label.</param> + /// <param name="setup">The setup object for the radio button.</param> + /// <param name="validationMethod">The validation method. Pass null if you’re only using this control for page modification.</param> + public Checkbox CreateRadioButton( + bool value, IReadOnlyCollection<PhrasingComponent> label, RadioButtonSetup setup = null, + Action<PostBackValue<bool>, Validator> validationMethod = null ) { + setup = setup ?? RadioButtonSetup.Create(); + + var id = new ElementId(); + formValue.AddPageModificationValue( setup.PageModificationValue, v => v == id ); + buttonIdAndIsReadOnlyAndValueAndPmvQuadruples.Add( ( id, setup.IsReadOnly, value, setup.PageModificationValue ) ); + + return new Checkbox( + formValue, + id, + setup, + label, + selectionChangedAction, + () => StringTools.ConcatenateWithDelimiter( + " ", + buttonIdAndIsReadOnlyAndValueAndPmvQuadruples.Select( i => i.pmv.GetJsModificationStatements( i.id == id ? "true" : "false" ) ).ToArray() ), + validationMethod != null + ? formValue.CreateValidation( + ( postBackValue, validator ) => validationMethod( + new PostBackValue<bool>( postBackValue.Value == id, postBackValue.ChangedOnPostBack ), + validator ) ) + : null ); + } + + /// <summary> + /// Creates a flow radio button that is part of the group. + /// </summary> + /// <param name="value"></param> + /// <param name="label">The radio button label. Do not pass null. Pass an empty collection for no label.</param> + /// <param name="setup">The setup object for the flow radio button.</param> + /// <param name="validationMethod">The validation method. Pass null if you’re only using the radio button for page modification.</param> + public FlowCheckbox CreateFlowRadioButton( + bool value, IReadOnlyCollection<PhrasingComponent> label, FlowRadioButtonSetup setup = null, + Action<PostBackValue<bool>, Validator> validationMethod = null ) { + setup = setup ?? FlowRadioButtonSetup.Create(); + return new FlowCheckbox( setup, CreateRadioButton( value, label, setup: setup.RadioButtonSetup, validationMethod: validationMethod ) ); + } + } + + [ Obsolete( "Guaranteed through 28 Feb 2019. Use RadioButtonGroup instead." ) ] + public class LegacyRadioButtonGroup {   internal static FormValue<CommonCheckBox> GetFormValue(   bool allowsNoSelection, Func<IEnumerable<CommonCheckBox>> allCheckBoxesGetter, Func<IEnumerable<CommonCheckBox>> checkedCheckBoxesGetter,   Func<CommonCheckBox, string> stringValueSelector, Func<string, IEnumerable<CommonCheckBox>> checkedCheckBoxesInPostBackGetter ) { @@ -66,7 +193,7 @@
  /// Nielsen Norman Group; see http://www.nngroup.com/articles/checkboxes-vs-radio-buttons/ for more information.</param>   /// <param name="disableSingleButtonDetection">Pass true to allow just a single radio button to be displayed for this group. Use with caution, as this   /// violates the HTML specification.</param> - public RadioButtonGroup( bool allowNoSelection, bool disableSingleButtonDetection = false ) { + public LegacyRadioButtonGroup( bool allowNoSelection, bool disableSingleButtonDetection = false ) {   formValue = GetFormValue(   allowNoSelection,   () => from i in checkBoxesAndSelectionStatesAndPageModificationValues select i.Item1,
 
3
4
5
6
7
8
9
10
11
12
 
 
 
13
14
15
 
3
4
5
 
 
 
 
 
 
 
6
7
8
9
10
11
@@ -3,13 +3,9 @@
   namespace EnterpriseWebLibrary.EnterpriseWebFramework {   public abstract class AutoCompleteService: EwfPage { - protected override EwfSafeResponseWriter responseWriter { - get { - return - new EwfSafeResponseWriter( - EwfResponse.Create( ContentTypes.PlainText, new EwfResponseBodyCreator( () => new JavaScriptSerializer().Serialize( getItems() ) ) ) ); - } - } + protected override EwfSafeRequestHandler requestHandler => + new EwfSafeResponseWriter( + EwfResponse.Create( ContentTypes.PlainText, new EwfResponseBodyCreator( () => new JavaScriptSerializer().Serialize( getItems() ) ) ) );     protected abstract IEnumerable<AutoCompleteItem> getItems();   }
 
1
 
 
 
2
3
4
 
30
31
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
 
 
1
2
3
4
5
6
 
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 
@@ -1,4 +1,6 @@
-using System.Collections.Generic; +using System; +using System.Collections.Generic; +using Humanizer;    namespace EnterpriseWebLibrary.EnterpriseWebFramework {   /// <summary> @@ -30,4 +32,24 @@
  return children;   }   } + + public static class GenericPhrasingContainerExtensionCreators { + /// <summary> + /// Creates a generic phrasing container (i.e. span element) that depends on this page-modification value. + /// </summary> + public static IReadOnlyCollection<PhrasingComponent> ToGenericPhrasingContainer<ModificationValueType>( + this PageModificationValue<ModificationValueType> pageModificationValue, Func<ModificationValueType, string> textSelector, + Func<string, string> jsTextExpressionGetter ) { + return new CustomPhrasingComponent( + new DisplayableElement( + context => { + pageModificationValue.AddJsModificationStatement( + valueExpression => "$( '#{0}' ).text( {1} );".FormatWith( context.Id, jsTextExpressionGetter( valueExpression ) ) ); + return new DisplayableElementData( + null, + () => new DisplayableElementLocalData( "span", focusDependentData: new DisplayableElementFocusDependentData( includeIdAttribute: true ) ), + children: new TextNode( () => textSelector( pageModificationValue.Value ) ).ToCollection() ); + } ).ToCollection() ).ToCollection(); + } + }  } \ No newline at end of file
 
191
192
193
194
 
 
195
196
197
 
198
199
200
 
208
209
210
211
 
212
213
 
214
215
216
 
191
192
193
 
194
195
196
197
 
198
199
200
201
 
209
210
211
 
212
213
 
214
215
216
217
@@ -191,10 +191,11 @@
  if( disabledMode != null )   throw new PageDisabledException( disabledMode.Message );   - if( responseWriter != null ) { + var cachedRequestHandler = requestHandler; + if( cachedRequestHandler != null ) {   Response.ClearHeaders();   Response.ClearContent(); - responseWriter.WriteResponse(); + cachedRequestHandler.WriteResponse();     // Calling Response.End() is not a good practice; see http://stackoverflow.com/q/1087777/35349. We should be able to remove this call when we separate   // EWF from Web Forms. This is EnduraCode goal 790. @@ -208,9 +209,9 @@
  protected abstract void initEntitySetup();     /// <summary> - /// Gets the response writer for this page. NOTE: We should re-implement this such that the classes that override this are plain old HTTP handlers instead of pages. + /// Gets the request handler for this page, which will override the page.   /// </summary> - protected virtual EwfSafeResponseWriter responseWriter { get { return null; } } + protected virtual EwfSafeRequestHandler requestHandler => null;     /// <summary>   /// Performs EWF activities in addition to the normal InitComplete activities.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
@@ -0,0 +1,37 @@
+using System; +using EnterpriseWebLibrary.DataAccess; + +namespace EnterpriseWebLibrary.EnterpriseWebFramework { + /// <summary> + /// An object that handles a safe HTTP request (e.g. GET, HEAD). + /// </summary> + public sealed class EwfSafeRequestHandler { + public static implicit operator EwfSafeRequestHandler( EwfSafeResponseWriter responseWriter ) { + return new EwfSafeRequestHandler( responseWriter ); + } + + private readonly EwfSafeResponseWriter responseWriter; + + /// <summary> + /// Creates a request handler from the result of the specified data-modification method. If you do not need to modify data, do not call this constructor; + /// use <see cref="EwfSafeResponseWriter"/>, which can be implicitly converted to a request handler. + /// </summary> + public EwfSafeRequestHandler( Func<EwfSafeResponseWriter> dataModificationMethod ) { + DataAccessState.Current.DisableCache(); + try { + responseWriter = dataModificationMethod(); + } + finally { + DataAccessState.Current.ResetCache(); + } + } + + private EwfSafeRequestHandler( EwfSafeResponseWriter responseWriter ) { + this.responseWriter = responseWriter; + } + + internal void WriteResponse() { + responseWriter.WriteResponse(); + } + } +} \ No newline at end of file
Show Entire File Core/​EnterpriseWebFramework/​Request Handling/​EwfSafeResponseWriter.cs Stacked
renamed from Core/EnterpriseWebFramework/EwfSafeResponseWriter.cs
(No changes)
Show Entire File Core/​EnterpriseWebFramework/​Request Handling/​StaticFileHandler.cs Stacked
renamed from Core/EnterpriseWebFramework/StaticFileHandler.cs
(No changes)
This file's diff was not loaded because this changeset is very large. Load changes
 
9
10
11
12
 
13
14
15
16
17
 
 
18
19
 
 
9
10
11
 
12
13
14
 
 
 
15
16
17
18
 
@@ -9,11 +9,10 @@
  throw new ApplicationException();   }   - protected override ConnectionSecurity ConnectionSecurity { get { return ConnectionSecurity.MatchingCurrentRequest; } } + protected override ConnectionSecurity ConnectionSecurity => ConnectionSecurity.MatchingCurrentRequest;   }   - protected override EwfSafeResponseWriter responseWriter { - get { return new EwfSafeResponseWriter( new EwfResponse( StandardLibrarySessionState.Instance.ResponseToSend ) ); } - } + protected override EwfSafeRequestHandler requestHandler => + new EwfSafeResponseWriter( new EwfResponse( StandardLibrarySessionState.Instance.ResponseToSend ) );   }  } \ No newline at end of file
 
180
181
182
183
 
184
185
186
 
 
 
 
 
 
 
187
188
189
 
180
181
182
 
183
184
185
186
187
188
189
190
191
192
193
194
195
196
@@ -180,10 +180,17 @@
  width: 100%;  }   -/* check boxes */ +/* checkboxes */  ewfInlineCheckBox > ewfInlineCheckBoxBox, ewfInlineCheckBox > ewfInlineCheckBoxLabel {   vertical-align: middle;  } +ewfFlowCheckboxAllStates > ewfCheckbox { + display: block; +} +ewfFlowCheckboxAllStates > ewfFlowCheckboxNestedContentContainer { + margin-top: .5em; + margin-left: 2em; +}  table.ewfBlockCheckBox {   width: 100%;  }
 
8
9
10
 
11
12
 
13
14
15
 
78
79
80
81
 
82
83
84
 
8
9
10
11
12
 
13
14
15
16
 
79
80
81
 
82
83
84
85
@@ -8,8 +8,9 @@
 ewfSectionBoxStyleBothStates > ewfSectionHeadingContainer > ewfSectionHeading,  ewfTableStandardAndStandardExceptLayoutStyles,  ewfTableStandardAndStandardExceptLayoutStyles > tbody > ewfTrStatesWithContrast, +ewfFlowCheckboxHighlightedState > ewfCheckbox,  .checkedChecklistCheckboxDiv { - background-image: url( '../../VersionedStaticFiles/Backgrounds-v2/Darker.svg' ); + background-image: linear-gradient( rgba( 0, 0, 0, .05 ), rgba( 0, 0, 0, .05 ) );  }    /* block highlighting */ @@ -78,7 +79,7 @@
 ewfUiTopTabBlock ewfActionControlAllStylesStatesWithFocus,  ewfUiSideTabBlock ewfActionControlAllStylesStatesWithHover,  ewfUiSideTabBlock ewfActionControlAllStylesStatesWithFocus { - background-image: url( '../../VersionedStaticFiles/Backgrounds-v2/Lighter.svg' ); + background-image: linear-gradient( rgba( 255, 255, 255, .3 ), rgba( 255, 255, 255, .3 ) );  }    /* new content */
 
1
2
3
4
5
6
 
 
 
 
 
 
 
 
 
@@ -1,6 +0,0 @@
-<?xml version="1.0" standalone="no"?> -<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> -<!-- For width and height on the svg element, the default value of 100% causes Chrome to peg the CPU! --> -<svg width="1" height="1" version="1.1" xmlns="http://www.w3.org/2000/svg"> - <rect width="100%" height="100%" style="fill:rgb(0,0,0);fill-opacity:.05"/> -</svg> \ No newline at end of file
 
1
2
3
4
5
6
 
 
 
 
 
 
 
 
 
@@ -1,6 +0,0 @@
-<?xml version="1.0" standalone="no"?> -<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> -<!-- For width and height on the svg element, the default value of 100% causes Chrome to peg the CPU! --> -<svg width="1" height="1" version="1.1" xmlns="http://www.w3.org/2000/svg"> - <rect width="100%" height="100%" style="fill:rgb(255,255,255);fill-opacity:.3"/> -</svg> \ No newline at end of file
 
16
17
18
19
 
20
21
22
23
24
25
26
27
28
29
 
 
 
 
 
30
31
 
 
16
17
18
 
19
20
21
 
 
 
 
 
 
 
 
22
23
24
25
26
27
28
 
@@ -16,16 +16,13 @@
  throw new ApplicationException( "File does not exist." );   }   - protected override ConnectionSecurity ConnectionSecurity { get { return ConnectionSecurity.NonSecure; } } + protected override ConnectionSecurity ConnectionSecurity => ConnectionSecurity.NonSecure;   }   - protected override EwfSafeResponseWriter responseWriter { - get { - return new EwfSafeResponseWriter( - () => EwfResponse.Create( ContentTypes.Xml, new EwfResponseBodyCreator( () => File.ReadAllText( info.FilePath ) ) ), - EwlStatics.EwlBuildDateTime, - () => "getSchema" + info.FileName ); - } - } + protected override EwfSafeRequestHandler requestHandler => + new EwfSafeResponseWriter( + () => EwfResponse.Create( ContentTypes.Xml, new EwfResponseBodyCreator( () => File.ReadAllText( info.FilePath ) ) ), + EwlStatics.EwlBuildDateTime, + () => "getSchema" + info.FileName );   }  } \ No newline at end of file
Change 1 of 1 Show Entire File Web Site/​TestPages/​Checkboxes.aspx Stacked
renamed from Web Site/TestPages/CheckBox.aspx
 
1
 
2
3
4
 
 
1
2
3
4
@@ -1,4 +1,4 @@
-<%@ Page Language="C#" CodeBehind="CheckBox.aspx.cs" Inherits="EnterpriseWebLibrary.WebSite.TestPages.CheckBox" MasterPageFile="~/Ewf/EwfUi.master" %> +<%@ Page Language="C#" CodeBehind="Checkboxes.aspx.cs" Inherits="EnterpriseWebLibrary.WebSite.TestPages.Checkboxes" MasterPageFile="~/Ewf/EwfUi.master" %>    <asp:Content runat="server" ContentPlaceHolderID="contentPlace">   <asp:PlaceHolder runat="server" ID="ph" />
Show Entire File Web Site/​TestPages/​Checkboxes.aspx.cs Stacked
renamed from Web Site/TestPages/CheckBox.aspx.cs
This file's diff was not loaded because this changeset is very large. Load changes
Change 1 of 1 Show Changes Only Web Site/​TestPages/​Checkboxes.aspx.designer.cs Stacked
renamed from Web Site/TestPages/CheckBox.aspx.designer.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
1
2
3
4
5
6
7
8
9
10
11
12
 
13
14
15
16
17
18
19
20
21
22
23
24
 //------------------------------------------------------------------------------  // <auto-generated>  // This code was generated by a tool.  //  // Changes to this file may cause incorrect behavior and will be lost if  // the code is regenerated.  // </auto-generated>  //------------------------------------------------------------------------------    namespace EnterpriseWebLibrary.WebSite.TestPages {     - public partial class CheckBox { + public partial class Checkboxes {     /// <summary>   /// ph control.   /// </summary>   /// <remarks>   /// Auto-generated field.   /// To modify move field declaration from designer file to code-behind file.   /// </remarks>   protected global::System.Web.UI.WebControls.PlaceHolder ph;   }  }
 
26
27
28
29
 
30
31
32
 
26
27
28
 
29
30
31
32
@@ -26,7 +26,7 @@
  "Form Controls",   new TextControlDemo.Info( this ),   new NumberControlDemo.Info( this ), - new CheckBox.Info( this ), + new Checkboxes.Info( this ),   new CheckBoxList.Info( this ),   new SelectListDemo.Info( this ),   new DateAndTimePickers.Info( this ) ),
This file's diff was not loaded because this changeset is very large. Load changes
This file's diff was not loaded because this changeset is very large. Load changes
Show Entire File Web Site/​Web Site.csproj Stacked
This file's diff was not loaded because this changeset is very large. Load changes