mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 01:46:45 +02:00
MDL-54687 core_message: added ability to toggle between tabs
This commit is contained in:
parent
879e2bef23
commit
9aa012b5a1
6 changed files with 259 additions and 2 deletions
79
message/amd/src/message-area.js
Normal file
79
message/amd/src/message-area.js
Normal file
|
@ -0,0 +1,79 @@
|
|||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This module handles toggling between the 'Conversations' and 'Contacts'
|
||||
* tabs in the message area.
|
||||
*
|
||||
* @module core_message/message-area
|
||||
* @package core_message
|
||||
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define(['jquery', 'core/ajax', 'core/templates', 'core/notification'], function($, ajax, templates, notification) {
|
||||
|
||||
function Messagearea(selector) {
|
||||
this._node = $(selector);
|
||||
this._init();
|
||||
}
|
||||
|
||||
Messagearea.prototype.find = function(selector) {
|
||||
return this._node.find(selector);
|
||||
};
|
||||
|
||||
Messagearea.prototype._init = function() {
|
||||
this._node.on('click', '.tabconversations', this._loadConversations.bind(this));
|
||||
this._node.on('click', '.tabcontacts', this._loadContacts.bind(this));
|
||||
};
|
||||
|
||||
Messagearea.prototype._loadConversations = function() {
|
||||
this._loadContactArea('core_message_data_for_messagearea_conversations');
|
||||
};
|
||||
|
||||
Messagearea.prototype._loadContacts = function() {
|
||||
this._loadContactArea('core_message_data_for_messagearea_contacts');
|
||||
};
|
||||
|
||||
Messagearea.prototype._loadContactArea = function(methodname) {
|
||||
// Show loading template.
|
||||
templates.render('core_message/loading', {}).done(function(html) {
|
||||
this.find('.contacts').empty().append(html);
|
||||
}.bind(this));
|
||||
|
||||
// Call the web service to return the data we want to view.
|
||||
var promises = ajax.call([{
|
||||
methodname: methodname,
|
||||
args: {
|
||||
userid: this._getCurrentUserId()
|
||||
}
|
||||
}]);
|
||||
|
||||
// After the request render the contacts area.
|
||||
promises[0].then(function(data) {
|
||||
// We have the data - lets re-render the template with it.
|
||||
return templates.render('core_message/contacts', data).then(function(html, js) {
|
||||
this.find('.contacts-area').empty().append(html);
|
||||
// And execute any JS that was in the template.
|
||||
templates.runTemplateJS(js);
|
||||
}.bind(this));
|
||||
}.bind(this)).fail(notification.exception);
|
||||
};
|
||||
|
||||
Messagearea.prototype._getCurrentUserId = function() {
|
||||
return this._node.data('userid');
|
||||
};
|
||||
|
||||
return Messagearea;
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue