Skip to content
Snippets Groups Projects
Commit aa0d28ce authored by legac's avatar legac
Browse files

The viewport can open a tab at startup.

parent 34284995
No related branches found
No related tags found
No related merge requests found
......@@ -49,3 +49,5 @@ viewportModifier = dbui.ViewportModifier()
viewportModifier.append_plugins('pViewportLogin')
viewportModifier.configure(logged=True)
viewportModifier.add_node(helpNode, formNode, gridNode, reportNode)
viewportModifier.default_node(T('Tables'), T('publications'))
......@@ -759,6 +759,9 @@ def to_viewport(**kwargs):
if modifier_viewports:
cfg = modifier_viewports.extjs
if modifier_viewports.default:
cfg['defaultTabPath'] = modifier_viewports.default
# configuration options from the keyword arguments
cfg.update(kwargs)
......
......@@ -32,12 +32,18 @@ class ViewportModifier(Modifier):
The keys of the C{data} structure are:
- C{default} (list) list of C{Node.text} defining the path of the node
which will be opened at start up.
- C{extjs} (dict) Ext JS configuration options for the viewport widget.
- C{nodes} (list) list of L{Node} defining the navigation tree
"""
Modifier.__init__(self, MODIFIER_VIEWPORTS)
if 'default' not in self.data:
self.data.default = None
if 'nodes' not in self.data:
self.data.nodes = []
......@@ -57,4 +63,14 @@ class ViewportModifier(Modifier):
self.data.nodes.extend(args)
def default_node(self, *args):
"""Defined the node which will be opened at start up.
@type args: list of L{Node.text}
@param args: define the path of the node
"""
self.data.default = args
class ViewportModifierException(BaseException): pass
--------------------------------- CHANGE LOG ----------------------------------
HEAD
- The viewport can open a tab at startup.
0.4.13.2 (Jul 2013)
- Table callback _before_delete, _before_insert and _before_update
......
/**
* The Viewport for the application.
* The ViewPort for the application.
*
* The type of this component is xviewport.
*
......@@ -11,13 +11,20 @@ Ext.namespace('App');
App.Viewport = Ext.extend(Ext.Viewport, {
/**
* @cfg {array} defaultTabPath
* list of node.text attribute defining the path of the node
* to be opened at start up
*/
defaultTabPath: null,
/**
* @cfg {boolean} logged true when the user pass the login procedure
*/
logged: false,
/**
* private shortcuts
* private short cuts
*/
tabPanel: null,
treePanel: null,
......@@ -91,20 +98,44 @@ App.Viewport = Ext.extend(Ext.Viewport, {
// apply the user configuration if any
Ext.apply(this, cfg);
// instanciate the viewport
// instantiate the ViewPort
App.Viewport.superclass.constructor.call(this);
// define shortcuts
// define short cuts
this.tabPanel = this.getComponent('tabPanel');
this.treePanel = this.getComponent('treePanel');
// Add handler to create tab and their widget
this.treePanel.on('click', this.onCreateTab, this);
// disable contextmenu in the treepanel
// disable ContextMenu in the TreePanel
this.treePanel.on('contextmenu', function (node, event) {
event.stopEvent();
});
// open the default Tab
loader.on('load', this.onTreeLoaderLoaded, this);
/*
loader.on('load', function (treeLoader, node, response) {
var myLeaf,
myNode;
console.log('tree loader loaded');
console.log('node', node);
myNode = node.findChild('text', 'Tables');
myNode.expand();
myLeaf = myNode.findChild('text', 'publications');
console.log(myLeaf);
//myLeaf.select();
this.onCreateTab(myLeaf);
myNode.collapse();
}, this); */
},
/**
......@@ -127,13 +158,12 @@ App.Viewport = Ext.extend(Ext.Viewport, {
* @param {Object} node
* @param {Object} event
*/
onCreateTab: function(node, event) {
onCreateTab: function (node, event) {
"use strict";
var cfg,
parent = node.parentNode,
panel,
tabId,
wdgcfg = node.attributes.cfg,
wdgtype = node.attributes.cfg.xtype;
......@@ -171,8 +201,57 @@ App.Viewport = Ext.extend(Ext.Viewport, {
}
// create a new tab and activate it
panel = this.tabPanel.add(cfg);
this.tabPanel.add(cfg);
this.tabPanel.setActiveTab(tabId);
},
/**
* Handler to Activate the default tab when the tree is loaded
* Expand all the nodes, create the Tab for the leaf, collapse node.
* The scope is the ViewPort.
*
* @param {Ext.tree.TreeLoader} treeLoader
* @param {Ext.tree.TreeNode} rootNode
* @param {Object} response
*/
onTreeLoaderLoaded: function (treeLoader, rootNode, response) {
"use strict";
var i,
leaf,
node,
nodes = [],
path = this.defaultTabPath;
if (!path) {
return;
}
// expand all intermediate nodes
node = rootNode;
for (i = 0; i < path.length; i += 1) {
node = node.findChild('text', path[i]);
if (node.isLeaf()) {
leaf = node;
break;
}
node.expand();
nodes.push(node);
}
// create the tab for the leaf
if (leaf) {
this.onCreateTab(leaf);
}
// collapse all intermediate nodes
for (i = 0; i < nodes.length; i += 1) {
nodes[i].collapse();
}
}
});
......
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