From 75d07096d30b4fc44a67c3b349ff24bb4116def9 Mon Sep 17 00:00:00 2001 From: dongsheng Date: Thu, 8 Oct 2009 06:37:00 +0000 Subject: [PATCH] "MDL-14651, improved chat module interface" --- lang/en_utf8/chat.php | 1 + mod/chat/chat_ajax.php | 18 +- mod/chat/gui_ajax/index.php | 54 ++-- mod/chat/gui_ajax/script.js | 66 +++-- mod/chat/gui_ajax/theme/bubble/bubbles.png | Bin 0 -> 1668 bytes mod/chat/gui_ajax/theme/bubble/chat.css | 37 +++ mod/chat/gui_ajax/theme/bubble/config.php | 73 ++++++ mod/chat/gui_ajax/theme/bubble/horizontal.png | Bin 0 -> 357 bytes mod/chat/gui_ajax/theme/bubble/input.png | Bin 0 -> 182 bytes mod/chat/gui_ajax/theme/bubble/vertical.png | Bin 0 -> 232 bytes mod/chat/gui_ajax/theme/compact/chat.css | 51 ++++ mod/chat/gui_ajax/theme/compact/config.php | 22 ++ mod/chat/lib.php | 232 ++++++++++++++---- mod/chat/view.php | 4 +- theme/standard/styles_layout.css | 44 ++-- 15 files changed, 486 insertions(+), 116 deletions(-) create mode 100755 mod/chat/gui_ajax/theme/bubble/bubbles.png create mode 100755 mod/chat/gui_ajax/theme/bubble/chat.css create mode 100755 mod/chat/gui_ajax/theme/bubble/config.php create mode 100755 mod/chat/gui_ajax/theme/bubble/horizontal.png create mode 100755 mod/chat/gui_ajax/theme/bubble/input.png create mode 100755 mod/chat/gui_ajax/theme/bubble/vertical.png create mode 100755 mod/chat/gui_ajax/theme/compact/chat.css create mode 100755 mod/chat/gui_ajax/theme/compact/config.php diff --git a/lang/en_utf8/chat.php b/lang/en_utf8/chat.php index ca5a09a0d7..ea1cf3bc71 100644 --- a/lang/en_utf8/chat.php +++ b/lang/en_utf8/chat.php @@ -40,6 +40,7 @@ $string['helpchatting'] = 'Help with chatting'; $string['idle'] = 'Idle'; $string['invalidid'] = 'Could not find that chat room!'; $string['inputarea'] = 'Input area'; +$string['messageyoubeep'] = 'You beeped $a'; $string['messagebeepseveryone'] = '$a beeps everyone!'; $string['messagebeepsyou'] = '$a has just beeped you!'; $string['messageenter'] = '$a has just entered this chat'; diff --git a/mod/chat/chat_ajax.php b/mod/chat/chat_ajax.php index 6af584f6a0..bee3580d0b 100644 --- a/mod/chat/chat_ajax.php +++ b/mod/chat/chat_ajax.php @@ -20,6 +20,7 @@ require_once(dirname(__FILE__) . '/lib.php'); $action = optional_param('action', '', PARAM_ALPHANUM); $beep_id = optional_param('beep', '', PARAM_RAW); $chat_sid = required_param('chat_sid', PARAM_ALPHANUM); +$theme = required_param('theme', PARAM_ALPHANUM); $chat_message = optional_param('chat_message', '', PARAM_RAW); $chat_lasttime = optional_param('chat_lasttime', 0, PARAM_INT); $chat_lastrow = optional_param('chat_lastrow', 1, PARAM_INT); @@ -124,22 +125,15 @@ case 'update': foreach ($messages as $n => &$message) { $tmp = new stdclass; // when somebody enter room, user list will be updated - if($message->system == 1){ + if (!empty($message->system)){ $send_user_list = true; - $tmp->type = 'system'; $users = chat_format_userlist(chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid), $course); } - if ($html = chat_format_message($message, $chatuser->course, $USER, $chat_lastrow)) { - if ($html->beep) { - $tmp->type = 'beep'; - } elseif (empty($tmp->type)) { - $tmp->type = 'user'; - } - $tmp->mymessage = ($USER->id == $message->userid); - $tmp->msg = $html->html; - $message = $tmp; + if ($html = chat_format_message_theme($message, $chatuser->course, $USER, $theme)) { + $message->mymessage = ($USER->id == $message->userid); + $message->message = $html->html; } else { - unset($message); + unset($messages[$n]); } } } diff --git a/mod/chat/gui_ajax/index.php b/mod/chat/gui_ajax/index.php index 83987ece14..7d69560d17 100644 --- a/mod/chat/gui_ajax/index.php +++ b/mod/chat/gui_ajax/index.php @@ -1,15 +1,16 @@ wwwroot.'/mod/chat/gui_ajax/index.php', array('id'=>$id)); if ($groupid !== 0) { $url->param('groupid', $groupid); } $PAGE->set_url($url); - if (!$chat = $DB->get_record('chat', array('id'=>$id))) { print_error('invalidid', 'chat'); } @@ -53,6 +54,7 @@ if (!$chat_sid = chat_login_user($chat->id, 'ajax', $groupid, $course)) { $str_title = format_string($course->shortname) . ": ".format_string($chat->name,true).$groupname; $str_send = get_string('send', 'chat'); +$str_themes = get_string('themes'); $PAGE->set_generaltype('popup'); $PAGE->set_title('Chat'); @@ -62,13 +64,19 @@ $PAGE->requires->yui_lib('layout'); $PAGE->requires->yui_lib('container'); $PAGE->requires->yui_lib('connection'); $PAGE->requires->yui_lib('json'); -$PAGE->requires->yui_lib('button'); -$PAGE->requires->yui_lib('selector'); +$PAGE->requires->yui_lib('animation'); +$PAGE->requires->yui_lib('menu'); + +if (!file_exists(dirname(__FILE__) . '/theme/'.$theme.'/chat.css')) { + $theme = 'bubble'; +} $PAGE->requires->data_for_js('chat_cfg', array( 'home'=>$CFG->httpswwwroot.'/mod/chat/view.php?id='.$cm->id, + 'chaturl'=>$CFG->httpswwwroot.'/mod/chat/gui_ajax/index.php?id='.$id, + 'theme'=>$theme, 'userid'=>$USER->id, 'sid'=>$chat_sid, - 'timer'=>5000, + 'timer'=>3000, 'chat_lasttime'=>0, 'chat_lastrow'=>null, 'chatroom_name'=>$str_title @@ -84,38 +92,44 @@ $PAGE->requires->string_for_js('talk', 'chat'); $PAGE->requires->js('mod/chat/gui_ajax/script.js'); $PAGE->requires->yui_lib('animation')->in_head(); -$PAGE->requires->css('mod/chat/chat.css'); +$PAGE->requires->css('mod/chat/gui_ajax/theme/'.$theme.'/chat.css'); $PAGE->add_body_class('yui-skin-sam'); +$PAGE->set_generaltype('embedded'); echo $OUTPUT->header(); -echo $OUTPUT->heading($str_title, 1); $intro = format_text($chat->intro, $chat->introformat); +$home_url = $CFG->httpswwwroot.'/mod/chat/gui_ajax/index.php?id='.$id; echo << -{$chat->name} {$intro} +{$chat->name}

{$intro}

+-->
    -
-
-
+
-
-
    -
  • -
      -
-
-
- - +
-
+
+ + + + + +
+ » + + + + {$str_themes} ▶ +
+
DIVS; echo $OUTPUT->footer(); ?> diff --git a/mod/chat/gui_ajax/script.js b/mod/chat/gui_ajax/script.js index 550d83a9eb..a0c848e7ec 100644 --- a/mod/chat/gui_ajax/script.js +++ b/mod/chat/gui_ajax/script.js @@ -1,5 +1,3 @@ -// record msg IDs - YAHOO.namespace('moodle.chat'); YAHOO.moodle.chat.api = moodle_cfg.wwwroot+'/mod/chat/chat_ajax.php'; YAHOO.moodle.chat.interval = null; @@ -7,17 +5,17 @@ YAHOO.moodle.chat.chat_input_element = null; YAHOO.moodle.chat.msgs = []; YAHOO.moodle.chat.scrollable = true; + (function() { var Dom = YAHOO.util.Dom, Event = YAHOO.util.Event; // window.onload Event.onDOMReady(function() { - // build layout var layout = new YAHOO.widget.Layout({ units: [ - { position: 'top', height: 50, body: 'chat-header', gutter: '5px', resize: false }, + //{ position: 'top', height: 50, body: 'chat-header', gutter: '5px', resize: false }, { position: 'right', width: 180, resize: true, gutter: '5px', scroll: true, body: 'chat-userlist', animate: false }, - { position: 'bottom', height: 42, resize: false, 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: 'bottom', height: 42, resize: false, body: 'chat-input-area', 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-messages', gutter: '5px', scroll: true } ] }); @@ -27,7 +25,7 @@ Event.onDOMReady(function() { }); }); layout.render(); - Event.on('btn_send', 'click', function(ev) { + Event.on('button-send', 'click', function(ev) { Event.stopEvent(ev); YAHOO.moodle.chat.send_message(); }); @@ -39,7 +37,7 @@ Event.onDOMReady(function() { Event.stopEvent(ev); YAHOO.moodle.chat.scrollable = true; }); - YAHOO.moodle.chat.chat_input_element = document.getElementById('input_msgbox'); + YAHOO.moodle.chat.chat_input_element = document.getElementById('input-message'); YAHOO.moodle.chat.chat_input_element.onkeypress = function(ev) { var e = (ev)?ev:event; if (e.keyCode == 13) { @@ -51,6 +49,9 @@ Event.onDOMReady(function() { this.cb = { success: function(o){ YAHOO.moodle.chat.chat_input_element.focus(); + document.getElementById('input-message').disabled = false; + document.getElementById('input-message').value = ''; + document.getElementById('input-message').focus(); if(o.responseText){ var data = YAHOO.lang.JSON.parse(o.responseText); } else { @@ -63,10 +64,22 @@ Event.onDOMReady(function() { params.action = 'init'; params.chat_init = 1; params.chat_sid = chat_cfg.sid; + params.theme = chat_cfg.theme; var trans = YAHOO.util.Connect.asyncRequest('POST', YAHOO.moodle.chat.api, this.cb, build_querystring(params)); YAHOO.moodle.chat.interval = setInterval(function(){ YAHOO.moodle.chat.update_messages(); }, chat_cfg.timer); + var oMenu = new YAHOO.widget.Menu("basicmenu", { xy:[0,0] }); + oMenu.addItems([ + { text: "Bubble", url: chat_cfg.chaturl+'&theme=bubble'}, + { text: "Compact", url: chat_cfg.chaturl+'&theme=compact'}, + ]); + oMenu.render(document.body); + YAHOO.util.Event.addListener('choosetheme', 'click', function(e) { + var position = YAHOO.util.Event.getXY(e); + oMenu.moveTo(position[0]-120, position[1]-70); + oMenu.show(); + }); }); })(); @@ -82,7 +95,7 @@ function in_array(f, t){ } YAHOO.moodle.chat.talkto = function(name) { - var msg = document.getElementById('input_msgbox'); + var msg = document.getElementById('input-message'); msg.value = "To "+name+": "; msg.focus(); } @@ -90,8 +103,8 @@ YAHOO.moodle.chat.talkto = function(name) { YAHOO.moodle.chat.send_callback = { success: function(o) { if(o.responseText == 200){ - document.getElementById('btn_send').value = mstr.chat.send; - document.getElementById('input_msgbox').value = ''; + document.getElementById('button-send').value = mstr.chat.send; + document.getElementById('input-message').value = ''; } clearInterval(YAHOO.moodle.chat.interval) @@ -99,20 +112,20 @@ YAHOO.moodle.chat.send_callback = { YAHOO.moodle.chat.interval = setInterval(function(){ YAHOO.moodle.chat.update_messages(); }, chat_cfg.timer); - //document.getElementById('input_msgbox').focus(); + //document.getElementById('input-message').focus(); } } YAHOO.moodle.chat.send_message = function(ev) { - var msg = document.getElementById('input_msgbox').value; - var el_send = document.getElementById('btn_send'); + var msg = document.getElementById('input-message').value; + var el_send = document.getElementById('button-send'); if (!msg) { - alert('Empty message not allowed'); return; } el_send.value = mstr.chat.sending; var params = {}; params.chat_message=msg; params.chat_sid=chat_cfg.sid; + params.theme = chat_cfg.theme; var trans = YAHOO.util.Connect.asyncRequest('POST', YAHOO.moodle.chat.api+"?action=chat", YAHOO.moodle.chat.send_callback, build_querystring(params)); } @@ -121,6 +134,7 @@ YAHOO.moodle.chat.send_beep = function(user_id) { var params = {}; params.chat_sid = chat_cfg.sid; params.beep=user_id; + params.theme = chat_cfg.theme; var trans = YAHOO.util.Connect.asyncRequest('POST', YAHOO.moodle.chat.api+"?action=chat", YAHOO.moodle.chat.send_callback, build_querystring(params)); } @@ -137,9 +151,16 @@ YAHOO.moodle.chat.update_users = function(users) { html += ''; html += '' + users[i].picture + ''; html += ''; - html += ' '+ users[i].name+'
'; - html += '
'+mstr.chat.talk+' '; - html += ' '+mstr.chat.beep+''; + if (users[i].id==chat_cfg.userid) { + html += ' '+ users[i].name+''; + } else { + html += ' '+ users[i].name+''; + } + html += '
'; + if (users[i].id!=chat_cfg.userid) { + html += ' '+mstr.chat.talk+' '; + html += ' '+mstr.chat.beep+''; + } html += ''; html += ''; html += ''; @@ -160,6 +181,7 @@ YAHOO.moodle.chat.update_messages = function() { } params.chat_lasttime = chat_cfg.chat_lasttime; params.chat_sid = chat_cfg.sid; + params.theme = chat_cfg.theme; var trans = YAHOO.util.Connect.asyncRequest('POST', YAHOO.moodle.chat.api+"?action=update", YAHOO.moodle.chat.update_cb, build_querystring(params)); } @@ -184,14 +206,14 @@ YAHOO.moodle.chat.append_msg = function(key, msg, row) { } else { item.className = 'mdl-chat-entry'; } - item.innerHTML = msg.msg; - if(msg.type && msg.type == 'beep'){ - document.getElementById('notify').innerHTML = ''; + item.innerHTML = msg.message; + if(msg.type && msg.type == 'beep') { + document.getElementById('chat-notify').innerHTML = ''; } list.appendChild(item); if (!row) { var anim = new YAHOO.util.ColorAnim(item.id, YAHOO.moodle.chat.oddmsg_cfg); - anim.animate(); + //anim.animate(); } if (msg.mymessage) { //var anim = new YAHOO.util.ColorAnim(item.id, YAHOO.moodle.chat.mymsg_cfg); diff --git a/mod/chat/gui_ajax/theme/bubble/bubbles.png b/mod/chat/gui_ajax/theme/bubble/bubbles.png new file mode 100755 index 0000000000000000000000000000000000000000..e81653b9c8ba073d5a2f61c1fb0e405d9849c787 GIT binary patch literal 1668 zcmV-~27CF5P) z{f^G^eAM)d+Vz#P$$iT0eZ<7X<^8L~>2S2PwAA;4x3{;fx{c%im#M>ZpuFMd;-{1TD`~Cg>@$vEa`1r%=Z1nW>?(XjF?CkgV_q*a_gvzum&fLTlqc$;t2U z@6yuJ%kX%}$jI2(*z@!A?d|QW&{p05km2Fs%*@P=utDD5-p}%X;NalR&CT8E!otGB zo3C!!+1Z_`fyv&N-~N=&=9k;s+l;P3psa?QoSTV>iP7_d;s2S`<*l5uZQA^f!{mAA z{kH4t>yffXqN1XkzD=FKPTBd5-v5!)^oGmJ%fIAmy5C~G!L;@D_1NaPfPjG0*3H-3 z&$!=T!RKs?tU;TmgW}@i%50?!g2w4}tjuMz*I>QTjm^}&rpZ>Q%v7`4VA1l0+WL~*`;^Y*mdxyg!Of(ft$~`I zlC;Nxv%`Z#BJN|nbX+F*WAnD`=;XjrLM?x(d3w-u!W?vfxF&prL%>n zwuR2{g39i9+VY{t=6Is9e~FTH!{L37rd5}*ThZ}|p21M9&s>$4kfgVDuF_hHt3Q#e zTH*hdyu7@qsHl;%L%!c~k+ejVwMX#q@S46#-TRx}`kmkXnYYT<2WB6TFR0MhSpnL`- zIZY*1KNBDwAgd}Ehc3&b>go(-`m4IiqRJ|(EBP2e*;+2HDm=)t(kkNo-uf_Ls>09j zf{^tVe5s%iU;+gJ*5W|m4VQHnm-X|?Hw6JZ5ccCyRw#$d#>l#KD>`a}fF%$+`nZ(y z*uZ4XY+MvIp`aT~Dt5Z_m_cQC_=tt;p@8sY#VAdvtY%z@t~RqL7+8XVW2AGG7*sY+ zPuJAUP8STomTNOxin(h;WyLHF4ZTeR1I^&TjyclH3M%XPUdJ5hOKU?o@V3(og}T|! z6c~CsRz^nVFi>qB=&lQq4KxLj20)+%1v*A1F4EwTG+@^Fj}A2Sef$hSvU<+`KGLCn zUN&mV{#GzqyC^RmNE{hKfK`5{c#IFTk->lKNNMF{jI{AzD} zs=8lPRJ=aP9tx5~Clx=hvVzKnY;SV?h8JnH$`Ed%gvLvlIjWlQ&Clcz}T~2(-2yyUsmjsyEnK3_S7E_s(I5gNTTT zjIsxJw`zl(#o)Y|i#ubn035WnwUuzLS$@_8WHf^{fBc5BeY0#~U}8?rx{se0?QS;$ zr5r2&wAmabY{5`aTKYBd^9Vk{^CZGP%)4M%QkjDlBoUOrW z!-Uz(l{LNgPi;D@t89z5E)-asL(`SDouinuzq6R5owd0R3}|Tq1Q-A-pjJQcA4ih_ O0000avatar = true; +$chattheme_cfg->align = true; +$chattheme_cfg->event_message = <<