[Checkins] SVN: z3c.formjsdemo/trunk/src/z3c/formjsdemo/c
preliminary work on chat demo.
Paul Carduner
paulcarduner at gmail.com
Sat Jul 7 03:00:54 EDT 2007
Log message for revision 77560:
preliminary work on chat demo.
Changed:
A z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/
A z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/__init__.py
A z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/browser.py
A z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/browser.pyc
A z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.css
A z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.js
A z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.pt
A z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.py
A z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/configure.zcml
A z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/interfaces.py
U z3c.formjsdemo/trunk/src/z3c/formjsdemo/configure.zcml
-=-
Added: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/__init__.py
===================================================================
Property changes on: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/browser.py
===================================================================
--- z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/browser.py (rev 0)
+++ z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/browser.py 2007-07-07 07:00:53 UTC (rev 77560)
@@ -0,0 +1,100 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Browser code for JS button demo.
+
+$Id: layer.py 75942 2007-05-24 14:53:46Z srichter $
+"""
+__docformat__="restructuredtext"
+import os.path
+import zope.interface
+from zope.viewlet.viewlet import CSSViewlet, JavaScriptViewlet
+from zope.app.container.interfaces import INameChooser
+from zope.traversing.browser import absoluteURL
+from zope.security.proxy import removeSecurityProxy
+from z3c.form import form, button, field
+from z3c.form.interfaces import IWidgets
+from z3c.formui import layout
+from z3c.formjs import jsaction, jsevent
+
+from z3c.formjsdemo.chat import chat, interfaces
+
+ChatCSSViewlet = CSSViewlet('chat.css')
+ChatJSViewlet = JavaScriptViewlet('chat.js')
+
+class ChatRoomAddForm(layout.FormLayoutSupport, form.AddForm):
+
+ label = "Add a Chat Room"
+ fields = field.Fields(interfaces.IChatRoom).select('topic')
+
+ def create(self, data):
+ return chat.ChatRoom(data['topic'])
+
+ def add(self, object):
+ name = object.topic.lower().replace(' ','')
+ context = removeSecurityProxy(self.context)
+ name = INameChooser(context).chooseName(name, object)
+ context[name] = object
+ self._name = name
+
+ def nextURL(self):
+ return absoluteURL(removeSecurityProxy(self.context)[self._name], self.request)
+
+
+class IButtons(zope.interface.Interface):
+ send = jsaction.JSButton(title=u'Send')
+
+class IFields(zope.interface.Interface):
+ message = zope.schema.TextLine(title=u"Message")
+
+class ChatForm(layout.FormLayoutSupport, form.Form):
+ buttons = button.Buttons(IButtons)
+ fields = field.Fields(IFields)
+
+ @jsaction.handler(buttons['send'])
+ def handleSend(self, selecter):
+ messageId = self.widgets['message'].id
+ return '''$.get("addMessage", {message: $("#%s").val()}, function(data){
+ $("#%s").val("");
+ });
+ ''' % (messageId, messageId)
+
+ def updateWidgets(self):
+ '''See interfaces.IForm'''
+ self.widgets = zope.component.getMultiAdapter(
+ (self, self.request, self.getContent()), IWidgets)
+ self.widgets.ignoreContext = True
+ self.widgets.update()
+
+
+def renderMessage(message):
+ return '<div class="message">%s</div>' % message
+
+
+class AddMessageView(object):
+
+ def __call__(self):
+ message = self.request.get('message')
+ if message is not None:
+ self.context.addMessage(message)
+ return renderMessage(message)
+
+
+class GetMessagesView(object):
+
+ def __call__(self):
+ index = int(self.request.get('index'))
+ result = ""
+ for message in self.context.messages[index:]:
+ result += renderMessage(message)
+ return result
Property changes on: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/browser.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/browser.pyc
===================================================================
(Binary files differ)
Property changes on: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/browser.pyc
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.css
===================================================================
--- z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.css (rev 0)
+++ z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.css 2007-07-07 07:00:53 UTC (rev 77560)
@@ -0,0 +1 @@
+//css
\ No newline at end of file
Property changes on: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.css
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.js
===================================================================
--- z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.js (rev 0)
+++ z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.js 2007-07-07 07:00:53 UTC (rev 77560)
@@ -0,0 +1,12 @@
+function mainLoop() {
+ var num = $("div.message").length;
+ $.get("getMessages", {index: $("div.message").length},
+ function(data) {
+ $("#chat-window").append(data);
+ t=setTimeout("mainLoop()", 1000);
+ });
+}
+
+$(document).ready(function() {
+ mainLoop()
+})
Property changes on: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.js
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.pt
===================================================================
--- z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.pt (rev 0)
+++ z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.pt 2007-07-07 07:00:53 UTC (rev 77560)
@@ -0,0 +1,10 @@
+<h1 id="header" tal:content="context/topic">Topic</h1>
+<div id="chat-window">
+ <div tal:repeat="message context/messages"
+ tal:content="message" />
+</div>
+<div id="controls">
+ <div tal:replace="structure view/widgets/message/render" />
+ <div tal:repeat="action view/actions/values"
+ tal:replace="structure action/render" />
+</div>
\ No newline at end of file
Property changes on: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.py
===================================================================
--- z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.py (rev 0)
+++ z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.py 2007-07-07 07:00:53 UTC (rev 77560)
@@ -0,0 +1,39 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Simple Chat room implementation.
+
+$Id:$
+"""
+__docformat__ = "reStructuredText"
+import persistent
+from persistent.list import PersistentList
+import zope.interface
+from zope.location import location
+from zope.schema.fieldproperty import FieldProperty
+
+import interfaces
+
+class ChatRoom(location.Location, persistent.Persistent):
+ """See interfaces.IChatRoom."""
+ zope.interface.implements(interfaces.IChatRoom)
+
+ topic = FieldProperty(interfaces.IChatRoom['topic'])
+
+ def __init__(self, topic):
+ self.topic = topic
+ self.messages = PersistentList()
+
+
+ def addMessage(self, message):
+ self.messages.append(message)
Property changes on: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/chat.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/configure.zcml
===================================================================
--- z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/configure.zcml (rev 0)
+++ z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/configure.zcml 2007-07-07 07:00:53 UTC (rev 77560)
@@ -0,0 +1,85 @@
+<configure
+ xmlns="http://namespaces.zope.org/browser"
+ xmlns:zope="http://namespaces.zope.org/zope"
+ xmlns:z3c="http://namespaces.zope.org/z3c"
+ i18n_domain="z3c.formjsdemo">
+
+ <zope:class class=".chat.ChatRoom">
+ <allow
+ interface=".interfaces.IChatRoom"
+ />
+ <require
+ permission="zope.View"
+ set_schema=".interfaces.IChatRoom"
+ />
+ </zope:class>
+
+ <z3c:pagelet
+ name="addChatRoom.html"
+ for="zope.app.folder.interfaces.IFolder"
+ class=".browser.ChatRoomAddForm"
+ layer="z3c.formjsdemo.layer.IDemoBrowserLayer"
+ permission="zope.Public"
+ />
+
+ <z3c:pagelet
+ name="index.html"
+ for=".interfaces.IChatRoom"
+ class=".browser.ChatForm"
+ layer="z3c.formjsdemo.layer.IDemoBrowserLayer"
+ permission="zope.Public"
+ />
+
+ <z3c:template
+ template="chat.pt"
+ for=".browser.ChatForm"
+ layer="z3c.formjsdemo.layer.IDemoBrowserLayer"
+ />
+
+ <z3c:pagelet
+ name="addMessage"
+ for=".interfaces.IChatRoom"
+ class=".browser.AddMessageView"
+ layer="z3c.formjsdemo.layer.IDemoBrowserLayer"
+ permission="zope.Public"
+ />
+
+ <z3c:pagelet
+ name="getMessages"
+ for=".interfaces.IChatRoom"
+ class=".browser.GetMessagesView"
+ layer="z3c.formjsdemo.layer.IDemoBrowserLayer"
+ permission="zope.Public"
+ />
+
+ <zrt-resource
+ name="chat.css"
+ file="chat.css"
+ layer="z3c.formjsdemo.layer.IDemoBrowserLayer"
+ />
+
+ <zrt-resource
+ name="chat.js"
+ file="chat.js"
+ layer="z3c.formjsdemo.layer.IDemoBrowserLayer"
+ />
+
+ <viewlet
+ name="chat.css"
+ view=".browser.ChatForm"
+ manager="z3c.formjsdemo.skin.ICSS"
+ class=".browser.ChatCSSViewlet"
+ permission="zope.Public"
+ layer="z3c.formjsdemo.layer.IDemoBrowserLayer"
+ />
+
+ <viewlet
+ name="chat.js"
+ view=".browser.ChatForm"
+ manager="z3c.formjsdemo.skin.IJavaScript"
+ class=".browser.ChatJSViewlet"
+ permission="zope.Public"
+ layer="z3c.formjsdemo.layer.IDemoBrowserLayer"
+ />
+
+</configure>
Property changes on: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/interfaces.py
===================================================================
--- z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/interfaces.py (rev 0)
+++ z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/interfaces.py 2007-07-07 07:00:53 UTC (rev 77560)
@@ -0,0 +1,19 @@
+import zope.interface
+import zope.schema
+
+class IChatRoom(zope.interface.Interface):
+ """A simple chat room."""
+
+ messages = zope.schema.List(
+ title=u"Messages",
+ description=u"The Chat Messages.",
+ readonly=True,
+ required=True)
+
+ topic = zope.schema.TextLine(
+ title=u"Topic",
+ description=u"Topic of the Chat Room.",
+ required=True)
+
+ def addMessage(message):
+ """Add a message to the list."""
Property changes on: z3c.formjsdemo/trunk/src/z3c/formjsdemo/chat/interfaces.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: z3c.formjsdemo/trunk/src/z3c/formjsdemo/configure.zcml
===================================================================
--- z3c.formjsdemo/trunk/src/z3c/formjsdemo/configure.zcml 2007-07-07 06:37:40 UTC (rev 77559)
+++ z3c.formjsdemo/trunk/src/z3c/formjsdemo/configure.zcml 2007-07-07 07:00:53 UTC (rev 77560)
@@ -16,5 +16,6 @@
<include package=".button" />
<include package=".calculator" />
<include package=".validator" />
+ <include package=".chat" />
</configure>
More information about the Checkins
mailing list