Skip to content
Permalink
Browse files
Merge branch 'MDL-65464-master' of https://github.com/ryanwyllie/moodle
  • Loading branch information
David Monllaó authored and abgreeve committed May 7, 2019
2 parents 14b1327 + 902c8f5 commit 2558e0cd7129b88e750f0c0f9152adb9dffe97ca

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

@@ -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,21 +140,26 @@ 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);
});
}
});
};

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>

0 comments on commit 2558e0c

Please sign in to comment.