incubator-esme-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dha...@apache.org
Subject svn commit: r731359 - in /incubator/esme/trunk/server: ./ src/main/scala/us/esme/comet/PublicTimeline.scala src/main/scala/us/esme/comet/Timeline.scala src/main/webapp/templates-hidden/message.html
Date Sun, 04 Jan 2009 21:15:11 GMT
Author: dhague
Date: Sun Jan  4 13:15:10 2009
New Revision: 731359

URL: http://svn.apache.org/viewvc?rev=731359&view=rev
Log:
JavaScript comet message update now more generic, and deals with both user and public timelines.

Modified:
    incubator/esme/trunk/server/   (props changed)
    incubator/esme/trunk/server/src/main/scala/us/esme/comet/PublicTimeline.scala
    incubator/esme/trunk/server/src/main/scala/us/esme/comet/Timeline.scala
    incubator/esme/trunk/server/src/main/webapp/templates-hidden/message.html

Propchange: incubator/esme/trunk/server/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sun Jan  4 13:15:10 2009
@@ -1 +1,5 @@
 target
+esme_db
+esme_test_db
+derby.log
+compass-index

Modified: incubator/esme/trunk/server/src/main/scala/us/esme/comet/PublicTimeline.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/us/esme/comet/PublicTimeline.scala?rev=731359&r1=731358&r2=731359&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/us/esme/comet/PublicTimeline.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/us/esme/comet/PublicTimeline.scala Sun Jan
 4 13:15:10 2009
@@ -54,10 +54,11 @@
     scheduled = false
     val msgMap = Message.findMessages(messages)
     val toDisplay = messages.flatMap(msgMap.get)
-  
-    OnLoad(JsCrVar("public_timeline_messages", JsArray(
+    val jsId = "public_timeline_messages";
+
+    OnLoad(JsCrVar(jsId, JsArray(
         toDisplay.map(_.asJs) :_*)) &
-    JsFunc("displayMessages", JsVar("public_timeline_messages"), uniqueId).cmd)
+    JsFunc("displayMessages", JsVar(jsId), jsId).cmd)
   }
 
   override def lowPriority = {

Modified: incubator/esme/trunk/server/src/main/scala/us/esme/comet/Timeline.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/us/esme/comet/Timeline.scala?rev=731359&r1=731358&r2=731359&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/us/esme/comet/Timeline.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/us/esme/comet/Timeline.scala Sun Jan  4 13:15:10
2009
@@ -55,10 +55,11 @@
   def render = {
     val msgMap = Message.findMessages(messages)
     val toDisplay = messages.flatMap(msgMap.get)
+    val jsId = "timeline_messages";
 
-    OnLoad(JsCrVar("timeline_messages", JsArray(
+    OnLoad(JsCrVar(jsId, JsArray(
         toDisplay.map(_.asJs) :_*)) &
-    JsFunc("displayMessages", JsVar("timeline_messages"), uniqueId).cmd)
+    JsFunc("displayMessages", JsVar(jsId), jsId).cmd)
   }
   
   override def lowPriority = {

Modified: incubator/esme/trunk/server/src/main/webapp/templates-hidden/message.html
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/webapp/templates-hidden/message.html?rev=731359&r1=731358&r2=731359&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/webapp/templates-hidden/message.html (original)
+++ incubator/esme/trunk/server/src/main/webapp/templates-hidden/message.html Sun Jan  4 13:15:10
2009
@@ -8,6 +8,80 @@
 
     <script id="jquery" src="/classpath/jquery.js" type="text/javascript"/>
     <script id="json" src="/classpath/json.js" type="text/javascript"/>
+    <script>
+// <![CDATA[
+    /*
+     * displayMessages called by lift:comet, type="Timeline" and type="PublicTimeline"
+     */
+
+    function msgDateCompare(msg1, msg2)
+    {
+        return parseInt(msg1.when) - parseInt(msg2.when);
+    }
+
+    function displayMessages(msgArray, elementId)
+    {
+        // Select the first element in table id="timeline_messages"
+        //  with id="message" as the message template
+        if (msgTemplate == null) {
+//                                    var msgTemplate = jQuery('span.'+spanId+' message:first');
+            var msgTemplate = jQuery('#'+elementId+' #message:first');
+            var tagTemplate = msgTemplate.find('#tag:first');
+            var msgInsertPt = jQuery('#'+elementId);
+
+            // Now we have the template, make the existing instances invisible
+            jQuery('#'+elementId+' *[id=message]').hide();
+        }
+
+        // Sort the messages into date order
+        msgArray.sort(msgDateCompare);
+
+        for (var msgIndex in msgArray)
+        {
+            // Marshall the data from the Comet-supplied message
+            var cometMsg = msgArray[msgIndex];
+            var msgId = "message_"+cometMsg.id;
+
+            // Only do this if the message is not already in the table
+            if (jQuery('#'+elementId+' #'+msgId).size() == 0)
+            {
+                var msgAuthor = cometMsg.author;
+                var msgBody = jQuery(cometMsg.text).find('body').html();
+                var msgDateObj = new Date(parseInt(cometMsg.when));
+                var msgDateStr = msgDateObj.toLocaleDateString() +
+                    ' ' + msgDateObj.toLocaleTimeString();
+                var msgSource = cometMsg.source;
+                var msgTags = jQuery(cometMsg.text).find('tag').get();
+                for (var tagIndex=0; tagIndex < msgTags.length; tagIndex++) {
+                    // Replace each tag element with the plain tag text
+                    msgTags[tagIndex] = jQuery(msgTags[tagIndex]).attr('name');
+                }
+
+                // Put the marshalled data into a copy of the template
+                var newMsg = msgTemplate.clone(true).attr('id',msgId);
+
+                newMsg.find('#author').text(msgAuthor);
+                newMsg.find('#body').html(msgBody);
+                newMsg.find('#source').text(msgSource);
+                newMsg.find('#when').text(msgDateStr);
+                for (var tagIndex=0; tagIndex < msgTags.length; tagIndex++) {
+                    var newTag = tagTemplate.clone(true).attr('id',msgTags[tagIndex]);
+                    newTag.find('a')
+                        .attr('href','tag/'+msgTags[tagIndex])
+                        .text(msgTags[tagIndex]);
+                    newTag.insertBefore(newMsg.find('#tag'));
+                }
+
+                // Remove any old tags from the template
+                newMsg.find('*[id=tag]').remove();
+
+                // Insert the updated copy of the message into the page
+                newMsg.prependTo(msgInsertPt).show();
+            }
+        }
+    }
+// ]]>
+    </script>
 
   </head>
   <body>
@@ -35,9 +109,8 @@
                     <dt class="caption">Your timeline</dt>
 
                     <dd>
-                      <lift:comet type="Timeline"/>
                       <div class="b-list">
-                      <table id="timeline_messages">
+                      <table>
                         <thead>
                           <tr>
                               <th>Author</th>
@@ -47,84 +120,8 @@
                               <th>Date</th>
                           </tr>
                         </thead>
-<!-- msgArray is an array of objects of the form:
-  'conversation': 0, 'author': 1, 'replyto': 0, 'viagroup': 0, 'id': 1,
-  'text': '<message><body>Checking out the latest ESME</body>\u000a
-        <tags><tag name="Esme" id="1"></tag></tags></message>',
-  'source': 'web', 'when': 1230587914019}
--->
-                        <script>
-                    // <![CDATA[
-                            function msgDateCompare(msg1, msg2)
-                            {
-                                return parseInt(msg1.when) - parseInt(msg2.when);
-                            }
-
-                            function displayMessages(msgArray, spanId)
-                            {
-                                // Select the first element in table id="timeline_messages"
-                                //  with id="message" as the message template
-                                if (msgTemplate == null) {
-//                                    var msgTemplate = jQuery('span.'+spanId+' message:first');
-                                    var msgTemplate = jQuery('table#timeline_messages #message:first');
-                                    var tagTemplate = msgTemplate.find('#tag:first');
-                                    var msgInsertPt = jQuery('table#timeline_messages #messages');
-
-                                    // Now we have the template, make the existing instances
invisible
-                                    jQuery('table#timeline_messages *[id=message]').hide();
-                                }
-
-                                // Sort the messages into date order
-                                msgArray.sort(msgDateCompare);
-
-                                for (var msgIndex in msgArray)
-                                {
-                                    // Marshall the data from the Comet-supplied message
-                                    var cometMsg = msgArray[msgIndex];
-                                    var msgId = "message_"+cometMsg.id;
-
-                                    // Only do this if the message is not already in the
table
-                                    if (jQuery('table#timeline_messages #'+msgId).size()
== 0)
-                                    {
-                                        var msgAuthor = cometMsg.author;
-                                        var msgBody = jQuery(cometMsg.text).find('body').html();
-                                        var msgDateObj = new Date(parseInt(cometMsg.when));
-                                        var msgDateStr = msgDateObj.toLocaleDateString()
+
-                                            ' ' + msgDateObj.toLocaleTimeString();
-                                        var msgSource = cometMsg.source;
-                                        var msgTags = jQuery(cometMsg.text).find('tag').get();
-                                        for (var tagIndex=0; tagIndex < msgTags.length;
tagIndex++) {
-                                            // Replace each tag element with the plain tag
text
-                                            msgTags[tagIndex] = jQuery(msgTags[tagIndex]).attr('name');
-                                        }
-
-                                        // Put the marshalled data into a copy of the template
-                                        var newMsg = msgTemplate.clone(true).attr('id',msgId);
-
-                                        newMsg.find('#author').text(msgAuthor);
-                                        newMsg.find('#body').html(msgBody);
-                                        newMsg.find('#source').text(msgSource);
-                                        newMsg.find('#when').text(msgDateStr);
-                                        for (var tagIndex=0; tagIndex < msgTags.length;
tagIndex++) {
-//                                            alert('msgId: '+msgId+' msgTags['+tagIndex+']
= '+ msgTag);
-
-                                            var newTag = tagTemplate.clone(true).attr('id',msgTags[tagIndex]);
-                                            newTag.find('a')
-                                                .attr('href','tag/'+msgTags[tagIndex])
-                                                .text(msgTags[tagIndex]);
-                                            newTag.insertBefore(newMsg.find('#tag'));
-                                        }
-                                        // Remove any old tags from the template
-                                        newMsg.find('*[id=tag]').remove();
-
-                                        // Insert the updated copy of the message into the
page
-                                        newMsg.prependTo(msgInsertPt).show();
-                                    }
-                                }
-                            }
-                    // ]]>
-                        </script>
-                        <tbody id="messages">
+                        <lift:comet type="Timeline"/>
+                        <tbody id="timeline_messages">
                           <tr id="message">
                               <td id="author">dhague</td>
                               <td class="message">
@@ -160,12 +157,39 @@
                   </dl>
 
                   <dl class="tagclouds">
-                    <dt class="caption">
-                      Public Timeline
-                    </dt>
+                    <dt class="caption">Public timeline</dt>
 
-                    <dd class="b-clouds">
-                      <lift:comet type="PublicTimeline" />
+                    <dd>
+                      <div class="b-list">
+                      <table>
+                        <thead>
+                          <tr>
+                              <th>Author</th>
+                              <th>Message</th>
+                              <th>Tags</th>
+                              <th>Source</th>
+                              <th>Date</th>
+                          </tr>
+                        </thead>
+                        <lift:comet type="PublicTimeline"/>
+                        <tbody id="public_timeline_messages">
+                          <tr id="message">
+                              <td id="author">dhague</td>
+                              <td class="message">
+                                <div class="outer"><div class="inner clear">
+                                    <p class="text" id="body">This is a public timeline
message in the HTML for designers.</p>
+                                </div></div>
+                              </td>
+                              <td id="tags" class="tag">
+                                  <p id="tag"><a href="tag/tagA">tagA</a></p>
+                                  <p id="tag"><a href="tag/tagB">tagB</a></p>
+                              </td>
+                              <td id="source">web</td>
+                              <td id="when" class="date">Jan 1, 2009 12:00</td>
+                          </tr>
+                        </tbody>
+                      </table>
+                      </div>
                     </dd>
                   </dl>
                   <dl class="contacts">



Mime
View raw message