From ad8bd9002a1d200e33e3c26fb82d94d2b0918f44 Mon Sep 17 00:00:00 2001 From: Kirill Astashov Date: Tue, 28 Oct 2025 06:31:40 +0000 Subject: [PATCH] Fix multiple issues as per ISSUE-59 --- evaluate.js | 57 +++++++------------ evaluatesave.php | 2 +- locallib.php | 2 +- rb_sources/rb_source_ojt_completion.php | 4 +- .../rb_source_ojt_topic_item_completion.php | 4 +- renderer.php | 27 ++++++--- uploadfile.php | 9 +++ 7 files changed, 55 insertions(+), 50 deletions(-) diff --git a/evaluate.js b/evaluate.js index b793687b782..bc626fffb75 100644 --- a/evaluate.js +++ b/evaluate.js @@ -58,9 +58,15 @@ M.mod_ojt_evaluate = M.mod_ojt_evaluate || { var config = this.config; // Init ojt topic item selection toggle - $('.mod-ojt-topic-item-selection-label').on('click', function() { + $('.mod-ojt-topic-item-selection-container').on('click', function(e) { var topicitemselection = $(this); - var itemid = topicitemselection.parent().attr('ojt-item-id'); + var itemid = topicitemselection.data('itemid'); + var choice = topicitemselection.data('choice'); + // console.log('Clicked', e.target.tagName); + // Avoid firing the event twice, one for input, the other for label + if (e.target.tagName === 'LABEL') { + return; + } $.ajax({ url: M.cfg.wwwroot + '/mod/ojt/evaluatesave.php', type: 'POST', @@ -69,14 +75,24 @@ M.mod_ojt_evaluate = M.mod_ojt_evaluate || { 'action': 'complete', 'bid': config.ojtid, 'userid': config.userid, - 'id': itemid + 'id': itemid, + 'comment': choice }, success: function(data) { // Update the topic's completion too. - ojtobj.setTopicStatusIcon(data.item.status, $('#ojt-topic-' + data.item.topicid + ' .ojt-topic-status')); + ojtobj.setTopicStatusIcon(data.topic.status, $('#ojt-topic-' + data.item.topicid + ' .ojt-topic-status')); // Update modified string. $('.mod-ojt-modifiedstr[ojt-item-id=' + itemid + ']').html(data.modifiedstr); + + // Update the comment print box + $('.ojt-completion-comment-print[ojt-item-id='+itemid+']').html(data.item.comment); + $('.mod-ojt-modifiedstr[ojt-item-id='+itemid+']').html(data.modifiedstr); + // Trigger click if checkbox icon is unchecked. + $selector = $(".ojt-eval-actions[ojt-item-id='"+itemid+"'] span[data-flex-icon]"); + if ($selector.length && $selector[0].classList.contains("fa-square-o")) { + $selector.trigger("click"); + } }, error: function(data) { console.log(data); @@ -155,39 +171,6 @@ M.mod_ojt_evaluate = M.mod_ojt_evaluate || { }); }); - $('span.mod-ojt-item-type-select input').change(function() { - var commentinput = this; - var itemid = $(this).parent().attr('ojt-item-id'); - - $.ajax({ - url: M.cfg.wwwroot+'/mod/ojt/evaluatesave.php', - type: 'POST', - data: { - 'sesskey' : M.cfg.sesskey, - 'action': 'savecomment', - 'bid': config.ojtid, - 'userid': config.userid, - 'id': itemid, - 'comment': $(commentinput).val() - }, - success: function(data) { - // Unlike text comments, no update for the value here. - // Update the comment print box - $('.ojt-completion-comment-print[ojt-item-id='+itemid+']').html(data.item.comment); - $('.mod-ojt-modifiedstr[ojt-item-id='+itemid+']').html(data.modifiedstr); - // Trigger click if checkbox icon is unchecked. - $selector = $(".ojt-eval-actions[ojt-item-id='"+itemid+"'] span[data-flex-icon]"); - if ($selector.length && $selector[0].classList.contains("fa-square-o")) { - $selector.trigger("click"); - } - }, - error: function(data) { - console.log(data); - alert('Error saving comment...'); - } - }); - }); - // Init completion witness toggle. $('.ojt-witness-toggle').on('click', function() { var completionimg = $(this); diff --git a/evaluatesave.php b/evaluatesave.php index 2b3ec8533ae..9372da357f4 100644 --- a/evaluatesave.php +++ b/evaluatesave.php @@ -72,7 +72,6 @@ break; case 'complete': $completion->status = OJT_COMPLETE; - break; case 'savecomment': $completion->comment = required_param('comment', PARAM_TEXT); // append a date to the comment string @@ -91,6 +90,7 @@ $completion->status = OJT_COMPLETE; break; case 'complete': + $completion->status = OJT_COMPLETE; case 'savecomment': $completion->comment = required_param('comment', PARAM_TEXT); // append a date to the comment string diff --git a/locallib.php b/locallib.php index 987fad7dcc3..b2bfc4b663d 100644 --- a/locallib.php +++ b/locallib.php @@ -89,7 +89,7 @@ function ojt_get_user_ojt($ojtid, $userid) { $items = $DB->get_records_sql($sql, $params); foreach ($items as $i => $item) { - $ojt->topics[$item->topicid]->items[$i] = $item; + $ojt->topics[$item->topicid]->items[$i] = clone($item); } return $ojt; diff --git a/rb_sources/rb_source_ojt_completion.php b/rb_sources/rb_source_ojt_completion.php index 4e1d37a8540..9963f943b3a 100644 --- a/rb_sources/rb_source_ojt_completion.php +++ b/rb_sources/rb_source_ojt_completion.php @@ -440,9 +440,9 @@ function rb_filter_ojt_type_list() { /** * Inject column_test data into database. - * @param totara_reportbuilder_column_testcase $testcase + * @param totara_reportbuilder_column_test $testcase */ - public function phpunit_column_test_add_data(totara_reportbuilder_column_testcase $testcase) { + public function phpunit_column_test_add_data(totara_reportbuilder_column_test $testcase) { global $DB; if (!PHPUNIT_TEST) { diff --git a/rb_sources/rb_source_ojt_topic_item_completion.php b/rb_sources/rb_source_ojt_topic_item_completion.php index bba78acdfa8..88bbb22d01d 100644 --- a/rb_sources/rb_source_ojt_topic_item_completion.php +++ b/rb_sources/rb_source_ojt_topic_item_completion.php @@ -405,9 +405,9 @@ function rb_filter_ojt_completion_status_list() { /** * Inject column_test data into database. - * @param totara_reportbuilder_column_testcase $testcase + * @param totara_reportbuilder_column_test $testcase */ - public function phpunit_column_test_add_data(totara_reportbuilder_column_testcase $testcase) { + public function phpunit_column_test_add_data(totara_reportbuilder_column_test $testcase) { global $DB; if (!PHPUNIT_TEST) { diff --git a/renderer.php b/renderer.php index 53f15a08e72..002c6dc8de2 100644 --- a/renderer.php +++ b/renderer.php @@ -209,15 +209,26 @@ function user_ojt(stdClass $userojt, bool $evaluate = false, bool $signoff = fal 'name' => "comment-{$item->id}", 'value' => $choice, 'type' => 'radio', + 'style' => 'cursor:pointer', ); - if ($choice == $comment) { + // Comparing "Needs Improvement - 16/10/25, 11:51." to "Needs Improvement" + if (strpos($comment, $choice) === 0) { $inputattrs['checked'] = true; } - $cellcontent .= html_writer::tag('input', '', $inputattrs); - $cellcontent .= html_writer::tag('label', $choice, array( - 'for' => "comment-{$item->id}-$i", - 'class' => 'mod-ojt-topic-item-selection-label' - )); + $cellcontent .= html_writer::start_tag('span', + [ + 'class' => 'mod-ojt-topic-item-selection-container', + 'data-itemid' => $item->id, + 'data-choice' => htmlspecialchars($choice), + ] + ); + $cellcontent .= html_writer::tag('input', '', $inputattrs); + $cellcontent .= html_writer::tag('label', $choice, array( + 'for' => "comment-{$item->id}-$i", + 'class' => 'mod-ojt-topic-item-selection-label', + 'style' => 'cursor:pointer' + )); + $cellcontent .= html_writer::end_tag('span'); } $cellcontent .= html_writer::end_tag('span'); @@ -265,7 +276,7 @@ function user_ojt(stdClass $userojt, bool $evaluate = false, bool $signoff = fal $cellcontent = ''; if ($itemwitness) { $witnessicon = $item->witnessedby ? 'completion-manual-y' : 'completion-manual-n'; - $cellcontent .= html_writer:: start_tag('span', array('class' => 'ojt-witness-item', 'ojt-item-id' => $item->id)); + $cellcontent .= html_writer:: start_tag('span', array('class' => 'ojt-witness-item', 'ojt-item-id' => $item->id, 'style' => 'cursor: pointer')); $cellcontent .= $this->output->flex_icon($witnessicon, ['classes' => 'ojt-witness-toggle']); $cellcontent .= html_writer::end_tag('div'); @@ -298,8 +309,10 @@ function user_ojt(stdClass $userojt, bool $evaluate = false, bool $signoff = fal $out .= html_writer::start_tag('div', array('class' => 'mod-ojt-topic-signoff', 'ojt-topic-id' => $topic->id)); $out .= get_string('managersignoff', 'ojt'); if ($signoff) { + $out .= html_writer::start_tag('span', ['style' => 'cursor: pointer']); $out .= $this->output->flex_icon($topic->signedoff ? 'completion-manual-y' : 'completion-manual-n', ['classes' => 'ojt-topic-signoff-toggle']); + $out .= html_writer::end_tag('span'); } else { if ($topic->signedoff) { $out .= $this->output->flex_icon('check-success', ['alt' => get_string('signedoff', 'ojt')]); diff --git a/uploadfile.php b/uploadfile.php index e524e606d31..2decdfe304a 100644 --- a/uploadfile.php +++ b/uploadfile.php @@ -78,6 +78,15 @@ $fileoptions = $FILEPICKER_OPTIONS; $fileoptions['maxfiles'] = 10; +$fileoptions['accepted_types'] = array( + 'video', + 'audio', + 'archive', + 'spreadsheet', + 'presentation', + 'document', + 'image', +); $item = new stdClass(); $item->topicitemid = $topicitemid;