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 import os
def index(): def index():
"""Controller returning a form/vieweddit widget. """Controller loading javascript librairies and launching the application.
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.
""" """
# 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 # application path
base = os.path.join(os.path.sep, request.application) base = os.path.join(os.path.sep, request.application)
...@@ -39,13 +22,12 @@ def index(): ...@@ -39,13 +22,12 @@ def index():
os.path.join(base, 'static', 'dbjs', 'combobox.js'), os.path.join(base, 'static', 'dbjs', 'combobox.js'),
os.path.join(base, 'static', 'dbjs', 'entryform.js'), os.path.join(base, 'static', 'dbjs', 'entryform.js'),
os.path.join(base, 'static', 'dbjs', 'vieweditgrid.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 # application librairies
response.title = "%s %s" % (ui, table) applibs = [os.path.join(base, 'static', 'appjs', 'core.js'),
os.path.join(base, 'static', 'appjs', 'main.js')]
# page view
response.view = "app.html" response.view = "app.html"
return dict(clibs=csslibs, jlibs=jslibs) return dict(clibs=csslibs, jlibs=jslibs, alibs= applibs)
\ No newline at end of file \ No newline at end of file
...@@ -8,20 +8,27 @@ ...@@ -8,20 +8,27 @@
<meta name="description" content="{{=response.description}}" /> <meta name="description" content="{{=response.description}}" />
<title>{{=response.title or URL(r=request)}}</title> <title>{{=response.title or URL(r=request)}}</title>
<!-- Load css class --> <!-- css class -->
{{for el in clibs:}} {{for el in clibs:}}
<link rel="stylesheet" type="text/css" href="{{=el}}"/>{{pass}} <link rel="stylesheet" type="text/css" href="{{=el}}"/>{{pass}}
<!-- define global variable for javascripts -->
<script type="text/javascript">
AppName = '{{=request.application}}';
</script>
</head> </head>
<body> <body>
<!-- the loading indicator --> <!-- the loading indicator -->
<!-- load javascript librairies --> <!-- javascript librairies -->
{{for el in jlibs:}} {{for el in jlibs:}}
<script type="text/javascript" src="{{=el}}"></script>{{pass}} <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> </body>
</html> </html>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment