diff --git a/comment/lib.php b/comment/lib.php index 8a392840916..7c95224fc15 100644 --- a/comment/lib.php +++ b/comment/lib.php @@ -506,6 +506,9 @@ class comment { $html .= html_writer::start_tag('div', array('class' => 'comment-area')); $html .= html_writer::start_tag('div', array('class' => 'db')); + $html .= html_writer::tag('label', + get_string('comment', 'comment'), + ['for' => 'dlg-content-'.$this->cid, 'class' => 'sr-only']); $html .= html_writer::tag('textarea', '', $textareaattrs); $html .= html_writer::end_tag('div'); // .db diff --git a/question/bank/comment/amd/build/comment.min.js b/question/bank/comment/amd/build/comment.min.js index 47a8d787fc2..95326aadd70 100644 --- a/question/bank/comment/amd/build/comment.min.js +++ b/question/bank/comment/amd/build/comment.min.js @@ -6,6 +6,6 @@ define("qbank_comment/comment",["exports","core/fragment","core/str","core/modal * @copyright 2021 Catalyst IT Australia Pty Ltd * @author Safat Shahin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_fragment=_interopRequireDefault(_fragment),Str=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(Str),_modal_events=_interopRequireDefault(_modal_events),_modal_factory=_interopRequireDefault(_modal_factory),_notification=_interopRequireDefault(_notification);_exports.init=questionSelector=>{const target=document.querySelector(questionSelector);target.addEventListener("click",(()=>{((questionId,courseID,contextId)=>{let args={questionid:questionId,courseid:courseID};_modal_factory.default.create({type:_modal_factory.default.types.SAVE_CANCEL,title:Str.get_string("commentheader","qbank_comment"),body:_fragment.default.loadFragment("qbank_comment","question_comment",contextId,args),large:!0}).then((modal=>{let root=modal.getRoot();return root.on(_modal_events.default.bodyRendered,(function(){document.querySelectorAll("div.comment-area a")[0].style.display="none"})),root.on("change","#question_comment_version_dropdown",(function(e){args.questionid=e.target.value,modal.setBody(_fragment.default.loadFragment("qbank_comment","question_comment",contextId,args))})),Str.get_strings([{key:"addcomment",component:"qbank_comment"},{key:"close",component:"qbank_comment"}]).then((strings=>{modal.setButtonText("save",strings[0]),modal.setButtonText("cancel",strings[1])})).fail(_notification.default.exception),root.on(_modal_events.default.cancel,(function(){location.reload(),modal.hide()})),root.on(_modal_events.default.save,(function(e){e.preventDefault();const submitlink=document.querySelectorAll("div.comment-area a")[0],textarea=document.querySelectorAll("div.comment-area textarea")[0];textarea.value!=textarea.getAttribute("aria-label")&&""!=textarea.value&&submitlink.click()})),root.on("click",'button[data-action="hide"]',(()=>{location.reload(),modal.hide()})),modal.show(),modal})).fail(_notification.default.exception)})(target.dataset.questionid,target.dataset.courseid,target.dataset.contextid)}))}})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_fragment=_interopRequireDefault(_fragment),Str=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(Str),_modal_events=_interopRequireDefault(_modal_events),_modal_factory=_interopRequireDefault(_modal_factory),_notification=_interopRequireDefault(_notification);_exports.init=()=>{const target=document.querySelector("#categoryquestions");null!==target&&target.addEventListener("click",(e=>{e.target.dataset.target&&e.target.dataset.target.includes("questioncommentpreview")&&((questionId,courseID,contextId)=>{let args={questionid:questionId,courseid:courseID};_modal_factory.default.create({type:_modal_factory.default.types.SAVE_CANCEL,title:Str.get_string("commentheader","qbank_comment"),body:_fragment.default.loadFragment("qbank_comment","question_comment",contextId,args),large:!0}).then((modal=>{let root=modal.getRoot();return root.on(_modal_events.default.bodyRendered,(function(){document.querySelectorAll("div.comment-area a")[0].style.display="none"})),root.on("change","#question_comment_version_dropdown",(function(e){args.questionid=e.target.value,modal.setBody(_fragment.default.loadFragment("qbank_comment","question_comment",contextId,args))})),Str.get_strings([{key:"addcomment",component:"qbank_comment"},{key:"close",component:"qbank_comment"}]).then((strings=>{modal.setButtonText("save",strings[0]),modal.setButtonText("cancel",strings[1])})).fail(_notification.default.exception),root.on(_modal_events.default.cancel,(function(){location.reload(),modal.hide()})),root.on(_modal_events.default.save,(function(e){e.preventDefault();const submitlink=document.querySelectorAll("div.comment-area a")[0],textarea=document.querySelectorAll("div.comment-area textarea")[0];textarea.value!=textarea.getAttribute("aria-label")&&""!=textarea.value&&submitlink.click()})),root.on("click",'button[data-action="hide"]',(()=>{location.reload(),modal.hide()})),modal.show(),modal})).fail(_notification.default.exception)})(e.target.dataset.questionid,e.target.dataset.courseid,e.target.dataset.contextid)}))}})); //# sourceMappingURL=comment.min.js.map \ No newline at end of file diff --git a/question/bank/comment/amd/build/comment.min.js.map b/question/bank/comment/amd/build/comment.min.js.map index 2c2442c499c..bf0715609e8 100644 --- a/question/bank/comment/amd/build/comment.min.js.map +++ b/question/bank/comment/amd/build/comment.min.js.map @@ -1 +1 @@ -{"version":3,"file":"comment.min.js","sources":["../src/comment.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 * Column selector js.\n *\n * @module qbank_comment/comment\n * @copyright 2021 Catalyst IT Australia Pty Ltd\n * @author Safat Shahin \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Fragment from 'core/fragment';\nimport * as Str from 'core/str';\nimport ModalEvents from 'core/modal_events';\nimport ModalFactory from 'core/modal_factory';\nimport Notification from 'core/notification';\n\n/**\n * Event listeners for the module.\n *\n * @method clickEvent\n * @param {Number} questionId\n * @param {Number} courseID\n * @param {Number} contextId\n */\nconst commentEvent = (questionId, courseID, contextId) => {\n let args = {\n questionid: questionId,\n courseid: courseID\n };\n ModalFactory.create({\n type: ModalFactory.types.SAVE_CANCEL,\n title: Str.get_string('commentheader', 'qbank_comment'),\n body: Fragment.loadFragment('qbank_comment', 'question_comment', contextId, args),\n large: true,\n }).then((modal) => {\n let root = modal.getRoot();\n\n // Don't display the default add comment link in the modal.\n root.on(ModalEvents.bodyRendered, function() {\n const submitlink = document.querySelectorAll(\"div.comment-area a\")[0];\n submitlink.style.display = 'none';\n });\n\n // Version selection event.\n root.on('change', '#question_comment_version_dropdown', function(e) {\n args.questionid = e.target.value;\n modal.setBody(Fragment.loadFragment('qbank_comment', 'question_comment', contextId, args));\n });\n\n // Get the required strings and updated the modal button text labels.\n Str.get_strings([\n {key: 'addcomment', component: 'qbank_comment'},\n {key: 'close', component: 'qbank_comment'},\n ]).then((strings) => {\n modal.setButtonText('save', strings[0]);\n modal.setButtonText('cancel', strings[1]);\n return;\n }).fail(Notification.exception);\n\n root.on(ModalEvents.cancel, function() {\n location.reload();\n modal.hide();\n });\n\n // Handle adding the comment when the button in the modal is clicked.\n root.on(ModalEvents.save, function(e) {\n e.preventDefault();\n const submitlink = document.querySelectorAll(\"div.comment-area a\")[0];\n const textarea = document.querySelectorAll(\"div.comment-area textarea\")[0];\n\n // Check there is a valid comment to add, and trigger adding if there is.\n if (textarea.value != textarea.getAttribute('aria-label') && textarea.value != '') {\n submitlink.click();\n }\n\n });\n root.on('click', 'button[data-action=\"hide\"]', () => {\n location.reload();\n modal.hide();\n });\n modal.show();\n return modal;\n }).fail(Notification.exception);\n};\n\n/**\n * Entrypoint of the js.\n *\n * @method init\n * @param {string} questionSelector the question comment identifier.\n */\nexport const init = (questionSelector) => {\n const target = document.querySelector(questionSelector);\n target.addEventListener('click', () => {\n // Call for the event listener to listed for clicks in any comment count row.\n commentEvent(target.dataset.questionid, target.dataset.courseid, target.dataset.contextid);\n });\n};\n"],"names":["questionSelector","target","document","querySelector","addEventListener","questionId","courseID","contextId","args","questionid","courseid","create","type","ModalFactory","types","SAVE_CANCEL","title","Str","get_string","body","Fragment","loadFragment","large","then","modal","root","getRoot","on","ModalEvents","bodyRendered","querySelectorAll","style","display","e","value","setBody","get_strings","key","component","strings","setButtonText","fail","Notification","exception","cancel","location","reload","hide","save","preventDefault","submitlink","textarea","getAttribute","click","show","commentEvent","dataset","contextid"],"mappings":";;;;;;;;g8BAyGqBA,yBACXC,OAASC,SAASC,cAAcH,kBACtCC,OAAOG,iBAAiB,SAAS,KArEhB,EAACC,WAAYC,SAAUC,iBACpCC,KAAO,CACPC,WAAYJ,WACZK,SAAUJ,iCAEDK,OAAO,CAChBC,KAAMC,uBAAaC,MAAMC,YACzBC,MAAOC,IAAIC,WAAW,gBAAiB,iBACvCC,KAAMC,kBAASC,aAAa,gBAAiB,mBAAoBd,UAAWC,MAC5Ec,OAAO,IACRC,MAAMC,YACDC,KAAOD,MAAME,iBAGjBD,KAAKE,GAAGC,sBAAYC,cAAc,WACX3B,SAAS4B,iBAAiB,sBAAsB,GACxDC,MAAMC,QAAU,UAI/BP,KAAKE,GAAG,SAAU,sCAAsC,SAASM,GAC7DzB,KAAKC,WAAawB,EAAEhC,OAAOiC,MAC3BV,MAAMW,QAAQf,kBAASC,aAAa,gBAAiB,mBAAoBd,UAAWC,UAIxFS,IAAImB,YAAY,CACZ,CAACC,IAAK,aAAcC,UAAW,iBAC/B,CAACD,IAAK,QAASC,UAAW,mBAC3Bf,MAAMgB,UACLf,MAAMgB,cAAc,OAAQD,QAAQ,IACpCf,MAAMgB,cAAc,SAAUD,QAAQ,OAEvCE,KAAKC,sBAAaC,WAErBlB,KAAKE,GAAGC,sBAAYgB,QAAQ,WACxBC,SAASC,SACTtB,MAAMuB,UAIVtB,KAAKE,GAAGC,sBAAYoB,MAAM,SAASf,GAC/BA,EAAEgB,uBACIC,WAAahD,SAAS4B,iBAAiB,sBAAsB,GAC7DqB,SAAWjD,SAAS4B,iBAAiB,6BAA6B,GAGpEqB,SAASjB,OAASiB,SAASC,aAAa,eAAmC,IAAlBD,SAASjB,OAClEgB,WAAWG,WAInB5B,KAAKE,GAAG,QAAS,8BAA8B,KAC3CkB,SAASC,SACTtB,MAAMuB,UAEVvB,MAAM8B,OACC9B,SACRiB,KAAKC,sBAAaC,YAajBY,CAAatD,OAAOuD,QAAQ/C,WAAYR,OAAOuD,QAAQ9C,SAAUT,OAAOuD,QAAQC"} \ No newline at end of file +{"version":3,"file":"comment.min.js","sources":["../src/comment.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 * Column selector js.\n *\n * @module qbank_comment/comment\n * @copyright 2021 Catalyst IT Australia Pty Ltd\n * @author Safat Shahin \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Fragment from 'core/fragment';\nimport * as Str from 'core/str';\nimport ModalEvents from 'core/modal_events';\nimport ModalFactory from 'core/modal_factory';\nimport Notification from 'core/notification';\n\n/**\n * Event listeners for the module.\n *\n * @method clickEvent\n * @param {Number} questionId\n * @param {Number} courseID\n * @param {Number} contextId\n */\nconst commentEvent = (questionId, courseID, contextId) => {\n let args = {\n questionid: questionId,\n courseid: courseID\n };\n ModalFactory.create({\n type: ModalFactory.types.SAVE_CANCEL,\n title: Str.get_string('commentheader', 'qbank_comment'),\n body: Fragment.loadFragment('qbank_comment', 'question_comment', contextId, args),\n large: true,\n }).then((modal) => {\n let root = modal.getRoot();\n\n // Don't display the default add comment link in the modal.\n root.on(ModalEvents.bodyRendered, function() {\n const submitlink = document.querySelectorAll(\"div.comment-area a\")[0];\n submitlink.style.display = 'none';\n });\n\n // Version selection event.\n root.on('change', '#question_comment_version_dropdown', function(e) {\n args.questionid = e.target.value;\n modal.setBody(Fragment.loadFragment('qbank_comment', 'question_comment', contextId, args));\n });\n\n // Get the required strings and updated the modal button text labels.\n Str.get_strings([\n {key: 'addcomment', component: 'qbank_comment'},\n {key: 'close', component: 'qbank_comment'},\n ]).then((strings) => {\n modal.setButtonText('save', strings[0]);\n modal.setButtonText('cancel', strings[1]);\n return;\n }).fail(Notification.exception);\n\n root.on(ModalEvents.cancel, function() {\n location.reload();\n modal.hide();\n });\n\n // Handle adding the comment when the button in the modal is clicked.\n root.on(ModalEvents.save, function(e) {\n e.preventDefault();\n const submitlink = document.querySelectorAll(\"div.comment-area a\")[0];\n const textarea = document.querySelectorAll(\"div.comment-area textarea\")[0];\n\n // Check there is a valid comment to add, and trigger adding if there is.\n if (textarea.value != textarea.getAttribute('aria-label') && textarea.value != '') {\n submitlink.click();\n }\n\n });\n root.on('click', 'button[data-action=\"hide\"]', () => {\n location.reload();\n modal.hide();\n });\n modal.show();\n return modal;\n }).fail(Notification.exception);\n};\n\n/**\n * Entrypoint of the js.\n *\n * @method init\n */\nexport const init = () => {\n const target = document.querySelector('#categoryquestions');\n if (target !== null) {\n target.addEventListener('click', (e) => {\n if (e.target.dataset.target && e.target.dataset.target.includes('questioncommentpreview')) {\n // Call for the event listener to listed for clicks in any comment count row.\n commentEvent(e.target.dataset.questionid, e.target.dataset.courseid, e.target.dataset.contextid);\n }\n });\n }\n};\n"],"names":["target","document","querySelector","addEventListener","e","dataset","includes","questionId","courseID","contextId","args","questionid","courseid","create","type","ModalFactory","types","SAVE_CANCEL","title","Str","get_string","body","Fragment","loadFragment","large","then","modal","root","getRoot","on","ModalEvents","bodyRendered","querySelectorAll","style","display","value","setBody","get_strings","key","component","strings","setButtonText","fail","Notification","exception","cancel","location","reload","hide","save","preventDefault","submitlink","textarea","getAttribute","click","show","commentEvent","contextid"],"mappings":";;;;;;;;g8BAwGoB,WACVA,OAASC,SAASC,cAAc,sBACvB,OAAXF,QACAA,OAAOG,iBAAiB,SAAUC,IAC1BA,EAAEJ,OAAOK,QAAQL,QAAUI,EAAEJ,OAAOK,QAAQL,OAAOM,SAAS,2BAtEvD,EAACC,WAAYC,SAAUC,iBACpCC,KAAO,CACPC,WAAYJ,WACZK,SAAUJ,iCAEDK,OAAO,CAChBC,KAAMC,uBAAaC,MAAMC,YACzBC,MAAOC,IAAIC,WAAW,gBAAiB,iBACvCC,KAAMC,kBAASC,aAAa,gBAAiB,mBAAoBd,UAAWC,MAC5Ec,OAAO,IACRC,MAAMC,YACDC,KAAOD,MAAME,iBAGjBD,KAAKE,GAAGC,sBAAYC,cAAc,WACX9B,SAAS+B,iBAAiB,sBAAsB,GACxDC,MAAMC,QAAU,UAI/BP,KAAKE,GAAG,SAAU,sCAAsC,SAASzB,GAC7DM,KAAKC,WAAaP,EAAEJ,OAAOmC,MAC3BT,MAAMU,QAAQd,kBAASC,aAAa,gBAAiB,mBAAoBd,UAAWC,UAIxFS,IAAIkB,YAAY,CACZ,CAACC,IAAK,aAAcC,UAAW,iBAC/B,CAACD,IAAK,QAASC,UAAW,mBAC3Bd,MAAMe,UACLd,MAAMe,cAAc,OAAQD,QAAQ,IACpCd,MAAMe,cAAc,SAAUD,QAAQ,OAEvCE,KAAKC,sBAAaC,WAErBjB,KAAKE,GAAGC,sBAAYe,QAAQ,WACxBC,SAASC,SACTrB,MAAMsB,UAIVrB,KAAKE,GAAGC,sBAAYmB,MAAM,SAAS7C,GAC/BA,EAAE8C,uBACIC,WAAalD,SAAS+B,iBAAiB,sBAAsB,GAC7DoB,SAAWnD,SAAS+B,iBAAiB,6BAA6B,GAGpEoB,SAASjB,OAASiB,SAASC,aAAa,eAAmC,IAAlBD,SAASjB,OAClEgB,WAAWG,WAInB3B,KAAKE,GAAG,QAAS,8BAA8B,KAC3CiB,SAASC,SACTrB,MAAMsB,UAEVtB,MAAM6B,OACC7B,SACRgB,KAAKC,sBAAaC,YAcTY,CAAapD,EAAEJ,OAAOK,QAAQM,WAAYP,EAAEJ,OAAOK,QAAQO,SAAUR,EAAEJ,OAAOK,QAAQoD"} \ No newline at end of file diff --git a/question/bank/comment/amd/src/comment.js b/question/bank/comment/amd/src/comment.js index afab5d5d15b..b2a6e0f7e80 100644 --- a/question/bank/comment/amd/src/comment.js +++ b/question/bank/comment/amd/src/comment.js @@ -101,12 +101,15 @@ const commentEvent = (questionId, courseID, contextId) => { * Entrypoint of the js. * * @method init - * @param {string} questionSelector the question comment identifier. */ -export const init = (questionSelector) => { - const target = document.querySelector(questionSelector); - target.addEventListener('click', () => { - // Call for the event listener to listed for clicks in any comment count row. - commentEvent(target.dataset.questionid, target.dataset.courseid, target.dataset.contextid); - }); +export const init = () => { + const target = document.querySelector('#categoryquestions'); + if (target !== null) { + target.addEventListener('click', (e) => { + if (e.target.dataset.target && e.target.dataset.target.includes('questioncommentpreview')) { + // Call for the event listener to listed for clicks in any comment count row. + commentEvent(e.target.dataset.questionid, e.target.dataset.courseid, e.target.dataset.contextid); + } + }); + } }; diff --git a/question/bank/comment/classes/comment_count_column.php b/question/bank/comment/classes/comment_count_column.php index 171dff3fa5a..3995cf3367b 100644 --- a/question/bank/comment/classes/comment_count_column.php +++ b/question/bank/comment/classes/comment_count_column.php @@ -29,6 +29,35 @@ use question_bank; */ class comment_count_column extends column_base { + /** + * @var bool Comments enabled or not from config. + */ + protected $commentsenabled = true; + + /** + * Load javascript module if enabled. + * + * @return void + */ + public function init(): void { + parent::init(); + $this->check_comments_status(); + if ($this->commentsenabled) { + global $PAGE; + $PAGE->requires->js_call_amd('qbank_comment/comment', 'init'); + } + } + + /** + * Check if comments is turned on in the system or not. + */ + protected function check_comments_status(): void { + global $CFG; + if (!$CFG->usecomments) { + $this->commentsenabled = false; + } + } + /** * Get the name of the column, used internally. * @@ -54,7 +83,7 @@ class comment_count_column extends column_base { * @param string $rowclasses Classes that can be added. */ protected function display_content($question, $rowclasses): void { - global $DB, $PAGE; + global $DB; $syscontext = \context_system::instance(); $args = [ 'component' => 'qbank_comment', @@ -66,8 +95,6 @@ class comment_count_column extends column_base { $attributes = []; if (question_has_capability_on($question, 'comment')) { $target = 'questioncommentpreview_' . $question->id; - $datatarget = '[data-target="' . $target . '"]'; - $PAGE->requires->js_call_amd('qbank_comment/comment', 'init', [$datatarget]); $attributes = [ 'href' => '#', 'data-target' => $target,