Commit 81517613 authored by Adrian Greeve's avatar Adrian Greeve
Browse files

MDL-56603 messaging: Add a new message link to popup.

Added a link to create a new message from the message
popup menu.
parent af5765b3
......@@ -68,6 +68,9 @@ $string['messagepreferences'] = 'Message preferences';
$string['messages'] = 'Messages';
$string['messagingdisabled'] = 'Messaging is disabled on this site, emails will be sent instead';
$string['newonlymsg'] = 'Show only new';
$string['newmessage'] = 'New message';
$string['newmessagesearch'] = 'Select or search for a contact to send a new message.';
$string['newsearch'] = 'New search';
$string['noframesjs'] = 'Use more accessible interface';
$string['nocontacts'] = 'No contacts';
$string['nomessages'] = 'No messages';
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -117,6 +117,15 @@ define(['jquery', 'core_message/message_area_contacts', 'core_message/message_ar
return this.node.data('userid');
};
/**
* Function to determine if we should be showing contacts initially or messages.
*
* @return {boolean} True to show contacts first, otherwise show messages.
*/
Messagearea.prototype.showContactsFirst = function() {
return !!this.node.data('displaycontacts');
};
return Messagearea;
}
);
......@@ -149,9 +149,10 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
this.messageArea.onDelegateEvent(CustomEvents.events.scrollBottom, SELECTORS.CONTACTS,
this._loadContacts.bind(this));
// Set the number of conversations. We set this to the number of conversations we asked to retrieve not by
// the number that was actually retrieved, see MDL-55870.
this._numConversationsDisplayed = 20;
if (!this.messageArea.showContactsFirst()) {
// Set the initial number of conversations to retrieve. Otherwise it will display no conversations.
this._numConversationsDisplayed = 20;
}
};
/**
......
......@@ -145,7 +145,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
);
// Set the initial search area.
this._searchArea = this._searchAreas.MESSAGES;
this._searchArea = (this.messageArea.showContactsFirst()) ? this._searchAreas.USERS : this._searchAreas.MESSAGES;
};
/**
......
......@@ -78,6 +78,11 @@ class message_area implements templatable, renderable {
*/
public $polltimeout;
/**
* @var bool Are we creating a new message and show the contacts section first?
*/
public $contactsfirst;
/**
* Constructor.
*
......@@ -86,20 +91,23 @@ class message_area implements templatable, renderable {
* @param array $contacts
* @param array|null $messages
* @param bool $requestedconversation
* @param bool $contactsfirst Whether we are viewing the contacts first.
* @param int $pollmin
* @param int $pollmax
* @param int $polltimeout
*/
public function __construct($userid, $otheruserid, $contacts, $messages, $requestedconversation, $pollmin, $pollmax,
$polltimeout) {
public function __construct($userid, $otheruserid, $contacts, $messages, $requestedconversation, $contactsfirst, $pollmin,
$pollmax, $polltimeout) {
$this->userid = $userid;
$this->otheruserid = $otheruserid;
// Setting the other user to null when showing contacts will remove any contact from being selected.
$this->otheruserid = (!$contactsfirst) ? $otheruserid : null;
$this->contacts = $contacts;
$this->messages = $messages;
$this->requestedconversation = $requestedconversation;
$this->pollmin = $pollmin;
$this->pollmax = $pollmax;
$this->polltimeout = $polltimeout;
$this->contactsfirst = $contactsfirst;
}
public function export_for_template(\renderer_base $output) {
......@@ -107,13 +115,19 @@ class message_area implements templatable, renderable {
$data->userid = $this->userid;
$contacts = new contacts($this->otheruserid, $this->contacts);
$data->contacts = $contacts->export_for_template($output);
$messages = new messages($this->userid, $this->otheruserid, $this->messages);
if ($this->contactsfirst) {
// Don't show any messages if we are creating a new message.
$messages = new messages($this->userid, null, array());
} else {
$messages = new messages($this->userid, $this->otheruserid, $this->messages);
}
$data->messages = $messages->export_for_template($output);
$data->isconversation = true;
$data->isconversation = ($this->contactsfirst) ? false : true;
$data->requestedconversation = $this->requestedconversation;
$data->pollmin = $this->pollmin;
$data->pollmax = $this->pollmax;
$data->polltimeout = $this->polltimeout;
$data->contactsfirst = $this->contactsfirst;
return $data;
}
......
......@@ -41,6 +41,7 @@ $id = optional_param('id', 0, PARAM_INT);
// we are going to accept other URL parameters to figure this out.
$user1id = optional_param('user1', $USER->id, PARAM_INT);
$user2id = optional_param('user2', $id, PARAM_INT);
$contactsfirst = optional_param('contactsfirst', 0, PARAM_INT);
$url = new moodle_url('/message/index.php');
if ($id) {
......@@ -52,6 +53,9 @@ if ($id) {
if ($user2id) {
$url->param('user2', $user2id);
}
if ($contactsfirst) {
$url->param('contactsfirst', $contactsfirst);
}
}
$PAGE->set_url($url);
......@@ -98,7 +102,11 @@ $settings->make_active();
// Get the renderer and the information we are going to be use.
$renderer = $PAGE->get_renderer('core_message');
$requestedconversation = false;
$conversations = \core_message\api::get_conversations($user1->id, 0, 20);
if ($contactsfirst) {
$conversations = \core_message\api::get_contacts($user1->id, 0, 20);
} else {
$conversations = \core_message\api::get_conversations($user1->id, 0, 20);
}
$messages = [];
if (!$user2realuser) {
// If there are conversations, but the user has not chosen a particular one, then render the most recent one.
......@@ -131,7 +139,7 @@ $pollmin = !empty($CFG->messagingminpoll) ? $CFG->messagingminpoll : MESSAGE_DEF
$pollmax = !empty($CFG->messagingmaxpoll) ? $CFG->messagingmaxpoll : MESSAGE_DEFAULT_MAX_POLL_IN_SECONDS;
$polltimeout = !empty($CFG->messagingtimeoutpoll) ? $CFG->messagingtimeoutpoll : MESSAGE_DEFAULT_TIMEOUT_POLL_IN_SECONDS;
$messagearea = new \core_message\output\messagearea\message_area($user1->id, $user2->id, $conversations, $messages,
$requestedconversation, $pollmin, $pollmax, $polltimeout);
$requestedconversation, $contactsfirst, $pollmin, $pollmax, $polltimeout);
// Now the page contents.
echo $OUTPUT->header();
......
......@@ -46,6 +46,7 @@ function message_popup_render_navbar_output(\renderer_base $renderer) {
$context = [
'userid' => $USER->id,
'urls' => [
'writeamessage' => (new moodle_url('/message/index.php', ['contactsfirst' => 1]))->out(),
'preferences' => (new moodle_url('/message/edit.php', ['id' => $USER->id]))->out(),
],
];
......
......@@ -52,6 +52,12 @@
{{$headertext}}{{#str}} messages, message {{/str}}{{/headertext}}
{{$headeractions}}
<div class="newmessage-link">
{{$anchor}}
<a href="{{{urls.writeamessage}}}">{{#str}} newmessage, message {{/str}}
</a>
{{/anchor}}
</div>
{{< core/hover_tooltip }}
{{$anchor}}
<a class="mark-all-read-button"
......
......@@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
<div class="messaging-area-container" data-userid="{{userid}}">
<div class="messaging-area-container" data-userid="{{userid}}" data-displaycontacts="{{contactsfirst}}">
<div class="messaging-area {{#requestedconversation}}show-messages{{/requestedconversation}}
{{^requestedconversation}}hide-messages{{/requestedconversation}}" data-region="messaging-area">
<div class="contacts-area" data-region="contacts-area" role="tablist">
......
......@@ -16,24 +16,32 @@
}}
<div class="searchtextarea" data-region="search-text-area">
<label class="accesshide" for="searchtext">{{#str}}search{{/str}}</label>
<input data-region="search-box" type="text" id="searchtext" placeholder="{{#str}}searchmessages, message{{/str}}">
<input data-region="search-box" type="text" id="searchtext" placeholder="{{#contactsfirst}} {{#str}}searchforuserorcourse, message{{/str}} {{/contactsfirst}} {{^contactsfirst}} {{#str}}searchmessages, message{{/str}} {{/contactsfirst}}">
<div data-region="search-filter-area" class="searchfilterarea" style="display:none">
<div data-region="search-filter" class="searchfilter"></div>
<div data-action="search-filter-delete" class="searchfilterdelete">{{#pix}}t/delete{{/pix}}</div>
</div>
</div>
{{#contactsfirst}}
<div class="contacts" data-region="contacts" data-region-content="conversations" style="display:none;" role="tabpanel" id="conversations-tab-panel"></div>
<div class="contacts" data-region="contacts" data-region-content="contacts" role="tabpanel" id="contacts-tab-panel">
{{> core_message/message_area_contacts }}
</div>
{{/contactsfirst}}
{{^contactsfirst}}
<div class="contacts" data-region="contacts" data-region-content="conversations" role="tabpanel" id="conversations-tab-panel">
{{> core_message/message_area_contacts }}
</div>
{{! Hidden divs to load the other tab and search panels via JS when appropriate. }}
<div class="contacts" data-region="contacts" data-region-content="contacts" style="display:none;" role="tabpanel" id="contacts-tab-panel"></div>
{{/contactsfirst}}
{{! Hidden divs to load the other tab and search panels via JS when appropriate. }}
<div class="contacts searcharea" data-region="search-results-area" style="display:none;"></div>
<div class="tabs">
<div class="tab tabconversations selected" data-action="conversations-view" role="tab" aria-controls="conversations-tab-panel" aria-selected="true" tabindex="0">
<div class="tab tabconversations {{^contactsfirst}}selected{{/contactsfirst}} " data-action="conversations-view" role="tab" aria-controls="conversations-tab-panel" aria-selected="{{^contactsfirst}}true{{/contactsfirst}}{{#contactsfirst}}false{{/contactsfirst}}" tabindex="0">
<div class="tabimage">{{#pix}}t/message, moodle{{/pix}}</div>
<div>{{#str}}messages, message{{/str}}</div>
</div>
<div class="tab tabcontacts" data-action="contacts-view" role="tab" aria-controls="contacts-tab-panel" aria-selected="false" tabindex="-1">
<div class="tab tabcontacts {{#contactsfirst}}selected{{/contactsfirst}}" data-action="contacts-view" role="tab" aria-controls="contacts-tab-panel" aria-selected="{{#contactsfirst}}true{{/contactsfirst}}{{^contactsfirst}}false{{/contactsfirst}}" tabindex="-1">
<div class="tabimage">{{#pix}}i/cohort, moodle{{/pix}}</div>
<div>{{#str}}contacts, message{{/str}}</div>
</div>
......
......@@ -40,6 +40,15 @@
</div>
</div>
{{/otheruserid}}
{{#contactsfirst}}
<div class="messages-header">
<div class="name-container">
<div class="name">
{{#str}}newmessagesearch, message{{/str}}
</div>
</div>
</div>
{{/contactsfirst}}
<div class="messages" data-region="messages" data-userid="{{otheruserid}}">
{{> core_message/message_area_messages }}
</div>
......
......@@ -123,6 +123,11 @@ $content-item-unread-colour: #f4f4f4;
height: 12px;
width: 12px;
}
.newmessage-link {
margin-right: 10px;
}
label {
display: inline-block;
text-align: center;
......
......@@ -101,6 +101,9 @@
height: 12px;
width: 12px;
}
.newmessage-link {
margin-right: 10px;
}
label {
display: inline-block;
text-align: center;
......@@ -447,6 +450,10 @@
.popover-region-header-actions {
float: left;
.newmessage-link {
margin-left: 10px;
}
}
}
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment