Copied to clipboard

Flag this post as spam?

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


  • Dylan 5 posts 25 karma points
    Aug 25, 2009 @ 19:06
    Dylan
    0

    Custom Umbraco Section - Create Function

    Hello,

    I'm new to umbraco and need some help with creating a custom section. I have created a section called notifications which will allow users to create messages for displaying in the front end, depending on which member is logged in the notifications will vary. I have modified the code found here: http://www.nibble.be/?p=71 to fit my needs, and created an aspx page with the notifications form. I need to be able to create an unlimited amount of nodes in the notifications tree and store each one in the database. When i right click on the root node i see the option to create a new node, but this throws an error as i have not coded the create functionality. I would like to know how i can allow this create button to create a new node with a new node id, and save it to the database. Any help or examples would be greatly appreciated.

    Please let me know if any additional information is required.

     

     

  • Masood Afzal 176 posts 522 karma points
    Aug 25, 2009 @ 19:27
    Masood Afzal
    0

    To create new nodes, you can add code to "Save()" function of class CustomTasks

    To render nodes in nodes tree, add your code to "Render()" function of class LoadCustomTree

     

  • Dylan 5 posts 25 karma points
    Aug 25, 2009 @ 19:46
    Dylan
    0

    Hi,

    Thanks for the quick reply.

    Here is what i have for those two functions:

     public bool Save()
            {
                m_returnUrl = string.Format("notifications/editNotifs.aspx?id={0}", "1");

                return true;
            }

    public override void Render(ref XmlTree tree)
            {
                XmlTreeNode xNode = XmlTreeNode.Create(this);
                xNode.NodeID = "-2000";
                xNode.Text = "Notification";
                xNode.Action = "javascript:openNotif('" + "-2000" + "');";
                xNode.Icon = "doc.gif";
                tree.Add(xNode);
            }

     

    Do you have an example of what needs to go where in order to be able to create new nodes?

     

    Thanks.

     

  • Masood Afzal 176 posts 522 karma points
    Aug 25, 2009 @ 20:01
    Masood Afzal
    0

    I have added a csv export in custom section. Here is code for rendering the nodes. 'custom/contentExport.aspx' is my aspx page which export contents as csv.  

     

    public override void Render(ref XmlTree tree)

    {

     

    // CsvExport

    XmlTreeNode csvNode = XmlTreeNode.Create(

    this);

    csvNode.NodeID =

    "2";

    csvNode.Text =

    "Content Export";

    csvNode.Action =

    "javascript:contentExport('" + "2" + "');";

    csvNode.Icon =

    "doc.gif";

    tree.Add(csvNode);

    }

     

     

    public override void RenderJS(ref StringBuilder Javascript)

    {

    Javascript.Append(

     

    @"

    function contentExport(id) {

    parent.right.document.location.href = 'custom/contentExport.aspx?id=' + id;

    }

    "

     

    );

    }

  • Masood Afzal 176 posts 522 karma points
    Aug 25, 2009 @ 20:04
    Masood Afzal
    0

    Unfortunatley i dont have any example for creating nodes. To create nodes in tree , you have to create nodes and save in database. On rendering you have to retrieve list of nodes and add links by adding nodeid. NodeType is available in qureystring parameters (custom in this case)

     

     

  • Dylan 5 posts 25 karma points
    Aug 26, 2009 @ 17:40
    Dylan
    0

    Thanks for your help.

    I've added some code to the save function in order to add a new row using the next id in the sequence. I'm getting the following error when I right click on the parent node and click create:

    Server Error in '/' Application.

    ERROR CREATING CONTROL FOR NODETYPE: initNotifications

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentException: ERROR CREATING CONTROL FOR NODETYPE: initNotifications

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace:

    [ArgumentException: ERROR CREATING CONTROL FOR NODETYPE: initNotifications]
    umbraco.cms.presentation.Create.Page_Load(Object sender, EventArgs e) +415
    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
    System.Web.UI.Control.OnLoad(EventArgs e) +99
    umbraco.BasePages.BasePage.OnLoad(EventArgs e) +12
    System.Web.UI.Control.LoadRecursive() +47
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436



    Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433

     

     

    It seems I need to define the nodetype somewhere in order to be able to create new nodes. Any ideas on where to add the code?


  • dandrayne 1138 posts 2262 karma points
    Aug 26, 2009 @ 18:25
  • Dylan 5 posts 25 karma points
    Aug 26, 2009 @ 18:41
    Dylan
    0

    Thanks for your reply, unfortunately that example creates only two nodes in the tree. The example does not cover the functionality of the create button. I am able to hard code more than one node into the tree, but I need to be able to right click on the parent node and create an unlimited amount of nodes from the back office.

  • Petr Snobelt 923 posts 1535 karma points
    Aug 26, 2009 @ 19:47
    Petr Snobelt
    0

    You can remove original create action from tree contextmenu and replace it with your own. But I'm also interested if there is another way.

  • Dylan 5 posts 25 karma points
    Aug 27, 2009 @ 19:53
    Dylan
    0

    I managed to create my own dialog box using the same create button by checking the nodeType in the umbracoDefault.js file. In the function createNew(), I simply added an if statement checking the nodeType. If the node type is set to "Notifications" then i redirect to my new custom aspx page using the function openModal().

Please Sign in or register to post replies

Write your reply to:

Draft