2 * NOTE: the /mod/chat/gui_header_js/ is not a real plugin,
3 * ideally this code should be in /mod/chat/module.js
7 * @namespace M.mod_chat_header
9 M.mod_chat_header = M.mod_chat_ajax || {};
12 * Init header based Chat UI - frame input
14 * @namespace M.mod_chat_header
17 * @param {Boolean} forcerefreshasap refresh users frame asap
19 M.mod_chat_header.init_insert = function(Y, forcerefreshasap) {
20 if (forcerefreshasap) {
21 parent.jsupdate.location.href = parent.jsupdate.document.anchors[0].href;
23 parent.input.enableForm();
27 * Init header based Chat UI - frame input
29 * @namespace M.mod_chat_header
33 M.mod_chat_header.init_input = function(Y) {
37 waitflag : false, // True when a submission is in progress
40 * Initialises the input frame
45 Y.one('#inputForm').on('submit', this.submit, this);
48 * Enables the input form
49 * @this {M.mod_chat.js}
51 enable_form : function() {
52 var el = Y.one('#input_chat_message');
53 this.waitflag = false;
54 el.set('className', '');
58 * Submits the entered message
61 submit : function(e) {
67 var inputchatmessage = Y.one('#input_chat_message');
68 Y.one('#insert_chat_message').set('value', inputchatmessage.get('value'));
69 inputchatmessage.set('value', '');
70 inputchatmessage.addClass('wait');
71 Y.one('#sendForm').submit();
82 * Init header based Chat UI - frame users
84 * @namespace M.mod_chat_header
87 * @param {Array} users
89 M.mod_chat_header.init_users = function(Y, users) {
93 timer : null, // Stores the timer object
94 timeout : 1, // The seconds between updates
95 users : [], // An array of users
98 * Initialises the frame with list of users
102 * @param {Array|null} users
104 init : function(users) {
107 Y.one(document.body).on('unload', this.stop, this);
110 * Starts the update timeout
116 this.timer = setTimeout(function(self) {
118 }, this.timeout * 1000, this);
121 * Stops the update timeout
126 clearTimeout(this.timer);
129 * Updates the user information
134 update : function() {
135 for (var i in this.users) {
136 var el = Y.one('#uidle' + this.users[i]);
138 var parts = el.get('innerHTML').split(':');
139 var time = this.timeout + (parseInt(parts[0], 10) * 60) + parseInt(parts[1], 10);
140 var min = Math.floor(time / 60);
142 el.set('innerHTML', ((min < 10) ? "0" : "") + min + ":" + ((sec < 10) ? "0" : "") + sec);
149 usersframe.init(users);