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 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) { }
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?
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.
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
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
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
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
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>
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
Are you sure you set the namespace right in the config/create/ui.xml file?
I did that wrong.
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 :-)
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
I think you incorrectly combined the ui.xml info + the node-loading class + the tasks class.
Check the following codes:
ui.xml
LoadTree.cs
ExampleTasks.cs
But thats Umbraco 6. didnt try umbraco 7. Which version are you running?
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
is working on a reply...