]> git.mjollnir.org Git - moodle.git/commitdiff
CHAT_MOD/MDL-14651
authordongsheng <dongsheng>
Wed, 19 Nov 2008 07:32:39 +0000 (07:32 +0000)
committerdongsheng <dongsheng>
Wed, 19 Nov 2008 07:32:39 +0000 (07:32 +0000)
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
mod/chat/gui_ajax/script.js
mod/chat/lib.php

index f7f3555686e2e55ee455ad099d2bd3809536c925..6763450ab4458ca8083217cd83c5a9747e790728 100644 (file)
@@ -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');
 ?>
 <html>
 <head>
@@ -60,8 +65,8 @@ if (!$chat_sid = chat_login_user($chat->id, 'ajax', $groupid, $course)) {
 <link rel="stylesheet" type="text/css" href="<?php echo $CFG->httpswwwroot;?>/lib/yui/layout/assets/skins/sam/layout.css" />
 <link rel="stylesheet" type="text/css" href="<?php echo $CFG->httpswwwroot;?>/lib/yui/button/assets/skins/sam/button.css" />
 <?php
-print_js_config(array('userid'=>$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');
 ?>
 <script type="text/javascript" src="<?php echo $CFG->httpswwwroot;?>/lib/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
 <script type="text/javascript" src="<?php echo $CFG->httpswwwroot;?>/lib/yui/element/element-beta-min.js"></script>
@@ -74,6 +79,11 @@ print_js_config(array('send'=>$str_send, 'sending'=>$str_sending), 'chat_lang');
 <script type="text/javascript" src="<?php echo $CFG->httpswwwroot;?>/lib/yui/button/button-min.js"></script>
 <script type="text/javascript" src="<?php echo $CFG->httpswwwroot;?>/lib/yui/selector/selector-beta-min.js"></script>
 <script type="text/javascript" src="script.js"></script>
+<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>
 </head>
 <body class=" yui-skin-sam">
 <div id="chat_header">
index d74b2c9a6d9e120c13cdde88e351649eadd37f0f..15bc3adc6ae1c2507d7d9408f9eeb9c781b997df 100644 (file)
@@ -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<t.length; i++){
+        if(f==t[i]){
+            a=true;
+            break;
+        }
+    }
+    return a;
+}
+
+function talkto(name) {
+    var msg = document.getElementById('input_msgbox');
+    msg.value = "To "+name+": ";
+    msg.focus();
+}
 function send_msg() {
     var msg = document.getElementById('input_msgbox').value;
     var el_send = document.getElementById('btn_send');
@@ -57,36 +79,31 @@ 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);
 }
-
-// record msg IDs
-var msgs = [];
-var interval = null;
-var scrollable = true;
-
 function update_users(users) {
     if(!users){
         return;
     }
     var list = document.getElementById('listing');
+    list.innerHTML = '';
     var html = '';
     for(var i in users){
         var el = document.createElement('li');
         html += '<table><tr><td>' + users[i].picture + '</td><td>'
-        html += users[i].name+'<br/><a href="###" onclick="send_beep('+users[i].id+')"> Beep </a>';
+        html += '<a target="_blank" href="'+users[i].url+'">'+ users[i].name+'<br/>';
+        html += '<a href="###" onclick="talkto(\''+users[i].name+'\')">Talk</a> ';
+        html += '<a href="###" onclick="send_beep('+users[i].id+')">Beep</a>';
         html += '</td></tr></table>';
         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 = '<embed src="../beep.wav" autostart="true" hidden="true" name="beep" />';
@@ -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; i<t.length; i++){
-        if(f==t[i]){
-            a=true;
-            break;
-        }
-    }
-    return a;
-}
-
 // debug code
 if(!console){
     var console = {
index 5e1bdadf28053c59b8f60650a6d9469e65221193..56714c33e6c0c15b5bd480df35b5a7aea5015727 100644 (file)
@@ -480,6 +480,7 @@ function chat_login_user($chatid, $version, $groupid, $course) {
     global $USER, $DB;
 
     if (($version != 'sockets') and $chatuser = $DB->get_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 = '*** <b>'.$sender->firstname.' '.substr($text, 4).'</b>';
             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').' <i>'.$matches[1].'</i>: '.$matches[2];
     }
 
     if(!$special) {