cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject svn commit: r327595 - in /cocoon/blocks/forms/trunk/samples/sql: flow/flow.js forms/employee.xml pages/employee-edit.xml pages/employee-list.xml resources/page-styling.xsl selection-list.xml sitemap.xmap
Date Fri, 21 Oct 2005 22:22:03 GMT
Author: sylvain
Date: Fri Oct 21 15:21:53 2005
New Revision: 327595

URL: http://svn.apache.org/viewcvs?rev=327595&view=rev
Log:
Code cleanup, comments, licence headers

Modified:
    cocoon/blocks/forms/trunk/samples/sql/flow/flow.js
    cocoon/blocks/forms/trunk/samples/sql/forms/employee.xml
    cocoon/blocks/forms/trunk/samples/sql/pages/employee-edit.xml
    cocoon/blocks/forms/trunk/samples/sql/pages/employee-list.xml
    cocoon/blocks/forms/trunk/samples/sql/resources/page-styling.xsl
    cocoon/blocks/forms/trunk/samples/sql/selection-list.xml
    cocoon/blocks/forms/trunk/samples/sql/sitemap.xmap

Modified: cocoon/blocks/forms/trunk/samples/sql/flow/flow.js
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/samples/sql/flow/flow.js?rev=327595&r1=327594&r2=327595&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/samples/sql/flow/flow.js (original)
+++ cocoon/blocks/forms/trunk/samples/sql/flow/flow.js Fri Oct 21 15:21:53 2005
@@ -1,3 +1,26 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * CRUD operations on the "personnel" database that comes with Cocoon samples,
+ * showing how a few conventions, Map and List wrappers for forms and JDBC allow
+ * to easily connect forms and a database.
+ *
+ * @version $Id$
+ */
 cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js");
 cocoon.load("flow/jdbi.js");
 importClass(org.apache.cocoon.forms.formmodel.WidgetState);
@@ -13,7 +36,7 @@
 }
 
 // The DAO object for our application
-var dao = function() {};
+dao = function() {};
 
 // The database interface for our DAO
 dao.dbi = new JDBI("personnel");
@@ -27,7 +50,7 @@
     return id;
 }
 
-// Get the contents of a table as a selectionList
+// Get the contents of a table as a selectionList (see dao.department below)
 function selection_list() {
     var table = dao[cocoon.parameters.table];
     if (!table) throw "No table named " + table;
@@ -35,6 +58,10 @@
 }
 
 //-------------------------------------------------------------------------------------------------
+// The Data Access Object for the employees table.
+// Defining DAOs is not mandatory, and SQL statements can be written directly in the flow
+// functions. However, separating SQL from page flow control is a good practice. DAOs also
share
+// a common structure that allows entity-independent flow scenarios to be written.
 
 dao.employee = function() {};
 
@@ -46,12 +73,20 @@
     return dao.dbi.query("select * from employee order by name");
 };
 
-dao.employee.insert = function(employee) {
+// Insert a new employee in the database
+// This function (and other below) accepts a variable number of arguments, which should all
be
+// either JS objects of Maps. They are all combined to a single Map that defines the prepared
+// statement parameters.
+// The order of arguments is important as first parameters "hide" the properties held by
those
+// that follow.
+dao.employee.insert = function() {
+    var employee = JDBI.combine.apply(this, arguments);
     return dao.dbi.execute("insert into employee ( id,  department_id,  name,  description)
" +
                                         " values (:id, :department_id, :name, :description)",
employee);
 };
     
-dao.employee.update = function(employee) {
+dao.employee.update = function() {
+    var employee = JDBI.combine.apply(this, arguments);
     return dao.dbi.execute("update employee set department_id = :department_id, name = :name,
" +
         "description = :description where id = :id", employee);
 };
@@ -61,7 +96,7 @@
     return dao.dbi.execute("delete from employee where id = ?", [id]);
 };
     
-// Above where the functions that exist on all DAOs. You can of course add specialized functions
if needed.
+// Now come the employee-related flow scenarios.
 
 function do_list_employees() {
     var list = dao.employee.getAll();
@@ -70,7 +105,7 @@
 }
 
 function do_edit_employee() {
-    var id = cocoon.request.getParameter("id");
+    var id = cocoon.request.getParameter("id"); // Can be null for creation
     var form = new Form("forms/employee.xml");
     
     // Create a Map view of the form, that will be used with JDBI
@@ -101,15 +136,13 @@
         if (id == null) {
             id = dao.newId("employee");
             
-            // Combine form data and the newly created id in a Map
-            var data = JDBI.combine({id: id}, formMap);
-            
             // And insert the employee.
             // Again, no binding file, no Java object, no nothing! Cool, isn't it?
-            dao.employee.insert(data);
+            // All parameters will be combined to a single Map to feed the database.
+            dao.employee.insert({id: id}, formMap);
         } else {
             // Use a shorter notation now
-            dao.employee.update(JDBI.combine({id: id}, formMap));
+            dao.employee.update({id: id}, formMap);
         }
     }
     
@@ -131,6 +164,8 @@
     return dao.dbi.first("select * from department where id = ?", [id]);
 }
 
+// Return a selection-list view of the departments. This is a list of (value, label) pairs
+// that is later rendered to XML by a JXTemplate.
 dao.department.selectionList = function() {
     return dao.dbi.query("select id as value, name as label from department order by name");
 }

Modified: cocoon/blocks/forms/trunk/samples/sql/forms/employee.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/samples/sql/forms/employee.xml?rev=327595&r1=327594&r2=327595&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/samples/sql/forms/employee.xml (original)
+++ cocoon/blocks/forms/trunk/samples/sql/forms/employee.xml Fri Oct 21 15:21:53 2005
@@ -1,3 +1,23 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 2005 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!--+
+    | @version $Id$
+    +-->
 <fd:form xmlns:fd="http://apache.org/cocoon/forms/1.0#definition">
   <fd:widgets>
     <fd:field id="name" required="true">

Modified: cocoon/blocks/forms/trunk/samples/sql/pages/employee-edit.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/samples/sql/pages/employee-edit.xml?rev=327595&r1=327594&r2=327595&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/samples/sql/pages/employee-edit.xml (original)
+++ cocoon/blocks/forms/trunk/samples/sql/pages/employee-edit.xml Fri Oct 21 15:21:53 2005
@@ -1,3 +1,23 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 2005 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!--+
+    | @version $Id$
+    +-->
 <html xmlns:ft="http://apache.org/cocoon/forms/1.0#template"
       xmlns:fi="http://apache.org/cocoon/forms/1.0#instance"
       xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">

Modified: cocoon/blocks/forms/trunk/samples/sql/pages/employee-list.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/samples/sql/pages/employee-list.xml?rev=327595&r1=327594&r2=327595&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/samples/sql/pages/employee-list.xml (original)
+++ cocoon/blocks/forms/trunk/samples/sql/pages/employee-list.xml Fri Oct 21 15:21:53 2005
@@ -1,3 +1,23 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 2005 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!--+
+    | @version $Id$
+    +-->
 <html xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
   <head>
     <title>

Modified: cocoon/blocks/forms/trunk/samples/sql/resources/page-styling.xsl
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/samples/sql/resources/page-styling.xsl?rev=327595&r1=327594&r2=327595&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/samples/sql/resources/page-styling.xsl (original)
+++ cocoon/blocks/forms/trunk/samples/sql/resources/page-styling.xsl Fri Oct 21 15:21:53 2005
@@ -1,3 +1,23 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 2005 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!--+
+    | @version $Id$
+    +-->
 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
 <xsl:template match="head">

Modified: cocoon/blocks/forms/trunk/samples/sql/selection-list.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/samples/sql/selection-list.xml?rev=327595&r1=327594&r2=327595&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/samples/sql/selection-list.xml (original)
+++ cocoon/blocks/forms/trunk/samples/sql/selection-list.xml Fri Oct 21 15:21:53 2005
@@ -1,3 +1,25 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 2005 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!--+
+    | Renders a list of (value, label) items as a widget selection-list
+    |
+    | @version $Id$
+    +-->
 <fd:selection-list xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
                    xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
   <jx:forEach var="item" items="${items}">

Modified: cocoon/blocks/forms/trunk/samples/sql/sitemap.xmap
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/samples/sql/sitemap.xmap?rev=327595&r1=327594&r2=327595&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/samples/sql/sitemap.xmap (original)
+++ cocoon/blocks/forms/trunk/samples/sql/sitemap.xmap Fri Oct 21 15:21:53 2005
@@ -1,3 +1,23 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 2005 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!--+
+    | @version $Id$
+    +-->
 <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
 
 <map:components>



Mime
View raw message