I have created a new Custom Section. I would like to design my own dialog to create new items. What i needed to be able to call your own dialog from the context menu and what are the requirements for such a dialog
I have created a custom section which maintains a list of items - in three levels. When I right-click the root node and select Create a dialog pops up giving me the possibility to create a new item by specifying a name.
For one of the levels it's not enough for me just to enter a name - I need to be fill more fields in order to create the new item so I need to create my own dialog to be shown when I right click the root node and select create.
I don't have a problem creating the dialog - just a problem on how to wired this up - and wiring it up to different dialog boxes depending on the level in which I want to add a new item - I believe something needs to be added to some config files also.
I have seen a lot of tutorials describing the multi level custom sections - I just haven't seen any on how to wire up a level specific 'create-dialog'
- hope it clarifies to be able to help - appreciate your effort
Ok - why would you need properties in the create dialogue? Why not have the additional information in fields in the content node itself?
To be honest I've lost track a bit here because I didn't think that you could just roll out custom content trees. are you extending the existing "loadContent" tree or have you written something bespoke?
I believe I need a special Create dialog for the CourseDetail because the unique key consist of 2 fields - must be the same when I'm creating a new XSLT file in the Developer section.
I am stuck at exactly the same place... I have a custom tree and a custom create usercontrol in place, but I do not know how to get the parentId needed to create a new record in my custom database.
Sure I can.... I've seen a previous post of yours where you've been building a complete custom tree with three different node types (Club, Course, CourseDetail), and you've also added your own custom actions to each of these type of nodes.
Honestly, I'm bit confused about your question as you've already answered the question yourself. From looking at your code:
you already use your own custom action (which is probably invoking a dialog). So, only thing that's left is to define different custom actions for the other type of nodes (that you can use in the FillCourses() and FillCourseDetails() functions) to call a different dialog
And so, each of your own custom actions will call their own custom create dialog....A short example:
public class ActionCreateActivity : IAction {
private static readonly ActionCreateActivity instance = new ActionCreateActivity();
private ActionCreateActivity() { }
public static ActionCreateActivity Instance {
get {
return instance;
}
}
#region Implementation of IAction
public char Letter {
get { return '~'; }
}
public bool ShowInNotifier {
get { return true; }
}
public bool CanBePermissionAssigned {
get { return false; }
}
public string Icon {
get {
return ".menuSpr sprNew";
}
}
public string Alias {
get { return "createActivity"; }
}
public string JsFunctionName {
get {
return "createActivity();";
}
}
public string JsSource {
get {
return @"function createActivity(){
UmbClientMgr.openModalWindow('dialogs/CreateActivityDialog.aspx?parentId=' + UmbClientMgr.mainTree().getActionNode().nodeId, 'New activity', true, 460, 200, 0, 0, '', '');
}";
}
}
#endregion
}
Most important is the JsSource property which should return some javascript code that'll be injected automagically into the tree code... that piece of javascript code will launch a custom dialog and because you've defined different custom actions on the different node types, you'll have different dialogs for each of the node types.
And btw, there's no need to add some xml to the ui.xml located in /umbraco/config/create
(Remark: this code is only applicable as from v4.5.x)
Does that make sense? Or still lots of questions. Let us know, we'll see how we can help you...
It looks as if you have opened my eyes. I guess I have to just tried so much that I couldn't see the solution - I'll try it right away and let you know.
Create new items in Custom Section
Hi
I have created a new Custom Section. I would like to design my own dialog to create new items. What i needed to be able to call your own dialog from the context menu and what are the requirements for such a dialog
Thanks
Paul S
You need to assign a list of IAction to your tree node - these can be default actions or your own:
You define context menu items by implementing the IAction interface e.g.
Your JS function can either open a modal or update the right frame in Umbraco with an aspx page provided by your application.
These pages should inherit from UmbracoEnsuredPad to ensure that access is restricted to authenticated users.
Hi
Do I need all this if all I want to do is to call my own 'create' dialog. I must be possible to call it when the existing 'Create' action is called
Paul S
Hi Paul,
Invest 10 minutes in explaining what you are trying to do in a bit more detail and I'll see if I can help.
What does your custom section do? What are the items that you want to create?
You could just use the existing create IAction instance but there are certain requirements that you'd have to fulfill.
Hi Darren
I have created a custom section which maintains a list of items - in three levels. When I right-click the root node and select Create a dialog pops up giving me the possibility to create a new item by specifying a name.
For one of the levels it's not enough for me just to enter a name - I need to be fill more fields in order to create the new item so I need to create my own dialog to be shown when I right click the root node and select create.
I don't have a problem creating the dialog - just a problem on how to wired this up - and wiring it up to different dialog boxes depending on the level in which I want to add a new item - I believe something needs to be added to some config files also.
I have seen a lot of tutorials describing the multi level custom sections - I just haven't seen any on how to wire up a level specific 'create-dialog'
- hope it clarifies to be able to help - appreciate your effort
Paul S
I'm confused by the notion of 'item'. what are the items in your tree? Content nodes, custom objects?
Thanks.
D.
Item = Content node
Paul S
Ok - why would you need properties in the create dialogue? Why not have the additional information in fields in the content node itself?
To be honest I've lost track a bit here because I didn't think that you could just roll out custom content trees. are you extending the existing "loadContent" tree or have you written something bespoke?
It may help if you post your custom tree code.
Here's my Custom Section
I have 3 levels of nodes . Club, Course and CourseDetail.
I load them like this:
protected override void CreateRootNode(ref XmlTreeNode rootNode)
{
rootNode.Icon = FolderIcon;
rootNode.OpenIcon = FolderIconOpen;
rootNode.NodeType = TreeAlias;
rootNode.NodeID = "init";
}
public override void Render(ref XmlTree tree)
{
try
{
if (string.IsNullOrEmpty(this.NodeKey))
{
ClubCollection clubs = new ClubCollection();
clubs.Fill();
foreach (ClubInfo c in clubs)
{
XmlTreeNode node = XmlTreeNode.Create(this);
node.NodeID = c.ClubId.ToString();
node.Text = c.ClubName;
node.Icon = "doc2.gif";
node.NodeType = this.TreeAlias;
node.Action = "javascript:ClubLoad(" + node.NodeID + ")";
TreeService treeService = new TreeService(-1, TreeAlias,
ShowContextMenu, IsDialog, DialogMode, app,
string.Format("Club-{0}", c.ClubId));
node.Menu.Clear();
node.Menu.AddRange(new List<IAction> {
CourseCreateAction.Instance,
ContextMenuSeperator.Instance,
ActionRefresh.Instance });
node.Source = treeService.GetServiceUrl();
tree.Add(node);
}
}
else
{
string[] keys = this.NodeKey.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
if (string.Equals(keys[0], "Club", StringComparison.InvariantCultureIgnoreCase))
FillCourses(tree, Convert.ToInt32(keys[1]));
else if (string.Equals(keys[0], "Course", StringComparison.InvariantCultureIgnoreCase))
FillCourseDetails(tree, Convert.ToInt32(keys[1]));
return;
}
}
catch (Exception ex)
{
PaulS.Utility.Helper.LogError(ex);
}
}
private void FillCourses(XmlTree tree, int id)
{
ClubCollection clubs = new ClubCollection();
clubs.Fill(id);
if (clubs.Count < 1)
return;
clubs[0].Courses.Fill();
CourseCollection courses = clubs[0].Courses;
foreach (CourseInfo c in courses)
{
XmlTreeNode node = XmlTreeNode.Create(this);
node.NodeID = c.CourseId.ToString();
node.Text = c.CourseName;
node.Icon = "doc3.gif";
node.NodeType = "Course";
node.Action = string.Format("javascript:CourseLoad({0});", node.NodeID);
TreeService treeService = new TreeService(-1, TreeAlias,
ShowContextMenu, IsDialog, DialogMode, this.app,
string.Format("Course-{0}", c.CourseId));
node.Menu.Clear();
node.Menu.AddRange(new List<IAction> {
ActionNew.Instance,
ContextMenuSeperator.Instance,
ActionRefresh.Instance });
node.Source = treeService.GetServiceUrl();
tree.Add(node);
}
}
private void FillCourseDetails(XmlTree tree, int courseId)
{
CourseDetailCollection details = new CourseDetailCollection();
details.FillById(courseId);
if (details.Count < 1)
return;
foreach (CourseDetailInfo d in details)
{
XmlTreeNode node = XmlTreeNode.Create(this);
node.NodeID = d.CourseDetailId.ToString();
node.Text = d.CourseDetailText; // d.TeeColour;
node.Icon = "doc3.gif";
node.NodeType = "CourseDetail";
node.Action = string.Format("javascript:CourseDetailLoad({0});", node.NodeID);
TreeService treeService = new TreeService(-1, TreeAlias,
base.ShowContextMenu, base.IsDialog, base.DialogMode, base.app,
string.Format("CourseDetail-{0}", d.CourseId));
node.Menu.Clear();
//node.Menu.AddRange(new List<IAction> {
// ActionNew.Instance,
// ContextMenuSeperator.Instance,
// ActionRefresh.Instance });
node.Source = treeService.GetServiceUrl();
tree.Add(node);
}
return;
}
public override void RenderJS(ref System.Text.StringBuilder Javascript)
{
Javascript.Append(
@"function ClubLoad(id)
{
parent.right.document.location.href = 'plugins/ClubEdit.aspx?id=' + id;
}
function CourseLoad(id)
{
parent.right.document.location.href = 'plugins/CourseEdit.aspx?id=' + id;
}
function CourseDetailLoad(id)
{
parent.right.document.location.href = 'plugins/CourseDetailEdit.aspx?id=' + id;
}"
);
}
I'm not sure about the NodeType.
In the UI.xml located in the umbraco/config/create folder i have:
I think the alias is the link to the NodeType.
I believe I need a special Create dialog for the CourseDetail because the unique key consist of 2 fields - must be the same when I'm creating a new XSLT file in the Developer section.
- hope this helps to clarify
/Paul S
I am stuck at exactly the same place... I have a custom tree and a custom create usercontrol in place, but I do not know how to get the parentId needed to create a new record in my custom database.
Hi Morten,
If you're using v4.5.x, to get a reference to the node the action is operated on, use:
Hope this helps.
Regards,
/Dirk
Hi Dirk
Can you answer the question about how to call different dialogs depending on the node in the tree?
/Paul S
Sure I can.... I've seen a previous post of yours where you've been building a complete custom tree with three different node types (Club, Course, CourseDetail), and you've also added your own custom actions to each of these type of nodes.
Honestly, I'm bit confused about your question as you've already answered the question yourself. From looking at your code:
node.Menu.AddRange(new List<IAction> {
CourseCreateAction.Instance,
ContextMenuSeperator.Instance,
ActionRefresh.Instance });
you already use your own custom action (which is probably invoking a dialog). So, only thing that's left is to define different custom actions for the other type of nodes (that you can use in the FillCourses() and FillCourseDetails() functions) to call a different dialog
And so, each of your own custom actions will call their own custom create dialog....A short example:
Most important is the JsSource property which should return some javascript code that'll be injected automagically into the tree code... that piece of javascript code will launch a custom dialog and because you've defined different custom actions on the different node types, you'll have different dialogs for each of the node types.
And btw, there's no need to add some xml to the ui.xml located in /umbraco/config/create
(Remark: this code is only applicable as from v4.5.x)
Does that make sense? Or still lots of questions. Let us know, we'll see how we can help you...
Cheers,
/Dirk
Thanks Dirk
It looks as if you have opened my eyes. I guess I have to just tried so much that I couldn't see the solution - I'll try it right away and let you know.
Thanks again
Paul S
is working on a reply...