]> git.mjollnir.org Git - moodle.git/commitdiff
"MDL-14651, update chat module to work in new API"
authordongsheng <dongsheng>
Sat, 15 Aug 2009 11:20:35 +0000 (11:20 +0000)
committerdongsheng <dongsheng>
Sat, 15 Aug 2009 11:20:35 +0000 (11:20 +0000)
mod/chat/gui_ajax/common.php
mod/chat/gui_ajax/index.php
mod/chat/gui_ajax/script.js
mod/chat/gui_ajax/update.php
mod/chat/lib.php
mod/chat/view.php

index 8f72fb8b7aa49ca191706da7bc1b841ef3e375f7..32afe33eceee2482cb4c52789b0409eab269ebf1 100755 (executable)
@@ -1,17 +1,16 @@
 <?php
-
 function microtime_float(){
     list($usec, $sec) = explode(" ", microtime());
     return ((float)$usec+(float)$sec);
 }
 
 function format_user_list($data, $course) {
-    global $CFG, $DB;
+    global $CFG, $DB, $COURSE;
     $users = array();
     foreach($data as $v){
         $user['name'] = fullname($v);
         $user['url'] = $CFG->wwwroot.'/user/view.php?id='.$v->id.'&amp;course='.$course->id;
-        $user['picture'] = print_user_picture($v->id, 0, $v->picture, false, true, false);
+        $user['picture'] = print_user_picture($v->id, $COURSE->id, $v->picture, false, true, false);
         $user['id'] = $v->id;
         $users[] = $user;
     }
index 88d30c1fbfc7934014def5ded7298203166a1c10..2c35bfc6cb87b50efa02a2641272e30c51484797 100644 (file)
@@ -57,8 +57,6 @@ $str_userlist  = get_string('userlist',  'chat');
 $PAGE->set_generaltype('popup');
 $PAGE->set_title('Chat');
 
-$PAGE->requires->yui_lib('dom');
-$PAGE->requires->yui_lib('element');
 $PAGE->requires->yui_lib('dragdrop');
 $PAGE->requires->yui_lib('resize');
 $PAGE->requires->yui_lib('layout');
@@ -72,13 +70,17 @@ $PAGE->requires->data_for_js('chat_lang', array('send'=>$str_send, 'sending'=>$s
 $PAGE->requires->js('mod/chat/gui_ajax/script.js');
 $PAGE->add_body_class('yui-skin-sam');
 
-$PAGE->requires->css('lib/yui/reset-fonts-grids/reset-fonts-grids.css');
-$PAGE->requires->css('lib/yui/resize/assets/skins/sam/resize.css');
-$PAGE->requires->css('lib/yui/layout/assets/skins/sam/layout.css');
-$PAGE->requires->css('lib/yui/button/assets/skins/sam/button.css');
-
 echo $OUTPUT->header();
-echo "<style type='text/css'> #listing a{text-decoration:none;color:gray} #listing a:hover {text-decoration:underline;color:white;background:blue} #listing{padding: .5em}</style>";
+echo <<<STY
+<style type='text/css'>
+#messageslist{list-style-type:none;padding:0;margin:0}
+#listing a{text-decoration:none;color:gray}
+#listing a:hover {text-decoration:underline;color:white;background:blue}
+#listing{padding: .5em}
+h2{margin:0}
+</style>
+STY;
+
 echo $OUTPUT->heading($str_title,1);
 echo <<<DIVS
 <div id="chat_header">
@@ -88,14 +90,14 @@ echo <<<DIVS
     <input type="button" id="btn_send" value="$str_send" />
 </div>
 <div id="chat_user_list">
-<ul id="listing">
-</ul>
+    <ul id="listing">
+    </ul>
 </div>
 <div id="chat_options">
 </div>
 <div id="chat_panel">
-<ul id="msg_list">
-<ul>
+    <ul id="messageslist">
+    <ul>
 </div>
 <div id="notify">
 </div>
index 318d6c80a2e5b49bacb359dd41f7781ef3c6f0d8..9639581a68f0a813dc1366f50be456c69f531c40 100644 (file)
@@ -25,7 +25,7 @@ Event.onDOMReady(function() {
     layout.render();
     Event.on('btn_send', 'click', function(ev) {
         Event.stopEvent(ev);
-        send_msg();
+        send_message();
     });
     Event.on('chat_panel', 'mouseover', function(ev) {
         Event.stopEvent(ev);
@@ -35,15 +35,27 @@ Event.onDOMReady(function() {
         Event.stopEvent(ev);
         scrollable = true;
     });
-    var key_send = new YAHOO.util.KeyListener(document, { keys:13 }, {fn:send_msg, correctScope:true });
+    var key_send = new YAHOO.util.KeyListener(document, { keys:13 }, {fn:send_message, correctScope:true });
     key_send.enable();
     document.getElementById('input_msgbox').focus();
     document.title = chat_cfg.chatroom_name;
 
-    // done build layout
-    var transaction = YAHOO.util.Connect.asyncRequest('POST', "update.php?chat_sid="+chat_cfg.sid+"&chat_init=1", init_cb, null);
+
+    this.cb = {
+        success: function(o){
+            if(o.responseText){
+                var data = YAHOO.lang.JSON.parse(o.responseText);
+            } else {
+                return;
+            }
+            if (data.users) {
+                update_users(data.users);
+            }
+        }
+    }
+    var transaction = YAHOO.util.Connect.asyncRequest('POST', "update.php?chat_sid="+chat_cfg.sid+"&chat_init=1", this.cb, null);
     interval = setInterval(function(){
-        update_info();
+        update_messages();
     }, chat_cfg.timer);
 });
 })();
@@ -64,21 +76,38 @@ function talkto(name) {
     msg.value = "To "+name+": ";
     msg.focus();
 }
-function send_msg() {
+
+function send_message() {
     var msg = document.getElementById('input_msgbox').value;
     var el_send = document.getElementById('btn_send');
     if (!msg) {
-        alert('null?');
+        alert('Empty message not allowed');
         return;
     }
     var url = 'post.php?chat_sid='+chat_cfg.sid;
     el_send.value = chat_lang.sending;
-    var a = YAHOO.util.Connect.asyncRequest('POST', url, send_cb, "chat_message="+msg);
+    var trans = YAHOO.util.Connect.asyncRequest('POST', url, send_cb, "chat_message="+msg);
 }
 function send_beep(id){
     var url = 'post.php?chat_sid='+chat_cfg.sid;
-    var a = YAHOO.util.Connect.asyncRequest('POST', url, send_cb, "beep="+id);
+    var trans = YAHOO.util.Connect.asyncRequest('POST', url, send_cb, "beep="+id);
+}
+
+var send_cb = {
+    success: function(o) {
+        if(o.responseText == 200){
+            document.getElementById('btn_send').value = chat_lang.send;
+            document.getElementById('input_msgbox').value = '';
+        }
+        clearInterval(interval)
+        update_messages();
+        interval = setInterval(function(){
+            update_messages();
+        }, chat_cfg.timer);
+        document.getElementById('input_msgbox').focus();
+    }
 }
+
 function update_users(users) {
     if(!users){
         return;
@@ -97,7 +126,7 @@ function update_users(users) {
         list.appendChild(el);
     }
 }
-function update_info() {
+function update_messages() {
     if(!chat_cfg.req_count){
         chat_cfg.req_count = 1;
     } else {
@@ -108,32 +137,17 @@ function update_info() {
     if(chat_cfg.chat_lastrow != null){
         url += "&chat_lastrow="+chat_cfg.chat_lastrow;
     }
-    var a = YAHOO.util.Connect.asyncRequest('POST', url, update_cb, null);
+    var trans = YAHOO.util.Connect.asyncRequest('POST', url, update_cb, null);
 }
 function append_msg(msg) {
-    var list = document.getElementById('msg_list');
-    var el = document.createElement('li');
+    var list = document.getElementById('messageslist');
+    var item = document.createElement('li');
     console.info('New message:'+msg.msg);
-    el.innerHTML = msg.msg;
+    item.innerHTML = msg.msg;
     if(msg.type && msg.type == 'beep'){
         document.getElementById('notify').innerHTML = '<embed src="../beep.wav" autostart="true" hidden="true" name="beep" />';
     }
-    list.appendChild(el);
-}
-
-var send_cb = {
-    success: function(o) {
-        if(o.responseText == 200){
-         document.getElementById('btn_send').value = chat_lang.send;
-         document.getElementById('input_msgbox').value = '';
-        }
-        clearInterval(interval)
-        update_info();
-        interval = setInterval(function(){
-            update_info();
-        }, chat_cfg.timer);
-        document.getElementById('input_msgbox').focus();
-    }
+    list.appendChild(item);
 }
 var update_cb = {
 success: function(o){
@@ -173,18 +187,6 @@ success: function(o){
     }
 }
 }
-var init_cb = {
-    success: function(o){
-        if(o.responseText){
-            var data = YAHOO.lang.JSON.parse(o.responseText);
-        } else {
-            return;
-        }
-        if (data.users) {
-            update_users(data.users);
-        }
-    }
-}
 
 // debug code
 if(!console){
index 26442f9e926001c312b1beaaf0679a5ad0e2ec19..51bbe0c4b73d8785df566b69b96a9284bbd03c3a 100755 (executable)
@@ -7,9 +7,9 @@
 
 define('NO_MOODLE_COOKIES', true); // session not used here
 
-require_once('../../../config.php');
-require_once('../lib.php');
-require_once('common.php');
+require_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php');
+require_once(dirname(dirname(__FILE__)) . '/lib.php');
+require_once(dirname(__FILE__) . '/common.php');
 
 ob_start();
 header('Expires: Sun, 28 Dec 1997 09:32:45 GMT');
index 926e4328177a577c799954ba02a178b22a36a43b..95114c5608224a9ce1da4d0ff0888f1bd228b445 100644 (file)
@@ -777,7 +777,7 @@ function chat_format_message_manually($message, $courseid, $sender, $currentuser
     $USER->timezone = $tz;
     $message->strtime = userdate($message->timestamp, get_string('strftimemessage', 'chat'), $tz);
 
-    $message->picture = print_user_picture($sender->id, 0, $sender->picture, false, true, false);
+    $message->picture = print_user_picture($sender->id, $courseid, $sender->picture, false, true, false);
     if ($courseid) {
         $message->picture = "<a onclick=\"window.open('$CFG->wwwroot/user/view.php?id=$sender->id&amp;course=$courseid')\" href=\"$CFG->wwwroot/user/view.php?id=$sender->id&amp;course=$courseid\">$message->picture</a>";
     }
index ee617f6e06d2cda4eced07168b0a0d2e31d6e861..1c403c873d4b0b2bff21547f2b7626c94353687c 100644 (file)
 
     if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) {
         $timenow = time();
-        print_simple_box_start('center');
+        $OUTPUT->box_start('generalbox');
         echo $OUTPUT->heading($strcurrentusers);
         echo '<table id="chatcurrentusers">';
         foreach ($chatusers as $chatuser) {
             $lastping = $timenow - $chatuser->lastmessageping;
             echo '<tr><td class="chatuserimage">';
             echo "<a href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&amp;course=$chat->course\">";
-            print_user_picture($chatuser, 0, $chatuser->picture, false, false, false);
+            print_user_picture($chatuser, $COURSE->id, $chatuser->picture, false, false, false);
             echo '</a></td><td class="chatuserdetails">';
             echo '<p>';
             echo fullname($chatuser).'<br />';
             echo '</td></tr>';
         }
         echo '</table>';
-        print_simple_box_end();
+        $OUTPUT->box_end();
     }
 
     echo $OUTPUT->footer();