[ 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 * Module to enable inline editing of a comptency grade. 18 * 19 * @package tool_lp 20 * @copyright 2015 Damyon Wiese 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 */ 23 24 define(['jquery', 25 'core/notification', 26 'core/ajax', 27 'core/log', 28 'tool_lp/grade_dialogue', 29 'tool_lp/event_base', 30 'tool_lp/scalevalues', 31 ], function($, notification, ajax, log, GradeDialogue, EventBase, ScaleValues) { 32 33 /** 34 * InlineEditor 35 * 36 * @param {String} selector The selector to trigger the grading. 37 * @param {Number} scaleId The id of the scale for this competency. 38 * @param {Number} competencyId The id of the competency. 39 * @param {Number} userId The id of the user. 40 * @param {Number} planId The id of the plan. 41 * @param {Number} courseId The id of the course. 42 * @param {String} chooseStr Language string for choose a rating. 43 */ 44 var InlineEditor = function(selector, scaleId, competencyId, userId, planId, courseId, chooseStr) { 45 EventBase.prototype.constructor.apply(this, []); 46 47 var trigger = $(selector); 48 if (!trigger.length) { 49 throw new Error('Could not find the trigger'); 50 } 51 52 this._scaleId = scaleId; 53 this._competencyId = competencyId; 54 this._userId = userId; 55 this._planId = planId; 56 this._courseId = courseId; 57 this._chooseStr = chooseStr; 58 this._setUp(); 59 60 trigger.click(function(e) { 61 e.preventDefault(); 62 this._dialogue.display(); 63 }.bind(this)); 64 65 if (this._planId) { 66 this._methodName = 'core_competency_grade_competency_in_plan'; 67 this._args = { 68 competencyid: this._competencyId, 69 planid: this._planId 70 }; 71 } else if (this._courseId) { 72 this._methodName = 'core_competency_grade_competency_in_course'; 73 this._args = { 74 competencyid: this._competencyId, 75 courseid: this._courseId, 76 userid: this._userId 77 }; 78 } else { 79 this._methodName = 'core_competency_grade_competency'; 80 this._args = { 81 userid: this._userId, 82 competencyid: this._competencyId 83 }; 84 } 85 }; 86 InlineEditor.prototype = Object.create(EventBase.prototype); 87 88 /** 89 * Setup. 90 * 91 * @method _setUp 92 */ 93 InlineEditor.prototype._setUp = function() { 94 var options = [], 95 self = this; 96 97 var promise = ScaleValues.get_values(self._scaleId); 98 promise.done(function(scalevalues) { 99 options.push({ 100 value: '', 101 name: self._chooseStr 102 }); 103 104 for (var i = 0; i < scalevalues.length; i++) { 105 var optionConfig = scalevalues[i]; 106 options.push({ 107 value: optionConfig.id, 108 name: optionConfig.name 109 }); 110 } 111 112 self._dialogue = new GradeDialogue(options); 113 self._dialogue.on('rated', function(e, data) { 114 var args = self._args; 115 args.grade = data.rating; 116 args.note = data.note; 117 ajax.call([{ 118 methodname: self._methodName, 119 args: args, 120 done: function(evidence) { 121 self._trigger('competencyupdated', {args: args, evidence: evidence}); 122 }, 123 fail: notification.exception 124 }]); 125 }); 126 }).fail(notification.exception); 127 }; 128 129 /** @type {Number} The scale id for this competency. */ 130 InlineEditor.prototype._scaleId = null; 131 /** @type {Number} The id of the competency. */ 132 InlineEditor.prototype._competencyId = null; 133 /** @type {Number} The id of the user. */ 134 InlineEditor.prototype._userId = null; 135 /** @type {Number} The id of the plan. */ 136 InlineEditor.prototype._planId = null; 137 /** @type {Number} The id of the course. */ 138 InlineEditor.prototype._courseId = null; 139 /** @type {String} The text for Choose rating. */ 140 InlineEditor.prototype._chooseStr = null; 141 /** @type {GradeDialogue} The grading dialogue. */ 142 InlineEditor.prototype._dialogue = null; 143 144 return /** @alias module:tool_lp/grade_user_competency_inline */ InlineEditor; 145 146 });
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 |