MDL-66481 forum: Show notification on toggled subscription

For usability, after selecting the subscription toggle action menu item,
a notification message will be shown to the user.
This commit is contained in:
Jun Pataleta
2019-09-26 10:47:05 +08:00
parent 5132de054c
commit 0f3e5a9b8d
4 changed files with 27 additions and 4 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
define ("mod_forum/discussion",["jquery","core/custom_interaction_events","mod_forum/selectors"],function(a,b,c){var d=function(a){var b=a.prev(c.post.post);if(b.length){var d=b.find(c.post.post).last();if(d.length){d.focus()}else{b.focus()}}else{a.parents(c.post.post).first().focus()}},e=function(b){var d=b.find(c.post.post).first();if(d.length){d.focus()}else{var e=b.next(c.post.post);if(e.length){e.focus()}else{for(var f=b.parents(c.post.post).toArray(),g=0,h;g<f.length;g++){h=a(f[g]).next(c.post.post);if(h.length){h.focus();break}}}}},f=function(b){var d=a(b).closest(c.post.inpageReplyContent);return d.length?!0:!1},g=function(g){var h=g.find(c.post.post);h.each(function(b,d){var e=a(d).find(c.post.action),f=e.first();e.attr("tabindex","-1");f.attr("tabindex",0)});b.define(g,[b.events.up,b.events.down,b.events.next,b.events.previous,b.events.home,b.events.end]);g.on(b.events.up,function(b,e){var h=document.activeElement;if(f(h)){return}var i=a(h).closest(c.post.post);if(i.length){d(i)}else{g.find(c.post.post).first().focus()}e.originalEvent.preventDefault()});g.on(b.events.down,function(b,d){var h=document.activeElement;if(f(h)){return}var i=a(h).closest(c.post.post);if(i.length){e(i)}else{g.find(c.post.post).first().focus()}d.originalEvent.preventDefault()});g.on(b.events.home,function(a,b){if(f(document.activeElement)){return}g.find(c.post.post).first().focus();b.originalEvent.preventDefault()});g.on(b.events.end,function(a,b){if(f(document.activeElement)){return}g.find(c.post.post).last().focus();b.originalEvent.preventDefault()});g.on(b.events.next,c.post.action,function(b,d){var e=a(b.target),f=e.closest(c.post.actionsContainer),g=f.find(c.post.action),h=e.next(c.post.action);g.attr("tabindex","-1");if(!h.length){h=g.first()}h.attr("tabindex",0);h.focus();d.originalEvent.preventDefault()});g.on(b.events.previous,c.post.action,function(b,d){var e=a(b.target),f=e.closest(c.post.actionsContainer),g=f.find(c.post.action),h=e.prev(c.post.action);g.attr("tabindex","-1");if(!h.length){h=g.last()}h.attr("tabindex",0);h.focus();d.originalEvent.preventDefault()});g.on(b.events.home,c.post.action,function(b,d){var e=a(b.target),f=e.closest(c.post.actionsContainer),g=f.find(c.post.action),h=g.first();g.attr("tabindex","-1");h.attr("tabindex",0);h.focus();b.stopPropagation();d.originalEvent.preventDefault()});g.on(b.events.end,c.post.action,function(b,d){var e=a(b.target),f=e.closest(c.post.actionsContainer),g=f.find(c.post.action),h=g.last();g.attr("tabindex","-1");h.attr("tabindex",0);h.focus();b.stopPropagation();d.originalEvent.preventDefault()})};return{init:function init(a){g(a)}}});
define ("mod_forum/discussion",["jquery","core/custom_interaction_events","mod_forum/selectors","core/pubsub","mod_forum/forum_events","core/str","core/notification"],function(a,b,c,d,e,f,g){var h=function(a){var b=a.prev(c.post.post);if(b.length){var d=b.find(c.post.post).last();if(d.length){d.focus()}else{b.focus()}}else{a.parents(c.post.post).first().focus()}},i=function(b){var d=b.find(c.post.post).first();if(d.length){d.focus()}else{var e=b.next(c.post.post);if(e.length){e.focus()}else{for(var f=b.parents(c.post.post).toArray(),g=0,h;g<f.length;g++){h=a(f[g]).next(c.post.post);if(h.length){h.focus();break}}}}},j=function(b){var d=a(b).closest(c.post.inpageReplyContent);return d.length?!0:!1},k=function(k){var l=k.find(c.post.post);l.each(function(b,d){var e=a(d).find(c.post.action),f=e.first();e.attr("tabindex","-1");f.attr("tabindex",0)});b.define(k,[b.events.up,b.events.down,b.events.next,b.events.previous,b.events.home,b.events.end]);k.on(b.events.up,function(b,d){var e=document.activeElement;if(j(e)){return}var f=a(e).closest(c.post.post);if(f.length){h(f)}else{k.find(c.post.post).first().focus()}d.originalEvent.preventDefault()});k.on(b.events.down,function(b,d){var e=document.activeElement;if(j(e)){return}var f=a(e).closest(c.post.post);if(f.length){i(f)}else{k.find(c.post.post).first().focus()}d.originalEvent.preventDefault()});k.on(b.events.home,function(a,b){if(j(document.activeElement)){return}k.find(c.post.post).first().focus();b.originalEvent.preventDefault()});k.on(b.events.end,function(a,b){if(j(document.activeElement)){return}k.find(c.post.post).last().focus();b.originalEvent.preventDefault()});k.on(b.events.next,c.post.action,function(b,d){var e=a(b.target),f=e.closest(c.post.actionsContainer),g=f.find(c.post.action),h=e.next(c.post.action);g.attr("tabindex","-1");if(!h.length){h=g.first()}h.attr("tabindex",0);h.focus();d.originalEvent.preventDefault()});k.on(b.events.previous,c.post.action,function(b,d){var e=a(b.target),f=e.closest(c.post.actionsContainer),g=f.find(c.post.action),h=e.prev(c.post.action);g.attr("tabindex","-1");if(!h.length){h=g.last()}h.attr("tabindex",0);h.focus();d.originalEvent.preventDefault()});k.on(b.events.home,c.post.action,function(b,d){var e=a(b.target),f=e.closest(c.post.actionsContainer),g=f.find(c.post.action),h=g.first();g.attr("tabindex","-1");h.attr("tabindex",0);h.focus();b.stopPropagation();d.originalEvent.preventDefault()});k.on(b.events.end,c.post.action,function(b,d){var e=a(b.target),f=e.closest(c.post.actionsContainer),g=f.find(c.post.action),h=g.last();g.attr("tabindex","-1");h.attr("tabindex",0);h.focus();b.stopPropagation();d.originalEvent.preventDefault()});d.subscribe(e.SUBSCRIPTION_TOGGLED,function(a){var b=a.subscriptionState,c=b?"discussionsubscribed":"discussionunsubscribed";f.get_string(c,"forum").then(function(a){return g.addNotification({message:a,type:"info"})}).catch(g.exception)})};return{init:function init(a){k(a)}}});
//# sourceMappingURL=discussion.min.js.map
File diff suppressed because one or more lines are too long
+23 -2
View File
@@ -25,12 +25,20 @@ define(
[
'jquery',
'core/custom_interaction_events',
'mod_forum/selectors'
'mod_forum/selectors',
'core/pubsub',
'mod_forum/forum_events',
'core/str',
'core/notification',
],
function(
$,
CustomEvents,
Selectors
Selectors,
PubSub,
ForumEvents,
String,
Notification
) {
/**
@@ -261,6 +269,19 @@ function(
e.stopPropagation();
data.originalEvent.preventDefault();
});
PubSub.subscribe(ForumEvents.SUBSCRIPTION_TOGGLED, function(data) {
var subscribed = data.subscriptionState;
var updateMessage = subscribed ? 'discussionsubscribed' : 'discussionunsubscribed';
String.get_string(updateMessage, "forum")
.then(function(s) {
return Notification.addNotification({
message: s,
type: "info"
});
})
.catch(Notification.exception);
});
};
return {
+2
View File
@@ -185,6 +185,7 @@ $string['discussionpin'] = 'Pin';
$string['discussionpinned'] = 'Pinned';
$string['discussionpinned_help'] = 'Pinned discussions will appear at the top of a forum.';
$string['discussionsplit'] = 'Discussion has been split';
$string['discussionsubscribed'] = 'You are now subscribed to this discussion.';
$string['discussionsubscribestop'] = 'I don\'t want to be notified of new posts in this discussion';
$string['discussionsubscribestart'] = 'Send me notifications of new posts in this discussion';
$string['discussionsubscription'] = 'Discussion subscription';
@@ -194,6 +195,7 @@ $string['discussionsstartedby'] = 'Discussions started by {$a}';
$string['discussionsstartedbyrecent'] = 'Discussions recently started by {$a}';
$string['discussionsstartedbyuserincourse'] = 'Discussions started by {$a->fullname} in {$a->coursename}';
$string['discussionunpin'] = 'Unpin';
$string['discussionunsubscribed'] = 'You are now unsubscribed from this discussion.';
$string['discussthistopic'] = 'Discuss this topic';
$string['displayend'] = 'Display end';
$string['displayend_help'] = 'This setting specifies whether a forum post should be hidden after a certain date. Note that administrators can always view forum posts.';