mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-54687 core_message: added ability to toggle between tabs
- Loading branch information
Showing
6 changed files
with
259 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{{! | ||
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/>. | ||
}} | ||
{{! | ||
@template core_message/loading | ||
Loading spinner shown while waiting for an ajax request | ||
Classes required for JS: | ||
* None | ||
Data attibutes required for JS: | ||
* None | ||
Context variables required for this template: | ||
* None | ||
Example context (json): | ||
{ } | ||
}} | ||
{{#pix}}y/loading, core, {{#str}}loading, core_message{{/str}}{{/pix}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters