[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

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

   1  /**
   2   * A dialogue type designed to display a confirmation to the user.
   3   *
   4   * @module moodle-core-notification
   5   * @submodule moodle-core-notification-confirm
   6   */
   7  
   8  var CONFIRM_NAME = 'Moodle confirmation dialogue',
   9      CONFIRM;
  10  
  11  /**
  12   * Extends core Dialogue to show the confirmation dialogue.
  13   *
  14   * @param {Object} config Object literal specifying the dialogue configuration properties.
  15   * @constructor
  16   * @class M.core.confirm
  17   * @extends M.core.dialogue
  18   */
  19  CONFIRM = function(config) {
  20      CONFIRM.superclass.constructor.apply(this, [config]);
  21  };
  22  Y.extend(CONFIRM, M.core.notification.info, {
  23      /**
  24       * The list of events to detach when destroying this dialogue.
  25       *
  26       * @property _closeEvents
  27       * @type EventHandle[]
  28       * @private
  29       */
  30      _closeEvents: null,
  31  
  32      /**
  33       * A reference to the yes button.
  34       *
  35       * @property _yesButton
  36       * @type Node
  37       * @private
  38       */
  39      _yesButton: null,
  40  
  41      /**
  42       * A reference to the No button.
  43       *
  44       * @property _noButton
  45       * @type Node
  46       * @private
  47       */
  48      _noButton: null,
  49  
  50      /**
  51       * A reference to the Question.
  52       *
  53       * @property _question
  54       * @type Node
  55       * @private
  56       */
  57      _question: null,
  58  
  59      initializer: function() {
  60          this._closeEvents = [];
  61          this.publish('complete');
  62          this.publish('complete-yes');
  63          this.publish('complete-no');
  64          this._yesButton = Y.Node.create('<input type="button" id="id_yuiconfirmyes-' + this.get('COUNT') + '" value="'+this.get(CONFIRMYES)+'" />');
  65          this._noButton = Y.Node.create('<input type="button" id="id_yuiconfirmno-' + this.get('COUNT') + '" value="'+this.get(CONFIRMNO)+'" />');
  66          this._question = Y.Node.create('<div class="confirmation-message">' + this.get(QUESTION) + '</div>');
  67          var content = Y.Node.create('<div class="confirmation-dialogue"></div>')
  68                          .append(this._question)
  69                          .append(Y.Node.create('<div class="confirmation-buttons"></div>')
  70                              .append(this._yesButton)
  71                              .append(this._noButton));
  72          this.get(BASE).addClass('moodle-dialogue-confirm');
  73          this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
  74          this.setStdModContent(Y.WidgetStdMod.HEADER,
  75                  '<h1 id="moodle-dialogue-'+this.get('COUNT')+'-header-text">' + this.get(TITLE) + '</h1>', Y.WidgetStdMod.REPLACE);
  76  
  77          this._closeEvents.push(
  78              Y.on('key', this.submit, window, 'down:27', this, false),
  79              this._yesButton.on('click', this.submit, this, true),
  80              this._noButton.on('click', this.submit, this, false)
  81          );
  82  
  83          var closeButton = this.get('boundingBox').one('.closebutton');
  84          if (closeButton) {
  85              // The close button should act exactly like the 'No' button.
  86              this._closeEvents.push(
  87                  closeButton.on('click', this.submit, this)
  88              );
  89          }
  90      },
  91      submit: function(e, outcome) {
  92          new Y.EventHandle(this._closeEvents).detach();
  93          this.fire('complete', outcome);
  94          if (outcome) {
  95              this.fire('complete-yes');
  96          } else {
  97              this.fire('complete-no');
  98          }
  99          this.hide();
 100          this.destroy();
 101      }
 102  }, {
 103      NAME: CONFIRM_NAME,
 104      CSS_PREFIX: DIALOGUE_PREFIX,
 105      ATTRS: {
 106  
 107          /**
 108           * The button text to use to accept the confirmation.
 109           *
 110           * @attribute yesLabel
 111           * @type String
 112           * @default 'Yes'
 113           */
 114          yesLabel: {
 115              validator: Y.Lang.isString,
 116              valueFn: function() {
 117                  return M.util.get_string('yes', 'moodle');
 118              },
 119              setter: function(value) {
 120                  if (this._yesButton) {
 121                      this._yesButton.set('value', value);
 122                  }
 123                  return value;
 124              }
 125          },
 126  
 127          /**
 128           * The button text to use to reject the confirmation.
 129           *
 130           * @attribute noLabel
 131           * @type String
 132           * @default 'No'
 133           */
 134          noLabel: {
 135              validator: Y.Lang.isString,
 136              valueFn: function() {
 137                  return M.util.get_string('no', 'moodle');
 138              },
 139              setter: function(value) {
 140                  if (this._noButton) {
 141                      this._noButton.set('value', value);
 142                  }
 143                  return value;
 144              }
 145          },
 146  
 147          /**
 148           * The title of the dialogue.
 149           *
 150           * @attribute title
 151           * @type String
 152           * @default 'Confirm'
 153           */
 154          title: {
 155              validator: Y.Lang.isString,
 156              value: M.util.get_string('confirm', 'moodle')
 157          },
 158  
 159          /**
 160           * The question posed by the dialogue.
 161           *
 162           * @attribute question
 163           * @type String
 164           * @default 'Are you sure?'
 165           */
 166          question: {
 167              validator: Y.Lang.isString,
 168              valueFn: function() {
 169                  return M.util.get_string('areyousure', 'moodle');
 170              },
 171              setter: function(value) {
 172                  if (this._question) {
 173                      this._question.set('value', value);
 174                  }
 175                  return value;
 176              }
 177          }
 178      }
 179  });
 180  Y.augment(CONFIRM, Y.EventTarget);
 181  
 182  M.core.confirm = CONFIRM;


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