Example #1
0
        protected override void loadData()
        {
            var staticFil = FormItemList.CreateStack(generalSetup: new FormItemListSetup(buttonSetup: new ButtonSetup("Submit")));

            staticFil.AddFormItems(
                new TextControl("Values here will be retained across post-backs", true).ToFormItem(label: "Static Field".ToComponents()),
                new TextControl("", true).ToFormItem(label: "Static Field".ToComponents()),
                new TextControl(
                    "Edit this one to get a validation error",
                    true,
                    setup: TextControlSetup.Create(validationPredicate: valueChangedOnPostBack => valueChangedOnPostBack),
                    validationMethod: (postBackValue, validator) => validator.NoteErrorAndAddMessage("You can't change the value in this box!")).ToFormItem(
                    label: "Static Field".ToComponents()));
            ph.AddControlsReturnThis(staticFil.ToCollection().GetControls());

            ph.AddControlsReturnThis(getBasicRegionComponents().GetControls());

            var listTable = EwfTable.Create(
                style: EwfTableStyle.StandardLayoutOnly,
                fields: new[] { 10, 1, 10 }.Select(i => new EwfTableField(size: i.ToPercentage())).Materialize());

            listTable.AddItem(
                EwfTableItem.Create(
                    EwfTableItemSetup.Create(verticalAlignment: TableCellVerticalAlignment.Top),
                    getNonIdListRegionComponents().ToCell(),
                    "".ToCell(),
                    getIdListRegionComponents().ToCell()));
            ph.AddControlsReturnThis(listTable.ToCollection().GetControls());
        }
        private IReadOnlyCollection <FlowComponent> getNewCommentComponents(UpdateRegionSet createUpdateRegions)
        {
            if (AppTools.User == null)
            {
                return(new Paragraph(
                           new EwfHyperlink(
                               EnterpriseWebLibrary.EnterpriseWebFramework.UserManagement.Pages.LogIn.GetInfo(Home.GetInfo().GetUrl()),
                               new StandardHyperlinkStyle("Sign in")).Concat(" or ".ToComponents())
                           .Append(new EwfHyperlink(User.GetInfo(), new StandardHyperlinkStyle("sign up")))
                           .Concat(" to add comments on this article.".ToComponents())
                           .Materialize()).ToCollection());
            }

            commentMod = getCommentMod();
            return(FormState.ExecuteWithDataModificationsAndDefaultAction(
                       PostBack.CreateIntermediate(
                           createUpdateRegions.ToCollection(),
                           id: "comment",
                           modificationMethod: () => {
                commentMod.CommentId = MainSequence.GetNextValue();
                commentMod.Execute();
            })
                       .ToCollection(),
                       () => new FlowIdContainer(
                           commentMod.GetBodyTextTextControlFormItem(
                               false,
                               label: Enumerable.Empty <PhrasingComponent>().Materialize(),
                               controlSetup: TextControlSetup.Create(numberOfRows: 3, placeholder: "Write a comment..."),
                               value: "")
                           .ToComponentCollection()
                           .Append(new EwfButton(new StandardButtonStyle("Post Comment"))),
                           updateRegionSets: createUpdateRegions.ToCollection()).ToCollection()));
        }
Example #3
0
        protected override void loadData()
        {
            ph.AddControlsReturnThis(new LegacyParagraph("You may report any problems, make suggestions, or ask for help here."));

            FormState.ExecuteWithDataModificationsAndDefaultAction(
                PostBack.CreateFull(firstModificationMethod: modifyData, actionGetter: () => new PostBackAction(new ExternalResourceInfo(info.ReturnUrl)))
                .ToCollection(),
                () => {
                var list = FormItemList.CreateStack();
                list.AddFormItems(
                    new EmailAddress(AppTools.User.Email, AppTools.User.FriendlyName).ToMailAddress()
                    .ToString()
                    .ToComponents()
                    .ToFormItem(label: "From".ToComponents()),
                    "{0} ({1} for this system)".FormatWith(
                        StringTools.GetEnglishListPhrase(EmailStatics.GetAdministratorEmailAddresses().Select(i => i.DisplayName), true),
                        "support contacts".ToQuantity(EmailStatics.GetAdministratorEmailAddresses().Count(), showQuantityAs: ShowQuantityAs.None))
                    .ToComponents()
                    .ToFormItem(label: "To".ToComponents()),
                    body.ToTextControl(false, setup: TextControlSetup.Create(numberOfRows: 10), value: "").ToFormItem(label: "Message".ToComponents()));
                ph.AddControlsReturnThis(list.ToCollection().GetControls());

                EwfUiStatics.SetContentFootActions(new ButtonSetup("Send Message").ToCollection());
            });
        }
        protected override PageContent getContent()
        {
            var mod    = getMod();
            var tagIds = ComponentStateItem.Create(
                "tags",
                ArticleId.HasValue
                                        ? ArticleTagsTableRetrieval.GetRowsLinkedToArticle(ArticleId.Value).Select(i => i.TagId).Materialize()
                                        : Enumerable.Empty <int>().Materialize(),
                v => v.All(id => TagsTableRetrieval.GetRowMatchingId(id, returnNullIfNoMatch: true) != null),
                true);

            return(FormState.ExecuteWithDataModificationsAndDefaultAction(
                       PostBack.CreateFull(
                           modificationMethod: () => {
                if (!ArticleId.HasValue)
                {
                    mod.ArticleId = MainSequence.GetNextValue();
                    mod.Slug = getSuffixedSlug(mod.Title.ToUrlSlug());
                    mod.CreationDateAndTime = DateTime.UtcNow;
                }
                mod.Execute();

                if (ArticleId.HasValue)
                {
                    ArticleTagsModification.DeleteRows(new ArticleTagsTableEqualityConditions.ArticleId(ArticleId.Value));
                }
                foreach (var i in tagIds.Value.Value)
                {
                    ArticleTagsModification.InsertRow(mod.ArticleId, i);
                }
            },
                           actionGetter: () => new PostBackAction(Article.GetInfo(mod.ArticleId)))
                       .ToCollection(),
                       () => {
                var stack = FormItemList.CreateStack(generalSetup: new FormItemListSetup(etherealContent: tagIds.ToCollection()));

                stack.AddItems(
                    mod.GetTitleTextControlFormItem(false, label: "Article title".ToComponents(), value: ArticleId.HasValue ? null : "")
                    .Append(
                        mod.GetDescriptionTextControlFormItem(false, label: "What's this article about?".ToComponents(), value: ArticleId.HasValue ? null : ""))
                    .Append(
                        mod.GetBodyMarkdownTextControlFormItem(
                            false,
                            label: "Write your article (in markdown)".ToComponents(),
                            controlSetup: TextControlSetup.Create(numberOfRows: 8),
                            value: ArticleId.HasValue ? null : ""))
                    .Append(getTagFormItem(tagIds.Value))
                    .Materialize());

                return new UiPageContent(contentFootActions: new ButtonSetup("Publish Article").ToCollection()).Add(stack);
            }));
        }
Example #5
0
 private IReadOnlyCollection <Func <string, FormItem> > getControls() =>
 new[]
 {
     get("Standard", null), get("Max length 25", null, maxLength: 25), get("Placeholder", TextControlSetup.Create(placeholder: "Type here")),
     get("Name auto-fill", TextControlSetup.Create(autoFillTokens: "name")),
     get("Auto-complete", TextControlSetup.CreateAutoComplete(TestService.GetInfo())),
     get("Spell-checking disabled", TextControlSetup.Create(checksSpellingAndGrammar: false)),
     get("Spell-checking enabled", TextControlSetup.Create(checksSpellingAndGrammar: true)), id => {
         var pb = PostBack.CreateIntermediate(null, id: id);
         return(FormState.ExecuteWithDataModificationsAndDefaultAction(
                    FormState.Current.DataModifications.Append(pb),
                    () => get("Separate value-changed action", TextControlSetup.Create(valueChangedAction: new PostBackFormAction(pb)))(id)));
     },
     get("Read-only", TextControlSetup.CreateReadOnly()), get("Multiline", TextControlSetup.Create(numberOfRows: 3)),
     get("Multiline, max length 25", TextControlSetup.Create(numberOfRows: 3), maxLength: 25),
     get("Multiline with placeholder", TextControlSetup.Create(numberOfRows: 3, placeholder: "Type longer text here")),
     get("Multiline auto-fill", TextControlSetup.Create(numberOfRows: 3, autoFillTokens: "street-address")),
     get("Multiline auto-complete", TextControlSetup.CreateAutoComplete(TestService.GetInfo(), numberOfRows: 3)),
     get("Multiline, spell-checking disabled", TextControlSetup.Create(numberOfRows: 3, checksSpellingAndGrammar: false)),
     get("Multiline, spell-checking enabled", TextControlSetup.Create(numberOfRows: 3, checksSpellingAndGrammar: true)), id => {
         var pb = PostBack.CreateIntermediate(null, id: id);
         return(FormState.ExecuteWithDataModificationsAndDefaultAction(
                    FormState.Current.DataModifications.Append(pb),
                    () => get(
                        "Multiline with separate value-changed action",
                        TextControlSetup.Create(numberOfRows: 3, valueChangedAction: new PostBackFormAction(pb)))(id)));
     },
     get("Multiline read-only", TextControlSetup.CreateReadOnly(numberOfRows: 3)), get("Obscured", TextControlSetup.CreateObscured()),
     get("Obscured, max length 25", TextControlSetup.CreateObscured(), maxLength: 25),
     get("Obscured with placeholder", TextControlSetup.CreateObscured(placeholder: "Type here")),
     get("Obscured auto-fill", TextControlSetup.CreateObscured(autoFillTokens: "new-password")), id => {
         var pb = PostBack.CreateIntermediate(null, id: id);
         return(FormState.ExecuteWithDataModificationsAndDefaultAction(
                    FormState.Current.DataModifications.Append(pb),
                    () => get(
                        "Obscured with separate value-changed action",
                        TextControlSetup.CreateObscured(valueChangedAction: new PostBackFormAction(pb)))(id)));
     }
 };
Example #6
0
        private FlowComponent getFormItemStack(UsersModification mod, DataValue <string> password)
        {
            var stack = FormItemList.CreateStack();

            if (AppTools.User != null)
            {
                stack.AddItem(mod.GetProfilePictureUrlUrlControlFormItem(true, label: "URL of profile picture".ToComponents()));
            }
            stack.AddItem(mod.GetUsernameTextControlFormItem(false, label: "Username".ToComponents(), value: AppTools.User == null ? "" : null));
            if (AppTools.User != null)
            {
                stack.AddItem(
                    mod.GetShortBioTextControlFormItem(true, label: "Short bio about you".ToComponents(), controlSetup: TextControlSetup.Create(numberOfRows: 8)));
            }
            stack.AddItem(mod.GetEmailAddressEmailAddressControlFormItem(false, label: "Email".ToComponents(), value: AppTools.User == null ? "" : null));

            if (AppTools.User == null)
            {
                stack.AddItems(password.GetPasswordModificationFormItems());
            }
            else
            {
                var changePasswordChecked = new DataValue <bool>();
                stack.AddItem(
                    changePasswordChecked.ToFlowCheckbox(
                        "Change password".ToComponents(),
                        setup: FlowCheckboxSetup.Create(
                            nestedContentGetter: () => FormState.ExecuteWithValidationPredicate(
                                () => changePasswordChecked.Value,
                                () => FormItemList.CreateGrid(1, items: password.GetPasswordModificationFormItems()).ToCollection())),
                        value: false)
                    .ToFormItem());
            }

            return(stack);
        }