[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/forum/yui/build/moodle-mod_forum-subscriptiontoggle/ -> moodle-mod_forum-subscriptiontoggle.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              return;
  87          }
  88  
  89          var container = args.clickedLink.ancestor('.discussionsubscription');
  90          if (container) {
  91              // We should just receive the new value for the table.
  92              // Note: We do not need to escape the HTML here as it should be provided sanitised from the JS response already.
  93              container.set('innerHTML', responseObject.icon);
  94          }
  95      }
  96  }, {
  97      NAME: 'subscriptionToggle',
  98      ATTRS: {
  99          /**
 100           * The AJAX endpoint which controls the subscription toggle.
 101           *
 102           * @attribute uri
 103           * @type String
 104           * @default M.cfg.wwwroot + '/mod/forum/subscribe_ajax.php'
 105           */
 106          uri: {
 107              value: M.cfg.wwwroot + '/mod/forum/subscribe_ajax.php'
 108          }
 109      }
 110  });
 111  
 112  var NS = Y.namespace('M.mod_forum.subscriptiontoggle');
 113  NS.init = function(config) {
 114      return new SubscriptionToggle(config);
 115  };
 116  
 117  
 118  }, '@VERSION@', {"requires": ["base-base", "io-base"]});


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