fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [11239] more on ajax-menu


From: Sigurd Nes
Subject: [Fmsystem-commits] [11239] more on ajax-menu
Date: Mon, 29 Jul 2013 06:52:44 +0000

Revision: 11239
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11239
Author:   sigurdne
Date:     2013-07-29 06:52:43 +0000 (Mon, 29 Jul 2013)
Log Message:
-----------
more on ajax-menu

Modified Paths:
--------------
    trunk/property/js/yahoo/test.menu.js
    trunk/property/test_menu.php

Modified: trunk/property/js/yahoo/test.menu.js
===================================================================
--- trunk/property/js/yahoo/test.menu.js        2013-07-29 06:51:42 UTC (rev 
11238)
+++ trunk/property/js/yahoo/test.menu.js        2013-07-29 06:52:43 UTC (rev 
11239)
@@ -1,4 +1,56 @@
 
+//test_
+
+var items = [
+    {"Id": "1", "Name": "abc", "Parent": "2"},
+    {"Id": "2", "Name": "abc", "Parent": ""},
+    {"Id": "3", "Name": "abc", "Parent": "5"},
+    {"Id": "4", "Name": "abc", "Parent": "2"},
+    {"Id": "5", "Name": "abc", "Parent": ""},
+    {"Id": "6", "Name": "abc", "Parent": "2"},
+    {"Id": "7", "Name": "abc", "Parent": "6"},
+    {"Id": "8", "Name": "abc", "Parent": "6"}
+];
+
+function buildHierarchy(arry) {
+
+    var roots = [], children = {};
+
+    // find the top level nodes and hash the children based on parent
+    for (var i = 0, len = arry.length; i < len; ++i) {
+        var item = arry[i],
+            p = item.Parent,
+            target = !p ? roots : (children[p] || (children[p] = []));
+
+        target.push({ value: item });
+    }
+
+    // function to recursively build the tree
+    var findChildren = function(parent) {
+        if (children[parent.value.Id]) {
+            parent.children = children[parent.value.Id];
+            for (var i = 0, len = parent.children.length; i < len; ++i) {
+                findChildren(parent.children[i]);
+            }
+        }
+    };
+
+    // enumerate through to handle the case where there are multiple roots
+    for (var i = 0, len = roots.length; i < len; ++i) {
+        findChildren(roots[i]);
+    }
+
+    return roots;
+}
+
+
+var test = buildHierarchy(items);
+//console.log(buildHierarchy(items));​
+
+// test
+
+
+
 function get_html (sUrl)
 {
        document.getElementById('html_content').src = sUrl;
@@ -22,10 +74,8 @@
 //an anonymous function wraps our code to keep our variables
 //in function scope rather than in the global namespace:
 (function() {
-       var tree;
+//     var tree;
 
-
-
        function loadNodeData(node, fnLoadComplete)  {
                //We'll load node data based on what we get back when we
                //use Connection Manager topass the text label of the
@@ -38,7 +88,8 @@
                //Get the node's label and urlencode it; this is the word/s
                //on which we'll search for related words:
                //var nodeLabelElId = encodeURI(node.labelElId);
-          
+//console.log(mapping);
+
                var mapping_str = node.labelElId
                mapping_id = mapping_str.replace('ygtvlabelel','');
                var app = mapping[mapping_id];
@@ -79,6 +130,18 @@
                                                        mapping_id = 
mapping_str.replace('ygtvlabelel','');
                                                        mapping[mapping_id] = 
app + '|' + key;
 
+
+                                                       //----------
+                                                       var parent_mapping_str 
= node.labelElId
+                                                       parent_mapping_id = 
parent_mapping_str.replace('ygtvlabelel','');
+
+                                                       myobj['parent'] = 
parent_mapping_id;
+                                                       myobj['id'] = 
mapping_id;
+                                                       myobj['isLeaf'] = 
is_leaf;
+                                                       proxy_data[mapping_id] 
=  myobj;
+                                                       
proxy_data[parent_mapping_id]['expanded'] = true;
+                                                       //----------
+
                                                        // we can tell the tree 
node that this is a leaf node so
                                                        // that it doesn't try 
to dynamically load children.
 
@@ -125,9 +188,65 @@
                //make our XHR call using Connection Manager's
                //asyncRequest method:
                YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
+
+               var json_proxy_data = JSON.stringify(proxy_data);
+
+//             alert(json_proxy_data);
+
+               sessionStorage.menu_tree_data = json_proxy_data;
+//             alert(YAHOO.util.Cookie.get("menu_tree_data"));
+
+
+//             var menu_tree_data = tree.getNodesBy(function(o){return true;});
+//             var menu_tree_data = tree.getTreeDefinition();
+//console.log(menu_tree_data);
+//alert(JSON.stringify(menu_tree_data));
+//             YAHOO.util.Cookie.set("menu_tree_data", 
tree.getNodesBy(function(o){return true;}));
+//console.log(tree.getNodesBy(function(o){return true;}));
+
+
+//             alert(tree_struct_x());
+
        }
 
        function init() {
+
+               var menu_tree_data;
+               var menu_arranged_data = {};
+
+               if(typeof(Storage)!=="undefined")
+               {
+//                     alert('Yes! localStorage and sessionStorage support!');
+                       menu_tree_data = sessionStorage.menu_tree_data;
+               }
+               else
+               {
+                       alert('Sorry! No web storage support..');
+               }
+               
+               if(menu_tree_data !=null)
+               {
+                       alert(menu_tree_data);
+                       menu_tree_data = JSON.parse(menu_tree_data);
+                       var k = 0;
+                       for (var i=0, j=menu_tree_data.length; i<j; i++)
+                       {
+                               if(menu_tree_data[i]['parent'] == 0)
+                               {
+                                       menu_arranged_data[k] = 
menu_tree_data[i];
+                                       k++;
+                               }
+                               else
+                               {
+                               
+                               }
+                       }
+
+
+               }
+
+//             console.log(menu_tree_data);
+
           //create a new tree:
           tree = new YAHOO.widget.TreeView("treeDiv1");
 
@@ -139,18 +258,44 @@
 
           //add child nodes for tree; our top level nodes are apps - defined 
in html
 
-          for (var i=0, j=apps.length; i<j; i++) {
-       //              var myobj = { label: apps[i]['text'], 
href:apps[i]['href']}//,target:"_self" };
+          var id = 0;
+          for (var i=0, j=apps.length; i<j; i++)
+          {
                        var myobj = { label: apps[i]['text'], 
href:'javascript:get_html("' + apps[i]['href'] + '");'}//,target:"_self" };
+                       var tempNode = new YAHOO.widget.TextNode(myobj, root, 
false);
+                       
+                       id = i + 1;
+                       myobj['parent'] = 0;
+                       myobj['id'] = id;
+                       proxy_data[id] =  myobj;
+                       proxy_data[id]['expanded'] = false;
 
-                               var tempNode = new YAHOO.widget.TextNode(myobj, 
root, false);
+                       if(typeof(apps[i]['children']) != 'undefined' && 
apps[i]['children'].length)
+                       {
+                               buildBranch(tmpNode, apps[i]['children']);
+                       }
           }
 
           //render tree with these toplevel nodes; all descendants of these 
nodes
           //will be generated as needed by the dynamic loader.
+
           tree.draw();
        }
 
+
+       function buildBranch(node, branch)
+       {
+               for (var i = 0; i < branch.length; i++)
+               {
+                       var tmpNode = new 
YAHOO.widget.TextNode({label:branch[i]['text'], href:branch[i]['link']}, node, 
false);
+                       if(branch[i]['children'])
+                       {
+                               buildBranch(tmpNode, branch[i]['children']);
+                       }
+               }
+       }
+       
+
        //once the DOM has loaded, we can go ahead and set up our tree:
        YAHOO.util.Event.onDOMReady(init);
 

Modified: trunk/property/test_menu.php
===================================================================
--- trunk/property/test_menu.php        2013-07-29 06:51:42 UTC (rev 11238)
+++ trunk/property/test_menu.php        2013-07-29 06:52:43 UTC (rev 11239)
@@ -20,10 +20,12 @@
        phpgw::import_class('phpgwapi.yui');
        
$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/examples/treeview/assets/css/folders/tree.css');
        phpgwapi_yui::load_widget('treeview');
+       phpgwapi_yui::load_widget('cookie');
        $GLOBALS['phpgw']->js->validate_file( 'yahoo', 'test.menu', 'property' 
);
 
                $currentapp = $GLOBALS['phpgw_info']['flags']['currentapp'];
                $applications = array();
+               $mapping = array();
                $exclude = array('home', 'preferences', 'about', 'logout');
                $navbar = execMethod('phpgwapi.menu.get', 'navbar');
 
@@ -58,6 +60,7 @@
                <script type="text/javascript">
                   var apps = {$applications};
                   var mapping = {$mapping};
+                  var proxy_data = {};
                </script>
 HTML;
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]