diff --git a/amd/build/questionnaire.min.js b/amd/build/questionnaire.min.js index a442c99..ca17bb7 100644 --- a/amd/build/questionnaire.min.js +++ b/amd/build/questionnaire.min.js @@ -6,6 +6,6 @@ * @copyright 2020 Kevin Tippenhauer * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define("mod_verbalfeedback/questionnaire",["jquery","core/templates","core/notification","core/ajax","core/str","core/modal_factory","core/modal_events"],(function($,Templates,Notification,Ajax,Str,ModalFactory,ModalEvents){var responses=[];let editor;const getEditor=function(){return editor||(editor=$(".editor_atto").length>0?"atto":window.tinyMCE?"tiny":"textarea",editor)},setComment=function(row,classSelector,comment){let append=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if("atto"===getEditor()){const editorcontent=row.find(classSelector+".editor_atto_content");return append?void editorcontent.append(""):void editorcontent.html(comment)}const commentId=row.find(classSelector).attr("id");if(commentId){const $input=$("#"+commentId);if("tiny"===getEditor())return append?void window.tinyMCE.get(commentId).insertContent("
"):void window.tinyMCE.get(commentId).setContent(comment);if(append){const oldComment=$input.val();if(""!==oldComment.trim())return void $input.val(oldComment+"\n\n -"+comment)}$input.val(comment)}},getComment=function(row,classSel){if("atto"===getEditor()){let comment=row.find(classSel+".editor_atto_content").html();return""===comment.replace(/<[^>]+>/g,"").trim()?"":comment}const commentId=row.find(classSel).attr("id");if(commentId){let comment="";return comment="tiny"===getEditor()?window.tinyMCE.get(commentId).getContent():$("#"+commentId).val(),""===comment.replace(/<[^>]+>/g,"").trim()?"":comment}return""};var questionnaire=function(){this.registerEvents(),$('[data-region="question-row"]').each((function(){responses[$(this).data("criterionid")]={criterionid:$(this).data("criterionid"),value:null,studentcomment:"",privatecomment:""}}));let questionnaireTable=$('[data-region="questionnaire"]');if(1==questionnaireTable.data("preview"))return;let fromUser=questionnaireTable.data("fromuserid"),toUser=questionnaireTable.data("touserid"),verbalfeedbackId=questionnaireTable.data("verbalfeedbackid"),submissionId=questionnaireTable.data("submissionid");Ajax.call([{methodname:"mod_verbalfeedback_get_responses",args:{verbalfeedbackid:verbalfeedbackId,fromuserid:fromUser,touserid:toUser,submissionid:submissionId}}])[0].done((function(result){$.each(result.responses,(function(){let response=this;responses[response.criterionid].criterionid=response.criterionid,responses[response.criterionid].value=response.value,responses[response.criterionid].studentcomment=response.studentcomment,responses[response.criterionid].privatecomment=response.privatecomment,$('[data-region="question-row"]').each((function(){if($(this).data("criterionid")===response.criterionid){let options=$(this).find(".scaleoption");options&&options.each((function(){let selected=$(this).find("label");(selected.data("value")===response.value||""===selected.data("value")&&null===response.value)&&(selected.removeClass("badge-secondary"),selected.removeClass("badge-info"),selected.addClass("badge-success"))})),""!==response.studentcomment&&setComment($(this),".student-comment",response.studentcomment),""!==response.privatecomment&&setComment($(this),".private-comment",response.privatecomment)}}))}))})).fail(Notification.exception)};function saveResponses(finalise){$(".student-comment").each((function(){let row=$(this).parents('[data-region="question-row"]');responses[row.data("criterionid")].studentcomment=getComment(row,".student-comment")})),$(".private-comment").each((function(){let row=$(this).parents('[data-region="question-row"]');responses[row.data("criterionid")].privatecomment=getComment(row,".private-comment")}));let questionnaireTable=$('[data-region="questionnaire"]'),toUser=questionnaireTable.data("touserid"),toUserFullname=questionnaireTable.data("tousername"),verbalfeedbackId=questionnaireTable.data("verbalfeedbackid"),submissionId=questionnaireTable.data("submissionid");if(questionnaireTable.data("anonymous")&&finalise){let messageStrings=[{key:"finaliseanonymousfeedback",component:"mod_verbalfeedback"},{key:"confirmfinaliseanonymousfeedback",component:"mod_verbalfeedback",param:{name:toUserFullname}}];Str.get_strings(messageStrings,"mod_verbalfeedback").done((function(messages){!function(title,confirmationMessage,verbalfeedbackId,submissionId,toUser,responses,finalise){let confirmButtonTextPromise=Str.get_string("finalise","mod_verbalfeedback"),confirmModalPromise=ModalFactory.create({title:title,body:confirmationMessage,large:!0,type:ModalFactory.types.SAVE_CANCEL});$.when(confirmButtonTextPromise,confirmModalPromise).done((function(confirmButtonText,modal){modal.setSaveButtonText(confirmButtonText),modal.show(),modal.getRoot().on(ModalEvents.hidden,(function(){modal.setBody("")})),modal.getRoot().on(ModalEvents.save,(function(){submitResponses(verbalfeedbackId,submissionId,toUser,responses,finalise)}))}))}(messages[0],messages[1],verbalfeedbackId,submissionId,toUser,responses,finalise)})).fail(Notification.exception)}else submitResponses(verbalfeedbackId,submissionId,toUser,responses,finalise)}function submitResponses(verbalfeedbackId,submissionId,toUser,responses,finalise){let responseObjects=[];for(const tuple of Object.entries(responses))null!==tuple[1]&&responseObjects.push(tuple[1]);Ajax.call([{methodname:"mod_verbalfeedback_save_responses",args:{verbalfeedbackid:verbalfeedbackId,submissionid:submissionId,touserid:toUser,responses:responseObjects,complete:finalise}}])[0].done((function(response){Str.get_strings([{key:"responsessaved",component:"mod_verbalfeedback"},{key:"errorresponsesavefailed",component:"mod_verbalfeedback"}]).done((function(messages){let notificationData={};response.result?(notificationData.message=messages[0],notificationData.type="success"):(notificationData.message=messages[1],notificationData.type="error"),Notification.addNotification(notificationData)})).fail(Notification.exception),window.location=response.redirurl})).fail(Notification.exception)}return questionnaire.prototype.registerEvents=function(){$(".scaleoption").click((function(e){e.preventDefault();let row=$(this).parents('[data-region="question-row"]'),options=row.find("label");$.each(options,(function(){if($(this).hasClass("badge-success")){$(this).removeClass("badge-success"),$(this).addClass("badge-secondary");var forId=$(this).attr("for");$("#"+forId).removeAttr("checked")}}));let selected=$(this).find("label");selected.removeClass("badge-secondary"),selected.removeClass("badge-info"),selected.addClass("badge-success"),$("#"+selected.attr("for")).attr("checked","checked");let criterionid=row.data("criterionid");""===selected.data("value")?responses[criterionid].value=null:responses[criterionid].value=selected.data("value")})),$(".scaleoptionlabel").hover((function(e){e.preventDefault(),$(this).hasClass("badge-success")||($(this).hasClass("badge-secondary")?($(this).removeClass("badge-secondary"),$(this).addClass("badge-info")):($(this).addClass("badge-secondary"),$(this).removeClass("badge-info")))})),$(".detail-scaleoption").click((function(e){e.preventDefault();let row=$(this).parents('[data-region="detailed-rating"]'),value=$(this).find(".detail-scaleoptionlabel").data("value");setComment(row,".student-comment",value,!0)})),$(".detail-scaleoptionlabel").hover((function(e){e.preventDefault(),$(this).hasClass("badge-success")||($(this).hasClass("badge-secondary")?($(this).removeClass("badge-secondary"),$(this).addClass("badge-info")):($(this).addClass("badge-secondary"),$(this).removeClass("badge-info")))})),$("#save-feedback").click((function(){saveResponses(!1)})),$("#submit-feedback").click((function(){saveResponses(!0)})),$(".btn-detail-rating").click((function(e){e.preventDefault();let detailedRating=$(this).parents('[data-region="question-row"]').find(".detailed-rating");detailedRating.hasClass("hidden")?(detailedRating.removeClass("hidden"),$(this).html("−")):(detailedRating.addClass("hidden"),$(this).html("+"))}))},questionnaire})); +define("mod_verbalfeedback/questionnaire",["jquery","core/templates","core/notification","core/ajax","core/str","core/modal_factory","core/modal_events"],(function($,Templates,Notification,Ajax,Str,ModalFactory,ModalEvents){var responses=[];let editor;const getEditor=function(){return editor||(editor=$(".editor_atto").length>0?"atto":window.tinyMCE?"tiny":"textarea",editor)},setComment=function(row,classSelector,comment){let append=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if("atto"===getEditor()){const editorcontent=row.find(classSelector+".editor_atto_content");return append?void editorcontent.append(""):void editorcontent.html(comment)}const commentId=row.find(classSelector).attr("id");if(commentId){const $input=$("#"+commentId);if("tiny"===getEditor())return append?void window.tinyMCE.get(commentId).insertContent("
"):void window.tinyMCE.get(commentId).setContent(comment);if(append){const oldComment=$input.val();if(""!==oldComment.trim())return void $input.val(oldComment+"\n\n"+comment)}$input.val(comment)}},getComment=function(row,classSel){if("atto"===getEditor()){let comment=row.find(classSel+".editor_atto_content").html();return""===comment.replace(/<[^>]+>/g,"").trim()?"":comment}const commentId=row.find(classSel).attr("id");if(commentId){let comment="";return comment="tiny"===getEditor()?window.tinyMCE.get(commentId).getContent():$("#"+commentId).val(),""===comment.replace(/<[^>]+>/g,"").trim()?"":comment}return""};var questionnaire=function(){this.registerEvents(),$('[data-region="question-row"]').each((function(){responses[$(this).data("criterionid")]={criterionid:$(this).data("criterionid"),value:null,studentcomment:"",privatecomment:""}}));let questionnaireTable=$('[data-region="questionnaire"]');if(1==questionnaireTable.data("preview"))return;let fromUser=questionnaireTable.data("fromuserid"),toUser=questionnaireTable.data("touserid"),verbalfeedbackId=questionnaireTable.data("verbalfeedbackid"),submissionId=questionnaireTable.data("submissionid");Ajax.call([{methodname:"mod_verbalfeedback_get_responses",args:{verbalfeedbackid:verbalfeedbackId,fromuserid:fromUser,touserid:toUser,submissionid:submissionId}}])[0].done((function(result){$.each(result.responses,(function(){let response=this;responses[response.criterionid].criterionid=response.criterionid,responses[response.criterionid].value=response.value,responses[response.criterionid].studentcomment=response.studentcomment,responses[response.criterionid].privatecomment=response.privatecomment,$('[data-region="question-row"]').each((function(){if($(this).data("criterionid")===response.criterionid){let options=$(this).find(".scaleoption");options&&options.each((function(){let selected=$(this).find("label");(selected.data("value")===response.value||""===selected.data("value")&&null===response.value)&&(selected.removeClass("badge-secondary"),selected.removeClass("badge-info"),selected.addClass("badge-success"))})),""!==response.studentcomment&&setComment($(this),".student-comment",response.studentcomment),""!==response.privatecomment&&setComment($(this),".private-comment",response.privatecomment)}}))}))})).fail(Notification.exception)};function saveResponses(finalise){$(".student-comment").each((function(){let row=$(this).parents('[data-region="question-row"]');responses[row.data("criterionid")].studentcomment=getComment(row,".student-comment")})),$(".private-comment").each((function(){let row=$(this).parents('[data-region="question-row"]');responses[row.data("criterionid")].privatecomment=getComment(row,".private-comment")}));let questionnaireTable=$('[data-region="questionnaire"]'),toUser=questionnaireTable.data("touserid"),toUserFullname=questionnaireTable.data("tousername"),verbalfeedbackId=questionnaireTable.data("verbalfeedbackid"),submissionId=questionnaireTable.data("submissionid");if(questionnaireTable.data("anonymous")&&finalise){let messageStrings=[{key:"finaliseanonymousfeedback",component:"mod_verbalfeedback"},{key:"confirmfinaliseanonymousfeedback",component:"mod_verbalfeedback",param:{name:toUserFullname}}];Str.get_strings(messageStrings,"mod_verbalfeedback").done((function(messages){!function(title,confirmationMessage,verbalfeedbackId,submissionId,toUser,responses,finalise){let confirmButtonTextPromise=Str.get_string("finalise","mod_verbalfeedback"),confirmModalPromise=ModalFactory.create({title:title,body:confirmationMessage,large:!0,type:ModalFactory.types.SAVE_CANCEL});$.when(confirmButtonTextPromise,confirmModalPromise).done((function(confirmButtonText,modal){modal.setSaveButtonText(confirmButtonText),modal.show(),modal.getRoot().on(ModalEvents.hidden,(function(){modal.setBody("")})),modal.getRoot().on(ModalEvents.save,(function(){submitResponses(verbalfeedbackId,submissionId,toUser,responses,finalise)}))}))}(messages[0],messages[1],verbalfeedbackId,submissionId,toUser,responses,finalise)})).fail(Notification.exception)}else submitResponses(verbalfeedbackId,submissionId,toUser,responses,finalise)}function submitResponses(verbalfeedbackId,submissionId,toUser,responses,finalise){let responseObjects=[];for(const tuple of Object.entries(responses))null!==tuple[1]&&responseObjects.push(tuple[1]);Ajax.call([{methodname:"mod_verbalfeedback_save_responses",args:{verbalfeedbackid:verbalfeedbackId,submissionid:submissionId,touserid:toUser,responses:responseObjects,complete:finalise}}])[0].done((function(response){Str.get_strings([{key:"responsessaved",component:"mod_verbalfeedback"},{key:"errorresponsesavefailed",component:"mod_verbalfeedback"}]).done((function(messages){let notificationData={};response.result?(notificationData.message=messages[0],notificationData.type="success"):(notificationData.message=messages[1],notificationData.type="error"),Notification.addNotification(notificationData)})).fail(Notification.exception),window.location=response.redirurl})).fail(Notification.exception)}return questionnaire.prototype.registerEvents=function(){$(".scaleoption").click((function(e){e.preventDefault();let row=$(this).parents('[data-region="question-row"]'),options=row.find("label");$.each(options,(function(){if($(this).hasClass("badge-success")){$(this).removeClass("badge-success"),$(this).addClass("badge-secondary");var forId=$(this).attr("for");$("#"+forId).removeAttr("checked")}}));let selected=$(this).find("label");selected.removeClass("badge-secondary"),selected.removeClass("badge-info"),selected.addClass("badge-success"),$("#"+selected.attr("for")).attr("checked","checked");let criterionid=row.data("criterionid");""===selected.data("value")?responses[criterionid].value=null:responses[criterionid].value=selected.data("value")})),$(".scaleoptionlabel").hover((function(e){e.preventDefault(),$(this).hasClass("badge-success")||($(this).hasClass("badge-secondary")?($(this).removeClass("badge-secondary"),$(this).addClass("badge-info")):($(this).addClass("badge-secondary"),$(this).removeClass("badge-info")))})),$(".detail-scaleoption").click((function(e){e.preventDefault();let row=$(this).parents('[data-region="detailed-rating"]'),value=$(this).find(".detail-scaleoptionlabel").data("value");setComment(row,".student-comment",value,!0)})),$(".detail-scaleoptionlabel").hover((function(e){e.preventDefault(),$(this).hasClass("badge-success")||($(this).hasClass("badge-secondary")?($(this).removeClass("badge-secondary"),$(this).addClass("badge-info")):($(this).addClass("badge-secondary"),$(this).removeClass("badge-info")))})),$("#save-feedback").click((function(){saveResponses(!1)})),$("#submit-feedback").click((function(){saveResponses(!0)})),$(".btn-detail-rating").click((function(e){e.preventDefault();let detailedRating=$(this).parents('[data-region="question-row"]').find(".detailed-rating");detailedRating.hasClass("hidden")?(detailedRating.removeClass("hidden"),$(this).html("−")):(detailedRating.addClass("hidden"),$(this).html("+"))}))},questionnaire})); //# sourceMappingURL=questionnaire.min.js.map \ No newline at end of file diff --git a/amd/build/questionnaire.min.js.map b/amd/build/questionnaire.min.js.map index 6aaf054..19d9207 100644 --- a/amd/build/questionnaire.min.js.map +++ b/amd/build/questionnaire.min.js.map @@ -1 +1 @@ -{"version":3,"file":"questionnaire.min.js","sources":["../src/questionnaire.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 * AMD code for the frequently used comments chooser for the marking guide grading form.\n *\n * @module mod_verbalfeedback/questionnaire\n * @class view\n * @copyright 2020 Kevin Tippenhauer \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery',\n 'core/templates',\n 'core/notification',\n 'core/ajax',\n 'core/str',\n 'core/modal_factory',\n 'core/modal_events'\n], function($, Templates, Notification, Ajax, Str, ModalFactory, ModalEvents) {\n\n var responses = [];\n\n let editor;\n const getEditor = function() {\n if (editor) {\n return editor;\n }\n if ($('.editor_atto').length > 0) {\n editor = 'atto';\n } else if (window.tinyMCE) {\n editor = 'tiny';\n } else {\n editor = 'textarea';\n }\n return editor;\n };\n\n const setComment = function(row, classSelector, comment, append = false) {\n if (getEditor() === 'atto') {\n const editorcontent = row.find(classSelector + '.editor_atto_content');\n if (append) {\n editorcontent.append(\"
  • \" + comment + \"
\");\n return;\n }\n editorcontent.html(comment);\n return;\n }\n const commentId = row.find(classSelector).attr('id');\n if (commentId) {\n const $input = $('#' + commentId);\n if (getEditor() === 'tiny') {\n if (append) {\n window.tinyMCE.get(commentId).insertContent('
  • ' + comment + '

');\n return;\n }\n window.tinyMCE.get(commentId).setContent(comment);\n return;\n }\n if (append) {\n const oldComment = $input.val();\n if (oldComment.trim() !== '') {\n $input.val(oldComment + \"\\n\\n -\" + comment);\n return;\n }\n }\n $input.val(comment);\n }\n };\n\n const getComment = function (row, classSel) {\n if (getEditor() === 'atto') {\n let comment = row.find(classSel + '.editor_atto_content').html();\n return comment.replace(/<[^>]+>/g,'').trim() === '' ? '' : comment; // drop empty comments\n }\n const commentId = row.find(classSel).attr('id');\n if (commentId) {\n let comment = '';\n if (getEditor() === 'tiny') {\n comment = window.tinyMCE.get(commentId).getContent();\n } else {\n comment = $('#' + commentId).val();\n }\n return comment.replace(/<[^>]+>/g,'').trim() === '' ? '' : comment; // drop empty comments\n }\n return '';\n };\n\n var questionnaire = function() {\n this.registerEvents();\n\n // Prefill responses array.\n $('[data-region=\"question-row\"]').each(function() {\n responses[$(this).data('criterionid')] = {\n criterionid: $(this).data('criterionid'),\n value: null,\n studentcomment: \"\",\n privatecomment: \"\"\n };\n });\n\n let questionnaireTable = $('[data-region=\"questionnaire\"]');\n\n if(questionnaireTable.data('preview') == true) { // dont use '===' as $preview is '1' not 'true'.\n // do not look for existing submission on preview page\n return;\n }\n\n let fromUser = questionnaireTable.data('fromuserid');\n let toUser = questionnaireTable.data('touserid');\n let verbalfeedbackId = questionnaireTable.data('verbalfeedbackid');\n let submissionId = questionnaireTable.data('submissionid');\n\n let promises = Ajax.call([\n {\n methodname: 'mod_verbalfeedback_get_responses',\n args: {\n verbalfeedbackid: verbalfeedbackId,\n fromuserid: fromUser,\n touserid: toUser,\n submissionid: submissionId\n }\n }\n ]);\n\n promises[0].done(function(result) {\n $.each(result.responses, function() {\n let response = this;\n responses[response.criterionid]['criterionid'] = response.criterionid;\n responses[response.criterionid]['value'] = response.value;\n responses[response.criterionid]['studentcomment'] = response.studentcomment;\n responses[response.criterionid]['privatecomment'] = response.privatecomment;\n\n $('[data-region=\"question-row\"]').each(function() {\n if ($(this).data('criterionid') === response.criterionid) {\n let options = $(this).find('.scaleoption');\n if (options) {\n options.each(function() {\n // Mark selected option as selected.\n let selected = $(this).find('label');\n if (selected.data('value') === response.value) {\n selected.removeClass('badge-secondary');\n selected.removeClass('badge-info');\n selected.addClass('badge-success');\n } else if (selected.data('value') === \"\" && response.value === null) {\n selected.removeClass('badge-secondary');\n selected.removeClass('badge-info');\n selected.addClass('badge-success');\n }\n });\n }\n if (response.studentcomment !== '') {\n setComment($(this), '.student-comment', response.studentcomment);\n }\n if (response.privatecomment !== '') {\n setComment($(this), '.private-comment', response.privatecomment);\n }\n }\n });\n });\n }).fail(Notification.exception);\n };\n\n questionnaire.prototype.registerEvents = function() {\n $('.scaleoption').click(function(e) {\n e.preventDefault();\n\n let row = $(this).parents('[data-region=\"question-row\"]');\n let options = row.find('label');\n\n // Deselect the option that has been selected.\n $.each(options, function() {\n if ($(this).hasClass('badge-success')) {\n $(this).removeClass('badge-success');\n $(this).addClass('badge-secondary');\n\n var forId = $(this).attr('for');\n var optionRadio = $(\"#\" + forId);\n optionRadio.removeAttr('checked');\n }\n });\n\n // Mark selected option as selected.\n let selected = $(this).find('label');\n selected.removeClass('badge-secondary');\n selected.removeClass('badge-info');\n selected.addClass('badge-success');\n\n // Mark hidden radio button as checked.\n let radio = $(\"#\" + selected.attr('for'));\n radio.attr('checked', 'checked');\n let criterionid = row.data('criterionid');\n\n // Add this selected value to the array of responses.\n if (selected.data('value') === \"\") { // === is necessary because == \"0\" equals true;\n responses[criterionid]['value'] = null;\n } else {\n responses[criterionid]['value'] = selected.data('value');\n }\n });\n\n $('.scaleoptionlabel').hover(function(e) {\n e.preventDefault();\n\n if (!$(this).hasClass('badge-success')) {\n if ($(this).hasClass('badge-secondary')) {\n $(this).removeClass('badge-secondary');\n $(this).addClass('badge-info');\n } else {\n $(this).addClass('badge-secondary');\n $(this).removeClass('badge-info');\n }\n }\n });\n\n $('.detail-scaleoption').click(function(e) {\n e.preventDefault();\n\n let row = $(this).parents('[data-region=\"detailed-rating\"]');\n let value = $(this).find('.detail-scaleoptionlabel').data(\"value\");\n setComment(row, '.student-comment', value, true);\n });\n\n $('.detail-scaleoptionlabel').hover(function(e) {\n e.preventDefault();\n\n if (!$(this).hasClass('badge-success')) {\n if ($(this).hasClass('badge-secondary')) {\n $(this).removeClass('badge-secondary');\n $(this).addClass('badge-info');\n } else {\n $(this).addClass('badge-secondary');\n $(this).removeClass('badge-info');\n }\n }\n });\n\n $(\"#save-feedback\").click(function() {\n saveResponses(false);\n });\n\n $(\"#submit-feedback\").click(function() {\n saveResponses(true);\n });\n\n $(\".btn-detail-rating\").click(function(e) {\n e.preventDefault();\n let row = $(this).parents('[data-region=\"question-row\"]');\n let detailedRating = row.find(\".detailed-rating\");\n if(detailedRating.hasClass(\"hidden\")) {\n detailedRating.removeClass(\"hidden\");\n $(this).html(\"−\");\n } else {\n detailedRating.addClass(\"hidden\");\n $(this).html(\"+\");\n }\n\n });\n };\n\n /**\n * Save the responses.\n *\n * @param {boolean} finalise\n */\n function saveResponses(finalise) {\n\n $('.student-comment').each(function() {\n let row = $(this).parents('[data-region=\"question-row\"]');\n responses[row.data('criterionid')]['studentcomment'] = getComment(row,'.student-comment');\n });\n $('.private-comment').each(function() {\n let row = $(this).parents('[data-region=\"question-row\"]');\n responses[row.data('criterionid')]['privatecomment'] = getComment(row, '.private-comment');\n });\n\n let questionnaireTable = $('[data-region=\"questionnaire\"]');\n let toUser = questionnaireTable.data('touserid');\n let toUserFullname = questionnaireTable.data('tousername');\n let verbalfeedbackId = questionnaireTable.data('verbalfeedbackid');\n let submissionId = questionnaireTable.data('submissionid');\n let anonymous = questionnaireTable.data('anonymous');\n\n if (anonymous && finalise) {\n // Show confirmation dialogue to anonymise the feedback responses.\n let messageStrings = [\n {\n key: 'finaliseanonymousfeedback',\n component: 'mod_verbalfeedback'\n },\n {\n key: 'confirmfinaliseanonymousfeedback',\n component: 'mod_verbalfeedback',\n param: {\n 'name': toUserFullname\n }\n }\n ];\n\n Str.get_strings(messageStrings, 'mod_verbalfeedback').done(function(messages) {\n showConfirmationDialogue(messages[0], messages[1], verbalfeedbackId, submissionId, toUser, responses, finalise);\n }).fail(Notification.exception);\n } else {\n // Just save the responses.\n submitResponses(verbalfeedbackId, submissionId, toUser, responses, finalise);\n }\n }\n\n /**\n * Send the responses to the server.\n *\n * @param {number} verbalfeedbackId\n * @param {number} submissionId\n * @param {number} toUser\n * @param {array} responses\n * @param {boolean} finalise\n */\n function submitResponses(verbalfeedbackId, submissionId, toUser, responses, finalise) {\n let responseObjects = [];\n for (const tuple of Object.entries(responses)) {\n if (tuple[1] !== null) {\n responseObjects.push(tuple[1]);\n }\n }\n\n let promises = Ajax.call([\n {\n methodname: 'mod_verbalfeedback_save_responses',\n args: {\n verbalfeedbackid: verbalfeedbackId,\n submissionid: submissionId,\n touserid: toUser,\n responses: responseObjects,\n complete: finalise\n }\n }\n ]);\n\n promises[0].done(function(response) {\n // console.log(response);\n let messageStrings = [\n {\n key: 'responsessaved',\n component: 'mod_verbalfeedback'\n },\n {\n key: 'errorresponsesavefailed',\n component: 'mod_verbalfeedback'\n }\n ];\n\n Str.get_strings(messageStrings).done(function(messages) {\n let notificationData = {};\n if (response.result) {\n notificationData.message = messages[0];\n notificationData.type = \"success\";\n } else {\n notificationData.message = messages[1];\n notificationData.type = \"error\";\n }\n Notification.addNotification(notificationData);\n }).fail(Notification.exception);\n\n window.location = response.redirurl;\n }).fail(Notification.exception);\n }\n\n /**\n * Renders the confirmation dialogue to submit and finalise the responses.\n *\n * @param {string} title\n * @param {string} confirmationMessage\n * @param {number} verbalfeedbackId\n * @param {number} submissionId\n * @param {number} toUser\n * @param {Array} responses\n * @param {boolean} finalise\n */\n function showConfirmationDialogue(title, confirmationMessage, verbalfeedbackId, submissionId, toUser, responses, finalise) {\n let confirmButtonTextPromise = Str.get_string('finalise', 'mod_verbalfeedback');\n let confirmModalPromise = ModalFactory.create({\n title: title,\n body: confirmationMessage,\n large: true,\n type: ModalFactory.types.SAVE_CANCEL\n });\n $.when(confirmButtonTextPromise, confirmModalPromise).done(function(confirmButtonText, modal) {\n modal.setSaveButtonText(confirmButtonText);\n\n // Display the dialogue.\n modal.show();\n\n // On hide handler.\n modal.getRoot().on(ModalEvents.hidden, function() {\n // Empty modal contents when it's hidden.\n modal.setBody('');\n });\n\n modal.getRoot().on(ModalEvents.save, function() {\n submitResponses(verbalfeedbackId, submissionId, toUser, responses, finalise);\n });\n });\n\n }\n\n return questionnaire;\n});\n"],"names":["define","$","Templates","Notification","Ajax","Str","ModalFactory","ModalEvents","responses","editor","getEditor","length","window","tinyMCE","setComment","row","classSelector","comment","append","editorcontent","find","html","commentId","attr","$input","get","insertContent","setContent","oldComment","val","trim","getComment","classSel","replace","getContent","questionnaire","registerEvents","each","this","data","criterionid","value","studentcomment","privatecomment","questionnaireTable","fromUser","toUser","verbalfeedbackId","submissionId","call","methodname","args","verbalfeedbackid","fromuserid","touserid","submissionid","done","result","response","options","selected","removeClass","addClass","fail","exception","saveResponses","finalise","parents","toUserFullname","messageStrings","key","component","param","get_strings","messages","title","confirmationMessage","confirmButtonTextPromise","get_string","confirmModalPromise","create","body","large","type","types","SAVE_CANCEL","when","confirmButtonText","modal","setSaveButtonText","show","getRoot","on","hidden","setBody","save","submitResponses","showConfirmationDialogue","responseObjects","tuple","Object","entries","push","complete","notificationData","message","addNotification","location","redirurl","prototype","click","e","preventDefault","hasClass","forId","removeAttr","hover","detailedRating"],"mappings":";;;;;;;;AAuBAA,0CAAO,CAAC,SACJ,iBACA,oBACA,YACA,WACA,qBACA,sBACD,SAASC,EAAGC,UAAWC,aAAcC,KAAMC,IAAKC,aAAcC,iBAEzDC,UAAY,OAEZC,aACEC,UAAY,kBACVD,SAIAA,OADAR,EAAE,gBAAgBU,OAAS,EAClB,OACFC,OAAOC,QACL,OAEA,WAENJ,SAGLK,WAAa,SAASC,IAAKC,cAAeC,aAASC,kEACjC,SAAhBR,YAAwB,OAClBS,cAAgBJ,IAAIK,KAAKJ,cAAgB,+BAC3CE,YACAC,cAAcD,OAAO,WAAaD,QAAU,mBAGhDE,cAAcE,KAAKJ,eAGjBK,UAAYP,IAAIK,KAAKJ,eAAeO,KAAK,SAC3CD,UAAW,OACLE,OAASvB,EAAE,IAAMqB,cACH,SAAhBZ,mBACIQ,YACAN,OAAOC,QAAQY,IAAIH,WAAWI,cAAc,WAAaT,QAAU,wBAGvEL,OAAOC,QAAQY,IAAIH,WAAWK,WAAWV,YAGzCC,OAAQ,OACFU,WAAaJ,OAAOK,SACA,KAAtBD,WAAWE,mBACXN,OAAOK,IAAID,WAAa,SAAWX,SAI3CO,OAAOK,IAAIZ,WAIbc,WAAa,SAAUhB,IAAKiB,aACV,SAAhBtB,YAAwB,KACpBO,QAAUF,IAAIK,KAAKY,SAAW,wBAAwBX,aACT,KAA1CJ,QAAQgB,QAAQ,WAAW,IAAIH,OAAgB,GAAKb,cAEzDK,UAAYP,IAAIK,KAAKY,UAAU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,qBAEEK,eADMpH,EAAEqC,MAAM6B,QAAQ,gCACD/C,KAAK,oBAC3BiG,eAAeJ,SAAS,WACvBI,eAAexD,YAAY,UAC3B5D,EAAEqC,MAAMjB,KAAK,OAEbgG,eAAevD,SAAS,UACxB7D,EAAEqC,MAAMjB,KAAK,UAuJlBc"} \ No newline at end of file +{"version":3,"file":"questionnaire.min.js","sources":["../src/questionnaire.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 * AMD code for the frequently used comments chooser for the marking guide grading form.\n *\n * @module mod_verbalfeedback/questionnaire\n * @class view\n * @copyright 2020 Kevin Tippenhauer \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery',\n 'core/templates',\n 'core/notification',\n 'core/ajax',\n 'core/str',\n 'core/modal_factory',\n 'core/modal_events'\n], function($, Templates, Notification, Ajax, Str, ModalFactory, ModalEvents) {\n\n var responses = [];\n\n let editor;\n const getEditor = function() {\n if (editor) {\n return editor;\n }\n if ($('.editor_atto').length > 0) {\n editor = 'atto';\n } else if (window.tinyMCE) {\n editor = 'tiny';\n } else {\n editor = 'textarea';\n }\n return editor;\n };\n\n const setComment = function(row, classSelector, comment, append = false) {\n if (getEditor() === 'atto') {\n const editorcontent = row.find(classSelector + '.editor_atto_content');\n if (append) {\n editorcontent.append(\"
  • \" + comment + \"
\");\n return;\n }\n editorcontent.html(comment);\n return;\n }\n const commentId = row.find(classSelector).attr('id');\n if (commentId) {\n const $input = $('#' + commentId);\n if (getEditor() === 'tiny') {\n if (append) {\n window.tinyMCE.get(commentId).insertContent('
  • ' + comment + '

');\n return;\n }\n window.tinyMCE.get(commentId).setContent(comment);\n return;\n }\n if (append) {\n const oldComment = $input.val();\n if (oldComment.trim() !== '') {\n $input.val(oldComment + \"\\n\\n\" + comment);\n return;\n }\n }\n $input.val(comment);\n }\n };\n\n const getComment = function (row, classSel) {\n if (getEditor() === 'atto') {\n let comment = row.find(classSel + '.editor_atto_content').html();\n return comment.replace(/<[^>]+>/g,'').trim() === '' ? '' : comment; // drop empty comments\n }\n const commentId = row.find(classSel).attr('id');\n if (commentId) {\n let comment = '';\n if (getEditor() === 'tiny') {\n comment = window.tinyMCE.get(commentId).getContent();\n } else {\n comment = $('#' + commentId).val();\n }\n return comment.replace(/<[^>]+>/g,'').trim() === '' ? '' : comment; // drop empty comments\n }\n return '';\n };\n\n var questionnaire = function() {\n this.registerEvents();\n\n // Prefill responses array.\n $('[data-region=\"question-row\"]').each(function() {\n responses[$(this).data('criterionid')] = {\n criterionid: $(this).data('criterionid'),\n value: null,\n studentcomment: \"\",\n privatecomment: \"\"\n };\n });\n\n let questionnaireTable = $('[data-region=\"questionnaire\"]');\n\n if(questionnaireTable.data('preview') == true) { // dont use '===' as $preview is '1' not 'true'.\n // do not look for existing submission on preview page\n return;\n }\n\n let fromUser = questionnaireTable.data('fromuserid');\n let toUser = questionnaireTable.data('touserid');\n let verbalfeedbackId = questionnaireTable.data('verbalfeedbackid');\n let submissionId = questionnaireTable.data('submissionid');\n\n let promises = Ajax.call([\n {\n methodname: 'mod_verbalfeedback_get_responses',\n args: {\n verbalfeedbackid: verbalfeedbackId,\n fromuserid: fromUser,\n touserid: toUser,\n submissionid: submissionId\n }\n }\n ]);\n\n promises[0].done(function(result) {\n $.each(result.responses, function() {\n let response = this;\n responses[response.criterionid]['criterionid'] = response.criterionid;\n responses[response.criterionid]['value'] = response.value;\n responses[response.criterionid]['studentcomment'] = response.studentcomment;\n responses[response.criterionid]['privatecomment'] = response.privatecomment;\n\n $('[data-region=\"question-row\"]').each(function() {\n if ($(this).data('criterionid') === response.criterionid) {\n let options = $(this).find('.scaleoption');\n if (options) {\n options.each(function() {\n // Mark selected option as selected.\n let selected = $(this).find('label');\n if (selected.data('value') === response.value) {\n selected.removeClass('badge-secondary');\n selected.removeClass('badge-info');\n selected.addClass('badge-success');\n } else if (selected.data('value') === \"\" && response.value === null) {\n selected.removeClass('badge-secondary');\n selected.removeClass('badge-info');\n selected.addClass('badge-success');\n }\n });\n }\n if (response.studentcomment !== '') {\n setComment($(this), '.student-comment', response.studentcomment);\n }\n if (response.privatecomment !== '') {\n setComment($(this), '.private-comment', response.privatecomment);\n }\n }\n });\n });\n }).fail(Notification.exception);\n };\n\n questionnaire.prototype.registerEvents = function() {\n $('.scaleoption').click(function(e) {\n e.preventDefault();\n\n let row = $(this).parents('[data-region=\"question-row\"]');\n let options = row.find('label');\n\n // Deselect the option that has been selected.\n $.each(options, function() {\n if ($(this).hasClass('badge-success')) {\n $(this).removeClass('badge-success');\n $(this).addClass('badge-secondary');\n\n var forId = $(this).attr('for');\n var optionRadio = $(\"#\" + forId);\n optionRadio.removeAttr('checked');\n }\n });\n\n // Mark selected option as selected.\n let selected = $(this).find('label');\n selected.removeClass('badge-secondary');\n selected.removeClass('badge-info');\n selected.addClass('badge-success');\n\n // Mark hidden radio button as checked.\n let radio = $(\"#\" + selected.attr('for'));\n radio.attr('checked', 'checked');\n let criterionid = row.data('criterionid');\n\n // Add this selected value to the array of responses.\n if (selected.data('value') === \"\") { // === is necessary because == \"0\" equals true;\n responses[criterionid]['value'] = null;\n } else {\n responses[criterionid]['value'] = selected.data('value');\n }\n });\n\n $('.scaleoptionlabel').hover(function(e) {\n e.preventDefault();\n\n if (!$(this).hasClass('badge-success')) {\n if ($(this).hasClass('badge-secondary')) {\n $(this).removeClass('badge-secondary');\n $(this).addClass('badge-info');\n } else {\n $(this).addClass('badge-secondary');\n $(this).removeClass('badge-info');\n }\n }\n });\n\n $('.detail-scaleoption').click(function(e) {\n e.preventDefault();\n\n let row = $(this).parents('[data-region=\"detailed-rating\"]');\n let value = $(this).find('.detail-scaleoptionlabel').data(\"value\");\n setComment(row, '.student-comment', value, true);\n });\n\n $('.detail-scaleoptionlabel').hover(function(e) {\n e.preventDefault();\n\n if (!$(this).hasClass('badge-success')) {\n if ($(this).hasClass('badge-secondary')) {\n $(this).removeClass('badge-secondary');\n $(this).addClass('badge-info');\n } else {\n $(this).addClass('badge-secondary');\n $(this).removeClass('badge-info');\n }\n }\n });\n\n $(\"#save-feedback\").click(function() {\n saveResponses(false);\n });\n\n $(\"#submit-feedback\").click(function() {\n saveResponses(true);\n });\n\n $(\".btn-detail-rating\").click(function(e) {\n e.preventDefault();\n let row = $(this).parents('[data-region=\"question-row\"]');\n let detailedRating = row.find(\".detailed-rating\");\n if(detailedRating.hasClass(\"hidden\")) {\n detailedRating.removeClass(\"hidden\");\n $(this).html(\"−\");\n } else {\n detailedRating.addClass(\"hidden\");\n $(this).html(\"+\");\n }\n\n });\n };\n\n /**\n * Save the responses.\n *\n * @param {boolean} finalise\n */\n function saveResponses(finalise) {\n\n $('.student-comment').each(function() {\n let row = $(this).parents('[data-region=\"question-row\"]');\n responses[row.data('criterionid')]['studentcomment'] = getComment(row,'.student-comment');\n });\n $('.private-comment').each(function() {\n let row = $(this).parents('[data-region=\"question-row\"]');\n responses[row.data('criterionid')]['privatecomment'] = getComment(row, '.private-comment');\n });\n\n let questionnaireTable = $('[data-region=\"questionnaire\"]');\n let toUser = questionnaireTable.data('touserid');\n let toUserFullname = questionnaireTable.data('tousername');\n let verbalfeedbackId = questionnaireTable.data('verbalfeedbackid');\n let submissionId = questionnaireTable.data('submissionid');\n let anonymous = questionnaireTable.data('anonymous');\n\n if (anonymous && finalise) {\n // Show confirmation dialogue to anonymise the feedback responses.\n let messageStrings = [\n {\n key: 'finaliseanonymousfeedback',\n component: 'mod_verbalfeedback'\n },\n {\n key: 'confirmfinaliseanonymousfeedback',\n component: 'mod_verbalfeedback',\n param: {\n 'name': toUserFullname\n }\n }\n ];\n\n Str.get_strings(messageStrings, 'mod_verbalfeedback').done(function(messages) {\n showConfirmationDialogue(messages[0], messages[1], verbalfeedbackId, submissionId, toUser, responses, finalise);\n }).fail(Notification.exception);\n } else {\n // Just save the responses.\n submitResponses(verbalfeedbackId, submissionId, toUser, responses, finalise);\n }\n }\n\n /**\n * Send the responses to the server.\n *\n * @param {number} verbalfeedbackId\n * @param {number} submissionId\n * @param {number} toUser\n * @param {array} responses\n * @param {boolean} finalise\n */\n function submitResponses(verbalfeedbackId, submissionId, toUser, responses, finalise) {\n let responseObjects = [];\n for (const tuple of Object.entries(responses)) {\n if (tuple[1] !== null) {\n responseObjects.push(tuple[1]);\n }\n }\n\n let promises = Ajax.call([\n {\n methodname: 'mod_verbalfeedback_save_responses',\n args: {\n verbalfeedbackid: verbalfeedbackId,\n submissionid: submissionId,\n touserid: toUser,\n responses: responseObjects,\n complete: finalise\n }\n }\n ]);\n\n promises[0].done(function(response) {\n // console.log(response);\n let messageStrings = [\n {\n key: 'responsessaved',\n component: 'mod_verbalfeedback'\n },\n {\n key: 'errorresponsesavefailed',\n component: 'mod_verbalfeedback'\n }\n ];\n\n Str.get_strings(messageStrings).done(function(messages) {\n let notificationData = {};\n if (response.result) {\n notificationData.message = messages[0];\n notificationData.type = \"success\";\n } else {\n notificationData.message = messages[1];\n notificationData.type = \"error\";\n }\n Notification.addNotification(notificationData);\n }).fail(Notification.exception);\n\n window.location = response.redirurl;\n }).fail(Notification.exception);\n }\n\n /**\n * Renders the confirmation dialogue to submit and finalise the responses.\n *\n * @param {string} title\n * @param {string} confirmationMessage\n * @param {number} verbalfeedbackId\n * @param {number} submissionId\n * @param {number} toUser\n * @param {Array} responses\n * @param {boolean} finalise\n */\n function showConfirmationDialogue(title, confirmationMessage, verbalfeedbackId, submissionId, toUser, responses, finalise) {\n let confirmButtonTextPromise = Str.get_string('finalise', 'mod_verbalfeedback');\n let confirmModalPromise = ModalFactory.create({\n title: title,\n body: confirmationMessage,\n large: true,\n type: ModalFactory.types.SAVE_CANCEL\n });\n $.when(confirmButtonTextPromise, confirmModalPromise).done(function(confirmButtonText, modal) {\n modal.setSaveButtonText(confirmButtonText);\n\n // Display the dialogue.\n modal.show();\n\n // On hide handler.\n modal.getRoot().on(ModalEvents.hidden, function() {\n // Empty modal contents when it's hidden.\n modal.setBody('');\n });\n\n modal.getRoot().on(ModalEvents.save, function() {\n submitResponses(verbalfeedbackId, submissionId, toUser, responses, finalise);\n });\n });\n\n }\n\n return questionnaire;\n});\n"],"names":["define","$","Templates","Notification","Ajax","Str","ModalFactory","ModalEvents","responses","editor","getEditor","length","window","tinyMCE","setComment","row","classSelector","comment","append","editorcontent","find","html","commentId","attr","$input","get","insertContent","setContent","oldComment","val","trim","getComment","classSel","replace","getContent","questionnaire","registerEvents","each","this","data","criterionid","value","studentcomment","privatecomment","questionnaireTable","fromUser","toUser","verbalfeedbackId","submissionId","call","methodname","args","verbalfeedbackid","fromuserid","touserid","submissionid","done","result","response","options","selected","removeClass","addClass","fail","exception","saveResponses","finalise","parents","toUserFullname","messageStrings","key","component","param","get_strings","messages","title","confirmationMessage","confirmButtonTextPromise","get_string","confirmModalPromise","create","body","large","type","types","SAVE_CANCEL","when","confirmButtonText","modal","setSaveButtonText","show","getRoot","on","hidden","setBody","save","submitResponses","showConfirmationDialogue","responseObjects","tuple","Object","entries","push","complete","notificationData","message","addNotification","location","redirurl","prototype","click","e","preventDefault","hasClass","forId","removeAttr","hover","detailedRating"],"mappings":";;;;;;;;AAuBAA,0CAAO,CAAC,SACJ,iBACA,oBACA,YACA,WACA,qBACA,sBACD,SAASC,EAAGC,UAAWC,aAAcC,KAAMC,IAAKC,aAAcC,iBAEzDC,UAAY,OAEZC,aACEC,UAAY,kBACVD,SAIAA,OADAR,EAAE,gBAAgBU,OAAS,EAClB,OACFC,OAAOC,QACL,OAEA,WAENJ,SAGLK,WAAa,SAASC,IAAKC,cAAeC,aAASC,kEACjC,SAAhBR,YAAwB,OA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ACjB7D,EAAEqC,MAAMuB,YAAY,mBAKhC5D,EAAE,uBAAuB6G,OAAM,SAASC,GACpCA,EAAEC,qBAEEjG,IAAMd,EAAEqC,MAAM6B,QAAQ,mCACtB1B,MAAQxC,EAAEqC,MAAMlB,KAAK,4BAA4BmB,KAAK,SAC1DzB,WAAWC,IAAK,mBAAoB0B,OAAO,MAG/CxC,EAAE,4BAA4BmH,OAAM,SAASL,GACzCA,EAAEC,iBAEG/G,EAAEqC,MAAM2E,SAAS,mBACdhH,EAAEqC,MAAM2E,SAAS,oBACjBhH,EAAEqC,MAAMuB,YAAY,mBACpB5D,EAAEqC,MAAMwB,SAAS,gBAEjB7D,EAAEqC,MAAMwB,SAAS,mBACjB7D,EAAEqC,MAAMuB,YAAY,mBAKhC5D,EAAE,kBAAkB6G,OAAM,WACtB7C,eAAc,MAGlBhE,EAAE,oBAAoB6G,OAAM,WACxB7C,eAAc,MAGlBhE,EAAE,sBAAsB6G,OAAM,SAASC,GACnCA,EAAEC,qBAEEK,eADMpH,EAAEqC,MAAM6B,QAAQ,gCACD/C,KAAK,oBAC3BiG,eAAeJ,SAAS,WACvBI,eAAexD,YAAY,UAC3B5D,EAAEqC,MAAMjB,KAAK,OAEbgG,eAAevD,SAAS,UACxB7D,EAAEqC,MAAMjB,KAAK,UAuJlBc"} \ No newline at end of file diff --git a/amd/build/report.min.js b/amd/build/report.min.js deleted file mode 100644 index f93f0a4..0000000 --- a/amd/build/report.min.js +++ /dev/null @@ -1,3 +0,0 @@ - - -//# sourceMappingURL=report.min.js.map \ No newline at end of file diff --git a/amd/src/report.js b/amd/src/report.js deleted file mode 100644 index b6ae14d..0000000 --- a/amd/src/report.js +++ /dev/null @@ -1,17 +0,0 @@ -// define(['jquery', -// 'core/templates', -// 'core/notification', -// 'core/ajax', -// 'core/str', -// 'core/modal_factory', -// 'core/modal_events' -// ], function() { -// let init = function (data) { -// this.spiderData = data; -// }; - -// return { -// init: init, -// spiderData: this.spiderData -// }; -// }); \ No newline at end of file diff --git a/classes/forms/template_criterion_delete_form.php b/classes/forms/template_criterion_delete_form.php index ff00cde..0b93205 100644 --- a/classes/forms/template_criterion_delete_form.php +++ b/classes/forms/template_criterion_delete_form.php @@ -53,22 +53,22 @@ public function definition() { foreach ($languages as $l) { $localizedstring = []; - $localizedstring[] =& $mform->createElement('hidden', 'id', 0); - $localizedstring[] =& $mform->createElement('hidden', 'language_id', $l->get_id()); + $localizedstring[] = $mform->createElement('hidden', 'id', 0); + $localizedstring[] = $mform->createElement('hidden', 'language_id', $l->get_id()); $textfieldname = get_string('text', 'verbalfeedback') . ' - ' . $l->get_language(); $style = 'disabled="disabled" wrap="virtual" rows="5" cols="50"'; - $localizedstring[] =& $mform->createElement('textarea', 'string', $textfieldname, $style); + $localizedstring[] = $mform->createElement('textarea', 'string', $textfieldname, ['style' => $style]); $groupname = 'localized_strings[' . $l->get_id() .']'; - $mform->addGroup($localizedstring, $groupname, $textfieldname, [''], true, 'disabled="disabled"'); + $mform->addGroup($localizedstring, $groupname, $textfieldname, [''], true, ['disabled' => 'disabled']); $mform->setType('localized_strings[' . $l->get_id() .'][id]', PARAM_INT); $mform->setType('localized_strings[' . $l->get_id() .'][language_id]', PARAM_INT); $mform->setType('localized_strings[' . $l->get_id() .'][string]', PARAM_TEXT); } - $this->add_action_buttons($cancel = true, $submitlabel = get_string('delete')); + $this->add_action_buttons(true, get_string('delete')); } /** diff --git a/classes/forms/template_criterion_edit_form.php b/classes/forms/template_criterion_edit_form.php index 197e6e1..4dbc0a7 100644 --- a/classes/forms/template_criterion_edit_form.php +++ b/classes/forms/template_criterion_edit_form.php @@ -34,6 +34,10 @@ * The template criterion edit form */ class template_criterion_edit_form extends \moodleform { + + /** @var int */ + public $subratingcount; + /** * The class constructor * @@ -51,7 +55,6 @@ public function __construct($subratingcount = 0) { * @throws \coding_exception */ public function definition() { - global $CFG; $languagerepo = new language_repository(); $mform = $this->_form; // Don't forget the underscore! diff --git a/classes/model/report.php b/classes/model/report.php index a31ba18..90edf39 100644 --- a/classes/model/report.php +++ b/classes/model/report.php @@ -39,6 +39,8 @@ class report { private $reportcategories = []; /** @var null The result */ private $result = null; + /** @var int The instance id */ + public $instanceid = 0; /** * The report class constructor diff --git a/classes/output/model/report_category_view_model.php b/classes/output/model/report_category_view_model.php index cad955a..c6a1658 100644 --- a/classes/output/model/report_category_view_model.php +++ b/classes/output/model/report_category_view_model.php @@ -37,6 +37,8 @@ class report_category_view_model { public $percentage; /** @var array The criteria */ public $criteria = []; + /** @var float */ + public $weight; /** * The report category view model class constructor diff --git a/classes/output/model/report_view_model.php b/classes/output/model/report_view_model.php index 0a1a0d6..9ca3d3c 100644 --- a/classes/output/model/report_view_model.php +++ b/classes/output/model/report_view_model.php @@ -36,6 +36,8 @@ class report_view_model { public $radar; /** @var array The categories */ public $categories = []; + /** @var \lang_string|string */ + public $resultvsmax; /** * The report view model class constructor diff --git a/classes/output/questionnaire.php b/classes/output/questionnaire.php index 6f144ff..4cbf7c3 100644 --- a/classes/output/questionnaire.php +++ b/classes/output/questionnaire.php @@ -28,6 +28,7 @@ use dml_exception; use mod_verbalfeedback\api; use mod_verbalfeedback\helper; +use mod_verbalfeedback\model\instance; use mod_verbalfeedback\model\submission; use mod_verbalfeedback\model\submission_status; use mod_verbalfeedback\repository\instance_repository; @@ -50,6 +51,21 @@ class questionnaire implements renderable, templatable { /** @var bool True, if the questionnaire is rendered for preview. */ private $preview; + /** @var int $contextid */ + public $contextid; + + /** @var instance|null Instance of language */ + public $instance; + + /** @var array List of categories */ + public $categories; + + /** @var int The id of the student */ + public $touserid; + + /** @var int The id of the teacher */ + public $fromuserid; + /** * questionnaire constructor. * diff --git a/classes/output/report.php b/classes/output/report.php index c2e14be..3831c10 100644 --- a/classes/output/report.php +++ b/classes/output/report.php @@ -62,6 +62,12 @@ class report implements renderable, templatable { /** @var string $reportdownloadurl The report download url. */ protected $reportdownloadurl; + /** @var ModelReport */ + public $report; + + /** @var int */ + public $touser; + /** * report constructor. * diff --git a/classes/output/template_category_list.php b/classes/output/template_category_list.php index f709c23..8758c4a 100644 --- a/classes/output/template_category_list.php +++ b/classes/output/template_category_list.php @@ -91,12 +91,14 @@ public function export_for_template(renderer_base $output) { class template_category_view_model { /** @var int The category id */ public $id; - /** @var string The category name */ - public $name; /** @var string The category edit url */ public $editurl; /** @var string The category delete url */ public $deleteurl; + /** @var string */ + public $uniquename; + /** @var int|null Nomber of criterias. */ + public $criteriacount; /** * The template category view model class constructor diff --git a/classes/output/template_criterion_list.php b/classes/output/template_criterion_list.php index 6b1d64f..6fb26f4 100644 --- a/classes/output/template_criterion_list.php +++ b/classes/output/template_criterion_list.php @@ -42,22 +42,11 @@ class template_criterion_list implements renderable, templatable { * @var array */ protected $templatecriteria = []; + /** * @var */ - protected $templatelisturl; - /** - * @var - */ - protected $templatecategorylisturl; - /** - * @var - */ - protected $templatecriterialisturl; - /** - * @var - */ - protected $newtemplatecriteriaurl; + protected $newtemplatecriterionurl; /** * Verbal feedback admin settings constructor. @@ -115,6 +104,9 @@ class template_criterion_view_model { */ public $deleteurl; + /** @var int */ + public $subratingcount; + /** * The template criterion view model class constructor * diff --git a/classes/output/template_list.php b/classes/output/template_list.php index 09d8b57..b1e426d 100644 --- a/classes/output/template_list.php +++ b/classes/output/template_list.php @@ -94,10 +94,14 @@ class template_view_model { public $name; /** @var string The description */ public $description; + /** @var int Number of categories */ + public $categorycount; /** @var string The edit url */ public $editurl; /** @var string The delete url */ public $deleteurl; + /** @var string The download url */ + public $downloadurl; /** * The template view model class constructor diff --git a/classes/utils/calendar_utils.php b/classes/utils/calendar_utils.php deleted file mode 100644 index 263c022..0000000 --- a/classes/utils/calendar_utils.php +++ /dev/null @@ -1,140 +0,0 @@ -. - -/** - * Class for performing user related actions for the verbal feedback activity module. - * - * @package mod_verbalfeedback - * @copyright 2020 Kevin Tippenhauer - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -namespace mod_verbalfeedback\utils; - -defined('MOODLE_INTERNAL') || die(); - -global $CFG; -global $DB; - -require_once($CFG->libdir.'/accesslib.php'); - -use stdClass; -use calendar_event; -use mod_verbalfeedback\api; -use mod_verbalfeedback\model\instance; - -/** - * Class for performing calendar related actions for the verbal feedback activity module. - * - * @copyright 2020 Kevin Tippenhauer - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class calendar_utils { - - /** - * This creates new calendar events given as timeopen and timeclose by $instance. - * - * @param instance $instance The verbal feedback instance. - * @return void - */ - public static function register_events(instance $instance) { - global $CFG; - - require_once($CFG->dirroot.'/calendar/lib.php'); - - $cm = get_coursemodule_from_instance('verbalfeedback', $instance->get_id(), $courseid = $instance->get_course(), - $sectionnum = false, $strictness = MUST_EXIST); - - // Get CMID if not sent as part of $verbalfeedback. - if (!isset($instance->coursemodule)) { - $instance->coursemodule = $cm->id; - } - - // Common event parameters. - $instanceid = $instance->get_id(); - $courseid = $instance->get_course(); - $eventdescription = format_module_intro('verbalfeedback', $instance, $cm); - $visible = instance_is_visible('verbalfeedback', $instance); - - // Calendar event for when the verbal feedback opens. - $eventname = get_string('calendarstart', 'verbalfeedback', $instance->get_name()); - $eventtype = api::VERBALFEEDBACK_EVENT_TYPE_OPEN; - // Calendar event type is set to action event when there's no timeclose. - $calendareventtype = empty($instance->get_timeclose()) ? CALENDAR_EVENT_TYPE_ACTION : CALENDAR_EVENT_TYPE_STANDARD; - self::set_event($instanceid, $eventname, $eventdescription, $eventtype, $calendareventtype, $instance->get_timeopen(), - $visible, $courseid); - - // Calendar event for when the verbal feedback closes. - $eventname = get_string('calendarend', 'verbalfeedback', $instance->get_name()); - $eventtype = api::VERBALFEEDBACK_EVENT_TYPE_CLOSE; - $calendareventtype = CALENDAR_EVENT_TYPE_ACTION; - self::set_event($instanceid, $eventname, $eventdescription, $eventtype, $calendareventtype, - $verbalfeedback->get_timeclose(), $visible, $courseid); - } - - /** - * Sets the calendar event for the verbal feedback instance. - * - * For existing events, if timestamp is not empty, the event will be updated. Otherwise, it will be deleted. - * If the event is not yet existing and the timestamp is empty, the event will be created. - * - * @param int $id The verbal feedback instance ID. - * @param string $eventname The event name. - * @param string $description The event description. - * @param string $eventtype The type of the module event. - * @param int $calendareventtype The calendar event type, whether a standard or an action event. - * @param int $timestamp The event's timestamp. - * @param bool $visible Whether this event is visible. - * @param int $courseid The course ID of this event. - */ - protected static function set_event($id, $eventname, $description, $eventtype, $calendareventtype, $timestamp, $visible, - $courseid) { - global $DB; - - // Build the calendar event object. - $event = new stdClass(); - $event->name = $eventname; - $event->description = $description; - $event->eventtype = $eventtype; - $event->timestart = $timestamp; - $event->timesort = $timestamp; - $event->visible = $visible; - $event->timeduration = 0; - $event->type = $calendareventtype; - - // Check if event exists. - $event->id = $DB->get_field('event', 'id', ['modulename' => 'verbalfeedback', 'instance' => $id, - 'eventtype' => $eventtype, ]); - if ($event->id) { - $calendarevent = calendar_event::load($event->id); - if ($timestamp) { - // Calendar event exists so update it. - $calendarevent->update($event, false); - } else { - // Calendar event is no longer needed. - $calendarevent->delete(); - } - } else if ($timestamp) { - // Event doesn't exist so create one. - $event->courseid = $courseid; - $event->groupid = 0; - $event->userid = 0; - $event->modulename = 'verbalfeedback'; - $event->instance = $id; - - calendar_event::create($event, false); - } - } -} diff --git a/classes/utils/instance_utils.php b/classes/utils/instance_utils.php index ad6f2cd..96af715 100644 --- a/classes/utils/instance_utils.php +++ b/classes/utils/instance_utils.php @@ -96,6 +96,11 @@ public static function register_calendar_events(instance $verbalfeedback) { $cm = get_coursemodule_from_instance('verbalfeedback', $verbalfeedback->get_id(), $verbalfeedback->get_course()); + // Get CMID if not sent as part of $verbalfeedback. + if (!isset($instance->coursemodule)) { + $verbalfeedback->coursemodule = $cm->id; + } + // Common event parameters. $instanceid = $verbalfeedback->get_id(); $courseid = $verbalfeedback->get_course();