[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yui/src/notification/js/ -> alert.js (source)

   1  /* global BASE, TITLE, CONFIRMYES, DIALOGUE_PREFIX */
   2  
   3  /**
   4   * A dialogue type designed to display an alert to the user.
   5   *
   6   * @module moodle-core-notification
   7   * @submodule moodle-core-notification-alert
   8   */
   9  
  10  var ALERT_NAME = 'Moodle alert',
  11      ALERT;
  12  
  13  /**
  14   * Extends core Dialogue to show the alert dialogue.
  15   *
  16   * @param {Object} config Object literal specifying the dialogue configuration properties.
  17   * @constructor
  18   * @class M.core.alert
  19   * @extends M.core.dialogue
  20   */
  21  ALERT = function(config) {
  22      config.closeButton = false;
  23      ALERT.superclass.constructor.apply(this, [config]);
  24  };
  25  Y.extend(ALERT, M.core.notification.info, {
  26      /**
  27       * The list of events to detach when destroying this dialogue.
  28       *
  29       * @property _closeEvents
  30       * @type EventHandle[]
  31       * @private
  32       */
  33      _closeEvents: null,
  34      initializer: function() {
  35          this._closeEvents = [];
  36          this.publish('complete');
  37          var yes = Y.Node.create('<input type="button" id="id_yuialertconfirm-' + this.get('COUNT') + '"' +
  38                                   'value="' + this.get(CONFIRMYES) + '" />'),
  39              content = Y.Node.create('<div class="confirmation-dialogue"></div>')
  40                      .append(Y.Node.create('<div class="confirmation-message">' + this.get('message') + '</div>'))
  41                      .append(Y.Node.create('<div class="confirmation-buttons"></div>')
  42                              .append(yes));
  43          this.get(BASE).addClass('moodle-dialogue-confirm');
  44          this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
  45          this.setStdModContent(Y.WidgetStdMod.HEADER,
  46                  '<h1 id="moodle-dialogue-' + this.get('COUNT') + '-header-text">' + this.get(TITLE) + '</h1>',
  47                  Y.WidgetStdMod.REPLACE);
  48  
  49          this._closeEvents.push(
  50              Y.on('key', this.submit, window, 'down:13', this),
  51              yes.on('click', this.submit, this)
  52          );
  53  
  54          var closeButton = this.get('boundingBox').one('.closebutton');
  55          if (closeButton) {
  56              // The close button should act exactly like the 'No' button.
  57              this._closeEvents.push(
  58                  closeButton.on('click', this.submit, this)
  59              );
  60          }
  61      },
  62      submit: function() {
  63          new Y.EventHandle(this._closeEvents).detach();
  64          this.fire('complete');
  65          this.hide();
  66          this.destroy();
  67      }
  68  }, {
  69      NAME: ALERT_NAME,
  70      CSS_PREFIX: DIALOGUE_PREFIX,
  71      ATTRS: {
  72  
  73          /**
  74           * The title of the alert.
  75           *
  76           * @attribute title
  77           * @type String
  78           * @default 'Alert'
  79           */
  80          title: {
  81              validator: Y.Lang.isString,
  82              value: 'Alert'
  83          },
  84  
  85          /**
  86           * The message of the alert.
  87           *
  88           * @attribute message
  89           * @type String
  90           * @default 'Confirm'
  91           */
  92          message: {
  93              validator: Y.Lang.isString,
  94              value: 'Confirm'
  95          },
  96  
  97          /**
  98           * The button text to use to accept the alert.
  99           *
 100           * @attribute yesLabel
 101           * @type String
 102           * @default 'Ok'
 103           */
 104          yesLabel: {
 105              validator: Y.Lang.isString,
 106              setter: function(txt) {
 107                  if (!txt) {
 108                      txt = 'Ok';
 109                  }
 110                  return txt;
 111              },
 112              value: 'Ok'
 113          }
 114      }
 115  });
 116  
 117  M.core.alert = ALERT;


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