Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"grade_dialogue.min.js","sources":["../src/grade_dialogue.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 * Grade dialogue.\n *\n * @module     tool_lp/grade_dialogue\n * @copyright  2016 Frédéric Massart - FMCorz.net\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['jquery',\n        'core/notification',\n        'core/templates',\n        'tool_lp/dialogue',\n        'tool_lp/event_base',\n        'core/str'],\n        function($, Notification, Templates, Dialogue, EventBase, Str) {\n\n    /**\n     * Grade dialogue class.\n     *\n     * @class tool_lp/grade_dialogue\n     * @param {Array} ratingOptions\n     */\n    var Grade = function(ratingOptions) {\n        EventBase.prototype.constructor.apply(this, []);\n        this._ratingOptions = ratingOptions;\n    };\n    Grade.prototype = Object.create(EventBase.prototype);\n\n    /** @property {Dialogue} The dialogue. */\n    Grade.prototype._popup = null;\n    /** @property {Array} Array of objects containing, 'value', 'name' and optionally 'selected'. */\n    Grade.prototype._ratingOptions = null;\n\n    /**\n     * After render hook.\n     *\n     * @method _afterRender\n     * @protected\n     */\n    Grade.prototype._afterRender = function() {\n        var btnRate = this._find('[data-action=\"rate\"]'),\n            lstRating = this._find('[name=\"rating\"]'),\n            txtComment = this._find('[name=\"comment\"]');\n\n        this._find('[data-action=\"cancel\"]').click(function(e) {\n            e.preventDefault();\n            this._trigger('cancelled');\n            this.close();\n        }.bind(this));\n\n        lstRating.change(function() {\n            var node = $(this);\n            if (!node.val()) {\n                btnRate.prop('disabled', true);\n            } else {\n                btnRate.prop('disabled', false);\n            }\n        }).change();\n\n        btnRate.click(function(e) {\n            e.preventDefault();\n            var val = lstRating.val();\n            if (!val) {\n                return;\n            }\n            this._trigger('rated', {\n                'rating': val,\n                'note': txtComment.val()\n            });\n            this.close();\n        }.bind(this));\n    };\n\n    /**\n     * Close the dialogue.\n     *\n     * @method close\n     */\n    Grade.prototype.close = function() {\n        this._popup.close();\n        this._popup = null;\n    };\n\n    /**\n     * Opens the picker.\n     *\n     * @method display\n     * @return {Promise}\n     */\n    Grade.prototype.display = function() {\n        M.util.js_pending('tool_lp/grade_dialogue:display');\n        return $.when(\n            Str.get_string('rate', 'tool_lp'),\n            this._render()\n        )\n        .then(function(title, templateResult) {\n            this._popup = new Dialogue(\n                title,\n                templateResult[0],\n                function() {\n                    this._afterRender();\n                    M.util.js_complete('tool_lp/grade_dialogue:display');\n                }.bind(this)\n            );\n\n            return this._popup;\n        }.bind(this))\n        .catch(Notification.exception);\n    };\n\n    /**\n     * Find a node in the dialogue.\n     *\n     * @param {String} selector\n     * @method _find\n     * @returns {node} The node\n     * @protected\n     */\n    Grade.prototype._find = function(selector) {\n        return $(this._popup.getContent()).find(selector);\n    };\n\n    /**\n     * Render the dialogue.\n     *\n     * @method _render\n     * @protected\n     * @return {Promise}\n     */\n    Grade.prototype._render = function() {\n        var context = {\n            cangrade: this._canGrade,\n            ratings: this._ratingOptions\n        };\n        return Templates.render('tool_lp/competency_grader', context);\n    };\n\n    return Grade;\n});\n"],"names":["define","$","Notification","Templates","Dialogue","EventBase","Str","Grade","ratingOptions","prototype","constructor","apply","this","_ratingOptions","Object","create","_popup","_afterRender","btnRate","_find","lstRating","txtComment","click","e","preventDefault","_trigger","close","bind","change","val","prop","display","M","util","js_pending","when","get_string","_render","then","title","templateResult","js_complete","catch","exception","selector","getContent","find","context","cangrade","_canGrade","ratings","render"],"mappings":";;;;;;;AAuBAA,gCAAO,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