From e8041d2c0dfd7414ab7c52e277905e86a96bb5bd Mon Sep 17 00:00:00 2001 From: dongsheng Date: Sat, 15 Aug 2009 11:20:35 +0000 Subject: [PATCH] "MDL-14651, update chat module to work in new API" --- mod/chat/gui_ajax/common.php | 5 +-- mod/chat/gui_ajax/index.php | 26 ++++++----- mod/chat/gui_ajax/script.js | 86 ++++++++++++++++++------------------ mod/chat/gui_ajax/update.php | 6 +-- mod/chat/lib.php | 2 +- mod/chat/view.php | 6 +-- 6 files changed, 67 insertions(+), 64 deletions(-) diff --git a/mod/chat/gui_ajax/common.php b/mod/chat/gui_ajax/common.php index 8f72fb8b7a..32afe33ece 100755 --- a/mod/chat/gui_ajax/common.php +++ b/mod/chat/gui_ajax/common.php @@ -1,17 +1,16 @@ wwwroot.'/user/view.php?id='.$v->id.'&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; } diff --git a/mod/chat/gui_ajax/index.php b/mod/chat/gui_ajax/index.php index 88d30c1fbf..2c35bfc6cb 100644 --- a/mod/chat/gui_ajax/index.php +++ b/mod/chat/gui_ajax/index.php @@ -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 ""; +echo << +#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} + +STY; + echo $OUTPUT->heading($str_title,1); echo << @@ -88,14 +90,14 @@ echo <<
-
    -
+
    +
-
    -
      +
        +
diff --git a/mod/chat/gui_ajax/script.js b/mod/chat/gui_ajax/script.js index 318d6c80a2..9639581a68 100644 --- a/mod/chat/gui_ajax/script.js +++ b/mod/chat/gui_ajax/script.js @@ -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 = ''; } - 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){ diff --git a/mod/chat/gui_ajax/update.php b/mod/chat/gui_ajax/update.php index 26442f9e92..51bbe0c4b7 100755 --- a/mod/chat/gui_ajax/update.php +++ b/mod/chat/gui_ajax/update.php @@ -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'); diff --git a/mod/chat/lib.php b/mod/chat/lib.php index 926e432817..95114c5608 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -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 = "wwwroot/user/view.php?id=$sender->id&course=$courseid')\" href=\"$CFG->wwwroot/user/view.php?id=$sender->id&course=$courseid\">$message->picture"; } diff --git a/mod/chat/view.php b/mod/chat/view.php index ee617f6e06..1c403c873d 100644 --- a/mod/chat/view.php +++ b/mod/chat/view.php @@ -165,14 +165,14 @@ 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 ''; foreach ($chatusers as $chatuser) { $lastping = $timenow - $chatuser->lastmessageping; echo ''; } echo '
'; echo "wwwroot/user/view.php?id=$chatuser->id&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 ''; echo '

'; echo fullname($chatuser).'
'; @@ -181,7 +181,7 @@ echo '

'; - print_simple_box_end(); + $OUTPUT->box_end(); } echo $OUTPUT->footer(); -- 2.39.5