From bd9f843bda96cb8f45846507deb71e886b69f219 Mon Sep 17 00:00:00 2001 From: TamaroWalter Date: Tue, 28 Mar 2023 16:49:05 +0200 Subject: [PATCH 1/2] add setting to allow multiple marks of helpful and solved --- db/install.xml | 1 + db/upgrade.php | 18 ++++++++++++++++++ lang/en/moodleoverflow.php | 2 ++ locallib.php | 1 - mod_form.php | 5 +++++ version.php | 2 +- 6 files changed, 27 insertions(+), 2 deletions(-) diff --git a/db/install.xml b/db/install.xml index fb1f1f2b2e..e4651fdc18 100644 --- a/db/install.xml +++ b/db/install.xml @@ -27,6 +27,7 @@ + diff --git a/db/upgrade.php b/db/upgrade.php index 8c5b7f2356..7a35dd6026 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -273,5 +273,23 @@ function xmldb_moodleoverflow_upgrade($oldversion) { // Moodleoverflow savepoint reached. upgrade_mod_savepoint(true, 2023022400, 'moodleoverflow'); } + + if ($oldversion < 2023032800) { + // Define table moodleoverflow to be edited. + $table = new xmldb_table('moodleoverflow'); + + // Define field allowmultiplemarks to be added to moodleoverflow + $field = new xmldb_field('allowmultiplemarks', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'needsreview'); + + //Conditionally launch add field allowmultiplemarks + + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Moodleoverflow savepoint reached. + upgrade_mod_savepoint(true, 2023032800, 'moodleoverflow'); + } + return true; } diff --git a/lang/en/moodleoverflow.php b/lang/en/moodleoverflow.php index c6b5dea5bb..49b49286bb 100644 --- a/lang/en/moodleoverflow.php +++ b/lang/en/moodleoverflow.php @@ -328,6 +328,8 @@ $string['attachment'] = 'Attachment'; $string['attachments'] = 'Attachments'; $string['attachment_help'] = 'You can optionally attach one or more files to a forum post. If you attach an image, it will be displayed after the message.'; +$string['allowmultiplemarks'] = 'Multiple marks?'; +$string['allowmultiplemarks_help'] = 'A post can be marked as helpful or solved. Withing a discussion, only one post can be marked as helpful/solved. Click the checkbox to mark multiple posts as helpful/solved.'; // Templates. $string['helpfulanswer'] = 'The question owner accepted this as the best answer.'; diff --git a/locallib.php b/locallib.php index 3bb8fd54e5..0f001969f6 100644 --- a/locallib.php +++ b/locallib.php @@ -1350,7 +1350,6 @@ function moodleoverflow_print_post($post, $discussion, $moodleoverflow, $cm, $co } } if ($post->statusstarter) { - if ($post->statusteacher) { $postclass = ' statusboth'; } else { diff --git a/mod_form.php b/mod_form.php index 1cb85ae630..a7d218a4a1 100644 --- a/mod_form.php +++ b/mod_form.php @@ -224,6 +224,11 @@ public function definition() { $mform->addHelpButton('allownegativereputation', 'allownegativereputation', 'moodleoverflow'); $mform->setDefault('allownegativereputation', MOODLEOVERFLOW_REPUTATION_NEGATIVE); + // Allow multiple marks of helpful/solved + $mform->addElement('checkbox', 'allowmultiplemarks', get_string('allowmultiplemarks', 'moodleoverflow')); + $mform->addHelpButton('allowmultiplemarks', 'allowmultiplemarks', 'moodleoverflow'); + $mform->setDefault('allowmultiplemarks', 0); + // Add standard elements, common to all modules. $this->standard_coursemodule_elements(); diff --git a/version.php b/version.php index d630f8cafc..ba97bf6558 100644 --- a/version.php +++ b/version.php @@ -28,7 +28,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'mod_moodleoverflow'; -$plugin->version = 2023022406; +$plugin->version = 2023032800; $plugin->release = 'v4.1-r1'; $plugin->requires = 2020061500; // Requires Moodle 3.9+. $plugin->maturity = MATURITY_STABLE; From ee5c99ccb8d16e64017ff1322534c1aa3f06525a Mon Sep 17 00:00:00 2001 From: TamaroWalter Date: Wed, 29 Mar 2023 14:04:57 +0200 Subject: [PATCH 2/2] WIP add allowmultiplemarks check in function.js --- amd/build/functions.min.js | 2 +- amd/build/functions.min.js.map | 2 +- amd/build/reviewing.min.js.map | 2 +- amd/build/warnmodechange.min.js.map | 2 +- amd/src/functions.js | 10 ++++++++-- discussion.php | 4 +++- lang/en/moodleoverflow.php | 2 +- locallib.php | 3 +-- 8 files changed, 17 insertions(+), 10 deletions(-) diff --git a/amd/build/functions.min.js b/amd/build/functions.min.js index 8adfcc8dcb..907f1e33e0 100644 --- a/amd/build/functions.min.js +++ b/amd/build/functions.min.js @@ -5,6 +5,6 @@ * @copyright 2017 Tamara Gunkel * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define("mod_moodleoverflow/functions",["jquery","core/ajax","core/templates","core/notification","core/config","core/url","core/str"],(function($,ajax,templates,notification,Cfg,Url,str){var t={recordvote:function(discussionid,ratingid,userid,event){var postid=$(event.target).closest(".moodleoverflowpost").attr("id");postid=postid.substring(1);var vote=ajax.call([{methodname:"mod_moodleoverflow_record_vote",args:{discussionid:discussionid,postid:postid,ratingid:ratingid,sesskey:Cfg.sesskey}}]);return vote[0].done((function(response){var parentdiv=$(event.target).parent().parent();2===ratingid?(parentdiv.children("a:first-of-type").children().attr("src",Url.imageUrl("vote/upvoted","moodleoverflow")),parentdiv.children("a:nth-of-type(2)").children().attr("src",Url.imageUrl("vote/downvote","moodleoverflow"))):1===ratingid?(parentdiv.children("a:first-of-type").children().attr("src",Url.imageUrl("vote/upvote","moodleoverflow")),parentdiv.children("a:nth-of-type(2)").children().attr("src",Url.imageUrl("vote/downvoted","moodleoverflow"))):(parentdiv.children("a:first-of-type").children().attr("src",Url.imageUrl("vote/upvote","moodleoverflow")),parentdiv.children("a:nth-of-type(2)").children().attr("src",Url.imageUrl("vote/downvote","moodleoverflow"))),parentdiv.children("p").text(response.postrating),templates.replaceNode($(".user-details,.author").find('a[href*="id='+userid+'"]').siblings("span"),""+response.raterreputation+"",""),response.ownerid&&userid!==response.ownerid&&templates.replaceNode($(".user-details,.author").find('a[href*="id='+response.ownerid+'"]').siblings("span"),""+response.ownerreputation+"","")})).fail(notification.exception),vote},clickevent:function(discussionid,userid){$(".upvote").on("click",(function(event){$(event.target).is("a")&&(event.target=$(event.target).children()),$(event.target).parent().attr("class").indexOf("active")>=0?t.recordvote(discussionid,20,userid,event):t.recordvote(discussionid,2,userid,event),$(event.target).parent().toggleClass("active"),$(event.target).parent().nextAll("a").removeClass("active")})),$(".downvote").on("click",(function(event){$(event.target).is("a")&&(event.target=$(event.target).children()),$(event.target).parent().attr("class").indexOf("active")>=0?t.recordvote(discussionid,10,userid,event):t.recordvote(discussionid,1,userid,event),$(event.target).parent().toggleClass("active"),$(event.target).parent().prevAll("a").removeClass("active")})),$(".marksolved").on("click",(function(event){var post=$(event.target).parents(".moodleoverflowpost");post.hasClass("statusteacher")||post.hasClass("statusboth")?t.recordvote(discussionid,30,userid,event)[0].then((function(){t.removeSolvedFromPost(post)})):t.recordvote(discussionid,3,userid,event)[0].then((function(){t.removeOtherSolved(post.parent().parent()),post.hasClass("statusstarter")?(post.removeClass("statusstarter"),post.addClass("statusboth")):post.addClass("statusteacher");var promiseStringNotSolved=str.get_string("marknotsolved","mod_moodleoverflow");$.when(promiseStringNotSolved).done((function(string){$(event.target).text(string)})),t.redoStatus(post)}))})),$(".markhelpful").on("click",(function(event){var post=$(event.target).parents(".moodleoverflowpost");post.hasClass("statusstarter")||post.hasClass("statusboth")?t.recordvote(discussionid,40,userid,event)[0].then((function(){t.removeHelpfulFromPost(post)})):t.recordvote(discussionid,4,userid,event)[0].then((function(){t.removeOtherHelpful(post.parent().parent()),post.hasClass("statusteacher")?(post.removeClass("statusteacher"),post.addClass("statusboth")):post.addClass("statusstarter");var promiseStringNotHelpful=str.get_string("marknothelpful","mod_moodleoverflow");$.when(promiseStringNotHelpful).done((function(string){$(event.target).text(string)})),t.redoStatus(post)}))}))},removeHelpfulFromPost:function(post){post.hasClass("statusstarter")?post.removeClass("statusstarter"):(post.removeClass("statusboth"),post.addClass("statusteacher")),t.redoStatus(post);var promiseHelpful=str.get_string("markhelpful","mod_moodleoverflow");$.when(promiseHelpful).done((function(string){post.find(".markhelpful").text(string)}))},removeOtherHelpful:function(root){var formerhelpful=root.find(".statusstarter, .statusboth");formerhelpful.length>0&&t.removeHelpfulFromPost(formerhelpful)},removeSolvedFromPost:function(post){post.hasClass("statusteacher")?post.removeClass("statusteacher"):(post.removeClass("statusboth"),post.addClass("statusstarter")),t.redoStatus(post);var promiseHelpful=str.get_string("marksolved","mod_moodleoverflow");$.when(promiseHelpful).done((function(string){post.find(".marksolved").text(string)}))},removeOtherSolved:function(root){var formersolution=root.find(".statusteacher, .statusboth");formersolution.length>0&&t.removeSolvedFromPost(formersolution)},redoStatus:function(post){if($(post).hasClass("statusboth")){str.get_strings([{key:"teacherrating",component:"mod_moodleoverflow"},{key:"starterrating",component:"mod_moodleoverflow"},{key:"bestanswer",component:"mod_moodleoverflow"}]).then((function(results){var circle=templates.renderPix("status/c_circle","mod_moodleoverflow",results[0]),box=templates.renderPix("status/b_box","mod_moodleoverflow",results[1]);return $.when(box,circle).done((function(boxImg,circleImg){screen.width>600?post.find(".status").html(boxImg+circleImg+results[2]):post.find(".status").html(boxImg+circleImg)})),results}))}else if($(post).hasClass("statusteacher")){str.get_strings([{key:"teacherrating",component:"mod_moodleoverflow"},{key:"solvedanswer",component:"mod_moodleoverflow"}]).then((function(results){var circle=templates.renderPix("status/c_outline","mod_moodleoverflow",results[0]);return $.when(circle).done((function(circleImg){screen.width>600?post.find(".status").html(circleImg+results[1]):post.find(".status").html(circleImg)})),results}))}else if($(post).hasClass("statusstarter")){str.get_strings([{key:"starterrating",component:"mod_moodleoverflow"},{key:"helpfulanswer",component:"mod_moodleoverflow"}]).then((function(results){var box=templates.renderPix("status/b_outline","mod_moodleoverflow",results[0]);return $.when(box).done((function(boxImg){screen.width>600?post.find(".status").html(boxImg+results[1]):post.find(".status").html(boxImg)})),results}))}else post.find(".status").html("")}};return t})); +define("mod_moodleoverflow/functions",["jquery","core/ajax","core/templates","core/notification","core/config","core/url","core/str"],(function($,ajax,templates,notification,Cfg,Url,str){var t={recordvote:function(discussionid,ratingid,userid,event){var postid=$(event.target).closest(".moodleoverflowpost").attr("id");postid=postid.substring(1);var vote=ajax.call([{methodname:"mod_moodleoverflow_record_vote",args:{discussionid:discussionid,postid:postid,ratingid:ratingid,sesskey:Cfg.sesskey}}]);return vote[0].done((function(response){var parentdiv=$(event.target).parent().parent();2===ratingid?(parentdiv.children("a:first-of-type").children().attr("src",Url.imageUrl("vote/upvoted","moodleoverflow")),parentdiv.children("a:nth-of-type(2)").children().attr("src",Url.imageUrl("vote/downvote","moodleoverflow"))):1===ratingid?(parentdiv.children("a:first-of-type").children().attr("src",Url.imageUrl("vote/upvote","moodleoverflow")),parentdiv.children("a:nth-of-type(2)").children().attr("src",Url.imageUrl("vote/downvoted","moodleoverflow"))):(parentdiv.children("a:first-of-type").children().attr("src",Url.imageUrl("vote/upvote","moodleoverflow")),parentdiv.children("a:nth-of-type(2)").children().attr("src",Url.imageUrl("vote/downvote","moodleoverflow"))),parentdiv.children("p").text(response.postrating),templates.replaceNode($(".user-details,.author").find('a[href*="id='+userid+'"]').siblings("span"),""+response.raterreputation+"",""),response.ownerid&&userid!==response.ownerid&&templates.replaceNode($(".user-details,.author").find('a[href*="id='+response.ownerid+'"]').siblings("span"),""+response.ownerreputation+"","")})).fail(notification.exception),vote},clickevent:function(discussionid,userid,allowmultiplemarks){$(".upvote").on("click",(function(event){$(event.target).is("a")&&(event.target=$(event.target).children()),$(event.target).parent().attr("class").indexOf("active")>=0?t.recordvote(discussionid,20,userid,event):t.recordvote(discussionid,2,userid,event),$(event.target).parent().toggleClass("active"),$(event.target).parent().nextAll("a").removeClass("active")})),$(".downvote").on("click",(function(event){$(event.target).is("a")&&(event.target=$(event.target).children()),$(event.target).parent().attr("class").indexOf("active")>=0?t.recordvote(discussionid,10,userid,event):t.recordvote(discussionid,1,userid,event),$(event.target).parent().toggleClass("active"),$(event.target).parent().prevAll("a").removeClass("active")})),$(".marksolved").on("click",(function(event){var post=$(event.target).parents(".moodleoverflowpost");post.hasClass("statusteacher")||post.hasClass("statusboth")?t.recordvote(discussionid,30,userid,event)[0].then((function(){t.removeSolvedFromPost(post)})):t.recordvote(discussionid,3,userid,event)[0].then((function(){if(0==discussionid){t.removeOtherSolved(post.parent().parent()),post.hasClass("statusstarter")?(post.removeClass("statusstarter"),post.addClass("statusboth")):post.addClass("statusteacher");var promiseStringNotSolved=str.get_string("marknotsolved","mod_moodleoverflow");$.when(promiseStringNotSolved).done((function(string){$(event.target).text(string)})),t.redoStatus(post)}}))})),$(".markhelpful").on("click",(function(event){var post=$(event.target).parents(".moodleoverflowpost");post.hasClass("statusstarter")||post.hasClass("statusboth")?t.recordvote(discussionid,40,userid,event)[0].then((function(){t.removeHelpfulFromPost(post)})):t.recordvote(discussionid,4,userid,event)[0].then((function(){if(0==discussionid){t.removeOtherHelpful(post.parent().parent()),post.hasClass("statusteacher")?(post.removeClass("statusteacher"),post.addClass("statusboth")):post.addClass("statusstarter");var promiseStringNotHelpful=str.get_string("marknothelpful","mod_moodleoverflow");$.when(promiseStringNotHelpful).done((function(string){$(event.target).text(string)})),t.redoStatus(post)}}))}))},removeHelpfulFromPost:function(post){post.hasClass("statusstarter")?post.removeClass("statusstarter"):(post.removeClass("statusboth"),post.addClass("statusteacher")),t.redoStatus(post);var promiseHelpful=str.get_string("markhelpful","mod_moodleoverflow");$.when(promiseHelpful).done((function(string){post.find(".markhelpful").text(string)}))},removeOtherHelpful:function(root){var formerhelpful=root.find(".statusstarter, .statusboth");formerhelpful.length>0&&t.removeHelpfulFromPost(formerhelpful)},removeSolvedFromPost:function(post){post.hasClass("statusteacher")?post.removeClass("statusteacher"):(post.removeClass("statusboth"),post.addClass("statusstarter")),t.redoStatus(post);var promiseHelpful=str.get_string("marksolved","mod_moodleoverflow");$.when(promiseHelpful).done((function(string){post.find(".marksolved").text(string)}))},removeOtherSolved:function(root){var formersolution=root.find(".statusteacher, .statusboth");formersolution.length>0&&t.removeSolvedFromPost(formersolution)},redoStatus:function(post){if($(post).hasClass("statusboth")){str.get_strings([{key:"teacherrating",component:"mod_moodleoverflow"},{key:"starterrating",component:"mod_moodleoverflow"},{key:"bestanswer",component:"mod_moodleoverflow"}]).then((function(results){var circle=templates.renderPix("status/c_circle","mod_moodleoverflow",results[0]),box=templates.renderPix("status/b_box","mod_moodleoverflow",results[1]);return $.when(box,circle).done((function(boxImg,circleImg){screen.width>600?post.find(".status").html(boxImg+circleImg+results[2]):post.find(".status").html(boxImg+circleImg)})),results}))}else if($(post).hasClass("statusteacher")){str.get_strings([{key:"teacherrating",component:"mod_moodleoverflow"},{key:"solvedanswer",component:"mod_moodleoverflow"}]).then((function(results){var circle=templates.renderPix("status/c_outline","mod_moodleoverflow",results[0]);return $.when(circle).done((function(circleImg){screen.width>600?post.find(".status").html(circleImg+results[1]):post.find(".status").html(circleImg)})),results}))}else if($(post).hasClass("statusstarter")){str.get_strings([{key:"starterrating",component:"mod_moodleoverflow"},{key:"helpfulanswer",component:"mod_moodleoverflow"}]).then((function(results){var box=templates.renderPix("status/b_outline","mod_moodleoverflow",results[0]);return $.when(box).done((function(boxImg){screen.width>600?post.find(".status").html(boxImg+results[1]):post.find(".status").html(boxImg)})),results}))}else post.find(".status").html("")}};return t})); //# sourceMappingURL=functions.min.js.map \ No newline at end of file diff --git a/amd/build/functions.min.js.map b/amd/build/functions.min.js.map index 8edc3539b3..fd974fc0c3 100644 --- a/amd/build/functions.min.js.map +++ b/amd/build/functions.min.js.map @@ -1 +1 @@ -{"version":3,"file":"functions.min.js","sources":["../src/functions.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Ajax functions for moodleoverflow\n *\n * @module mod_moodleoverflow/functions\n * @copyright 2017 Tamara Gunkel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/config', 'core/url', 'core/str'],\n function($, ajax, templates, notification, Cfg, Url, str) {\n\n var RATING_SOLVED = 3;\n var RATING_REMOVE_SOLVED = 30;\n var RATING_HELPFUL = 4;\n var RATING_REMOVE_HELPFUL = 40;\n\n var t = {\n\n /**\n * Reoords a upvote / downvote.\n * @param {int} discussionid\n * @param {int} ratingid\n * @param {int} userid\n * @param {event} event\n * @returns {string}\n */\n recordvote: function(discussionid, ratingid, userid, event) {\n var target = $(event.target).closest('.moodleoverflowpost');\n var postid = target.attr('id');\n postid = postid.substring(1);\n\n var vote = ajax.call([{\n methodname: 'mod_moodleoverflow_record_vote',\n args: {\n discussionid: discussionid,\n postid: postid,\n ratingid: ratingid,\n sesskey: Cfg.sesskey\n }\n }\n ]);\n\n vote[0].done(function(response) {\n\n var parentdiv = $(event.target).parent().parent();\n // Update Votes.\n if (ratingid === 2) {\n parentdiv.children('a:first-of-type').children().attr(\n 'src', Url.imageUrl('vote/upvoted', 'moodleoverflow'));\n parentdiv.children('a:nth-of-type(2)').children().attr(\n 'src', Url.imageUrl('vote/downvote', 'moodleoverflow'));\n } else if (ratingid === 1) {\n parentdiv.children('a:first-of-type').children().attr(\n 'src', Url.imageUrl('vote/upvote', 'moodleoverflow'));\n parentdiv.children('a:nth-of-type(2)').children().attr(\n 'src', Url.imageUrl('vote/downvoted', 'moodleoverflow'));\n } else {\n parentdiv.children('a:first-of-type').children().attr(\n 'src', Url.imageUrl('vote/upvote', 'moodleoverflow'));\n parentdiv.children('a:nth-of-type(2)').children().attr(\n 'src', Url.imageUrl('vote/downvote', 'moodleoverflow'));\n }\n\n parentdiv.children('p').text(response.postrating);\n\n // Update user reputation.\n templates.replaceNode($('.user-details,.author').find('a[href*=\"id=' + userid + '\"]')\n .siblings('span'), '' + response.raterreputation + '', \"\");\n if (response.ownerid && userid !== response.ownerid) {\n templates.replaceNode($('.user-details,.author').find('a[href*=\"id=' + response.ownerid + '\"]')\n .siblings('span'), '' + response.ownerreputation + '', \"\");\n }\n }).fail(notification.exception);\n\n return vote;\n },\n\n /**\n * Initializes the clickevent on upvotes / downvotes.\n * @param {int} discussionid\n * @param {int} userid\n */\n clickevent: function(discussionid, userid) {\n $(\".upvote\").on(\"click\", function(event) {\n if ($(event.target).is('a')) {\n event.target = $(event.target).children();\n }\n\n if ($(event.target).parent().attr('class').indexOf('active') >= 0) {\n t.recordvote(discussionid, 20, userid, event);\n } else {\n t.recordvote(discussionid, 2, userid, event);\n }\n $(event.target).parent().toggleClass('active');\n $(event.target).parent().nextAll('a').removeClass('active');\n });\n\n $(\".downvote\").on(\"click\", function(event) {\n if ($(event.target).is('a')) {\n event.target = $(event.target).children();\n }\n\n if ($(event.target).parent().attr('class').indexOf('active') >= 0) {\n t.recordvote(discussionid, 10, userid, event);\n } else {\n t.recordvote(discussionid, 1, userid, event);\n }\n $(event.target).parent().toggleClass('active');\n $(event.target).parent().prevAll('a').removeClass('active');\n });\n\n $(\".marksolved\").on(\"click\", function(event) {\n var post = $(event.target).parents('.moodleoverflowpost');\n\n if (post.hasClass('statusteacher') || post.hasClass('statusboth')) {\n // Remove solution mark.\n t.recordvote(discussionid, RATING_REMOVE_SOLVED, userid, event)[0].then(function() {\n t.removeSolvedFromPost(post);\n });\n } else {\n // Add solution mark.\n t.recordvote(discussionid, RATING_SOLVED, userid, event)[0].then(function() {\n // Remove other solution mark in dom.\n t.removeOtherSolved(post.parent().parent());\n if (post.hasClass('statusstarter')) {\n post.removeClass('statusstarter');\n post.addClass('statusboth');\n } else {\n post.addClass('statusteacher');\n }\n\n var promiseStringNotSolved = str.get_string('marknotsolved', 'mod_moodleoverflow');\n $.when(promiseStringNotSolved).done(function(string) {\n $(event.target).text(string);\n });\n t.redoStatus(post);\n });\n }\n\n\n });\n\n $(\".markhelpful\").on(\"click\", function(event) {\n var post = $(event.target).parents('.moodleoverflowpost');\n\n if (post.hasClass('statusstarter') || post.hasClass('statusboth')) {\n // Remove helpful mark.\n t.recordvote(discussionid, RATING_REMOVE_HELPFUL, userid, event)[0].then(function() {\n t.removeHelpfulFromPost(post);\n });\n } else {\n // Add helpful mark.\n t.recordvote(discussionid, RATING_HELPFUL, userid, event)[0].then(function() {\n // Remove other helpful mark in dom.\n t.removeOtherHelpful(post.parent().parent());\n if (post.hasClass('statusteacher')) {\n post.removeClass('statusteacher');\n post.addClass('statusboth');\n } else {\n post.addClass('statusstarter');\n }\n\n var promiseStringNotHelpful = str.get_string('marknothelpful', 'mod_moodleoverflow');\n $.when(promiseStringNotHelpful).done(function(string) {\n $(event.target).text(string);\n });\n t.redoStatus(post);\n });\n }\n\n });\n },\n\n removeHelpfulFromPost: function (post) {\n if (post.hasClass('statusstarter')) {\n post.removeClass('statusstarter');\n } else {\n post.removeClass('statusboth');\n post.addClass('statusteacher');\n }\n\n t.redoStatus(post);\n\n var promiseHelpful = str.get_string('markhelpful', 'mod_moodleoverflow');\n $.when(promiseHelpful).done(function (string) {\n post.find('.markhelpful').text(string);\n });\n },\n\n removeOtherHelpful: function(root) {\n var formerhelpful = root.find('.statusstarter, .statusboth');\n if (formerhelpful.length > 0) {\n t.removeHelpfulFromPost(formerhelpful);\n }\n },\n\n removeSolvedFromPost: function(post) {\n if (post.hasClass('statusteacher')) {\n post.removeClass('statusteacher');\n } else {\n post.removeClass('statusboth');\n post.addClass('statusstarter');\n }\n\n t.redoStatus(post);\n\n var promiseHelpful = str.get_string('marksolved', 'mod_moodleoverflow');\n $.when(promiseHelpful).done(function(string) {\n post.find('.marksolved').text(string);\n });\n },\n\n removeOtherSolved: function(root) {\n var formersolution = root.find('.statusteacher, .statusboth');\n if (formersolution.length > 0) {\n t.removeSolvedFromPost(formersolution);\n }\n },\n\n /**\n * Redoes the post status\n * @param {object} post dom with .moodleoverflowpost which status should be redone\n */\n redoStatus: function(post) {\n if ($(post).hasClass('statusboth')) {\n var statusBothRequest = [\n {key: 'teacherrating', component: 'mod_moodleoverflow'},\n {key: 'starterrating', component: 'mod_moodleoverflow'},\n {key: 'bestanswer', component: 'mod_moodleoverflow'}\n ];\n str.get_strings(statusBothRequest).then(function(results) {\n var circle = templates.renderPix('status/c_circle', 'mod_moodleoverflow', results[0]);\n var box = templates.renderPix('status/b_box', 'mod_moodleoverflow', results[1]);\n $.when(box, circle).done(function(boxImg, circleImg) {\n if (screen.width > 600) {\n post.find('.status').html(boxImg + circleImg + results[2]);\n } else {\n post.find('.status').html(boxImg + circleImg);\n }\n });\n return results;\n });\n } else if ($(post).hasClass('statusteacher')) {\n var statusTeacherRequest = [\n {key: 'teacherrating', component: 'mod_moodleoverflow'},\n {key: 'solvedanswer', component: 'mod_moodleoverflow'}\n ];\n str.get_strings(statusTeacherRequest).then(function(results) {\n var circle = templates.renderPix('status/c_outline', 'mod_moodleoverflow', results[0]);\n $.when(circle).done(function(circleImg) {\n if (screen.width > 600) {\n post.find('.status').html(circleImg + results[1]);\n } else {\n post.find('.status').html(circleImg);\n }\n\n });\n return results;\n });\n } else if ($(post).hasClass('statusstarter')) {\n var statusStarterRequest = [\n {key: 'starterrating', component: 'mod_moodleoverflow'},\n {key: 'helpfulanswer', component: 'mod_moodleoverflow'}\n ];\n str.get_strings(statusStarterRequest).then(function(results) {\n var box = templates.renderPix('status/b_outline', 'mod_moodleoverflow', results[0]);\n $.when(box).done(function(boxImg) {\n if (screen.width > 600) {\n post.find('.status').html(boxImg + results[1]);\n } else {\n post.find('.status').html(boxImg);\n }\n });\n return results;\n });\n } else {\n post.find('.status').html('');\n }\n\n }\n };\n\n return t;\n});\n"],"names":["define","$","ajax","templates","notification","Cfg","Url","str","t","recordvote","discussionid","ratingid","userid","event","postid","target","closest","attr","substring","vote","call","methodname","args","sesskey","done","response","parentdiv","parent","children","imageUrl","text","postrating","replaceNode","find","siblings","raterreputation","ownerid","ownerreputation","fail","exception","clickevent","on","is","indexOf","toggleClass","nextAll","removeClass","prevAll","post","parents","hasClass","then","removeSolvedFromPost","removeOtherSolved","addClass","promiseStringNotSolved","get_string","when","string","redoStatus","removeHelpfulFromPost","removeOtherHelpful","promiseStringNotHelpful","promiseHelpful","root","formerhelpful","length","formersolution","get_strings","key","component","results","circle","renderPix","box","boxImg","circleImg","screen","width","html"],"mappings":";;;;;;;AAsBAA,sCAAO,CAAC,SAAU,YAAa,iBAAkB,oBAAqB,cAAe,WAAY,aAC7F,SAASC,EAAGC,KAAMC,UAAWC,aAAcC,IAAKC,IAAKC,SAOjDC,EAAI,CAUJC,WAAY,SAASC,aAAcC,SAAUC,OAAQC,WAE7CC,OADSb,EAAEY,MAAME,QAAQC,QAAQ,uBACjBC,KAAK,MACzBH,OAASA,OAAOI,UAAU,OAEtBC,KAAOjB,KAAKkB,KAAK,CAAC,CAClBC,WAAY,iCACZC,KAAM,CACFZ,aAAcA,aACdI,OAAQA,OACRH,SAAUA,SACVY,QAASlB,IAAIkB,mBAKrBJ,KAAK,GAAGK,MAAK,SAASC,cAEdC,UAAYzB,EAAEY,MAAME,QAAQY,SAASA,SAExB,IAAbhB,UACAe,UAAUE,SAAS,mBAAmBA,WAAWX,KAC7C,MAAOX,IAAIuB,SAAS,eAAgB,mBACxCH,UAAUE,SAAS,oBAAoBA,WAAWX,KAC9C,MAAOX,IAAIuB,SAAS,gBAAiB,oBACrB,IAAblB,UACPe,UAAUE,SAAS,mBAAmBA,WAAWX,KAC7C,MAAOX,IAAIuB,SAAS,cAAe,mBACvCH,UAAUE,SAAS,oBAAoBA,WAAWX,KAC9C,MAAOX,IAAIuB,SAAS,iBAAkB,qBAE1CH,UAAUE,SAAS,mBAAmBA,WAAWX,KAC7C,MAAOX,IAAIuB,SAAS,cAAe,mBACvCH,UAAUE,SAAS,oBAAoBA,WAAWX,KAC9C,MAAOX,IAAIuB,SAAS,gBAAiB,oBAG7CH,UAAUE,SAAS,KAAKE,KAAKL,SAASM,YAGtC5B,UAAU6B,YAAY/B,EAAE,yBAAyBgC,KAAK,eAAiBrB,OAAS,MAC3EsB,SAAS,QAAS,SAAWT,SAASU,gBAAkB,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AAQ,IAE9CvB,KAAKf,KAAK,WAAW8C,KAAKH,cAI3BL,gBAER,GAAItE,EAAE+C,MAAME,SAAS,iBAAkB,CAK1C3C,IAAI6D,YAJuB,CACvB,CAACC,IAAK,gBAAiBC,UAAW,sBAClC,CAACD,IAAK,gBAAiBC,UAAW,wBAEAnB,MAAK,SAASoB,aAC5CG,IAAMvE,UAAUsE,UAAU,mBAAoB,qBAAsBF,QAAQ,WAChFtE,EAAEwD,KAAKiB,KAAKlD,MAAK,SAASmD,QAClBE,OAAOC,MAAQ,IACf9B,KAAKf,KAAK,WAAW8C,KAAKJ,OAASJ,QAAQ,IAE3CvB,KAAKf,KAAK,WAAW8C,KAAKJ,WAG3BJ,gBAGXvB,KAAKf,KAAK,WAAW8C,KAAK,aAM/BvE"} \ No newline at end of file +{"version":3,"file":"functions.min.js","sources":["../src/functions.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Ajax functions for moodleoverflow\n *\n * @module mod_moodleoverflow/functions\n * @copyright 2017 Tamara Gunkel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/config', 'core/url', 'core/str'],\n function($, ajax, templates, notification, Cfg, Url, str) {\n\n var RATING_SOLVED = 3;\n var RATING_REMOVE_SOLVED = 30;\n var RATING_HELPFUL = 4;\n var RATING_REMOVE_HELPFUL = 40;\n\n var t = {\n\n /**\n * Reoords a upvote / downvote.\n * @param {int} discussionid\n * @param {int} ratingid\n * @param {int} userid\n * @param {event} event\n * @returns {string}\n */\n recordvote: function(discussionid, ratingid, userid, event) {\n var target = $(event.target).closest('.moodleoverflowpost');\n var postid = target.attr('id');\n postid = postid.substring(1);\n\n var vote = ajax.call([{\n methodname: 'mod_moodleoverflow_record_vote',\n args: {\n discussionid: discussionid,\n postid: postid,\n ratingid: ratingid,\n sesskey: Cfg.sesskey\n }\n }\n ]);\n\n vote[0].done(function(response) {\n\n var parentdiv = $(event.target).parent().parent();\n // Update Votes.\n if (ratingid === 2) {\n parentdiv.children('a:first-of-type').children().attr(\n 'src', Url.imageUrl('vote/upvoted', 'moodleoverflow'));\n parentdiv.children('a:nth-of-type(2)').children().attr(\n 'src', Url.imageUrl('vote/downvote', 'moodleoverflow'));\n } else if (ratingid === 1) {\n parentdiv.children('a:first-of-type').children().attr(\n 'src', Url.imageUrl('vote/upvote', 'moodleoverflow'));\n parentdiv.children('a:nth-of-type(2)').children().attr(\n 'src', Url.imageUrl('vote/downvoted', 'moodleoverflow'));\n } else {\n parentdiv.children('a:first-of-type').children().attr(\n 'src', Url.imageUrl('vote/upvote', 'moodleoverflow'));\n parentdiv.children('a:nth-of-type(2)').children().attr(\n 'src', Url.imageUrl('vote/downvote', 'moodleoverflow'));\n }\n\n parentdiv.children('p').text(response.postrating);\n\n // Update user reputation.\n templates.replaceNode($('.user-details,.author').find('a[href*=\"id=' + userid + '\"]')\n .siblings('span'), '' + response.raterreputation + '', \"\");\n if (response.ownerid && userid !== response.ownerid) {\n templates.replaceNode($('.user-details,.author').find('a[href*=\"id=' + response.ownerid + '\"]')\n .siblings('span'), '' + response.ownerreputation + '', \"\");\n }\n }).fail(notification.exception);\n\n return vote;\n },\n\n /**\n * Initializes the clickevent on upvotes / downvotes.\n * @param {int} discussionid\n * @param {int} userid\n * @param {int} allowmultiplemarks\n */\n clickevent: function(discussionid, userid, allowmultiplemarks) {\n allowmultiplemarks = 1;\n if(allowmultiplemarks == 1) {}\n $(\".upvote\").on(\"click\", function(event) {\n if ($(event.target).is('a')) {\n event.target = $(event.target).children();\n }\n\n if ($(event.target).parent().attr('class').indexOf('active') >= 0) {\n t.recordvote(discussionid, 20, userid, event);\n } else {\n t.recordvote(discussionid, 2, userid, event);\n }\n $(event.target).parent().toggleClass('active');\n $(event.target).parent().nextAll('a').removeClass('active');\n });\n\n $(\".downvote\").on(\"click\", function(event) {\n if ($(event.target).is('a')) {\n event.target = $(event.target).children();\n }\n\n if ($(event.target).parent().attr('class').indexOf('active') >= 0) {\n t.recordvote(discussionid, 10, userid, event);\n } else {\n t.recordvote(discussionid, 1, userid, event);\n }\n $(event.target).parent().toggleClass('active');\n $(event.target).parent().prevAll('a').removeClass('active');\n });\n\n $(\".marksolved\").on(\"click\", function(event) {\n var post = $(event.target).parents('.moodleoverflowpost');\n\n if (post.hasClass('statusteacher') || post.hasClass('statusboth')) {\n // Remove solution mark.\n t.recordvote(discussionid, RATING_REMOVE_SOLVED, userid, event)[0].then(function() {\n t.removeSolvedFromPost(post);\n });\n } else {\n // Add solution mark.\n t.recordvote(discussionid, RATING_SOLVED, userid, event)[0].then(function() {\n /* check if allowmultiplemarks is on.\n if false: remove other solution marks (false means allowmultiplemarks == 0)\n else: do nothing. */\n if(discussionid == 0) {\n // Remove other solution mark in dom.\n t.removeOtherSolved(post.parent().parent());\n if (post.hasClass('statusstarter')) {\n post.removeClass('statusstarter');\n post.addClass('statusboth');\n } else {\n post.addClass('statusteacher');\n }\n\n var promiseStringNotSolved = str.get_string('marknotsolved', 'mod_moodleoverflow');\n $.when(promiseStringNotSolved).done(function(string) {\n $(event.target).text(string);\n });\n t.redoStatus(post);\n }\n });\n }\n\n\n });\n\n $(\".markhelpful\").on(\"click\", function(event) {\n var post = $(event.target).parents('.moodleoverflowpost');\n if (post.hasClass('statusstarter') || post.hasClass('statusboth')) {\n // Remove helpful mark.\n t.recordvote(discussionid, RATING_REMOVE_HELPFUL, userid, event)[0].then(function() {\n t.removeHelpfulFromPost(post);\n });\n } else {\n // Add helpful mark.\n t.recordvote(discussionid, RATING_HELPFUL, userid, event)[0].then(function() {\n /* check if allowmultiplemarks is on.\n if false: remove other helpful marks false means allowmultiplemarks == 0)\n else: do nothing. */\n if(discussionid == 0) {\n // Remove other helpful mark in dom.\n t.removeOtherHelpful(post.parent().parent());\n if (post.hasClass('statusteacher')) {\n post.removeClass('statusteacher');\n post.addClass('statusboth');\n } else {\n post.addClass('statusstarter');\n }\n\n var promiseStringNotHelpful = str.get_string('marknothelpful', 'mod_moodleoverflow');\n $.when(promiseStringNotHelpful).done(function(string) {\n $(event.target).text(string);\n });\n t.redoStatus(post);\n }\n });\n }\n\n });\n },\n\n removeHelpfulFromPost: function (post) {\n if (post.hasClass('statusstarter')) {\n post.removeClass('statusstarter');\n } else {\n post.removeClass('statusboth');\n post.addClass('statusteacher');\n }\n\n t.redoStatus(post);\n\n var promiseHelpful = str.get_string('markhelpful', 'mod_moodleoverflow');\n $.when(promiseHelpful).done(function (string) {\n post.find('.markhelpful').text(string);\n });\n },\n\n removeOtherHelpful: function(root) {\n var formerhelpful = root.find('.statusstarter, .statusboth');\n if (formerhelpful.length > 0) {\n t.removeHelpfulFromPost(formerhelpful);\n }\n },\n\n removeSolvedFromPost: function(post) {\n if (post.hasClass('statusteacher')) {\n post.removeClass('statusteacher');\n } else {\n post.removeClass('statusboth');\n post.addClass('statusstarter');\n }\n\n t.redoStatus(post);\n\n var promiseHelpful = str.get_string('marksolved', 'mod_moodleoverflow');\n $.when(promiseHelpful).done(function(string) {\n post.find('.marksolved').text(string);\n });\n },\n\n removeOtherSolved: function(root) {\n var formersolution = root.find('.statusteacher, .statusboth');\n if (formersolution.length > 0) {\n t.removeSolvedFromPost(formersolution);\n }\n },\n\n /**\n * Redoes the post status\n * @param {object} post dom with .moodleoverflowpost which status should be redone\n */\n redoStatus: function(post) {\n if ($(post).hasClass('statusboth')) {\n var statusBothRequest = [\n {key: 'teacherrating', component: 'mod_moodleoverflow'},\n {key: 'starterrating', component: 'mod_moodleoverflow'},\n {key: 'bestanswer', component: 'mod_moodleoverflow'}\n ];\n str.get_strings(statusBothRequest).then(function(results) {\n var circle = templates.renderPix('status/c_circle', 'mod_moodleoverflow', results[0]);\n var box = templates.renderPix('status/b_box', 'mod_moodleoverflow', results[1]);\n $.when(box, circle).done(function(boxImg, circleImg) {\n if (screen.width > 600) {\n post.find('.status').html(boxImg + circleImg + results[2]);\n } else {\n post.find('.status').html(boxImg + circleImg);\n }\n });\n return results;\n });\n } else if ($(post).hasClass('statusteacher')) {\n var statusTeacherRequest = [\n {key: 'teacherrating', component: 'mod_moodleoverflow'},\n {key: 'solvedanswer', component: 'mod_moodleoverflow'}\n ];\n str.get_strings(statusTeacherRequest).then(function(results) {\n var circle = templates.renderPix('status/c_outline', 'mod_moodleoverflow', results[0]);\n $.when(circle).done(function(circleImg) {\n if (screen.width > 600) {\n post.find('.status').html(circleImg + results[1]);\n } else {\n post.find('.status').html(circleImg);\n }\n\n });\n return results;\n });\n } else if ($(post).hasClass('statusstarter')) {\n var statusStarterRequest = [\n {key: 'starterrating', component: 'mod_moodleoverflow'},\n {key: 'helpfulanswer', component: 'mod_moodleoverflow'}\n ];\n str.get_strings(statusStarterRequest).then(function(results) {\n var box = templates.renderPix('status/b_outline', 'mod_moodleoverflow', results[0]);\n $.when(box).done(function(boxImg) {\n if (screen.width > 600) {\n post.find('.status').html(boxImg + results[1]);\n } else {\n post.find('.status').html(boxImg);\n }\n });\n return results;\n });\n } else {\n post.find('.status').html('');\n }\n\n }\n };\n\n return t;\n});\n"],"names":["define","$","ajax","templates","notification","Cfg","Url","str","t","recordvote","discussionid","ratingid","userid","event","postid","target","closest","attr","substring","vote","call","methodname","args","sesskey","done","response","parentdiv","parent","children","imageUrl","text","postrating","replaceNode","find","siblings","raterreputation","ownerid","ownerreputation","fail","exception","clickevent","allowmultiplemarks","on","is","indexOf","toggleClass","nextAll","removeClass","prevAll","post","parents","hasClass","then","removeSolvedFromPost","removeOtherSolved","addClass","promiseStringNotSolved","get_string","when","string","redoStatus","removeHelpfulFromPost","removeOtherHelpful","promiseStringNotHelpful","promiseHelpful","root","formerhelpful","length","formersolution","get_strings","key","component","results","circle","renderPix","box","boxImg","circleImg","screen","width","html"],"mappings":";;;;;;;AAsBAA,sCAAO,CAAC,SAAU,YAAa,iBAAkB,oBAAqB,cAAe,WAAY,aAC7F,SAASC,EAAGC,KAAMC,UAAWC,aAAcC,IAAKC,IAAKC,SAOjDC,EAAI,CAUJC,WAAY,SAASC,aAAcC,SAAUC,OAAQC,WAE7CC,OADSb,EAAEY,MAAME,QAAQC,QAAQ,uBACjBC,KAAK,MACzBH,OAASA,OAAOI,UAAU,OAEtBC,KAAOjB,KAAKkB,KAAK,CAAC,CAClBC,WAAY,iCACZC,KAAM,CACFZ,aAAcA,aACdI,OAAQA,OACRH,SAAUA,SACVY,QAASlB,IAAIkB,mBAKrBJ,KAAK,GAAGK,MAAK,SAASC,cAEdC,UAAYzB,EAAEY,MAAME,QAAQY,SAASA,SAExB,IAAbhB,UACAe,UAAUE,SAAS,mBAAmBA,WAAWX,KAC7C,MAAOX,IAAIuB,SAAS,eAAgB,mBACxCH,UAAUE,SAAS,oBAAoBA,WAAWX,KAC9C,MAAOX,IAAIuB,SAAS,gBAAiB,oBACrB,IAAblB,UACPe,UAAUE,SAAS,mBAAmBA,WAAWX,KAC7C,MAAOX,IAAIuB,SAAS,cAAe,mBACvCH,UAAUE,SAAS,oBAAoBA,WAAWX,KAC9C,MAAOX,IAAIuB,SAAS,iBAAkB,qBAE1CH,UAAUE,SAAS,mBAAmBA,WAAWX,KAC7C,MAAOX,IAAIuB,SAAS,cAAe,mBACvCH,UAAUE,SAAS,oBAAoBA,WAAWX,KAC9C,MAAOX,IAAIuB,SAAS,gBAAiB,oBAG7CH,UAAUE,SAAS,KAAKE,KAAKL,SAASM,YAGtC5B,UAAU6B,YAAY/B,EAAE,yBAAyBgC,KAAK,eAAiBrB,OAAS,MAC3EsB,SAAS,QAAS,SAAWT,SAASU,gBAAkB,UAAW,IACpEV,SA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Q,IACf9B,KAAKhB,KAAK,WAAW+C,KAAKH,UAAYL,QAAQ,IAE9CvB,KAAKhB,KAAK,WAAW+C,KAAKH,cAI3BL,gBAER,GAAIvE,EAAEgD,MAAME,SAAS,iBAAkB,CAK1C5C,IAAI8D,YAJuB,CACvB,CAACC,IAAK,gBAAiBC,UAAW,sBAClC,CAACD,IAAK,gBAAiBC,UAAW,wBAEAnB,MAAK,SAASoB,aAC5CG,IAAMxE,UAAUuE,UAAU,mBAAoB,qBAAsBF,QAAQ,WAChFvE,EAAEyD,KAAKiB,KAAKnD,MAAK,SAASoD,QAClBE,OAAOC,MAAQ,IACf9B,KAAKhB,KAAK,WAAW+C,KAAKJ,OAASJ,QAAQ,IAE3CvB,KAAKhB,KAAK,WAAW+C,KAAKJ,WAG3BJ,gBAGXvB,KAAKhB,KAAK,WAAW+C,KAAK,aAM/BxE,CACV"} \ No newline at end of file diff --git a/amd/build/reviewing.min.js.map b/amd/build/reviewing.min.js.map index d5002e736d..13a68e7925 100644 --- a/amd/build/reviewing.min.js.map +++ b/amd/build/reviewing.min.js.map @@ -1 +1 @@ -{"version":3,"file":"reviewing.min.js","sources":["../src/reviewing.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Implements reviewing functionality\n *\n * @module mod_moodleoverflow/reviewing\n * @copyright 2022 Justus Dieckmann WWU\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport Ajax from 'core/ajax';\nimport Prefetch from 'core/prefetch';\nimport Templates from 'core/templates';\nimport {get_string as getString} from 'core/str';\n\n/**\n * Init function.\n */\nexport function init() {\n Prefetch.prefetchTemplates(['mod_moodleoverflow/reject_post_form', 'mod_moodleoverflow/review_buttons']);\n Prefetch.prefetchStrings('mod_moodleoverflow',\n ['post_was_approved', 'jump_to_next_post_needing_review', 'there_are_no_posts_needing_review', 'post_was_rejected']);\n\n const root = document.getElementById('moodleoverflow-posts');\n root.onclick = async(e) => {\n const action = e.target.getAttribute('data-moodleoverflow-action');\n\n if (!action) {\n return;\n }\n\n const post = e.target.closest('*[data-moodleoverflow-postid]');\n const reviewRow = e.target.closest('.reviewrow');\n const postID = post.getAttribute('data-moodleoverflow-postid');\n\n if (action === 'approve') {\n reviewRow.innerHTML = '.';\n const nextPostURL = await Ajax.call([{\n methodname: 'mod_moodleoverflow_review_approve_post',\n args: {\n postid: postID,\n }\n }])[0];\n\n let message = await getString('post_was_approved', 'mod_moodleoverflow') + ' ';\n if (nextPostURL) {\n message += ``\n + await getString('jump_to_next_post_needing_review', 'mod_moodleoverflow')\n + \"\";\n } else {\n message += await getString('there_are_no_posts_needing_review', 'mod_moodleoverflow');\n }\n reviewRow.innerHTML = message;\n post.classList.remove(\"pendingreview\");\n } else if (action === 'reject') {\n reviewRow.innerHTML = '.';\n reviewRow.innerHTML = await Templates.render('mod_moodleoverflow/reject_post_form', {});\n } else if (action === 'reject-submit') {\n const rejectMessage = post.querySelector('textarea.reject-reason').value.toString().trim();\n reviewRow.innerHTML = '.';\n const args = {\n postid: postID,\n reason: rejectMessage ? rejectMessage : null\n };\n const nextPostURL = await Ajax.call([{\n methodname: 'mod_moodleoverflow_review_reject_post',\n args: args\n }])[0];\n\n let message = await getString('post_was_rejected', 'mod_moodleoverflow') + ' ';\n if (nextPostURL) {\n message += ``\n + await getString('jump_to_next_post_needing_review', 'mod_moodleoverflow')\n + \"\";\n } else {\n message += await getString('there_are_no_posts_needing_review', 'mod_moodleoverflow');\n }\n reviewRow.innerHTML = message;\n } else if (action === 'reject-cancel') {\n reviewRow.innerHTML = '.';\n reviewRow.innerHTML = await Templates.render('mod_moodleoverflow/review_buttons', {});\n }\n };\n}"],"names":["prefetchTemplates","prefetchStrings","document","getElementById","onclick","async","action","e","target","getAttribute","post","closest","reviewRow","postID","innerHTML","nextPostURL","Ajax","call","methodname","args","postid","message","classList","remove","Templates","render","rejectMessage","querySelector","value","toString","trim","reason"],"mappings":";;;;;;;wGA+BaA,kBAAkB,CAAC,sCAAuC,wDAC1DC,gBAAgB,qBACrB,CAAC,oBAAqB,mCAAoC,oCAAqC,sBAEtFC,SAASC,eAAe,wBAChCC,QAAUC,MAAAA,UACLC,OAASC,EAAEC,OAAOC,aAAa,kCAEhCH,oBAICI,KAAOH,EAAEC,OAAOG,QAAQ,iCACxBC,UAAYL,EAAEC,OAAOG,QAAQ,cAC7BE,OAASH,KAAKD,aAAa,iCAElB,YAAXH,OAAsB,CACtBM,UAAUE,UAAY,UAChBC,kBAAoBC,cAAKC,KAAK,CAAC,CACjCC,WAAY,yCACZC,KAAM,CACFC,OAAQP,WAEZ,OAEAQ,cAAgB,mBAAU,oBAAqB,sBAAwB,IAEvEA,SADAN,YACW,mBAAYA,wBACX,mBAAU,mCAAoC,sBACpD,aAEW,mBAAU,oCAAqC,sBAEpEH,UAAUE,UAAYO,QACtBX,KAAKY,UAAUC,OAAO,sBACnB,GAAe,WAAXjB,OACPM,UAAUE,UAAY,IACtBF,UAAUE,gBAAkBU,mBAAUC,OAAO,sCAAuC,SACjF,GAAe,kBAAXnB,OAA4B,OAC7BoB,cAAgBhB,KAAKiB,cAAc,0BAA0BC,MAAMC,WAAWC,OACpFlB,UAAUE,UAAY,UAChBK,KAAO,CACTC,OAAQP,OACRkB,OAAQL,eAAgC,MAEtCX,kBAAoBC,cAAKC,KAAK,CAAC,CACjCC,WAAY,wCACZC,KAAMA,QACN,OAEAE,cAAgB,mBAAU,oBAAqB,sBAAwB,IAEvEA,SADAN,YACW,mBAAYA,wBACX,mBAAU,mCAAoC,sBACpD,aAEW,mBAAU,oCAAqC,sBAEpEH,UAAUE,UAAYO,YACJ,kBAAXf,SACPM,UAAUE,UAAY,IACtBF,UAAUE,gBAAkBU,mBAAUC,OAAO,oCAAqC"} \ No newline at end of file +{"version":3,"file":"reviewing.min.js","sources":["../src/reviewing.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Implements reviewing functionality\n *\n * @module mod_moodleoverflow/reviewing\n * @copyright 2022 Justus Dieckmann WWU\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport Ajax from 'core/ajax';\nimport Prefetch from 'core/prefetch';\nimport Templates from 'core/templates';\nimport {get_string as getString} from 'core/str';\n\n/**\n * Init function.\n */\nexport function init() {\n Prefetch.prefetchTemplates(['mod_moodleoverflow/reject_post_form', 'mod_moodleoverflow/review_buttons']);\n Prefetch.prefetchStrings('mod_moodleoverflow',\n ['post_was_approved', 'jump_to_next_post_needing_review', 'there_are_no_posts_needing_review', 'post_was_rejected']);\n\n const root = document.getElementById('moodleoverflow-posts');\n root.onclick = async(e) => {\n const action = e.target.getAttribute('data-moodleoverflow-action');\n\n if (!action) {\n return;\n }\n\n const post = e.target.closest('*[data-moodleoverflow-postid]');\n const reviewRow = e.target.closest('.reviewrow');\n const postID = post.getAttribute('data-moodleoverflow-postid');\n\n if (action === 'approve') {\n reviewRow.innerHTML = '.';\n const nextPostURL = await Ajax.call([{\n methodname: 'mod_moodleoverflow_review_approve_post',\n args: {\n postid: postID,\n }\n }])[0];\n\n let message = await getString('post_was_approved', 'mod_moodleoverflow') + ' ';\n if (nextPostURL) {\n message += ``\n + await getString('jump_to_next_post_needing_review', 'mod_moodleoverflow')\n + \"\";\n } else {\n message += await getString('there_are_no_posts_needing_review', 'mod_moodleoverflow');\n }\n reviewRow.innerHTML = message;\n post.classList.remove(\"pendingreview\");\n } else if (action === 'reject') {\n reviewRow.innerHTML = '.';\n reviewRow.innerHTML = await Templates.render('mod_moodleoverflow/reject_post_form', {});\n } else if (action === 'reject-submit') {\n const rejectMessage = post.querySelector('textarea.reject-reason').value.toString().trim();\n reviewRow.innerHTML = '.';\n const args = {\n postid: postID,\n reason: rejectMessage ? rejectMessage : null\n };\n const nextPostURL = await Ajax.call([{\n methodname: 'mod_moodleoverflow_review_reject_post',\n args: args\n }])[0];\n\n let message = await getString('post_was_rejected', 'mod_moodleoverflow') + ' ';\n if (nextPostURL) {\n message += ``\n + await getString('jump_to_next_post_needing_review', 'mod_moodleoverflow')\n + \"\";\n } else {\n message += await getString('there_are_no_posts_needing_review', 'mod_moodleoverflow');\n }\n reviewRow.innerHTML = message;\n } else if (action === 'reject-cancel') {\n reviewRow.innerHTML = '.';\n reviewRow.innerHTML = await Templates.render('mod_moodleoverflow/review_buttons', {});\n }\n };\n}"],"names":["prefetchTemplates","prefetchStrings","document","getElementById","onclick","async","action","e","target","getAttribute","post","closest","reviewRow","postID","innerHTML","nextPostURL","Ajax","call","methodname","args","postid","message","classList","remove","Templates","render","rejectMessage","querySelector","value","toString","trim","reason"],"mappings":";;;;;;;wGA+BaA,kBAAkB,CAAC,sCAAuC,wDAC1DC,gBAAgB,qBACrB,CAAC,oBAAqB,mCAAoC,oCAAqC,sBAEtFC,SAASC,eAAe,wBAChCC,QAAUC,gBACLC,OAASC,EAAEC,OAAOC,aAAa,kCAEhCH,oBAICI,KAAOH,EAAEC,OAAOG,QAAQ,iCACxBC,UAAYL,EAAEC,OAAOG,QAAQ,cAC7BE,OAASH,KAAKD,aAAa,iCAElB,YAAXH,OAAsB,CACtBM,UAAUE,UAAY,UAChBC,kBAAoBC,cAAKC,KAAK,CAAC,CACjCC,WAAY,yCACZC,KAAM,CACFC,OAAQP,WAEZ,OAEAQ,cAAgB,mBAAU,oBAAqB,sBAAwB,IAEvEA,SADAN,YACW,mBAAYA,wBACX,mBAAU,mCAAoC,sBACpD,aAEW,mBAAU,oCAAqC,sBAEpEH,UAAUE,UAAYO,QACtBX,KAAKY,UAAUC,OAAO,sBACnB,GAAe,WAAXjB,OACPM,UAAUE,UAAY,IACtBF,UAAUE,gBAAkBU,mBAAUC,OAAO,sCAAuC,SACjF,GAAe,kBAAXnB,OAA4B,OAC7BoB,cAAgBhB,KAAKiB,cAAc,0BAA0BC,MAAMC,WAAWC,OACpFlB,UAAUE,UAAY,UAChBK,KAAO,CACTC,OAAQP,OACRkB,OAAQL,eAAgC,MAEtCX,kBAAoBC,cAAKC,KAAK,CAAC,CACjCC,WAAY,wCACZC,KAAMA,QACN,OAEAE,cAAgB,mBAAU,oBAAqB,sBAAwB,IAEvEA,SADAN,YACW,mBAAYA,wBACX,mBAAU,mCAAoC,sBACpD,aAEW,mBAAU,oCAAqC,sBAEpEH,UAAUE,UAAYO,YACJ,kBAAXf,SACPM,UAAUE,UAAY,IACtBF,UAAUE,gBAAkBU,mBAAUC,OAAO,oCAAqC"} \ No newline at end of file diff --git a/amd/build/warnmodechange.min.js.map b/amd/build/warnmodechange.min.js.map index 70683e5540..b4120395cd 100644 --- a/amd/build/warnmodechange.min.js.map +++ b/amd/build/warnmodechange.min.js.map @@ -1 +1 @@ -{"version":3,"file":"warnmodechange.min.js","sources":["../src/warnmodechange.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Warns on changing the subscription mode.\n *\n * @module mod_moodleoverflow/warnmodechange\n * @copyright 2022 Justus Dieckmann WWU\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport {get_string as getString} from 'core/str';\nimport Notification from 'core/notification';\nimport Prefetch from 'core/prefetch';\n\n/**\n * Init function.\n * @param {string} previousSetting\n */\nexport function init(previousSetting) {\n Prefetch.prefetchStrings('mod_moodleoverflow', ['switchtooptional', 'switchtoauto']);\n Prefetch.prefetchStrings('moodle', ['confirm', 'cancel']);\n const form = document.querySelector('form.mform');\n const select = document.getElementById('id_forcesubscribe');\n form.onsubmit = async(e) => {\n const value = select.selectedOptions[0].value;\n if (value == previousSetting || value == 1 || value == 3) {\n return;\n }\n e.preventDefault();\n await Notification.confirm(\n await getString('confirm'),\n await getString(value == 0 ? 'switchtooptional' : 'switchtoauto', 'mod_moodleoverflow'),\n await getString('confirm'),\n await getString('cancel'),\n () => {\n // Prevent this listener from preventing the event again.\n form.onsubmit = undefined;\n form.requestSubmit(e.submitter);\n }, undefined);\n };\n}"],"names":["previousSetting","prefetchStrings","form","document","querySelector","select","getElementById","onsubmit","async","value","selectedOptions","e","preventDefault","Notification","confirm","undefined","requestSubmit","submitter"],"mappings":";;;;;;;oFA8BqBA,mCACRC,gBAAgB,qBAAsB,CAAC,mBAAoB,mCAC3DA,gBAAgB,SAAU,CAAC,UAAW,iBACzCC,KAAOC,SAASC,cAAc,cAC9BC,OAASF,SAASG,eAAe,qBACvCJ,KAAKK,SAAWC,MAAAA,UACNC,MAAQJ,OAAOK,gBAAgB,GAAGD,MACpCA,OAAST,iBAA4B,GAATS,OAAuB,GAATA,QAG9CE,EAAEC,uBACIC,sBAAaC,cACT,mBAAU,iBACV,mBAAmB,GAATL,MAAa,mBAAqB,eAAgB,4BAC5D,mBAAU,iBACV,mBAAU,WAChB,KAEIP,KAAKK,cAAWQ,EAChBb,KAAKc,cAAcL,EAAEM,kBACtBF"} \ No newline at end of file +{"version":3,"file":"warnmodechange.min.js","sources":["../src/warnmodechange.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Warns on changing the subscription mode.\n *\n * @module mod_moodleoverflow/warnmodechange\n * @copyright 2022 Justus Dieckmann WWU\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport {get_string as getString} from 'core/str';\nimport Notification from 'core/notification';\nimport Prefetch from 'core/prefetch';\n\n/**\n * Init function.\n * @param {string} previousSetting\n */\nexport function init(previousSetting) {\n Prefetch.prefetchStrings('mod_moodleoverflow', ['switchtooptional', 'switchtoauto']);\n Prefetch.prefetchStrings('moodle', ['confirm', 'cancel']);\n const form = document.querySelector('form.mform');\n const select = document.getElementById('id_forcesubscribe');\n form.onsubmit = async(e) => {\n const value = select.selectedOptions[0].value;\n if (value == previousSetting || value == 1 || value == 3) {\n return;\n }\n e.preventDefault();\n await Notification.confirm(\n await getString('confirm'),\n await getString(value == 0 ? 'switchtooptional' : 'switchtoauto', 'mod_moodleoverflow'),\n await getString('confirm'),\n await getString('cancel'),\n () => {\n // Prevent this listener from preventing the event again.\n form.onsubmit = undefined;\n form.requestSubmit(e.submitter);\n }, undefined);\n };\n}"],"names":["previousSetting","prefetchStrings","form","document","querySelector","select","getElementById","onsubmit","async","value","selectedOptions","e","preventDefault","Notification","confirm","undefined","requestSubmit","submitter"],"mappings":";;;;;;;oFA8BqBA,mCACRC,gBAAgB,qBAAsB,CAAC,mBAAoB,mCAC3DA,gBAAgB,SAAU,CAAC,UAAW,iBACzCC,KAAOC,SAASC,cAAc,cAC9BC,OAASF,SAASG,eAAe,qBACvCJ,KAAKK,SAAWC,gBACNC,MAAQJ,OAAOK,gBAAgB,GAAGD,MACpCA,OAAST,iBAA4B,GAATS,OAAuB,GAATA,QAG9CE,EAAEC,uBACIC,sBAAaC,cACT,mBAAU,iBACV,mBAAmB,GAATL,MAAa,mBAAqB,eAAgB,4BAC5D,mBAAU,iBACV,mBAAU,WAChB,KAEIP,KAAKK,cAAWQ,EAChBb,KAAKc,cAAcL,EAAEM,kBACtBF,GATP"} \ No newline at end of file diff --git a/amd/src/functions.js b/amd/src/functions.js index 21a7f8ead5..1bdc3c991b 100644 --- a/amd/src/functions.js +++ b/amd/src/functions.js @@ -93,8 +93,9 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/conf * Initializes the clickevent on upvotes / downvotes. * @param {int} discussionid * @param {int} userid + * @param {int} allowmultiplemarks */ - clickevent: function(discussionid, userid) { + clickevent: function(discussionid, userid, allowmultiplemarks) { $(".upvote").on("click", function(event) { if ($(event.target).is('a')) { event.target = $(event.target).children(); @@ -134,6 +135,9 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/conf } else { // Add solution mark. t.recordvote(discussionid, RATING_SOLVED, userid, event)[0].then(function() { + /* check if allowmultiplemarks is on. + if false: remove other solution marks (false means allowmultiplemarks == 0) + else: do nothing. */ // Remove other solution mark in dom. t.removeOtherSolved(post.parent().parent()); if (post.hasClass('statusstarter')) { @@ -156,7 +160,6 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/conf $(".markhelpful").on("click", function(event) { var post = $(event.target).parents('.moodleoverflowpost'); - if (post.hasClass('statusstarter') || post.hasClass('statusboth')) { // Remove helpful mark. t.recordvote(discussionid, RATING_REMOVE_HELPFUL, userid, event)[0].then(function() { @@ -165,6 +168,9 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/conf } else { // Add helpful mark. t.recordvote(discussionid, RATING_HELPFUL, userid, event)[0].then(function() { + /* check if allowmultiplemarks is on. + if false: remove other helpful marks false means allowmultiplemarks == 0) + else: do nothing. */ // Remove other helpful mark in dom. t.removeOtherHelpful(post.parent().parent()); if (post.hasClass('statusteacher')) { diff --git a/discussion.php b/discussion.php index 1989776532..f0dd027d08 100644 --- a/discussion.php +++ b/discussion.php @@ -55,8 +55,10 @@ throw new moodle_exception('invalidcoursemodule'); } +$multiplemarks = $DB->get_record('moodleoverflow', array('id' => $moodleoverflow->id), 'allowmultiplemarks'); + $PAGE->requires->js_call_amd('mod_moodleoverflow/functions', - 'clickevent', array($d, $USER->id)); + 'clickevent', array($d, $USER->id, $multiplemarks->allowmultiplemarks)); // Set the modulecontext. $modulecontext = context_module::instance($cm->id); diff --git a/lang/en/moodleoverflow.php b/lang/en/moodleoverflow.php index 49b49286bb..c640dbfdcd 100644 --- a/lang/en/moodleoverflow.php +++ b/lang/en/moodleoverflow.php @@ -329,7 +329,7 @@ $string['attachments'] = 'Attachments'; $string['attachment_help'] = 'You can optionally attach one or more files to a forum post. If you attach an image, it will be displayed after the message.'; $string['allowmultiplemarks'] = 'Multiple marks?'; -$string['allowmultiplemarks_help'] = 'A post can be marked as helpful or solved. Withing a discussion, only one post can be marked as helpful/solved. Click the checkbox to mark multiple posts as helpful/solved.'; +$string['allowmultiplemarks_help'] = 'A post can be marked as helpful or solved. Within a discussion, only one post can be marked as helpful/solved. Click the checkbox to mark multiple posts as helpful/solved.'; // Templates. $string['helpfulanswer'] = 'The question owner accepted this as the best answer.'; diff --git a/locallib.php b/locallib.php index 0f001969f6..47b5de099e 100644 --- a/locallib.php +++ b/locallib.php @@ -1214,7 +1214,6 @@ function moodleoverflow_print_post($post, $discussion, $moodleoverflow, $cm, $co $canmarkhelpful = (($USER->id == $discussion->userid) && ($USER->id != $post->userid) && ($iscomment != $post->parent) && !empty($post->parent)); if ($canmarkhelpful) { - // When the post is already marked, remove the mark instead. $link = '/mod/moodleoverflow/discussion.php'; if ($post->statusstarter) { @@ -1235,7 +1234,7 @@ function moodleoverflow_print_post($post, $discussion, $moodleoverflow, $cm, $co $link = '/mod/moodleoverflow/discussion.php'; if ($post->statusteacher) { $commands[] = html_writer::tag('a', $str->marknotsolved, - array('class' => 'marksolved onlyifreviewed', 'role' => 'button', 'tabindex' => '0')); + array('class' => 'marksolved onlyifreviewed', 'role' => 'button', 'tabindex' => '0')); } else { $commands[] = html_writer::tag('a', $str->marksolved, array('class' => 'marksolved onlyifreviewed', 'role' => 'button', 'tabindex' => '0'));