From 7f0483f6cd1320f54148f374c5d74d598c71e6c0 Mon Sep 17 00:00:00 2001 From: dongsheng Date: Wed, 19 Nov 2008 07:32:39 +0000 Subject: [PATCH] CHAT_MOD/MDL-14651 1. click a button to "talk to" a specific user 2. adjust UI layout 3. add more language string --- mod/chat/gui_ajax/index.php | 26 +++++++++++----- mod/chat/gui_ajax/script.js | 62 ++++++++++++++++++++----------------- mod/chat/lib.php | 13 ++++++-- 3 files changed, 62 insertions(+), 39 deletions(-) diff --git a/mod/chat/gui_ajax/index.php b/mod/chat/gui_ajax/index.php index f7f3555686..6763450ab4 100644 --- a/mod/chat/gui_ajax/index.php +++ b/mod/chat/gui_ajax/index.php @@ -3,7 +3,6 @@ require_once('../../../config.php'); require_once('../lib.php'); require_once('common.php'); -$time_start = microtime_float(); $id = required_param('id', PARAM_INT); $groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers if (!$chat = $DB->get_record('chat', array('id'=>$id))) { @@ -22,7 +21,8 @@ $context = get_context_instance(CONTEXT_MODULE, $cm->id); require_login($course->id, false, $cm); require_capability('mod/chat:chat',$context); -if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id))) { +if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id))) +{ print_header(); notice(get_string("activityiscurrentlyhidden")); } @@ -42,13 +42,18 @@ if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_ $groupname = ''; } -$strchat = get_string('modulename', 'chat'); // must be before current_language() in chat_login_user() to force course language!!! -$str_send = get_string('send', 'chat'); -$str_sending = get_string('sending', 'chat'); -$str_title = format_string($course->shortname) . ": ".format_string($chat->name,true).$groupname; +// login chat room if (!$chat_sid = chat_login_user($chat->id, 'ajax', $groupid, $course)) { print_error('cantlogin', 'chat'); } + +// language string +$str_chat = get_string('modulename', 'chat'); // must be before current_language() in chat_login_user() to force course language!!! +$str_send = get_string('send', 'chat'); +$str_sending = get_string('sending', 'chat'); +$str_title = format_string($course->shortname) . ": ".format_string($chat->name,true).$groupname; +$str_inputarea = get_string('inputarea', 'chat'); +$str_userlist = get_string('userlist', 'chat'); ?> @@ -60,8 +65,8 @@ if (!$chat_sid = chat_login_user($chat->id, 'ajax', $groupid, $course)) { $USER->id, 'sid'=>$chat_sid,'timer'=>5000, 'chat_lasttime'=>0,'chat_lastrow'=>null,'header_title'=>$strchat,'chatroom_name'=>$str_title), 'chat_cfg'); -print_js_config(array('send'=>$str_send, 'sending'=>$str_sending), 'chat_lang'); +print_js_config(array('userid'=>$USER->id, 'sid'=>$chat_sid,'timer'=>5000, 'chat_lasttime'=>0,'chat_lastrow'=>null,'header_title'=>$str_chat,'chatroom_name'=>$str_title), 'chat_cfg'); +print_js_config(array('send'=>$str_send, 'sending'=>$str_sending, 'inputarea'=>$str_inputarea, 'userlist'=>$str_userlist), 'chat_lang'); ?> @@ -74,6 +79,11 @@ print_js_config(array('send'=>$str_send, 'sending'=>$str_sending), 'chat_lang'); +
diff --git a/mod/chat/gui_ajax/script.js b/mod/chat/gui_ajax/script.js index d74b2c9a6d..15bc3adc6a 100644 --- a/mod/chat/gui_ajax/script.js +++ b/mod/chat/gui_ajax/script.js @@ -1,3 +1,8 @@ +// record msg IDs +var msgs = []; +var interval = null; +var scrollable = true; + (function() { var Dom = YAHOO.util.Dom, Event = YAHOO.util.Event; // window.onload @@ -6,8 +11,8 @@ Event.onDOMReady(function() { var layout = new YAHOO.widget.Layout({ units: [ { position: 'top', height: 60, body: 'chat_header', header: chat_cfg.header_title, gutter: '5px', collapse: true, resize: false }, - { position: 'right', header: 'User List', width: 300, resize: true, gutter: '5px', footer: null, collapse: true, scroll: true, body: 'chat_user_list', animate: false }, - { position: 'bottom', header: 'Input Area', height: 60, resize: true, body: 'chat_input', gutter: '5px', collapse: false }, + { position: 'right', header: chat_lang.userlist, width: 180, resize: true, gutter: '5px', footer: null, collapse: true, scroll: true, body: 'chat_user_list', animate: false }, + { position: 'bottom', header: chat_lang.inputarea, height: 60, resize: true, body: 'chat_input', gutter: '5px', collapse: false, resize: false }, //{ position: 'left', header: 'Options', width: 200, resize: true, body: 'chat_options', gutter: '5px', collapse: true, close: true, collapseSize: 50, scroll: true, animate: false }, { position: 'center', body: 'chat_panel', gutter: '5px', scroll: true } ] @@ -28,7 +33,7 @@ Event.onDOMReady(function() { }); Event.on('chat_panel', 'mouseout', function(ev) { Event.stopEvent(ev); - scrollable = false; + scrollable = true; }); var key_send = new YAHOO.util.KeyListener(document, { keys:13 }, {fn:send_msg, correctScope:true }); key_send.enable(); @@ -42,6 +47,23 @@ Event.onDOMReady(function() { }, chat_cfg.timer); }); })(); + +function in_array(f, t){ + var a = false; + for( var i = 0; i Beep '; + html += ''+ users[i].name+'
'; + html += '
Talk '; + html += 'Beep'; html += ''; el.innerHTML = html; - console.info(el.innerHTML); list.appendChild(el); } } - function update_info() { if(!chat_cfg.req_count){ chat_cfg.req_count = 1; } else { chat_cfg.req_count++; } - console.info(chat_cfg.req_count); + console.info('Update count: '+chat_cfg.req_count); var url = "update.php?chat_sid="+chat_cfg.sid+"&chat_lasttime="+chat_cfg.chat_lasttime; if(chat_cfg.chat_lastrow != null){ url += "&chat_lastrow="+chat_cfg.chat_lastrow; @@ -96,7 +113,7 @@ function update_info() { function append_msg(msg) { var list = document.getElementById('msg_list'); var el = document.createElement('li'); - console.info(msg); + console.info('New message:'+msg); el.innerHTML = msg.msg; if(msg.type && msg.type == 'beep'){ document.getElementById('notify').innerHTML = ''; @@ -140,13 +157,14 @@ success: function(o){ if(!in_array(key, msgs)){ msgs.push(key); append_msg(data['msgs'][key]); - console.log(data['msgs'][key]); } } // update users update_users(data['users']); // scroll to the bottom of the message list - document.getElementById('chat_panel').parentNode.scrollTop+=500; + if(scrollable){ + document.getElementById('chat_panel').parentNode.scrollTop+=500; + } } } var init_cb = { @@ -157,23 +175,11 @@ var init_cb = { return; } if (data.users) { - console.info(data); update_users(data.users); } } } -function in_array(f, t){ - var a = false; - for( var i = 0; iget_record('chat_users', array('chatid'=>$chatid, 'userid'=>$USER->id, 'groupid'=>$groupid))) { + // this will update logged user information $chatuser->version = $version; $chatuser->ip = $USER->lastip; $chatuser->lastping = time(); @@ -495,8 +496,7 @@ function chat_login_user($chatid, $version, $groupid, $course) { } } - if (($chatuser->course != $course->id) - or ($chatuser->userid != $USER->id)) { + if (($chatuser->course != $course->id) or ($chatuser->userid != $USER->id)) { return false; } if (!$DB->update_record('chat_users', $chatuser)) { @@ -540,7 +540,8 @@ function chat_login_user($chatid, $version, $groupid, $course) { $message->system = 1; $message->timestamp = time(); - if (!$DB->insert_record('chat_messages', $message) || !$DB->insert_record('chat_messages_current', $message)) { + if (!$DB->insert_record('chat_messages', $message) || !$DB->insert_record('chat_messages_current', $message)) + { print_error('cantinsert', 'chat'); } } @@ -723,6 +724,12 @@ function chat_format_message_manually($message, $courseid, $sender, $currentuser $outmain = '*** '.$sender->firstname.' '.substr($text, 4).''; break; } + } elseif (substr($text, 0, 2) == 'To') { + $pattern = '#To[[:space:]](.*):(.*)#'; + preg_match($pattern, trim($text), $matches); + $special = true; + $outinfo = $message->strtime; + $outmain = $sender->firstname.' '.get_string('saidto', 'chat').' '.$matches[1].': '.$matches[2]; } if(!$special) { -- 2.39.5