fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [11235] test ajax menu


From: Sigurd Nes
Subject: [Fmsystem-commits] [11235] test ajax menu
Date: Thu, 04 Jul 2013 14:09:17 +0000

Revision: 11235
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11235
Author:   sigurdne
Date:     2013-07-04 14:09:16 +0000 (Thu, 04 Jul 2013)
Log Message:
-----------
test ajax menu

Modified Paths:
--------------
    trunk/phpgwapi/inc/class.menu.inc.php

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

Modified: trunk/phpgwapi/inc/class.menu.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.menu.inc.php       2013-07-03 09:39:08 UTC (rev 
11234)
+++ trunk/phpgwapi/inc/class.menu.inc.php       2013-07-04 14:09:16 UTC (rev 
11235)
@@ -33,6 +33,11 @@
         */
        class phpgwapi_menu
        {
+               var $public_functions = array
+               (
+                       'get_local_menu_ajax' => true
+               );
+               
                /**
                * Clear the user's menu so it can be regenerated cleanly
                *
@@ -364,6 +369,35 @@
                        return $menu;
                }
 
+               public function get_local_menu_ajax()
+               {
+                       $node           = phpgw::get_var('node');
+
+                       $selection = explode('::',$node);
+
+                       $app = $selection[0];
+
+                       if(!isset($GLOBALS['phpgw_info']['user']['apps'][$app]))
+                       {
+                               return array();
+                       }
+
+//                     if(!$menu = phpgwapi_cache::session_get('phpgwapi', 
"menu_{$node}"))
+                       {
+                               $menu_gross = 
execMethod("{$app}.menu.get_menu");
+                               $selection = 
explode('::',$GLOBALS['phpgw_info']['flags']['menu_selection']);
+                               $level=0;
+                               $menu = 
self::_get_sub_menu($menu_gross['navigation'],$selection,$level);
+                               phpgwapi_cache::session_set('phpgwapi', 
"menu_{$node}",$menu);
+                               unset($menu_gross);
+                       }
+
+_debug_array($menu);
+                       return $menu;
+               }
+
+
+
                protected static function _get_sub_menu($children = array(), 
$selection=array(),$level=0)
                {
                        $level++;
@@ -378,7 +412,7 @@
                                        $menu[$i]['this'] = true;
                                        if(isset($menu[$i]['children']))
                                        {
-                                               $menu[$i]['children'] = 
self::_get_sub_menu($menu[$i]['children'],$selection,$level);
+                                               $menu[$i]['children'] = 
self::_get_sub_menu_($menu[$i]['children'],$selection,$level);
                                        }
                                }
                                else

Added: trunk/property/js/yahoo/test.menu.js
===================================================================
--- trunk/property/js/yahoo/test.menu.js                                (rev 0)
+++ trunk/property/js/yahoo/test.menu.js        2013-07-04 14:09:16 UTC (rev 
11235)
@@ -0,0 +1,126 @@
+//an anonymous function wraps our code to keep our variables
+//in function scope rather than in the global namespace:
+(function() {
+    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
+        //expanding node to the Yahoo!
+        //Music track search API.  Here, we're at the
+        //first part of the request -- we'll make the request to the
+        //server.  In our success handler, we'll build our new children
+        //and then return fnLoadComplete back to the tree.
+
+        //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);
+       
+        var mapping_str = node.labelElId
+        mapping_id = mapping_str.replace('ygtvlabelel','');
+        var app = mapping[mapping_id];
+
+        //prepare URL for XHR request:
+               var oArgs = 
{menuaction:'phpgwapi.menu.get_local_menu_ajax',node:app};
+               var sUrl = phpGWLink('index.php', oArgs, true);
+
+   //     var sUrl = "assets/ysuggest_proxy.php?query=" + nodeLabelElId;
+
+        //prepare our callback object
+        var callback = {
+
+            //if our XHR call is successful, we want to make use
+            //of the returned data and create child nodes.
+            success: function(oResponse) {
+                YAHOO.log("XHR transaction was successful.", "info", 
"example");
+                //YAHOO.log(oResponse.responseText);
+              var oResults = eval("(" + oResponse.responseText + ")");
+            //    var oResults = oResponse.responseText;
+ console.log(oResults);
+                var title, url, titles, tempNode;
+
+                if (YAHOO.lang.isArray(oResults)) {
+
+                    titles = {};
+                    for (var i = 0, len = oResults.length; i < len; i++) {
+                        title = oResults[i].text;
+                        url = oResults[i].url;
+
+                        // prevent duplicate track titles by creating a hash 
of titles
+                        if (!titles[title]) {
+                            titles[title] = true;
+                            tempNode = new YAHOO.widget.TextNode(title, node, 
false);
+
+                            // we can tell the tree node that this is a leaf 
node so
+                            // that it doesn't try to dynamically load 
children.
+                     //       tempNode.isLeaf = true;
+
+                            // Define a href so that a click on the node will 
navigate
+                            // to the page that has the track that you may be 
able
+                            // to listen to.
+                            tempNode.href = url;
+                        }
+                    }
+                }
+
+                //When we're done creating child nodes, we execute the node's
+                //loadComplete callback method which comes in via the argument
+                //in the response object (we could also access it at 
node.loadComplete,
+                //if necessary):
+                oResponse.argument.fnLoadComplete();
+            },
+
+            //if our XHR call is not successful, we want to
+            //fire the TreeView callback and let the Tree
+            //proceed with its business.
+            failure: function(oResponse) {
+                YAHOO.log("Failed to process XHR transaction.", "info", 
"example");
+                oResponse.argument.fnLoadComplete();
+            },
+
+            //our handlers for the XHR response will need the same
+            //argument information we got to loadNodeData, so
+            //we'll pass those along:
+            argument: {
+                "node": node,
+                "fnLoadComplete": fnLoadComplete
+            },
+
+            //timeout -- if more than 7 seconds go by, we'll abort
+            //the transaction and assume there are no children:
+            timeout: 7000
+        };
+
+        //With our callback object ready, it's now time to
+        //make our XHR call using Connection Manager's
+        //asyncRequest method:
+        YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
+    }
+
+    function init() {
+       //create a new tree:
+       tree = new YAHOO.widget.TreeView("treeDiv1");
+
+       //turn dynamic loading on for entire tree:
+       tree.setDynamicLoad(loadNodeData);
+
+       //get root node for tree:
+       var root = tree.getRoot();
+
+       //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'],labelElId:apps[i]['labelElId'], 
href:apps[i]['href']}//,target:"_self" };
+            var tempNode = new YAHOO.widget.TextNode(myobj, root, false);
+       }
+
+       //render tree with these toplevel nodes; all descendants of these nodes
+       //will be generated as needed by the dynamic loader.
+       tree.draw();
+    }
+
+    //once the DOM has loaded, we can go ahead and set up our tree:
+    YAHOO.util.Event.onDOMReady(init);
+
+       
+})();

Added: trunk/property/test_menu.php
===================================================================
--- trunk/property/test_menu.php                                (rev 0)
+++ trunk/property/test_menu.php        2013-07-04 14:09:16 UTC (rev 11235)
@@ -0,0 +1,80 @@
+<?php
+
+       $GLOBALS['phpgw_info'] = array();
+
+       $GLOBALS['phpgw_info']['flags'] = array
+       (
+               'noheader'                => true,
+               'nonavbar'                => false,
+               'currentapp'              => 'home',
+               'enable_network_class'    => true,
+               'enable_contacts_class'   => true,
+               'enable_nextmatchs_class' => true
+       );
+
+
+       include_once('../header.inc.php');
+
+// Start-------------------------------------------------
+
+       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');
+       $GLOBALS['phpgw']->js->validate_file( 'yahoo', 'test.menu', 'property' 
);
+
+               $currentapp = $GLOBALS['phpgw_info']['flags']['currentapp'];
+               $applications = array();
+               $exclude = array('home', 'preferences', 'about', 'logout');
+               $navbar = execMethod('phpgwapi.menu.get', 'navbar');
+
+               $i = 1;
+               foreach ( $navbar as $app => $app_data )
+               {
+                       if ( in_array($app, $exclude) )
+                       {
+                               continue;
+                       }
+                       if ( $app == $currentapp)
+                       {
+                               $app_data['text'] = 
"[<b>{$app_data['text']}</b>]";
+                       }
+
+                       $applications[] = array
+                       (
+                               'text' => $app_data['text'],
+                               'href'  => $app_data['url'],
+                       );
+                       $mapping[$i] = $app;
+                       $i ++;
+               }
+               $applications = json_encode($applications);
+               $mapping = json_encode($mapping);
+
+$html = <<<HTML
+                                                       <div 
id="treeDiv1"></div>
+                                                               <!-- Some style 
for the expand/contract section-->
+                                                               <style>
+                                                                       
#expandcontractdiv {border:1px dotted #dedede; margin:0 0 .5em 0; 
padding:0.4em;}
+                                                                       
#treeDiv1 { background: #fff; padding:1em; margin-top:1em; }
+                                                               </style>
+                                                               <script 
type="text/javascript">
+                                                                  var apps = 
{$applications};
+                                                                  var mapping 
= {$mapping};
+                                                               </script>
+                                                               <div 
id="treeDiv1"/>
+
+HTML;
+
+
+
+// End--------------------------------------------------
+
+       $GLOBALS['phpgw']->common->phpgw_header();
+       echo parse_navbar();
+
+       echo $html;
+
+
+       $GLOBALS['phpgw']->common->phpgw_footer();
+
+




reply via email to

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