Copied to clipboard

Flag this post as spam?

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


  • Sean Dooley 288 posts 527 karma points
    Jan 24, 2013 @ 12:59
    Sean Dooley
    0

    Create a custom section with multiple child node levels

    I am looking to create a custom section with multiple child node levels.

    The custom section needs to display a list of retailers (select * from Retailer)
    Underneath each retailer I would like to display a list of stores (select * from Store where RetailerId = X)

    Retailer
    > Store
    > Store
    Retailer
    > Store
    > Store

    So far I have the below setup which displays all retailers. What do I need to do to display stores underneath a retailer in a custom section?

    public override void Render(ref XmlTree tree){
      IRecordsReader reader = Application.SqlHelper.ExecuteReader("select * from Retailer");
      while (reader.Read()){
    XmlTreeNode xNode = XmlTreeNode.Create(this);
    xNode.NodeID = reader.GetInt("id").ToString();
    xNode.Text = reader.GetString("Name");
    xNode.Icon = "building.png";
    xNode.Action = "javascript:openRetailer(" + reader.GetInt("id").ToString() + ")";
    tree.Add(xNode);
    } }

     

    Umbraco v 4.8.0

  • Sean Dooley 288 posts 527 karma points
    Jan 28, 2013 @ 09:08
    Sean Dooley
    0

    When attempting to edit my previous post I kept getting a xslt error so please use this reply as the main post instead.

    The functionality I am trying to implement in the custom section is as follows

    • The custom section needs to display a list of retailers (select * from Retailer)
    • Underneath each retailer I would like to display a list of stores (select * from Store where RetailerId = X)
    • When right-clicking the root node, Retailers, the user can create a Retailer
    • When right-clicking a Retailer node, the user can delete the Retailer node or create a Store node

    Below is the tree structure I am after

    Retailers
    > Retailer
    >> Store
    >> Store
    > Retailer
    >> Store
    >> Store
    >> Store

    So far I have the below setup which displays all retailers and the related stores.

    What do I need to do to be able to create Store nodes when right-clicking a Retailer node?

    /// Override the render method to create the tree
    public override void Render(ref XmlTree tree){
      IRecordsReader reader;
      if (this.id == this.StartNodeID){
        // Render the Retailer nodes
        reader = Application.SqlHelper.ExecuteReader(@"
          SELECT
            r.Id,
            r.Name,
            CASE
              WHEN s.Total IS NULL
                THEN 0
              ELSE s.Total
            END AS NumStores
          FROM
            mosRetailer r
          LEFT JOIN (SELECT Retailer, COUNT(mosStore.Id) AS Total FROM mosStore GROUP BY Retailer) AS s ON r.Id = s.Retailer");
    
        while (reader.Read()){
          XmlTreeNode xNode = XmlTreeNode.Create(this);
          xNode.NodeID = reader.GetInt("Id").ToString();
          xNode.NodeType = "stockist";
          xNode.Text = reader.GetString("Name");
          xNode.Icon = "building.png";
          xNode.Action = "javascript:openRetailer(" + reader.GetInt("Id").ToString() + ")";
          xNode.Source = (reader.GetInt("NumStores") > 0 ? this.GetTreeServiceUrl(reader.GetInt("Id")) : "");
    
          //set actions
          xNode.Menu.Clear();
          xNode.Menu.Add(ActionNew.Instance);
          xNode.Menu.Add(ActionDelete.Instance);
          xNode.Menu.Add(ActionRefresh.Instance);
    
          tree.Add(xNode);
        }
      } else {
        // Render the Store nodes for the relevant Retailer node
        reader = Application.SqlHelper.ExecuteReader("SELECT * FROM mosStore WHERE Retailer = " + this.id);
        while (reader.Read()) {
          XmlTreeNode xNode = XmlTreeNode.Create(this);
          xNode.NodeID = reader.GetInt("Id").ToString();
          xNode.NodeType = "store";
          xNode.Text = reader.GetString("Name");
          xNode.Icon = "building.png";
          xNode.Action = "javascript:openStore(" + reader.GetInt("Id").ToString() + ")";
          xNode.Source = "";
    
          tree.Add(xNode);
        }
      }
    }

     

    Umbraco v 4.8.0

  • Frederik Østerbye 11 posts 81 karma points
    Feb 03, 2013 @ 15:42
    Frederik Østerbye
    100

    Hi Sean

    First of all you need to create a class that implements the ITask-interface e.g. a class named "RetailerTask".

    I have used BaseTask from this tutorial as template.

    Then you will have to tell Umbraco, that when you click on create it should direct the event to this class. This is configured in the UI.xml-file:

    SITE\Umbraco\Config\Create\UI.xml

    Add an entry that looks something like this:

      <nodeType alias="stockist">
        <header>Macro</header>
        <usercontrol>/Create/simple.ascx</usercontrol>
        <tasks>
          <create assembly="YOURASSEMBLY" type="RetailerTask" />
          <delete assembly="YOURASSEMBLY" type="RetailerTask" />
        </tasks>
      </nodeType> 

     

Please Sign in or register to post replies

Write your reply to:

Draft