Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Elwyn 2 posts 22 karma points
    Jun 20, 2011 @ 00:37
    Elwyn
    0

    Generate link to exit from Canvas mode

    Hiya,

    Currently my logged in Users are presented with a link on the front end of the site, "Edit this page", which looks something like this:

    <a href="/umbraco/canvas.aspx?redir=/<%= currentNode.Id %>.aspx">Edit this page</a>

    How can I generate a similar link to exit out of Canvas mode?

    <% if(umbraco.presentation.UmbracoContext.Current.LiveEditingContext.Enabled) { %>
    <a href="/umbraco/#end-canvas?redir=<%= currentNode.NiceUrl %>">Stop editing page</a>
    <% } %>

    Is this possible?
    How would a user normally exit out of canvas mode? I guess I would have expected a button on the LiveEditingToolbar.

    So far the only way I have figured out is to click "Log out", and log back in. But this is obviously a usability issue, and I feel like I'm missing something obvious here!

  • Elwyn 2 posts 22 karma points
    Jun 20, 2011 @ 01:32
    Elwyn
    0

    Well I have a solution - it works, but I am still very interested in how a user normally exits out of Canvas mode.

     

    I ended up creating a User Control, and essentially duplicating the code from /umbraco/canvas.aspx.cs (but turning it off rather than on, of course).

    public partial class EndCanvasMode : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                User currentUser = User.GetCurrent();
                if (currentUser != null)
                {
                    UmbracoContext.Current.LiveEditingContext.Enabled = false; //Turning it off, rather than on
    
                    string redirUrl = "/";
                    if (!String.IsNullOrEmpty(helper.Request("redir")))
                        redirUrl = helper.Request("redir");
                    else if (Request.UrlReferrer != null && !Request.UrlReferrer.AbsolutePath.Contains("login.aspx"))
                        redirUrl = Request.UrlReferrer.AbsolutePath;
    
                    Response.Redirect(redirUrl +
                        (string.IsNullOrEmpty(UmbracoContext.Current.Request["umbSkinning"]) ? "" : "?umbSkinning=true") + (string.IsNullOrEmpty(UmbracoContext.Current.Request["umbSkinningConfigurator"]) ? "" : "&umbSkinningConfigurator=true"), true);
                }
                else
                {
                    throw new Exception("User not logged in");
                }
            }
        }

    So in my templates, my link looks like this:

     

    if(umbraco.presentation.UmbracoContext.Current.LiveEditingContext.Enabled){%>
       
    <a href="/system-pages/EndCanvasMode?redir==currentNode.NiceUrl%>">Stop editing page<a>
    }%>

    (with "/system-pages/EndCanvasmode" being an empty content node with the above user control embedded).

     This feels like it should be a built in function somewhere - am I just not looking in the right place?

Please Sign in or register to post replies

Write your reply to:

Draft