mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 14:03:52 +01:00
MDL-53921 gradingform: Destroy frequently used comment dialog on hide
This commit is contained in:
parent
6c1342d7e5
commit
7a6346429b
@ -1 +1 @@
|
||||
define(["jquery","core/templates","core/notification","core/yui"],function(a,b,c){return{initialise:function(d,e,f,g){function h(b,c){var e="<label>"+M.util.get_string("insertcomment","gradingform_guide")+"</label>",g="comment-chooser-"+d+"-cancel",h='<button id="'+g+'">'+M.util.get_string("cancel","moodle")+"</button>";"undefined"==typeof j&&(j=new M.core.dialogue({modal:!0,headerContent:e,bodyContent:b,footerContent:h,focusAfterHide:"#"+f,id:"comments-chooser-dialog-"+d}),a("#"+g).click(function(){"undefined"!=typeof j&&j.hide()}),a.each(c,function(b,c){var e="#comment-option-"+d+"-"+c.id;a(e).click(function(){var b=a("#"+f),d=b.val();""!==a.trim(d)&&(d+="\n"),d+=c.description,b.val(d),"undefined"!=typeof j&&j.hide()}),a(document).off("keypress",e).on("keypress",e,function(){var b=event.which||event.keyCode;(13==b||32==b)&&a(e).click()})})),j.show()}function i(){var a={criterionId:d,comments:g};b.render("gradingform_guide/comment_chooser",a).done(function(a){h(a,g)}).fail(c.exception)}var j;a("#"+e).click(function(a){a.preventDefault(),i()})}}});
|
||||
define(["jquery","core/templates","core/notification","core/yui"],function(a,b,c){return{initialise:function(d,e,f,g){function h(b,c){var e="<label>"+M.util.get_string("insertcomment","gradingform_guide")+"</label>",g="comment-chooser-"+d+"-cancel",h='<button id="'+g+'">'+M.util.get_string("cancel","moodle")+"</button>",i=new M.core.dialogue({modal:!0,headerContent:e,bodyContent:b,footerContent:h,focusAfterHide:"#"+f,id:"comments-chooser-dialog-"+d});a("#"+g).click(function(){i.hide()}),a.each(c,function(b,c){var e="#comment-option-"+d+"-"+c.id;a(e).click(function(){var b=a("#"+f),d=b.val();""!==a.trim(d)&&(d+="\n"),d+=c.description,b.val(d),i.hide()}),a(document).off("keypress",e).on("keypress",e,function(){var b=event.which||event.keyCode;(13==b||32==b)&&a(e).click()})}),i.after("visibleChange",function(a){a.prevVal&&!a.newVal&&this.destroy()},i),i.show()}function i(){var a={criterionId:d,comments:g};b.render("gradingform_guide/comment_chooser",a).done(function(a){h(a,g)}).fail(c.exception)}a("#"+e).click(function(a){a.preventDefault(),i()})}}});
|
@ -40,8 +40,6 @@ define(['jquery', 'core/templates', 'core/notification', 'core/yui'], function (
|
||||
* @param commentOptions The array of frequently used comments to be used as options.
|
||||
*/
|
||||
initialise: function (criterionId, buttonId, remarkId, commentOptions) {
|
||||
var chooserDialog;
|
||||
|
||||
/**
|
||||
* Display the chooser dialog using the compiled HTML from the mustache template
|
||||
* and binds onclick events for the generated comment options.
|
||||
@ -54,58 +52,61 @@ define(['jquery', 'core/templates', 'core/notification', 'core/yui'], function (
|
||||
var cancelButtonId = 'comment-chooser-' + criterionId + '-cancel';
|
||||
var cancelButton = '<button id="' + cancelButtonId + '">' + M.util.get_string('cancel', 'moodle') + '</button>';
|
||||
|
||||
if (typeof chooserDialog === 'undefined') {
|
||||
// Set dialog's body content.
|
||||
chooserDialog = new M.core.dialogue({
|
||||
modal: true,
|
||||
headerContent: titleLabel,
|
||||
bodyContent: compiledSource,
|
||||
footerContent: cancelButton,
|
||||
focusAfterHide: '#' + remarkId,
|
||||
id: "comments-chooser-dialog-" + criterionId
|
||||
// Set dialog's body content.
|
||||
var chooserDialog = new M.core.dialogue({
|
||||
modal: true,
|
||||
headerContent: titleLabel,
|
||||
bodyContent: compiledSource,
|
||||
footerContent: cancelButton,
|
||||
focusAfterHide: '#' + remarkId,
|
||||
id: "comments-chooser-dialog-" + criterionId
|
||||
});
|
||||
|
||||
// Bind click event to the cancel button.
|
||||
$("#" + cancelButtonId).click(function() {
|
||||
chooserDialog.hide();
|
||||
});
|
||||
|
||||
// Loop over each comment item and bind click events.
|
||||
$.each(comments, function (index, comment) {
|
||||
var commentOptionId = '#comment-option-' + criterionId + '-' + comment.id;
|
||||
|
||||
// Delegate click event for the generated option link.
|
||||
$(commentOptionId).click(function () {
|
||||
var remarkTextArea = $('#' + remarkId);
|
||||
var remarkText = remarkTextArea.val();
|
||||
|
||||
// Add line break if the current value of the remark text is not empty.
|
||||
if ($.trim(remarkText) !== '') {
|
||||
remarkText += '\n';
|
||||
}
|
||||
remarkText += comment.description;
|
||||
|
||||
remarkTextArea.val(remarkText);
|
||||
|
||||
chooserDialog.hide();
|
||||
});
|
||||
|
||||
// Bind click event to the cancel button.
|
||||
$("#" + cancelButtonId).click(function() {
|
||||
if (typeof chooserDialog !== 'undefined') {
|
||||
chooserDialog.hide();
|
||||
// Handle keypress on list items.
|
||||
$(document).off('keypress', commentOptionId).on('keypress', commentOptionId, function () {
|
||||
var keyCode = event.which || event.keyCode;
|
||||
|
||||
// Enter or space key.
|
||||
if (keyCode == 13 || keyCode == 32) {
|
||||
// Trigger click event.
|
||||
$(commentOptionId).click();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Loop over each comment item and bind click events.
|
||||
$.each(comments, function (index, comment) {
|
||||
var commentOptionId = '#comment-option-' + criterionId + '-' + comment.id;
|
||||
|
||||
// Delegate click event for the generated option link.
|
||||
$(commentOptionId).click(function () {
|
||||
var remarkTextArea = $('#' + remarkId);
|
||||
var remarkText = remarkTextArea.val();
|
||||
|
||||
// Add line break if the current value of the remark text is not empty.
|
||||
if ($.trim(remarkText) !== '') {
|
||||
remarkText += '\n';
|
||||
}
|
||||
remarkText += comment.description;
|
||||
|
||||
remarkTextArea.val(remarkText);
|
||||
|
||||
if (typeof chooserDialog !== 'undefined') {
|
||||
chooserDialog.hide();
|
||||
}
|
||||
});
|
||||
|
||||
// Handle keypress on list items.
|
||||
$(document).off('keypress', commentOptionId).on('keypress', commentOptionId, function () {
|
||||
var keyCode = event.which || event.keyCode;
|
||||
|
||||
// Enter or space key.
|
||||
if (keyCode == 13 || keyCode == 32) {
|
||||
// Trigger click event.
|
||||
$(commentOptionId).click();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
// Destroy the dialog when it is hidden to allow the grading section to
|
||||
// be loaded as a fragment multiple times within the same page.
|
||||
chooserDialog.after('visibleChange', function(e) {
|
||||
// Going from visible to hidden.
|
||||
if (e.prevVal && !e.newVal) {
|
||||
this.destroy();
|
||||
}
|
||||
}, chooserDialog);
|
||||
|
||||
// Show dialog.
|
||||
chooserDialog.show();
|
||||
|
Loading…
x
Reference in New Issue
Block a user