Skip to content

Commit

Permalink
Merge branch 'MDL-66025' of git://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
abgreeve committed Mar 11, 2021
2 parents 98fa5b6 + 3112712 commit baa9064
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions lang/en/message.php
Expand Up @@ -118,6 +118,7 @@
$string['messagepreferences'] = 'Message preferences';
$string['messages'] = 'Messages';
$string['messagesselected:'] = 'Messages selected:';
$string['messagetextrequired'] = 'Please enter message text';
$string['messagingdatahasnotbeenmigrated'] = 'Your messages are temporarily unavailable due to upgrades in the messaging infrastructure. Please wait for them to be migrated.';
$string['muteconversation'] = 'Mute';
$string['mutedconversation'] = 'Muted conversation';
Expand Down
2 changes: 1 addition & 1 deletion user/amd/build/local/participants/bulkactions.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion user/amd/build/local/participants/bulkactions.min.js.map

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions user/amd/src/local/participants/bulkactions.js
Expand Up @@ -26,6 +26,7 @@ import * as Repository from 'core_user/repository';
import * as Str from 'core/str';
import ModalEvents from 'core/modal_events';
import ModalFactory from 'core/modal_factory';
import Notification from 'core/notification';
import Templates from 'core/templates';
import {add as notifyUser} from 'core/toast';

Expand Down Expand Up @@ -151,8 +152,15 @@ export const showSendMessage = users => {
removeOnClose: true,
})
.then(modal => {
modal.getRoot().on(ModalEvents.save, () => {
submitSendMessage(modal, users);
modal.getRoot().on(ModalEvents.save, (e) => {
const text = modal.getRoot().find('form textarea').val();
if (text.trim() === '') {
modal.getRoot().find('[data-role="messagetextrequired"]').removeAttr('hidden');
e.preventDefault();
return;
}

submitSendMessage(modal, users, text);
});

modal.show();
Expand All @@ -166,11 +174,10 @@ export const showSendMessage = users => {
*
* @param {Modal} modal
* @param {Number[]} users
* @param {String} text
* @return {Promise}
*/
const submitSendMessage = (modal, users) => {
const text = modal.getRoot().find('form textarea').val();

const submitSendMessage = (modal, users, text) => {
const messages = users.map(touserid => {
return {
touserid,
Expand Down
3 changes: 3 additions & 0 deletions user/templates/send_bulk_message.mustache
Expand Up @@ -33,6 +33,9 @@
</label>
<textarea id="bulk-message" rows="3" data-max-rows="10" data-auto-rows="true" cols="30" class="form-control"></textarea>
</p>
<div class="text-danger" data-role="messagetextrequired" hidden>
{{#str}} messagetextrequired, core_message {{/str}}
</div>
</form>
{{#js}}
require(['core/auto_rows'], function(AutoRows) {
Expand Down
9 changes: 6 additions & 3 deletions user/tests/behat/bulk_message.feature
Expand Up @@ -25,8 +25,11 @@ Feature: Bulk message
And I navigate to course participants
And I click on "Select all" "checkbox"
And I set the field "With selected users..." to "Send a message"
And I should see "Send message to 3 people"
And "Send message to 3 people" "dialogue" should exist
# Try to send an empty message.
When I press "Send message to 3 people"
Then I should see "Please enter message text"
And I set the following fields to these values:
| bulk-message | "Hello world!" |
When I press "Send message to 3 people"
Then I should see "Message sent to 3 people"
And I press "Send message to 3 people"
And I should see "Message sent to 3 people"

0 comments on commit baa9064

Please sign in to comment.