Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defect 828690: Behat: mod/studentquiz (tt) - Test delete comment feat… #508

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion amd/build/comment_area.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/comment_area.min.js.map

Large diffs are not rendered by default.

24 changes: 21 additions & 3 deletions amd/src/comment_area.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ define(['jquery', 'core/str', 'core/ajax', 'core/modal_factory', 'core/templates
self.canViewDeleted = params.canviewdeleted;
self.isNoComment = params.isnocomment;
self.allowSelfCommentRating = params.allowselfcommentrating;
self.isusingtinymce = params.isusingtinymce;

self.initServerRender();
if (params.allowselfcommentrating) {
Expand Down Expand Up @@ -267,17 +268,24 @@ define(['jquery', 'core/str', 'core/ajax', 'core/modal_factory', 'core/templates
// Interval to init atto editor, there are time when Atto's Javascript slow to init the editor, so we
// check interval here to make sure the Atto is init before calling our script.
var interval = setInterval(function() {
// Check whether TinyMCE is being used and wait for the editor to fully load.
var editor = self.isusingtinymce ?
window?.tinyMCE?.get(
self.formSelector?.find(t.SELECTOR.TEXTAREA)?.attr('id') ?? '') : null;
if (!self.isusingtinymce || (editor && editor?.getBody())) {
// Binding events to the editor.
self.bindEditorEvent(self.formSelector);
isEditorLoaded = true;
clearInterval(interval);
M.util.js_complete(t.ACTION_EDITOR_INIT);
}
}, 500);

// If the editor has some content that has been restored
// then check the editor content.
var editorWaiting = setInterval(function() {
if (isEditorLoaded) {
if (self.formSelector.find(t.SELECTOR.TINYMCE.CONTENT).length !== 0) {
if (self.isusingtinymce) {
const textareaSelector = self.formSelector.find(t.SELECTOR.TEXTAREA);
const tinyEditorId = textareaSelector.attr('id');
const editor = window.tinyMCE.get(tinyEditorId);
Expand Down Expand Up @@ -393,7 +401,7 @@ define(['jquery', 'core/str', 'core/ajax', 'core/modal_factory', 'core/templates
// Clear form in setTimeout to prevent require message still shown when reset on Firefox.
setTimeout(function() {
// Clear form data.
if (self.formSelector.find(t.SELECTOR.TINYMCE.CONTENT).length !== 0) {
if (self.isusingtinymce) {
self.resetContent(formSelector, t.EDITOR.TINYMCE.TYPE);
} else if (self.formSelector.find(t.SELECTOR.ATTO.CONTENT).length !== 0) {
self.formSelector.trigger('reset');
Expand Down Expand Up @@ -1087,6 +1095,8 @@ define(['jquery', 'core/str', 'core/ajax', 'core/modal_factory', 'core/templates
var textFragmentFormId = '#id_editor_question_' + self.studentQuizQuestionId + '_' +
self.type + '_' + item.id + 'editable';
fragmentForm.find(textFragmentFormId).focus();
// Disable the reply button by default because the reply content is always empty at the beginning.
self.triggerAttoNoContent(fragmentForm);
self.bindFragmentFormEvent(fragmentForm, item);
M.util.js_complete(t.ACTION_LOAD_FRAGMENT_FORM);
});
Expand Down Expand Up @@ -1371,6 +1381,14 @@ define(['jquery', 'core/str', 'core/ajax', 'core/modal_factory', 'core/templates
editor.on("input", function() {
self.checkEditorContent(formSelector, editor.getBody(), t.EDITOR.TINYMCE.TYPE);
});
// It is necessary to check the SetContent event from the start because:
// When the editor content is empty, the tiny_autosave_update_session service is called.
// If there is existing restore data, it will be set in the editor, but this action won't trigger
// the "input" event. Therefore, we need to use the SetContent event in this case.
// The SetContent event is also triggered during undo and redo actions.
editor.on("SetContent", function() {
self.checkEditorContent(formSelector, editor.getBody(), t.EDITOR.TINYMCE.TYPE);
});
// This event will be triggered when user paste content.
editor.on("change", function() {
self.checkEditorContent(formSelector, editor.getBody(), t.EDITOR.TINYMCE.TYPE);
Expand Down Expand Up @@ -1453,7 +1471,7 @@ define(['jquery', 'core/str', 'core/ajax', 'core/modal_factory', 'core/templates
*/
bindEditorEvent: function(formSelector) {
var self = this;
if (self.formSelector.find(t.SELECTOR.TINYMCE.CONTENT).length !== 0) {
if (self.isusingtinymce) {
self.bindHandleTinyEditor(formSelector);
} else if (self.formSelector.find(t.SELECTOR.ATTO.CONTENT).length !== 0) {
self.bindHandleAttoEditor(formSelector);
Expand Down
3 changes: 2 additions & 1 deletion renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2383,7 +2383,8 @@ public function render_comment_area($studentquizquestion, $userid, $highlight =
$jsdata = array_merge($jsdata, [
'count' => $count,
'total' => $total,
'allowselfcommentrating' => $allowselfcommentrating
'allowselfcommentrating' => $allowselfcommentrating,
'isusingtinymce' => editors_get_preferred_editor() instanceof \editor_tiny\editor,
]);

$this->page->requires->js_call_amd(self::MODNAME . '/comment_area', 'generate', [$jsdata]);
Expand Down
Loading