Copied to clipboard

Flag this post as spam?

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


  • sailesh 14 posts 45 karma points
    Jun 07, 2010 @ 16:35
    sailesh
    0

    Custom section tree context menu Delete function

    Hi,

    I followed the video tutorials on creating the custom section and its set of Trees.

    However I cannot seem to get the Delete of the context menu to work.

    I have a class called ManufacturerTasks which is suppose to handel the various events. But I cannot get the Delete method to work from the right-click(Context menu)

     public class ManufacturerTasks : umbraco.interfaces.ITaskReturnUrl
    {
     #region members
            private string _alias;
            private int _parentID;
            private int _typeID;
            private int _userID;
            private string m_returnUrl = "";
            #endregion

            #region ITaskReturnUrl Members

            public string ReturnUrl
            {
                get { throw new NotImplementedException(); }
            }

            #endregion

            #region ITask Members

            public string Alias
            {
                get
                {
                    return _alias;
                }
                set
                {
                    _alias = value;
                }
            }

            public bool Delete()
            {
             
                Manufacturer.Delete(Manufacturer.Columns.Name, _alias);
                return true;
               
            }

            public int ParentID
            {
                get
                {
                    return _parentID;
                }
                set
                {
                    _parentID = value;
                }
            }

            public bool Save()
            {
                Manufacturer manu = new Manufacturer();
                manu.Name = _alias;
                manu.Save();
                int id = manu.ManufacturerId;
                m_returnUrl = string.Format("commerce/editManufacturer.aspx?man={0}", id);
                return true;

            }

            public int TypeID
            {
                get
                {
                    return _typeID;
                }
                set
                {
                    _typeID = value;
                }
            }

            public int UserId
            {
                set { _userID = value; }
            }

            #endregion
        }

     

    The following is the class I use to loadup the tree
    ---------------------------------------------------------------------------------------------------------------------------------------

    public class loadManufacturerTree : BaseTree
        {
            public loadManufacturerTree(string application) : base(application) { }

            protected override void CreateRootNode(ref XmlTreeNode rootNode)
            {
                rootNode.Icon = FolderIcon;
                rootNode.OpenIcon = FolderIconOpen;
                rootNode.NodeType = "init" + TreeAlias;
                //rootNode.NodeType = TreeAlias;
                rootNode.NodeID = "init";
            }

            public override void Render(ref XmlTree tree)
            {
                ManufacturerCollection manuCollection = new ManufacturerController().FetchAll();

                foreach (Manufacturer manu in manuCollection)
                {
                    XmlTreeNode xNode = XmlTreeNode.Create(this);
                    xNode.NodeID = manu.ManufacturerId.ToString();
                    xNode.Text = manu.Name;
                    xNode.Action = "javascript:openManufacturer(" + manu.ManufacturerId + ");";
                    xNode.Icon = "statistik.gif";
                    xNode.OpenIcon = "statistik.gif";

                    tree.Add(xNode);
                }
            }

            public override void RenderJS(ref System.Text.StringBuilder Javascript)
            {
                Javascript.Append(
                        @"
                        function openManufacturer(id) {
                            parent.right.document.location.href = 'commerce/editManufacturer.aspx?man=' + id;
                        }
                    ");
            }

            protected override void CreateAllowedActions(ref System.Collections.Generic.List<IAction> actions)
            {
                actions.Clear();
                actions.Add(ActionRefresh.Instance);
                actions.Add(ActionDelete.Instance);
                //base.CreateAllowedActions(ref actions);
            }

            protected override void CreateRootNodeActions(ref System.Collections.Generic.List<IAction> actions)
            {
                actions.Clear();
                actions.Add(ActionNew.Instance);
                actions.Add(ActionRefresh.Instance);
            }

        }

     

     

    Thanks any help appreciated.

    Sailesh

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jun 07, 2010 @ 17:02
    Dirk De Grave
    0

    Hi Sailesh,

    You don't get the delete to work, or you don't get the 'Delete' context menu option?

    Also, I think you'll get an endless node tree as the Render() method gets hit for each node you click, so you're constantly adding new child nodes...

     

    Cheers,

    /Dirk

  • sailesh 14 posts 45 karma points
    Jun 07, 2010 @ 17:46
    sailesh
    0

    I can get the Delete context menu but nothig happens when I click it. Its the event I want to get it to work.

    The code I gave above works fine in loading the tree as of the moment.

    Sailesh

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jun 07, 2010 @ 20:23
    Dirk De Grave
    0

    Ok Sailesh,

    About time to do some debugging... can you attach to the w3wp.exe process (if running vista/win7) while browsing your umbraco backend. Hit delete from your context menu and verify whether your code is being hit.

    On the other hand, what are you supposed to delete? and why are you using Alias instead of manufacturerId to delete a record from your table?

     

    Let us know how it goes or if you need more info.

     

    Cheers,

    /Dirk

  • sailesh 14 posts 45 karma points
    Jun 10, 2010 @ 16:05
    sailesh
    0

    Hi Dirk,

    did an attach to w3wp process and hit delete. It does not reach the code at all.

    It is suppose to delete a manufacturer's record. I know it is suppose to use the id instead of Alias, that would be my second task after i figure out how to run the delete method.

    In case it helps this is how the <dir>\umbraco\config\create\UI.xml  is configured for the Manufacturer tree.

    <nodeType alias="initmanufacturer">
        <header>Manufacturer</header>
        <usercontrol>/create/simple.ascx</usercontrol>
        <tasks>
          <create assembly="DodecCommerce.umbracoAdmin" type="tasks.ManufacturerTasks" />
          <delete assembly="DodecCommerce.umbracoAdmin" type="tasks.ManufacturerTasks" />
        </tasks>
      </nodeType>

  • sailesh 14 posts 45 karma points
    Jun 10, 2010 @ 17:09
    sailesh
    0

    Following is a javascript error i get

    Message: Sys.Net.WebServiceFailedException: The server method 'Delete' failed with the following error: System.NullReferenceException-- Object reference not set to an instance of an object.
    Line: 4723
    Char: 21
    Code: 0
    URI: http://<siteurl>/ScriptResource.axd?d=D0Tgf587VciCBjeW0RL31ePXEFbJVTTp9DsFioxYDR-5wkU_MT2QQ9LEwQKYB6z2FV9B0d3uzyx1kM_MWnyv62ch935qfAoZFsKDqqiW0Ro1&t=ffffffffec2d9970

  • Martin Lingstuyl 202 posts 379 karma points
    Feb 01, 2011 @ 12:10
    Martin Lingstuyl
    0

    Are you sure you set the namespace right in the config/create/ui.xml file?

    I did that wrong.

  • dolberdinho 5 posts 26 karma points
    Nov 25, 2011 @ 23:55
    dolberdinho
    1

    Hi Martin,

    thanks for the clue, solved it for me.

    I just want to elaborate for others.

    Make sure the nodetype from config/create/ui.xml file

    <nodeType alias="myNodeType">

    actually matches an existing nodetype :-)

     

     

     

  • Anand Kumar 4 posts 24 karma points
    Jun 03, 2014 @ 09:10
    Anand Kumar
    0

    Hi, 

    I have done exactly as you suggested, but I am still getting the error "

    Error handling action

    Value cannot be null. Parameter name: type

     

    and the breakpoint doesn't hit the code at all on debugging.

    Please suggest what may be wrong.

     

    Thanks

  • Martin Lingstuyl 202 posts 379 karma points
    Jun 03, 2014 @ 16:26
    Martin Lingstuyl
    0

    I think you incorrectly combined the ui.xml info + the node-loading class + the tasks class.

    Check the following codes:

    ui.xml

    <nodeType alias="ExampleNodeType">
        <header>Webwinkel Beheer</header>
        <usercontrol>/create/simple.ascx</usercontrol>
        <tasks>
          <delete assembly="ExampleAssembly" type="ExampleTasks" />
        </tasks>
      </nodeType>

     

    LoadTree.cs

    XmlTreeNode sNode = XmlTreeNode.Create(this);
    sNode.NodeID = "uniqueExampleId1";
    sNode.NodeType = "ExampleNodeType";
    sNode.Text = "Example 1";
    sNode.Icon = "node.png";
    sNode.Action = "javascript:editExampleNode(1)";

    sNode.Menu.Clear();
    sNode.Menu.AddRange(new List<IAction> { ActionDelete.Instance });
    sNode.Source = "";
    Tree.Add(sNode);

     

    ExampleTasks.cs

    namespace ExampleAssembly
    {
        class ExampleTasks : umbraco.interfaces.ITaskReturnUrl
        {
    ...implemented class here ....
       }
    }

     

    But thats Umbraco 6. didnt try umbraco 7. Which version are you running?

  • Anand Kumar 4 posts 24 karma points
    Jun 04, 2014 @ 08:22
    Anand Kumar
    0

    Thanks Martin,

    The code helped me and I am able to solve the problem.

    I was putting absolute namespace i.e the full path in the Task.cs file. Also same thins I was doing in UI.xml.

    Thanks again.

    Regards,

    Anand

Please Sign in or register to post replies

Write your reply to:

Draft