[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 // This file is part of Moodle - http://moodle.org/ 2 // 3 // Moodle is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // (at your option) any later version. 7 // 8 // Moodle is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License 14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 15 16 /** 17 * Grade dialogue. 18 * 19 * @package tool_lp 20 * @copyright 2016 Frédéric Massart - FMCorz.net 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 */ 23 24 define(['jquery', 25 'core/notification', 26 'core/templates', 27 'tool_lp/dialogue', 28 'tool_lp/event_base', 29 'core/str'], 30 function($, Notification, Templates, Dialogue, EventBase, Str) { 31 32 /** 33 * Grade dialogue class. 34 * @param {Array} ratingOptions 35 */ 36 var Grade = function(ratingOptions) { 37 EventBase.prototype.constructor.apply(this, []); 38 this._ratingOptions = ratingOptions; 39 }; 40 Grade.prototype = Object.create(EventBase.prototype); 41 42 /** @type {Dialogue} The dialogue. */ 43 Grade.prototype._popup = null; 44 /** @type {Array} Array of objects containing, 'value', 'name' and optionally 'selected'. */ 45 Grade.prototype._ratingOptions = null; 46 47 /** 48 * After render hook. 49 * 50 * @method _afterRender 51 * @protected 52 */ 53 Grade.prototype._afterRender = function() { 54 var btnRate = this._find('[data-action="rate"]'), 55 lstRating = this._find('[name="rating"]'), 56 txtComment = this._find('[name="comment"]'); 57 58 this._find('[data-action="cancel"]').click(function(e) { 59 e.preventDefault(); 60 this._trigger('cancelled'); 61 this.close(); 62 }.bind(this)); 63 64 lstRating.change(function() { 65 var node = $(this); 66 if (!node.val()) { 67 btnRate.prop('disabled', true); 68 } else { 69 btnRate.prop('disabled', false); 70 } 71 }).change(); 72 73 btnRate.click(function(e) { 74 e.preventDefault(); 75 var val = lstRating.val(); 76 if (!val) { 77 return; 78 } 79 this._trigger('rated', { 80 'rating': val, 81 'note': txtComment.val() 82 }); 83 this.close(); 84 }.bind(this)); 85 }; 86 87 /** 88 * Close the dialogue. 89 * 90 * @method close 91 */ 92 Grade.prototype.close = function() { 93 this._popup.close(); 94 this._popup = null; 95 }; 96 97 /** 98 * Opens the picker. 99 * 100 * @param {Number} competencyId The competency ID of the competency to work on. 101 * @method display 102 * @return {Promise} 103 */ 104 Grade.prototype.display = function() { 105 return this._render().then(function(html) { 106 return Str.get_string('rate', 'tool_lp').then(function(title) { 107 this._popup = new Dialogue( 108 title, 109 html, 110 this._afterRender.bind(this) 111 ); 112 }.bind(this)); 113 }.bind(this)).fail(Notification.exception); 114 }; 115 116 /** 117 * Find a node in the dialogue. 118 * 119 * @param {String} selector 120 * @method _find 121 * @returns {node} The node 122 * @protected 123 */ 124 Grade.prototype._find = function(selector) { 125 return $(this._popup.getContent()).find(selector); 126 }; 127 128 /** 129 * Render the dialogue. 130 * 131 * @method _render 132 * @protected 133 * @return {Promise} 134 */ 135 Grade.prototype._render = function() { 136 var context = { 137 cangrade: this._canGrade, 138 ratings: this._ratingOptions 139 }; 140 return Templates.render('tool_lp/competency_grader', context); 141 }; 142 143 return /** @alias module:tool_lp/grade_dialogue */ Grade; 144 145 });
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |