Example #1
0
 string HyperlinkStyle.GetJsInitStatements(string id)
 {
     return(rolloverImageInfo != null && rolloverImageInfo.GetUrl() != imageInfo.GetUrl()
                                ? StringTools.ConcatenateWithDelimiter(
                " ",
                "new Image().src = '{0}';".FormatWith(rolloverImageInfo.GetUrl()),
                "$( '#{0}' ).mouseover( function() {{ $( this ).children().attr( 'src', '{1}' ); }} );".FormatWith(id, rolloverImageInfo.GetUrl()),
                "$( '#{0}' ).mouseout( function() {{ $( this ).children().attr( 'src', '{1}' ); }} );".FormatWith(id, imageInfo.GetUrl()))
                                : "");
 }
        internal static FormAction GetHyperlinkPostBackAction(ResourceInfo destination)
        {
            var id = PostBack.GetCompositeId("ewfLink", destination.GetUrl());

            return(new PostBackFormAction(
                       EwfPage.Instance.GetPostBack(id) ?? PostBack.CreateFull(id: id, actionGetter: () => new PostBackAction(destination))));
        }
Example #3
0
        private string getTransferPath(ResourceInfo resource)
        {
            var url = resource.GetUrl(true, true, false);

            if (resource.ShouldBeSecureGivenCurrentRequest != RequestIsSecure(Request))
            {
                throw new ApplicationException(url + " has a connection security setting that is incompatible with the current request.");
            }
            return(url);
        }
Example #4
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 = () => { }
            };
        }
 /// <summary>
 /// Creates an image with a single source. Use only when you do not know the width of the image resource, or if the resource only supports a single width.
 /// </summary>
 /// <param name="generalSetup">The general setup object for the image.</param>
 /// <param name="imageResource">Do not pass null.</param>
 public EwfImage(ImageSetup generalSetup, ResourceInfo imageResource)
 {
     children = generalSetup.ComponentGetter(() => imageResource.GetUrl(), () => "");
 }
        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 = () => {}
            };
        }
        internal HyperlinkBehavior(ResourceInfo destination, bool disableAuthorizationCheck, string target, Func <string, string> actionStatementGetter)
        {
            hasDestination = destination != null;
            userCanNavigateToDestinationPredicate = () => !hasDestination || disableAuthorizationCheck || destination.UserCanAccessResource;

            var destinationAlternativeMode = hasDestination && !disableAuthorizationCheck ? destination.AlternativeMode : null;

            Classes = destinationAlternativeMode is NewContentResourceMode ? ActionComponentCssElementCreator.NewContentClass : ElementClassSet.Empty;

            Url = new Lazy <string>(() => hasDestination ? destination.GetUrl(!disableAuthorizationCheck, false) : "");
            var isPostBackHyperlink = new Lazy <bool>(
                () => hasDestination && !(destinationAlternativeMode is DisabledResourceMode) && !target.Any() && PageBase.Current.IsAutoDataUpdater.Value);

            AttributeGetter = forNonHyperlinkElement =>
                              (hasDestination && !forNonHyperlinkElement ? new ElementAttribute("href", Url.Value).ToCollection() : Enumerable.Empty <ElementAttribute>()).Concat(
                hasDestination && target.Any() && !forNonHyperlinkElement
                                                ? new ElementAttribute("target", target).ToCollection()
                                                : Enumerable.Empty <ElementAttribute>())
                              .Concat(
                // for https://instant.page/
                !isPostBackHyperlink.Value && destination is ResourceBase && !(destinationAlternativeMode is DisabledResourceMode) && !forNonHyperlinkElement
                                                ? new ElementAttribute("data-instant").ToCollection()
                                                : Enumerable.Empty <ElementAttribute>())
                              .Materialize();

            FormAction postBackAction = null;

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

            if (destinationAlternativeMode 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.Value || (hasDestination && (actionStatementGetter != null || forNonHyperlinkElement));
                EtherealChildren      = null;
                JsInitStatementGetter = (id, forNonHyperlinkElement) => {
                    var actionStatements = isPostBackHyperlink.Value ? postBackAction.GetJsStatements() :
                                           hasDestination && actionStatementGetter != null?actionStatementGetter(Url.Value) :
                                               hasDestination && 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 = hasDestination;

            PostBackAdder = () => {
                if (!isPostBackHyperlink.Value)
                {
                    return;
                }
                var postBackId = PostBack.GetCompositeId("hyperlink", destination.GetUrl(), disableAuthorizationCheck.ToString());
                postBackAction = new PostBackFormAction(
                    PageBase.Current.GetPostBack(postBackId) ?? PostBack.CreateFull(
                        id: postBackId,
                        actionGetter: () => new PostBackAction(destination, authorizationCheckDisabledPredicate: effectiveDestination => disableAuthorizationCheck)));
                postBackAction.AddToPageIfNecessary();
            };
        }
 private string getTransferPath( ResourceInfo resource )
 {
     var url = resource.GetUrl( true, true, false );
     if( resource.ShouldBeSecureGivenCurrentRequest != RequestIsSecure( Request ) )
         throw new ApplicationException( url + " has a connection security setting that is incompatible with the current request." );
     return url;
 }
        private void navigate( ResourceInfo destination, FullResponse secondaryResponse )
        {
            var requestState = AppRequestState.Instance.EwfPageRequestState;

            string destinationUrl;
            try {
                // Determine the final redirect destination. If a destination is already specified and it is the current page or a page with the same entity setup,
                // replace any default optional parameter values it may have with new values from this post back. If a destination isn't specified, make it the current
                // page with new parameter values from this post back. At the end of this block, redirectInfo is always newly created with fresh data that reflects any
                // changes that may have occurred in EH methods. It's important that every case below *actually creates* a new page info object to guard against this
                // scenario:
                // 1. A page modifies data such that a previously created redirect destination page info object that is then used here is no longer valid because it
                //    would throw an exception from init if it were re-created.
                // 2. The page redirects, or transfers, to this destination, leading the user to an error page without developers being notified. This is bad behavior.
                if( requestState.ModificationErrorsExist ||
                    ( requestState.DmIdAndSecondaryOp != null && requestState.DmIdAndSecondaryOp.Item2 == SecondaryPostBackOperation.NoOperation ) )
                    destination = InfoAsBaseType.CloneAndReplaceDefaultsIfPossible( true );
                else if( destination != null )
                    destination = destination.CloneAndReplaceDefaultsIfPossible( false );
                else
                    destination = createInfoFromNewParameterValues();

                // This GetUrl call is important even for the transfer case below for the same reason that we *actually create* a new page info object in every case
                // above. We want to force developers to get an error email if a page modifies data to make itself unauthorized/disabled without specifying a different
                // page as the redirect destination. The resulting transfer would lead the user to an error page.
                destinationUrl = destination.GetUrl();
            }
            catch( Exception e ) {
                throw getPossibleDeveloperMistakeException( "The post-modification destination page became invalid.", innerException: e );
            }

            // Put the secondary response into session state right before navigation so that it doesn't get sent if there is an error before this point.
            if( secondaryResponse != null ) {
                // It's important that we put the response in session state first since it's used by the Info.init method of the pre-built-response page.
                StandardLibrarySessionState.Instance.ResponseToSend = secondaryResponse;
                StandardLibrarySessionState.Instance.SetClientSideNavigation(
                    EwfApp.MetaLogicFactory.CreatePreBuiltResponsePageInfo().GetUrl(),
                    !secondaryResponse.FileName.Any(),
                    null );
            }

            // If the redirect destination is identical to the current page, do a transfer instead of a redirect.
            if( destination.IsIdenticalToCurrent() ) {
                AppRequestState.Instance.ClearUserAndImpersonator();
                resetPage();
            }

            // If the redirect destination is the current page, but with different query parameters, save request state in session state until the next request.
            if( destination.GetType() == InfoAsBaseType.GetType() )
                StandardLibrarySessionState.Instance.EwfPageRequestState = requestState;

            NetTools.Redirect( destinationUrl );
        }
Example #10
0
        // Web Forms compatibility. Remove when EnduraCode goal 790 is complete.
        internal void SetUpClickableControl(WebControl clickableControl)
        {
            if (resource == null && action == null && script == "")
            {
                return;
            }

            clickableControl.CssClass = clickableControl.CssClass.ConcatenateWithSpace(ActivatableClass.ClassName);

            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()); };
        }