[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/tool/lp/amd/src/ -> user_competency_plan_popup.js (source)

   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 open user competency plan in popup
  18   *
  19   * @package    report_competency
  20   * @copyright  2016 Issam Taboubi <issam.taboubi@umontreal.ca>
  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/templates', 'tool_lp/dialogue'],
  25         function($, notification, str, ajax, templates, Dialogue) {
  26  
  27      /**
  28       * UserCompetencyPopup
  29       *
  30       * @param {String} regionSelector The regionSelector
  31       * @param {String} userCompetencySelector The userCompetencySelector
  32       * @param {Number} planId The plan ID
  33       */
  34      var UserCompetencyPopup = function(regionSelector, userCompetencySelector, planId) {
  35          this._regionSelector = regionSelector;
  36          this._userCompetencySelector = userCompetencySelector;
  37          this._planId = planId;
  38  
  39          $(this._regionSelector).on('click', this._userCompetencySelector, this._handleClick.bind(this));
  40      };
  41  
  42      /**
  43       * Get the data from the closest TR and open the popup.
  44       *
  45       * @method _handleClick
  46       * @param {Event} e
  47       */
  48      UserCompetencyPopup.prototype._handleClick = function(e) {
  49          e.preventDefault();
  50          var tr = $(e.target).closest('tr');
  51          var competencyId = $(tr).data('competencyid');
  52          var userId = $(tr).data('userid');
  53          var planId = this._planId;
  54  
  55          var requests = ajax.call([{
  56              methodname: 'tool_lp_data_for_user_competency_summary_in_plan',
  57              args: {competencyid: competencyId, planid: planId},
  58              done: this._contextLoaded.bind(this),
  59              fail: notification.exception
  60          }]);
  61  
  62          // Log the user competency viewed in plan event.
  63          requests[0].then(function(result) {
  64              var eventMethodName = 'core_competency_user_competency_viewed_in_plan';
  65              // Trigger core_competency_user_competency_plan_viewed event instead if plan is already completed.
  66              if (result.plan.iscompleted) {
  67                  eventMethodName = 'core_competency_user_competency_plan_viewed';
  68              }
  69              ajax.call([{
  70                  methodname: eventMethodName,
  71                  args: {competencyid: competencyId, userid: userId, planid: planId},
  72                  fail: notification.exception
  73              }]);
  74          });
  75      };
  76  
  77      /**
  78       * We loaded the context, now render the template.
  79       *
  80       * @method _contextLoaded
  81       * @param {Object} context
  82       */
  83      UserCompetencyPopup.prototype._contextLoaded = function(context) {
  84          var self = this;
  85          templates.render('tool_lp/user_competency_summary_in_plan', context).done(function(html, js) {
  86              str.get_string('usercompetencysummary', 'report_competency').done(function(title) {
  87                  (new Dialogue(title, html, templates.runTemplateJS.bind(templates, js), self._refresh.bind(self), true));
  88              }).fail(notification.exception);
  89          }).fail(notification.exception);
  90      };
  91  
  92      /**
  93       * Refresh the page.
  94       *
  95       * @method _refresh
  96       */
  97      UserCompetencyPopup.prototype._refresh = function() {
  98          var planId = this._planId;
  99  
 100          ajax.call([{
 101              methodname: 'tool_lp_data_for_plan_page',
 102              args: {planid: planId},
 103              done: this._pageContextLoaded.bind(this),
 104              fail: notification.exception
 105          }]);
 106      };
 107  
 108      /**
 109       * We loaded the context, now render the template.
 110       *
 111       * @method _pageContextLoaded
 112       * @param {Object} context
 113       */
 114      UserCompetencyPopup.prototype._pageContextLoaded = function(context) {
 115          var self = this;
 116          templates.render('tool_lp/plan_page', context).done(function(html, js) {
 117              templates.replaceNode(self._regionSelector, html, js);
 118          }).fail(notification.exception);
 119      };
 120  
 121      /** @type {String} The selector for the region with the user competencies */
 122      UserCompetencyPopup.prototype._regionSelector = null;
 123      /** @type {String} The selector for the region with a single user competencies */
 124      UserCompetencyPopup.prototype._userCompetencySelector = null;
 125      /** @type {Number} The plan Id */
 126      UserCompetencyPopup.prototype._planId = null;
 127  
 128      return /** @alias module:tool_lp/user_competency_plan_popup */ UserCompetencyPopup;
 129  
 130  });


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1