Proyectos de Subversion Moodle

Rev

Rev 1 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

{"version":3,"file":"comment_chooser.min.js","sources":["../src/comment_chooser.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 <http://www.gnu.org/licenses/>.\n\n/**\n * AMD code for the frequently used comments chooser for the marking guide grading form.\n *\n * @module     gradingform_guide/comment_chooser\n * @copyright  2015 Jun Pataleta <jun@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/templates', 'core/key_codes', 'core/notification', 'core/yui'],\n        function($, templates, keycodes, notification) {\n\n    // Private variables and functions.\n\n    return /** @alias module:gradingform_guide/comment_chooser */ {\n        // Public variables and functions.\n        /**\n         * Initialises the module.\n         *\n         * Basically, it performs the binding and handling of the button click event for\n         * the 'Insert frequently used comment' button.\n         *\n         * @param {Integer} criterionId The criterion ID.\n         * @param {String} buttonId The element ID of the button which the handler will be bound to.\n         * @param {String} remarkId The element ID of the remark text area where the text of the selected comment will be copied to.\n         * @param {Array} commentOptions The array of frequently used comments to be used as options.\n         */\n        initialise: function(criterionId, buttonId, remarkId, commentOptions) {\n            /**\n             * Display the chooser dialog using the compiled HTML from the mustache template\n             * and binds onclick events for the generated comment options.\n             *\n             * @param {String} compiledSource The compiled HTML from the mustache template\n             * @param {Array} comments Array containing comments.\n             */\n            function displayChooserDialog(compiledSource, comments) {\n                var titleLabel = '<label>' + M.util.get_string('insertcomment', 'gradingform_guide') + '</label>';\n                var cancelButtonId = 'comment-chooser-' + criterionId + '-cancel';\n                var cancelButton = '<button id=\"' + cancelButtonId + '\">' + M.util.get_string('cancel', 'moodle') + '</button>';\n\n                // Set dialog's body content.\n                var chooserDialog = new M.core.dialogue({\n                    modal: true,\n                    headerContent: titleLabel,\n                    bodyContent: compiledSource,\n                    footerContent: cancelButton,\n                    focusAfterHide: '#' + remarkId,\n                    id: \"comments-chooser-dialog-\" + criterionId\n                });\n\n                // Bind click event to the cancel button.\n                $(\"#\" + cancelButtonId).click(function() {\n                    chooserDialog.hide();\n                });\n\n                // Loop over each comment item and bind click events.\n                $.each(comments, function(index, comment) {\n                    var commentOptionId = '#comment-option-' + criterionId + '-' + comment.id;\n\n                    // Delegate click event for the generated option link.\n                    $(commentOptionId).click(function() {\n                        var remarkTextArea = $('#' + remarkId);\n                        var remarkText = remarkTextArea.val();\n\n                        // Add line break if the current value of the remark text is not empty.\n                        if (remarkText.trim() !== '') {\n                            remarkText += '\\n';\n                        }\n                        remarkText += comment.description;\n\n                        remarkTextArea.val(remarkText);\n\n                        chooserDialog.hide();\n                    });\n\n                    // Handle keypress on list items.\n                    $(document).off('keypress', commentOptionId).on('keypress', commentOptionId, function() {\n                        var keyCode = event.which || event.keyCode;\n\n                        // Trigger click event when user presses space.\n                        if (keyCode === keycodes.space) {\n                            $(commentOptionId).click();\n                        }\n                    });\n                });\n\n                // Destroy the dialog when it is hidden to allow the grading section to\n                // be loaded as a fragment multiple times within the same page.\n                chooserDialog.after('visibleChange', function(e) {\n                    // Going from visible to hidden.\n                    if (e.prevVal && !e.newVal) {\n                        this.destroy();\n                    }\n                }, chooserDialog);\n\n                // Show dialog.\n                chooserDialog.show();\n            }\n\n            /**\n             * Generates the comments chooser dialog from the grading_form/comment_chooser mustache template.\n             */\n            function generateCommentsChooser() {\n                // Template context.\n                var context = {\n                    criterionId: criterionId,\n                    comments: commentOptions\n                };\n\n                // Render the template and display the comment chooser dialog.\n                templates.render('gradingform_guide/comment_chooser', context)\n                    .done(function(compiledSource) {\n                        displayChooserDialog(compiledSource, commentOptions);\n                    })\n                    .fail(notification.exception);\n            }\n\n            // Bind click event for the comments chooser button.\n            $(\"#\" + buttonId).click(function(e) {\n                e.preventDefault();\n                generateCommentsChooser();\n            });\n        }\n    };\n});\n"],"names":["define","$","templates","keycodes","notification","initialise","criterionId","buttonId","remarkId","commentOptions","generateCommentsChooser","context","comments","render","done","compiledSource","titleLabel","M","util","get_string","cancelButtonId","cancelButton","chooserDialog","core","dialogue","modal","headerContent","bodyContent","footerContent","focusAfterHide","id","click","hide","each","index","comment","commentOptionId","remarkTextArea","remarkText","val","trim","description","document","off","on","event","which","keyCode","space","after","e","prevVal","newVal","destroy","show","displayChooserDialog","fail","exception","preventDefault"],"mappings":";;;;;;;AAsBAA,2CAAO,CAAC,SAAU,iBAAkB,iBAAkB,oBAAqB,aACnE,SAASC,EAAGC,UAAWC,SAAUC,oBAIyB,CAa1DC,WAAY,SAASC,YAAaC,SAAUC,SAAUC,yBA2EzCC,8BAEDC,QAAU,CACVL,YAAaA,YACbM,SAAUH,gBAIdP,UAAUW,OAAO,oCAAqCF,SACjDG,MAAK,SAASC,0BA5EOA,eAAgBH,cACtCI,WAAa,UAAYC,EAAEC,KAAKC,WAAW,gBAAiB,qBAAuB,WACnFC,eAAiB,mBAAqBd,YAAc,UACpDe,aAAe,eAAiBD,eAAiB,KAAOH,EAAEC,KAAKC,WAAW,SAAU,UAAY,YAGhGG,cAAgB,IAAIL,EAAEM,KAAKC,SAAS,CACpCC,OAAO,EACPC,cAAeV,WACfW,YAAaZ,eACba,cAAeP,aACfQ,eAAgB,IAAMrB,SACtBsB,GAAI,2BAA6BxB,cAIrCL,EAAE,IAAMmB,gBAAgBW,OAAM,WAC1BT,cAAcU,UAIlB/B,EAAEgC,KAAKrB,UAAU,SAASsB,MAAOC,aACzBC,gBAAkB,mBAAqB9B,YAAc,IAAM6B,QAAQL,GAGvE7B,EAAEmC,iBAAiBL,OAAM,eACjBM,eAAiBpC,EAAE,IAAMO,UACzB8B,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