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

Improved version with global variables and a clear separation between...

Improved version with global variables and a clear separation between librairies and application scripts.
parent 80664a03
No related branches found
No related tags found
No related merge requests found
""" $Id$ """
import os
def index():
"""Controller returning a form/vieweddit widget.
The two keywords ui and table are used to steer the response.
The keyword ui is either form or viewedit.
The keyword table is a name of a database table.
"""Controller loading javascript librairies and launching the application.
"""
# protection
if ('ui' not in request.vars) or ('table' not in request.vars):
raise HTTP(400, "BAD REQUEST")
ui = request.vars.ui
table = request.vars.table
if ui not in ['form', 'viewedit']:
raise HTTP(400, "BAD REQUEST")
if table not in db.tables:
raise HTTP(400, "BAD REQUEST")
# application path
base = os.path.join(os.path.sep, request.application)
......@@ -39,13 +22,12 @@ def index():
os.path.join(base, 'static', 'dbjs', 'combobox.js'),
os.path.join(base, 'static', 'dbjs', 'entryform.js'),
os.path.join(base, 'static', 'dbjs', 'vieweditgrid.js')]
# javascript to render the request page
script = "%s%s.js" % (ui, table)
jslibs.append(os.path.join(base, 'static', 'appjs', script))
# page view and title
response.title = "%s %s" % (ui, table)
# application librairies
applibs = [os.path.join(base, 'static', 'appjs', 'core.js'),
os.path.join(base, 'static', 'appjs', 'main.js')]
# page view
response.view = "app.html"
return dict(clibs=csslibs, jlibs=jslibs)
\ No newline at end of file
return dict(clibs=csslibs, jlibs=jslibs, alibs= applibs)
\ No newline at end of file
......@@ -8,20 +8,27 @@
<meta name="description" content="{{=response.description}}" />
<title>{{=response.title or URL(r=request)}}</title>
<!-- Load css class -->
<!-- css class -->
{{for el in clibs:}}
<link rel="stylesheet" type="text/css" href="{{=el}}"/>{{pass}}
<!-- define global variable for javascripts -->
<script type="text/javascript">
AppName = '{{=request.application}}';
</script>
</head>
<body>
<!-- the loading indicator -->
<!-- load javascript librairies -->
<!-- javascript librairies -->
{{for el in jlibs:}}
<script type="text/javascript" src="{{=el}}"></script>{{pass}}
<!-- Namespace and global variables for the application -->
<script type="text/javascript">
Ext.namespace('App');
App.name = '{{=request.application}}';
</script>
<!-- application scripts -->
{{for el in alibs:}}
<script type="text/javascript" src="{{=el}}"></script>{{pass}}
</body>
</html>
......
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