private static string getDefaultLabelAndSubject( ModificationField field )
 {
     var result = field.PascalCasedName.CamelToEnglish();
     if( result.ToLower().EndsWith( " id" ) )
         result = result.Substring( 0, result.Length - 3 );
     return result;
 }
 private static void writeBoolFormItemGetters( TextWriter writer, ModificationField field )
 {
     if( field.TypeIs( typeof( bool ) ) ) {
         writeCheckBoxFormItemGetters( writer, field, "bool" );
         writeNumberAsSelectListFormItemGetters( writer, field );
     }
     if( field.TypeIs( typeof( bool? ) ) )
         writeNumberAsSelectListFormItemGetters( writer, field );
 }
 private static string getFormItemGetterSummary( ModificationField field, string controlType, IEnumerable<string> additionalSentences )
 {
     var sentences = new[]
         {
             "Creates a " + field.PropertyName + controlType.PrependDelimiter( " " ) + " form item, which includes a label, a control, and a validation.",
             controlType.Any() ? "" : "This is a generic form-item getter; use it only if there is no specific getter for the control type that you need.",
             "You almost certainly should not call this method from a deferred block of code since this could cause validations to be added to the data modification in the wrong order."
         };
     return StringTools.ConcatenateWithDelimiter( " ", sentences.Concat( additionalSentences ).ToArray() );
 }
 private static string getValidationGetter( ModificationField field, bool includeValidationMethodReturnValue )
 {
     var fieldPropertyName = EwlStatics.GetCSharpIdentifierSimple( field.PropertyName );
     var statements = new[]
         {
             "if( validationPredicate != null && !validationPredicate() ) return;",
             ( includeValidationMethodReturnValue ? fieldPropertyName + " = " : "" ) + "validationMethod( control, postBackValues, labelAndSubject, validator );",
             "if( validator.ErrorsOccurred && validationErrorNotifier != null ) validationErrorNotifier();",
             "if( !validator.ErrorsOccurred && additionalValidationMethod != null ) additionalValidationMethod( labelAndSubject, validator );"
         };
     return "control => new EwfValidation( ( postBackValues, validator ) => { " + StringTools.ConcatenateWithDelimiter( " ", statements ) +
            " }, validationList ?? EwfPage.Instance.DataUpdate )";
 }
        internal static void WriteFormItemGetters( TextWriter writer, ModificationField field )
        {
            // Some of these form item getters need modification methods to be executed to work properly. They return these methods, as out parameters, instead of
            // just adding them to the data modification. This allows client code on a page to specify the order of modification methods, which is important because
            // there may be both child modifications (like file collections) and one-to-many modifications (like M+Vision references for an applicant) on the same
            // page, and the main modification needs to execute between these.
            writeStringFormItemGetters( writer, field );
            writeNumericFormItemGetters( writer, field );
            writeBoolFormItemGetters( writer, field );
            writeDateFormItemGetters( writer, field );
            writeEnumerableFormItemGetters( writer, field );
            writeGuidFormItemGetters( writer, field );

            writeGenericGetterWithoutValueParams( writer, field, null );
            writeGenericGetterWithoutValueParams( writer, field, false );
            writeGenericGetterWithoutValueParams( writer, field, true );
            writeGenericGetterWithValueParams( writer, field, null );
            writeGenericGetterWithValueParams( writer, field, false );
            writeGenericGetterWithValueParams( writer, field, true );
        }
Exemplo n.º 6
0
 private static void writeHtmlAndFileFormItemGetters(TextWriter writer, ModificationField field, string valueParamTypeName)
 {
     writeFormItemGetters(
         writer,
         field,
         "HtmlBlockEditor",
         "Html",
         valueParamTypeName,
         "null",
         new CSharpParameter("out HtmlBlockEditorModification", "mod").ToSingleElementArray(),
         new CSharpParameter[0],
         new CSharpParameter("string", "ckEditorConfiguration", "\"\"").ToSingleElementArray(),
         new CSharpParameter[0],
         "new HtmlBlockEditor( (int?)v, id => " + field.PropertyName + " = id, out m, ckEditorConfiguration: ckEditorConfiguration )",
         "control.Validate( postBackValues, validator, new ValidationErrorHandler( subject ) )",
         "",
         preFormItemGetterStatements: "HtmlBlockEditorModification m = null;",
         postFormItemGetterStatements: "mod = m;");
     writeFormItemGetters(
         writer,
         field,
         "BlobFileManager",
         "File",
         valueParamTypeName,
         "null",
         new CSharpParameter("out System.Action", "modificationMethod").ToSingleElementArray(),
         new CSharpParameter[0],
         new CSharpParameter[0],
         new CSharpParameter("bool", "requireUploadIfNoFile", "false").ToSingleElementArray(),
         "{ var control = new BlobFileManager(); if( v.HasValue ) control.LoadData( (int)v.Value ); mm = () => " + field.PropertyName +
         " = control.ModifyData(); return control; }",
         "control.ValidateFormValues( validator, subject, requireUploadIfNoFile )",
         "",
         preFormItemGetterStatements: "System.Action mm = null;",
         postFormItemGetterStatements: "modificationMethod = mm;");
 }
        private static void writeStringFormItemGetters( TextWriter writer, ModificationField field )
        {
            if( !field.TypeIs( typeof( string ) ) )
                return;

            writeFormItemGetters(
                writer,
                field,
                "EwfTextBox",
                "Text",
                "string",
                "\"\"",
                new CSharpParameter[ 0 ],
                getAllowEmptyParameter( false ).ToSingleElementArray(),
                new[]
                    {
                        new CSharpParameter( "int", "textBoxRows", "1" ), new CSharpParameter( "bool", "masksCharacters", "false" ),
                        new CSharpParameter( "bool", "readOnly", "false" ), new CSharpParameter( "bool?", "suggestSpellCheck", "null" ),
                        new CSharpParameter( "PostBack", "postBack", "null" ), new CSharpParameter( "bool", "autoPostBack", "false" )
                    },
                new CSharpParameter[ 0 ],
                "new EwfTextBox( v, rows: textBoxRows, masksCharacters: masksCharacters, " + ( field.Size.HasValue ? "maxLength: " + field.Size.Value + ", " : "" ) +
                "readOnly: readOnly, suggestSpellCheck: suggestSpellCheck, postBack: postBack, autoPostBack: autoPostBack )",
                "validator.GetString( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty" +
                ( field.Size.HasValue ? ", " + field.Size.Value : "" ) + " )",
                "" );
            writeFormItemGetters(
                writer,
                field,
                "EwfTextBox",
                "EmailAddress",
                "string",
                "\"\"",
                new CSharpParameter[ 0 ],
                getAllowEmptyParameter( false ).ToSingleElementArray(),
                new[]
                    {
                        new CSharpParameter( "bool", "readOnly", "false" ), new CSharpParameter( "PostBack", "postBack", "null" ),
                        new CSharpParameter( "bool", "autoPostBack", "false" )
                    },
                new CSharpParameter[ 0 ],
                "new EwfTextBox( v" + ( field.Size.HasValue ? ", maxLength: " + field.Size.Value : "" ) +
                ", readOnly: readOnly, postBack: postBack, autoPostBack: autoPostBack )",
                "validator.GetEmailAddress( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty" +
                ( field.Size.HasValue ? ", maxLength: " + field.Size.Value : "" ) + " )",
                "" );
            writeFormItemGetters(
                writer,
                field,
                "EwfTextBox",
                "PhoneNumber",
                "string",
                "\"\"",
                new CSharpParameter[ 0 ],
                getAllowEmptyParameter( false ).ToSingleElementArray(),
                new[]
                    {
                        new CSharpParameter( "bool", "readOnly", "false" ), new CSharpParameter( "PostBack", "postBack", "null" ),
                        new CSharpParameter( "bool", "autoPostBack", "false" )
                    },
                new[] { new CSharpParameter( "bool", "allowExtension", "true" ), new CSharpParameter( "bool", "allowSurroundingGarbage", "false" ) },
                "new EwfTextBox( v" + ( field.Size.HasValue ? ", maxLength: " + field.Size.Value : "" ) +
                ", readOnly: readOnly, postBack: postBack, autoPostBack: autoPostBack )",
                "validator.GetPhoneNumber( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowExtension, allowEmpty, allowSurroundingGarbage )",
                "" );
            writeFormItemGetters(
                writer,
                field,
                "EwfTextBox",
                "ZipCode",
                "string",
                "\"\"",
                new CSharpParameter[ 0 ],
                getAllowEmptyParameter( false ).ToSingleElementArray(),
                new[]
                    {
                        new CSharpParameter( "bool", "readOnly", "false" ), new CSharpParameter( "PostBack", "postBack", "null" ),
                        new CSharpParameter( "bool", "autoPostBack", "false" )
                    },
                new CSharpParameter[ 0 ],
                "new EwfTextBox( v" + ( field.Size.HasValue ? ", maxLength: " + field.Size.Value : "" ) +
                ", readOnly: readOnly, postBack: postBack, autoPostBack: autoPostBack )",
                "validator.GetZipCode( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty ).FullZipCode",
                "" );
            writeFormItemGetters(
                writer,
                field,
                "EwfTextBox",
                "Uri",
                "string",
                "\"\"",
                new CSharpParameter[ 0 ],
                getAllowEmptyParameter( false ).ToSingleElementArray(),
                new[]
                    {
                        new CSharpParameter( "bool", "readOnly", "false" ), new CSharpParameter( "PostBack", "postBack", "null" ),
                        new CSharpParameter( "bool", "autoPostBack", "false" )
                    },
                new CSharpParameter[ 0 ],
                "new EwfTextBox( v" + ( field.Size.HasValue ? ", maxLength: " + field.Size.Value : "" ) +
                ", readOnly: readOnly, postBack: postBack, autoPostBack: autoPostBack )",
                "validator.GetUrl( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty" +
                ( field.Size.HasValue ? ", " + field.Size.Value : "" ) + " )",
                "" );
            writeFormItemGetters(
                writer,
                field,
                "SelectList<string>",
                "RadioList",
                "string",
                "\"\"",
                new[] { new CSharpParameter( "IEnumerable<SelectListItem<string>>", "items" ) },
                new CSharpParameter[ 0 ],
                new[]
                    {
                        new CSharpParameter( "bool", "useHorizontalLayout", "false" ), new CSharpParameter( "string", "defaultValueItemLabel", "\"\"" ),
                        new CSharpParameter( "bool", "disableSingleButtonDetection", "false" ), new CSharpParameter( "PostBack", "postBack", "null" ),
                        new CSharpParameter( "bool", "autoPostBack", "false" )
                    },
                new CSharpParameter[ 0 ],
                "SelectList.CreateRadioList( items, v, useHorizontalLayout: useHorizontalLayout, defaultValueItemLabel: defaultValueItemLabel, disableSingleButtonDetection: disableSingleButtonDetection, postBack: postBack, autoPostBack: autoPostBack )",
                "control.ValidateAndGetSelectedItemIdInPostBack( postBackValues, validator )",
                "" );
            writeFormItemGetters(
                writer,
                field,
                "SelectList<string>",
                "DropDown",
                "string",
                "\"\"",
                new[] { new CSharpParameter( "IEnumerable<SelectListItem<string>>", "items" ) },
                new CSharpParameter[ 0 ],
                new[]
                    {
                        new CSharpParameter( "Unit?", "width", "null" ), new CSharpParameter( "string", "defaultValueItemLabel", "\"\"" ),
                        new CSharpParameter( "bool", "placeholderIsValid", "false" ), new CSharpParameter( "string", "placeholderText", "\"Please select\"" ),
                        new CSharpParameter( "PostBack", "postBack", "null" ), new CSharpParameter( "bool", "autoPostBack", "false" )
                    },
                new CSharpParameter[ 0 ],
                "SelectList.CreateDropDown( items, v, width: width, defaultValueItemLabel: defaultValueItemLabel, placeholderIsValid: placeholderIsValid, placeholderText: placeholderText, postBack: postBack, autoPostBack: autoPostBack )",
                "control.ValidateAndGetSelectedItemIdInPostBack( postBackValues, validator )",
                "" );
            writeFormItemGetters(
                writer,
                field,
                "WysiwygHtmlEditor",
                "Html",
                "string",
                "\"\"",
                new CSharpParameter[ 0 ],
                getAllowEmptyParameter( false ).ToSingleElementArray(),
                new CSharpParameter( "string", "ckEditorConfiguration", "\"\"" ).ToSingleElementArray(),
                new CSharpParameter[ 0 ],
                "new WysiwygHtmlEditor( v, ckEditorConfiguration: ckEditorConfiguration )",
                "validator.GetString( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty" +
                ( field.Size.HasValue ? ", " + field.Size.Value : "" ) + " )",
                "",
                additionalSummarySentences:
                    new[]
                        {
                            "WARNING: Do not use this form-item getter unless you know exactly what you're doing.",
                            "If you want to store HTML, it is almost always better to use an HTML block instead of just a string field.",
                            "HTML blocks have special handling for intra-site URIs and may include additional features in the future.",
                            "They also cause all of your HTML to be stored in one place, which is usually a good practice."
                        } );
        }
        private static void writeNumericFormItemGetters( TextWriter writer, ModificationField field )
        {
            if( field.TypeIs( typeof( int ) ) ) {
                writeNumberAsTextFormItemGetters(
                    writer,
                    field,
                    "int?",
                    new[] { new CSharpParameter( "int", "min", "int.MinValue" ), new CSharpParameter( "int", "max", "int.MaxValue" ) },
                    "validator.GetInt( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), min, max )" );
                writeNumberAsSelectListFormItemGetters( writer, field );
                writeHtmlAndFileFormItemGetters( writer, field, "int?" );
                writeFileCollectionFormItemGetters( writer, field, "int" );
                writeDurationFormItemGetters( writer, field );
            }
            if( field.TypeIs( typeof( int? ) ) ) {
                writeNumberAsTextFormItemGetters(
                    writer,
                    field,
                    "int?",
                    new[] { getAllowEmptyParameter( true ), new CSharpParameter( "int", "min", "int.MinValue" ), new CSharpParameter( "int", "max", "int.MaxValue" ) },
                    "validator.GetNullableInt( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty, min: min, max: max )" );
                writeNumberAsSelectListFormItemGetters( writer, field );
                writeHtmlAndFileFormItemGetters( writer, field, "int?" );
            }

            if( field.TypeIs( typeof( short ) ) ) {
                writeNumberAsTextFormItemGetters(
                    writer,
                    field,
                    "short?",
                    new[] { new CSharpParameter( "short", "min", "short.MinValue" ), new CSharpParameter( "short", "max", "short.MaxValue" ) },
                    "validator.GetShort( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), min, max )" );
                writeNumberAsSelectListFormItemGetters( writer, field );
            }
            if( field.TypeIs( typeof( short? ) ) ) {
                writeNumberAsTextFormItemGetters(
                    writer,
                    field,
                    "short?",
                    new[] { getAllowEmptyParameter( true ), new CSharpParameter( "short", "min", "short.MinValue" ), new CSharpParameter( "short", "max", "short.MaxValue" ) },
                    "validator.GetNullableShort( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty, min, max )" );
                writeNumberAsSelectListFormItemGetters( writer, field );
            }

            if( field.TypeIs( typeof( byte ) ) ) {
                writeNumberAsTextFormItemGetters(
                    writer,
                    field,
                    "byte?",
                    new[] { new CSharpParameter( "byte", "min", "byte.MinValue" ), new CSharpParameter( "byte", "max", "byte.MaxValue" ) },
                    "validator.GetByte( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), min, max )" );
                writeNumberAsSelectListFormItemGetters( writer, field );
            }
            if( field.TypeIs( typeof( byte? ) ) ) {
                writeNumberAsTextFormItemGetters(
                    writer,
                    field,
                    "byte?",
                    getAllowEmptyParameter( true ).ToSingleElementArray(),
                    "validator.GetNullableByte( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty )" );
                writeNumberAsSelectListFormItemGetters( writer, field );
            }

            if( field.TypeIs( typeof( decimal ) ) ) {
                writeNumberAsTextFormItemGetters(
                    writer,
                    field,
                    "decimal?",
                    new[]
                        { new CSharpParameter( "decimal", "min", "Validator.SqlDecimalDefaultMin" ), new CSharpParameter( "decimal", "max", "Validator.SqlDecimalDefaultMax" ) },
                    "validator.GetDecimal( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), min, max )" );
                writeNumberAsSelectListFormItemGetters( writer, field );
                writeCheckBoxFormItemGetters( writer, field, "decimal" );
                writeHtmlAndFileFormItemGetters( writer, field, "decimal?" );
                writeFileCollectionFormItemGetters( writer, field, "decimal" );
                writeDurationFormItemGetters( writer, field );
            }
            if( field.TypeIs( typeof( decimal? ) ) ) {
                writeNumberAsTextFormItemGetters(
                    writer,
                    field,
                    "decimal?",
                    new[]
                        {
                            getAllowEmptyParameter( true ), new CSharpParameter( "decimal", "min", "Validator.SqlDecimalDefaultMin" ),
                            new CSharpParameter( "decimal", "max", "Validator.SqlDecimalDefaultMax" )
                        },
                    "validator.GetNullableDecimal( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty, min, max )" );
                writeNumberAsSelectListFormItemGetters( writer, field );
                writeHtmlAndFileFormItemGetters( writer, field, "decimal?" );
            }
        }
 private static void writeDurationFormItemGetters( TextWriter writer, ModificationField field )
 {
     writeFormItemGetters(
         writer,
         field,
         "DurationPicker",
         "Duration",
         field.TypeName,
         "0",
         new CSharpParameter[ 0 ],
         new CSharpParameter[ 0 ],
         new CSharpParameter[ 0 ],
         new CSharpParameter[ 0 ],
         "new DurationPicker( System.TimeSpan.FromSeconds( (int)v ) )",
         "(" + field.TypeName + ")control.ValidateAndGetPostBackDuration( postBackValues, validator, new ValidationErrorHandler( subject ) ).TotalSeconds",
         "" );
 }
 private static void writeEnumerableFormItemGetters( TextWriter writer, ModificationField field )
 {
     if( !field.EnumerableElementTypeName.Any() )
         return;
     writeFormItemGetters(
         writer,
         field,
         "EwfCheckBoxList<" + field.EnumerableElementTypeName + ">",
         "CheckBoxList",
         field.TypeName,
         "null",
         new CSharpParameter( "IEnumerable<SelectListItem<" + field.EnumerableElementTypeName + ">>", "items" ).ToSingleElementArray(),
         new CSharpParameter[ 0 ],
         new[]
             {
                 new CSharpParameter( "string", "caption", "\"\"" ), new CSharpParameter( "bool", "includeSelectAndDeselectAllButtons", "false" ),
                 new CSharpParameter( "byte", "numberOfColumns", "1" ), new CSharpParameter( "PostBack", "postBack", "null" )
             },
         new CSharpParameter[ 0 ],
         "new EwfCheckBoxList<" + field.EnumerableElementTypeName + ">( items, v ?? new " + field.EnumerableElementTypeName +
         "[ 0 ], caption: caption, includeSelectAndDeselectAllButtons: includeSelectAndDeselectAllButtons, numberOfColumns: numberOfColumns, postBack: postBack )",
         "control.GetSelectedItemIdsInPostBack( postBackValues )",
         "" );
 }
 private static void writeNumberAsTextFormItemGetters(
     TextWriter writer, ModificationField field, string valueParamTypeName, IEnumerable<CSharpParameter> optionalValidationParams,
     string validationMethodExpressionOrBlock)
 {
     writeFormItemGetters(
         writer,
         field,
         "EwfTextBox",
         "Text",
         valueParamTypeName,
         "null",
         new CSharpParameter[ 0 ],
         new CSharpParameter[ 0 ],
         new[]
             {
                 new CSharpParameter( "bool", "readOnly", "false" ), new CSharpParameter( "PostBack", "postBack", "null" ),
                 new CSharpParameter( "bool", "autoPostBack", "false" )
             },
         optionalValidationParams,
         "new EwfTextBox( v.ObjectToString( true ), readOnly: readOnly, postBack: postBack, autoPostBack: autoPostBack )",
         validationMethodExpressionOrBlock,
         "" );
 }
Exemplo n.º 12
0
        private static void writeListFormItemGetters(TextWriter writer, ModificationField field)
        {
            if (field.TypeIs(typeof(bool)) || field.TypeIs(typeof(int)) || field.TypeIs(typeof(long)) || field.TypeIs(typeof(decimal)))
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "RadioList",
                    new CSharpParameter("RadioListSetup<{0}>".FormatWith(field.NullableTypeName), "controlSetup").ToCollection(),
                    false,
                    Enumerable.Empty <CSharpParameter>(),
                    "SpecifiedValue<{0}>".FormatWith(field.NullableTypeName),
                    Enumerable.Empty <CSharpParameter>(),
                    true,
                    dv =>
                    "{0}.ToRadioList( controlSetup, value: value, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv));
            }
            if (field.TypeIs(typeof(bool?)) || field.TypeIs(typeof(int?)) || field.TypeIs(typeof(long?)) || field.TypeIs(typeof(string)) ||
                field.TypeIs(typeof(decimal? )))
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "RadioList",
                    new CSharpParameter("RadioListSetup<{0}>".FormatWith(field.NullableTypeName), "controlSetup").ToCollection(),
                    false,
                    new CSharpParameter("string", "defaultValueItemLabel", defaultValue: field.TypeIs(typeof(string)) ? "\"\"" : "\"None\"").ToCollection(),
                    field.TypeIs(typeof(string)) ? field.NullableTypeName : "SpecifiedValue<{0}>".FormatWith(field.NullableTypeName),
                    Enumerable.Empty <CSharpParameter>(),
                    true,
                    dv =>
                    "{0}.ToRadioList( controlSetup, defaultValueItemLabel: defaultValueItemLabel, value: value, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv));
            }

            if (field.TypeIs(typeof(bool)) || field.TypeIs(typeof(int)) || field.TypeIs(typeof(long)) || field.TypeIs(typeof(decimal)))
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "DropDown",
                    new CSharpParameter("DropDownSetup<{0}>".FormatWith(field.NullableTypeName), "controlSetup").ToCollection(),
                    false,
                    Enumerable.Empty <CSharpParameter>(),
                    "SpecifiedValue<{0}>".FormatWith(field.NullableTypeName),
                    Enumerable.Empty <CSharpParameter>(),
                    true,
                    dv =>
                    "{0}.ToDropDown( controlSetup, value: value, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv));
            }
            if (field.TypeIs(typeof(bool?)) || field.TypeIs(typeof(int?)) || field.TypeIs(typeof(long?)) || field.TypeIs(typeof(string)) ||
                field.TypeIs(typeof(decimal? )))
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "DropDown",
                    new CSharpParameter("DropDownSetup<{0}>".FormatWith(field.NullableTypeName), "controlSetup").ToCollection()
                    .Concat(
                        field.TypeIs(typeof(string))
                                                                ? Enumerable.Empty <CSharpParameter>()
                                                                : new CSharpParameter("string", "defaultValueItemLabel").ToCollection()),
                    false,
                    (field.TypeIs(typeof(string))
                                                  ? new CSharpParameter("string", "defaultValueItemLabel", defaultValue: "\"\"").ToCollection()
                                                  : Enumerable.Empty <CSharpParameter>()).Append(
                        new CSharpParameter("bool", "placeholderIsValid", field.TypeIs(typeof(string)) ? "false" : "true")),
                    field.TypeIs(typeof(string)) ? field.NullableTypeName : "SpecifiedValue<{0}>".FormatWith(field.NullableTypeName),
                    Enumerable.Empty <CSharpParameter>(),
                    true,
                    dv =>
                    "{0}.ToDropDown( controlSetup, {1}defaultValueItemLabel, placeholderIsValid: placeholderIsValid, value: value, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv, field.TypeIs(typeof(string)) ? "defaultValueItemLabel: " : ""));
            }

            if (field.EnumerableElementTypeName.Any())
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "CheckboxList",
                    new CSharpParameter("CheckboxListSetup<{0}>".FormatWith(field.EnumerableElementTypeName), "checkboxListSetup").ToCollection(),
                    false,
                    Enumerable.Empty <CSharpParameter>(),
                    field.TypeName,
                    Enumerable.Empty <CSharpParameter>(),
                    true,
                    dv =>
                    "{0}.ToCheckboxList( checkboxListSetup, value: value, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv));
            }
        }
 private static void writeDateFormItemGetters( TextWriter writer, ModificationField field )
 {
     if( field.TypeIs( typeof( DateTime? ) ) ) {
         writeFormItemGetters(
             writer,
             field,
             "DatePicker",
             "Date",
             "System.DateTime?",
             "null",
             new CSharpParameter[ 0 ],
             new CSharpParameter[ 0 ],
             new[]
                 {
                     new CSharpParameter( "System.DateTime?", "minDate", "null" ), new CSharpParameter( "System.DateTime?", "maxDate", "null" ),
                     new CSharpParameter( "bool", "constrainToSqlSmallDateTimeRange", "true" ), new CSharpParameter( "PostBack", "postBack", "null" )
                 },
             getAllowEmptyParameter( true ).ToSingleElementArray(),
             "{ " +
             StringTools.ConcatenateWithDelimiter(
                 " ",
                 "var c = new DatePicker( v, postBack: postBack ) { ConstrainToSqlSmallDateTimeRange = constrainToSqlSmallDateTimeRange };",
                 "if( minDate.HasValue ) c.MinDate = minDate.Value;",
                 "if( maxDate.HasValue ) c.MaxDate = maxDate.Value;",
                 "return c;" ) + " }",
             "control.ValidateAndGetNullablePostBackDate( postBackValues, validator, new ValidationErrorHandler( subject ), allowEmpty )",
             "" );
     }
     if( field.TypeIs( typeof( DateTime ) ) ) {
         writeFormItemGetters(
             writer,
             field,
             "DatePicker",
             "Date",
             "System.DateTime?",
             "null",
             new CSharpParameter[ 0 ],
             new CSharpParameter[ 0 ],
             new[]
                 {
                     new CSharpParameter( "System.DateTime?", "minDate", "null" ), new CSharpParameter( "System.DateTime?", "maxDate", "null" ),
                     new CSharpParameter( "bool", "constrainToSqlSmallDateTimeRange", "true" ), new CSharpParameter( "PostBack", "postBack", "null" )
                 },
             new CSharpParameter[ 0 ],
             "{ " +
             StringTools.ConcatenateWithDelimiter(
                 " ",
                 "var c = new DatePicker( v, postBack: postBack ) { ConstrainToSqlSmallDateTimeRange = constrainToSqlSmallDateTimeRange };",
                 "if( minDate.HasValue ) c.MinDate = minDate.Value;",
                 "if( maxDate.HasValue ) c.MaxDate = maxDate.Value;",
                 "return c;" ) + " }",
             "control.ValidateAndGetPostBackDate( postBackValues, validator, new ValidationErrorHandler( subject ) )",
             "" );
     }
 }
        private static void writeNumberAsSelectListFormItemGetters(TextWriter writer, ModificationField field)
        {
            var nonNullableField = field.TypeName != field.NullableTypeName;

            writeFormItemGetters(
                writer,
                field,
                "SelectList<" + field.NullableTypeName + ">",
                "RadioList",
                field.NullableTypeName,
                "null",
                new[] { new CSharpParameter("IEnumerable<SelectListItem<" + field.NullableTypeName + ">>", "items") },
                new CSharpParameter[0],
                new CSharpParameter("bool", "useHorizontalLayout", "false").ToSingleElementArray()
                .Concat(nonNullableField ? new CSharpParameter[0] : new CSharpParameter("string", "defaultValueItemLabel", "\"None\"").ToSingleElementArray())
                .Concat(
                    new[]
            {
                new CSharpParameter("bool", "disableSingleButtonDetection", "false"), new CSharpParameter("PostBack", "postBack", "null"),
                new CSharpParameter("bool", "autoPostBack", "false")
            }),
                new CSharpParameter[0],
                "SelectList.CreateRadioList( items, v, useHorizontalLayout: useHorizontalLayout, defaultValueItemLabel: " +
                (nonNullableField ? "\"\"" : "defaultValueItemLabel") +
                ", disableSingleButtonDetection: disableSingleButtonDetection, postBack: postBack, autoPostBack: autoPostBack )",
                "{ var selectedItemIdInPostBack = control.ValidateAndGetSelectedItemIdInPostBack( postBackValues, validator ); return " +
                (nonNullableField ? "selectedItemIdInPostBack.HasValue ? selectedItemIdInPostBack.Value : default( " + field.TypeName + " )" : "selectedItemIdInPostBack") +
                "; }",
                "");
            writeFormItemGetters(
                writer,
                field,
                "SelectList<" + field.NullableTypeName + ">",
                "DropDown",
                field.NullableTypeName,
                "null",
                new CSharpParameter("IEnumerable<SelectListItem<" + field.NullableTypeName + ">>", "items").ToSingleElementArray()
                .Concat(nonNullableField ? new CSharpParameter[0] : new CSharpParameter("string", "defaultValueItemLabel").ToSingleElementArray()),
                new CSharpParameter[0],
                new CSharpParameter("Unit?", "width", "null").ToSingleElementArray()
                .Concat((nonNullableField ? new CSharpParameter[0] : new CSharpParameter("bool", "placeholderIsValid", "true").ToSingleElementArray()))
                .Concat(
                    new[]
            {
                new CSharpParameter("string", "placeholderText", "\"Please select\""), new CSharpParameter("PostBack", "postBack", "null"),
                new CSharpParameter("bool", "autoPostBack", "false")
            }),
                new CSharpParameter[0],
                "SelectList.CreateDropDown( items, v, width: width, defaultValueItemLabel: " + (nonNullableField ? "\"\"" : "defaultValueItemLabel") +
                ", placeholderIsValid: " + (nonNullableField ? "false" : "placeholderIsValid") +
                ", placeholderText: placeholderText, postBack: postBack, autoPostBack: autoPostBack )",
                "{ var selectedItemIdInPostBack = control.ValidateAndGetSelectedItemIdInPostBack( postBackValues, validator ); return " +
                (nonNullableField ? "selectedItemIdInPostBack.HasValue ? selectedItemIdInPostBack.Value : default( " + field.TypeName + " )" : "selectedItemIdInPostBack") +
                "; }",
                "");
        }
Exemplo n.º 15
0
        private static void writeTextFormItemGetters(TextWriter writer, ModificationField field)
        {
            if (field.TypeIs(typeof(string)))
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "TextControl",
                    getAllowEmptyParameter(false).ToCollection(),
                    false,
                    new CSharpParameter("TextControlSetup", "controlSetup", defaultValue: "null").ToCollection(),
                    "string",
                    Enumerable.Empty <CSharpParameter>(),
                    true,
                    dv =>
                    "{0}.ToTextControl( allowEmpty, setup: controlSetup, value: value, maxLength: {1}, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv, field.Size?.ToString() ?? "null"));
                writeFormItemGetter(
                    writer,
                    field,
                    "EmailAddressControl",
                    getAllowEmptyParameter(false).ToCollection(),
                    false,
                    new CSharpParameter("EmailAddressControlSetup", "controlSetup", defaultValue: "null").ToCollection(),
                    "string",
                    Enumerable.Empty <CSharpParameter>(),
                    true,
                    dv =>
                    "{0}.ToEmailAddressControl( allowEmpty, setup: controlSetup, value: value, maxLength: {1}, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv, field.Size?.ToString() ?? "null"));
                writeFormItemGetter(
                    writer,
                    field,
                    "TelephoneNumberControl",
                    getAllowEmptyParameter(false).ToCollection(),
                    false,
                    new CSharpParameter("TelephoneNumberControlSetup", "controlSetup", defaultValue: "null").ToCollection(),
                    "string",
                    Enumerable.Empty <CSharpParameter>(),
                    true,
                    dv =>
                    "{0}.ToTelephoneNumberControl( allowEmpty, setup: controlSetup, value: value, maxLength: {1}, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv, field.Size?.ToString() ?? "null"));
                writeFormItemGetter(
                    writer,
                    field,
                    "UrlControl",
                    getAllowEmptyParameter(false).ToCollection(),
                    false,
                    new CSharpParameter("UrlControlSetup", "controlSetup", defaultValue: "null").ToCollection(),
                    "string",
                    Enumerable.Empty <CSharpParameter>(),
                    true,
                    dv =>
                    "{0}.ToUrlControl( allowEmpty, setup: controlSetup, value: value, maxLength: {1}, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv, field.Size?.ToString() ?? "null"));
            }

            if (field.TypeIs(typeof(string)))
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "NumericTextControl",
                    getAllowEmptyParameter(false).ToCollection(),
                    false,
                    new CSharpParameter("NumericTextControlSetup", "controlSetup", defaultValue: "null").ToCollection(),
                    "string",
                    new CSharpParameter("int?", "minLength", defaultValue: "null").ToCollection(),
                    true,
                    dv =>
                    "{0}.ToNumericTextControl( allowEmpty, setup: controlSetup, value: value, minLength: minLength, maxLength: {1}, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv, field.Size?.ToString() ?? "null"));
            }
            if (field.TypeIs(typeof(int)) || field.TypeIs(typeof(long)))
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "TextControl",
                    Enumerable.Empty <CSharpParameter>(),
                    false,
                    new CSharpParameter("NumericTextControlSetup", "controlSetup", defaultValue: "null").ToCollection(),
                    "SpecifiedValue<{0}>".FormatWith(field.NullableTypeName),
                    new CSharpParameter(field.NullableTypeName, "minValue", "null").ToCollection()
                    .Append(new CSharpParameter(field.NullableTypeName, "maxValue", "null")),
                    true,
                    dv =>
                    "{0}.ToTextControl( setup: controlSetup, value: value, minValue: minValue, maxValue: maxValue, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv));
            }
            if (field.TypeIs(typeof(int?)) || field.TypeIs(typeof(long?)))
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "TextControl",
                    Enumerable.Empty <CSharpParameter>(),
                    false,
                    new CSharpParameter("NumericTextControlSetup", "controlSetup", defaultValue: "null").ToCollection(),
                    "SpecifiedValue<{0}>".FormatWith(field.NullableTypeName),
                    getAllowEmptyParameter(true)
                    .ToCollection()
                    .Append(new CSharpParameter(field.NullableTypeName, "minValue", "null"))
                    .Append(new CSharpParameter(field.NullableTypeName, "maxValue", "null")),
                    true,
                    dv =>
                    "{0}.ToTextControl( setup: controlSetup, value: value, allowEmpty: allowEmpty, minValue: minValue, maxValue: maxValue, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv));
            }

            if (field.TypeIs(typeof(string)))
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "Html",
                    getAllowEmptyParameter(false).ToCollection(),
                    false,
                    new CSharpParameter("WysiwygHtmlEditorSetup", "editorSetup", "null").ToCollection(),
                    "string",
                    new CSharpParameter[0],
                    true,
                    dv =>
                    "{0}.ToHtmlEditor( allowEmpty, setup: editorSetup, value: value, maxLength: {1}, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv, field.Size?.ToString() ?? "null"),
                    additionalSummarySentences: new[]
                {
                    "WARNING: Do not use this form-item getter unless you know exactly what you're doing.",
                    "If you want to store HTML, it is almost always better to use an HTML block instead of just a string field.",
                    "HTML blocks have special handling for intra-site URIs and may include additional features in the future.",
                    "They also cause all of your HTML to be stored in one place, which is usually a good practice."
                });
            }
        }
 private static void writeFileCollectionFormItemGetters( TextWriter writer, ModificationField field, string valueParamTypeName )
 {
     writeFormItemGetters(
         writer,
         field,
         "BlobFileCollectionManager",
         "FileCollection",
         valueParamTypeName,
         "-1",
         new CSharpParameter( "bool", "sortByName" ).ToSingleElementArray(),
         new CSharpParameter[ 0 ],
         new CSharpParameter[ 0 ],
         new CSharpParameter[ 0 ],
         "{ var control = new BlobFileCollectionManager( sortByName: sortByName ); control.LoadData( (int)v ); return control; }",
         "",
         "" );
 }
        private static void writeNumericFormItemGetters(TextWriter writer, ModificationField field)
        {
            if (field.TypeIs(typeof(int)))
            {
                writeNumberAsTextFormItemGetters(
                    writer,
                    field,
                    "int?",
                    new[] { new CSharpParameter("int", "min", "int.MinValue"), new CSharpParameter("int", "max", "int.MaxValue") },
                    "validator.GetInt( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), min, max )");
                writeNumberAsSelectListFormItemGetters(writer, field);
                writeHtmlAndFileFormItemGetters(writer, field, "int?");
                writeFileCollectionFormItemGetters(writer, field, "int");
                writeDurationFormItemGetters(writer, field);
            }
            if (field.TypeIs(typeof(int?)))
            {
                writeNumberAsTextFormItemGetters(
                    writer,
                    field,
                    "int?",
                    new[] { getAllowEmptyParameter(true), new CSharpParameter("int", "min", "int.MinValue"), new CSharpParameter("int", "max", "int.MaxValue") },
                    "validator.GetNullableInt( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty, min: min, max: max )");
                writeNumberAsSelectListFormItemGetters(writer, field);
                writeHtmlAndFileFormItemGetters(writer, field, "int?");
            }

            if (field.TypeIs(typeof(short)))
            {
                writeNumberAsTextFormItemGetters(
                    writer,
                    field,
                    "short?",
                    new[] { new CSharpParameter("short", "min", "short.MinValue"), new CSharpParameter("short", "max", "short.MaxValue") },
                    "validator.GetShort( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), min, max )");
                writeNumberAsSelectListFormItemGetters(writer, field);
            }
            if (field.TypeIs(typeof(short?)))
            {
                writeNumberAsTextFormItemGetters(
                    writer,
                    field,
                    "short?",
                    new[] { getAllowEmptyParameter(true), new CSharpParameter("short", "min", "short.MinValue"), new CSharpParameter("short", "max", "short.MaxValue") },
                    "validator.GetNullableShort( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty, min, max )");
                writeNumberAsSelectListFormItemGetters(writer, field);
            }

            if (field.TypeIs(typeof(byte)))
            {
                writeNumberAsTextFormItemGetters(
                    writer,
                    field,
                    "byte?",
                    new[] { new CSharpParameter("byte", "min", "byte.MinValue"), new CSharpParameter("byte", "max", "byte.MaxValue") },
                    "validator.GetByte( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), min, max )");
                writeNumberAsSelectListFormItemGetters(writer, field);
            }
            if (field.TypeIs(typeof(byte?)))
            {
                writeNumberAsTextFormItemGetters(
                    writer,
                    field,
                    "byte?",
                    getAllowEmptyParameter(true).ToSingleElementArray(),
                    "validator.GetNullableByte( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty )");
                writeNumberAsSelectListFormItemGetters(writer, field);
            }

            if (field.TypeIs(typeof(decimal)))
            {
                writeNumberAsTextFormItemGetters(
                    writer,
                    field,
                    "decimal?",
                    new[]
                    { new CSharpParameter("decimal", "min", "Validator.SqlDecimalDefaultMin"), new CSharpParameter("decimal", "max", "Validator.SqlDecimalDefaultMax") },
                    "validator.GetDecimal( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), min, max )");
                writeNumberAsSelectListFormItemGetters(writer, field);
                writeCheckBoxFormItemGetters(writer, field, "decimal");
                writeHtmlAndFileFormItemGetters(writer, field, "decimal?");
                writeFileCollectionFormItemGetters(writer, field, "decimal");
                writeDurationFormItemGetters(writer, field);
            }
            if (field.TypeIs(typeof(decimal? )))
            {
                writeNumberAsTextFormItemGetters(
                    writer,
                    field,
                    "decimal?",
                    new[]
                {
                    getAllowEmptyParameter(true), new CSharpParameter("decimal", "min", "Validator.SqlDecimalDefaultMin"),
                    new CSharpParameter("decimal", "max", "Validator.SqlDecimalDefaultMax")
                },
                    "validator.GetNullableDecimal( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty, min, max )");
                writeNumberAsSelectListFormItemGetters(writer, field);
                writeHtmlAndFileFormItemGetters(writer, field, "decimal?");
            }
        }
        private static void writeGenericGetter(
            TextWriter writer, ModificationField field, bool includeValueParams, bool? includeValidationMethodReturnValue, string body)
        {
            CodeGenerationStatics.AddSummaryDocComment( writer, getFormItemGetterSummary( field, "", new string[ 0 ] ) );
            CodeGenerationStatics.AddParamDocComment( writer, "additionalValidationMethod", "Passes the labelAndSubject and a validator to the function." );
            CodeGenerationStatics.AddParamDocComment( writer, "validationList", validationListParamDocComment );

            var parameters = new List<CSharpParameter>();
            if( includeValueParams )
                parameters.Add( new CSharpParameter( "bool", "useValueParameter" ) );
            parameters.Add(
                new CSharpParameter( "System.Func<" + ( includeValueParams ? field.NullableTypeName : field.TypeName ) + ",string,ControlType>", "controlGetter" ) );
            if( includeValidationMethodReturnValue.HasValue ) {
                parameters.Add(
                    includeValidationMethodReturnValue.Value
                        ? new CSharpParameter( "System.Func<ControlType,PostBackValueDictionary,string,Validator," + field.TypeName + ">", "validationMethod" )
                        : new CSharpParameter( "System.Action<ControlType,PostBackValueDictionary,string,Validator>", "validationMethod" ) );
            }
            parameters.Add( new CSharpParameter( "string", "labelAndSubject", "\"" + getDefaultLabelAndSubject( field ) + "\"" ) );
            parameters.Add( new CSharpParameter( "FormItemLabel", "labelOverride", "null" ) );
            if( includeValueParams )
                parameters.Add( new CSharpParameter( field.NullableTypeName, "value", field.TypeIs( typeof( string ) ) ? "\"\"" : "null" ) );
            parameters.Add( new CSharpParameter( "int?", "cellSpan", "null" ) );
            parameters.Add( new CSharpParameter( "TextAlignment", "textAlignment", "TextAlignment.NotSpecified" ) );
            if( includeValidationMethodReturnValue.HasValue ) {
                parameters.Add( new CSharpParameter( "System.Func<bool>", "validationPredicate", "null" ) );
                parameters.Add( new CSharpParameter( "System.Action", "validationErrorNotifier", "null" ) );
                parameters.Add( new CSharpParameter( "System.Action<string,Validator>", "additionalValidationMethod", "null" ) );
                parameters.Add( new CSharpParameter( "ValidationList", "validationList", "null" ) );
            }

            writer.WriteLine(
                "public FormItem<ControlType> " + EwlStatics.GetCSharpIdentifierSimple( "Get" + field.PascalCasedName + "FormItem" ) + "<ControlType>( " +
                parameters.Select( i => i.MethodSignatureDeclaration ).GetCommaDelimitedStringFromCollection() + " ) where ControlType: Control {" );
            writer.WriteLine( body );
            writer.WriteLine( "}" );
        }
 private static void writeFormItemGetterWithValueParams(
     TextWriter writer, string controlType, ModificationField field, string controlTypeForName, string valueParamTypeName, string valueParamDefaultValue,
     IEnumerable<CSharpParameter> requiredControlParams, IEnumerable<CSharpParameter> requiredValidationParams, IEnumerable<CSharpParameter> optionalControlParams,
     IEnumerable<CSharpParameter> optionalValidationParams, string preFormItemGetterStatements, string controlGetterExpressionOrBlock,
     string validationMethodExpressionOrBlock, string labelOverrideNullCoalescingExpression, string postFormItemGetterStatements,
     IEnumerable<string> additionalSummarySentences)
 {
     var validationMethod = "( control, postBackValues, subject, validator ) => " + validationMethodExpressionOrBlock;
     var formItemGetterStatement = "var formItem = " + EwlStatics.GetCSharpIdentifierSimple( "Get" + field.PascalCasedName + "FormItem" ) +
                                   "( useValueParameter, ( v, ls ) => " + controlGetterExpressionOrBlock +
                                   ( validationMethodExpressionOrBlock.Any() ? ", " + validationMethod : "" ) +
                                   ", labelAndSubject: labelAndSubject, labelOverride: labelOverride" +
                                   labelOverrideNullCoalescingExpression.PrependDelimiter( " ?? " ) +
                                   ", value: value, cellSpan: cellSpan, textAlignment: textAlignment" +
                                   ( validationMethodExpressionOrBlock.Any()
                                         ? ", validationPredicate: validationPredicate, validationErrorNotifier: validationErrorNotifier, additionalValidationMethod: additionalValidationMethod, validationList: validationList"
                                         : "" ) + " );";
     writeFormItemGetter(
         writer,
         controlType,
         field,
         controlTypeForName,
         valueParamTypeName,
         requiredControlParams,
         requiredValidationParams,
         valueParamDefaultValue,
         optionalControlParams,
         validationMethodExpressionOrBlock.Any(),
         optionalValidationParams,
         StringTools.ConcatenateWithDelimiter(
             Environment.NewLine,
             preFormItemGetterStatements,
             formItemGetterStatement,
             postFormItemGetterStatements,
             "return formItem;" ),
         additionalSummarySentences );
 }
        private static void writeFormItemGetterWithoutValueParams(
            TextWriter writer, string controlType, ModificationField field, string controlTypeForName, bool includeValidationParams,
            IEnumerable<CSharpParameter> requiredControlParams, IEnumerable<CSharpParameter> requiredValidationParams, IEnumerable<CSharpParameter> optionalControlParams,
            IEnumerable<CSharpParameter> optionalValidationParams, IEnumerable<string> additionalSummarySentences)
        {
            // NOTE: The "out" parameter logic is a hack. We need to improve CSharpParameter.
            var body = "return " + EwlStatics.GetCSharpIdentifierSimple( "Get" + field.PascalCasedName + controlTypeForName + "FormItem" ) + "( false, " +
                       requiredControlParams.Concat( requiredValidationParams )
                           .Select( i => ( i.MethodSignatureDeclaration.StartsWith( "out " ) ? "out " : "" ) + i.Name )
                           .GetCommaDelimitedStringFromCollection()
                           .AppendDelimiter( ", " ) + "labelAndSubject: labelAndSubject, labelOverride: labelOverride, " +
                       optionalControlParams.Select( i => i.Name + ": " + i.Name ).GetCommaDelimitedStringFromCollection().AppendDelimiter( ", " ) +
                       "cellSpan: cellSpan, textAlignment: textAlignment" + ( includeValidationParams ? ", validationPredicate: validationPredicate" : "" ) +
                       optionalValidationParams.Select( i => i.Name + ": " + i.Name ).GetCommaDelimitedStringFromCollection().PrependDelimiter( ", " ) +
                       ( includeValidationParams
                             ? ", validationErrorNotifier: validationErrorNotifier, additionalValidationMethod: additionalValidationMethod, validationList: validationList"
                             : "" ) + " );";

            writeFormItemGetter(
                writer,
                controlType,
                field,
                controlTypeForName,
                "",
                requiredControlParams,
                requiredValidationParams,
                "",
                optionalControlParams,
                includeValidationParams,
                optionalValidationParams,
                body,
                additionalSummarySentences );
        }
 private static void writeFormItemGetters(
     TextWriter writer, ModificationField field, string controlType, string controlTypeForName, string valueParamTypeName, string valueParamDefaultValue,
     IEnumerable<CSharpParameter> requiredControlParams, IEnumerable<CSharpParameter> requiredValidationParams, IEnumerable<CSharpParameter> optionalControlParams,
     IEnumerable<CSharpParameter> optionalValidationParams, string controlGetterExpressionOrBlock, string validationMethodExpressionOrBlock,
     string labelOverrideNullCoalescingExpression, string preFormItemGetterStatements = "", string postFormItemGetterStatements = "",
     IEnumerable<string> additionalSummarySentences = null)
 {
     writeFormItemGetterWithoutValueParams(
         writer,
         controlType,
         field,
         controlTypeForName,
         validationMethodExpressionOrBlock.Any(),
         requiredControlParams,
         requiredValidationParams,
         optionalControlParams,
         optionalValidationParams,
         additionalSummarySentences ?? new string[ 0 ] );
     writeFormItemGetterWithValueParams(
         writer,
         controlType,
         field,
         controlTypeForName,
         valueParamTypeName,
         valueParamDefaultValue,
         requiredControlParams,
         requiredValidationParams,
         optionalControlParams,
         optionalValidationParams,
         preFormItemGetterStatements,
         controlGetterExpressionOrBlock,
         validationMethodExpressionOrBlock,
         labelOverrideNullCoalescingExpression,
         postFormItemGetterStatements,
         additionalSummarySentences ?? new string[ 0 ] );
 }
        private static void writeFormItemGetter(
            TextWriter writer, string controlType, ModificationField field, string controlTypeForName, string valueParamTypeName,
            IEnumerable<CSharpParameter> requiredControlParams, IEnumerable<CSharpParameter> requiredValidationParams, string valueParamDefaultValue,
            IEnumerable<CSharpParameter> optionalControlParams, bool includeValidationParams, IEnumerable<CSharpParameter> optionalValidationParams, string body,
            IEnumerable<string> additionalSummarySentences)
        {
            CodeGenerationStatics.AddSummaryDocComment( writer, getFormItemGetterSummary( field, controlTypeForName, additionalSummarySentences ) );
            CodeGenerationStatics.AddParamDocComment( writer, "additionalValidationMethod", "Passes the labelAndSubject and a validator to the function." );
            CodeGenerationStatics.AddParamDocComment( writer, "validationList", validationListParamDocComment );

            var parameters = new List<CSharpParameter>();
            if( valueParamTypeName.Length > 0 )
                parameters.Add( new CSharpParameter( "bool", "useValueParameter" ) );
            parameters.AddRange( requiredControlParams );
            parameters.AddRange( requiredValidationParams );
            parameters.Add( new CSharpParameter( "string", "labelAndSubject", "\"" + getDefaultLabelAndSubject( field ) + "\"" ) );
            parameters.Add( new CSharpParameter( "FormItemLabel", "labelOverride", "null" ) );
            if( valueParamTypeName.Length > 0 )
                parameters.Add( new CSharpParameter( valueParamTypeName, "value", valueParamDefaultValue ) );
            parameters.AddRange( optionalControlParams );
            parameters.Add( new CSharpParameter( "int?", "cellSpan", "null" ) );
            parameters.Add( new CSharpParameter( "TextAlignment", "textAlignment", "TextAlignment.NotSpecified" ) );
            if( includeValidationParams )
                parameters.Add( new CSharpParameter( "System.Func<bool>", "validationPredicate", "null" ) );
            parameters.AddRange( optionalValidationParams );
            if( includeValidationParams ) {
                parameters.Add( new CSharpParameter( "System.Action", "validationErrorNotifier", "null" ) );
                parameters.Add( new CSharpParameter( "System.Action<string,Validator>", "additionalValidationMethod", "null" ) );
                parameters.Add( new CSharpParameter( "ValidationList", "validationList", "null" ) );
            }

            writer.WriteLine(
                "public FormItem<" + controlType + "> " + EwlStatics.GetCSharpIdentifierSimple( "Get" + field.PascalCasedName + controlTypeForName + "FormItem" ) + "( " +
                parameters.Select( i => i.MethodSignatureDeclaration ).GetCommaDelimitedStringFromCollection() + " ) {" );
            writer.WriteLine( body );
            writer.WriteLine( "}" );
        }
        private static void writeCheckBoxFormItemGetters( TextWriter writer, ModificationField field, string valueParamTypeName )
        {
            var fieldIsDecimal = valueParamTypeName == "decimal";
            var valueParamDefaultValue = fieldIsDecimal ? false.BooleanToDecimal().ToString() : "false";
            var toBoolSuffix = fieldIsDecimal ? ".DecimalToBoolean()" : "";
            var fromBoolSuffix = fieldIsDecimal ? ".BooleanToDecimal()" : "";

            writeFormItemGetters(
                writer,
                field,
                "EwfCheckBox",
                "CheckBox",
                valueParamTypeName,
                valueParamDefaultValue,
                new CSharpParameter[ 0 ],
                new CSharpParameter[ 0 ],
                new[]
                    {
                        new CSharpParameter( "bool", "putLabelOnCheckBox", "true" ), new CSharpParameter( "PostBack", "postBack", "null" ),
                        new CSharpParameter( "bool", "autoPostBack", "false" )
                    },
                new CSharpParameter[ 0 ],
                "new EwfCheckBox( v.Value" + toBoolSuffix + ", label: putLabelOnCheckBox ? ls : \"\", postBack: postBack ) { AutoPostBack = autoPostBack }",
                "control.IsCheckedInPostBack( postBackValues )" + fromBoolSuffix,
                "( putLabelOnCheckBox ? \"\" : (FormItemLabel)null )" );
            writeFormItemGetters(
                writer,
                field,
                "BlockCheckBox",
                "BlockCheckBox",
                valueParamTypeName,
                valueParamDefaultValue,
                new CSharpParameter( "IEnumerable<Control>", "nestedControls" ).ToSingleElementArray(),
                new CSharpParameter[ 0 ],
                new[]
                    {
                        new CSharpParameter( "bool", "putLabelOnCheckBox", "true" ), new CSharpParameter( "PostBack", "postBack", "null" ),
                        new CSharpParameter( "bool", "autoPostBack", "false" ), new CSharpParameter( "bool", "nestedControlsAlwaysVisible", "false" )
                    },
                new CSharpParameter[ 0 ],
                "{ " +
                StringTools.ConcatenateWithDelimiter(
                    " ",
                    "var c = new BlockCheckBox( v.Value" + toBoolSuffix +
                    ", label: putLabelOnCheckBox ? ls : \"\", postBack: postBack ) { AutoPostBack = autoPostBack, NestedControlsAlwaysVisible = nestedControlsAlwaysVisible };",
                    "c.NestedControls.AddRange( nestedControls );",
                    "return c;" ) + " }",
                "control.IsCheckedInPostBack( postBackValues )" + fromBoolSuffix,
                "( putLabelOnCheckBox ? \"\" : (FormItemLabel)null )" );
        }
 private static void writeGenericGetterWithoutValueParams( TextWriter writer, ModificationField field, bool? includeValidationMethodReturnValue )
 {
     var controlGetter = "( v, ls ) => controlGetter( v" + ( field.TypeName != field.NullableTypeName ? ".Value" : "" ) + ", ls )";
     var body = "return " + EwlStatics.GetCSharpIdentifierSimple( "Get" + field.PascalCasedName + "FormItem" ) + "( false, " + controlGetter +
                ( includeValidationMethodReturnValue.HasValue ? ", validationMethod" : "" ) +
                ", labelAndSubject: labelAndSubject, labelOverride: labelOverride, cellSpan: cellSpan, textAlignment: textAlignment" +
                ( includeValidationMethodReturnValue.HasValue
                      ? ", validationPredicate: validationPredicate, validationErrorNotifier: validationErrorNotifier, additionalValidationMethod: additionalValidationMethod, validationList: validationList"
                      : "" ) + " );";
     writeGenericGetter( writer, field, false, includeValidationMethodReturnValue, body );
 }
        private static void writeStringFormItemGetters(TextWriter writer, ModificationField field)
        {
            if (!field.TypeIs(typeof(string)))
            {
                return;
            }

            writeFormItemGetters(
                writer,
                field,
                "EwfTextBox",
                "Text",
                "string",
                "\"\"",
                new CSharpParameter[0],
                getAllowEmptyParameter(false).ToSingleElementArray(),
                new[]
            {
                new CSharpParameter("int", "textBoxRows", "1"), new CSharpParameter("bool", "masksCharacters", "false"),
                new CSharpParameter("bool", "readOnly", "false"), new CSharpParameter("bool?", "suggestSpellCheck", "null"),
                new CSharpParameter("PostBack", "postBack", "null"), new CSharpParameter("bool", "autoPostBack", "false")
            },
                new CSharpParameter[0],
                "new EwfTextBox( v, rows: textBoxRows, masksCharacters: masksCharacters, " + (field.Size.HasValue ? "maxLength: " + field.Size.Value + ", " : "") +
                "readOnly: readOnly, suggestSpellCheck: suggestSpellCheck, postBack: postBack, autoPostBack: autoPostBack )",
                "validator.GetString( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty" +
                (field.Size.HasValue ? ", " + field.Size.Value : "") + " )",
                "");
            writeFormItemGetters(
                writer,
                field,
                "EwfTextBox",
                "EmailAddress",
                "string",
                "\"\"",
                new CSharpParameter[0],
                getAllowEmptyParameter(false).ToSingleElementArray(),
                new[]
            {
                new CSharpParameter("bool", "readOnly", "false"), new CSharpParameter("PostBack", "postBack", "null"),
                new CSharpParameter("bool", "autoPostBack", "false")
            },
                new CSharpParameter[0],
                "new EwfTextBox( v" + (field.Size.HasValue ? ", maxLength: " + field.Size.Value : "") +
                ", readOnly: readOnly, postBack: postBack, autoPostBack: autoPostBack )",
                "validator.GetEmailAddress( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty" +
                (field.Size.HasValue ? ", maxLength: " + field.Size.Value : "") + " )",
                "");
            writeFormItemGetters(
                writer,
                field,
                "EwfTextBox",
                "PhoneNumber",
                "string",
                "\"\"",
                new CSharpParameter[0],
                getAllowEmptyParameter(false).ToSingleElementArray(),
                new[]
            {
                new CSharpParameter("bool", "readOnly", "false"), new CSharpParameter("PostBack", "postBack", "null"),
                new CSharpParameter("bool", "autoPostBack", "false")
            },
                new[] { new CSharpParameter("bool", "allowExtension", "true"), new CSharpParameter("bool", "allowSurroundingGarbage", "false") },
                "new EwfTextBox( v" + (field.Size.HasValue ? ", maxLength: " + field.Size.Value : "") +
                ", readOnly: readOnly, postBack: postBack, autoPostBack: autoPostBack )",
                "validator.GetPhoneNumber( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowExtension, allowEmpty, allowSurroundingGarbage )",
                "");
            writeFormItemGetters(
                writer,
                field,
                "EwfTextBox",
                "ZipCode",
                "string",
                "\"\"",
                new CSharpParameter[0],
                getAllowEmptyParameter(false).ToSingleElementArray(),
                new[]
            {
                new CSharpParameter("bool", "readOnly", "false"), new CSharpParameter("PostBack", "postBack", "null"),
                new CSharpParameter("bool", "autoPostBack", "false")
            },
                new CSharpParameter[0],
                "new EwfTextBox( v" + (field.Size.HasValue ? ", maxLength: " + field.Size.Value : "") +
                ", readOnly: readOnly, postBack: postBack, autoPostBack: autoPostBack )",
                "validator.GetZipCode( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty ).FullZipCode",
                "");
            writeFormItemGetters(
                writer,
                field,
                "EwfTextBox",
                "Uri",
                "string",
                "\"\"",
                new CSharpParameter[0],
                getAllowEmptyParameter(false).ToSingleElementArray(),
                new[]
            {
                new CSharpParameter("bool", "readOnly", "false"), new CSharpParameter("PostBack", "postBack", "null"),
                new CSharpParameter("bool", "autoPostBack", "false")
            },
                new CSharpParameter[0],
                "new EwfTextBox( v" + (field.Size.HasValue ? ", maxLength: " + field.Size.Value : "") +
                ", readOnly: readOnly, postBack: postBack, autoPostBack: autoPostBack )",
                "validator.GetUrl( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty" +
                (field.Size.HasValue ? ", " + field.Size.Value : "") + " )",
                "");
            writeFormItemGetters(
                writer,
                field,
                "SelectList<string>",
                "RadioList",
                "string",
                "\"\"",
                new[] { new CSharpParameter("IEnumerable<SelectListItem<string>>", "items") },
                new CSharpParameter[0],
                new[]
            {
                new CSharpParameter("bool", "useHorizontalLayout", "false"), new CSharpParameter("string", "defaultValueItemLabel", "\"\""),
                new CSharpParameter("bool", "disableSingleButtonDetection", "false"), new CSharpParameter("PostBack", "postBack", "null"),
                new CSharpParameter("bool", "autoPostBack", "false")
            },
                new CSharpParameter[0],
                "SelectList.CreateRadioList( items, v, useHorizontalLayout: useHorizontalLayout, defaultValueItemLabel: defaultValueItemLabel, disableSingleButtonDetection: disableSingleButtonDetection, postBack: postBack, autoPostBack: autoPostBack )",
                "control.ValidateAndGetSelectedItemIdInPostBack( postBackValues, validator )",
                "");
            writeFormItemGetters(
                writer,
                field,
                "SelectList<string>",
                "DropDown",
                "string",
                "\"\"",
                new[] { new CSharpParameter("IEnumerable<SelectListItem<string>>", "items") },
                new CSharpParameter[0],
                new[]
            {
                new CSharpParameter("Unit?", "width", "null"), new CSharpParameter("string", "defaultValueItemLabel", "\"\""),
                new CSharpParameter("bool", "placeholderIsValid", "false"), new CSharpParameter("string", "placeholderText", "\"Please select\""),
                new CSharpParameter("PostBack", "postBack", "null"), new CSharpParameter("bool", "autoPostBack", "false")
            },
                new CSharpParameter[0],
                "SelectList.CreateDropDown( items, v, width: width, defaultValueItemLabel: defaultValueItemLabel, placeholderIsValid: placeholderIsValid, placeholderText: placeholderText, postBack: postBack, autoPostBack: autoPostBack )",
                "control.ValidateAndGetSelectedItemIdInPostBack( postBackValues, validator )",
                "");
            writeFormItemGetters(
                writer,
                field,
                "WysiwygHtmlEditor",
                "Html",
                "string",
                "\"\"",
                new CSharpParameter[0],
                getAllowEmptyParameter(false).ToSingleElementArray(),
                new CSharpParameter("string", "ckEditorConfiguration", "\"\"").ToSingleElementArray(),
                new CSharpParameter[0],
                "new WysiwygHtmlEditor( v, ckEditorConfiguration: ckEditorConfiguration )",
                "validator.GetString( new ValidationErrorHandler( subject ), control.GetPostBackValue( postBackValues ), allowEmpty" +
                (field.Size.HasValue ? ", " + field.Size.Value : "") + " )",
                "",
                additionalSummarySentences:
                new[]
            {
                "WARNING: Do not use this form-item getter unless you know exactly what you're doing.",
                "If you want to store HTML, it is almost always better to use an HTML block instead of just a string field.",
                "HTML blocks have special handling for intra-site URIs and may include additional features in the future.",
                "They also cause all of your HTML to be stored in one place, which is usually a good practice."
            });
        }
 private static void writeGenericGetterWithValueParams( TextWriter writer, ModificationField field, bool? includeValidationMethodReturnValue )
 {
     var control = "useValueParameter ? controlGetter( value, labelAndSubject ) : controlGetter( " + EwlStatics.GetCSharpIdentifierSimple( field.PropertyName ) +
                   ", labelAndSubject )";
     var body = "return FormItem.Create( labelOverride ?? labelAndSubject, " + control + ", cellSpan: cellSpan, textAlignment: textAlignment" +
                ( includeValidationMethodReturnValue.HasValue
                      ? ", validationGetter: " + getValidationGetter( field, includeValidationMethodReturnValue.Value )
                      : "" ) + " );";
     writeGenericGetter( writer, field, true, includeValidationMethodReturnValue, body );
 }
Exemplo n.º 27
0
        private static void writeNumericFormItemGetters(TextWriter writer, ModificationField field)
        {
            if (field.TypeIs(typeof(int)) || field.TypeIs(typeof(long)) || field.TypeIs(typeof(short)) || field.TypeIs(typeof(byte)) ||
                field.TypeIs(typeof(decimal)))
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "NumberControl",
                    Enumerable.Empty <CSharpParameter>(),
                    false,
                    new CSharpParameter("NumberControlSetup", "controlSetup", defaultValue: "null").ToCollection(),
                    "SpecifiedValue<{0}>".FormatWith(field.NullableTypeName),
                    new CSharpParameter(field.NullableTypeName, "minValue", "null").ToCollection()
                    .Append(new CSharpParameter(field.NullableTypeName, "maxValue", "null"))
                    .Append(new CSharpParameter(field.NullableTypeName, "valueStep", "null")),
                    true,
                    dv =>
                    "{0}.ToNumberControl( setup: controlSetup, value: value, minValue: minValue, maxValue: maxValue, valueStep: valueStep, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv),
                    preFormItemStatements: getNumberControlValueStepStatements(field));
            }
            if (field.TypeIs(typeof(int?)) || field.TypeIs(typeof(long?)) || field.TypeIs(typeof(short?)) || field.TypeIs(typeof(byte?)) ||
                field.TypeIs(typeof(decimal? )))
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "NumberControl",
                    Enumerable.Empty <CSharpParameter>(),
                    false,
                    new CSharpParameter("NumberControlSetup", "controlSetup", defaultValue: "null").ToCollection(),
                    "SpecifiedValue<{0}>".FormatWith(field.NullableTypeName),
                    getAllowEmptyParameter(true)
                    .ToCollection()
                    .Append(new CSharpParameter(field.NullableTypeName, "minValue", "null"))
                    .Append(new CSharpParameter(field.NullableTypeName, "maxValue", "null"))
                    .Append(new CSharpParameter(field.NullableTypeName, "valueStep", "null")),
                    true,
                    dv =>
                    "{0}.ToNumberControl( setup: controlSetup, value: value, allowEmpty: allowEmpty, minValue: minValue, maxValue: maxValue, valueStep: valueStep, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv),
                    preFormItemStatements: getNumberControlValueStepStatements(field));
            }

            if (field.TypeIs(typeof(int)) || field.TypeIs(typeof(long)) || field.TypeIs(typeof(short)) || field.TypeIs(typeof(byte)) ||
                field.TypeIs(typeof(decimal)))
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "ImpreciseNumberControl",
                    new CSharpParameter(field.TypeName, "minValue").ToCollection().Append(new CSharpParameter(field.TypeName, "maxValue")),
                    false,
                    new CSharpParameter("ImpreciseNumberControlSetup", "controlSetup", defaultValue: "null").ToCollection(),
                    field.NullableTypeName,
                    new CSharpParameter(field.NullableTypeName, "valueStep", "null").ToCollection(),
                    true,
                    dv =>
                    "{0}.ToImpreciseNumberControl( minValue, maxValue, setup: controlSetup, value: value, valueStep: valueStep, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv),
                    preFormItemStatements: getNumberControlValueStepStatements(field));
            }

            if (field.TypeIs(typeof(int)))
            {
                writeHtmlAndFileFormItemGetters(writer, field, "int?");
            }
            if (field.TypeIs(typeof(int?)))
            {
                writeHtmlAndFileFormItemGetters(writer, field, "int?");
            }

            if (field.TypeIs(typeof(decimal)))
            {
                writeHtmlAndFileFormItemGetters(writer, field, "decimal?");
            }
            if (field.TypeIs(typeof(decimal? )))
            {
                writeHtmlAndFileFormItemGetters(writer, field, "decimal?");
            }
        }
 private static void writeGuidFormItemGetters( TextWriter writer, ModificationField field )
 {
     if( !field.TypeIs( typeof( Guid ) ) )
         return;
     writeNumberAsSelectListFormItemGetters( writer, field );
 }
Exemplo n.º 29
0
        private static void writeCheckboxFormItemGetters(TextWriter writer, ModificationField field)
        {
            if (!field.TypeIs(typeof(bool)) && !field.TypeIs(typeof(bool?)) && !field.TypeIs(typeof(decimal)) && !field.TypeIs(typeof(decimal? )))
            {
                return;
            }

            var preFormItemStatements = field.TypeName == field.NullableTypeName
                                                            ? "var nonNullableValue = new DataValue<{0}>();".FormatWith(field.TypeIs(typeof(decimal? )) ? "decimal" : "bool")
                                            : "";

            string getDataValueExpression(string dv) => field.TypeName == field.NullableTypeName ? "nonNullableValue" : dv;
            string getValueExpression(string dv) => field.TypeName == field.NullableTypeName ? "value ?? {0}.Value.Value".FormatWith(dv) : "value";

            string getAdditionalValidationMethodExpression(string dv) =>
            field.TypeName == field.NullableTypeName
                                        ? "validator => {{ {0}.Value = nonNullableValue.Value; additionalValidationMethod?.Invoke( validator ); }}".FormatWith(dv)
                                        : "additionalValidationMethod";

            // checkboxes
            writeFormItemGetter(
                writer,
                field,
                "Checkbox",
                new CSharpParameter[0],
                true,
                new[] { new CSharpParameter("CheckboxSetup", "checkboxSetup", "null") },
                field.NullableTypeName,
                new CSharpParameter[0],
                true,
                dv =>
                "{0}.ToCheckbox( label, setup: checkboxSetup, value: {1}, additionalValidationMethod: {2} ).ToFormItem( setup: formItemSetup, label: formItemLabel )"
                .FormatWith(getDataValueExpression(dv), getValueExpression(dv), getAdditionalValidationMethodExpression(dv)),
                preFormItemStatements: preFormItemStatements);
            writeFormItemGetter(
                writer,
                field,
                "FlowCheckbox",
                new CSharpParameter[0],
                true,
                new[] { new CSharpParameter("FlowCheckboxSetup", "checkboxSetup", "null") },
                field.NullableTypeName,
                new CSharpParameter[0],
                true,
                dv =>
                "{0}.ToFlowCheckbox( label, setup: checkboxSetup, value: {1}, additionalValidationMethod: {2} ).ToFormItem( setup: formItemSetup, label: formItemLabel )"
                .FormatWith(getDataValueExpression(dv), getValueExpression(dv), getAdditionalValidationMethodExpression(dv)),
                preFormItemStatements: preFormItemStatements);

            // radio buttons
            writeFormItemGetter(
                writer,
                field,
                "RadioButton",
                new CSharpParameter("RadioButtonGroup", "group").ToCollection(),
                true,
                new[] { new CSharpParameter("RadioButtonSetup", "radioButtonSetup", "null") },
                field.NullableTypeName,
                new CSharpParameter[0],
                true,
                dv =>
                "{0}.ToRadioButton( group, label, setup: radioButtonSetup, value: {1}, additionalValidationMethod: {2} ).ToFormItem( setup: formItemSetup, label: formItemLabel )"
                .FormatWith(getDataValueExpression(dv), getValueExpression(dv), getAdditionalValidationMethodExpression(dv)),
                preFormItemStatements: preFormItemStatements);
            writeFormItemGetter(
                writer,
                field,
                "FlowRadioButton",
                new CSharpParameter("RadioButtonGroup", "group").ToCollection(),
                true,
                new[] { new CSharpParameter("FlowRadioButtonSetup", "radioButtonSetup", "null") },
                field.NullableTypeName,
                new CSharpParameter[0],
                true,
                dv =>
                "{0}.ToFlowRadioButton( group, label, setup: radioButtonSetup, value: {1}, additionalValidationMethod: {2} ).ToFormItem( setup: formItemSetup, label: formItemLabel )"
                .FormatWith(getDataValueExpression(dv), getValueExpression(dv), getAdditionalValidationMethodExpression(dv)),
                preFormItemStatements: preFormItemStatements);
        }
 private static void writeHtmlAndFileFormItemGetters( TextWriter writer, ModificationField field, string valueParamTypeName )
 {
     writeFormItemGetters(
         writer,
         field,
         "HtmlBlockEditor",
         "Html",
         valueParamTypeName,
         "null",
         new CSharpParameter( "out HtmlBlockEditorModification", "mod" ).ToSingleElementArray(),
         new CSharpParameter[ 0 ],
         new CSharpParameter( "string", "ckEditorConfiguration", "\"\"" ).ToSingleElementArray(),
         new CSharpParameter[ 0 ],
         "new HtmlBlockEditor( (int?)v, id => " + field.PropertyName + " = id, out m, ckEditorConfiguration: ckEditorConfiguration )",
         "control.Validate( postBackValues, validator, new ValidationErrorHandler( subject ) )",
         "",
         preFormItemGetterStatements: "HtmlBlockEditorModification m = null;",
         postFormItemGetterStatements: "mod = m;" );
     writeFormItemGetters(
         writer,
         field,
         "BlobFileManager",
         "File",
         valueParamTypeName,
         "null",
         new CSharpParameter( "out System.Action", "modificationMethod" ).ToSingleElementArray(),
         new CSharpParameter[ 0 ],
         new CSharpParameter[ 0 ],
         new CSharpParameter( "bool", "requireUploadIfNoFile", "false" ).ToSingleElementArray(),
         "{ var control = new BlobFileManager(); if( v.HasValue ) control.LoadData( (int)v.Value ); mm = () => " + field.PropertyName +
         " = control.ModifyData(); return control; }",
         "control.ValidateFormValues( validator, subject, requireUploadIfNoFile )",
         "",
         preFormItemGetterStatements: "System.Action mm = null;",
         postFormItemGetterStatements: "modificationMethod = mm;" );
 }
Exemplo n.º 31
0
        private static void writeDateAndTimeFormItemGetters(TextWriter writer, ModificationField field)
        {
            if (field.TypeIs(typeof(DateTime)))
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "DateControl",
                    Enumerable.Empty <CSharpParameter>(),
                    false,
                    new CSharpParameter("DateControlSetup", "controlSetup", defaultValue: "null").ToCollection(),
                    "SpecifiedValue<{0}>".FormatWith(field.NullableTypeName),
                    new CSharpParameter("LocalDate?", "minValue", "null").ToCollection().Append(new CSharpParameter("LocalDate?", "maxValue", "null")),
                    true,
                    dv =>
                    "{0}.ToDateControl( setup: controlSetup, value: value, minValue: minValue, maxValue: maxValue, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv));
            }
            if (field.TypeIs(typeof(DateTime? )))
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "DateControl",
                    Enumerable.Empty <CSharpParameter>(),
                    false,
                    new CSharpParameter("DateControlSetup", "controlSetup", defaultValue: "null").ToCollection(),
                    "SpecifiedValue<{0}>".FormatWith(field.NullableTypeName),
                    getAllowEmptyParameter(true)
                    .ToCollection()
                    .Append(new CSharpParameter("LocalDate?", "minValue", "null"))
                    .Append(new CSharpParameter("LocalDate?", "maxValue", "null")),
                    true,
                    dv =>
                    "{0}.ToDateControl( setup: controlSetup, value: value, allowEmpty: allowEmpty, minValue: minValue, maxValue: maxValue, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv));
            }

            if (field.TypeIs(typeof(DateTime)))
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "DateAndTimeControl",
                    Enumerable.Empty <CSharpParameter>(),
                    false,
                    new CSharpParameter("DateAndTimeControlSetup", "controlSetup", defaultValue: "null").ToCollection(),
                    "SpecifiedValue<{0}>".FormatWith(field.NullableTypeName),
                    new CSharpParameter("LocalDate?", "minValue", "null").ToCollection().Append(new CSharpParameter("LocalDate?", "maxValue", "null")),
                    true,
                    dv =>
                    "{0}.ToDateAndTimeControl( setup: controlSetup, value: value, minValue: minValue, maxValue: maxValue, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv));
            }
            if (field.TypeIs(typeof(DateTime? )))
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "DateAndTimeControl",
                    Enumerable.Empty <CSharpParameter>(),
                    false,
                    new CSharpParameter("DateAndTimeControlSetup", "controlSetup", defaultValue: "null").ToCollection(),
                    "SpecifiedValue<{0}>".FormatWith(field.NullableTypeName),
                    getAllowEmptyParameter(true)
                    .ToCollection()
                    .Append(new CSharpParameter("LocalDate?", "minValue", "null"))
                    .Append(new CSharpParameter("LocalDate?", "maxValue", "null")),
                    true,
                    dv =>
                    "{0}.ToDateAndTimeControl( setup: controlSetup, value: value, allowEmpty: allowEmpty, minValue: minValue, maxValue: maxValue, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv));
            }

            if (field.TypeIs(typeof(int)) || field.TypeIs(typeof(int?)) || field.TypeIs(typeof(decimal)) || field.TypeIs(typeof(decimal? )))
            {
                writeFormItemGetter(
                    writer,
                    field,
                    "DurationControl",
                    Enumerable.Empty <CSharpParameter>(),
                    false,
                    new CSharpParameter("DurationControlSetup", "controlSetup", defaultValue: "null").ToCollection(),
                    "SpecifiedValue<{0}>".FormatWith(field.NullableTypeName),
                    field.TypeName == field.NullableTypeName ? getAllowEmptyParameter(true).ToCollection() : Enumerable.Empty <CSharpParameter>(),
                    true,
                    dv => field.TypeName == field.NullableTypeName
                                                      ? "{0}.ToDurationControl( setup: controlSetup, value: value, allowEmpty: allowEmpty, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv)
                                                      : "{0}.ToDurationControl( setup: controlSetup, value: value, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: label )"
                    .FormatWith(dv));
            }
        }
 private static void writeNumberAsSelectListFormItemGetters( TextWriter writer, ModificationField field )
 {
     var nonNullableField = field.TypeName != field.NullableTypeName;
     writeFormItemGetters(
         writer,
         field,
         "SelectList<" + field.NullableTypeName + ">",
         "RadioList",
         field.NullableTypeName,
         "null",
         new[] { new CSharpParameter( "IEnumerable<SelectListItem<" + field.NullableTypeName + ">>", "items" ) },
         new CSharpParameter[ 0 ],
         new CSharpParameter( "bool", "useHorizontalLayout", "false" ).ToSingleElementArray()
             .Concat( nonNullableField ? new CSharpParameter[ 0 ] : new CSharpParameter( "string", "defaultValueItemLabel", "\"None\"" ).ToSingleElementArray() )
             .Concat(
                 new[]
                     {
                         new CSharpParameter( "bool", "disableSingleButtonDetection", "false" ), new CSharpParameter( "PostBack", "postBack", "null" ),
                         new CSharpParameter( "bool", "autoPostBack", "false" )
                     } ),
         new CSharpParameter[ 0 ],
         "SelectList.CreateRadioList( items, v, useHorizontalLayout: useHorizontalLayout, defaultValueItemLabel: " +
         ( nonNullableField ? "\"\"" : "defaultValueItemLabel" ) +
         ", disableSingleButtonDetection: disableSingleButtonDetection, postBack: postBack, autoPostBack: autoPostBack )",
         "{ var selectedItemIdInPostBack = control.ValidateAndGetSelectedItemIdInPostBack( postBackValues, validator ); return " +
         ( nonNullableField ? "selectedItemIdInPostBack.HasValue ? selectedItemIdInPostBack.Value : default( " + field.TypeName + " )" : "selectedItemIdInPostBack" ) +
         "; }",
         "" );
     writeFormItemGetters(
         writer,
         field,
         "SelectList<" + field.NullableTypeName + ">",
         "DropDown",
         field.NullableTypeName,
         "null",
         new CSharpParameter( "IEnumerable<SelectListItem<" + field.NullableTypeName + ">>", "items" ).ToSingleElementArray()
             .Concat( nonNullableField ? new CSharpParameter[ 0 ] : new CSharpParameter( "string", "defaultValueItemLabel" ).ToSingleElementArray() ),
         new CSharpParameter[ 0 ],
         new CSharpParameter( "Unit?", "width", "null" ).ToSingleElementArray()
             .Concat( ( nonNullableField ? new CSharpParameter[ 0 ] : new CSharpParameter( "bool", "placeholderIsValid", "true" ).ToSingleElementArray() ) )
             .Concat(
                 new[]
                     {
                         new CSharpParameter( "string", "placeholderText", "\"Please select\"" ), new CSharpParameter( "PostBack", "postBack", "null" ),
                         new CSharpParameter( "bool", "autoPostBack", "false" )
                     } ),
         new CSharpParameter[ 0 ],
         "SelectList.CreateDropDown( items, v, width: width, defaultValueItemLabel: " + ( nonNullableField ? "\"\"" : "defaultValueItemLabel" ) +
         ", placeholderIsValid: " + ( nonNullableField ? "false" : "placeholderIsValid" ) +
         ", placeholderText: placeholderText, postBack: postBack, autoPostBack: autoPostBack )",
         "{ var selectedItemIdInPostBack = control.ValidateAndGetSelectedItemIdInPostBack( postBackValues, validator ); return " +
         ( nonNullableField ? "selectedItemIdInPostBack.HasValue ? selectedItemIdInPostBack.Value : default( " + field.TypeName + " )" : "selectedItemIdInPostBack" ) +
         "; }",
         "" );
 }