[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

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

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


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1