Copied to clipboard

Flag this post as spam?

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


  • Paul Sørensen 304 posts 650 karma points
    Aug 13, 2010 @ 10:54
    Paul Sørensen
    0

    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

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Aug 13, 2010 @ 11:30
    Darren Ferguson
    0

    You need to assign a list of IAction to your tree node - these can be default actions or your own:

    node.Menu = new List<IAction>(new IAction[] { ActionRefresh.Instance, ActionWorkflowCreate.Instance });

    You define context menu items by implementing the IAction interface e.g.

    public class ActionWorkflowCreate : IAction
        {
            private static readonly ActionWorkflowCreate m_instance = new ActionWorkflowCreate();


            public static ActionWorkflowCreate Instance
            {
                get { return m_instance; }
            }

            public char Letter
            {
                get
                {
                    return '~';
                }
            }

            public string JsFunctionName
            {
                get
                {
                    return "parent.newWorkflow()";
                }
            }

            public string JsSource
            {
                get
                {

                    return ConfigurationManager.AppSettings["umbracoPath"] + "/plugins/FMWG/Workflow/tree.js";
                }
            }

            public string Alias
            {
                get
                {

                    return "Create New Configuration";
                }
            }

            public string Icon
            {
                get { return "editor/SaveToPublish.gif"; }
            }

            public bool ShowInNotifier
            {
                get
                {

                    return false;
                }
            }
            public bool CanBePermissionAssigned
            {
                get
                {

                    return false;
                }
            }
        }

    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.

     

  • Paul Sørensen 304 posts 650 karma points
    Aug 13, 2010 @ 22:54
    Paul Sørensen
    0

     

    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

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Aug 14, 2010 @ 09:52
    Darren Ferguson
    0

    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.

     

  • Paul Sørensen 304 posts 650 karma points
    Aug 14, 2010 @ 14:47
    Paul Sørensen
    0

    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

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Aug 15, 2010 @ 12:40
    Darren Ferguson
    0

    I'm confused by the notion of 'item'. what are the items in your tree? Content nodes, custom objects?

    Thanks.

    D.

  • Paul Sørensen 304 posts 650 karma points
    Aug 15, 2010 @ 14:46
    Paul Sørensen
    0

     

    Item = Content node

    Paul S

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Aug 16, 2010 @ 09:45
    Darren Ferguson
    0

    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.

  • Paul Sørensen 304 posts 650 karma points
    Aug 16, 2010 @ 17:31
    Paul Sørensen
    0

    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:

    <nodeType alias="clubs">
        <header>Klub</header>
        <usercontrol>/create/simple.ascx</usercontrol>
        <tasks>
            <create assembly="PaulS.Club" type="ClubTasks" />
            <delete assembly="PaulS.Club" type="ClubTasks" />
        </tasks>
    </nodeType>
    <nodeType alias="Course">
        <header>Bane</header>
        <usercontrol>/create/simple.ascx</usercontrol>
        <tasks>
            <create assembly="PaulS.Club" type="CourseTasks" />
            <delete assembly="PaulS.Club" type="CourseTasks" />
        </tasks>
    </nodeType>
    <nodeType alias="CourseDetail">
        <header>Detaljer</header>
        <usercontrol>/create/CourseCreateDialog.ascx</usercontrol>
        <tasks>
            <create assembly="PaulS.Club" type="CourseDetailTasks" />
            <delete assembly="PaulS.Club" type="CourseDetailTasks" />
        </tasks>
    </nodeType>

     

    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

      

  • Morten K. J. 23 posts 64 karma points
    Sep 03, 2010 @ 18:17
    Morten K. J.
    0

    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.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 03, 2010 @ 18:59
    Dirk De Grave
    0

    Hi Morten,

    If you're using v4.5.x, to get a reference to the node the action is operated on, use:

    UmbClientMgr.mainTree().getActionNode().nodeId;

     

    Hope this helps.

    Regards,

    /Dirk

  • Paul Sørensen 304 posts 650 karma points
    Sep 03, 2010 @ 21:43
    Paul Sørensen
    0

    Hi Dirk

    Can you answer the question about how to call different dialogs depending on the node in the tree?

    /Paul S

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 03, 2010 @ 22:51
    Dirk De Grave
    0

    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:

     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...

     

    Cheers,

    /Dirk

     

     

  • Paul Sørensen 304 posts 650 karma points
    Sep 03, 2010 @ 23:08
    Paul Sørensen
    0

    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

     

Please Sign in or register to post replies

Write your reply to:

Draft