From 16d710c4da2eb4f2c34c37a20d817b92a117765d Mon Sep 17 00:00:00 2001 From: Renaud Le Gac <renaud.legac@free.fr> Date: Sun, 3 May 2009 19:43:32 +0000 Subject: [PATCH] Improved version with global variables and a clear separation between librairies and application scripts. --- controllers/app.py | 34 ++++++++-------------------------- views/app.html | 21 ++++++++++++++------- 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/controllers/app.py b/controllers/app.py index da20a908..bb3b2283 100644 --- a/controllers/app.py +++ b/controllers/app.py @@ -1,28 +1,11 @@ - +""" $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 diff --git a/views/app.html b/views/app.html index dc8d6473..680a3326 100644 --- a/views/app.html +++ b/views/app.html @@ -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> -- GitLab