Commit 90224604 authored by tux091's avatar tux091
Browse files

redesign to_panelWithUrlSelector, add to_panel and to_fieldset, simplify the report section.

parent e8e0fde1
......@@ -13,30 +13,7 @@ def report_1():
"""First trial
"""
# Resolve foreign key
query = db.publications.id_collaborations == db.collaborations.id
query = (query) & (db.publications.id_publishers == db.publishers.id)
query = (query) & (db.publications.id_categories == db.categories.id)
# publication with comite de lecture
query = (query) & (db.publications.conference_title == '')
query = (query) & ((db.categories.code == 'ACL') | (db.categories.code == 'ACLN'))
# Interrogate the database
rows = db(query).select(db.publications.title,
db.publications.authors,
db.publications.id_collaborations,
db.collaborations.collaboration,
db.publishers.abbreviation,
db.publications.year,
db.publications.doi,
db.publications.volume,
db.publications.first_page,
db.publications.last_page,
db.publications.conference_title,
db.categories.code)
return {'title': 'Rapport 1', 'publis': rows}
return "report_1"
def report_2():
......@@ -45,6 +22,7 @@ def report_2():
"""
s = ""
print request.post_vars
for k in request.post_vars:
s += "<br>%s: %s" % (k, request.post_vars[k])
......
......@@ -40,6 +40,7 @@
'Report Numbers': 'Numéro du rapport',
'Report type': 'Type du rapport',
'Reports': 'Rapports',
'Select': 'Selectionner',
'Speaker': 'Orateur',
'Start date': 'Date de début',
'Table': 'Table',
......@@ -63,6 +64,7 @@
'report_1': 'report_1',
'report_2': 'report_2',
'reports': 'rapports',
'select': 'select',
'select publication for a given year': 'selectionne les publication pour une année',
'select publications for a given CPPM author': 'selectionne les publications pour un auteur du CPPM',
'select publications for a given project': 'selectionne les publications pour un projet',
......
......@@ -192,13 +192,17 @@ configurator = lambda tablename: cvtSvc.to_grid_panel(db[tablename])
gridNode.add_children(db.tables, func=configurator)
reportNode = dbui.Node(T('Reports'))
cfg = dbui.to_urlPanel(URL(c="reports", f="report_1"))
reportNode.add_child(T('report_1'), cfg)
form_items = cvtSvc.to_form_items(dummy.foo1)
cfg = dbui.to_panelWithUrlSelector(form_items,
baseUrl=URL(c="reports", f="report_2"))
reportNode.add_child(T('report_2'), cfg)
node = dbui.to_panel(html='salut ma poule')
reportNode.add_child(T('report_1'), node)
panel = dbui.to_panel()
fields = cvtSvc.to_form_items(dummy.foo1)
selector = dbui.to_fieldset(fields, title=T('Select'))
node = dbui.to_panelWithUrlSelector(panel,
selector,
controller="reports",
function="report_2")
reportNode.add_child(T('report_2'), node)
viewportModifier = dbui.ViewportModifier()
viewportModifier.add_node(formNode, gridNode, reportNode)
......@@ -28,5 +28,9 @@ from helper import (as_list,
rows_serializer)
from mapper import map_default, map_tabpanel
from modifier import Spacer, Widget
from navtree import Node, to_panelWithUrlSelector, to_urlPanel
from navtree import (Node,
to_fieldset,
to_panel,
to_panelWithUrlSelector,
to_urlPanel)
from viewportmodifier import ViewportModifier
\ No newline at end of file
......@@ -3,74 +3,123 @@
"""
import locale
import os
from gluon import current
from helper import is_mathjax
def to_panelWithUrlSelector(formItems,
application=None,
def to_panel(**kwargs):
"""Return the configuration dictionary of an Ext.Panel.
The keyword arguments are the configuration options of
the Ext.Panel widget.
"""
cfg = {'xtype': 'panel'}
cfg.update(kwargs)
return cfg
def to_fieldset(fields, **kwargs):
"""Return the confiuration dictionary of Ext.form.Fieldset.
This widget contains list of Ext.form.Field.
fields is a list of configuration dictioanry for form.Fields.
The keyword arguments are the configuration options of
the Ext.form.FieldSet widget.
"""
cfg = {'defaults': {'anchor': '99%'},
'items': fields,
'xtype': 'fieldset'}
cfg.update(kwargs)
return cfg
def to_panelWithUrlSelector(panelCfg,
selectorCfg,
baseUrl=None,
application=None,
controller=None,
function=None,
ctrlField=None,
extField=None,
title='Configure'):
extField=None,
funcField=None):
"""Return the configuration dictionary for an App.PanelWithUrlSelector.
the main panel displays the URL content while the selector panel shows
a form allowing to change the URL setting.
application and controller
The base URL is: /application/controller.
This widget is split in two part a main panel and a selector.
The selector display a list of fields organized in fieldset.
There values define the URL parameters. The main panel displays
the URL content.
Configuration dictionary for the main panel and fieldset are set via:
panelCfg
selectorCfg
In web2py an URL is defined as application/controller/function.extension
There are several ways to define it.
application
The base URL is: /application
By default the application is the current application.
The argument ctlField and extField allow to extend the base URL to
/application/controller/ctlField.extField
baseUrl
Another way to defined the base URL associated to the panel.
It should be a well-formed URL string, i.e http://blabla
Another way to defined the URL associated to the panel.
It should be a well-formed URL string, i.e http://blabla.
It is a more general approach where the URL can point to a
any links.
controller
The base URL is: /application/controller.
function
The base URL is: /application/controller/function.
The URL can be modified dynamicaly by extracting the name of the
controller, function and/or extension from the selector fields.
ctrlField
Name of the form field defining the name of the controller.
When define the URL become baseUrl/ctrlFieldValue
Name of the field defining the name of the controller.
When define the URL become baseURL/ctrlFieldValue.
extField
the url become baseUrl/ctrField.extField
Useful to play with different view rendering their content in
html, json, xml, ...
formItems
A list of configuration dictionary defining the
widget embedded in the form
title
Title of the box surrounding form widgets
Name of the field defining the name of the extension.
When define the URL become baseUrl.extFieldValue.
Useful to play with different view rendering the same
controller/function.
funcField
Name of the form field defining the name of the function.
When define the URL become baseURL/funcFieldValue.
To be used with ctrlField. In that case the URL is
/application/ctrFieldValue/funcFieldValue.
"""
url = baseUrl
if not url:
if application:
url = '/%s/%s' % (application, controller)
url = os.path.join('/', application)
else:
url = '/%s/%s' % (current.request.application, controller)
url = os.path.join('/', current.request.application)
if controller:
url = os.path.join(url, controller)
if function:
url = os.path.join(url, function)
cfg = {'baseUrl': url,
'ctrlField': ctrlField,
'extField': extField,
'funcField': funcField,
'isMathJax': is_mathjax(),
'panelCfg': None,
'selectorCfg':None,
'panelCfg': panelCfg,
'selectorCfg': selectorCfg,
'xtype': 'xpanelwithurlselector'}
# configuration of the child panel displaying URL
cfg['panelCfg'] = {'plugins': [],
'xtype': 'panel'}
# configuration of the selector
cfg['selectorCfg'] = {'defaults': {'anchor': '99%'},
'items': formItems,
'title': title,
'xtype': 'fieldset'}
return cfg
......@@ -82,13 +131,11 @@ def to_urlPanel(url):
well-formed URL string, i.e http://blabla
"""
cfg = {'autoLoad': url,
'plugins': [],
'preventBodyReset': True,
'xtype': 'panel'}
cfg = to_panel(autoload=url,
preventBodyReset=True)
if is_mathjax:
cfg['plugins'].append('pPanelMathJax')
if is_mathjax():
cfg['plugins'] = ['pPanelMathJax']
return cfg
......
/**
* A panel displaying an url content with a collpasible selector.
* The selector allows to setup the url parameters and to launch the
* request to the server.
* This widget is split in two part a main panel and a selector.
* The selector display a list of fields organized in fieldset.
* There values define the URL parameters. The main panel displays
* the URL content.
*
* The url is build as baseUrl or baseUrl/CtrlFieldValue if ctrlField
* is defined. The value of the other fields are pass as Field1=Field1Value,
* Field2=Field2Value via the POST transfert
* Configuration for the main panel and the selelctor are set via
* the option panelCfg and selectorCgf.
*
* The URL display in the main panel is defined by the baseUrl option.
* It can be modified dynamicaly by extracting the name of the
* controller, function and/or extension from the selector fields.
* The options ctrlField, extField and funcField associated field
* used to determine the value.
*
* Mathematical symbols will be interpreted, if the javascript library
* mathjax is load. Use the isMathJax property.
......@@ -27,18 +33,24 @@ App.PanelWithUrlSelector = Ext.extend(App.BasePanelWithSelector, {
/**
* @param {String} ctrFiedl name of the field defining the controller
* When define the url become http://blabla/ctrlFieldValue
* When define the url become baseUrl/ctrlFieldValue
*/
ctrlField: null,
/**
* @param {String} extFiedl name of the field defining the view extension
* When define the url become http://blabla/ctrlFieldValue.extField
* @param {String} extFiedl name of the field defining the extension
* When define the url become baseUrl.extFieldValue
*/
extField: null,
/**
* @param {String} funcFiedl name of the field defining the function
* When define the url become baseUrl/funcFieldValue
*/
funcField: null,
/**
* @param {Boolean} isMathJax
* @param {Boolean} isMathJax True is the mathjax library is installed
*/
isMathJax: false,
......@@ -64,33 +76,37 @@ App.PanelWithUrlSelector = Ext.extend(App.BasePanelWithSelector, {
*/
onGo: function() {
var ctrlFunc=null,
ctrlExt=null,
fields,
var fields,
i,
mainPanel = this.getComponent('mainPanel'),
params = {},
selector = this.getComponent('selectorPanel'),
url = this.baseUrl;
url = this.baseUrl,
urlCtrl = null,
urlFunc = null,
urlExt = null;
// activate the auto scrolling
mainPanel.setAutoScroll(true);
// basic fields
// extract basic parameters
fields = selector.findByType('field');
for (i = 0; i < fields.length; i += 1) {
if(fields[i].getName() === this.ctrlField) {
ctrlFunc = fields[i].getValue();
urlCtrl = fields[i].getValue();
} else if (fields[i].getName() === this.extField) {
ctrlExt = fields[i].getValue();
urlExt = fields[i].getValue();
} else if (fields[i].getName() === this.funcField) {
urlFunc = fields[i].getValue();
} else {
params[fields[i].getName()] = fields[i].getValue();
}
}
// fields embedded in composite fields
// extract parameters embedded in composite fields
fields = this.findByType('compositefield');
for (i = 0; i < fields.length; i += 1) {
fields[i].items.eachKey(function(key, subfield) {
......@@ -98,15 +114,20 @@ App.PanelWithUrlSelector = Ext.extend(App.BasePanelWithSelector, {
});
}
// build the URL when only the ctrlFunc is defined
if (ctrlFunc !== null && ctrlExt === null) {
url = url + '/' + ctrlFunc;
// build the url when both the ctrlFunc and ctrlExt are defined
} else if (ctrlFunc !== null && ctrlExt !== null) {
url = url + '/' + ctrlFunc + '.' + ctrlExt;
// build the URL
if (urlCtrl !== null) {
url = url + '/' + urlCtrl;
}
if (urlFunc !== null) {
url = url + '/' + urlFunc;
}
if (urlExt !== null) {
url = url + '.' + urlExt;
}
// load url in the main panel
mainPanel.load({
callback: this.onLoad,
params: params,
......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>{{=title}}</title>
<!-- mathjax library -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
jax: ["input/TeX", "output/HTML-CSS"],
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true
},
"HTML-CSS": { availableFonts: ["TeX"] }
});
</script>
<script type="text/javascript" src="/{{=request.application}}/static/plugin_mathjax/MathJax.js"></script>
</head>
<body>
<h2>Publications avec comité de lecture</h2>
<ol>
{{for el in publis:}}
<li>
{{=el.publications.title}}<br>
{{=el.publications.authors}}
{{if el.publications.id_collaborations > 1:}}, {{=el.collaborations.collaboration}},{{pass}}<br>
{{if el.publishers.abbreviation:}}{{=el.publishers.abbreviation}}{{pass}}
{{if el.publications.volume:}}{{=el.publications.volume}}{{pass}}
{{if el.publications.year:}}({{=el.publications.year}}){{pass}}
{{if el.publications.first_page:}}{{=el.publications.first_page}}{{pass}}
{{if el.publications.last_page:}}- {{=el.publications.last_page}}{{pass}}
</li>
{{pass}}
</ol>
</body>
</html>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment