WebControl ActionControlStyle.SetUpControl(WebControl control, string defaultText)
        {
            control.CssClass =
                control.CssClass.ConcatenateWithSpace(
                    ActionComponentCssElementCreator.AllStylesClass.ClassName + " " + ActionComponentCssElementCreator.ImageStyleClass.ClassName);

            if (rolloverImageInfo != null && rolloverImageInfo.GetUrl() != imageInfo.GetUrl())
            {
                control.AddJavaScriptEventScript(
                    JavaScriptWriting.JsWritingMethods.onmouseover,
                    "$( this ).children().attr( 'src', '{0}' )".FormatWith(rolloverImageInfo.GetUrl()));
                control.AddJavaScriptEventScript(
                    JavaScriptWriting.JsWritingMethods.onmouseout,
                    "$( this ).children().attr( 'src', '{0}' )".FormatWith(imageInfo.GetUrl()));
            }

            control.AddControlsReturnThis(
                new EwfImage(
                    new ImageSetup(
                        AlternateText,
                        sizesToAvailableWidth: SizesToAvailableWidth,
                        classes: SizesToAvailableWidth ? new ElementClass("ewfBlockContainer") : ElementClassSet.Empty),
                    imageInfo).ToCollection().GetControls());

            return(null);
        }
コード例 #2
0
        internal static void AddCheckBoxAttributes(WebControl checkBoxElement, Control checkBox, FormValue <bool> checkBoxFormValue,
                                                   FormValue <CommonCheckBox> radioButtonFormValue, string radioButtonListItemId, PostBack postBack, bool autoPostBack,
                                                   IEnumerable <string> onClickJsMethods)
        {
            checkBoxElement.Attributes.Add("type", checkBoxFormValue != null ? "checkbox" : "radio");
            checkBoxElement.Attributes.Add("name", checkBoxFormValue != null ? checkBox.UniqueID : ((FormValue)radioButtonFormValue).GetPostBackValueKey());
            if (radioButtonFormValue != null)
            {
                checkBoxElement.Attributes.Add("value", radioButtonListItemId ?? checkBox.UniqueID);
            }
            if (checkBoxFormValue != null
                                    ? checkBoxFormValue.GetValue(AppRequestState.Instance.EwfPageRequestState.PostBackValues)
                                    : radioButtonFormValue.GetValue(AppRequestState.Instance.EwfPageRequestState.PostBackValues) == checkBox)
            {
                checkBoxElement.Attributes.Add("checked", "checked");
            }

            PostBackButton.EnsureImplicitSubmission(checkBoxElement, postBack);
            var isSelectedRadioButton = radioButtonFormValue != null &&
                                        radioButtonFormValue.GetValue(AppRequestState.Instance.EwfPageRequestState.PostBackValues) == checkBox;
            var postBackScript = autoPostBack && !isSelectedRadioButton
                                                     ? PostBackButton.GetPostBackScript(postBack ?? EwfPage.Instance.DataUpdatePostBack, includeReturnFalse : false)
                                                     : "";

            var customScript = StringTools.ConcatenateWithDelimiter("; ", onClickJsMethods.ToArray());

            checkBoxElement.AddJavaScriptEventScript(JsWritingMethods.onclick, StringTools.ConcatenateWithDelimiter("; ", postBackScript, customScript));
        }
コード例 #3
0
        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()); };
        }
コード例 #4
0
        internal void SetUpClickableControl(WebControl clickableControl)
        {
            if (resource == null && postBack == null && script == "")
            {
                return;
            }

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

            if (resource != null && EwfPage.Instance.IsAutoDataUpdater)
            {
                postBack = EwfLink.GetLinkPostBack(resource);
                resource = null;
            }

            Func <string> scriptGetter;

            if (resource != null)
            {
                scriptGetter = () => "location.href = '" + EwfPage.Instance.GetClientUrl(resource.GetUrl()) + "'; return false";
            }
            else if (postBack != null)
            {
                EwfPage.Instance.AddPostBack(postBack);
                scriptGetter = () => PostBackButton.GetPostBackScript(postBack);
            }
            else
            {
                scriptGetter = () => script;
            }

            // Defer script generation until after all controls have IDs.
            EwfPage.Instance.PreRender += delegate { clickableControl.AddJavaScriptEventScript(JsWritingMethods.onclick, scriptGetter()); };
        }
コード例 #5
0
        /// <summary>
        /// Ensures that the specified control will trigger the specified action when the enter key is pressed while the control has focus. If you specify the
        /// submit-button post-back, this method relies on HTML's built-in implicit submission behavior, which will simulate a click on the submit button.
        /// </summary>
        /// <param name="control"></param>
        /// <param name="action">Do not pass null.</param>
        /// <param name="forceJsHandling"></param>
        /// <param name="predicate"></param>
        internal static void EnsureImplicitSubmissionAction(WebControl control, FormAction action, bool forceJsHandling, string predicate = "")
        {
            var postBackAction = action as PostBackFormAction;

            // EWF does not allow form controls to use HTML's built-in implicit submission on a page with no submit button. There are two reasons for this. First, the
            // behavior of HTML's implicit submission appears to be somewhat arbitrary when there is no submit button; see
            // https://html.spec.whatwg.org/multipage/forms.html#implicit-submission. Second, we don't want the implicit submission behavior of form controls to
            // unpredictably change if a submit button is added or removed.
            if (postBackAction == null || postBackAction.PostBack != EwfPage.Instance.SubmitButtonPostBack || forceJsHandling)
            {
                control.AddJavaScriptEventScript(
                    JsWritingMethods.onkeypress,
                    "if( event.which == 13 " + predicate.PrependDelimiter(" && ") + " ) { " + action.GetJsStatements() + " return false; }");
            }
        }
コード例 #6
0
        /// <summary>
        /// Ensures that the specified control will submit the form when the enter key is pressed while the control has focus. Specify null for the post-back to
        /// rely on HTML's built-in implicit submission behavior, which will simulate a click on the submit button.
        /// </summary>
        internal static void EnsureImplicitSubmission(WebControl control, PostBack postBack, string predicate = "")
        {
            if (postBack != null)
            {
                control.AddJavaScriptEventScript(
                    JsWritingMethods.onkeypress,
                    "if( event.which == 13 " + predicate.PrependDelimiter(" && ") + " ) { " + GetPostBackScript(postBack) + "; }");
                return;
            }
            if (EwfPage.Instance.SubmitButtonPostBack != null)
            {
                return;
            }

            var sentences = new[]
            {
                "EWF does not allow form controls to use HTML's built-in implicit submission on a page with no submit button.", "There are two reasons for this.",
                "First, the behavior of HTML's implicit submission appears to be somewhat arbitrary when there is no submit button; see http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#implicit-submission.",
                "Second, we don't want the implicit submission behavior of form controls to unpredictably change if a submit button is added or removed."
            };

            throw new ApplicationException(StringTools.ConcatenateWithDelimiter(" ", sentences));
        }
コード例 #7
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); }
        }
コード例 #8
0
 /// <summary>
 /// Allows for adding custom JavaScript event scripts to the text box.
 /// </summary>
 public void AddJavaScriptEventScript(string jsEventConstant, string script)
 {
     PreRender += delegate { textBox.AddJavaScriptEventScript(jsEventConstant, script); };
 }
コード例 #9
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)
                {
                    AddTextareaValue(textBox, 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( '' )");
            }

            var jsNeededForImplicitSubmission = postBack != null || autoPostBack ||
                                                (autoCompleteService != null && autoCompleteOption == AutoCompleteOption.PostBackOnTextChangeAndItemSelect);

            if (postBack == null && (autoPostBack || (autoCompleteService != null && autoCompleteOption != AutoCompleteOption.NoPostBack)))
            {
                postBack = EwfPage.Instance.DataUpdatePostBack;
            }

            if (postBack != null)
            {
                EwfPage.Instance.AddPostBack(postBack);
            }
            PreRender += delegate { PostBackButton.EnsureImplicitSubmission(this, jsNeededForImplicitSubmission ? postBack : null); };

            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() { " + PostBackButton.GetPostBackScript(postBack, includeReturnFalse: false) + "; }, 0 )");
                };
            }

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