Skip to content

Commit

Permalink
MDL-55638 core_message: add message when there are no contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Oct 7, 2016
1 parent ab95d75 commit 4d1b76e
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 19 deletions.
2 changes: 2 additions & 0 deletions lang/en/message.php
Expand Up @@ -109,6 +109,8 @@
$string['newonlymsg'] = 'Show only new';
$string['newsearch'] = 'New search';
$string['noframesjs'] = 'Use more accessible interface';
$string['nocontacts'] = 'No contacts';
$string['noconversations'] = 'No conversations';
$string['nomessages'] = 'No messages waiting';
$string['nomessagesfound'] = 'No messages were found';
$string['noreply'] = 'Do not reply to this message';
Expand Down
1 change: 1 addition & 0 deletions message/amd/src/message_area.js
Expand Up @@ -57,6 +57,7 @@ define(['jquery', 'core_message/message_area_contacts', 'core_message/message_ar
MESSAGESHEADERACTIONS: "[data-region='messages-header-actions']",
MESSAGERESPONSE: "[data-region='response']",
MESSAGETEXT: "[data-region='message-text']",
NOCONTACTS: "[data-region=no-contacts]",
PROFILE: "[data-region='profile']",
PROFILEADDCONTACT: "[data-action='profile-add-contact']",
PROFILEBLOCKCONTACT: "[data-action='profile-block-contact']",
Expand Down
53 changes: 37 additions & 16 deletions message/amd/src/message_area_contacts.js
Expand Up @@ -130,6 +130,11 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
* @private
*/
Contacts.prototype._viewConversations = function() {
// If conversations is empty then try load some.
if (this._numConversationsDisplayed === 0) {
this._loadConversations();
}

this.messageArea.find(this.messageArea.SELECTORS.CONTACTS).hide();
this.messageArea.find(this.messageArea.SELECTORS.CONVERSATIONS).show();
};
Expand All @@ -140,7 +145,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
* @private
*/
Contacts.prototype._viewContacts = function() {
// If contacts is empty then load some.
// If contacts is empty then try load some.
if (this._numContactsDisplayed === 0) {
this._loadContacts();
}
Expand Down Expand Up @@ -179,6 +184,9 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
user = usercontact.clone();
// Change the data action attribute.
user.attr('data-action', 'view-contact-msg');
// Remove the 'no conversations' message.
this.messageArea.find(this.messageArea.SELECTORS.CONVERSATIONS + " " +
this.messageArea.SELECTORS.NOCONTACTS).remove();
// Increment the number of conversations displayed.
this._numConversationsDisplayed++;
}
Expand Down Expand Up @@ -214,8 +222,13 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
var numberreceived = 0;
// Add loading icon to the end of the list.
return templates.render('core/loading', {}).then(function(html, js) {
templates.appendNodeContents(this.messageArea.SELECTORS.CONVERSATIONS,
"<div style='text-align:center'>" + html + "</div>", js);
if (this._numConversationsDisplayed) {
templates.appendNodeContents(this.messageArea.SELECTORS.CONVERSATIONS,
"<div style='text-align:center'>" + html + "</div>", js);
} else { // No conversations, just replace contents.
templates.replaceNodeContents(this.messageArea.SELECTORS.CONVERSATIONS,
"<div style='text-align:center'>" + html + "</div>", js);
}
return this._getItems('core_message_data_for_messagearea_conversations',
this._numConversationsDisplayed, this._numConversationsToRetrieve);
}.bind(this)).then(function(data) {
Expand All @@ -231,6 +244,9 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
templates.appendNodeContents(this.messageArea.SELECTORS.CONVERSATIONS, html, js);
// Increment the number of conversations displayed.
this._numConversationsDisplayed += numberreceived;
} else if (!this._numConversationsDisplayed) {
// If we didn't receive any contacts and there are currently none, then we want to show a message.
templates.replaceNodeContents(this.messageArea.SELECTORS.CONVERSATIONS, html, js);
}
// Mark that we are no longer busy loading data.
this._isLoadingConversations = false;
Expand Down Expand Up @@ -259,8 +275,13 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
var numberreceived = 0;
// Add loading icon to the end of the list.
return templates.render('core/loading', {}).then(function(html, js) {
templates.appendNodeContents(this.messageArea.SELECTORS.CONTACTS,
"<div style='text-align:center'>" + html + "</div>", js);
if (this._numContactsDisplayed) {
templates.appendNodeContents(this.messageArea.SELECTORS.CONTACTS,
"<div style='text-align:center'>" + html + "</div>", js);
} else { // No contacts, just replace contents.
templates.replaceNodeContents(this.messageArea.SELECTORS.CONTACTS,
"<div style='text-align:center'>" + html + "</div>", js);
}
return this._getItems('core_message_data_for_messagearea_contacts',
this._numContactsDisplayed, this._numContactsToRetrieve);
}.bind(this)).then(function(data) {
Expand All @@ -276,6 +297,9 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
templates.appendNodeContents(this.messageArea.SELECTORS.CONTACTS, html, js);
// Increment the number of contacts displayed.
this._numContactsDisplayed += numberreceived;
} else if (!this._numContactsDisplayed) {
// If we didn't receive any contacts and there are currently none, then we want to show a message.
templates.replaceNodeContents(this.messageArea.SELECTORS.CONTACTS, html, js);
}
// Mark that we are no longer busy loading data.
this._isLoadingContacts = false;
Expand Down Expand Up @@ -401,8 +425,10 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
for (var i = 0; i <= requests.length - 1; i++) {
// Remove the conversation.
this._removeContact(this.messageArea.SELECTORS.CONVERSATIONS, requests[i].args.otheruserid);
this._numConversationsDisplayed--;
// Trigger conversation deleted events.
this.messageArea.trigger(this.messageArea.EVENTS.CONVERSATIONDELETED, requests[i].args.otheruserid);

}
}.bind(this), notification.exception);
}
Expand Down Expand Up @@ -441,16 +467,10 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
* @param {int} userid
* @private
*/
Contacts.prototype._addContact = function(userid) {
var user = this._getUserNode(this.messageArea.SELECTORS.CONTACTS, userid);
if (user.length !== 0) {
user.show();
} else {
// Must have added contact we searched for that wasn't in the contact list. Let's just refresh the contact panel.
this.messageArea.find(this.messageArea.SELECTORS.CONTACTS).empty();
this._numContactsDisplayed = 0;
this._loadContacts();
}
Contacts.prototype._addContact = function() {
this.messageArea.find(this.messageArea.SELECTORS.CONTACTS).empty();
this._numContactsDisplayed = 0;
this._loadContacts();
};

/**
Expand All @@ -473,7 +493,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
* @private
*/
Contacts.prototype._removeContact = function(selector, userid) {
this._getUserNode(selector, userid).hide();
this._getUserNode(selector, userid).remove();
this._numContactsDisplayed--;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion message/classes/api.php
Expand Up @@ -259,7 +259,7 @@ public static function get_contacts($userid, $limitfrom = 0, $limitnum = 0) {
}
}

return new \core_message\output\messagearea\contacts($userid, 0, $arrcontacts);
return new \core_message\output\messagearea\contacts($userid, 0, $arrcontacts, false);
}

/**
Expand Down
11 changes: 9 additions & 2 deletions message/classes/output/messagearea/contacts.php
Expand Up @@ -51,17 +51,24 @@ class contacts implements templatable, renderable {
*/
protected $contacts;

/**
* Are we storing conversations or contacts?
*/
protected $isconversation;

/**
* Constructor.
*
* @param int $userid The id of the user the contacts belong to
* @param int $otheruserid The id of the user we are viewing
* @param bool $isconversation Are we storing conversations or contacts?
* @param \core_message\output\messagearea\contact[] $contacts
*/
public function __construct($userid, $otheruserid, $contacts) {
public function __construct($userid, $otheruserid, $contacts, $isconversation = true) {
$this->userid = $userid;
$this->otheruserid = $otheruserid;
$this->contacts = $contacts;
$this->isconversation = $isconversation;
}

/**
Expand Down Expand Up @@ -93,7 +100,7 @@ public function export_for_template(\renderer_base $output) {
}
$data->contacts[] = $contactdata;
}

$data->isconversation = $this->isconversation;
return $data;
}
}
1 change: 1 addition & 0 deletions message/externallib.php
Expand Up @@ -742,6 +742,7 @@ public static function data_for_messagearea_conversations_returns() {
return new external_single_structure(
array(
'userid' => new external_value(PARAM_INT, 'The id of the user who we are viewing conversations for'),
'isconversation' => new external_value(PARAM_BOOL, 'Are we storing conversations or contacts?'),
'contacts' => new external_multiple_structure(
new external_single_structure(
array(
Expand Down
10 changes: 10 additions & 0 deletions message/templates/message_area_contacts.mustache
@@ -1,3 +1,13 @@
{{#contacts}}
{{> core_message/message_area_contact }}
{{/contacts}}
{{^contacts}}
<div class="nocontacts" data-region="no-contacts">
{{#isconversation}}
{{#str}}noconversations, message{{/str}}
{{/isconversation}}
{{^isconversation}}
{{#str}}nocontacts, message{{/str}}
{{/isconversation}}
</div>
{{/contacts}}
5 changes: 5 additions & 0 deletions theme/bootstrapbase/less/moodle/message.less
Expand Up @@ -138,6 +138,11 @@
height: 500px;
overflow-y: auto;

.nocontacts {
padding-top: 20px;
text-align: center;
}

.contact {
height: 66px;
cursor: pointer;
Expand Down
4 changes: 4 additions & 0 deletions theme/bootstrapbase/style/moodle.css
Expand Up @@ -5863,6 +5863,10 @@ a.ygtvspacer:hover {
height: 500px;
overflow-y: auto;
}
.messaging-area-container .messaging-area .contacts-area .contacts .nocontacts {
padding-top: 20px;
text-align: center;
}
.messaging-area-container .messaging-area .contacts-area .contacts .contact {
height: 66px;
cursor: pointer;
Expand Down

0 comments on commit 4d1b76e

Please sign in to comment.