[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/tool/lp/amd/src/ -> competencydialogue.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   * Display Competency in dialogue box.
  18   *
  19   * @module     tool_lp/Competencydialogue
  20   * @package    tool_lp
  21   * @copyright  2015 Issam Taboubi <issam.taboubi@umontreal.ca>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  define(['jquery',
  25          'core/notification',
  26          'core/ajax',
  27          'core/templates',
  28          'core/str',
  29          'tool_lp/dialogue'],
  30         function($, notification, ajax, templates, str, Dialogue) {
  31  
  32      /**
  33       * The main instance we'll be working with.
  34       *
  35       * @type {Competencydialogue}
  36       */
  37      var instance;
  38  
  39      /**
  40       * Constructor for CompetencyDialogue.
  41       *
  42       * @param {Object} options
  43       *
  44       */
  45      var Competencydialogue = function() {
  46        // Intentionally left empty.
  47      };
  48  
  49      /**
  50       * Log the competency viewed event.
  51       *
  52       * @param  {Number} competencyId The competency ID.
  53       * @method triggerCompetencyViewedEvent
  54       */
  55      Competencydialogue.prototype.triggerCompetencyViewedEvent = function(competencyId) {
  56          ajax.call([{
  57                  methodname: 'core_competency_competency_viewed',
  58                  args: {id: competencyId}
  59          }]);
  60      };
  61  
  62      /**
  63       * Display a dialogue box by competencyid.
  64       *
  65       * @param {Number} competencyid The competency ID.
  66       * @param {Object} options The options.
  67       * @method showDialogue
  68       */
  69      Competencydialogue.prototype.showDialogue = function(competencyid, options) {
  70  
  71          var datapromise = this.getCompetencyDataPromise(competencyid, options);
  72          var localthis = this;
  73          datapromise.done(function(data) {
  74              // Inner Html in the dialogue content.
  75              templates.render('tool_lp/competency_summary', data)
  76                  .done(function(html) {
  77                      // Log competency viewed event.
  78                      localthis.triggerCompetencyViewedEvent(competencyid);
  79  
  80                      // Show the dialogue.
  81                      new Dialogue(
  82                          data.competency.shortname,
  83                          html
  84                      );
  85                  }).fail(notification.exception);
  86          }).fail(notification.exception);
  87      };
  88  
  89      /**
  90       * Display a dialogue box from data.
  91       *
  92       * @param {Object} dataSource data to be used to display dialogue box
  93       * @method showDialogueFromData
  94       */
  95      Competencydialogue.prototype.showDialogueFromData = function(dataSource) {
  96  
  97          var localthis = this;
  98          // Inner Html in the dialogue content.
  99          templates.render('tool_lp/competency_summary', dataSource)
 100              .done(function(html) {
 101                  // Log competency viewed event.
 102                  localthis.triggerCompetencyViewedEvent(dataSource.id);
 103  
 104                  // Show the dialogue.
 105                  new Dialogue(
 106                      dataSource.shortname,
 107                      html,
 108                      localthis.enhanceDialogue
 109                  );
 110              }).fail(notification.exception);
 111      };
 112  
 113      /**
 114       * The action on the click event.
 115       *
 116       * @param {Event} e event click
 117       * @method clickEventHandler
 118       */
 119      Competencydialogue.prototype.clickEventHandler = function(e) {
 120  
 121          var compdialogue = e.data.compdialogue;
 122          var currentTarget = $(e.currentTarget);
 123          var competencyid = currentTarget.data('id');
 124          var includerelated = !(currentTarget.data('excluderelated'));
 125          var includecourses = currentTarget.data('includecourses');
 126  
 127          // Show the dialogue box.
 128          compdialogue.showDialogue(competencyid, {
 129              includerelated: includerelated,
 130              includecourses: includecourses
 131          });
 132          e.preventDefault();
 133      };
 134  
 135      /**
 136       * Get a promise on data competency.
 137       *
 138       * @param {Number} competencyid
 139       * @param {Object} options
 140       * @return {Promise} return promise on data request
 141       * @method getCompetencyDataPromise
 142       */
 143      Competencydialogue.prototype.getCompetencyDataPromise = function(competencyid, options) {
 144  
 145          var requests = ajax.call([
 146              {methodname: 'tool_lp_data_for_competency_summary',
 147                args: {competencyid: competencyid,
 148                        includerelated: options.includerelated || false,
 149                        includecourses: options.includecourses || false
 150                      }
 151              }
 152          ]);
 153  
 154          return requests[0].then(function(context) {
 155             return context;
 156          }).fail(notification.exception);
 157      };
 158  
 159      return /** @alias module:tool_lp/competencydialogue */ {
 160  
 161          /**
 162           * Initialise the competency dialogue module.
 163           *
 164           * Only the first call matters.
 165           */
 166          init: function() {
 167              if (typeof instance !== 'undefined') {
 168                  return;
 169              }
 170  
 171              // Instantiate the one instance and delegate event on the body.
 172              instance = new Competencydialogue();
 173              $('body').delegate('[data-action="competency-dialogue"]', 'click', {compdialogue: instance},
 174                  instance.clickEventHandler.bind(instance));
 175          }
 176      };
 177  });


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