Copied to clipboard

Flag this post as spam?

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


  • Bob Krusemeijer 4 posts 24 karma points
    May 26, 2010 @ 15:51
    Bob Krusemeijer
    0

    Context menu in custom tree behaving strange

    Hi,

    I'm currently usering umbraco 4.0.4.1
    I've made a custom tree with subnodes (much like http://www.netaddicts.be/articles/building-a-custom-section-to-manage-external-data.aspx )

    I also made 2 actions for in the context menu. If the childnode is at level 1, I add CreateAfdelingAction  to the context menu and if at level 2, I add CreateLocatieAction. to the context menu.

    When opening the tree in umbraco, both lvl 1 and 2 show the CreateLocatieAction in their context menu. When walking through the code with the debugger, I see nothing going wrong.

    Am I doing something wrong? Is this behavoir not supported? Is there a other way of doing this?

    Tree code:
     

     

    using

     

    System;

    using

     

    System.Collections.Generic;

    using

     

    System.Web;

    using

     

    System.Text;

    using

     

    umbraco.cms.presentation.Trees;

    using

     

    umbraco.DataLayer;

    using

     

    umbraco.BusinessLogic;

    using

     

    umbraco.interfaces;

    using

     

    umbraco.BusinessLogic.Actions;

    namespace

     

    Organisatiestructuur

    {

     

    public class LoadOrganisatiestructuur : BaseTree

    {

     

    public LoadOrganisatiestructuur(string application)

    :

    base(application)

    {

    }

     

    //Hoofd node aanmaken

     

    protected override void CreateRootNode(ref XmlTreeNode rootNode)

    {

    rootNode.Text =

    "Organisatiestructuur";

    rootNode.Icon = FolderIcon;

    rootNode.OpenIcon = FolderIconOpen;

    rootNode.NodeType =

    string.Format("init{0}", TreeAlias);

    rootNode.NodeID =

    "-1"; // belangrijk, moet -1 zijn!

    }

     

    // default actions momenteel uit.

     

    protected override void CreateAllowedActions(ref List<IAction> actions)

    {

    actions.Clear();

    actions.Add(

    ActionNew.Instance);

    actions.Add(

    ActionDelete.Instance);

    actions.Add(

    ContextMenuSeperator.Instance);

    actions.Add(

    ActionRefresh.Instance);

    }

     

    // javascript acties voor de nodes

     

    public override void RenderJS(ref StringBuilder Javascript)

    {

    Javascript.Append(

    @"

    function openCollege(id) {

    parent.right.document.location.href = 'plugins/editCollege.aspx?id=' + id;

    }

    function openAfdeling(id) {

    parent.right.document.location.href = 'plugins/editAfdeling.aspx?id=' + id;

    }

    function openLocatie(id,afdid) {

    parent.right.document.location.href = 'plugins/editLocatie.aspx?id=' + id + '&afdid=' +afdid;

    }

    function openOpleiding(id) {

    parent.right.document.location.href = 'plugins/editOpleiding.aspx?id=' + id;

    }

    "

     

    );

    }

     

    //Render de boom (is recursief , voor iedere node die aangemaakt wordt loopt ie hierdoor.

     

    public override void Render(ref XmlTree tree)

    {

     

    // db, om makkelijk van omgeving te switchen, word later een waarde in een config file.

     

    string db = "";

     

    // string db = "rocwb_umbraco_shared.dbo.";

     

    if (this.NodeKey == string.Empty)

    {

     

    //College niveau

     

    var reader = Application.SqlHelper.ExecuteReader(@"Select * from " + db + "college order by col_naam");

     

    while (reader.Read())

    {

     

    XmlTreeNode node = XmlTreeNode.Create(this);

    node.NodeID =

    Convert.ToString(reader.Get<int>("col_id"));

    node.Text = reader.Get<

    string>("col_naam");

    node.OpenIcon = FolderIconOpen;

    node.Icon = FolderIcon;

    node.Action =

    string.Format("javascript:openCollege('{0}');", node.NodeID);

     

    TreeService treeService = new TreeService(-1, TreeAlias, ShowContextMenu, IsDialog, DialogMode, app, string.Format("College-{0}", Convert.ToString(reader.Get<int>("col_id"))));

    node.Source = treeService.GetServiceUrl();

    node.Menu.Clear();

    node.Menu.AddRange(

    new List<IAction> { CreateAfdelingAction.Instance, ContextMenuSeperator.Instance, ActionRefresh.Instance });

     

    // node.Menu.Insert(0, new CreateAfdelingAction());

    tree.Add(node);

    }

    }

     

    else

    {

     

    switch (this.NodeKey.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries)[0])

    {

     

    case "College": // college is parent, afdelingen toevoegen

     

    var afdelingReader = Application.SqlHelper.ExecuteReader(@"SELECT * from " + db + "[afdeling] WHERE afd_col_id = @College order by afd_naam ",

     

    Application.SqlHelper.CreateParameter("@College", this.NodeKey.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries)[1]));

     

    while (afdelingReader.Read())

    {

     

    XmlTreeNode node = XmlTreeNode.Create(this);

    node.NodeID =

    "afd" + Convert.ToString(afdelingReader.Get<int>("afd_id"));

    node.Text = afdelingReader.Get<

    string>("afd_naam");

    node.OpenIcon = FolderIconOpen;

    node.Icon = FolderIcon;

    node.Action =

    string.Format("javascript:openAfdeling('{0}');", node.NodeID);

     

    TreeService treeService = new TreeService(-1, TreeAlias, ShowContextMenu, IsDialog, DialogMode, app, string.Format("Afdeling-{0}", "afd" + Convert.ToString(afdelingReader.Get<int>("afd_id"))));

    node.Source = treeService.GetServiceUrl();

    node.Menu.Clear();

    tree.Add(node);

    }

     

    break;

     

    case "Afdeling": // afdeling is parent, opleiding en locatie node toevoegen

     

    // standaard node voor opleidingen

     

    XmlTreeNode nodeOpl = XmlTreeNode.Create(this);

    nodeOpl.NodeID =

    "Opleidingen" + this.NodeKey.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries)[1];

    nodeOpl.Text =

    "Opleidingen";

    nodeOpl.OpenIcon = FolderIconOpen;

    nodeOpl.Icon = FolderIcon;

    nodeOpl.Action =

    string.Empty;

     

    TreeService treeServiceOpl = new TreeService(-1, TreeAlias, ShowContextMenu, IsDialog, DialogMode, app, string.Format("AfdelingOpl-{0}", this.NodeKey.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries)[1]));

    nodeOpl.Source = treeServiceOpl.GetServiceUrl();

    nodeOpl.Menu.Clear();

    tree.Add(nodeOpl);

     

    // standaard node voor locaties

     

    XmlTreeNode nodeLoc = XmlTreeNode.Create(this);

    nodeLoc.NodeID =

    "Locaties" + this.NodeKey.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries)[1];

    nodeLoc.Text =

    "Locaties";

    nodeLoc.OpenIcon = FolderIconOpen;

    nodeLoc.Icon = FolderIcon;

    nodeLoc.Action =

    string.Empty;

     

    TreeService treeServiceLoc = new TreeService(-1, TreeAlias, ShowContextMenu, IsDialog, DialogMode, app, string.Format("AfdelingLoc-{0}", this.NodeKey.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries)[1]));

    nodeLoc.Source = treeServiceLoc.GetServiceUrl();

    nodeLoc.Menu.Clear();

    nodeLoc.Menu.AddRange(

    new List<IAction> { CreateLocatieAction.Instance, ContextMenuSeperator.Instance, ActionRefresh.Instance });

    tree.Add(nodeLoc);

     

    break;

     

    case "AfdelingOpl": // opleidingen toevoegen

     

    var opleidingReader = Application.SqlHelper.ExecuteReader(@"SELECT * FROM " + db + "[opleiding] WHERE opl_afd_id = replace(@Afdeling,'afd','')",

     

    Application.SqlHelper.CreateParameter("@Afdeling", this.NodeKey.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries)[1]));

     

    while (opleidingReader.Read())

    {

     

    XmlTreeNode node = XmlTreeNode.Create(this);

    node.NodeID =

    "opl" + Convert.ToString(opleidingReader.Get<int>("opl_id"));

    node.Text = opleidingReader.Get<

    string>("opl_naam");

    node.OpenIcon = FolderIconOpen;

    node.Icon = FolderIcon;

    node.Action =

    string.Empty;

    node.Source =

    string.Empty;

    node.Menu.Clear();

    tree.Add(node);

    }

     

    break;

     

    case "AfdelingLoc": // locaties toevoegen

     

    string afd = this.NodeKey.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries)[1];

     

    var locatieReader = Application.SqlHelper.ExecuteReader(@"SELECT * from " + db + "[locatie] WHERE loc_afd_id = replace(@Afdeling,'afd','')",

     

    Application.SqlHelper.CreateParameter("@Afdeling", afd));

     

    while (locatieReader.Read())

    {

     

    XmlTreeNode node = XmlTreeNode.Create(this);

    node.NodeID =

    "loc" + Convert.ToString(locatieReader.Get<int>("loc_id"));

    node.Text =

    Convert.ToString(locatieReader.Get<string>("loc_naam"));

    node.OpenIcon = FolderIconOpen;

    node.Icon = FolderIcon;

    node.Action =

    "javascript:openLocatie('" + node.NodeID.Replace("loc", "") + "'," + afd.Replace("afd", "") + ");";

    node.Source =

    string.Empty;

    node.Menu.Clear();

    tree.Add(node);

    }

     

    break;

     

    case "Opleiding": //indien iets onder opleiding komt.

     

    break;

     

    case "Locatie": // indien iets onder locatie komt.

     

    break;

     

    default:

     

    break;

    }

    }

    }

    }

    }



     

     Action 1:

    using

     

    System;

    using

     

    System.Collections.Generic;

    using

     

    System.Linq;

    using

     

    System.Web;

    namespace

     

    Organisatiestructuur

    {

     

    /// <summary>

     

    /// Afdeling toevoegen functie

     

    /// </summary>

     

    public class CreateAfdelingAction : umbraco.interfaces.IAction

    {

     

    private string _alias = "Afdeling aanmaken";

     

    public string Alias

    {

     

    get { return _alias; }

    }

     

    //create singleton

     

    private static readonly CreateAfdelingAction instance = new CreateAfdelingAction();

     

    private CreateAfdelingAction() { }

     

    public static CreateAfdelingAction Instance

    {

     

    get { return instance; }

    }

     

     

    public bool CanBePermissionAssigned

    {

     

    get { return true; }

    }

     

    public string Icon

    {

     

    //icoontje

     

    get { return "tree/fam_icons/icons/chart_organisation_add.png"; }

    }

     

    public string JsFunctionName

    {

     

    get

    {

    // stuurt je naar edit pagina, met id=0 (toevoeg mode)

     

    return "parent.right.document.location.href = 'plugins/editAfdeling.aspx?id=0&colid='+ nodeID ";

    }

    }

     

    public string JsSource

    {

     

    get { return ""; }

    }

     

    public char Letter

    {

     

    get { return ''; }

    }

     

    public bool ShowInNotifier

    {

     

    get { return false; }

    }

    }

    }


     

     

    Action 2:

    using

     

    System;

    using

     

    System.Collections.Generic;

    using

     

    System.Linq;

    using

     

    System.Text;

    using

     

    System.Web.UI;

    using

     

    System.Web.UI.WebControls;

    using

     

    umbraco.BusinessLogic;

    using

     

    umbraco.presentation.masterpages;

    using

     

    umbraco.uicontrols;

     

    namespace

     

    Organisatiestructuur

    {

     

    /// <summary>

     

    /// Locatie toevoegen functie

     

    /// </summary>

     

    public class CreateLocatieAction : umbraco.interfaces.IAction

    {

     

    private string _alias = "Locatie aanmaken";

     

    public string Alias

    {

     

    get { return _alias; }

    }

     

    //create singleton

     

    private static readonly CreateLocatieAction instance = new CreateLocatieAction();

     

    private CreateLocatieAction() { }

     

    public static CreateLocatieAction Instance

    {

     

    get { return instance; }

    }

     

    public bool CanBePermissionAssigned

    {

     

    get { return true; }

    }

     

    public string Icon

    {

     

    //icoontje

     

    get { return "tree/fam_icons/icons/chart_organisation_add.png"; }

    }

     

    public string JsFunctionName

    {

     

    get

    {

    // stuurt je naar edit pagina, met id=0 (toevoeg mode)

     

    return "parent.right.document.location.href = 'plugins/editLocatie.aspx?id=0&afdid='+ nodeID ";

    }

    }

     

    public string JsSource

    {

     

    get { return ""; }

    }

     

    public char Letter

    {

     

    get { return ''; }

    }

     

    public bool ShowInNotifier

    {

     

    get { return false; }

    }

    }

    }

  • Bob Krusemeijer 4 posts 24 karma points
    Jun 04, 2010 @ 15:51
    Bob Krusemeijer
    0

    If anyone has the same problem: here is how to fix it:

    in the Action classes that inherit the IAcion interface, make sure you have a different letter for each action you use in the following funciton:

     

     

    public char

    Letter

    {

     

    get { return 'a'

    ; }

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies