Loading ...
Sorry, an error occurred while loading the content.

TreeView/Connection Manager Problem

Expand Messages
  • smeep2k4
    When I first was playing with the TreeView component, all the examples had a nice little spinner when the user clicked a node. I ve created an app that makes
    Message 1 of 2 , Jan 2, 2007
    • 0 Attachment
      When I first was playing with the TreeView component, all the examples
      had a nice little spinner when the user clicked a node. I've created
      an app that makes Connection Manager calls and now the spinner no
      longer appears. It would be much more helpful now that I'm using the
      Connection Manager, too, to denote that I'm waiting for the server to
      return. Currently, I click a node, and the + disappears until the
      server replies. This is fine, except for nodes that have no children.
      then I have to assume after 5 seconds that the node is childless.

      Here's the code I'm using to fill the tree:

      <script>
      var tree;
      function initTree() {
      // create a new tree
      tree = new YAHOO.widget.TreeView("treeContainer");

      //get root node for tree:
      var root = tree.getRoot();

      // set the whole tree to do dynamic loading
      tree.setDynamicLoad(loadNodeData,1);
      // create dummy data for root
      var tmpNode = new YAHOO.widget.TextNode({label:"main_program", id:
      "main_program01"}, root, false);

      // Now draw the tree
      tree.draw();
      }

      function loadNodeData(node, onCompleteCallback) {
      var label = node.data.label;
      var id = node.data.id;
      var release = document.callTreeForm.release.value;
      // -- code to get your data, possibly using Connect --
      var responseSuccess = function(o)
      {
      var programs;
      var programIds;
      var xmlDoc = o.responseXML;
      programs = xmlDoc.getElementsByTagName('programName');
      programIds = xmlDoc.getElementsByTagName('programId');
      for(var i = 0;i < programs.length;i++)
      {
      var myobj = { label: programs[i].firstChild.nodeValue, id:
      programIds[i].firstChild.nodeValue };

      var tmpNode = new YAHOO.widget.TextNode(myobj, node, false);
      tree.draw();
      }
      }
      var responseFailure = function(o){ alert('responseFailure: ' +
      o.statusText); }
      var callback =
      {
      success:responseSuccess,
      failure:responseFailure
      };
      var cObj = YAHOO.util.Connect.asyncRequest('POST', 'callTree.cgi',
      callback, "program="+label+"&release="+release);

      onCompleteCallback();
      }
      </script>

      This is the first time I've played with YUI, and I wouldn't classify
      myself as a javascript expert, so I'm assuming I'm missing something
      simple. Any ideas out there?
    • smeep2k4
      Nevermind... Figured it out. I had to move the onCompleteCallback() inside the success/failure code sections. Works very well now!
      Message 2 of 2 , Jan 2, 2007
      • 0 Attachment
        Nevermind... Figured it out. I had to move the onCompleteCallback()
        inside the success/failure code sections. Works very well now!

        --- In ydn-javascript@yahoogroups.com, "smeep2k4" <wilsondr@...> wrote:
        >
        > When I first was playing with the TreeView component, all the examples
        > had a nice little spinner when the user clicked a node. I've created
        > an app that makes Connection Manager calls and now the spinner no
        > longer appears. It would be much more helpful now that I'm using the
        > Connection Manager, too, to denote that I'm waiting for the server to
        > return. Currently, I click a node, and the + disappears until the
        > server replies. This is fine, except for nodes that have no children.
        > then I have to assume after 5 seconds that the node is childless.
        >
        > Here's the code I'm using to fill the tree:
        >
        > <script>
        > var tree;
        > function initTree() {
        > // create a new tree
        > tree = new YAHOO.widget.TreeView("treeContainer");
        >
        > //get root node for tree:
        > var root = tree.getRoot();
        >
        > // set the whole tree to do dynamic loading
        > tree.setDynamicLoad(loadNodeData,1);
        > // create dummy data for root
        > var tmpNode = new YAHOO.widget.TextNode({label:"main_program", id:
        > "main_program01"}, root, false);
        >
        > // Now draw the tree
        > tree.draw();
        > }
        >
        > function loadNodeData(node, onCompleteCallback) {
        > var label = node.data.label;
        > var id = node.data.id;
        > var release = document.callTreeForm.release.value;
        > // -- code to get your data, possibly using Connect --
        > var responseSuccess = function(o)
        > {
        > var programs;
        > var programIds;
        > var xmlDoc = o.responseXML;
        > programs = xmlDoc.getElementsByTagName('programName');
        > programIds = xmlDoc.getElementsByTagName('programId');
        > for(var i = 0;i < programs.length;i++)
        > {
        > var myobj = { label: programs[i].firstChild.nodeValue, id:
        > programIds[i].firstChild.nodeValue };
        >
        > var tmpNode = new YAHOO.widget.TextNode(myobj, node, false);
        > tree.draw();
        > }
        > }
        > var responseFailure = function(o){ alert('responseFailure: ' +
        > o.statusText); }
        > var callback =
        > {
        > success:responseSuccess,
        > failure:responseFailure
        > };
        > var cObj = YAHOO.util.Connect.asyncRequest('POST', 'callTree.cgi',
        > callback, "program="+label+"&release="+release);
        >
        > onCompleteCallback();
        > }
        > </script>
        >
        > This is the first time I've played with YUI, and I wouldn't classify
        > myself as a javascript expert, so I'm assuming I'm missing something
        > simple. Any ideas out there?
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.