1. #1
    Ext User
    Join Date
    Mar 2007
    Posts
    2
    Vote Rating
    0
    MBragg is on a distinguished road

      0  

    Default Help: Sending Ext.tree data back to server (ColdFusion)

    Help: Sending Ext.tree data back to server (ColdFusion)


    Hi everyone,

    I'm new to YUI, JSON, and a fairly novice JavaScripter - I usually deal with the server side of things and am comfortable in CFMX.

    I'm re-writing an app, and want to use the (awesome!) drag-and-drop tree control to maintain various hierarchies within the database. I have found a few examples in the forums, and has kludged together something that kind of works (See below...)

    Code:
    /*
    		 * Ext - JS Library 1.0 Alpha 3 - Rev 4
    		 * Copyright(c) 2006-2007, Jack Slocum.
    		 */
    		 
    		Ext.onReady(function(){
    			// shorthand
    			var Tree = Ext.tree;
    			
    			var tree = new Tree.TreePanel('tree-div', {
    				animate:true, 
    				loader: new Tree.TreeLoader({dataUrl:'boo.cfm'}),
    				enableDD:true,
    				containerScroll: true
    			});
    			
    			tree.on("enddrag", function(tree) {
    			   
    				// create a simplified node hierarchy that can be JSONified
    				function simplifyNodes(node) {
    					var resultNode = {};
    					var kids = node.childNodes;
    					var len = kids.length;
    					for (var i = 0; i < len; i++) {
    						resultNode[kids[i].id] = simplifyNodes(kids[i]);
    					}
    					return resultNode;
    				}
    				
    				// JSON-encode our tree
    				var encNodes = Ext.encode(simplifyNodes(tree.root));
    				
    				// send it to the backend to save
    				YAHOO.util.Connect.asyncRequest(
    					'POST',
    					'boo.cfm',
    					null,
    					'action=treeUpdate&nodes=' + encodeURIComponent(encNodes)
    				);
    			   
    			});
    		
    			// set the root node
    			var root = new Tree.AsyncTreeNode({
    				text: '#arguments.nodeTitle#',
    				draggable:false,
    				id:'id_#arguments.nodeID#'
    			});
    			tree.setRootNode(root);
    		
    			// render the tree
    			tree.render();
    			root.expand();
    		});
    With this I can create the tree I need from my hier, allow the user to assign new parent nodes, and also allow the user to reorder the nodes, then send the current state of the hierarchy back to the server where it waits to be processed if everything checks out and the user completes the process...

    My problem starts with the "simplifyNodes()" function - which creates a JSON string that decodes into a structure of nested structures (objects) in CFMX (I'm using jsonDecode() from cflib.org)...

    Structure keys in CF are unordered - so while I can determine if a node has a new parent, I can not determine the sort order easily, without custom parsing the JSON string (which does maintain the proper key order as an ordered list of sorts).

    My questions are:

    1. Is there an easier method to send the current tree state back via JSON string rather than recursive looping over node.childNodes? (I've looked thru the API guide and can not find anything - but it seems almost impossible that it doesn't exist somewhere I can simply "dump" the current data to the JSON encoder before sending it back to my handler...)

    2. Barring that, can anyone hold my hand a little and help me with the "simplifyNodes()" function so it returns a JSON string that includes required arrays - to keep the nodes in the proper order when decoded by CFMX jsonDecode()... I'm new to JSON, and unsure of the formatting required. (And I'm too lazy to go learn it right now...)

    What I am guessing is that if the JSON is created correctly, it will jsonDecode() into a complex object of nested structures with arrays... I can work with that...

    Thanks in advance,

    Mike

  2. #2
    Ext User
    Join Date
    Mar 2007
    Posts
    2
    Vote Rating
    0
    MBragg is on a distinguished road

      0  

    Default I should have noted...

    I should have noted...


    I'll be away for a few days - but I wanted to post before I lost my train of thought - I will be back next Tuesday to continue conversating with whoever is kind enough to reply to my request!

    Thank you,

    Mike

  3. #3
    Ext User
    Join Date
    Mar 2007
    Posts
    14
    Vote Rating
    0
    wiredmonkey is on a distinguished road

      0  

    Default Help: Sending Ext.tree data back to server (ColdFusion)

    Help: Sending Ext.tree data back to server (ColdFusion)


    Hi there

    i m looking to build something similar that u mentioned in ur post, also with coldfusion. did you have any joy? I m having problems getting my tree to display.

    any help or advice appreciated!

    Shaun

Similar Threads

  1. EditorGrid + Store and how to send back modified data
    By alfiewong in forum Ext 2.x: Help & Discussion
    Replies: 11
    Last Post: 20 May 2010, 10:03 AM
  2. JSON data in coldfusion
    By dangerzone in forum Ext 1.x: Help & Discussion
    Replies: 9
    Last Post: 23 Nov 2007, 3:08 PM
  3. Error sending xml from grid to Server?
    By franklt69 in forum Ext 1.x: Help & Discussion
    Replies: 0
    Last Post: 21 Feb 2007, 1:37 PM
  4. Sending multiple tree node values to server.
    By rahulmca1@gmail.com in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 10 Jan 2007, 12:22 AM
  5. onCellUpdated and sending updates back to the server
    By judah in forum Ext 1.x: Help & Discussion
    Replies: 3
    Last Post: 4 Oct 2006, 11:52 PM

Thread Participants: 1