void ControlTreeDataLoader.LoadData()
        {
            action.AddToPageIfNecessary();

            CssClass = elementClass.ClassName.ConcatenateWithSpace(CssClass);

            checkBox   = new WebControl(HtmlTextWriterTag.Input);
            PreRender += delegate {
                AddCheckBoxAttributes(
                    checkBox,
                    this,
                    checkBoxFormValue,
                    radioButtonFormValue,
                    radioButtonListItemId,
                    action,
                    AutoPostBack,
                    jsClickHandlerStatementLists.SelectMany(i => i()));
                checkBox.Attributes.Add("class", elementClass.ClassName);
            };
            Controls.Add(checkBox);

            if (label.Any())
            {
                this.AddControlsReturnThis(new GenericPhrasingContainer(label.ToComponents(), classes: elementClass).ToCollection().GetControls());
            }
        }
        internal void SetUpClickableControl(WebControl clickableControl)
        {
            if (resource == null && action == null && script == "")
            {
                return;
            }

            clickableControl.CssClass = clickableControl.CssClass.ConcatenateWithSpace("ewfClickable");

            if (resource != null && EwfPage.Instance.IsAutoDataUpdater)
            {
                action   = HyperlinkBehavior.GetHyperlinkPostBackAction(resource);
                resource = null;
            }

            Func <string> scriptGetter;

            if (resource != null)
            {
                scriptGetter = () => "location.href = '" + EwfPage.Instance.GetClientUrl(resource.GetUrl()) + "'; return false";
            }
            else if (action != null)
            {
                action.AddToPageIfNecessary();
                scriptGetter = () => action.GetJsStatements() + " return false";
            }
            else
            {
                scriptGetter = () => script;
            }

            // Defer script generation until after all controls have IDs.
            EwfPage.Instance.PreRender += delegate { clickableControl.AddJavaScriptEventScript(JsWritingMethods.onclick, scriptGetter()); };
        }
Пример #3
0
        /// <summary>
        /// Creates a submit button.
        /// </summary>
        /// <param name="style">The style.</param>
        /// <param name="displaySetup"></param>
        /// <param name="classes">The classes on the button.</param>
        /// <param name="postBack">Pass null to use the post-back corresponding to the first of the current data modifications.</param>
        public SubmitButton(ButtonStyle style, DisplaySetup displaySetup = null, ElementClassSet classes = null, PostBack postBack = null)
        {
            var elementChildren = style.GetChildren();
            var postBackAction  = new PostBackFormAction(postBack ?? FormState.Current.PostBack);

            children = new DisplayableElement(
                context => {
                FormAction action = postBackAction;
                action.AddToPageIfNecessary();

                if (EwfPage.Instance.SubmitButtonPostBack != null)
                {
                    throw new ApplicationException("A submit button already exists on the page.");
                }
                EwfPage.Instance.SubmitButtonPostBack = postBackAction.PostBack;

                return(new DisplayableElementData(
                           displaySetup,
                           () =>
                           new DisplayableElementLocalData(
                               "button",
                               attributes: new[] { Tuple.Create("name", EwfPage.ButtonElementName), Tuple.Create("value", "v") },
                               jsInitStatements: style.GetJsInitStatements(context.Id)),
                           classes: style.GetClasses().Add(classes ?? ElementClassSet.Empty),
                           children: elementChildren));
            }).ToCollection();
        }
        void ControlTreeDataLoader.LoadData()
        {
            FormState.ExecuteWithDataModificationsAndDefaultAction(
                dataModifications,
                () => {
                if (TagKey == HtmlTextWriterTag.Button)
                {
                    Attributes.Add("name", EwfPage.ButtonElementName);
                    Attributes.Add("value", "v");
                    Attributes.Add("type", usesSubmitBehavior ? "submit" : "button");
                }

                FormAction action = postBackAction;
                action.AddToPageIfNecessary();

                if (ConfirmationWindowContentControl != null)
                {
                    if (usesSubmitBehavior)
                    {
                        throw new ApplicationException("PostBackButton cannot be the submit button and also have a confirmation message.");
                    }
                    confirmationWindow = new ModalWindow(this, ConfirmationWindowContentControl, title: "Confirmation", postBack: postBackAction.PostBack);
                }
                else if (!usesSubmitBehavior)
                {
                    PreRender += delegate { this.AddJavaScriptEventScript(JsWritingMethods.onclick, action.GetJsStatements() + " return false"); }
                }
                ;

                CssClass = CssClass.ConcatenateWithSpace("ewfClickable");
                ActionControlStyle.SetUpControl(this, "");
            });
        }
Пример #5
0
        internal HyperlinkBehavior(ResourceInfo destination, string target)
        {
            this.destination = destination;
            Classes          = destination?.AlternativeMode is NewContentResourceMode ? ActionComponentCssElementCreator.NewContentClass : ElementClassSet.Empty;

            Url = destination != null?destination.GetUrl(true, false, true) : "";

            var isPostBackHyperlink = destination != null && !(destination.AlternativeMode is DisabledResourceMode) && !target.Any() &&
                                      EwfPage.Instance.IsAutoDataUpdater;
            FormAction postBackAction = null;

            AttributeGetter =
                () =>
                (Url.Any() ? Tuple.Create("href", Url).ToCollection() : Enumerable.Empty <Tuple <string, string> >()).Concat(
                    target.Any() ? Tuple.Create("target", target).ToCollection() : Enumerable.Empty <Tuple <string, string> >())
                .Concat(
                    isPostBackHyperlink
                                                        ? Tuple.Create(JsWritingMethods.onclick, postBackAction.GetJsStatements() + " return false").ToCollection()
                                                        : Enumerable.Empty <Tuple <string, string> >())
                .ToImmutableArray();

            var disabledResourceMode = destination?.AlternativeMode as DisabledResourceMode;

            if (disabledResourceMode != null)
            {
                IncludeIdAttribute = true;
                Func <string, string> toolTipInitStatementGetter;
                EtherealChildren =
                    new ToolTip(
                        (disabledResourceMode.Message.Any() ? disabledResourceMode.Message : Translation.ThePageYouRequestedIsDisabled).ToComponents(),
                        out toolTipInitStatementGetter).ToCollection();
                JsInitStatementGetter = id => "$( '#{0}' ).click( function( e ) {{ e.preventDefault(); }} );".FormatWith(id) + toolTipInitStatementGetter(id);
            }
            else
            {
                EtherealChildren      = ImmutableArray <EtherealComponent> .Empty;
                JsInitStatementGetter = id => "";
            }

            if (isPostBackHyperlink)
            {
                PostBackAdder = () => {
                    postBackAction = GetHyperlinkPostBackAction(destination);
                    postBackAction.AddToPageIfNecessary();
                }
            }
            ;
            else
            {
                PostBackAdder = () => { }
            };
        }
Пример #6
0
        /// <summary>
        /// Creates a submit button.
        /// </summary>
        /// <param name="style">The style.</param>
        /// <param name="displaySetup"></param>
        /// <param name="classes">The classes on the button.</param>
        /// <param name="postBack">Pass null to use the post-back corresponding to the first of the current data modifications.</param>
        public SubmitButton(ButtonStyle style, DisplaySetup displaySetup = null, ElementClassSet classes = null, PostBack postBack = null)
        {
            var elementChildren = style.GetChildren();
            var postBackAction  = new PostBackFormAction(postBack ?? FormState.Current.PostBack);

            children = new DisplayableElement(
                context => {
                FormAction action = postBackAction;
                action.AddToPageIfNecessary();

                if (PageBase.Current.SubmitButtonPostBack != null)
                {
                    throw new ApplicationException("A submit button already exists on the page.");
                }
                PageBase.Current.SubmitButtonPostBack = postBackAction.PostBack;

                return(new DisplayableElementData(
                           displaySetup,
                           () => new DisplayableElementLocalData(
                               "button",
                               new FocusabilityCondition(true),
                               isFocused => {
                    var attributes =
                        new List <ElementAttribute> {
                        new ElementAttribute("name", PageBase.ButtonElementName), new ElementAttribute("value", "v")
                    };
                    if (isFocused)
                    {
                        attributes.Add(new ElementAttribute("autofocus"));
                    }

                    return new DisplayableElementFocusDependentData(attributes: attributes, jsInitStatements: style.GetJsInitStatements(context.Id));
                }),
                           classes: style.GetClasses().Add(classes ?? ElementClassSet.Empty),
                           children: elementChildren));
            }).ToCollection();
        }
Пример #7
0
 void ButtonBehavior.AddPostBack()
 {
     Action.AddToPageIfNecessary();
 }
        internal HyperlinkBehavior(ResourceInfo destination, string target, Func <string, string> actionStatementGetter)
        {
            this.destination = destination;
            Classes          = destination?.AlternativeMode is NewContentResourceMode ? ActionComponentCssElementCreator.NewContentClass : ElementClassSet.Empty;

            Url             = new Lazy <string>(() => destination != null ? destination.GetUrl(true, false, true) : "");
            AttributeGetter = forNonHyperlinkElement =>
                              (destination != null && !forNonHyperlinkElement ? Tuple.Create("href", Url.Value).ToCollection() : Enumerable.Empty <Tuple <string, string> >())
                              .Concat(
                destination != null && target.Any() && !forNonHyperlinkElement
                                                ? Tuple.Create("target", target).ToCollection()
                                                : Enumerable.Empty <Tuple <string, string> >())
                              .Materialize();

            var isPostBackHyperlink = destination != null && !(destination.AlternativeMode is DisabledResourceMode) && !target.Any() &&
                                      EwfPage.Instance.IsAutoDataUpdater;
            FormAction postBackAction = null;

            string getActionInitStatements(string id, bool omitPreventDefaultStatement, string actionStatements) =>
            "$( '#{0}' ).click( function( e ) {{ {1} }} );".FormatWith(
                id,
                (omitPreventDefaultStatement ? "" : "e.preventDefault();").ConcatenateWithSpace(actionStatements));

            if (destination?.AlternativeMode is DisabledResourceMode disabledResourceMode)
            {
                IncludesIdAttribute = forNonHyperlinkElement => true;
                EtherealChildren    = new ToolTip(
                    (disabledResourceMode.Message.Any() ? disabledResourceMode.Message : Translation.ThePageYouRequestedIsDisabled).ToComponents(),
                    out var toolTipInitStatementGetter).ToCollection();
                JsInitStatementGetter = (id, forNonHyperlinkElement) =>
                                        (forNonHyperlinkElement ? "" : getActionInitStatements(id, false, "") + " ") + toolTipInitStatementGetter(id);
            }
            else
            {
                IncludesIdAttribute = forNonHyperlinkElement =>
                                      isPostBackHyperlink || (destination != null && (actionStatementGetter != null || forNonHyperlinkElement));
                EtherealChildren      = null;
                JsInitStatementGetter = (id, forNonHyperlinkElement) => {
                    var actionStatements = isPostBackHyperlink ? postBackAction.GetJsStatements() :
                                           destination != null && actionStatementGetter != null?actionStatementGetter(Url.Value) :
                                               destination != null && forNonHyperlinkElement ? !target.Any()
                                                                                                                       ? "window.location.href = '{0}';".FormatWith(Url.Value)
                                                                                                                       :
                                               target == "_parent"
                                                                                                                               ?
                                               "window.parent.location.href = '{0}';".FormatWith(Url.Value)
                                                                                                                               : "window.open( '{0}', '{1}' );".FormatWith(Url.Value, target) : "";

                    return(actionStatements.Any() ? getActionInitStatements(id, forNonHyperlinkElement, actionStatements) : "");
                };
            }

            IsFocusable = destination != null;

            if (isPostBackHyperlink)
            {
                PostBackAdder = () => {
                    postBackAction = GetHyperlinkPostBackAction(destination);
                    postBackAction.AddToPageIfNecessary();
                }
            }
            ;
            else
            {
                PostBackAdder = () => {}
            };
        }
Пример #9
0
        void ButtonBehavior.AddPostBack()
        {
            FormAction action = PostBackAction;

            action.AddToPageIfNecessary();
        }
Пример #10
0
        private PhrasingComponent getComponent(
            FormValue formValue, ElementId id, string radioButtonListItemId, DisplaySetup displaySetup, bool isReadOnly, ElementClassSet classes,
            PageModificationValue <bool> pageModificationValue, IReadOnlyCollection <PhrasingComponent> label, FormAction action, FormAction valueChangedAction,
            Func <string> jsClickStatementGetter)
        {
            return(new CustomPhrasingComponent(
                       new DisplayableElement(
                           labelContext => new DisplayableElementData(
                               displaySetup,
                               () => new DisplayableElementLocalData("label"),
                               classes: elementClass.Add(classes ?? ElementClassSet.Empty),
                               children: new DisplayableElement(
                                   context => {
                if (!isReadOnly)
                {
                    action?.AddToPageIfNecessary();
                    valueChangedAction?.AddToPageIfNecessary();
                }

                return new DisplayableElementData(
                    null,
                    () => {
                    var attributes = new List <ElementAttribute>();
                    var radioButtonFormValue = formValue as FormValue <ElementId>;
                    attributes.Add(new ElementAttribute("type", radioButtonFormValue != null ? "radio" : "checkbox"));
                    if (radioButtonFormValue != null || !isReadOnly)
                    {
                        attributes.Add(
                            new ElementAttribute(
                                "name",
                                radioButtonFormValue != null ? ((FormValue)radioButtonFormValue).GetPostBackValueKey() : context.Id));
                    }
                    if (radioButtonFormValue != null)
                    {
                        attributes.Add(new ElementAttribute("value", radioButtonListItemId ?? context.Id));
                    }
                    if (pageModificationValue.Value)
                    {
                        attributes.Add(new ElementAttribute("checked"));
                    }
                    if (isReadOnly)
                    {
                        attributes.Add(new ElementAttribute("disabled"));
                    }

                    var jsInitStatements = StringTools.ConcatenateWithDelimiter(
                        " ",
                        !isReadOnly
                                                                                                        ? SubmitButton.GetImplicitSubmissionKeyPressStatements(action, false)
                        .Surround("$( '#{0}' ).keypress( function( e ) {{ ".FormatWith(context.Id), " } );")
                                                                                                        : "",
                        jsClickStatementGetter().Surround("$( '#{0}' ).click( function() {{ ".FormatWith(context.Id), " } );"));

                    return new DisplayableElementLocalData(
                        "input",
                        new FocusabilityCondition(!isReadOnly),
                        isFocused => {
                        if (isFocused)
                        {
                            attributes.Add(new ElementAttribute("autofocus"));
                        }
                        return new DisplayableElementFocusDependentData(
                            attributes: attributes,
                            includeIdAttribute: true,
                            jsInitStatements: jsInitStatements);
                    });
                },
                    classes: elementClass,
                    clientSideIdReferences: id.ToCollection());
            },
                                   formValue: formValue).ToCollection()
                               .Concat(label.Any() ? new GenericPhrasingContainer(label, classes: elementClass).ToCollection() : Enumerable.Empty <FlowComponent>())
                               .Materialize())).ToCollection()));
        }
Пример #11
0
        void ControlTreeDataLoader.LoadData()
        {
            var isTextarea = rows > 1;

            textBox    = new WebControl(isTextarea ? HtmlTextWriterTag.Textarea : HtmlTextWriterTag.Input);
            PreRender += delegate {
                if (!isTextarea)
                {
                    textBox.Attributes.Add("type", masksCharacters ? "password" : "text");
                }
                textBox.Attributes.Add("name", UniqueID);
                if (isTextarea)
                {
                    textBox.Attributes.Add("rows", rows.ToString());
                }
                if (maxLength.HasValue)
                {
                    textBox.Attributes.Add("maxlength", maxLength.Value.ToString());
                }
                if (readOnly)
                {
                    textBox.Attributes.Add("readonly", "readonly");
                }
                if (disableBrowserAutoComplete || autoCompleteService != null)
                {
                    textBox.Attributes.Add("autocomplete", "off");
                }
                if (suggestSpellCheck.HasValue)
                {
                    textBox.Attributes.Add("spellcheck", suggestSpellCheck.Value.ToString().ToLower());
                }

                var value            = formValue.GetValue(AppRequestState.Instance.EwfPageRequestState.PostBackValues);
                var valueOrWatermark = watermarkText.Any() && !value.Any() ? watermarkText : value;
                if (isTextarea)
                {
                    textBox.Controls.Add(new Literal {
                        Text = HttpUtility.HtmlEncode(GetTextareaValue(valueOrWatermark))
                    });
                }
                else if (!masksCharacters)
                {
                    textBox.Attributes.Add("value", valueOrWatermark);
                }
            };
            Controls.Add(textBox);

            if (watermarkText.Any())
            {
                textBox.AddJavaScriptEventScript(JsWritingMethods.onfocus, "if( value == '" + watermarkText + "' ) value = ''");
                textBox.AddJavaScriptEventScript(JsWritingMethods.onblur, "if( value == '' ) value = '" + watermarkText + "'");
                EwfPage.Instance.ClientScript.RegisterOnSubmitStatement(
                    GetType(),
                    UniqueID + "watermark",
                    "$( '#" + textBox.ClientID + "' ).filter( function() { return this.value == '" + watermarkText + "'; } ).val( '' )");
            }

            if (!isTextarea || autoPostBack || (autoCompleteService != null && autoCompleteOption != AutoCompleteOption.NoPostBack))
            {
                action.AddToPageIfNecessary();
            }
            if (!isTextarea)
            {
                PreRender +=
                    delegate {
                    SubmitButton.EnsureImplicitSubmissionAction(
                        this,
                        action,
                        autoPostBack || (autoCompleteService != null && autoCompleteOption == AutoCompleteOption.PostBackOnTextChangeAndItemSelect));
                }
            }
            ;

            if (autoPostBack || (autoCompleteService != null && autoCompleteOption == AutoCompleteOption.PostBackOnTextChangeAndItemSelect))
            {
                PreRender += delegate {
                    // Use setTimeout to prevent keypress and change from *both* triggering post-backs at the same time when Enter is pressed after a text change.
                    textBox.AddJavaScriptEventScript(JsWritingMethods.onchange, "setTimeout( function() { " + action.GetJsStatements() + " }, 0 )");
                }
            }
            ;

            if (ToolTip != null || ToolTipControl != null)
            {
                new ToolTip(ToolTipControl ?? EnterpriseWebFramework.Controls.ToolTip.GetToolTipTextControl(ToolTip), textBox);
            }
        }

        string ControlWithJsInitLogic.GetJsInitStatements()
        {
            var script = new StringBuilder();

            if (watermarkText.Any())
            {
                var restorationStatement = "$( '#" + textBox.ClientID + "' ).filter( function() { return this.value == ''; } ).val( '" + watermarkText + "' );";

                // The first line is for bfcache browsers; the second is for all others. See http://stackoverflow.com/q/1195440/35349.
                script.Append("$( window ).on( 'pagehide', function() { " + restorationStatement + " } );");
                script.Append(restorationStatement);
            }

            if (autoCompleteService != null)
            {
                const int delay         = 250;         // Default delay is 300 ms.
                const int minCharacters = 3;

                var autocompleteOptions = new List <Tuple <string, string> >();
                autocompleteOptions.Add(Tuple.Create("delay", delay.ToString()));
                autocompleteOptions.Add(Tuple.Create("minLength", minCharacters.ToString()));
                autocompleteOptions.Add(Tuple.Create("source", "'" + autoCompleteService.GetUrl() + "'"));

                if (autoCompleteOption != AutoCompleteOption.NoPostBack)
                {
                    var handler = "function( event, ui ) {{ $( '#{0}' ).val( ui.item.value ); {1} return false; }}".FormatWith(textBox.ClientID, action.GetJsStatements());
                    autocompleteOptions.Add(Tuple.Create("select", handler));
                }

                script.Append(
                    @"$( '#" + textBox.ClientID +
                    "' ).autocomplete( {{ {0} }} );".FormatWith(
                        autocompleteOptions.Select(o => "{0}: {1}".FormatWith(o.Item1, o.Item2)).GetCommaDelimitedStringFromCollection()));
            }

            return(script.ToString());
        }

        FormValue FormValueControl.FormValue {
            get { return(formValue); }
        }
        void ControlTreeDataLoader.LoadData()
        {
            action.AddToPageIfNecessary();

            PreRender += delegate {
                if (setup.HighlightedWhenChecked && checkBoxFormValue.GetValue(AppRequestState.Instance.EwfPageRequestState.PostBackValues))
                {
                    CssClass = CssClass.ConcatenateWithSpace("checkedChecklistCheckboxDiv");
                }
            };

            var table = TableOps.CreateUnderlyingTable();

            table.CssClass = "ewfBlockCheckBox";

            checkBox   = new WebControl(HtmlTextWriterTag.Input);
            PreRender +=
                delegate {
                EwfCheckBox.AddCheckBoxAttributes(
                    checkBox,
                    this,
                    checkBoxFormValue,
                    radioButtonFormValue,
                    radioButtonListItemId,
                    action,
                    setup.TriggersPostBackWhenCheckedOrUnchecked,
                    jsClickHandlerStatementLists.SelectMany(i => i()));
            };

            var checkBoxCell = new TableCell().AddControlsReturnThis(checkBox);

            checkBoxCell.Style.Add("width", "13px");

            var row = new TableRow();

            row.Cells.Add(checkBoxCell);

            var labelControl = new HtmlGenericControl("label")
            {
                InnerText = label
            };

            row.Cells.Add(new TableCell().AddControlsReturnThis(labelControl));
            PreRender += (s, e) => labelControl.Attributes.Add("for", checkBox.ClientID);

            table.Rows.Add(row);

            if (nestedControls.Any())
            {
                var nestedControlRow = new TableRow();
                nestedControlRow.Cells.Add(new TableCell());
                nestedControlRow.Cells.Add(new TableCell().AddControlsReturnThis(nestedControls));
                table.Rows.Add(nestedControlRow);

                if (!setup.NestedControlsAlwaysVisible)
                {
                    CheckBoxToControlArrayDisplayLink.AddToPage(this, true, nestedControlRow);
                }
            }

            Controls.Add(table);
            if (ToolTip != null || ToolTipControl != null)
            {
                new Controls.ToolTip(
                    ToolTipControl ?? EnterpriseWebFramework.Controls.ToolTip.GetToolTipTextControl(ToolTip),
                    label.Length > 0 ? (Control)labelControl : checkBox);
            }
        }