1 // This file is part of Moodle - http://moodle.org/
3 // Moodle is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // Moodle is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 * This module instantiates the functionality of the messaging area.
19 * @module core_message/message_area
20 * @package core_message
21 * @copyright 2016 Mark Nelson <markn@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 define(['jquery', 'core_message/message_area_contacts', 'core_message/message_area_messages',
25 'core_message/message_area_profile', 'core_message/message_area_tabs', 'core_message/message_area_search'],
26 function($, Contacts, Messages, Profile, Tabs, Search) {
31 * @param {String} selector The selector for the page region containing the message area.
32 * @param {int} pollmin
33 * @param {int} pollmax
34 * @param {int} polltimeout
36 function Messagearea(selector, pollmin, pollmax, polltimeout) {
37 this.node = $(selector);
38 this.pollmin = pollmin;
39 this.pollmax = pollmax;
40 this.polltimeout = polltimeout;
44 /** @type {jQuery} The jQuery node for the page region containing the message area. */
45 Messagearea.prototype.node = null;
47 /** @type {int} The minimum time to poll for messages. */
48 Messagearea.prototype.pollmin = null;
50 /** @type {int} The maximum time to poll for messages. */
51 Messagearea.prototype.pollmax = null;
53 /** @type {int} The time used once we have reached the maximum polling time. */
54 Messagearea.prototype.polltimeout = null;
57 * Initialise the other objects we require.
59 Messagearea.prototype._init = function() {
68 * Handles adding a delegate event to the messaging area node.
70 * @param {String} action The action we are listening for
71 * @param {String} selector The selector for the page we are assigning the action to
72 * @param {Function} callable The function to call when the event happens
74 Messagearea.prototype.onDelegateEvent = function(action, selector, callable) {
75 this.node.on(action, selector, callable);
79 * Handles adding a custom event to the messaging area node.
81 * @param {String} action The action we are listening for
82 * @param {Function} callable The function to call when the event happens
84 Messagearea.prototype.onCustomEvent = function(action, callable) {
85 this.node.on(action, callable);
89 * Handles triggering an event on the messaging area node.
91 * @param {String} event The selector for the page region containing the message area
92 * @param {Object=} data The data to pass when we trigger the event
94 Messagearea.prototype.trigger = function(event, data) {
95 if (typeof data == 'undefined') {
98 this.node.trigger(event, data);
102 * Handles finding a node in the messaging area.
104 * @param {String} selector The selector for the node we are looking for
105 * @return {jQuery} The node
107 Messagearea.prototype.find = function(selector) {
108 return this.node.find(selector);
112 * Returns the ID of the user whose message area we are viewing.
114 * @return {int} The user id
116 Messagearea.prototype.getCurrentUserId = function() {
117 return this.node.data('userid');
121 * Function to determine if we should be showing contacts initially or messages.
123 * @return {boolean} True to show contacts first, otherwise show messages.
125 Messagearea.prototype.showContactsFirst = function() {
126 return !!this.node.data('displaycontacts');