mirror of
https://github.com/moodle/moodle.git
synced 2025-04-12 03:52:16 +02:00
MDL-65464 forum: disable buttons when saving in page reply
This commit is contained in:
parent
09cbe51999
commit
902c8f58b2
2
mod/forum/amd/build/inpage_reply.min.js
vendored
2
mod/forum/amd/build/inpage_reply.min.js
vendored
@ -1 +1 @@
|
||||
define(["jquery","core/templates","core/notification","mod_forum/repository","mod_forum/selectors"],function(a,b,c,d,e){var f={THREADED:2,NESTED:3,FLAT_OLDEST_FIRST:1,FLAT_NEWEST_FIRST:-1},g=function(g){g.on("click",e.post.inpageSubmitBtn,function(h){h.preventDefault();var i,j=a(h.currentTarget).parents(e.post.inpageReplyForm).get(0),k=j.elements.post.value.trim(),l=j.elements.reply.value,m=j.elements.subject.value,n=a(h.currentTarget).parents(e.post.forumContent),o=parseInt(g.find(e.post.modeSelect).get(0).value);k.length&&d.addDiscussionPost(l,m,k).then(function(a){var b=a.messages.reduce(function(a,b){return"success"==b.type&&(a+="<p>"+b.message+"</p>"),a},"");return c.addNotification({message:b,type:"success"}),a}).then(function(a){j.reset();var c=a.post;switch(i=c.id,o){case f.THREADED:return b.render("mod_forum/forum_discussion_threaded_post",c);case f.NESTED:return b.render("mod_forum/forum_discussion_nested_post",c);default:return b.render("mod_forum/forum_discussion_post",c)}}).then(function(a,c){var d;return o!=f.FLAT_OLDEST_FIRST&&o!=f.FLAT_NEWEST_FIRST||(d=n.parents(e.post.repliesContainer).children().get(0)),void 0==d&&(d=n.siblings(e.post.repliesContainer).children().get(0)),o==f.FLAT_NEWEST_FIRST?b.prependNodeContents(d,a,c):b.appendNodeContents(d,a,c)}).then(function(){return n.find(e.post.inpageReplyContent).hide()}).then(function(){location.href="#p"+i}).fail(c.exception)})};return{init:function(a){g(a)}}});
|
||||
define(["jquery","core/templates","core/notification","mod_forum/repository","mod_forum/selectors"],function(a,b,c,d,e){var f={THREADED:2,NESTED:3,FLAT_OLDEST_FIRST:1,FLAT_NEWEST_FIRST:-1},g=function(a){var b=a.find(e.post.inpageSubmitBtnText),c=a.find(e.post.loadingIconContainer),d=a.outerWidth();a.css("width",d),b.addClass("hidden"),c.removeClass("hidden")},h=function(a){var b=a.find(e.post.inpageSubmitBtnText),c=a.find(e.post.loadingIconContainer);a.css("width",""),b.removeClass("hidden"),c.addClass("hidden")},i=function(i){i.on("click",e.post.inpageSubmitBtn,function(j){j.preventDefault();var k,l=a(j.currentTarget),m=l.parent().find(e.post.inpageReplyButton),n=l.parents(e.post.inpageReplyForm).get(0),o=n.elements.post.value.trim(),p=n.elements.reply.value,q=n.elements.subject.value,r=l.parents(e.post.forumContent),s=parseInt(i.find(e.post.modeSelect).get(0).value);o.length&&(g(l),m.prop("disabled",!0),d.addDiscussionPost(p,q,o).then(function(a){var b=a.messages.reduce(function(a,b){return"success"==b.type&&(a+="<p>"+b.message+"</p>"),a},"");return c.addNotification({message:b,type:"success"}),a}).then(function(a){n.reset();var c=a.post;switch(k=c.id,s){case f.THREADED:return b.render("mod_forum/forum_discussion_threaded_post",c);case f.NESTED:return b.render("mod_forum/forum_discussion_nested_post",c);default:return b.render("mod_forum/forum_discussion_post",c)}}).then(function(a,c){var d;return s!=f.FLAT_OLDEST_FIRST&&s!=f.FLAT_NEWEST_FIRST||(d=r.parents(e.post.repliesContainer).children().get(0)),void 0==d&&(d=r.siblings(e.post.repliesContainer).children().get(0)),s==f.FLAT_NEWEST_FIRST?b.prependNodeContents(d,a,c):b.appendNodeContents(d,a,c)}).then(function(){return h(l),m.prop("disabled",!1),r.find(e.post.inpageReplyContent).hide()}).then(function(){location.href="#p"+k})["catch"](function(a){return h(l),m.prop("disabled",!1),c.exception(a)}))})};return{init:function(a){i(a)}}});
|
2
mod/forum/amd/build/selectors.min.js
vendored
2
mod/forum/amd/build/selectors.min.js
vendored
@ -1 +1 @@
|
||||
define([],function(){return{subscription:{toggle:"[data-type='subscription-toggle'][data-action='toggle']"},post:{post:'[data-region="post"]',action:'[data-region="post-action"]',actionsContainer:'[data-region="post-actions-container"]',forumCoreContent:"[data-region-content='forum-post-core']",forumContent:"[data-content='forum-post']",forumSubject:"[data-region-content='forum-post-core-subject']",inpageReplyLink:"[data-action='collapsible-link']",inpageReplyContent:"[data-content='inpage-reply-content']",inpageReplyForm:"form[data-content='inpage-reply-form']",inpageSubmitBtn:"[data-action='forum-inpage-submit']",repliesContainer:"[data-region='replies-container']",modeSelect:"select[name='mode']"},lock:{toggle:"[data-action='toggle'][data-type='lock-toggle']"},favourite:{toggle:"[data-type='favorite-toggle'][data-action='toggle']"},pin:{toggle:"[data-type='pin-toggle'][data-action='toggle']"}}});
|
||||
define([],function(){return{subscription:{toggle:"[data-type='subscription-toggle'][data-action='toggle']"},post:{post:'[data-region="post"]',action:'[data-region="post-action"]',actionsContainer:'[data-region="post-actions-container"]',forumCoreContent:"[data-region-content='forum-post-core']",forumContent:"[data-content='forum-post']",forumSubject:"[data-region-content='forum-post-core-subject']",inpageReplyButton:"button",inpageReplyLink:"[data-action='collapsible-link']",inpageReplyContent:"[data-content='inpage-reply-content']",inpageReplyForm:"form[data-content='inpage-reply-form']",inpageSubmitBtn:"[data-action='forum-inpage-submit']",inpageSubmitBtnText:"[data-region='submit-text']",loadingIconContainer:"[data-region='loading-icon-container']",repliesContainer:"[data-region='replies-container']",modeSelect:"select[name='mode']"},lock:{toggle:"[data-action='toggle'][data-type='lock-toggle']"},favourite:{toggle:"[data-type='favorite-toggle'][data-action='toggle']"},pin:{toggle:"[data-type='pin-toggle'][data-action='toggle']"}}});
|
@ -14,13 +14,9 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This module is the highest level module for the calendar. It is
|
||||
* responsible for initialising all of the components required for
|
||||
* the calendar to run. It also coordinates the interaction between
|
||||
* components by listening for and responding to different events
|
||||
* triggered within the calendar UI.
|
||||
* This module handles the in page replying to forum posts.
|
||||
*
|
||||
* @module mod_forum/posts_list
|
||||
* @module mod_forum/inpage_reply
|
||||
* @package mod_forum
|
||||
* @copyright 2019 Peter Dias
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
@ -46,18 +42,57 @@ define([
|
||||
FLAT_NEWEST_FIRST: -1
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the loading icon for the submit button.
|
||||
*
|
||||
* @param {Object} button The submit button element
|
||||
*/
|
||||
var showSubmitButtonLoadingIcon = function(button) {
|
||||
var textContainer = button.find(Selectors.post.inpageSubmitBtnText);
|
||||
var loadingIconContainer = button.find(Selectors.post.loadingIconContainer);
|
||||
var width = button.outerWidth();
|
||||
// Fix the width so that the button size doesn't change when we show the loading icon.
|
||||
button.css('width', width);
|
||||
textContainer.addClass('hidden');
|
||||
loadingIconContainer.removeClass('hidden');
|
||||
};
|
||||
|
||||
/**
|
||||
* Hide the loading icon for the submit button.
|
||||
*
|
||||
* @param {Object} button The submit button element
|
||||
*/
|
||||
var hideSubmitButtonLoadingIcon = function(button) {
|
||||
var textContainer = button.find(Selectors.post.inpageSubmitBtnText);
|
||||
var loadingIconContainer = button.find(Selectors.post.loadingIconContainer);
|
||||
// Reset the width back to it's default.
|
||||
button.css('width', '');
|
||||
textContainer.removeClass('hidden');
|
||||
loadingIconContainer.addClass('hidden');
|
||||
};
|
||||
|
||||
/**
|
||||
* Register the event listeners for the submit button of the in page reply.
|
||||
*
|
||||
* @param {Object} root The discussion container element.
|
||||
*/
|
||||
var registerEventListeners = function(root) {
|
||||
root.on('click', Selectors.post.inpageSubmitBtn, function(e) {
|
||||
e.preventDefault();
|
||||
var form = $(e.currentTarget).parents(Selectors.post.inpageReplyForm).get(0);
|
||||
var submitButton = $(e.currentTarget);
|
||||
var allButtons = submitButton.parent().find(Selectors.post.inpageReplyButton);
|
||||
var form = submitButton.parents(Selectors.post.inpageReplyForm).get(0);
|
||||
var message = form.elements.post.value.trim();
|
||||
var postid = form.elements.reply.value;
|
||||
var subject = form.elements.subject.value;
|
||||
var currentRoot = $(e.currentTarget).parents(Selectors.post.forumContent);
|
||||
var currentRoot = submitButton.parents(Selectors.post.forumContent);
|
||||
var mode = parseInt(root.find(Selectors.post.modeSelect).get(0).value);
|
||||
var newid;
|
||||
|
||||
if (message.length) {
|
||||
showSubmitButtonLoadingIcon(submitButton);
|
||||
allButtons.prop('disabled', true);
|
||||
|
||||
Repository.addDiscussionPost(postid, subject, message)
|
||||
.then(function(context) {
|
||||
var message = context.messages.reduce(function(carry, message) {
|
||||
@ -105,13 +140,19 @@ define([
|
||||
}
|
||||
})
|
||||
.then(function() {
|
||||
hideSubmitButtonLoadingIcon(submitButton);
|
||||
allButtons.prop('disabled', false);
|
||||
return currentRoot.find(Selectors.post.inpageReplyContent).hide();
|
||||
})
|
||||
.then(function() {
|
||||
location.href = "#p" + newid;
|
||||
return;
|
||||
})
|
||||
.fail(Notification.exception);
|
||||
.catch(function(error) {
|
||||
hideSubmitButtonLoadingIcon(submitButton);
|
||||
allButtons.prop('disabled', false);
|
||||
return Notification.exception(error);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -119,7 +160,6 @@ define([
|
||||
return {
|
||||
init: function(root) {
|
||||
registerEventListeners(root);
|
||||
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -33,10 +33,13 @@ define([], function() {
|
||||
forumCoreContent: "[data-region-content='forum-post-core']",
|
||||
forumContent: "[data-content='forum-post']",
|
||||
forumSubject: "[data-region-content='forum-post-core-subject']",
|
||||
inpageReplyButton: "button",
|
||||
inpageReplyLink: "[data-action='collapsible-link']",
|
||||
inpageReplyContent: "[data-content='inpage-reply-content']",
|
||||
inpageReplyForm: "form[data-content='inpage-reply-form']",
|
||||
inpageSubmitBtn: "[data-action='forum-inpage-submit']",
|
||||
inpageSubmitBtnText: "[data-region='submit-text']",
|
||||
loadingIconContainer: "[data-region='loading-icon-container']",
|
||||
repliesContainer: "[data-region='replies-container']",
|
||||
modeSelect: "select[name='mode']"
|
||||
},
|
||||
|
@ -46,12 +46,13 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<button class="btn btn-primary" title="{{#str}} submit, core {{/str}}" data-action="forum-inpage-submit">
|
||||
{{#str}} submit, core {{/str}}
|
||||
<span data-region="submit-text">{{#str}} submit, core {{/str}}</span>
|
||||
<span data-region="loading-icon-container" class="hidden">{{> core/loading }}</span>
|
||||
</button>
|
||||
<button class="btn btn-secondary" title="{{#str}} cancel, core {{/str}}" data-action="collapsible-link">
|
||||
{{#str}} cancel, core {{/str}}
|
||||
</button>
|
||||
<button title="{{#str}} advanced, forum {{/str}}" data-action="forum-advanced-reply" class="btn btn-link float-right" type="submit">
|
||||
<button title="{{#str}} advanced, core {{/str}}" data-action="forum-advanced-reply" class="btn btn-link float-right" type="submit">
|
||||
{{#str}} advanced, core {{/str}}
|
||||
</button>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user