[ 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 report_competency 20 * @copyright 2015 Damyon Wiese 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 */ 23 24 define(['jquery', 'core/notification', 'core/str', 'core/ajax', 'core/log', 'core/templates', 'tool_lp/dialogue'], 25 function($, notification, str, ajax, log, templates, Dialogue) { 26 27 /** 28 * GradingPopup 29 * 30 * @param {String} regionSelector The regionSelector 31 * @param {String} userCompetencySelector The userCompetencySelector 32 */ 33 var GradingPopup = function(regionSelector, userCompetencySelector) { 34 this._regionSelector = regionSelector; 35 this._userCompetencySelector = userCompetencySelector; 36 37 $(this._regionSelector).on('click', this._userCompetencySelector, this._handleClick.bind(this)); 38 }; 39 40 /** 41 * Get the data from the clicked cell and open the popup. 42 * 43 * @method _handleClick 44 * @param {Event} e The event 45 */ 46 GradingPopup.prototype._handleClick = function(e) { 47 var cell = $(e.target).closest(this._userCompetencySelector); 48 var competencyId = $(cell).data('competencyid'); 49 var courseId = $(cell).data('courseid'); 50 var userId = $(cell).data('userid'); 51 52 log.debug('Clicked on cell: competencyId=' + competencyId + ', courseId=' + courseId + ', userId=' + userId); 53 54 var requests = ajax.call([{ 55 methodname: 'tool_lp_data_for_user_competency_summary_in_course', 56 args: {userid: userId, competencyid: competencyId, courseid: courseId}, 57 done: this._contextLoaded.bind(this), 58 fail: notification.exception 59 }]); 60 61 // Log the user competency viewed in course event. 62 requests[0].then(function() { 63 ajax.call([{ 64 methodname: 'core_competency_user_competency_viewed_in_course', 65 args: {userid: userId, competencyid: competencyId, courseid: courseId}, 66 fail: notification.exception 67 }]); 68 }); 69 }; 70 71 /** 72 * We loaded the context, now render the template. 73 * 74 * @method _contextLoaded 75 * @param {Object} context 76 */ 77 GradingPopup.prototype._contextLoaded = function(context) { 78 var self = this; 79 // We have to display user info in popup. 80 context.displayuser = true; 81 templates.render('tool_lp/user_competency_summary_in_course', context).done(function(html, js) { 82 str.get_string('usercompetencysummary', 'report_competency').done(function(title) { 83 (new Dialogue(title, html, templates.runTemplateJS.bind(templates, js), self._refresh.bind(self), true)); 84 }).fail(notification.exception); 85 }).fail(notification.exception); 86 }; 87 88 /** 89 * Refresh the page. 90 * 91 * @method _refresh 92 */ 93 GradingPopup.prototype._refresh = function() { 94 var region = $(this._regionSelector); 95 var courseId = region.data('courseid'); 96 var userId = region.data('userid'); 97 98 ajax.call([{ 99 methodname: 'report_competency_data_for_report', 100 args: {courseid: courseId, userid: userId}, 101 done: this._pageContextLoaded.bind(this), 102 fail: notification.exception 103 }]); 104 }; 105 106 /** 107 * We loaded the context, now render the template. 108 * 109 * @method _pageContextLoaded 110 * @param {Object} context 111 */ 112 GradingPopup.prototype._pageContextLoaded = function(context) { 113 var self = this; 114 templates.render('report_competency/report', context).done(function(html, js) { 115 templates.replaceNode(self._regionSelector, html, js); 116 }).fail(notification.exception); 117 }; 118 119 /** @type {String} The selector for the region with the user competencies */ 120 GradingPopup.prototype._regionSelector = null; 121 /** @type {String} The selector for the region with a single user competencies */ 122 GradingPopup.prototype._userCompetencySelector = null; 123 124 return /** @alias module:report_competency/grading_popup */ GradingPopup; 125 126 });
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 |