Author: jmorliaguet
Date: Mon Feb  6 13:37:33 2006
New Revision: 2309

Modified:
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/chat/browser.py
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/chat/configure.zcml
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/chat/cpsskins_chat.pt
Log:

- updated the chat demo



Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/chat/browser.py
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/chat/browser.py
      (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/chat/browser.py
      Mon Feb  6 13:37:33 2006
@@ -3,7 +3,6 @@
 
 from zope.app.publisher.browser import BrowserView
 from zope.app.cache.ram import RAMCache
-from zope.app.session.interfaces import ISession
 
 from cpsskins import minjson as json
 
@@ -14,41 +13,28 @@
     def __init__(self, context, request):
         self.context = context
         self.request = request
-        self.session = ISession(self.request)['cpsskins']
 
     def getData(self):
-        data = cache.query('data2', {}, {})
+        data = cache.query('data', {}, {})
         return json.write(data)
 
     def setData(self, data):
+        time.sleep(1)
         data = json.read(data)
 
-        current_data = cache.query('data2', {}, {})
+        current_data = cache.query('data', {}, {})
         messages = current_data.get('messages', [])
-        message = data.get('message')
-        if message:
+        input = data.get('input')
+        if input:
             ip = self.request.get('REMOTE_ADDR')
-            messages.append({'message': message, 'ip': ip});
+            messages.append({'text': input, 'ip': ip});
+            del data['input']
 
+        data['status'] = ''
         data['messages'] = messages
-        data['last-updated'] = int(time.time())
-        cache.set(data, 'data2', {})
-
-        return json.write(data)
-
-    def getLastUpdated(self):
-        data = cache.query('data2', {}, {})
-        return json.write({'last-updated': data.get('last-updated', 0)})
-
-    def getPreferences(self):
-        data = self.session.get('data4', {u'user': u'Guest'})
-        return json.write(data)
-
-    def setPreferences(self, data):
-        data = json.read(data)
-        user = data.get('user')
-        if user:
-            self.session['data1'] = data
+        data['lastupdated'] = int(time.time())
 
+        cache.set(data, 'data', {})
+        print data
         return json.write(data)
 

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/chat/configure.zcml
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/chat/configure.zcml
  (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/chat/configure.zcml
  Mon Feb  6 13:37:33 2006
@@ -25,21 +25,6 @@
         attribute="setData"
     />
 
-    <browser:page
-        name="getLastUpdated"
-        attribute="getLastUpdated"
-    />
-
-    <browser:page
-        name="getPreferences"
-        attribute="getPreferences"
-    />
-
-    <browser:page
-        name="setPreferences"
-        attribute="setPreferences"
-    />
-
   </browser:pages>
 
 </configure>

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/chat/cpsskins_chat.pt
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/chat/cpsskins_chat.pt
        (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/chat/cpsskins_chat.pt
        Mon Feb  6 13:37:33 2006
@@ -15,31 +15,39 @@
         href="/++skin++cpsskins/@@/++resource++cpsskins.css" />
 
   <style type="text/css">
-    .choices {
-      font: 1.3em Arial;
-    }
-
     div.chatbox {
       padding: 0.5em;
-      width: 300px;
-      border: 1px solid #666;
-      background-color: #efc;
+      border: 1px solid #999;
+      background-color: #cd9;
     }
 
     input {
       margin-bottom: 0.5em;
+      margin-top: 0.5em;
       border-width: 1px;
       border-style: solid;
       border-color: #000 #999 #999 #000;
-      width: 175px;
-      font: 1.3em arial;
+      width: 400px;
+      font: 1.5em arial, sans-serif;
     }
 
     div.message {
-      border: 1px solid #fc0;
-      background-color: #ffc;
-      padding: 1em;
+      border: 1px solid #999;
+      background-color: #efc;
+      padding: 0.5em;
       margin: 0.5em;
+      font: 1.3em verdana, arial, sans-serif;
+    }
+
+    div.status {
+      border: 1px solid #000;
+      background-color: #fc0;
+      padding: 0.5em;
+      margin: 0.3em 0;
+      margin-bottom: 1em;
+      position: absolute;
+      top: 20px;
+      right: 20px;
     }
 
   </style>
@@ -51,10 +59,17 @@
       chatbox: function(def) {
         var widget = Canvas.createNode({
           tag: "div",
-          classes: "inputbox"
+          classes: "chatbox"
         });
-
         return new ChatBox(widget, def);
+      },
+
+      inputbox: function(def) {
+        var widget = Canvas.createNode({
+          tag: "div",
+          classes: "inputbox"
+        });
+        return new InputBox(widget, def);
       }
 
     });
@@ -62,27 +77,48 @@
     ChatBox = Class.create();
     ChatBox.prototype = Object.extend(new CPSSkins.View(), {
 
-      setup: function() {
-        this.changeEvent = this.changeEvent.bindAsEventListener(this);
-        Event.observe(this.widget, "change", this.changeEvent);
-      },
-
       render: function(data) {
         var widget = this.widget;
         widget.innerHTML = '';
 
         var messages = data.messages;
 
-        $A(messages).each(function(m) {
+        $A(messages).reverse(false).each(function(m, index) {
+          if (index > 5) return;
           widget.appendChild(
             Canvas.createNode({
               tag: "div",
               classes: "message",
-              text: '[' + m.ip + '] ' + m.message
+              text: '[' + m.ip + '] ' + m.text
           }));
-
         });
 
+      }
+
+    });
+
+    InputBox = Class.create();
+    InputBox.prototype = Object.extend(new CPSSkins.View(), {
+
+      setup: function() {
+        this.changeEvent = this.changeEvent.bindAsEventListener(this);
+        Event.observe(this.widget, "change", this.changeEvent);
+      },
+
+      render: function(data) {
+        var widget = this.widget;
+        widget.innerHTML = '';
+
+        var status = data.status;
+        if (status) {
+          var statusbox = Canvas.createNode({
+            tag: "div",
+            classes: "status",
+            text: status
+          });
+          widget.appendChild(statusbox);
+        }
+
         var input = Canvas.createNode({
           tag: "input",
           attributes: {
@@ -90,7 +126,6 @@
           }
         });
         widget.appendChild(input);
-
       },
 
       changeEvent: function(e) {
@@ -104,7 +139,7 @@
     /* Controller */
 
     function changeContent(model, context, value) {
-      model.setData({'message': value});
+      model.setData({'status': 'Sending message ...', 'input': value});
     }
 
     CPSSkins.registerHandlers({'changeContent': changeContent});
@@ -124,10 +159,27 @@
   </ins>
 
   <div id="area0">
+
+    <!-- messages -->
+    <ins class="model">
+    {"id": "messages",
+     "data": {
+      "messages": []
+     },
+     "storage": {
+       "type": "remote",
+       "refresh": 3,
+       "accessors": {
+         "get": "@@getData"
+       }
+    }}
+    </ins>
+
+    <!-- status message -->
     <ins class="model">
-    {"id": "local",
+    {"id": "status",
      "data": {
-      "message": ""
+      "status": ""
      },
      "storage": {
        "type": "ram"
@@ -135,39 +187,65 @@
     }}
     </ins>
 
+    <!-- input area / server response -->
     <ins class="model">
-    {"id": "remote",
+    {"id": "input",
      "data": {
+      "status": "",
+      "input": "",
       "messages": []
      },
      "storage": {
        "type": "remote",
        "accessors": {
-         "get": "@@getData",
          "set": "@@setData"
        }
     }}
     </ins>
 
     <ins class="model">
-    {"id": "messages",
+    {"id": "chat",
      "data": {
+      "status": "",
+      "input": "",
       "messages": []
      },
      "storage": {
        "type": "compound",
-       "partitions": ["local", "remote"]
+       "partitions": ["messages", "status", "input"]
+       }
+    }}
+    </ins>
+
+    <ins class="model">
+    {"id": "form",
+     "data": {
+      "status": "",
+      "input": ""
+     },
+     "storage": {
+       "type": "compound",
+       "partitions": ["status", "input"]
+       }
     }}
     </ins>
 
     <ins class="view">
     {"widget": {
-      "type": "chatbox"
+      "type": "inputbox"
      },
-     "model": "messages",
+     "model": "form",
      "controller": "controller"
     }
     </ins>
 
+    <ins class="view">
+    {"widget": {
+      "type": "chatbox"
+     },
+     "model": "chat"
+    }
+    </ins>
+
 </body>
 </html>
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to