[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

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


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