Author: jmorliaguet
Date: Mon Jan 30 01:03:54 2006
New Revision: 2244

Modified:
   cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
   cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/browser.py
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/cpsskins_storage_adapters.pt
Log:

- fixed race conditions

- added an example of server-side validation



Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js (original)
+++ cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Mon Jan 30 
01:03:54 2006
@@ -577,14 +577,6 @@
 
   setData: function(data) {
     this.storage.storeData(data);
-
-    // Update the observers
-    var observers = this.observers;
-    if (observers) {
-      observers.each(function(o) {
-        o[1].update();
-      });
-    }
   },
 
   // TODO: to rewrite: this might not work if called asynchronously.
@@ -624,7 +616,7 @@
   _setStorageAdapter: function() {
     var storage_def = this.def.storage;
     if (!storage_def) {
-      storage_def = {"type": "client"};
+      storage_def = {"type": "local"};
     }
     this.storage = Storages[storage_def.type](this);
   }
@@ -653,8 +645,8 @@
 if (!window.Storages) { var Storages = new Object(); }
 Object.extend(Storages, {
 
-  client: function(model) {
-    return new CPSSkins.ClientStorage(model);
+  local: function(model) {
+    return new CPSSkins.LocalStorage(model);
   },
 
   remote: function(model) {
@@ -663,8 +655,8 @@
 
 });
 
-CPSSkins.ClientStorage = Class.create();
-CPSSkins.ClientStorage.prototype = Object.extend(
+CPSSkins.LocalStorage = Class.create();
+CPSSkins.LocalStorage.prototype = Object.extend(
   new CPSSkins.StorageAdapter(), {
 
   requestData: function() {
@@ -674,6 +666,7 @@
   storeData: function(data) {
     /* Store the data directly */
     this.model.def.data = data;
+    this.model.notifyObservers(data);
   }
 
 });
@@ -696,6 +689,8 @@
 
   storeData: function(data) {
     var model = this.model;
+    model.def.data = data;
+
     var url = model.def.storage.accessors.set;
     new Ajax.Request(url, {
       method: "post",
@@ -703,6 +698,7 @@
         "data": JSON.stringify(data)
         }).toQueryString(),
       onComplete: function(req) {
+        var data = JSON.parse(req.responseText);
         model.def.data = data;
         model.notifyObservers(data);
       }

Modified: cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/browser.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/browser.py      
(original)
+++ cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/browser.py      
Mon Jan 30 01:03:54 2006
@@ -6,6 +6,8 @@
 
 from cpsskins import minjson as json
 
+RIGHT_ANSWERS = ('blue', 'red', 'yellow')
+
 class Accessors(BrowserView):
 
     def __init__(self, context, request):
@@ -14,16 +16,31 @@
         self.session = ISession(self.request)['cpsskins']
 
     def getData1(self):
+        """Get the data from the 
+        """
         # sleep one second to simulate a delay
         time.sleep(1.5)
 
         # get the data from the session
-        data = self.session.get('data1', {u'content': u'Enter some text'})
+        data = self.session.get('data1', {u'content': u'No data available.'})
+
+        # return the data
         return json.write(data)
 
     def setData1(self, data):
         # sleep one second to simulate a delay
         time.sleep(2)
 
+        # get the data
+        data = json.read(data)
+        content = data['content']
+
+        # validate the data
+        comment = content in RIGHT_ANSWERS and 'RIGHT :-)' or 'WRONG :-('
+        data['content'] = "You answered '%s': %s" % (content, comment)
+
         # store the data in the session
-        self.session['data1'] = json.read(data)
+        self.session['data1'] = data
+
+        # return the results
+        return json.write(data)

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/cpsskins_storage_adapters.pt
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/cpsskins_storage_adapters.pt
    (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/cpsskins_storage_adapters.pt
    Mon Jan 30 01:03:54 2006
@@ -11,9 +11,13 @@
   <link rel="stylesheet" href="/++skin++cpsskins/@@/++resource++cpsskins.css" 
type="text/css" />
 
   <style type="text/css">
+    .choices {
+      font: 1.3em Arial;
+    }
+
     div.inputbox {
       padding: 0.5em;
-      width: 180px;
+      width: 260px;
       border: 1px solid gray;
       background-color: #efc;
       font: 1.3em arial;
@@ -102,8 +106,8 @@
 
   <h1>CPSSkins: storage adapters</h1>
 
-  <p>The model definition can specify a storage adapter to get and set the
-     data.
+  <p>A storage adapter can be specified in the model definition to describe
+     how the model will access the data.
   </p>
 
   <ins class="controller">
@@ -113,11 +117,63 @@
   }}
   </ins>
 
+
+  <h2>Local storage</h2>
+
+  <p>In a local storage the data is store on the client.</p>
+
   <div id="area1">
 
     <ins class="model">
     {"id": "data-provider",
      "data": {
+      "content": ""
+     },
+     "storage": {
+       "type": "local"
+       }
+     }
+    }
+    </ins>
+
+    <ins class="view">
+    {"widget": {
+      "type": "inputbox"
+     },
+     "model": "data-provider",
+     "controller": "controller"
+    }
+    </ins>
+
+  </div>
+
+  <h2>Remote storage</h2>
+  <p>In this example the data is stored on the server inside the session.
+     This provides persistence which means that the page can be reloaded and
+     the current data will be restored.
+  </p>
+
+  <p>An extra delay has been added when retrieving and storing data to
+     simulate network or database latency.</p>
+
+  <p>The input is validated before storing the data.</p>
+
+  <p>Finally the view gets refreshed when the model is updated.</p>
+
+  <h3>Which of these are colors?</h3>
+  <p class="choices">
+     <cite>red</cite>
+     <cite>light</cite>
+     <cite>yellow</cite>
+     <cite>blue</cite>
+     <cite>dark</cite>
+  </p>
+
+  <div id="area2">
+
+    <ins class="model">
+    {"id": "data-provider",
+     "data": {
       "content": "Loading data ..."
      },
      "storage": {
@@ -141,5 +197,6 @@
 
   </div>
 
+
 </body>
 </html>
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to