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

Tree view control - task list - posting results

Expand Messages
  • chris_k_becker
    Hi all; I am exploring the use of the TreeView control to allow users to make selections from a hierarchical structure, and post the choices back to the server
    Message 1 of 4 , Jun 1, 2006
      Hi all;
      I am exploring the use of the TreeView control to allow users to make
      selections from a hierarchical structure, and post the choices back to
      the server for database update. The Task List approach in the online
      examples served as my starting point for development.

      I wish to have user's choices rendered as an array of request
      parameters, to be sent via a POST in a form back to the server. Could
      someone point me in the right direction as to how to achieve this?

      Any help would be greatly appreciated - thanks!

      Regards,

      --Chris
    • Nige White
      ... I trap the submit event, and send an XML version of the tree: YAHOO.util.Event.addListener( mainForm , submit , function(e) { var c =
      Message 2 of 4 , Jun 1, 2006
        chris_k_becker wrote:

        >Hi all;
        >I am exploring the use of the TreeView control to allow users to make
        >selections from a hierarchical structure, and post the choices back to
        >the server for database update. The Task List approach in the online
        >examples served as my starting point for development.
        >
        >I wish to have user's choices rendered as an array of request
        >parameters, to be sent via a POST in a form back to the server. Could
        >someone point me in the right direction as to how to achieve this?
        >
        >Any help would be greatly appreciated - thanks!
        >
        I trap the submit event, and send an XML version of the tree:

        YAHOO.util.Event.addListener("mainForm", "submit", function(e)
        {
        var c = YAHOO.util.Connect.asyncRequest("POST", "<%=
        request.getContextPath()%>/MenuBuilder.jsp?updateUserUuid=<%=userUuid%>",
        {
        success:updateDone,
        failure:updateNotDone,
        scope:c
        }, tree.toXML());
        YAHOO.util.Event.preventDefault(e);
        });


        DDTreeView.prototype.toXML = function(url)
        {
        return fcl.util.objectToXml(this.getData());
        };

        DDTreeView.prototype.getData = function()
        {
        var result = this.data || {};
        var r = this.getRoot();
        var c = [];
        result[result.length]= c;
        for (var i = 0; i < r.children.length; i++)
        {
        c.push({node:this.getNodeData(r.children[i])});
        }
        return {tree:result};
        };

        DDTreeView.prototype.getNodeData = function(node)
        {
        var result = (typeof node.data == "object") ? node.data : {};
        result.description = node.label;
        if (node.children && node.children.length)
        {
        var c = [];
        result[result.length] = c;
        for (var i = 0; i < node.children.length; i++)
        {
        c.push({node:this.getNodeData(node.children[i])});
        }
        }
        return result;
        };



        fcl.util.objectToXml = function(o, name)
        {
        var result = "";
        var body = "";
        if (name)
        result = "<" + name;
        for (var prop in o)
        {
        if (o[prop].constructor == Array)
        {
        var a = o[prop];
        if (a.length)
        {
        for (var i = 0; i < a.length; i++)
        {
        if (prop != "undefined")
        body += fcl.util.objectToXml(a[i], prop);
        else
        body += fcl.util.objectToXml(a[i]);
        }
        }
        else
        {
        if (prop && (prop != "undefined"))
        body += "<" + prop + "/>";
        }
        }
        else if (typeof o[prop] == "object")
        {
        body += fcl.util.objectToXml(o[prop], prop);
        }
        else
        {
        if (name)
        result += " " + prop + "=\"" + o[prop] + "\"";
        else
        body += "<" + prop + " value=\"" + o[prop] + "\"/>";
        }
        }
        if (name)
        {
        if (body.length)
        return result + ">" + body + "</" + name + ">";
        else
        return result + "/>";
        }
        else
        return body;
        };

        _____________________________________________________________________
        This message has been checked for all known viruses. Virus scanning
        powered by Messagelabs http://www.messagelabs.com For more information
        e-mail : hostmaster@...
      • chris_k_becker
        Nige; Thanks for the response. A couple of quick followup questions, if I may: 1) Does the code you provided reside in the body of the page containing the
        Message 3 of 4 , Jun 1, 2006
          Nige;

          Thanks for the response. A couple of quick followup questions, if I
          may:
          1) Does the code you provided reside in the body of the page
          containing the form?
          2) If not, could you show how the page containing the form submit
          would invoke the listener?

          I know this is a bit OT, but would appreciate the feedback... thanks
          again for the reply

          Regards,

          --Chris




          --- In ydn-javascript@yahoogroups.com, Nige White <nigelw@...> wrote:
          >
          > chris_k_becker wrote:
          >
          > >Hi all;
          > >I am exploring the use of the TreeView control to allow users to
          make
          > >selections from a hierarchical structure, and post the choices
          back to
          > >the server for database update. The Task List approach in the
          online
          > >examples served as my starting point for development.
          > >
          > >I wish to have user's choices rendered as an array of request
          > >parameters, to be sent via a POST in a form back to the server.
          Could
          > >someone point me in the right direction as to how to achieve this?
          > >
          > >Any help would be greatly appreciated - thanks!
          > >
          > I trap the submit event, and send an XML version of the tree:
          >
          > YAHOO.util.Event.addListener("mainForm", "submit",
          function(e)
          > {
          > var c = YAHOO.util.Connect.asyncRequest("POST", "<%
          =
          > request.getContextPath()%>/MenuBuilder.jsp?updateUserUuid=<%
          =userUuid%>",
          > {
          > success:updateDone,
          > failure:updateNotDone,
          > scope:c
          > }, tree.toXML());
          > YAHOO.util.Event.preventDefault(e);
          > });
          >
          >
          > DDTreeView.prototype.toXML = function(url)
          > {
          > return fcl.util.objectToXml(this.getData());
          > };
          >
          > DDTreeView.prototype.getData = function()
          > {
          > var result = this.data || {};
          > var r = this.getRoot();
          > var c = [];
          > result[result.length]= c;
          > for (var i = 0; i < r.children.length; i++)
          > {
          > c.push({node:this.getNodeData(r.children[i])});
          > }
          > return {tree:result};
          > };
          >
          > DDTreeView.prototype.getNodeData = function(node)
          > {
          > var result = (typeof node.data == "object") ? node.data :
          {};
          > result.description = node.label;
          > if (node.children && node.children.length)
          > {
          > var c = [];
          > result[result.length] = c;
          > for (var i = 0; i < node.children.length; i++)
          > {
          > c.push({node:this.getNodeData(node.children[i])});
          > }
          > }
          > return result;
          > };
          >
          >
          >
          > fcl.util.objectToXml = function(o, name)
          > {
          > var result = "";
          > var body = "";
          > if (name)
          > result = "<" + name;
          > for (var prop in o)
          > {
          > if (o[prop].constructor == Array)
          > {
          > var a = o[prop];
          > if (a.length)
          > {
          > for (var i = 0; i < a.length; i++)
          > {
          > if (prop != "undefined")
          > body += fcl.util.objectToXml(a[i], prop);
          > else
          > body += fcl.util.objectToXml(a[i]);
          > }
          > }
          > else
          > {
          > if (prop && (prop != "undefined"))
          > body += "<" + prop + "/>";
          > }
          > }
          > else if (typeof o[prop] == "object")
          > {
          > body += fcl.util.objectToXml(o[prop], prop);
          > }
          > else
          > {
          > if (name)
          > result += " " + prop + "=\"" + o[prop] + "\"";
          > else
          > body += "<" + prop + " value=\"" + o[prop] + "\"/>";
          > }
          > }
          > if (name)
          > {
          > if (body.length)
          > return result + ">" + body + "</" + name + ">";
          > else
          > return result + "/>";
          > }
          > else
          > return body;
          > };
          >
          >
          _____________________________________________________________________
          > This message has been checked for all known viruses. Virus scanning
          > powered by Messagelabs http://www.messagelabs.com For more
          information
          > e-mail : hostmaster@...
          >
        • Nige White
          ... You don t invoke the listener. It s attached to the submit event for the form whose id is mainForm : YAHOO.util.Event.addListener( mainForm , submit ,
          Message 4 of 4 , Jun 1, 2006
            chris_k_becker wrote:

            >Nige;
            >
            >Thanks for the response. A couple of quick followup questions, if I
            >may:
            >1) Does the code you provided reside in the body of the page
            >containing the form?
            >2) If not, could you show how the page containing the form submit
            >would invoke the listener?
            >
            >I know this is a bit OT, but would appreciate the feedback... thanks
            >again for the reply
            >
            You don't invoke the listener. It's attached to the submit event for the
            form whose id is "mainForm":

            YAHOO.util.Event.addListener("mainForm", "submit", function(){alert("submitting"}});



            _____________________________________________________________________
            This message has been checked for all known viruses. Virus scanning
            powered by Messagelabs http://www.messagelabs.com For more information
            e-mail : hostmaster@...
          Your message has been successfully submitted and would be delivered to recipients shortly.