From 2fb018933748210a3dda6380cb63d8d9afe739f5 Mon Sep 17 00:00:00 2001
From: Renaud Le Gac <renaud.legac@free.fr>
Date: Sun, 4 Dec 2011 17:21:52 +0100
Subject: [PATCH] Polish navigation tree

- Add the class NodeURL
- Add the keyword refName for all node. To be used by the server side as
a table or a node identifier.
---
 modules/plugin_dbui/__init__.py       |  2 +-
 modules/plugin_dbui/navtree.py        | 48 +++++++++++++++++++++++++--
 static/plugin_dbui/src/appviewport.js |  6 ++--
 3 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/modules/plugin_dbui/__init__.py b/modules/plugin_dbui/__init__.py
index 90429d40..51090280 100755
--- a/modules/plugin_dbui/__init__.py
+++ b/modules/plugin_dbui/__init__.py
@@ -16,5 +16,5 @@ from helper import (get_js_files,
                     get_script_path)
 from mapper import map_default, map_tabpanel
 from modifier import Spacer, Widget
-from navtree import NodeDB
+from navtree import NodeDB, NodeURL
 from viewportmodifier import ViewportModifier
\ No newline at end of file
diff --git a/modules/plugin_dbui/navtree.py b/modules/plugin_dbui/navtree.py
index bbdc2e37..010ec811 100644
--- a/modules/plugin_dbui/navtree.py
+++ b/modules/plugin_dbui/navtree.py
@@ -69,7 +69,7 @@ class NodeDB(NodeBase):
     
     """
     
-    def __init__(self, text, tables=[], widget='', hidden=[], widgets=[]):
+    def __init__(self, text, tables=[], widget='', hidden=[], widgets={}):
 
         T = current.T
         
@@ -94,5 +94,47 @@ class NodeDB(NodeBase):
             if table in widgets:
                 wdg = widgets[table]
             
-            self.add_children(text=tr_table, widget=wdg, tableName=table)
-                
\ No newline at end of file
+            self.add_children(refName=table, text=tr_table, widget=wdg)
+
+
+class NodeURL(NodeBase):
+    """Navigation node where each leaf is associated to an url.
+
+    ExtJS widget can be associated to each leaf either globally
+    or individually using widget and widgets arguments respectively.
+    The widget identifier is its ExtJS type: xform, xgrid, ...
+    
+    Some leaf my be hidden depending on the context using hidden
+    argument.
+    
+    Leaves are sorted by alphabetic order.
+    Name of the leaf appearing in the tree are translated.
+    
+    """
+    def __init__(self, text, leaves=[], url=[], widget='', hidden=[], widgets={}):
+
+        T = current.T
+        
+        NodeBase.__init__(self, text)
+        
+        # order leaf in alphabetic order according to local setting
+        # the local setting is defined in the model as the time as the language
+        leavesCvt = {}
+        for el in leaves:
+            leavesCvt[T(el)] = leaves.index(el)
+                  
+        translate_leaves = leavesCvt.keys()
+        translate_leaves.sort(cmp=locale.strcoll)            
+        
+        # fill the node with its children        
+        for tr_leaf in translate_leaves:
+            i = leavesCvt[tr_leaf]
+            leaf = leaves[i]        
+            if leaf in hidden:
+                continue
+            
+            wdg = widget
+            if leaf in widgets:
+                wdg = widgets[leaf]
+            
+            self.add_children(refName=leaf, text=tr_leaf, url=url[i], widget=wdg)
\ No newline at end of file
diff --git a/static/plugin_dbui/src/appviewport.js b/static/plugin_dbui/src/appviewport.js
index 6d856dac..7cc76832 100644
--- a/static/plugin_dbui/src/appviewport.js
+++ b/static/plugin_dbui/src/appviewport.js
@@ -99,7 +99,7 @@ App.Viewport = Ext.extend(Ext.Viewport, {
         var parent = node.parentNode,
             panel,
             tabId,
-            tableName = node.attributes.tableName,
+            refName = node.attributes.refName,
             viewport = this,
             wdg,
             xtype = node.attributes.widget;
@@ -116,7 +116,7 @@ App.Viewport = Ext.extend(Ext.Viewport, {
         }   
         
         // generate a unique tab identifier
-        tabId = tableName + '/' + xtype;
+        tabId = refName + '/' + xtype;
         
         // activate an existing tab
         if (this.tabPanel.getComponent(tabId)) {
@@ -135,6 +135,6 @@ App.Viewport = Ext.extend(Ext.Viewport, {
         this.tabPanel.setActiveTab(tabId);
         
         // add the widget in the newly created tab
-        Dbui.getConfiguration(tableName, xtype, addWidget);
+        Dbui.getConfiguration(refName, xtype, addWidget);
     }
 });
-- 
GitLab