MDL-66025 user: require message content in bulk action.

Also import missing 'core/notification' dependency.
This commit is contained in:
Paul Holden 2021-02-12 21:47:58 +00:00
parent 41037efa7a
commit 3112712ec3
6 changed files with 24 additions and 10 deletions

View File

@ -118,6 +118,7 @@ $string['messagedrawerviewsettings'] = 'Message settings';
$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';

View File

@ -1,2 +1,2 @@
function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core_user/local/participants/bulkactions",["exports","core_user/repository","core/str","core/modal_events","core/modal_factory","core/templates","core/toast"],function(a,b,c,d,e,f,g){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.showSendMessage=a.showAddNote=void 0;b=j(b);c=j(c);d=h(d);e=h(e);f=h(f);function h(a){return a&&a.__esModule?a:{default:a}}function i(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;i=function(){return a};return a}function j(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=i();if(b&&b.has(a)){return b.get(a)}var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a){if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;if(f&&(f.get||f.set)){Object.defineProperty(c,e,f)}else{c[e]=a[e]}}}c.default=a;if(b){b.set(a,c)}return c}var k=function(a,b,g,h){if(!b.length){return Promise.resolve()}var i=[];for(var m in g){switch(m){case"draft":i.push({value:"personal",label:g[m]});break;case"public":i.push({value:"course",label:g[m],selected:1});break;case"site":i.push({value:m,label:g[m]});break;}}var j={stateNames:i,stateHelpIcon:h.innerHTML},k=null;if(1===b.length){k=c.get_string("addbulknotesingle","core_notes")}else{k=c.get_string("addbulknote","core_notes",b.length)}return e.default.create({type:e.default.types.SAVE_CANCEL,body:f.default.render("core_user/add_bulk_note",j),title:k,buttons:{save:k},removeOnClose:!0}).then(function(c){c.getRoot().on(d.default.save,function(){return l(a,b,c)});c.show();return c})};a.showAddNote=k;var l=function(a,d,e){var f=e.getRoot().find("form textarea").val(),h=e.getRoot().find("form select").val(),i=d.map(function(b){return{userid:b,text:f,courseid:a,publishstate:h}});return b.createNotesForUsers(i).then(function(a){if(1===a.length){return c.get_string("addbulknotedonesingle","core_notes")}else{return c.get_string("addbulknotedone","core_notes",a.length)}}).then(function(a){return(0,g.add)(a)}).catch(Notification.exception)},m=function(a){if(!a.length){return Promise.resolve()}var b;if(1===a.length){b=c.get_string("sendbulkmessagesingle","core_message")}else{b=c.get_string("sendbulkmessage","core_message",a.length)}return e.default.create({type:e.default.types.SAVE_CANCEL,body:f.default.render("core_user/send_bulk_message",{}),title:b,buttons:{save:b},removeOnClose:!0}).then(function(b){b.getRoot().on(d.default.save,function(){n(b,a)});b.show();return b})};a.showSendMessage=m;var n=function(a,d){var e=a.getRoot().find("form textarea").val(),f=d.map(function(a){return{touserid:a,text:e}});return b.sendMessagesToUsers(f).then(function(a){if(1==a.length){return c.get_string("sendbulkmessagesentsingle","core_message")}else{return c.get_string("sendbulkmessagesent","core_message",a.length)}}).then(function(a){return(0,g.add)(a)}).catch(Notification.exception)}});
function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core_user/local/participants/bulkactions",["exports","core_user/repository","core/str","core/modal_events","core/modal_factory","core/notification","core/templates","core/toast"],function(a,b,c,d,e,f,g,h){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.showSendMessage=a.showAddNote=void 0;b=k(b);c=k(c);d=i(d);e=i(e);f=i(f);g=i(g);function i(a){return a&&a.__esModule?a:{default:a}}function j(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;j=function(){return a};return a}function k(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=j();if(b&&b.has(a)){return b.get(a)}var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a){if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;if(f&&(f.get||f.set)){Object.defineProperty(c,e,f)}else{c[e]=a[e]}}}c.default=a;if(b){b.set(a,c)}return c}var l=function(a,b,f,h){if(!b.length){return Promise.resolve()}var i=[];for(var l in f){switch(l){case"draft":i.push({value:"personal",label:f[l]});break;case"public":i.push({value:"course",label:f[l],selected:1});break;case"site":i.push({value:l,label:f[l]});break;}}var j={stateNames:i,stateHelpIcon:h.innerHTML},k=null;if(1===b.length){k=c.get_string("addbulknotesingle","core_notes")}else{k=c.get_string("addbulknote","core_notes",b.length)}return e.default.create({type:e.default.types.SAVE_CANCEL,body:g.default.render("core_user/add_bulk_note",j),title:k,buttons:{save:k},removeOnClose:!0}).then(function(c){c.getRoot().on(d.default.save,function(){return m(a,b,c)});c.show();return c})};a.showAddNote=l;var m=function(a,d,e){var g=e.getRoot().find("form textarea").val(),i=e.getRoot().find("form select").val(),j=d.map(function(b){return{userid:b,text:g,courseid:a,publishstate:i}});return b.createNotesForUsers(j).then(function(a){if(1===a.length){return c.get_string("addbulknotedonesingle","core_notes")}else{return c.get_string("addbulknotedone","core_notes",a.length)}}).then(function(a){return(0,h.add)(a)}).catch(f.default.exception)},n=function(a){if(!a.length){return Promise.resolve()}var b;if(1===a.length){b=c.get_string("sendbulkmessagesingle","core_message")}else{b=c.get_string("sendbulkmessage","core_message",a.length)}return e.default.create({type:e.default.types.SAVE_CANCEL,body:g.default.render("core_user/send_bulk_message",{}),title:b,buttons:{save:b},removeOnClose:!0}).then(function(b){b.getRoot().on(d.default.save,function(c){var d=b.getRoot().find("form textarea").val();if(""===d.trim()){b.getRoot().find("[data-role=\"messagetextrequired\"]").removeAttr("hidden");c.preventDefault();return}o(b,a,d)});b.show();return b})};a.showSendMessage=n;var o=function(a,d,e){var g=d.map(function(a){return{touserid:a,text:e}});return b.sendMessagesToUsers(g).then(function(a){if(1==a.length){return c.get_string("sendbulkmessagesentsingle","core_message")}else{return c.get_string("sendbulkmessagesent","core_message",a.length)}}).then(function(a){return(0,h.add)(a)}).catch(f.default.exception)}});
//# sourceMappingURL=bulkactions.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -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';
@ -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();
@ -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,

View File

@ -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) {

View File

@ -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"