[Jaws-commits] r13500 - in trunk/jaws/html/gadgets/Chatbox: . resources templates

afz at jaws-project.com afz at jaws-project.com
Sat Aug 25 17:50:02 UTC 2012


Author: afz
Date: 2012-08-25 17:50:02 +0000 (Sat, 25 Aug 2012)
New Revision: 13500

Added:
   trunk/jaws/html/gadgets/Chatbox/Ajax.php
   trunk/jaws/html/gadgets/Chatbox/resources/site_script.js
Modified:
   trunk/jaws/html/gadgets/Chatbox/LayoutHTML.php
   trunk/jaws/html/gadgets/Chatbox/templates/Chatbox.html
Log:
[ChatBox]: Added ajax stuff for forntend area

Added: trunk/jaws/html/gadgets/Chatbox/Ajax.php
===================================================================
--- trunk/jaws/html/gadgets/Chatbox/Ajax.php	                        (rev 0)
+++ trunk/jaws/html/gadgets/Chatbox/Ajax.php	2012-08-25 17:50:02 UTC (rev 13500)
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Chatbox AJAX API
+ *
+ * @category   Ajax
+ * @package    Chatbox
+ * @author     Ali Fazelzadeh <afz at php.net>
+ * @copyright  2012 Jaws Development Group
+ * @license    http://www.gnu.org/copyleft/gpl.html
+ */
+class ChatboxAjax extends Jaws_Ajax
+{
+    /**
+     * Get messages list
+     *
+     * @access  public
+     * @return  template content
+     */
+    function GetMessages()
+    {
+        $layoutGadget = $GLOBALS['app']->LoadGadget('Chatbox', 'LayoutHTML');
+        $messages = $layoutGadget->GetMessages();
+        _log_var_dump($messages);
+        return $messages;
+    }
+
+}
\ No newline at end of file

Modified: trunk/jaws/html/gadgets/Chatbox/LayoutHTML.php
===================================================================
--- trunk/jaws/html/gadgets/Chatbox/LayoutHTML.php	2012-08-25 17:49:42 UTC (rev 13499)
+++ trunk/jaws/html/gadgets/Chatbox/LayoutHTML.php	2012-08-25 17:50:02 UTC (rev 13500)
@@ -5,6 +5,7 @@
  * @category   GadgetLayout
  * @package    Chatbox
  * @author     Pablo Fischer <pablo at pablo.com.mx>
+ * @author     Ali Fazelzadeh <afz at php.net>
  * @copyright  2004-2012 Jaws Development Group
  * @license    http://www.gnu.org/copyleft/gpl.html
  */
@@ -21,7 +22,6 @@
         $tpl = new Jaws_Template('gadgets/Chatbox/templates/');
         $tpl->Load('Chatbox.html');
         $tpl->SetBlock('chatbox');
-
         $tpl->SetVariable('title', _t('CHATBOX_NAME'));
 
         if ($GLOBALS['app']->Session->Logged() ||
@@ -79,15 +79,33 @@
             $tpl->ParseBlock('chatbox/response');
         }
 
+        $hModel = $GLOBALS['app']->LoadGadget('Chatbox', 'HTML');
+        $hModel->AjaxMe('site_script.js');
+
+        $tpl->SetVariable('chatbox_messages', $this->GetMessages());
+        $tpl->ParseBlock('chatbox');
+        return $tpl->Get();
+    }
+
+    /**
+     * Get the chatbox messages list
+     *
+     * @access       public
+     * @return       template content
+     */
+    function GetMessages()
+    {
         $model = $GLOBALS['app']->LoadGadget('Chatbox', 'Model');
         $entries = $model->GetEntries($GLOBALS['app']->Registry->Get('/gadgets/Chatbox/limit'));
+        if (!Jaws_Error::IsError($entries) && !empty($entries)) {
+            $tpl = new Jaws_Template('gadgets/Chatbox/templates/');
+            $tpl->Load('Chatbox.html');
+            $tpl->SetBlock('messages');
 
-        if (!Jaws_Error::IsError($entries) && count($entries)) {
             $date = $GLOBALS['app']->loadDate();
             $xss  = $GLOBALS['app']->loadClass('XSS', 'Jaws_XSS');
-            $tpl->SetBlock('chatbox/entries');
             foreach ($entries as $entry) {
-                $tpl->SetBlock('chatbox/entries/entry');
+                $tpl->SetBlock('messages/entry');
                 $tpl->SetVariable('name', $xss->filter($entry['name']));
                 $tpl->SetVariable('email', $xss->filter($entry['email']));
                 $tpl->SetVariable('url', $xss->filter($entry['url']));
@@ -100,13 +118,12 @@
                 } else {
                     $tpl->SetVariable('status_message', ' ');
                 }
-                $tpl->ParseBlock('chatbox/entries/entry');
+                $tpl->ParseBlock('messages/entry');
             }
-            $tpl->ParseBlock('chatbox/entries');
+            $tpl->ParseBlock('messages');
         }
-        $tpl->ParseBlock('chatbox');
 
         return $tpl->Get();
     }
 
-}
+}
\ No newline at end of file

Added: trunk/jaws/html/gadgets/Chatbox/resources/site_script.js
===================================================================
--- trunk/jaws/html/gadgets/Chatbox/resources/site_script.js	                        (rev 0)
+++ trunk/jaws/html/gadgets/Chatbox/resources/site_script.js	2012-08-25 17:50:02 UTC (rev 13500)
@@ -0,0 +1,23 @@
+/**
+ * Chatbox Javascript actions
+ *
+ * @category   Ajax
+ * @package    Chatbox
+ * @author     Ali Fazelzadeh <afz at php.net>
+ * @copyright  2012 Jaws Development Group
+ * @license    http://www.gnu.org/copyleft/gpl.html
+ */
+
+/**
+ * Get messages list
+ *
+ */
+function GetMessages()
+{
+    var messages = chatbox.getmessages();
+    $('chatbox_messages').innerHTML = messages;
+}
+
+var chatbox = new chatboxajax();
+chatbox.serverErrorFunc = Jaws_Ajax_ServerError;
+setInterval("GetMessages()", 30*1000);

Modified: trunk/jaws/html/gadgets/Chatbox/templates/Chatbox.html
===================================================================
--- trunk/jaws/html/gadgets/Chatbox/templates/Chatbox.html	2012-08-25 17:49:42 UTC (rev 13499)
+++ trunk/jaws/html/gadgets/Chatbox/templates/Chatbox.html	2012-08-25 17:50:02 UTC (rev 13500)
@@ -2,14 +2,8 @@
 <div class="gadget chatbox">
   <h2>{title}</h2>
   <!-- BEGIN response --><div class="simple-response-msg">{msg}</div><!-- END response -->
-  <div class="content">
-    <!-- BEGIN entries -->
-    <ul>
-      <!-- BEGIN entry -->
-      <li><div><a href="{url}" title="{email}/{updatetime}" rel="external">{name}</a>: {message} <em>{status_message}</em></div></li>
-      <!-- END entry -->
-    </ul>
-    <!-- END entries -->
+  <div class="content" id="chatbox_messages">
+    {chatbox_messages}
   </div>
   <!-- BEGIN fieldset -->
   <form action="{base_script}" method="post">
@@ -42,3 +36,10 @@
   <!-- END unregistered -->
 </div>
 <!-- END chatbox -->
+<!-- BEGIN messages -->
+<ul>
+  <!-- BEGIN entry -->
+  <li><div><a href="{url}" title="{email}/{updatetime}" rel="external">{name}</a>: {message} <em>{status_message}</em></div></li>
+  <!-- END entry -->
+</ul>
+<!-- END messages -->



More information about the Jaws-commits mailing list