From bf142a78d3542046bf7eee2a076388f10cddad45 Mon Sep 17 00:00:00 2001
From: Renaud Le Gac <renaud.legac@free.fr>
Date: Wed, 2 Mar 2011 20:05:02 +0000
Subject: [PATCH] add a new helper function get_js_files.

---
 modules/plugin_dbui/__init__.py |  3 +-
 modules/plugin_dbui/helper.py   | 51 ++++++++++++++++++++++-----------
 views/plugin_dbui/index.html    | 35 ++++++++++++++++++++++
 3 files changed, 72 insertions(+), 17 deletions(-)
 create mode 100644 views/plugin_dbui/index.html

diff --git a/modules/plugin_dbui/__init__.py b/modules/plugin_dbui/__init__.py
index 9cbbe150..9a798d05 100644
--- a/modules/plugin_dbui/__init__.py
+++ b/modules/plugin_dbui/__init__.py
@@ -8,7 +8,8 @@ from directsvc import DBUI, DirectSvc
 from fieldmodifier import FieldModifier
 from formmodifier import configure_forms, FormModifier
 from gridmodifier import configure_grids, GridModifier
-from helper import (get_extjs_path, 
+from helper import (get_extjs_path,
+                    get_js_files, 
                     get_language, 
                     get_reference_paths, 
                     get_script_path)
diff --git a/modules/plugin_dbui/helper.py b/modules/plugin_dbui/helper.py
index a50353e4..4000810d 100644
--- a/modules/plugin_dbui/helper.py
+++ b/modules/plugin_dbui/helper.py
@@ -74,6 +74,41 @@ def get_extjs_path(environment):
     return os.path.join(os.path.sep, application, 'static', 'plugin_extjs')
 
 
+def get_js_files(server_path, client_path, directory):
+    """Return a list of javascript files stored in the directory.
+    The alphabetic order is preserved.
+    
+    """
+    li = []
+
+    cltdir = os.path.join(client_path, directory)
+    svrdir = os.path.join(server_path, directory)
+    
+    if os.path.exists(svrdir):
+        for file in os.listdir(svrdir):
+            if file.endswith(".js"):
+                li.append(os.path.join(cltdir, file))
+
+    li.sort()
+    return li
+
+
+def get_language(environment):
+    """Helper method returning the application language.
+    The result is compliant with the ExtJS file name.
+
+    The dictionary environment contains the keys request, response, 
+    session, plugins, ....
+    
+    """
+    lg = environment['T'].accepted_language
+    
+    if len(lg) == 5 and lg[0:2] == lg[3:5]: 
+        lg = lg[0:2]
+
+    return lg
+
+
 def get_reference_paths(environment):
     """Helper method returning a tuple with the server and the local paths.
 
@@ -125,22 +160,6 @@ def get_script_path(environment):
     return script
 
 
-def get_language(environment):
-    """Helper method returning the application language.
-    The result is compliant with the ExtJS file name.
-
-    The dictionary environment contains the keys request, response, 
-    session, plugins, ....
-    
-    """
-    lg = environment['T'].accepted_language
-    
-    if len(lg) == 5 and lg[0:2] == lg[3:5]: 
-        lg = lg[0:2]
-
-    return lg
-
-
 def rows_serializer(rows):
     """Helper function to serialize a gluon.dal.Rows.
     
diff --git a/views/plugin_dbui/index.html b/views/plugin_dbui/index.html
new file mode 100644
index 00000000..e3f831ed
--- /dev/null
+++ b/views/plugin_dbui/index.html
@@ -0,0 +1,35 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+    <head>
+        <!-- $Id: plugin_dbui.html 1129 2011-02-19 13:50:53Z legac $ -->
+        
+        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+        <meta name="author" lang="en" content="{{=response.author}}" />
+        <meta name="keywords" content="{{=response.keywords}}" />
+        <meta name="description" content="{{=response.description}}" />
+        
+        <title>{{=request.application}}</title>
+        
+        <!-- extjs css -->
+        <link rel="stylesheet" type="text/css" href="{{=pextjs}}/resources/css/ext-all.css"/>
+        <link rel="stylesheet" type="text/css" href="{{=pextjs}}/examples/shared/icons/silk.css"/> 
+
+        <!-- extjs javascript library -->
+        <script type="text/javascript" src="{{=pextjs}}/adapter/ext/ext-base.js"></script>
+        <script type="text/javascript" src="{{=pextjs}}/ext-all.js"></script>
+        <script type="text/javascript" src="{{=pextjs}}/src/locale/ext-lang-{{=lg}}.js"></script>
+
+        <!-- dbui javascript library -->
+        <script type="text/javascript" src="/{{=request.application}}/plugin_dbui/get_api"></script>
+        <script type="text/javascript" src="/{{=request.application}}/static/plugin_dbui/dbui.min.js"></script>
+        
+        <!-- user javascript library and main script-->
+        {{for el in response.files:}}
+        <script type="text/javascript" src="{{=el}}"></script>
+        {{pass}}
+
+    </head>
+    <body>
+        <div id='appmain'></div>
+    </body>
+</html>
-- 
GitLab