[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/course/yui/src/management/js/ -> course.js (source)

   1  /* global Item */
   2  
   3  /**
   4   * A managed course.
   5   *
   6   * @namespace M.course.management
   7   * @class Course
   8   * @constructor
   9   * @extends Item
  10   */
  11  function Course() {
  12      Course.superclass.constructor.apply(this, arguments);
  13  }
  14  Course.NAME = 'moodle-course-management-course';
  15  Course.CSS_PREFIX = 'management-course';
  16  Course.ATTRS = {
  17  
  18      /**
  19       * The course ID of this course.
  20       * @attribute courseid
  21       * @type Number
  22       */
  23      courseid: {},
  24  
  25      /**
  26       * True if this is the selected course.
  27       * @attribute selected
  28       * @type Boolean
  29       * @default null
  30       */
  31      selected: {
  32          getter: function(value, name) {
  33              if (value === null) {
  34                  value = this.get('node').getData(name);
  35                  this.set(name, value);
  36              }
  37              return value;
  38          },
  39          value: null
  40      },
  41      node: {
  42  
  43      },
  44      /**
  45       * The management console tracking this course.
  46       * @attribute console
  47       * @type Console
  48       * @writeOnce
  49       */
  50      console: {
  51          writeOnce: 'initOnly'
  52      },
  53  
  54      /**
  55       * The category this course belongs to.
  56       * @attribute category
  57       * @type Category
  58       * @writeOnce
  59       */
  60      category: {
  61          writeOnce: 'initOnly'
  62      }
  63  };
  64  Course.prototype = {
  65      /**
  66       * Initialises the new course instance.
  67       * @method initializer
  68       */
  69      initializer: function() {
  70          var node = this.get('node'),
  71              category = this.get('category');
  72          this.set('courseid', node.getData('id'));
  73          if (category && category.registerCourse) {
  74              category.registerCourse(this);
  75          }
  76          this.set('itemname', 'course');
  77      },
  78  
  79      /**
  80       * Returns the name of the course.
  81       * @method getName
  82       * @return {String}
  83       */
  84      getName: function() {
  85          return this.get('node').one('a.coursename').get('innerHTML');
  86      },
  87  
  88      /**
  89       * Handles an event relating to this course.
  90       * @method handle
  91       * @param {String} action
  92       * @param {EventFacade} e
  93       * @return {Boolean}
  94       */
  95      handle: function(action, e) {
  96          var managementconsole = this.get('console'),
  97              args = {courseid: this.get('courseid')};
  98          switch (action) {
  99              case 'moveup':
 100                  e.halt();
 101                  managementconsole.performAjaxAction('movecourseup', args, this.moveup, this);
 102                  break;
 103              case 'movedown':
 104                  e.halt();
 105                  managementconsole.performAjaxAction('movecoursedown', args, this.movedown, this);
 106                  break;
 107              case 'show':
 108                  e.halt();
 109                  managementconsole.performAjaxAction('showcourse', args, this.show, this);
 110                  break;
 111              case 'hide':
 112                  e.halt();
 113                  managementconsole.performAjaxAction('hidecourse', args, this.hide, this);
 114                  break;
 115              case 'select':
 116                  var c = this.get('console'),
 117                      movetonode = c.get('courselisting').one('#menumovecoursesto');
 118                  if (movetonode) {
 119                      if (c.isCourseSelected(e.currentTarget)) {
 120                          movetonode.removeAttribute('disabled');
 121                      } else {
 122                          movetonode.setAttribute('disabled', true);
 123                      }
 124                  }
 125                  break;
 126              default:
 127                  Y.log('Invalid AJAX action requested of managed course.', 'warn', 'moodle-course-management');
 128                  return false;
 129          }
 130      },
 131  
 132      /**
 133       * Removes this course.
 134       * @method remove
 135       */
 136      remove: function() {
 137          this.get('console').removeCourseById(this.get('courseid'));
 138          this.get('node').remove();
 139      },
 140  
 141      /**
 142       * Moves this course after another course.
 143       *
 144       * @method moveAfter
 145       * @param {Number} moveaftercourse The course to move after or 0 to put it at the top.
 146       * @param {Number} previousid the course it was previously after in case we need to revert.
 147       */
 148      moveAfter: function(moveaftercourse, previousid) {
 149          var managementconsole = this.get('console'),
 150              args = {
 151                  courseid: this.get('courseid'),
 152                  moveafter: moveaftercourse,
 153                  previous: previousid
 154              };
 155          managementconsole.performAjaxAction('movecourseafter', args, this.moveAfterResponse, this);
 156      },
 157  
 158      /**
 159       * Performs the actual move.
 160       *
 161       * @method moveAfterResponse
 162       * @protected
 163       * @param {Number} transactionid The transaction ID for the request.
 164       * @param {Object} response The response to the request.
 165       * @param {Objects} args The arguments that were given with the request.
 166       * @return {Boolean}
 167       */
 168      moveAfterResponse: function(transactionid, response, args) {
 169          var outcome = this.checkAjaxResponse(transactionid, response, args),
 170              node = this.get('node'),
 171              previous;
 172          if (outcome === false) {
 173              previous = node.ancestor('ul').one('li[data-id=' + args.previous + ']');
 174              Y.log('AJAX failed to move this course after the requested course', 'warn', 'moodle-course-management');
 175              if (previous) {
 176                  // After the last previous.
 177                  previous.insertAfter(node, 'after');
 178              } else {
 179                  // Start of the list.
 180                  node.ancestor('ul').one('li').insert(node, 'before');
 181              }
 182              return false;
 183          }
 184          Y.log('AJAX successfully moved course (' + this.getName() + ')', 'info', 'moodle-course-management');
 185          this.highlight();
 186      }
 187  };
 188  Y.extend(Course, Item, Course.prototype);


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