[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/forum/yui/build/moodle-mod_forum-subscriptiontoggle/ -> moodle-mod_forum-subscriptiontoggle-debug.js (source)

   1  YUI.add('moodle-mod_forum-subscriptiontoggle', function (Y, NAME) {
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * A utility to check whether the connection to the Moodle server is still
  20   * active.
  21   *
  22   * @module     moodle-core-subscriptiontoggle
  23   * @package    mod_forum
  24   * @copyright  2014 Andrew Nicols <andrew@nicols.co.uk>
  25   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   * @main       moodle-mod_forum-subscriptiontoggle
  27   */
  28  
  29  /**
  30   * @namespace M.mod_forum
  31   * @class subscriptiontoggle
  32   */
  33  
  34  function SubscriptionToggle() {
  35      SubscriptionToggle.superclass.constructor.apply(this, arguments);
  36  }
  37  
  38  var LOGNAME = 'moodle-mod_forum-subscriptiontoggle';
  39  
  40  Y.extend(SubscriptionToggle, Y.Base, {
  41      initializer: function() {
  42          Y.delegate('click', this._toggleSubscription, Y.config.doc.body, '.discussionsubscription .discussiontoggle', this);
  43      },
  44      _toggleSubscription: function(e) {
  45          var clickedLink = e.currentTarget;
  46  
  47          Y.io(this.get('uri'), {
  48              data: {
  49                  sesskey: M.cfg.sesskey,
  50                  forumid: clickedLink.getData('forumid'),
  51                  discussionid: clickedLink.getData('discussionid'),
  52                  includetext: clickedLink.getData('includetext')
  53              },
  54              context: this,
  55              'arguments': {
  56                  clickedLink: clickedLink
  57              },
  58              on: {
  59                  complete: this._handleCompletion
  60              }
  61          });
  62  
  63          // Prevent the standard browser behaviour now.
  64          e.preventDefault();
  65      },
  66  
  67      _handleCompletion: function(tid, response, args) {
  68          var responseObject;
  69          // Attempt to parse the response into an object.
  70          try {
  71              responseObject = Y.JSON.parse(response.response);
  72              if (responseObject.error) {
  73                  Y.use('moodle-core-notification-ajaxexception', function() {
  74                      return new M.core.ajaxException(responseObject);
  75                  });
  76                  return this;
  77              }
  78          } catch (error) {
  79              Y.use('moodle-core-notification-exception', function() {
  80                  return new M.core.exception(error);
  81              });
  82              return this;
  83          }
  84  
  85          if (!responseObject.icon) {
  86              Y.log('No icon received. Skipping the current value replacement', 'warn', LOGNAME);
  87              return;
  88          }
  89  
  90          var container = args.clickedLink.ancestor('.discussionsubscription');
  91          if (container) {
  92              // We should just receive the new value for the table.
  93              // Note: We do not need to escape the HTML here as it should be provided sanitised from the JS response already.
  94              container.set('innerHTML', responseObject.icon);
  95          }
  96      }
  97  }, {
  98      NAME: 'subscriptionToggle',
  99      ATTRS: {
 100          /**
 101           * The AJAX endpoint which controls the subscription toggle.
 102           *
 103           * @attribute uri
 104           * @type String
 105           * @default M.cfg.wwwroot + '/mod/forum/subscribe_ajax.php'
 106           */
 107          uri: {
 108              value: M.cfg.wwwroot + '/mod/forum/subscribe_ajax.php'
 109          }
 110      }
 111  });
 112  
 113  var NS = Y.namespace('M.mod_forum.subscriptiontoggle');
 114  NS.init = function(config) {
 115      return new SubscriptionToggle(config);
 116  };
 117  
 118  
 119  }, '@VERSION@', {"requires": ["base-base", "io-base"]});


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