Skip to content
Snippets Groups Projects
Commit 2fb01893 authored by Renaud Le Gac's avatar Renaud Le Gac
Browse files

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.
parent d43ab662
No related branches found
No related tags found
No related merge requests found
...@@ -16,5 +16,5 @@ from helper import (get_js_files, ...@@ -16,5 +16,5 @@ from helper import (get_js_files,
get_script_path) get_script_path)
from mapper import map_default, map_tabpanel from mapper import map_default, map_tabpanel
from modifier import Spacer, Widget from modifier import Spacer, Widget
from navtree import NodeDB from navtree import NodeDB, NodeURL
from viewportmodifier import ViewportModifier from viewportmodifier import ViewportModifier
\ No newline at end of file
...@@ -69,7 +69,7 @@ class NodeDB(NodeBase): ...@@ -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 T = current.T
...@@ -94,5 +94,47 @@ class NodeDB(NodeBase): ...@@ -94,5 +94,47 @@ class NodeDB(NodeBase):
if table in widgets: if table in widgets:
wdg = widgets[table] wdg = widgets[table]
self.add_children(text=tr_table, widget=wdg, tableName=table) self.add_children(refName=table, text=tr_table, widget=wdg)
\ No newline at end of file
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
...@@ -99,7 +99,7 @@ App.Viewport = Ext.extend(Ext.Viewport, { ...@@ -99,7 +99,7 @@ App.Viewport = Ext.extend(Ext.Viewport, {
var parent = node.parentNode, var parent = node.parentNode,
panel, panel,
tabId, tabId,
tableName = node.attributes.tableName, refName = node.attributes.refName,
viewport = this, viewport = this,
wdg, wdg,
xtype = node.attributes.widget; xtype = node.attributes.widget;
...@@ -116,7 +116,7 @@ App.Viewport = Ext.extend(Ext.Viewport, { ...@@ -116,7 +116,7 @@ App.Viewport = Ext.extend(Ext.Viewport, {
} }
// generate a unique tab identifier // generate a unique tab identifier
tabId = tableName + '/' + xtype; tabId = refName + '/' + xtype;
// activate an existing tab // activate an existing tab
if (this.tabPanel.getComponent(tabId)) { if (this.tabPanel.getComponent(tabId)) {
...@@ -135,6 +135,6 @@ App.Viewport = Ext.extend(Ext.Viewport, { ...@@ -135,6 +135,6 @@ App.Viewport = Ext.extend(Ext.Viewport, {
this.tabPanel.setActiveTab(tabId); this.tabPanel.setActiveTab(tabId);
// add the widget in the newly created tab // add the widget in the newly created tab
Dbui.getConfiguration(tableName, xtype, addWidget); Dbui.getConfiguration(refName, xtype, addWidget);
} }
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment