$id = required_param('id', PARAM_INT);
$groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers
-$theme = optional_param('theme', 'compact', PARAM_ALPHANUM);
+$theme = optional_param('theme', 'compact', PARAM_SAFEDIR);
$url = new moodle_url('/mod/chat/gui_ajax/index.php', array('id'=>$id));
if ($groupid !== 0) {
}
$module = array(
- 'name' => 'mod_chat_ajax',
+ 'name' => 'mod_chat_ajax', // chat gui's are not real plugins, we have to break the naming standards for JS modules here :-(
'fullpath' => '/mod/chat/gui_ajax/module.js',
- 'requires' => array('base', 'dom', 'event', 'event-mouseenter', 'event-key', 'json-parse', 'io', 'overlay', 'yui2-resize', 'yui2-layout', 'yui2-menu')
+ 'requires' => array('base', 'dom', 'event', 'event-mouseenter', 'event-key', 'json-parse', 'io', 'overlay', 'yui2-resize', 'yui2-layout', 'yui2-menu'),
+ 'strings' => array(array('send', 'chat'), array('sending', 'chat'), array('inputarea', 'chat'), array('userlist', 'chat'),
+ array('modulename', 'chat'), array('beep', 'chat'), array('talk', 'chat'))
);
-$modulecfg = array(array(
+$modulecfg = array(
'home'=>$CFG->httpswwwroot.'/mod/chat/view.php?id='.$cm->id,
'chaturl'=>$CFG->httpswwwroot.'/mod/chat/gui_ajax/index.php?id='.$id,
'theme'=>$theme,
'chat_lasttime'=>0,
'chat_lastrow'=>null,
'chatroom_name'=>format_string($course->shortname) . ": ".format_string($chat->name,true).$groupname
-));
-$PAGE->requires->js_init_call('M.mod_chat.ajax.init', $modulecfg, false, $module);
-$PAGE->requires->strings_for_js(array('send','sending','inputarea','userlist','modulename','beep','talk'), 'chat');
+);
+$PAGE->requires->js_init_call('M.mod_chat_ajax.init', array($modulecfg), false, $module);
-$PAGE->set_title('Chat');
+$PAGE->set_title(get_string('modulename', 'chat').": $course->shortname: ".format_string($chat->name,true)."$groupname");
$PAGE->add_body_class('yui-skin-sam');
$PAGE->set_pagelayout('embedded');
+
+/*
+ * NOTE: the /mod/chat/gui_header_js/ is not a real plugin,
+ * ideally this code should be in /mod/chat/module.js
+ */
+
+/**
+ * @namespace M.mod_chat_ajax
+ */
+M.mod_chat_ajax = M.mod_chat_ajax || {};
+
/**
- * AJAX Chat Module
+ * Init ajax based Chat UI.
+ * @namespace M.mod_chat_ajax
+ * @function
+ * @param {YUI} Y
+ * @param {Object} cfg configuration data
*/
-YUI.add('mod_chat_ajax', function(Y) {
-
- /**
- * @namespace M.mod_chat
- */
- M.mod_chat = M.mod_chat || {};
- /**
- * This is the AJAX chat modules main namespace
- * @namespace M.mod_chat.ajax
- */
- M.mod_chat.ajax = {
+M.mod_chat_ajax.init = function(Y, cfg) {
+
+ var gui_ajax = {
// Properties
api : M.cfg.wwwroot+'/mod/chat/chat_ajax.php', // The path to the ajax callback script
sendbutton : null,
messagebox : null,
- init : function(m, cfg) {
+ init : function(cfg) {
this.cfg = cfg;
this.cfg.req_count = this.cfg.req_count || 0;
this.layout = new YAHOO.widget.Layout({
// Attach the default events for this module
this.sendbutton.on('click', this.send, this);
- this.messagebox.on('mouseenter', new function(){this.scrollable = false;}, this);
- this.messagebox.on('mouseleave', new function(){this.scrollable = true;}, this);
+ this.messagebox.on('mouseenter', function() {
+ this.scrollable = false;
+ }, this);
+ this.messagebox.on('mouseleave', function() {
+ this.scrollable = true;
+ }, this);
// Send the message when the enter key is pressed
Y.on('key', this.send, this.messageinput, 'press:13', this);
this.sendbutton.set('value', M.str.chat.sending);
var data = {
- chat_message : (!beep)?this.messageinput.get('value'):'',
- chat_sid : this.cfg.sid,
- theme : this.cfg.theme
- }
- if (beep) {
- data.beep = beep
- }
+ chat_message : (!beep)?this.messageinput.get('value'):'',
+ chat_sid : this.cfg.sid,
+ theme : this.cfg.theme
+ };
+ if (beep) {
+ data.beep = beep
+ }
Y.io(this.api+'?action=chat', {
- method : 'POST',
- data : build_querystring(data),
- on : {
- success : this.send_callback
- },
- context : this
+ method : 'POST',
+ data : build_querystring(data),
+ on : {
+ success : this.send_callback
+ },
+ context : this
});
},
send_callback : function(tid, outcome, args) {
- if(outcome.responseText == 200){
+ if (outcome.responseText == 200) {
this.sendbutton.set('value', M.str.chat.send);
this.messageinput.set('value', '');
}
clearInterval(this.interval);
this.update_messages();
- this.interval = setInterval(function(me){
+ this.interval = setInterval(function(me) {
me.update_messages();
}, this.cfg.timer, this);
},
this.cfg.chat_lastrow = data.lastrow;
// Update messages
for (var key in data.msgs){
- if(!M.util.in_array(key, this.messages)){
+ if (!M.util.in_array(key, this.messages)) {
this.messages.push(key);
this.append_message(key, data.msgs[key], data.lastrow);
}
},
update_users : function(users) {
- if(!users){
+ if (!users) {
return;
}
var list = Y.one('#users-list');
list.append(li);
}
}
-
- }
-
-}, '2.0.0', {requires:['base', 'dom', 'event', 'event-mouseenter', 'event-key', 'json-parse', 'io', 'overlay', 'yui2-resize', 'yui2-layout']});
\ No newline at end of file
+
+ };
+
+ gui_ajax.init(cfg);
+};