Edit mode

Topics: Developer Forum
Apr 28, 2008 at 7:48 AM
Hi,

is there an easy way to know if a page is loaded in edit-mode or loaded in the website itself?

Martijn
Coordinator
Apr 28, 2008 at 12:28 PM
Do you mean displaying something different/more when the page is diplayed in the preview frame as opposed to when you're logged in as editor but visit the site normally?

A few options:
  • override PreviewUrl in your base class and append some query string
  • look at url referrer
  • check the presense of a frame client side
Apr 28, 2008 at 1:32 PM
Yes, that is exactly what I wanted.
I have a page whcich display's content based on a group a logged in user belongs to.
In edit mode this is somewhat difficult, since the loggedin user is a completely different one. There I want to hardcode the group (of even provide a selection) in the preview.
URL Referrer is a good one, I had not thought of it.
Thanks.
May 16, 2008 at 12:22 PM
Hi,

having some troubles though...
  • override PreviewUrl in your base class and append some query string
    --> Is this overridable? Do you have an example?
  • look at url referrer
    --> This will not work since the referrer is the page itself after publishing it...no distinct identification here...
  • check the presense of a frame client side
    --> This is not safe enough since it can be manipulated.

The reason I want this is that in edit mode I need to hardcode some settings that in normal mode would be set by page prior to the one I'm viewing...
Is there an other solution?

Martijn
Coordinator
May 16, 2008 at 2:31 PM
You're right, it's not overrideable per se. You need to implemen an interface as well. E.g:

public class MyBaseClass : ContentItem, INode
{
    public string PreviewUrl
    {
        get { return ((INode)base).PreviewUrl + "?previewing=true"; }
    }
}
May 16, 2008 at 3:02 PM
with
public abstract class PageItem : ContentItem, INode
{
    public string PreviewUrl
    {
        get { return ((INode)base).PreviewUrl + "?previewing=true"; }
    }
}

I get an error on the keyword base:
"Cannot use 'base' expression in this context"
tried to solve it, but no success...
Coordinator
May 16, 2008 at 4:34 PM
Right. of course... Try this:

public abstract class PageItem : ContentItem, INode
{
    public string PreviewUrl
    {
        get { return Url + "?previewing=true"; }
    }
}
May 16, 2008 at 6:32 PM
That's the one!
Thanks for the swift reply's

:-)
Jun 4, 2008 at 7:44 AM


libardo wrote:
Right. of course... Try this:

public abstract class PageItem : ContentItem, INode
{
    public string PreviewUrl
    {
        get { return Url + "?previewing=true"; }
    }
}


Is there a wat to override the EditUrl?
I have some hierarchical maintenance-options which would fit since in a node under the root (not the homepage node) instead of being called from the toolbar with navigation on a custom page...
But for the pages I want to call for the edit-mode it would be nice to be more flexible than the edit.aspx will allow me (there is no "publish" for these pages neither).

Thanks!
Coordinator
Jun 4, 2008 at 5:32 PM
The way to do it in the current version (maybe this should be more easily configurable) is configuring a custom edit manager implementation:

public class MyEditManager : DefaultEditManager, IEditManager
{
    public new string GetEditNewPageUrl(ContentItem selected, ItemDefinition definition, string zoneName, CreationPosition position)
    {
        ...
    }
    public new string GetEditExistingItemUrl(ContentItem item)
    {
        ...
    }
}

web.config:
<castle>
...
        <components>
                <component id="n2.myEditManager"                service="N2.Edit.IEditManager, N2"                    type="Namespace.MyEditManager, Assembly"/>
        </components>
        <include uri="assembly://N2/Engine/n2.configuration.xml"/>
...
Jun 4, 2008 at 7:24 PM
indeed a bit more easily would be nice, but if it works nothing wrong with it, right?

Thanks!
Jul 13, 2008 at 8:58 AM


libardo wrote:
Right. of course... Try this:

public abstract class PageItem : ContentItem, INode
{
    public string PreviewUrl
    {
        get { return Url + "?previewing=true"; }
    }
}


This only works for the first level items in the tree (in edit mode)...any ideas how that is?
Second and lower level items do not get the "?previewing=true" appended to the url...